OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1.h
Go to the documentation of this file.
1 #ifndef _L1_H
2 #define _L1_H
3 
4 #include "l1_input.h"
5 #include "filehandle.h"
6 #include "l2_flags.h"
7 
8 #include <clo.h>
9 #include <genutils.h>
10 #include <timeutils.h>
11 #include <libnav.h>
12 
13 #include <stdint.h>
14 #include <stdbool.h>
15 
16 // Metadata standard strings
17 #define INSTITUTION "NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group"
18 #define LICENSE "https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/"
19 #define NAMING_AUTHORITY "gov.nasa.gsfc.sci.oceandata"
20 #define KEYWORDS_VOCABULARY "NASA Global Change Master Directory (GCMD) Science Keywords"
21 #define STDNAME_VOCABULARY "CF Standard Name Table v36"
22 #define CREATOR_NAME "NASA/GSFC/OBPG"
23 #define CREATOR_EMAIL "data@oceancolor.gsfc.nasa.gov"
24 #define CREATOR_URL "https://oceandata.sci.gsfc.nasa.gov"
25 #define PROJECT "Ocean Biology Processing Group (NASA/GSFC/OBPG)"
26 #define PUBLISHER_NAME "NASA/GSFC/OBPG"
27 #define PUBLISHER_EMAIL "data@oceancolor.gsfc.nasa.gov"
28 #define PUBLISHER_URL "https://oceandata.sci.gsfc.nasa.gov"
29 
30 #ifndef MIN
31 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
32 #endif
33 #ifndef MAX
34 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
35 #endif
36 
37 #ifndef PI
38 #define PI 3.141592654
39 #endif
40 #define RADEG 57.29577951
41 
42 #define OFF 0
43 #define ON 1
44 #define NO 0
45 #define YES 1
46 
47 #define SUCCESS 0
48 #define FATAL_ERROR 1
49 #define LONLAT_ERROR 110
50 #define MAXPIX 10000
51 
52 #define BANDW 10
53 
54 #define BT_LO -1000
55 #define BT_HI 1000
56 
57 #define SOLZNIGHT 85.0
58 #define SOLZNIGHTA 80.0
59 #define GLINT_MIN 0.0001
60 
61 
62 //VIIRS aggregation zone pixel indexes (M-band)
63 #define AGZONE0 0
64 #define AGZONE1 640
65 #define AGZONE2 1008
66 #define AGZONE3 1600
67 #define AGZONE4 2192
68 #define AGZONE5 2560
69 
70 // evalmask
71 #define STDPROC 0 /* evalmask bit definitions */
72 #define OLDAERMOD 1 /* init to old aerosol models */
73 #define MODCLOUD 2 /* enables MODIS/MERIS cloud mask algorithm */
74 #define MODCIRRUS 16 /* enables MODIS cirrus mask */
75 #define NEWSENSINFO 32 /* use test sensor info file */
76 #define NEWRAYTAB 64 /* use test rayleigh tables */
77 #define NEWAERTAB 128 /* use test aerosol tables */
78 #define NEWPOLTAB 256 /* use test polarization tables */
79 #define MSKMODMIR1 1024 /* mask modis mirror-side 1 (navfail) */
80 #define MSKMODMIR2 2048 /* mask modis mirror-side 2 (navfail) */
81 #define SSTMODS 4096 /* reserved for testing SST changes */
82 #define ALTSENSORINFO 8192 /* use .alt sensor infor file in eval */
83 #define TRANSSPHER 32768 /* enables spherical path geom for dtran */
84 
85 #define XCALRVS 1
86 #define XCALPOL 2
87 #define XCALOLI 4 //Sudipta added for OLI SCA based XCAL
88 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 
93 
94 /* Notice: any changes to this structure may require modifications to the */
95 /* following routines: alloc_l1.c, cpl1rec.c, l1subpix.c. */
96 
97 typedef struct geom_struc_def {
98  float *senz;
99  float *sena;
100  float *csenz;
101  float *solz;
102  float *sola;
103  float *csolz;
104  float *delphi;
105  float *scattang;
106 } geom_struc;
107 
108 typedef struct anc_add_struc_def {
109  int32_t nlvl; /* number of profile levels */
110  float *prof_temp;
111  float *prof_rh;
112  float *prof_height;
113  float *prof_q;
114  float *prof_o3;
115 } anc_struc;
116 
117 // ancillary aerosol from GMAO MERRA model
118 typedef struct anc_aer_struc_def {
121  float *dust_ext;
122  float *dust_scat;
123  float *sea_salt_ext;
125  float *sulphur_ext;
126  float *sulphur_scat;
131 } anc_aer_struc;
132 
133 // for the cloud parameters, now just the sfc albedos
134 typedef struct cld_dat_struc_def {
140 } cld_struc;
141 
142 typedef struct l1_struct {
143  int32_t length; /* number of bytes allocated to data block */
144  int32_t npix;
145 
146  int32_t iscan;
147  int32_t detnum;
148  int32_t mside;
149 
150  /* scan-time-specific data */
151  double scantime;
152  double fsol;
153 
154  bool is_l2;
156  /* scan attributes */
157 
158  float tilt;
159  float alt; //altitude of sensor
160 
161  /* All parameters below are scan-length dependent */
162 
163  /* sensor band-pass-specific data */
164 
165 
166  char *data; /* points to start of variable-length data block */
167 
168  int32_t *nobs;
169  float *lon;
170  float *lat;
171  float *solz;
172  float *sola;
173  float *senz;
174  float *sena;
175  float *Lt;
176  float *Lt_unc;
177 
178  float *Ltir;
179  float *Bt;
180 
181  float *delphi;
182  float *csolz;
183  float *csenz;
184  int32_t *pixnum;
185  char *slot;
186  float *alpha;
187  float *scattang;
188 
189  float *ws;
190  float *wd;
191  float *mw;
192  float *zw;
193  float *pr;
194  float *oz;
195  float *wv;
196  float *rh;
197  float *no2_tropo;
198  float *no2_strat;
199  float *no2_frac;
200  float *sfcp;
201  float *sfcrh;
202  float *sfct;
203  float *icefr;
204  float *height;
205  float *dem;
206 
207  float *ws_unc;
208  float *wd_unc;
209  float *mw_unc;
210  float *zw_unc;
211  float *pr_unc;
212  float *oz_unc;
213  float *wv_unc;
214  float *rh_unc;
217 
218  // TODO: can get rid of this. Only used in setanc.c
219  short *ancqc;
220 
221 
222  short *ssttype; /* per pixel - reference type or climatology */
223 
224  int32_t *flags;
225  char *mask; // this group of params is the flags expanded into a byte
226  char *hilt;
227  char *cloud;
228  char *glint;
229  char *land;
230  char *swater;
231  char *ice;
232  char *solzmax;
233  char *senzmax;
234  char *stlight;
235  char *absaer;
236  char *navfail;
237  char *navwarn;
238 
239  char *filter;
240 
241  float *t_h2o;
242  float *t_o2;
243  float *tg_sol;
244  float *tg_sen;
245  float *t_sol;
246  float *t_sen;
247  float *rhof;
248  float *tLf;
249  float *Lr;
250  float *L_q;
251  float *L_u;
252  float *polcor;
253  float *dpol;
254  float *TLg;
255  float *rhos;
256  float *glint_coef;
257  float *cloud_albedo;
258  float *aerindex;
259  float *sstref;
260  float *sssref;
261  float *sw_n;
262  float *sw_a;
263  float *sw_bb;
264  float *sw_a_avg;
265  float *sw_bb_avg;
266  float *rho_cirrus;
267 
268  // TODO: move MERIS L1 to private_data pointer in l1rec
269  /* for MERIS L1 */
270  int32_t *pixdet; /* detector index of pixel */
271  float *radcor; /* smile correction */
272 
273 
274  float *Fo;
275 
276  // TODO: this needs to go into private_data pointer in filehandle
277  /* for VIIRS unaggregated and superscan */
278  int16_t scn_fmt; /* scan format of data, 0 std, else unaggregated */
279  float margin_s; /* extra scan margin beyond actual samples */
280 
281  filehandle *l1file;
282 
283  // pointer to data needed by specific readers so far just meris, hawkeye
285 
286  // geometry per band
287  geom_struc *geom_per_band;
288 
289  // added ancillary data, for CHIMAERA profiles, etc
290  anc_struc *anc_add;
291 
292  // ancillary aerosol information from MERRA-2
293  anc_aer_struc *anc_aerosol;
294 
295  // cloud processing data
296  cld_struc *cld_dat;
297 
298 } l1str;
299 
300 void l1_input_init();
301 void l1_input_delete(l1_input_t *input);
303 void l1_read_default_files(clo_optionList_t *list, filehandle *l1file, const char *ifile);
304 void l1_load_options(clo_optionList_t *list, filehandle *l1file);
305 void l1_get_input_params(filehandle *l1file, char *input_parms);
306 void l1_get_input_files(filehandle *l1file, char *input_files);
307 
308 void bindex_set(int32_t wave[], int nwave, int dwave_vswir);
309 int bindex_get(int32_t wave);
310 int bindex_get_555(void);
311 int windex(float wave, float twave[], int ntwave);
312 int invbindx(int band, int32_t *bindx, int nbands);
313 
314 void radiance2bt(l1str *l1rec, int resolution);
315 void flag_bowtie_deleted(l1str *l1rec, size_t ipix, int extract_offset);
316 
317 int get_f0_neckel(int32_t wl, int32_t width, float *f0);
318 int get_f0_thuillier(int32_t wl, int32_t width, float *f0);
319 void get_f0_thuillier_ext(int32_t wl, int32_t width, float *f0);
320 
321 int init_geom_per_band(l1str *);
322 int geom_per_band_deriv(l1str *);
323 int destroy_geom_per_band(geom_struc *);
324 
325 void init_l1(l1str *l1rec);
326 int32_t alloc_l1(filehandle *l1file, l1str *l1rec);
327 void free_l1(l1str *l1rec);
328 
329 int openl1(filehandle *l1file);
330 int readl1(filehandle *l1file, int32_t recnum, l1str *l1rec);
331 int readl1_lonlat(filehandle *l1file, int32_t recnum, l1str *l1rec);
332 void closel1(filehandle *l1file);
333 void closel1_generic(filehandle *l1file);
334 
335 int openl1_write(filehandle *l1file);
336 int writel1(filehandle *l1file, int32_t recnum, l1str *l1rec);
337 int openl1_read_hdf(filehandle *l1file);
338 int openl1_write_hdf(filehandle *l1file);
339 int writel1_hdf(filehandle *l1file, int32_t recnum, l1str *l1rec);
340 void closel1_hdf(filehandle *l1file);
341 
342 int l1subpix(filehandle *l1file, l1str *l1rec);
343 
344 void l1_mask_set(l1str *l1rec, int32_t ip);
345 int setflags(l1str *l1rec);
346 void setflagbits_l1(int level, l1str *l1rec, int32_t ipix);
347 
348 char get_cldmask(l1str *l1rec, int32_t ip);
349 int modis_cloud_mask(l1str *l1rec, int32_t ip);
350 int get_sdps_cld_mask( l1str *, int32_t, char *);
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #endif
float * organic_carbon_ext
Definition: l1.h:127
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
float * polcor
Definition: l1.h:252
float * prof_rh
Definition: l1.h:111
void l1_input_init()
Definition: l1_options.c:11
void bindex_set(int32_t wave[], int nwave, int dwave_vswir)
Definition: windex.c:15
const int bindx[3]
Definition: DbLutNetcdf.cpp:28
char * slot
Definition: l1.h:185
float * sssref
Definition: l1.h:260
int readl1(filehandle *l1file, int32_t recnum, l1str *l1rec)
Definition: l1_io.c:400
int16_t scn_fmt
Definition: l1.h:278
int init_geom_per_band(l1str *)
Definition: geom_per_band.c:7
float * sena
Definition: l1.h:174
float * alpha
Definition: l1.h:186
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
int32_t alloc_l1(filehandle *l1file, l1str *l1rec)
Definition: alloc_l1.c:15
char get_cldmask(l1str *l1rec, int32_t ip)
Definition: cloud_flag.c:280
float * Lr
Definition: l1.h:249
float * no2_strat
Definition: l1.h:198
float * ws
Definition: l1.h:189
int32_t iscan
Definition: l1.h:146
char * navfail
Definition: l1.h:236
float * height
Definition: l1.h:204
geom_struc * geom_per_band
Definition: l1.h:287
int32_t npix
Definition: l1.h:144
void free_l1(l1str *l1rec)
Definition: alloc_l1.c:6
float * Ltir
Definition: l1.h:178
float * dpol
Definition: l1.h:253
float * solz
Definition: l1.h:171
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that resolution
Definition: HISTORY.txt:188
float * TLg
Definition: l1.h:254
float * sulphur_scat
Definition: l1.h:126
float * sea_salt_ext
Definition: l1.h:123
int32_t * nobs
Definition: l1.h:168
char * stlight
Definition: l1.h:234
read l1rec
int geom_per_band_deriv(l1str *)
Definition: geom_per_band.c:51
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second band
anc_struc * anc_add
Definition: l1.h:290
int openl1_write_hdf(filehandle *l1file)
float * zw
Definition: l1.h:192
float * ws_unc
Definition: l1.h:207
float * no2_frac
Definition: l1.h:199
filehandle * l1file
Definition: l1.h:281
int writel1(filehandle *l1file, int32_t recnum, l1str *l1rec)
void radiance2bt(l1str *l1rec, int resolution)
Definition: brightness.c:170
float * sola
Definition: l1.h:102
float * scattang
Definition: l1.h:105
float * Lt_unc
Definition: l1.h:176
float * csolz
Definition: l1.h:103
int32_t mside
Definition: l1.h:148
float * sstref
Definition: l1.h:259
float * sena
Definition: l1.h:99
int destroy_geom_per_band(geom_struc *)
float * t_sol
Definition: l1.h:245
int openl1_read_hdf(filehandle *l1file)
float * total_aerosol_scat
Definition: l1.h:130
void l1_mask_set(l1str *l1rec, int32_t ip)
Definition: setflags_l1.c:3
float * zw_unc
Definition: l1.h:210
void * private_data
Definition: l1.h:284
float * L_u
Definition: l1.h:251
float * csenz
Definition: l1.h:100
int32_t detnum
Definition: l1.h:147
float * tg_sen
Definition: l1.h:244
float * total_aerosol_ext
Definition: l1.h:129
void l1_get_input_params(filehandle *l1file, char *input_parms)
Definition: l1_options.c:444
int get_sdps_cld_mask(l1str *, int32_t, char *)
Definition: cloud_flag.c:5
float * t_sen
Definition: l1.h:246
int invbindx(int band, int32_t *bindx, int nbands)
Definition: windex.c:106
short * ssttype
Definition: l1.h:222
float * sw_bb
Definition: l1.h:263
float * icefr
Definition: l1.h:203
char * senzmax
Definition: l1.h:233
Definition: l1.h:142
int bindex_get(int32_t wave)
Definition: windex.c:45
int writel1_hdf(filehandle *l1file, int32_t recnum, l1str *l1rec)
float * prof_height
Definition: l1.h:112
float * dem
Definition: l1.h:205
float * wv_unc
Definition: l1.h:213
void l1_input_delete(l1_input_t *input)
Definition: l1_options.c:65
float * csenz
Definition: l1.h:183
int32_t * pixdet
Definition: l1.h:270
read recnum
float * rhof
Definition: l1.h:247
float * Bt
Definition: l1.h:179
bool is_l2
Definition: l1.h:154
int l1subpix(filehandle *l1file, l1str *l1rec)
Definition: l1subpix.c:17
float * sw_a_avg
Definition: l1.h:264
float * mw
Definition: l1.h:191
int32_t * pixnum
Definition: l1.h:184
void l1_add_options(clo_optionList_t *list)
Definition: l1_options.c:76
float * dust_scat
Definition: l1.h:122
float * tLf
Definition: l1.h:248
void l1_get_input_files(filehandle *l1file, char *input_files)
Definition: l1_options.c:644
float * organic_carbon_scat
Definition: l1.h:128
float * prof_q
Definition: l1.h:113
float * rh_unc
Definition: l1.h:214
float * radcor
Definition: l1.h:271
int modis_cloud_mask(l1str *l1rec, int32_t ip)
char * absaer
Definition: l1.h:235
cld_struc * cld_dat
Definition: l1.h:296
int readl1_lonlat(filehandle *l1file, int32_t recnum, l1str *l1rec)
Definition: l1_io.c:587
float * rh
Definition: l1.h:196
float * sfc_albedo_1240
Definition: l1.h:137
float * csolz
Definition: l1.h:182
char * data
Definition: l1.h:166
double fsol
Definition: l1.h:152
int32_t * flags
Definition: l1.h:224
float * senz
Definition: l1.h:98
float * sfc_albedo_659
Definition: l1.h:135
void init_l1(l1str *l1rec)
Definition: init_l1.c:11
float * glint_coef
Definition: l1.h:256
float * sfc_albedo_858
Definition: l1.h:136
anc_aer_struc * anc_aerosol
Definition: l1.h:293
float * Lt
Definition: l1.h:175
float * mw_unc
Definition: l1.h:209
short * ancqc
Definition: l1.h:219
float * no2_tropo
Definition: l1.h:197
float alt
Definition: l1.h:159
float * sfcrh
Definition: l1.h:201
float * no2_strat_unc
Definition: l1.h:216
float margin_s
Definition: l1.h:279
void closel1_hdf(filehandle *l1file)
void closel1(filehandle *l1file)
Definition: l1_io.c:68
int32_t nlvl
Definition: l1.h:109
float * wd_unc
Definition: l1.h:208
int get_f0_thuillier(int32_t wl, int32_t width, float *f0)
Definition: get_f0.c:71
float * sw_a
Definition: l1.h:262
level
Definition: mapgen.py:186
double scantime
Definition: l1.h:151
float * sulphur_ext
Definition: l1.h:125
void closel1_generic(filehandle *l1file)
float * lon
Definition: l1.h:169
float * t_h2o
Definition: l1.h:241
float * sea_salt_scat
Definition: l1.h:124
char * cloud
Definition: l1.h:227
float * prof_temp
Definition: l1.h:110
char * land
Definition: l1.h:229
float * black_carbon_ext
Definition: l1.h:119
int32_t nbands
float * Fo
Definition: l1.h:274
float * t_o2
Definition: l1.h:242
float * sfcp
Definition: l1.h:200
float * sw_bb_avg
Definition: l1.h:265
int windex(float wave, float twave[], int ntwave)
Definition: windex.c:73
float * prof_o3
Definition: l1.h:114
float * no2_tropo_unc
Definition: l1.h:215
void l1_load_options(clo_optionList_t *list, filehandle *l1file)
Definition: l1_options.c:247
float * scattang
Definition: l1.h:187
void l1_read_default_files(clo_optionList_t *list, filehandle *l1file, const char *ifile)
Definition: l1_options.c:192
float * sw_n
Definition: l1.h:261
float * oz
Definition: l1.h:194
float * cloud_albedo
Definition: l1.h:257
float tilt
Definition: l1.h:158
int openl1_write(filehandle *l1file)
int setflags(l1str *l1rec)
Definition: setflags_l1.c:16
char * filter
Definition: l1.h:239
void setflagbits_l1(int level, l1str *l1rec, int32_t ipix)
Definition: setflags_l1.c:129
float * oz_unc
Definition: l1.h:212
float * rho_cirrus
Definition: l1.h:266
char * swater
Definition: l1.h:230
float * solz
Definition: l1.h:101
float * pr
Definition: l1.h:193
float * rhos
Definition: l1.h:255
float * wv
Definition: l1.h:195
float * lat
Definition: l1.h:170
float * senz
Definition: l1.h:173
char * glint
Definition: l1.h:228
float * sfc_albedo_1640
Definition: l1.h:138
float * tg_sol
Definition: l1.h:243
float * pr_unc
Definition: l1.h:211
char * solzmax
Definition: l1.h:232
char * mask
Definition: l1.h:225
int32_t length
Definition: l1.h:143
float * L_q
Definition: l1.h:250
float * sfc_albedo_2130
Definition: l1.h:139
char * ice
Definition: l1.h:231
char * hilt
Definition: l1.h:226
int openl1(filehandle *l1file)
Definition: l1_io.c:207
float * sola
Definition: l1.h:172
float * delphi
Definition: l1.h:181
float * dust_ext
Definition: l1.h:121
float * delphi
Definition: l1.h:104
void flag_bowtie_deleted(l1str *l1rec, size_t ipix, int extract_offset)
Definition: l1b_viirs_nc.c:881
float * aerindex
Definition: l1.h:258
int bindex_get_555(void)
Definition: windex.c:57
float * sfct
Definition: l1.h:202
float * black_carbon_scat
Definition: l1.h:120
void get_f0_thuillier_ext(int32_t wl, int32_t width, float *f0)
Definition: get_f0.c:137
char * navwarn
Definition: l1.h:237
float * wd
Definition: l1.h:190
int get_f0_neckel(int32_t wl, int32_t width, float *f0)
Definition: get_f0.c:5