NASA Logo
Ocean Color Science Software

ocssw V2022
l1bgen_oci.h
Go to the documentation of this file.
1 #ifndef _L1BGEN_OCI_H_
2 #define _L1BGEN_OCI_H_
3 
4 #include <stdint.h>
5 #include <fstream>
6 #include <timeutils.h>
7 #include <netcdf>
8 #include <vector>
9 
10 #include "common.h"
11 
12 #include <gsl/gsl_fit.h>
13 
14 #define NBWAVE 512
15 #define NRWAVE 512
16 #define NIWAVE 9
17 //#define NTIMES 2
18 //#define NTEMPS 30
19 
20 typedef struct {
21  uint16_t ldims[7];
22  float **K1;
23  float ***K2;
24  float ***K3_coef;
25  float ****K4_coef;
26  double **K5_coef;
27  uint32_t *sat_thres;
28  float ***m12_coef;
29  float ***m13_coef;
31 
32 typedef struct {
33  uint16_t ldims[6];
34  float **K1K2;
35  float ***K3_coef;
36  float ***K4_coef;
37  double **K5_coef;
38  uint32_t *sat_thres;
39 } gains_struct;
40 
41 
42 #define SWAP_2(x) ( (((x) & 0xff) << 8) | ((unsigned short)(x) >> 8) )
43 
44 #define SWAP_4(x) ( ((x) << 24) | \
45  (((x) << 8) & 0x00ff0000) | \
46  (((x) >> 8) & 0x0000ff00) | \
47  ((x) >> 24) )
48 
49 
50 class l1bFile {
51  std::string fileName;
52 
53  int ngrps;
54  int ndims;
55 
56  netCDF::NcDim ncDims[1000];
57 
58  public:
59  l1bFile();
60  ~l1bFile();
61 
62  netCDF::NcFile *l1bfile;
63 
64  netCDF::NcGroup ncGrps[10];
65 
66 // std::string platform;
67 // int apktsize;
68 // int bpktsize;
69 // int EV_APIDs;
70 
71  int parseDims( std::string dimString, std::vector<netCDF::NcDim>& varDims);
72 
73  int write_oci_science_data( uint32_t isc,
74  uint16_t nbbs, uint16_t nrbs, uint16_t nswb,
75  uint16_t ncps, uint16_t nsps,
76  uint16_t **bsci, uint16_t **rsci,
77  uint32_t **ssci, int8_t *sfrms);
78 
79 
81  std::string l1b_name);
82 
83  int close();
84 };
85 
86 int read_oci_cal_lut( netCDF::NcFile *calLUTfile, std::string tag,
87  netCDF::NcGroup gidLUT,
88  uint32_t& banddim, uint32_t mcedim, uint32_t& nldim,
89  uint32_t& poldim, cal_lut_struct& cal_lut);
90 
91 int make_oci_gains( uint32_t nib, uint32_t banddim, uint16_t iyr, uint32_t jd,
92  double stime, size_t numTimes, double *K2t, int16_t board_id,
93  int16_t iagg, int16_t *jagg, cal_lut_struct& cal_lut,
94  float **gmat, gains_struct& gains);
95 
96 int createField( netCDF::NcGroup &ncGrp, const char *sname, const char *lname,
97  const char *standard_name, const char *units,
98  void *fill_value, const char *flag_values,
99  const char *flag_meanings,
100  double low, double high, int nt,
101  std::vector<netCDF::NcDim>& varVec);
102 
103 template <typename T>
104 int get_oci_dark( size_t iscn, uint32_t nscan, uint8_t *hside, uint16_t ndsc,
105  uint16_t nskp, int16_t iags, int16_t iagd, uint32_t ntaps,
106  int16_t *jagg, uint32_t dfill, int16_t ndc, T ***dark,
107  uint32_t nib, float *dc, int16_t& iret);
108 
109 int get_oci_temp_corr( uint32_t nib, gains_struct gains, float *K3T,
110  float *caltemps, uint32_t nscan, float *k3);
111 
112 int get_oci_rvs_corr( uint32_t nib, uint16_t pdim, uint8_t hside,
113  gains_struct gains, double *theta, float **k4);
114 
115 int get_oci_lin_corr( uint32_t nib, uint16_t pdim, uint32_t nldim,
116  gains_struct gains, float **dn, float **k5);
117 //int get_oci_lin_corr( uint32_t nib, uint16_t pdim, gains_struct gains,
118 // float *K3T, float *caltemps, float **dn, float **k5);
119 
120 
121 int get_oci_cal_temps( netCDF::NcFile *l1afile, netCDF::NcGroup edid,
122  uint16_t ntemps, uint32_t nscan,
123  double *evtime, float **caltemps);
124 
125 template <typename T> T*** make3dT( size_t dims[3]);
126 template <typename T> T**** make4dT( size_t dims[4]);
127 
128 inline
129 int expandEnvVar( std::string *sValue) {
130  if ( (*sValue).find_first_of( "$" ) == std::string::npos) return 0;
131  std::string::size_type posEndIdx = (*sValue).find_first_of( "/" );
132  if ( posEndIdx == std::string::npos) return 0;
133  const std::string envVar = sValue->substr (1, posEndIdx - 1);
134  char *envVar_str = getenv(envVar.c_str());
135  if (envVar_str == 0x0) {
136  printf("Environment variable: %s not defined.\n", sValue->c_str());
137  exit(1);
138  }
139  *sValue = envVar_str + (*sValue).substr( posEndIdx);
140 
141  return 0;
142 }
143 
145 
146 }
147 
148 
150 
151 }
152 
153 
154 #endif // _L1BGEN_OCI_H_
int createField(netCDF::NcGroup &ncGrp, const char *sname, const char *lname, const char *standard_name, const char *units, void *fill_value, const char *flag_values, const char *flag_meanings, double low, double high, int nt, std::vector< netCDF::NcDim > &varVec)
double ** K5_coef
Definition: l1bgen_oci.h:26
int make_oci_gains(uint32_t nib, uint32_t banddim, uint16_t iyr, uint32_t jd, double stime, size_t numTimes, double *K2t, int16_t board_id, int16_t iagg, int16_t *jagg, cal_lut_struct &cal_lut, float **gmat, gains_struct &gains)
int get_oci_dark(size_t iscn, uint32_t nscan, uint8_t *hside, uint16_t ndsc, uint16_t nskp, int16_t iags, int16_t iagd, uint32_t ntaps, int16_t *jagg, uint32_t dfill, int16_t ndc, T ***dark, uint32_t nib, float *dc, int16_t &iret)
int read_oci_cal_lut(netCDF::NcFile *calLUTfile, std::string tag, netCDF::NcGroup gidLUT, uint32_t &banddim, uint32_t mcedim, uint32_t &nldim, uint32_t &poldim, cal_lut_struct &cal_lut)
~l1bFile()
Definition: l1bgen_oci.h:149
@ string
int get_oci_rvs_corr(uint32_t nib, uint16_t pdim, uint8_t hside, gains_struct gains, double *theta, float **k4)
float *** K3_coef
Definition: l1bgen_oci.h:35
float ** K1
Definition: l1bgen_oci.h:22
T **** make4dT(size_t dims[4])
int parseDims(std::string dimString, std::vector< netCDF::NcDim > &varDims)
uint32_t * sat_thres
Definition: l1bgen_oci.h:38
float *** m13_coef
Definition: l1bgen_oci.h:29
Definition: jd.py:1
int get_oci_lin_corr(uint32_t nib, uint16_t pdim, uint32_t nldim, gains_struct gains, float **dn, float **k5)
int get_oci_temp_corr(uint32_t nib, gains_struct gains, float *K3T, float *caltemps, uint32_t nscan, float *k3)
float *** K2
Definition: l1bgen_oci.h:23
int write_granule_metadata(std::string tstart, std::string tend, std::string l1b_name)
float **** K4_coef
Definition: l1bgen_oci.h:25
int expandEnvVar(std::string *sValue)
Definition: l1bgen_oci.h:129
float ** K1K2
Definition: l1bgen_oci.h:34
int get_oci_cal_temps(netCDF::NcFile *l1afile, netCDF::NcGroup edid, uint16_t ntemps, uint32_t nscan, double *evtime, float **caltemps)
netCDF::NcFile * l1bfile
Definition: l1bgen_oci.h:62
int write_oci_science_data(uint32_t isc, uint16_t nbbs, uint16_t nrbs, uint16_t nswb, uint16_t ncps, uint16_t nsps, uint16_t **bsci, uint16_t **rsci, uint32_t **ssci, int8_t *sfrms)
float *** K3_coef
Definition: l1bgen_oci.h:24
float *** K4_coef
Definition: l1bgen_oci.h:36
netCDF::NcGroup ncGrps[10]
Definition: l1bgen_oci.h:64
int close()
float *** m12_coef
Definition: l1bgen_oci.h:28
These two strings are used for the product XML output If product_id is not set then prefix is used If the last char of the name_prefix is _ then it is removed If algorithm_id is not set then name_suffix is used If the first char is _ then it is removed l2prod standard_name[0]
int32_t iyr
Definition: atrem_corl1.h:161
double ** K5_coef
Definition: l1bgen_oci.h:37
T *** make3dT(size_t dims[3])
uint32_t * sat_thres
Definition: l1bgen_oci.h:27