Advertisement
SUGIYAMA

☆text2binary-vtk-points2

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