#include #include #include #define VERBOSE 0 #define MAXNUMLINES 5 #define PCDOS 0 FILE *fp1; /*Procedure Prototypes...*/ void openmetfile(char*); void getmetdata(void); void closemetfile(void); char metname[80]; void main(void) { char metname[80]; printf("Please enter the filename of the met data\n"); scanf("%s", metname); openmetfile(metname); getmetdata(); closemetfile(); } void getmetdata(void) { char buff[500]; double decday, decmin, lat, longitude, tsgtemp, chaff; double pressure, airtemp, relhum, winddir, relwindspeed, truewinddir, truewindspeed; double startime, stoptime; double avperiod; int year, day; char chaffchar; char trimtime[10]; char h1,h2,m1,m2,s1,s2; char targettime[5]; char hhmm[5]; char startimestring[10], stoptimestring[10]; double airtemparray[MAXNUMLINES+1]; double seatemparray[MAXNUMLINES+1]; double windarray[MAXNUMLINES+1]; double relhumarray[MAXNUMLINES+1]; double airtempav, airtempstd, seatempav, seatempstd, avwindspeed, airminussea, stdwindspeed; double relhumav, relhumstd; int j; sprintf(targettime, "%s", "0000"); while (strcmp(targettime, "exit")!=0) { if (PCDOS) printf("\n\n\n\n\nWelcome to the BOSBORNE DiscoMet Archive Searcher and Data Assimilator...\n"); printf("What target time would you like to search for? (HHMM)"); scanf("%s", targettime); if (strcmp(targettime, "exit")==0) exit(0); while (!feof(fp1)) { fgets(buff, 499, fp1); if (VERBOSE) { if (PCDOS) { } else printf("Data stream: %s\n", buff); } sscanf(buff, "%d,%lf,%d,%lf,%6s,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &year, &decday, &day, &decmin, trimtime, &lat, &longitude, &tsgtemp, &chaff, &chaff, &pressure, &airtemp, &relhum, &winddir, &relwindspeed, &truewinddir, &truewindspeed); if (VERBOSE) { if (PCDOS) { } } sscanf(trimtime, "%c%c%c%c%c%c", &h1, &h2, &m1, &m2, &s1, &s2); sprintf(hhmm, "%c%c%c%c", h1, h2, m1, m2); if (VERBOSE) { if (PCDOS) { } else printf("Current metdata time is %s\n", hhmm); } if(strcmp(targettime,hhmm)==0) { if (VERBOSE) { printf("\0\n"); printf("\nMatching Time Found\n"); } break; } } if (strcmp(targettime,hhmm)!=0) { printf("Sorry, target time not available\n"); exit(0); } printf("\n\n\n\nAveraging Period Results...\n"); for (j=1; j<=MAXNUMLINES; j++) { if (j!=1) fgets(buff, 499, fp1); sscanf(buff, "%d,%lf,%d,%lf,%6s,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &year, &decday, &day, &decmin, trimtime, &lat, &longitude, &tsgtemp, &chaff, &chaff, &pressure, &airtemp, &relhum, &winddir, &relwindspeed, &truewinddir, &truewindspeed); if (j==1) startime = decday; if (j==1) strcpy(startimestring, trimtime); if (VERBOSE) printf("Air temperature %d is %lf; windspeed %lf; 5m-SST %lf; RH %lf\n", j, airtemp, truewindspeed, tsgtemp, relhum); seatemparray[j]= tsgtemp; airtemparray[j]= airtemp; windarray[j] = truewindspeed; relhumarray[j] = relhum; printf("relhum is now %lf\n", relhum);} if(feof(fp1)) { printf("Sorry, end of file reached before last entry... \n"); exit(0); } stoptime = decday; strcpy(stoptimestring,trimtime); airtempav = 0.0; relhumav = 0.0; avwindspeed = 0.0; seatempav = 0.0; for (j=1; j<=MAXNUMLINES; j++) { airtempav = airtempav + airtemparray[j]; avwindspeed = avwindspeed + windarray[j]; seatempav = seatempav + seatemparray[j]; relhumav = relhumav + relhumarray[j]; printf("relhumav is currently %lf\n", relhumav);} airtempav = airtempav/MAXNUMLINES; avwindspeed = avwindspeed/MAXNUMLINES; seatempav = seatempav/MAXNUMLINES; relhumav = relhumav/MAXNUMLINES; printf("relhumav is now %lf\n", relhumav); airminussea = airtempav - seatempav; printf("Average air temperature = %lf\n", airtempav); printf("Average sea temperature (5m) = %lf\n", seatempav); printf("Average windspeed = %lf\n", avwindspeed); printf("Average relhum = %lf\n", relhumav); printf("Average air/sea temperature difference (air-sea) = %lf\n", airminussea); if (airminussea < 0) printf("Sea is WARMER\n"); else printf("Sea is COOLER\n"); avperiod = stoptime - startime; airtempstd = 0.0; stdwindspeed = 0.0; seatempstd = 0.0; relhumstd = 0.0; for (j=1; j<=MAXNUMLINES; j++) { airtempstd = airtempstd + (airtempav - airtemparray[j])*(airtempav - airtemparray[j]); seatempstd = seatempstd + (seatempav - seatemparray[j])*(seatempav - seatemparray[j]); stdwindspeed = stdwindspeed + (avwindspeed - windarray[j])*(avwindspeed - windarray[j]); relhumstd = relhumstd + (relhumav - relhumarray[j])*(relhumav - relhumarray[j]); } airtempstd = airtempstd/(MAXNUMLINES-1); airtempstd = sqrt(airtempstd); stdwindspeed = stdwindspeed/(MAXNUMLINES-1); stdwindspeed = sqrt(stdwindspeed); seatempstd = seatempstd/(MAXNUMLINES-1); seatempstd = sqrt(seatempstd); relhumstd = relhumstd/(MAXNUMLINES -1); relhumstd = sqrt(relhumstd); printf("Airtempstd = %lf\n", airtempstd); printf("Seatempstd = %lf\n", seatempstd); printf("Windspeed std = %lf\n", stdwindspeed); printf("RHstd = %lf\n", relhumstd); printf("Startime (HHMMSS) %s, Stoptime (HHMMSS) %s, avperiod %lf minutes\n", startimestring, stoptimestring, avperiod*60.0*24.0); fflush(stdin); printf("\nPress any key, plus ENTER, to continue\n"); scanf("%c", &chaffchar); } } void openmetfile(char *metname) { fp1 = fopen(metname, "r"); if (fp1 == NULL) { printf("Sorry, unable to open met file\n"); exit(0); } } void closemetfile (void) { fclose(fp1); }