Commit 127ebad4 authored by Jesse Mapel's avatar Jesse Mapel
Browse files

Reverted incorrect trunk merge

parent ba74911d
Loading
Loading
Loading
Loading
+73 −166
Original line number Diff line number Diff line
#include "Isis.h"

#include <QString>

#include "Application.h"
#include "Cube.h"
#include "ExportDescription.h"
#include "FileName.h"
#include "Process.h"
#include "ProcessExportPds.h"
#include "ProcessExportPds4.h"
#include "Pvl.h"
#include "PvlKeyword.h"
#include "PvlToXmlTranslationManager.h"

using namespace std;
using namespace Isis;

enum Pixtype { NONE, NEG, BOTH };

void setRangeAndPixels(UserInterface &ui, ProcessExport &p,
void setRangeAndPixels(UserInterface &ui, ProcessExportPds &p,
                       double &min, double &max, Pixtype ptype);
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  // Check if input file is indeed, a cube
  if (ui.GetFileName("FROM").right(3) != "cub") {
    QString msg = "Input file [" + ui.GetFileName("FROM") +
                "] does not appear to be a cube";
    throw  IException(IException::User, msg, _FILEINFO_);
  }

  if (ui.GetString("PDSVERSION") == "PDS3") {
  // Set the processing object
  ProcessExportPds p;

  // Setup the input cube
  p.SetInputCube("FROM");

  UserInterface &ui = Application::GetUserInterface();

  if(ui.GetString("STRETCH") == "LINEAR") {
    if(ui.GetString("BITTYPE") != "32BIT")
      p.SetInputRange();
@@ -113,85 +93,12 @@ void IsisMain() {
  results += PvlKeyword("ValidMin", toString(min));
  results += PvlKeyword("ValidMax", toString(max));
  Application::Log(results);
  }
  else {
    // Setup the process and set the input cube
    ProcessExportPds4 process;
    Cube *icube = process.SetInputCube("FROM");

    PvlObject *label= icube->label();
    if (!label->hasObject("IsisCube")) {
      QString msg = "Input file [" + ui.GetFileName("FROM") +
                  "] does not appear to be an ISIS3 cube.";
      throw  IException(IException::User, msg, _FILEINFO_);
    }
    
    FileName outFile(ui.GetFileName("TO", "img"));
    QString outFileName(outFile.expanded());
    
    if(ui.GetString("STRETCH") == "LINEAR") {
      if(ui.GetString("BITTYPE") != "32BIT")
        process.SetInputRange();
    }
    if(ui.GetString("STRETCH") == "MANUAL")
      process.SetInputRange(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"));

    double min = -DBL_MAX;
    double max = DBL_MAX;

    if(ui.GetString("BITTYPE") == "8BIT") {
      process.SetOutputType(Isis::UnsignedByte);
      min = 0.0;
      max = 255.0;
      setRangeAndPixels(ui, process, min, max, BOTH);
    }
    else if(ui.GetString("BITTYPE") == "S16BIT") {
      process.SetOutputType(Isis::SignedWord);
      min = -32768.0;
      max = 32767.0;
      setRangeAndPixels(ui, process, min, max, NEG);
    }
    else if(ui.GetString("BITTYPE") == "U16BIT") {
      process.SetOutputType(Isis::UnsignedWord);
      min = 0.0;
      max = 65535.0;
      setRangeAndPixels(ui, process, min, max, BOTH);
    }
    else {
      process.SetOutputType(Isis::Real);
      process.SetOutputNull(Isis::NULL4);
      process.SetOutputLrs(Isis::LOW_REPR_SAT4);
      process.SetOutputLis(Isis::LOW_INSTR_SAT4);
      process.SetOutputHrs(Isis::HIGH_REPR_SAT4);
      process.SetOutputHis(Isis::HIGH_INSTR_SAT4);
      setRangeAndPixels(ui, process, min, max, NONE);
    }

    if(ui.GetString("ENDIAN") == "MSB")
      process.SetOutputEndian(Isis::Msb);
    else if(ui.GetString("ENDIAN") == "LSB")
      process.SetOutputEndian(Isis::Lsb);

    // Records what it did to the print.prt file
    PvlGroup results("DNs Used");
    results += PvlKeyword("Null", toString(process.OutputNull()));
    results += PvlKeyword("LRS", toString(process.OutputLrs()));
    results += PvlKeyword("LIS", toString(process.OutputLis()));
    results += PvlKeyword("HIS", toString(process.OutputHis()));
    results += PvlKeyword("HRS", toString(process.OutputHrs()));
    results += PvlKeyword("ValidMin", toString(min));
    results += PvlKeyword("ValidMax", toString(max));
    Application::Log(results);

    process.StandardPds4Label();
    process.WritePds4(outFileName);
  }

  return;
}

//Sets up special pixels and valid pixel ranges
void setRangeAndPixels(UserInterface &ui, ProcessExport &p, double &min, double &max, Pixtype ptype) {
void setRangeAndPixels(UserInterface &ui, ProcessExportPds &p, double &min, double &max, Pixtype ptype) {
  if(ptype == NEG) {
    if(ui.GetBoolean("NULL")) {
      p.SetOutputNull(min++);
+7 −69
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>

<application name="isis2pds" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Application/application.xsd">

  <brief>
    Convert from ISIS3 cube to PDS 3 or PDS 4 format
    Convert from cube to pds format
  </brief>

  <description>
   Program to convert cubes to PDS3 or PDS4 image files.

   For PDS4, If available, Instrument and  Mapping information will be written to the detached output PDS4 formatted xml label file.   
<p>
   Not all values in the generated PDS4 labels can be determined automatically by ISIS3, and some must be updated by the user (by opening up the xml label output by this application and editing it with a text editor) for the generated label to be PDS4 compliant. The values UNK (unknown) and TBD (to be determined) are used as placeholders in the generated label. TBD values must be replaced by the user for the output label to be PDS4 compliant. Some of these TBDs can only be replaced with one of several specific enumerated values to meet compliancy. These possible values can be found in the <a href="https://pds.jpl.nasa.gov/pds4/doc/im/current/index_1900.html">PDS 4 Information Model Specification</a> in the Value/Class column of the table for the associated tag or in the index at the end of the document. Searching this page for the name of the field you need to determine a value for is recommended. 
</p>

<p>
For example: For a cube with map-projected data, ISIS3 will populate planar_coordinate encoding_method with a value on its own, but if it did not and instead had "TBD", we would find at <a href="https://pds.jpl.nasa.gov/pds4/doc/im/current/index_1900.html#attribute_cart_planar_coordinate_information_cart_planar_coordinate_encoding_method">planar_coordinate_coding_method</a> that there are 3 possible values: 'Coordinate Pair', 'Distance and Bearing', 'Row and Column'.
</p>

<p>
Not everything is in the  <a href="https://pds.jpl.nasa.gov/pds4/doc/im/current/index_1900.html">PDS 4 Information Model Specification</a> at this time, so if the information about a tag is not in there, it may be necessary to find the options in the appropriate schematron file (.sch) available at: <a href="https://pds.jpl.nasa.gov/pds4/schema/released/">PDS4 Released Schema</a>. For the previous example, the same information can be found in the <a href="https://pds.jpl.nasa.gov/pds4/cart/v1/PDS4_CART_1700.sch">PDS4 Cartography schematron file </a>.
</p>

<p>
UNK  is used as a placeholder if any value can be used and still be a valid PDS4-formatted xml header. UNKs can, but are not required to be, replaced by the user with
better information. 
</p>

   Program to convert cubes to pds image files.
  </description>

  <category>
@@ -42,22 +22,12 @@ better information.
      Added the Label Type capability (param)
    </change>
    <change name="Kristin Berry" date="2014-06-06">
      Changed to assume that radii without units in the input Isis cube are in meters, map scales without units are in meters/pixel, and
       map resolutions without units are in pixels/degree.
      Changed to assume that radii without units in the input Isis cube are in meters, map scales without units are in meters/pixel, and map resolutions without units are in pixels/degree.
    </change>
    <change name="Makayla Shepherd and Ian Humphrey" date="2017-05-17">
      Added CHECKSUM parameter to optionally generate and attach an MD5 checksum to the exported
      image label. This checksum is generated from the image data. Fixes #1013.
    </change>
    <change name="Jeannie Backer, Mayayla Shepard, and Kristin Berry" date="2017-10-27">
       Added PDS4 output option. Previously, this application converted ISIS3 cubes to PDS3 format only. 
    </change>
    <change name="Jeannie Backer" date="2017-11-13">
       Updated to attach *.img extension to pds4 output data file. 
    </change>
    <change name="Kristin Berry" date="2017-11-26">
       Updated with very basic documentation about the PDS4 output labels. 
    </change>
    </history>

  <groups>
@@ -83,8 +53,7 @@ better information.
          Output pds image
        </brief>
        <description>
          The resulting pds file. For PDS4, a detached label of the same name with the file extension .xml 
          will be created in the same directory.
          The resulting pds file.
        </description>
        <filter>
          *.img
@@ -92,36 +61,6 @@ better information.
      </parameter>
    </group>

    <group name="PDS Format Version">
      <parameter name="PDSVERSION">
        <type>string</type>
         <default><item>PDS3</item></default>
	 <brief>Version of PDS to output</brief>
	 <description>
	     Changes which version of PDS file format
	     to output in.
	 </description>
	 <list>
	     <option value="PDS3">
		 <brief>Convert ISIS3 cube to PDS3 format</brief>
		 <description>
		     Convert ISIS3 cube to PDS3 format.
		 </description>
	     </option>
	     <option value="PDS4">
		 <brief>Convert ISIS3 cube to PDS4 format</brief>
		 <description>
		     Convert ISIS3 cube to PDS4 format.
		  </description>
		  <exclusions>
		      <item>LABTYPE</item>
		      <item>CHECKSUM</item>
		  </exclusions>
	     </option>
	 </list>
      </parameter>
    </group>

    <group name="Output Settings">
      <parameter name="LABTYPE">
        <type>string</type>
@@ -148,7 +87,6 @@ better information.
          </option>
        </list>
      </parameter>

      <parameter name="BITTYPE">
        <type>string</type>
        <default>
+0 −14
Original line number Diff line number Diff line
APPNAME = isis2pds

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) from=$(INPUT)/dawnEqui1.cub to=$(OUTPUT)/dawnEqui.img pdsversion=pds4 > /dev/null;

	# Remove parts of output that can occur in any order and convert to txt for comparison
	$(SED) 's+\Product_Observational.*>+\Product_Observational>+' \
	       $(OUTPUT)/dawnEqui.xml > $(OUTPUT)/dawnEqui.txt;

	$(RM) $(OUTPUT)/dawnEqui.xml > /dev/null; 
	$(RM) $(OUTPUT)/dawnEqui.img > /dev/null; 
+22 −23
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ namespace Isis {
        }
        catch(IException &e) {
          if(!IsOptional(g.name())) {
            throw e;//??? is this needed???
            throw;
          }
        }
      }
@@ -174,14 +174,14 @@ namespace Isis {
 *                          <li>the value to check for</li>
 *                        </ol>
 *
 * @throws IException::Programmer "Malformed dependency specification."
 * @throws IException::Programmer "Specification does not have two components
 * @throws IException::Unknown "Malformed dependency specification."
 * @throws IException::Unknown "Specification does not have two components
 *                              separated by [@], the type of dependency and
 *                              the name-value pair.
 * @throws IException::Programmer "Dependency type specification is invalid.
 * @throws IException::Unknown "Dependency type specification is invalid.
 *                              Valid types are [att] and [tag]"
 * @throws IException::Programmer "Name-value specification does not have two
 *                              components separated by [|]."
 * @throws IException::Unknown "Name-value specification does not have two
 *                              components separated by [:]."
 *
 */
QStringList LabelTranslationManager::parseSpecification(QString specification) const {
@@ -190,19 +190,18 @@ QStringList LabelTranslationManager::parseSpecification(QString specification) c

  try {
    QStringList typeSplit = specification.split("@", QString::SkipEmptyParts);
    QStringList barSplit = specification.split("|", QString::SkipEmptyParts);
   
    if (typeSplit.size() == 2) { //handle tag@elementname|value
    QStringList colonSplit = specification.split(":", QString::SkipEmptyParts);
    if (typeSplit.size() == 2) { //handle tag@elementname:value
      if (typeSplit[0].toLower() != "att" &&
          typeSplit[0].toLower() != "tag" &&
          typeSplit[0].toLower() != "new") {
        QString msg = "Dependency type specification [" + typeSplit[0] +
                      "] is invalid. Valid types are [att], [tag] and [new]";
        throw IException(IException::Programmer, msg, _FILEINFO_);
        throw IException(IException::Unknown, msg, _FILEINFO_);
      }
      parsedSpecification.append(typeSplit[0].toLower());

      QStringList nameValueSplit = typeSplit[1].split("|", QString::SkipEmptyParts);
      QStringList nameValueSplit = typeSplit[1].split(":", QString::SkipEmptyParts);
      if (nameValueSplit.size() == 2) {
        parsedSpecification.append(nameValueSplit);
      }
@@ -211,24 +210,24 @@ QStringList LabelTranslationManager::parseSpecification(QString specification) c
      }
      else { //nameValueSplit is an unexpected value
        QString msg = "Malformed dependency specification [" + specification + "].";
        throw IException(IException::Programmer, msg, _FILEINFO_);
        throw IException(IException::Unknown, msg, _FILEINFO_);
      }
    }
    else if (barSplit.size() == 2) { //handle elementname|value
      parsedSpecification = barSplit;
    else if (colonSplit.size() == 2) { //handle elementname:value
      parsedSpecification = colonSplit;
    }
    else if (barSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or "|" characters
      parsedSpecification = barSplit;
    else if (colonSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or ":" characters
      parsedSpecification = colonSplit;
    }
    else { //nameValueSplit is an unexpected value
      QString msg = " [" + specification + "] has unexpected number of '@' or '|' delimiters";
      throw IException(IException::Programmer,msg, _FILEINFO_);
      QString msg = " [" + specification + "] has unexpected number of '@' or ':' delimiters";
      throw IException(IException::Unknown,msg, _FILEINFO_);
    }
  }

  catch (IException &e) {
    QString msg = "Malformed dependency specification [" + specification + "].";
    throw IException(e, IException::Programmer, msg, _FILEINFO_);
    throw IException(e, IException::Unknown, msg, _FILEINFO_);
  }

  return parsedSpecification;
+0 −4
Original line number Diff line number Diff line
@@ -51,10 +51,6 @@ namespace Isis {
   *                          Fixes #4584.
   *  @history 2017-05-26 Cole Neubauer - Moved parseDependancy from children
   *                          class. Fixes #5167.
   *  @history 2017-10-26 Kristin Berry - Modified parseSpecification to switch
   *                          from parsing translation table dependency specifications of the form
   *                          name:value to strings of the form name|value. Colons are
   *                          now used for namespaces only.
   */
  class LabelTranslationManager : public PvlTranslationTable {
    public:
Loading