12 #define VERSION "0.68"
46 cout <<
"l0info_oci " <<
VERSION <<
" (" << __DATE__ <<
" " << __TIME__ <<
")" << endl;
49 cout << endl <<
"l0info_oci OCI_packet_file granule_len" << endl;
56 tfileStream.open(argv[optind + 0], fstream::in | fstream::binary);
57 if (tfileStream.fail()) {
58 cout << argv[optind + 0] <<
" not found" << endl;
68 uint32_t maxpkts = 15000;
72 uint8_t **pbuffer0 =
new uint8_t *[maxpkts];
73 pbuffer0[0] =
new uint8_t[
PKTSIZE * maxpkts];
74 for (
size_t i = 1;
i < maxpkts;
i++)
80 vector<int32_t> tlmind0;
85 cout <<
"Packet too big (" << len <<
") for buffer (" <<
PKTSIZE <<
")" << endl;
88 read_packet(&tfileStream, fpacket, len, apid, endfile);
89 apid = (fpacket[0] % 8) * 256 + fpacket[1];
91 while (apid != 636 && apid != 700 && apid != 720 && !endfile) {
95 cout <<
"Packet too big (" << len <<
") for buffer (" <<
PKTSIZE <<
")" << endl;
98 read_packet(&tfileStream, fpacket, len, apid, endfile);
99 apid = (fpacket[0] % 8) * 256 + fpacket[1];
103 cout <<
"No science packets found in file" << endl;
107 cout << nsk <<
" packets skipped" << endl;
120 string str = argv[optind + 1];
121 istringstream(
str) >> mper;
127 string dtypes[] = {
"",
"",
"_DARK",
"_SOL-D",
"_SOL-M",
"_LIN",
128 "_LUN",
"_DIAG",
"_SNAP-T",
"_SNAP-S",
"_STAT",
"_SPEC"};
129 string smodes[] = {
"",
"_SDIAG",
"_SRAW",
"_STEST"};
131 uint8_t **pbuffer =
new uint8_t *[maxpkts];
132 pbuffer[0] =
new uint8_t[
PKTSIZE * maxpkts];
133 for (
size_t i = 1;
i < maxpkts;
i++)
136 uint16_t ncps, nbbs, nrbs, nsps, ndcs, ndss, btaps[16], rtaps[16];
138 uint8_t *seqerr =
new uint8_t[maxpkts];
139 for (
size_t i = 1;
i < maxpkts;
i++) {
146 while (ancind0 == -1) {
148 ancind0, tlmind0, noseq, endfile);
150 cout <<
"No ancillary packets found in file" << endl;
156 memcpy(apacket0, &pbuffer0[ancind0][0],
ANCSIZE);
157 get_band_dims(apacket0, ncps, nbbs, nrbs, nsps, ndcs, ndss, btaps, rtaps, itable);
159 while (((ncps == 1 && ndcs == 1) || ancind0 == -1) && !endfile) {
162 ancind0, tlmind0, noseq, endfile);
165 memcpy(apacket0, &pbuffer0[ancind0][0],
ANCSIZE);
166 get_band_dims(apacket0, ncps, nbbs, nrbs, nsps, ndcs, ndss, btaps, rtaps, itable);
170 cout <<
"No ancillary packets for last granule" << endl;
176 double scanp = 1.0 / 5.737;
177 double stimp = stime - scanp;
189 ltime = (((int32_t)(stime)) / 60 / mper) * (mper * 60);
193 ltime = (int32_t)stime;
196 cout <<
"Processing with single file option" << endl;
197 ltime = (int32_t)stime;
206 uint16_t smodep = smode;
210 uint32_t jd0 =
jday(iyear, 1, iday);
212 int16_t yr16 = (int16_t)iyear;
213 int16_t doy = (int16_t)iday;
215 yd2md(yr16, doy, &month, &dom);
217 int32_t
ih = (int32_t)(ltime / 3600);
218 int32_t mn = (int32_t)((ltime -
ih * 3600) / 60);
219 int32_t isec = (int32_t)(ltime -
ih * 3600 - mn * 60);
221 stringstream timestr, datestr;
222 timestr << setfill(
'0') << setw(2) <<
ih << setfill(
'0') << setw(2) << mn << setfill(
'0') << setw(2)
227 datestr << setfill(
'0') << setw(4) << iyear << setfill(
'0') << setw(2) << month << setfill(
'0')
230 string l1a_name =
string(
"PACE_OCI") + dtypes[itable[1].
dtype] + smodes[smode] +
"." + datestr.str() +
231 "T" + timestr.str() +
".L1A.nc";
235 cout << endl << l1a_name.c_str() << endl;
237 uint8_t **ancdata =
new uint8_t *[maxsc + 1];
238 ancdata[0] =
new uint8_t[
ANCSIZE * (maxsc + 1)];
239 for (
size_t i = 1;
i < (size_t)(maxsc + 1);
i++)
250 while (!enddata && scomp) {
254 memcpy(&pbuffer[0][0], &pbuffer0[0][0],
PKTSIZE * maxpkts);
262 ancind0, tlmind0, seqerr[isc], endfile);
266 if (stime > stimp && npkts > 1) {
269 memcpy(ancdata[isc], pbuffer[ancind],
ANCSIZE);
273 endtime.
iyear = iyear;
281 if (!enddata && ancind0 != -1) {
282 memcpy(apacket, &pbuffer0[ancind0][0],
ANCSIZE);
284 uint32_t
jd =
jday(iyear, 1, iday);
285 stime += (
jd - jd0) * 86400;
288 scomp = (smode == smodep);
291 ih = (int32_t)(stime / 3600);
292 mn = (int32_t)((stime -
ih * 3600) / 60);
293 isec = (int32_t)(stime -
ih * 3600 - mn * 60);
294 cout <<
"SWIR data mode change at: " <<
ih <<
" " << mn <<
" " << isec << endl;
302 cout <<
"Spin number gap: " << spn <<
" " << spn0 << endl;
305 cout <<
"Scans in file: " << isc << endl;
310 memcpy(ancdata[isc], apacket,
ANCSIZE);
316 string startstring, endstring;
318 cout <<
"Start Time=" << startstring.c_str() << endl;
319 cout <<
"End Time =" << endstring.c_str() << endl;
347 ss << setw(4) << to_string(
starttime.iyear) <<
"-";
348 ss << setw(2) << setfill(
'0') << mon <<
"-";
349 ss << setw(2) << setfill(
'0') << idm <<
"T";
351 ss << setw(2) << setfill(
'0') <<
ih <<
":";
352 ss << setw(2) << setfill(
'0') << mn <<
":";
353 ss << fixed << setw(6) << setprecision(3) << setfill(
'0') <<
starttime.sec;
355 startstring = ss.str();
360 endtime.
sec -=
ih * 3600;
361 mn = (
int)(endtime.
sec / 60);
362 endtime.
sec -= mn * 60;
366 ss << setw(4) << to_string(endtime.
iyear) <<
"-";
367 ss << setw(2) << setfill(
'0') << mon <<
"-";
368 ss << setw(2) << setfill(
'0') << idm <<
"T";
370 ss << setw(2) << setfill(
'0') <<
ih <<
":";
371 ss << setw(2) << setfill(
'0') << mn <<
":";
372 ss << fixed << setw(6) << setprecision(3) << setfill(
'0') << endtime.
sec;
374 endstring = ss.str();