#include #include #define MXBND 50 main() /*************************************************************/ /* Cmbgrd: This program allows one to overlay several grid */ /* files which have been created by rdssmi. For */ /* example one can run rdssmi for a whole day and */ /* grid the files up, then run this program to look */ /* at an image of the composite orbits. */ /*************************************************************/ { FILE *inp1, *inp2, *opf1, *opf2, *fopen(); short int ival1,ival2,invl; float dmax[MXBND],dmin[MXBND]; int pmax[MXBND]; int i, j, k, m; int nfiles, status; int nlat,nlon,nband; static short int **pop[MXBND]; static float **grid[MXBND]; char a, c, s[2]; char infile1[60],infile2[60],outfile1[60],outfile2[60],buf[1000]; float **matrix(); short int **ismatrix(); /* ------------------- */ /* request user input */ /* ------------------- */ printf(" Please enter the output data file name: "); gets(outfile1); while ((opf1 = fopen(outfile1,"w")) == NULL) { printf(" cannot open specified output data file, please re-enter!\n"); printf(" Please enter the output data file name: "); gets(outfile1); } printf(" Please enter the output pop file name: "); gets(outfile2); while ((opf2 = fopen(outfile2,"w")) == NULL) { printf(" cannot open specified output pop file, please re-enter!\n"); printf(" Please enter the output pop file name: "); gets(outfile2); } i = 0; printf(" Please enter the number of input data files: "); gets(s); nfiles = atoi(s); printf(" Please enter the number of latitude bins: "); gets(s); nlat = atoi(s); printf(" Please enter the number of longitude bins: "); gets(s); nlon = atoi(s); printf(" Please enter the number of bands: "); gets(s); nband = atoi(s); /* ---------------------- */ /* allocate arrays */ /* ---------------------- */ for (i=0; i= 0) { if (grid[k][i][j] == -3.0 || grid[k][i][j] == -4.0 || grid[k][i][j] == -5.0) { grid[k][i][j] = (float)ival1; if (ival2 == 0) pop[k][i][j] = 1; else pop[k][i][j] = ival2; } else { grid[k][i][j] = (grid[k][i][j]*(float)pop[k][i][j] + (float)ival1*(float)ival2)/ (float)(pop[k][i][j]+ival2); if (ival2 == 0) pop[k][i][j] = pop[k][i][j] + 1; else pop[k][i][j] = pop[k][i][j] + ival2; } } else if (ival1 == -3 || ival1 == -4 || ival1 == -5) { if (pop[k][i][j] == 0) grid[k][i][j] = (float)ival1; } } /* Loop through longitude grid points */ } /* Loop through latitude grid points */ } /* Loop throught all of the grid bands */ fclose(inp1); fclose(inp2); } /* loop through all of the input files */ for (k=0; k= 0.0) { ival1 = (int)grid[k][i][j]; ival2 = pop[k][i][j]; } else if (grid[k][i][j] == -3.0) { ival1 = -3; ival2 = pop[k][i][j]; } else if (grid[k][i][j] == -4.0) { ival1 = -4; ival2 = pop[k][i][j]; } else if (grid[k][i][j] == -5.0) { ival1 = -5; ival2 = pop[k][i][j]; } else if (grid[k][i][j] == -998.0) { ival1 = -998; ival2 = pop[k][i][j]; } else if (grid[k][i][j] == -999.0) { ival1 = -999; ival2 = pop[k][i][j]; } if (grid[k][i][j] > dmax[k]) dmax[k] = grid[k][i][j]; if (grid[k][i][j]=0.0 && pop[k][i][j]>0) dmin[k] = grid[k][i][j]; if (pop[k][i][j] > pmax[k]) pmax[k] = pop[k][i][j]; fwrite(&ival1,2,1,opf1); fwrite(&ival2,2,1,opf2); } /* Loop through longitude grid points */ } /* Loop through latitude grid points */ } /* Loop throught all of the grid bands */ /* ------------------------------------------------- */ /* write out the resulting status information */ /* ------------------------------------------------- */ printf("\n total of %d files processed!\n\n",nfiles); for (k=0; k