ait-survey

float_raw_average

Dec 8th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 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 *fpio;
  8.     int i,height,width;
  9.     float dn;
  10.     float *file;//image data
  11.     //float *file3;
  12.     //float start,end;
  13.     float total,average;
  14.    
  15.     if(argc!=4)
  16.     {
  17.         fprintf(stderr,"Usage: %s\n(2)Input_R_READ_filename\n(3)width\n(4)height\n",argv[0]);
  18.         exit(1);
  19.     }
  20.    
  21.         printf("Input FILE NAME:%s\n",argv[1]);
  22.    
  23.    
  24.     width = atoi(argv[2]); printf("W = %d,", width);
  25.         height = atoi(argv[3]); printf("H = %d\n", height);
  26.    
  27.     /*---------ÉÅÉÇÉäÇÃé©ìÆäÑìñ----------*/
  28.         file= (float *)malloc(width*height*sizeof(float));
  29.    
  30.     /*----------------ì¸óÕRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  31.         if((fpio=fopen(argv[1],"rb"))==NULL)
  32.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  33.             fprintf(stderr,"input file open error\n");
  34.         exit(1);
  35.         }
  36.    
  37.         fread((float *)file,sizeof(float),width*height,fpio);
  38.     /*----------------âÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìèIóπ----------------------*/
  39.     /*----------------ì¸óÕNIRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  40.    
  41.         //fread((float *)file3,sizeof(float),width*height,fpo);
  42.    
  43.     total=0;
  44.    
  45.     for(i=0;i<height*width;i++)
  46.     {
  47.         total=total+file[i];
  48.     }
  49.    
  50.     average=total/(height*width);
  51.         printf("The average depth is %fm.",average);
  52.     free(file);
  53.    
  54.     fclose(fpio);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment