Advertisement
Kojima0502

text→binary 30m OsakaWan

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