Advertisement
SUGIYAMA

☆text2binary-vtk-polygons2

Jan 27th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. int main(int argc,char *argv[])
  7. {
  8.     FILE *fpi,*fpo;
  9.     int i,j,k,nums/*,face,vertex,point*/;
  10.     int data;
  11.     int id,x,y,z;
  12.     int *file1;
  13.     char line[4];
  14.  
  15.     if(argc!=4)
  16.     {
  17.         fprintf(stderr,"Usage: %s 5m_mesh_data.lem,5m_mesh_data.raw\n",argv[0]);
  18.         exit(1);
  19.     }
  20.     printf("OPEN FILE NAME:%s\n",argv[1]);
  21.  
  22.     if((fpi=fopen(argv[1],"r"))==NULL)
  23.     {
  24.         fprintf(stderr,"Can not open\n");
  25.         exit(1);
  26.     }
  27.  
  28.     if((fpo=fopen(argv[2],"wb"))==NULL)
  29.     {
  30.         fprintf(stderr,"Can not open\n");
  31.         exit(1);
  32.     }
  33.  
  34.     nums=atoi(argv[3]);
  35.     file1= (int *)malloc(nums*3*sizeof(int));
  36.     //vertex=atoi(argv[4]);
  37.     //point=atoi(argv[5]);
  38. /*  for(i=0;i<nums;i++)
  39.     {
  40.         for (j=0;j<3;j++)
  41.         {
  42.             //for (k=0;k<point;k++)
  43.             //{
  44.                 //fseek(fpi,6*k+j*20+i*68,SEEK_SET);
  45.                 fseek(fpi,j*3+i*11,SEEK_SET);
  46.                 fgets(line, 4, fpi);
  47.                 data=atoi(line);
  48.                 //printf("%d\n",data);
  49.                 fwrite(&data,sizeof(int),1,fpo);
  50.                 //fseek(fpi,2,SEEK_CUR);
  51.             //}
  52.         }
  53.     }
  54. */
  55.  
  56.     int count=0;
  57.  
  58.     while (fscanf(fpi,"%d %d %d %d ",&id, &x, &y, &z )!= EOF)
  59.     {
  60.         file1[3*count]=x;
  61.         file1[3*count+1]=y;
  62.         file1[3*count+2]=z;
  63.         count=count+1;
  64.  
  65.        
  66.        
  67.     }
  68.     fwrite(file1,sizeof(int),nums*3,fpo);
  69.     fclose(fpi);
  70.     fclose(fpo);
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement