Isis 3 Programmer Reference
ImportPdsTable.cpp
Go to the documentation of this file.
1 
22 #include "ImportPdsTable.h"
23 
24 #include <cctype>
25 #include <iomanip>
26 #include <iostream>
27 #include <sstream>
28 
29 #include <QDebug>
30 #include <QScopedPointer>
31 #include <QString>
32 
33 #include "EndianSwapper.h"
34 #include "FileName.h"
35 #include "IString.h"
36 #include "Pvl.h"
37 #include "PvlObject.h"
38 #include "Table.h"
39 #include "TableField.h"
40 #include "TableRecord.h"
41 #include "TextFile.h"
42 
43 
44 using namespace std;
45 
46 namespace Isis {
47 
48 
58  ImportPdsTable::ImportPdsTable() {
59  // just inititalize the member variables
60  init();
61  m_tableName = "TABLE";
62  }
63 
64 
88  ImportPdsTable::ImportPdsTable(const QString &pdsLabFile,
89  const QString &pdsTableFile,
90  const QString &pdsTableName) {
91  m_tableName = pdsTableName;
92  load(pdsLabFile, pdsTableFile, pdsTableName);
93  }
94 
95 
99  ImportPdsTable::~ImportPdsTable() {
100  }
101 
102 
104  QString ImportPdsTable::name() const {
105  return (m_tableName);
106  }
107 
113  void ImportPdsTable::setName(const QString &name) {
114  m_tableName = name;
115  return;
116  }
117 
118 
147  void ImportPdsTable::load(const QString &pdsLabFile,
148  const QString &pdsTableFile,
149  const QString &pdsTableName) {
150 
151  init();
152  QString tempTblFile;
153  loadLabel(pdsLabFile, tempTblFile, pdsTableName);
154  if (!pdsTableFile.isEmpty()) tempTblFile = pdsTableFile;
155  // Vet the table filename. Many PDS files record the filename in
156  // uppercase and in practice, the filename is in lowercase. Do this
157  // check here.
158  FileName tableFile(tempTblFile);
159  try {
160  int tableStartRecord = toInt(tableFile.baseName());
161  tempTblFile = pdsLabFile;
162  m_pdsTableStart = tableStartRecord;
163  }
164  catch (IException &e) {
165  // if we are unable to cast the table file value to an integer, it must be a
166  // file name, not a location in the label file.
167  if (!tableFile.fileExists()) {
168  // if the table file name doesn't exist, try lowercased version...
169  FileName tableFileLowercase(tableFile.path() + "/"
170  + tableFile.name().toLower());
171  if (!tableFileLowercase.fileExists()) {
172  IString msg = "Unable to import PDS table. Neither of the following "
173  "possible table files were found: ["
174  + tableFile.expanded() + "] or ["
175  + tableFileLowercase.expanded() + "]";
176  throw IException(e, IException::Unknown, msg, _FILEINFO_);
177  }
178  tableFile = tableFileLowercase.expanded();
179  tempTblFile = tableFile.expanded();
180  }
181  m_pdsTableStart = 1;
182  }
183  if (m_pdsTableType == "ASCII") {
184  loadTable(tempTblFile);
185  }
186  m_pdsTableFile = tempTblFile;
187  return;
188  }
189 
190 
201  bool ImportPdsTable::hasColumn(const QString &colName) const {
202  return (findColumn(colName) != 0);
203  }
204 
205 
226  QString ImportPdsTable::getColumnName(const unsigned int &index,
227  const bool &formatted) const {
228  if ((int) index >= columns() - 1) {
229  QString msg = "Unable to import the binary PDS table [" + m_tableName
230  + "] into Isis. The requested column index ["
231  + toString((int) index) + "] exceeds the last column index ["
232  + toString(columns() - 1) + "]";
233  throw IException(IException::Programmer, msg.toStdString(), _FILEINFO_);
234  }
235  QString name = m_coldesc[index].m_name;
236  if (formatted) name = getFormattedName(name);
237  return (name);
238  }
239 
240 
257  QStringList ImportPdsTable::getColumnNames(const bool &formatted) const {
258  QStringList colnames;
259  for (int i = 0 ; i < columns() ; i++) {
260  QString name = m_coldesc[i].m_name;
261  if (formatted) name = getFormattedName(name);
262  colnames.push_back(name);
263  }
264  return (colnames);
265  }
266 
267 
283  QString ImportPdsTable::getType(const QString &colName) const {
284  const ColumnDescr *column = findColumn(colName);
285  QString dtype("");
286  if (column != 0) {
287  dtype = column->m_dataType;
288  }
289  return (dtype);
290  }
291 
292 
310  bool ImportPdsTable::setType(const QString &colName,
311  const QString &dataType) {
312  ColumnDescr *column = findColumn(colName);
313  if (column != 0) {
314  column->m_dataType = dataType.toUpper();
315  }
316  return (column != 0);
317  }
318 
319 
333  Table ImportPdsTable::importTable(const QString &isisTableName) {
334  try {
335  TableRecord record = makeRecord(m_coldesc);
336  Table table(isisTableName, record);
337  fillTable(table, m_coldesc, record);
338  return (table);
339  }
340  catch (IException &e) {
341  QString msg = "Unable to import the PDS table [" + m_tableName
342  + "] from the PDS file [" + m_pdsTableFile + "] into Isis.";
343  throw IException(e, IException::Unknown, msg.toStdString(), _FILEINFO_);
344 
345  }
346  }
347 
348 
365  Table ImportPdsTable::importTable(const QString &colnames,
366  const QString &isisTableName) {
367  return (importTable(colnames.split(","), isisTableName));
368  }
369 
370 
388  Table ImportPdsTable::importTable(const QStringList &colnames,
389  const QString &isisTableName) {
390  ColumnTypes ctypes;
391  for (int i = 0 ; i < colnames.size() ; i++) {
392  const ColumnDescr *descr = findColumn(colnames[i]);
393  if (!descr) {
394  QString msg = "Unable to import the PDS table [" + m_tableName
395  + "] into Isis. The requested column name ["
396  + colnames[i] + "] does not "
397  "exist in table.";
398  throw IException(IException::Programmer, msg.toStdString(), _FILEINFO_);
399  }
400  ctypes.push_back(*descr);
401  }
402 
403  // Create and populate the table
404  TableRecord record = makeRecord(ctypes);
405  Table table(isisTableName, record);
406  fillTable(table, ctypes, record);
407  return (table);
408  }
409 
410 
416  void ImportPdsTable::init() {
417 
418  m_byteOrder = "";
419  m_trows = 0;
420  m_pdsTableStart = 0;
421  m_coldesc.clear();
422  m_rows.clear();
423  m_pdsTableType = "";
424  m_pdsTableFile = "";
425  return;
426  }
427 
428 
453  void ImportPdsTable::loadLabel(const QString &pdsLabFile,
454  QString &pdsTableFile,
455  const QString &tblname) {
456 
457  Isis::Pvl label(pdsLabFile);
458 
459  QString tableName = ( tblname.isEmpty() ) ? m_tableName : tblname;
460  if (!label.hasObject(tableName)) {
461  QString msg = "The PDS file " + pdsLabFile +
462  " does not have the required TABLE object, ["
463  + tableName +"]. The PDS label file is probably invalid";
464  throw IException(IException::Unknown, msg.toStdString(), _FILEINFO_);
465  }
466  // Get some pertinent information from the label
467  PvlObject &tabObj = label.findObject(tableName);
468  // The table description contains the actual "RECORD_BYTES"
469  if (tabObj.hasKeyword("RECORD_BYTES")) {
470  m_recordBytes = (int) tabObj.findKeyword("RECORD_BYTES");
471  }
472  // The table description has "ROW_BYTES" and "ROW_SUFFIX_BYTES". These summed is the
473  // record length. Can be for detached and attached labels
474  else if (tabObj.hasKeyword("ROW_BYTES") && tabObj.hasKeyword("ROW_SUFFIX_BYTES")) {
475  m_recordBytes = (int) tabObj.findKeyword("ROW_BYTES") +
476  (int) tabObj.findKeyword("ROW_SUFFIX_BYTES");
477  }
478  // The table record length is defined by the file record
479  // length (i.e., table is in with the image)
480  else {
481  m_recordBytes = (int) label.findKeyword("RECORD_BYTES");
482  }
483 
484  QString trueTableName;
485  PvlObject *tableDetails = &tabObj;
486  if (label.hasKeyword("^" + tableName)) {
487  trueTableName = tableName;
488  pdsTableFile = FileName(pdsLabFile).path() + "/"
489  + label["^" + tableName][0];
490  }
491  else if (tabObj.objects() == 1) {
492  trueTableName = tabObj.object(0).name();
493  tableDetails = &tabObj.object(0);
494  pdsTableFile = FileName(pdsLabFile).path() + "/"
495  + tabObj["^" + trueTableName][0];
496  }
497  m_trows = (int) tableDetails->findKeyword("ROWS");
498  int ncols = (int) tableDetails->findKeyword("COLUMNS");
499  m_pdsTableType = QString(tableDetails->findKeyword("INTERCHANGE_FORMAT"));
500  if (m_pdsTableType != "ASCII" && m_pdsTableType.toUpper() != "BINARY") {
501  QString msg = "Unable to import the PDS table [" + tableName
502  + "] from the PDS file ["
503  + pdsTableFile + "] into Isis. "
504  "The PDS INTERCHANGE_FORMAT [" + m_pdsTableType
505  + "] is not supported. Valid values are ASCII or BINARY.";
506  throw IException(IException::User, msg.toStdString(), _FILEINFO_);
507  }
508  m_rowBytes = tableDetails->findKeyword("ROW_BYTES");
509 
510  m_coldesc.clear();
511  PvlObject::PvlObjectIterator colobj = tableDetails->beginObject();
512  int icol(0);
513  while (colobj != tableDetails->endObject()) {
514  if (colobj->isNamed("COLUMN")) {
515  m_coldesc.push_back(getColumnDescription(*colobj, icol));
516  icol++;
517  }
518  ++colobj;
519  }
520 
521  // Test to ensure columns match the number listed in the label
522  if (ncols != columns()) {
523  ostringstream msg;
524  msg << "Number of columns in the COLUMNS label keyword (" << ncols
525  << ") does not match number of COLUMN objects found ("
526  << columns() << ")";
527  cout << msg.str() << endl;
528  }
529  return;
530  }
531 
532 
549  void ImportPdsTable::loadTable(const QString &pdsTableFile) {
550 
551  // Vet the filename. Many PDS files record the filename in uppercase and
552  // in practice, the filename is in lowercase. Do this check here.
553  QString tempTblFile(pdsTableFile);
554  TextFile tfile(tempTblFile);
555  QString tline;
556  m_rows.clear();
557  int irow(0);
558  while (tfile.GetLine(tline, false)) {
559  if (irow >= m_trows) break;
560 
561  (void) processRow(irow, tline);
562 
563  irow++;
564  }
565  return;
566  }
567 
568 
587  ImportPdsTable::getColumnDescription(PvlObject &colobj, int nth) const {
588  ColumnDescr cd;
589  cd.m_name = colobj["NAME"][0];
590  cd.m_colnum = nth; // 0-based indexing, will be COLUMN_NUM - 1
591 
592  if (m_pdsTableType == "ASCII") {
593  cd.m_dataType = getGenericType(colobj["DATA_TYPE"][0]).toUpper();
594  }
595  else {
596  cd.m_dataType = colobj["DATA_TYPE"][0].toUpper();
597  }
598 
599  cd.m_startByte = ((int) colobj["START_BYTE"]) - 1; // 0-based indexing
600  cd.m_numBytes = (int) colobj["BYTES"];
601 
602 
603  cd.m_itemBytes = cd.m_numBytes;
604  if ( colobj.hasKeyword("ITEM_BYTES") ) {
605  cd.m_itemBytes = (int) colobj["ITEM_BYTES"];
606  }
607 
608  cd.m_items = 1;
609  if ( colobj.hasKeyword("ITEMS") ) {
610  cd.m_items = (int) colobj["ITEMS"];
611  }
612 
613  return (cd);
614  }
615 
616 
629  const ImportPdsTable::ColumnDescr &ImportPdsTable::getColumnDescriptor(const int &nth) const {
630 
631  // Ensure the nrequested column is valid
632  if ( (nth >= columns()) || ( nth < 0) ) {
633  QString mess = "Index (" + QString::number(nth) +
634  ") into Columns invalid (max: " + QString::number(columns()) + ")";
635  throw IException(IException::Programmer, mess, _FILEINFO_);
636  }
637 
638  // All good, return the expected
639  return (m_coldesc[nth]);
640  }
641 
642 
657  ImportPdsTable::ColumnDescr *ImportPdsTable::findColumn(const QString &colName) {
658  QString cName = getFormattedName(colName);
659  ColumnTypes::iterator col = m_coldesc.begin();
660  while (col != m_coldesc.end()) {
661  QString c = getFormattedName(col->m_name);
662  if (c.toUpper() == cName.toUpper()) { return (&(*col)); }
663  col++;
664  }
665  return (0);
666  }
667 
668 
683  const ImportPdsTable::ColumnDescr *ImportPdsTable::findColumn(const QString &colName) const {
684  QString cName = getFormattedName(colName);
685  ColumnTypes::const_iterator col = m_coldesc.begin();
686  while (col != m_coldesc.end()) {
687  QString c = getFormattedName(col->m_name);
688  if (c.toUpper() == cName.toUpper()) { return (&(*col)); }
689  col++;
690  }
691  return (0);
692  }
693 
694 
705  QString ImportPdsTable::getColumnValue(const QString &tline,
706  const ColumnDescr &cdesc,
707  const QString &delimiter) const {
708  return (tline.mid(cdesc.m_startByte, cdesc.m_numBytes));
709  }
710 
711 
727  QStringList ImportPdsTable::getColumnFields(const QString &tline,
728  const ColumnDescr &cdesc,
729  const QString &delimiter) const {
730 
731  // If item count is 1, simply return the whole column
732  QString value = getColumnValue(tline, cdesc, delimiter);
733  if ( 1 == cdesc.m_items) return ( QStringList(value) );
734 
735  // If there is no item size specified, see if we should seperate with
736  // delimiter
737  if ( 0 == cdesc.m_itemBytes ) {
738  if ( delimiter.isEmpty() ) return ( QStringList(value));
739 
740  return ( value.split(delimiter, QString::SkipEmptyParts) );
741  }
742 
743  // Have an item size specified. Assume it has single character separator
744  QStringList fields;
745  int pos = 0;
746  for (int i = 0 ; i < cdesc.m_items ; i++) {
747  fields.push_back(value.mid(pos, cdesc.m_itemBytes));
748  pos += cdesc.m_itemBytes + 1;
749  }
750 
751  return (fields);
752  }
753 
754 
774  QString ImportPdsTable::getFormattedName(const QString &colname) const {
775  QString cname = QString(colname).replace(QRegExp("[(),]"), " ").simplified();
776 
777  bool uppercase = true;
778  QString oString;
779  for (int i = 0 ; i < cname.size() ; i++) {
780  if (uppercase) {
781  oString.push_back(cname[i].toUpper());
782  uppercase = false;
783  }
784  else if ( (cname[i] == ' ') || (cname[i] == '_') ) {
785  uppercase = true;
786  }
787  else {
788  oString.push_back(cname[i].toLower());
789  }
790  }
791 
792  return (oString);
793  }
794 
795 
813  QString ImportPdsTable::getGenericType(const QString &ttype) const {
814  return ttype.split("_").last();
815  }
816 
817 
835  TableField ImportPdsTable::makeField(const ColumnDescr &cdesc) {
836  QString dtype = cdesc.m_dataType;
837  QString name = getFormattedName(cdesc.m_name);
838  if (m_pdsTableType == "ASCII") {
839  if ( dtype == "INTEGER" ) {
840  return (TableField(name, TableField::Integer));
841  }
842  else if ( ((dtype == "DOUBLE")
843  || (dtype == "REAL")
844  || (dtype == "FLOAT")) ) {
845  return (TableField(name, TableField::Double));
846  }
847  else {
848  return (TableField(name, TableField::Text, cdesc.m_numBytes));
849  }
850  }
851  else {
852  return makeFieldFromBinaryTable(cdesc);
853  }
854  }
855 
856 
871  TableRecord ImportPdsTable::makeRecord(const ColumnTypes &ctypes) {
872  TableRecord rec;
873  for (int i = 0 ; i < ctypes.size() ; i++) {
874  TableField field = makeField(ctypes[i]);
875  rec += field;
876  }
877  return (rec);
878  }
879 
880 
897  TableField &ImportPdsTable::extract(const Columns &cols,
898  const ColumnDescr &cdesc,
899  TableField &tfield) const {
900  int ith = cdesc.m_colnum;
901  try {
902  IString data(cols[ith]);
903  if (tfield.isInteger()) {
904  data.Trim(" \t\r\n");
905  tfield = data.ToInteger();
906  }
907  else if (tfield.isDouble()) {
908  data.Trim(" \t\r\n");
909  tfield = data.ToDouble();
910  }
911  else { // Its a text field
912  QString str(tfield.size(), ' ');
913  str.insert(0, data.Trim(" \t\r\n").ToQt());
914  tfield = str;
915  }
916  }
917  catch (IException &e) {
918  QString msg = "Conversion failure of column " + cdesc.m_name;
919  throw IException(e, IException::Programmer, msg, _FILEINFO_);
920  }
921 
922  return (tfield);
923  }
924 
925 
940  TableRecord &ImportPdsTable::extract(const Columns &cols,
941  const ColumnTypes &ctypes,
942  TableRecord &record) const {
943  for (int i = 0 ; i < ctypes.size() ; i++) {
944  extract(cols, ctypes[i], record[i]);
945  }
946  return (record);
947  }
948 
949 
965  void ImportPdsTable::fillTable(Table &table,
966  const ColumnTypes &cols,
967  TableRecord &record) const {
968  if (m_pdsTableType == "ASCII") {
969  for (int i = 0 ; i < m_rows.size() ; i++) {
970  try {
971  table += extract(m_rows[i], cols, record);
972  }
973  catch (IException &e) {
974  QString msg = "Failed to convert data in row [" + toString((int) i) + "]";
975  throw IException(e, IException::Programmer, msg, _FILEINFO_);
976  }
977  }
978  }
979 
980  else {
981  QString tempTblFile = m_pdsTableFile;
982  ifstream pdsFileStream(tempTblFile.toLatin1().data(), ifstream::binary);
983 
984  if (!pdsFileStream) {
985  IString msg = "Unable to open file containing PDS table ["
986  + tempTblFile + "].";
987  throw IException(IException::Unknown, msg, _FILEINFO_);
988  }
989 
990  // read and discard the rows above the table data
991  QScopedPointer<char, QScopedPointerArrayDeleter<char> > rowBuffer(new char[m_recordBytes]);
992  for (int i = 1; i < m_pdsTableStart; i++) {
993  pdsFileStream.read(rowBuffer.data(), m_recordBytes);
994  }
995  // now, import and add the records to the table
996  for (int rowIndex = 0; rowIndex < m_trows; rowIndex++) {
997  pdsFileStream.read(rowBuffer.data(), m_recordBytes);
998  TableRecord rec = extractBinary(rowBuffer.data(), record);
999  table += rec;
1000  }
1001  }
1002 
1003  return;
1004  }
1005 
1006 
1014  int ImportPdsTable::columns() const {
1015  return (m_coldesc.size());
1016  }
1017 
1018 
1026  int ImportPdsTable::rows() const {
1027  return (m_rows.size());
1028  }
1029 
1030 
1046  TableRecord ImportPdsTable::extractBinary(char *rowBuffer, TableRecord &record) const {
1047  // for each record loop through the columns to get field values
1048  for (int colIndex = 0; colIndex < columns(); colIndex++) {
1049  QString columnName = m_coldesc[colIndex].m_name;
1050  for (int fieldIndex = 0 ; fieldIndex < record.Fields() ; fieldIndex++) {
1051  QString fieldName = record[fieldIndex].name();
1052  if (fieldName == columnName) {
1053  int startByte = m_coldesc[colIndex].m_startByte;
1054  int numBytes = m_coldesc[colIndex].m_numBytes;
1055 
1056  if (record[fieldIndex].isInteger()) {
1057  int columnValue;
1058  memmove(&columnValue, &rowBuffer[startByte], numBytes);
1059  EndianSwapper endianSwap(m_byteOrder);
1060  int fieldValue = endianSwap.Int(&columnValue);
1061  record[fieldIndex] = fieldValue;
1062  }
1063 
1064  else if (record[fieldIndex].isDouble()) {
1065  EndianSwapper endianSwap(m_byteOrder);
1066  double columnValue;
1067  memmove(&columnValue, &rowBuffer[startByte], numBytes);
1068  double fieldValue = endianSwap.Double(&columnValue);
1069  record[fieldIndex] = fieldValue;
1070  }
1071 
1072  else if (record[fieldIndex].isReal()) {
1073  EndianSwapper endianSwap(m_byteOrder);
1074  float columnValue;
1075  memmove(&columnValue, &rowBuffer[startByte], numBytes);
1076  float fieldValue = endianSwap.Float(&columnValue);
1077  record[fieldIndex] = fieldValue;
1078  }
1079 
1080  else if (record[fieldIndex].isText()) {
1081  QString fieldValue(numBytes, '\0');
1082  for (int byte = 0; byte < numBytes; byte++) {
1083  fieldValue[byte] = rowBuffer[startByte + byte];
1084  }
1085  record[fieldIndex] = fieldValue;
1086  }
1087 
1088  }
1089  }
1090  }
1091  return record;
1092  }
1093 
1094 
1117  TableField ImportPdsTable::makeFieldFromBinaryTable(const ColumnDescr &cdesc){
1118  QString dataType = cdesc.m_dataType;
1119  // For binary tables, we will not reformat the name of the column
1120  QString name = cdesc.m_name;
1121  if (dataType == "MSB_INTEGER" || dataType == "INTEGER"
1122  || dataType == "SUN_INTEGER" || dataType == "MAC_INTEGER") {
1123  if (cdesc.m_numBytes != 4) {
1124  QString msg = "Only 4 byte integer values are supported in Isis. "
1125  "PDS Column [" + cdesc.m_name
1126  + "] has an integer DATA_TYPE with [BYTES = "
1127  + toString(cdesc.m_numBytes) + "].";
1128  throw IException(IException::Unknown, msg, _FILEINFO_);
1129  }
1130  setPdsByteOrder("MSB");
1131  return TableField(name, TableField::Integer);
1132  }
1133  else if (dataType == "LSB_INTEGER" || dataType == "VAX_INTEGER"
1134  || dataType == "PC_INTEGER" ) {
1135  if (cdesc.m_numBytes != 4) {
1136  QString msg = "Only 4 byte integer values are supported in Isis. "
1137  "PDS Column [" + cdesc.m_name
1138  + "] has an integer DATA_TYPE with [BYTES = "
1139  + toString(cdesc.m_numBytes) + "].";
1140  throw IException(IException::Unknown, msg, _FILEINFO_);
1141  }
1142  setPdsByteOrder("LSB");
1143  return TableField(name, TableField::Integer);
1144  }
1145  else if (dataType == "FLOAT" //IEEE_REAL alias (MSB)
1146  || dataType == "REAL" //IEEE_REAL alias (MSB)
1147  || dataType == "SUN_REAL" //IEEE_REAL alias (MSB)
1148  || dataType == "MAC_REAL" //IEEE_REAL alias (MSB)
1149  || dataType == "IEEE_REAL" ) {
1150  setPdsByteOrder("MSB");
1151  if (cdesc.m_numBytes == 8) {
1152  return TableField(name, TableField::Double);
1153  }
1154  else if (cdesc.m_numBytes == 4) {
1155  return TableField(name, TableField::Real);
1156  }
1157  else {
1158  IString msg = "Only 4 byte or 8 byte real values are supported in Isis. "
1159  "PDS Column [" + cdesc.m_name
1160  + "] has a real DATA_TYPE with [BYTES = "
1161  + toString(cdesc.m_numBytes) + "].";
1162  throw IException(IException::Unknown, msg, _FILEINFO_);
1163  }
1164  }
1165  else if (dataType == "PC_REAL") {
1166  setPdsByteOrder("LSB");
1167  if (cdesc.m_numBytes == 8) {
1168  return TableField(name, TableField::Double);
1169  }
1170  else if (cdesc.m_numBytes == 4) {
1171  return TableField(name, TableField::Real);
1172  }
1173  else {
1174  QString msg = "Only 4 byte or 8 byte real values are supported in Isis. "
1175  "PDS Column [" + cdesc.m_name
1176  + "] has a real DATA_TYPE with [BYTES = "
1177  + toString(cdesc.m_numBytes) + "].";
1178  throw IException(IException::Unknown, msg, _FILEINFO_);
1179  }
1180  }
1181  else if (dataType.contains("CHARACTER")
1182  || dataType.contains("ASCII")
1183  || dataType == "DATE" || dataType == "TIME" ) {
1184  return TableField(name, TableField::Text, cdesc.m_numBytes);
1185  }
1186  // Isis3 tables currently don't support any of the following PDS DATA_TYPE:
1187  // BIT_STRING, COMPLEX, N/A, BOOLEAN, UNSIGNED_INTEGER, IBM types, some VAX types
1188  IString msg = "PDS Column [" + cdesc.m_name
1189  + "] has an unsupported DATA_TYPE ["
1190  + dataType + "].";
1191  throw IException(IException::Unknown, msg, _FILEINFO_);
1192  }
1193 
1194 
1206  void ImportPdsTable::setPdsByteOrder(QString byteOrder) {
1207  if (!m_byteOrder.isEmpty() && m_byteOrder != byteOrder) {
1208  QString msg = "Unable to import the binary PDS table [" + m_tableName
1209  + "]. The column DATA_TYPE values indicate differing byte "
1210  "orders. ";
1211  throw IException(IException::Unknown, msg.toStdString(), _FILEINFO_);
1212  }
1213  m_byteOrder = byteOrder;
1214  }
1215 
1216 
1227  bool ImportPdsTable::processRow(const int &row, const QString &rowdata) {
1228  Columns cols;
1229  for (int i = 0 ; i < columns() ; i++) {
1230  cols.push_back(getColumnValue(rowdata, m_coldesc[i]));
1231  }
1232  m_rows.append(cols);
1233 
1234  return (true);
1235  }
1236 
1237 } // namespace Isis
PvlObject & object(const int index)
Return the object at the specified index.
Definition: PvlObject.cpp:460
QString path() const
Returns the path of the file name.
Definition: FileName.cpp:119
float Float(void *buf)
Swaps a floating point value.
void clear()
Clears all values and units for this PvlKeyword object.
Definition: PvlKeyword.cpp:307
PvlObjectIterator endObject()
Returns the index of the ending object.
Definition: PvlObject.h:265
File name manipulation and expansion.
Definition: FileName.h:116
int objects() const
Returns the number of objects.
Definition: PvlObject.h:231
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
double ToDouble() const
Returns the floating point value the IString represents.
Definition: IString.cpp:814
int m_itemBytes
Number bytes per item.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
Namespace for the standard library.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:178
QString m_name
Name of column.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
int ToInteger() const
Returns the object string as an integer.
Definition: IString.cpp:733
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
Definition: PvlObject.cpp:207
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
Definition: PvlObject.h:335
QString name() const
Returns the container name.
Definition: PvlContainer.h:77
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
Definition: PvlObject.h:239
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Definition: PvlObject.cpp:148
bool isInteger() const
Determines whether the field type is Integer.
Definition: TableField.cpp:138
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
double Double(void *buf)
Swaps a double precision value.
Byte swapper.
Definition: EndianSwapper.h:55
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:884
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
Definition: TextFile.cpp:427
int size() const
Returns the number of values stored for the field at each record.
Definition: TableField.cpp:184
Container for cube-like labels.
Definition: Pvl.h:135
int m_items
Number of items in column.
Provides access to sequential ASCII stream I/O.
Definition: TextFile.h:54
QString baseName() const
Returns the name of the file without the path and without extensions.
Definition: FileName.cpp:161
Class for storing Table blobs information.
Definition: Table.h:77
int m_startByte
Starting byte of data.
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
int Fields() const
Returns the number of fields that are currently in the record.
Definition: TableRecord.cpp:94
Class for storing an Isis::Table&#39;s field information.
Definition: TableField.h:63
int m_numBytes
Number bytes in column.
bool isDouble() const
Determines whether the field type is Double.
Definition: TableField.cpp:148
QString m_dataType
PDS table DATA_TYPE of column.
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
PvlObjectIterator beginObject()
Returns the index of the beginning object.
Definition: PvlObject.h:247
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:465
IString Trim(const std::string &chars)
Removes characters from the beginning and end of the IString.
Definition: IString.cpp:540
int Int(void *buf)
Swaps a 4 byte integer value.