Skip to content. | Skip to navigation

Personal tools

extract_spectrum.c

#include <stdio.h>
#include <stdlib.h>
#include "airs_rad_typ.h"
#include "airs_rad_struct.h"


/*
* Note: this struct is about 121 MBytes. On my system this works
* when allocated this way but not when allocated as an automatic
* local variable in main(). It could also be dynamically allocated
* with malloc().
*/
static airs_rad_gran_t airs_rad_gran;

int main(int argc, char * argv[]) {
int chan; /* 0-based channel index */
int track; /* 1-based index along track */
int xtrack;/* 1-based index across-track */
char * file_name = 0;

if (argc != 4) {
fprintf(stderr, "%s extracts a single spectrum from a specified input\n",
argv[0]);
fprintf(stderr, "file to stdout. It requires exactly three arguments:\n");
fprintf(stderr, " 1) scan line number [1, 135]\n");
fprintf(stderr, " 2) field-of-view number [1, 90]\n");
fprintf(stderr, " 3) file name\n\n");
exit(EXIT_FAILURE);
}
track = atoi(argv[1]);
if (track < 1 || track > 135) {
fprintf(stderr,
"Error: first argument must be scan line number [1, 135].\n");
fprintf(stderr, "got \"%s\".\n\n", argv[1]);
exit(EXIT_FAILURE);
}
xtrack = atoi(argv[2]);
if (xtrack < 1 || xtrack > 90) {
fprintf(stderr,
"Error: first argument must be scan line number [1, 90].\n");
fprintf(stderr, "got \"%s\".\n\n", argv[2]);
exit(EXIT_FAILURE);
}
file_name = argv[3];

airs_rad_rdr(file_name, &airs_rad_gran);

/*
* Each AIRS field-of-view has a "state", indicating
* whether the instrument was in science mode when the data
* was taken and whether the data was successfully transmitted.
*/
if ( 0 != airs_rad_gran.state[track-1][xtrack-1]) {
printf("Warning, state for this profile is %s, not PROCESS\n",
airs_rad_gran.state[track-1][xtrack-1] == 1 ? "SPECIAL" :
airs_rad_gran.state[track-1][xtrack-1] == 2 ? "ERRONEOUS" :
airs_rad_gran.state[track-1][xtrack-1] == 3 ? "MISSING" :
"UNKNOWN");
}

printf("#\tFrequency\tRadiance\n");
printf("#\t(cm**-1)\t(milliWatts/m**2/cm**-1/steradian)\n");
printf("#\t\t\t(-9999 flags bad value)\n");
for (chan = 0; chan < AIRS_RAD_CHANNEL; chan++) {
printf("\t%7.3f\t\t", airs_rad_gran.nominal_freq[chan]);
/*
* channel should not be used because ExcludedChans indicates
* known radiometric problems. ExcludedChans echos information in
* field AB_State of the Channel Properties File
*/
if ( (airs_rad_gran.ExcludedChans[chan] > 2)

/*
* channel should not be used because CalChanSummary indicates
* a transient problem with high noise
*/
|| (airs_rad_gran.CalChanSummary[chan] & 8)

/*
* channel should not be used because CalChanSummary indicates
* a problem was encountered in calculating calibration coefficients
*/
/* 32 (bit 5) indicates gain anamoly, 64 (bit 6) for offset anamoly */
|| (airs_rad_gran.CalChanSummary[chan] & (32 + 64))

/* channel has "popped". (transient change in zero-level in this scan) */
|| (airs_rad_gran.CalFlag[track-1][chan] & 16))

/* something is wrong -- put out flag value -9999.0 */
printf("%.5e\n", -9999.0);
else
printf("%.5e\n",
airs_rad_gran.radiances[track-1][xtrack-1][chan]);
}

return 0;
}

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