69 Pvl &lab = *cube.
label();
70 PvlGroup &inst = lab.findGroup(
"Instrument", Pvl::Traverse);
71 p_instrumentId = (QString) inst[
"InstrumentId"];
72 p_startingSample = inst[
"FirstLineSample"];
73 p_crosstrackSumming = inst[
"CrosstrackSumming"];
74 p_downtrackSumming = inst[
"DowntrackSumming"];
75 p_exposureDuration = inst[
"LineExposureDuration"];
76 p_focalPlaneTemp = inst[
"FocalPlaneTemperature"];
77 p_clockCount = (QString) inst[
"SpacecraftClockCount"];
79 if(inst.hasKeyword(
"OrbitNumber")) {
80 p_orbitNumber = inst[
"OrbitNumber"];
82 p_gainModeId = (QString) inst[
"GainModeId"];
83 p_offsetModeId = inst[
"OffsetModeId"];
84 p_startTime = (QString) inst[
"StartTime"];
87 p_dataQuality =
"Unknown";
88 PvlGroup &arch = lab.findGroup(
"Archive", Pvl::Traverse);
89 if(arch.hasKeyword(
"DataQualityDesc")) {
90 p_dataQuality = (QString) arch[
"DataQualityDesc"];
94 PvlGroup &bandBin = lab.findGroup(
"BandBin", Pvl::Traverse);
95 p_filter = (QString) bandBin[
"FilterName"];
104 PvlGroup &kerns = lab.findGroup(
"Kernels", Pvl::Traverse);
105 p_lsk = FileName(kerns[
"LeapSecond"][0]);
106 p_sclk = FileName(kerns[
"SpacecraftClock"][0]);
118 if(p_instrumentId ==
"MOC-NA") p_mocNA =
true;
119 if(p_instrumentId ==
"MOC-WA") {
120 if(p_filter ==
"RED") p_mocRedWA =
true;
121 if(p_filter ==
"BLUE") p_mocBlueWA =
true;
124 if(!p_mocNA && !p_mocRedWA && !p_mocBlueWA) {
125 QString msg =
"InstrumentID [" + p_instrumentId +
"] and/or FilterName ["
126 + p_filter +
"] are inappropriate for the MOC camera";
127 throw IException(IException::Unknown, msg, _FILEINFO_);
132 if((p_crosstrackSumming < 1) || (p_crosstrackSumming > 8)) {
133 string msg =
"MOC-NA keyword [CrosstrackSumming] must be between ";
134 msg +=
"1 and 8, but is [" + IString(p_crosstrackSumming) +
"]";
135 throw IException(IException::Unknown, msg, _FILEINFO_);
138 if((p_downtrackSumming < 1) || (p_downtrackSumming > 8)) {
139 string msg =
"MOC-NA keyword [DowntrackSumming] must be between ";
140 msg +=
"1 and 8, but is [" + IString(p_downtrackSumming) +
"]";
141 throw IException(IException::Unknown, msg, _FILEINFO_);
146 if((p_mocRedWA) || (p_mocBlueWA)) {
147 if((p_crosstrackSumming < 1) || (p_crosstrackSumming > 127)) {
148 string msg =
"MOC-WA keyword [CrosstrackSumming] must be between ";
149 msg +=
"1 and 127, but is [" + IString(p_crosstrackSumming) +
"]";
150 throw IException(IException::Unknown, msg, _FILEINFO_);
153 if((p_downtrackSumming < 1) || (p_downtrackSumming > 127)) {
154 string msg =
"MOC-WA keyword [DowntrackSumming] must be between ";
155 msg +=
"1 and 127, but is [" + IString(p_downtrackSumming) +
"]";
156 throw IException(IException::Unknown, msg, _FILEINFO_);
165 p_trueLineRate = p_exposureDuration * (double) p_downtrackSumming;
166 p_trueLineRate /= 1000.0;
170 p_exposureDuration *= p_downtrackSumming;
174 map<QString, double>::iterator p;
176 p = p_gainMapNA.find(p_gainModeId);
177 if(p == p_gainMapNA.end()) {
178 QString msg =
"Invalid value for PVL keyword GainModeId [" +
180 throw IException(IException::Unknown, msg, _FILEINFO_);
184 p = p_gainMapWA.find(p_gainModeId);
185 if(p == p_gainMapWA.end()) {
186 QString msg =
"Invalid value for PVL keyword GainModeId [" +
188 throw IException(IException::Unknown, msg, _FILEINFO_);
194 p_offset = p_offsetModeId * 5.0;
200 iTime currentTime(p_startTime);
201 iTime mappingPhaseBeginTime(
"1999-04-03T01:00:40.441");
202 if(currentTime < mappingPhaseBeginTime) {
203 double newGain = p_gain / (double) p_downtrackSumming;
204 double mindiff = DBL_MAX;
205 map<QString, double>::iterator p;
207 p = p_gainMapNA.begin();
208 while(p != p_gainMapNA.end()) {
209 double diff = abs(newGain - p->second);
218 p = p_gainMapNA.find(index);
219 if(p == p_gainMapNA.end()) {
220 string msg =
"Could not find new gain for pre-mapping narrow angle image";
221 throw IException(IException::Unknown, msg, _FILEINFO_);
230 bool useWeb = QString(Preference::Preferences().findGroup(
"SpiceQL")[
"UseSpiceQL"]).toUpper() ==
"TRUE";
232 auto [output, kernels] = SpiceQL::strSclkToEt(-94, p_clockCount.toLatin1().data(),
"mgs", useWeb);
323 if(p_crosstrackSumming == 13) {
324 for(
int i = 0; i < p_ns; i++) {
325 p_startDetector[i] = mode13_table[i].starting_pixel +
326 p_startingSample - 1;
327 p_endDetector[i] = mode13_table[i].ending_pixel +
328 p_startingSample - 1;
331 else if(p_crosstrackSumming == 27) {
332 for(
int i = 0; i < p_ns; i++) {
333 p_startDetector[i] = mode27_table[i].starting_pixel +
334 p_startingSample - 1;
335 p_endDetector[i] = mode27_table[i].ending_pixel +
336 p_startingSample - 1;
340 int detector = (p_startingSample - 1);
341 for(
int i = 0; i < p_ns; i++) {
342 p_startDetector[i] = detector;
343 detector += p_crosstrackSumming - 1;
344 p_endDetector[i] = detector;
351 for(
int det = 0; det <
Detectors(); det++) {
352 p_sample[det] = -1.0;
355 for(
int samp = 1; samp <= p_ns; samp++) {
356 int sd = p_startDetector[samp-1];
357 int ed = p_endDetector[samp-1];
359 double m = ((samp + 0.5) - (samp - 0.5)) / ((ed + 0.5) - (sd - 0.5));
360 for(
int det = sd; det <= ed; det++) {
361 p_sample[det] = m * (det - (sd - 0.5)) + (samp - 0.5);
421 static bool firstTime =
true;
422 if(!firstTime)
return;
426 FileName wagoFile(
"$mgs/calibration/MGSC_????_wago.tab");
427 wagoFile = wagoFile.highestVersion();
428 QString nameOfFile = wagoFile.expanded();
429 ifstream temp(nameOfFile.toLatin1().data());
430 vector<int> wholeFile;
434 int nextByte = temp.get();
435 if(nextByte != 10 && nextByte != 13) {
436 wholeFile.push_back(nextByte);
443 int high = wholeFile.size() / 35;
445 IString line, filter, sclk, offsetId;
453 middle = (low + high) / 2;
454 int SclkStart = middle * 35 + 8;
455 int SclkEnd = SclkStart + 15;
459 for(
int i = SclkStart; i < SclkEnd; i++) {
460 currentSclk += (char)wholeFile[i];
466 bool useWeb = QString(Preference::Preferences().findGroup(
"SpiceQL")[
"UseSpiceQL"]).toUpper() ==
"TRUE";
467 auto [et, kernels] = SpiceQL::strSclkToEt(-94, currentSclk,
"mgs", useWeb);
470 if(et < p_etEnd && et > p_etStart) {
471 int linenum = middle;
476 while(et >= p_etStart) {
478 int lineStart = (linenum * 35);
479 int lineEnd = lineStart + 35;
481 string currentLine =
"";
482 for(
int i = lineStart; i < lineEnd; i++) {
483 currentLine += (char)wholeFile[i];
488 for(
int i = 8; i < 23; ++i) {
489 currentSclk += currentLine[i];
494 tie(et, kernels) = SpiceQL::strSclkToEt(-94, currentSclk,
"mgs", useWeb);
495 scs2e_c(-94, currentSclk.c_str(), &et);
500 while(et <= p_etEnd) {
502 int lineStart = (linenum * 35);
503 int lineEnd = lineStart + 35;
505 string currentLine =
"";
506 for(
int i = lineStart; i < lineEnd; i++) {
507 currentLine += (char)wholeFile[i];
512 for(
int i = 8; i < 23; ++i) {
513 currentSclk += currentLine[i];
517 tie(et, kernels) = SpiceQL::strSclkToEt(-94, currentSclk,
"mgs", useWeb);
522 for(
int i = bottom; i <= top; ++i) {
523 int lineStart = (i * 35);
524 int lineEnd = lineStart + 35;
525 string currentLine =
"";
526 for(
int j = lineStart; j < lineEnd; j++) {
527 currentLine += (char)wholeFile[j];
532 filter = line.Token(
",");
541 sclk = line.Token(
",");
545 tie(et, kernels) = SpiceQL::strSclkToEt(-94, currentSclk,
"mgs", useWeb);
548 gainId = line.Token(
",").ToQt().remove(
"\"").trimmed();
552 offsetId.Remove(
"\"");
553 offsetId.ConvertWhiteSpace();
557 map<QString, double>::iterator p;
558 p = p_gainMapWA.find(gainId);
559 if(p == p_gainMapWA.end()) {
562 QString msg =
"Invalid GainModeId [" + gainId +
"] in wago table";
563 throw IException(IException::Unknown, msg, _FILEINFO_);
565 double gain = p->second;
568 double offset = offsetId.ToDouble() * 5.0;
573 wago.offset = offset;
574 p_wagos.push_back(wago);
581 else if(et < p_etStart) {
591 sort(p_wagos.begin(), p_wagos.end());
592 boost::ignore_unused((unique(p_wagos.begin(), p_wagos.end())));