15 #define VERSION "1.0.4"
96 int main (
int argc,
char* argv[])
99 cout <<
"l1agen_hawkeye " <<
VERSION <<
" ("
100 << __DATE__ <<
" " << __TIME__ <<
")" << endl;
105 "input_l0_filename input_l0_textfilename output_l1a_filename" << endl;
112 tlmfile.open( argv[1], ios::binary | ifstream::in);
121 bool bImageCrossDay =
false;
122 int32_t startyr, startdy, stopyr, stopdy;
123 double startsec, stopsec;
126 l0Text.open( argv[2], ifstream::in);
127 if ( l0Text.fail() != 0) {
128 cout << endl <<
"L0 Text File: " << argv[2] <<
" not found." << endl;
133 while( !l0Text.eof()) {
135 l0Text.getline( txtbuf, 512);
136 string sValue = txtbuf;
138 found = sValue.find(
"StartHWKTime");
139 if ( found != string::npos) {
140 found = sValue.find(
"=");
141 istr.str(sValue.substr(found+1));
142 istr >> startHWKTime;
146 found = sValue.find(
"StopHWKTime");
147 if ( found != string::npos) {
148 found = sValue.find(
"=");
149 istr.str(sValue.substr(found+1));
155 nSC = (uint32_t) (stopHWKTime - startHWKTime) + 2;
157 tepoch2yds(startHWKTime, &startyr, &startdy, &startsec);
158 tepoch2yds(stopHWKTime, &stopyr, &stopdy, &stopsec);
159 if ((stopyr*1000+stopdy)>(startyr*1000+startdy)) bImageCrossDay =
true;
169 uint32_t n[4]={0,0,0,0};
170 uint32_t packet_length;
173 vector<uint8_t> heb_buf;
175 uint8_t **packet =
new uint8_t*;
176 uint32_t nImages=0, nFinder=0;
180 int tlmfile_pos = tlmfile.tellg();
189 tlmfile.read( (
char *) header, 6);
191 if( tlmfile.eof())
break;
193 int dataLen = header[4]*256 + header[5] - 2;
194 packet_length = 6 + 3 + dataLen;
195 tlmfile.seekg( -6, ios::cur);
197 (*packet) =
new uint8_t[packet_length];
198 tlmfile.read( (
char *) (*packet), packet_length);
219 if ((*packet)[7] == 255) {
220 short psub = (*packet)[8];
224 }
else if (psub == 2) {
226 }
else if (psub == 3) {
228 }
else if (psub == 4) {
234 cout <<
"Insufficient pointer allocation for psub: " << psub << endl;
235 cout <<
"Increase value of MAXNPACKETS" << endl;
240 sensor[n[0]], psensor[n[1]],
243 if (
status == 0) n[psub-1]++;
251 }
else if ((*packet)[7] == 253) {
256 if ( (*packet)[8] == 2) {
257 uint8_t infoByte = (*packet)[15];
258 uint8_t
sb = infoByte & 0x1f;
261 uint8_t sd_f = (infoByte & 0x40) >> 6;
262 uint8_t dark = (infoByte & 0x80) >> 7;
263 memcpy(&row, &(*packet)[20], 2);
266 if (sd_f == 0 &&
sb > nFinder) nFinder =
sb;
267 if (sd_f == 1 &&
sb > nImages) nImages =
sb;
270 cout <<
"SB or Finder #: " << (
int)
sb <<
271 " SpecData or Finder: " << (
int) sd_f <<
272 " Dark: " << (
int) dark <<
" Row #: " << row <<
273 " packet length: " << packet_length <<
274 " tlmfile_pos: " << tlmfile_pos << endl;
279 if ( (*packet)[8] == 3) {
282 memcpy(&
hgt, &(*packet)[48], 2);
292 uint8_t bss[6] = {0x00,0x00,0xff,0xff,0xff,0xff};
295 uint16_t checksum = 4*255;
296 for (
size_t i=8;
i<packet_length;
i++) {
297 checksum += (*packet)[
i];
299 uint16_t swapcheck =
SWAP_2(checksum);
302 heb_buf.insert(heb_buf.end(), bss, bss+6);
303 heb_buf.insert(heb_buf.end(), &(*packet)[8], &(*packet)[packet_length]);
304 heb_buf.push_back(swapcheck & 0x00ff);
305 heb_buf.push_back((swapcheck & 0xff00) >> 8);
312 uint32_t hebBufLength = heb_buf.size();
314 cout <<
"Number of SENSOR packets: " << n[
SENSOR] << endl;
315 cout <<
"Number of PSENSOR packets: " << n[
PSENSOR] << endl;
316 cout <<
"Number of ATTITUDE packets: " << n[
ATTITUDE] << endl;
317 cout <<
"Number of PROPAGATOR packets: " << n[
PROPAGATOR] << endl << endl;
319 cout <<
"Number of Spectral Images: " << nImages << endl;
320 cout <<
"Number of Finder Images: " << nFinder << endl << endl;
323 ofstream hebFile (
"heb_buf.bin",
ios::out | ios::binary);
324 hebFile.write((
char *) heb_buf.data(), hebBufLength);
332 l1a_name.assign( argv[3]);
340 cout <<
"Empty output file: " << l1a_name.c_str() << endl;
347 uint16_t band_max_height = 0;
348 for (
size_t i=0;
i<8;
i++) {
353 if (band_max_height==0) {
354 cout <<
"Image height in all bands exceeds MAXIMGHEIGHT " << endl;
359 for (
size_t i=0;
i<8;
i++) {
361 cout <<
"Image height " <<streamInfo.
spectralInfo[
i].
height<<
" in band " <<(
i+1)<<
" exceeds MAXIMGHEIGHT " << endl;
373 outfile.
createl1( (
char *) l1a_name.c_str(), nSC,
394 size_t nTlmBlocks, sizeTelBlk, nCCDtemps, nFPGAvolts, nCurrents, nCCDvolts;
396 nc_inq_dimid( outfile.
ncid,
"number_of_tlm_blocks", &dimid);
397 nc_inq_dimlen( outfile.
ncid, dimid, &nTlmBlocks);
399 nc_inq_dimid( outfile.
ncid,
"telemetry_block", &dimid);
400 nc_inq_dimlen( outfile.
ncid, dimid, &sizeTelBlk);
402 nc_inq_dimid( outfile.
ncid,
"ccd_temps", &dimid);
403 nc_inq_dimlen( outfile.
ncid, dimid, &nCCDtemps);
405 nc_inq_dimid( outfile.
ncid,
"ccd_volts", &dimid);
406 nc_inq_dimlen( outfile.
ncid, dimid, &nCCDvolts);
408 nc_inq_dimid( outfile.
ncid,
"fpga_volts", &dimid);
409 nc_inq_dimlen( outfile.
ncid, dimid, &nFPGAvolts);
411 nc_inq_dimid( outfile.
ncid,
"currents", &dimid);
412 nc_inq_dimlen( outfile.
ncid, dimid, &nCurrents);
415 uint16_t *telemetry =
new uint16_t[nTlmBlocks*sizeTelBlk];
416 double *tlm_time =
new double[nTlmBlocks];
417 uint32_t *tlm_time_stamp =
new uint32_t[nTlmBlocks];
418 int16_t *software_version =
new int16_t[nTlmBlocks];
419 int16_t *fpga_version =
new int16_t[nTlmBlocks];
420 int16_t *telemetry_counter =
new int16_t[nTlmBlocks];
422 float *ccd_temperatures =
new float[nTlmBlocks*nCCDtemps];
423 for (
size_t i=0;
i<nTlmBlocks*nCCDtemps;
i++) ccd_temperatures[
i] = -999.0;
425 float *fpga_temperature =
new float[nTlmBlocks];
426 for (
size_t i=0;
i<nTlmBlocks;
i++) fpga_temperature[
i] = -999.0;
428 float *fpga_voltages =
new float [nTlmBlocks*nFPGAvolts];
429 for (
size_t i=0;
i<nTlmBlocks*nFPGAvolts;
i++) fpga_voltages[
i] = -999.0;
431 int16_t *overcurrent =
new int16_t[nTlmBlocks];
433 float *current_monitors =
new float[nTlmBlocks*nCurrents];
434 for (
size_t i=0;
i<nTlmBlocks*nCurrents;
i++) current_monitors[
i] = -999.0;
436 float *ccd_voltages =
new float[nTlmBlocks*nCCDvolts];
437 for (
size_t i=0;
i<nTlmBlocks*nCCDvolts;
i++) ccd_voltages[
i] = -999.0;
439 float *solenoid_voltage =
new float[nTlmBlocks];
440 for (
size_t i=0;
i<nTlmBlocks;
i++) solenoid_voltage[
i] = -999.0;
445 for (
size_t i=0;
i<nTlmBlocks;
i++) {
461 tlm_time[
i] -= (53*24*3600 + 14788.224);
466 if (bImageCrossDay && (sec<80000)) tlm_time[
i] = sec+86400.0;
469 sizeTelBlk*
sizeof(
short));
472 for (
size_t j=0;
j<nChannels;
j++) {
483 software_version[
i] =
value;
485 software_version[
i] = -999;
492 fpga_version[
i] = -999;
497 telemetry_counter[
i] =
value;
499 telemetry_counter[
i] = -999;
523 fpga_temperature[
i] = -999.0;
539 overcurrent[
i] = -999;
571 solenoid_voltage[
i] =
value / 1000.0;
573 solenoid_voltage[
i] = -999.0;
580 varname.assign(
"telemetry");
581 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
582 status = nc_put_var_ushort( outfile.
gid[1], varid, telemetry);
585 varname.assign(
"tlm_time_stamp");
586 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
587 status = nc_put_var_uint( outfile.
gid[1], varid, tlm_time_stamp);
590 varname.assign(
"tlm_time");
591 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
592 status = nc_put_var_double( outfile.
gid[1], varid, tlm_time);
595 varname.assign(
"software_version");
596 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
597 status = nc_put_var_short( outfile.
gid[1], varid, software_version);
600 varname.assign(
"FPGA_version");
601 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
602 status = nc_put_var_short( outfile.
gid[1], varid, fpga_version);
605 varname.assign(
"telemetry_counter");
606 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
607 status = nc_put_var_short( outfile.
gid[1], varid, telemetry_counter);
610 varname.assign(
"CCD_temperatures");
611 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
612 status = nc_put_var_float( outfile.
gid[1], varid, ccd_temperatures);
615 varname.assign(
"FPGA_temperature");
616 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
617 status = nc_put_var_float( outfile.
gid[1], varid, fpga_temperature);
620 varname.assign(
"FPGA_voltages");
621 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
622 status = nc_put_var_float( outfile.
gid[1], varid, fpga_voltages);
625 varname.assign(
"overcurrent");
626 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
627 status = nc_put_var_short( outfile.
gid[1], varid, overcurrent);
630 varname.assign(
"current_monitors");
631 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
632 status = nc_put_var_float( outfile.
gid[1], varid, current_monitors);
635 varname.assign(
"CCD_voltages");
636 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
637 status = nc_put_var_float( outfile.
gid[1], varid, ccd_voltages);
640 varname.assign(
"solenoid_voltage");
641 status = nc_inq_varid( outfile.
gid[1], varname.c_str(), &varid);
642 status = nc_put_var_float( outfile.
gid[1], varid, solenoid_voltage);
646 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"errorCode",
650 status = nc_put_att_uint( outfile.
gid[1], NC_GLOBAL,
"exposureID",
654 status = nc_put_att_uint( outfile.
gid[1], NC_GLOBAL,
"imageID",
658 status = nc_put_att_ulonglong( outfile.
gid[1], NC_GLOBAL,
"epochT0",
659 NC_UINT64, 1, (
const long long unsigned int*)
663 status = nc_put_att_uint( outfile.
gid[1], NC_GLOBAL,
"hostDeltaEpoch",
667 status = nc_put_att_uint( outfile.
gid[1], NC_GLOBAL,
"hawkeyeDeltaEpoch",
672 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"spectralBinning",
677 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"finderscopeBinning",
682 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"channelBitfield",
687 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"ccd1Exposure",
691 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"ccd2Exposure",
695 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"ccd3Exposure",
699 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"ccd4Exposure",
703 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"height",
707 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"darkHeight",
711 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"interval",
715 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"oversampling",
719 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"finderscopeExposure",
724 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"noFinderscopeImages",
729 status = nc_put_att_ubyte( outfile.
gid[1], NC_GLOBAL,
"compression",
734 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"darkSubtracted",
739 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"shutterSolenoid",
744 status = nc_put_att_ushort( outfile.
gid[1], NC_GLOBAL,
"readoutOrder",
748 delete[] ( telemetry);
749 delete[] ( tlm_time);
750 delete[] ( tlm_time_stamp);
751 delete[] ( software_version);
752 delete[] ( fpga_version);
753 delete[] ( telemetry_counter);
754 delete[] ( ccd_temperatures);
755 delete[] ( fpga_temperature);
756 delete[] ( fpga_voltages);
757 delete[] ( overcurrent);
758 delete[] ( current_monitors);
759 delete[] ( ccd_voltages);
760 delete[] ( solenoid_voltage);
764 status = nc_put_att_text(outfile.
ncid, NC_GLOBAL,
765 "date_created", strlen(buf), buf);
772 delta_time[
i] = -999;
776 size_t startDark[3]={0, 0, 0};
777 size_t countDark[3]={1, 1, (size_t) rowOffset-2};
778 status = nc_inq_varid( outfile.
gid[3],
"band_dark_pixels", &varidDark);
780 for (
size_t i=0;
i<8;
i++) {
789 uint32_t pixelLen = imgHeight * imgWidth;
803 uint16_t *pixels =
new uint16_t[pixelLen];
804 for (
size_t j=0;
j<pixelLen;
j++) pixels[
j] = 0;
809 size_t start[2]={0, 0};
810 size_t count[2]={1, (size_t) imgWidth-rowOffset};
813 varstr <<
"band_" << setw(1) <<
i+1;
814 status = nc_inq_varid( outfile.
gid[3], varstr.str().c_str(), &varid);
816 cout <<
"Writing Band: " << (
i+1);
817 cout <<
" Image size: " << imgWidth-rowOffset <<
" by "
822 cout <<
"Image Width Error in Band " << (
i+1) << endl;
827 for (
size_t j=0;
j < (size_t) (imgHeight-1);
j++) {
829 delta_time[
j] = pixels[
j*imgWidth]*256*256 + pixels[
j*imgWidth+1];
830 if ((delta_time[
j]==0) && (
j>0) )
continue;
831 scan_time[
j] = epochT0 + delta_time[
j];
832 scan_time[
j] *= 0.001;
833 scan_time[
j] -= (53*24*3600 + 14788.224);
836 if (bImageCrossDay && (sec<80000)) scan_time[
j] = sec + 86400.0;
838 if (
j == 0 ||
j == (
size_t) (imgHeight-2)) {
846 status = nc_put_att_text(outfile.
ncid, NC_GLOBAL,
847 "time_coverage_start", strlen(buf), buf);
849 status = nc_put_att_text(outfile.
ncid, NC_GLOBAL,
850 "time_coverage_end", strlen(buf), buf);
856 &pixels[rowOffset+
j*imgWidth]);
860 status = nc_put_vara_ushort( outfile.
gid[3], varidDark,
861 startDark, countDark,
862 &pixels[2+
j*imgWidth]);
868 varname.assign(
"scan_time");
869 status = nc_inq_varid( outfile.
gid[0], varname.c_str(), &varid);
870 status = nc_put_var_double( outfile.
gid[0], varid, scan_time);
873 varname.assign(
"delta_time");
874 status = nc_inq_varid( outfile.
gid[0], varname.c_str(), &varid);
875 status = nc_put_var_int( outfile.
gid[0], varid, delta_time);
883 uint16_t finderHeight = 0;
884 uint16_t finderWidth = 0;
890 uint32_t finderPixelLen = finderHeight*finderWidth;
892 if ( finderPixelLen == 0) {
893 cout <<
"Zero Finder Pixel Length" << endl;
898 uint16_t *finderPixels =
new uint16_t[finderPixelLen];
899 for (
size_t i=0;
i<finderPixelLen;
i++) finderPixels[
i] = 0;
901 size_t start[3]={0, 0, 0};
902 size_t count[3]={1, finderHeight, finderWidth};
908 status = nc_inq_varid( outfile.
gid[3],
"finder", &varid);
910 cout << endl <<
"Writing Finder Images";
911 cout <<
" Finder size: " << finderWidth <<
" by " << finderHeight << endl;
912 int finderScopeStatus;
917 finder_time[
i] = -999;
943 finder_time[
i] = epochT0 + finder_delta_time[
i];
944 finder_time[
i] *= 0.001;
945 finder_time[
i] -= (53*24*3600 + 14788.224);
947 finder_time[
i] = sec;
948 if (bImageCrossDay && (sec<80000)) finder_time[
i] = sec + 86400.0;
951 delete[] finderPixels;
954 varname.assign(
"finder_time");
955 status = nc_inq_varid( outfile.
gid[0], varname.c_str(), &varid);
956 status = nc_put_var_double( outfile.
gid[0], varid, finder_time);
959 varname.assign(
"finder_delta_time");
960 status = nc_inq_varid( outfile.
gid[0], varname.c_str(), &varid);
961 status = nc_put_var_int( outfile.
gid[0], varid, finder_delta_time);
967 size_t startNav[2]={0, 0};
968 size_t countNav[2]={1, 1};
992 if (ngood > nSC) ngood = nSC;
995 cout <<
"No attitude records written" << endl;
998 varname.assign(
"att_time");
999 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1000 for (
size_t i=0;
i<ngood;
i++) {
1002 status = nc_put_vara_double( outfile.
gid[2], varid, startNav, countNav,
1007 varname.assign(
"att_quat");
1008 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1009 for (
size_t i=0;
i<ngood;
i++) {
1012 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1019 min = propagator[0]->
sec;
1022 if (propagator[
i]->sec <
min) {
1030 if ((propagator[
i]->sec-propagator[
i-1]->sec) < 0) {
1031 ngood =
i - offadcs;
1035 if (ngood > nSC) ngood = nSC;
1038 cout <<
"No progagator records written" << endl;
1041 varname.assign(
"orb_time");
1042 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1043 for (
size_t i=0;
i<ngood;
i++) {
1045 status = nc_put_vara_double( outfile.
gid[2], varid, startNav, countNav,
1046 &propagator[
i+offadcs]->
sec);
1050 varname.assign(
"orb_pos");
1051 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1052 for (
size_t i=0;
i<ngood;
i++) {
1055 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1056 &propagator[
i+offadcs]->
pos[0]);
1060 varname.assign(
"orb_vel");
1061 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1062 for (
size_t i=0;
i<ngood;
i++) {
1065 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1066 &propagator[
i+offadcs]->
vel[0]);
1083 for (
size_t i=offadcs+1;
i<n[
SENSOR];
i++) {
1085 ngood =
i - offadcs;
1089 if (ngood > nSC) ngood = nSC;
1092 cout <<
"No sensor records written" << endl;
1095 varname.assign(
"sensor_time");
1096 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1097 for (
size_t i=0;
i<ngood;
i++) {
1099 status = nc_put_vara_double( outfile.
gid[2], varid, startNav, countNav,
1104 varname.assign(
"sensor_bus_telemetry");
1105 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1106 for (
size_t i=0;
i<ngood;
i++) {
1109 status = nc_put_vara_ubyte( outfile.
gid[2], varid, startNav, countNav,
1110 &
sensor[
i+offadcs]->bus_telemetry[0]);
1120 if (psensor[
i]->sec <
min) {
1127 for (
size_t i=offadcs+1;
i<n[
PSENSOR];
i++) {
1128 if ((psensor[
i]->sec-psensor[
i-1]->sec) < 0) {
1129 ngood =
i - offadcs;
1133 if (ngood > nSC) ngood = nSC;
1136 cout <<
"No psensor records written" << endl;
1139 varname.assign(
"processed_sensor_time");
1140 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1141 for (
size_t i=0;
i<ngood;
i++) {
1143 status = nc_put_vara_double( outfile.
gid[2], varid, startNav, countNav,
1144 &psensor[
i+offadcs]->
sec);
1148 varname.assign(
"gyro_rates");
1149 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1150 for (
size_t i=0;
i<ngood;
i++) {
1153 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1154 &psensor[
i+offadcs]->
gyro[0]);
1158 varname.assign(
"mag1");
1159 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1160 for (
size_t i=0;
i<ngood;
i++) {
1163 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1164 &psensor[
i+offadcs]->
mag1[0]);
1168 varname.assign(
"mag2");
1169 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1170 for (
size_t i=0;
i<ngood;
i++) {
1173 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1174 &psensor[
i+offadcs]->
mag2[0]);
1178 varname.assign(
"rwheels");
1179 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1180 for (
size_t i=0;
i<ngood;
i++) {
1183 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1188 varname.assign(
"sun_vector");
1189 status = nc_inq_varid( outfile.
gid[2], varname.c_str(), &varid);
1190 for (
size_t i=0;
i<ngood;
i++) {
1193 status = nc_put_vara_float( outfile.
gid[2], varid, startNav, countNav,
1194 &psensor[
i+offadcs]->
sunb[0]);
1208 uint32_t imgWidth, uint32_t imgHeight,
1209 uint32_t fndWidth, uint32_t fndHeight) {
1213 status = nc_create( l1_filename, NC_NETCDF4, &ncid);
1216 ifstream hawkeye_l1a_data_structure;
1218 string dataStructureFile;
1220 dataStructureFile.assign(
"$OCDATAROOT/hawkeye/Hawkeye_Level-1A_Data_Structure.cdl");
1223 hawkeye_l1a_data_structure.open( dataStructureFile.c_str(), ifstream::in);
1224 if ( hawkeye_l1a_data_structure.fail() ==
true) {
1225 cout <<
"\"" << dataStructureFile.c_str() <<
"\" not found" << endl;
1231 getline( hawkeye_l1a_data_structure,
line);
1232 size_t pos =
line.find(
"dimensions:");
1233 if (
pos == 0)
break;
1240 getline( hawkeye_l1a_data_structure,
line);
1241 size_t pos =
line.find(
" = ");
1242 if (
pos == string::npos)
break;
1245 istringstream iss(
line.substr(
pos+2, string::npos));
1250 iss >> skipws >>
line;
1259 if (
line.compare(
"number_of_SC_records") == 0) {
1263 if (
line.compare(
"number_of_scans") == 0) {
1264 dimSize = imgHeight;
1267 if (
line.compare(
"number_of_pixels") == 0) {
1271 if (
line.compare(
"finder_lines") == 0) {
1272 dimSize = fndHeight;
1275 if (
line.compare(
"finder_pixels") == 0) {
1279 status = nc_def_dim( ncid,
line.c_str(), dimSize, &dimid[ndims++]);
1286 getline( hawkeye_l1a_data_structure,
line);
1287 size_t pos =
line.find(
"// global attributes");
1288 if (
pos == 0)
break;
1292 getline( hawkeye_l1a_data_structure,
line);
1293 size_t pos =
line.find(
" = ");
1294 if (
pos == string::npos)
break;
1299 attValue.assign(
line.substr(
pos+4));
1300 size_t posQuote = attValue.find(
"\"");
1301 attValue.assign(attValue.substr(0, posQuote));
1303 istringstream iss(
line.substr(
pos+2));
1306 iss >> skipws >>
line;
1309 if (
line.compare(
"//") == 0)
continue;
1312 attName.assign(
line.substr(1).c_str());
1315 if (attName.compare(
"orbit_number") == 0)
continue;
1316 if (attName.compare(
"history") == 0)
continue;
1317 if (attName.compare(
"format_version") == 0)
continue;
1318 if (attName.compare(
"instrument_number") == 0)
continue;
1319 if (attName.compare(
"pixel_offset") == 0)
continue;
1320 if (attName.compare(
"number_of_filled_scans") == 0)
continue;
1324 status = nc_put_att_text(ncid, NC_GLOBAL, attName.c_str(),
1325 strlen(attValue.c_str()), attValue.c_str());
1334 getline( hawkeye_l1a_data_structure,
line);
1338 if (
line.substr(0,1).compare(
"}") == 0) {
1339 hawkeye_l1a_data_structure.close();
1344 size_t pos =
line.find(
"group:");
1350 istringstream iss(
line.substr(6, string::npos));
1351 iss >> skipws >>
line;
1354 status = nc_def_grp( ncid,
line.c_str(), &gid[ngrps]);
1360 int varDims[NC_MAX_DIMS];
1361 size_t dimSize[NC_MAX_DIMS];
1362 char dimName[NC_MAX_NAME+1];
1368 string flag_meanings;
1371 double fill_value=0.0;
1372 float scale_factor=1.0;
1373 float add_offset=0.0;
1378 getline( hawkeye_l1a_data_structure,
line);
1380 getline( hawkeye_l1a_data_structure,
line);
1382 if (
line.length() == 0)
continue;
1383 if (
line.substr(0,1).compare(
"\r") == 0)
continue;
1384 if (
line.substr(0,1).compare(
"\n") == 0)
continue;
1389 if (
pos == string::npos) {
1394 sname.c_str(), lname.c_str(),
1396 (
void *) &fill_value,
1397 flag_values.c_str(), flag_meanings.c_str(),
1400 flag_values.assign(
"");
1401 flag_meanings.assign(
"");
1409 if (
line.substr(0,10).compare(
"} // group") == 0)
break;
1413 istringstream iss(
line);
1414 iss >> skipws >> varType;
1417 if ( varType.compare(
"char") == 0) ntype = NC_CHAR;
1418 else if ( varType.compare(
"byte") == 0) ntype = NC_BYTE;
1419 else if ( varType.compare(
"short") == 0) ntype = NC_SHORT;
1420 else if ( varType.compare(
"int") == 0) ntype = NC_INT;
1421 else if ( varType.compare(
"long") == 0) ntype = NC_INT;
1422 else if ( varType.compare(
"float") == 0) ntype = NC_FLOAT;
1423 else if ( varType.compare(
"real") == 0) ntype = NC_FLOAT;
1424 else if ( varType.compare(
"double") == 0) ntype = NC_DOUBLE;
1425 else if ( varType.compare(
"ubyte") == 0) ntype = NC_UBYTE;
1426 else if ( varType.compare(
"ushort") == 0) ntype = NC_USHORT;
1427 else if ( varType.compare(
"uint") == 0) ntype = NC_UINT;
1428 else if ( varType.compare(
"int64") == 0) ntype = NC_INT64;
1429 else if ( varType.compare(
"uint64") == 0) ntype = NC_UINT64;
1433 size_t posSname =
line.substr(0,
pos).rfind(
" ");
1434 sname.assign(
line.substr(posSname+1,
pos-posSname-1));
1440 for (
int i=0;
i<numDims;
i++) {
1441 nc_inq_dim( ncid, varDims[
i], dimName, &dimSize[
i]);
1448 size_t posEql =
line.find(
"=");
1449 size_t pos1qte =
line.find(
"\"");
1450 size_t pos2qte =
line.substr(pos1qte+1, string::npos).find(
"\"");
1456 if (
attrName.compare(
"long_name") == 0) {
1457 lname.assign(
line.substr(pos1qte+1, pos2qte));
1462 else if (
attrName.compare(
"units") == 0) {
1463 units.assign(
line.substr(pos1qte+1, pos2qte));
1468 else if (
attrName.compare(
"_FillValue") == 0) {
1470 iss.str(
line.substr(posEql+1, string::npos));
1476 else if (
attrName.compare(
"flag_values") == 0) {
1477 flag_values.assign(
line.substr(pos1qte+1, pos2qte));
1481 else if (
attrName.compare(
"flag_meanings") == 0) {
1482 flag_meanings.assign(
line.substr(pos1qte+1, pos2qte));
1486 else if (
attrName.compare(
"valid_min") == 0) {
1488 iss.str(
line.substr(posEql+1, string::npos));
1494 else if (
attrName.compare(
"valid_max") == 0) {
1496 iss.str(
line.substr(posEql+1, string::npos));
1512 size_t dimSize, curPos=0;
1513 char dimName[NC_MAX_NAME+1];
1518 size_t pos = dimString.find(
",", curPos);
1519 if (
pos == string::npos)
1520 pos = dimString.find(
")");
1523 istringstream iss(dimString.substr(curPos,
pos-curPos));
1524 iss >> skipws >> varDimName;
1526 for (
int i=0;
i<ndims;
i++) {
1527 int status = nc_inq_dim( ncid, dimid[
i], dimName, &dimSize);
1529 if ( varDimName.compare(dimName) == 0) {
1530 varDims[(*numDims)++] = dimid[
i];
1534 if ( dimString.substr(
pos, 1).compare(
")") == 0)
break;
1545 int status = nc_close(ncid);
1549 printf(
"-E - nc_close failed for ncid: %i\n",ncid);
1562 int32_t startdy, stopdy;
1565 short psub = apkt[8];
1574 memcpy(&i32, &apkt[9], 4);
1575 double tepoch = (
double) __builtin_bswap32(i32) - (1104105600+16);
1578 if ( (startHWKTime-tepoch) > 2 || (tepoch - stopHWKTime) > 1) {
1583 startdy =
iyr*1000 +
idy;
1588 memcpy(&i32, &apkt[13], 4);
1589 sec += ((
double) __builtin_bswap32(i32)) / 4294967296.0;
1590 memcpy(&i16, &apkt[17], 2);
1594 if ((stopdy>startdy) && (sec<80000)) sec += 86400.0;
1601 memcpy(
sensor->bus_telemetry, &apkt[19],
sizeof(
sensor->bus_telemetry));
1608 for (
size_t i=0;
i<3;
i++) {
1609 memcpy(&i32, &apkt[19+4*
i], 4);
1610 i32 = __builtin_bswap32(i32);
1611 memcpy(&psensor->
gyro[
i], &i32, 4);
1613 memcpy(&i32, &apkt[31+4*
i], 4);
1614 i32 = __builtin_bswap32(i32);
1615 memcpy(&psensor->
mag1[
i], &i32, 4);
1617 memcpy(&i32, &apkt[43+4*
i], 4);
1618 i32 = __builtin_bswap32(i32);
1619 memcpy(&psensor->
mag2[
i], &i32, 4);
1621 memcpy(&i32, &apkt[55+4*
i], 4);
1622 i32 = __builtin_bswap32(i32);
1623 memcpy(&psensor->
rwheels[
i], &i32, 4);
1625 memcpy(&i32, &apkt[67+4*
i], 4);
1626 i32 = __builtin_bswap32(i32);
1627 memcpy(&psensor->
sunb[
i], &i32, 4);
1635 for (
size_t i=0;
i<4;
i++) {
1636 memcpy(&i32, &apkt[19+4*
i], 4);
1637 i32 = __builtin_bswap32(i32);
1645 propagator->
sec = sec;
1646 for (
size_t i=0;
i<3;
i++) {
1647 memcpy(&i32, &apkt[19+4*
i], 4);
1648 i32 = __builtin_bswap32(i32);
1649 memcpy(&propagator->
pos[
i], &i32, 4);
1651 memcpy(&i32, &apkt[31+4*
i], 4);
1652 i32 = __builtin_bswap32(i32);
1653 memcpy(&propagator->
vel[
i], &i32, 4);