OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
atrem_corl1v2.h
Go to the documentation of this file.
1 /*
2  * atrem.h
3  *
4  * Created on: Feb 11, 2015
5  * Author: rhealy
6  */
7 
8 #ifndef SRC_ATREM_ATREM_H_
9 #define SRC_ATREM_ATREM_H_
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <timeutils.h>
14 #include "l12_proto.h"
15 
16 #define NBANDS 1024 /* maximum number of bands */
17 #define NH2OMAX 60
18 #define NH2OMAXM1 (NH2OMAX-1)
19 #define FINSTMAX 100
20 #define MODELMAX 25
21 #define ABSCF_MAXLYR 19
22 #define NO3PT 5001
23 #define NO2PT 5001
24 #define NINSTRF 5000
25 #define NP_HI 300000
26 #define NP_MED 25401
27 #define NP_STD 28001
28 #define NINSTR_MAX 3001
29 #define NPSHIF 2600 //NPSHIF = NP_STD - NP_MED
30 
31 #define VSTART 0.56 //Starting wavelength for calculations
32 #define VEND 3.1
33 #define DWAVLN 1e-4
34 #define DWAVNO 0.05 //Point spacing of high res. spectra (cm-1).
35 #define DLT_MED 0.0002 // 0.2-nm medium resolution spectrum.
36 #define FACDLT 2.0 //Factor to multiply DLT by to determine the
37 //range used in the Gaussian function
38 //calculation for smoothing spectra.
39 
40 #define ATREM_O3 1
41 #define ATREM_CO2 2
42 #define ATREM_NO2 4
43 #define ATREM_CO 8
44 #define ATREM_CH4 16
45 #define ATREM_O2 32
46 #define ATREM_N2O 64
47 
48 #define RAD_DEG 57.29577951
49 #define CONST1 2.7725887 // CONST1=4.0*ln(2)=2.7725887
50 
51 typedef float t_array[NBANDS];
52 
53 typedef struct param_table {
54  /*Number of narrow channels to form broader window and absorption channels. */
55  int32_t nb1, nb2, nb3, nb4;
56  /*number of points used in channel ratios for both the .94- and 1.14-um regions */
57  int32_t nbp94, nb1p14;
58 
59  int32_t nh2o; /* number of water vapor values */
60  int32_t nobs; /* number of spectral observations - this should be nbands? number of channels? */
61  /* 3-channel ratioing
62  * parameters for bands up to the 0.94-um water vapor band [index=0,1]
63  * parameters for bands up to the 1.14-um water vapor band [index=2,3]
64  * */
65  int32_t start_ndx[4]; //ist1,ist2,ist3,ist4
66  int32_t end_ndx[4]; //ied1,ied2,ied3,ied4
67  /* 3-channel ratioing parameters for the 0.94-um water vapor band */
68  int32_t start_p94;
69  int32_t end_p94;
70  /* 3-channel ratioing parameters for the 1.14-um water vapor band */
71  int32_t start_1p14;
72  int32_t end_1p14;
73  /* Parameters for smoothing output reflectance spectra. */
74  int32_t start2;
75  int32_t end2;
76  int32_t ncv2;
77  /* number of channels of the four AVIRIS spectrometers. */
78  int32_t natot, nbtot, nctot, ndtot;
79  /* how often to recalculate geometry
80  * dogeom = 1 - every pixel
81  */
82  int32_t dogeom;
83  /* Atmospheric model number */
84  int model;
85  /* Relative weights for the four window *
86  * channels used in channel-ratioing calculations */
87  int idx450; // 450 nm wavelength index
88 
89  double wt1, wt2, wt3, wt4;
90  /*
91  * delta, delta2 - resolution, in units of nm, of input
92  * spectra and resolution of output surface reflectance
93  * spectra. If DLT2>DLT, output spectra are smoothed
94  * using a gaussian function.
95  */
96  double delta, delta2;
97  /* The "equivalent" geometrical *
98  * factor corresponding to the total slant vapor amount *
99  * VAP_SLANT_MDL and the column vapor amount CLMVAP. */
100  double g_vap_equiv; // This depends on zenith angle and lat/lon of measurement
101  float *r0p94; //ratio for the 0.94 um H2O absorption band
102  float *r1p14; //ratio for the 1.14 um H2O absorption band
103  float *finst2; // some kind of smoothing factor calculated in INIT_SPECCAL only used for AVIRIS?
104  /* TOTAL SUN-SURFACE-SENSOR PATH WATER VAPOR IN UNITS OF CM */
105  float *vaptot;
106 
107  /* total transmittances of all gases that match the *
108  * resolutions of imaging spectrometers */
109  t_array *trntbl;
110  float water_vapor; // returned water vapor value from get_atrem
111  int ja, jb; // indices to tran_table from get_atrem
112  float f1a, f2a, f1b, f2b; // fractions for interpolation of transmittances in tran_table from get_atrem
113 } paramstr;
114 
115 float get_atrem(float *tg_tot, float *rhot, paramstr *P);
116 int get_atrem_cor(l1str *l1rec, int32_t ip, float *rhot, float *tg_tot, float *tg_sol, float *tg_sen);
117 int init_atrem(int32_t sensorID, paramstr *P, l1str *l2rec, int32_t nbands);
118 int32_t rdatreminfo(int32_t sensorID, int32_t evalmask, const char *pname, void **pval);
119 int get_angle_limits(float **angle_limit, float **senz, float **solz, int *n_senz, int *n_solz);
120 float get_current_angle_limit(float insenz, float insolz, int *i, int *j, float **anglelimit, float senz[], float solz[], int n_senz, int n_solz);
121 int32_t hunt(float *xx, int32_t n, double x, int32_t jlo);
122 int init_tpvmr(int model);
123 int getModelNum(float lat, int32_t day);
124 int32_t findMatch(float *list, int32_t nobs, float elem);
125 void channelRatio();
126 void ecdf_(float *xcdf, float *ycdf, int32_t *bin_number, float *xs, int32_t *sample_size);
127 void kdistgasabs(float *kcdf, float *abscf, float*waveno, float *wavobs, int32_t np_hi, int32_t nlayers, int32_t nbands);
128 void model_adjust();
129 void locate_pos_(float *xx, int32_t *n1, float *x1, int32_t *jj);
130 void geometry();
132 void get_abscf_data(int levels, int bands, int sds_id, char filename[FILENAME_MAX], float* abscf, char *varname);
133 void get_tpvmr(size_t layers, size_t models, int sds_id,
134  char filename[FILENAME_MAX], char *varname, float* var_a);
135 int init_tpvmr_nc(int model);
136 void tran_table();
137 void tran_smooth(float *tran_hi);
138 void tran_smooth_others();
139 
140 extern void get_input_();
141 extern void model_adj_();
142 extern void geometry_();
143 extern void init_speccal_();
144 //extern void solar_irr_pc_();
145 extern void tran_table_();
146 extern void kdist_gas_abs_(float *tkcdf, float *abscf_h2o, int32_t *bands, float *wavno_hi, float *wavobs, int32_t *nobs);
147 extern void tran_smooth_();
148 extern void tran_smooth_others_();
149 extern void chnlratio_();
150 
151 extern struct {
152  int32_t h2o, co2, o3, n2o, co, ch4, o2, no2;
153 } getinput1_;
154 
155 extern struct {
156  char filename[FILENAME_MAX];
157  int32_t dln;
158 } input_l2gen_;
159 
160 extern struct {
163 
164 extern struct {
166 } tran_tables_;
167 
168 extern struct {
181 
182 } tran_tables1_;
183 
184 extern struct {
186  int32_t nb, nl, model, iaer; //iaer not used because call to ssssss routine commented out in fortran code
187  float v, taer55, vrto3, sno2;
188  //nb = number of atmospheric levels in model
189  //nl = nb - 1
190  //sno2 = scaling factor for no2 (builtin NO2 column amount is 5.0E+15 molecules/cm^2
191  //vrto3 = column ozone amount (atm-cm) 0.28-0.55 is typical
192  //v = visibility (km)
193  //iaer = aerosol model value
194  //taerr55 = aerosol optical depth at 550 nm
195 } getinput3_;
196 
197 extern struct {
199 } getinput4_;
200 
201 extern struct {
202  int32_t nobs, full_calc;
203  float hsurf, dlt, dlt2;
204 } getinput5_;
205 
206 extern struct {
208 } getinput6_;
209 
210 extern struct {
211  int32_t nb1, nb2, nbp94, nb3, nb4, nb1p14;
212 } getinput7_;
213 
214 extern struct {
215  int32_t imn, idy, iyr, ih, im, is;
216 } getinput8_;
217 
218 extern struct {
219  float xpss, xppp;
220 } getinput14_;
221 
222 extern struct {
223  float clmvap, q;
224 } model_adj1_;
225 
226 extern struct {
228 } model_adj2_;
229 
230 extern struct {
231  int32_t k_plane;
233 } model_adj3_;
234 
235 extern struct {
236  int32_t k_surf;
237 } model_adj4_;
238 
239 extern struct {
240  float tran_hi_others[NP_HI]; //Transmittance of high res. data(.05cm-1)
242 
243 extern struct {
244  int32_t nh2o;
246 
247 extern struct {
250 
251 extern struct {
252  int32_t ist1, ied1, ist2, ied2, istp94, iedp94;
254 
255 extern struct {
258 
259 extern struct {
260  float wt1, wt2, wt3, wt4;
261  int32_t ja;
263 
264 extern struct {
265  int32_t ncv2, ncvhf2, ncvtt2;
266  int32_t istrt2, iend2;
267  float finst2[FINSTMAX];
269 
270 extern struct {
271  int32_t natot, nbtot, nctot, ndtot;
273 
274 extern struct {
277 
278 extern struct {
279  int32_t index_med[NP_MED];
282 
283 /* Arrays for wavelength positions and FWHM of measured imaging spectrometer
284  data and for smoothing the medium resolution spectrum (FWHM = 0.2 nm,
285  and point spacing = 0.1 nm) to match coarser resolution spectrum
286  of imaging spectrometer data
287  */
288 extern struct {
290  int32_t ncvhf[NBANDS];
292 
293 extern struct {
296 
297 extern struct {
300 
301 extern struct {
304 } tran_table1_;
305 
306 extern struct {
308  int32_t day;
309 } geometry1_;
310 
311 extern struct {
313 } geometry2_;
314 
315 extern struct {
317 } geometry3_;
318 
319 extern struct {
321 } geometry4_;
322 
323 extern struct {
324  float mu, mu0, ssh2o_s[2][NH2OMAX];
325 } geometry5_;
326 
327 extern struct {
329  float water_vapor;
330  int32_t ja, jb;
331  int32_t splitpaths;
332  float f1a, f2a, f1b, f2b;
334 
335 extern struct {
336  float tpvmr[81][7];
337 } tpvmr_init1_;
338 
339 extern struct {
340  float o3cf[NO3PT];
341 } o3cf_init1_;
342 
343 extern struct {
344  float rno2cf[NO2PT];
345 } no2cf_init1_;
346 
347 struct {
348  float cst1, cst2, cst3, cst4, cst5, cst6;
349  double rp94, r1p14;
350  int32_t jac, jbc;
351 } debug_atrem;
352 #endif /* SRC_ATREM_ATREM_H_ */
float get_current_angle_limit(float insenz, float insolz, int *i, int *j, float **anglelimit, float senz[], float solz[], int n_senz, int n_solz)
float tran_std_sap1_sol[NP_STD]
int32_t end_p94
Definition: atrem.h:35
int32_t ndtot
Definition: atrem.h:44
float dlt
float wndow3
float tg_sen[NBANDS]
float tran_hi_others[NP_HI]
int32_t findMatch(float *list, int32_t nobs, float elem)
int32_t jbc
float gco2
float tran_std_sbp1_sen[NP_STD]
float tran_std_sb_sen[NP_STD]
float cst2
float vmrp[MODELMAX]
double wt3
Definition: atrem.h:47
float g_vap[MODELMAX]
void geometry()
int32_t imn
int32_t h2o
float g_vap_equiv
int32_t ndtot
int32_t nb1p14
int32_t im
int j
Definition: decode_rs.h:73
float wavln_med_index[NP_MED]
int32_t nbtot
int32_t day
float tran_med_index_sa_sol[NP_MED]
float wavln_med[NP_MED]
float cst1
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
float tran_no2_std[NO3PT]
int32_t full_calc
float go3
int32_t nb2
Definition: atrem.h:21
float hp[MODELMAX]
int32_t iaer
struct @76 tran_table1_
void model_adjust()
#define NO3PT
Definition: atrem_corl1v2.h:22
int32_t ncvhf[NBANDS]
float t_array[NBANDS]
Definition: atrem_corl1v2.h:51
int32_t idy
int32_t nctot
Definition: atrem.h:44
struct @77 geometry1_
struct @85 no2cf_init1_
float senzn_l2
int32_t iyr
list levels
Definition: mapgen.py:180
int32_t dln
float wt1
void init_speccal_()
int32_t ncv2
Definition: atrem.h:42
float wt4
float sno2
int32_t ja
void get_tpvmr(size_t layers, size_t models, int sds_id, char filename[FILENAME_MAX], char *varname, float *var_a)
int32_t end_1p14
Definition: atrem.h:38
float totlo3
int getModelNum(float lat, int32_t day)
int32_t nbtot
Definition: atrem.h:44
float r1p14[NH2OMAX]
float f2a
float tran_hi_sbp1[2][NP_HI]
float tran_med_sbp1_sen[NP_MED]
#define NP_STD
Definition: atrem_corl1v2.h:27
#define FINSTMAX
Definition: atrem_corl1v2.h:19
int32_t nbp94
Definition: atrem.h:23
void channelRatio()
double r1p14[TBLMAX]
Definition: atrem.h:60
read l1rec
int32_t ncv2
float gn2o
float vrto3
int32_t ied1
double r0p94[TBLMAX]
Definition: atrem.h:59
int32_t is
int32_t natot
Definition: atrem.h:44
int32_t ied3
float tran_med_index_sa_sen[NP_MED]
float wavln_std[NP_STD]
int init_tpvmr(int model)
struct @75 init_speccal17_
void init_spectral_calculations()
void locate_pos_(float *xx, int32_t *n1, float *x1, int32_t *jj)
float p[MODELMAX]
float tran_med_index_sb_sol[NP_MED]
float mu
struct @65 init_speccal5_
int init_tpvmr_nc(int model)
float * lat
float tm[MODELMAX]
float cst6
double wt4
Definition: atrem.h:47
int32_t splitpaths
float tran_med_index_sap1_sen[NP_MED]
int32_t nb
int32_t k_plane
double g_vap_equiv
Definition: atrem.h:58
float vaptot[NH2OMAX]
float vmrm[MODELMAX]
int get_angle_limits(float **angle_limit, float **senz, float **solz, int *n_senz, int *n_solz)
int32_t no2
float v
void tran_smooth_()
float tran_o3_std[NO3PT]
float tran_med_sa_sol[NP_MED]
int32_t ied4
float tran_med_sb_sol[NP_MED]
float trntblo[NBANDS]
int32_t ist4
struct @55 getinput6_
int32_t o2
float tran_med_sbp1_sol[NP_MED]
float tran_med_index[NH2OMAX][NP_MED]
float tran_med_index_sbp1_sen[NP_MED]
float wt2
double rp94
float tran_hi_sa[2][NP_HI]
float tg_seno[NBANDS]
int32_t natot
float water_vapor
int32_t rdatreminfo(int32_t sensorID, int32_t evalmask, const char *pname, void **pval)
Definition: rdatreminfo.c:38
int32_t iedp94
int32_t nl
float rno2cf[NO2PT]
float t[MODELMAX]
float g_other[MODELMAX]
struct @81 geometry5_
struct @59 model_adj1_
float dp_plane
struct @57 getinput8_
float tran_kd[NH2OMAX][NBANDS]
int32_t co
int32_t nb4
Definition: atrem.h:21
struct @54 getinput5_
int32_t start_ndx[4]
Definition: atrem.h:31
float tran_std_sa_sen[NP_STD]
int32_t ist1p14
float ggeom
void get_abscf_data(int levels, int bands, int sds_id, char filename[FILENAME_MAX], float *abscf, char *varname)
struct @86 debug_atrem
float dlt2
int32_t k_surf
float diff_tran[NH2OMAX][NBANDS]
float finstr[NBANDS][NINSTR_MAX]
float solaz
void tran_smooth_others_()
double wt1
Definition: atrem.h:47
float vmr[MODELMAX]
int32_t start_1p14
Definition: atrem.h:37
float r0p94[NH2OMAX]
float wavobs[NBANDS]
struct @84 o3cf_init1_
float tg_solo[NBANDS]
float gch4
float wndow2
int32_t ch4
#define NBANDS
Definition: atrem_corl1v2.h:16
void tran_table_()
float go2
double wt2
Definition: atrem.h:47
int32_t ied2
float tg_sol[NBANDS]
#define MODELMAX
Definition: atrem_corl1v2.h:20
float tran_std_sbp1_sol[NP_STD]
float vap_slant_mdl
float wt3
void tran_smooth(float *tran_hi)
float dp_layer
float tp[MODELMAX]
float h[MODELMAX]
int32_t nb2
struct @79 geometry3_
int32_t ist3
float tran_std_sa_sol[NP_STD]
float wp94c
float f1b
float sh2o
struct @64 init_speccal3_
struct @50 tran_tables_
struct @69 init_speccal10_
void kdistgasabs(float *kcdf, float *abscf, float *waveno, float *wavobs, int32_t np_hi, int32_t nlayers, int32_t nbands)
double trntbl[TBLMAX][NBANDS]
Definition: atrem.h:66
float q
double finst2[FINSTMAX]
Definition: atrem.h:61
float senaz_l2
float clmvapp
int32_t nh2o
Definition: atrem.h:25
float solzni
int32_t istrt2
int32_t nb4
float dp[MODELMAX]
float dvap_plane
float tran_hi_sb[2][NP_HI]
int32_t nobs
int32_t o3
float tran_med_sap1_sen[NP_MED]
int32_t nh2o
float tran_med_index_sap1_sol[NP_MED]
int32_t nobs
Definition: atrem.h:26
struct @48 input_l2gen_
float ssh2o[NH2OMAX]
void get_input_()
float tran_med_sap1_sol[NP_MED]
float water_vapor
Definition: atrem_corl1.h:89
#define NH2OMAX
Definition: atrem_corl1v2.h:17
int32_t ncvhf2
float clmvap
int32_t n2o
int32_t end_ndx[4]
Definition: atrem.h:32
void geometry_()
#define NP_HI
Definition: atrem_corl1v2.h:25
float ssh2o_s[2][NH2OMAX]
int32_t co2
float tran_std_sb_sol[NP_STD]
int32_t ied1p14
float xppp
char filename[FILENAME_MAX]
int32_t iend2
struct @74 init_speccal16_
int32_t index_med[NP_MED]
float pm[MODELMAX]
struct @52 getinput3_
float xpss
struct @56 getinput7_
struct @51 tran_tables1_
int32_t jac
void chnlratio_()
float solzn_l2
int32_t end2
Definition: atrem.h:41
struct @78 geometry2_
int32_t ih
int32_t ist1
double vaptot[TBLMAX]
Definition: atrem.h:63
int32_t ncvtt2
float dvap_layer
int32_t nb1
void model_adj_()
double delta
Definition: atrem.h:54
void tran_table()
struct @63 init_speccal1_
float get_atrem(float *tg_tot, float *rhot, paramstr *P)
struct @68 init_speccal8_
int32_t nbands
float gco
int32_t dogeom
Definition: atrem_corl1.h:61
float f1a
float obszni
float taer55
struct @62 model_adj4_
int32_t hunt(float *xx, int32_t n, double x, int32_t jlo)
struct @47 getinput1_
float finst2[FINSTMAX]
struct @82 geometry_l2gen_
int32_t istp94
float mu0
void ecdf_(float *xcdf, float *ycdf, int32_t *bin_number, float *xs, int32_t *sample_size)
Definition: numerical.c:22
struct @58 getinput14_
int32_t nb1
Definition: atrem.h:21
int32_t nb1p14
Definition: atrem.h:23
struct @80 geometry4_
int32_t ist2
struct @67 init_speccal7_
float tran_std_sap1_sen[NP_STD]
struct @71 init_speccal12_
struct @60 model_adj2_
float tran_med_sa_sen[NP_MED]
float tran_hi_sap1[2][NP_HI]
float wndow1
int32_t start2
Definition: atrem.h:40
float hsurf
struct @49 tran_table_l2gen_
#define NINSTR_MAX
Definition: atrem_corl1v2.h:28
int init_atrem(int32_t sensorID, paramstr *P, l1str *l2rec, int32_t nbands)
float wndow4
float trntbl[NH2OMAX][NBANDS]
int get_atrem_cor(l1str *l1rec, int32_t ip, float *rhot, float *tg_tot, float *tg_sol, float *tg_sen)
float cst5
float tran_med_index_sb_sen[NP_MED]
int i
Definition: decode_rs.h:71
float cst4
float f2b
int32_t nb3
int32_t sensorID[MAXNFILES]
Definition: l2bin.cpp:97
float tran_med_sb_sen[NP_MED]
struct @66 init_speccal6_
float pp[MODELMAX]
#define NO2PT
Definition: atrem_corl1v2.h:23
float w1p14c
int32_t nbp94
struct @72 init_speccal13_
float fwhm[NBANDS]
struct @83 tpvmr_init1_
float cst3
int32_t model
int32_t nb3
Definition: atrem.h:21
struct @73 init_speccal15_
struct @61 model_adj3_
float tran_med_index_sbp1_sol[NP_MED]
struct @70 init_speccal11_
int32_t jb
float o3cf[NO3PT]
void kdist_gas_abs_(float *tkcdf, float *abscf_h2o, int32_t *bands, float *wavno_hi, float *wavobs, int32_t *nobs)
float tpvmr[81][7]
int32_t nctot
float obsphi
#define NP_MED
Definition: atrem_corl1v2.h:26
int32_t start_p94
Definition: atrem.h:34
void tran_smooth_others()
struct @53 getinput4_
double delta2
Definition: atrem.h:54