8 extern void ch_cld_sci_(
float *,
int *,
unsigned char *,
int *,
9 int32_t *,
int *,
int *,
char * );
38 static int32_t cur_cmp_rec = -1;
40 int get_cmp( l2str *l2rec,
int prodnum,
float prod[])
59 void get_cmp_prod_(
int *,
float *,
int * );
62 if(
input->proc_cloud == 0 ) {
63 printf(
"%s, %d: Cloud products require the proc_cloud=1 set\n", __FILE__,
68 if( l2rec->l1rec->iscan != cur_cmp_rec )
70 cur_cmp_rec = l2rec->l1rec->iscan;
73 printf(
"%s, %d: E - CMP computation failure\n", __FILE__, __LINE__ );
84 if( ( prodnum >= 480 ) && ( prodnum <= 482 ) ) n_prd = 10;
85 get_cmp_prod_( &prodnum, prod, &n_prd );
94 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
95 if( *( prod + ipix ) < -900 )
96 l2rec->l1rec->flags[ipix] |=
PRODFAIL;
104 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
105 if( *( prod + ipix ) < -900 )
106 l2rec->l1rec->flags[ipix] |=
PRODWARN;
111 for( ipix = 0; ipix < l2rec->l1rec->npix; ipix++ )
112 if( *( prod + ipix ) < -900 )
113 l2rec->l1rec->flags[ipix] |=
NAVFAIL;
135 static unsigned char *bprod =
NULL;
136 void get_cmp_byt_(
int *,
unsigned char * );
138 if( l2rec->l1rec->iscan != cur_cmp_rec )
140 cur_cmp_rec = l2rec->l1rec->iscan;
143 printf(
"%s, %d: E - CMP computation failure\n", __FILE__, __LINE__ );
150 if( ( bprod = (
unsigned char *)
151 malloc( l2rec->l1rec->npix *
sizeof(
unsigned char) ) ) ==
NULL )
153 printf(
"%s, %d: E - unable to alocate byte storage\n",
154 __FILE__, __LINE__ );
162 get_cmp_byt_( &prodnum, bprod );
176 int set_cmp( l2str *,
float **, int32_t *, int32_t **, int32_t *,
177 unsigned char **, int32_t * );
178 int32_t nfloat, nint32, nubyte;
180 static unsigned char *ubdat;
181 static int32_t *i32dat;
182 int sensor_id = l2rec->l1rec->l1file->sensorID;
186 if(
set_cmp( l2rec, &tdat, &nfloat, &i32dat, &nint32, &ubdat, &nubyte ) != 0 )
192 ch_cld_sci_( tdat, &nfloat, ubdat, &nubyte, i32dat, &nint32, &sensor_id,
193 input->cloud_hgt_file );
198 int set_cmp( l2str *l2rec,
float **tdat, int32_t *nfloat, int32_t **i32dat,
199 int32_t *nint32,
unsigned char **ubdat, int32_t *nubyte )
207 int mk_cmp_prof(
float *,
float *,
float *,
float *,
float,
float,
float,
208 float,
unsigned char *,
unsigned char *,
double *,
double *,
double *,
211 int mk_cmp_prof_dum(
float *,
float *,
float *,
float *,
float,
float,
float,
212 float,
unsigned char *,
unsigned char *,
double *,
double *,
double *,
216 l1str *
l1rec = l2rec->l1rec;
217 int32_t nbnd_ref, nbnd_emis, foff, foff2, uoff, uoff2,
nbnd, sensor_id;
219 int32_t dbg_print, ix_bnd, force_oci, cld_missed;
220 int32_t ncmp_bnd = 15;
222 int profile_print(
float *,
unsigned char *, int32_t *, int32_t, int32_t,
229 int32_t ref_for_cmb[] = { 1, 1, 1, 1, 1, 1, 0, 2, 0, 0, 1, 0, 0, 1, 1 };
231 static char cmp_there[15];
233 static int32_t l1ix[15];
235 int32_t cld_wav_mod[] = { 645, 859, 1240, 1640, 2130, 930, 3750, 1375,
236 8550, 11000, 443, 12000, 13600, 469, 555 };
241 int32_t cld_wav_oci[] = { 665, 865, 1250, 1616, 2130, 930, 3750, 1375,
242 8550, 11000, 443, 12000, 13600, 469, 555 };
245 int32_t oci_bnd_avail[] = { 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1 };
247 int32_t cld_min_bnd[] = { 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1 };
253 float chim_rad_corr[] = { 1.0, 1.0, 1.0, 1.0, 1.0,
258 -1., 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
265 static int32_t firstcall = 0;
271 int32_t nlvl = 42, nlvl_cmp = 101, ilvl, is_land, cld_flg;
272 int32_t bad_rad, ice_flg, glint_flg;
273 int32_t npix_scan, lst, len, pst, pen, apx, aln, itot, nland;
274 unsigned char sfc_lvl, trop_lvl;
275 float merra_p_set[] = { 0.1, 0.3, 0.4, 0.5, 0.7, 1., 2., 3., 4., 5., 7., 10.,
276 20., 30., 40., 50., 70., 100., 150., 200., 250., 300., 350., 400.,
277 450., 500., 550., 600., 650., 700., 725., 750., 775., 800., 825.,
278 850., 875., 900., 925., 950., 975., 1000. };
279 float merra_t[nlvl], merra_p[nlvl], merra_q[nlvl], merra_h[nlvl];
280 double cmp_t[nlvl_cmp], cmp_mixr[nlvl_cmp], cmp_h[nlvl_cmp];
281 double cmp_p[nlvl_cmp], cmp_p_set[nlvl_cmp];
287 ctr_que =
l1que.nq / 2;
318 nbnd_ref =
l1rec->l1file->nbands;
319 nbnd_emis =
l1rec->l1file->nbandsir;
320 sensor_id =
l1rec->l1file->sensorID;
324 if( ( *tdat = (
float *) malloc( *nfloat *
sizeof(
float) ) ) ==
NULL )
326 printf(
"%s - %d: Allocation of real storage failed\n",
327 __FILE__, __LINE__ );
336 if( ( *ubdat = (
unsigned char *)
337 malloc( *nubyte *
sizeof(
unsigned char) ) ) ==
NULL )
339 printf(
"%s - %d: Allocation of byte storage failed\n",
340 __FILE__, __LINE__ );
347 if( ( *i32dat = (int32_t *) malloc( *nint32 *
sizeof(int32_t) ) ) ==
NULL )
349 printf(
"%s - %d: Allocation of i32 storage failed\n",
350 __FILE__, __LINE__ );
356 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
357 cld_wav[ibnd] = ( sensor_id ==
OCIS ) ?
358 cld_wav_oci[ibnd] : cld_wav_mod[ibnd];
360 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
363 if( ( ix_bnd < 0 ) && ( ref_for_cmb[ibnd] != 2 ) )
372 if( ref_for_cmb[ibnd] == 0 )
374 else if( ref_for_cmb[ibnd] == 1 )
384 printf(
"OCI band forcing is set to %d\n", force_oci );
387 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
388 cmp_there[ibnd] *= oci_bnd_avail[ibnd];
395 printf(
"Talley of current instrument's wavelengths\n" );
396 printf(
"Cloud wave is wave is\n" );
397 printf(
"wavelength available required\n" );
399 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
401 if( ( cld_min_bnd[ibnd] == 1 ) && ( cmp_there[ibnd] == 0 ) )
403 printf(
"%10d %9d %8d\n", cld_wav[ibnd], cmp_there[ibnd],
406 if( cld_missed == 1 )
408 printf(
"%s, %d: The required wavelengths for cloud processing were not found, Exiting\n", __FILE__, __LINE__ );
416 for( ibnd = 0; ibnd < ncmp_bnd; ibnd++ )
418 for( iln = 0; iln <
nlin; iln++ )
420 qln = iln + ctr_que -
nlin / 2;
421 for( ipx = 0; ipx <
npix; ipx++ )
424 if( ( iln == 1) && ( dbg_print == 1 ) )
426 printf(
"%s, %d: bnd %d, lin %d, pix %d, rad %f\n",
427 __FILE__, __LINE__, ibnd, iln, ipx,
428 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] );
431 if( cmp_there[ibnd] == 1 )
434 if( ref_for_cmb[ibnd] == 1 )
436 rad =
l1que.r[qln].Lt[ l1ix[ ibnd ] + nbnd_ref * ipx ];
438 out = rad *
PI / ( cos(
solz *
PI / 180. ) *
F0[ l1ix[ ibnd ] ] );
439 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] =
440 chim_rad_corr[ibnd] *
out;
442 else if( ref_for_cmb[ibnd] == 2 )
445 rad =
l1que.r[qln].rho_cirrus[ipx];
446 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] =
447 chim_rad_corr[ibnd] * rad * cos(
solz *
PI / 180. );
451 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] =
452 chim_rad_corr[ibnd] *
453 10. *
l1que.r[qln].Ltir[ ( l1ix[ ibnd ] - nbnd_ref ) +
460 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] = -999.0;
463 if( ( iln == 1 ) && (dbg_print == 1 ) )
465 printf(
"%s, %d: bnd %d, lin %d, pix %d, rad %f\n",
466 __FILE__, __LINE__, ibnd, iln, ipx,
467 (*tdat)[ ipx +
npix * ( ibnd + ncmp_bnd * iln ) ] );
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, UNC %f\n",
503 __FILE__, __LINE__, ibnd, iln, ipx,
510 if( ( iln == 1 ) && (dbg_print == 1 ) )
512 printf(
"%s, %d: bnd %d, lin %d, pix %d, UNC %f\n",
513 __FILE__, __LINE__, ibnd, iln, ipx,
527 (*tdat)[ foff + ibnd ] = 0.;
528 (*tdat)[ foff2 + ibnd ] = 1.;
536 for( iln = 0; iln <
nlin; iln++ )
538 qln = iln + ctr_que -
nlin / 2;
539 for( ipx = 0; ipx <
npix; ipx++ )
541 if( ( iln == 1 ) && ( dbg_print == 1 ) )
543 printf(
"%s, %d: lin %d, pix %d, INITIAL lon %f, lat %f, senz %f, sena %f, solz %f, sola %f, relaz %f\n",
544 __FILE__, __LINE__, iln, ipx,
545 (*tdat)[ foff + ipx +
npix * iln ], (*tdat)[ foff + foff2 + ipx +
npix * iln ],
546 (*tdat)[ foff + 2 * foff2 + ipx +
npix * iln ],
547 (*tdat)[ foff + 3 * foff2 + ipx +
npix * iln ],
548 (*tdat)[ foff + 4 * foff2 + ipx +
npix * iln ],
549 (*tdat)[ foff + 5 * foff2 + ipx +
npix * iln ],
550 (*tdat)[ foff + 6 * foff2 + ipx +
npix * iln ] );
554 (*tdat)[ foff + ipx +
npix * iln ] =
out;
556 (*tdat)[ foff + foff2 + ipx +
npix * iln ] =
out;
559 (*tdat)[ foff + 2 * foff2 + ipx +
npix * iln ] =
out;
561 (*tdat)[ foff + 3 * foff2 + ipx +
npix * iln ] =
out;
563 (*tdat)[ foff + 4 * foff2 + ipx +
npix * iln ] =
out;
565 (*tdat)[ foff + 5 * foff2 + ipx +
npix * iln ] =
out;
567 (*tdat)[ foff + 6 * foff2 + ipx +
npix * iln ] = -
out;
569 if( ( iln == 1 ) && ( dbg_print == 1 ) )
571 printf(
"%s, %d: lin %d, pix %d, FINAL lon %f, lat %f, senz %f, sena %f, solz %f, sola %f, relaz %f\n",
572 __FILE__, __LINE__, iln, ipx,
573 (*tdat)[ foff + ipx +
npix * iln ], (*tdat)[ foff + foff2 + ipx +
npix * iln ],
574 (*tdat)[ foff + 2 * foff2 + ipx +
npix * iln ],
575 (*tdat)[ foff + 3 * foff2 + ipx +
npix * iln ],
576 (*tdat)[ foff + 4 * foff2 + ipx +
npix * iln ],
577 (*tdat)[ foff + 5 * foff2 + ipx +
npix * iln ],
578 (*tdat)[ foff + 6 * foff2 + ipx +
npix * iln ] );
590 for( iln = 0; iln <
nlin; iln++ )
592 qln = iln + ctr_que -
nlin / 2;
593 for( ipx = 0; ipx <
npix; ipx++ )
595 memcpy( merra_p, merra_p_set, nlvl *
sizeof(
float) );
596 for( ilvl = 0; ilvl < nlvl; ilvl++ )
600 merra_t[ nlvl - 1 - ilvl ] =
l1que.r[qln].anc_add->prof_temp[ ilvl + nlvl * ipx ];
601 merra_q[ nlvl - 1 - ilvl ] =
l1que.r[qln].anc_add->prof_q[ ilvl + nlvl * ipx ];
602 merra_h[ nlvl - 1 - ilvl ] =
l1que.r[qln].anc_add->prof_height[ ilvl + nlvl * ipx ];
605 int tpix = 2, tlin = 1;
606 if( (ipx == tpix) && ( iln == tlin ) && ( dbg_print == 1 ) )
608 printf(
"\n\n%s, %d: merra_p for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
609 for( ilvl = 0; ilvl < nlvl; ilvl++ )
610 printf(
"%f ", merra_p[ilvl] );
613 printf(
"%s, %d: merra_t for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
614 for( ilvl = 0; ilvl < nlvl; ilvl++ )
615 printf(
"%f ", merra_t[ilvl] );
618 printf(
"%s, %d: merra_q for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
619 for( ilvl = 0; ilvl < nlvl; ilvl++ )
620 printf(
"%f ", merra_q[ilvl] );
623 printf(
"%s, %d: merra_h for pix: %d, lin: %d\n", __FILE__, __LINE__, ipx, iln );
624 for( ilvl = 0; ilvl < nlvl; ilvl++ )
625 printf(
"%f ", merra_h[ilvl] );
633 memcpy( cmp_p, cmp_p_set, nlvl_cmp *
sizeof(
double) );
640 l1que.r[qln].sfct[ipx],
l1que.r[qln].sfcrh[ipx],
641 l1que.r[qln].lat[ipx], &sfc_lvl, &trop_lvl, cmp_p, cmp_t,
647 l1que.r[qln].sfct[ipx],
l1que.r[qln].sfcrh[ipx],
648 l1que.r[qln].lat[ipx], &sfc_lvl, &trop_lvl, cmp_p, cmp_t,
652 sfc_lvl = ( sfc_lvl == nlvl_cmp ) ? sfc_lvl : sfc_lvl + 1;
653 trop_lvl = ( trop_lvl == nlvl_cmp ) ? trop_lvl : trop_lvl + 1;
659 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
661 if( ( cmp_t[ilvl] > 350. ) || ( cmp_t[ilvl] < 100. ) )
663 printf(
"PROFILE ODD T: %f, iln: %d, ipx: %d, ilvl: %d\n",
664 cmp_t[ilvl], iln, ipx, ilvl );
666 if( ( cmp_mixr[ilvl] > 100. ) || ( cmp_mixr[ilvl] < 0 ) )
668 printf(
"PROFILE ODD MIXR: %f, iln: %d, ipx: %d, ilvl: %d\n",
669 cmp_mixr[ilvl], iln, ipx, ilvl );
671 if( ( cmp_h[ilvl] > 1000000. ) || ( cmp_h[ilvl] < -20000. ) )
673 printf(
"PROFILE ODD height: %f, iln: %d, ipx: %d, ilvl: %d\n",
674 cmp_h[ilvl], iln, ipx, ilvl );
676 if( ( cmp_p[ilvl] > 1200. ) || ( cmp_p[ilvl] < 0. ) )
678 printf(
"PROFILE ODD P: %f, iln: %d, ipx: %d, ilvl: %d\n",
679 cmp_p[ilvl], iln, ipx, ilvl );
693 if( ( ipx == tpix ) && ( iln == tlin ) && ( dbg_print == 1 ) )
695 printf(
"/n%s, %d: mix, t, p, h profiles BEFORE, pix %d, lin %d\n", __FILE__, __LINE__, ipx, iln );
697 printf(
"OUR sfcp: %f, sfct: %f\n",
l1que.r[qln].sfcp[ipx],
l1que.r[qln].sfct[ipx] );
698 printf(
"mk_cmp_prof sfc_lvl: %d, trop_lvl: %d\n", sfc_lvl, trop_lvl );
700 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
702 (*tdat)[foff + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_mixr[ilvl];
703 foff2 = foff +
npix *
nlin * nlvl_cmp;
704 (*tdat)[foff2 + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_t[ilvl];
705 foff2 = foff + 2 *
npix *
nlin * nlvl_cmp;
706 (*tdat)[foff2 + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_p[ilvl];
707 foff2 = foff + 3 *
npix *
nlin * nlvl_cmp;
708 (*tdat)[foff2 + ipx +
npix * ( iln +
nlin * ilvl ) ] = cmp_h[ilvl];
714 foff2 = foff + 4 *
npix *
nlin * nlvl_cmp;
715 (*tdat)[foff2 + ipx +
npix * iln ] = 273.15 +
l1que.r[qln].sfct[ipx];
718 (*tdat)[foff2 + ipx +
npix * iln ] =
l1que.r[qln].sfcp[ipx];
721 (*tdat)[foff2 + ipx +
npix * iln ] =
l1que.r[qln].ws[ipx];
724 (*tdat)[foff2 + ipx +
npix * iln ] = 1.e3 *
l1que.r[qln].oz[ipx];
726 is_land =
l1que.r[qln].land[ipx];
732 (*tdat)[foff2 + ipx +
npix * iln ] = ( is_land ) ? 0. :
733 l1que.r[qln].icefr[ipx];
736 (*tdat)[foff2 + ipx +
npix * iln ] = ( is_land ) ?
737 l1que.r[qln].icefr[ipx] : 0;
740 (*tdat)[foff2 + ipx +
npix * iln ] = 1.e3 *
l1que.r[qln].oz[ipx];
747 (*tdat)[foff2 + ipx +
npix * iln ] =
l1que.r[qln].icefr[ipx];
750 (*tdat)[foff2 + ipx +
npix * iln ] =
751 l1que.r[qln].cld_dat->sfc_albedo_659[ipx];
753 (*tdat)[foff2 + ipx +
npix * iln ] =
754 l1que.r[qln].cld_dat->sfc_albedo_858[ipx];
756 (*tdat)[foff2 + ipx +
npix * iln ] =
757 l1que.r[qln].cld_dat->sfc_albedo_1240[ipx];
759 (*tdat)[foff2 + ipx +
npix * iln ] =
760 l1que.r[qln].cld_dat->sfc_albedo_1640[ipx];
762 (*tdat)[foff2 + ipx +
npix * iln ] =
763 l1que.r[qln].cld_dat->sfc_albedo_2130[ipx];
768 (*ubdat)[ uoff + ipx +
npix * iln ] = sfc_lvl;
770 (*ubdat)[ uoff2 + ipx +
npix * iln ] = trop_lvl;
774 (*i32dat)[ ipx +
npix * iln ] = 100 *
l1que.r[qln].icefr[ipx];
781 bad_rad = (
l1que.r[qln].Lt[l1ix[0]+nbnd_ref * ipx] ==
BAD_INT ) ? 1 : 0;
782 cld_flg =
l1que.r[qln].cloud[ipx];
783 ice_flg =
l1que.r[qln].ice[ipx];
784 glint_flg =
l1que.r[qln].glint[ipx];
785 npix_scan =
l1que.r[qln].npix;
786 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( bad_rad == 0 ) ? 1 : 0;
793 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category == 0 ) ? 1 : 0;
795 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category == 1 ) ? 1 : 0;
797 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category == 2 ) ? 1 : 0;
799 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_category >= 3 ) ? 1 : 0;
804 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_flg != 0 ) ? 1 : 0;
806 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_flg != 0 ) ? 1 : 0;
808 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( cld_flg != 0 ) ? 1 : 0;
810 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
814 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
815 ( ( is_land == 1 ) && ( ice_flg == 1 ) ) ? 1 : 0;
818 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( is_land == 0 ) ? 1 : 0;
821 lst = ( iln < 1 ) ? iln : iln - 1;
822 len = ( iln >= (
nlin - 1 ) ) ? iln : iln + 1;
823 pst = ( ipx <= 0 ) ? 0 : ipx -1;
824 pen = ( ipx >= ( npix_scan - 1 ) ) ? ipx : ipx + 1;
825 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
828 for( aln = lst; aln <= len; aln++ )
829 for( apx = pst; apx <= pen; apx++ )
832 if(
l1que.r[aln].land[apx] ) nland++;
834 if( ( nland != 0 ) && ( nland != itot ) )
835 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 1;
838 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
841 (*ubdat)[ uoff2 + ipx +
npix * iln ] = ( is_land ) ? 1 : 0;
844 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
845 (
l1que.r[iln].solz[ipx] > 90. ) ? 1 : 0;
848 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
849 ( glint_flg ) ? 1 : 0;
852 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
853 ( ( is_land == 0 ) && ( ice_flg == 0 ) ) ? 1 : 0;
856 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
857 ( ( is_land == 0 ) && ( ice_flg == 1 ) ) ? 1 : 0;
860 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
861 ( ( is_land == 1 ) && ( ice_flg == 0 ) ) ? 1 : 0;
864 (*ubdat)[ uoff2 + ipx +
npix * iln ] =
865 ( ( is_land == 1 ) && ( ice_flg == 1 ) ) ? 1 : 0;
868 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
871 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
874 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
877 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
880 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
883 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
886 (*ubdat)[ uoff2 + ipx +
npix * iln ] = 0;
889 if( ( ipx == tpix ) && ( iln == tlin ) && ( dbg_print == 1 ) )
891 printf(
"/n%s, %d: mix, t, p, h profiles AFTER, pix %d, lin %d\n", __FILE__, __LINE__, ipx, iln );
903 memcpy( ( *ubdat + 25 *
npix *
nlin ), cmp_there, ncmp_bnd );
909 int32_t ipx, int32_t iln, int32_t
npix, int32_t
nlin )
938 printf(
"mixr profile\n" );
939 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
941 printf(
"%f ", prof[ ipx +
npix * ( iln +
nlin * ilvl ) ] );
943 printf(
"\nT profile\n" );
945 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
947 printf(
"%f ", prof[ off + ipx +
npix * ( iln +
nlin * ilvl ) ] );
949 printf(
"\nPRESS profile\n" );
951 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
953 printf(
"%f ", prof[ off + ipx +
npix * ( iln +
nlin * ilvl ) ] );
955 printf(
"\nHEIGHT profile\n" );
957 for( ilvl = 0; ilvl < nlvl_cmp; ilvl++ )
959 printf(
"%f ", prof[ off + ipx +
npix * ( iln +
nlin * ilvl ) ] );
964 printf(
"TSFC: %f, ", prof[ off + ipx +
npix * iln] );
966 printf(
"PSFC: %f, ", prof[ off + ipx +
npix * iln] );
968 printf(
"WIND SP: %f, ", prof[ off + ipx +
npix * iln] );
970 printf(
"O3: %f\n", prof[ off + ipx +
npix * iln] );
973 printf(
"ICE FR: %f, ", prof[ off + ipx +
npix * iln] );
975 printf(
"SNO FR: %f, ", prof[ off + ipx +
npix * iln] );
977 printf(
"ALT O3: %f, ", prof[ off + ipx +
npix * iln] );
979 printf(
"ALT ICEC: %f\n", prof[ off + ipx +
npix * iln] );
983 printf(
"SFC_LVL: %d, ", ubdat[ off + ipx +
npix * iln ] );
985 printf(
"TROP_LVL: %d\n", ubdat[ off + ipx +
npix * iln ] );
987 printf(
"ALT ICE: %d\n", i32dat[ ipx +
npix * iln ] );
990 printf(
"---- Cloud Mask values ----\n" );
991 printf(
"CLD_DET: %d, ", ubdat[ off + ipx +
npix * iln ] );
993 printf(
"CONF_CLD: %d, ", ubdat[ off + ipx +
npix * iln ] );
995 printf(
"CLR_66: %d, ", ubdat[ off + ipx +
npix * iln ] );
997 printf(
"CLR_95: %d\n", ubdat[ off + ipx +
npix * iln ] );
999 printf(
"CLR_99: %d, ", ubdat[ off + ipx +
npix * iln ] );
1001 printf(
"SNO_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1003 printf(
"WTR_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1005 printf(
"COAST_SFC: %d\n", ubdat[ off + ipx +
npix * iln ] );
1007 printf(
"DESERT_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1009 printf(
"LND_SFC: %d, ", ubdat[ off + ipx +
npix * iln ] );
1011 printf(
"NIGHT: %d, ", ubdat[ off + ipx +
npix * iln ] );
1013 printf(
"GLINT: %d\n", ubdat[ off + ipx +
npix * iln ] );
1015 printf(
"OCEAN_NO_SNOW: %d, ", ubdat[ off + ipx +
npix * iln ] );
1017 printf(
"OCEAN_SNOW: %d, ", ubdat[ off + ipx +
npix * iln ] );
1019 printf(
"LND_NO_SNOW: %d, ", ubdat[ off + ipx +
npix * iln ] );
1021 printf(
"LND_SNOW: %d\n", ubdat[ off + ipx +
npix * iln ] );
1023 printf(
"TST_H_138: %d, ", ubdat[ off + ipx +
npix * iln ] );
1025 printf(
"TST_VIS_REFL: %d, ", ubdat[ off + ipx +
npix * iln ] );
1027 printf(
"TST_VIS_RATIO: %d, ", ubdat[ off + ipx +
npix * iln ] );
1029 printf(
"VIS_CLD_250: %d\n", ubdat[ off + ipx +
npix * iln ] );
1031 printf(
"APPL_HCLD_138: %d, ", ubdat[ off + ipx +
npix * iln ] );
1033 printf(
"APPL_VIS_REFL: %d, ", ubdat[ off + ipx +
npix * iln ] );
1035 printf(
"APPL_VIS_NIR_RATIO: %d\n", ubdat[ off + ipx +
npix * iln ] );
1042 float *merra_h,
float sfcp,
float sfct,
float sfcrh,
float lat,
1043 unsigned char *sfc_lvl,
unsigned char *trop_lvl,
double *cmp_p,
1044 double *cmp_t,
double *cmp_mixr,
double *cmp_h )
1047 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};
1048 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};
1049 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};
1052 for(
i = 0;
i < 101;
i++ )
1054 *(cmp_t +
i) = *(cmp_t_sav +
i);
1055 *(cmp_mixr +
i) = *(cmp_mixr_sav +
i);
1056 *(cmp_h +
i) = *(cmp_h_sav +
i);
1062 float *merra_h,
float sfcp,
float sfct,
float sfcrh,
float lat,
1063 unsigned char *sfc_lvl,
unsigned char *trop_lvl,
double *cmp_p,
1064 double *cmp_t,
double *cmp_mixr,
double *cmp_h )
1066 unsigned char get_trop(
double *,
double *,
unsigned char );
1070 double *,
double *,
double *,
int * );
1071 int32_t nlvl = 42, nlvl_cmp = 101, ioz = 0, ilvl, kstart;
1072 int32_t nlvl_d = nlvl + 1;
1073 float oval, a_factor;
1074 double p_init[nlvl_d], lcl_p[nlvl_d], lcl_t[nlvl_d];
1075 double lcl_w[nlvl_d], lcl_h[nlvl_d], lat_d, sfcp_d;
1089 for( ilvl = 0; ilvl < nlvl; ilvl++ )
1091 merra_q[ilvl] = 1000. * merra_q[ilvl] / ( 1. - merra_q[ilvl]);
1092 merra_t[ilvl] += 273.15;
1103 sfcrh = oval / ( 1. - oval );
1106 for( ilvl = 0; ilvl < nlvl; ilvl++ )
1108 lcl_p[ilvl] = merra_p[ilvl];
1109 lcl_t[ilvl] = merra_t[ilvl];
1110 lcl_w[ilvl] = merra_q[ilvl];
1111 lcl_h[ilvl] = merra_h[ilvl];
1113 if( lcl_t[ilvl] < 0. )
1115 lcl_t[ilvl] = lcl_t[ ilvl - 1 ];
1116 lcl_w[ilvl] = lcl_w[ ilvl - 1 ];
1117 lcl_h[ilvl] = lcl_h[ ilvl - 1 ];
1120 lcl_p[nlvl] = 1100.;
1121 lcl_t[nlvl] = lcl_t[ nlvl - 1 ];
1122 lcl_w[nlvl] = lcl_w[ nlvl - 1 ];
1123 lcl_h[nlvl] = lcl_h[ nlvl - 1 ];
1129 memcpy( p_init, lcl_p, nlvl_d *
sizeof(
double) );
1132 if( ( sfcp > 0 ) && ( lcl_p[ nlvl_d - 2 ] > sfcp ) )
1133 *sfc_lvl = nlvl_d - 1;
1139 kstart = nlvl_d / 2;
1141 for( ilvl = kstart; ilvl < nlvl_d; ilvl++ )
1143 if( ( sfcp > 0 ) && ( lcl_p[ilvl] > sfcp ) )
1151 if( ( sfcp - lcl_p[ ilvl - 1 ] < 5. ) ||
1152 ( lcl_p[ilvl] - sfcp < 5. ) )
1154 lcl_p[ilvl] = ( lcl_p[ilvl] + lcl_p[ ilvl - 1 ] ) / 2.;
1160 lcl_w[ilvl] = sfcrh;
1165 lcl_w[ilvl] = sfcrh;
1166 lcl_p[ilvl] = p_init[ ilvl - 1 ];
1171 if( *sfc_lvl != nlvl_d )
1172 merra_p[ nlvl_d - 1 ] = p_init[ ilvl - 1 ];
1174 lcl_p[ nlvl - 1 ] = sfcp;
1175 lcl_t[ nlvl - 1 ] = sfct;
1176 lcl_w[ nlvl - 1 ] = sfcrh;
1179 kstart = nlvl_cmp / 2;
1180 for( ilvl = kstart; ilvl < nlvl_cmp; ilvl++ )
1182 if( cmp_p[ilvl] >= sfcp )
1194 a_factor = ( sfcp - cmp_p[ *sfc_lvl - 1 ] ) /
1195 ( cmp_p[*sfc_lvl] - cmp_p[ *sfc_lvl - 1 ] );
1196 cmp_t[*sfc_lvl] = cmp_t[ *sfc_lvl - 1 ] + a_factor *
1197 ( cmp_t[*sfc_lvl] - cmp_t[ *sfc_lvl - 1 ] );
1198 cmp_mixr[*sfc_lvl] = cmp_mixr[ *sfc_lvl - 1 ] + a_factor *
1199 ( cmp_mixr[*sfc_lvl] - cmp_mixr[ *sfc_lvl - 1 ] );
1201 cmp_p[*sfc_lvl] = sfcp;
1205 cmp_h[nlvl_cmp - 1 ] = 0.;
1208 *trop_lvl =
get_trop( cmp_t, cmp_p, *sfc_lvl );
1213 unsigned char get_trop(
double *cmp_t,
double *cmp_p,
unsigned char sfc_lvl )
1215 unsigned char trop_lvl;
1217 float xmin, ptop = 100.;
1222 for( ilev = 0; ilev < sfc_lvl - 5; ilev++ )
1224 if( ( cmp_t[ilev] < xmin ) && ( cmp_p[ilev] > ptop ) )
1233 for( ilev = imin; ilev < 71; ilev++ )
1235 if( ( cmp_t[ ilev - 1 ] >= cmp_t[ilev] ) &&
1236 ( cmp_t[ ilev + 1 ] > cmp_t[ilev] ) )
1243 if( trop_lvl == 200 ) trop_lvl = imin;
1276 if ((
status = nc_inq_varid(ncid, ds_name, &var_id)) != NC_NOERR) {
1277 printf(
"%s, %d: nc_inq_varid returned error %d\n", __FILE__, __LINE__,
1284 if ((
status = nc_get_var_uchar(ncid, var_id,
data)) != NC_NOERR) {
1285 printf(
"%s, %d: nc_get_var_uchar returned error %d\n",
1286 __FILE__, __LINE__,
status);
1320 if ((
status = nc_inq_varid(ncid, ds_name, &var_id)) != NC_NOERR) {
1321 printf(
"%s, %d: nc_inq_varid returned error %d\n", __FILE__, __LINE__,
1328 if ((
status = nc_get_var_int(ncid, var_id, (int32_t *)
data)) != NC_NOERR) {
1329 printf(
"%s, %d: nc_get_var_int returned error %d\n",
1330 __FILE__, __LINE__,
status);