Advertisement
d10070dd

text2binary-vtk-points-x

Nov 19th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. /*********************************************************************************
  2.  Input file : ASCII - space separated file (x,y,z)
  3.  Processing : ascii to binary
  4.  Output file : binary
  5.  
  6.  ***********************************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     //Decralation of variables
  15.     FILE *fpi,*fpo;
  16.     float points[3];
  17.    
  18.     int num=397;
  19.    
  20.     //Open CSV file
  21.     if((fpi=fopen(argv[1],"r"))==NULL)
  22.     {
  23.         printf ("The file can't be opened. The program is exit.\n");
  24.        
  25.         return 0;
  26.     }
  27.    
  28.     //Open VTK file for save
  29.     if((fpo=fopen(argv[2],"wb"))==NULL)
  30.     {
  31.         printf("The file can't be opened. The program is exit.\n");
  32.        
  33.         return 0;
  34.     }
  35.    
  36.     //points=(float *)malloc(num*3*sizeof(float));
  37.     //fread((float *)points,sizeof(float),1,fpi);
  38.    
  39.    
  40.     while(fscanf(fpi,"%f %f %f",&points[0],&points[1],&points[2])!=EOF)
  41.     {
  42.  
  43.         printf("%f %f %f\n",points[0],points[1],points[2]);
  44.        
  45.         fwrite(&points,sizeof(float),3,fpo);
  46.         //fwrite(&x,sizeof(float),1,fpo);
  47.         //fwrite(&y,sizeof(float),1,fpo);
  48.         //fwrite(&z,sizeof(float),1,fpo);
  49.     }
  50.    
  51.     fclose(fpi);
  52.     fclose(fpo);
  53.    
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement