ait-survey

resize

Dec 7th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  textbinaryO2
  4. //
  5. //  Created by Dai on 2013/11/13.
  6. //  Copyright (c) 2013年 Dai. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. int main(int argc,char*argv[])
  14. {
  15.    
  16.     FILE *fpi,*fpo;
  17.    
  18.     int i,j,height,width,r_height;
  19.    
  20.     int k,l;
  21.     int a,r;
  22.     //int m;
  23.     float data;
  24.     float *file3;
  25.     char line[9];
  26.    
  27.    
  28.     if(argc!=6)
  29.     {
  30.         fprintf(stderr,"Usage: %s original.txt, output.raw, height, width, resolution\n",argv[0]);
  31.         exit(1);
  32.     }
  33.     printf("OPEN FILE NAME:%s\n",argv[1]);
  34.    
  35.    
  36.     if((fpi=fopen(argv[1],"r"))==NULL)
  37.     {
  38.         fprintf(stderr,"5mïWçÇÉfÅ[É^ÉtÉ@ÉCÉãñº.lem\n");
  39.         exit(1);
  40.     }
  41.    
  42.     if((fpo=fopen(argv[2],"wb"))==NULL)
  43.     {
  44.         fprintf(stderr,"5mïWçÇÉfÅ[É^ÉtÉ@ÉCÉã.raw\n");
  45.         exit(1);
  46.     }
  47.    
  48.     height=atoi(argv[3]);
  49.     width=atoi(argv[4]);
  50.    
  51.     r=atoi(argv[5]);
  52.     a=r/10;
  53.     //printf("%d\n",a);
  54.    
  55.    
  56.     r_height=height*width/10;
  57.    
  58.    
  59.     file3= (float *)malloc(width*height*sizeof(float));
  60.    
  61.     //from text to binary
  62.     for(i=0;i<r_height;i++)
  63.     {
  64.         fseek(fpi,i*82,SEEK_SET);
  65.        
  66.         for (j=0;j<10;j++)
  67.         {
  68.            
  69.             fseek(fpi,8*j+i*82,SEEK_SET);
  70.             fgets(line, 9, fpi);
  71.             data=atof(line);
  72.             //printf("%f\n",data);
  73.             file3[i*10+j]=data;
  74.             //printf("%d\n",i*10+j);
  75.         }
  76.     }
  77.    
  78.    
  79.     //Resize : binary
  80.     //for(m=0;m<3;m++)
  81.     //{
  82.         for(i=0;i<height*a;i++)
  83.         {
  84.             for(j=0;j<width*a;j++)
  85.             {
  86.                 k=i/a;
  87.                 l=j/a;
  88.                 data=file3[k*width+l];
  89.                 //printf("%d %d\n",k,l);
  90.                 //printf("%d %d\n",i,j);
  91.                 //printf("%f\n",data);
  92.                 fwrite(&data,sizeof(float),1,fpo);
  93.             }
  94.         }
  95.     //}
  96.    
  97.     free(file3);
  98.     fclose(fpi);
  99.     fclose(fpo);
  100.    
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment