Advertisement
k3rsowa

two points txt→bin (image coordinates)

Oct 30th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     //Decralation of variables
  6.     FILE *fpi1,*fpi2,*fpo;
  7.     int id,ix1,iy1,ix2,iy2;
  8.     float x1,y1,z1,x2,y2,z2;
  9.     char nan[4];
  10.    
  11.     //Open CSV file
  12.     if((fpi1=fopen(argv[1],"r"))==NULL)
  13.     {
  14.         printf ("The file can't be opened. The program is exit.\n");
  15.        
  16.         return 0;
  17.     }
  18.     //Open CSV file
  19.     if((fpi2=fopen(argv[2],"r"))==NULL)
  20.     {
  21.         printf ("The file can't be opened. The program is exit.\n");
  22.        
  23.         return 0;
  24.     }
  25.  
  26.    
  27.     //Open VTK file for save
  28.     if((fpo=fopen(argv[3],"wb"))==NULL)
  29.     {
  30.         printf("The file can't be opened. The program is exit.\n");
  31.        
  32.         return 0;
  33.     }
  34.    
  35.    
  36.     //count how many lines
  37.     /*
  38.      while((c=fgetc(fpi))!=EOF)
  39.      {
  40.      if(c=='\n')
  41.      newline_count++;
  42.      }
  43.      */
  44.    
  45.     while(fscanf(fpi1,"%d %f %f %f %s",&id,&x1,&y1,&z1,nan)!=EOF)
  46.     {
  47.  
  48.         ix1=(int)((x1+28000)-1);
  49.         iy1=(int)((-139500-y1)-1);
  50.         ix2=(int)((x2+28000)-1);
  51.         iy2=(int)((-139500-y2)-1);
  52.    
  53.        
  54.         while(fscanf(fpi2,"%d %f %f %f %s",&id,&x2,&y2,&z2,nan)!=EOF)
  55.        {
  56.            
  57.            
  58.            ix1=(int)((x1+28000)-1);
  59.            iy1=(int)((-139500-y1)-1);
  60.            ix2=(int)((x2+28000)-1);
  61.            iy2=(int)((-139500-y2)-1);
  62.            
  63.            printf("%d %f %f %f %d %d %f %f %f %d %d\n",id,x1,y1,z1,ix1,iy1,x2,y2,z2,ix2,iy2);
  64.            
  65.         fwrite(&id,sizeof(int), 1,fpo);
  66.         fwrite(&x1,sizeof(float),1,fpo);
  67.         fwrite(&y1,sizeof(float),1,fpo);
  68.         fwrite(&z1,sizeof(float),1,fpo);
  69.         fwrite(&ix1,sizeof(int),1,fpo);
  70.         fwrite(&iy1,sizeof(int),1,fpo);
  71.         fwrite(&id,sizeof(int), 1,fpo);
  72.         fwrite(&x2,sizeof(float),1,fpo);
  73.         fwrite(&y2,sizeof(float),1,fpo);
  74.         fwrite(&z2,sizeof(float),1,fpo);
  75.         fwrite(&ix2,sizeof(int),1,fpo);
  76.         fwrite(&iy2,sizeof(int),1,fpo);
  77.            
  78.            //*
  79.            fprintf(fpo,"%d %f %f %f %d %d %f %f %f %d %d\n",id,x1,y1,z1,ix1,iy1,x2,y2,z2,ix2,iy2);
  80.            //*
  81.        }
  82.     }
  83.    
  84.    
  85.     fclose(fpi1);
  86.     fclose(fpi2);
  87.     fclose(fpo);
  88.    
  89.    
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement