/********************************************************************* * grid_data (NEW VERSION) * * DESCRIPTION: * This program will grid up an data file already * processed by rdssmi and written out in full resolution * format after the fact. It works exactly the same as * the gridding function available with rdssmi. *********************************************************************/ #include #include #include "common_structures" #define NFIELDS 20 FILE *inf ; /* Input file pointer */ FILE *opf ; /* Output grid file */ FILE *opf2 ; /* Output population file */ FILE *stf ; /* Output status file */ FILE *hdf ; /* Output header file */ /** Function prototypes **/ int allocdata ( struct std_data *, short, short ) ; main(argc, argv) int argc; char **argv; { static float **grid[NFIELDS]; static short int **pop[NFIELDS]; static float amin[NFIELDS],amax[NFIELDS]; static float gmin[NFIELDS],gmax[NFIELDS]; static float dmin[NFIELDS],dmax[NFIELDS]; static int total[NFIELDS],count[NFIELDS],intcnt[NFIELDS]; static int bmin[NFIELDS],bmax[NFIELDS]; static int nbmin[NFIELDS],nbmax[NFIELDS]; static float dval[NFIELDS]; float **matrix(); short int **ismatrix(); short int istat,eoflag=0; long int itime,stime,etime; int np,i,j,k,n,totpts,pop_flag,hdr_flag; int high_res; char infile[80],outfile[80],stfile[80],popfile[80],hdrfile[80],temp[80]; char s[20],sd[9],st[9],buf[1000]; double atof(); int nlat=0,nlon=0,intdat=0,filter_flag=0,nfield,nfiles=0; float maxlat=0.0,minlat=0.0,maxlon=0.0,minlon=0.0; float scale[NFIELDS]; float offset[NFIELDS]; int scancount ; int tscans=0 ; struct std_hdr filehdr ; /* Hold header data */ struct std_data datalo ; /* Hold lo-res data */ struct std_data datahiA ; /* Hold hi-res scan A data */ struct std_data datahiB ; /* Hold hi-res scan B data */ /***********************************************/ /* check for input arguements */ /***********************************************/ if (argc > 1) { if (argv[1][0] == '-' && argv[1][1] == 'f') { filter_flag = 1; strcpy(infile,"stdin"); strcpy(outfile,"data.grd"); strcpy(stfile,"data.status"); strcpy(hdrfile,"data.hdr"); pop_flag = 0; hdr_flag = 0; nlat = 180; nlon = 360; minlat = -90.0; maxlat = 90.0; minlon = 0.0; maxlon = 360.0; intdat = 1; } else if (argv[1][0] == '-' && argv[1][1] == 'h') { printf("grid_data -f -i -o -s -g
-r -c -b -h -d -m -t1 -t2 -n1 -n2 \n\n"); printf("flags\n"); printf(" 1 2 arguements default description\n"); printf("-- -- ---------- ------- -----------\n"); printf("-h (none) off display help information (does not execute)\n"); printf("-f (none) off run as a filter (if false, promps for input)\n"); printf(" -m (none) on turns off interpolation of data grid\n"); printf(" -i stdin specify input file\n"); printf(" -o data.grd specify output file\n"); printf(" -s data.status specify status file\n"); printf(" -g (none) specify grads header file\n"); printf(" -p (none) write out population file (int*2 output format)\n"); printf(" -r 180 specify number of output rows (lines)\n"); printf(" -c 360 specify number of output columns (samples)\n"); printf(" -t1 -90.0 minimum latitude value\n"); printf(" -t2 90.0 maximum latitude value\n"); printf(" -n1 0.0 minimum longitude value\n"); printf(" -n2 360.0 maximum longitude value\n"); exit(1); } else { printf(" Illegal command parameter (-f), exiting program! "); exit(1); } } if (filter_flag == 1 && argc > 2) { i=1; while (++i < argc) { if (argv[i][0] != '-') { printf(" Illegal command parameter (-), exiting program! "); exit(1); } switch (argv[i][1]) { case 'i': strcpy(infile,argv[i+1]); i++; break; case 'o': strcpy(outfile,argv[i+1]); i++; break; case 's': strcpy(stfile,argv[i+1]); i++; break; case 'g': hdr_flag = 1; strcpy(hdrfile,argv[i+1]); i++; break; case 'p': pop_flag = 1; strcpy(popfile,argv[i+1]); i++; break; case 'm': intdat = 0; break; case 'r': nlat = atoi(argv[i+1]); i++; break; case 'c': nlon = atoi(argv[i+1]); i++; break; case 't': if (argv[i][2] == '1') minlat = atof(argv[i+1]); else if (argv[i][2] = '2') maxlat = atof(argv[i+1]); else { printf(" Illegal command parameter (-t), exiting program! "); exit(1); } i++; break; case 'n': if (argv[i][2] == '1') minlon = atof(argv[i+1]); else if (argv[i][2] = '2') maxlon = atof(argv[i+1]); else { printf(" Illegal command parameter (-n), exiting program! "); exit(1); } i++; break; default: printf(" Illegal command parameter, exiting program! "); exit(1); } } } /***********************************************/ /* obtain user input for interactive execution */ /***********************************************/ if (filter_flag == 0) istat = grdinp(infile,outfile,stfile,popfile,hdrfile,&intdat,&nlat,&nlon, &maxlat,&minlat,&maxlon,&minlon,dmin,dmax,nbmin,nbmax, &pop_flag,&hdr_flag); else { if (strcmp(infile,"stdin") == 0) inf = stdin; else if ((inf = fopen(infile,"r")) == NULL) { printf(" Unable to open specified input file, aborting execution!"); exit(1); } if ((opf = fopen(outfile,"w")) == NULL) { printf(" Unable to open specified output file, aborting execution!"); exit(1); } if ((stf = fopen(stfile,"w")) == NULL) { printf(" Unable to open specified status file, aborting execution!"); exit(1); } if (pop_flag == 1) { if ((opf2 = fopen(popfile,"w")) == NULL) { printf(" Unable to open specified pop file, aborting execution!"); exit(1); } } if (hdr_flag == 1) { if ((hdf = fopen(hdrfile,"w")) == NULL) { printf(" Unable to open specified header file, aborting execution!"); exit(1); } } } for (i=0; i