From 3d40d684a4926418b21d2f1c2dc765ffe0078e2b Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Tue, 30 Jul 2024 13:37:54 -0600 Subject: [PATCH 1/3] Modified to work with new (detached) data --- .../apps/kaguyasp2ascii/kaguyasp2ascii.xml | 4 +-- isis/src/kaguya/apps/kaguyasp2ascii/main.cpp | 34 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/isis/src/kaguya/apps/kaguyasp2ascii/kaguyasp2ascii.xml b/isis/src/kaguya/apps/kaguyasp2ascii/kaguyasp2ascii.xml index 52cb9fe6cd..a33636c6cd 100644 --- a/isis/src/kaguya/apps/kaguyasp2ascii/kaguyasp2ascii.xml +++ b/isis/src/kaguya/apps/kaguyasp2ascii/kaguyasp2ascii.xml @@ -80,10 +80,10 @@ Input Kaguya SP file - This is the input Kaguya SP file + This is the input Kaguya SP file. For an attached label, use the .spc file, or for a detached label, use the .lbl file. - *.spc + *.lbl *.spc diff --git a/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp b/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp index 7fa27fab97..a414fce14b 100644 --- a/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp +++ b/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp @@ -25,8 +25,17 @@ void IsisMain() { ProcessImportPds p; UserInterface &ui = Application::GetUserInterface(); - FileName inFile = ui.GetFileName("FROM"); - Pvl lab(inFile.expanded()); + QString inFile = ui.GetFileName("FROM"); + Pvl lab(inFile); + QString dataFile = lab.findKeyword("FILE_NAME")[0]; + + // Detached labels use format keyword = "dataFile" value + int keywordIndex = 1; + + if (inFile == dataFile){ + // Attached labels use format keyword = value + keywordIndex = 0; + } ofstream os; QString outFile = FileName(ui.GetFileName("TO")).expanded(); @@ -59,32 +68,32 @@ void IsisMain() { int qaptr = 0; if (lab.hasKeyword("^SP_SPECTRUM_WAV")) { - wavptr = toInt(lab.findKeyword("^SP_SPECTRUM_WAV")[0]) - 1; + wavptr = toInt(lab.findKeyword("^SP_SPECTRUM_WAV")[keywordIndex]) - 1; } if (lab.hasKeyword("^SP_SPECTRUM_RAW")) { - rawptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAW")[0]) - 1; + rawptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAW")[keywordIndex]) - 1; } if (lab.hasKeyword("^SP_SPECTRUM_RAD")) { - radptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAD")[0]) - 1; + radptr = toInt(lab.findKeyword("^SP_SPECTRUM_RAD")[keywordIndex]) - 1; } //older-format file without calibrated NIR2 data if (lab.hasKeyword("^SP_SPECTRUM_REF")) { - refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF")[0]) - 1; + refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF")[keywordIndex]) - 1; } //newer-format file with calibrated NIR2 data and 2 different Reflectances if (lab.hasKeyword("^SP_SPECTRUM_REF1")) { - refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF1")[0]) - 1; + refptr1 = toInt(lab.findKeyword("^SP_SPECTRUM_REF1")[keywordIndex]) - 1; } if (lab.hasKeyword("^SP_SPECTRUM_REF2")) { - refptr2 = toInt(lab.findKeyword("^SP_SPECTRUM_REF2")[0]) - 1; + refptr2 = toInt(lab.findKeyword("^SP_SPECTRUM_REF2")[keywordIndex]) - 1; } if (lab.hasKeyword("^SP_SPECTRUM_QA")) { - qaptr = toInt(lab.findKeyword("^SP_SPECTRUM_QA")[0]) - 1; + qaptr = toInt(lab.findKeyword("^SP_SPECTRUM_QA")[keywordIndex]) - 1; } FILE *spcptr; - if ((spcptr = fopen(inFile.expanded().toLatin1().data(),"rb")) == 0) { - QString msg = "Error opening input Kaguya SP file [" + inFile.expanded() + "]"; + if ((spcptr = fopen(dataFile.toLatin1().data(),"rb")) == 0) { + QString msg = "Error opening input Kaguya SP file [" + dataFile + "]"; throw IException(IException::User, msg, _FILEINFO_); } @@ -101,7 +110,7 @@ void IsisMain() { if (!lab.hasObject("SP_SPECTRUM_WAV") || !lab.hasObject("SP_SPECTRUM_QA") || !lab.hasObject("SP_SPECTRUM_RAD") || !(lab.hasObject("SP_SPECTRUM_REF") || (lab.hasObject("SP_SPECTRUM_REF1") && lab.hasObject("SP_SPECTRUM_REF2")))) { - QString msg = "Input file [" + inFile.expanded() + "] is not a valid "; + QString msg = "Input file [" + inFile + "] is not a valid "; msg += "Kaguya Spectral Profiler file"; throw IException(IException::User, msg, _FILEINFO_); } @@ -261,6 +270,7 @@ void IsisMain() { PvlObject refobj; PvlObject refobj2; + if (lab.hasKeyword("^SP_SPECTRUM_REF")) { refobj = lab.findObject("SP_SPECTRUM_REF"); } From 8b49c8b5f43c0d667a77331cf967a6b3d1eaa37d Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Tue, 30 Jul 2024 13:46:02 -0600 Subject: [PATCH 2/3] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5835647caf..41b9e1063d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ release. ## [Unreleased] ### Changed +- Modified kaguyasp2isis to work with new (detached) data [#5436](https://github.com/DOI-USGS/ISIS3/issues/5436) - Added jigsaw error message for csminit'd images without csm parameters[#5486](https://github.com/DOI-USGS/ISIS3/issues/5486) - Changed `qwt` dependency version to 6.2.0 or below [#5498](https://github.com/DOI-USGS/ISIS3/issues/5498) - Pinned `suitesparse` dependency version to maximum not including 7.7.0 [#5496](https://github.com/DOI-USGS/ISIS3/issues/5496) From 79d9a5b8e6c4ae1c1fd90264ba15455022811941 Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Tue, 30 Jul 2024 16:52:34 -0600 Subject: [PATCH 3/3] Allow data specification outside current directory --- isis/src/kaguya/apps/kaguyasp2ascii/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp b/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp index a414fce14b..ac42ba6e28 100644 --- a/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp +++ b/isis/src/kaguya/apps/kaguyasp2ascii/main.cpp @@ -32,7 +32,10 @@ void IsisMain() { // Detached labels use format keyword = "dataFile" value int keywordIndex = 1; - if (inFile == dataFile){ + if (FileName(inFile).baseName() == FileName(dataFile).baseName()){ + // data files usually do not include path information. If input basename matches datafile basename, include path information + // this allows users to specify data that is not in the current directory. + dataFile = inFile; // Attached labels use format keyword = value keywordIndex = 0; }