73 char *FUNC =
"openHDF";
75 if ((lsdfid = SDstart(
infile, DFACC_RDONLY)) < 0) {
76 sprintf(
ERR_MSG,
"%s: Cannot open file -- SDstart failed on %s",
81 if ((lfid = Hopen(
infile, 0, DFACC_RDONLY)) < 0) {
82 sprintf(
ERR_MSG,
"%s: Cannot open file -- Hopen failed on %s",
121 int32_t
rdancattr(int32_t sdfid,
char *attr_name,
void *buf) {
122 int32 attrnum, nt,
count;
124 char *FUNC =
"rdancattr";
126 if ((attrnum = SDfindattr(sdfid, attr_name)) < 0) {
127 sprintf(
ERR_MSG,
"%s: SDfindattr failed for %s", FUNC, attr_name);
131 if ((SDattrinfo(sdfid, attrnum,
name, &nt, &
count)) < 0) {
132 sprintf(
ERR_MSG,
"%s: SDattrinfo failed for %s", FUNC, attr_name);
136 if ((SDreadattr(sdfid, attrnum, buf)) < 0) {
137 sprintf(
ERR_MSG,
"%s: SDreadattr failed for %s", FUNC, attr_name);
171 int rdlatlon(int32_t sdfid, int32_t *dims,
float *lat_buf,
float *lon_buf) {
173 float32 vsize, hsize, sw_lat, sw_lon;
191 lat_buf[dims[0] - 1] = sw_lat;
192 for (
i = dims[0] - 2;
i >= 0;
i--)
193 lat_buf[
i] = (lat_buf[
i + 1] + vsize);
195 for (lon_buf[0] = sw_lon,
i = 1;
i < dims[1];
i++)
196 lon_buf[
i] = (lon_buf[
i - 1] + hsize);
224 if ((
result = Vend(fid)) < 0) perror(
"closing V file");
225 if ((
result = SDend(sdfid)) < 0) perror(
"closing SDS");
226 if ((
result = Hclose(fid)) < 0) perror(
"closing H file");
265 int16_t month, int32_t *dims,
float *lat_buf,
266 float *lon_buf,
void *parm_buf) {
268 int32 vref, vid,
index, sdsid, nrefs;
270 int32
rank, nattrs, numbertype;
273 if ((vref = Vfind(fid, clim_vgps[month - 1])) <= 0) {
274 sprintf(
ERR_MSG,
"%s: Vfind failed to find vgroup %s",
275 FUNC, clim_vgps[month - 1]);
279 if ((vid = Vattach(fid, vref,
"r")) < 0) {
280 sprintf(
ERR_MSG,
"%s: Vattach failed for vgroup %s",
281 FUNC, clim_vgps[month - 1]);
285 if ((Vgettagrefs(vid, taglist, reflist,
MAXVAL)) < 0) {
286 sprintf(
ERR_MSG,
"%s: Vgettagrefs failed for vgroup %s",
287 FUNC, clim_vgps[month - 1]);
291 if ((nrefs = Vntagrefs(vid)) < 0)
295 for (
i = 0;
i < nrefs && !done;
i++) {
296 if (taglist[
i] == DFTAG_NDG) {
297 if ((
index = SDreftoindex(sdfid, reflist[
i])) < 0)
299 if ((sdsid = SDselect(sdfid,
index)) < 0)
301 if ((SDgetinfo(sdsid,
name, &
rank, dims, &numbertype, &nattrs)) < 0)
303 if (strcmp(
name, clim_datasets[parm_flag]) == 0)
310 "%s: requested dataset %s not found", FUNC, clim_datasets[parm_flag]);
314 if ((
rdlatlon(sdfid, dims, lat_buf, lon_buf)) < 0)
317 if ((SDreaddata(sdsid,
start,
NULL, dims, parm_buf)) < 0)
360 int get_NRT_data(int32_t fid, int32_t sdfid,
char *anc_cor_file, int16_t parm_flag,
361 int32_t *dims,
float *lat_buf,
float *lon_buf,
362 void *parm_buf, int8_t *qc_buf) {
364 int32 sdsid,
index, numbertype;
365 int32
rank,
start[3] = {0, 0, 0}, nattrs;
366 char name[132], *FUNC =
"get_NRT_data", dsrc[100];
372 if ((
index = SDnametoindex(sdfid, data_sdsnames[parm_flag])) < 0) {
373 sprintf(
ERR_MSG,
"%s: SDnametoindex failed for %s",
374 FUNC, data_sdsnames[parm_flag]);
378 if ((sdsid = SDselect(sdfid,
index)) < 0) {
379 sprintf(
ERR_MSG,
"%s: SDselect failed for %s",
380 FUNC, data_sdsnames[parm_flag]);
384 if ((SDgetinfo(sdsid,
name, &
rank, dims, &numbertype, &nattrs)) < 0)
387 if ((SDreaddata(sdsid,
start,
NULL, dims, (VOIDP) parm_buf)) < 0) {
388 sprintf(
ERR_MSG,
"%s: SDreaddata faild for sds - %s", FUNC,
name);
396 if ((
index = SDnametoindex(sdfid, QC_sdsnames[parm_flag])) < 0) {
397 sprintf(
ERR_MSG,
"%s: SDnametoindex failed for %s ",
398 FUNC, QC_sdsnames[parm_flag]);
402 if ((sdsid = SDselect(sdfid,
index)) < 0)
405 if ((SDgetinfo(sdsid,
name, &
rank, dims, &numbertype, &nattrs)) < 0)
408 if ((SDreaddata(sdsid,
start,
NULL, dims, (VOIDP) qc_buf)) < 0)
413 if ((
rdlatlon(sdfid, dims, lat_buf, lon_buf)) < 0)
419 if (parm_flag == 4) {
420 if (
rdancattr(sdfid,
"Data Source", (
void *) dsrc) != DFNT_CHAR) {
421 printf(
"%s, %d E: Could not read 'Data Source' from ozone file\n",
426 if (strcmp(dsrc,
"N7TOMS") == 0)
428 else if (strcmp(dsrc,
"EPTOMS") == 0)
430 else if (strcmp(dsrc,
"AURAOMI") == 0)
445 if (strcmp(anc_cor_file,
"") != 0) {
452 "%s, %d E: Could not read 'Start Year' or 'Start Day' from ozone file\n",
456 if (
corr_oz(anc_cor_file, parm_buf, (
char*) qc_buf, dims, st_yr,
457 st_day, oz_typ) != 0)
492 int corr_oz(
char *oz_corr_file,
int16 *oz_dat,
char *qc_dat, int32 *dims,
494 int ncid, gid,
status, var_id;
495 char *oz_inst_grp[] = {
"N7TOMS",
"EPTOMS",
"AURAOMI",
"Extrap_AURAOMI"};
496 int16 corr_time_st[4], corr_time_en[4], mon,
day;
497 int32_t yrs[2], mons[2], npix_oz, nlin_oz, ilin, ipix, ixmon, tot_mon;
499 float t_wt1, t_wt2, l_wt1, l_wt2, corr_arr[2 * 36],
lat, slat, del_lat;
505 if (nc_open(oz_corr_file, 0, &ncid) != NC_NOERR) {
506 printf(
"%s, %d E: Unable to open ozone correction file: %s\n",
507 __FILE__, __LINE__, oz_corr_file);
513 if (nc_inq_grp_ncid(ncid, oz_inst_grp[oz_typ], &gid) != NC_NOERR) {
514 printf(
"%s, %d E: Unable to set group: %s for ozone correction file: %s\n",
515 __FILE__, __LINE__, oz_inst_grp[oz_typ], oz_corr_file);
518 printf(
"%s, %d I: Correcting ozone using file:\n", __FILE__, __LINE__);
519 printf(
" %s\n", oz_corr_file);
520 printf(
" ozone inst: %s\n", oz_inst_grp[oz_typ]);
524 if ((
status = nc_inq_varid(gid,
"start_time", &var_id)) != NC_NOERR) {
525 printf(
"%s, %d E: Unable to read 'start_time' from correction file: %s\n",
526 __FILE__, __LINE__, oz_corr_file);
529 if ((
status = nc_get_var_short(gid, var_id, corr_time_st)) != NC_NOERR) {
530 printf(
"%s, %d E: Unable to read 'start_time' from correction file: %s\n",
531 __FILE__, __LINE__, oz_corr_file);
535 if ((
status = nc_inq_varid(gid,
"end_time", &var_id)) != NC_NOERR) {
536 printf(
"%s, %d E: Unable to read 'end_time' from correction file: %s\n",
537 __FILE__, __LINE__, oz_corr_file);
540 if ((
status = nc_get_var_short(gid, var_id, corr_time_en)) != NC_NOERR) {
541 printf(
"%s, %d E: Unable to read 'end_time' from correction file: %s\n",
542 __FILE__, __LINE__, oz_corr_file);
559 t_wt1 = (15 -
day) / 30.;
560 t_wt2 = (15 +
day) / 30.;
571 t_wt1 = (45 -
day) / 30.;
572 t_wt2 = (
day - 15) / 30.;
578 ixmon = (yrs[0] - corr_time_st[0]) * 12 +
579 (mons[0] - corr_time_st[1]);
580 tot_mon = (corr_time_en[0] - corr_time_st[0]) * 12 +
581 (corr_time_en[1] - corr_time_st[1] + 1);
590 }
else if (ixmon >= (tot_mon - 1)) {
600 if (nc_inq_grp_ncid(ncid, oz_inst_grp[oz_typ], &gid) != NC_NOERR) {
602 "%s, %d E: Unable to set group: %s for ozone correction file: %s\n",
603 __FILE__, __LINE__, oz_inst_grp[oz_typ], oz_corr_file);
606 printf(
"%s, %d I: Extrapolated ozone correction used, name: %s\n",
607 __FILE__, __LINE__, oz_inst_grp[oz_typ]);
618 if ((
status = nc_inq_varid(gid,
"correction_array", &var_id))
620 printf(
"%s, %d E: Unable to read 'correction_array' from correction file: %s\n",
621 __FILE__, __LINE__, oz_corr_file);
632 printf(
"%s, %d E: Unable to read 'correction_array' from correction file: %s\n",
633 __FILE__, __LINE__, oz_corr_file);
653 del_lat = -180. / nlin_oz;
654 slat = 90. + del_lat / 2.;
660 for (ilin = 0; ilin < nlin_oz; ilin++) {
661 lat = slat + ilin * del_lat;
663 ixlat = (
int) (
pos + 1) - 1;
668 }
else if (ixlat > 34) {
679 corr_fac = t_wt1 * (l_wt1 * *(corr_arr + 2 * ixlat) +
680 l_wt2 * *(corr_arr + 2 * (ixlat + 1))) +
681 t_wt2 * (l_wt1 * *(corr_arr + 1 + 2 * ixlat) +
682 l_wt2 * *(corr_arr + 1 + 2 * (ixlat + 1)));
687 for (ipix = 0; ipix < npix_oz; ipix++) {
688 if (*(qc_dat + ipix + npix_oz * ilin) != 20)
689 *(oz_dat + ipix + npix_oz * ilin) += (corr_fac + 0.5);
726 int get_refs(int32_t fid, int32_t sdfid, int32_t vid,
char *parm_label,
727 char *QC_label, int32_t *geom_id, int32_t *parm_sdsid, int32_t *QC_sdsid,
731 int32
index, sdsid,
rank, numbertype, nattrs, numSDSs;
735 if ((vg = Vattach(fid, vid,
"r")) < 0)
738 Vgettagrefs(vg, tagarray, refarray, natts);
739 nrefs = Vntagrefs(vg);
740 for (
i = 0,
j = 0;
i < nrefs;
i++) {
741 if (tagarray[
i] == DFTAG_NDG || tagarray[
i] == DFTAG_SD) {
742 sdrefs[
j++] = refarray[
i];
744 if (tagarray[
i] == DFTAG_VH || tagarray[
i] == DFTAG_VS)
745 *geom_id = refarray[
i];
750 for (
i = 0; i < numSDSs && ret >= 0;
i++) {
751 index = SDreftoindex(sdfid, sdrefs[
i]);
752 sdsid = SDselect(sdfid,
index);
753 if ((SDgetinfo(sdsid,
name, &
rank, dims, &numbertype, &nattrs)) < 0)
755 if (strcmp(
name, parm_label) == 0) {
758 if (strcmp(
name, QC_label) == 0)