Unverified Commit f005a9b6 authored by tgiroux's avatar tgiroux Committed by GitHub
Browse files

Getsn tests (#3790)



* Replaced old getsn tests with gtests

* removed an old Makefile

* getsn? for like get working am I right? (now featuring less spiceinit)

Co-authored-by: default avatarKelvin <kelvinrr@icloud.com>
parent 8b605fcb
Loading
Loading
Loading
Loading
+94 −0
Original line number Diff line number Diff line
#include "getsn.h"

#include <iostream>
#include <sstream>
#include <QString>

#include "Blob.h"
#include "Cube.h"
#include "History.h"
#include "ObservationNumber.h"
#include "Preference.h"
#include "Pvl.h"
#include "SerialNumber.h"
#include "SessionLog.h"
#include "TextFile.h"

using namespace Isis;
using namespace std;


namespace Isis {

  void getsn( UserInterface &ui, Pvl *log ) {
    // Open the input cube
    Cube *cube = new Cube( ui.GetFileName("FROM"), "r");
    
    getsn( cube, ui, log );

  }


  void getsn( Cube *cube, UserInterface &ui, Pvl *log ) {

    // Determine if output should be written base on parameters
    bool WriteFile = ui.GetBoolean("FILE");
    bool WriteSN = ui.GetBoolean("SN");
    bool WriteObservation = ui.GetBoolean("OBSERVATION");
    
    QString from = cube->fileName();    
    QString format = ui.GetString("FORMAT");
    bool pvl;
    if (format == "PVL") {
      pvl = true;
    }
    else {
      pvl = false;
    }

    // Extract label from cube file
    Pvl *label = cube->label();

    PvlGroup sn("Results");

    if (WriteFile) sn += PvlKeyword("Filename", from);
    if (WriteSN) sn += PvlKeyword( "SerialNumber", SerialNumber::Compose( *label, ui.GetBoolean("DEFAULT") ) );
    if (WriteObservation) sn += PvlKeyword( "ObservationNumber", ObservationNumber::Compose( *label, ui.GetBoolean("DEFAULT") ) );

    if ( ui.WasEntered("TO") ) {
      // PVL option
      if (pvl) {
	// Create a serial number and observation number for this cube & put it in a pvlgroup for output
	Pvl pvl;
	pvl.addGroup(sn);
	if ( ui.GetBoolean("APPEND") )
	  pvl.append( ui.GetFileName("TO") );
	else
	  pvl.write( ui.GetFileName("TO") );
      }
      // FLAT option
      else {
	bool append = ui.GetBoolean("APPEND");
	// Open in append or overwrite
	TextFile txt(ui.GetFileName("TO"), append ? "append" : "overwrite");

	// Build QString
	QString line = "";
	for (int i = 0; i < sn.keywords(); i++) {
	  if (i != 0)
	    line += ",";
	  line += sn[i][0];
	}
	txt.PutLine(line);
      }
            
    }
    else {
      for (int i = 0; i < sn.keywords(); i++) {
	cout << sn[i][0] << endl;
      }
    }

    log->addGroup(sn);    
  }
}
+13 −0
Original line number Diff line number Diff line
#ifndef getsn_h
#define getsn_h

#include "UserInterface.h"
#include "Pvl.h"
#include "Cube.h"

namespace Isis {
  extern void getsn( Cube *cube, UserInterface &ui, Pvl *log ); 
  extern void getsn( UserInterface &ui, Pvl *log );
}

#endif
+14 −67
Original line number Diff line number Diff line
#include "Isis.h"

#include <iostream>
#include <sstream>
#include <QString>
#include "getsn.h"
#include "PvlGroup.h"
#include "Pvl.h"

#include "Blob.h"
#include "Cube.h"
#include "History.h"
#include "ObservationNumber.h"
#include "Preference.h"
#include "Pvl.h"

#include "SerialNumber.h"
#include "SessionLog.h"
#include "TextFile.h"


using namespace Isis;
using namespace std;

void IsisMain() {

  // Set Preferences to always turn off Terminal Output
  PvlGroup &grp = Isis::Preference::Preferences().findGroup("SessionLog", Isis::Pvl::Traverse);
  grp["TerminalOutput"].setValue("Off");

  // Open the input cube
  UserInterface &ui = Application::GetUserInterface();
  Cube cube;
  QString from = ui.GetFileName("FROM");
  cube.open(from, "r");

  // Determine if output should be written base on parameters
  bool WriteFile = ui.GetBoolean("FILE");
  bool WriteSN = ui.GetBoolean("SN");
  bool WriteObservation = ui.GetBoolean("OBSERVATION");

  QString format = ui.GetString("FORMAT");
  bool pvl;
  if (format == "PVL") {
    pvl = true;
  }
  else {
    pvl = false;
  }

  // Extract label from cube file
  Pvl *label = cube.label();
  Pvl appLog;

  PvlGroup sn("Results");
  getsn(ui, &appLog);

  if (WriteFile) sn += PvlKeyword("Filename", from);
  if (WriteSN) sn += PvlKeyword( "SerialNumber", SerialNumber::Compose( *label, ui.GetBoolean("DEFAULT") ) );
  if (WriteObservation) sn += PvlKeyword( "ObservationNumber", ObservationNumber::Compose( *label, ui.GetBoolean("DEFAULT") ) );
  PvlGroup results = appLog.findGroup("Results");

  if ( ui.WasEntered("TO") ) {
    // PVL option
    if (pvl) {
      // Create a serial number and observation number for this cube & put it in a pvlgroup for output
      Pvl pvl;
      pvl.addGroup(sn);
      if ( ui.GetBoolean("APPEND") )
        pvl.append( ui.GetFileName("TO") );
      else
        pvl.write( ui.GetFileName("TO") );
  if( ui.WasEntered("TO") && ui.IsInteractive() ) {
    Application::GuiLog(results);
  }
    // FLAT option
    else {
      bool append = ui.GetBoolean("APPEND");
      // Open in append or overwrite
      TextFile txt(ui.GetFileName("TO"), append ? "append" : "overwrite");

      // Build QString
      QString line = "";
      for (int i = 0; i < sn.keywords(); i++) {
        if (i != 0)
          line += ",";
        line += sn[i][0];
      }
      txt.PutLine(line);
    }
  SessionLog::TheLog().AddResults(results);
  
    // Construct a label with the results
    if ( ui.IsInteractive() ) {
      Application::GuiLog(sn);
    }
  }
  else {
    for (int i = 0; i < sn.keywords(); i++) {
      cout << sn[i][0] << endl;
    }
  }
  // Write the results to the log but not the terminal
  SessionLog::TheLog().AddResults(sn);
}
+0 −13
Original line number Diff line number Diff line
APPNAME = getsn

peaks.txt.IGNORELINES = Filename
hirise.txt.IGNORELINES = Filename

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/peaks.cub \
	  FILE=false OBSERVATION=false \
          >& $(OUTPUT)/peaks.txt;
	$(APPNAME) FROM=$(INPUT)/hirise.cub \
	FILE=FALSE OBSERVATION=TRUE >& $(OUTPUT)/hirise.txt;
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
Loading