Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
ObservationNumber.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "ObservationNumber.h"
8#include "IException.h"
9#include "Pvl.h"
10#include "Cube.h"
11#include "Process.h"
12#include "PvlToPvlTranslationManager.h"
13#include "FileName.h"
14
15namespace Isis {
20
25
31 QString ObservationNumber::Compose(Pvl &label, bool def2filename) {
32 QString sn;
33 try {
34 PvlGroup snGroup = FindObservationTranslation(label);
35 sn = CreateSerialNumber(snGroup, (int)snGroup["ObservationKeys"]);
36 }
37 catch(IException &e) {
38 if(def2filename) {
39 // Try to return the filename if it exists in the label, otherwise use
40 // "Unknown" as a last resort.
41 QString snTemp = label.fileName();
42 if(!snTemp.isEmpty()) {
43 sn = FileName(snTemp).name();
44 }
45 else {
46 sn = "Unknown";
47 }
48 }
49 else {
50 sn = "Unknown";
51 }
52 }
53
54 return sn;
55 }
56
62 QString ObservationNumber::Compose(Cube &cube, bool def2filename) {
63 return Compose(*cube.label(), def2filename);
64 }
65
71 QString ObservationNumber::Compose(const QString &filename, bool def2filename) {
72 Pvl p(filename);
73 return Compose(p, def2filename);
74 }
75
82 Pvl outLabel;
83
84 // Get the mission name
85 static QString missionTransFile = "$ISISROOT/appdata/translations/MissionName2DataDir.trn";
86 static PvlToPvlTranslationManager missionXlater(missionTransFile);
87 missionXlater.SetLabel(label);
88 QString mission = missionXlater.Translate("MissionName");
89
90 // Get the instrument name
91 static QString instTransFile = "$ISISROOT/appdata/translations/Instruments.trn";
92 static PvlToPvlTranslationManager instrumentXlater(instTransFile);
93 instrumentXlater.SetLabel(label);
94 QString instrument = instrumentXlater.Translate("InstrumentName");
95
96 // We want to use this instrument's translation manager. It's much faster for
97 // ObservationNumberList if we keep the translation manager in memory, so re-reading
98 // from the disk is not necessary every time. To do this, we'll use a map to store
99 // the translation managers and observation number keys with a string identifier to find them.
100 // This identifier needs to have the mission name and the instrument name.
101 static std::map<QString, std::pair<PvlToPvlTranslationManager, PvlKeyword> > missionTranslators;
102 QString key = mission + "_" + instrument;
103 std::map<QString, std::pair<PvlToPvlTranslationManager, PvlKeyword> >::iterator
104 translationIterator = missionTranslators.find(key);
105
106 if(translationIterator == missionTranslators.end()) {
107 // Get the file
108 FileName snFile((QString) "$ISISROOT/appdata/translations/" + mission +
109 instrument + "SerialNumber.trn");
110
111 // Delets the extra
112 Pvl translation(snFile.expanded());
113 PvlKeyword observationKeys;
114 if(translation.hasKeyword("ObservationKeys")) {
115 observationKeys = translation["ObservationKeys"];
116 }
117
118 // use the translation file to generate keywords
119 missionTranslators.insert(
120 std::pair<QString, std::pair<PvlToPvlTranslationManager, PvlKeyword> >
121 (key, std::pair<PvlToPvlTranslationManager, PvlKeyword>(PvlToPvlTranslationManager(snFile.expanded()), observationKeys))
122 );
123
124 translationIterator = missionTranslators.find(key);
125 }
126
127 translationIterator->second.first.SetLabel(label);
128 translationIterator->second.first.Auto(outLabel);
129 PvlGroup snGroup = outLabel.findGroup("SerialNumberKeywords");
130
131 // Delets the extra
132 if(!translationIterator->second.second.name().isEmpty()) {
133 snGroup += translationIterator->second.second;
134 }
135 else {
136 snGroup += PvlKeyword("ObservationKeys", toString(snGroup.keywords()));
137 }
138
139 return snGroup;
140 }
141
150 std::vector<QString> ObservationNumber::PossibleSerial(const QString &on, SerialNumberList &list) {
151 std::vector<QString> sn;
152 for(int i = 0; i < list.size(); i++) {
153 if(list.serialNumber(i).startsWith(on)) {
154 sn.push_back(list.serialNumber(i));
155 }
156 }
157 return sn;
158 }
159
160
161
162}
IO Handler for Isis Cubes.
Definition Cube.h:168
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition Cube.cpp:1975
ObservationNumber()
Create an empty SerialNumber object.
virtual ~ObservationNumber()
Destroy a SerialNumber object.
std::vector< QString > PossibleSerial(const QString &on, SerialNumberList &list)
Creates a vector of plasible SerialNumbers from a string representing the ObservationNumber and a Ser...
static QString Compose(Pvl &label, bool def2filename=false)
Compose a ObservationNumber from a PVL.
static PvlGroup FindObservationTranslation(Pvl &label)
Get Groups by translating from correct Translation table.
Allows applications to translate simple text files.
virtual QString Translate(QString translationGroupName, int findex=0)
Returns a translated value.
static QString CreateSerialNumber(PvlGroup &snGroup, int key)
Create the SerialNumber string by concatenating the keywords in the label with '/' in between serialN...
Serial Number list generator.
QString serialNumber(const QString &filename)
Return a serial number given a filename.
int size() const
How many serial number / filename combos are in the list.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.