Advertisement
Kojima0502

combineD

Nov 12th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.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 *fpi1,*fpi2,*fpo;
  8.     int i,j,height1,width1,height2,width2;
  9.     float dn1;
  10.     int x,y;
  11.     int re;
  12.     int ix,iy;
  13.     int iw,ih,iW,iH;
  14.     float *file1,*file2;//,*file3;
  15.     if(argc!=11)
  16.     {
  17.         fprintf(stderr,"Usage: %s\n(2)Input_file1_filename\n(3)Input_file2_filename\n(4)Output_new_filename\n(5)width1\n(6)height1\n(7)width2\n(8)height2\n(9)x\n(10)y\n(11)re\n",argv[0]);
  18.         exit(1);
  19.     }
  20.    
  21.     printf("OPEN R FILE NAME:%s\n",argv[1]);
  22.     printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
  23.     printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
  24.    
  25.     width1 = atoi(argv[4]); printf("W = %d,", width1);
  26.     iw=width1/10;
  27.    
  28.     height1 = atoi(argv[5]); printf("H = %d\n", height1);
  29.     ih=height1/10;
  30.    
  31.     width2 = atoi(argv[6]); printf("W = %d,", width2);
  32.     iW=width2/10;
  33.    
  34.     height2 = atoi(argv[7]); printf("H = %d\n", height2);
  35.     iH=height2/10;
  36.    
  37.  
  38.     x = atoi(argv[8]); printf("X = %d\n" , x);
  39.     y = atoi(argv[9]); printf("Y = %d\n" , y);
  40.     re = atoi(argv[10]); printf("RE = %d\n" , re);
  41.     ix=x*re/10;
  42.     iy=y*re/10;
  43.    
  44.     printf("check00\n");
  45.     file1= (float *)malloc(iw*ih*sizeof(float));
  46.     file2= (float *)malloc(iW*iH*sizeof(float));
  47.     //file3= (float *)malloc(width1*height1*sizeof(float));
  48.    
  49.  //   printf("check0\n");
  50.    
  51.     if((fpi1=fopen(argv[1],"rb"))==NULL)
  52.     {
  53.         fprintf(stderr,"input file open error\n");
  54.         exit(1);
  55.     }
  56.     printf("check0-1\n");
  57.     fread((float *)file1,sizeof(float),iw*ih,fpi1);
  58.     printf("check0-2\n");
  59.     if((fpi2=fopen(argv[2],"rb"))==NULL)
  60.     {
  61.         fprintf(stderr,"input file open error\n");
  62.         exit(1);
  63.     }
  64.     printf("check0-3\n");
  65.     fread((float *)file2,sizeof(float),iW*iH,fpi2);
  66.     printf("check0-4\n");
  67.     if((fpo=fopen(argv[3],"wb"))==NULL)
  68.     {
  69.         fprintf(stderr,"output file open error\n");
  70.         exit(1);
  71.     }
  72.     //fread((float *)file3,sizeof(float),width1*height1,fpo);
  73.     printf("check1\n");
  74.     for(i=0;i<ih;i++)
  75.     {
  76.         for(j=0;j<iw;j++)
  77.         {
  78.             if(i>iy && i<iy+iH && j>ix && j<ix+iW)
  79.             {
  80.                 dn1=file2[(i-iy)*iW+(j-ix)];
  81.             }
  82.            // else
  83.            // {
  84.                // dn1=file1[i*iw+j];
  85.             //}
  86.             //printf("check3\n");
  87.             //fwrite(&dn1,sizeof(float),1,fpo);
  88.             //printf("i=%d j=%d dn1=%f\n",i,j,dn1);
  89.         }
  90.     }
  91.     printf("check2\n");
  92.    
  93.     free(file1);
  94.     free(file2);
  95.     //free(file3);
  96.     fclose(fpi1);
  97.     fclose(fpi2);
  98.     fclose(fpo);
  99.    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement