103 #define VGROUPNAME "Geophysical Data"
105 #define REGISTRATION CENTER
106 #define EARLIERVAL 10
107 #define NEARESTVAL 11
110 int main(
int argc,
char *argv[]) {
132 int modified_pts = 0;
136 short startyear, startday, starthour,
139 short endyear, endday, endhour,
145 float latstep, lonstep;
146 float nmostlat, smostlat, wmostlon, emostlon;
149 int16 prevdatarr[180][360];
159 int32 sdfid, fid, gridid;
166 int8 *int8_SDSdataQC;
167 int16 *int16_SDSdataO3;
190 strcpy(annotfile, argv[1]);
192 strcpy(directory, argv[3]);
199 if (!strcmp(
upcase(itype),
"OMITOMS")) {
201 if (argc == 6)
strcpy(prevfile, argv[5]);
202 else strcpy(prevfile,
"");
204 pexit(
"ERROR: OMITOMS not specified");
212 acntime, &
result, 255, 17, 17, 9);
228 sprintf(outfile,
"%s/S%04d%03d%02d_%s.OZONE", directory,
year,
229 julval, hour,
"TOMS");
235 sprintf(start_time,
"%04d%03d%02d0000000",
year, julval, hour);
236 sprintf(end_time,
"%04d%03d%02d0000000",
year, julval, hour);
242 startmsecday = endmsecday = 0;
243 }
else if (
type == 1) {
245 strcpy(&start_time[16],
"\0");
246 strcpy(&end_time[16],
"\0");
248 strncpy(tmpvar, &start_time[0], 4);
250 startyear = (short) atoi(tmpvar);
252 strncpy(tmpvar, &start_time[4], 3);
254 startday = (short) atoi(tmpvar);
256 strncpy(tmpvar, &start_time[7], 2);
258 starthour = (short) atoi(tmpvar);
260 strncpy(tmpvar, &start_time[9], 2);
262 startmin = (short) atoi(tmpvar);
264 strncpy(tmpvar, &start_time[11], 2);
266 startsec = (short) atoi(tmpvar);
268 strncpy(tmpvar, &start_time[13], 3);
270 startmsec = atoi(tmpvar);
274 strncpy(tmpvar, &end_time[0], 4);
276 endyear = (short) atoi(tmpvar);
278 strncpy(tmpvar, &end_time[4], 3);
280 endday = (short) atoi(tmpvar);
282 strncpy(tmpvar, &end_time[7], 2);
284 endhour = (short) atoi(tmpvar);
286 strncpy(tmpvar, &end_time[9], 2);
288 endmin = (short) atoi(tmpvar);
290 strncpy(tmpvar, &end_time[11], 2);
292 endsec = (short) atoi(tmpvar);
294 strncpy(tmpvar, &end_time[13], 3);
296 endmsec = atoi(tmpvar);
301 printf(
"startyear: %04d\n", startyear);
302 printf(
"startday: %03d\n", startday);
303 printf(
"starthour: %02d\n", starthour);
305 printf(
"endyear: %04d\n", endyear);
306 printf(
"endday: %03d\n", endday);
307 printf(
"endhour: %02d\n", endhour);
309 printf(
"%s/S%04d%03d%02d%03d%02d_%s.OZONE\n", directory,
310 startyear, startday, starthour, endday, endhour,
"TOVS");
313 sprintf(outfile,
"%s/S%04d%03d%02d%03d%02d_%s.OZONE", directory,
314 startyear, startday, starthour, endday, endhour,
"TOVS");
315 sprintf(
outfilename,
"S%04d%03d%02d%03d%02d_%s.OZONE",
316 startyear, startday, starthour, endday, endhour,
"TOVS");
319 (starthour * 60 * 60 * 1000) +
320 (startmin * 60 * 1000) +
325 (endhour * 60 * 60 * 1000) +
326 (endmin * 60 * 1000) +
329 }
else if (
type == 2) {
332 sprintf(outfile,
"%s/N%04d%03d%02d_O3_TOMSOMI_24h.hdf",
333 directory,
year, julval, hour);
335 sprintf(
outfilename,
"N%04d%03d%02d_O3_TOMSOMI_24h.hdf",
339 sprintf(end_time,
"%04d%03d235959999",
year, julval);
343 endmsecday = 86399999;
346 sprintf(start_time,
"%04d%03d000000000",
year, julval);
353 strcpy(&acntime[8],
"\0");
355 strncpy(tmpvar, &acntime[0], 2);
357 hour = (short) atoi(tmpvar);
359 strncpy(tmpvar, &acntime[6], 2);
360 if (!strcmp(tmpvar,
"pm")) hour += 12;
362 strncpy(tmpvar, &acntime[3], 2);
364 min = (short) atoi(tmpvar);
366 sprintf(node_time,
"%04d%03d%02d%02d00000",
372 start_time, end_time, acntime, &
result, 255, 17, 17, 9);
375 if (
type != 2)
pexit(
"2nd EPTOMS file not of EPTOMS type. Exit.");
377 }
else if (
type == 3) {
380 sprintf(outfile,
"%s/S%04d%03d%02d_%s.OZONE",
381 directory,
year, julval, hour,
"ADTOMS");
384 year, julval, hour,
"ADTOMS");
386 sprintf(end_time,
"%04d%03d235959999",
year, julval);
390 endmsecday = 86399999;
394 strcpy(&acntime[8],
"\0");
396 strncpy(tmpvar, &acntime[0], 2);
398 hour = (short) atoi(tmpvar);
400 strncpy(tmpvar, &acntime[6], 2);
406 if (!strcmp(tmpvar,
"AM")) hour += 12;
408 strncpy(tmpvar, &acntime[3], 2);
410 min = (short) atoi(tmpvar);
412 sprintf(node_time,
"%04d%03d%02d%02d00000",
415 sprintf(start_time,
"%04d%03d000000000",
year, julval);
419 }
else pexit(
"ERROR: Neither TOMS, TOVS, EPTOMS or ADTOMS specified");
421 if (!access(outfile, F_OK))
422 pexit(
"....output file exists. Won't overwrite.");
429 pexit(
"no annotations found");
432 malloc(
sizeof (
struct annotation) * numannarr))
441 for (
i = 0;
i < numannarr;
i++) {
443 if (!strcmp(xannot[
i].
label,
"Northernmost Latitude"))
444 sscanf(xannot[
i].
descr,
"%f", &nmostlat);
446 else if (!strcmp(xannot[
i].
label,
"Southernmost Latitude"))
447 sscanf(xannot[
i].
descr,
"%f", &smostlat);
449 else if (!strcmp(xannot[
i].
label,
"Westernmost Longitude"))
450 sscanf(xannot[
i].
descr,
"%f", &wmostlon);
452 else if (!strcmp(xannot[
i].
label,
"Easternmost Longitude"))
453 sscanf(xannot[
i].
descr,
"%f", &emostlon);
455 else if (!strcmp(xannot[
i].
label,
"Latitude Step"))
456 sscanf(xannot[
i].
descr,
"%f", &latstep);
458 else if (!strcmp(xannot[
i].
label,
"Longitude Step"))
459 sscanf(xannot[
i].
descr,
"%f", &lonstep);
461 else if (!strcmp(xannot[
i].
label,
"Number of Rows"))
462 sscanf(xannot[
i].
descr,
"%d", &latsz);
464 else if (!strcmp(xannot[
i].
label,
"Number of Columns"))
465 sscanf(xannot[
i].
descr,
"%d", &lonsz);
473 nmostlat = nmostlat - (latstep / 0.5);
474 smostlat = smostlat + (latstep / 0.5);
475 wmostlon = wmostlon + (lonstep / 0.5);
476 emostlon = emostlon - (lonstep / 0.5);
482 if ((
result =
startHDF(outfile, &sdfid, &fid, DFACC_CREATE)) != 0)
483 pexit(
"Fatal error starting HDF file");
492 array_size = shape[0] * shape[1];
494 if ((int16_SDSdataO3 =
497 pexit(
"malloc int16_SDSdataO3");
500 pexit(
"calloc int16_SDSdataO3");
503 if ((int8_SDSdataQC =
505 (int8 *) malloc(
sizeof (int8) * array_size)) ==
NULL)
506 pexit(
"malloc int8_SDSdataQC");
508 (int8 *) calloc(
sizeof (int8), array_size)) ==
NULL)
509 pexit(
"calloc int8_SDSdataQC");
511 for (
i = 0;
i < array_size;
i++) int8_SDSdataQC[
i] = 0;
518 for (
j = 0;
j < shape[0];
j++) {
519 for (
k = 0;
k < shape[1];
k++) {
524 if ((
type == 2) && (datarr[
j][
k] == 0)) {
525 if (prevdatarr[
j][
k] != 0) {
526 datarr[
j][
k] = prevdatarr[
j][
k];
532 for (kk = 1; kk <= 50; kk++) {
533 if ((
k - kk >= 0) && (datarr[
j][
k - kk] > 0)) {
534 datarr[
j][
k] = datarr[
j][
k - kk];
537 }
else if ((
k + kk < shape[1]) && (datarr[
j][
k + kk] > 0)) {
538 datarr[
j][
k] = datarr[
j][
k + kk];
547 if (datarr[
j][
k] > 0) {
548 int16_SDSdataO3[l] = (
int16) datarr[
j][
k];
549 }
else int16_SDSdataO3[l] = 0;
565 for (
i = 0;
i < numannarr;
i++) {
567 if (!strcmp(xannot[
i].
label,
"Product Name"))
570 else if (!strcmp(xannot[
i].
label,
"Processing Time")) {
574 localtm = localtime(&
t);
575 pyear = localtm->tm_year;
576 if (pyear < 90) pyear = pyear + 2000;
577 else pyear = pyear + 1900;
579 sprintf(xannot[
i].
descr,
"%04d%03d%02d%02d%02d%03d",
580 pyear, localtm->tm_yday + 1, localtm->tm_hour, localtm->tm_min,
583 else if (!strcmp(xannot[
i].
label,
"Input Files")) {
589 else if (!strcmp(xannot[
i].
label,
"Processing Control"))
591 sprintf(xannot[
i].
descr,
"%s %s %s %s %s %s",
592 argv[0], annotfile,
infile, directory, itype, prevfile);
594 sprintf(xannot[
i].
descr,
"%s %s %s %s %s",
595 argv[0], annotfile,
infile, directory, itype);
597 else if (!strcmp(xannot[
i].
label,
"Start Time"))
598 sprintf(xannot[
i].
descr,
"%s", start_time);
600 else if (!strcmp(xannot[
i].
label,
"End Time"))
601 sprintf(xannot[
i].
descr,
"%s", end_time);
603 else if (!strcmp(xannot[
i].
label,
"Start Year"))
604 sprintf(xannot[
i].
descr,
"%04d", startyear);
606 else if (!strcmp(xannot[
i].
label,
"Start Day"))
607 sprintf(xannot[
i].
descr,
"%03d", startday);
609 else if (!strcmp(xannot[
i].
label,
"Start Millisec"))
610 sprintf(xannot[
i].
descr,
"%08d", startmsecday);
612 else if (!strcmp(xannot[
i].
label,
"End Year"))
613 sprintf(xannot[
i].
descr,
"%04d", endyear);
615 else if (!strcmp(xannot[
i].
label,
"End Day"))
616 sprintf(xannot[
i].
descr,
"%03d", endday);
618 else if (!strcmp(xannot[
i].
label,
"End Millisec"))
619 sprintf(xannot[
i].
descr,
"%08d", endmsecday);
621 else if (!strcmp(xannot[
i].
label,
"Node Crossing Time"))
622 sprintf(xannot[
i].
descr,
"%s", node_time);
624 else if (!strcmp(xannot[
i].
label,
"Points Modified"))
625 sprintf(xannot[
i].
descr,
"%08d", modified_pts);
643 strcpy(dataunit,
"Total ozone");
644 strcpy(dataattr,
"Dobson units");
650 if ((
SDSinFile(datalabel, dataunit, dataattr, datafmt,
651 datatype, sdfid,
rank, shape, int16_SDSdataO3, gridid)) != 0)
652 pexit(
"SDSinFile ozone wrtsds");
654 free(int16_SDSdataO3);
660 datalabel =
"ozone_QC";
661 strcpy(dataunit,
"Total ozone Q/C flag");
664 datatype = DFNT_INT8;
666 if ((
SDSinFile(datalabel, dataunit, dataattr, datafmt,
667 datatype, sdfid,
rank, shape, int8_SDSdataQC, gridid)) != 0)
668 pexit(
"SDSinFile ozone QC wrtsds");
670 free(int8_SDSdataQC);
686 printf(
"%s+%s+%s\n", outfile, start_time, end_time);
724 printf(
"\n\nUsage:\n");
725 printf(
"\t%s <metafile> <file> <directory> <itype> [<prevfile>]\n", argv[0]);
726 printf(
"\nWhere:\n");
727 printf(
"\tmetafile: HDF metadata file (in ASCII)\n");
728 printf(
"\tfile: file to process\n");
729 printf(
"\tdirectory: output directory (no ending slash)\n");
730 printf(
"\titype: input data type 'TOMS', 'TOVS', 'EPTOMS' or 'ADTOMS'\n");
731 printf(
"\tprevfile: [optional] previous day if type 'EPTOMS'\n");
733 printf(
"\tExample:\n");
734 printf(
"\t\t o3nrt $SDSDEMO/fillenv.eptomsnrt $SDSDEMO/ga960903.ept\n");
735 printf(
"\t\t ./ 'EPTOMS' $SDSDEMO/ga960902.ept\n\n");