68 int outputFileRecordBytes,
69 QString pdsTableByteOrder) {
75 throw IException(IException::Unknown,
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 ["
90 throw IException(IException::Unknown, msg, _FILEINFO_);
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++) {
106 TableRecord record = (*m_isisTable)[recIndex];
107 char rowBuffer[record.RecordSize()];
108 Pack(record, rowBuffer, endianSwap);
110 memmove(pdsTableBuffer + i, &rowBuffer, record.RecordSize());
111 memmove(pdsTableBuffer + i +
m_rowBytes, &endRowPadding, numRowNulls);
124 PvlObject pdsTableLabelInfo(pdsTableName);
128 pdsTableLabelInfo.addKeyword(PvlKeyword(
"INTERCHANGE_FORMAT",
"BINARY"));
130 pdsTableLabelInfo.addKeyword(PvlKeyword(
"COLUMNS",
toString(
m_isisTable->RecordFields())));
134 for(
int fieldIndex = 0; fieldIndex <
m_isisTable->RecordFields(); fieldIndex++) {
136 TableField field = (*m_isisTable)[0][fieldIndex];
137 PvlObject columnObj(
"COLUMN");
138 columnObj.addKeyword(PvlKeyword(
"COLUMN_NUMBER",
toString(fieldIndex + 1)));
139 columnObj.addKeyword(PvlKeyword(
"NAME", field.name()));
142 if (field.type() == TableField::Text) {
143 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"CHARACTER"));
145 for(
int i = 0; i < field.size(); i++) {
149 else if (field.type() == TableField::Integer) {
151 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"MSB_INTEGER"));
152 columnBytes =
sizeof(int);
156 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"LSB_INTEGER"));
157 columnBytes =
sizeof(int);
160 else if (field.type() == TableField::Double) {
162 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"IEEE_REAL"));
163 columnBytes =
sizeof(double);
167 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"PC_REAL"));
168 columnBytes =
sizeof(double);
171 else if (field.type() == TableField::Real) {
173 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"IEEE_REAL"));
174 columnBytes =
sizeof(float);
178 columnObj.addKeyword(PvlKeyword(
"DATA_TYPE",
"PC_REAL"));
179 columnBytes =
sizeof(float);
185 QString msg =
"Unable to export Isis::Table object to PDS. Invalid "
186 "field type found for [" + field.name() +
"].";
187 throw IException(IException::Programmer, msg, _FILEINFO_);
189 columnObj.addKeyword(PvlKeyword(
"START_BYTE",
toString(startByte)));
190 startByte += columnBytes;
191 columnObj.addKeyword(PvlKeyword(
"BYTES",
toString(columnBytes)));
192 pdsTableLabelInfo.addObject(columnObj);
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].toLatin1() >= 65 && tableName[i].toLatin1() <= 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++) {
255 TableField &field = record[fieldIndex];
256 if(field.isDouble()) {
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);
264 else if(field.isInteger()) {
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);
272 else if(field.isText()) {
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;
288 else if(field.isReal()) {
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() +
"].";
301 throw IException(IException::Programmer, msg, _FILEINFO_);
310 QString msg =
"Unable to export Isis::Table object [" +
m_isisTable->Name()
311 +
"] to PDS. Record lengths are uneven.";
312 throw IException(IException::Unknown, msg, _FILEINFO_);
void Pack(TableRecord record, char *buffer, EndianSwapper *endianSwap)
Pack the buffer with data from the table record, swapping bytes if needed.
PvlObject exportTable(char *pdsTableBuffer, int pdsFileRecordBytes, QString pdsByteOrder)
This methods fills the given buffer with the binary PDS table data and returns label information.