7#include "ExportPdsTable.h"
13#include "EndianSwapper.h"
15#include "IException.h"
17#include "PvlKeyword.h"
20#include "TableField.h"
21#include "TableRecord.h"
68 int outputFileRecordBytes,
69 QString pdsTableByteOrder) {
76 "Unable to export Isis::Table object to PDS. The "
78 +
"] is larger than the record bytes allowed in the "
87 QString msg =
"Unable to export the Isis Table [" +
m_isisTable->Name()
88 +
"] to a PDS table using the requested byte order ["
95 int numRowNulls = outputFileRecordBytes -
m_rowBytes;
96 char endRowPadding[numRowNulls];
97 for (
int i = 0; i < numRowNulls; i++) {
98 endRowPadding[i] =
'\0';
105 for(
int recIndex = 0; recIndex <
m_isisTable->Records(); recIndex++) {
108 Pack(record, rowBuffer, endianSwap);
110 memmove(pdsTableBuffer + i, &rowBuffer, record.
RecordSize());
111 memmove(pdsTableBuffer + i +
m_rowBytes, &endRowPadding, numRowNulls);
124 PvlObject pdsTableLabelInfo(pdsTableName);
134 for(
int fieldIndex = 0; fieldIndex <
m_isisTable->RecordFields(); fieldIndex++) {
136 TableField field = (*m_isisTable)[0][fieldIndex];
145 for(
int i = 0; i < field.
size(); i++) {
152 columnBytes =
sizeof(int);
157 columnBytes =
sizeof(int);
163 columnBytes =
sizeof(double);
168 columnBytes =
sizeof(double);
174 columnBytes =
sizeof(float);
179 columnBytes =
sizeof(float);
185 QString msg =
"Unable to export Isis::Table object to PDS. Invalid "
186 "field type found for [" + field.
name() +
"].";
190 startByte += columnBytes;
194 return pdsTableLabelInfo;
217 QString tableName = isisTableName.simplified();
218 QString pdsTableName;
219 pdsTableName.push_back(tableName[0]);
220 for (
int i = 1 ; i < tableName.size() ; i++) {
221 if (tableName[i] >= 65 && tableName[i] <= 90) {
222 pdsTableName.push_back(
'_');
223 pdsTableName.push_back(tableName[i]);
226 pdsTableName.push_back(tableName[i]);
229 pdsTableName = pdsTableName.toUpper();
230 if (pdsTableName.indexOf(
"_TABLE") != pdsTableName.length() - 6) {
231 pdsTableName +=
"_TABLE";
250 for(
int fieldIndex = 0; fieldIndex < record.
Fields(); fieldIndex++) {
257 vector<double> fieldValues = field;
258 for(
unsigned int i = 0; i < fieldValues.size(); i++) {
259 double value = endianSwap->
Double(&fieldValues[i]);
260 memmove(buffer + startByte, &value, 8);
261 startByte +=
sizeof(double);
265 vector<int> fieldValues = field;
266 for(
unsigned int i = 0; i < fieldValues.size(); i++) {
267 int value = endianSwap->
Int(&fieldValues[i]);
268 memmove(buffer + startByte, &value, 4);
269 startByte +=
sizeof(int);
275 for(
int i = 0; i < field.
size(); i++) {
276 if(i < (
int)val.length()) {
277 buffer[startByte] = val[i].toLatin1();
283 buffer[startByte] = 0;
289 vector<float> fieldValues = field;
290 for(
unsigned int i = 0; i < fieldValues.size(); i++) {
291 float value = endianSwap->
Float(&fieldValues[i]);
292 memmove(buffer + startByte, &value, 4);
293 startByte +=
sizeof(float);
299 QString msg =
"Unable to export Isis::Table object to PDS. Invalid "
300 "field type found for [" + field.
name() +
"].";
310 QString msg =
"Unable to export Isis::Table object [" +
m_isisTable->Name()
311 +
"] to PDS. Record lengths are uneven.";
float Float(void *buf)
Swaps a floating point value.
int Int(void *buf)
Swaps a 4 byte integer value.
double Double(void *buf)
Swaps a double precision value.
~ExportPdsTable()
Destructs for ExportPdsTable objects.
void Pack(TableRecord record, char *buffer, EndianSwapper *endianSwap)
Pack the buffer with data from the table record, swapping bytes if needed.
int m_numRows
The number of rows in the exported PDS table.
QString m_pdsByteOrder
A string indicating the byte order of the exported PDS file.
PvlObject fillMetaData()
Creates a PvlObject to be added to the PDS label with needed TABLE information.
PvlObject exportTable(char *pdsTableBuffer, int pdsFileRecordBytes, QString pdsByteOrder)
This methods fills the given buffer with the binary PDS table data and returns label information.
QString formatPdsTableName()
Format the PDS table object name using the ISIS table name.
int m_rowBytes
The number of bytes per row in the exported PDS table.
int m_outputRecordBytes
The number of bytes per record in the exported PDS file.
Table * m_isisTable
Input ISIS Table object to be exported.
ExportPdsTable(Table isisTable)
Construct an ExportPdsTable object and set default member variable values.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
A single keyword-value pair.
Contains Pvl Groups and Pvl Objects.
void addObject(const PvlObject &object)
Add a PvlObject.
Class for storing an Isis::Table's field information.
bool isInteger() const
Determines whether the field type is Integer.
bool isDouble() const
Determines whether the field type is Double.
bool isReal() const
Determines whether the field type is Text.
QString name() const
Returns the name of the TableField.
@ Integer
The values in the field are 4 byte integers.
@ Real
The values in the field are 4 byte reals or floats.
@ Text
The values in the field are text strings with 1 byte per character.
@ Double
The values in the field are 8 byte doubles.
int size() const
Returns the number of values stored for the field at each record.
bool isText() const
Determines whether the field type is Text.
Type type() const
Returns the enumerated value of the TableField value's type.
Class for storing Table blobs information.
int Records() const
Returns the number of records.
int RecordSize() const
Returns the number of bytes per record.
int Fields() const
Returns the number of fields that are currently in the record.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Namespace for the standard library.