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 " 
   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';
 
  109      Pack(record, rowBuffer, endianSwap);
 
  111      memmove(pdsTableBuffer + i, &rowBuffer, record.
RecordSize());
 
  112      memmove(pdsTableBuffer + i + 
m_rowBytes, &endRowPadding, numRowNulls);
 
  114      buffsize+=numRowNulls;
 
 
  127    PvlObject pdsTableLabelInfo(pdsTableName);
 
  131    pdsTableLabelInfo.addKeyword(
PvlKeyword(
"INTERCHANGE_FORMAT", 
"BINARY"));
 
  139      TableField field = (*m_isisTable)[0][fieldIndex];
 
  142      columnObj.addKeyword(
PvlKeyword(
"NAME", field.name()));
 
  146        columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"CHARACTER"));
 
  148        for(
int i = 0; i < field.size(); i++) {
 
  154          columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"MSB_INTEGER"));
 
  155          columnBytes = 
sizeof(int);
 
  159          columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"LSB_INTEGER"));
 
  160          columnBytes = 
sizeof(int);
 
  165          columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"IEEE_REAL"));
 
  166          columnBytes = 
sizeof(double);
 
  170          columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"PC_REAL"));
 
  171          columnBytes = 
sizeof(double);
 
  176          columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"IEEE_REAL"));
 
  177          columnBytes = 
sizeof(float);
 
  181          columnObj.addKeyword(
PvlKeyword(
"DATA_TYPE", 
"PC_REAL"));
 
  182          columnBytes = 
sizeof(float);
 
  188        QString msg = 
"Unable to export Isis::Table object to PDS. Invalid " 
  189                      "field type found for [" + field.name() + 
"].";
 
  193      startByte += columnBytes;
 
  195      pdsTableLabelInfo.addObject(columnObj);
 
  197    return pdsTableLabelInfo;
 
 
  220    QString tableName = isisTableName.simplified();
 
  221    QString pdsTableName;
 
  222    pdsTableName.push_back(tableName[0]);
 
  223    for (
int i = 1 ; i < tableName.size() ; i++) {
 
  224      if (tableName[i] >= 65 && tableName[i] <= 90) {
 
  225        pdsTableName.push_back(
'_');
 
  226        pdsTableName.push_back(tableName[i]);
 
  229        pdsTableName.push_back(tableName[i]);
 
  232    pdsTableName = pdsTableName.toUpper();
 
  233    if (pdsTableName.indexOf(
"_TABLE") != pdsTableName.length() - 6) {
 
  234      pdsTableName += 
"_TABLE";
 
 
  253    for(
int fieldIndex = 0; fieldIndex < record.
Fields(); fieldIndex++) {
 
  259      if(field.isDouble()) {
 
  260        vector<double> fieldValues = field;
 
  261        for(
unsigned int i = 0; i < fieldValues.size(); i++) {
 
  262          double value = endianSwap->Double(&fieldValues[i]);
 
  263          memmove(buffer + startByte, &value, 8);
 
  264          startByte += 
sizeof(double);
 
  267      else if(field.isInteger()) {
 
  268        vector<int> fieldValues = field;
 
  269        for(
unsigned int i = 0; i < fieldValues.size(); i++) {
 
  270          int value = endianSwap->Int(&fieldValues[i]);
 
  271          memmove(buffer + startByte, &value, 4);
 
  272          startByte += 
sizeof(int);
 
  275      else if(field.isText()) {
 
  278        for(
int i = 0; i < field.size(); i++) {
 
  279          if(i < (
int)val.length()) {
 
  280            buffer[startByte] = val[i].toLatin1();
 
  286            buffer[startByte] = 0;
 
  291      else if(field.isReal()) {
 
  292        vector<float> fieldValues = field;
 
  293        for(
unsigned int i = 0; i < fieldValues.size(); i++) {
 
  294          float value = endianSwap->Float(&fieldValues[i]);
 
  295          memmove(buffer + startByte, &value, 4);
 
  296          startByte += 
sizeof(float);
 
  302        QString msg = 
"Unable to export Isis::Table object to PDS. Invalid " 
  303                      "field type found for [" + field.name() + 
"].";
 
  313      QString msg = 
"Unable to export Isis::Table object [" + 
m_isisTable->
Name()
 
  314                    + 
"] to PDS. Record lengths are uneven.";
 
 
~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.
 
A single keyword-value pair.
 
Contains Pvl Groups and Pvl Objects.
 
Class for storing an Isis::Table's field information.
 
@ 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.
 
Class for storing Table blobs information.
 
int RecordSize() const
Returns the number of bytes per record.
 
int RecordFields() const
Returns the number of fields per record.
 
int Records() const
Returns the number of records.
 
QString Name() const
The Table's name.
 
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.