Advertisement
Kojima0502

☆textbinary_PF☆

Dec 10th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc,char*argv[])
  6. {
  7.     FILE *fpi,*fpo;
  8.     int i,j,height,width,r_height;
  9.     int k,l;
  10.     int a,r;
  11.     float data;
  12.     float *file3;
  13.     char line[9];
  14.  
  15.     if(argc!=6)
  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.     //load text data
  23.     if((fpi=fopen(argv[1],"r"))==NULL)
  24.     {
  25.         fprintf(stderr,"5mïWçÇÉfÅ[É^ÉtÉ@ÉCÉãñº.lem\n");
  26.         exit(1);
  27.     }
  28.    
  29.     //save binary data
  30.     if((fpo=fopen(argv[2],"wb"))==NULL)
  31.     {
  32.         fprintf(stderr,"5mïWçÇÉfÅ[É^ÉtÉ@ÉCÉã.raw\n");
  33.         exit(1);
  34.     }
  35.    
  36.     height=atoi(argv[3]);
  37.     r=atoi(argv[5]);
  38.     a=r/10;
  39.     width=atoi(argv[4]);
  40.     r_height=height*width/10;
  41.    
  42.     file3= (float *)malloc(width*height*sizeof(float));
  43.    
  44.     for(i=0;i<r_height;i++)
  45.     {
  46.         fseek(fpi,i*82,SEEK_SET);
  47.        
  48.         for (j=0;j<10;j++)
  49.         {
  50.             fseek(fpi,8*j+i*82,SEEK_SET);
  51.             fgets(line, 9, fpi);
  52.             data=atof(line);
  53.             // printf("%f\n",data);
  54.             file3[i*10+j]=data;
  55.         }
  56.     }
  57.    
  58.    
  59.    
  60.     for(i=0;i<height*a;i++)
  61.     {
  62.        
  63.        
  64.         for(j=0;j<width*a;j++)
  65.         {
  66.             k=i/a;
  67.             l=j/a;
  68.             data=file3[k*width+l];
  69.            
  70.            
  71.             // printf("%f\n",data);
  72.             fwrite(&data,sizeof(float),1,fpo);
  73.         }
  74.     }
  75.    
  76.    
  77.     free(file3);
  78.     fclose(fpi);
  79.     fclose(fpo);
  80.    
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement