9#include <nlohmann/json.hpp>
12#include "IException.h"
18using json = nlohmann::json;
43 fileStream.seekg(0, std::ios_base::beg);
46 while (fileStream.read(readBuf, 80) && fileStream.gcount() == 80) {
56 while (line.substr(0, 3) !=
"END") {
59 if (line.substr(0, 1) !=
" " && line.substr(0, 1) !=
"/") {
62 if (QString::compare(label.
name(),
"OBJECT", Qt::CaseInsensitive) == 0) {
64 label.
addComment(
"NOTE: This keyword name was changed from 'OBJECT' in the original "
70 if (label.
name() ==
"COMMENT" || label.
name() ==
"HISTORY") {
75 if (line.substr(0,1) ==
"'") {
84 label += value.
ToQt();
88 if (line.size() > 2) {
91 if (line != line.
Token(
"[")) {
99 fileStream.read(readBuf, 80);
107 headerSizes->append((
int)ceil(place / 2880.0));
110 std::streamoff jump = 0;
111 jump = headerSizes->last() * 2880 - place;
112 fileStream.seekg(jump, std::ios_base::cur);
114 dataStarts->append(fileStream.tellg());
119 int bytesPerPixel = 0;
120 bytesPerPixel = (int)((*fitsLabel)[
"BITPIX"]);
121 bytesPerPixel = std::abs(bytesPerPixel);
124 unsigned int axis1 = 1;
125 axis1 =
toInt((*fitsLabel)[
"NAXIS1"]);
127 unsigned int axis2 = 1;
129 axis2 =
toInt((*fitsLabel)[
"NAXIS2"]);
132 unsigned int axis3 = 1;
134 axis3 =
toInt((*fitsLabel)[
"NAXIS3"]);
137 jump = (int)(ceil(bytesPerPixel * axis1 * axis2 * axis3 / 2880.0) * 2880.0);
138 fileStream.seekg(jump, std::ios_base::cur);
146 PvlGroup *extraLabelGroup = fitsImageLabels->last();
147 extraLabelGroup->
setName(
"FitsExtras");
148 extraFitsLabels->append(extraLabelGroup);
150 fitsImageLabels->removeLast();
151 headerSizes->removeLast();
152 dataStarts->removeLast();
157 else if (fitsImageLabels->size() > 1) {
158 fitsImageLabels->removeLast();
159 headerSizes->removeLast();
160 dataStarts->removeLast();
165 QString msg = QObject::tr(
"The FITS file does not contain a section header that appears "
166 "to describe an image.");
182 std::ifstream fileStream;
184 fileStream.open(fitsFile.
expanded().toLocal8Bit().constData(), std::ios::in | std::ios::binary);
187 QString msg = QString(
"Unable to open FITS formatted file [%1].")
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....
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.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
void setName(const QString &name)
Set the name of the container.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
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.
Contains Pvl Groups and Pvl Objects.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
int toInt(const QString &string)
Global function to convert from a string to an integer.
json fitsToJson(std::ifstream &fileStream)
Convert the contents of a stream to a JSON object.
json pvlObjectToJSON(PvlObject &object)
Convert the contents of a PvlObject to a JSON object.