13 #define VERSION "0.68"
46 int main (
int argc,
char* argv[])
49 cout <<
"l0info_oci " <<
VERSION <<
" ("
50 << __DATE__ <<
" " << __TIME__ <<
")" << endl;
54 "l0info_oci OCI_packet_file granule_len" << endl;
61 tfileStream.open( argv[optind+0], fstream::in | fstream::binary);
62 if ( tfileStream.fail()) {
63 cout << argv[optind+0] <<
" not found" << endl;
73 uint32_t maxpkts = 15000;
77 uint8_t **pbuffer0 =
new uint8_t *[maxpkts];
78 pbuffer0[0] =
new uint8_t[
PKTSIZE*maxpkts];
79 for (
size_t i=1;
i<maxpkts;
i++) pbuffer0[
i] = pbuffer0[
i-1] +
PKTSIZE;
84 vector<int32_t> tlmind0;
90 cout <<
"Packet too big (" << len <<
") for buffer (" <<
PKTSIZE <<
")"
94 read_packet( &tfileStream, fpacket, len, apid, endfile);
95 apid = (fpacket[0] % 8)*256 + fpacket[1];
97 while (apid != 636 && apid != 700 && apid != 720 && !endfile) {
101 cout <<
"Packet too big (" << len <<
") for buffer (" <<
PKTSIZE <<
")"
105 read_packet( &tfileStream, fpacket, len, apid, endfile);
106 apid = (fpacket[0] % 8)*256 + fpacket[1];
110 cout <<
"No science packets found in file" << endl;
113 if (nsk > 0) cout << nsk <<
" packets skipped" << endl;
127 string str = argv[optind+1];
128 istringstream(
str) >> mper;
134 string dtypes[] = {
"",
"",
"_DARK",
"_SOL-D",
"_SOL-M",
"_LIN",
"_LUN",
135 "_DIAG",
"_SNAP-T",
"_SNAP-S",
"_STAT",
"_SPEC"};
136 string smodes[] = {
"",
"_SDIAG",
"_SRAW",
"_STEST"};
138 uint8_t **pbuffer =
new uint8_t *[maxpkts];
139 pbuffer[0] =
new uint8_t[
PKTSIZE*maxpkts];
140 for (
size_t i=1;
i<maxpkts;
i++) pbuffer[
i] = pbuffer[
i-1] +
PKTSIZE;
142 uint16_t ncps, nbbs, nrbs, nsps, ndcs, ndss, btaps[16], rtaps[16];
144 uint8_t *seqerr =
new uint8_t[maxpkts];
145 for (
size_t i=1;
i<maxpkts;
i++) {
153 while (ancind0 == -1) {
155 (uint8_t (*)[
PKTSIZE]) &pbuffer0[0][0],
156 npkts0, spn0, ancind0, tlmind0, noseq, endfile);
158 cout <<
"No ancillary packets found in file" << endl;
164 memcpy( apacket0, &pbuffer0[ancind0][0],
ANCSIZE);
166 btaps, rtaps, itable);
168 while (((ncps == 1 && ndcs == 1) || ancind0 == -1) && !endfile) {
171 (uint8_t (*)[
PKTSIZE]) &pbuffer0[0][0],
172 npkts0, spn0, ancind0, tlmind0, noseq, endfile);
175 memcpy( apacket0, &pbuffer0[ancind0][0],
ANCSIZE);
177 btaps, rtaps, itable);
181 cout <<
"No ancillary packets for last granule" << endl;
187 double scanp = 1.0 / 5.737;
188 double stimp = stime - scanp;
200 ltime = (((int32_t) (stime)) / 60 / mper) * (mper*60);
204 ltime = (int32_t) stime;
207 cout <<
"Processing with single file option" << endl;
208 ltime = (int32_t) stime;
217 uint16_t smodep = smode;
221 uint32_t jd0 =
jday(iyear, 1, iday);
223 int16_t yr16 = (int16_t) iyear;
224 int16_t
doy = (int16_t) iday;
228 int32_t
ih = (int32_t) (ltime / 3600);
229 int32_t mn = (int32_t) ((ltime -
ih*3600) / 60);
230 int32_t isec = (int32_t) (ltime -
ih*3600 - mn*60);
232 stringstream timestr, datestr;
233 timestr << setfill(
'0') << setw(2) <<
ih
234 << setfill(
'0') << setw(2) << mn
235 << setfill(
'0') << setw(2) << isec;
239 datestr << setfill(
'0') << setw(4) << iyear
240 << setfill(
'0') << setw(2) << month
241 << setfill(
'0') << setw(2) << dom;
243 string l1a_name =
string(
"PACE_OCI") +
244 dtypes[itable[1].
dtype] + smodes[smode] +
"." +
245 datestr.str() +
"T" + timestr.str() +
".L1A.nc";
249 cout << endl << l1a_name.c_str() << endl;
251 uint8_t **ancdata =
new uint8_t *[maxsc+1];
252 ancdata[0] =
new uint8_t[
ANCSIZE*(maxsc+1)];
253 for (
size_t i=1;
i< (size_t) (maxsc+1);
i++)
264 while ( !enddata && scomp) {
268 memcpy( &pbuffer[0][0], &pbuffer0[0][0],
PKTSIZE*maxpkts);
276 (uint8_t (*)[
PKTSIZE]) &pbuffer0[0][0],
277 npkts0, spn0, ancind0, tlmind0, seqerr[isc],
283 if (stime > stimp && npkts > 1) {
286 if (ancind != -1) memcpy(ancdata[isc], pbuffer[ancind],
ANCSIZE);
290 endtime.
iyear = iyear;
298 if (!enddata && ancind0 != -1) {
299 memcpy( apacket, &pbuffer0[ancind0][0],
ANCSIZE);
301 uint32_t
jd =
jday(iyear, 1, iday);
302 stime += (
jd - jd0) * 86400;
305 scomp = (smode == smodep);
308 ih = (int32_t) (stime / 3600);
309 mn = (int32_t) ((stime -
ih*3600) / 60);
310 isec = (int32_t) (stime -
ih*3600 - mn*60);
311 cout <<
"SWIR data mode change at: "
312 <<
ih <<
" " << mn <<
" " << isec << endl;
319 if (dspn > maxsc) cout <<
"Spin number gap: " << spn <<
" " << spn0
323 cout <<
"Scans in file: " << isc << endl;
328 if (ancind0 != -1) memcpy(ancdata[isc], apacket,
ANCSIZE);
334 string startstring, endstring;
336 cout <<
"Start Time=" << startstring.c_str() << endl;
337 cout <<
"End Time =" << endstring.c_str() << endl;
353 string &startstring,
string &endstring) {
368 ss << setw(4) << to_string(
starttime.iyear) <<
"-";
369 ss << setw(2) << setfill(
'0') << mon <<
"-";
370 ss << setw(2) << setfill(
'0') << idm <<
"T";
372 ss << setw(2) << setfill(
'0') <<
ih <<
":";
373 ss << setw(2) << setfill(
'0') << mn <<
":";
374 ss << fixed << setw(6) << setprecision(3) <<
377 startstring = ss.str();
380 yd2md((int16_t) endtime.
iyear, (int16_t) endtime.
iday, &mon, &idm);
383 endtime.
sec -=
ih * 3600;
384 mn = (
int) (endtime.
sec/60);
385 endtime.
sec -= mn * 60;
389 ss << setw(4) << to_string(endtime.
iyear) <<
"-";
390 ss << setw(2) << setfill(
'0') << mon <<
"-";
391 ss << setw(2) << setfill(
'0') << idm <<
"T";
393 ss << setw(2) << setfill(
'0') <<
ih <<
":";
394 ss << setw(2) << setfill(
'0') << mn <<
":";
395 ss << fixed << setw(6) << setprecision(3) <<
396 setfill(
'0') << endtime.
sec;
398 endstring = ss.str();