Commit 3d786bf3 authored by Tyler Wilson's avatar Tyler Wilson
Browse files

isis2fits app no longer crashes with 'failed to convert string' error msg (Ref#2272)

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6382 41f8697f-d340-4b68-9986-7bafba869bb8
parent 639416d0
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -19,11 +19,12 @@ using namespace std;
using namespace Isis;

// Global variables
int headerBytes = 0;

int g_headerBytes = 0;

QString FitsKeyword(QString keyword, bool isVal, QString value, QString unit = "");

QString WritePvl(QString fitsKey, QString group, IString key, Cube *icube, bool isString);
QString WritePvl(QString fitsKey, QString group, QString key, Cube *icube, bool isString);

// Main program
void IsisMain() {
@@ -82,9 +83,7 @@ void IsisMain() {
  }


  //////////////////////////////////////////
  // Write the minimal fits header        //
  //////////////////////////////////////////
  // Write the minimal fits header   
  QString header;

  // specify that this file conforms to simple fits standard
@@ -118,7 +117,9 @@ void IsisMain() {

  // Sky and All cases
  if (ui.GetString("INFO") == "SKY" || ui.GetString("INFO") == "ALL") {
    IString msg = "cube has not been skymapped";

    //tjw:  IString msg changed to QString
    QString msg = "cube has not been skymapped";
    PvlGroup map;

    if (icube->hasGroup("mapping")) {
@@ -129,11 +130,9 @@ void IsisMain() {
    if (msg == "Sky") {
      double midRa = 0, midDec = 0;

      midRa = ((double)map["MaximumLongitude"] +
               (double)map["MinimumLongitude"]) / 2;
      midRa = ((double)map["MaximumLongitude"] + (double)map["MinimumLongitude"]) / 2;

      midDec = ((double)map["MaximumLatitude"] +
                (double)map["MinimumLatitude"]) / 2;
      midDec = ((double)map["MaximumLatitude"] + (double)map["MinimumLatitude"]) / 2;

      header += FitsKeyword("OBJCTRA", true, toString(midRa));

@@ -142,21 +141,28 @@ void IsisMain() {

    }

    //tjw:  All strings in this block  placed inside QString constructors
    if (ui.GetString("INFO") == "ALL") {
      header += WritePvl("INSTRUME", "Instrument", "InstrumentId", icube, true);
      header += WritePvl("OBSERVER", "Instrument", "SpacecraftName", icube, true);
      header += WritePvl("OBJECT  ", "Instrument", "TargetName", icube, true);
      header += WritePvl(QString("INSTRUME"), QString("Instrument"),
                         QString("InstrumentId"), icube, true);
      header += WritePvl(QString("OBSERVER"), QString("Instrument"),
                         QString("SpacecraftName"), icube, true);
      header += WritePvl(QString("OBJECT  "), QString("Instrument"),
                         QString("TargetName"), icube, true);
      // StartTime is sometimes middle of the exposure and somtimes beginning,
      // so StopTime can't be calculated off of exposure reliably.
      header += WritePvl("DATE-OBS", "Instrument", "StartTime", icube, true);
      header += WritePvl(QString("DATE-OBS"), QString("Instrument"),
                         QString("StartTime"), icube, true);
      // Some cameras don't have StopTime
      if (icube->hasGroup("Instrument")) {
        PvlGroup inst = icube->group("Instrument");
        if (inst.hasKeyword("StopTime")) {
          header += WritePvl("TIME_END", "Instrument", "StopTime", icube, true);
          header += WritePvl(QString("TIME_END"), QString("Instrument"),
                             QString("StopTime"), icube, true);
        }
        if (inst.hasKeyword("ExposureDuration")) {
          header += WritePvl("EXPTIME", "Instrument", "ExposureDuration", icube, false);
          header += WritePvl(QString("EXPTIME"), QString("Instrument"),
                             QString("ExposureDuration"), icube, false);
        }
      }
    }
@@ -230,11 +236,12 @@ QString FitsKeyword(QString key, bool isValue, QString value, QString unit) {
  }

  // record the total length of the header
  headerBytes += key.length();
  g_headerBytes += key.length();
  return key;
}

QString WritePvl(QString fitsKey, QString group, IString key, Cube *icube, bool isString) {
//tjw:  IString key -> QString key
QString WritePvl(QString fitsKey, QString group, QString key, Cube *icube, bool isString) {
  if (icube->hasGroup(group)) {
    PvlGroup theGroup = icube->group(group);
    QString name = (QString)theGroup[key];
+17 −0
Original line number Diff line number Diff line
APPNAME = isis2fits

# This test is for when the isis2fits paramter INFO is set to "ALL"

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/skymapTruth.cub \
	  TO=$(OUTPUT)/truth.fits \
	  BITTYPE=32BIT \
	  INFO=ALL;
	raw2isis FROM=$(OUTPUT)/truth.fits \
	  TO=$(OUTPUT)/truth.cub \
	  SAMPLES=90 LINES=14 BANDS=1 \
	  SKIP=2880 BITTYPE=REAL BYTEORDER=LSB;
	dd bs=2880 count=1 if=$(OUTPUT)/truth.fits > $(OUTPUT)/labels.txt 2> /dev/null;
	$(RM) $(OUTPUT)/truth.fits; > /dev/null;
+1 −0
Original line number Diff line number Diff line
SIMPLE  =                    T /                                                BITPIX  =                  -32 /                                                NAXIS   =                    2 /                                                NAXIS1  =                   90 /                                                NAXIS2  =                   14 /                                                BZERO   =                  0.0 /                                                BSCALE  =                  1.0 /                                                OBJCTRA =                180.0 /                                                OBJCTDEC=     -36.553241445319 /                                                INSTRUME=             'MOC-WA' /                                                OBSERVER= 'MARS GLOBAL SURVEYOR' /                                              OBJECT  =               'Mars' /                                                DATE-OBS= '1997-10-20T10:58:37.46' /                                            TIME_END= '1997-10-20T11:03:44.66' /                                            END                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
 No newline at end of file