/* This program reads the ASCII output file from SUN0063 (rainyy). The data is passed through a filter to remove impossible values. A column value of 999 and row value of 99 is used as an end flag. Records following this are used as an "audit trail". This reads rain rate processing version 3.4. COMMENT-IN APPROPRIATE RESOLUTION FOR MAP_ROWS AND MAP_COLS BEFORE COMPILING. This code is currently setup for reading 2.5 degree global resolution oceanic rain rate data sets. The output goes into a file written locally to the directory in which the program is run named test1 (for data set1) and test2 for dataset2. Usage: ReadRain.out infile.list */ #include #include /* For 5.0 degree resolution */ #define MAP_ROWS 20 #define MAP_COLS 72 /* For 2.5 degree resolution */ /*#define MAP_ROWS 52 */ /*#define MAP_COLS 144 */ /* Prototype */ void write_a_record( int, char *, unsigned int, char * ); main( int argc, char *argv[] ) { float AvgRain; char Info[104]; char dsn1[200], dsn2[200]; int ch, I1, I2, J1, J2; int numlist; int jrow, jcol, year, month, DaysInMonth; int item_cnt, iloop; int numargs; float ChiSq, TotalRain, rzero; float NonLeapYrDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; float LeapYrDays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; FILE *namelist; /* the infile.list containing input data set names */ FILE *in_file1; /* the 1st input rain rate file */ FILE *in_file2; /* the 2nd input rain rate file */ FILE *out_file1; /* the Output rain data file 1st */ FILE *out_file2; /* the Output rain data file 2nd */ /* fprintf(stderr," argv 1 %s\n",argv[1]); */ if( argc != 2) { fputs("AvgRain: Bad command line\n", stderr); return(1); } item_cnt = 0; /* Initializing item_cnt */ AvgRain = 0; /* Initializing AvgRain */ numlist = 1; /* Initializing numlist */ numargs = 0; /* Initializing numargs */ namelist = fopen( argv[1], "r"); /* opening the list of input dsn s */ out_file1 = fopen("test1", "w"); /* opening rain output file 1st */ out_file2 = fopen("test2", "w"); /* opening rain output file 2nd */ while (numlist != -1) { numlist = fscanf(namelist,"%s %s*[^\n]", &dsn1, &dsn2); if (numlist != -1 ) { fprintf(stderr,"\n namelist: INPUT FILES\n %s\n %s\n\n",dsn1, dsn2); in_file1 = fopen( dsn1, "r"); /* opening 1st 5.0 rainyy data set */ in_file2 = fopen( dsn2, "r"); /* opening 2nd 5.0 rainyy data set */ iloop = 0; /* Loop through two input data sets on variable iloop */ while(iloop < 2) { iloop = iloop +1; if(iloop == 1) { /* First data set of pair */ fscanf(in_file1,"Year:%d Month: %d Chan:%d Cols: %d %d Rows: %d %d %s%*[^\n]",&year,&month,&ch,&I1,&I2,&J1,&J2,&Info); /* fprintf(stderr,"\n Year %d Month %d Ch %d I1 %d I2 %d J1 %d J2 %d Info %s\n",year,month,ch,I1,I2,J1,J2,Info); */ if( month<1 || month>12 ) { fputs("AvgRain.c: Bad month number in command line!\n", stderr); return(1); } if( (year/4)*4 != year ) DaysInMonth = NonLeapYrDays[month-1]; else DaysInMonth = LeapYrDays[month-1]; while (numargs != -1) { numargs = fscanf(in_file1,"%d%d%f%f%*f%f%*[^\n]", &jrow, &jcol, &ChiSq, &TotalRain, &rzero); /* Look for end flag. */ if(jrow==99 && jcol==999) break; if(jrow<1 || jrow>MAP_ROWS || jcol<1 || jcol>MAP_COLS) { fprintf(stderr,"\7AvgRain: Bad input col or row, col:%d, row:%d\n", jcol, jrow); return(1); } /* fprintf(out_file1,"%6.2f\n",TotalRain); ORIG CODE */ fprintf(out_file1,"Row %d Col %d Total Rain %6.2f\n",jrow,jcol,TotalRain); } /* Ends while numargs... */ } /* Ends iloop == 1 */ /* Looping through second data set of pair */ /*if(iloop == 2) { for one data set */ if(iloop == 1) { fscanf(in_file2,"Year:%d Month: %d Chan:%d Cols: %d %d Rows: %d %d %s%*[^\n]",&year,&month,&ch,&I1,&I2,&J1,&J2,&Info); /* fprintf(stderr,"\n Year %d Month %d Ch %d I1 %d I2 %d J1 %d J2 %d Info %s\n",year,month,ch,I1,I2,J1,J2,Info); */ if( month<1 || month>12 ) { fputs("AvgRain.c: Bad month number in command line!\n", stderr); return(1); } if( (year/4)*4 != year ) DaysInMonth = NonLeapYrDays[month-1]; else DaysInMonth = LeapYrDays[month-1]; while (numargs != -1) { numargs = fscanf(in_file2,"%d%d%f%f%*f%f%*[^\n]", &jrow, &jcol, &ChiSq, &TotalRain, &rzero); /* Look for end flag. */ if(jrow==99 && jcol==999) break; if(jrow<1 || jrow>MAP_ROWS || jcol<1 || jcol>MAP_COLS) { fprintf(stderr,"\7AvgRain: Bad input col or row, col:%d, row:%d\n", jcol, jrow); return(1); } /* fprintf(out_file2,"%6.2f\n",TotalRain); ORIG */ fprintf(out_file2,"Row %d Col %d Total Rain %6.2f\n",jrow,jcol,TotalRain); } /* Ends while numargs... */ } /* Ends iloop == 2 */ } /* Close loop over iloop */ } /* Closes if numlist ne -1 - the infile.list read*/ } /* Closes while numlist - the infile.list read*/ fclose(out_file1); fclose(out_file2); return(0); }