9 extern void ch_cld_sci_(
float *,
int *,
unsigned char *,
int *,
10 int32_t *,
int *,
int *,
char * );
39 static int32_t cur_cmp_rec = -1;
41 int get_cmp( l2str *l2rec,
int prodnum,
float prod[])
60 void get_cmp_prod_(
int *,
float *,
int * );
63 if(
input->proc_cloud == 0 ) {
64 printf(
"%s, %d: Cloud products require the proc_cloud=1 set\n", __FILE__,
69 if( l2rec->l1rec->iscan != cur_cmp_rec )
71 cur_cmp_rec = l2rec->l1rec->iscan;
74 printf(
"%s, %d: E - CMP computation failure\n", __FILE__, __LINE__ );
85 if( ( prodnum >= 480 ) && ( prodnum <= 482 ) ) n_prd = 10;
86 if( prodnum == 492 ) n_prd = 10;
87 get_cmp_prod_( &prodnum, prod, &n_prd );
96 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
97 if( *( prod + ipix ) < -900 )
98 l2rec->l1rec->flags[ipix] |=
PRODFAIL;
107 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
108 if( *( prod + ipix ) < -900 )
109 l2rec->l1rec->flags[ipix] |=
PRODWARN;
114 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
115 if( *( prod + ipix ) < -900 )
116 l2rec->l1rec->flags[ipix] |=
NAVFAIL;
121 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
122 if( *( prod + ipix ) < -900 )
123 l2rec->l1rec->flags[ipix] |=
ATMFAIL;
145 static unsigned char *bprod =
NULL;
146 void get_cmp_byt_(
int *,
unsigned char * );
148 if( l2rec->l1rec->iscan != cur_cmp_rec )
150 cur_cmp_rec = l2rec->l1rec->iscan;
153 printf(
"%s, %d: E - CMP computation failure\n", __FILE__, __LINE__ );
160 if( ( bprod = (
unsigned char *)
161 malloc( l2rec->l1rec->npix *
sizeof(
unsigned char) ) ) ==
NULL )
163 printf(
"%s, %d: E - unable to alocate byte storage\n",
164 __FILE__, __LINE__ );
172 get_cmp_byt_( &prodnum, bprod );
186 int set_cmp( l2str *,
float **, int32_t *, int32_t **, int32_t *,
187 unsigned char **, int32_t * );
188 void get_cmp_byt_(
int *,
unsigned char * );
189 unsigned char *lcl_prd;
190 int32_t nfloat, nint32, nubyte;
192 static unsigned char *ubdat;
193 static int32_t *i32dat;
194 int sensor_id = l2rec->l1rec->l1file->sensorID;
195 int ip,
npix = l2rec->l1rec->npix;
206 if(
set_cmp( l2rec, &tdat, &nfloat, &i32dat, &nint32, &ubdat, &nubyte ) != 0 )
212 ch_cld_sci_( tdat, &nfloat, ubdat, &nubyte, i32dat, &nint32, &sensor_id,
213 input->cloud_hgt_file );
218 if( ( lcl_prd = (
unsigned char *)malloc(
npix *
sizeof(
char ) ) ) ==
NULL )
220 printf(
"%s, %d: Unable to allocate cloud phase buffer\n", __FILE__, __LINE__ );
227 get_cmp_byt_( &cat_val, lcl_prd );
229 for( ip = 0; ip <
npix; ip++ )
231 if( *( lcl_prd + ip ) == 3 )
233 if( ( *( lcl_prd + ip ) == 2 ) || ( *( lcl_prd + ip ) == 4 ) )
234 l2rec->l1rec->flags[ip] |=
TURBIDW;
242 int set_cmp( l2str *l2rec,
float **tdat, int32_t *nfloat, int32_t **i32dat,
243 int32_t *nint32,
unsigned char **ubdat, int32_t *nubyte )
253 int mk_cmp_prof(
float *,
float *,
float *,
float *,
float,
float,
float,
254 float,
unsigned char *,
unsigned char *,
double *,
double *,
double *,
257 int mk_cmp_prof_dum(
float *,
float *,
float *,
float *,
float,
float,
float,
258 float,
unsigned char *,
unsigned char *,
double *,
double *,
double *,
262 l1str *
l1rec = l2rec->l1rec;
263 int32_t nbnd_ref, nbnd_emis, foff, foff2, uoff, uoff2,
nbnd, sensor_id;
265 int32_t dbg_print, ix_bnd, force_oci, cld_missed;
266 int32_t ncmp_bnd = 15;
268 int profile_print(
float *,
unsigned char *, int32_t *, int32_t, int32_t,
275 static int32_t ref_for_cmb[] = { 1, 1, 1, 1, 1, 1, 0, 2, 0, 0, 1, 0, 0, 1, 1 };
277 static char cmp_there[15];
279 static int32_t l1ix[15];
281 int32_t cld_wav_mod[] = { 645, 859, 1240, 1640, 2130, 930, 3750, 1375,
282 8550, 11000, 443, 12000, 13600, 469, 555 };
298 int32_t cld_wav_ocis[] = { 665, 865, 1250, 1616, 2130, 930, 2260, 1375,
299 8550, 11000, 443, 12000, 13600, 469, 555 };
301 int32_t cld_wav_oci[] = { 665, 865, 1249, 1618, 2131, 940, 2258, 1378,
302 8550, 11000, 442, 12000, 13600, 470, 555 };
305 int32_t oci_bnd_avail[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1 };
307 static int32_t cld_min_bnd[] = { 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1 };
313 float chim_rad_corr[] = { 1.0, 1.0, 1.0, 1.0, 1.0,
318 -1., 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
325 static int32_t firstcall = 0;
331 int32_t nlvl = 42, nlvl_cmp = 101, ilvl, is_land, cld_flg;
332 int32_t bad_rad, ice_flg, glint_flg, n_sfc_albedo;
333 int32_t npix_scan, lst, len, pst, pen, apx, aln, itot, nland;
334 unsigned char sfc_lvl, trop_lvl;
335 float merra_p_set[] = { 0.1, 0.3, 0.4, 0.5, 0.7, 1., 2., 3., 4., 5., 7., 10.,
336 20., 30., 40., 50., 70., 100., 150., 200., 250., 300., 350., 400.,
337 450., 500., 550., 600., 650., 700., 725., 750., 775., 800., 825.,
338 850., 875., 900., 925., 950., 975., 1000. };
339 float merra_t[nlvl], merra_p[nlvl], merra_q[nlvl], merra_h[nlvl];
340 double cmp_t[nlvl_cmp], cmp_mixr[nlvl_cmp], cmp_h[nlvl_cmp];
341 double cmp_p[nlvl_cmp], cmp_p_set[nlvl_cmp];
347 ctr_que =
l1que.nq / 2;
368 sensor_id =
l1rec->l1file->sensorID;
370 if( ( sensor_id ==
OCIS ) || ( sensor_id ==
OCI ) ) n_sfc_albedo = 6;
384 nbnd_ref =
l1rec->l1file->nbands;
385 nbnd_emis =
l1rec->l1file->nbandsir;
389 if( ( *tdat = (
float *) malloc( *nfloat *
sizeof(
float) ) ) ==
NULL )
391 printf(
"%s - %d: Allocation of real storage failed\n",
392 __FILE__, __LINE__ );
401 if( ( *ubdat = (
unsigned char *)
402 malloc( *nubyte *
sizeof(
unsigned char) ) ) ==
NULL )
404 printf(
"%s - %d: Allocation of byte storage failed\n",
405 __FILE__, __LINE__ );
412 if( ( *i32dat = (int32_t *) malloc( *nint32 *
sizeof(int32_t) ) ) ==
NULL )
414 printf(
"%s - %d: Allocation of i32 storage failed\n",
415 __FILE__, __LINE__ );
421 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
423 if( sensor_id ==
OCIS )
424 cld_wav[ibnd] = cld_wav_ocis[ibnd];
425 else if( sensor_id ==
OCI )
426 cld_wav[ibnd] = cld_wav_oci[ibnd];
428 cld_wav[ibnd] = cld_wav_mod[ibnd];
431 if( ( sensor_id ==
OCIS ) || ( sensor_id ==
OCI ) )
436 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
439 if( ( ix_bnd < 0 ) && ( ref_for_cmb[ibnd] != 2 ) )
448 if( ref_for_cmb[ibnd] == 0 )
450 else if( ref_for_cmb[ibnd] == 1 )
460 printf(
"OCI band forcing is set to %d\n", force_oci );
463 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
464 cmp_there[ibnd] *= oci_bnd_avail[ibnd];
471 printf(
"Talley of current instrument's wavelengths\n" );
472 printf(
"Cloud wave is wave is\n" );
473 printf(
"wavelength available required\n" );
475 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
477 if( ( cld_min_bnd[ibnd] == 1 ) && ( cmp_there[ibnd] == 0 ) )
479 printf(
"%10d %9d %8d\n", cld_wav[ibnd], cmp_there[ibnd],
482 if( cld_missed == 1 )
484 printf(
"%s, %d: The required wavelengths for cloud processing were not found, Exiting\n", __FILE__, __LINE__ );
492 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
494 for( iln = 0; iln <
nlin; iln++ )
496 qln = iln + ctr_que -
nlin / 2;
497 for( ipx = 0; ipx <
npix; ipx++ )
500 if( ( iln == 1) && ( dbg_print == 1 ) )
502 printf(
"%s, %d: bnd %d, lin %d, pix %d, rad %f\n",
503 __FILE__, __LINE__, ibnd, iln, ipx,
504 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] );
507 if( cmp_there[ibnd] == 1 )
510 if( ref_for_cmb[ibnd] == 1 )
512 rad =
l1que.r[qln].Lt[ l1ix[ ibnd ] + nbnd_ref * ipx ];
514 out = rad *
PI / ( cos(
solz *
PI / 180. ) *
F0[ l1ix[ ibnd ] ] );
515 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] =
516 chim_rad_corr[ibnd] *
out;
518 else if( ref_for_cmb[ibnd] == 2 )
521 rad =
l1que.r[qln].rho_cirrus[ipx];
522 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] =
523 chim_rad_corr[ibnd] * rad * cos(
solz *
PI / 180. );
527 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] =
528 chim_rad_corr[ibnd] *
529 10. *
l1que.r[qln].Ltir[ ( l1ix[ ibnd ] - nbnd_ref ) +
536 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] = -999.0;
539 if( ( iln == 1 ) && (dbg_print == 1 ) )
541 printf(
"%s, %d: bnd %d, lin %d, pix %d, rad %f\n",
542 __FILE__, __LINE__, ibnd, iln, ipx,
543 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] );
570 for( iln = 0; iln <
nlin; iln++ )
572 qln = iln + ctr_que -
nlin / 2;
573 for( ipx = 0; ipx <
npix; ipx++ )
576 if( ( iln == 1 ) && (dbg_print == 1 ) )
578 printf(
"%s, %d: bnd %d, lin %d, pix %d, UNC %f\n",
579 __FILE__, __LINE__, ibnd, iln, ipx,
586 if( ( iln == 1 ) && (dbg_print == 1 ) )
588 printf(
"%s, %d: bnd %d, lin %d, pix %d, UNC %f\n",
589 __FILE__, __LINE__, ibnd, iln, ipx,
603 (*tdat)[ foff + ibnd ] = 0.;
604 (*tdat)[ foff2 + ibnd ] = 1.;
612 for( iln = 0; iln <
nlin; iln++ )
614 qln = iln + ctr_que -
nlin / 2;
615 for( ipx = 0; ipx <
npix; ipx++ )
617 if( ( iln == 1 ) && ( dbg_print == 1 ) )
619 printf(
"%s, %d: lin %d, pix %d, INITIAL lon %f, lat %f, senz %f, sena %f, solz %f, sola %f, relaz %f\n",
620 __FILE__, __LINE__, iln, ipx,
621 (*tdat)[ foff + ipx +
npix * iln ], (*tdat)[ foff + foff2 + ipx +
npix * iln ],
622 (*tdat)[ foff + 2 * foff2 + ipx +
npix * iln ],
623 (*tdat)[ foff + 3 * foff2 + ipx +
npix * iln ],
624 (*tdat)[ foff + 4 * foff2 + ipx +
npix * iln ],
625 (*tdat)[ foff + 5 * foff2 + ipx +
npix * iln ],
626 (*tdat)[ foff + 6 * foff2 + ipx +
npix * iln ] );
630 (*tdat)[ foff + ipx +
npix * iln ] =
out;
632 (*tdat)[ foff + foff2 + ipx +
npix * iln ] =
out;
635 (*tdat)[ foff + 2 * foff2 + ipx +
npix * iln ] =
out;
637 (*tdat)[ foff + 3 * foff2 + ipx +
npix * iln ] =
out;
639 (*tdat)[ foff + 4 * foff2 + ipx +
npix * iln ] =
out;
641 (*tdat)[ foff + 5 * foff2 + ipx +
npix * iln ] =
out;
643 (*tdat)[ foff + 6 * foff2 + ipx +
npix * iln ] = -
out;
645 if( ( iln == 1 ) && ( dbg_print == 1 ) )
647 printf(
"%s, %d: lin %d, pix %d, FINAL lon %f, lat %f, senz %f, sena %f, solz %f, sola %f, relaz %f\n",
648 __FILE__, __LINE__, iln, ipx,
649 (*tdat)[ foff + ipx +
npix * iln ], (*tdat)[ foff + foff2 + ipx +
npix * iln ],
650 (*tdat)[ foff + 2 * foff2 + ipx +
npix * iln ],
651 (*tdat)[ foff + 3 * foff2 + ipx +
npix * iln ],
652 (*tdat)[ foff + 4 * foff2 + ipx +
npix * iln ],
653 (*tdat)[ foff + 5 * foff2 + ipx +
npix * iln ],
654 (*tdat)[ foff + 6 * foff2 + ipx +
npix * iln ] );
669 "-E- %s %d: Ancillary profile required for cloud processing is missing\n",
674 for( iln = 0; iln <
nlin; iln++ )
676 qln = iln + ctr_que -
nlin / 2;
677 for( ipx = 0; ipx <
npix; ipx++ )
679 memcpy( merra_p, merra_p_set, nlvl *
sizeof(
float) );
680 for( ilvl = 0; ilvl < nlvl; ilvl++ )
684 merra_t[ nlvl - 1 - ilvl ] =
l1que.r[qln].anc_add->prof_temp[ ilvl + nlvl * ipx ];
685 merra_q[ nlvl - 1 - ilvl ] =
l1que.r[qln].anc_add->prof_q[ ilvl + nlvl * ipx ];
686 merra_h[ nlvl - 1 - ilvl ] =
l1que.r[qln].anc_add->prof_height[ ilvl + nlvl * ipx ];
689 int tpix = 2, tlin = 1;
690 if( (ipx == tpix) && ( iln == tlin ) && ( dbg_print == 1 ) )
692 printf(
"\n\n%s, %d: merra_p for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
693 for( ilvl = 0; ilvl < nlvl; ilvl++ )
694 printf(
"%f ", merra_p[ilvl] );
697 printf(
"%s, %d: merra_t for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
698 for( ilvl = 0; ilvl < nlvl; ilvl++ )
699 printf(
"%f ", merra_t[ilvl] );
702 printf(
"%s, %d: merra_q for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
703 for( ilvl = 0; ilvl < nlvl; ilvl++ )
704 printf(
"%f ", merra_q[ilvl] );
707 printf(
"%s, %d: merra_h for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
708 for( ilvl = 0; ilvl < nlvl; ilvl++ )
709 printf(
"%f ", merra_h[ilvl] );
717 memcpy( cmp_p, cmp_p_set, nlvl_cmp *
sizeof(
double) );
724 l1que.r[qln].sfct[ipx],
l1que.r[qln].sfcrh[ipx],
725 l1que.r[qln].lat[ipx], &sfc_lvl, &trop_lvl, cmp_p, cmp_t,
731 l1que.r[qln].sfct[ipx],
l1que.r[qln].sfcrh[ipx],
732 l1que.r[qln].lat[ipx], &sfc_lvl, &trop_lvl, cmp_p, cmp_t,
736 sfc_lvl = ( sfc_lvl == nlvl_cmp ) ? sfc_lvl : sfc_lvl + 1;
737 trop_lvl = ( trop_lvl == nlvl_cmp ) ? trop_lvl : trop_lvl + 1;
781 if( ( ipx == tpix ) && ( iln == tlin ) && ( dbg_print == 1 ) )
783 printf(
"/n%s, %d: mix, t, p, h profiles BEFORE, pix %d, lin %d\n", __FILE__, __LINE__, ipx, iln );
785 printf(
"OUR sfcp: %f, sfct: %f\n",
l1que.r[qln].sfcp[ipx],
l1que.r[qln].sfct[ipx] );
786 printf(
"mk_cmp_prof sfc_lvl: %d, trop_lvl: %d\n", sfc_lvl, trop_lvl );
788 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
790 (*tdat)[foff + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_mixr[ilvl];
791 foff2 = foff +
npix *
nlin * nlvl_cmp;
792 (*tdat)[foff2 + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_t[ilvl];
793 foff2 = foff + 2 *
npix *
nlin * nlvl_cmp;
794 (*tdat)[foff2 + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_p[ilvl];
795 foff2 = foff + 3 *
npix *
nlin * nlvl_cmp;
796 (*tdat)[foff2 + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_h[ilvl];
802 foff2 = foff + 4 *
npix *
nlin * nlvl_cmp;
803 (*tdat)[foff2 + ipx +
npix * iln ] = 273.15 +
l1que.r[qln].sfct[ipx];
806 (*tdat)[foff2 + ipx +
npix * iln ] =
l1que.r[qln].sfcp[ipx];
809 (*tdat)[foff2 + ipx +
npix * iln ] =
l1que.r[qln].ws[ipx];
812 (*tdat)[foff2 + ipx +
npix * iln ] = 1.e3 *
l1que.r[qln].oz[ipx];
814 is_land =
l1que.r[qln].land[ipx];
820 (*tdat)[foff2 + ipx +
npix * iln ] = ( is_land ) ? 0. :
821 l1que.r[qln].icefr[ipx];
824 (*tdat)[foff2 + ipx +
npix * iln ] = ( is_land ) ?
825 l1que.r[qln].icefr[ipx] : 0;
828 (*tdat)[foff2 + ipx +
npix * iln ] = 1.e3 *
l1que.r[qln].oz[ipx];
835 (*tdat)[foff2 + ipx +
npix * iln ] =
l1que.r[qln].icefr[ipx];
838 (*tdat)[foff2 + ipx +
npix * iln ] =
839 l1que.r[qln].cld_dat->sfc_albedo_659[ipx];
841 (*tdat)[foff2 + ipx +
npix * iln ] =
842 l1que.r[qln].cld_dat->sfc_albedo_858[ipx];
844 (*tdat)[foff2 + ipx +
npix * iln ] =
845 l1que.r[qln].cld_dat->sfc_albedo_1240[ipx];
847 (*tdat)[foff2 + ipx +
npix * iln ] =
848 l1que.r[qln].cld_dat->sfc_albedo_1640[ipx];
850 (*tdat)[foff2 + ipx +
npix * iln ] =
851 l1que.r[qln].cld_dat->sfc_albedo_2130[ipx];
853 if( ( sensor_id ==
OCIS ) || ( sensor_id ==
OCI ) )
856 (*tdat)[foff2 + ipx +
npix * iln ] =
857 l1que.r[qln].cld_dat->sfc_albedo_2130[ipx];
861 (*tdat)[foff2 + ipx +
npix * iln ] =
864 (*tdat)[foff2 + ipx +
npix * iln ] =
867 (*tdat)[foff2 + ipx +
npix * iln ] =
874 (*ubdat)[ uoff + ipx +
npix * iln ] = sfc_lvl;
876 (*ubdat)[ uoff2 + ipx +
npix * iln ] = trop_lvl;
880 (*i32dat)[ ipx +
npix * iln ] = 100 *
l1que.r[qln].icefr[ipx];
887 bad_rad = (
l1que.r[qln].Lt[l1ix[0]+nbnd_ref * ipx] ==
BAD_INT ) ? 1 : 0;
888 cld_flg =
l1que.r[qln].cloud[ipx];
889 ice_flg =
l1que.r[qln].ice[ipx];
890 glint_flg =
l1que.r[qln].glint[ipx];
891 npix_scan =
l1que.r[qln].npix;
892 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( bad_rad == 0 ) ? 1 : 0;
901 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
905 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category == 0 ) ? 1 : 0;
907 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category == 1 ) ? 1 : 0;
909 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category == 2 ) ? 1 : 0;
911 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category >= 3 ) ? 1 : 0;
916 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_flg != 0 ) ? 1 : 0;
918 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_flg != 0 ) ? 1 : 0;
920 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_flg != 0 ) ? 1 : 0;
922 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
926 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
927 ( ( is_land == 1 ) && ( ice_flg == 1 ) ) ? 1 : 0;
930 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( is_land == 0 ) ? 1 : 0;
933 lst = ( iln < 1 ) ? iln : iln - 1;
934 len = ( iln >= (
nlin - 1 ) ) ? iln : iln + 1;
935 pst = ( ipx <= 0 ) ? 0 : ipx -1;
936 pen = ( ipx >= ( npix_scan - 1 ) ) ? ipx : ipx + 1;
937 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
940 for( aln = lst; aln <= len; aln++ )
941 for( apx = pst; apx <= pen; apx++ )
944 if(
l1que.r[aln].land[apx] ) nland++;
946 if( ( nland != 0 ) && ( nland != itot ) )
947 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 1;
950 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
953 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( is_land ) ? 1 : 0;
956 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
957 (
l1que.r[iln].solz[ipx] > 90. ) ? 1 : 0;
960 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
961 ( glint_flg ) ? 1 : 0;
964 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
965 ( ( is_land == 0 ) && ( ice_flg == 0 ) ) ? 1 : 0;
968 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
969 ( ( is_land == 0 ) && ( ice_flg == 1 ) ) ? 1 : 0;
972 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
973 ( ( is_land == 1 ) && ( ice_flg == 0 ) ) ? 1 : 0;
976 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
977 ( ( is_land == 1 ) && ( ice_flg == 1 ) ) ? 1 : 0;
980 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
983 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
986 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
989 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
992 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
995 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
998 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
1001 if( ( ipx == tpix ) && ( iln == tlin ) && ( dbg_print == 1 ) )
1003 printf(
"/n%s, %d: mix, t, p, h profiles AFTER, pix %d, lin %d\n", __FILE__, __LINE__, ipx, iln );
1015 memcpy( ( *ubdat + 25 *
npix *
nlin ), cmp_there, ncmp_bnd );
1021 int32_t ipx, int32_t iln, int32_t
npix, int32_t
nlin )
1050 printf(
"mixr profile\n" );
1051 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
1053 printf(
"%f ", prof[ ipx +
npix * ( iln +
nlin * ilvl ) ] );
1055 printf(
"\nT profile\n" );
1057 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
1059 printf(
"%f ", prof[ off + ipx +
npix * ( iln +
nlin * ilvl ) ] );
1061 printf(
"\nPRESS profile\n" );
1063 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
1065 printf(
"%f ", prof[ off + ipx +
npix * ( iln +
nlin * ilvl ) ] );
1067 printf(
"\nHEIGHT profile\n" );
1069 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
1071 printf(
"%f ", prof[ off + ipx +
npix * ( iln +
nlin * ilvl ) ] );
1076 printf(
"TSFC: %f, ", prof[ off + ipx +
npix * iln] );
1078 printf(
"PSFC: %f, ", prof[ off + ipx +
npix * iln] );
1080 printf(
"WIND SP: %f, ", prof[ off + ipx +
npix * iln] );
1082 printf(
"O3: %f\n", prof[ off + ipx +
npix * iln] );
1085 printf(
"ICE FR: %f, ", prof[ off + ipx +
npix * iln] );
1087 printf(
"SNO FR: %f, ", prof[ off + ipx +
npix * iln] );
1089 printf(
"ALT O3: %f, ", prof[ off + ipx +
npix * iln] );
1091 printf(
"ALT ICEC: %f\n", prof[ off + ipx +
npix * iln] );
1095 printf(
"SFC_LVL: %d, ", ubdat[ off + ipx +
npix * iln ] );
1097 printf(
"TROP_LVL: %d\n", ubdat[ off + ipx +
npix * iln ] );
1099 printf(
"ALT ICE: %d\n", i32dat[ ipx +
npix * iln ] );
1102 printf(
"---- Cloud Mask values ----\n" );
1103 printf(
"CLD_DET: %d, ", ubdat[ off + ipx +
npix * iln ] );
1105 printf(
"CONF_CLD: %d, ", ubdat[ off + ipx +
npix * iln ] );
1107 printf(
"CLR_66: %d, ", ubdat[ off + ipx +
npix * iln ] );
1109 printf(
"CLR_95: %d\n", ubdat[ off + ipx +
npix * iln ] );
1111 printf(
"CLR_99: %d, ", ubdat[ off + ipx +
npix * iln ] );
1113 printf(
"SNO_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1115 printf(
"WTR_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1117 printf(
"COAST_SFC: %d\n", ubdat[ off + ipx +
npix * iln ] );
1119 printf(
"DESERT_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1121 printf(
"LND_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1123 printf(
"NIGHT: %d, ", ubdat[ off + ipx +
npix * iln ] );
1125 printf(
"GLINT: %d\n", ubdat[ off + ipx +
npix * iln ] );
1127 printf(
"OCEAN_NO_SNOW: %d, ", ubdat[ off + ipx +
npix * iln ] );
1129 printf(
"OCEAN_SNOW: %d, ", ubdat[ off + ipx +
npix * iln ] );
1131 printf(
"LND_NO_SNOW: %d, ", ubdat[ off + ipx +
npix * iln ] );
1133 printf(
"LND_SNOW: %d\n", ubdat[ off + ipx +
npix * iln ] );
1135 printf(
"TST_H_138: %d, ", ubdat[ off + ipx +
npix * iln ] );
1137 printf(
"TST_VIS_REFL: %d, ", ubdat[ off + ipx +
npix * iln ] );
1139 printf(
"TST_VIS_RATIO: %d, ", ubdat[ off + ipx +
npix * iln ] );
1141 printf(
"VIS_CLD_250: %d\n", ubdat[ off + ipx +
npix * iln ] );
1143 printf(
"APPL_HCLD_138: %d, ", ubdat[ off + ipx +
npix * iln ] );
1145 printf(
"APPL_VIS_REFL: %d, ", ubdat[ off + ipx +
npix * iln ] );
1147 printf(
"APPL_VIS_NIR_RATIO: %d\n", ubdat[ off + ipx +
npix * iln ] );
1154 float *merra_h,
float sfcp,
float sfct,
float sfcrh,
float lat,
1155 unsigned char *sfc_lvl,
unsigned char *trop_lvl,
double *cmp_p,
1156 double *cmp_t,
double *cmp_mixr,
double *cmp_h )
1159 double cmp_t_sav[] = {169.25176566420146, 197.35942572651811, 229.18349451149692, 256.22238210609601, 236.47864107966123, 244.04297143175555, 250.64605396062848, 255.49783596464286, 259.17682096634508, 260.50430632229126, 257.86788008325004, 255.09753268656993, 251.71866532458688, 246.82264824496451, 241.36301970269031, 235.5349625222656, 231.00564672010188, 230.31934481415178, 230.00717490122784, 230.93984650147675, 231.87556038742846, 230.052070835427, 226.94875351064999, 223.97554681909486, 221.12246382681033, 218.38062746953614, 216.05483908715939, 214.30433557126059, 212.6156777870857, 210.98488863951465, 209.57034993410883, 208.26534656680437, 207.00140487891071, 205.76477951859837, 204.56229701519121, 202.84595260841155, 200.1528837094385, 197.5345872033561, 194.98734605240188, 193.13906753041528, 192.9482175288388, 192.76222219178675, 192.58086243374066, 192.4039337826197, 193.53690804615815, 196.34328186967463, 199.08486131023724, 201.76426680177968, 204.38396142841776, 206.94626326403974, 209.4240557622999, 211.67158053966773, 213.87221009140157, 216.02762928535265, 218.13943261959307, 220.23999924343335, 222.60373354556071, 224.92166874653532, 227.195309078017, 229.42608466977327, 232.27719286025973, 235.2490670940424, 238.1670467211311, 241.03276062011722, 243.91780941249539, 246.75240714620259, 249.53800835678237, 251.86502860055904, 253.8587763082154, 255.81919333430849, 257.63971457966039, 259.29891772708743, 260.9312384604865, 262.72494342240276, 264.64753610551918, 266.53988144929855, 268.11359331445857, 269.60080666913444, 271.01286592906087, 272.25331134687139, 273.4751007120372, 274.88788770642338, 276.32402654921054, 277.67617255366838, 278.94743905007527, 280.29684643297759, 281.87085668556011, 283.47072360439103, 285.24727818913414, 286.9975584364218, 288.51282458375113, 289.86087429979796, 290.9986136887851, 292.01521247752953, 292.98262145756013, 294.3041990659554, 296.79569609374886, 298.98862037321277, 299.76233992810609, 300.50664057118684, 301.24118800223761};
1160 double cmp_mixr_sav[] = {0.0030000000000000001, 0.0030000000000000001, 0.0030000000000000001, 0.0030000000000000001, 0.0039293894442529974, 0.0041105013907719468, 0.0042181900744832808, 0.0042143496342834938, 0.0041817655664085482, 0.0040206101090032517, 0.0038733849643674614, 0.0037377625227534746, 0.0036014648248259636, 0.0034516475997961819, 0.0033167026788735537, 0.0031947714963073749, 0.0030799596646610928, 0.0030107622372746654, 0.0029488582454394335, 0.0028982059410255015, 0.0028502657213637195, 0.0027944201318237261, 0.002735964452701974, 0.0026799596042977963, 0.0026262174675935851, 0.0025745708296473057, 0.0025405554258138494, 0.0025323804296621087, 0.0025244942581909551, 0.0025168783380373483, 0.0025258323028017112, 0.0025409217199495382, 0.0025555363514953174, 0.0025643709192777427, 0.0025716416839911219, 0.0025546327064356832, 0.0024931393172969081, 0.002433353276920958, 0.0023751897106692147, 0.0023510380165387293, 0.0024102799348228623, 0.0024680149123855986, 0.0025243109557570816, 0.0025792315352972882, 0.0028074932565275365, 0.0032578001900602956, 0.0036977103048750353, 0.004127644072243016, 0.004547996715297346, 0.0049591401890269129, 0.0066045793017774166, 0.015756209535939904, 0.024716888476006896, 0.033493476685974542, 0.042092466755785318, 0.053504463790107065, 0.094126872282568774, 0.13396219155187214, 0.17303627285925954, 0.21137369397371381, 0.2419968812989492, 0.27022626866094007, 0.2979437192418275, 0.32516470551490928, 0.47386770138225009, 0.6199703171142984, 0.76354752329508391, 1.0340410272474989, 1.3924930017834096, 1.7449525187114237, 1.9710464191297217, 2.0459308727278538, 2.1196020481996749, 2.5849697692954705, 3.3725913913975889, 4.1478216949005233, 4.7278626505249006, 5.2595586368380491, 5.6780053593354278, 5.7887852404941018, 5.897899014248777, 6.0126629733222074, 6.1272686176990323, 6.2612715902934664, 6.4138250668383652, 6.5300489624532512, 6.6239450570569449, 7.0237148492647679, 7.815759173341303, 8.9338062006928265, 10.017175527482264, 10.798574208009653, 11.482688439271284, 12.855657707404751, 14.06097496976534, 15.451677990360071, 8.9087798522868766, 0.078892832367705168, 0.0013115547243546515, 0.0021613451297737749, 0.0030000000000000001};
1161 double cmp_h_sav[] = {80980.567272357701, 75343.876190403083, 70225.982411112418, 65480.628319062816, 61428.924238065607, 58024.80202191414, 54950.191567802227, 52150.37234583289, 49587.069685576469, 47234.584895480606, 45084.856633888245, 43122.927977172032, 41324.952076504, 39676.318479632821, 38164.924587601548, 36777.388481093178, 35497.403939587413, 34300.298902152295, 33167.424793334678, 32088.91680780418, 31057.094888806638, 30073.813431125316, 29143.272510847557, 28263.483356793786, 27430.050001579777, 26639.098949354469, 25886.659507298184, 25168.400851046954, 24481.003799506794, 23822.279970437601, 23190.014293749664, 22582.119678830768, 21996.942353189086, 21433.083441024752, 20889.269993475449, 20365.028820377422, 19861.183794284312, 19377.767922145697, 18913.565376345625, 18466.731479797825, 18033.779798131261, 17612.242600176087, 17201.593473696255, 16801.341547642598, 16409.703419308389, 16023.364531449324, 15640.568137969527, 15261.317752839021, 14885.61129854926, 14513.441856962587, 14144.824125415456, 13779.920194073944, 13418.849581909997, 13061.570770637654, 12708.041363820343, 12358.193358432209, 12011.718940291992, 11668.35429065583, 11328.08453068694, 10990.892967344218, 10656.282389846725, 10323.666245846885, 9992.9598216377744, 9664.201332244118, 9337.3653911268993, 9012.4264031402581, 8689.4162094312233, 8368.613449980001, 8050.4524006411266, 7735.0947019042451, 7422.5961680835417, 7113.1000037295735, 6806.6644285353668, 6503.107856676912, 6202.1379607025819, 5903.6184955729223, 5607.7124190540144, 5314.6091843005188, 5024.3518657619488, 4737.0487534217273, 4452.7644388850267, 4171.3480686550502, 3892.6336221371671, 3616.5978083090913, 3343.2676087364471, 3072.5944718766254, 2804.3890955354977, 2538.46734163782, 2274.6417716957349, 2012.7539832113782, 1752.8699864080911, 1495.1635489650282, 1239.7954748266484, 986.82637292768879, 736.25029352497961, 487.89682088402327, 241.65371459693083, 0, -243.21093547707787, -481.72170087446557, 0};
1164 for(
i = 0;
i < 101;
i++ )
1166 *(cmp_t +
i) = *(cmp_t_sav +
i);
1167 *(cmp_mixr +
i) = *(cmp_mixr_sav +
i);
1168 *(cmp_h +
i) = *(cmp_h_sav +
i);
1174 float *merra_h,
float sfcp,
float sfct,
float sfcrh,
float lat,
1175 unsigned char *sfc_lvl,
unsigned char *trop_lvl,
double *cmp_p,
1176 double *cmp_t,
double *cmp_mixr,
double *cmp_h )
1178 unsigned char get_trop(
double *,
double *,
unsigned char );
1182 double *,
double *,
double *,
int * );
1183 int32_t nlvl = 42, nlvl_cmp = 101, ioz = 0, ilvl, kstart;
1184 int32_t nlvl_d = nlvl + 1;
1185 float oval, a_factor;
1186 double p_init[nlvl_d], lcl_p[nlvl_d], lcl_t[nlvl_d];
1187 double lcl_w[nlvl_d], lcl_h[nlvl_d], lat_d, sfcp_d;
1201 for( ilvl = 0; ilvl < nlvl; ilvl++ )
1203 merra_q[ilvl] = 1000. * merra_q[ilvl] / ( 1. - merra_q[ilvl]);
1204 merra_t[ilvl] += 273.15;
1215 sfcrh = oval / ( 1. - oval );
1218 for( ilvl = 0; ilvl < nlvl; ilvl++ )
1220 lcl_p[ilvl] = merra_p[ilvl];
1221 lcl_t[ilvl] = merra_t[ilvl];
1222 lcl_w[ilvl] = merra_q[ilvl];
1223 lcl_h[ilvl] = merra_h[ilvl];
1225 if( lcl_t[ilvl] < 0. )
1227 lcl_t[ilvl] = lcl_t[ ilvl - 1 ];
1228 lcl_w[ilvl] = lcl_w[ ilvl - 1 ];
1229 lcl_h[ilvl] = lcl_h[ ilvl - 1 ];
1232 lcl_p[nlvl] = 1100.;
1233 lcl_t[nlvl] = lcl_t[ nlvl - 1 ];
1234 lcl_w[nlvl] = lcl_w[ nlvl - 1 ];
1235 lcl_h[nlvl] = lcl_h[ nlvl - 1 ];
1241 memcpy( p_init, lcl_p, nlvl_d *
sizeof(
double) );
1244 if( ( sfcp > 0 ) && ( lcl_p[ nlvl_d - 2 ] > sfcp ) )
1245 *sfc_lvl = nlvl_d - 1;
1251 kstart = nlvl_d / 2;
1253 for( ilvl = kstart; ilvl < nlvl_d; ilvl++ )
1255 if( ( sfcp > 0 ) && ( lcl_p[ilvl] > sfcp ) )
1263 if( ( sfcp - lcl_p[ ilvl - 1 ] < 5. ) ||
1264 ( lcl_p[ilvl] - sfcp < 5. ) )
1266 lcl_p[ilvl] = ( lcl_p[ilvl] + lcl_p[ ilvl - 1 ] ) / 2.;
1272 lcl_w[ilvl] = sfcrh;
1277 lcl_w[ilvl] = sfcrh;
1278 lcl_p[ilvl] = p_init[ ilvl - 1 ];
1283 if( *sfc_lvl != nlvl_d )
1284 merra_p[ nlvl_d - 1 ] = p_init[ ilvl - 1 ];
1286 lcl_p[ nlvl - 1 ] = sfcp;
1287 lcl_t[ nlvl - 1 ] = sfct;
1288 lcl_w[ nlvl - 1 ] = sfcrh;
1291 kstart = nlvl_cmp / 2;
1292 for( ilvl = kstart; ilvl < nlvl_cmp; ilvl++ )
1294 if( cmp_p[ilvl] >= sfcp )
1306 a_factor = ( sfcp - cmp_p[ *sfc_lvl - 1 ] ) /
1307 ( cmp_p[*sfc_lvl] - cmp_p[ *sfc_lvl - 1 ] );
1308 cmp_t[*sfc_lvl] = cmp_t[ *sfc_lvl - 1 ] + a_factor *
1309 ( cmp_t[*sfc_lvl] - cmp_t[ *sfc_lvl - 1 ] );
1310 cmp_mixr[*sfc_lvl] = cmp_mixr[ *sfc_lvl - 1 ] + a_factor *
1311 ( cmp_mixr[*sfc_lvl] - cmp_mixr[ *sfc_lvl - 1 ] );
1313 cmp_p[*sfc_lvl] = sfcp;
1317 cmp_h[nlvl_cmp - 1 ] = 0.;
1320 *trop_lvl =
get_trop( cmp_t, cmp_p, *sfc_lvl );
1325 unsigned char get_trop(
double *cmp_t,
double *cmp_p,
unsigned char sfc_lvl )
1327 unsigned char trop_lvl;
1329 float xmin, ptop = 100.;
1334 for( ilev = 0; ilev < sfc_lvl - 5; ilev++ )
1336 if( ( cmp_t[ilev] < xmin ) && ( cmp_p[ilev] > ptop ) )
1345 for( ilev = imin; ilev < 71; ilev++ )
1347 if( ( cmp_t[ ilev - 1 ] >= cmp_t[ilev] ) &&
1348 ( cmp_t[ ilev + 1 ] > cmp_t[ilev] ) )
1355 if( trop_lvl == 200 ) trop_lvl = imin;
1388 if ((
status = nc_inq_varid(ncid, ds_name, &var_id)) != NC_NOERR) {
1389 printf(
"%s, %d: nc_inq_varid returned error %d\n", __FILE__, __LINE__,
1396 if ((
status = nc_get_var_uchar(ncid, var_id,
data)) != NC_NOERR) {
1397 printf(
"%s, %d: nc_get_var_uchar returned error %d\n",
1398 __FILE__, __LINE__,
status);
1432 if ((
status = nc_inq_varid(ncid, ds_name, &var_id)) != NC_NOERR) {
1433 printf(
"%s, %d: nc_inq_varid returned error %d\n", __FILE__, __LINE__,
1440 if ((
status = nc_get_var_int(ncid, var_id, (int32_t *)
data)) != NC_NOERR) {
1441 printf(
"%s, %d: nc_get_var_int returned error %d\n",
1442 __FILE__, __LINE__,
status);