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
Changes from 1 commit
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
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 ',' delimieter, if that only produces one row
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delimieter -> delimiter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs changelog entry

// 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