43 fileStream.seekg(0, std::ios_base::beg);
46 while (fileStream.read(readBuf, 80) && fileStream.gcount() == 80) {
48 PvlGroup *fitsLabel =
new PvlGroup(
"FitsLabels");
56 while (line.substr(0, 3) !=
"END") {
59 if (line.substr(0, 1) !=
" " && line.substr(0, 1) !=
"/") {
61 PvlKeyword label(line.Token(
" =").ToQt());
62 if (QString::compare(label.name(),
"OBJECT", Qt::CaseInsensitive) == 0) {
63 label.setName(
"TARGET");
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) ==
"'") {
77 label += line.Token(
"'").TrimHead(
" ").TrimTail(
" ").ToQt();
82 IString value = line.Token(
"/");
84 label += value.ToQt();
88 if (line.size() > 2) {
90 label.addComment(line.ToQt());
91 if (line != line.Token(
"[")) {
92 label.setUnits(line.Token(
"[").Token(
"]").ToQt());
96 fitsLabel->addKeyword(label);
99 fileStream.read(readBuf, 80);
106 fitsPvl.addGroup(*fitsLabel);
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());
116 if (fitsLabel->hasKeyword(
"BITPIX") && fitsLabel->hasKeyword(
"NAXIS")) {
118 if((
int)fitsLabel->findKeyword(
"NAXIS") > 0) {
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;
128 if (fitsLabel->hasKeyword(
"NAXIS2")) {
129 axis2 = toInt((*fitsLabel)[
"NAXIS2"]);
132 unsigned int axis3 = 1;
133 if (fitsLabel->hasKeyword(
"NAXIS3")) {
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();
154 fitsPvl.addGroup(*extraLabelGroup);
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.");
167 throw IException(IException::User, msg, _FILEINFO_);
182 std::ifstream fileStream;
184 fileStream.open(fitsFile.expanded().toLocal8Bit().constData(), std::ios::in | std::ios::binary);
186 catch (IException &e) {
187 QString msg = QString(
"Unable to open FITS formatted file [%1].")
188 .arg(fitsFile.toString());
189 throw IException(e, IException::User, msg, _FILEINFO_);