7#include "ProcessImportFits.h"
16#include "IException.h"
18#include "LineManager.h"
19#include "Preference.h"
23#include "SpecialPixel.h"
24#include "UserInterface.h"
74 m_file.seekg(0, std::ios_base::beg);
78 while (
m_file.read(readBuf, 80) &&
m_file.gcount() == 80) {
80 PvlGroup *fitsLabel =
new PvlGroup(
"FitsLabels");
88 while (line.substr(0, 3) !=
"END") {
91 if (line.substr(0, 1) !=
" " && line.substr(0, 1) !=
"/") {
93 PvlKeyword label(line.Token(
" =").ToQt());
94 if (QString::compare(label.name(),
"OBJECT", Qt::CaseInsensitive) == 0) {
95 label.setName(
"TARGET");
96 label.addComment(
"NOTE: This keyword name was changed from 'OBJECT' in the original "
102 if (label.name() ==
"COMMENT" || label.name() ==
"HISTORY") {
103 label += line.ToQt();
107 if (line.substr(0,1) ==
"'") {
109 label += line.Token(
"'").TrimHead(
" ").TrimTail(
" ").ToQt();
114 IString value = line.Token(
"/");
117 label += value.ToQt();
121 if (line.size() > 2) {
123 label.addComment(line.ToQt());
125 if (line != line.Token(
"[")) {
126 label.setUnits(line.Token(
"[").Token(
"]").ToQt());
130 fitsLabel->addKeyword(label);
148 m_file.seekg(jump, std::ios_base::cur);
154 if (fitsLabel->hasKeyword(
"BITPIX") && fitsLabel->hasKeyword(
"NAXIS")) {
158 if((
int)fitsLabel->findKeyword(
"NAXIS") > 0) {
159 int bytesPerPixel = 0;
160 bytesPerPixel = (int)((*fitsLabel)[
"BITPIX"]);
161 bytesPerPixel = std::abs(bytesPerPixel);
164 unsigned int axis1 = 1;
165 axis1 = toInt((*fitsLabel)[
"NAXIS1"]);
167 unsigned int axis2 = 1;
168 if (fitsLabel->hasKeyword(
"NAXIS2")) {
169 axis2 = toInt((*fitsLabel)[
"NAXIS2"]);
172 unsigned int axis3 = 1;
173 if (fitsLabel->hasKeyword(
"NAXIS3")) {
174 axis3 = toInt((*fitsLabel)[
"NAXIS3"]);
177 jump = (int)(ceil(bytesPerPixel * axis1 * axis2 * axis3 / 2880.0) * 2880.0);
178 m_file.seekg(jump, std::ios_base::cur);
187 extraLabelGroup->setName(
"FitsExtras");
205 QString msg = QObject::tr(
"The FITS file does not contain a section header that appears "
206 "to describe an image [%1].").arg(
m_name.toString());
207 throw IException(IException::User, msg, _FILEINFO_);
226 QString msg = QObject::tr(
"The requested label number [%1], from file [%2] is "
227 "past the last extra group found in this FITS file. "
228 "Extra label count is [%3]").arg(labelNumber).
230 throw IException(IException::User, msg, _FILEINFO_);
234 QString msg = QObject::tr(
"The FITS label has not been initialized, "
235 "call setFitsFile() first.");
236 throw IException(IException::Programmer, msg, _FILEINFO_);
239 QString msg = QObject::tr(
"The requested FITS label number "
240 "was not found in file [%1].").arg(
m_name.toString());
241 throw IException(IException::Programmer, msg, _FILEINFO_);
244 return *(*m_extraFitsLabels)[labelNumber];
262 QString msg = QObject::tr(
"The requested label number [%1], from file [%2] is "
263 "past the last image group found in this FITS file. "
264 "Image label count is [%3]").arg(labelNumber).
266 throw IException(IException::User, msg, _FILEINFO_);
270 QString msg = QObject::tr(
"The FITS label has not been initialized, "
271 "call setFitsFile first.");
272 throw IException(IException::Programmer, msg, _FILEINFO_);
275 QString msg = QObject::tr(
"The requested FITS label number "
276 "was not found in file [%1].").arg(
m_name.toString());
277 throw IException(IException::Programmer, msg, _FILEINFO_);
280 return *(*m_fitsImageLabels)[labelNumber];
300 PvlGroup inst(
"Instrument");
301 if (fitsLabel.hasKeyword(
"DATE-OBS")) {
302 inst += PvlKeyword(
"StartTime", fitsLabel[
"DATE-OBS"][0]);
304 if (fitsLabel.hasKeyword(
"TARGET")) {
305 inst += PvlKeyword(
"Target", fitsLabel[
"TARGET"][0]);
307 if (fitsLabel.hasKeyword(
"INSTRUME")) {
308 inst += PvlKeyword(
"InstrumentId", fitsLabel[
"INSTRUME"][0]);
310 if (fitsLabel.hasKeyword(
"OBSERVER")) {
311 inst += PvlKeyword(
"SpacecraftName", fitsLabel[
"OBSERVER"][0]);
329 m_file.open(fitsFile.expanded().toLocal8Bit().constData(), std::ios::in | std::ios::binary);
332 QString msg = QObject::tr(
"Unable to open FITS formatted file [%1].")
333 .arg(fitsFile.toString());
334 throw IException(IException::User, msg, _FILEINFO_);
342 if (label.hasKeyword(
"SIMPLE") && label[
"SIMPLE"][0] ==
"F") {
343 QString msg = QObject::tr(
"The file [%1] cannot be processed. "
344 "It is an unsupported format.").
345 arg(fitsFile.toString());
346 throw IException(IException::User, msg, _FILEINFO_);
366 QString msg = QObject::tr(
"The requested label number [%1], from file [%2] is "
367 "past the last image in this FITS file [%3].").arg(labelNumber).
369 throw IException(IException::User, msg, _FILEINFO_);
372 PvlGroup label = *(*m_fitsImageLabels)[labelNumber];
379 Isis::PixelType type;
381 switch (toInt(label[
"BITPIX"][0])) {
383 type = Isis::UnsignedByte;
386 type = Isis::SignedWord;
389 type = Isis::SignedInteger;
395 msg =
"Signed 64-bit integer (long) pixel type is not supported for FITS imports.";
396 throw IException(IException::User, msg, _FILEINFO_);
402 msg =
"Unknown pixel type [" + label[
"BITPIX"][0] +
"] is not supported for FITS imports.";
403 throw IException(IException::User, msg, _FILEINFO_);
417 if (toInt(label[
"NAXIS"][0]) == 2) {
420 toInt(label[
"NAXIS2"][0]), 1);
422 else if (toInt(label[
"NAXIS"][0]) == 3) {
425 toInt(label[
"NAXIS2"][0]), toInt(label[
"NAXIS3"][0]));
428 QString msg =
"NAXIS count of ["
430 +
"] is not supported for FITS imports.";
431 throw IException(IException::User, msg, _FILEINFO_);
435 if (toInt(label[
"NAXIS"][0]) == 2) {
438 1, toInt(label[
"NAXIS2"][0]));
440 else if (toInt(label[
"NAXIS"][0]) == 3) {
443 toInt(label[
"NAXIS3"][0]), toInt(label[
"NAXIS2"][0]));
446 QString msg =
"NAXIS count of ["
448 +
"] is not supported for FITS imports.";
449 throw IException(IException::User, msg, _FILEINFO_);
453 QString msg =
"BIP (Band Interleaved by Pixel) "
454 "organization is not supported for FITS imports.";
455 throw IException(IException::User, msg, _FILEINFO_);
458 QString msg =
"Unknown organization is not supported for FITS imports.";
459 throw IException(IException::User, msg, _FILEINFO_);
463 if (label.hasKeyword(
"BZERO")) {
464 SetBase(toDouble(label[
"BZERO"][0]));
469 if (label.hasKeyword(
"BSCALE")) {
FileName m_name
The name of the input FITS file.
PvlGroup fitsImageLabel(int labelNumber) const
Supplies the FITS image label corresponding to the given index.
void extractFitsLabels()
Extract all the FITS labels from the file.
void setFitsFile(FileName fitsFile)
Opens a FITS image file with header and reads the FITS labels.
QList< PvlGroup * > * m_extraFitsLabels
Holds the PvlGroups with the converted extra FITS labels from the main and all extensions.
ProcessImportFits()
Constructor for ProcessImportFits.
std::ifstream m_file
The stream used to read the FITS file.
PvlGroup standardInstrumentGroup(PvlGroup fitsLabel) const
Return a PVL instrument group populated with expected default values.
PvlGroup extraFitsLabel(int labelNumber) const
Supplies the extra FITS label corresponding to the given index.
QList< PvlGroup * > * m_fitsImageLabels
Holds the PvlGroups with the converted FITS image labels from the main and all extensions.
void setProcessFileStructure(int labelNumber)
Sets the Process file structure parameters based on the given image label index.
virtual ~ProcessImportFits()
Destructor for ProcessImportFits.
QList< int > * m_dataStarts
The starting byte of the data for each image.
QList< int > * m_headerSizes
The number, or count, of 2880 byte header records for each image header section.
void SetPixelType(const Isis::PixelType type)
Sets the pixel type of the input file.
void SetFileHeaderBytes(const int bytes)
This method sets the number of bytes in the header of a file.
void SetInputFile(const QString &file)
Sets the name of the input file to be read in the import StartProcess method and verifies its existan...
void SetMultiplier(const double mult)
Sets the core multiplier of the input cube.
int DataPrefixBytes() const
This method returns the number of data prefix bytes.
Interleave Organization() const
Gets the organization of the input cube.
QString InputFile()
Sets the name of the input file to be read in the import StartProcess method and verifies its existan...
int DataSuffixBytes() const
This method returns the number of data duffix bytes.
void SetByteOrder(const Isis::ByteOrder order)
Sets the byte order of the input file.
@ BIL
Band Interleaved By Line Format (i.e.
@ BIP
Band Interleaved By Pixel Format (i.e.
@ BSQ
Band Sequential Format (i.e.
void SetBase(const double base)
Sets the core base of the input cube.
void SetDimensions(const int ns, const int nl, const int nb)
Sets the physical size of the input cube.
This is free and unencumbered software released into the public domain.