Advertisement
Kojima0502

textbinaryO2

Nov 15th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 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.     if(argc!=6)
  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,"5mïWçÇÉfÅ[É^ÉtÉ@ÉCÉãñº.lem\n");
  24.         exit(1);
  25.     }
  26.    
  27.     if((fpo=fopen(argv[2],"wb"))==NULL)
  28.     {
  29.         fprintf(stderr,"5mïWçÇÉfÅ[É^ÉtÉ@ÉCÉã.raw\n");
  30.         exit(1);
  31.     }
  32.    
  33.     height=atoi(argv[3]);
  34.     width=atoi(argv[4]);
  35.     r=atoi(argv[5]);
  36.     a=r/10;
  37.     //printf("%d\n",a);
  38.    
  39.     r_height=height*width/10;
  40.    
  41.     file3= (float *)malloc(width*height*sizeof(float));
  42.    
  43.     for(i=0;i<r_height;i++)
  44.     {
  45.         fseek(fpi,i*82,SEEK_SET);
  46.        
  47.         for (j=0;j<10;j++)
  48.         {
  49.             fseek(fpi,8*j+i*82,SEEK_SET);
  50.             fgets(line, 9, fpi);
  51.             data=atof(line);
  52.             //printf("%f\n",data);
  53.             file3[i*10+j]=data;
  54.             //printf("%d\n",i*10+j);
  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.             printf("%d %d\n",k,l);
  70.             //printf("%d %d\n",i,j);
  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