ait-survey

combineD-e

Dec 26th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.75 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  combineD
  4. //
  5. //  Created by Dai on 2013/10/21.
  6. //  Copyright (c) 2013年 Dai. All rights reserved.
  7. //
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h> //memcpy
  11. #include<memory.h>
  12.  
  13. int main(int argc,char *argv[])
  14. {
  15.     FILE *fpi1,*fpi2,*fpo;
  16.     int i,j,height1,width1,height2,width2;
  17.     float dn1;
  18.     int x,y;
  19.     int re;
  20.     int ix,iy;
  21.     float *file1,*file2;
  22.     float *file3;
  23.     int iw,ih,iW,iH;
  24.    
  25.     if(argc!=11)
  26.     {
  27.         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]);
  28.         exit(1);
  29.     }
  30.    
  31.     printf("OPEN R FILE NAME:%s\n",argv[1]);
  32.     printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
  33.     printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
  34.    
  35.     //large
  36.     width1 = atoi(argv[4]); printf("W = %d,", width1);
  37.     iw=width1/10;
  38.    
  39.     height1 = atoi(argv[5]); printf("H = %d\n", height1);
  40.     ih=height1/10;
  41.    
  42.     //small
  43.     width2 = atoi(argv[6]); printf("W = %d,", width2);
  44.     iW=width2/10;
  45.     printf("iW=%d\n",iW);
  46.    
  47.     height2 = atoi(argv[7]); printf("H = %d\n", height2);
  48.     iH=height2/10;
  49.     printf("iH=%d\n",iH);
  50.    
  51.     x = atoi(argv[8]); printf("X = %d\n" , x); //corner of upper left in large image
  52.     y = atoi(argv[9]); printf("Y = %d\n" , y); //corner of upper left in large image
  53.     re = atoi(argv[10]); printf("RE = %d\n" , re);
  54.    
  55.     ix=x*re/10;
  56.     iy=y*re/10;
  57.    
  58.     printf("ix=%d\n",ix);
  59.     printf("iy=%d\n",iy);
  60.    
  61.     printf("check00\n");
  62.    
  63.    // file1= (float *)malloc(iw*ih*sizeof(float));  //large
  64.     file2= (float *)malloc(iW*iH*sizeof(float));  //small
  65.   //  file3= (float *)malloc(iw*ih*sizeof(float));  //for output
  66.    
  67.     printf("check0\n");
  68.    
  69.     if((fpi1=fopen(argv[1],"rb+"))==NULL)
  70.     {
  71.         fprintf(stderr,"input file open error\n");
  72.         exit(1);
  73.     }
  74.     printf("check0-1\n");
  75.   //  fread((float *)file1,sizeof(float),iw*ih,fpi1);
  76.    
  77.     printf("check0-2\n");
  78.     if((fpi2=fopen(argv[2],"rb"))==NULL)
  79.     {
  80.         fprintf(stderr,"input file open error\n");
  81.         exit(1);
  82.     }
  83.     printf("check0-3\n");
  84.     fread((float *)file2,sizeof(float),iW*iH,fpi2);
  85.     printf("check0-4\n");
  86.    /* if((fpo=fopen(argv[3],"wb"))==NULL)
  87.     {
  88.         fprintf(stderr,"output file open error\n");
  89.         exit(1);
  90.     }
  91.     */
  92.     //fread((float *)file3,sizeof(float),width1*height1,fpo);
  93.     printf("check1\n");
  94.    
  95.     j=0;
  96.    
  97.     for(i=iy;i<iy+iH;i++)//for large
  98.     {
  99.         for(j=0;j<iW;j++)//for large
  100.         {
  101.         //fseek(fpi1,i*iw*sizeof(float)+ix*sizeof(float),SEEK_SET);
  102.         //fseek(fpi2,i*iW*sizeof(float),SEEK_SET);
  103.      
  104.       //if(i>iy && i<iy+iH && j>ix && j<ix+iW) //for small
  105.       //{
  106.         //j=ix;
  107.        // printf("i=%d\n",i);
  108.        // printf("j=%d\n\n",j);
  109.        
  110.         //printf("file1=%d\n",i*ih+j);
  111.        // printf("file2=%d\n",(i-iy)*iW);
  112.         //memcpy(&file1[i*iw+j],&file2[(i-iy)*iW],sizeof(float)*iW);
  113.        // printf("memcpy-OK\n");
  114.         fseek(fpi1,i*iw+ix+j,SEEK_SET);
  115.         dn1=file2[(i-iy)*iW+j];
  116.         fwrite(&dn1,sizeof(float),1,fpi1);
  117.     //  }
  118.         /*
  119.         if(i>iy && i<iy+iH && j>ix && j<ix+iW) //for small
  120.             {
  121.                 dn1=file2[(i-iy)*iW+(j-ix)];
  122.             }
  123.             else
  124.             {
  125.                 dn1=file1[i*iw+j];
  126.             }
  127.             file3[i*iw+j]=dn1;
  128.            // printf("check3\n");
  129.             //fwrite(&dn1,sizeof(float),1,fpo);
  130.             //printf("i=%d j=%d dn1=%f\n",i,j,dn1);
  131.         */
  132.       }
  133.     }
  134.     printf("check2\n");
  135.     //fwrite(&file1,sizeof(float),iw*ih,fpo);
  136.    
  137.     //free(file1);
  138.     free(file2);
  139.     //free(file3);
  140.     fclose(fpi1);
  141.     fclose(fpi2);
  142.    // fclose(fpo);
  143.    
  144. }
Advertisement
Add Comment
Please, Sign In to add comment