7#include "SerialNumberList.h"
11#include "IException.h"
14#include "ObservationNumber.h"
17#include "SerialNumber.h"
54 if (progress != NULL) {
55 progress->
SetText(
"Creating Isis serial numbers from list file.");
59 for (
int i = 0; i < flist.size(); i++) {
61 if (progress != NULL) {
66 catch (IException &e) {
67 QString msg =
"Can't open or invalid file list [" + listfile +
"].";
68 throw IException(e, IException::User, msg, _FILEINFO_);
122 Pvl p(Isis::FileName(filename).expanded());
123 PvlObject cubeObj = p.findObject(
"IsisCube");
130 PvlGroup targetGroup;
131 if (cubeObj.hasGroup(
"Instrument")) {
132 targetGroup = cubeObj.findGroup(
"Instrument");
134 else if (def2filename) {
136 if (cubeObj.hasGroup(
"Mapping")) {
137 targetGroup = cubeObj.findGroup(
"Mapping");
140 QString msg =
"Unable to find Instrument or Mapping group in "
141 + filename +
" for comparing target.";
142 throw IException(IException::User, msg, _FILEINFO_);
147 QString msg =
"Unable to find Instrument group in " + filename
148 +
" for comparing target.";
149 throw IException(IException::User, msg, _FILEINFO_);
152 target = targetGroup[
"TargetName"][0];
153 target = target.toUpper();
158 QString msg =
"Target name of [" + target +
"] from file ["
159 + filename +
"] does not match [" +
m_target +
"].";
160 throw IException(IException::User, msg, _FILEINFO_);
167 if (sn ==
"Unknown") {
168 QString msg =
"Invalid serial number [Unknown] from file ["
170 throw IException(IException::User, msg, _FILEINFO_);
174 QString msg =
"Duplicate serial number [" + sn +
"] from files ["
176 throw IException(IException::User, msg, _FILEINFO_);
180 nextpair.filename = Isis::FileName(filename).expanded();
181 nextpair.serialNumber = sn;
182 nextpair.observationNumber = on;
186 if (cubeObj.hasGroup(
"CsmInfo")) {
187 PvlGroup csmGroup = cubeObj.findGroup(
"CsmInfo");
188 if (csmGroup.hasKeyword(
"CSMPlatformID") && csmGroup.hasKeyword(
"CSMInstrumentId")) {
189 nextpair.spacecraftName = cubeObj.findGroup(
"CsmInfo")[
"CSMPlatformID"][0];
190 nextpair.instrumentId = cubeObj.findGroup(
"CsmInfo")[
"CSMInstrumentId"][0];
196 else if (cubeObj.hasGroup(
"Instrument")) {
197 PvlGroup instGroup = cubeObj.findGroup(
"Instrument");
198 if (instGroup.hasKeyword(
"SpacecraftName") && instGroup.hasKeyword(
"InstrumentId")) {
199 nextpair.spacecraftName = cubeObj.findGroup(
"Instrument")[
"SpacecraftName"][0];
200 nextpair.instrumentId = cubeObj.findGroup(
"Instrument")[
"InstrumentId"][0];
206 m_fileMap.insert(std::pair<QString, int>(nextpair.filename, (
int)(
m_pairs.size() - 1)));
208 catch (IException &e) {
209 QString msg =
"FileName [" + Isis::FileName(filename).expanded() +
210 "] can not be added to serial number list.";
211 throw IException(e, IException::User, msg, _FILEINFO_);
252 Pvl p(Isis::FileName(filename).expanded());
253 PvlObject cubeObj = p.findObject(
"IsisCube");
260 PvlGroup targetGroup;
261 if (cubeObj.hasGroup(
"Instrument")) {
262 targetGroup = cubeObj.findGroup(
"Instrument");
264 else if (cubeObj.hasGroup(
"Mapping")) {
266 targetGroup = cubeObj.findGroup(
"Mapping");
269 QString msg =
"Unable to find Instrument or Mapping group in "
270 + filename +
" for comparing target.";
271 throw IException(IException::User, msg, _FILEINFO_);
274 target = targetGroup[
"TargetName"][0];
275 target = target.toUpper();
280 QString msg =
"Target name of [" + target +
"] from file ["
281 + filename +
"] does not match [" +
m_target +
"].";
282 throw IException(IException::User, msg, _FILEINFO_);
288 QString msg =
"Invalid serial number [Unknown] from file ["
290 throw IException(IException::User, msg, _FILEINFO_);
294 QString msg =
"Duplicate, serial number [" +
serialNumber +
"] from files ["
296 +
"] and [" +
fileName(index) +
"].";
297 throw IException(IException::User, msg, _FILEINFO_);
301 if (!cubeObj.hasGroup(
"CsmInfo")) {
305 if (!cubeObj.hasGroup(
"Instrument")) {
306 QString msg =
"Unable to find Instrument group in " + filename
307 +
" needed for performing bundle adjustment.";
308 throw IException(IException::User, msg, _FILEINFO_);
310 PvlGroup instGroup = cubeObj.findGroup(
"Instrument");
311 if (!instGroup.hasKeyword(
"SpacecraftName") || !instGroup.hasKeyword(
"InstrumentId")) {
312 QString msg =
"Unable to find SpacecraftName or InstrumentId keywords in " + filename
313 +
" needed for performing bundle adjustment.";
314 throw IException(IException::User, msg, _FILEINFO_);
319 PvlGroup csmGroup = cubeObj.findGroup(
"CSMInfo");
320 if (!csmGroup.hasKeyword(
"CSMPlatformID") || !csmGroup.hasKeyword(
"CSMInstrumentId")) {
321 QString msg =
"Unable to find CSMPlatformID or CSMInstrumentId keywords in " + filename
322 +
" needed for performing bundle adjustment.";
323 throw IException(IException::User, msg, _FILEINFO_);
328 nextpair.filename = Isis::FileName(filename).expanded();
334 if (cubeObj.hasGroup(
"CsmInfo")) {
335 PvlGroup csmGroup = cubeObj.findGroup(
"CsmInfo");
336 if (csmGroup.hasKeyword(
"CSMPlatformID") && csmGroup.hasKeyword(
"CSMInstrumentId")) {
337 nextpair.spacecraftName = cubeObj.findGroup(
"CsmInfo")[
"CSMPlatformID"][0];
338 nextpair.instrumentId = cubeObj.findGroup(
"CsmInfo")[
"CSMInstrumentId"][0];
344 else if (cubeObj.hasGroup(
"Instrument")) {
345 PvlGroup instGroup = cubeObj.findGroup(
"Instrument");
346 if (instGroup.hasKeyword(
"SpacecraftName") && instGroup.hasKeyword(
"InstrumentId")) {
347 nextpair.spacecraftName = cubeObj.findGroup(
"Instrument")[
"SpacecraftName"][0];
348 nextpair.instrumentId = cubeObj.findGroup(
"Instrument")[
"InstrumentId"][0];
354 m_fileMap.insert(std::pair<QString, int>(nextpair.filename, (
int)(
m_pairs.size() - 1)));
356 catch (IException &e) {
357 QString msg =
"[SerialNumber, FileName] = [" +
serialNumber +
", "
358 + Isis::FileName(filename).expanded()
359 +
"] can not be added to serial number list.";
360 throw IException(e, IException::User, msg, _FILEINFO_);
402 return m_pairs[index].filename;
405 QString msg =
"Unable to get the FileName. The given serial number ["
406 + sn +
"] does not exist in the list.";
407 throw IException(IException::Programmer, msg, _FILEINFO_);
428 QString msg =
"Unable to get the SerialNumber. The given file name ["
429 + Isis::FileName(filename).expanded() +
"] does not exist in the list.";
430 throw IException(IException::Programmer, msg, _FILEINFO_);
433 return m_pairs[index].serialNumber;
447 if (index >= 0 && index < (
int)
m_pairs.size()) {
448 return m_pairs[index].serialNumber;
451 QString msg =
"Unable to get the SerialNumber. The given index ["
452 +
toString(index) +
"] is invalid.";
453 throw IException(IException::Programmer, msg, _FILEINFO_);
469 if (index >= 0 && index < (
int)
m_pairs.size()) {
470 return m_pairs[index].observationNumber;
473 QString msg =
"Unable to get the ObservationNumber. The given index ["
474 +
toString(index) +
"] is invalid.";
475 throw IException(IException::Programmer, msg, _FILEINFO_);
495 QString msg =
"Unable to get the SerialNumber index. The given serial number ["
496 + sn +
"] does not exist in the list.";
497 throw IException(IException::Programmer, msg, _FILEINFO_);
518 std::map<QString, int>::iterator pos;
520 QString msg =
"Unable to get the FileName index. The given file name ["
521 + Isis::FileName(filename).expanded() +
"] does not exist in the list.";
522 throw IException(IException::Programmer, msg, _FILEINFO_);
538 if (index >= 0 && index < (
int)
m_pairs.size()) {
539 return m_pairs[index].filename;
542 QString msg =
"Unable to get the FileName. The given index ["
543 +
toString(index) +
"] is invalid.";
544 throw IException(IException::Programmer, msg, _FILEINFO_);
560 if (index >= 0 && index < (
int)
m_pairs.size()) {
561 QString scid = (
m_pairs[index].spacecraftName +
"/" +
m_pairs[index].instrumentId).toUpper();
564 (void)scid.simplified();
565 return scid.replace(
" ",
"");
568 QString msg =
"Unable to get the Spacecraft InstrumentId. The given index ["
569 +
toString(index) +
"] is invalid.";
570 throw IException(IException::Programmer, msg, _FILEINFO_);
588 QString scid = (
m_pairs[index].spacecraftName +
"/" +
m_pairs[index].instrumentId).toUpper();
591 (void)scid.simplified();
592 return scid.replace(
" ",
"");
595 QString msg =
"Unable to get the Spacecraft InstrumentId. The given serial number ["
596 + sn +
"] does not exist in the list.";
597 throw IException(IException::Programmer, msg, _FILEINFO_);
614 std::vector<QString> numbers;
615 for (
unsigned index = 0; index <
m_pairs.size(); index++) {
620 if (numbers.size() > 0) {
624 QString msg =
"Unable to get the possible serial numbers. The given observation number ["
625 + on +
"] does not exist in the list.";
626 throw IException(IException::Programmer, msg, _FILEINFO_);
Internalizes a list of files.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a ObservationNumber from a PVL.
Program progress reporter.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
void CheckStatus()
Checks and updates the status.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
virtual ~SerialNumberList()
Destructor.
bool hasSerialNumber(QString sn)
Determines whether or not the requested serial number exists in the list.
QString observationNumber(int index)
Return a observation number given an index.
std::map< QString, int > m_serialMap
Maps serial numbers to their positions in the list.
std::map< QString, int > m_fileMap
Maps filenames to their positions in the list.
void remove(const QString &sn)
Remove the specified serial number from the list.
QString serialNumber(const QString &filename)
Return a serial number given a filename.
void add(const QString &filename, bool def2filename=false)
Adds a new filename / serial number pair to the SerialNumberList.
bool m_checkTarget
Specifies whether or not to check to make sure the target names match between files added to the seri...
SerialNumberList(bool checkTarget=true)
Creates an empty SerialNumberList.
QString spacecraftInstrumentId(int index)
Return the spacecraftname/instrumentid at the given index.
QString m_target
Target name that the files must have if m_checkTarget is true.
int size() const
How many serial number / filename combos are in the list.
int serialNumberIndex(const QString &sn)
Return a list index given a serial number.
int fileNameIndex(const QString &filename)
Return a list index given a filename.
std::vector< Pair > m_pairs
List of serial number Pair entities.
std::vector< QString > possibleSerialNumbers(const QString &on)
Return possible serial numbers given an observation number.
QString fileName(const QString &sn)
Return a filename given a serial number.
This is free and unencumbered software released into the public domain.
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.
A serial number list entity that contains the filename serial number pair.