OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1bgen_oci.h
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <fstream>
3 #include <timeutils.h>
4 #include <netcdf>
5 #include <vector>
6 
7 #define NBWAVE 512
8 #define NRWAVE 512
9 #define NIWAVE 9
10 #define NTIMES 2
11 #define NTEMPS 30
12 
13 typedef struct {
14  double master_clock;
15  double MCE_clock;
16 
17  double sc_to_tilt[3][3];
18  double tilt_axis[3];
19  double tilt_angles[2];
20  double tilt_to_oci_mech[3][3];
21  double oci_mech_to_oci_opt[3][3];
22  double rta_axis[3];
23  double ham_axis[3];
24  double ham_at_angles[2];
25  double ham_ct_angles[2];
26  double rta_enc_scale;
27  double ham_enc_scale;
28 
29  int32_t rta_nadir;
30 } geo_struct;
31 
32 typedef struct {
33  uint16_t ldims[6];
34  float **K1;
35  float ***K2;
36  float ***K3_coef;
37  float ***K4_coef;
38  double **K5;
40 
41 typedef struct {
42  uint16_t ldims[6];
43  float **K1K2;
44  float ***K3_coef;
45  float ***K4_coef;
46  double **K5;
47 } gains_struct;
48 
49 
50 #define SWAP_2(x) ( (((x) & 0xff) << 8) | ((unsigned short)(x) >> 8) )
51 
52 #define SWAP_4(x) ( ((x) << 24) | \
53  (((x) << 8) & 0x00ff0000) | \
54  (((x) >> 8) & 0x0000ff00) | \
55  ((x) >> 24) )
56 
57 
58 class l1bFile {
59  netCDF::NcFile *l1bfile;
60 
61  std::string fileName;
62 
63  int ngrps;
64  int ndims;
65 
66  netCDF::NcDim ncDims[1000];
67 
68  public:
69  l1bFile();
70  ~l1bFile();
71 
72  netCDF::NcGroup ncGrps[10];
73 
74 // std::string platform;
75 // int apktsize;
76 // int bpktsize;
77 // int EV_APIDs;
78 
79  int createl1b( char* l1b_filename, uint16_t nscan_good,
80  uint16_t pcdim, uint16_t bbb, uint16_t rbb,
81  uint16_t psdim, uint16_t swb);
82 
83 
84  int parseDims( std::string dimString, std::vector<netCDF::NcDim>& varDims);
85 
86  int write_oci_science_data( uint32_t isc,
87  uint16_t nbbs, uint16_t nrbs, uint16_t nswb,
88  uint16_t ncps, uint16_t nsps,
89  uint16_t **bsci, uint16_t **rsci,
90  uint32_t **ssci, int8_t *sfrms);
91 
92 
94  std::string l1b_name);
95 
96  int close();
97 };
98 
99 
100 int read_mce_tlm( netCDF::NcFile *l1afile, netCDF::NcGroup egid,
101  uint32_t nscan, uint32_t nenc,
102  int32_t& ppr_off, double& revpsec, double&secpline,
103  int32_t *mspin, int32_t *ot_10us, uint8_t *enc_count,
104  float **hamenc, float **rtaenc);
105 
106 int get_ev( double secpline, int16_t *dtype, int16_t *lines, int16_t *iagg,
107  uint16_t& pcdim, uint16_t& psdim, double& ev_toff,
108  float *clines, float *slines, double *deltc, double *delts,
109  int16_t& iret);
110 
111 int get_agg_mat( size_t *ia, int16_t iagg, int16_t jagg[16], uint16_t nib,
112  uint32_t& nbb, uint32_t ntb[16], float **amat, float **gmat);
113 
114 int read_oci_cal_lut( netCDF::NcFile *calLUTfile, std::string tag,
115  netCDF::NcGroup gidLUT, uint32_t& banddim,
116  cal_lut_struct& cal_lut);
117 
118 int make_oci_gains( uint32_t nib, uint32_t banddim, uint16_t iyr, uint16_t idom,
119  double stime, double K2t[NTIMES], cal_lut_struct& cal_lut,
120  float **gmat, gains_struct& gains);
121 
122 
123 int createField( netCDF::NcGroup &ncGrp, const char *sname, const char *lname,
124  const char *standard_name, const char *units,
125  void *fill_value, const char *flag_values,
126  const char *flag_meanings,
127  double low, double high, int nt,
128  std::vector<netCDF::NcDim>& varVec);
129 
130 int get_oci_vecs( uint32_t nscan, uint16_t pdim, geo_struct& geoLUT,
131  double ev_toff, int32_t spin, float *slines, double *delt,
132  double revpsec, int32_t ppr_off, int32_t *mspin,
133  int32_t *ot_10us, uint8_t *enc_count, float **hamenc,
134  float **rtaenc, float **pview, double *theta, int16_t& iret);
135 
136 template <typename T>
137 int get_oci_dark( size_t iscn, uint32_t nscan, uint8_t *hside, uint16_t ndsc,
138  uint16_t nskp, int16_t iags, int16_t iagd, uint32_t ntaps,
139  int16_t *jagg, uint32_t dfill, int16_t ndc, T ***dark,
140  uint32_t nib, float *dc, int16_t& iret);
141 
142 int get_oci_temp_corr( uint32_t nib, gains_struct gains, float K3T[NTEMPS],
143  float *caltemps, uint32_t nscan, float *k3);
144 
145 int get_oci_rvs_corr( uint32_t nib, uint16_t pdim, uint8_t hside,
146  gains_struct gains, double *theta, float **k4);
147 
148 int get_oci_lin_corr( uint32_t nib, uint16_t pdim, gains_struct gains,
149  float K3T[NTEMPS], float *caltemps, float **dn,
150  float **k5);
151 
152 template <typename T> T*** make3dT( size_t dims[3]);
153 
154 
155 inline
156 int expandEnvVar( std::string *sValue) {
157  if ( (*sValue).find_first_of( "$" ) == std::string::npos) return 0;
158  std::string::size_type posEndIdx = (*sValue).find_first_of( "/" );
159  if ( posEndIdx == std::string::npos) return 0;
160  const std::string envVar = sValue->substr (1, posEndIdx - 1);
161  char *envVar_str = getenv(envVar.c_str());
162  if (envVar_str == 0x0) {
163  printf("Environment variable: %s not defined.\n", sValue->c_str());
164  exit(1);
165  }
166  *sValue = envVar_str + (*sValue).substr( posEndIdx);
167 
168  return 0;
169 }
170 
172 
173 }
174 
175 
177 
178 }
179 
int read_mce_tlm(netCDF::NcFile *l1afile, netCDF::NcGroup egid, uint32_t nscan, uint32_t nenc, int32_t &ppr_off, double &revpsec, double &secpline, int32_t *mspin, int32_t *ot_10us, uint8_t *enc_count, float **hamenc, float **rtaenc)
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)
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, cal_lut_struct &cal_lut)
void spin(double st, double *pos1, double *pos2)
~l1bFile()
Definition: l1bgen_oci.h:176
int32 nscan
Definition: l1_czcs_hdf.c:19
@ 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:44
int createl1b(char *l1b_filename, uint16_t nscan_good, uint16_t pcdim, uint16_t bbb, uint16_t rbb, uint16_t psdim, uint16_t swb)
int get_oci_lin_corr(uint32_t nib, uint16_t pdim, gains_struct gains, float K3T[NTEMPS], float *caltemps, float **dn, float **k5)
int get_ev(double secpline, int16_t *dtype, int16_t *lines, int16_t *iagg, uint16_t &pcdim, uint16_t &psdim, double &ev_toff, float *clines, float *slines, double *deltc, double *delts, int16_t &iret)
Definition: common.cpp:7
float ** K1
Definition: l1bgen_oci.h:34
int get_agg_mat(size_t *ia, int16_t iagg, int16_t jagg[16], uint16_t nib, uint32_t &nbb, uint32_t ntb[16], float **amat, float **gmat)
int parseDims(std::string dimString, std::vector< netCDF::NcDim > &varDims)
double ** K5
Definition: l1bgen_oci.h:38
#define NTIMES
Definition: l1bgen_oci.h:10
float *** K2
Definition: l1bgen_oci.h:35
int write_granule_metadata(std::string tstart, std::string tend, std::string l1b_name)
int expandEnvVar(std::string *sValue)
Definition: l1bgen_oci.h:156
float ** K1K2
Definition: l1bgen_oci.h:43
double ** K5
Definition: l1bgen_oci.h:46
float *** K4_coef
Definition: l1bgen_oci.h:37
dtype
Definition: DDataset.hpp:31
int get_oci_vecs(uint32_t nscan, uint16_t pdim, geo_struct &geoLUT, double ev_toff, int32_t spin, float *slines, double *delt, double revpsec, int32_t ppr_off, int32_t *mspin, int32_t *ot_10us, uint8_t *enc_count, float **hamenc, float **rtaenc, float **pview, double *theta, int16_t &iret)
Definition: common.cpp:56
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:36
float *** K4_coef
Definition: l1bgen_oci.h:45
int get_oci_temp_corr(uint32_t nib, gains_struct gains, float K3T[NTEMPS], float *caltemps, uint32_t nscan, float *k3)
netCDF::NcGroup ncGrps[10]
Definition: l1bgen_oci.h:72
int make_oci_gains(uint32_t nib, uint32_t banddim, uint16_t iyr, uint16_t idom, double stime, double K2t[NTIMES], cal_lut_struct &cal_lut, float **gmat, gains_struct &gains)
int close()
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
T *** make3dT(size_t dims[3])
#define NTEMPS
Definition: l1bgen_oci.h:11