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

Ckwriter App and Test Update (#4126)

* Convert ckwriter to new app format

* Updated ckwriter tests to gtest and fixed angular velocities in the ThreeImageNetwork fixture

* Removed old/unnecessary includes

* Removed old ckwriter test makefiles
parent 7552d121
Loading
Loading
Loading
Loading
+85 −0
Original line number Diff line number Diff line
#include <cmath>

#include "ckwriter.h"

#include "Cube.h"
#include "FileList.h"
#include "Process.h"
#include "Pvl.h"
#include "SpiceKernel.h"

using namespace std;

namespace Isis {
  void ckwriter(UserInterface &ui, Pvl *log) {
    Process p;

    // Get the list of names of input CCD cubes to stitch together
    FileList flist;
    if (ui.WasEntered("FROM")) flist.push_back(FileName(ui.GetFileName("FROM")));
    if (ui.WasEntered("FROMLIST")) flist.read(FileName(ui.GetFileName("FROMLIST")));
    if (flist.size() < 1) {
      QString msg = "Files must be specified in FROM and/or FROMLIST - none found!";
      throw IException(IException::User,msg,_FILEINFO_);
    }

    bool overlap_is_error = ( "ERROR" == ui.GetString("OVERLAP") ) ? true : false;

    SpiceKernel kernel;
    Progress prog;
    prog.SetMaximumSteps(flist.size());
    prog.CheckStatus();

    for (int i = 0 ; i < flist.size() ; i++) {
      // Add and process each image
      kernel.add(flist[i].toString());
      prog.CheckStatus();
    }

    try {
      kernel.validate();
    }
    catch ( IException &ie ) {

      // Check for user preference in treatment overlaps
      if ( overlap_is_error ) { throw; }

      //  Log it to file
      Pvl overrors = ie.toPvl();
      for(int i = 0; i < overrors.groups(); i++) {
        PvlGroup overlap = overrors.group(i);
        overlap.setName("Overlaps");
        overlap.addKeyword(PvlKeyword("Class", "WARNING"), PvlContainer::Replace);
        if (log) {
          log->addGroup(overlap);
        }
      }
    }


    //  Get comment file
    QString comfile("");
    if (ui.WasEntered("COMFILE")) comfile = ui.GetFileName("COMFILE");

    // Write the output file if requested
    if (ui.WasEntered("TO")) {
      int cktype = ui.GetInteger("CKTYPE");
      kernel.write(ui.GetFileName("TO"), comfile, cktype);
    }

    // Write a summary of the documentation
    if (ui.WasEntered("SUMMARY")) {
      QString fFile = FileName(ui.GetFileName("SUMMARY")).expanded();
      ofstream os;
      os.open(fFile.toLatin1().data(),ios::out);
      if (!os) {
        QString mess = "Cannot create SUMMARY output file " + fFile;
        throw IException(IException::User, mess, _FILEINFO_);
      }
      os << kernel.getSummary(comfile);
      os.close();
    }

    p.EndProcess();
  }
}
+11 −0
Original line number Diff line number Diff line
#ifndef ckwriter_h
#define ckwriter_h

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

namespace Isis{
  void ckwriter(UserInterface &ui, Pvl *log=nullptr);
}

#endif
+12 −68
Original line number Diff line number Diff line
#include <cmath>

#include "Isis.h"
#include "FileList.h"
#include "Cube.h"
#include "Process.h"

#include "ckwriter.h"

#include "Application.h"
#include "Pvl.h"
#include "SpiceKernel.h"
#include "CkSpiceSegment.h"

using namespace std;
using namespace Isis;

void IsisMain() {
  Process p;

  // Get the list of names of input CCD cubes to stitch together
  FileList flist;
  UserInterface &ui = Application::GetUserInterface();
  if (ui.WasEntered("FROM")) flist.push_back(FileName(ui.GetFileName("FROM")));
  if (ui.WasEntered("FROMLIST")) flist.read(FileName(ui.GetFileName("FROMLIST")));
  if (flist.size() < 1) {
    QString msg = "Files must be specified in FROM and/or FROMLIST - none found!";
    throw IException(IException::User,msg,_FILEINFO_);
  }

  bool overlap_is_error = ( "ERROR" == ui.GetString("OVERLAP") ) ? true : false;

  SpiceKernel kernel;
  Progress prog;
  prog.SetMaximumSteps(flist.size());
  prog.CheckStatus();

  for (int i = 0 ; i < flist.size() ; i++) {
    // Add and process each image
    kernel.add(flist[i].toString());
    prog.CheckStatus();
  }

  Pvl appLog;
  try {
    kernel.validate();
    ckwriter(ui, &appLog);
  }
  catch ( IException &ie ) {

    // Check for user preference in treatment overlaps
    if ( overlap_is_error ) { throw; }

    //  Log it to file
    Pvl overrors = ie.toPvl();
    for(int i = 0; i < overrors.groups(); i++) {
      PvlGroup overlap = overrors.group(i);
      overlap.setName("Overlaps");
      overlap.addKeyword(PvlKeyword("Class", "WARNING"), PvlContainer::Replace);
      Application::Log(overlap);
  catch (...) {
    for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
      Application::Log(*grpIt);
    }
    throw;
  }


  //  Get comment file
  QString comfile("");
  if (ui.WasEntered("COMFILE")) comfile = ui.GetFileName("COMFILE");

  // Write the output file if requested
  if (ui.WasEntered("TO")) {
    int cktype = ui.GetInteger("CKTYPE");
    kernel.write(ui.GetFileName("TO"), comfile, cktype);
  for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
    Application::Log(*grpIt);
  }

  // Write a summary of the documentation
  if (ui.WasEntered("SUMMARY")) {
    QString fFile = FileName(ui.GetFileName("SUMMARY")).expanded();
    ofstream os;
    os.open(fFile.toLatin1().data(),ios::out);
    if (!os) {
      QString mess = "Cannot create SUMMARY output file " + fFile;
      throw IException(IException::User, mess, _FILEINFO_);
    }
    os << kernel.getSummary(comfile);
    os.close();
  }

  p.EndProcess();
}
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
+0 −22
Original line number Diff line number Diff line
APPNAME = ckwriter

include $(ISISROOT)/make/isismake.tsts

#  Only use 12 digits in the output of tabledump due to precision issues
commands:
	$(APPNAME) FROM=$(INPUT)/N1487301032_2.cub \
	TO=$(OUTPUT)/N1487301032_2.bc > /dev/null;
	$(CP) $(INPUT)/N1487301032_2.cub $(OUTPUT)
	spiceinit from=$(OUTPUT)/N1487301032_2.cub \
	  ck=$(OUTPUT)/N1487301032_2.bc > /dev/null;
	tabledump from=$(OUTPUT)/N1487301032_2.cub \
	  to=$(OUTPUT)/N1487301032_2.dat \
	  name=InstrumentPointing > /dev/null;
	cat $(OUTPUT)/N1487301032_2.dat \
	  | sed 's/\([0-9][0-9]*\.[0-9]\{12\}\)\([0-9][0-9]*\)/\1/g' \
	  > $(OUTPUT)/N1487301032_2.txt;
	$(RM) $(OUTPUT)/N1487301032_2.cub 
	$(RM) $(OUTPUT)/N1487301032_2.bc
	$(RM) $(OUTPUT)/N1487301032_2.dat

Loading