Go to the documentation of this file.
18 static int firstCall = 1;
19 static int nx =
NXANC;
20 static int ny =
NYANC;
21 static float dx = 360.0 /
NXANC;
22 static float dy = 180.0 /
NYANC;
24 typedef float map_frac_t[
NXANC + 2];
25 static map_frac_t* map_frac;
43 int32 dims[H4_MAX_VAR_DIMS];
47 char name[H4_MAX_NC_NAME];
48 char sdsname[H4_MAX_NC_NAME];
50 char *no2_frac_fil, no2_frac_file[300];
57 if ((no2_frac_fil = getenv(
"OCDATAROOT")) ==
NULL) {
58 printf(
"-E- %s: Error looking up environmental variable OCDATAROOT\n",
62 strcpy(no2_frac_file, no2_frac_fil);
63 strcat(no2_frac_file,
"/common/trop_f_no2_200m.hdf");
67 printf(
"-E- %s: Error allocating NO2 frac space for %s.\n", __FILE__,
72 sd_id = SDstart(no2_frac_file, DFACC_RDONLY);
74 printf(
"-E- %s: Error opening NO2 frac file %s.\n", __FILE__,
79 printf(
"\nOpening NO2 frac file %s\n\n", no2_frac_file);
81 strcpy(sdsname,
"f_no2_200m");
82 sds_index = SDnametoindex(sd_id, sdsname);
83 if (sds_index == -1) {
84 printf(
"-E- %s: Error seeking %s SDS from %s.\n", __FILE__, sdsname,
88 sds_id = SDselect(sd_id, sds_index);
92 printf(
"-E- %s: Error reading SDS info for %s from %s.\n", __FILE__,
93 sdsname, no2_frac_file);
96 if (dims[0] != ny || dims[1] != nx) {
97 printf(
"-E- %s: Dimension mis-match on %s array from %s.\n", __FILE__,
98 sdsname, no2_frac_file);
99 printf(
" Expecting %d x %d\n", nx, ny);
100 printf(
" Reading %d x %d\n", dims[1], dims[0]);
111 printf(
"-E- %s: Error reading SDS %s from %s.\n", __FILE__, sdsname,
116 for (
j = 0;
j < ny;
j++) {
117 for (
i = 0;
i < nx;
i++) {
118 map_frac[
j + 1][
i + 1] = map[ny -
j - 1][
i];
124 for (
j = 0;
j < ny;
j++) {
125 map_frac[
j + 1][0] = map_frac[
j + 1][nx];
126 map_frac[
j + 1][nx + 1] = map_frac[
j + 1][1];
128 for (
i = 0;
i < nx + 2;
i++) {
129 map_frac[0][
i] = map_frac[1][
i];
130 map_frac[ny + 1][
i] = map_frac[ny][
i];
140 i =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
141 j =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
143 xx =
i * dx - 180.0 - dx / 2;
144 yy =
j * dy - 90.0 - dy / 2;
149 frac = (1 -
t) * (1 -
u) * map_frac[
j][
i] +
t * (1 -
u) * map_frac[
j][
i + 1]
150 +
t *
u * map_frac[
j + 1][
i + 1] + (1 -
t) *
u * map_frac[
j + 1][
i];
154 *no2_frac_200 =
MAX(frac, 0.0);
161 static int firstCall = 1;
162 static int nx =
NXNO2;
163 static int ny =
NYNO2;
164 static float dx = 360.0 /
NXNO2;
165 static float dy = 180.0 /
NYNO2;
167 typedef float map_t[
NXNO2 + 2];
168 static map_t* map_total;
169 static map_t* map_tropo;
189 int32 dims[H4_MAX_VAR_DIMS];
193 char name[H4_MAX_NC_NAME];
194 char sdsname[H4_MAX_NC_NAME];
208 printf(
"-E- %s: Error allocating space for %s.\n", __FILE__, no2file);
212 sd_id = SDstart(no2file, DFACC_RDONLY);
214 printf(
"-E- %s: Error opening NO2 file %s.\n", __FILE__, no2file);
218 printf(
"\nOpening NO2 file %s\n\n", no2file);
220 if (SDreadattr(sd_id, SDfindattr(sd_id,
"Title"), (VOIDP)
title) == 0) {
221 if (strstr(
title,
"NO2 Climatology") !=
NULL) {
223 sprintf(mstr,
"_%2.2i", month + 1);
227 strcpy(sdsname,
"tot_no2");
228 strcat(sdsname, mstr);
229 sds_index = SDnametoindex(sd_id, sdsname);
230 if (sds_index == -1) {
231 printf(
"-E- %s: Error seeking %s SDS from %s.\n", __FILE__, sdsname,
235 sds_id = SDselect(sd_id, sds_index);
239 printf(
"-E- %s: Error reading SDS info for %s from %s.\n", __FILE__,
243 if (dims[0] != ny || dims[1] != nx) {
244 printf(
"-E- %s: Dimension mis-match on %s array from %s.\n", __FILE__,
246 printf(
" Expecting %d x %d\n", nx, ny);
247 printf(
" Reading %d x %d\n", dims[1], dims[0]);
258 printf(
"-E- %s: Error reading SDS %s from %s.\n", __FILE__, sdsname,
263 for (
j = 0;
j < ny;
j++) {
264 for (
i = 0;
i < nx;
i++) {
265 map_total[
j + 1][
i + 1] = map[ny -
j - 1][
i];
269 status = SDendaccess(sds_id);
271 printf(
"-E- %s: Error closing SDS %s from %s.\n", __FILE__, sdsname,
276 strcpy(sdsname,
"trop_no2");
277 strcat(sdsname, mstr);
278 sds_index = SDnametoindex(sd_id, sdsname);
279 if (sds_index == -1) {
280 printf(
"-E- %s: Error seeking %s SDS from %s.\n", __FILE__, sdsname,
284 sds_id = SDselect(sd_id, sds_index);
288 printf(
"-E- %s: Error reading SDS info for %s from %s.\n", __FILE__,
292 if (dims[0] != ny || dims[1] != nx) {
293 printf(
"-E- %s: Dimension mis-match on %s array from %s.\n", __FILE__,
295 printf(
" Expecting %d x %d\n", nx, ny);
296 printf(
" Reading %d x %d\n", dims[1], dims[0]);
307 printf(
"-E- %s: Error reading SDS %s from %s.\n", __FILE__, sdsname,
312 status = SDendaccess(sds_id);
314 printf(
"-E- %s: Error closing SDS %s from %s.\n", __FILE__, sdsname,
319 for (
j = 0;
j < ny;
j++) {
320 for (
i = 0;
i < nx;
i++) {
321 map_tropo[
j + 1][
i + 1] = map[ny -
j - 1][
i];
327 for (
j = 0;
j < ny;
j++) {
328 map_total[
j + 1][0] = map_total[
j + 1][nx];
329 map_total[
j + 1][nx + 1] = map_total[
j + 1][1];
330 map_tropo[
j + 1][0] = map_tropo[
j + 1][nx];
331 map_tropo[
j + 1][nx + 1] = map_tropo[
j + 1][1];
333 for (
i = 0;
i < nx + 2;
i++) {
334 map_total[0][
i] = map_total[1][
i];
335 map_total[ny + 1][
i] = map_total[ny][
i];
336 map_tropo[0][
i] = map_tropo[1][
i];
337 map_tropo[ny + 1][
i] = map_tropo[ny][
i];
346 i =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
347 j =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
349 xx =
i * dx - 180.0 - dx / 2;
350 yy =
j * dy - 90.0 - dy / 2;
355 total = (1 -
t) * (1 -
u) * map_total[
j][
i]
356 +
t * (1 -
u) * map_total[
j][
i + 1] +
t *
u * map_total[
j + 1][
i + 1]
357 + (1 -
t) *
u * map_total[
j + 1][
i];
359 tropo = (1 -
t) * (1 -
u) * map_tropo[
j][
i]
360 +
t * (1 -
u) * map_tropo[
j][
i + 1] +
t *
u * map_tropo[
j + 1][
i + 1]
361 + (1 -
t) *
u * map_tropo[
j + 1][
i];
365 *no2_strat =
MAX(
total - tropo, 0.0);
366 *no2_tropo =
MAX(tropo, 0.0);
380 static int firstCall = 1;
381 static int nx, ny, mapx;
382 static float dx, dy, *map;
386 float t,
u, val_11, val_12, val_21, val_22;
397 int32 dims[H4_MAX_VAR_DIMS];
401 char name[H4_MAX_NC_NAME];
402 char sdsname[H4_MAX_NC_NAME];
406 if (day < 1 || day > 366) {
407 printf(
"-E- %s: Bogus day number for ozone look-up: %d\n", __FILE__,
423 sd_id = SDstart(
file, DFACC_RDONLY);
425 printf(
"-E- %s: Error openin file %s.\n", __FILE__,
file);
429 printf(
"\nOpening ozone file %s\n\n",
file);
431 sprintf(sdsname,
"ozone_mean_%03d",
day);
432 sds_index = SDnametoindex(sd_id, sdsname);
433 if (sds_index == -1) {
434 printf(
"-E- %s: Error seeking %s SDS from %s.\n", __FILE__, sdsname,
438 sds_id = SDselect(sd_id, sds_index);
442 printf(
"-E- %s: Error reading SDS info for %s from %s.\n", __FILE__,
449 if (nx < 0 || ny < 0) {
450 printf(
"-E- %s: grid has bad dimensions, sds %s from %s.\n", __FILE__,
452 printf(
" Reading %d x %d\n", nx, ny);
461 if (((
tmp = (
float *) malloc(nx * ny *
sizeof (
float))) ==
NULL) ||
462 ((map = (
float *) malloc(mapx * (ny + 2) *
sizeof (
float)))
465 "-E- %s, %d: Unable to allocate space for climatology grid storage\n",
477 printf(
"-E- %s: Error reading SDS %s from %s.\n", __FILE__, sdsname,
482 for (
j = 0;
j < ny;
j++) {
483 for (
i = 0;
i < nx;
i++) {
484 *(map +
i + 1 + mapx * (
j + 1)) = *(
tmp +
i + nx *
j);
485 *(map +
i + 1 + mapx * (
j + 1)) =
486 *(
tmp +
i + nx * (ny -
j - 1));
494 for (
j = 0;
j < ny;
j++) {
495 *(map + mapx * (
j + 1)) = *(map + nx + mapx * (
j + 1));
496 *(map + (nx + 1) + mapx * (
j + 1)) =
497 *(map + 1 + mapx * (
j + 1));
499 for (
i = 0;
i < mapx;
i++) {
500 *(map +
i) = *(map + mapx +
i);
501 *(map +
i + mapx * (ny + 1)) = *(map +
i + mapx * ny);
511 i =
MAX(
MIN((
int) ((
lon + 180.0 + dx / 2) / dx), nx + 1), 0);
512 j =
MAX(
MIN((
int) ((
lat + 90.0 + dy / 2) / dy), ny + 1), 0);
514 xx =
i * dx - 180.0 - dx / 2;
515 yy =
j * dy - 90.0 - dy / 2;
520 val_11 = *(map +
i + mapx *
j);
521 val_12 = *(map +
i + 1 + mapx *
j);
522 val_21 = *(map +
i + mapx * (
j + 1));
523 val_22 = *(map +
i + 1 + mapx * (
j + 1));
525 if ((val_11 < 0) || (val_12 < 0) || (val_21 < 0) || (val_22 < 0)) {
527 printf(
"I %s, %d: Attempt to use missing climatology points\n",
530 ozone = (1 -
t) * (1 -
u) * val_11 +
t * (1 -
u) * val_12
531 +
t *
u * val_22 + (1 -
t) *
u * val_21;
564 static float r2d = 57.29577951;
565 static int firstCall = 1;
566 static int32_t anc_id[] ={
569 static short *ancqc =
NULL;
570 static char *no2file =
NULL;
573 float u,
v, u_u, v_u, ws_2;
581 int32_t
msec = (int32_t) (dsec * 1.e3);
590 printf(
"\nOpening meteorological files.\n");
591 printf(
" met1 = %s\n",
input->met1);
592 printf(
" met2 = %s\n",
input->met2);
593 printf(
" met3 = %s\n",
input->met3);
594 printf(
" ozone1 = %s\n",
input->ozone1);
595 printf(
" ozone2 = %s\n",
input->ozone2);
596 printf(
" ozone3 = %s\n",
input->ozone3);
597 printf(
" no2 = %s\n",
input->no2file);
599 if ((ancqc = calloc(
npix,
sizeof (
short))) ==
NULL) {
600 fprintf(
stderr,
"-E- %s %d: Unable to allocate buffer space.\n", __FILE__,
604 if (strcmp(
input->no2file,
"") != 0) {
605 no2file =
input->no2file;
616 if ((ancqc = calloc(
npix,
sizeof (
short))) ==
NULL) {
617 fprintf(
stderr,
"-E- %s %d: Unable to allocate buffer space.\n", __FILE__,
628 if (anc_id[0] == 0) {
631 }
else if (anc_id[0] == 2) {
634 }
else if (anc_id[0] == 3) {
642 if(
input->relhumid != -2000) {
648 "-E- %s %d: Error loading relative humidity ancillary data. %s\n",
649 __FILE__, __LINE__,
input->anc_cor_file);
660 l1rec->zw_unc, ancqc);
663 "-E- %s %d: Error loading Zonal wind speed ancillary data.\n", __FILE__,
671 l1rec->mw_unc, ancqc);
674 "-E- %s %d: Error loading Meridional wind speed ancillary data.\n",
684 ws_2 =
u *
u +
v *
v;
686 if(
input->windspeed != -2000)
687 l1rec->ws[
i] = sqrt(ws_2);
688 if(
input->windangle != -2000)
696 if ((
u +
v) > 0.05 * (u_u + v_u)) {
697 l1rec->ws_unc[
i] = sqrt((
u *
u * u_u * u_u +
v *
v * v_u * v_u) /
699 l1rec->wd_unc[
i] = sqrt(
v *
v * u_u * u_u +
u *
u * v_u * v_u) / ws_2;
702 l1rec->ws_unc[
i] = sqrt(0.5 * (u_u * u_u + v_u * v_u));
713 if(
input->pressure != -2000) {
716 l1rec->pr_unc, ancqc);
719 "-E- %s %d: Error loading surface pressure ancillary data.\n", __FILE__,
729 else if (
l1rec->pr[
i] < 900.0)
731 else if (
l1rec->pr[
i] > 1100.0)
747 if(
input->watervapor != -2000) {
750 l1rec->wv_unc, ancqc);
753 "-E- %s %d: Error loading precipitable water ancillary data.\n",
770 if (strlen(
input->anc_profile1)){
777 if (strlen(
input->anc_aerosol1)){
782 if( strlen(
input->sfc_albedo) ){
786 if(
input->proc_cloud ) {
788 "%s, %d: Cloud processing, requires an input surface albedo (sfc_albedo=...)\n",
789 __FILE__, __LINE__ );
794 if (anc_id[1] == 0) {
797 }
else if (anc_id[1] == 2) {
800 }
else if (anc_id[1] == 3) {
804 if(
input->ozone != -2000) {
805 if (strstr(
input->ozone1,
"ozone_climatology") !=
NULL) {
819 fprintf(
stderr,
"-E- %s %d: Error loading Ozone ancillary data.\n",
847 l1rec->no2_tropo[
i] *= 1e15;
848 l1rec->no2_strat[
i] *= 1e15;
855 fprintf(
stderr,
"-E- %s %d: Error loading ancillary data.\n", __FILE__,
int anc_acq_lin(int32_t anc_class, l1str *l1rec)
int32_t anc_acq_lin_aerosol(l1str *l1rec)
int32_t anc_acq_lin_prof(l1str *l1rec)
void no2conc(char *no2file, float lon, float lat, int32_t doy, float *no2_tropo, float *no2_strat)
void * allocateMemory(size_t numBytes, const char *name)
float ozone_climatology(char *file, int day, float lon, float lat)
int32_t jday(int16_t i, int16_t j, int16_t k)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
int32_t anc_acq_lin_met(l1str *l1rec)
int get_ancillary(float *in_lat, float *in_lon, int16_t cnt, int16_t syear, int16_t sday, int16_t eday, int32_t time, char *filename1, char *filename2, char *filename3, char *anc_cor_file, int16_t parm_flag, float *interp, float *anc_unc, int16_t *qcflag)
MOD_PR02AQUA Production where MYD is the prefix denoting AQUA file output The total
void free2d_float(float **p)
Free a two-dimensional array created by allocate2d_float.
int anc_acq_lin_olci(int anc_class, char *file, l1str *l1rec)
void unix2yds(double usec, short *year, short *day, double *secs)
Extra metadata that will be written to the HDF4 file l2prod rank
int32_t anc_acq_lin_oz(l1str *l1rec)
void no2_frac(float lon, float lat, float *no2_frac_200)
float ** allocate2d_float(size_t h, size_t w)
Allocate a two-dimensional array of type float of a given size.
int acq_sfc_albedo(l1str *l1rec)
int anc_acq_init(instr *input, l1str *l1rec, int32_t *anc_id)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")