Skip to content. | Skip to navigation

Personal tools

extract_profile.c

#include <stdio.h>
#include <stdlib.h>
#include "airs_ret_typ.h"
#include "airs_ret_struct.h"


/*
* Note: this struct is large. 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_ret_gran_t airs_ret_gran;

int main(int argc, char * argv[]) {
int layer; /* 0-based atmospheric pressure layer index. */
/* 0 is surface (or below) */
int track; /* 0-based index along track */
int xtrack;/* 0-based index across-track */
int i, j; /* 0-based indices for 3x3 of IR spots per profile */
char * file_name = 0;

if (argc != 4) {
fprintf(stderr, "%s extracts a single profile 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, 45]\n");
fprintf(stderr, " 2) field-of-view number [1, 30]\n");
fprintf(stderr, " 3) file name\n\n");
exit(EXIT_FAILURE);
}
track = atoi(argv[1]);
if (track < 1 || track > 45) {
fprintf(stderr,
"Error: first argument must be scan line number [1, 45].\n");
fprintf(stderr, "got \"%s\".\n\n", argv[1]);
exit(EXIT_FAILURE);
}
track--; /* change to 0-based for internal use */

xtrack = atoi(argv[2]);
if (xtrack < 1 || xtrack > 30) {
fprintf(stderr,
"Error: first argument must be scan line number [1, 30].\n");
fprintf(stderr, "got \"%s\".\n\n", argv[2]);
exit(EXIT_FAILURE);
}
xtrack--; /* change to 0-based for internal use */

file_name = argv[3];

airs_ret_rdr(file_name, &airs_ret_gran);

printf("# Atmospheric profile from top down\n");
printf("#\tPressure\tTemperature\tH2O MMR\t\tO3 VMR\n");
printf("#\t(mbar)\t\t(Kelvins)\t(gm/kg dry air)\t(vmr)\n");
printf("#\t\t(-9999 flags bad value)\n");
for (layer = AIRS_RET_STDPRESSURELAY - 1; layer >= 0; layer--) {
unsigned short qual; /* temporary for quality of current species */

/*
* Pressure for layer. For layer quantities like water vapor,
* this is the pressure at the bottom of the layer. For level
* quantities like temperature, the temperature is measured at
* this level.
*/
printf("\t%.5e", airs_ret_gran.pressStd[layer]);

/*
* Which Qual flag to check depends on layer
*
* "+ 1" because nStd* fields are 1-based indices and layer is 0-based.
*/
if (layer + 1 >= airs_ret_gran.nStd_mid_top_bndry[track][xtrack])
qual = airs_ret_gran.Qual_Temp_Profile_Top[track][xtrack];
else if (layer + 1> airs_ret_gran.nStd_bot_mid_bndry[track][xtrack])
qual = airs_ret_gran.Qual_Temp_Profile_Mid[track][xtrack];
else
qual = airs_ret_gran.Qual_Temp_Profile_Bot[track][xtrack];

/* Temperature. If quality is bad (2) then put out flag value of -9999.0 */
if (qual < 2)
printf("\t%8.2f", airs_ret_gran.TAirStd[track][xtrack][layer]);
else
printf("\t%8.2f", -9999.0);

/* Water vapor. If quality is bad (2) then put out flag value of -9999.0 */
if (airs_ret_gran.Qual_H2O[track][xtrack] < 2)
printf("\t%11.5f", airs_ret_gran.H2OMMRStd[track][xtrack][layer]);
else
printf("\t%11.5f", -9999.0);

/* Ozone. If quality is bad (2) then put out flag value of -9999.0 */
if (airs_ret_gran.Qual_O3[track][xtrack] < 2)
printf("\t%11.4e", airs_ret_gran.O3VMRStd[track][xtrack][layer]);
else
printf("\t%11.4e", -9999.0);

printf("\n");
}

/*
* Need to output quality info so users can tell if we have a good
* retrieval with no clouds or a bad retrieval. Both cases will put
* all -9999s below.
*/
printf("\n\n# Cloud quality:\n");
if (airs_ret_gran.Qual_Cloud_OLR[track][xtrack] == 0)
printf("\t0\tVery Good\n");
else if (airs_ret_gran.Qual_Cloud_OLR[track][xtrack] == 1)
printf("\t1\tGood\n");
else
printf("\t2\tDo Not Use\n");

printf("\n\n# Cloud top info by layer:\n");
printf("# Pressure Temperature Overall Fraction\n");
printf("# mbar K [0.0, 1.0]\n");
for (layer = 0; layer < 2; layer++) {
/*
* Require good quality on cloud retreival in general and print out
* info only for cloud layers that exist.
*/
if (airs_ret_gran.Qual_Cloud_OLR[track][xtrack] < 2
&& airs_ret_gran.numCloud[track][xtrack] > layer)
printf("\t%10.3e\t%8.2f\t%8.2f\n",
airs_ret_gran.PCldTopStd[track][xtrack][layer],
airs_ret_gran.TCldTopStd[track][xtrack][layer],
( airs_ret_gran.CldFrcStd[track][xtrack][0][0][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][0][1][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][0][2][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][1][0][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][1][1][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][1][2][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][2][0][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][2][1][layer]
+ airs_ret_gran.CldFrcStd[track][xtrack][2][2][layer])
/ 9);
else /* Cloud retrieval failed or this layer has no cloud. */
printf("\t%10.3e\t%8.2f\t%8.2f\n", -9999.0, -9999.0, -9999.0);
}
printf("\n\n# Cloud fraction by spot:\n");
printf("# Latitude Longitude Fraction\n");
printf("# (degrees) (degrees) [0.0, 1.0]\n");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if ( (airs_ret_gran.Qual_Cloud_OLR[track][xtrack] == 2)
|| (airs_ret_gran.numCloud[track][xtrack] == 0))
/* bad cloud retrieval or no cloud layers */
printf("\t%10.3f\t%10.3f\t%8.2f\n", -9999.0, -9999.0, -9999.0);
else if (airs_ret_gran.numCloud[track][xtrack] == 1)
printf("\t%10.3f\t%10.3f\t%8.2f\n",
airs_ret_gran.latAIRS[track][xtrack][i][j],
airs_ret_gran.lonAIRS[track][xtrack][i][j],
airs_ret_gran.CldFrcStd[track][xtrack][i][j][0]);
else /* 2 cloud layers -- must sum */
printf("\t%10.3f\t%10.3f\t%8.2f\n",
airs_ret_gran.latAIRS[track][xtrack][i][j],
airs_ret_gran.lonAIRS[track][xtrack][i][j],
airs_ret_gran.CldFrcStd[track][xtrack][i][j][0]
+ airs_ret_gran.CldFrcStd[track][xtrack][i][j][1]);
return 0;
}

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