Commit 477eba24 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Updated ImportPdsTable class with changes to support isisminer. Fixes #2397.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6587 41f8697f-d340-4b68-9986-7bafba869bb8
parent 27cddd71
Loading
Loading
Loading
Loading
+254 −66

File changed.

Preview size limit exceeded, changes collapsed.

+41 −15
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
 */

#include <QString>
#include <QList>
#include <QStringList>

#include <fstream>
#include <vector>
@@ -95,6 +97,11 @@ namespace Isis {
   *                           binary PDS tables. Changed method name from
   *                           "exportAsTable" to "importTable". Improved
   *                           unitTest coverage. References #700.
   *   @history 2015-07-17 Kris Becker - Declare destructor as virtual to make
   *                           it iheritable. Reorganized to support interception
   *                           of storage methods for derivedŒ class use.
   *   @history 2016-02-24 Ian Humphrey - Updated documentation and unit test. Added edrindex.lbl
   *                           and edrindex.tab files to data directory (for tests). Fixes #2397.
   *  
   *  
   * @todo The binary table import methods were written after the ascii table 
@@ -109,12 +116,16 @@ namespace Isis {
      ImportPdsTable(const QString &pdsLabFile, 
                     const QString &pdsTabFile="",
                     const QString &pdsTableName ="TABLE");
      ~ImportPdsTable();
      virtual ~ImportPdsTable();

      QString name() const;
      void setName(const QString &name = "TABLE");

      int columns() const;
      int rows() const;

      void load(const QString &pdsLabFile, const QString &pdsTabFile = "");
      void load(const QString &pdsLabFile, const QString &pdsTabFile = "", 
                const QString &pdsTableName = "TABLE");

      bool hasColumn(const QString &colName) const;
      QString getColumnName(const unsigned int &index = 0, 
@@ -131,34 +142,50 @@ namespace Isis {
      Table importTable(const QStringList &colNames,
                        const QString &isisTableName);

    private:

  protected:
      struct ColumnDescr {
        QString m_name;       //!< Name of column
        int     m_colnum;     //!< Column number
        QString m_dataType;   //!< PDS table DATA_TYPE of column
        int     m_startByte;  //!< Starting byte of data
        int     m_numBytes;   //!< Number bytes in column
        int         m_itemBytes;  //!<
        int     m_itemBytes;  //!< Number bytes per item 
        int     m_items;      //!< Number of items in column
      };

      typedef std::vector<ColumnDescr> ColumnTypes;
      typedef std::vector<QString>     Columns;
      typedef std::vector<Columns>     Rows;
      // Internal types
      typedef QList<ColumnDescr> ColumnTypes;
      typedef QStringList        Columns;
      typedef QList<Columns>     Rows;

      void init();

      void loadLabel(const QString &labfile, QString &tblfile);
      void loadTable(const QString &tabfile);

      ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const;
      const ColumnDescr &getColumnDescriptor(const int &nth) const;
      ColumnDescr *findColumn(const QString &colName);
      const ColumnDescr *findColumn(const QString &colName) const;


      QString getColumnValue(const QString &tline,
                                 const ColumnDescr &cdesc) const;
                             const ColumnDescr &cdesc,
                             const QString &delimiter = "") const;
      QStringList getColumnFields(const QString &tline,
                                  const ColumnDescr &cdesc,
                                  const QString &delimiter = "") const;


      QString getGenericType(const QString &ttype) const;

      virtual bool processRow(const int &row, const QString &rowdata);


  private:
      void init();

      void loadLabel(const QString &labfile, QString &tblfile,
                     const QString &tblname = "");
      void loadTable(const QString &tabfile);

      ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const;

      TableRecord makeRecord(const ColumnTypes &ctypes);
      TableField makeField(const ColumnDescr &cdesc);
      TableField makeFieldFromBinaryTable(const ColumnDescr &cdesc);
@@ -185,7 +212,6 @@ namespace Isis {
      int      m_pdsTableStart; //!< The start byte of the PDS table data.
      QString  m_byteOrder;     /**< The byte order of the PDS table file, if 
                                     binary. Valid values are "MSB" or "LSB".*/

  };

}
+54 −3
Original line number Diff line number Diff line
@@ -93,6 +93,50 @@ Double Value Integer Value Text Value Real Value
3.14159			3				PI			3.1428570747375
2.71828			2				e			2.0



Testing name() (default TABLE): TABLE

Testing setName("My Table"): My Table


Testing ImportPdsTable protected methods with file data/edrindex.lbl

Constructing new ImportPdsTable where the PDS table object name is INDEX_TABLE

Testing getColumnFields...

Column TELEMETRY_SOURCE_NAME items: 1
  030_009_f0006-000-0000_003_0128278505-223.dat               

Column Description for this column: 
m_name: TELEMETRY_SOURCE_NAME
m_colnum: 42
m_dataType: CHARACTER
m_startByte: 658
m_numBytes: 60
m_itemBytes: 60
m_items: 1


Column ROVER_MOTION_COUNTER items: 5
  0     
  0     
  0     
  0     
  0     

Column Description for this column: 
m_name: ROVER_MOTION_COUNTER
m_colnum: 43
m_dataType: INTEGER
m_startByte: 720
m_numBytes: 34
m_itemBytes: 6
m_items: 5



Throw error for invalid table file name: 
**ERROR** Unable to import PDS table.  Neither of the following possible table files were found: [INVALID_TABLE_FILE_NAME.DAT]  or [./invalid_table_file_name.dat].
**ERROR** Failed to convert string [INVALID_TABLE_FILE_NAME] to an integer.
@@ -100,8 +144,8 @@ Throw error for invalid table file name:
Throw error for attempt to access invalid column index: 
**PROGRAMMER ERROR** Unable to import the binary PDS table [TABLE] into Isis. The requested column index [5] exceeds the last column index [3].

Throw error for attempt to export non-existant columns: 
**PROGRAMMER ERROR** Unable to import the PDS table [TABLE] into Isis. The requested column name [Invalid Column Name] does not exist in table.
Throw error for attempt to export non-existent columns: 
**PROGRAMMER ERROR** Unable to import the PDS table [My Table] into Isis. The requested column name [Invalid Column Name] does not exist in table.

Throw error for missing table location in label file:
**ERROR** The PDS file data/lsb_pds_binary_table.lbl does not have the required TABLE object, [MISSING_TABLE]. The PDS label file is probably invalid.
@@ -140,7 +184,14 @@ Throw error for invalid column DATA_TYPE in label file:

Throw error for inconsistent byte order in label file: 
**ERROR** Unable to import the PDS table [TABLE] from the PDS file [data/lsb_pds_binary_table.dat] into Isis.
**ERROR** Unable import the binary PDS table [TABLE]. The column DATA_TYPE values indicate differing byte orders.
**ERROR** Unable to import the binary PDS table [TABLE]. The column DATA_TYPE values indicate differing byte orders.

Throw error if index used to request a column description 
is greater than the number of columns in the table: 
**PROGRAMMER ERROR** Index (100) into Columns invalid (max: 48).

Throw error if index used to request a column description is less than 0: 
**PROGRAMMER ERROR** Index (-1) into Columns invalid (max: 48).

cols = 4
rows = 0
+580 −0

File added.

Preview size limit exceeded, changes collapsed.

+9 −0
Original line number Diff line number Diff line
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278505EDN0000F0006N0M1"	2004-06-03T06:54:46Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:53:53Z	2004-01-25T04:53:53Z	2004-01-25T20:03:12Z	2004-01-25T20:03:52Z	"128278505.871                 "	"128278505.876                 "	"f0006                         "	"0                   "	"13:11:46    "	256 	1024	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000000  "	"REGULAR   "	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	45.176601 	45.176601 	0.000000  	0.000000  	0.000000  	0.000000  	248.587006 	70.908096  	-20.900101 	30  	"030_009_f0006-000-0000_003_0128278505-223.dat               "	0     	0     	0     	0     	0     	"0"	"0"	4   	1   
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278505ERP0000F0006N0M1"	2004-06-03T06:54:41Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:53:53Z	2004-01-25T04:53:53Z	2004-01-25T20:03:11Z	2004-01-25T20:03:12Z	"128278505.871                 "	"128278505.876                 "	"f0006                         "	"0                   "	"13:11:46    "	1024	32  	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000000  "	"REF_PIXELS"	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	1.411770  	180.705994	0.000000  	0.000000  	0.000000  	0.000000  	248.587006 	70.908096  	-20.900101 	30  	"030_012_f0006-000-0000_003_0128278505-223.dat               "	0     	0     	0     	0     	0     	"0"	"0"	4   	1   
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278505ETH0000F0006N0M1"	2004-06-06T07:04:48Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:53:53Z	2004-01-25T04:53:53Z	2004-01-26T08:59:22Z	2004-01-26T08:59:22Z	"128278505.871                 "	"128278505.876                 "	"f0006                         "	"0                   "	"13:11:46    "	64  	64  	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000000  "	"THUMBNAIL "	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	45.176601 	45.176601 	0.000000  	0.000000  	0.000000  	0.000000  	248.587006 	70.908096  	-20.900101 	30  	"030_003_f0006-000-0000_002_0128278505-223.dat               "	0     	0     	0     	0     	0     	"0"	"0"	16  	16  
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278509EDN0000F0006N0M1"	2004-06-03T06:55:00Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:53:56Z	2004-01-25T04:53:56Z	2004-01-25T20:03:54Z	2004-01-25T20:22:15Z	"128278509.621                 "	"128278509.626                 "	"f0006                         "	"0                   "	"13:11:50    "	256 	1024	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000001  "	"REGULAR   "	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	45.176601 	45.176601 	0.000000  	0.000000  	0.000000  	0.000000  	248.602997 	70.893997  	-20.900101 	30  	"030_009_f0006-000-0000_003_0128278509-159.dat               "	0     	0     	0     	0     	0     	"0"	"0"	4   	1   
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278509ERP0000F0006N0M1"	2004-06-03T06:54:51Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:53:56Z	2004-01-25T04:53:56Z	2004-01-25T20:03:52Z	2004-01-25T20:03:54Z	"128278509.621                 "	"128278509.626                 "	"f0006                         "	"0                   "	"13:11:50    "	1024	32  	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000001  "	"REF_PIXELS"	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	1.411770  	180.705994	0.000000  	0.000000  	0.000000  	0.000000  	248.602997 	70.893997  	-20.900101 	30  	"030_012_f0006-000-0000_003_0128278509-159.dat               "	0     	0     	0     	0     	0     	"0"	"0"	4   	1   
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278509ETH0000F0006N0M1"	2004-06-06T07:04:51Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:53:56Z	2004-01-25T04:53:56Z	2004-01-26T08:59:22Z	2004-01-26T08:59:22Z	"128278509.621                 "	"128278509.626                 "	"f0006                         "	"0                   "	"13:11:50    "	64  	64  	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000001  "	"THUMBNAIL "	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	45.176601 	45.176601 	0.000000  	0.000000  	0.000000  	0.000000  	248.602997 	70.893997  	-20.900101 	30  	"030_003_f0006-000-0000_002_0128278509-159.dat               "	0     	0     	0     	0     	0     	"0"	"0"	16  	16  
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278513EDN0000F0006N0M1"	2004-06-03T06:55:10Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:54:00Z	2004-01-25T04:54:00Z	2004-01-25T20:22:16Z	2004-01-25T20:22:30Z	"128278513.371                 "	"128278513.376                 "	"f0006                         "	"0                   "	"13:11:53    "	256 	1024	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000002  "	"REGULAR   "	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	45.176601 	45.176601 	0.000000  	0.000000  	0.000000  	0.000000  	248.617996 	70.879799  	-20.900101 	30  	"030_009_f0006-000-0000_003_0128278513-095.dat               "	0     	0     	0     	0     	0     	"0"	"0"	4   	1   
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278513ERP0000F0006N0M1"	2004-06-03T06:55:05Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:54:00Z	2004-01-25T04:54:00Z	2004-01-25T20:22:15Z	2004-01-25T20:22:16Z	"128278513.371                 "	"128278513.376                 "	"f0006                         "	"0                   "	"13:11:53    "	1024	32  	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000002  "	"REF_PIXELS"	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	1.411770  	180.705994	0.000000  	0.000000  	0.000000  	0.000000  	248.617996 	70.879799  	-20.900101 	30  	"030_012_f0006-000-0000_003_0128278513-095.dat               "	0     	0     	0     	0     	0     	"0"	"0"	4   	1   
"mer1do_0xxx"	"MER1-M-DESCAM-2-EDR-OPS-V1.0            "	"MER1"	"DESCAM            "	"0001"	"1E128278513ETH0000F0006N0M1"	2004-06-06T07:04:53Z	"MARS  "	"PRIMARY MISSION               "	1   	2004-01-25T04:54:00Z	2004-01-25T04:54:00Z	2004-01-26T08:59:23Z	2004-01-26T08:59:23Z	"128278513.371                 "	"128278513.376                 "	"f0006                         "	"0                   "	"13:11:53    "	64  	64  	1   	1   	"123 "	"4X1SUMMATION_FRAME  "	"4000000002  "	"THUMBNAIL "	5.120000     	"NONE                  "	0   	"MONO "	"MONO  "	45.176601 	45.176601 	0.000000  	0.000000  	0.000000  	0.000000  	248.617996 	70.879799  	-20.900101 	30  	"030_003_f0006-000-0000_002_0128278513-095.dat               "	0     	0     	0     	0     	0     	"0"	"0"	16  	16  
Loading