Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes CSV parsing in shadowtau #5316

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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