//OBTcomp.c, to compare brightness temperature estimates between the AERI and Peter Minnett's IRTs. #include #include #include #define dev (1) //development flag, prints working values FILE *fp1,*fp2,*fp3; void openfiles(void); //procedure prototypes void readfile (void); double convertime(char *); char[80] date, infile1name, infile2name, outfilename, suffix; int runmode; main() { getinquiry(void); openfiles(void); while (!(EOF(fp1)) readfile (void); closefiles(void); } /*-----------------------------------------------------------*/ void getinquiry (void) { char [5] y1,y2,d1,d2,m1,m2, day, month, year; int yy,mm,dd; printf("Please enter the date for your SST comparison enquiry, in the form YYMMDD\n"); scanf("%s", &date); sscanf(date, "%c%c%c%c%c%c" &y1,&y2, &m1, &m2, &d1, &d2); sprintf(year, "%c%c", y1,y2); sprintf(month, "%c%c", m1, m2); sprintf(day, "%c%c", d1, d2); mm = atoi(month); yy = atoi (year); dd = atoi (day); //check date integrity if (yy!=96) { printf("Sorry, only 1996 data is available\n") exit(0); } if ((mm<0) || (mm>12)) { printf("Input error in month field\n"); exit(0); } if ((dd<0) || (dd>31)) { printf("Input error in day field\n"); exit(0); } printf("Please enter the AERI datafile suffix (s55,w35, etc)\n"); scanf("%s", &suffix); sprintf(infilename1,"ae%s.%s", date, suffix); sprintf(infilename2, "Peter's filename"); sprintf(outfilename, "AT%s.%s", date, suffix); printf("Please select operation mode: \n") printf("\n") printf("\t1: One IRT measurement only\n"); printf("\t2: Averaged IRT measurement\n"); scanf("%d", &runmode); } /*-----------------------------------------------------------*/ void openfiles() char[200] chaff; { sprintf(outfilename, "OP%s.%s", date, suffix); fp1 = fopen(infile1name,"r"); if (fp1 == NULL) { printf("Sorry, could not open file %s\n", infile1name); exit(0); } fgets(chaff, 199,fp1); //remove header lines fgets(chaff, 199, fp1); fp2 = fopen (infile2name, "r"); if (fp2 == NULL) { printf("Sorry, could not open file %s\n", infile2name); exit(0); } fp3 = fopen (outfilename, "w"); if (fp3 == NULL) printf("Sorry, could not open file %s\n", outfilename); } /*-----------------------------------------------------------*/ void readfile (void) { char [200] aeribuffer, irtbuffer1, irtbuffer2; char[400] outputbuff; char[15] aeridate, aeritime, irtdate, irttime, irt2date, irt2time; char[5] aeday, aemonth, aeyear, irday, irmonth, iryear; char aey1, aey2, aed1, aed2, aem1, aem2; char iry1, iry2, ird1, ird2, irm1, irm2; double ModyFraction, UTCHour, AvWavenumber, Rad, BTempK, BTempC; int aeyy, aemm, aedd, iryy, irmm, irdd; double decaetime, decirtime, decirt2time; //decimal conversion for time double difftime1, difftime2; //the difference between AERI and IRT time double aeritemp, irttemp, irt2temp; long int aedateint, aetimeint; //for each row fgets(aeribuffer,199,fp1); //get the first row of AERI file sscanf(aeribuffer, "%ld, %ld, %lf, %lf, %lf, %lf, %lf, %lf", &aedateint, &aetimeint, &ModyFraction, &UTCHour, &AvWavenumber, &Rad, &BTempK, &BTempC); //extract variables if(dev) printf("Date is %ld, Time is %ld, ModyFraction is %lf, UTCHour is %lf, AvWavenumber is %lf, Rad is %lf, BTempK is %lf, BTempC is %lf", aedateint, aetime, ModyFraction, UTCHour, AvWavenumber, Rad, BTempK, BTempC); sprintf(aedate, "%ld", aedateint); sscanf(aedate, "%c%c%c%c%c%c" &aey1,&aey2, &aem1, &aem2, &aed1, &aed2); sprintf(aeyear, "%c%c", aey1,aey2); sprintf(aemonth, "%c%c", aem1, aem2); sprintf(aeday, "%c%c", aed1, aed2); aemm = atoi(aemonth); aeyy = atoi (aeyear); aedd = atoi (aeday); fgets(irtbuffer,199,fp2); sscanf(irtbuffer, "%s, %s, %d, %d, %lf, %ld", irtdate, irttime, &irttemp); sscanf(irdate, "%c%c%c%c%c%c%c%c%c%c" &chaff, &chaff, &iry1,&iry2, &chaff, &irm1, &irm2, &chaff, &ird1, &ird2); sprintf(iryear, "%c%c", iry1,iry2); sprintf(irmonth, "%c%c", irm1, irm2); sprintf(irday, "%c%c", ird1, ird2); irmm = atoi(irmonth); iryy = atoi (iryear); irdd = atoi (irday); if ((irmm == aemm)&&(iryy == aeyy)&&(irdd == aedd)) { printf("Successful date match achieved. Stand by...\n"); } else { printf("Unsuccessful date match. Exiting...\n"); exit(0); } decaetime = UTCHour; decirtime = converttime(irtime); printf("Decimal time conversion complete: first AERI data is for %lf\n", decaetime); printf(" first IRT data is for %lf\n", decirtime); difftime1 = decaetime - decirtime; if((difftime1) < 0) { printf("Sorry, this date will require manual manipulation\n"); exit(0); } while (TRUE) do { fgets(irtbuffer,199,fp2); sscanf(irtbuffer, "%s, %s, %d, %d, %lf, %ld", irtdate, irttime, &irttemp); decirtime = converttime(irtime); difftime1 = decaetime - decirtime; fgets(irtbuffer2,199,fp2); sscanf(irtbuffer2, "%s, %s, %d, %d, %lf, %ld", irt2date, irt2time, &irt2temp); decirt2time = converttime(irt2time); difftime2 = decaetime - decirt2time; if (difftime2 < 0) break; } if (abs(difftime1)>abs(difftime2)) fprintf(fp3, "%ld \t %ld \t %lf \t %lf\t %lf \t %lf\t %lf\t %lf\t %lf\t %lf\t %lf\t", aedateint, aetimeint, ModyFraction, UTCHour, AvWavenumber, Rad, BTempK, aetimeint, BTempC,irt2temp, irt2time); else fprintf(fp3, "%ld \t %ld \t %lf \t %lf\t %lf \t %lf\t %lf\t %lf\t %lf\t %lf\t %lf\t", aedateint, aetimeint, ModyFraction, UTCHour, AvWavenumber, Rad, BTempK, aetimeint, BTempC,irttemp, irttime); } /*-----------------------------------------------------------*/ double convertime(char *intime) char h1, h2, min1, min2, s1, s2, chaff; //single characters for reading in time string. char[5] hour, min, sec; //hours, minutes and seconds in string form int hh, minmin, ss; //hours, minutes and seconds as ints sscanf(intime, "%c%c%c%c%c%c%c%c " &aeh1,&aeh2, &chaff, &aemin1, &aemin2, &chaff, &aes1, &aes2); //chaff colons. sprintf(aehour, "%c%c", h1,h2); sprintf(aemin, "%c%c", min1, min2); sprintf(aesec, "%c%c", s1, s2); aehh = atoi(hour); aeminmin = atoi (min); aess = atoi (sec); return(hh + double(minmin)/60 + double(ss)/3600); /*-----------------------------------------------------------*/ void closefiles() fclose(fp1); fclose(fp2); fclose(fp3); printf("Files successfully closed\n"); /*-----------------------------------------------------------*/