Unverified Commit 3c18de0c authored by jcwbacker's avatar jcwbacker Committed by GitHub
Browse files

Merge pull request #169 from TracieSucharski/ipce

Ipce-merge dev into ipce 
parents 6ad500d8 61afa7a9
Loading
Loading
Loading
Loading
+42 −60
Original line number Diff line number Diff line
@@ -1847,11 +1847,6 @@ namespace Isis {
   */
  void ProcessImport::ProcessBip(void funct(Isis::Buffer &out)) {

    // Figure out the number of bytes to read for a single line
    int readBytes = Isis::SizeOf(p_pixelType);
    readBytes = readBytes * p_ns * p_nb;
    char *in = new char [readBytes];

    // Set up an Isis::EndianSwapper object
    QString tok(Isis::ByteOrderName(p_byteOrder));
    tok = tok.toUpper();
@@ -1902,6 +1897,11 @@ namespace Isis {
    p_progress->SetMaximumSteps(p_nl);
    p_progress->CheckStatus();

    // Figure out the number of bytes to read for a single line
    int sampleBytes = Isis::SizeOf(p_pixelType) * p_nb + p_dataPreBytes + p_dataPostBytes;
    int readBytes = p_ns * sampleBytes;
    char *in = new char [readBytes];

    // Loop for each line
    for(int line = 0; line < p_nl; line++) {
      // Check the last io
@@ -1915,16 +1915,6 @@ namespace Isis {
      // Space for storing prefix and suffix data pointers
      vector<char *> tempPre, tempPost;

      // Handle any line prefix bytes
      pos = fin.tellg();
      if (p_saveDataPre) {
        tempPre.push_back(new char[p_dataPreBytes]);
        fin.read(tempPre.back(), p_dataPreBytes);
      }
      else {
        fin.seekg(p_dataPreBytes, ios_base::cur);
      }

      // Check the last io
      if (!fin.good()) {
        QString msg = "Cannot read file [" + p_inFile + "]. Position [" +
@@ -1960,31 +1950,32 @@ namespace Isis {
        // to special pixels
        int osamp = 0;

        for(int samp = band; samp < p_ns * p_nb; samp += p_nb) {
        for(int samp = 0; samp < p_ns; samp++) {
          int bufferIndex = p_dataPreBytes + Isis::SizeOf(p_pixelType)*band + samp*sampleBytes;
          switch(p_pixelType) {
            case Isis::UnsignedByte:
              (*out)[osamp] = (double)((unsigned char *)in)[samp];
              (*out)[osamp] = (double)((unsigned char *)in)[bufferIndex];
              break;
            case Isis::UnsignedWord:
              (*out)[osamp] =
                (double)swapper.UnsignedShortInt((unsigned short int *)in+samp);
                (double)swapper.UnsignedShortInt(&in[bufferIndex]);
              break;
            case Isis::SignedWord:
              (*out)[osamp] = (double)swapper.ShortInt((short int *)in+samp);
              (*out)[osamp] = (double)swapper.ShortInt(&in[bufferIndex]);
              break;
            case Isis::SignedInteger:
              (*out)[samp] = (double)swapper.Int((int *)in+samp);
              (*out)[samp] = (double)swapper.Int(&in[bufferIndex]);
              break;
            case Isis::Real:
              if(p_vax_convert) {
                (*out)[osamp]= VAXConversion( (float *)in+samp );
                (*out)[osamp]= VAXConversion(&in[bufferIndex]);
              }
              else {
                (*out)[osamp] = (double)swapper.Float((float *)in+samp);
                (*out)[osamp] = (double)swapper.Float(&in[bufferIndex]);
              }
              break;
            case Isis::Double:
              (*out)[osamp] = (double)swapper.Double((double *)in+samp);
              (*out)[osamp] = (double)swapper.Double(&in[bufferIndex]);
              break;
            default:
              break;
@@ -2008,33 +1999,25 @@ namespace Isis {
          funct(*out);
        }

        // Handle any line suffix bytes
        pos = fin.tellg();
        if (p_saveDataPost) {
          tempPost.push_back(new char[p_dataPostBytes]);
          fin.read(tempPost.back(), p_dataPostBytes);
        }
        else {
          fin.seekg(p_dataPostBytes, ios_base::cur);
        }

        // Check the last io
        if (!fin.good()) {
          QString msg = "Cannot read file [" + p_inFile + "]. Position [" +
                       toString((int)pos) + "]. Byte count [" +
                       toString(p_dataPreBytes) + "]" ;
          throw IException(IException::Io, msg, _FILEINFO_);
        }

      } // End band loop

        // Save off the prefix bytes vector
      // Handle record prefix and suffix
      if (p_saveDataPre) {
        for(int samp = 0; samp < p_ns; samp++) {
          char *samplePrefix = new char[p_dataPreBytes];
          memcpy(samplePrefix, &in[samp*sampleBytes], p_dataPreBytes);
          tempPre.push_back(samplePrefix);
        }
        p_dataPre.push_back(tempPre);
        tempPre.clear();
      }

        // Save off the suffix bytes vector
      if (p_saveDataPost) {
        for(int samp = 0; samp < p_ns; samp++) {
          char *sampleSuffix = new char[p_dataPostBytes];
          int suffixIndex = p_dataPreBytes + Isis::SizeOf(p_pixelType)*p_nb + samp*sampleBytes;
          memcpy(sampleSuffix, &in[suffixIndex], p_dataPostBytes);
          tempPost.push_back(sampleSuffix);
        }
        p_dataPost.push_back(tempPost);
        tempPost.clear();
      }
@@ -2043,12 +2026,11 @@ namespace Isis {
      if (!fin.good()) {
        QString msg = "Cannot read file [" + p_inFile + "]. Position [" +
                     toString((int)pos) + "]. Byte count [" +
                       toString(p_fileHeaderBytes) + "]" ;
                     toString(p_dataPreBytes) + "]" ;
        throw IException(IException::Io, msg, _FILEINFO_);
      }

      } // End band loop

      // Handle the data trailer
      pos = fin.tellg();
      if (p_saveDataTrailer) {
        p_dataTrailer.push_back(new char[p_dataTrailerBytes]);
+13 −2
Original line number Diff line number Diff line
@@ -152,6 +152,17 @@ namespace Isis {
   *   @history 2017-05-29 Kristin Berry - Added support for data trailers in BIP files and fixed
   *                           a typo so that DataTrailerBytes() will return the correct value.
   *                           References #3888.
   *   @history 2018-05-01 Jesse Mapel - Changed data suffix and prefix in BIP files. Previously,
   *                           data suffixes and prefixes were for each band before/after each line.
   *                           Now, data suffixes and prefixes are before/after each sample. For a
   *                           RGB, 3-band image with n samples a line of data was previously
   *                           | Header | R prefix | G prefix | B prefix | R 1 | G 1 | B 1| ...
   *                           | R n | G n | B n| R suffix | G suffix | B suffix | Trailer |. Now
   *                           it is | Header | Prefix 1 | R 1 | G 1 | B 1 | Suffix 1 | ...
   *                           | Prefix n | R n | G n | B n | Suffix n | Trailer |. This change
   *                           was made to accomodate Rosetta VIRTIS-m calibrated data files and
   *                           has no impact on other supported BIP files.
   *                           Fixes #5398.
   *
   */
  class ProcessImport : public Isis::Process {
+66 −45
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ namespace Isis {
   * set the input label before translating. This may be done by using
   * SetLabel(Pvl inputLabel) or Auto(Pvl inputLabel, Pvl outputLabel).
   *
   * @param transFile The translation file to be used to tranlate keywords in
   * @param transFile The translation file to be used to translate keywords in
   *                  the input label.
   */
  PvlToPvlTranslationManager::PvlToPvlTranslationManager(const QString &transFile)
@@ -53,8 +53,8 @@ namespace Isis {
   * input label before translating. This may be done by using SetLabel(Pvl
   * inputLabel) or Auto(Pvl inputLabel, Pvl outputLabel).
   *
   * @param transStrm A stream containing the tranlation table to be used to
   *                  tranlate keywords in the input label.
   * @param transStrm A stream containing the translation table to be used to
   *                  translate keywords in the input label.
   */
  PvlToPvlTranslationManager::PvlToPvlTranslationManager(std::istream &transStrm)
      : LabelTranslationManager(transStrm) {
@@ -66,7 +66,7 @@ namespace Isis {
   *
   * @param inputLabel The Pvl holding the input label.
   *
   * @param transFile The translation file to be used to tranlate keywords in
   * @param transFile The translation file to be used to translate keywords in
   *                  the input label.
   */
  PvlToPvlTranslationManager::PvlToPvlTranslationManager(Pvl &inputLabel,
@@ -81,8 +81,8 @@ namespace Isis {
   *
   * @param inputLabel The Pvl holding the input label.
   *
   * @param transStrm A stream containing the tranlation table to be used to
   *                  tranlate keywords in the input label.
   * @param transStrm A stream containing the translation table to be used to
   *                  translate keywords in the input label.
   */
  PvlToPvlTranslationManager::PvlToPvlTranslationManager(Pvl &inputLabel,
      std::istream &transStrm)
@@ -103,34 +103,37 @@ namespace Isis {

  /**
   * Returns a translated value. The output name is used to find the input
   * group, keyword, default and tranlations in the translation table. If the
   * group, keyword, default and translations in the translation table. If the
   * keyword does not exist in the input label and an input default is available,
   * then this default will be used as the input value. This input value is
   * then used to search all of the translations. If a match is found the
   * translated value is returned. 
   *
   * @param nName The output name used to identify the input keyword to be
   *              translated.
   * @param translationGroupName The name of the PVL translation 
   *                             group used to identify the
   *                             input/output keywords to be
   *                             translated. Often, this is the
   *                             same as the output keyword name.
   *
   * @param findex The index into the input keyword array.  Defaults to 0
   *
   * @return string
   */
  QString PvlToPvlTranslationManager::Translate(QString nName, int findex) {
  QString PvlToPvlTranslationManager::Translate(QString translationGroupName, int findex) {
    const PvlContainer *con;
    int inst = 0;
    PvlKeyword grp;

    while((grp = InputGroup(nName, inst++)).name() != "") {
    while((grp = InputGroup(translationGroupName, inst++)).name() != "") {
      if((con = GetContainer(grp)) != NULL) {
        if(con->hasKeyword(InputKeywordName(nName))) {
          return PvlTranslationTable::Translate(nName,
                                                (*con)[InputKeywordName(nName)][findex]);
        if(con->hasKeyword(InputKeywordName(translationGroupName))) {
          return PvlTranslationTable::Translate(translationGroupName,
                                                (*con)[InputKeywordName(translationGroupName)][findex]);
        }
      }
    }

    return PvlTranslationTable::Translate(nName);
    return PvlTranslationTable::Translate(translationGroupName);
  }


@@ -143,12 +146,15 @@ namespace Isis {
   *  
   * @see Auto().
   *
   * @param nName The output name used to identify the input keyword to be
   *              translated.
   * @param translationGroupName The name of the PVL translation 
   *                             group used to identify the
   *                             input/output keywords to be
   *                             translated. Often, this is the
   *                             same as the output keyword name.
   *
   * @return PvlKeyword
   */
   PvlKeyword PvlToPvlTranslationManager::DoTranslation(const QString nName) {
   PvlKeyword PvlToPvlTranslationManager::DoTranslation(const QString translationGroupName) {
     const PvlContainer *con = NULL;
     PvlKeyword key;

@@ -156,9 +162,9 @@ namespace Isis {
     PvlGroup transGroup;
     PvlKeyword grp;

     while((grp = InputGroup(nName, inst++)).name() != "") {
     while((grp = InputGroup(translationGroupName, inst++)).name() != "") {
       if((con = GetContainer(grp)) != NULL) {
         transGroup = TranslationTable().findGroup(nName);
         transGroup = TranslationTable().findGroup(translationGroupName);
         Pvl::ConstPvlKeywordIterator it = transGroup.findKeyword("InputKey",
                                           transGroup.begin(),
                                           transGroup.end());
@@ -167,10 +173,10 @@ namespace Isis {
         while(it != transGroup.end()) {
           const PvlKeyword &result = *it;
           if(con->hasKeyword(result[0])) {
             key.setName(OutputName(nName));
             key.setName(OutputName(translationGroupName));

             for(int v = 0; v < (*con)[(result[0])].size(); v++) {
               key.addValue(PvlTranslationTable::Translate(nName,
               key.addValue(PvlTranslationTable::Translate(translationGroupName,
                                                           (*con)[result[0]][v]),
                            (*con)[result[0]].unit(v));
             }
@@ -182,8 +188,8 @@ namespace Isis {
       }
     }

     return PvlKeyword(OutputName(nName),
                       PvlTranslationTable::Translate(nName, ""));
     return PvlKeyword(OutputName(translationGroupName),
                       PvlTranslationTable::Translate(translationGroupName, ""));
   }


@@ -227,16 +233,20 @@ namespace Isis {
  /**
   * Returns the ith input value associated with the output name argument.
   *
   * @param nName The output name used to identify the input keyword.
   * @param translationGroupName The name of the PVL translation 
   *                             group used to identify the
   *                             input/output keywords to be
   *                             translated. Often, this is the
   *                             same as the output keyword name.
   *
   * @param findex The index into the input keyword array.  Defaults to 0
   *
   * @throws IException::Programmer
   */
  const PvlKeyword &PvlToPvlTranslationManager::InputKeyword(const QString nName) const {
  const PvlKeyword &PvlToPvlTranslationManager::InputKeyword(const QString translationGroupName) const {

    int instanceNumber = 0;
    PvlKeyword inputGroupKeyword = InputGroup(nName, instanceNumber);
    PvlKeyword inputGroupKeyword = InputGroup(translationGroupName, instanceNumber);
    bool anInputGroupFound = false;

    while(inputGroupKeyword.name() != "") {
@@ -244,31 +254,31 @@ namespace Isis {
      if(containingGroup != NULL) {
        anInputGroupFound = true;

        if(containingGroup->hasKeyword(InputKeywordName(nName))) {
          return containingGroup->findKeyword(InputKeywordName(nName));
        if(containingGroup->hasKeyword(InputKeywordName(translationGroupName))) {
          return containingGroup->findKeyword(InputKeywordName(translationGroupName));
        }
      }

      instanceNumber ++;
      inputGroupKeyword = InputGroup(nName, instanceNumber);
      inputGroupKeyword = InputGroup(translationGroupName, instanceNumber);
    }

    if(anInputGroupFound) {
      QString msg = "Unable to find input keyword [" + InputKeywordName(nName) +
                   "] for output name [" + nName + "] in file [" + TranslationTable().fileName() + "]";
      QString msg = "Unable to find input keyword [" + InputKeywordName(translationGroupName) +
                   "] for output name [" + translationGroupName + "] in file [" + TranslationTable().fileName() + "]";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    else {
      QString container = "";

      for(int i = 0; i < InputGroup(nName).size(); i++) {
      for(int i = 0; i < InputGroup(translationGroupName).size(); i++) {
        if(i > 0) container += ",";

        container += InputGroup(nName)[i];
        container += InputGroup(translationGroupName)[i];
      }

      QString msg = "Unable to find input group [" + container +
                   "] for output name [" + nName + "] in file [" + TranslationTable().fileName() + "]";
                   "] for output name [" + translationGroupName + "] in file [" + TranslationTable().fileName() + "]";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
  }
@@ -278,21 +288,25 @@ namespace Isis {
   * Indicates if the input keyword corresponding to the output name exists in
   * the label
   *
   * @param nName The output name used to identify the input keyword.
   * @param translationGroupName The name of the PVL translation 
   *                             group used to identify the
   *                             input/output keywords to be
   *                             translated. Often, this is the
   *                             same as the output keyword name.
   */
  bool PvlToPvlTranslationManager::InputHasKeyword(const QString nName) {
  bool PvlToPvlTranslationManager::InputHasKeyword(const QString translationGroupName) {

    // Set the current position in the input label pvl
    // by finding the input group corresponding to the output group
    const PvlContainer *con;
    int inst = 0;
    //while ((con = GetContainer(InputGroup(nName, inst++))) != NULL) {
    //if ((con = GetContainer (InputGroup(nName))) != NULL) {
    //while ((con = GetContainer(InputGroup(translationGroupName, inst++))) != NULL) {
    //if ((con = GetContainer (InputGroup(translationGroupName))) != NULL) {

    PvlKeyword grp;
    while((grp = InputGroup(nName, inst++)).name() != "") {
    while((grp = InputGroup(translationGroupName, inst++)).name() != "") {
      if((con = GetContainer(grp)) != NULL) {
        if(con->hasKeyword(InputKeywordName(nName))) return true;
        if(con->hasKeyword(InputKeywordName(translationGroupName))) return true;
      }
    }

@@ -340,10 +354,17 @@ namespace Isis {

  /**
   * Create the requsted container and any containers above it and
   * return a reference to the container
   * list is an PvlKeyword with an array of container types an their names
   * return a reference to the container. List is a PvlKeyword 
   * with an array of container types and their names. 
   *  
   * @param translationGroupName The name of the PVL translation 
   *                        group used to identify the
   *                        input/output keywords to be
   *                        translated. Often, this is the
   *                        same as the output keyword name.
   * @param pvl Pvl 
   */
  PvlContainer *PvlToPvlTranslationManager::CreateContainer(const QString nName, Pvl &pvl) {
    return LabelTranslationManager::CreateContainer(nName, pvl);
  PvlContainer *PvlToPvlTranslationManager::CreateContainer(const QString translationGroupName, Pvl &pvl) {
    return LabelTranslationManager::CreateContainer(translationGroupName, pvl);
  }
} // end namespace isis
+7 −6
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ namespace Isis {
   *                          PvlToPvlTranslationManager. Fixes #4901.
   *  @history 2018-01-10 Christopher Combs - Changed ProcessDataFilePointer call to reflect 
   *                          changes made to voy2isis. Fixes #4345, #4421.
   *  @history 2018-04-16 Jeannie Backer - Fixed indentation of history comments.
   *  @history 2018-04-16 Jeannie Backer - Fixed indentation of history comments and
   *                          brought code closer to coding standards.
   *  @todo 2005-02-15 Stuart Sides - add coded example and implementation example
   *                          to class documentation, and finish
   *                          documentation.
@@ -92,24 +93,24 @@ namespace Isis {

      // Attempt to translate the requested output name to output value
      // using the input name and value/default value
      virtual QString Translate(QString nName, int findex = 0);
      virtual QString Translate(QString translationGroupName, int findex = 0);

      // Translate all translation table groups which contain "Auto"
      void Auto(Pvl &outputLabel);
      void Auto(Pvl &inputLabel, Pvl &outputLabel);

      // Return the ith input value associated with a output name
      virtual const PvlKeyword &InputKeyword(const QString nName) const;
      virtual const PvlKeyword &InputKeyword(const QString translationGroupName) const;

      // Return true if the input lable contains the translated group and key names
      virtual bool InputHasKeyword(const QString nName);
      virtual bool InputHasKeyword(const QString translationGroupName);

      void SetLabel(Pvl &inputLabel);

    protected:
      virtual PvlKeyword DoTranslation(const QString nName);
      virtual PvlKeyword DoTranslation(const QString translationGroupName);
      virtual const PvlContainer *GetContainer(const PvlKeyword &inputGroup) const;
      virtual PvlContainer *CreateContainer(const QString nName, Pvl &pvl);
      virtual PvlContainer *CreateContainer(const QString translationGroupName, Pvl &pvl);
    private:
      Pvl p_fLabel; //!< A Pvl object for the input label file
  };
+53 −13

File changed.

Preview size limit exceeded, changes collapsed.

Loading