Skip to content

Commit

Permalink
Fixes CSV parsing in shadowtau (#5316)
Browse files Browse the repository at this point in the history
* Fixes CSV parsing in shadowtau

* Addressed PR feedback
  • Loading branch information
acpaquette authored Nov 7, 2023
1 parent e381aff commit c2197f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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

Expand Down
48 changes: 38 additions & 10 deletions isis/src/base/apps/shadowtau/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ',' delimiter, 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<double> 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) ||
Expand Down

0 comments on commit c2197f7

Please sign in to comment.