Commit 778a019c authored by Makayla Shepherd's avatar Makayla Shepherd
Browse files

Non-numeric characters will be skipped over instead of causing ascii2isis to...

Non-numeric characters will be skipped over instead of causing ascii2isis to hang. When the input file is not large enough to fill the specified size of the output cube, ascii2isis will display an error message. Fixes #2066.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6272 41f8697f-d340-4b68-9986-7bafba869bb8
parent 9c53bcb8
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ double TestSpecial(const double pixel);
void ascii2isis(Buffer &out);
ifstream fin;
QString order;
QString from;
//Initialize values to make special pixels invalid
double null_min = DBL_MAX;
double null_max = DBL_MIN;
@@ -24,10 +25,15 @@ double lrs_min = DBL_MAX;
double lrs_max = DBL_MIN;

void IsisMain() {
  //initialize fin
  if (fin.is_open()) {
    fin.close();
  }

  //  Open input text file
  UserInterface &ui = Application::GetUserInterface();
  QString from = ui.GetFileName("FROM");
  from = ui.GetFileName("FROM");
  
  // Get storage order of data
  order = ui.GetString("ORDER");

@@ -45,6 +51,7 @@ void IsisMain() {
    null_min = ui.GetDouble("NULLMIN");
    null_max = ui.GetDouble("NULLMAX");
  }
  
  if (ui.GetBoolean("SETHRSRANGE")) {
    hrs_min = ui.GetDouble("HRSMIN");
    hrs_max = ui.GetDouble("HRSMAX");
@@ -54,19 +61,23 @@ void IsisMain() {
    lrs_max = ui.GetDouble("LRSMAX");
  }

  
  fin.open(from.toAscii().data(), std::ios::in);
  if (!fin.is_open()) {
    QString msg = "Cannot open input file [" + from + "]";
    throw IException(IException::Io, msg, _FILEINFO_);
  }

  
  //  Skip header information if it exists
  fin.seekg(skip, std::ios::beg);

  
  //  Set up process depending on order
  if (order == "BSQ") {
    ProcessByLine p;

    
    p.SetOutputCube(ui.GetFileName("TO"), att, ns, nl, nb);
    p.StartProcess(ascii2isis);
    p.EndProcess();
@@ -74,6 +85,7 @@ void IsisMain() {
  if (order == "BIL") {
    ProcessBySpectra p(Isis::ProcessBySpectra::ByLine);

    
    // Set Special Pixel ranges
    p.SetOutputCube(ui.GetFileName("TO"), att, ns, nl, nb);
    p.StartProcess(ascii2isis);
@@ -82,6 +94,7 @@ void IsisMain() {
  if (order == "BIP") {
    ProcessBySpectra p(Isis::ProcessBySpectra::PerPixel);

    
    p.SetOutputCube(ui.GetFileName("TO"), att, ns, nl, nb);
    p.StartProcess(ascii2isis);
    p.EndProcess();
@@ -93,13 +106,22 @@ void IsisMain() {
void ascii2isis(Buffer &out) {
  //Define all legal characters for the beginning of a number
  const string legal = ".0123456789+-";

    
  for (int i = 0; i < out.size(); i++) {
    fin >> out[i];
    out[i] = TestSpecial(out[i]);
    
    //Discard all nonlegal characters
    while ((legal.find(fin.peek()) == string::npos) && !fin.eof()) {
      fin.ignore();
    }  
    
    fin >> out[i];
    if (!fin && fin.eof()) {
      QString msg = "End of file reached. There is not enough data in [" + from;
      msg += "] to fill the output cube.";
      throw IException(IException::User, msg, _FILEINFO_);
    }
    out[i] = TestSpecial(out[i]);
  }
}

+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@
    <change name="Steven Koechle" date="2008-08-30">
        Added ability to change special pixel ranges. Added example.
    </change>
    <change name="Makayla Shepherd" data="2015-07-15">
        Fixed a problem with non-numeric cahracters in the file which resulted ascii2isis
        hanging. Fixes #2066.
    </change>
  </history>