From 588f3f13e8450b79d46df63713fca95e495c47f8 Mon Sep 17 00:00:00 2001 From: acpaquette Date: Tue, 24 Oct 2023 15:12:22 -0700 Subject: [PATCH 1/2] Fixes CSV parsing in shadowtau --- isis/src/base/apps/shadowtau/main.cpp | 48 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/isis/src/base/apps/shadowtau/main.cpp b/isis/src/base/apps/shadowtau/main.cpp index 1d1d4383ca..0d281d3252 100644 --- a/isis/src/base/apps/shadowtau/main.cpp +++ b/isis/src/base/apps/shadowtau/main.cpp @@ -250,17 +250,45 @@ void IsisMain() { // rejected if there aren't enough words or if any of them don't make // sense as the corresponding parameter. FileName sInFileName(sInFile); - TextFile infile(sInFileName.expanded()); + // Try with the default ',' delimieter, if that only produces one row + // item, try with spaces + CSVReader inFile(sInFileName.expanded()); + if (inFile.getRow(0).dim() <= 1) { + inFile = CSVReader(sInFileName.expanded(), false, 0, ' '); + } + + if (inFile.getRow(0).dim() <= 1) { + QString msg = "File [" + sInFileName.expanded() + "] either has only one line item or is not delimited by a ',' or ' '."; + throw IException(IException::User, msg, _FILEINFO_); + } + QString infileString; - while (infile.GetLine(infileString)) { - QStringList tokens = infileString.split(QRegExp("[ ,]")); - - QString imgId = tokens.takeFirst(); - double inc = toDouble(tokens.takeFirst()); - double ema = toDouble(tokens.takeFirst()); - double phase = toDouble(tokens.takeFirst()); - double pflat = toDouble(tokens.takeFirst()); - double pshad = toDouble(tokens.takeFirst()); + for (int i = 0; i < inFile.rows(); i++) { + CSVReader::CSVAxis row = inFile.getRow(i); + + if (row.dim1() < 6) { + continue; + } + + QString imgId = row[0]; + std::vector angles = {}; + for (int j = 1; j < row.dim(); j++) { + try { + angles.push_back(toDouble(row[j])); + } + catch (IException &e) { + QString msg = "Unable to convert (" + toString(i) + ", " + toString(j) + + ") element [" + row[j] + "] to double. You may want to check for excess delimiters." + + "Current delimiter is set to '" + inFile.getDelimiter() + "'"; + throw IException(IException::User, msg, _FILEINFO_); + } + } + + double inc = angles[0]; + double ema = angles[1]; + double phase = angles[2]; + double pflat = angles[3]; + double pshad = angles[4]; // checking validity if (!imgId.length() || (inc < 0 || inc >= 89.9) || (ema < 0 || ema >= 89.9) || From 48150c99aa92bbecffd12853d8ead798b074cce7 Mon Sep 17 00:00:00 2001 From: acpaquette Date: Wed, 25 Oct 2023 13:12:52 -0700 Subject: [PATCH 2/2] Addressed PR feedback --- CHANGELOG.md | 1 + isis/src/base/apps/shadowtau/main.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e1993e125..264e742335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ release. - Fixed `campt` to handle input band selection attribute correctly [#5234](https://github.com/DOI-USGS/ISIS3/issues/5235) - Fixed target name translation for any dawn images with target "4 CERES" [#5294](https://github.com/DOI-USGS/ISIS3/pull/5294) - Fixed exception pop ups in qview when viewing images created using the CSM Camera [#5259](https://github.com/DOI-USGS/ISIS3/pull/5295/files) +- Fixed shadowtau input file parseing errors when using example file [#5316](https://github.com/DOI-USGS/ISIS3/pull/5316) ## [8.0.0] - 2023-04-19 diff --git a/isis/src/base/apps/shadowtau/main.cpp b/isis/src/base/apps/shadowtau/main.cpp index 0d281d3252..f712cd1bc4 100644 --- a/isis/src/base/apps/shadowtau/main.cpp +++ b/isis/src/base/apps/shadowtau/main.cpp @@ -250,7 +250,7 @@ void IsisMain() { // rejected if there aren't enough words or if any of them don't make // sense as the corresponding parameter. FileName sInFileName(sInFile); - // Try with the default ',' delimieter, if that only produces one row + // Try with the default ',' delimiter, if that only produces one row // item, try with spaces CSVReader inFile(sInFileName.expanded()); if (inFile.getRow(0).dim() <= 1) {