Commit f64f9796 authored by Kaitlyn Lee's avatar Kaitlyn Lee
Browse files

Removed changed files from other branches.

parent ac6bcd49
Loading
Loading
Loading
Loading
+39 −75
Original line number Diff line number Diff line
@@ -9,11 +9,19 @@ using namespace std;
using namespace Isis;

void IsisMain() {

  UserInterface &ui = Application::GetUserInterface();
  ProcessImport p;
  IString from = ui.GetFileName("FROM");
  ifstream fin;
  EndianSwapper swp("MSB");
  int nsamples = 0, nlines = 0, nbands = 1, noffset = 0, bittype = 0, nbytes = 0;

  union {
    char readChars[4];
    long readLong;
    float readFloat;
  } readBytes;

  ifstream fin;
  fin.open(from.c_str(), ios::in | ios::binary);
  if(!fin.is_open()) {
    string msg = "Cannot open input file [" + from + "]";
@@ -33,40 +41,25 @@ void IsisMain() {
   *
   */

   // ifstream read() needs a char* to read values into, so the union
   // is used to store read values
   union {
     char readChars[4];
     long readLong;
     float readFloat;
   } readBytes;

   // ddd files are LSB
   EndianSwapper swp("MSB");

  // Verify that the file is a .ddd by reading in the first 4 bytes and
  // comparing the magic numbers
  // Verify the magic number
  readBytes.readLong = 0;
  fin.seekg(0);
  fin.read(readBytes.readChars, 4);
  readBytes.readFloat = swp.Float(readBytes.readChars);

  if(readBytes.readLong != 1659) {
  if(readBytes.readLong != 0x67B) {
    string msg = "Input file [" + from + "] does not appear to be in ddd format";
    throw IException(IException::Io, msg, _FILEINFO_);
  }

  // Read bytes 4-7 to get number of lines
  fin.read(readBytes.readChars, 4);
  readBytes.readFloat = swp.Float(readBytes.readChars);
  int nLines = (int) readBytes.readLong;
  nlines = (int)readBytes.readLong;

  // Read bytes 8-11 to get number of bytes
  fin.read(readBytes.readChars, 4);
  readBytes.readFloat = swp.Float(readBytes.readChars);
  int nBytes = (int) readBytes.readLong;
  nbytes = (int)readBytes.readLong;

  // Read bytes 12-15 to get the total number of bits out of all the bands
  fin.read(readBytes.readChars, 4);
  readBytes.readFloat = swp.Float(readBytes.readChars);

@@ -74,63 +67,34 @@ void IsisMain() {
    string msg = "An error ocurred when reading the input file [" + from + "]";
    throw IException(IException::Io, msg, _FILEINFO_);
  }
  int totalBandBits = readBytes.readLong;

  // Maps the bit type of the file to the number of bytes
  map<int, int> dataTypes = {
    {1450901768, 1},
    {1450902032, 2},
    {1450902288, 2},
    {1450902560, 4},
    {1450902816, 4},
    {1450903072, 4},
    {1450903360, 8},
    {8, 1},
    {16, 2},
    {48, 2}
  };

  // Read bytes 16-19 to get the bit type
  // Map the bit type to the number of bytes and store in dataTypeBytes

  bittype = readBytes.readLong;

  fin.read(readBytes.readChars, 4);
  readBytes.readFloat = swp.Float(readBytes.readChars);
  int bitType = (int) readBytes.readLong;

  int dataTypeBytes;
  //Old header format has no bit type
  if (bitType == 0) {
    dataTypeBytes = dataTypes.find( totalBandBits ) -> second;
  }
  else{
    dataTypeBytes = dataTypes.find( bitType ) -> second;
  }

  // Read bytes 20-23 to get offset
  fin.read(readBytes.readChars, 4);
  readBytes.readFloat = swp.Float(readBytes.readChars);
  int nOffset = (int) readBytes.readLong;
  if (nOffset < 1024) {
    nOffset = 1024;
  noffset = (int)readBytes.readLong;
  if (noffset < 1024) {
    noffset = 1024;
  }

  PvlGroup results("FileInfo");
  results += PvlKeyword( "NumberOfLines", toString(nLines) );
  results += PvlKeyword( "NumberOfBytesPerLine", toString(nBytes) );
  results += PvlKeyword( "BitType", toString(totalBandBits) );
  int nSamples = nBytes / (totalBandBits / 8);
  results += PvlKeyword( "NumberOfSamples", toString(nSamples) );
  int nBands = (totalBandBits / 8) / dataTypeBytes;
  results += PvlKeyword( "NumberOfBands", toString(nBands) );
  results += PvlKeyword( "LabelBytes", toString(nOffset) );
  results += PvlKeyword("NumberOfLines", toString(nlines));
  results += PvlKeyword("NumberOfBytesPerLine", toString(nbytes));
  results += PvlKeyword("BitType", toString(bittype));
  nsamples = nbytes / (bittype / 8);
  results += PvlKeyword("NumberOfSamples", toString(nsamples));
  nbands = nbytes / nsamples;
  results += PvlKeyword("NumberOfBands", toString(nbands));
  results += PvlKeyword("LabelBytes", toString(noffset));
  Application::Log(results);

  fin.close();

  ProcessImport p;

  int bitsPerBand = totalBandBits / nBands;
  if (ui.WasEntered("TO")) {
    switch(bitsPerBand) {
    switch(bittype) {
      case 8:
        p.SetPixelType(Isis::UnsignedByte);
        break;
@@ -141,17 +105,14 @@ void IsisMain() {
        p.SetPixelType(Isis::Real);
        break;
      default:
        IString msg = "Unsupported bit per pixel count [" + IString(totalBandBits) + "]. ";
        IString msg = "Unsupported bit per pixel count [" + IString(bittype) + "]. ";
        msg += "(Use the raw2isis and crop programs to import the file in case it is ";
        msg += "line or sample interleaved.)";
        throw IException(IException::Io, msg, _FILEINFO_);
    }

    // ddd files are pixel interleaved
    p.SetOrganization(ProcessImport::BIP);

    p.SetDimensions(nSamples, nLines, nBands);
    p.SetFileHeaderBytes(nOffset);
    p.SetDimensions(nsamples, nlines, nbands);
    p.SetFileHeaderBytes(noffset);
    p.SetByteOrder(Isis::Msb);
    p.SetInputFile(ui.GetFileName("FROM"));
    p.SetOutputCube("TO");
@@ -159,4 +120,7 @@ void IsisMain() {
    p.StartProcess();
    p.EndProcess();
  }

  return;
}
+14 −10
Original line number Diff line number Diff line
@@ -34,13 +34,17 @@ void IsisMain() {
  bool WriteObservation = ui.GetBoolean("OBSERVATION");

  QString format = ui.GetString("FORMAT");
  bool pvl;
  bool pvl = true;
  if (format == "PVL") {
    pvl = true;
  }
  else {
  else if (format == "FLAT") {
    pvl = false;
  }
  else {
    QString msg = "Invalid format QString [" + format + "]";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  // Extract label from cube file
  Pvl *label = cube.label();
+14 −19
Original line number Diff line number Diff line
@@ -42,11 +42,6 @@
      Added FORMAT option to choose between PVL and FLAT format. Effects output
      file only, default is still PVL.
    </change>
    <change name="Kaitlyn Lee" date="2018-01-17">
      Removed unreachable else clause that assumed more than two options are
      allowed to be entered in for the parameter FORMAT. Added test to default case
      to increase code coverage.
    </change>
  </history>

  <groups>
+4 −7
Original line number Diff line number Diff line
@@ -4,11 +4,8 @@ include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/peaks.cub \
		TO=$(OUTPUT)/peaks.pvl FILE=FALSE OBSERVATION=TRUE SN=FALSE \
	TO=$(OUTPUT)/peaks.pvl FILE=TRUE OBSERVATION=TRUE \
	APPEND=false;
	$(APPNAME) FROM=$(INPUT)/peaks.cub \
		TO=$(OUTPUT)/peaks.pvl FILE=TRUE OBSERVATION=FALSE SN=TRUE \
			APPEND=TRUE;
	$(APPNAME) FROM=$(INPUT)/hirise.cub \
	TO= $(OUTPUT)/hirise.pvl FILE=TRUE OBSERVATION=TRUE \
	APPEND=false;