OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1agen_oci.h
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <fstream>
3 #include <timeutils.h>
4 #include <netcdf>
5 
6 #include "common.h"
7 
8 #define PBUFFER_SIZE 32768
9 #define ANCSIZE 104
10 #define TLMSIZE 3200
11 
12 const uint16_t SWIR_LOFF_ETU[9] = {80,88,72,64,80,72,0,0,0};
13 
14 // From: https://stackoverflow.com/questions/2782725/
15 // converting-float-values-from-big-endian-to-little-endian
16 float ReverseFloat( const float inFloat )
17 {
18  float retVal;
19  char *floatToConvert = ( char* ) & inFloat;
20  char *returnFloat = ( char* ) & retVal;
21 
22  // swap the bytes into a temporary buffer
23  returnFloat[0] = floatToConvert[3];
24  returnFloat[1] = floatToConvert[2];
25  returnFloat[2] = floatToConvert[1];
26  returnFloat[3] = floatToConvert[0];
27 
28  return retVal;
29 }
30 
31 typedef struct {
32  int32_t iyear;
33  int32_t iday;
34  double sec;
35 } time_struct;
36 
37 class l1aFile {
38  netCDF::NcFile *l1afile;
39 
40  std::string fileName;
41 
42  int ngrps;
43  int ndims;
44 
45  netCDF::NcDim ncDims[1000];
46  netCDF::NcGroup ncGrps[10];
47 
48  public:
49  l1aFile();
50  ~l1aFile();
51 
53  int apktsize;
54  int bpktsize;
55  int EV_APIDs;
56 
57  int createl1( char* l1_filename, uint16_t maxsc,
58  uint16_t ncps, uint16_t nbbs, uint16_t nrbs,
59  uint16_t nsps, uint16_t ndcs);
60 
61  int parseDims( std::string dimString, std::vector<netCDF::NcDim>& varDims);
62 
63  int write_oci_science_data( uint32_t isc,
64  uint16_t nbbs, uint16_t nrbs, uint16_t nswb,
65  uint16_t ncps, uint16_t nsps,
66  uint16_t **bsci, uint16_t **rsci,
67  uint32_t **ssci, int8_t *sfrms);
68 
69  int write_oci_cal_data( uint32_t isc,
70  uint16_t nbbs, uint16_t nrbs, uint16_t nswb,
71  uint16_t ndcs, uint16_t ndss,
72  uint16_t *dark_b, uint16_t *dark_r,
73  uint32_t *dark_s,
74  int8_t *sdfrms);
75 
76  int write_oci_scan_metadata( uint32_t isc, uint8_t *ancdata,
77  uint8_t *seqerr, uint8_t *linerr,
78  int32_t *spinID);
79 
81  time_struct &endtime,
82  std::string l1a_name,
83  std::string sdir, std::string edir,
84  uint32_t isc, short dtype,
85  uint16_t smode, uint16_t cdsmode,
86  std::ofstream &fout);
87 
88  int write_oci_ancil_data( uint32_t isc, uint8_t *ancdata);
89 
90  int write_oci_tlm_data( itab *itable, uint32_t ntlm, uint8_t (*tlmdata)[TLMSIZE],
91  int32_t *spinID, uint16_t &cdsmode, uint32_t isc);
93  int close();
94 };
95 
96 int make_oci_line_index( itab *itable, int16_t *cindex, int16_t *sindex,
97  int16_t *cdindex, int16_t *sdindex, int16_t *swir_loff);
98 
99 int unpack_oci_sci( uint32_t npkts, int32_t spin, uint16_t ncps, uint16_t nsps,
100  uint16_t msps,
101  uint16_t &nbands,
102  uint16_t btaps[16], uint16_t rtaps[16],
103  uint8_t (*pbuffer)[PKTSIZE],
104  uint16_t **bbands, uint16_t **rbands, uint32_t **sbands,
105  int16_t *blines, int16_t *rlines, int16_t *slines,
106  uint16_t &btype, uint16_t bagg[16],
107  uint16_t &rtype, uint16_t ragg[16],
108  int8_t *sfrm, int &iret);
109 
110 int unpack_ccd_packet( uint8_t *packet, uint16_t btaps[16], uint16_t rtaps[16],
111  uint16_t &ccdid, uint32_t &line, uint16_t &dtype,
112  uint16_t &iagg, uint16_t jagg[16], uint16_t &nbands,
113  uint16_t **ccddata, uint16_t ossdata[16]);
114 
115 int check_load_oci_data( short dtype, uint16_t ncps, uint16_t nsps,
116  uint16_t ndcs, uint16_t ndss,
117  uint16_t nbbs, uint16_t nrbs, uint16_t nswb,
118  int16_t *cindex, int16_t *sindex,
119  int16_t *cdindex, int16_t *sdindex,
120  uint16_t **bbands, uint16_t **rbands,
121  uint32_t **sbands,
122  int16_t *blines, int16_t *rlines, int16_t *slines,
123  uint16_t **bsci, uint16_t **rsci, uint32_t **ssci,
124  uint16_t **bdark, uint16_t **rdark, uint32_t **sdark,
125  uint8_t &linerr, int &icheck);
126 
127 int unpack_swir_packet( uint8_t *packet, int16_t *slines, uint8_t *swirfrm,
128  uint32_t *swirdata);
129 
130 uint8_t check_sum( int32_t nc, uint8_t *dat, uint8_t *chk);
131 
132 int eight20( uint8_t *inbytes, uint32_t *outsamples);
133 
134 int createNCDF( netCDF::NcGroup &ncGrp, const char *sname, const char *lname,
135  const char *standard_name, const char *units,
136  void *fill_value, const char *flag_values,
137  const char *flag_meanings, const char *reference,
138  double low, double high, int nt,
139  std::vector<netCDF::NcDim>& varVec);
140 
141 inline
142 int expandEnvVar( std::string *sValue) {
143  if ( (*sValue).find_first_of( "$" ) == std::string::npos) return 0;
144  std::string::size_type posEndIdx = (*sValue).find_first_of( "/" );
145  if ( posEndIdx == std::string::npos) return 0;
146  const std::string envVar = sValue->substr (1, posEndIdx - 1);
147  char *envVar_str = getenv(envVar.c_str());
148  if (envVar_str == 0x0) {
149  printf("Environment variable: %s not defined.\n", sValue->c_str());
150  exit(1);
151  }
152  *sValue = envVar_str + (*sValue).substr( posEndIdx);
153 
154  return 0;
155 }
156 
158 
159 }
160 
161 
163 
164 }
165 
int createNCDF(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, const char *reference, double low, double high, int nt, std::vector< netCDF::NcDim > &varVec)
const uint16_t SWIR_LOFF_ETU[9]
Definition: l1agen_oci.h:12
int write_navigation(std::string hktlist, time_struct &starttime, time_struct &endtime)
float ReverseFloat(const float inFloat)
Definition: l1agen_oci.h:16
int createl1(char *l1_filename, uint32_t nSC, uint32_t imgWidth, uint32_t imgHeight, uint32_t fndWidth, uint32_t fndHeight)
uint8_t check_sum(int32_t nc, uint8_t *dat, uint8_t *chk)
void spin(double st, double *pos1, double *pos2)
int bpktsize
Definition: l1agen_oci.h:54
int unpack_oci_sci(uint32_t npkts, int32_t spin, uint16_t ncps, uint16_t nsps, uint16_t msps, uint16_t &nbands, uint16_t btaps[16], uint16_t rtaps[16], uint8_t(*pbuffer)[PKTSIZE], uint16_t **bbands, uint16_t **rbands, uint32_t **sbands, int16_t *blines, int16_t *rlines, int16_t *slines, uint16_t &btype, uint16_t bagg[16], uint16_t &rtype, uint16_t ragg[16], int8_t *sfrm, int &iret)
#define TLMSIZE
Definition: l1agen_oci.h:10
int expandEnvVar(std::string *sValue)
Definition: l1agen_oci.h:142
int check_load_oci_data(short dtype, uint16_t ncps, uint16_t nsps, uint16_t ndcs, uint16_t ndss, uint16_t nbbs, uint16_t nrbs, uint16_t nswb, int16_t *cindex, int16_t *sindex, int16_t *cdindex, int16_t *sdindex, uint16_t **bbands, uint16_t **rbands, uint32_t **sbands, int16_t *blines, int16_t *rlines, int16_t *slines, uint16_t **bsci, uint16_t **rsci, uint32_t **ssci, uint16_t **bdark, uint16_t **rdark, uint32_t **sdark, uint8_t &linerr, int &icheck)
@ string
int write_oci_cal_data(uint32_t isc, uint16_t nbbs, uint16_t nrbs, uint16_t nswb, uint16_t ndcs, uint16_t ndss, uint16_t *dark_b, uint16_t *dark_r, uint32_t *dark_s, int8_t *sdfrms)
int write_oci_tlm_data(itab *itable, uint32_t ntlm, uint8_t(*tlmdata)[TLMSIZE], int32_t *spinID, uint16_t &cdsmode, uint32_t isc)
int parseDims(string dimString, int *numDims, int *varDims)
int make_oci_line_index(itab *itable, int16_t *cindex, int16_t *sindex, int16_t *cdindex, int16_t *sdindex, int16_t *swir_loff)
Definition: l1agen_oci.cpp:944
int eight20(uint8_t *inbytes, uint32_t *outsamples)
int32_t nbands
dtype
Definition: DDataset.hpp:31
Definition: common.h:9
int EV_APIDs
Definition: l1agen_oci.h:55
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)
int write_oci_global_metadata(time_struct &starttime, time_struct &endtime, std::string l1a_name, std::string sdir, std::string edir, uint32_t isc, short dtype, uint16_t smode, uint16_t cdsmode, std::ofstream &fout)
int apktsize
Definition: l1agen_oci.h:53
int unpack_ccd_packet(uint8_t *packet, uint16_t btaps[16], uint16_t rtaps[16], uint16_t &ccdid, uint32_t &line, uint16_t &dtype, uint16_t &iagg, uint16_t jagg[16], uint16_t &nbands, uint16_t **ccddata, uint16_t ossdata[16])
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]
#define PKTSIZE
Definition: common.h:7
int unpack_swir_packet(uint8_t *packet, int16_t *slines, uint8_t *swirfrm, uint32_t *swirdata)
int write_oci_scan_metadata(uint32_t isc, uint8_t *ancdata, uint8_t *seqerr, uint8_t *linerr, int32_t *spinID)
std::string platform
Definition: l1agen_oci.h:52
int write_oci_ancil_data(uint32_t isc, uint8_t *ancdata)