Isis 3.0 Programmer Reference
Back | Home
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"
44 #include "PvlTranslationManager.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 
60  // Set up a translater for PDS file of type IMAGE
61  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
62  p_transDir = (QString) dataDir["Base"];
63  }
64 
65 
66  ProcessImportPds::~ProcessImportPds() {
67  }
68 
69 
84  void ProcessImportPds::SetPdsFile(const Isis::Pvl &pdsLabelPvl,
85  const QString &pdsDataFile,
86  PdsFileType allowedTypes) {
87 
88  // Save the label and file for future use
89  p_pdsLabel = pdsLabelPvl;
90  p_labelFile = pdsDataFile;
91  ProcessLabel(pdsDataFile, allowedTypes);
92  }
93 
94 
112  void ProcessImportPds::SetPdsFile(const QString &pdsLabelFile,
113  const QString &pdsDataFile,
114  Isis::Pvl &pdsLabel,
115  PdsFileType allowedTypes) {
116 
117  // Internalize the PDS label in the PVL that was passed in
118  try {
119  pdsLabel.read(pdsLabelFile);
120  }
121  catch (IException &e) {
122  throw IException(e, IException::User,
123  QObject::tr("This image does not contain a pds label. You will need an "
124  "image with a PDS label or a detached PDS label for this "
125  "image."), _FILEINFO_);
126  }
127 
128  // Save the label and file for future use
129  p_pdsLabel = pdsLabel;
130  p_labelFile = pdsLabelFile;
131  ProcessLabel(pdsDataFile, allowedTypes);
132  }
133 
134 
150  void ProcessImportPds::ProcessLabel(const QString &pdsDataFile, PdsFileType allowedTypes) {
151  // Create a temporary Isis::PvlTranslationManager so we can find out what
152  // type of PDS file this is (i.e., Qube or Image or SpectralQube)
153  stringstream trnsStrm;
154  trnsStrm << "Group = PdsTypeImage" << endl;
155  trnsStrm << " InputPosition = ROOT" << endl;
156  trnsStrm << " InputPosition = FILE" << endl;
157  trnsStrm << " InputPosition = UNCOMPRESSED_FILE" << endl;
158  trnsStrm << " InputKey = ^IMAGE" << endl;
159  trnsStrm << "EndGroup" << endl;
160  trnsStrm << "Group = PdsCombinedSpectrum" << endl;
161  trnsStrm << " InputPosition = ROOT" << endl;
162  trnsStrm << " InputPosition = FILE" << endl;
163  trnsStrm << " InputPosition = UNCOMPRESSED_FILE" << endl;
164  trnsStrm << " InputKey = ^COMBINED_SPECTRUM" << endl;
165  trnsStrm << "EndGroup" << endl;
166  trnsStrm << "Group = PdsTypeL0" << endl;
167  trnsStrm << " InputPosition = L0_FILE" << endl;
168  trnsStrm << " InputKey = ^L0_IMAGE" << endl;
169  trnsStrm << "EndGroup" << endl;
170  trnsStrm << "Group = PdsTypeRdn" << endl;
171  trnsStrm << " InputPosition = RDN_FILE" << endl;
172  trnsStrm << " InputKey = ^RDN_IMAGE" << endl;
173  trnsStrm << "EndGroup" << endl;
174  trnsStrm << "Group = PdsTypeLoc" << endl;
175  trnsStrm << " InputPosition = LOC_FILE" << endl;
176  trnsStrm << " InputKey = ^LOC_IMAGE" << endl;
177  trnsStrm << "EndGroup" << endl;
178  trnsStrm << "Group = PdsTypeObs" << endl;
179  trnsStrm << " InputPosition = OBS_FILE" << endl;
180  trnsStrm << " InputKey = ^OBS_IMAGE" << endl;
181  trnsStrm << "EndGroup" << endl;
182  trnsStrm << "Group = PdsTypeQube" << endl;
183  trnsStrm << " InputKey = ^QUBE" << endl;
184  trnsStrm << "EndGroup" << endl;
185  trnsStrm << "Group = PdsTypeSpectralQube" << endl;
186  trnsStrm << " InputKey = ^SPECTRAL_QUBE" << endl;
187  trnsStrm << "EndGroup" << endl;
188  trnsStrm << "Group = PdsEncodingType" << endl;
189  trnsStrm << " InputPosition = COMPRESSED_FILE" << endl;
190  trnsStrm << " InputKey = ENCODING_TYPE" << endl;
191  trnsStrm << " Translation = (*,*)" << endl;
192  trnsStrm << "EndGroup" << endl;
193  trnsStrm << "Group = PdsCompressedFile" << endl;
194  trnsStrm << " InputPosition = COMPRESSED_FILE" << endl;
195  trnsStrm << " InputKey = FILE_NAME" << endl;
196  trnsStrm << " Translation = (*,*)" << endl;
197  trnsStrm << "EndGroup" << endl;
198  trnsStrm << "END";
199 
200 
201  //tjw
202  //Determine if we are processing a QUBE whose
203  //core data type is VAX_REAL
204 
205  try{
206 
207  PvlObject obj = p_pdsLabel.findObject("QUBE");
208  PvlKeyword coreKey = obj.findKeyword("CORE_ITEM_TYPE");
209  PvlKeyword suffixKey = obj.findKeyword("BAND_SUFFIX_ITEM_TYPE");
210  //if ( (coreKey[0] == "VAX_REAL") && (suffixKey[0] =="VAX_REAL") )
211 
212  if (coreKey[0] == "VAX_REAL") {
213 
214  ProcessImport::SetVAXConvert(true);
215  }
216 
217  }
218  catch(IException &e){
219 
220 
221  }
222 
223 
224 
225  Isis::PvlTranslationManager pdsXlater(p_pdsLabel, trnsStrm);
226 
227 
228  // Check to see if we are dealing with a JPEG2000 file
229  QString str;
230  if (pdsXlater.InputHasKeyword("PdsEncodingType")) {
231  str = pdsXlater.Translate("PdsEncodingType");
232  if (str == "JP2") {
233  p_encodingType = JP2;
234  str = pdsXlater.Translate("PdsCompressedFile");
235  if (pdsDataFile.isEmpty()) {
236  Isis::FileName lfile(p_labelFile);
237  Isis::FileName ifile(lfile.path() + "/" + str);
238  if (ifile.fileExists()) {
239  p_jp2File = ifile.expanded();
240  }
241  else {
242  QString tmp = ifile.expanded();
243  str = str.toLower();
244  ifile = lfile.path() + "/" + str;
245  if (ifile.fileExists()) {
246  p_jp2File = ifile.expanded();
247  }
248  else {
249  QString msg = "Unable to find input file [" + tmp + "] or [" +
250  ifile.expanded() + "]";
251  throw IException(IException::Io, msg, _FILEINFO_);
252  }
253  }
254  }
255  }
256  else {
257  QString msg = "Unsupported encoding type in [" + p_labelFile + "]";
258  throw IException(IException::Io, msg, _FILEINFO_);
259  }
260  }
261 
262 
263 
264 
265  // Call the correct label processing
266  if ((allowedTypes & Image) == Image && pdsXlater.InputHasKeyword("PdsTypeImage")) {
267 
268  ProcessPdsImageLabel(pdsDataFile);
269  }
270  else if ((allowedTypes & Qube) == Qube && pdsXlater.InputHasKeyword("PdsTypeQube")) {
271 
272  ProcessPdsQubeLabel(pdsDataFile, "pdsQube.trn");
273  }
274  else if ((allowedTypes & SpectralQube) == SpectralQube &&
275  pdsXlater.InputHasKeyword("PdsTypeSpectralQube")) {
276 
277  ProcessPdsQubeLabel(pdsDataFile, "pdsSpectralQube.trn");
278  }
279  else if ((allowedTypes & L0) == L0 && pdsXlater.InputHasKeyword("PdsTypeL0")) {
280 
281  ProcessPdsM3Label(pdsDataFile, L0);
282  }
283  else if ((allowedTypes & Rdn) == Rdn && pdsXlater.InputHasKeyword("PdsTypeRdn")) {
284 
285  ProcessPdsM3Label(pdsDataFile, Rdn);
286  }
287  else if ((allowedTypes & Loc) == Loc && pdsXlater.InputHasKeyword("PdsTypeLoc")) {
288 
289  ProcessPdsM3Label(pdsDataFile, Loc);
290  }
291  else if ((allowedTypes & Obs) == Obs && pdsXlater.InputHasKeyword("PdsTypeObs")) {
292 
293  ProcessPdsM3Label(pdsDataFile, Obs);
294  }
295  else if ((allowedTypes & CombinedSpectrum) == CombinedSpectrum &&
296  pdsXlater.InputHasKeyword("PdsCombinedSpectrum")) {
297 
298  ProcessPdsCombinedSpectrumLabel(pdsDataFile);
299  }
300  else {
301  QString msg = "Unknown label type in [" + p_labelFile + "]";
302  throw IException(IException::Io, msg, _FILEINFO_);
303  }
304 
305 
306 
307  // Find out if this is a PDS file or an ISIS2 file
308  IdentifySource(p_pdsLabel);
309 
310 
311 
312 
313  return;
314  }
315 
316 
323  void ProcessImportPds::ProcessDataFilePointer(Isis::PvlTranslationManager & pdsXlater,
324  const bool & calcOffsetOnly) {
325 
326  const PvlKeyword & dataFilePointer = pdsXlater.InputKeyword("DataFilePointer");
327 
328  QString dataFileName;
329  QString units;
330  QString str;
331  int offset = -1;
332 
333  // If only size 1, we either have a file name or an offset
334  // Either way, when we're done with these two ifs, variables offset and
335  // dataFileName will be set.
336  if (dataFilePointer.size() == 1) {
337  try {
338  str = pdsXlater.Translate("DataFilePointer");
339  offset = toInt(str);
340  units = dataFilePointer.unit();
341  // Successful? we have an offset, means current, p_labelFile
342  // is the location of the data as well
343  dataFileName = FileName(p_labelFile).name();
344  }
345  catch(IException &e) {
346  // Failed to parse to an int, means we have a file name
347  // No offset given, so we use 1, offsets are 1 based
348  offset = 1;
349  units = "BYTES";
350  dataFileName = str;
351  }
352  }
353  // We must have a filename and an offset, in that order
354  // Expection ("filname", <offset>)
355  else if (dataFilePointer.size() == 2) {
356  dataFileName = pdsXlater.Translate("DataFilePointer", 0);
357  offset = IString(pdsXlater.Translate("DataFilePointer", 1)).ToInteger();
358  units = dataFilePointer.unit(1);
359  }
360  // Error, no value
361  else if (dataFilePointer.size() == 0) {
362  QString msg = "Data file pointer ^IMAGE or ^QUBE has no value, must"
363  "have either file name or offset or both, in [" +
364  p_labelFile + "]";
365  throw IException(IException::Unknown, msg, _FILEINFO_);
366  }
367  // Error, more than two values
368  else {
369  QString msg = "Improperly formatted data file pointer keyword ^IMAGE or "
370  "^QUBE, in [" + p_labelFile + "], must contain filename "
371  " or offset or both";
372  throw IException(IException::Unknown, msg, _FILEINFO_);
373  }
374 
375  // Now, to handle the values we found
376  // the filename first, only do so if calcOffsetOnly is false
377  if (!calcOffsetOnly) {
378  Isis::FileName labelFile(p_labelFile);
379 
380  // If dataFileName isn't empty, and does start at the root, use it
381  Isis::FileName dataFile;
382  if (dataFileName.size() != 0 && dataFileName.at(0) == '/')
383  dataFile = FileName(dataFileName);
384  // Otherwise, use the path to it and its name
385  else
386  dataFile = FileName(labelFile.path() + "/" + dataFileName);
387 
388  // If it exists, use it
389  if (dataFile.fileExists()) {
390  SetInputFile(dataFile.expanded());
391  }
392  // Retry with downcased name, if still no luck, fail
393  else {
394  QString tmp = dataFile.expanded();
395  dataFileName = dataFileName.toLower();
396  dataFile = FileName(labelFile.path() + "/" + dataFileName);
397  if (dataFile.fileExists()) {
398  SetInputFile(dataFile.expanded());
399  }
400  else {
401  QString msg = "Unable to find input file [" + tmp + "] or [" +
402  dataFile.expanded() + "]";
403  throw IException(IException::Io, msg, _FILEINFO_);
404  }
405  }
406  }
407 
408  // Now, to handle the offset
409  units = units.trimmed();
410  if (units == "BYTES" || units == "B") {
411  SetFileHeaderBytes(offset - 1);
412  }
413  else {
414  QString recSize = pdsXlater.Translate("DataFileRecordBytes");
415  SetFileHeaderBytes((offset - 1) * toInt(recSize));
416  }
417  }
418 
419 
424  void ProcessImportPds::ProcessPixelBitandType(Isis::PvlTranslationManager & pdsXlater) {
425  QString str;
426  str = pdsXlater.Translate("CoreBitsPerPixel");
427  int bitsPerPixel = toInt(str);
428  str = pdsXlater.Translate("CorePixelType");
429 
430  if ((str == "Real") && (bitsPerPixel == 64)) {
431 
432  SetPixelType(Isis::Double);
433  }
434  else if ((str == "Real") && (bitsPerPixel == 32)) {
435  SetPixelType(Isis::Real);
436  }
437  else if ((str == "Integer") && (bitsPerPixel == 8)) {
438  SetPixelType(Isis::UnsignedByte);
439  }
440  else if ((str == "Integer") && (bitsPerPixel == 16)) {
441  SetPixelType(Isis::SignedWord);
442  }
443  else if ((str == "Integer") && (bitsPerPixel == 32)) {
444  SetPixelType(Isis::SignedInteger);
445  }
446  else if ((str == "Natural") && (bitsPerPixel == 8)) {
447  SetPixelType(Isis::UnsignedByte);
448  }
449  else if ((str == "Natural") && (bitsPerPixel == 16)) {
450  SetPixelType(Isis::UnsignedWord);
451  }
452  else if ((str == "Natural") && (bitsPerPixel == 16)) {
453  SetPixelType(Isis::SignedWord);
454  }
455  else if ((str == "Natural") && (bitsPerPixel == 32)) {
456  SetPixelType(Isis::UnsignedInteger);
457  }
458 
459 
460  else {
461  QString msg = "Invalid PixelType and BitsPerPixel combination [" + str +
462  ", " + toString(bitsPerPixel) + "]";
463  throw IException(IException::Io, msg, _FILEINFO_);
464  }
465  }
466 
467 
471  void ProcessImportPds::ProcessSpecialPixels(Isis::PvlTranslationManager & pdsXlater, const bool & isQube) {
472  QString str;
473  // Set any special pixel values
474  double pdsNull = Isis::NULL8;
475  if (pdsXlater.InputHasKeyword("CoreNull")) {
476  str = pdsXlater.Translate("CoreNull");
477  if (str != "NULL") {
478  pdsNull = toDouble(str);
479  }
480  }
481  else if (!isQube && pdsXlater.InputHasKeyword("CoreNull2")) {
482  str = pdsXlater.Translate("CoreNull2");
483  if (str != "NULL") {
484  pdsNull = toDouble(str);
485  }
486  }
487 
488  double pdsLrs = Isis::Lrs;
489  if (pdsXlater.InputHasKeyword("CoreLrs")) {
490  str = pdsXlater.Translate("CoreLrs");
491  if (str != "NULL") {
492  pdsLrs = toDouble(str);
493  }
494  }
495  else if (!isQube && pdsXlater.InputHasKeyword("CoreLrs2")) {
496  str = pdsXlater.Translate("CoreLrs2");
497  if (str != "NULL") {
498  pdsLrs = toDouble(str);
499  }
500  }
501 
502  double pdsLis = Isis::Lis;
503  if (pdsXlater.InputHasKeyword("CoreLis")) {
504  str = pdsXlater.Translate("CoreLis");
505  if (str != "NULL") {
506  pdsLis = toDouble(str);
507  }
508  }
509  else if (!isQube && pdsXlater.InputHasKeyword("CoreLis2")) {
510  str = pdsXlater.Translate("CoreLis2");
511  if (str != "NULL") {
512  pdsLis = toDouble(str);
513  }
514  }
515 
516  double pdsHrs = Isis::Hrs;
517  if (pdsXlater.InputHasKeyword("CoreHrs")) {
518  str = pdsXlater.Translate("CoreHrs");
519  if (str != "NULL") {
520  pdsHrs = toDouble(str);
521  }
522  }
523  else if (!isQube && pdsXlater.InputHasKeyword("CoreHrs2")) {
524  str = pdsXlater.Translate("CoreHrs2");
525  if (str != "NULL") {
526  pdsHrs = toDouble(str);
527  }
528  }
529 
530  double pdsHis = Isis::His;
531  if (pdsXlater.InputHasKeyword("CoreHis")) {
532  str = pdsXlater.Translate("CoreHis");
533  if (str != "NULL") {
534  pdsHis = toDouble(str);
535  }
536  }
537  else if (!isQube && pdsXlater.InputHasKeyword("CoreHis2")) {
538  str = pdsXlater.Translate("CoreHis2");
539  if (str != "NULL") {
540  pdsHis = toDouble(str);
541  }
542  }
543 
544  SetSpecialValues(pdsNull, pdsLrs, pdsLis, pdsHrs, pdsHis);
545  }
546 
547 
559  void ProcessImportPds::ProcessPdsImageLabel(const QString &pdsDataFile) {
560  Isis::FileName transFile(p_transDir + "/translations/pdsImage.trn");
561  Isis::PvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
562 
563  QString str;
564 
565  str = pdsXlater.Translate("CoreLinePrefixBytes");
566  SetDataPrefixBytes(toInt(str));
567 
568  str = pdsXlater.Translate("CoreLineSuffixBytes");
569  SetDataSuffixBytes(toInt(str));
570 
571  ProcessPixelBitandType(pdsXlater);
572 
573  str = pdsXlater.Translate("CoreByteOrder");
574  SetByteOrder(Isis::ByteOrderEnumeration(str));
575 
576  str = pdsXlater.Translate("CoreSamples");
577  int ns = toInt(str);
578  str = pdsXlater.Translate("CoreLines");
579  int nl = toInt(str);
580  str = pdsXlater.Translate("CoreBands");
581  int nb = toInt(str);
582 
583  SetDimensions(ns, nl, nb);
584 
585  // Set any special pixel values, not qube, so use false
586  ProcessSpecialPixels(pdsXlater, false);
587 
588  //-----------------------------------------------------------------
589  // Find the data filename it may be the same as the label file
590  // OR the label file may contain a pointer to the data
591  //-----------------------------------------------------------------
592 
593  // Use the name supplied by the application if it is there
594  if (pdsDataFile.length() > 0) {
595  SetInputFile(pdsDataFile);
596  ProcessDataFilePointer(pdsXlater, true);
597  }
598  // If the data is in JPEG 2000 format, then use the name of the file
599  // from the label
600  else if (p_jp2File.length() > 0) {
601  SetInputFile(p_jp2File);
602  ProcessDataFilePointer(pdsXlater, true);
603  }
604  // Use the "^IMAGE or ^QUBE" label to get the filename for the image data
605  // Get the path portion from user entered label file spec
606  else {
607  // Handle filename and offset
608  ProcessDataFilePointer(pdsXlater, false);
609  }
610 
611  //------------------------------------------------------------
612  // Find the image data base and multiplier
613  //------------------------------------------------------------
614  str = pdsXlater.Translate("CoreBase");
615  SetBase(toDouble(str));
616  str = pdsXlater.Translate("CoreMultiplier");
617  SetMultiplier(toDouble(str));
618 
619  // Find the organization of the image data
620  str = pdsXlater.Translate("CoreOrganization");
621 
622  if (p_encodingType == JP2) {
623  SetOrganization(ProcessImport::JP2);
624  }
625  else if (str == "BSQ") {
626  SetOrganization(ProcessImport::BSQ);
627  }
628  else if (str == "BIP") {
629  SetOrganization(ProcessImport::BIP);
630  }
631  else if (str == "BIL") {
632  SetOrganization(ProcessImport::BIL);
633  }
634  else {
635  QString msg = "Unsupported axis order [" + str + "]";
636  throw IException(IException::Programmer, msg, _FILEINFO_);
637  }
638  }
639 
640 
657  void ProcessImportPds::ProcessPdsQubeLabel(const QString &pdsDataFile,
658  const QString &transFile) {
659 
660 
661  Isis::FileName tFile(p_transDir + "/translations/" + transFile);
662 
663  Isis::PvlTranslationManager pdsXlater(p_pdsLabel, tFile.expanded());
664 
665  QString str;
666 
667 
668  // Find the organization of the image data
669  // Save off which axis the samples, lines and bands are on
670  int linePos = 0;
671  int samplePos = 0;
672  int bandPos = 0;
673  int val = pdsXlater.InputKeyword("CoreOrganization").size();
674  QString tmp = "";
675  for(int i = 0; i < val; i++) {
676  str = pdsXlater.Translate("CoreOrganization", i);
677  tmp += str;
678  if (str == "SAMPLE") {
679  samplePos = i;
680  }
681  else if (str == "LINE") {
682  linePos = i;
683  }
684  else if (str == "BAND") {
685  bandPos = i;
686  }
687  else {
688  QString message = "Unknown file axis name [" + str + "]";
689  throw IException(IException::User, message, _FILEINFO_);
690  }
691  }
692 
693  if (p_encodingType == JP2) {
694  SetOrganization(ProcessImport::JP2);
695  }
696  else if (tmp == "SAMPLELINEBAND") {
697  SetOrganization(ProcessImport::BSQ);
698  }
699  else if (tmp == "BANDSAMPLELINE") {
700  SetOrganization(ProcessImport::BIP);
701  }
702  else if (tmp == "SAMPLEBANDLINE") {
703  SetOrganization(ProcessImport::BIL);
704  }
705  else {
706  PvlKeyword pdsCoreOrg = p_pdsLabel.findKeyword(pdsXlater.
707  InputKeywordName("CoreOrganization"), Pvl::Traverse);
708 
709  stringstream pdsCoreOrgStream;
710  pdsCoreOrgStream << pdsCoreOrg;
711 
712  QString msg = "Unsupported axis order [" + QString(pdsCoreOrgStream.str().c_str()) + "]";
713  throw IException(IException::Programmer, msg, _FILEINFO_);
714  }
715 
716 
717  // Set the number of byte preceding the second dimension (left side plane)
718  // There are no capabilities in a PDS QUBE for this
719  SetDataPrefixBytes(0);
720 
721  // Set the number of bytes following the second dimension (right side plane)
722  str = pdsXlater.Translate("SuffixItemSize");
723  int suffix = toInt(str);
724  str = pdsXlater.Translate("AxisSuffixCount", 0);
725  suffix *= toInt(str);
726  SetDataSuffixBytes(suffix);
727 
728  str = pdsXlater.Translate("SuffixItemSize");
729  int trailer = toInt(str);
730  str = pdsXlater.Translate("AxisSuffixCount", 1);
731  trailer *= toInt(str);
732  str = pdsXlater.Translate("CoreSamples", samplePos);
733  trailer *= toInt(str);
734  trailer += suffix;
735  SetDataTrailerBytes(trailer);
736 
737  ProcessPixelBitandType(pdsXlater);
738 
739  // Set the byte order
740 
741  //tjw:
742  str = pdsXlater.Translate("CoreByteOrder");
743 
744  SetByteOrder(Isis::ByteOrderEnumeration(str));
745 
746  //if(str == "LSB" || str == "MSB")
747  // SetByteOrder(Isis::ByteOrderEnumeration(str));
748  //else {
749  // QString msg = "Unrecognized byte order ["+str+"]";
750  // throw IException(IException::Programmer,msg,_FILEINFO_);
751  //}
752 
753 
754 
755  // Set the number of samples, lines and bands
756  str = pdsXlater.Translate("CoreSamples", samplePos);
757  int ns = toInt(str);
758  str = pdsXlater.Translate("CoreLines", linePos);
759  int nl = toInt(str);
760  str = pdsXlater.Translate("CoreBands", bandPos);
761  int nb = toInt(str);
762  SetDimensions(ns, nl, nb);
763 
764 
765  // Set any special pixels values, qube, so use true
766  ProcessSpecialPixels(pdsXlater, true);
767 
768  //---------------------------------------------------------------
769  // Find the data filename, it may be the same as the label file
770  // Or the label file may contain a pointer to the data
771  //---------------------------------------------------------------
772 
773  // Use the name supplied by the application if it is there
774  if (pdsDataFile.length() > 0) {
775  SetInputFile(pdsDataFile);
776  ProcessDataFilePointer(pdsXlater, true);
777  }
778  // If the data is in JPEG 2000 format, then use the name of the file
779  // from the label
780  else if (p_jp2File.length() > 0) {
781  SetInputFile(p_jp2File);
782  ProcessDataFilePointer(pdsXlater, true);
783  }
784  else {
785  // Handle filename and offset
786  ProcessDataFilePointer(pdsXlater, false);
787  }
788 
789 
790  //------------------------------------------------------------
791  // Find the image data base and multiplier
792  //------------------------------------------------------------
793  // First see if there are base and multiplier in the band bin group
794  if ((pdsXlater.InputHasKeyword("BandBase")) &&
795  (pdsXlater.InputHasKeyword("BandMultiplier"))) {
796  vector<double> bases;
797  vector<double> mults;
798  for(int i = 0; i < pdsXlater.InputKeyword("BandBase").size(); i++) {
799  str = pdsXlater.Translate("BandBase", i);
800  bases.push_back(toDouble(str));
801  str = pdsXlater.Translate("BandMultiplier", i);
802  mults.push_back(toDouble(str));
803  }
804  SetBase(bases);
805  SetMultiplier(mults);
806  }
807  else {
808  str = pdsXlater.Translate("CoreBase");
809  SetBase(toDouble(str));
810  str = pdsXlater.Translate("CoreMultiplier");
811  SetMultiplier(toDouble(str));
812  }
813  }
814 
815 
827  void ProcessImportPds::ProcessPdsM3Label(const QString &pdsDataFile, PdsFileType fileType) {
828  Isis::FileName transFile;
829  if (fileType == L0) {
830  transFile = p_transDir + "/translations/pdsL0.trn";
831  }
832  else if (fileType == Rdn) {
833  transFile = p_transDir + "/translations/pdsRdn.trn";
834  }
835  else if (fileType == Loc) {
836  transFile = p_transDir + "/translations/pdsLoc.trn";
837  }
838  else if (fileType == Obs) {
839  transFile = p_transDir + "/translations/pdsObs.trn";
840  }
841  else {
842  throw IException(IException::Programmer, "ProcessImportPds::ProcessPdsM3Label can only be "
843  "called with file type of L0, Rdn, Loc or Obs.", _FILEINFO_);
844  }
845  Isis::PvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
846 
847  QString str;
848 
849  // L1B (Rdn) products do not have an prefix or suffix data. L0 have 1280 bytes at the
850  // beginning of each line of the BIL formatted file.
851  str = pdsXlater.Translate("CoreLinePrefixBytes");
852  SetDataHeaderBytes(toInt(str));
853 
854  str = pdsXlater.Translate("CoreLineSuffixBytes");
855  SetDataSuffixBytes(toInt(str));
856 
857  ProcessPixelBitandType(pdsXlater);
858 
859  str = pdsXlater.Translate("CoreByteOrder");
860  SetByteOrder(Isis::ByteOrderEnumeration(str));
861 
862  str = pdsXlater.Translate("CoreSamples");
863  int ns = toInt(str);
864  str = pdsXlater.Translate("CoreLines");
865  int nl = toInt(str);
866  str = pdsXlater.Translate("CoreBands");
867  int nb = toInt(str);
868  SetDimensions(ns, nl, nb);
869 
870  // Set any special pixel values, not qube, so use false
871  ProcessSpecialPixels(pdsXlater, false);
872 
873  //-----------------------------------------------------------------
874  // Find the data filename it may be the same as the label file
875  // OR the label file may contain a pointer to the data
876  //-----------------------------------------------------------------
877 
878  // Use the name supplied by the application if it is there
879  if (pdsDataFile.length() > 0) {
880  SetInputFile(pdsDataFile);
881  ProcessDataFilePointer(pdsXlater, true);
882  }
883  // If the data is in JPEG 2000 format, then use the name of the file
884  // from the label
885  else if (p_jp2File.length() > 0) {
886  SetInputFile(p_jp2File);
887  ProcessDataFilePointer(pdsXlater, true);
888  }
889  // Use the "^IMAGE or ^QUBE" label to get the filename for the image data
890  // Get the path portion from user entered label file spec
891  else {
892  // Handle filename and offset
893  ProcessDataFilePointer(pdsXlater, false);
894  }
895 
896  //------------------------------------------------------------
897  // Find the image data base and multiplier
898  //------------------------------------------------------------
899  str = pdsXlater.Translate("CoreBase");
900  SetBase(toDouble(str));
901  str = pdsXlater.Translate("CoreMultiplier");
902  SetMultiplier(toDouble(str));
903 
904  // Find the organization of the image data
905  str = pdsXlater.Translate("CoreOrganization");
906 
907  if (p_encodingType == JP2) {
908  SetOrganization(ProcessImport::JP2);
909  }
910  else if (str == "BSQ") {
911  SetOrganization(ProcessImport::BSQ);
912  }
913  else if (str == "BIP") {
914  SetOrganization(ProcessImport::BIP);
915  }
916  else if (str == "BIL") {
917  SetOrganization(ProcessImport::BIL);
918  }
919  else {
920  QString msg = "Unsupported axis order [" + str + "]";
921  throw IException(IException::Programmer, msg, _FILEINFO_);
922  }
923  }
924 
925 
937  void ProcessImportPds::ProcessPdsCombinedSpectrumLabel(const QString &pdsDataFile) {
938  Isis::FileName transFile(p_transDir + "/translations/pdsCombinedSpectrum.trn");
939  Isis::PvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
940 
941  QString str;
942 
943  str = pdsXlater.Translate("CoreLinePrefixBytes");
944  SetDataPrefixBytes(toInt(str));
945 
946  str = pdsXlater.Translate("CoreLineSuffixBytes");
947  SetDataSuffixBytes(toInt(str));
948 
949  ProcessPixelBitandType(pdsXlater);
950 
951  str = pdsXlater.Translate("CoreByteOrder");
952  SetByteOrder(Isis::ByteOrderEnumeration(str));
953 
954  str = pdsXlater.Translate("CoreSamples");
955  int ns = toInt(str);
956  str = pdsXlater.Translate("CoreLines");
957  int nl = toInt(str);
958  str = pdsXlater.Translate("CoreBands");
959  int nb = toInt(str);
960 
961  SetDimensions(ns, nl, nb);
962 
963  //-----------------------------------------------------------------
964  // Find the data filename it may be the same as the label file
965  // OR the label file may contain a pointer to the data
966  //-----------------------------------------------------------------
967 
968  // Use the name supplied by the application if it is there
969  if (pdsDataFile.length() > 0) {
970  SetInputFile(pdsDataFile);
971  ProcessDataFilePointer(pdsXlater, true);
972  }
973  // If the data is in JPEG 2000 format, then use the name of the file
974  // from the label
975  else if (p_jp2File.length() > 0) {
976  SetInputFile(p_jp2File);
977  ProcessDataFilePointer(pdsXlater, true);
978  }
979  // Use the "^IMAGE or ^QUBE" label to get the filename for the image data
980  // Get the path portion from user entered label file spec
981  else {
982  // Handle filename and offset
983  ProcessDataFilePointer(pdsXlater, false);
984  }
985 
986  //------------------------------------------------------------
987  // Find the image data base and multiplier
988  //------------------------------------------------------------
989  str = pdsXlater.Translate("CoreBase");
990  SetBase(toDouble(str));
991  str = pdsXlater.Translate("CoreMultiplier");
992  SetMultiplier(toDouble(str));
993 
994  // Find the organization of the image data
995  str = pdsXlater.Translate("CoreOrganization");
996 
997  if (p_encodingType == JP2) {
998  SetOrganization(ProcessImport::JP2);
999  }
1000  else if (str == "BSQ") {
1001  SetOrganization(ProcessImport::BSQ);
1002  }
1003  else if (str == "BIP") {
1004  SetOrganization(ProcessImport::BIP);
1005  }
1006  else if (str == "BIL") {
1007  SetOrganization(ProcessImport::BIL);
1008  }
1009  else {
1010  QString msg = "Unsupported axis order [" + str + "]";
1011  throw IException(IException::Programmer, msg, _FILEINFO_);
1012  }
1013  }
1014 
1015 
1027  void ProcessImportPds::TranslatePdsProjection(Isis::Pvl &lab) {
1028 
1029  // Create a temporary Isis::PvlTranslationManager so we can find out what
1030  // type of projection labels exist
1031  stringstream trnsStrm;
1032  trnsStrm << "Group = PdsProjectionTypeImage" << endl;
1033  trnsStrm << " InputPosition = IMAGE_MAP_PROJECTION" << endl;
1034  trnsStrm << " InputPosition = IMAGE_MAP_PROJECTION_CATALOG" << endl;
1035  trnsStrm << " InputKey = MAP_PROJECTION_TYPE" << endl;
1036  trnsStrm << "EndGroup" << endl;
1037  trnsStrm << "Group = PdsProjectionTypeQube" << endl;
1038  trnsStrm << " InputPosition = (QUBE,IMAGE_MAP_PROJECTION)" << endl;
1039  trnsStrm << " InputKey = MAP_PROJECTION_TYPE" << endl;
1040  trnsStrm << "EndGroup" << endl;
1041  trnsStrm << "Group = PdsProjectionTypeSpectralQube" << endl;
1042  trnsStrm << " InputPosition = (SPECTRAL_QUBE,IMAGE_MAP_PROJECTION)" << endl;
1043  trnsStrm << " InputKey = MAP_PROJECTION_TYPE" << endl;
1044  trnsStrm << "EndGroup" << endl;
1045  trnsStrm << "END";
1046 
1047  Isis::PvlTranslationManager projType(p_pdsLabel, trnsStrm);
1048 
1049  // Set up the correct projection translation table for this label
1050  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
1051  QString transDir = (QString) dataDir["Base"];
1052 
1053  Isis::FileName transFile;
1054  if (projType.InputHasKeyword("PdsProjectionTypeImage")) {
1055  transFile = transDir + "/" + "translations/pdsImageProjection.trn";
1056  }
1057  else if (projType.InputHasKeyword("PdsProjectionTypeQube")) {
1058  transFile = transDir + "/" + "translations/pdsQubeProjection.trn";
1059  }
1060  else if (projType.InputHasKeyword("PdsProjectionTypeSpectralQube")) {
1061  transFile = transDir + "/" + "translations/pdsSpectralQubeProjection.trn";
1062  }
1063  else {
1064  return;
1065  }
1066 
1067  Isis::PvlTranslationManager pdsXlater(p_pdsLabel, transFile.expanded());
1068 
1069  ExtractPdsProjection(pdsXlater);
1070 
1071  Isis::PvlGroup mapGroup("Mapping");
1072  mapGroup += Isis::PvlKeyword("ProjectionName", p_projection);
1073  mapGroup += Isis::PvlKeyword("TargetName", p_targetName);
1074  mapGroup += Isis::PvlKeyword("EquatorialRadius", toString(p_equatorialRadius), "meters");
1075  mapGroup += Isis::PvlKeyword("PolarRadius", toString(p_polarRadius), "meters");
1076  mapGroup += Isis::PvlKeyword("LongitudeDirection", p_longitudeDirection);
1077  mapGroup += Isis::PvlKeyword("LongitudeDomain", toString(p_longitudeDomain));
1078  mapGroup += Isis::PvlKeyword("LatitudeType", p_latitudeType);
1079  if (p_minimumLatitude != Isis::NULL8) {
1080  mapGroup += Isis::PvlKeyword("MinimumLatitude", toString(p_minimumLatitude));
1081  }
1082  if (p_maximumLatitude != Isis::NULL8) {
1083  mapGroup += Isis::PvlKeyword("MaximumLatitude", toString(p_maximumLatitude));
1084  }
1085  if (p_minimumLongitude != Isis::NULL8) {
1086  mapGroup += Isis::PvlKeyword("MinimumLongitude", toString(p_minimumLongitude));
1087  }
1088  if (p_maximumLongitude != Isis::NULL8) {
1089  mapGroup += Isis::PvlKeyword("MaximumLongitude", toString(p_maximumLongitude));
1090  }
1091 
1092  // if both longitudes exist, verify they are ordered correctly
1093  if (p_minimumLongitude != Isis::NULL8 && p_maximumLongitude != Isis::NULL8) {
1094  if (p_maximumLongitude <= p_minimumLongitude) {
1095  if (p_longitudeDomain == 180) {
1096  mapGroup["MinimumLongitude"] = toString(-180);
1097  mapGroup["MaximumLongitude"] = toString(180);
1098  }
1099  else {
1100  mapGroup["MinimumLongitude"] = toString(0);
1101  mapGroup["MaximumLongitude"] = toString(360);
1102  }
1103  }
1104  }
1105 
1106  mapGroup += Isis::PvlKeyword("PixelResolution", toString(p_pixelResolution), "meters/pixel");
1107  mapGroup += Isis::PvlKeyword("Scale", toString(p_scaleFactor), "pixels/degree");
1108  mapGroup += Isis::PvlKeyword("UpperLeftCornerX", toString(p_upperLeftX), "meters");
1109  mapGroup += Isis::PvlKeyword("UpperLeftCornerY", toString(p_upperLeftY), "meters");
1110  if (p_rotation != 0.0) {
1111  mapGroup += Isis::PvlKeyword("Rotation", toString(p_rotation));
1112  }
1113 
1114  // To handle new projections without the need to modify source code
1115  // we will construct a filename from the projection. The filename will
1116  // contain the projection specific translations from PDS to ISIS for each
1117  // projection
1118 
1119  QString projSpecificFileName = "$base/translations/pdsImport";
1120  projSpecificFileName += p_projection + ".trn";
1121  Isis::PvlTranslationManager specificXlater(p_pdsLabel, projSpecificFileName);
1122 
1123  lab.addGroup(mapGroup);
1124  specificXlater.Auto(lab);
1125 
1126  if (lab.findGroup("Mapping").hasKeyword("CenterLongitude")) {
1127  PvlKeyword &centerLon = lab.findGroup("Mapping")["CenterLongitude"];
1128  if (p_longitudeDomain == 180)
1129  centerLon = toString(TProjection::To180Domain((double)centerLon));
1130  else
1131  centerLon = toString(TProjection::To360Domain((double)centerLon));
1132  }
1133 
1134  if (lab.findGroup("Mapping").hasKeyword("PoleLongitude")) {
1135  PvlKeyword &poleLon = lab.findGroup("Mapping")["PoleLongitude"];
1136  if (p_longitudeDomain == 180)
1137  poleLon = toString(TProjection::To180Domain((double)poleLon));
1138  else
1139  poleLon = toString(TProjection::To360Domain((double)poleLon));
1140  }
1141 
1142  OutputCubes[0]->putGroup(lab.findGroup("Mapping"));
1143  }
1144 
1145 
1170  void ProcessImportPds::ExtractPdsProjection(Isis::PvlTranslationManager &pdsXlater) {
1171 
1172  QString str;
1173 
1174  if (pdsXlater.InputHasKeyword("ProjectionName")) {
1175  p_projection = pdsXlater.Translate("ProjectionName");
1176  }
1177  else {
1178  QString message = "No projection name in labels";
1179  throw IException(IException::Unknown, message, _FILEINFO_);
1180  }
1181 
1182  if (pdsXlater.InputHasKeyword("TargetName")) {
1183  p_targetName = pdsXlater.Translate("TargetName");
1184  }
1185  else {
1186  QString message = "No target name in labels";
1187  throw IException(IException::Unknown, message, _FILEINFO_);
1188  }
1189 
1190  if (pdsXlater.InputHasKeyword("EquatorialRadius")) {
1191  str = pdsXlater.Translate("EquatorialRadius");
1192  p_equatorialRadius = toDouble(str) * 1000.0;
1193  }
1194  else {
1195  QString message = "No equatorial radius name in labels";
1196  throw IException(IException::User, message, _FILEINFO_);
1197  }
1198 
1199  if (pdsXlater.InputHasKeyword("PolarRadius")) {
1200  str = pdsXlater.Translate("PolarRadius");
1201  p_polarRadius = toDouble(str) * 1000.0;
1202  }
1203  else {
1204  QString message = "No polar radius in labels";
1205  throw IException(IException::User, message, _FILEINFO_);
1206  }
1207 
1208  if (pdsXlater.InputHasKeyword("LongitudeDirection")) {
1209  p_longitudeDirection = pdsXlater.Translate("LongitudeDirection");
1210  }
1211  else {
1212  p_longitudeDirection = pdsXlater.Translate("LongitudeDirection2");
1213  }
1214 
1215  if (p_polarRadius == p_equatorialRadius) {
1216  p_latitudeType = "Planetocentric";
1217  }
1218  else if (pdsXlater.InputHasKeyword("LatitudeType2")) {
1219  p_latitudeType = pdsXlater.Translate("LatitudeType2");
1220  }
1221  else {
1222  p_latitudeType = pdsXlater.Translate("LatitudeType");
1223  }
1224 
1225  if (pdsXlater.InputHasKeyword("MinimumLatitude")) {
1226  str = pdsXlater.Translate("MinimumLatitude");
1227  try {
1228  p_minimumLatitude = toDouble(str);
1229  }
1230  catch(IException &e) {
1231  p_minimumLatitude = Isis::NULL8;
1232  }
1233  }
1234  else {
1235  p_minimumLatitude = Isis::NULL8;
1236  }
1237 
1238  if (pdsXlater.InputHasKeyword("MaximumLatitude")) {
1239  str = pdsXlater.Translate("MaximumLatitude");
1240  try {
1241  p_maximumLatitude = toDouble(str);
1242  }
1243  catch(IException &e) {
1244  p_maximumLatitude = Isis::NULL8;
1245  }
1246  }
1247  else {
1248  p_maximumLatitude = Isis::NULL8;
1249  }
1250 
1251  // This variable represents if the longitudes were read in as
1252  // positive west
1253  bool positiveWest = false;
1254  if (pdsXlater.InputHasKeyword("MinimumLongitude")) {
1255  str = pdsXlater.Translate("MinimumLongitude");
1256  try {
1257  positiveWest = true;
1258  p_minimumLongitude = toDouble(str);
1259  }
1260  catch(IException &e) {
1261  p_minimumLongitude = Isis::NULL8;
1262  }
1263  }
1264  else if (pdsXlater.InputHasKeyword("MinimumLongitude2")) {
1265  str = pdsXlater.Translate("MinimumLongitude2");
1266  try {
1267  p_minimumLongitude = toDouble(str);
1268  }
1269  catch(IException &e) {
1270  p_minimumLongitude = Isis::NULL8;
1271  }
1272  }
1273  else {
1274  p_minimumLongitude = Isis::NULL8;
1275  }
1276 
1277  if (pdsXlater.InputHasKeyword("MaximumLongitude")) {
1278  str = pdsXlater.Translate("MaximumLongitude");
1279  try {
1280  positiveWest = true;
1281  p_maximumLongitude = toDouble(str);
1282  }
1283  catch(IException &e) {
1284  p_maximumLongitude = Isis::NULL8;
1285  }
1286  }
1287  else if (pdsXlater.InputHasKeyword("MaximumLongitude2")) {
1288  str = pdsXlater.Translate("MaximumLongitude2");
1289  try {
1290  p_maximumLongitude = toDouble(str);
1291  }
1292  catch(IException &e) {
1293  p_maximumLongitude = Isis::NULL8;
1294  }
1295  }
1296  else {
1297  p_maximumLongitude = Isis::NULL8;
1298  }
1299 
1300  str = pdsXlater.Translate("LongitudeDomain");
1301  p_longitudeDomain = toInt(str);
1302 
1321  if (positiveWest && (p_longitudeDirection.compare("PositiveEast") == 0)) {
1322  double tmp = p_minimumLongitude;
1323  p_minimumLongitude = p_maximumLongitude;
1324  p_maximumLongitude = tmp;
1325  }
1326 
1327  if (p_minimumLongitude > p_maximumLongitude) {
1328  // Force the change to 180
1329  p_longitudeDomain = 180;
1330  p_minimumLongitude = Isis::TProjection::To180Domain(p_minimumLongitude);
1331  }
1332 
1333  // If either the minimumLongitude or maximumLongitude are < 0, change
1334  // longitude Domain to 180.
1335  if (p_minimumLongitude < 0 || p_maximumLongitude < 0) {
1336  p_longitudeDomain = 180;
1337  }
1338 
1339  str = pdsXlater.Translate("PixelResolution");
1340  p_pixelResolution = toDouble(str);
1341  str = pdsXlater.InputKeyword("PixelResolution").unit().toUpper();
1342  // Assume KM/PIXEL if the unit doesn't exist or is not METERS/PIXEL
1343  if ((str != "METERS/PIXEL") && (str != "M/PIXEL") && (str != "M/PIX")) {
1344  p_pixelResolution *= 1000.0;
1345  }
1346 
1347  str = pdsXlater.Translate("Scale");
1348  p_scaleFactor = toDouble(str);
1349 
1350  try {
1351  str = pdsXlater.Translate("Rotation");
1352  p_rotation = toDouble(str);
1353  }
1354  catch(IException &) {
1355  // assume no rotation if the value isn't a number
1356  p_rotation = 0.0;
1357  }
1358 
1359  // Look for projection offsets/mults to convert between line/samp and x/y
1360  double xoff, yoff, xmult, ymult;
1361  GetProjectionOffsetMults(xoff, yoff, xmult, ymult);
1362 
1363  if (pdsXlater.InputHasKeyword("LineProjectionOffset")) {
1364  str = pdsXlater.Translate("LineProjectionOffset");
1365  }
1366  else {
1367  str = pdsXlater.Translate("LineProjectionOffset2");
1368  }
1369  p_lineProjectionOffset = toDouble(str);
1370  p_upperLeftY = ymult * (p_lineProjectionOffset + yoff) * p_pixelResolution;
1371 
1372  if (pdsXlater.InputHasKeyword("SampleProjectionOffset")) {
1373  str = pdsXlater.Translate("SampleProjectionOffset");
1374  }
1375  else {
1376  str = pdsXlater.Translate("SampleProjectionOffset2");
1377  }
1378  p_sampleProjectionOffset = toDouble(str);
1379  p_upperLeftX = xmult * (p_sampleProjectionOffset + xoff) * p_pixelResolution;
1380 
1381 
1382  }
1383 
1384 
1388  void ProcessImportPds::EndProcess() {
1389  ProcessImportPds::Finalize();
1390  }
1391 
1392 
1398  void ProcessImportPds::Finalize() {
1399  if (p_keepOriginalLabel) {
1400  OriginalLabel ol(p_pdsLabel);
1401  for (unsigned int i = 0; i < OutputCubes.size(); i++) {
1402  OutputCubes[i]->write(ol);
1403  }
1404  }
1405  Process::Finalize();
1406  }
1407 
1408 
1413  void ProcessImportPds::OmitOriginalLabel() {
1414  p_keepOriginalLabel = false;
1415  }
1416 
1417 
1424  void ProcessImportPds::IdentifySource(Isis::Pvl &inputLabel) {
1425 
1426  // Create a temporary Isis::PvlTranslationManager so we can find out what
1427  // type of input file we have
1428  stringstream trnsStrm;
1429  trnsStrm << "Group = PdsFile" << endl;
1430  trnsStrm << " InputPosition = ROOT" << endl;
1431  trnsStrm << " InputKey = PDS_VERSION_ID" << endl;
1432  trnsStrm << "EndGroup" << endl;
1433  trnsStrm << "Group = Isis2File" << endl;
1434  trnsStrm << " InputPosition = ROOT" << endl;
1435  trnsStrm << " InputKey = CCSD3ZF0000100000001NJPL3IF0PDS200000001" << endl;
1436  trnsStrm << "EndGroup" << endl;
1437  trnsStrm << "END";
1438 
1439  Isis::PvlTranslationManager sourceXlater(inputLabel, trnsStrm);
1440 
1441  if (sourceXlater.InputHasKeyword("PdsFile")) {
1442  p_source = PDS;
1443  }
1444  else if (sourceXlater.InputHasKeyword("Isis2File")) {
1445  p_source = ISIS2;
1446  }
1447  else {
1448  p_source = NOSOURCE;
1449  }
1450 
1451  }
1452 
1453 
1462  bool ProcessImportPds::IsIsis2() {
1463 
1464  if (p_source == ISIS2) {
1465 
1466  return true;
1467  }
1468  else {
1469  return false;
1470  }
1471 
1472 
1473  }
1474 
1475 
1483  void ProcessImportPds::TranslateIsis2Labels(Isis::Pvl &lab) {
1484  TranslateIsis2BandBin(lab);
1485  TranslateIsis2Instrument(lab);
1486  }
1487 
1488 
1496  void ProcessImportPds::TranslatePdsLabels(Isis::Pvl &lab) {
1497  TranslatePdsBandBin(lab);
1498  TranslatePdsArchive(lab);
1499  }
1500 
1501 
1508  void ProcessImportPds::TranslateIsis2BandBin(Isis::Pvl &lab) {
1509  // Set up a translater for Isis2 labels
1510  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
1511  QString transDir = (QString) dataDir["Base"];
1512 
1513  Isis::FileName transFile(transDir + "/" + "translations/isis2bandbin.trn");
1514  Isis::PvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1515 
1516  // Add all the Isis2 keywords that can be translated to the requested label
1517  isis2Xlater.Auto(lab);
1518  }
1519 
1520 
1527  void ProcessImportPds::TranslateIsis2Instrument(Isis::Pvl &lab) {
1528  // Set up a translater for Isis2 labels
1529  Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory");
1530  QString transDir = (QString) dataDir["Base"];
1531  Isis::FileName transFile(transDir + "/" + "translations/isis2instrument.trn");
1532  Isis::PvlTranslationManager 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  //Check StartTime for appended 'z' (Zulu time) and remove
1538  Isis::PvlGroup &inst = lab.findGroup("Instrument");
1539 
1540  if (inst.hasKeyword("StartTime")) {
1541  Isis::PvlKeyword &stkey = inst["StartTime"];
1542  QString stime = stkey[0];
1543  stime = stime.remove(QRegExp("[Zz]$"));
1544  stkey = stime;
1545  }
1546  }
1547 
1548 
1555  void ProcessImportPds::TranslatePdsBandBin(Isis::Pvl &lab) {
1556  // Set up a translater for PDS labels
1557  Isis::FileName transFile(p_transDir + "/" + "translations/pdsImageBandBin.trn");
1558  Isis::PvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1559 
1560  // Add all the Isis2 keywords that can be translated to the requested label
1561  isis2Xlater.Auto(lab);
1562  }
1563 
1564 
1571  void ProcessImportPds::TranslatePdsArchive(Isis::Pvl &lab) {
1572  // Set up a translater for PDS labels
1573  Isis::FileName transFile(p_transDir + "/" + "translations/pdsImageArchive.trn");
1574  Isis::PvlTranslationManager isis2Xlater(p_pdsLabel, transFile.expanded());
1575 
1576  // Add all the Isis2 keywords that can be translated to the requested label
1577  isis2Xlater.Auto(lab);
1578  }
1579 
1580 
1593  void ProcessImportPds::GetProjectionOffsetMults(double &xoff, double &yoff,
1594  double &xmult, double &ymult) {
1595 
1596  xmult = -1.0;
1597  ymult = 1.0;
1598  xoff = -0.5;
1599  yoff = -0.5;
1600 
1601  // Open projectionOffsetMults file
1602  Isis::Pvl p(p_transDir + "/" + "translations/pdsProjectionLineSampToXY.def");
1603 
1604  Isis::PvlObject &projDef = p.findObject("ProjectionOffsetMults",
1605  Pvl::Traverse);
1606 
1607  for(int g = 0; g < projDef.groups(); g++) {
1608  QString key = projDef.group(g)["Keyword"];
1609  if (p_pdsLabel.hasKeyword(key)) {
1610  QString value = p_pdsLabel[key];
1611  QString pattern = projDef.group(g)["Pattern"];
1612  // If value contains pattern, then set the mults to what is in translation file
1613  if (value.contains(pattern)) {
1614  xmult = projDef.group(g)["xMult"];
1615  ymult = projDef.group(g)["yMult"];
1616  xoff = projDef.group(g)["xOff"];
1617  yoff = projDef.group(g)["yOff"];
1618  return;
1619  }
1620  }
1621  }
1622  }
1623 
1624 
1632  Table &ProcessImportPds::ImportTable(QString pdsTableName) {
1633  // No table file given, let ImportPdsTable find it.
1634  ImportPdsTable pdsTable(p_labelFile, "", pdsTableName);
1635  // reformat the table name. If the name ends with the word "Table", remove
1636  // it. (So, for example, INSTRUMENT_POINTING_TABLE gets formatted to
1637  // InstrumentPointingTable and then to InstrumentPointing)
1638  QString isisTableName = pdsTable.getFormattedName(pdsTableName);
1639  int found = isisTableName.lastIndexOf("Table");
1640  if (found == isisTableName.length() - 5) {
1641  isisTableName.remove(found, 5);
1642  }
1643 
1644  Table isisTable = pdsTable.importTable(isisTableName);
1645  p_tables.push_back(isisTable);
1646 
1647  return p_tables.at(p_tables.size() - 1);
1648  }
1649 
1650 
1654  void ProcessImportPds::StartProcess() {
1655  ProcessImport::StartProcess();
1656  for (unsigned int i = 0; i < p_tables.size(); i++) {
1657  OutputCubes[0]->write(p_tables[i]);
1658  }
1659  return;
1660  }
1661 
1662 
1673  void ProcessImportPds::StartProcess(void funct(Isis::Buffer &out)) {
1674  ProcessImport::StartProcess(funct);
1675  return;
1676  }
1677 }
1678 
1679 
Buffer for reading and writing cube data.
Definition: Buffer.h:68
Read and store original labels.
Definition: OriginalLabel.h:51
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:141
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:111
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
QString getFormattedName(const QString &colname) const
Converts a column name to a camel-case after it has been cleansed.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
bool InputHasKeyword(const QString nName)
Indicates if the input keyword corresponding to the output name exists in the label.
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:119
Allows applications to translate simple text files.
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
const PvlKeyword & InputKeyword(const QString nName) const
Returns the ith input value assiciated with the output name argument.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
A single keyword-value pair.
Definition: PvlKeyword.h:98
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
This represents a cube in a project-based GUI interface.
Definition: Image.h:91
QString Translate(QString nName, int findex=0)
Returns a translated value.
Container for cube-like labels.
Definition: Pvl.h:135
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
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:74
Isis exception class.
Definition: IException.h:99
Adds specific functionality to C++ strings.
Definition: IString.h:179
const double Lrs
Value for an Isis Low Representation Saturation pixel.
Definition: SpecialPixel.h:113
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
QString path() const
Returns the path.
Definition: FileName.cpp:88
Import a PDS table file with a label description.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
const double His
Value for an Isis High Instrument Saturation pixel.
Definition: SpecialPixel.h:125
const double Hrs
Value for an Isis High Representation Saturation pixel.
Definition: SpecialPixel.h:131

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:26:27