Skip to content. | Skip to navigation

Personal tools

airs_cc_rad_rdr.c

#include <stdio.h>
#include <stdlib.h>
#include "hdf.h" /* defines int32, intn, etc. */
#include "HdfEosDef.h" /* declares SWopen(), etc. */
#include "airs_cc_rad_typ.h"
#include "airs_cc_rad_struct.h"


/*
* This function is autogenerated by the mkezio program to read
* an AIRS swath of type "L2_Standard_cloud-cleared_radiance_product" from file given by the
* file_name argument into a buffer pointed to by the airs_cc_rad_gran
* argument. The caller owns the buffer. The entire granule
* is read -- every attribute and field, the whole lat/lon/time
* extent.
*
* Errors opening the file, etc. are fatal and cause exit(EXIT_FAILURE).
* Problems reading individual attributes or fields are reported to
* the console but do not interrupt program flow.
*/
void airs_cc_rad_rdr(
char * file_name, /* name of file to read */
airs_cc_rad_gran_t * airs_cc_rad_gran ) /* structured buffer to hold entire granule */
{
intn statn; /* HDF-EOS status. 0 for success */
int32 fid; /* HDF-EOS file ID */
int32 swid; /* HDF-EOS swath ID */
int32 nchar; /* Number of characters */
char swathname[256]; /* Name of swath */
int nswath; /* Number of swaths */
char * cp = 0; /* pointer to start of version # in file name */
int major = 0, minor = 0, patch = 0, subpatch = 0;
/* parts of version number */

/* Figure out version from file name */

/* skip past directories if full path is present */
cp = strrchr(file_name, '/');
if (!cp) cp = file_name;

/*
* File will look more or less like:
* AIRS.2002.09.06.125.L1B.AIRS_Rad.v4.0.6.0.PGE_Verify.T04352025159.hdf
*/
cp = strstr(cp, ".v");

if (cp) {
int nscanned = sscanf(cp, ".v%d.%d.%d.%d",
&major, &minor, &patch, &subpatch);
if (nscanned != 4)
printf("Failed to get version from file name %s starting at %s\n",
file_name, cp);
} else {
printf("Failed to get version from file name %s\n", file_name);
printf("so version number cannot be checked.\n\n");
}

/* if we did get a version number, check it */
if (major + minor + patch + subpatch) {
if (major != 5 || minor != 0 || patch != 14 || subpatch != 0) {
printf("Warning: airs_cc_rad file read is version %d.%d.%d.%d ",
major, minor, patch, subpatch);
printf("but reader is designed for 5.0.14.0\n");
}
}

/* Clear granule structure */
memset(airs_cc_rad_gran, 0, sizeof(airs_cc_rad_gran));

fid = SWopen(file_name, DFACC_READ);
if (fid <= 0) {
printf("Error %ld opening file %s\n", (long)fid, file_name);
exit(EXIT_FAILURE);
}

/* Get name of swath(s) */
nswath = SWinqswath(file_name, swathname, &nchar);
if (nswath != 1) {
printf("SWinqswath found %d swaths for file \"%s\". Need exactly 1\n", nswath, file_name);
exit(EXIT_FAILURE);
}

/* There's exactly one swath. Make sure it is the right one. */
if (strcmp(swathname, "L2_Standard_cloud-cleared_radiance_product")) {
printf("Error: bad swath name \"%s\" in file \"%s\"\n", swathname, file_name);
printf("Expected \"L2_Standard_cloud-cleared_radiance_product\"\n");
exit(EXIT_FAILURE);
}

/* Attach to (open) the one swath. */
swid = SWattach(fid, swathname);
if (swid <= 0) {
printf("Failed to attach to swath \"%s\" in file %s\n", swathname, file_name);
exit(EXIT_FAILURE);
}

/* Attributes */
statn = SWreadattr(swid, "processing_level",
(void *)airs_cc_rad_gran->processing_level);
if (statn != 0)
printf("Error %d reading attribute processing_level\n", statn);

statn = SWreadattr(swid, "instrument",
(void *)airs_cc_rad_gran->instrument);
if (statn != 0)
printf("Error %d reading attribute instrument\n", statn);

statn = SWreadattr(swid, "DayNightFlag",
(void *)airs_cc_rad_gran->DayNightFlag);
if (statn != 0)
printf("Error %d reading attribute DayNightFlag\n", statn);

statn = SWreadattr(swid, "AutomaticQAFlag",
(void *)airs_cc_rad_gran->AutomaticQAFlag);
if (statn != 0)
printf("Error %d reading attribute AutomaticQAFlag\n", statn);

statn = SWreadattr(swid, "NumTotalData",
(void *)&airs_cc_rad_gran->NumTotalData);
if (statn != 0)
printf("Error %d reading attribute NumTotalData\n", statn);

statn = SWreadattr(swid, "NumProcessData",
(void *)&airs_cc_rad_gran->NumProcessData);
if (statn != 0)
printf("Error %d reading attribute NumProcessData\n", statn);

statn = SWreadattr(swid, "NumSpecialData",
(void *)&airs_cc_rad_gran->NumSpecialData);
if (statn != 0)
printf("Error %d reading attribute NumSpecialData\n", statn);

statn = SWreadattr(swid, "NumBadData",
(void *)&airs_cc_rad_gran->NumBadData);
if (statn != 0)
printf("Error %d reading attribute NumBadData\n", statn);

statn = SWreadattr(swid, "NumMissingData",
(void *)&airs_cc_rad_gran->NumMissingData);
if (statn != 0)
printf("Error %d reading attribute NumMissingData\n", statn);

statn = SWreadattr(swid, "NumLandSurface",
(void *)&airs_cc_rad_gran->NumLandSurface);
if (statn != 0)
printf("Error %d reading attribute NumLandSurface\n", statn);

statn = SWreadattr(swid, "NumOceanSurface",
(void *)&airs_cc_rad_gran->NumOceanSurface);
if (statn != 0)
printf("Error %d reading attribute NumOceanSurface\n", statn);

statn = SWreadattr(swid, "node_type",
(void *)airs_cc_rad_gran->node_type);
if (statn != 0)
printf("Error %d reading attribute node_type\n", statn);

statn = SWreadattr(swid, "start_year",
(void *)&airs_cc_rad_gran->start_year);
if (statn != 0)
printf("Error %d reading attribute start_year\n", statn);

statn = SWreadattr(swid, "start_month",
(void *)&airs_cc_rad_gran->start_month);
if (statn != 0)
printf("Error %d reading attribute start_month\n", statn);

statn = SWreadattr(swid, "start_day",
(void *)&airs_cc_rad_gran->start_day);
if (statn != 0)
printf("Error %d reading attribute start_day\n", statn);

statn = SWreadattr(swid, "start_hour",
(void *)&airs_cc_rad_gran->start_hour);
if (statn != 0)
printf("Error %d reading attribute start_hour\n", statn);

statn = SWreadattr(swid, "start_minute",
(void *)&airs_cc_rad_gran->start_minute);
if (statn != 0)
printf("Error %d reading attribute start_minute\n", statn);

statn = SWreadattr(swid, "start_sec",
(void *)&airs_cc_rad_gran->start_sec);
if (statn != 0)
printf("Error %d reading attribute start_sec\n", statn);

statn = SWreadattr(swid, "start_orbit",
(void *)&airs_cc_rad_gran->start_orbit);
if (statn != 0)
printf("Error %d reading attribute start_orbit\n", statn);

statn = SWreadattr(swid, "end_orbit",
(void *)&airs_cc_rad_gran->end_orbit);
if (statn != 0)
printf("Error %d reading attribute end_orbit\n", statn);

statn = SWreadattr(swid, "orbit_path",
(void *)&airs_cc_rad_gran->orbit_path);
if (statn != 0)
printf("Error %d reading attribute orbit_path\n", statn);

statn = SWreadattr(swid, "start_orbit_row",
(void *)&airs_cc_rad_gran->start_orbit_row);
if (statn != 0)
printf("Error %d reading attribute start_orbit_row\n", statn);

statn = SWreadattr(swid, "end_orbit_row",
(void *)&airs_cc_rad_gran->end_orbit_row);
if (statn != 0)
printf("Error %d reading attribute end_orbit_row\n", statn);

statn = SWreadattr(swid, "granule_number",
(void *)&airs_cc_rad_gran->granule_number);
if (statn != 0)
printf("Error %d reading attribute granule_number\n", statn);

statn = SWreadattr(swid, "num_scansets",
(void *)&airs_cc_rad_gran->num_scansets);
if (statn != 0)
printf("Error %d reading attribute num_scansets\n", statn);

statn = SWreadattr(swid, "num_scanlines",
(void *)&airs_cc_rad_gran->num_scanlines);
if (statn != 0)
printf("Error %d reading attribute num_scanlines\n", statn);

statn = SWreadattr(swid, "start_Latitude",
(void *)&airs_cc_rad_gran->start_Latitude);
if (statn != 0)
printf("Error %d reading attribute start_Latitude\n", statn);

statn = SWreadattr(swid, "start_Longitude",
(void *)&airs_cc_rad_gran->start_Longitude);
if (statn != 0)
printf("Error %d reading attribute start_Longitude\n", statn);

statn = SWreadattr(swid, "start_Time",
(void *)&airs_cc_rad_gran->start_Time);
if (statn != 0)
printf("Error %d reading attribute start_Time\n", statn);

statn = SWreadattr(swid, "end_Latitude",
(void *)&airs_cc_rad_gran->end_Latitude);
if (statn != 0)
printf("Error %d reading attribute end_Latitude\n", statn);

statn = SWreadattr(swid, "end_Longitude",
(void *)&airs_cc_rad_gran->end_Longitude);
if (statn != 0)
printf("Error %d reading attribute end_Longitude\n", statn);

statn = SWreadattr(swid, "end_Time",
(void *)&airs_cc_rad_gran->end_Time);
if (statn != 0)
printf("Error %d reading attribute end_Time\n", statn);

statn = SWreadattr(swid, "eq_x_longitude",
(void *)&airs_cc_rad_gran->eq_x_longitude);
if (statn != 0)
printf("Error %d reading attribute eq_x_longitude\n", statn);

statn = SWreadattr(swid, "eq_x_tai",
(void *)&airs_cc_rad_gran->eq_x_tai);
if (statn != 0)
printf("Error %d reading attribute eq_x_tai\n", statn);

statn = SWreadattr(swid, "orbitgeoqa",
(void *)&airs_cc_rad_gran->orbitgeoqa);
if (statn != 0)
printf("Error %d reading attribute orbitgeoqa\n", statn);

statn = SWreadattr(swid, "num_satgeoqa",
(void *)&airs_cc_rad_gran->num_satgeoqa);
if (statn != 0)
printf("Error %d reading attribute num_satgeoqa\n", statn);

statn = SWreadattr(swid, "num_glintgeoqa",
(void *)&airs_cc_rad_gran->num_glintgeoqa);
if (statn != 0)
printf("Error %d reading attribute num_glintgeoqa\n", statn);

statn = SWreadattr(swid, "num_moongeoqa",
(void *)&airs_cc_rad_gran->num_moongeoqa);
if (statn != 0)
printf("Error %d reading attribute num_moongeoqa\n", statn);

statn = SWreadattr(swid, "num_ftptgeoqa",
(void *)&airs_cc_rad_gran->num_ftptgeoqa);
if (statn != 0)
printf("Error %d reading attribute num_ftptgeoqa\n", statn);

statn = SWreadattr(swid, "num_zengeoqa",
(void *)&airs_cc_rad_gran->num_zengeoqa);
if (statn != 0)
printf("Error %d reading attribute num_zengeoqa\n", statn);

statn = SWreadattr(swid, "num_demgeoqa",
(void *)&airs_cc_rad_gran->num_demgeoqa);
if (statn != 0)
printf("Error %d reading attribute num_demgeoqa\n", statn);

statn = SWreadattr(swid, "num_fpe",
(void *)&airs_cc_rad_gran->num_fpe);
if (statn != 0)
printf("Error %d reading attribute num_fpe\n", statn);

statn = SWreadattr(swid, "LonGranuleCen",
(void *)&airs_cc_rad_gran->LonGranuleCen);
if (statn != 0)
printf("Error %d reading attribute LonGranuleCen\n", statn);

statn = SWreadattr(swid, "LatGranuleCen",
(void *)&airs_cc_rad_gran->LatGranuleCen);
if (statn != 0)
printf("Error %d reading attribute LatGranuleCen\n", statn);

statn = SWreadattr(swid, "LocTimeGranuleCen",
(void *)&airs_cc_rad_gran->LocTimeGranuleCen);
if (statn != 0)
printf("Error %d reading attribute LocTimeGranuleCen\n", statn);

statn = SWreadattr(swid, "CalGranSummary",
(void *)&airs_cc_rad_gran->CalGranSummary);
if (statn != 0)
printf("Error %d reading attribute CalGranSummary\n", statn);

statn = SWreadattr(swid, "DCR_scan",
(void *)&airs_cc_rad_gran->DCR_scan);
if (statn != 0)
printf("Error %d reading attribute DCR_scan\n", statn);

statn = SWreadattr(swid, "granules_present_L1B",
(void *)airs_cc_rad_gran->granules_present_L1B);
if (statn != 0)
printf("Error %d reading attribute granules_present_L1B\n", statn);


/* Geolocation fields */
statn = SWreadfield(swid, "Latitude", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->Latitude[0][0]);
if (statn != 0)
printf("Error %d reading field Latitude\n", statn);

statn = SWreadfield(swid, "Longitude", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->Longitude[0][0]);
if (statn != 0)
printf("Error %d reading field Longitude\n", statn);

statn = SWreadfield(swid, "Time", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->Time[0][0]);
if (statn != 0)
printf("Error %d reading field Time\n", statn);


/* Data Fields */
statn = SWreadfield(swid, "RetQAFlag", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->RetQAFlag[0][0]);
if (statn != 0)
printf("Error %d reading field RetQAFlag\n", statn);

statn = SWreadfield(swid, "Qual_CC_Rad", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->Qual_CC_Rad[0][0]);
if (statn != 0)
printf("Error %d reading field Qual_CC_Rad\n", statn);

statn = SWreadfield(swid, "radiances", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->radiances[0][0][0]);
if (statn != 0)
printf("Error %d reading field radiances\n", statn);

statn = SWreadfield(swid, "radiance_err", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->radiance_err[0][0][0]);
if (statn != 0)
printf("Error %d reading field radiance_err\n", statn);

statn = SWreadfield(swid, "CldClearParam", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->CldClearParam[0][0][0][0]);
if (statn != 0)
printf("Error %d reading field CldClearParam\n", statn);

statn = SWreadfield(swid, "nominal_freq", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->nominal_freq[0]);
if (statn != 0)
printf("Error %d reading field nominal_freq\n", statn);

statn = SWreadfield(swid, "scanang", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->scanang[0][0]);
if (statn != 0)
printf("Error %d reading field scanang\n", statn);

statn = SWreadfield(swid, "satheight", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satheight[0]);
if (statn != 0)
printf("Error %d reading field satheight\n", statn);

statn = SWreadfield(swid, "satroll", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satroll[0]);
if (statn != 0)
printf("Error %d reading field satroll\n", statn);

statn = SWreadfield(swid, "satpitch", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satpitch[0]);
if (statn != 0)
printf("Error %d reading field satpitch\n", statn);

statn = SWreadfield(swid, "satyaw", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satyaw[0]);
if (statn != 0)
printf("Error %d reading field satyaw\n", statn);

statn = SWreadfield(swid, "satgeoqa", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satgeoqa[0]);
if (statn != 0)
printf("Error %d reading field satgeoqa\n", statn);

statn = SWreadfield(swid, "glintgeoqa", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->glintgeoqa[0]);
if (statn != 0)
printf("Error %d reading field glintgeoqa\n", statn);

statn = SWreadfield(swid, "moongeoqa", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->moongeoqa[0]);
if (statn != 0)
printf("Error %d reading field moongeoqa\n", statn);

statn = SWreadfield(swid, "ftptgeoqa", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->ftptgeoqa[0][0]);
if (statn != 0)
printf("Error %d reading field ftptgeoqa\n", statn);

statn = SWreadfield(swid, "zengeoqa", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->zengeoqa[0][0]);
if (statn != 0)
printf("Error %d reading field zengeoqa\n", statn);

statn = SWreadfield(swid, "demgeoqa", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->demgeoqa[0][0]);
if (statn != 0)
printf("Error %d reading field demgeoqa\n", statn);

statn = SWreadfield(swid, "nadirTAI", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->nadirTAI[0]);
if (statn != 0)
printf("Error %d reading field nadirTAI\n", statn);

statn = SWreadfield(swid, "sat_lat", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->sat_lat[0]);
if (statn != 0)
printf("Error %d reading field sat_lat\n", statn);

statn = SWreadfield(swid, "sat_lon", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->sat_lon[0]);
if (statn != 0)
printf("Error %d reading field sat_lon\n", statn);

statn = SWreadfield(swid, "scan_node_type", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->scan_node_type[0]);
if (statn != 0)
printf("Error %d reading field scan_node_type\n", statn);

statn = SWreadfield(swid, "satzen", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satzen[0][0]);
if (statn != 0)
printf("Error %d reading field satzen\n", statn);

statn = SWreadfield(swid, "satazi", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->satazi[0][0]);
if (statn != 0)
printf("Error %d reading field satazi\n", statn);

statn = SWreadfield(swid, "solzen", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->solzen[0][0]);
if (statn != 0)
printf("Error %d reading field solzen\n", statn);

statn = SWreadfield(swid, "solazi", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->solazi[0][0]);
if (statn != 0)
printf("Error %d reading field solazi\n", statn);

statn = SWreadfield(swid, "glintlat", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->glintlat[0]);
if (statn != 0)
printf("Error %d reading field glintlat\n", statn);

statn = SWreadfield(swid, "glintlon", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->glintlon[0]);
if (statn != 0)
printf("Error %d reading field glintlon\n", statn);

statn = SWreadfield(swid, "sun_glint_distance", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->sun_glint_distance[0][0]);
if (statn != 0)
printf("Error %d reading field sun_glint_distance\n", statn);

statn = SWreadfield(swid, "topog", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->topog[0][0]);
if (statn != 0)
printf("Error %d reading field topog\n", statn);

statn = SWreadfield(swid, "topog_err", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->topog_err[0][0]);
if (statn != 0)
printf("Error %d reading field topog_err\n", statn);

statn = SWreadfield(swid, "landFrac", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->landFrac[0][0]);
if (statn != 0)
printf("Error %d reading field landFrac\n", statn);

statn = SWreadfield(swid, "landFrac_err", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->landFrac_err[0][0]);
if (statn != 0)
printf("Error %d reading field landFrac_err\n", statn);

statn = SWreadfield(swid, "CalFlag", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->CalFlag[0][0]);
if (statn != 0)
printf("Error %d reading field CalFlag\n", statn);

statn = SWreadfield(swid, "CalScanSummary", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->CalScanSummary[0]);
if (statn != 0)
printf("Error %d reading field CalScanSummary\n", statn);

statn = SWreadfield(swid, "CalChanSummary", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->CalChanSummary[0]);
if (statn != 0)
printf("Error %d reading field CalChanSummary\n", statn);

statn = SWreadfield(swid, "ExcludedChans", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->ExcludedChans[0]);
if (statn != 0)
printf("Error %d reading field ExcludedChans\n", statn);

statn = SWreadfield(swid, "NeN_L1B", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->NeN_L1B[0]);
if (statn != 0)
printf("Error %d reading field NeN_L1B\n", statn);

statn = SWreadfield(swid, "dust_flag", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->dust_flag[0][0]);
if (statn != 0)
printf("Error %d reading field dust_flag\n", statn);

statn = SWreadfield(swid, "CC_noise_eff_amp_factor", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->CC_noise_eff_amp_factor[0][0]);
if (statn != 0)
printf("Error %d reading field CC_noise_eff_amp_factor\n", statn);

statn = SWreadfield(swid, "CCfinal_Resid", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->CCfinal_Resid[0][0]);
if (statn != 0)
printf("Error %d reading field CCfinal_Resid\n", statn);

statn = SWreadfield(swid, "invalid", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->invalid[0][0]);
if (statn != 0)
printf("Error %d reading field invalid\n", statn);

statn = SWreadfield(swid, "all_spots_avg", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->all_spots_avg[0][0]);
if (statn != 0)
printf("Error %d reading field all_spots_avg\n", statn);

statn = SWreadfield(swid, "MW_ret_used", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->MW_ret_used[0][0]);
if (statn != 0)
printf("Error %d reading field MW_ret_used\n", statn);

statn = SWreadfield(swid, "bad_clouds", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->bad_clouds[0][0]);
if (statn != 0)
printf("Error %d reading field bad_clouds\n", statn);

statn = SWreadfield(swid, "retrieval_type", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->retrieval_type[0][0]);
if (statn != 0)
printf("Error %d reading field retrieval_type\n", statn);

statn = SWreadfield(swid, "Startup", NULL, NULL, NULL,
(void *)&airs_cc_rad_gran->Startup[0][0]);
if (statn != 0)
printf("Error %d reading field Startup\n", statn);


/* Final clean-up */
statn = SWdetach(swid);
if (statn != 0) printf("Error detaching from input file %s\n", file_name);

statn = SWclose(fid);
if (statn != 0) printf("Error closing input file %s\n", file_name);
}

Document Actions
NASA Logo - nasa.gov
NASA Privacy Policy and Important Notices
Last updated: Sep 09, 2009 02:25 PM ET
Top