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) {
88 while (line.substr(0, 3) !=
"END") {
91 if (line.substr(0, 1) !=
" " && line.substr(0, 1) !=
"/") {
94 if (QString::compare(label.
name(),
"OBJECT", Qt::CaseInsensitive) == 0) {
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) ==
"'") {
117 label += value.
ToQt();
121 if (line.size() > 2) {
125 if (line != line.
Token(
"[")) {
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 "
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).
234 QString msg = QObject::tr(
"The FITS label has not been initialized, "
235 "call setFitsFile() first.");
239 QString msg = QObject::tr(
"The requested FITS label number "
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).
270 QString msg = QObject::tr(
"The FITS label has not been initialized, "
271 "call setFitsFile first.");
275 QString msg = QObject::tr(
"The requested FITS label number "
280 return *(*m_fitsImageLabels)[labelNumber];
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());
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());
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).
372 PvlGroup label = *(*m_fitsImageLabels)[labelNumber];
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.";
402 msg =
"Unknown pixel type [" + label[
"BITPIX"][0] +
"] is not supported for FITS imports.";
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.";
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.";
453 QString msg =
"BIP (Band Interleaved by Pixel) "
454 "organization is not supported for FITS imports.";
458 QString msg =
"Unknown organization is not supported for FITS imports.";
File name manipulation and expansion.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
IString TrimTail(const std::string &chars)
Trims the input characters from the end of the object IString.
IString Token(const IString &separator)
Returns the first token in the IString.
QString ToQt() const
Retuns the object string as a QString.
IString TrimHead(const std::string &chars)
Trims The input characters from the beginning of the object IString.
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.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Contains multiple PvlContainers.
A single keyword-value pair.
void setName(QString name)
Sets the keyword name.
QString name() const
Returns the keyword name.
void setUnits(QString units)
Sets the unit of measure for all current values if any exist.
void addComment(QString comment)
Add a comment to the PvlKeyword.
This is free and unencumbered software released into the public domain.
int SizeOf(Isis::PixelType pixelType)
Returns the number of bytes of the specified PixelType.
int toInt(const QString &string)
Global function to convert from a string to an integer.
double toDouble(const QString &string)
Global function to convert from a string to a double.
PixelType
Enumerations for Isis Pixel Types.