38 #define VGROUPNAME "Geophysical Data"
43 int main(
int argc,
char *argv[]) {
63 short startyear, startday;
64 short endyear, endday;
72 toms_txt_info_struc toms_info, toms_info2;
74 int32 sdfid, fid, gridid;
78 int16 *int16_SDSdataO3;
80 char *inst_name_frag[] = {
"N7TOMS",
"EPTOMS",
"AURAOMI"};
81 char *inst_data_src[] = {
"Nimbus 7 / Total Ozone Mapping Spectrometer",
82 "Earth Probe / Total Ozone Mapping Spectrometer",
83 "Aura / Ozone Monitoring Instrument"};
84 char *inst_platform[] = {
"Nimbus 7",
"Earth Probe",
"Aura"};
85 char gen_strs[24], *ocpath;
102 int rd_oz_grid(
char *, toms_txt_info_struc * );
110 strcpy(annotfile, argv[1]);
112 strcpy(directory, argv[2]);
113 strcpy(prevfile, argv[3]);
117 if ((ocpath = getenv(
"OCDATAROOT")) ==
NULL) {
118 printf(
"%s, %d E: Cannot get OCDATAROOT definition\n", __FILE__,
122 strcpy(annotfile, ocpath);
123 strcat(annotfile,
"/common/fillenv.o3_toms");
139 sprintf(outfile,
"%s/N%04d%03d%02d_O3_%s_24h.hdf",
140 directory, toms_info.year, toms_info.doy, hour,
141 inst_name_frag[ toms_info.toms_typ - 1 ]);
143 sprintf(
outfilename,
"N%04d%03d%02d_O3_%s_24h.hdf",
144 toms_info.year, toms_info.doy, hour,
145 inst_name_frag[ toms_info.toms_typ - 1 ]);
148 sprintf(end_time,
"%04d%03d235959999", toms_info.year, toms_info.doy);
150 endyear = toms_info.year;
151 endday = toms_info.doy;
152 endmsecday = 86399999;
155 sprintf(start_time,
"%04d%03d000000000", toms_info.year, toms_info.doy);
156 startyear = toms_info.year;
157 startday = toms_info.doy;
163 pexit(
"rd_oz_grid, #2");
167 if ((toms_info2.nlat != toms_info.nlat) || (toms_info2.nlon != toms_info.nlon)) {
168 printf(
"%s, %d I: The 2 input files selected have different grid sizes\n",
170 printf(
"1: %d X %d: %s\n", toms_info.nlon, toms_info.nlat,
infile);
171 printf(
"2: %d X %d: %s\n", toms_info2.nlon, toms_info2.nlat, prevfile);
172 printf(
" Using primary file only\n");
173 toms_info2 = toms_info;
185 pexit(
"no annotations found");
188 malloc(
sizeof (
struct annotation) * numannarr))
198 shape[0] = toms_info.nlat;
199 shape[1] = toms_info.nlon;
200 array_size = shape[0] * shape[1];
202 if ((int16_SDSdataO3 = (
int16 *) malloc(
sizeof (
int16) * array_size))
204 pexit(
"malloc int16_SDSdataO3");
206 if ((int8_SDSdataQC = (int8 *) malloc(
sizeof (int8) * array_size)) ==
NULL)
207 pexit(
"malloc int8_SDSdataQC");
208 for (
i = 0;
i < array_size;
i++) int8_SDSdataQC[
i] = 0;
214 o3 = toms_info.datarr;
215 o3_prev = toms_info2.datarr;
218 for (
j = 0;
j < shape[0];
j++) {
219 for (
k = 0;
k < shape[1];
k++) {
224 if (*(
o3 +
k + shape[1] *
j) == 0) {
225 if (*(o3_prev +
k + shape[1] *
j) != 0) {
226 *(
o3 +
k + shape[1] *
j) = *(o3_prev +
k + shape[1] *
j);
230 for (kk = 1; kk <= 50; kk++) {
231 if ((
k - kk >= 0) && (*(
o3 + (
k - kk) + shape[1] *
j) > 0)) {
232 *(
o3 +
k + shape[1] *
j) = *(
o3 + (
k - kk) + shape[1] *
j);
235 }
else if ((
k + kk < shape[1])
236 && (*(
o3 + (
k + kk) + shape[1] *
j) > 0)) {
237 *(
o3 +
k + shape[1] *
j) = *(
o3 + (
k + kk) + shape[1] *
j);
246 if (*(
o3 +
k + shape[1] *
j) > 0) {
247 int16_SDSdataO3[l] = *(
o3 +
k + shape[1] *
j);
249 int16_SDSdataO3[l] = 0;
250 int8_SDSdataQC[l] = 20;
259 if (shape[0] * shape[1] == bad_ct)
260 pexit(
"Final ozone array is all bad");
265 if (
fill_smooth(int16_SDSdataO3, (
char *) int8_SDSdataQC, shape[1], shape[0])
267 pexit(
"fill_smooth problem");
271 strcpy(gen_strs, toms_info.gen_str);
272 strcat(gen_strs,
",");
273 strcat(gen_strs, toms_info2.gen_str);
279 for (
i = 0;
i < numannarr;
i++) {
281 if (!strcmp(xannot[
i].
label,
"Product Name"))
284 else if (!strcmp(xannot[
i].
label,
"Processing Time")) {
288 localtm = localtime(&
t);
289 pyear = localtm->tm_year;
290 if (pyear < 90) pyear = pyear + 2000;
291 else pyear = pyear + 1900;
293 sprintf(xannot[
i].
descr,
"%04d%03d%02d%02d%02d%03d",
294 pyear, localtm->tm_yday + 1, localtm->tm_hour, localtm->tm_min,
297 else if (!strcmp(xannot[
i].
label,
"Input Files"))
300 else if (!strcmp(xannot[
i].
label,
"Processing Control"))
301 sprintf(xannot[
i].
descr,
"%s %s %s %s %s",
302 argv[0], annotfile,
infile, directory, prevfile);
304 else if (!strcmp(xannot[
i].
label,
"Start Time"))
305 sprintf(xannot[
i].
descr,
"%s", start_time);
307 else if (!strcmp(xannot[
i].
label,
"End Time"))
308 sprintf(xannot[
i].
descr,
"%s", end_time);
310 else if (!strcmp(xannot[
i].
label,
"Start Year"))
311 sprintf(xannot[
i].
descr,
"%04d", startyear);
313 else if (!strcmp(xannot[
i].
label,
"Start Day"))
314 sprintf(xannot[
i].
descr,
"%03d", startday);
316 else if (!strcmp(xannot[
i].
label,
"Start Millisec"))
317 sprintf(xannot[
i].
descr,
"%08d", startmsecday);
319 else if (!strcmp(xannot[
i].
label,
"End Year"))
320 sprintf(xannot[
i].
descr,
"%04d", endyear);
322 else if (!strcmp(xannot[
i].
label,
"End Day"))
323 sprintf(xannot[
i].
descr,
"%03d", endday);
325 else if (!strcmp(xannot[
i].
label,
"End Millisec"))
326 sprintf(xannot[
i].
descr,
"%08d", endmsecday);
328 else if (!strcmp(xannot[
i].
label,
"Node Crossing Time"))
329 sprintf(xannot[
i].
descr,
"%s", toms_info.node_time);
331 else if (!strcmp(xannot[
i].
label,
"Points Modified"))
332 sprintf(xannot[
i].
descr,
"%08d", modified_pts);
334 else if (!strcmp(xannot[
i].
label,
"Data Source"))
335 sprintf(xannot[
i].
descr,
"%s",
336 inst_name_frag[ toms_info.toms_typ - 1 ]);
338 else if (!strcmp(xannot[
i].
label,
"Data Source Desc"))
339 sprintf(xannot[
i].
descr,
"%s",
340 inst_data_src[ toms_info.toms_typ - 1 ]);
342 else if (!strcmp(xannot[
i].
label,
"Satellite Platform"))
343 sprintf(xannot[
i].
descr,
"%s",
344 inst_platform[ toms_info.toms_typ - 1 ]);
346 else if (!strcmp(xannot[
i].
label,
"Latitude Step"))
347 sprintf(xannot[
i].
descr,
"%5.3f", toms_info.del_lat);
349 else if (!strcmp(xannot[
i].
label,
"Longitude Step"))
350 sprintf(xannot[
i].
descr,
"%5.3f", toms_info.del_lon);
352 else if (!strcmp(xannot[
i].
label,
"SW Point Latitude"))
353 sprintf(xannot[
i].
descr,
"%8.3f", toms_info.slat);
355 else if (!strcmp(xannot[
i].
label,
"SW Point Longitude"))
356 sprintf(xannot[
i].
descr,
"%8.3f", toms_info.slon);
358 else if (!strcmp(xannot[
i].
label,
"Number of Rows"))
359 sprintf(xannot[
i].
descr,
"%08d", toms_info.nlat);
361 else if (!strcmp(xannot[
i].
label,
"Number of Columns"))
362 sprintf(xannot[
i].
descr,
"%08d", toms_info.nlon);
364 else if (!strcmp(xannot[
i].
label,
"Raw Data Generation Date"))
365 sprintf(xannot[
i].
descr,
"%s", gen_strs);
373 if ((
result =
startHDF(outfile, &sdfid, &fid, DFACC_CREATE)) != 0)
374 pexit(
"Fatal error starting HDF file");
389 strcpy(dataunit,
"Total ozone");
390 strcpy(dataattr,
"Dobson units");
396 if ((
SDSinFile(datalabel, dataunit, dataattr, datafmt,
397 datatype, sdfid,
rank, shape, int16_SDSdataO3, gridid)) != 0)
398 pexit(
"SDSinFile ozone wrtsds");
400 free(int16_SDSdataO3);
406 datalabel =
"ozone_QC";
407 strcpy(dataunit,
"Total ozone Q/C flag");
410 datatype = DFNT_INT8;
412 if ((
SDSinFile(datalabel, dataunit, dataattr, datafmt,
413 datatype, sdfid,
rank, shape, int8_SDSdataQC, gridid)) != 0)
414 pexit(
"SDSinFile ozone QC wrtsds");
416 free(int8_SDSdataQC);
432 printf(
"%s+%s+%s\n", outfile, start_time, end_time);
455 h5io_str fid, grp_id;
456 int ret = 1, stat, iloc, oloc;
458 float *tmp_flt, fval;
460 "HDFEOS/GRIDS/OMI Column Amount O3/Data Fields/ColumnAmountO3";
461 char attr_path[] =
"HDFEOS/ADDITIONAL/FILE_ATTRIBUTES";
467 printf(
"%s, %d: Open error on file: %s\n", __FILE__, __LINE__,
infile );
476 if( ( tmp_flt = (
float *) malloc( 180 * 360 *
sizeof(
float) ) ) ==
NULL )
478 printf(
"%s, %d: Unable to malloc the oz storage space\n",
479 __FILE__, __LINE__ );
482 if( ( stat =
h5io_grab_ds( &fid, dat_grp, (
float *)tmp_flt ) ) != 0 ) {
483 printf(
"%s, %d: read error on file: %s\n", __FILE__, __LINE__,
infile );
492 printf(
"%s, %d: Unable to allocate the storage for the ozone data\n",
493 __FILE__, __LINE__ );
496 for( iloc = 0; iloc <
npix *
nlin; iloc++ )
500 fval = *( tmp_flt + iloc );
501 *( toms_info->datarr + oloc ) = ( ( fval < 50. ) || ( fval > 700. ) )
502 ? 0 : (
int16) ( fval + 0.5 );
509 if( ( stat =
h5io_set_grp( &fid, attr_path, &grp_id ) ) != 0 ) {
510 printf(
"%s, %d: path could not be set on file: %s\n", __FILE__,
517 printf(
"%s, %d: unable to read attr GranuleYear on file: %s\n", __FILE__,
523 printf(
"%s, %d: unable to read attr GranuleDayOfYear on file: %s\n", __FILE__,
531 toms_info->year =
year;
532 toms_info->doy =
doy;
533 sprintf( toms_info->node_time,
"%04d%03d000000000",
year,
doy );
534 toms_info->nlon =
npix;
535 toms_info->slon = -179.5;
536 toms_info->elon = 179.5;
537 toms_info->del_lon = 1.;
538 toms_info->nlat =
nlin;
539 toms_info->slat = -89.5;
540 toms_info->elat = 89.5;
541 toms_info->del_lat = 1.;
542 strcpy( toms_info->gen_str,
"None" );
556 pexit(
"rd_toms_ascii");
595 printf(
"\n\nUsage:\n");
596 printf(
"\t%s <file> <directory> <prevfile>\n", argv[0]);
597 printf(
"\nWhere:\n");
598 printf(
"\tfile: file to process\n");
599 printf(
"\tdirectory: output directory (no ending slash)\n");
600 printf(
"\tprevfile: previous day \n");
602 printf(
"\tExample:\n");
603 printf(
"\t\t o3_toms $SDSDEMO/fillenv.eptomsnrt $SDSDEMO/ga960903.ept\n");
604 printf(
"\t\t ./ $SDSDEMO/ga960902.ept\n\n");