Unverified Commit c2197f77 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Fixes CSV parsing in shadowtau (#5316)

* Fixes CSV parsing in shadowtau

* Addressed PR feedback
parent e381affa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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

+38 −10
Original line number Diff line number Diff line
@@ -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) ||