/* @(#) File name: fms_mcw_rad.c Release: 1.1 Date: 7/28/94, 14:00:08 */ /**************************************************************************** PROGRAM: mcw_rad () PURPOSE/DESCRIPTION: MCW_SAD reads in NOAA MICROWAVE RADIOMETER data at SAN NICOLAS ISLAND site taken during the FIRE Marine Stratacumulus Experiment. This program reads the header information and microwave radiometer record one at a time, verify the date/time (hour-second) values within each record, then prints out site, date/time range values from the header and the min. max. values of vapor and liquid variables. Data was collected during the period from July 1, 1987 to Dec. 7, 1987. INVOCATION: (void) mcw_rad (argc, argv); WHERE - I the number of arguments from the command line invocation. - I the argument list, including the program name and multiple microwave radiometer data files. For example, if the executable is fms_mcw_rad, then, fms_mcw_rad mcw_rad.001 mcw_rad.002 will read two files: mcw_rad.001, and mcw_rad.002. FILE/RECORD REFERENCES: The data files are named , where yy is the year, mm the month (only 11 and 12 are valid), and dd the day (UTC) when the data were collected. EXTERNAL ROUTINES: None. NOTES: Two external functions: interrupt_cat(), and str_trim() are in the fsdf_lib.c C source file. *****************************************************************************/ #ifdef sccs static char sccsid[] = "File: fms_mcw_rad.c Release: 1.1 Date: 7/28/94, 14:00:08" #endif #include #include #include /** For ANSI C comformance. **/ #include #include #include #include #define fmin(a, b) ((a >= b) ? b : a) #define fmax(a, b) ((a >= b) ? a : b) extern void interrupt_cat(); extern int str_trim(); main (argc, argv) int argc; char **argv; { void mcw_rad (); if (signal (SIGINT, SIG_IGN) != SIG_IGN) (void) signal (SIGINT, interrupt_cat); signal (SIGTERM, interrupt_cat); (void) mcw_rad (argc, argv); exit (0); } void mcw_rad (argc, argv) int argc; char **argv; { FILE *fptr, *tptr; char time_buf[3], beg_date[9], end_date[9], beg_time[5], end_time[5]; char filename[200], buf[160], vapor_buf[6], liquid_buf[6]; int i=0, total, year, month, day, hour, minute, second, nrec; double vapor, liquid, min_vapor, min_liquid, max_vapor, max_liquid; while (i++ < (argc-1)) { strcpy (filename, argv[i]); if ((fptr = fopen (filename, "r")) == NULL) { fprintf (stderr, "ERROR: Can't open file:\t %s\n", filename); continue; } /*** The following 4 lines of codes can be used to find out the number of *** lines, so we can get the rough idea of how many records in this file. *** It can allocate the space efficiently to store all vapor and liquid *** values. ***/ /* sprintf(buf, "wc -l %s| awk '{printf \$1}' > tobe_deleted", filename); system (buf); tptr = fopen ("tobe_deleted", "r"); fscanf (tptr, "%d", &total); */ nrec = 0; /**** Read the header lines. Header lines are as follows: **** Line 1: DATA line, identify type of data **** Line 2: SITE line, identify the site of data collected **** Line 3: Time range in UTC **** Line 4: RECORD AVERAGING. ****/ if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading header DATA line\n"); if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading header SITE line\n"); if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading header Date/time line\n"); if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading header RECORD AVERAGING line\n"); /**** Read the column headings, and a blnak line. ****/ if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading blank line.\n"); if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading column heading line 1.\n"); if (fgets (buf, sizeof (buf), fptr) == (char *)NULL) fprintf (stderr, "ERROR: reading column heading line 2.\n"); min_vapor = MAXDOUBLE; max_vapor = MINDOUBLE; min_liquid = MAXDOUBLE; max_liquid = MINDOUBLE; /**** Read the data record one by one. ****/ while (fgets (buf, sizeof (buf), fptr) != (char *)NULL) { str_trim (buf, 0); if (strlen (buf) == 0) continue; sscanf (buf, "%2d%2d%2d", &year, &month, &day); strncpy (time_buf, &(buf[7]), 2); time_buf[2] = '\0'; hour = atoi (time_buf); strncpy (time_buf, &(buf[9]), 2); time_buf[2] = '\0'; minute = atoi (time_buf); strncpy (time_buf, &(buf[11]), 2); time_buf[2] = '\0'; second = atoi (time_buf); if (nrec == 0) { sprintf (beg_date, "%2d/%02d/%2d", month, day, year); sprintf (beg_time, "%02d%02d", hour, minute); } strncpy (vapor_buf, &(buf[16]), 5); vapor_buf[5] = '\0'; strncpy (liquid_buf, &(buf[23]), 5); liquid_buf[5] = '\0'; vapor = atof (vapor_buf); liquid = atof (liquid_buf); if ((hour >= 24) || (hour < 0)) fprintf (stderr, "ERROR: record #: %d, hour = (%d) out of range\n", nrec+1, hour); if ((minute >= 60) || (minute < 0)) fprintf (stderr, "ERROR: record #: %d, minute = (%d) out of range\n", nrec+1, minute); if ((second >= 60) || (second < 0)) fprintf (stderr, "ERROR: record #: %d, second = (%d) out of range\n", nrec+1, second); min_vapor = fmin (min_vapor, vapor); max_vapor = fmax (max_vapor, vapor); min_liquid = fmin (min_liquid, liquid); max_liquid = fmax (max_liquid, liquid); nrec++; } sprintf (end_date, "%2d/%02d/%2d", month, day, year); sprintf (end_time, "%02d%02d", hour, minute); printf ("Total of %d records read in file %s\n", nrec, filename); printf ("Date/Time Range: From %s %s UTC TO %s %s UTC\n", beg_date, beg_time, end_date, end_time); printf ("(Min, Max) vapor = (%.2lf, %.3lf)\n", min_vapor, max_vapor); printf ("(Min, Max) liquid = (%.2lf, %.3lf)\n", min_liquid, max_liquid); fclose (fptr); } }