15 #define VERSION "1.0.5"
100 cout <<
"l1agen_hawkeye " <<
VERSION <<
" ("
101 << __DATE__ <<
" " << __TIME__ <<
")" << endl;
106 "input_l0_filename input_l0_textfilename output_l1a_filename" << endl;
113 tlmfile.open( argv[1], ios::binary | ifstream::in);
122 bool bImageCrossDay =
false;
123 int32_t startyr, startdy, stopyr, stopdy;
124 double startsec, stopsec;
127 l0Text.open( argv[2], ifstream::in);
128 if ( l0Text.fail() != 0) {
129 cout << endl <<
"L0 Text File: " << argv[2] <<
" not found." << endl;
134 while( !l0Text.eof()) {
136 l0Text.getline( txtbuf, 512);
137 string sValue = txtbuf;
139 found = sValue.find(
"StartHWKTime");
140 if ( found != string::npos) {
141 found = sValue.find(
"=");
142 istr.str(sValue.substr(found+1));
143 istr >> startHWKTime;
147 found = sValue.find(
"StopHWKTime");
148 if ( found != string::npos) {
149 found = sValue.find(
"=");
150 istr.str(sValue.substr(found+1));
156 nSC = (uint32_t) (stopHWKTime - startHWKTime) + 2;
158 tepoch2yds(startHWKTime, &startyr, &startdy, &startsec);
159 tepoch2yds(stopHWKTime, &stopyr, &stopdy, &stopsec);
160 if ((stopyr*1000+stopdy)>(startyr*1000+startdy)) bImageCrossDay =
true;
170 uint32_t n[4]={0,0,0,0};
171 uint32_t packet_length;
174 vector<uint8_t> heb_buf;
176 uint8_t **packet =
new uint8_t*;
177 uint32_t nImages=0, nFinder=0;
181 int tlmfile_pos = tlmfile.tellg();
190 tlmfile.read( (
char *) header, 6);
192 if( tlmfile.eof())
break;
194 int dataLen = header[4]*256 + header[5] - 2;
195 packet_length = 6 + 3 + dataLen;
196 tlmfile.seekg( -6, ios::cur);
198 (*packet) =
new uint8_t[packet_length];
199 tlmfile.read( (
char *) (*packet), packet_length);
220 if ((*packet)[7] == 255) {
221 short psub = (*packet)[8];
225 }
else if (psub == 2) {
227 }
else if (psub == 3) {
229 }
else if (psub == 4) {
235 cout <<
"Insufficient pointer allocation for psub: " << psub << endl;
236 cout <<
"Increase value of MAXNPACKETS" << endl;
241 sensor[n[0]], psensor[n[1]],
244 if (
status == 0) n[psub-1]++;
252 }
else if ((*packet)[7] == 253) {
257 if ( (*packet)[8] == 2) {
258 uint8_t infoByte = (*packet)[15];
259 uint8_t
sb = infoByte & 0x1f;
262 uint8_t sd_f = (infoByte & 0x40) >> 6;
263 uint8_t dark = (infoByte & 0x80) >> 7;
264 memcpy(&row, &(*packet)[20], 2);
267 if (sd_f == 0 &&
sb > nFinder) nFinder =
sb;
268 if (sd_f == 1 &&
sb > nImages) nImages =
sb;
271 cout <<
"SB or Finder #: " << (
int)
sb <<
272 " SpecData or Finder: " << (
int) sd_f <<
273 " Dark: " << (
int) dark <<
" Row #: " << row <<
274 " packet length: " << packet_length <<
275 " tlmfile_pos: " << tlmfile_pos << endl;
280 if ( (*packet)[8] == 3) {
283 memcpy(&
hgt, &(*packet)[48], 2);
293 uint8_t bss[6] = {0x00,0x00,0xff,0xff,0xff,0xff};
296 uint16_t checksum = 4*255;
297 for (
size_t i=8;
i<packet_length;
i++) {
298 checksum += (*packet)[
i];
300 uint16_t swapcheck =
SWAP_2(checksum);
303 heb_buf.insert(heb_buf.end(), bss, bss+6);
304 heb_buf.insert(heb_buf.end(), &(*packet)[8], &(*packet)[packet_length]);
305 heb_buf.push_back(swapcheck & 0x00ff);
306 heb_buf.push_back((swapcheck & 0xff00) >> 8);
313 uint32_t hebBufLength = heb_buf.size();
315 cout <<
"Number of SENSOR packets: " << n[
SENSOR] << endl;
316 cout <<
"Number of PSENSOR packets: " << n[
PSENSOR] << endl;
317 cout <<
"Number of ATTITUDE packets: " << n[
ATTITUDE] << endl;
318 cout <<
"Number of PROPAGATOR packets: " << n[
PROPAGATOR] << endl << endl;
320 cout <<
"Number of Spectral Images: " << nImages << endl;
321 cout <<
"Number of Finder Images: " << nFinder << endl << endl;
324 ofstream hebFile (
"heb_buf.bin",
ios::out | ios::binary);
325 hebFile.write((
char *) heb_buf.data(), hebBufLength);
333 l1a_name.assign( argv[3]);
341 cout <<
"Empty output file: " << l1a_name.c_str() << endl;
348 uint16_t band_max_height = 0;
349 for (
size_t i=0;
i<8;
i++) {
354 if (band_max_height==0) {
355 cout <<
"Image height in all bands exceeds MAXIMGHEIGHT " << endl;
360 for (
size_t i=0;
i<8;
i++) {
362 cout <<
"Image height " <<streamInfo.
spectralInfo[
i].
height<<
" in band " <<(
i+1)<<
" exceeds MAXIMGHEIGHT " << endl;
374 outfile.createl1( (
char *) l1a_name.c_str(), nSC,
395 size_t nTlmBlocks, sizeTelBlk, nCCDtemps, nFPGAvolts, nCurrents, nCCDvolts;
397 nc_inq_dimid(
outfile.ncid,
"number_of_tlm_blocks", &dimid);
398 nc_inq_dimlen(
outfile.ncid, dimid, &nTlmBlocks);
400 nc_inq_dimid(
outfile.ncid,
"telemetry_block", &dimid);
401 nc_inq_dimlen(
outfile.ncid, dimid, &sizeTelBlk);
403 nc_inq_dimid(
outfile.ncid,
"ccd_temps", &dimid);
404 nc_inq_dimlen(
outfile.ncid, dimid, &nCCDtemps);
406 nc_inq_dimid(
outfile.ncid,
"ccd_volts", &dimid);
407 nc_inq_dimlen(
outfile.ncid, dimid, &nCCDvolts);
409 nc_inq_dimid(
outfile.ncid,
"fpga_volts", &dimid);
410 nc_inq_dimlen(
outfile.ncid, dimid, &nFPGAvolts);
412 nc_inq_dimid(
outfile.ncid,
"currents", &dimid);
413 nc_inq_dimlen(
outfile.ncid, dimid, &nCurrents);
416 uint16_t *telemetry =
new uint16_t[nTlmBlocks*sizeTelBlk];
417 double *tlm_time =
new double[nTlmBlocks];
418 uint32_t *tlm_time_stamp =
new uint32_t[nTlmBlocks];
420 int16_t *fpga_version =
new int16_t[nTlmBlocks];
421 int16_t *telemetry_counter =
new int16_t[nTlmBlocks];
423 float *ccd_temperatures =
new float[nTlmBlocks*nCCDtemps];
424 for (
size_t i=0;
i<nTlmBlocks*nCCDtemps;
i++) ccd_temperatures[
i] = -999.0;
426 float *fpga_temperature =
new float[nTlmBlocks];
427 for (
size_t i=0;
i<nTlmBlocks;
i++) fpga_temperature[
i] = -999.0;
429 float *fpga_voltages =
new float [nTlmBlocks*nFPGAvolts];
430 for (
size_t i=0;
i<nTlmBlocks*nFPGAvolts;
i++) fpga_voltages[
i] = -999.0;
432 int16_t *overcurrent =
new int16_t[nTlmBlocks];
434 float *current_monitors =
new float[nTlmBlocks*nCurrents];
435 for (
size_t i=0;
i<nTlmBlocks*nCurrents;
i++) current_monitors[
i] = -999.0;
437 float *ccd_voltages =
new float[nTlmBlocks*nCCDvolts];
438 for (
size_t i=0;
i<nTlmBlocks*nCCDvolts;
i++) ccd_voltages[
i] = -999.0;
440 float *solenoid_voltage =
new float[nTlmBlocks];
441 for (
size_t i=0;
i<nTlmBlocks;
i++) solenoid_voltage[
i] = -999.0;
446 for (
size_t i=0;
i<nTlmBlocks;
i++) {
462 tlm_time[
i] -= (53*24*3600 + 14788.224);
467 if (bImageCrossDay && (sec<80000)) tlm_time[
i] = sec+86400.0;
470 sizeTelBlk*
sizeof(
short));
473 for (
size_t j=0;
j<nChannels;
j++) {
493 fpga_version[
i] = -999;
498 telemetry_counter[
i] =
value;
500 telemetry_counter[
i] = -999;
524 fpga_temperature[
i] = -999.0;
540 overcurrent[
i] = -999;
572 solenoid_voltage[
i] =
value / 1000.0;
574 solenoid_voltage[
i] = -999.0;
581 varname.assign(
"telemetry");
582 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
583 status = nc_put_var_ushort(
outfile.gid[1], varid, telemetry);
586 varname.assign(
"tlm_time_stamp");
587 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
588 status = nc_put_var_uint(
outfile.gid[1], varid, tlm_time_stamp);
591 varname.assign(
"tlm_time");
592 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
593 status = nc_put_var_double(
outfile.gid[1], varid, tlm_time);
596 varname.assign(
"software_version");
597 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
601 varname.assign(
"FPGA_version");
602 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
603 status = nc_put_var_short(
outfile.gid[1], varid, fpga_version);
606 varname.assign(
"telemetry_counter");
607 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
608 status = nc_put_var_short(
outfile.gid[1], varid, telemetry_counter);
611 varname.assign(
"CCD_temperatures");
612 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
613 status = nc_put_var_float(
outfile.gid[1], varid, ccd_temperatures);
616 varname.assign(
"FPGA_temperature");
617 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
618 status = nc_put_var_float(
outfile.gid[1], varid, fpga_temperature);
621 varname.assign(
"FPGA_voltages");
622 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
623 status = nc_put_var_float(
outfile.gid[1], varid, fpga_voltages);
626 varname.assign(
"overcurrent");
627 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
628 status = nc_put_var_short(
outfile.gid[1], varid, overcurrent);
631 varname.assign(
"current_monitors");
632 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
633 status = nc_put_var_float(
outfile.gid[1], varid, current_monitors);
636 varname.assign(
"CCD_voltages");
637 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
638 status = nc_put_var_float(
outfile.gid[1], varid, ccd_voltages);
641 varname.assign(
"solenoid_voltage");
642 status = nc_inq_varid(
outfile.gid[1], varname.c_str(), &varid);
643 status = nc_put_var_float(
outfile.gid[1], varid, solenoid_voltage);
647 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"errorCode",
651 status = nc_put_att_uint(
outfile.gid[1], NC_GLOBAL,
"exposureID",
655 status = nc_put_att_uint(
outfile.gid[1], NC_GLOBAL,
"imageID",
659 status = nc_put_att_ulonglong(
outfile.gid[1], NC_GLOBAL,
"epochT0",
660 NC_UINT64, 1, (
const long long unsigned int*)
664 status = nc_put_att_uint(
outfile.gid[1], NC_GLOBAL,
"hostDeltaEpoch",
668 status = nc_put_att_uint(
outfile.gid[1], NC_GLOBAL,
"hawkeyeDeltaEpoch",
673 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"spectralBinning",
678 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"finderscopeBinning",
683 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"channelBitfield",
688 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"ccd1Exposure",
692 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"ccd2Exposure",
696 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"ccd3Exposure",
700 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"ccd4Exposure",
704 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"height",
708 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"darkHeight",
712 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"interval",
716 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"oversampling",
720 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"finderscopeExposure",
725 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"noFinderscopeImages",
730 status = nc_put_att_ubyte(
outfile.gid[1], NC_GLOBAL,
"compression",
735 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"darkSubtracted",
740 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"shutterSolenoid",
745 status = nc_put_att_ushort(
outfile.gid[1], NC_GLOBAL,
"readoutOrder",
749 delete[] ( telemetry);
750 delete[] ( tlm_time);
751 delete[] ( tlm_time_stamp);
753 delete[] ( fpga_version);
754 delete[] ( telemetry_counter);
755 delete[] ( ccd_temperatures);
756 delete[] ( fpga_temperature);
757 delete[] ( fpga_voltages);
758 delete[] ( overcurrent);
759 delete[] ( current_monitors);
760 delete[] ( ccd_voltages);
761 delete[] ( solenoid_voltage);
766 "date_created", strlen(buf), buf);
773 delta_time[
i] = -999;
777 size_t startDark[3]={0, 0, 0};
778 size_t countDark[3]={1, 1, (size_t) rowOffset-2};
779 status = nc_inq_varid(
outfile.gid[3],
"band_dark_pixels", &varidDark);
781 for (
size_t i=0;
i<8;
i++) {
790 uint32_t pixelLen = imgHeight * imgWidth;
804 uint16_t *pixels =
new uint16_t[pixelLen];
805 for (
size_t j=0;
j<pixelLen;
j++) pixels[
j] = 0;
810 size_t start[2]={0, 0};
811 size_t count[2]={1, (size_t) imgWidth-rowOffset};
814 varstr <<
"band_" << setw(1) <<
i+1;
815 status = nc_inq_varid(
outfile.gid[3], varstr.str().c_str(), &varid);
817 cout <<
"Writing Band: " << (
i+1);
818 cout <<
" Image size: " << imgWidth-rowOffset <<
" by "
823 cout <<
"Image Width Error in Band " << (
i+1) << endl;
828 for (
size_t j=0;
j < (size_t) (imgHeight-1);
j++) {
830 delta_time[
j] = pixels[
j*imgWidth]*256*256 + pixels[
j*imgWidth+1];
831 if ((delta_time[
j]==0) && (
j>0) )
continue;
832 scan_time[
j] = epochT0 + delta_time[
j];
833 scan_time[
j] *= 0.001;
834 scan_time[
j] -= (53*24*3600 + 14788.224);
837 if (bImageCrossDay && (sec<80000)) scan_time[
j] = sec + 86400.0;
842 double myUnixTime=
yds2unix(year, doy, sec);
845 "time_coverage_start", strlen(buf), buf);
851 &pixels[rowOffset+
j*imgWidth]);
856 startDark, countDark,
857 &pixels[2+
j*imgWidth]);
864 double myUnixTime=
yds2unix(year, doy, sec);
867 "time_coverage_end", strlen(buf), buf);
872 varname.assign(
"scan_time");
873 status = nc_inq_varid(
outfile.gid[0], varname.c_str(), &varid);
874 status = nc_put_var_double(
outfile.gid[0], varid, scan_time);
877 varname.assign(
"delta_time");
878 status = nc_inq_varid(
outfile.gid[0], varname.c_str(), &varid);
887 uint16_t finderHeight = 0;
888 uint16_t finderWidth = 0;
894 uint32_t finderPixelLen = finderHeight*finderWidth;
896 if ( finderPixelLen == 0) {
897 cout <<
"Zero Finder Pixel Length" << endl;
902 uint16_t *finderPixels =
new uint16_t[finderPixelLen];
903 for (
size_t i=0;
i<finderPixelLen;
i++) finderPixels[
i] = 0;
905 size_t start[3]={0, 0, 0};
906 size_t count[3]={1, finderHeight, finderWidth};
914 cout << endl <<
"Writing Finder Images";
915 cout <<
" Finder size: " << finderWidth <<
" by " << finderHeight << endl;
916 int finderScopeStatus;
921 finder_time[
i] = -999;
947 finder_time[
i] = epochT0 + finder_delta_time[
i];
948 finder_time[
i] *= 0.001;
949 finder_time[
i] -= (53*24*3600 + 14788.224);
951 finder_time[
i] = sec;
952 if (bImageCrossDay && (sec<80000)) finder_time[
i] = sec + 86400.0;
955 delete[] finderPixels;
958 varname.assign(
"finder_time");
959 status = nc_inq_varid(
outfile.gid[0], varname.c_str(), &varid);
960 status = nc_put_var_double(
outfile.gid[0], varid, finder_time);
963 varname.assign(
"finder_delta_time");
964 status = nc_inq_varid(
outfile.gid[0], varname.c_str(), &varid);
965 status = nc_put_var_int(
outfile.gid[0], varid, finder_delta_time);
971 size_t startNav[2]={0, 0};
972 size_t countNav[2]={1, 1};
996 if (ngood > nSC) ngood = nSC;
999 cout <<
"No attitude records written" << endl;
1002 varname.assign(
"att_time");
1003 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1004 for (
size_t i=0;
i<ngood;
i++) {
1006 status = nc_put_vara_double(
outfile.gid[2], varid, startNav, countNav,
1011 varname.assign(
"att_quat");
1012 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1013 for (
size_t i=0;
i<ngood;
i++) {
1016 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1023 min = propagator[0]->
sec;
1026 if (propagator[
i]->sec <
min) {
1034 if ((propagator[
i]->sec-propagator[
i-1]->sec) < 0) {
1035 ngood =
i - offadcs;
1039 if (ngood > nSC) ngood = nSC;
1042 cout <<
"No progagator records written" << endl;
1045 varname.assign(
"orb_time");
1046 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1047 for (
size_t i=0;
i<ngood;
i++) {
1049 status = nc_put_vara_double(
outfile.gid[2], varid, startNav, countNav,
1050 &propagator[
i+offadcs]->
sec);
1054 varname.assign(
"orb_pos");
1055 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1056 for (
size_t i=0;
i<ngood;
i++) {
1059 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1060 &propagator[
i+offadcs]->
pos[0]);
1064 varname.assign(
"orb_vel");
1065 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1066 for (
size_t i=0;
i<ngood;
i++) {
1069 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1070 &propagator[
i+offadcs]->
vel[0]);
1087 for (
size_t i=offadcs+1;
i<n[
SENSOR];
i++) {
1089 ngood =
i - offadcs;
1093 if (ngood > nSC) ngood = nSC;
1096 cout <<
"No sensor records written" << endl;
1099 varname.assign(
"sensor_time");
1100 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1101 for (
size_t i=0;
i<ngood;
i++) {
1103 status = nc_put_vara_double(
outfile.gid[2], varid, startNav, countNav,
1108 varname.assign(
"sensor_bus_telemetry");
1109 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1110 for (
size_t i=0;
i<ngood;
i++) {
1113 status = nc_put_vara_ubyte(
outfile.gid[2], varid, startNav, countNav,
1114 &
sensor[
i+offadcs]->bus_telemetry[0]);
1124 if (psensor[
i]->sec <
min) {
1131 for (
size_t i=offadcs+1;
i<n[
PSENSOR];
i++) {
1132 if ((psensor[
i]->sec-psensor[
i-1]->sec) < 0) {
1133 ngood =
i - offadcs;
1137 if (ngood > nSC) ngood = nSC;
1140 cout <<
"No psensor records written" << endl;
1143 varname.assign(
"processed_sensor_time");
1144 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1145 for (
size_t i=0;
i<ngood;
i++) {
1147 status = nc_put_vara_double(
outfile.gid[2], varid, startNav, countNav,
1148 &psensor[
i+offadcs]->
sec);
1152 varname.assign(
"gyro_rates");
1153 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1154 for (
size_t i=0;
i<ngood;
i++) {
1157 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1158 &psensor[
i+offadcs]->
gyro[0]);
1162 varname.assign(
"mag1");
1163 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1164 for (
size_t i=0;
i<ngood;
i++) {
1167 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1168 &psensor[
i+offadcs]->
mag1[0]);
1172 varname.assign(
"mag2");
1173 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1174 for (
size_t i=0;
i<ngood;
i++) {
1177 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1178 &psensor[
i+offadcs]->
mag2[0]);
1182 varname.assign(
"rwheels");
1183 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1184 for (
size_t i=0;
i<ngood;
i++) {
1187 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1192 varname.assign(
"sun_vector");
1193 status = nc_inq_varid(
outfile.gid[2], varname.c_str(), &varid);
1194 for (
size_t i=0;
i<ngood;
i++) {
1197 status = nc_put_vara_float(
outfile.gid[2], varid, startNav, countNav,
1198 &psensor[
i+offadcs]->
sunb[0]);
1212 uint32_t imgWidth, uint32_t imgHeight,
1213 uint32_t fndWidth, uint32_t fndHeight) {
1217 status = nc_create( l1_filename, NC_NETCDF4, &ncid);
1220 ifstream hawkeye_l1a_data_structure;
1222 string dataStructureFile;
1224 dataStructureFile.assign(
"$OCDATAROOT/hawkeye/Hawkeye_Level-1A_Data_Structure.cdl");
1227 hawkeye_l1a_data_structure.open( dataStructureFile.c_str(), ifstream::in);
1228 if ( hawkeye_l1a_data_structure.fail() ==
true) {
1229 cout <<
"\"" << dataStructureFile.c_str() <<
"\" not found" << endl;
1235 getline( hawkeye_l1a_data_structure,
line);
1236 size_t pos =
line.find(
"dimensions:");
1237 if (
pos == 0)
break;
1244 getline( hawkeye_l1a_data_structure,
line);
1245 size_t pos =
line.find(
" = ");
1246 if (
pos == string::npos)
break;
1249 istringstream iss(
line.substr(
pos+2, string::npos));
1254 iss >> skipws >>
line;
1263 if (
line.compare(
"number_of_SC_records") == 0) {
1267 if (
line.compare(
"number_of_scans") == 0) {
1268 dimSize = imgHeight;
1271 if (
line.compare(
"number_of_pixels") == 0) {
1275 if (
line.compare(
"finder_lines") == 0) {
1276 dimSize = fndHeight;
1279 if (
line.compare(
"finder_pixels") == 0) {
1283 status = nc_def_dim( ncid,
line.c_str(), dimSize, &dimid[ndims++]);
1290 getline( hawkeye_l1a_data_structure,
line);
1291 size_t pos =
line.find(
"// global attributes");
1292 if (
pos == 0)
break;
1296 getline( hawkeye_l1a_data_structure,
line);
1297 size_t pos =
line.find(
" = ");
1298 if (
pos == string::npos)
break;
1303 attValue.assign(
line.substr(
pos+4));
1304 size_t posQuote = attValue.find(
"\"");
1305 attValue.assign(attValue.substr(0, posQuote));
1307 istringstream iss(
line.substr(
pos+2));
1310 iss >> skipws >>
line;
1313 if (
line.compare(
"//") == 0)
continue;
1316 attName.assign(
line.substr(1).c_str());
1319 if (attName.compare(
"orbit_number") == 0)
continue;
1320 if (attName.compare(
"history") == 0)
continue;
1321 if (attName.compare(
"format_version") == 0)
continue;
1322 if (attName.compare(
"instrument_number") == 0)
continue;
1323 if (attName.compare(
"pixel_offset") == 0)
continue;
1324 if (attName.compare(
"number_of_filled_scans") == 0)
continue;
1328 status = nc_put_att_text(ncid, NC_GLOBAL, attName.c_str(),
1329 strlen(attValue.c_str()), attValue.c_str());
1338 getline( hawkeye_l1a_data_structure,
line);
1342 if (
line.substr(0,1).compare(
"}") == 0) {
1343 hawkeye_l1a_data_structure.close();
1348 size_t pos =
line.find(
"group:");
1354 istringstream iss(
line.substr(6, string::npos));
1355 iss >> skipws >>
line;
1358 status = nc_def_grp( ncid,
line.c_str(), &gid[ngrps]);
1364 int varDims[NC_MAX_DIMS];
1365 size_t dimSize[NC_MAX_DIMS];
1366 char dimName[NC_MAX_NAME+1];
1372 string flag_meanings;
1375 double fill_value=0.0;
1376 float scale_factor=1.0;
1377 float add_offset=0.0;
1382 getline( hawkeye_l1a_data_structure,
line);
1384 getline( hawkeye_l1a_data_structure,
line);
1386 if (
line.length() == 0)
continue;
1387 if (
line.substr(0,1).compare(
"\r") == 0)
continue;
1388 if (
line.substr(0,1).compare(
"\n") == 0)
continue;
1393 if (
pos == string::npos) {
1398 sname.c_str(), lname.c_str(),
1400 (
void *) &fill_value,
1401 flag_values.c_str(), flag_meanings.c_str(),
1404 flag_values.assign(
"");
1405 flag_meanings.assign(
"");
1413 if (
line.substr(0,10).compare(
"} // group") == 0)
break;
1417 istringstream iss(
line);
1418 iss >> skipws >> varType;
1421 if ( varType.compare(
"char") == 0) ntype = NC_CHAR;
1422 else if ( varType.compare(
"byte") == 0) ntype = NC_BYTE;
1423 else if ( varType.compare(
"short") == 0) ntype = NC_SHORT;
1424 else if ( varType.compare(
"int") == 0) ntype = NC_INT;
1425 else if ( varType.compare(
"long") == 0) ntype = NC_INT;
1426 else if ( varType.compare(
"float") == 0) ntype = NC_FLOAT;
1427 else if ( varType.compare(
"real") == 0) ntype = NC_FLOAT;
1428 else if ( varType.compare(
"double") == 0) ntype = NC_DOUBLE;
1429 else if ( varType.compare(
"ubyte") == 0) ntype = NC_UBYTE;
1430 else if ( varType.compare(
"ushort") == 0) ntype = NC_USHORT;
1431 else if ( varType.compare(
"uint") == 0) ntype = NC_UINT;
1432 else if ( varType.compare(
"int64") == 0) ntype = NC_INT64;
1433 else if ( varType.compare(
"uint64") == 0) ntype = NC_UINT64;
1437 size_t posSname =
line.substr(0,
pos).rfind(
" ");
1438 sname.assign(
line.substr(posSname+1,
pos-posSname-1));
1444 for (
int i=0;
i<numDims;
i++) {
1445 nc_inq_dim( ncid, varDims[
i], dimName, &dimSize[
i]);
1452 size_t posEql =
line.find(
"=");
1453 size_t pos1qte =
line.find(
"\"");
1454 size_t pos2qte =
line.substr(pos1qte+1, string::npos).find(
"\"");
1460 if (
attrName.compare(
"long_name") == 0) {
1461 lname.assign(
line.substr(pos1qte+1, pos2qte));
1466 else if (
attrName.compare(
"units") == 0) {
1467 units.assign(
line.substr(pos1qte+1, pos2qte));
1472 else if (
attrName.compare(
"_FillValue") == 0) {
1474 iss.str(
line.substr(posEql+1, string::npos));
1480 else if (
attrName.compare(
"flag_values") == 0) {
1481 flag_values.assign(
line.substr(pos1qte+1, pos2qte));
1485 else if (
attrName.compare(
"flag_meanings") == 0) {
1486 flag_meanings.assign(
line.substr(pos1qte+1, pos2qte));
1490 else if (
attrName.compare(
"valid_min") == 0) {
1492 iss.str(
line.substr(posEql+1, string::npos));
1498 else if (
attrName.compare(
"valid_max") == 0) {
1500 iss.str(
line.substr(posEql+1, string::npos));
1516 size_t dimSize, curPos=0;
1517 char dimName[NC_MAX_NAME+1];
1522 size_t pos = dimString.find(
",", curPos);
1523 if (
pos == string::npos)
1524 pos = dimString.find(
")");
1527 istringstream iss(dimString.substr(curPos,
pos-curPos));
1528 iss >> skipws >> varDimName;
1530 for (
int i=0;
i<ndims;
i++) {
1531 int status = nc_inq_dim( ncid, dimid[
i], dimName, &dimSize);
1533 if ( varDimName.compare(dimName) == 0) {
1534 varDims[(*numDims)++] = dimid[
i];
1538 if ( dimString.substr(
pos, 1).compare(
")") == 0)
break;
1549 int status = nc_close(ncid);
1553 printf(
"-E - nc_close failed for ncid: %i\n",ncid);
1566 int32_t startdy, stopdy;
1569 short psub = apkt[8];
1578 memcpy(&i32, &apkt[9], 4);
1579 double tepoch = (
double) __builtin_bswap32(i32) - (1104105600+16);
1582 if ( (startHWKTime-tepoch) > 2 || (tepoch - stopHWKTime) > 1) {
1587 startdy =
iyr*1000 +
idy;
1592 memcpy(&i32, &apkt[13], 4);
1593 sec += ((
double) __builtin_bswap32(i32)) / 4294967296.0;
1594 memcpy(&i16, &apkt[17], 2);
1598 if ((stopdy>startdy) && (sec<80000)) sec += 86400.0;
1605 memcpy(
sensor->bus_telemetry, &apkt[19],
sizeof(
sensor->bus_telemetry));
1612 for (
size_t i=0;
i<3;
i++) {
1613 memcpy(&i32, &apkt[19+4*
i], 4);
1614 i32 = __builtin_bswap32(i32);
1615 memcpy(&psensor->
gyro[
i], &i32, 4);
1617 memcpy(&i32, &apkt[31+4*
i], 4);
1618 i32 = __builtin_bswap32(i32);
1619 memcpy(&psensor->
mag1[
i], &i32, 4);
1621 memcpy(&i32, &apkt[43+4*
i], 4);
1622 i32 = __builtin_bswap32(i32);
1623 memcpy(&psensor->
mag2[
i], &i32, 4);
1625 memcpy(&i32, &apkt[55+4*
i], 4);
1626 i32 = __builtin_bswap32(i32);
1627 memcpy(&psensor->
rwheels[
i], &i32, 4);
1629 memcpy(&i32, &apkt[67+4*
i], 4);
1630 i32 = __builtin_bswap32(i32);
1631 memcpy(&psensor->
sunb[
i], &i32, 4);
1639 for (
size_t i=0;
i<4;
i++) {
1640 memcpy(&i32, &apkt[19+4*
i], 4);
1641 i32 = __builtin_bswap32(i32);
1649 propagator->
sec = sec;
1650 for (
size_t i=0;
i<3;
i++) {
1651 memcpy(&i32, &apkt[19+4*
i], 4);
1652 i32 = __builtin_bswap32(i32);
1653 memcpy(&propagator->
pos[
i], &i32, 4);
1655 memcpy(&i32, &apkt[31+4*
i], 4);
1656 i32 = __builtin_bswap32(i32);
1657 memcpy(&propagator->
vel[
i], &i32, 4);