//Filter.c, 27 March 1996, to remove integrity-compromised data from the //AERI datafile. Ensure the datafile containing the info on which data is //to be excluded is of the form YYMMDD hh:mm:ss hh:mm:ss where times are //start excluding and stop excluding times respectively. #include #include #include #include #include #define dev (0) //development flag, prints working values #define batch (1) //for batch use set to 1 FILE *fp1,*fp2,*fp3, *fp4; //void main(void); remove comments for non-batch operation void main(int _argc, char **_argv); //remove comments for batch operation void openfiles(void); //procedure prototypes void filterfile (void); void closefiles(void); void getinquiry(void); double convertime(char *); char date[80], infile1name[50], infile2name[50], outfilename[50]; //void main(void) remove comments for non-batch operation void main (int _argc, char** _argv) //remove comments for batch operation { getinquiry(); while (!feof(fp1)) filterfile(); closefiles(); } /*-----------------------------------------------------------*/ void getinquiry (void) { char chaff[200]; char cchaff; if(batch) { if(_argc!=4) { printf("Sorry, wrong number of arguments to filter.c\n"); printf("Expected: AERI filename, Integrity-compromised data file, Output filename\n"); exit(0); } strcpy (infile1name, _argv[1]); strcpy (infile2name, _argv[2]); strcpy (outfilename, _argv[3]); } if(dev) //if developing, use these templates to avoiding entering full paths { sprintf(infile1name,"c:\\osborne\\cdev2\\ae960321.w55"); sprintf(infile2name,"c:\\osborne\\cdev2\\baddata.txt"); sprintf(outfilename,"c:\\osborne\\cdev2\\output.txt"); } printf("\nAERI Data Filtering Program...\n\n"); if(!(batch)) { printf("Please enter the filename for the source AERI data\n"); if(!(dev)) scanf("%s", infile1name); } fp1 = fopen(infile1name,"r"); if (fp1 == NULL) { printf("Sorry, could not open file %s\n", infile1name); printf("Press ENTER to continue...\n"); fflush(stdin); scanf("%c", &cchaff); exit(0); } fgets(chaff, 199, fp1); //remove header lines fgets(chaff, 199, fp1); if(!(batch)) { printf("\nPlease enter the name of the data integrity file\n"); if(!(dev)) scanf("%s", infile2name); } fp2 = fopen (infile2name, "r"); if (fp2 == NULL) { printf("Sorry, could not open file %s\n", infile2name); printf("Press ENTER to continue...\n"); fflush(stdin); scanf("%c", &cchaff); exit(0); } fgets(chaff, 199, fp2); //remove headers if(!(batch)) { printf("\nPlease enter a name for the filtered output file\n"); if(!(dev)) scanf("%s", outfilename); } fp3 = fopen (outfilename, "w"); if (fp3 == NULL) { printf("Sorry, could not open file %s\n", outfilename); printf("Press return to continue\n"); fflush(stdin); scanf("%c", &cchaff); exit(0); } fprintf(fp3, "Date Time ModyFraction UTCHour AvWavenumber "); fprintf(fp3, "Radiance BTemp (K) BTemp (C) \n"); fp4 = fopen ("filtlog.txt", "w"); if (fp4 == NULL) { printf("Sorry, could not open file filterlog\n"); printf("Press ENTER to continue...\n"); fflush(stdin); scanf("%c", &cchaff); exit(0); } fprintf(fp4, "Data removed from file %s...\n", infile1name); } /*-----------------------------------------------------------*/ void filterfile (void) { char aeribuffer[200], removebuffer[200]; char chaff[200]; char aeridate[15], aeritime[15]; double ModyFraction, UTCHour, AvWavenumber, Rad, BTempK, BTempC; double decaetime; //decimal conversion for time double aetimefloat; //float version of aedateint for printing leading zeros long int aedateint, aetimeint; //for each row double starttime, stoptime; long int bldate; //date on baddata file char blstoptime[14], blstarttime[14]; //start & stoptimes for exclusion int noprint; //flag for fprinting or not certain lines char cchaff; int j = 0; //counter for number of lines omitted while(!(feof(fp1))) //for every line in the AERI datafile... { fgets(aeribuffer, 199, fp1); //read in a line of AERI data if(feof(fp1)) //reached EOF { printf("\nFilter Complete (%d lines removed).\n",j); if(batch==0) { fflush(stdin); printf("Press ENTER to continue\n"); scanf("%c", &cchaff); } exit(0); } sscanf(aeribuffer, "%ld %ld %lf %lf %lf %lf %lf %lf", &aedateint, &aetimeint, &ModyFraction, &UTCHour, &AvWavenumber, &Rad, &BTempK, &BTempC); noprint =0; while(!(feof(fp2))) //for every line in the baddata file... { fgets(removebuffer, 199, fp2); if(feof(fp2)) break; sscanf(removebuffer, "%ld %10s %10s", &bldate, blstarttime, blstoptime); starttime = convertime(blstarttime); stoptime = convertime(blstoptime); if ((UTCHour > starttime)&&(UTCHour < stoptime)&&(bldate==aedateint)) { if(j==0) printf("\nData excluded from O/P file:\n"); printf("%06.lf\n",((double)(aetimeint))); if(((j==20)||(j==40))&&((batch==0))) { printf("Press ENTER for more...\n"); fflush(stdin); scanf("%c", &cchaff); } noprint = 1; aetimefloat = (double)(aetimeint); fprintf(fp4, "%6.ld %06.lf\n", aedateint, aetimefloat); j++; break; } } if(noprint==0) //if here, no exclusion necessary { aetimefloat = (double)(aetimeint); fprintf(fp3, "%6.ld %06.lf %11.5lf %10.5lf %10.3lf %10.4lf %8.2lf %7.2lf\n", aedateint, aetimefloat, ModyFraction, UTCHour, AvWavenumber, Rad, BTempK, BTempC); } rewind(fp2); fgets(chaff, 199, fp2); //remove header again } } /*-----------------------------------------------------------*/ double convertime(char *intime) { char h1, h2, min1, min2, s1, s2, chaff; //single characters for reading in time string. char hour[5], min[5], sec[5]; //hours, minutes and seconds in string form float hh, minmin, ss; //hours, minutes and seconds as ints double newtime; sscanf(intime, "%c%c%c%c%c%c%c%c", &h1,&h2, &chaff, &min1, &min2, &chaff, &s1, &s2); //chaff colons. sprintf(hour, "%c%c", h1,h2); sprintf(min, "%c%c", min1, min2); sprintf(sec, "%c%c", s1, s2); //if(dev) printf("Time to convert is %s\n", intime); hh = atof(hour); minmin = atof (min); ss = atof (sec); newtime = (hh + (minmin/60.0) + (ss/3600.0)); //if(dev) printf("Newtime after conversion is %lf\n", newtime); return(newtime); } /*-----------------------------------------------------------*/ void closefiles() //program normally exits before here { fclose(fp1); fclose(fp2); fclose(fp3); printf("Files successfully closed\n"); } /*-----------------------------------------------------------*/