Isis 3 Programmer Reference
ProcessImportPds.cpp
Go to the documentation of this file.
1 
22 #include "ProcessImportPds.h"
23 
24 #include <QString>
25 
26 #include <iostream>
27 #include <QString>
28 #include <sstream>
29 
30 #include "IException.h"
31 #include "ImportPdsTable.h"
32 #include "IString.h"
33 #include "LineManager.h"
34 #include "OriginalLabel.h"
35 #include "PixelType.h"
36 #include "Preference.h"
37 #include "Projection.h"
38 #include "TProjection.h"
39 #include "Pvl.h"
40 #include "PvlKeyword.h"
41 #include "PvlGroup.h"
42 #include "PvlObject.h"
43 #include "PvlTokenizer.h"
45 #include "SpecialPixel.h"
46 #include "Table.h"
47 #include "UserInterface.h"
48 
49 using namespace std;
50 namespace Isis {
51 
55  ProcessImportPds::ProcessImportPds() {
56  p_keepOriginalLabel = true;
57  p_encodingType = NONE;
58  p_jp2File.clear();
59  p_projectionOffsetChange = false;
60  p_projectionOffsetGroup.setName("ProjectionOffsets");
61 
62  // Set up a translater for PDS file of type IMAGE
63  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
64  p_transDir = (QString) dataDir["Base"];
65  }
66 
67 
68  ProcessImportPds::~ProcessImportPds() {
69  }
70 
71 
75  void ProcessImportPds::EndProcess() {
76  ProcessImportPds::Finalize();
77  }
78 
79 
104  void ProcessImportPds::ExtractPdsProjection(Isis::PvlToPvlTranslationManager &pdsXlater) {
105 
106  QString str;
107 
108  if (pdsXlater.InputHasKeyword("ProjectionName")) {
109  p_projection = pdsXlater.Translate("ProjectionName");
110  }
111  else {
112  QString message = "No projection name in labels";
113  throw IException(IException::Unknown, message, _FILEINFO_);
114  }
115 
116  if (pdsXlater.InputHasKeyword("TargetName")) {
117  p_targetName = pdsXlater.Translate("TargetName");
118  }
119  else {
120  QString message = "No target name in labels";
121  throw IException(IException::Unknown, message, _FILEINFO_);
122  }
123 
124  if (pdsXlater.InputHasKeyword("EquatorialRadius")) {
125  str = pdsXlater.Translate("EquatorialRadius");
126  p_equatorialRadius = toDouble(str) * 1000.0;
127  }
128  else {
129  QString message = "No equatorial radius name in labels";
130  throw IException(IException::User, message, _FILEINFO_);
131  }
132 
133  if (pdsXlater.InputHasKeyword("PolarRadius")) {
134  str = pdsXlater.Translate("PolarRadius");
135  p_polarRadius = toDouble(str) * 1000.0;
136  }
137  else {
138  QString message = "No polar radius in labels";
139  throw IException(IException::User, message, _FILEINFO_);
140  }
141 
142  if (pdsXlater.InputHasKeyword("LongitudeDirection")) {
143  p_longitudeDirection = pdsXlater.Translate("LongitudeDirection");
144  }
145  else {
146  p_longitudeDirection = pdsXlater.Translate("LongitudeDirection2");
147  }
148 
149  if (p_polarRadius == p_equatorialRadius) {
150  p_latitudeType = "Planetocentric";
151  }
152  else if (pdsXlater.InputHasKeyword("LatitudeType2")) {
153  p_latitudeType = pdsXlater.Translate("LatitudeType2");
154  }
155  else {
156  p_latitudeType = pdsXlater.Translate("LatitudeType");
157  }
158 
159  if (pdsXlater.InputHasKeyword("MinimumLatitude")) {
160  str = pdsXlater.Translate("MinimumLatitude");
161  try {
162  p_minimumLatitude = toDouble(str);
163  }
164  catch(IException &e) {
165  p_minimumLatitude = Isis::NULL8;
166  }
167  }
168  else {
169  p_minimumLatitude = Isis::NULL8;
170  }
171 
172  if (pdsXlater.InputHasKeyword("MaximumLatitude")) {
173  str = pdsXlater.Translate("MaximumLatitude");
174  try {
175  p_maximumLatitude = toDouble(str);
176  }
177  catch(IException &e) {
178  p_maximumLatitude = Isis::NULL8;
179  }
180  }
181  else {
182  p_maximumLatitude = Isis::NULL8;
183  }
184 
185  // This variable represents if the longitudes were read in as
186  // positive west
187  bool positiveWest = false;
188  if (pdsXlater.InputHasKeyword("MinimumLongitude")) {
189  str = pdsXlater.Translate("MinimumLongitude");
190  try {
191  positiveWest = true;
192  p_minimumLongitude = toDouble(str);
193  }
194  catch(IException &e) {
195  p_minimumLongitude = Isis::NULL8;
196  }
197  }
198  else if (pdsXlater.InputHasKeyword("MinimumLongitude2")) {
199  str = pdsXlater.Translate("MinimumLongitude2");
200  try {
201  p_minimumLongitude = toDouble(str);
202  }
203  catch(IException &e) {
204  p_minimumLongitude = Isis::NULL8;
205  }
206  }
207  else {
208  p_minimumLongitude = Isis::NULL8;
209  }
210 
211  if (pdsXlater.InputHasKeyword("MaximumLongitude")) {
212  str = pdsXlater.Translate("MaximumLongitude");
213  try {
214  positiveWest = true;
215  p_maximumLongitude = toDouble(str);
216  }
217  catch(IException &e) {
218  p_maximumLongitude = Isis::NULL8;
219  }
220  }
221  else if (pdsXlater.InputHasKeyword("MaximumLongitude2")) {
222  str = pdsXlater.Translate("MaximumLongitude2");
223  try {
224  p_maximumLongitude = toDouble(str);
225  }
226  catch(IException &e) {
227  p_maximumLongitude = Isis::NULL8;
228  }
229  }
230  else {
231  p_maximumLongitude = Isis::NULL8;
232  }
233 
234  str = pdsXlater.Translate("LongitudeDomain");
235  p_longitudeDomain = toInt(str);
236 
255  if (positiveWest && (p_longitudeDirection.compare("PositiveEast") == 0)) {
256  double tmp = p_minimumLongitude;
257  p_minimumLongitude = p_maximumLongitude;
258  p_maximumLongitude = tmp;
259  }
260 
261  if (p_minimumLongitude > p_maximumLongitude) {
262  // Force the change to 180
263  p_longitudeDomain = 180;
264  p_minimumLongitude = Isis::TProjection::To180Domain(p_minimumLongitude);
265  }
266 
267  // If either the minimumLongitude or maximumLongitude are < 0, change
268  // longitude Domain to 180.
269  if (p_minimumLongitude < 0 || p_maximumLongitude < 0) {
270  p_longitudeDomain = 180;
271  }
272 
273  str = pdsXlater.Translate("PixelResolution");
274  p_pixelResolution = toDouble(str);
275  str = pdsXlater.InputKeyword("PixelResolution").unit().toUpper();
276  // Assume KM/PIXEL if the unit doesn't exist or is not METERS/PIXEL
277  if ((str != "METERS/PIXEL") && (str != "M/PIXEL") && (str != "M/PIX")) {
278  p_pixelResolution *= 1000.0;
279  }
280 
281  str = pdsXlater.Translate("Scale");
282  p_scaleFactor = toDouble(str);
283 
284  try {
285  str = pdsXlater.Translate("Rotation");
286  p_rotation = toDouble(str);
287  }
288  catch(IException &) {
289  // assume no rotation if the value isn't a number
290  p_rotation = 0.0;
291  }
292 
293  // Look for projection offsets/mults to convert between line/samp and x/y
294  double xoff, yoff, xmult, ymult;
295  GetProjectionOffsetMults(xoff, yoff, xmult, ymult);
296 
297  if (pdsXlater.InputHasKeyword("LineProjectionOffset")) {
298  str = pdsXlater.Translate("LineProjectionOffset");
299  }
300  else {
301  str = pdsXlater.Translate("LineProjectionOffset2");
302  }
303  p_lineProjectionOffset = toDouble(str);
304  p_upperLeftY = ymult * (p_lineProjectionOffset + yoff) * p_pixelResolution;
305 
306  if (pdsXlater.InputHasKeyword("SampleProjectionOffset")) {
307  str = pdsXlater.Translate("SampleProjectionOffset");
308  }
309  else {
310  str = pdsXlater.Translate("SampleProjectionOffset2");
311  }
312  p_sampleProjectionOffset = toDouble(str);
313  p_upperLeftX = xmult * (p_sampleProjectionOffset + xoff) * p_pixelResolution;
314 
315  p_projectionOffsetGroup.addKeyword(PvlKeyword("xOffset", QString::number(xoff)));
316  p_projectionOffsetGroup.addKeyword(PvlKeyword("yOffset", QString::number(yoff)));
317  p_projectionOffsetGroup.addKeyword(PvlKeyword("xMultiplier", QString::number(xmult)));
318  p_projectionOffsetGroup.addKeyword(PvlKeyword("yMultiplier", QString::number(ymult)));
319 
320  }
321 
322 
328  void ProcessImportPds::Finalize() {
329  if (p_keepOriginalLabel) {
330  OriginalLabel ol(p_pdsLabel);
331  for (unsigned int i = 0; i < OutputCubes.size(); i++) {
332  OutputCubes[i]->write(ol);
333  }
334  }
335  Process::Finalize();
336  }
337 
338 
342  bool ProcessImportPds::GetProjectionOffsetChange() {
343  return p_projectionOffsetChange;
344  }
345 
346 
350  PvlGroup ProcessImportPds::GetProjectionOffsetGroup() {
351  return p_projectionOffsetGroup;
352  }
353 
354 
367  void ProcessImportPds::GetProjectionOffsetMults(double &xoff, double &yoff,
368  double &xmult, double &ymult) {
369 
370  xmult = -1.0;
371  ymult = 1.0;
372  xoff = 0.5;
373  yoff = 0.5;
374 
375  // Open projectionOffsetMults file
376  Isis::Pvl p(p_transDir + "/" + "translations/pdsProjectionLineSampToXY_V2.def");
377 
378  Isis::PvlObject &projDef = p.findObject("ProjectionOffsetMults",
379  Pvl::Traverse);
380 
381  for(int g = 0; g < projDef.groups(); g++) {
382  QString key = projDef.group(g)["Keyword"];
383  if (p_pdsLabel.hasKeyword(key)) {
384  QString value = p_pdsLabel[key];
385  QString pattern = projDef.group(g)["Pattern"];
386  // If value contains pattern, then set the mults to what is in translation file and
387  // update p_pdfChange
388  if (value.contains(pattern)) {
389  xmult = projDef.group(g)["xMult"];
390  ymult = projDef.group(g)["yMult"];
391  xoff = projDef.group(g)["xOff"];
392  yoff = projDef.group(g)["yOff"];
393  p_projectionOffsetChange = true;
394  return;
395  }
396  }
397  }
398  }
399 
400 
407  void ProcessImportPds::IdentifySource(Isis::Pvl &inputLabel) {
408 
409  // Create a temporary Isis::PvlToPvlTranslationManager so we can find out what
410  // type of input file we have
411  stringstream trnsStrm;
412  trnsStrm << "Group = PdsFile" << endl;
413  trnsStrm << " InputPosition = ROOT" << endl;
414  trnsStrm << " InputKey = PDS_VERSION_ID" << endl;
415  trnsStrm << "EndGroup" << endl;
416  trnsStrm << "Group = Isis2File" << endl;
417  trnsStrm << " InputPosition = ROOT" << endl;
418  trnsStrm << " InputKey = CCSD3ZF0000100000001NJPL3IF0PDS200000001" << endl;
419  trnsStrm << "EndGroup" << endl;
420  trnsStrm << "END";
421 
422  Isis::PvlToPvlTranslationManager sourceXlater(inputLabel, trnsStrm);
423 
424  if (sourceXlater.InputHasKeyword("PdsFile")) {
425  p_source = PDS;
426  }
427  else if (sourceXlater.InputHasKeyword("Isis2File")) {
428  p_source = ISIS2;
429  }
430  else {
431  p_source = NOSOURCE;
432  }
433 
434  }
435 
436 
444  Table &ProcessImportPds::ImportTable(QString pdsTableName) {
445  // No table file given, let ImportPdsTable find it.
446  ImportPdsTable pdsTable(p_labelFile, "", pdsTableName);
447  // reformat the table name. If the name ends with the word "Table", remove
448  // it. (So, for example, INSTRUMENT_POINTING_TABLE gets formatted to
449  // InstrumentPointingTable and then to InstrumentPointing)
450  QString isisTableName = pdsTable.getFormattedName(pdsTableName);
451  int found = isisTableName.lastIndexOf("Table");
452  if (found == isisTableName.length() - 5) {
453  isisTableName.remove(found, 5);
454  }
455 
456  Table isisTable = pdsTable.importTable(isisTableName);
457  p_tables.push_back(isisTable);
458 
459  return p_tables.at(p_tables.size() - 1);
460  }
461 
462 
471  bool ProcessImportPds::IsIsis2() {
472 
473  if (p_source == ISIS2) {
474 
475  return true;
476  }
477  else {
478  return false;
479  }
480 
481  }
482 
483 
488  void ProcessImportPds::OmitOriginalLabel() {
489  p_keepOriginalLabel = false;
490  }
491 
492 
499  void ProcessImportPds::ProcessDataFilePointer(Isis::PvlToPvlTranslationManager & pdsXlater,
500  const bool & calcOffsetOnly) {
501 
502  const PvlKeyword & dataFilePointer = pdsXlater.InputKeyword("DataFilePointer");
503 
504  QString dataFileName;
505  QString units;
506  QString str;
507  int offset = -1;
508 
509  // If only size 1, we either have a file name or an offset
510  // Either way, when we're done with these two ifs, variables offset and
511  // dataFileName will be set.
512  if (dataFilePointer.size() == 1) {
513  try {
514  str = pdsXlater.Translate("DataFilePointer");
515  offset = toInt(str);
516  units = dataFilePointer.unit();
517  // Successful? we have an offset, means current, p_labelFile
518  // is the location of the data as well
519  dataFileName = FileName(p_labelFile).name();
520  }
521  catch(IException &e) {
522  // Failed to parse to an int, means we have a file name
523  // No offset given, so we use 1, offsets are 1 based
524  offset = 1;
525  units = "BYTES";
526  dataFileName = str;
527  }
528  }
529  // We must have a filename and an offset, in that order
530  // Expection ("filname", <offset>)
531  else if (dataFilePointer.size() == 2) {
532  dataFileName = pdsXlater.Translate("DataFilePointer", 0);
533  offset = IString(pdsXlater.Translate("DataFilePointer", 1)).ToInteger();
534  units = dataFilePointer.unit(1);
535  }
536  // Error, no value
537  else if (dataFilePointer.size() == 0) {
538  QString msg = "Data file pointer ^IMAGE or ^QUBE has no value, must"
539  "have either file name or offset or both, in [" +
540  p_labelFile + "]";
541  throw IException(IException::Unknown, msg, _FILEINFO_);
542  }
543  // Error, more than two values
544  else {
545  QString msg = "Improperly formatted data file pointer keyword ^IMAGE or "
546  "^QUBE, in [" + p_labelFile + "], must contain filename "
547  " or offset or both";
548  throw IException(IException::Unknown, msg, _FILEINFO_);
549  }
550 
551  // Now, to handle the values we found
552  // the filename first, only do so if calcOffsetOnly is false
553  if (!calcOffsetOnly) {
554  Isis::FileName labelFile(p_labelFile);
555 
556  // If dataFileName isn't empty, and does start at the root, use it
557  Isis::FileName dataFile;
558  if (dataFileName.size() != 0 && dataFileName.at(0) == '/')
559  dataFile = FileName(dataFileName);
560  // Otherwise, use the path to it and its name
561  else
562  dataFile = FileName(labelFile.path() + "/" + dataFileName);
563 
564  // If it exists, use it
565  if (dataFile.fileExists()) {
566  SetInputFile(dataFile.expanded());
567  }
568  // Retry with downcased name, if still no luck, fail
569  else {
570  QString tmp = dataFile.expanded();
571  dataFileName = dataFileName.toLower();
572  dataFile = FileName(labelFile.path() + "/" + dataFileName);
573  if (dataFile.fileExists()) {
574  SetInputFile(dataFile.expanded());
575  }
576  else {
577  QString msg = "Unable to find input file [" + tmp + "] or [" +
578  dataFile.expanded() + "]";
579  throw IException(IException::Io, msg, _FILEINFO_);
580  }
581  }
582  }
583 
584  // Now, to handle the offset
585  units = units.trimmed();
586  if (units == "BYTES" || units == "B") {
587  SetFileHeaderBytes(offset - 1);
588  }
589  else {
590  QString recSize = pdsXlater.Translate("DataFileRecordBytes");
591  SetFileHeaderBytes((offset - 1) * toInt(recSize));
592  }
593  }
594 
595 
611  void ProcessImportPds::ProcessLabel(const QString &pdsDataFile, PdsFileType allowedTypes) {
612  // Create a temporary Isis::PvlToPvlTranslationManager so we can find out what
613  // type of PDS file this is (i.e., Qube or Image or SpectralQube)
614  stringstream trnsStrm;
615  trnsStrm << "Group = PdsTypeImage" << endl;
616  trnsStrm << " InputPosition = ROOT" << endl;
617  trnsStrm << " InputPosition = FILE" << endl;
618  trnsStrm << " InputPosition = UNCOMPRESSED_FILE" << endl;
619  trnsStrm << " InputKey = ^IMAGE" << endl;
620  trnsStrm << "EndGroup" << endl;
621  trnsStrm << "Group = PdsCombinedSpectrum" << endl;
622  trnsStrm << " InputPosition = ROOT" << endl;
623  trnsStrm << " InputPosition = FILE" << endl;
624  trnsStrm << " InputPosition = UNCOMPRESSED_FILE" << endl;
625  trnsStrm << " InputKey = ^COMBINED_SPECTRUM" << endl;
626  trnsStrm << "EndGroup" << endl;
627  trnsStrm << "Group = PdsTypeL0" << endl;
628  trnsStrm << " InputPosition = L0_FILE" << endl;
629  trnsStrm << " InputKey = ^L0_IMAGE" << endl;
630  trnsStrm << "EndGroup" << endl;
631  trnsStrm << "Group = PdsTypeRdn" << endl;
632  trnsStrm << " InputPosition = RDN_FILE" << endl;
633  trnsStrm << " InputKey = ^RDN_IMAGE" << endl;
634  trnsStrm << "EndGroup" << endl;
635  trnsStrm << "Group = PdsTypeLoc" << endl;
636  trnsStrm << " InputPosition = LOC_FILE" << endl;
637  trnsStrm << " InputKey = ^LOC_IMAGE" << endl;
638  trnsStrm << "EndGroup" << endl;
639  trnsStrm << "Group = PdsTypeObs" << endl;
640  trnsStrm << " InputPosition = OBS_FILE" << endl;
641  trnsStrm << " InputKey = ^OBS_IMAGE" << endl;
642  trnsStrm << "EndGroup" << endl;
643  trnsStrm << "Group = PdsTypeQube" << endl;
644  trnsStrm << " InputKey = ^QUBE" << endl;
645  trnsStrm << "EndGroup" << endl;
646  trnsStrm << "Group = PdsTypeSpectralQube" << endl;
647  trnsStrm << " InputKey = ^SPECTRAL_QUBE" << endl;
648  trnsStrm << "EndGroup" << endl;
649  trnsStrm << "Group = PdsEncodingType" << endl;
650  trnsStrm << " InputPosition = COMPRESSED_FILE" << endl;
651  trnsStrm << " InputKey = ENCODING_TYPE" << endl;
652  trnsStrm << " Translation = (*,*)" << endl;
653  trnsStrm << "EndGroup" << endl;
654  trnsStrm << "Group = PdsCompressedFile" << endl;
655  trnsStrm << " InputPosition = COMPRESSED_FILE" << endl;
656  trnsStrm << " InputKey = FILE_NAME" << endl;
657  trnsStrm << " Translation = (*,*)" << endl;
658  trnsStrm << "EndGroup" << endl;
659  trnsStrm << "END";
660 
661 
662  //tjw
663  //Determine if we are processing a QUBE whose
664  //core data type is VAX_REAL
665 
666  try {
667  PvlObject obj = p_pdsLabel.findObject("QUBE");
668  PvlKeyword coreKey = obj.findKeyword("CORE_ITEM_TYPE");
669  PvlKeyword suffixKey = obj.findKeyword("BAND_SUFFIX_ITEM_TYPE");
670  //if ( (coreKey[0] == "VAX_REAL") && (suffixKey[0] =="VAX_REAL") )
671 
672  if (coreKey[0] == "VAX_REAL") {
673  ProcessImport::SetVAXConvert(true);
674  }
675  }
676  catch (IException &e) {
677  }
678 
679  Isis::PvlToPvlTranslationManager pdsXlater(p_pdsLabel, trnsStrm);
680 
681  // Check to see if we are dealing with a JPEG2000 file
682  QString str;
683  if (pdsXlater.InputHasKeyword("PdsEncodingType")) {
684  str = pdsXlater.Translate("PdsEncodingType");
685  if (str == "JP2") {
686  p_encodingType = JP2;
687  str = pdsXlater.Translate("PdsCompressedFile");
688  if (pdsDataFile.isEmpty()) {
689  Isis::FileName lfile(p_labelFile);
690  Isis::FileName ifile(lfile.path() + "/" + str);
691  if (ifile.fileExists()) {
692  p_jp2File = ifile.expanded();
693  }
694  else {
695  QString tmp = ifile.expanded();
696  str = str.toLower();
697  ifile = lfile.path() + "/" + str;
698  if (ifile.fileExists()) {
699  p_jp2File = ifile.expanded();
700  }
701  else {
702  QString msg = "Unable to find input file [" + tmp + "] or [" +
703  ifile.expanded() + "]";
704  throw IException(IException::Io, msg, _FILEINFO_);
705  }
706  }
707  }
708  }
709  else {
710  QString msg = "Unsupported encoding type in [" + p_labelFile + "]";
711  throw IException(IException::Io, msg, _FILEINFO_);
712  }
713  }
714 
715 
716  // Call the correct label processing
717  if ((allowedTypes & Image) == Image && pdsXlater.InputHasKeyword("PdsTypeImage")) {
718 
719  ProcessPdsImageLabel(pdsDataFile);
720  }
721  else if ((allowedTypes & Qube) == Qube && pdsXlater.InputHasKeyword("PdsTypeQube")) {
722 
723  ProcessPdsQubeLabel(pdsDataFile, "pdsQube.trn");
724  }
725  else if ((allowedTypes & SpectralQube) == SpectralQube &&
726  pdsXlater.InputHasKeyword("PdsTypeSpectralQube")) {
727 
728  ProcessPdsQubeLabel(pdsDataFile, "pdsSpectralQube.trn");
729  }
730  else if ((allowedTypes & L0) == L0 && pdsXlater.InputHasKeyword("PdsTypeL0")) {
731 
732  ProcessPdsM3Label(pdsDataFile, L0);
733  }
734  else if ((allowedTypes & Rdn) == Rdn && pdsXlater.InputHasKeyword("PdsTypeRdn")) {
735 
736  ProcessPdsM3Label(pdsDataFile, Rdn);
737  }
738  else if ((allowedTypes & Loc) == Loc && pdsXlater.InputHasKeyword("PdsTypeLoc")) {
739 
740  ProcessPdsM3Label(pdsDataFile, Loc);
741  }
742  else if ((allowedTypes & Obs) == Obs && pdsXlater.InputHasKeyword("PdsTypeObs")) {
743 
744  ProcessPdsM3Label(pdsDataFile, Obs);
745  }
746  else if ((allowedTypes & CombinedSpectrum) == CombinedSpectrum &&
747  pdsXlater.InputHasKeyword("PdsCombinedSpectrum")) {
748 
749  ProcessPdsCombinedSpectrumLabel(pdsDataFile);
750  }
751  else {
752  QString msg = "Unknown label type in [" + p_labelFile + "]. It is possible the label file "
753 + "does not describe an image product (IMAGE, CUBE, or SPECTRALCUBE).";
754  throw IException(IException::Io, msg, _FILEINFO_);
755  }
756 
757 
758  // Find out if this is a PDS file or an ISIS2 file
759  IdentifySource(p_pdsLabel);
760 
761 
762  return;
763  }
764 
765 
777  void ProcessImportPds::ProcessPdsCombinedSpectrumLabel(const QString &pdsDataFile) {
778  Isis::FileName transFile(p_transDir + "/translations/pdsCombinedSpectrum.trn");
779  Isis::PvlToPvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
780 
781  QString str;
782 
783  str = pdsXlater.Translate("CoreLinePrefixBytes");
784  SetDataPrefixBytes(toInt(str));
785 
786  str = pdsXlater.Translate("CoreLineSuffixBytes");
787  SetDataSuffixBytes(toInt(str));
788 
789  ProcessPixelBitandType(pdsXlater);
790 
791  str = pdsXlater.Translate("CoreByteOrder");
792  SetByteOrder(Isis::ByteOrderEnumeration(str));
793 
794  str = pdsXlater.Translate("CoreSamples");
795  int ns = toInt(str);
796  str = pdsXlater.Translate("CoreLines");
797  int nl = toInt(str);
798  str = pdsXlater.Translate("CoreBands");
799  int nb = toInt(str);
800 
801  SetDimensions(ns, nl, nb);
802 
803  //-----------------------------------------------------------------
804  // Find the data filename it may be the same as the label file
805  // OR the label file may contain a pointer to the data
806  //-----------------------------------------------------------------
807 
808  // Use the name supplied by the application if it is there
809  if (pdsDataFile.length() > 0) {
810  ProcessDataFilePointer(pdsXlater, false);
811  }
812  // If the data is in JPEG 2000 format, then use the name of the file
813  // from the label
814  else if (p_jp2File.length() > 0) {
815  SetInputFile(p_jp2File);
816  ProcessDataFilePointer(pdsXlater, true);
817  }
818  // Use the "^IMAGE or ^QUBE" label to get the filename for the image data
819  // Get the path portion from user entered label file spec
820  else {
821  // Handle filename and offset
822  ProcessDataFilePointer(pdsXlater, false);
823  }
824 
825  //------------------------------------------------------------
826  // Find the image data base and multiplier
827  //------------------------------------------------------------
828  str = pdsXlater.Translate("CoreBase");
829  SetBase(toDouble(str));
830  str = pdsXlater.Translate("CoreMultiplier");
831  SetMultiplier(toDouble(str));
832 
833  // Find the organization of the image data
834  str = pdsXlater.Translate("CoreOrganization");
835 
836  if (p_encodingType == JP2) {
837  SetOrganization(ProcessImport::JP2);
838  }
839  else if (str == "BSQ") {
840  SetOrganization(ProcessImport::BSQ);
841  }
842  else if (str == "BIP") {
843  SetOrganization(ProcessImport::BIP);
844  }
845  else if (str == "BIL") {
846  SetOrganization(ProcessImport::BIL);
847  }
848  else {
849  QString msg = "Unsupported axis order [" + str + "]";
850  throw IException(IException::Programmer, msg, _FILEINFO_);
851  }
852  }
853 
854 
871  void ProcessImportPds::ProcessPdsQubeLabel(const QString &pdsDataFile,
872  const QString &transFile) {
873 
874 
875  Isis::FileName tFile(p_transDir + "/translations/" + transFile);
876 
877  Isis::PvlToPvlTranslationManager pdsXlater(p_pdsLabel, tFile.expanded());
878 
879  QString str;
880 
881 
882  // Find the organization of the image data
883  // Save off which axis the samples, lines and bands are on
884  int linePos = 0;
885  int samplePos = 0;
886  int bandPos = 0;
887  int val = pdsXlater.InputKeyword("CoreOrganization").size();
888  QString tmp = "";
889  for(int i = 0; i < val; i++) {
890  str = pdsXlater.Translate("CoreOrganization", i);
891  tmp += str;
892  if (str == "SAMPLE") {
893  samplePos = i;
894  }
895  else if (str == "LINE") {
896  linePos = i;
897  }
898  else if (str == "BAND") {
899  bandPos = i;
900  }
901  else {
902  QString message = "Unknown file axis name [" + str + "]";
903  throw IException(IException::User, message, _FILEINFO_);
904  }
905  }
906 
907  if (p_encodingType == JP2) {
908  SetOrganization(ProcessImport::JP2);
909  }
910  else if (tmp == "SAMPLELINEBAND") {
911  SetOrganization(ProcessImport::BSQ);
912  }
913  else if (tmp == "BANDSAMPLELINE") {
914  SetOrganization(ProcessImport::BIP);
915  }
916  else if (tmp == "SAMPLEBANDLINE") {
917  SetOrganization(ProcessImport::BIL);
918  }
919  else {
920  PvlKeyword pdsCoreOrg = p_pdsLabel.findKeyword(pdsXlater.
921  InputKeywordName("CoreOrganization"), Pvl::Traverse);
922 
923  stringstream pdsCoreOrgStream;
924  pdsCoreOrgStream << pdsCoreOrg;
925 
926  QString msg = "Unsupported axis order [" + QString(pdsCoreOrgStream.str().c_str()) + "]";
927  throw IException(IException::Programmer, msg, _FILEINFO_);
928  }
929 
930 
931  // Set the number of byte preceding the second dimension (left side plane)
932  // There are no capabilities in a PDS QUBE for this
933  SetDataPrefixBytes(0);
934 
935  // Set the number of bytes following the second dimension (right side plane)
936  str = pdsXlater.Translate("SuffixItemSize");
937  int suffix = toInt(str);
938  str = pdsXlater.Translate("AxisSuffixCount", 0);
939  suffix *= toInt(str);
940  SetDataSuffixBytes(suffix);
941 
942  str = pdsXlater.Translate("SuffixItemSize");
943 
944  // Only set DataTrailerBytes if we haven't already set it elsewhere. (It's inialized to 0.)
945  if (DataTrailerBytes() == 0) {
946  int trailer = toInt(str);
947  str = pdsXlater.Translate("AxisSuffixCount", 1);
948  trailer *= toInt(str);
949  str = pdsXlater.Translate("CoreSamples", samplePos);
950  trailer *= toInt(str);
951  trailer += suffix;
952  SetDataTrailerBytes(trailer);
953  }
954 
955  // Save the Data Trailer if it exists
956  if (DataTrailerBytes() != 0) {
957  SaveDataTrailer();
958  }
959 
960  ProcessPixelBitandType(pdsXlater);
961 
962  // Set the byte order
963 
964  //tjw:
965  str = pdsXlater.Translate("CoreByteOrder");
966 
967  SetByteOrder(Isis::ByteOrderEnumeration(str));
968 
969  //if(str == "LSB" || str == "MSB")
970  // SetByteOrder(Isis::ByteOrderEnumeration(str));
971  //else {
972  // QString msg = "Unrecognized byte order ["+str+"]";
973  // throw IException(IException::Programmer,msg,_FILEINFO_);
974  //}
975 
976 
977 
978  // Set the number of samples, lines and bands
979  str = pdsXlater.Translate("CoreSamples", samplePos);
980  int ns = toInt(str);
981  str = pdsXlater.Translate("CoreLines", linePos);
982  int nl = toInt(str);
983  str = pdsXlater.Translate("CoreBands", bandPos);
984  int nb = toInt(str);
985  SetDimensions(ns, nl, nb);
986 
987 
988  // Set any special pixels values, qube, so use true
989  ProcessSpecialPixels(pdsXlater, true);
990 
991  //---------------------------------------------------------------
992  // Find the data filename, it may be the same as the label file
993  // Or the label file may contain a pointer to the data
994  //---------------------------------------------------------------
995 
996  // Use the name supplied by the application if it is there
997  if (pdsDataFile.length() > 0) {
998  SetInputFile(pdsDataFile);
999  ProcessDataFilePointer(pdsXlater, true);
1000  }
1001  // If the data is in JPEG 2000 format, then use the name of the file
1002  // from the label
1003  else if (p_jp2File.length() > 0) {
1004  SetInputFile(p_jp2File);
1005  ProcessDataFilePointer(pdsXlater, true);
1006  }
1007  else {
1008  // Handle filename and offset
1009  ProcessDataFilePointer(pdsXlater, false);
1010  }
1011 
1012 
1013  //------------------------------------------------------------
1014  // Find the image data base and multiplier
1015  //------------------------------------------------------------
1016  // First see if there are base and multiplier in the band bin group
1017  if ((pdsXlater.InputHasKeyword("BandBase")) &&
1018  (pdsXlater.InputHasKeyword("BandMultiplier"))) {
1019  vector<double> bases;
1020  vector<double> mults;
1021  for(int i = 0; i < pdsXlater.InputKeyword("BandBase").size(); i++) {
1022  str = pdsXlater.Translate("BandBase", i);
1023  bases.push_back(toDouble(str));
1024  str = pdsXlater.Translate("BandMultiplier", i);
1025  mults.push_back(toDouble(str));
1026  }
1027  SetBase(bases);
1028  SetMultiplier(mults);
1029  }
1030  else {
1031  str = pdsXlater.Translate("CoreBase");
1032  SetBase(toDouble(str));
1033  str = pdsXlater.Translate("CoreMultiplier");
1034  SetMultiplier(toDouble(str));
1035  }
1036  }
1037 
1038 
1050  void ProcessImportPds::ProcessPdsImageLabel(const QString &pdsDataFile) {
1051  Isis::FileName transFile(p_transDir + "/translations/pdsImage.trn");
1052  Isis::PvlToPvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
1053 
1054  QString str;
1055 
1056  str = pdsXlater.Translate("CoreLinePrefixBytes");
1057  SetDataPrefixBytes(toInt(str));
1058 
1059  str = pdsXlater.Translate("CoreLineSuffixBytes");
1060  SetDataSuffixBytes(toInt(str));
1061 
1062  ProcessPixelBitandType(pdsXlater);
1063 
1064  str = pdsXlater.Translate("CoreByteOrder");
1065  SetByteOrder(Isis::ByteOrderEnumeration(str));
1066 
1067  str = pdsXlater.Translate("CoreSamples");
1068  int ns = toInt(str);
1069  str = pdsXlater.Translate("CoreLines");
1070  int nl = toInt(str);
1071  str = pdsXlater.Translate("CoreBands");
1072  int nb = toInt(str);
1073 
1074  SetDimensions(ns, nl, nb);
1075 
1076  // Set any special pixel values, not qube, so use false
1077  ProcessSpecialPixels(pdsXlater, false);
1078 
1079  //-----------------------------------------------------------------
1080  // Find the data filename it may be the same as the label file
1081  // OR the label file may contain a pointer to the data
1082  //-----------------------------------------------------------------
1083 
1084  // Use the name supplied by the application if it is there
1085  if (pdsDataFile.length() > 0) {
1086  SetInputFile(pdsDataFile);
1087  ProcessDataFilePointer(pdsXlater, true);
1088  }
1089  // If the data is in JPEG 2000 format, then use the name of the file
1090  // from the label
1091  else if (p_jp2File.length() > 0) {
1092  SetInputFile(p_jp2File);
1093  ProcessDataFilePointer(pdsXlater, true);
1094  }
1095  // Use the "^IMAGE or ^QUBE" label to get the filename for the image data
1096  // Get the path portion from user entered label file spec
1097  else {
1098  // Handle filename and offset
1099  ProcessDataFilePointer(pdsXlater, false);
1100  }
1101 
1102  //------------------------------------------------------------
1103  // Find the image data base and multiplier
1104  //------------------------------------------------------------
1105  str = pdsXlater.Translate("CoreBase");
1106  SetBase(toDouble(str));
1107  str = pdsXlater.Translate("CoreMultiplier");
1108  SetMultiplier(toDouble(str));
1109 
1110  // Find the organization of the image data
1111  str = pdsXlater.Translate("CoreOrganization");
1112 
1113  if (p_encodingType == JP2) {
1114  SetOrganization(ProcessImport::JP2);
1115  }
1116  else if (str == "BSQ") {
1117  SetOrganization(ProcessImport::BSQ);
1118  }
1119  else if (str == "BIP") {
1120  SetOrganization(ProcessImport::BIP);
1121  }
1122  else if (str == "BIL") {
1123  SetOrganization(ProcessImport::BIL);
1124  }
1125  else {
1126  QString msg = "Unsupported axis order [" + str + "]";
1127  throw IException(IException::Programmer, msg, _FILEINFO_);
1128  }
1129  }
1130 
1131 
1136  void ProcessImportPds::ProcessPixelBitandType(Isis::PvlToPvlTranslationManager & pdsXlater) {
1137  QString str;
1138  str = pdsXlater.Translate("CoreBitsPerPixel");
1139  int bitsPerPixel = toInt(str);
1140  str = pdsXlater.Translate("CorePixelType");
1141 
1142  if ((str == "Real") && (bitsPerPixel == 64)) {
1143 
1144  SetPixelType(Isis::Double);
1145  }
1146  else if ((str == "Real") && (bitsPerPixel == 32)) {
1147  SetPixelType(Isis::Real);
1148  }
1149  else if ((str == "Integer") && (bitsPerPixel == 8)) {
1150  SetPixelType(Isis::UnsignedByte);
1151  }
1152  else if ((str == "Integer") && (bitsPerPixel == 16)) {
1153  SetPixelType(Isis::SignedWord);
1154  }
1155  else if ((str == "Integer") && (bitsPerPixel == 32)) {
1156  SetPixelType(Isis::SignedInteger);
1157  }
1158  else if ((str == "Natural") && (bitsPerPixel == 8)) {
1159  SetPixelType(Isis::UnsignedByte);
1160  }
1161  else if ((str == "Natural") && (bitsPerPixel == 16)) {
1162  SetPixelType(Isis::UnsignedWord);
1163  }
1164  else if ((str == "Natural") && (bitsPerPixel == 16)) {
1165  SetPixelType(Isis::SignedWord);
1166  }
1167  else if ((str == "Natural") && (bitsPerPixel == 32)) {
1168  SetPixelType(Isis::UnsignedInteger);
1169  }
1170 
1171  else {
1172  QString msg = "Invalid PixelType and BitsPerPixel combination [" + str +
1173  ", " + toString(bitsPerPixel) + "]";
1174  throw IException(IException::Io, msg, _FILEINFO_);
1175  }
1176  }
1177 
1178 
1190  void ProcessImportPds::ProcessPdsM3Label(const QString &pdsDataFile, PdsFileType fileType) {
1191  Isis::FileName transFile;
1192  if (fileType == L0) {
1193  transFile = p_transDir + "/translations/pdsL0.trn";
1194  }
1195  else if (fileType == Rdn) {
1196  transFile = p_transDir + "/translations/pdsRdn.trn";
1197  }
1198  else if (fileType == Loc) {
1199  transFile = p_transDir + "/translations/pdsLoc.trn";
1200  }
1201  else if (fileType == Obs) {
1202  transFile = p_transDir + "/translations/pdsObs.trn";
1203  }
1204  else {
1205  throw IException(IException::Programmer, "ProcessImportPds::ProcessPdsM3Label can only be "
1206  "called with file type of L0, Rdn, Loc or Obs.", _FILEINFO_);
1207  }
1208  Isis::PvlToPvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
1209 
1210  QString str;
1211 
1212  // L1B (Rdn) products do not have an prefix or suffix data. L0 have 1280 bytes at the
1213  // beginning of each line of the BIL formatted file.
1214  str = pdsXlater.Translate("CoreLinePrefixBytes");
1215  SetDataHeaderBytes(toInt(str));
1216 
1217  str = pdsXlater.Translate("CoreLineSuffixBytes");
1218  SetDataSuffixBytes(toInt(str));
1219 
1220  ProcessPixelBitandType(pdsXlater);
1221 
1222  str = pdsXlater.Translate("CoreByteOrder");
1223  SetByteOrder(Isis::ByteOrderEnumeration(str));
1224 
1225  str = pdsXlater.Translate("CoreSamples");
1226  int ns = toInt(str);
1227  str = pdsXlater.Translate("CoreLines");
1228  int nl = toInt(str);
1229  str = pdsXlater.Translate("CoreBands");
1230  int nb = toInt(str);
1231  SetDimensions(ns, nl, nb);
1232 
1233  // Set any special pixel values, not qube, so use false
1234  ProcessSpecialPixels(pdsXlater, false);
1235 
1236  //-----------------------------------------------------------------
1237  // Find the data filename it may be the same as the label file
1238  // OR the label file may contain a pointer to the data
1239  //-----------------------------------------------------------------
1240 
1241  // Use the name supplied by the application if it is there
1242  if (pdsDataFile.length() > 0) {
1243  SetInputFile(pdsDataFile);
1244  ProcessDataFilePointer(pdsXlater, true);
1245  }
1246  // If the data is in JPEG 2000 format, then use the name of the file
1247  // from the label
1248  else if (p_jp2File.length() > 0) {
1249  SetInputFile(p_jp2File);
1250  ProcessDataFilePointer(pdsXlater, true);
1251  }
1252  // Use the "^IMAGE or ^QUBE" label to get the filename for the image data
1253  // Get the path portion from user entered label file spec
1254  else {
1255  // Handle filename and offset
1256  ProcessDataFilePointer(pdsXlater, false);
1257  }
1258 
1259  //------------------------------------------------------------
1260  // Find the image data base and multiplier
1261  //------------------------------------------------------------
1262  str = pdsXlater.Translate("CoreBase");
1263  SetBase(toDouble(str));
1264  str = pdsXlater.Translate("CoreMultiplier");
1265  SetMultiplier(toDouble(str));
1266 
1267  // Find the organization of the image data
1268  str = pdsXlater.Translate("CoreOrganization");
1269 
1270  if (p_encodingType == JP2) {
1271  SetOrganization(ProcessImport::JP2);
1272  }
1273  else if (str == "BSQ") {
1274  SetOrganization(ProcessImport::BSQ);
1275  }
1276  else if (str == "BIP") {
1277  SetOrganization(ProcessImport::BIP);
1278  }
1279  else if (str == "BIL") {
1280  SetOrganization(ProcessImport::BIL);
1281  }
1282  else {
1283  QString msg = "Unsupported axis order [" + str + "]";
1284  throw IException(IException::Programmer, msg, _FILEINFO_);
1285  }
1286  }
1287 
1288 
1292  void ProcessImportPds::ProcessSpecialPixels(Isis::PvlToPvlTranslationManager & pdsXlater, const bool & isQube) {
1293  QString str;
1294  // Set any special pixel values
1295  double pdsNull = Isis::NULL8;
1296  if (pdsXlater.InputHasKeyword("CoreNull")) {
1297  str = pdsXlater.Translate("CoreNull");
1298  if (str != "NULL") {
1299  pdsNull = toDouble(str);
1300  }
1301  }
1302  else if (!isQube && pdsXlater.InputHasKeyword("CoreNull2")) {
1303  str = pdsXlater.Translate("CoreNull2");
1304  if (str != "NULL") {
1305  pdsNull = toDouble(str);
1306  }
1307  }
1308 
1309  double pdsLrs = Isis::Lrs;
1310  if (pdsXlater.InputHasKeyword("CoreLrs")) {
1311  str = pdsXlater.Translate("CoreLrs");
1312  if (str != "NULL") {
1313  pdsLrs = toDouble(str);
1314  }
1315  }
1316  else if (!isQube && pdsXlater.InputHasKeyword("CoreLrs2")) {
1317  str = pdsXlater.Translate("CoreLrs2");
1318  if (str != "NULL") {
1319  pdsLrs = toDouble(str);
1320  }
1321  }
1322 
1323  double pdsLis = Isis::Lis;
1324  if (pdsXlater.InputHasKeyword("CoreLis")) {
1325  str = pdsXlater.Translate("CoreLis");
1326  if (str != "NULL") {
1327  pdsLis = toDouble(str);
1328  }
1329  }
1330  else if (!isQube && pdsXlater.InputHasKeyword("CoreLis2")) {
1331  str = pdsXlater.Translate("CoreLis2");
1332  if (str != "NULL") {
1333  pdsLis = toDouble(str);
1334  }
1335  }
1336 
1337  double pdsHrs = Isis::Hrs;
1338  if (pdsXlater.InputHasKeyword("CoreHrs")) {
1339  str = pdsXlater.Translate("CoreHrs");
1340  if (str != "NULL") {
1341  pdsHrs = toDouble(str);
1342  }
1343  }
1344  else if (!isQube && pdsXlater.InputHasKeyword("CoreHrs2")) {
1345  str = pdsXlater.Translate("CoreHrs2");
1346  if (str != "NULL") {
1347  pdsHrs = toDouble(str);
1348  }
1349  }
1350 
1351  double pdsHis = Isis::His;
1352  if (pdsXlater.InputHasKeyword("CoreHis")) {
1353  str = pdsXlater.Translate("CoreHis");
1354  if (str != "NULL") {
1355  pdsHis = toDouble(str);
1356  }
1357  }
1358  else if (!isQube && pdsXlater.InputHasKeyword("CoreHis2")) {
1359  str = pdsXlater.Translate("CoreHis2");
1360  if (str != "NULL") {
1361  pdsHis = toDouble(str);
1362  }
1363  }
1364 
1365  SetSpecialValues(pdsNull, pdsLrs, pdsLis, pdsHrs, pdsHis);
1366  }
1367 
1368 
1383  void ProcessImportPds::SetPdsFile(const Isis::Pvl &pdsLabelPvl,
1384  const QString &pdsDataFile,
1385  PdsFileType allowedTypes) {
1386 
1387  // Save the label and file for future use
1388  p_pdsLabel = pdsLabelPvl;
1389  p_labelFile = pdsDataFile;
1390  ProcessLabel(pdsDataFile, allowedTypes);
1391  }
1392 
1393 
1411  void ProcessImportPds::SetPdsFile(const QString &pdsLabelFile,
1412  const QString &pdsDataFile,
1413  Isis::Pvl &pdsLabel,
1414  PdsFileType allowedTypes) {
1415 
1416  // Internalize the PDS label in the PVL that was passed in
1417  try {
1418  pdsLabel.read(pdsLabelFile);
1419  }
1420  catch (IException &e) {
1421  throw IException(e, IException::User,
1422  QObject::tr("This image does not contain a pds label. You will need an "
1423  "image with a PDS label or a detached PDS label for this "
1424  "image."), _FILEINFO_);
1425  }
1426 
1427  // Save the label and file for future use
1428  p_pdsLabel = pdsLabel;
1429  p_labelFile = pdsLabelFile;
1430  ProcessLabel(pdsDataFile, allowedTypes);
1431  }
1432 
1433 
1437  void ProcessImportPds::StartProcess() {
1438  ProcessImport::StartProcess();
1439  for (unsigned int i = 0; i < p_tables.size(); i++) {
1440  OutputCubes[0]->write(p_tables[i]);
1441  }
1442  return;
1443  }
1444 
1445 
1456  void ProcessImportPds::StartProcess(void funct(Isis::Buffer &out)) {
1457  ProcessImport::StartProcess(funct);
1458  return;
1459  }
1460 
1461 
1462 
1469  void ProcessImportPds::TranslateIsis2BandBin(Isis::Pvl &lab) {
1470  // Set up a translater for Isis2 labels
1471  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
1472  QString transDir = (QString) dataDir["Base"];
1473 
1474  Isis::FileName transFile(transDir + "/" + "translations/isis2bandbin.trn");
1475  Isis::PvlToPvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1476 
1477  // Add all the Isis2 keywords that can be translated to the requested label
1478  isis2Xlater.Auto(lab);
1479  }
1480 
1481 
1488  void ProcessImportPds::TranslateIsis2Instrument(Isis::Pvl &lab) {
1489  // Set up a translater for Isis2 labels
1490  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
1491  QString transDir = (QString) dataDir["Base"];
1492  Isis::FileName transFile(transDir + "/" + "translations/isis2instrument.trn");
1493  Isis::PvlToPvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1494 
1495  // Add all the Isis2 keywords that can be translated to the requested label
1496  isis2Xlater.Auto(lab);
1497 
1498  //Check StartTime for appended 'z' (Zulu time) and remove
1499  Isis::PvlGroup &inst = lab.findGroup("Instrument");
1500 
1501  if (inst.hasKeyword("StartTime")) {
1502  Isis::PvlKeyword &stkey = inst["StartTime"];
1503  QString stime = stkey[0];
1504  stime = stime.remove(QRegExp("[Zz]$"));
1505  stkey = stime;
1506  }
1507  }
1508 
1509 
1517  void ProcessImportPds::TranslateIsis2Labels(Isis::Pvl &lab) {
1518  TranslateIsis2BandBin(lab);
1519  TranslateIsis2Instrument(lab);
1520  }
1521 
1522 
1529  void ProcessImportPds::TranslatePdsArchive(Isis::Pvl &lab) {
1530  // Set up a translater for PDS labels
1531  Isis::FileName transFile(p_transDir + "/" + "translations/pdsImageArchive.trn");
1532  Isis::PvlToPvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1533 
1534  // Add all the Isis2 keywords that can be translated to the requested label
1535  isis2Xlater.Auto(lab);
1536  }
1537 
1538 
1545  void ProcessImportPds::TranslatePdsBandBin(Isis::Pvl &lab) {
1546  // Set up a translater for PDS labels
1547  Isis::FileName transFile(p_transDir + "/" + "translations/pdsImageBandBin.trn");
1548  Isis::PvlToPvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1549 
1550  // Add all the Isis2 keywords that can be translated to the requested label
1551  isis2Xlater.Auto(lab);
1552  }
1553 
1554 
1562  void ProcessImportPds::TranslatePdsLabels(Isis::Pvl &lab) {
1563  TranslatePdsBandBin(lab);
1564  TranslatePdsArchive(lab);
1565  }
1566 
1567 
1579  void ProcessImportPds::TranslatePdsProjection(Isis::Pvl &lab) {
1580 
1581  // Create a temporary Isis::PvlToPvlTranslationManager so we can find out what
1582  // type of projection labels exist
1583  stringstream trnsStrm;
1584  trnsStrm << "Group = PdsProjectionTypeImage" << endl;
1585  trnsStrm << " InputPosition = IMAGE_MAP_PROJECTION" << endl;
1586  trnsStrm << " InputPosition = IMAGE_MAP_PROJECTION_CATALOG" << endl;
1587  trnsStrm << " InputKey = MAP_PROJECTION_TYPE" << endl;
1588  trnsStrm << "EndGroup" << endl;
1589  trnsStrm << "Group = PdsProjectionTypeQube" << endl;
1590  trnsStrm << " InputPosition = (QUBE,IMAGE_MAP_PROJECTION)" << endl;
1591  trnsStrm << " InputKey = MAP_PROJECTION_TYPE" << endl;
1592  trnsStrm << "EndGroup" << endl;
1593  trnsStrm << "Group = PdsProjectionTypeSpectralQube" << endl;
1594  trnsStrm << " InputPosition = (SPECTRAL_QUBE,IMAGE_MAP_PROJECTION)" << endl;
1595  trnsStrm << " InputKey = MAP_PROJECTION_TYPE" << endl;
1596  trnsStrm << "EndGroup" << endl;
1597  trnsStrm << "END";
1598 
1599  Isis::PvlToPvlTranslationManager projType(p_pdsLabel, trnsStrm);
1600 
1601  // Set up the correct projection translation table for this label
1602  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
1603  QString transDir = (QString) dataDir["Base"];
1604 
1605  Isis::FileName transFile;
1606  if (projType.InputHasKeyword("PdsProjectionTypeImage")) {
1607  transFile = transDir + "/" + "translations/pdsImageProjection.trn";
1608  }
1609  else if (projType.InputHasKeyword("PdsProjectionTypeQube")) {
1610  transFile = transDir + "/" + "translations/pdsQubeProjection.trn";
1611  }
1612  else if (projType.InputHasKeyword("PdsProjectionTypeSpectralQube")) {
1613  transFile = transDir + "/" + "translations/pdsSpectralQubeProjection.trn";
1614  }
1615  else {
1616  return;
1617  }
1618 
1619  Isis::PvlToPvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
1620 
1621  ExtractPdsProjection(pdsXlater);
1622 
1623  Isis::PvlGroup mapGroup("Mapping");
1624  mapGroup += Isis::PvlKeyword("ProjectionName", p_projection);
1625  mapGroup += Isis::PvlKeyword("TargetName", p_targetName);
1626  mapGroup += Isis::PvlKeyword("EquatorialRadius", toString(p_equatorialRadius), "meters");
1627  mapGroup += Isis::PvlKeyword("PolarRadius", toString(p_polarRadius), "meters");
1628  mapGroup += Isis::PvlKeyword("LongitudeDirection", p_longitudeDirection);
1629  mapGroup += Isis::PvlKeyword("LongitudeDomain", toString(p_longitudeDomain));
1630  mapGroup += Isis::PvlKeyword("LatitudeType", p_latitudeType);
1631  if (p_minimumLatitude != Isis::NULL8) {
1632  mapGroup += Isis::PvlKeyword("MinimumLatitude", toString(p_minimumLatitude));
1633  }
1634  if (p_maximumLatitude != Isis::NULL8) {
1635  mapGroup += Isis::PvlKeyword("MaximumLatitude", toString(p_maximumLatitude));
1636  }
1637  if (p_minimumLongitude != Isis::NULL8) {
1638  mapGroup += Isis::PvlKeyword("MinimumLongitude", toString(p_minimumLongitude));
1639  }
1640  if (p_maximumLongitude != Isis::NULL8) {
1641  mapGroup += Isis::PvlKeyword("MaximumLongitude", toString(p_maximumLongitude));
1642  }
1643 
1644  // if both longitudes exist, verify they are ordered correctly
1645  if (p_minimumLongitude != Isis::NULL8 && p_maximumLongitude != Isis::NULL8) {
1646  if (p_maximumLongitude <= p_minimumLongitude) {
1647  if (p_longitudeDomain == 180) {
1648  mapGroup["MinimumLongitude"] = toString(-180);
1649  mapGroup["MaximumLongitude"] = toString(180);
1650  }
1651  else {
1652  mapGroup["MinimumLongitude"] = toString(0);
1653  mapGroup["MaximumLongitude"] = toString(360);
1654  }
1655  }
1656  }
1657 
1658  mapGroup += Isis::PvlKeyword("PixelResolution", toString(p_pixelResolution), "meters/pixel");
1659  mapGroup += Isis::PvlKeyword("Scale", toString(p_scaleFactor), "pixels/degree");
1660  mapGroup += Isis::PvlKeyword("UpperLeftCornerX", toString(p_upperLeftX), "meters");
1661  mapGroup += Isis::PvlKeyword("UpperLeftCornerY", toString(p_upperLeftY), "meters");
1662  if (p_rotation != 0.0) {
1663  mapGroup += Isis::PvlKeyword("Rotation", toString(p_rotation));
1664  }
1665 
1666  // To handle new projections without the need to modify source code
1667  // we will construct a filename from the projection. The filename will
1668  // contain the projection specific translations from PDS to ISIS for each
1669  // projection
1670 
1671  QString projSpecificFileName = "$base/translations/pdsImport";
1672  projSpecificFileName += p_projection + ".trn";
1673  Isis::PvlToPvlTranslationManager specificXlater(p_pdsLabel, projSpecificFileName);
1674 
1675  lab.addGroup(mapGroup);
1676  specificXlater.Auto(lab);
1677 
1678  if (lab.findGroup("Mapping").hasKeyword("CenterLongitude")) {
1679  PvlKeyword &centerLon = lab.findGroup("Mapping")["CenterLongitude"];
1680  if (p_longitudeDomain == 180)
1681  centerLon = toString(TProjection::To180Domain((double)centerLon));
1682  else
1683  centerLon = toString(TProjection::To360Domain((double)centerLon));
1684  }
1685 
1686  if (lab.findGroup("Mapping").hasKeyword("PoleLongitude")) {
1687  PvlKeyword &poleLon = lab.findGroup("Mapping")["PoleLongitude"];
1688  if (p_longitudeDomain == 180)
1689  poleLon = toString(TProjection::To180Domain((double)poleLon));
1690  else
1691  poleLon = toString(TProjection::To360Domain((double)poleLon));
1692  }
1693 
1694  OutputCubes[0]->putGroup(lab.findGroup("Mapping"));
1695  }
1696 }
Buffer for reading and writing cube data.
Definition: Buffer.h:69
QString path() const
Returns the path of the file name.
Definition: FileName.cpp:119
Read and store original labels.
Definition: OriginalLabel.h:51
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
QString unit(const int index=0) const
Returns the units of measurement of the element of the array of values for the object at the specifie...
Definition: PvlKeyword.cpp:373
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
File name manipulation and expansion.
Definition: FileName.h:116
Table importTable(const QString &isisTableName)
Populate a Table object with the PDS table and return it.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:198
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
Namespace for the standard library.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
Allows applications to translate simple text files.
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
const double Lis
Value for an Isis Low Instrument Saturation pixel.
Definition: SpecialPixel.h:120
virtual bool InputHasKeyword(const QString translationGroupName)
Indicates if the input keyword corresponding to the output name exists in the label.
int ToInteger(const T &value)
Helper function to convert values to Integers.
Definition: HiCalUtil.h:236
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:141
static double To180Domain(const double lon)
This method converts a longitude into the -180 to 180 domain.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Definition: PvlObject.cpp:148
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
This represents a cube in a project-based GUI interface.
Definition: Image.h:107
virtual QString Translate(QString translationGroupName, int findex=0)
Returns a translated value.
Container for cube-like labels.
Definition: Pvl.h:135
virtual const PvlKeyword & InputKeyword(const QString translationGroupName) const
Returns the ith input value associated with the output name argument.
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:423
Class for storing Table blobs information.
Definition: Table.h:77
QString getFormattedName(const QString &colname) const
Converts a column name to a camel-case after it has been cleansed.
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void Auto(Pvl &outputLabel)
Automatically translate all the output names found in the translation table If a output name does not...
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
const double Lrs
Value for an Isis Low Representation Saturation pixel.
Definition: SpecialPixel.h:114
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
void read(const QString &file)
Loads PVL information from a stream.
Definition: Pvl.cpp:76
Import a PDS table file with a label description.
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:465
const double His
Value for an Isis High Instrument Saturation pixel.
Definition: SpecialPixel.h:126
const double Hrs
Value for an Isis High Representation Saturation pixel.
Definition: SpecialPixel.h:132