OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1agen_viirs.h
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <iostream>
3 #include <fstream>
4 
5 #define PBUFFER_SIZE 32768
6 
7 using namespace std;
8 
9 
10 class l1aFile {
11  int ncid;
12 
13  int ngrps;
14  int gid[10];
15  int ev_dids[26];
16 
17  int ndims;
18  int dimid[1000];
19 
20  uint32_t SC_records_val;
21  uint32_t SC_10hz_records_val;
22 
23  public:
24  l1aFile();
25  ~l1aFile();
26 
27  string platform;
28  int apktsize;
29  int bpktsize;
30  int gpktsize;
31  int EV_APIDs;
32 
33  int createl1( char* l1_filename, int32_t sscan, int32_t escan,
34  int32_t spixl, int32_t epixl, int32_t iopt_extract);
35  int createl1( char* l1_filename, int32_t numScans);
36 
37  int parseDims( string dimString, int *numDims, int *varDims);
38 
39  int getNcid() const { return ncid;}
40  int getNDims() const {return ndims;}
41  int getDimId (int index) const {return dimid[index];}
42 
43  int getGid( int index) { return gid[index];}
44 
45  int write_science_data( string platform, int32_t isc,
46  uint16_t (*mbands)[16][6304],
47  uint16_t (*ibands)[32][6400],
48  uint16_t (*dnb)[16][4064],
49  uint8_t (*mqfl)[16],
50  uint8_t (*iqfl)[32],
51  uint8_t (*dqfl)[16]);
52 
53  int write_scan_metadata(int32_t isc,
54  uint8_t (*p1)[180],
55  uint8_t (*hrmets)[146*26],
56  uint8_t (*calmets)[134],
57  uint8_t *mode, int iret,
58  const char* l1a_name,
59  char* VIIRS_packet_file);
60 
61  int write_eng_data( int32_t isc, uint8_t (*engdata)[9318]);
62 
63  int write_cal_data( int32_t isc,
64  int16_t (*sd_m)[48*16],
65  int16_t (*sv_m)[48*16],
66  int16_t (*bb_m)[48*16],
67  int16_t (*sd_i)[96*32],
68  int16_t (*sv_i)[96*32],
69  int16_t (*bb_i)[96*32],
70  int16_t (*sd_d)[64*16],
71  int16_t (*sv_d)[64*16],
72  int16_t (*bb_d)[64*16]);
73 
74  int write_diary( int32_t iyear, int32_t iday,
75  int32_t ltime, int32_t mtime,
76  int32_t iyrsc, int32_t idysc, int32_t nscd,
77  double *otime, float (*orb)[6],
78  double *atime, float (*quat)[4],
79  char *sdir, char *edir);
80 
81  int write_adcs_bus( int32_t iyear, int32_t iday,
82  int32_t ltime, int32_t mtime,
83  int32_t iyrad, int32_t idyad,
84  int32_t nadc, int32_t nbus, int32_t ngps,
85  double *adctime, uint8_t *admandone,
86  int16_t *adfftid,
87  double *bustime, uint8_t *adstate,
88  uint8_t *adsolution,
89  double *gpstime,
90  uint8_t *adcpkts[],
91  uint8_t *buspkts[],
92  uint8_t *gpspkts[]);
93 
94  int write_granule_metadata( int32_t iyear, int32_t iday,
95  int32_t ltime, int32_t mtime,
96  int32_t orbit,
97  const char* l1a_name,
98  char *sdir, char *edir,
99  uint8_t *p1,
100  int32_t isc, uint8_t *mode,
101  int argc, char *argv[],
102  const char* doi);
103 
104  int openl1( char* l1_filename);
105 
106  int copyl1( char *ifilename, char *ofilename, l1aFile* l1_ofile,
107  int32_t sscan, int32_t escan,
108  int32_t spixl, int32_t epixl);
109 
110  int close();
111 };
112 
113 #define SWAP_2(x) ( (((x) & 0xff) << 8) | ((unsigned short)(x) >> 8) )
114 
115 #define SWAP_4(x) ( ((x) << 24) | \
116  (((x) << 8) & 0x00ff0000) | \
117  (((x) >> 8) & 0x0000ff00) | \
118  ((x) >> 24) )
119 
120 int convert_diary( int32_t npkts, uint8_t (*dstore)[71],
121  int32_t *iyr, int32_t *iday, double *otime,
122  float (*orb)[6], double *atime, float (*quat)[4]);
123 
124 int extract_adcs_bus( int adoffsets[4],
125  int32_t nadc, uint8_t *astore[],
126  int32_t nbus, uint8_t *bstore[],
127  int32_t *iyr, int32_t *iday,
128  double *adctime, double *bustime,
129  uint8_t *adstate, uint8_t *admandone,
130  int16_t *adfftid, uint8_t *adsolution,
131  string& platform, uint16_t ngps,
132  uint8_t *gstore[], double *gpstime);
133 
134 int read_packet( fstream *vfileStream, uint8_t *packet,
135  int32_t *len, int32_t *apid, int32_t *endfile);
136 
137 int read_viirs_scan_packets( fstream *vfileStream, uint8_t *epacket,
138  uint8_t (*pbuffer)[PBUFFER_SIZE],
139  int32_t *npkts, int32_t *endfile);
140 
141 int unpack_viirs_scan( int32_t npkts,
142  uint8_t (*pbuffer)[PBUFFER_SIZE],
143  uint16_t (*mbands)[16][6304],
144  uint16_t (*ibands)[32][6400],
145  uint16_t (*dnb)[16][4064],
146  uint8_t (*mqfl)[16],
147  uint8_t (*iqfl)[32],
148  uint8_t (*dqfl)[16],
149  uint8_t (*hrmet)[146]);
150 
151 int unpack_viirs_cal( int32_t npkts,
152  uint8_t (*pbuffer)[PBUFFER_SIZE],
153  int16_t (*sdm)[16][48],
154  int16_t (*svm)[16][48],
155  int16_t (*bbm)[16][48],
156  int16_t (*sdi)[32][96],
157  int16_t (*svi)[32][96],
158  int16_t (*bbi)[32][96],
159  int16_t (*sdd)[64],
160  int16_t (*svd)[64],
161  int16_t (*bbd)[64],
162  uint8_t *calmet);
163 
164 int unpack_sci( uint8_t *idat, int32_t nsamp, int16_t *scan, uint8_t *qfl);
165 
166 int unpack_cal_sci( uint8_t *idat, int32_t nsamps, int32_t ndet,
167  int16_t *sp, int16_t *bl, int16_t *sd);
168 
169 uint8_t check_sum( int32_t nc, uint8_t *dat, uint8_t *chk);
170 
171 extern "C" int isleap(int year);
172 extern "C" int32_t jday( int16_t i, int16_t j, int16_t k);
173 extern "C" int jdate( int32_t julian, int32_t *year, int32_t *doy);
174 extern "C" int yds2tai( int16_t iyr, int16_t idy, double sec, double *tai93);
175 extern "C" int ccsds_to_yds( uint8_t *cctime, int32_t *iyear, int32_t *iday,
176  double *sec);
177 
178 //extern "C" int usds( int argc, char *argv[]);
179 extern "C" int usds( int argc, char *argv[], int32_t inBytes,
180  uint8_t *encryptData, uint16_t *decryptData);
181 
182 extern "C" long szip_uncompress_memory(int new_options_mask,
183  int new_bits_per_pixel,
184  int new_pixels_per_block,
185  int new_pixels_per_scanline,
186  const char* in,
187  long in_bytes,
188  void* out,
189  long out_pixels);
190 
191 int ccsds_to_yds( uint8_t *cctime,
192  int32_t *iyear, int32_t *iday, double *sec);
193 
194 int createNCDF( int ncid, const char *sname, const char *lname,
195  const char *standard_name, const char *units,
196  void *fill_value,
197  const char *flag_values, const char *flag_meanings,
198  double low, double high, int nt,
199  int rank, int *dimids);
200 
201 int yds2tai( int16_t iyr, int16_t idy, double sec, double *tai93);
202 
203 int32_t jday( int16_t i, int16_t j, int16_t k);
204 
205 int jgleap( int32_t jday, int32_t *leap);
206 
207 int scan_complete( uint8_t (*pbuffer)[PBUFFER_SIZE], int32_t npkts);
208 
209 inline
210 int expandEnvVar( string *sValue) {
211  if ( (*sValue).find_first_of( "$" ) == string::npos) return 0;
212  string::size_type posEndIdx = (*sValue).find_first_of( "/" );
213  if ( posEndIdx == string::npos) return 0;
214  const string envVar = sValue->substr (1, posEndIdx - 1);
215  char *envVar_str = getenv(envVar.c_str());
216  if (envVar_str == 0x0) {
217  printf("Environment variable: %s not defined.\n", sValue->c_str());
218  exit(1);
219  }
220  *sValue = envVar_str + (*sValue).substr( posEndIdx);
221 
222  return 0;
223 }
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
int scan_complete(uint8_t(*pbuffer)[PBUFFER_SIZE], int32_t npkts)
int j
Definition: decode_rs.h:73
long szip_uncompress_memory(int new_options_mask, int new_bits_per_pixel, int new_pixels_per_block, int new_pixels_per_scanline, const char *in, long in_bytes, void *out, long out_pixels)
int getNcid() const
Definition: l1agen_viirs.h:39
PGSt_SMF_status write_eng_data(EN_VDATA_TYPE_t *eng_data)
int read_packet(fstream *vfileStream, uint8_t *packet, int32_t *len, int32_t *apid, int32_t *endfile)
*********************************************HISTORY FILE for MOD_PR02AQUA **Version ****Point of no algorithm change is made in this so the and when the blackbody temperature is above a threshold Since the LWIR FPA temperature oscillates on orbit
Definition: HISTORY.txt:106
#define PBUFFER_SIZE
Definition: l1agen_viirs.h:5
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in out
Definition: HISTORY.txt:422
MOD_PR01 Production producing one five minute granule of output data in each run It can be configured to produce as many as three five minute granules per run Each execution with one construction record and one date file for each dataset In normal these are created by which splits them out of the hour datasets For LANCE they are created by which merges all session MODIS L0 datasets overlapping the requested time and extracts from the merged data those packets which fall within that time period Each scan of data is stored in the L1A granule that covers the start time of that scan
Definition: MOD_PR01_pr.txt:19
README for MOD_PR02AQUA(AQUA) Version to set to For disabling creating and output data sets when in night mode
Definition: README.txt:96
int unpack_viirs_scan(int32_t npkts, uint8_t(*pbuffer)[PBUFFER_SIZE], uint16_t(*mbands)[16][6304], uint16_t(*ibands)[32][6400], uint16_t(*dnb)[16][4064], uint8_t(*mqfl)[16], uint8_t(*iqfl)[32], uint8_t(*dqfl)[16], uint8_t(*hrmet)[146])
int jdate(int32_t julian, int32_t *year, int32_t *doy)
Definition: jdate.c:5
int getDimId(int index) const
Definition: l1agen_viirs.h:41
int usds(int argc, char *argv[], int32_t inBytes, uint8_t *encryptData, uint16_t *decryptData)
int ccsds_to_yds(uint8_t *cctime, int32_t *iyear, int32_t *iday, double *sec)
Definition: ccsds_to_yds.c:5
def mtime(the_file)
Definition: ProcUtils.py:344
string platform
Definition: l1agen_viirs.h:27
int createNCDF(int ncid, 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, int rank, int *dimids)
Definition: l1aFile.cpp:2137
PGSt_SMF_status write_scan_metadata(MODFILE *L1A_file_ptr, MD_SCAN_MET_t *scan_meta)
int gpktsize
Definition: l1agen_viirs.h:30
int extract_adcs_bus(int adoffsets[4], int32_t nadc, uint8_t *astore[], int32_t nbus, uint8_t *bstore[], int32_t *iyr, int32_t *iday, double *adctime, double *bustime, uint8_t *adstate, uint8_t *admandone, int16_t *adfftid, uint8_t *adsolution, string &platform, uint16_t ngps, uint8_t *gstore[], double *gpstime)
int unpack_sci(uint8_t *idat, int32_t nsamp, int16_t *scan, uint8_t *qfl)
int32_t jday(int16_t i, int16_t j, int16_t k)
Definition: jday.c:4
int expandEnvVar(string *sValue)
Definition: l1agen_viirs.h:210
uint8_t check_sum(int32_t nc, uint8_t *dat, uint8_t *chk)
int jgleap(int32_t jday, int32_t *leap)
Definition: l1aFile.cpp:2445
int yds2tai(int16_t iyr, int16_t idy, double sec, double *tai93)
int parseDims(int ncid, int ndims, string dimString, int *numDims, int *dimid, int *varDims)
int isleap(int year)
Definition: isleap.c:3
int unpack_viirs_cal(int32_t npkts, uint8_t(*pbuffer)[PBUFFER_SIZE], int16_t(*sdm)[16][48], int16_t(*svm)[16][48], int16_t(*bbm)[16][48], int16_t(*sdi)[32][96], int16_t(*svi)[32][96], int16_t(*bbi)[32][96], int16_t(*sdd)[64], int16_t(*svd)[64], int16_t(*bbd)[64], uint8_t *calmet)
Extra metadata that will be written to the HDF4 file l2prod rank
int getGid(int index)
Definition: l1agen_viirs.h:43
int read_viirs_scan_packets(fstream *vfileStream, uint8_t *epacket, uint8_t(*pbuffer)[PBUFFER_SIZE], int32_t *npkts, int32_t *endfile)
int unpack_cal_sci(uint8_t *idat, int32_t nsamps, int32_t ndet, int16_t *sp, int16_t *bl, int16_t *sd)
logical function leap(YEAR)
Definition: leap.f:10
integer function julian(DAY, MONTH, YEAR)
Definition: julian.f:2
int convert_diary(int32_t npkts, uint8_t(*dstore)[71], int32_t *iyr, int32_t *iday, double *otime, float(*orb)[6], double *atime, float(*quat)[4])
int32_t idy
Definition: atrem_corl1.h:161
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]
int i
Definition: decode_rs.h:71
#define EV_APIDs
int openl1(filehandle *l1file)
Definition: l1_io.c:207
int32_t iyr
Definition: atrem_corl1.h:161
int k
Definition: decode_rs.h:73
int getNDims() const
Definition: l1agen_viirs.h:40
subroutine bbm
Definition: 6sm1.f:3281