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