Isis 3 Programmer Reference
ImportPdsTable.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "ImportPdsTable.h"
8
9#include <cctype>
10#include <iomanip>
11#include <iostream>
12#include <sstream>
13
14#include <QDebug>
15#include <QScopedPointer>
16#include <QString>
17
18#include "EndianSwapper.h"
19#include "FileName.h"
20#include "IString.h"
21#include "Pvl.h"
22#include "PvlObject.h"
23#include "Table.h"
24#include "TableField.h"
25#include "TableRecord.h"
26#include "TextFile.h"
27
28
29using namespace std;
30
31namespace Isis {
32
33
44 // just inititalize the member variables
45 init();
46 m_tableName = "TABLE";
47 }
48
49
73 ImportPdsTable::ImportPdsTable(const QString &pdsLabFile,
74 const QString &pdsTableFile,
75 const QString &pdsTableName) {
76 m_tableName = pdsTableName;
77 load(pdsLabFile, pdsTableFile, pdsTableName);
78 }
79
80
86
87
89 QString ImportPdsTable::name() const {
90 return (m_tableName);
91 }
92
98 void ImportPdsTable::setName(const QString &name) {
100 return;
101 }
102
103
132 void ImportPdsTable::load(const QString &pdsLabFile,
133 const QString &pdsTableFile,
134 const QString &pdsTableName) {
135
136 init();
137 QString tempTblFile;
138 loadLabel(pdsLabFile, tempTblFile, pdsTableName);
139 if (!pdsTableFile.isEmpty()) tempTblFile = pdsTableFile;
140 // Vet the table filename. Many PDS files record the filename in
141 // uppercase and in practice, the filename is in lowercase. Do this
142 // check here.
143 FileName tableFile(tempTblFile);
144 try {
145 int tableStartRecord = toInt(tableFile.baseName());
146 tempTblFile = pdsLabFile;
147 m_pdsTableStart = tableStartRecord;
148 }
149 catch (IException &e) {
150 // if we are unable to cast the table file value to an integer, it must be a
151 // file name, not a location in the label file.
152 if (!tableFile.fileExists()) {
153 // if the table file name doesn't exist, try lowercased version...
154 FileName tableFileLowercase(tableFile.path() + "/"
155 + tableFile.name().toLower());
156 if (!tableFileLowercase.fileExists()) {
157 IString msg = "Unable to import PDS table. Neither of the following "
158 "possible table files were found: ["
159 + tableFile.expanded() + "] or ["
160 + tableFileLowercase.expanded() + "]";
161 throw IException(e, IException::Unknown, msg, _FILEINFO_);
162 }
163 tableFile = tableFileLowercase.expanded();
164 tempTblFile = tableFile.expanded();
165 }
166 m_pdsTableStart = 1;
167 }
168 if (m_pdsTableType == "ASCII") {
169 loadTable(tempTblFile);
170 }
171 m_pdsTableFile = tempTblFile;
172 return;
173 }
174
175
186 bool ImportPdsTable::hasColumn(const QString &colName) const {
187 return (findColumn(colName) != 0);
188 }
189
190
211 QString ImportPdsTable::getColumnName(const unsigned int &index,
212 const bool &formatted) const {
213 if ((int) index >= columns() - 1) {
214 QString msg = "Unable to import the binary PDS table [" + m_tableName
215 + "] into Isis. The requested column index ["
216 + toString((int) index) + "] exceeds the last column index ["
217 + toString(columns() - 1) + "]";
218 throw IException(IException::Programmer, msg.toStdString(), _FILEINFO_);
219 }
220 QString name = m_coldesc[index].m_name;
221 if (formatted) name = getFormattedName(name);
222 return (name);
223 }
224
225
242 QStringList ImportPdsTable::getColumnNames(const bool &formatted) const {
243 QStringList colnames;
244 for (int i = 0 ; i < columns() ; i++) {
245 QString name = m_coldesc[i].m_name;
246 if (formatted) name = getFormattedName(name);
247 colnames.push_back(name);
248 }
249 return (colnames);
250 }
251
252
268 QString ImportPdsTable::getType(const QString &colName) const {
269 const ColumnDescr *column = findColumn(colName);
270 QString dtype("");
271 if (column != 0) {
272 dtype = column->m_dataType;
273 }
274 return (dtype);
275 }
276
277
295 bool ImportPdsTable::setType(const QString &colName,
296 const QString &dataType) {
297 ColumnDescr *column = findColumn(colName);
298 if (column != 0) {
299 column->m_dataType = dataType.toUpper();
300 }
301 return (column != 0);
302 }
303
304
318 Table ImportPdsTable::importTable(const QString &isisTableName) {
319 try {
321 Table table(isisTableName, record);
322 fillTable(table, m_coldesc, record);
323 return (table);
324 }
325 catch (IException &e) {
326 QString msg = "Unable to import the PDS table [" + m_tableName
327 + "] from the PDS file [" + m_pdsTableFile + "] into Isis.";
328 throw IException(e, IException::Unknown, msg.toStdString(), _FILEINFO_);
329
330 }
331 }
332
333
350 Table ImportPdsTable::importTable(const QString &colnames,
351 const QString &isisTableName) {
352 return (importTable(colnames.split(","), isisTableName));
353 }
354
355
374 const QString &isisTableName) {
375 ColumnTypes ctypes;
376 for (int i = 0 ; i < colnames.size() ; i++) {
377 const ColumnDescr *descr = findColumn(colnames[i]);
378 if (!descr) {
379 QString msg = "Unable to import the PDS table [" + m_tableName
380 + "] into Isis. The requested column name ["
381 + colnames[i] + "] does not "
382 "exist in table.";
383 throw IException(IException::Programmer, msg.toStdString(), _FILEINFO_);
384 }
385 ctypes.push_back(*descr);
386 }
387
388 // Create and populate the table
389 TableRecord record = makeRecord(ctypes);
390 Table table(isisTableName, record);
391 fillTable(table, ctypes, record);
392 return (table);
393 }
394
395
402
403 m_byteOrder = "";
404 m_trows = 0;
405 m_pdsTableStart = 0;
406 m_coldesc.clear();
407 m_rows.clear();
408 m_pdsTableType = "";
409 m_pdsTableFile = "";
410 return;
411 }
412
413
438 void ImportPdsTable::loadLabel(const QString &pdsLabFile,
439 QString &pdsTableFile,
440 const QString &tblname) {
441
442 Isis::Pvl label(pdsLabFile);
443
444 QString tableName = ( tblname.isEmpty() ) ? m_tableName : tblname;
445 if (!label.hasObject(tableName)) {
446 QString msg = "The PDS file " + pdsLabFile +
447 " does not have the required TABLE object, ["
448 + tableName +"]. The PDS label file is probably invalid";
449 throw IException(IException::Unknown, msg.toStdString(), _FILEINFO_);
450 }
451 // Get some pertinent information from the label
452 PvlObject &tabObj = label.findObject(tableName);
453 // The table description contains the actual "RECORD_BYTES"
454 if (tabObj.hasKeyword("RECORD_BYTES")) {
455 m_recordBytes = (int) tabObj.findKeyword("RECORD_BYTES");
456 }
457 // The table description has "ROW_BYTES" and "ROW_SUFFIX_BYTES". These summed is the
458 // record length. Can be for detached and attached labels
459 else if (tabObj.hasKeyword("ROW_BYTES") && tabObj.hasKeyword("ROW_SUFFIX_BYTES")) {
460 m_recordBytes = (int) tabObj.findKeyword("ROW_BYTES") +
461 (int) tabObj.findKeyword("ROW_SUFFIX_BYTES");
462 }
463 // The table record length is defined by the file record
464 // length (i.e., table is in with the image)
465 else {
466 m_recordBytes = (int) label.findKeyword("RECORD_BYTES");
467 }
468
469 QString trueTableName;
470 PvlObject *tableDetails = &tabObj;
471 if (label.hasKeyword("^" + tableName)) {
472 trueTableName = tableName;
473 pdsTableFile = FileName(pdsLabFile).path() + "/"
474 + label["^" + tableName][0];
475 }
476 else if (tabObj.objects() == 1) {
477 trueTableName = tabObj.object(0).name();
478 tableDetails = &tabObj.object(0);
479 pdsTableFile = FileName(pdsLabFile).path() + "/"
480 + tabObj["^" + trueTableName][0];
481 }
482 m_trows = (int) tableDetails->findKeyword("ROWS");
483 int ncols = (int) tableDetails->findKeyword("COLUMNS");
484 m_pdsTableType = QString(tableDetails->findKeyword("INTERCHANGE_FORMAT"));
485 if (m_pdsTableType != "ASCII" && m_pdsTableType.toUpper() != "BINARY") {
486 QString msg = "Unable to import the PDS table [" + tableName
487 + "] from the PDS file ["
488 + pdsTableFile + "] into Isis. "
489 "The PDS INTERCHANGE_FORMAT [" + m_pdsTableType
490 + "] is not supported. Valid values are ASCII or BINARY.";
491 throw IException(IException::User, msg.toStdString(), _FILEINFO_);
492 }
493 m_rowBytes = tableDetails->findKeyword("ROW_BYTES");
494
495 m_coldesc.clear();
496 PvlObject::PvlObjectIterator colobj = tableDetails->beginObject();
497 int icol(0);
498 while (colobj != tableDetails->endObject()) {
499 if (colobj->isNamed("COLUMN")) {
500 m_coldesc.push_back(getColumnDescription(*colobj, icol));
501 icol++;
502 }
503 ++colobj;
504 }
505
506 // Test to ensure columns match the number listed in the label
507 if (ncols != columns()) {
508 ostringstream msg;
509 msg << "Number of columns in the COLUMNS label keyword (" << ncols
510 << ") does not match number of COLUMN objects found ("
511 << columns() << ")";
512 cout << msg.str() << endl;
513 }
514 return;
515 }
516
517
534 void ImportPdsTable::loadTable(const QString &pdsTableFile) {
535
536 // Vet the filename. Many PDS files record the filename in uppercase and
537 // in practice, the filename is in lowercase. Do this check here.
538 QString tempTblFile(pdsTableFile);
539 TextFile tfile(tempTblFile);
540 QString tline;
541 m_rows.clear();
542 int irow(0);
543 while (tfile.GetLine(tline, false)) {
544 if (irow >= m_trows) break;
545
546 (void) processRow(irow, tline);
547
548 irow++;
549 }
550 return;
551 }
552
553
573 ColumnDescr cd;
574 cd.m_name = colobj["NAME"][0];
575 cd.m_colnum = nth; // 0-based indexing, will be COLUMN_NUM - 1
576
577 if (m_pdsTableType == "ASCII") {
578 cd.m_dataType = getGenericType(colobj["DATA_TYPE"][0]).toUpper();
579 }
580 else {
581 cd.m_dataType = colobj["DATA_TYPE"][0].toUpper();
582 }
583
584 cd.m_startByte = ((int) colobj["START_BYTE"]) - 1; // 0-based indexing
585 cd.m_numBytes = (int) colobj["BYTES"];
586
587
588 cd.m_itemBytes = cd.m_numBytes;
589 if ( colobj.hasKeyword("ITEM_BYTES") ) {
590 cd.m_itemBytes = (int) colobj["ITEM_BYTES"];
591 }
592
593 cd.m_items = 1;
594 if ( colobj.hasKeyword("ITEMS") ) {
595 cd.m_items = (int) colobj["ITEMS"];
596 }
597
598 return (cd);
599 }
600
601
615
616 // Ensure the nrequested column is valid
617 if ( (nth >= columns()) || ( nth < 0) ) {
618 QString mess = "Index (" + QString::number(nth) +
619 ") into Columns invalid (max: " + QString::number(columns()) + ")";
620 throw IException(IException::Programmer, mess, _FILEINFO_);
621 }
622
623 // All good, return the expected
624 return (m_coldesc[nth]);
625 }
626
627
643 QString cName = getFormattedName(colName);
644 ColumnTypes::iterator col = m_coldesc.begin();
645 while (col != m_coldesc.end()) {
646 QString c = getFormattedName(col->m_name);
647 if (c.toUpper() == cName.toUpper()) { return (&(*col)); }
648 col++;
649 }
650 return (0);
651 }
652
653
668 const ImportPdsTable::ColumnDescr *ImportPdsTable::findColumn(const QString &colName) const {
669 QString cName = getFormattedName(colName);
670 ColumnTypes::const_iterator col = m_coldesc.begin();
671 while (col != m_coldesc.end()) {
672 QString c = getFormattedName(col->m_name);
673 if (c.toUpper() == cName.toUpper()) { return (&(*col)); }
674 col++;
675 }
676 return (0);
677 }
678
679
690 QString ImportPdsTable::getColumnValue(const QString &tline,
691 const ColumnDescr &cdesc,
692 const QString &delimiter) const {
693 return (tline.mid(cdesc.m_startByte, cdesc.m_numBytes));
694 }
695
696
713 const ColumnDescr &cdesc,
714 const QString &delimiter) const {
715
716 // If item count is 1, simply return the whole column
717 QString value = getColumnValue(tline, cdesc, delimiter);
718 if ( 1 == cdesc.m_items) return ( QStringList(value) );
719
720 // If there is no item size specified, see if we should seperate with
721 // delimiter
722 if ( 0 == cdesc.m_itemBytes ) {
723 if ( delimiter.isEmpty() ) return ( QStringList(value));
724
725 return ( value.split(delimiter, QString::SkipEmptyParts) );
726 }
727
728 // Have an item size specified. Assume it has single character separator
729 QStringList fields;
730 int pos = 0;
731 for (int i = 0 ; i < cdesc.m_items ; i++) {
732 fields.push_back(value.mid(pos, cdesc.m_itemBytes));
733 pos += cdesc.m_itemBytes + 1;
734 }
735
736 return (fields);
737 }
738
739
759 QString ImportPdsTable::getFormattedName(const QString &colname) const {
760 QString cname = QString(colname).replace(QRegExp("[(),]"), " ").simplified();
761
762 bool uppercase = true;
763 QString oString;
764 for (int i = 0 ; i < cname.size() ; i++) {
765 if (uppercase) {
766 oString.push_back(cname[i].toUpper());
767 uppercase = false;
768 }
769 else if ( (cname[i] == ' ') || (cname[i] == '_') ) {
770 uppercase = true;
771 }
772 else {
773 oString.push_back(cname[i].toLower());
774 }
775 }
776
777 return (oString);
778 }
779
780
798 QString ImportPdsTable::getGenericType(const QString &ttype) const {
799 return ttype.split("_").last();
800 }
801
802
821 QString dtype = cdesc.m_dataType;
822 QString name = getFormattedName(cdesc.m_name);
823 if (m_pdsTableType == "ASCII") {
824 if ( dtype == "INTEGER" ) {
826 }
827 else if ( ((dtype == "DOUBLE")
828 || (dtype == "REAL")
829 || (dtype == "FLOAT")) ) {
831 }
832 else {
833 return (TableField(name, TableField::Text, cdesc.m_numBytes));
834 }
835 }
836 else {
837 return makeFieldFromBinaryTable(cdesc);
838 }
839 }
840
841
857 TableRecord rec;
858 for (int i = 0 ; i < ctypes.size() ; i++) {
859 TableField field = makeField(ctypes[i]);
860 rec += field;
861 }
862 return (rec);
863 }
864
865
883 const ColumnDescr &cdesc,
884 TableField &tfield) const {
885 int ith = cdesc.m_colnum;
886 try {
887 IString data(cols[ith]);
888 if (tfield.isInteger()) {
889 data.Trim(" \t\r\n");
890 tfield = data.ToInteger();
891 }
892 else if (tfield.isDouble()) {
893 data.Trim(" \t\r\n");
894 tfield = data.ToDouble();
895 }
896 else { // Its a text field
897 QString str(tfield.size(), ' ');
898 str.insert(0, data.Trim(" \t\r\n").ToQt());
899 tfield = str;
900 }
901 }
902 catch (IException &e) {
903 QString msg = "Conversion failure of column " + cdesc.m_name;
904 throw IException(e, IException::Programmer, msg, _FILEINFO_);
905 }
906
907 return (tfield);
908 }
909
910
926 const ColumnTypes &ctypes,
927 TableRecord &record) const {
928 for (int i = 0 ; i < ctypes.size() ; i++) {
929 extract(cols, ctypes[i], record[i]);
930 }
931 return (record);
932 }
933
934
951 const ColumnTypes &cols,
952 TableRecord &record) const {
953 if (m_pdsTableType == "ASCII") {
954 for (int i = 0 ; i < m_rows.size() ; i++) {
955 try {
956 table += extract(m_rows[i], cols, record);
957 }
958 catch (IException &e) {
959 QString msg = "Failed to convert data in row [" + toString((int) i) + "]";
960 throw IException(e, IException::Programmer, msg, _FILEINFO_);
961 }
962 }
963 }
964
965 else {
966 QString tempTblFile = m_pdsTableFile;
967 ifstream pdsFileStream(tempTblFile.toLatin1().data(), ifstream::binary);
968
969 if (!pdsFileStream) {
970 IString msg = "Unable to open file containing PDS table ["
971 + tempTblFile + "].";
972 throw IException(IException::Unknown, msg, _FILEINFO_);
973 }
974
975 // read and discard the rows above the table data
976 QScopedPointer<char, QScopedPointerArrayDeleter<char> > rowBuffer(new char[m_recordBytes]);
977 for (int i = 1; i < m_pdsTableStart; i++) {
978 pdsFileStream.read(rowBuffer.data(), m_recordBytes);
979 }
980 // now, import and add the records to the table
981 for (int rowIndex = 0; rowIndex < m_trows; rowIndex++) {
982 pdsFileStream.read(rowBuffer.data(), m_recordBytes);
983 TableRecord rec = extractBinary(rowBuffer.data(), record);
984 table += rec;
985 }
986 }
987
988 return;
989 }
990
991
1000 return (m_coldesc.size());
1001 }
1002
1003
1012 return (m_rows.size());
1013 }
1014
1015
1032 // for each record loop through the columns to get field values
1033 for (int colIndex = 0; colIndex < columns(); colIndex++) {
1034 QString columnName = m_coldesc[colIndex].m_name;
1035 for (int fieldIndex = 0 ; fieldIndex < record.Fields() ; fieldIndex++) {
1036 QString fieldName = record[fieldIndex].name();
1037 if (fieldName == columnName) {
1038 int startByte = m_coldesc[colIndex].m_startByte;
1039 int numBytes = m_coldesc[colIndex].m_numBytes;
1040
1041 if (record[fieldIndex].isInteger()) {
1042 int columnValue;
1043 memmove(&columnValue, &rowBuffer[startByte], numBytes);
1044 EndianSwapper endianSwap(m_byteOrder);
1045 int fieldValue = endianSwap.Int(&columnValue);
1046 record[fieldIndex] = fieldValue;
1047 }
1048
1049 else if (record[fieldIndex].isDouble()) {
1050 EndianSwapper endianSwap(m_byteOrder);
1051 double columnValue;
1052 memmove(&columnValue, &rowBuffer[startByte], numBytes);
1053 double fieldValue = endianSwap.Double(&columnValue);
1054 record[fieldIndex] = fieldValue;
1055 }
1056
1057 else if (record[fieldIndex].isReal()) {
1058 EndianSwapper endianSwap(m_byteOrder);
1059 float columnValue;
1060 memmove(&columnValue, &rowBuffer[startByte], numBytes);
1061 float fieldValue = endianSwap.Float(&columnValue);
1062 record[fieldIndex] = fieldValue;
1063 }
1064
1065 else if (record[fieldIndex].isText()) {
1066 QString fieldValue(numBytes, '\0');
1067 for (int byte = 0; byte < numBytes; byte++) {
1068 fieldValue[byte] = rowBuffer[startByte + byte];
1069 }
1070 record[fieldIndex] = fieldValue;
1071 }
1072
1073 }
1074 }
1075 }
1076 return record;
1077 }
1078
1079
1103 QString dataType = cdesc.m_dataType;
1104 // For binary tables, we will not reformat the name of the column
1105 QString name = cdesc.m_name;
1106 if (dataType == "MSB_INTEGER" || dataType == "INTEGER"
1107 || dataType == "SUN_INTEGER" || dataType == "MAC_INTEGER") {
1108 if (cdesc.m_numBytes != 4) {
1109 QString msg = "Only 4 byte integer values are supported in Isis. "
1110 "PDS Column [" + cdesc.m_name
1111 + "] has an integer DATA_TYPE with [BYTES = "
1112 + toString(cdesc.m_numBytes) + "].";
1113 throw IException(IException::Unknown, msg, _FILEINFO_);
1114 }
1115 setPdsByteOrder("MSB");
1117 }
1118 else if (dataType == "LSB_INTEGER" || dataType == "VAX_INTEGER"
1119 || dataType == "PC_INTEGER" ) {
1120 if (cdesc.m_numBytes != 4) {
1121 QString msg = "Only 4 byte integer values are supported in Isis. "
1122 "PDS Column [" + cdesc.m_name
1123 + "] has an integer DATA_TYPE with [BYTES = "
1124 + toString(cdesc.m_numBytes) + "].";
1125 throw IException(IException::Unknown, msg, _FILEINFO_);
1126 }
1127 setPdsByteOrder("LSB");
1129 }
1130 else if (dataType == "FLOAT" //IEEE_REAL alias (MSB)
1131 || dataType == "REAL" //IEEE_REAL alias (MSB)
1132 || dataType == "SUN_REAL" //IEEE_REAL alias (MSB)
1133 || dataType == "MAC_REAL" //IEEE_REAL alias (MSB)
1134 || dataType == "IEEE_REAL" ) {
1135 setPdsByteOrder("MSB");
1136 if (cdesc.m_numBytes == 8) {
1138 }
1139 else if (cdesc.m_numBytes == 4) {
1141 }
1142 else {
1143 IString msg = "Only 4 byte or 8 byte real values are supported in Isis. "
1144 "PDS Column [" + cdesc.m_name
1145 + "] has a real DATA_TYPE with [BYTES = "
1146 + toString(cdesc.m_numBytes) + "].";
1147 throw IException(IException::Unknown, msg, _FILEINFO_);
1148 }
1149 }
1150 else if (dataType == "PC_REAL") {
1151 setPdsByteOrder("LSB");
1152 if (cdesc.m_numBytes == 8) {
1154 }
1155 else if (cdesc.m_numBytes == 4) {
1157 }
1158 else {
1159 QString msg = "Only 4 byte or 8 byte real values are supported in Isis. "
1160 "PDS Column [" + cdesc.m_name
1161 + "] has a real DATA_TYPE with [BYTES = "
1162 + toString(cdesc.m_numBytes) + "].";
1163 throw IException(IException::Unknown, msg, _FILEINFO_);
1164 }
1165 }
1166 else if (dataType.contains("CHARACTER")
1167 || dataType.contains("ASCII")
1168 || dataType == "DATE" || dataType == "TIME" ) {
1169 return TableField(name, TableField::Text, cdesc.m_numBytes);
1170 }
1171 // Isis tables currently don't support any of the following PDS DATA_TYPE:
1172 // BIT_STRING, COMPLEX, N/A, BOOLEAN, UNSIGNED_INTEGER, IBM types, some VAX types
1173 IString msg = "PDS Column [" + cdesc.m_name
1174 + "] has an unsupported DATA_TYPE ["
1175 + dataType + "].";
1176 throw IException(IException::Unknown, msg, _FILEINFO_);
1177 }
1178
1179
1191 void ImportPdsTable::setPdsByteOrder(QString byteOrder) {
1192 if (!m_byteOrder.isEmpty() && m_byteOrder != byteOrder) {
1193 QString msg = "Unable to import the binary PDS table [" + m_tableName
1194 + "]. The column DATA_TYPE values indicate differing byte "
1195 "orders. ";
1196 throw IException(IException::Unknown, msg.toStdString(), _FILEINFO_);
1197 }
1198 m_byteOrder = byteOrder;
1199 }
1200
1201
1212 bool ImportPdsTable::processRow(const int &row, const QString &rowdata) {
1213 Columns cols;
1214 for (int i = 0 ; i < columns() ; i++) {
1215 cols.push_back(getColumnValue(rowdata, m_coldesc[i]));
1216 }
1217 m_rows.append(cols);
1218
1219 return (true);
1220 }
1221
1222} // namespace Isis
File name manipulation and expansion.
Definition FileName.h:100
QString path() const
Returns the path of the file name.
Definition FileName.cpp:103
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Adds specific functionality to C++ strings.
Definition IString.h:165
int ToInteger() const
Returns the object string as an integer.
Definition IString.cpp:718
IString Trim(const std::string &chars)
Removes characters from the beginning and end of the IString.
Definition IString.cpp:525
QString ToQt() const
Retuns the object string as a QString.
Definition IString.cpp:869
double ToDouble() const
Returns the floating point value the IString represents.
Definition IString.cpp:799
void init()
Initialize object variables.
ColumnDescr * findColumn(const QString &colName)
Searches internal column descriptors for a named column.
virtual bool processRow(const int &row, const QString &rowdata)
Process a freshly read PDS table line of data.
void setName(const QString &name="TABLE")
Set the name of the PDS table object.
QString name() const
Return the name of the PDS table.
QString getFormattedName(const QString &colname) const
Converts a column name to a camel-case after it has been cleansed.
int rows() const
Returns the number of rows in the table.
void loadLabel(const QString &labfile, QString &tblfile, const QString &tblname="")
Loads the contents of a PDS table label description.
const ColumnDescr & getColumnDescriptor(const int &nth) const
Retrieve a column description by index.
int m_pdsTableStart
The start byte of the PDS table data.
Table importTable(const QString &isisTableName)
Populate a Table object with the PDS table and return it.
QString m_pdsTableFile
The name of the file containing the table data.
QString getColumnValue(const QString &tline, const ColumnDescr &cdesc, const QString &delimiter="") const
Extracts a column from a QString based upon a description.
void load(const QString &pdsLabFile, const QString &pdsTabFile="", const QString &pdsTableName="TABLE")
Loads a PDS table label and (optional) data file.
void setPdsByteOrder(QString byteOrder)
Sets the byte order for BINARY PDS table files.
int m_rowBytes
The number of bytes for one PDS table row.
QString m_pdsTableType
The INTERCHANGE_FORMAT value for the table.
TableField & extract(const Columns &columns, const ColumnDescr &cdesc, TableField &field) const
Extract a TableField from a PDS column in the text row.
TableRecord makeRecord(const ColumnTypes &ctypes)
Creates a TableRecord for columns.
TableRecord extractBinary(char *rowBuffer, TableRecord &record) const
This method is used to set the field values for the given record.
int m_trows
Number rows in table according to label.
QString m_tableName
The name of the PDS table object.
int m_recordBytes
The number of bytes for one Isis table record.
ColumnTypes m_coldesc
Column descriptions.
void loadTable(const QString &tabfile)
Loads the contents of a PDS table data file.
TableField makeFieldFromBinaryTable(const ColumnDescr &cdesc)
Creates an empty TableField with the appropriate type from a binary PDS table column description.
QString m_byteOrder
The byte order of the PDS table file, if binary.
virtual ~ImportPdsTable()
Destructs the ImportPdsTable object.
bool setType(const QString &colName, const QString &dataType)
Change the datatype for a column.
Rows m_rows
Table data.
QString getGenericType(const QString &ttype) const
Determine generic data type of a column.
ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const
Extract a column description from a COLUMN object.
ImportPdsTable()
Default constructor.
QString getType(const QString &colName) const
Get the type associated with the specified column.
bool hasColumn(const QString &colName) const
This method determines whether the PDS table has a column with the given name.
void fillTable(Table &table, const ColumnTypes &columns, TableRecord &record) const
Fill the ISIS Table object with PDS table data.
QStringList getColumnNames(const bool &formatted=true) const
Return the names of all the columns.
QString getColumnName(const unsigned int &index=0, const bool &formatted=true) const
Returns the name of the specifed column.
TableField makeField(const ColumnDescr &cdesc)
Creates a TableField for the column type.
int columns() const
Returns the number of columns in the table.
QStringList getColumnFields(const QString &tline, const ColumnDescr &cdesc, const QString &delimiter="") const
Extracts column fields from a QString based upon a description.
QString name() const
Returns the container name.
Container for cube-like labels.
Definition Pvl.h:119
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
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 ...
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:325
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition PvlObject.h:276
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
Definition PvlObject.h:229
PvlObject & object(const int index)
Return the object at the specified index.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Class for storing an Isis::Table's field information.
Definition TableField.h:47
@ Integer
The values in the field are 4 byte integers.
Definition TableField.h:53
@ Real
The values in the field are 4 byte reals or floats.
Definition TableField.h:57
@ Text
The values in the field are text strings with 1 byte per character.
Definition TableField.h:55
@ Double
The values in the field are 8 byte doubles.
Definition TableField.h:54
Class for storing Table blobs information.
Definition Table.h:61
int Fields() const
Returns the number of fields that are currently in the record.
Provides access to sequential ASCII stream I/O.
Definition TextFile.h:38
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition IString.cpp:93
Namespace for the standard library.
QString m_dataType
PDS table DATA_TYPE of column.