53 ExportPdsTable::ExportPdsTable(
Table isisTable) {
55 m_outputRecordBytes = 0;
56 m_pdsByteOrder =
"LSB";
57 m_isisTable =
new Table(isisTable);
58 m_numRows = isisTable.
Records();
59 m_rowBytes = m_isisTable->RecordSize();
66 ExportPdsTable::~ExportPdsTable() {
82 PvlObject ExportPdsTable::exportTable(
char *pdsTableBuffer,
83 int outputFileRecordBytes,
84 QString pdsTableByteOrder) {
88 m_outputRecordBytes = outputFileRecordBytes;
89 if (m_rowBytes > m_outputRecordBytes) {
91 "Unable to export Isis::Table object to PDS. The " 92 "Isis::Table record size [" +
toString(m_rowBytes)
93 +
"] is larger than the record bytes allowed in the " 94 "PDS file [" +
toString(m_outputRecordBytes) +
"].",
99 m_pdsByteOrder = pdsTableByteOrder.toUpper();
101 if (m_pdsByteOrder !=
"MSB" && m_pdsByteOrder !=
"LSB") {
102 QString msg =
"Unable to export the Isis Table [" + m_isisTable->Name()
103 +
"] to a PDS table using the requested byte order [" 104 + m_pdsByteOrder +
"]. Valid values are MSB or LSB.";
110 int numRowNulls = outputFileRecordBytes - m_rowBytes;
111 char endRowPadding[numRowNulls];
112 for (
int i = 0; i < numRowNulls; i++) {
113 endRowPadding[i] =
'\0';
121 for(
int recIndex = 0; recIndex < m_isisTable->Records(); recIndex++) {
124 Pack(record, rowBuffer, endianSwap);
125 int i = recIndex*m_outputRecordBytes;
126 memmove(pdsTableBuffer + i, &rowBuffer, record.
RecordSize());
127 memmove(pdsTableBuffer + i + m_rowBytes, &endRowPadding, numRowNulls);
129 buffsize+=numRowNulls;
131 return fillMetaData();
141 QString pdsTableName = formatPdsTableName();
142 PvlObject pdsTableLabelInfo(pdsTableName);
152 for(
int fieldIndex = 0; fieldIndex < m_isisTable->RecordFields(); fieldIndex++) {
154 TableField field = (*m_isisTable)[0][fieldIndex];
160 if (field.
type() == TableField::Text) {
163 for(
int i = 0; i < field.
size(); i++) {
167 else if (field.
type() == TableField::Integer) {
168 if (m_pdsByteOrder ==
"MSB") {
170 columnBytes =
sizeof(int);
175 columnBytes =
sizeof(int);
178 else if (field.
type() == TableField::Double) {
179 if (m_pdsByteOrder ==
"MSB") {
181 columnBytes =
sizeof(double);
186 columnBytes =
sizeof(double);
189 else if (field.
type() == TableField::Real) {
190 if (m_pdsByteOrder ==
"MSB") {
192 columnBytes =
sizeof(float);
197 columnBytes =
sizeof(float);
203 QString msg =
"Unable to export Isis::Table object to PDS. Invalid " 204 "field type found for [" + field.
name() +
"].";
208 startByte += columnBytes;
212 return pdsTableLabelInfo;
220 QString ExportPdsTable::formatPdsTableName() {
221 return ExportPdsTable::formatPdsTableName(m_isisTable->Name());
234 QString ExportPdsTable::formatPdsTableName(QString isisTableName) {
235 QString tableName = isisTableName.simplified();
236 QString pdsTableName;
237 pdsTableName.push_back(tableName[0]);
238 for (
int i = 1 ; i < tableName.size() ; i++) {
239 if (tableName[i] >= 65 && tableName[i] <= 90) {
240 pdsTableName.push_back(
'_');
241 pdsTableName.push_back(tableName[i]);
244 pdsTableName.push_back(tableName[i]);
247 pdsTableName = pdsTableName.toUpper();
248 if (pdsTableName.indexOf(
"_TABLE") != pdsTableName.length() - 6) {
249 pdsTableName +=
"_TABLE";
268 for(
int fieldIndex = 0; fieldIndex < record.
Fields(); fieldIndex++) {
275 vector<double> fieldValues = field;
276 for(
unsigned int i = 0; i < fieldValues.size(); i++) {
277 double value = endianSwap->
Double(&fieldValues[i]);
278 memmove(buffer + startByte, &value, 8);
279 startByte +=
sizeof(double);
283 vector<int> fieldValues = field;
284 for(
unsigned int i = 0; i < fieldValues.size(); i++) {
285 int value = endianSwap->
Int(&fieldValues[i]);
286 memmove(buffer + startByte, &value, 4);
287 startByte +=
sizeof(int);
293 for(
int i = 0; i < field.
size(); i++) {
294 if(i < (
int)val.length()) {
295 buffer[startByte] = val[i].toLatin1();
301 buffer[startByte] = 0;
307 vector<float> fieldValues = field;
308 for(
unsigned int i = 0; i < fieldValues.size(); i++) {
309 float value = endianSwap->
Float(&fieldValues[i]);
310 memmove(buffer + startByte, &value, 4);
311 startByte +=
sizeof(float);
317 QString msg =
"Unable to export Isis::Table object to PDS. Invalid " 318 "field type found for [" + field.
name() +
"].";
324 if (startByte != m_rowBytes) {
328 QString msg =
"Unable to export Isis::Table object [" + m_isisTable->Name()
329 +
"] to PDS. Record lengths are uneven.";
int RecordSize() const
Returns the number of bytes per record.
int Records() const
Returns the number of records.
float Float(void *buf)
Swaps a floating point value.
Type type() const
Returns the enumerated value of the TableField value's type.
Namespace for the standard library.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
bool isReal() const
Determines whether the field type is Text.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
void addObject(const PvlObject &object)
Add a PvlObject.
bool isInteger() const
Determines whether the field type is Integer.
#define _FILEINFO_
Macro for the filename and line number.
double Double(void *buf)
Swaps a double precision value.
A single keyword-value pair.
int size() const
Returns the number of values stored for the field at each record.
QString name() const
Returns the name of the TableField.
Class for storing Table blobs information.
Namespace for ISIS/Bullet specific routines.
int Fields() const
Returns the number of fields that are currently in the record.
bool isText() const
Determines whether the field type is Text.
Class for storing an Isis::Table's field information.
bool isDouble() const
Determines whether the field type is Double.
Contains Pvl Groups and Pvl Objects.
int Int(void *buf)
Swaps a 4 byte integer value.