summaryrefslogtreecommitdiffstats
path: root/fitsy++
diff options
context:
space:
mode:
Diffstat (limited to 'fitsy++')
-rw-r--r--fitsy++/alloc.C25
-rw-r--r--fitsy++/alloc.h51
-rw-r--r--fitsy++/allocgz.C25
-rw-r--r--fitsy++/allocgz.h46
-rw-r--r--fitsy++/analysis.C94
-rw-r--r--fitsy++/analysis.h16
-rw-r--r--fitsy++/block.C195
-rw-r--r--fitsy++/block.h30
-rw-r--r--fitsy++/card.C288
-rw-r--r--fitsy++/card.h71
-rw-r--r--fitsy++/channel.C21
-rw-r--r--fitsy++/channel.h55
-rw-r--r--fitsy++/column.C671
-rw-r--r--fitsy++/column.h207
-rw-r--r--fitsy++/compress.C842
-rw-r--r--fitsy++/compress.h94
-rw-r--r--fitsy++/envi.C142
-rw-r--r--fitsy++/envi.h35
-rw-r--r--fitsy++/envilex.C2223
-rw-r--r--fitsy++/envilex.L194
-rw-r--r--fitsy++/enviparser.C2017
-rw-r--r--fitsy++/enviparser.H179
-rw-r--r--fitsy++/enviparser.Y271
-rw-r--r--fitsy++/file.C512
-rw-r--r--fitsy++/file.h233
-rw-r--r--fitsy++/gzip.C341
-rw-r--r--fitsy++/gzip.h19
-rw-r--r--fitsy++/hcompress.C119
-rw-r--r--fitsy++/hcompress.h22
-rw-r--r--fitsy++/hdecompress.c2619
-rw-r--r--fitsy++/hdu.C323
-rw-r--r--fitsy++/hdu.h111
-rw-r--r--fitsy++/head.C634
-rw-r--r--fitsy++/head.h133
-rw-r--r--fitsy++/hist.C686
-rw-r--r--fitsy++/hist.h59
-rw-r--r--fitsy++/hpx.C588
-rw-r--r--fitsy++/hpx.h37
-rw-r--r--fitsy++/iis.C81
-rw-r--r--fitsy++/iis.h20
-rw-r--r--fitsy++/lex.C1959
-rw-r--r--fitsy++/lex.L156
-rw-r--r--fitsy++/map.C418
-rw-r--r--fitsy++/map.h69
-rw-r--r--fitsy++/mapincr.C600
-rw-r--r--fitsy++/mapincr.h67
-rw-r--r--fitsy++/mmap.C68
-rw-r--r--fitsy++/mmap.h47
-rw-r--r--fitsy++/mmapincr.C53
-rw-r--r--fitsy++/mmapincr.h41
-rw-r--r--fitsy++/nrrd.C81
-rw-r--r--fitsy++/nrrd.h36
-rw-r--r--fitsy++/nrrdgzip.C84
-rw-r--r--fitsy++/nrrdgzip.h19
-rw-r--r--fitsy++/nrrdlex.C2462
-rw-r--r--fitsy++/nrrdlex.L215
-rw-r--r--fitsy++/nrrdparser.C2196
-rw-r--r--fitsy++/nrrdparser.H259
-rw-r--r--fitsy++/nrrdparser.Y398
-rw-r--r--fitsy++/order.C267
-rw-r--r--fitsy++/order.h21
-rw-r--r--fitsy++/outchannel.C30
-rw-r--r--fitsy++/outchannel.h20
-rw-r--r--fitsy++/outfile.C63
-rw-r--r--fitsy++/outfile.h33
-rw-r--r--fitsy++/outfits.C59
-rw-r--r--fitsy++/outfits.h27
-rw-r--r--fitsy++/outsocket.C200
-rw-r--r--fitsy++/outsocket.h38
-rw-r--r--fitsy++/parser.C2194
-rw-r--r--fitsy++/parser.H133
-rw-r--r--fitsy++/parser.Y292
-rw-r--r--fitsy++/photo.C154
-rw-r--r--fitsy++/photo.h31
-rw-r--r--fitsy++/plio.C91
-rw-r--r--fitsy++/plio.h19
-rw-r--r--fitsy++/pliocomp.c331
-rw-r--r--fitsy++/rice.C157
-rw-r--r--fitsy++/rice.h24
-rw-r--r--fitsy++/ricecomp.c1386
-rw-r--r--fitsy++/savefits.C358
-rw-r--r--fitsy++/share.C103
-rw-r--r--fitsy++/share.h98
-rw-r--r--fitsy++/shmload.C84
-rw-r--r--fitsy++/smap.C187
-rw-r--r--fitsy++/smap.h49
-rw-r--r--fitsy++/smmap.C105
-rw-r--r--fitsy++/smmap.h33
-rw-r--r--fitsy++/socket.C27
-rw-r--r--fitsy++/socket.h51
-rw-r--r--fitsy++/socketgz.C142
-rw-r--r--fitsy++/socketgz.h48
-rw-r--r--fitsy++/sshare.C149
-rw-r--r--fitsy++/sshare.h44
-rw-r--r--fitsy++/strm.C803
-rw-r--r--fitsy++/strm.h89
-rw-r--r--fitsy++/var.C53
-rw-r--r--fitsy++/var.h53
-rw-r--r--fitsy++/wcs.h1
99 files changed, 31604 insertions, 0 deletions
diff --git a/fitsy++/alloc.C b/fitsy++/alloc.C
new file mode 100644
index 0000000..508a0ec
--- /dev/null
+++ b/fitsy++/alloc.C
@@ -0,0 +1,25 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdio.h>
+#include "alloc.h"
+
+FitsAlloc::FitsAlloc(const char* fn)
+{
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // we need the 'b' for windows...
+ if (!strncmp(pName_, "stdin", 5) ||
+ !strncmp(pName_, "STDIN", 5) ||
+ !strncmp(pName_, "-", 1))
+ stream_ = fdopen(dup(fileno(stdin)), "rb");
+ else
+ stream_ = fopen(pName_, "rb");
+
+ valid_ = stream_ ? 1 : 0;
+}
+
+
diff --git a/fitsy++/alloc.h b/fitsy++/alloc.h
new file mode 100644
index 0000000..9ad2bcd
--- /dev/null
+++ b/fitsy++/alloc.h
@@ -0,0 +1,51 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsalloc_h__
+#define __fitsalloc_h__
+
+#include "strm.h"
+
+class FitsAlloc : public virtual FitsStream<FILE*> {
+public:
+ FitsAlloc(const char*);
+ virtual ~FitsAlloc() {}
+};
+
+class FitsFitsAlloc : public FitsAlloc, public FitsFitsStream<FILE*> {
+public:
+ FitsFitsAlloc(const char* fn, ScanMode mode, FlushMode flush)
+ : FitsAlloc(fn), FitsFitsStream<FILE*>(mode, flush) {}
+};
+
+class FitsFitsNextAlloc : public FitsFitsNextStream<FILE*> {
+public:
+ FitsFitsNextAlloc(FitsFile* prev) : FitsFitsNextStream<FILE*>(prev) {}
+};
+
+class FitsArrAlloc : public FitsAlloc, FitsArrStream<FILE*> {
+public:
+ FitsArrAlloc(const char* fn, FlushMode flush)
+ : FitsAlloc(fn), FitsArrStream<FILE*>(flush) {}
+};
+
+class FitsNRRDAlloc : public FitsAlloc, FitsNRRDStream<FILE*> {
+public:
+ FitsNRRDAlloc(const char* fn, FlushMode flush)
+ : FitsAlloc(fn), FitsNRRDStream<FILE*>(flush) {}
+};
+
+class FitsMosaicAlloc : public FitsAlloc, FitsMosaicStream<FILE*> {
+public:
+ FitsMosaicAlloc(const char* fn, FlushMode flush) :
+ FitsAlloc(fn), FitsMosaicStream<FILE*>(flush) {}
+};
+
+class FitsMosaicNextAlloc : public FitsMosaicNextStream<FILE*> {
+public:
+ FitsMosaicNextAlloc(FitsFile* prev, FlushMode flush)
+ : FitsMosaicNextStream<FILE*>(prev, flush) {}
+};
+
+#endif
diff --git a/fitsy++/allocgz.C b/fitsy++/allocgz.C
new file mode 100644
index 0000000..b2bbba1
--- /dev/null
+++ b/fitsy++/allocgz.C
@@ -0,0 +1,25 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <unistd.h>
+#include "allocgz.h"
+
+FitsAllocGZ::FitsAllocGZ(const char* fn)
+{
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // we need the 'b' for windows...
+ if (!strncmp(pName_, "stdin", 5) ||
+ !strncmp(pName_, "STDIN", 5) ||
+ !strncmp(pName_, "-", 1))
+ stream_ = gzdopen(dup(STDIN_FILENO), "rb");
+ else
+ stream_ = gzopen(pName_, "rb");
+
+ valid_ = stream_ ? 1 : 0;
+}
+
+
diff --git a/fitsy++/allocgz.h b/fitsy++/allocgz.h
new file mode 100644
index 0000000..c0a08e4
--- /dev/null
+++ b/fitsy++/allocgz.h
@@ -0,0 +1,46 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsallocgz_h__
+#define __fitsallocgz_h__
+
+#include "strm.h"
+#include "zlib.h"
+
+class FitsAllocGZ : public virtual FitsStream<gzFile> {
+public:
+ FitsAllocGZ(const char*);
+ virtual ~FitsAllocGZ() {}
+};
+
+class FitsFitsAllocGZ : public FitsAllocGZ, public FitsFitsStream<gzFile> {
+public:
+ FitsFitsAllocGZ(const char* fn, ScanMode mode, FlushMode flush)
+ : FitsAllocGZ(fn), FitsFitsStream<gzFile>(mode, flush) {}
+};
+
+class FitsFitsNextAllocGZ : public FitsFitsNextStream<gzFile> {
+public:
+ FitsFitsNextAllocGZ(FitsFile* prev) : FitsFitsNextStream<gzFile>(prev) {}
+};
+
+class FitsArrAllocGZ : public FitsAllocGZ, FitsArrStream<gzFile> {
+public:
+ FitsArrAllocGZ(const char* fn, FlushMode flush)
+ : FitsAllocGZ(fn), FitsArrStream<gzFile>(flush) {}
+};
+
+class FitsMosaicAllocGZ : public FitsAllocGZ, FitsMosaicStream<gzFile> {
+public:
+ FitsMosaicAllocGZ(const char* fn, FlushMode flush)
+ : FitsAllocGZ(fn), FitsMosaicStream<gzFile>(flush) {}
+};
+
+class FitsMosaicNextAllocGZ : public FitsMosaicNextStream<gzFile> {
+public:
+ FitsMosaicNextAllocGZ(FitsFile* prev, FlushMode flush)
+ : FitsMosaicNextStream<gzFile>(prev, flush) {}
+};
+
+#endif
diff --git a/fitsy++/analysis.C b/fitsy++/analysis.C
new file mode 100644
index 0000000..cf7280a
--- /dev/null
+++ b/fitsy++/analysis.C
@@ -0,0 +1,94 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "analysis.h"
+#include "util.h"
+
+FitsAnalysis::FitsAnalysis(FitsFile* src, int bitpix)
+{
+ primary_ = src->primary();
+ managePrimary_ = 0;
+
+ head_ = new FitsHead(*(src->head()));
+ manageHead_ = 1;
+
+ ext_ = src->ext();
+ inherit_ = src->inherit();
+
+ int width = head_->naxis(0);
+ int height = head_->naxis(1);
+ size_t size = (size_t)width*height;
+
+ switch (bitpix) {
+ case 8:
+ head_->setInteger("BITPIX", 8, "");
+ data_ = new unsigned char[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(unsigned char));
+ break;
+ case 16:
+ head_->setInteger("BITPIX", 16, "");
+ data_ = new short[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(short));
+ break;
+ case -16:
+ head_->setInteger("BITPIX", -16, "");
+ data_ = new unsigned short[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(unsigned short));
+ break;
+ case 32:
+ head_->setInteger("BITPIX", 32, "");
+ data_ = new int[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(int));
+ break;
+ case 64:
+ head_->setInteger("BITPIX", 64, "");
+ data_ = new long long[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(long long));
+ break;
+ case -32:
+ head_->setInteger("BITPIX", -32, "");
+ data_ = new float[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(float));
+ break;
+ case -64:
+ head_->setInteger("BITPIX", -64, "");
+ data_ = new double[size];
+ if (data_)
+ memset(data_, 0, size*sizeof(double));
+ break;
+ }
+
+ // alloc memory
+ if (!data_)
+ return;
+
+ // unset BZERO/BSCALE if present
+ if (head_->find("BZERO"))
+ head_->setReal("BZERO",0,2,NULL);
+
+ if (head_->find("BSCALE"))
+ head_->setReal("BSCALE",1,2,NULL);
+
+ head_->updateHDU();
+
+ // made it this far, must be valid
+ dataSize_ = size;
+ dataSkip_ = 0;
+ byteswap_ = 0;
+ endian_ = lsb() ? LITTLE : BIG;
+ valid_ = 1;
+}
+
+FitsAnalysis::~FitsAnalysis()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
diff --git a/fitsy++/analysis.h b/fitsy++/analysis.h
new file mode 100644
index 0000000..402f4c8
--- /dev/null
+++ b/fitsy++/analysis.h
@@ -0,0 +1,16 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsanalysis_h__
+#define __fitsanalysis_h__
+
+#include "file.h"
+
+class FitsAnalysis : public FitsFile {
+public:
+ FitsAnalysis(FitsFile*, int);
+ ~FitsAnalysis();
+};
+
+#endif
diff --git a/fitsy++/block.C b/fitsy++/block.C
new file mode 100644
index 0000000..b519e51
--- /dev/null
+++ b/fitsy++/block.C
@@ -0,0 +1,195 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "block.h"
+#include "util.h"
+
+FitsBlock::FitsBlock(FitsFile* fits, Vector& block)
+{
+ FitsHead* srcHead = fits->head();
+
+ width_ = srcHead->naxis(0)/block[0];
+ height_ = srcHead->naxis(1)/block[1];
+ if (width_<1)
+ width_ = 1;
+ if (height_<1)
+ height_ = 1;
+ size_ = (size_t)width_*height_;
+
+ primary_ = fits->primary();
+ ext_ = fits->ext();
+ inherit_ = fits->inherit();
+
+ bitpix_ = srcHead->hdu()->bitpix();
+ switch (bitpix_) {
+ case -64:
+ if (!(data_ = new double[size_]))
+ return;
+ dataSize_ = size_*sizeof(double);
+ break;
+ default:
+ bitpix_ = -32;
+ if (!(data_ = new float[size_]))
+ return;
+ dataSize_ = size_*sizeof(float);
+ break;
+ }
+ dataSkip_ = 0;
+ memset(data_, 0, dataSize_);
+
+ initHeader(fits, block);
+
+ // made it this far, must be valid
+ byteswap_ = 0;
+ endian_ = lsb() ? LITTLE : BIG;
+ valid_ = 1;
+}
+
+FitsBlock::~FitsBlock()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+void FitsBlock::initHeader(FitsFile* fits, Vector& block)
+{
+ head_ = new FitsHead(*(fits->head()));
+
+ // change bitpix
+ switch (bitpix_) {
+ case -64:
+ head_->setInteger("BITPIX", -64, "");
+ break;
+ default:
+ head_->setInteger("BITPIX", -32, "");
+ break;
+ }
+
+ // change width/height
+ head_->setInteger("NAXIS1", width_, "");
+ head_->setInteger("NAXIS2", height_, "");
+
+ // IRAF
+ initLTMV(block);
+ initCCDSUM(block);
+ initKeySEC("BIASSEC",block);
+ initKeySEC("DATASEC",block);
+ initKeySEC("TRIMSEC",block);
+
+ // WCS blocking done later in FitsImage::resetWCS()
+
+ // clear cards
+ if (head_->find("BZERO"))
+ head_->carddel("BZERO");
+ if (head_->find("BSCALE"))
+ head_->carddel("BSCALE");
+ if (head_->find("DATASUM"))
+ head_->carddel("DATASUM");
+ if (head_->find("CHECKSUM"))
+ head_->carddel("CHECKSUM");
+ if (head_->find("DATAMIN"))
+ head_->carddel("DATAMIN");
+ if (head_->find("DATAMAX"))
+ head_->carddel("DATAMAX");
+ if (head_->find("DATAMEAN"))
+ head_->carddel("DATAMEAN");
+ if (head_->find("GOODMIN"))
+ head_->carddel("GOODMIN");
+ if (head_->find("GOODMAX"))
+ head_->carddel("GOODMAX");
+ if (head_->find("IRAF-MIN"))
+ head_->carddel("IRAF-MIN");
+ if (head_->find("IRAF-MAX"))
+ head_->carddel("IRAF-MAX");
+
+ head_->updateHDU();
+}
+
+void FitsBlock::initCCDSUM(Vector& block)
+{
+ if (head_->find("CCDSUM")) {
+ char* val = head_->getString("CCDSUM");
+ float xx,yy;
+ istringstream istr(val);
+ istr >> xx >> yy;
+
+ xx *= block[0];
+ yy *= block[1];
+
+ ostringstream ostr;
+ ostr << xx << ' ' << yy << ends;
+ head_->setString("CCDSUM", ostr.str().c_str(), "");
+ }
+}
+
+void FitsBlock::initKeySEC(const char* key, Vector& block)
+{
+ if (head_->find(key)) {
+ char* sec = head_->getString(key);
+ Vector ll,ur;
+ parseSection(sec,&ll,&ur);
+ Matrix mm = Translate(-1,-1) *
+ Scale(1/block[0],1/block[1]) *
+ Translate(1,1);
+
+ Vector nll = ll*mm;
+ Vector nur = ur*mm;
+ ostringstream ostr;
+ ostr << '[' << int(nll[0]) << ':' << int(nur[0])
+ << ',' << int(nll[1]) << ':' << int(nur[1]) << ']' << ends;
+ head_->setString(key, ostr.str().c_str(), "");
+ }
+}
+
+void FitsBlock::initLTMV(Vector& block)
+{
+ // always do LTMV
+ double ltv1 = head_->getReal("LTV1", 0);
+ double ltv2 = head_->getReal("LTV2", 0);
+ double ltm11 = head_->getReal("LTM1_1", 1);
+ double ltm12 = head_->getReal("LTM1_2", 0);
+ double ltm21 = head_->getReal("LTM2_1", 0);
+ double ltm22 = head_->getReal("LTM2_2", 1);
+
+ Matrix mm(ltm11,ltm12,ltm21,ltm22,ltv1,ltv2);
+ Matrix im = mm *
+ Translate(-.5,-.5) *
+ Scale(1./block[0],1./block[1]) *
+ Translate(.5,.5);
+
+ if (head_->find("LTV1"))
+ head_->setReal("LTV1", im.matrix(2,0), 8, "");
+ else
+ head_->appendReal("LTV1", im.matrix(2,0), 8, "");
+
+ if (head_->find("LTV2"))
+ head_->setReal("LTV2", im.matrix(2,1), 8, "");
+ else
+ head_->appendReal("LTV2", im.matrix(2,1), 8, "");
+
+ if (head_->find("LTM1_1"))
+ head_->setReal("LTM1_1", ltm11/block[0], 8, "");
+ else
+ head_->appendReal("LTM1_1", ltm11/block[0], 8, "");
+
+ if (head_->find("LTM1_2"))
+ head_->setReal("LTM1_2", ltm12, 8, "");
+ else
+ head_->appendReal("LTM1_2", ltm12, 8, "");
+
+ if (head_->find("LTM2_1"))
+ head_->setReal("LTM2_1", ltm21, 8, "");
+ else
+ head_->appendReal("LTM2_1", ltm21, 8, "");
+
+ if (head_->find("LTM2_2"))
+ head_->setReal("LTM2_2", ltm22/block[1], 8, "");
+ else
+ head_->appendReal("LTM2_2", ltm22/block[1], 8, "");
+}
diff --git a/fitsy++/block.h b/fitsy++/block.h
new file mode 100644
index 0000000..816c788
--- /dev/null
+++ b/fitsy++/block.h
@@ -0,0 +1,30 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsblock_h__
+#define __fitsblock_h__
+
+#include "vector.h"
+#include "vectorstr.h"
+#include "file.h"
+
+class FitsBlock : public FitsFile {
+ protected:
+ int width_;
+ int height_;
+ size_t size_;
+ int bitpix_;
+
+ void initHeader(FitsFile*, Vector&);
+
+ void initCCDSUM(Vector&);
+ void initKeySEC(const char*, Vector&);
+ void initLTMV(Vector&);
+
+ public:
+ FitsBlock(FitsFile*, Vector&);
+ ~FitsBlock();
+};
+
+#endif
diff --git a/fitsy++/card.C b/fitsy++/card.C
new file mode 100644
index 0000000..1645d68
--- /dev/null
+++ b/fitsy++/card.C
@@ -0,0 +1,288 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "card.h"
+
+// only used to return pointer to internal string
+char FitsCard::buf_[FTY_CARDLEN];
+
+FitsCard::FitsCard()
+{
+ card_ = new char[FTY_CARDLEN];
+ managed = 1;
+}
+
+FitsCard::FitsCard(char* c)
+{
+ card_ = c;
+ managed = 0;
+}
+
+FitsCard::FitsCard(const FitsCard& a)
+{
+ card_ = new char[FTY_CARDLEN];
+ managed = 1;
+ memcpy(card_, a.card_, FTY_CARDLEN);
+}
+
+FitsCard::~FitsCard()
+{
+ if (managed)
+ delete [] card_;
+}
+
+FitsCard& FitsCard::operator=(const FitsCard& a)
+{
+ memcpy(card_, a.card_, FTY_CARDLEN);
+ return *this;
+}
+
+FitsCard& FitsCard::clear()
+{
+ memset(card_, ' ', FTY_CARDLEN);
+ return *this;
+}
+
+FitsCard& FitsCard::setKey(const char* name)
+{
+ if (name) {
+ memset(card_, ' ', 8);
+ ostringstream str;
+ str << name;
+ memcpy(card_,str.str().c_str(),str.str().length());
+ }
+
+ return *this;
+}
+
+FitsCard& FitsCard::setLogical(const char* name, int value,
+ const char* comment)
+{
+ setKey(name);
+ memset(card_+8, ' ', FTY_CARDLEN-8);
+
+ ostringstream str;
+ str << "= " << (value ? 'T' : 'F');
+ if (comment)
+ str << " / " << comment;
+ memcpy(card_+8,str.str().c_str(),str.str().length());
+
+ return *this;
+}
+
+FitsCard& FitsCard::setInteger(const char* name, int value,
+ const char* comment)
+{
+ setKey(name);
+ memset(card_+8, ' ', FTY_CARDLEN-8);
+
+ ostringstream str;
+ str << "= " << setw(20) << value;
+ if (comment)
+ str << " / " << comment;
+ memcpy(card_+8,str.str().c_str(),str.str().length());
+
+ return *this;
+}
+
+FitsCard& FitsCard::setReal(const char* name, double value,
+ int prec, const char* comment)
+{
+ setKey(name);
+ memset(card_+8, ' ', FTY_CARDLEN-8);
+
+ ostringstream str;
+ str << "= " << setw(20) << setprecision(prec)
+ << uppercase << value << nouppercase;
+ if (comment)
+ str << " / " << comment;
+ memcpy(card_+8,str.str().c_str(),str.str().length());
+
+ return *this;
+}
+
+FitsCard& FitsCard::setComplex(const char* name, double real, double img,
+ int prec, const char* comment)
+{
+ setKey(name);
+ memset(card_+8, ' ', FTY_CARDLEN-8);
+
+ ostringstream str;
+ str << "= " << setw(20) << setprecision(prec) << real << img;
+ if (comment)
+ str << " / " << comment;
+ memcpy(card_+8,str.str().c_str(),str.str().length());
+
+ return *this;
+}
+
+FitsCard& FitsCard::setString(const char* name, const char* value,
+ const char* comment)
+{
+ setKey(name);
+ memset(card_+8, ' ', FTY_CARDLEN-8);
+
+ ostringstream str;
+ str << "= '" << value << '\'';
+ if (comment)
+ str << " / " << comment;
+ memcpy(card_+8,str.str().c_str(),str.str().length());
+
+ return *this;
+}
+
+FitsCard& FitsCard::setComment(const char* name, const char* value)
+{
+ setKey(name);
+ memset(card_+8, ' ', FTY_CARDLEN-8);
+
+ ostringstream str;
+ str << "= " << value;
+ memcpy(card_+8,str.str().c_str(),str.str().length());
+
+ return *this;
+}
+
+int FitsCard::getLogical()
+{
+ for (int i=10; i<80; i++)
+ if (card_[i] != ' ')
+ return (card_[i] == 'T' || card_[i] == 't');
+
+ return 0;
+}
+
+int FitsCard::getInteger()
+{
+ string x(card_+10,FTY_CARDLEN-10);
+ istringstream str(x);
+ int r;
+ str >> r;
+ return r;
+}
+
+double FitsCard::getReal()
+{
+ // support 'D' as well as 'E' format
+ char buf[FTY_CARDLEN-10+1];
+ memcpy(buf, card_+10, FTY_CARDLEN-10);
+ buf[FTY_CARDLEN-10] = '\0';
+
+ char* ptr = buf;
+ while (*ptr && *ptr != '/') {
+ if (*ptr == 'D' || *ptr == 'E') {
+ *ptr = 'E';
+ break;
+ }
+ ptr++;
+ }
+
+ string x(buf,FTY_CARDLEN-10);
+ istringstream str(x);
+ double r;
+ str >> r;
+ return r;
+}
+
+void FitsCard::getComplex(double* r, double* i)
+{
+ // support 'D' as well as 'E' format
+ char buf[FTY_CARDLEN-10+1];
+ memcpy(buf, card_+10, FTY_CARDLEN-10);
+ buf[FTY_CARDLEN-10] = '\0';
+
+ char* ptr = buf;
+ while (*ptr && *ptr != '/') {
+ if (*ptr == 'D' || *ptr == 'E') {
+ *ptr = 'E';
+ }
+ ptr++;
+ }
+
+ string x(buf,FTY_CARDLEN-10);
+ istringstream str(x);
+ str >> *r >> *i;
+}
+
+char* FitsCard::getString()
+{
+ buf_[0] = '\0';
+ buf_[FTY_CARDLEN-1] = '\0';
+
+ int i,j;
+
+ // find first '
+ for (i=10; i<FTY_CARDLEN; i++)
+ if (card_[i] == '\'')
+ break;
+
+ // now find last '
+ i++;
+ for (j=0; i<FTY_CARDLEN; i++,j++) {
+ if (card_[i] == '\'') {
+ if (i+1 == FTY_CARDLEN || card_[i+1] != '\'')
+ break;
+ else
+ i++;
+ }
+ buf_[j] = card_[i];
+ }
+
+ // DON'T strip any spaces
+ // for (; j && buf_[j-1]==' '; j--);
+ buf_[j] = '\0';
+
+ return buf_;
+}
+
+char* FitsCard::getComment()
+{
+ char* cpy = new char[FTY_CARDLEN-7];
+ memcpy(cpy, card_+8, FTY_CARDLEN-8);
+ cpy[FTY_CARDLEN-8] = '\0';
+
+ return cpy;
+}
+
+char* FitsCard::getKeyword()
+{
+ char value[FTY_CARDLEN];
+ value[0] = '\0';
+
+ int ii,jj;
+ int str =0;
+
+ for (ii=10; ii<FTY_CARDLEN; ii++) {
+ if (card_[ii] != ' ') {
+ if (card_[ii] == '\'' || card_[ii] == '\"') {
+ str = 1;
+ ii++;
+ }
+ break;
+ }
+ }
+
+ for (jj=0; ii<FTY_CARDLEN; ii++,jj++) {
+ if (!str) {
+ if (card_[ii] == '/')
+ break;
+ }
+ else {
+ if (card_[ii] == '\'' || card_[ii] == '\"')
+ break;
+ }
+
+ value[jj] = card_[ii];
+ }
+
+ // strip any spaces
+ for (; jj && value[jj-1]==' '; jj--);
+ value[jj] = '\0';
+
+ // return result
+ char* cpy = new char[strlen(value)+1];
+ strcpy(cpy, value);
+ return cpy;
+}
+
diff --git a/fitsy++/card.h b/fitsy++/card.h
new file mode 100644
index 0000000..1838c69
--- /dev/null
+++ b/fitsy++/card.h
@@ -0,0 +1,71 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitscard_h__
+#define __fitscard_h__
+
+#define FTY_CARDLEN 80
+
+#include <string.h>
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+class FitsCard {
+private:
+ char* card_;
+ int managed;
+ // only used to return pointer to internal string
+ static char buf_[FTY_CARDLEN];
+
+public:
+ FitsCard();
+ FitsCard(char*);
+ FitsCard(const FitsCard&);
+ ~FitsCard();
+ FitsCard& operator=(const FitsCard&);
+
+ char* card() {return card_;}
+
+ FitsCard& clear();
+
+ FitsCard& setKey(const char *name);
+
+ FitsCard& setLogical(const char* name, int value, const char* comment);
+ FitsCard& setLogical(int value, const char *comment)
+ {return setLogical(NULL, value, comment);}
+
+ FitsCard& setInteger(const char* name, int value, const char *comment);
+ FitsCard& setInteger(int value, const char *comment)
+ {return setInteger(NULL, value, comment);}
+
+ FitsCard& setReal(const char* name, double value, int prec, const char *comment);
+ FitsCard& setReal(double value, int prec, const char *comment)
+ {return setReal(NULL, value, prec, comment);}
+
+ FitsCard& setComplex(const char* name, double real, double img,
+ int prec, const char *comment);
+ FitsCard& setComplex(double real, double img, int prec, const char *comment)
+ {return setComplex(NULL, real, img, prec, comment);}
+
+ FitsCard& setString(const char* name, const char *value, const char *comm);
+ FitsCard& setString(const char *value, const char *comment)
+ {return setString(NULL, value, comment);}
+
+ FitsCard& setComment(const char* name, const char* value);
+ FitsCard& setComment(const char *value)
+ {return setComment(NULL, value);}
+
+ int getLogical();
+ int getInteger();
+ double getReal();
+ void getComplex(double*, double*);
+ char* getString();
+ char* getComment();
+ char* getKeyword();
+};
+
+#endif
diff --git a/fitsy++/channel.C b/fitsy++/channel.C
new file mode 100644
index 0000000..7fb106f
--- /dev/null
+++ b/fitsy++/channel.C
@@ -0,0 +1,21 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <tcl.h>
+
+#include "channel.h"
+
+FitsChannel::FitsChannel(Tcl_Interp* interp, const char* ch, const char* ext)
+{
+ parse(ext);
+ if (!valid_)
+ return;
+
+ int tclMode;
+ stream_ = Tcl_GetChannel(interp, (char*)ch, &tclMode);
+
+ valid_ = stream_ ? 1 : 0;
+}
+
+
diff --git a/fitsy++/channel.h b/fitsy++/channel.h
new file mode 100644
index 0000000..5cd4bc2
--- /dev/null
+++ b/fitsy++/channel.h
@@ -0,0 +1,55 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitschannel_h__
+#define __fitschannel_h__
+
+#include "strm.h"
+
+class FitsChannel : public virtual FitsStream<Tcl_Channel> {
+public:
+ FitsChannel(Tcl_Interp*, const char*, const char*);
+};
+
+class FitsFitsChannel : public FitsChannel, public FitsFitsStream<Tcl_Channel>{
+public:
+ FitsFitsChannel(Tcl_Interp* interp, const char* ch,
+ const char* ext, ScanMode mode, FlushMode flush)
+ : FitsChannel(interp, ch, ext), FitsFitsStream<Tcl_Channel>(mode, flush) {}
+};
+
+class FitsFitsNextChannel : public FitsFitsNextStream<Tcl_Channel> {
+public:
+ FitsFitsNextChannel(FitsFile* prev)
+ : FitsFitsNextStream<Tcl_Channel>(prev) {}
+};
+
+class FitsArrChannel : public FitsChannel, FitsArrStream<Tcl_Channel> {
+public:
+ FitsArrChannel(Tcl_Interp* interp, const char* ch, const char* ext,
+ FlushMode flush)
+ : FitsChannel(interp, ch, ext), FitsArrStream<Tcl_Channel>(flush) {}
+};
+
+class FitsNRRDChannel : public FitsChannel, FitsNRRDStream<Tcl_Channel> {
+public:
+ FitsNRRDChannel(Tcl_Interp* interp, const char* ch, const char* ext,
+ FlushMode flush)
+ : FitsChannel(interp, ch, ext), FitsNRRDStream<Tcl_Channel>(flush) {}
+};
+
+class FitsMosaicChannel : public FitsChannel, FitsMosaicStream<Tcl_Channel> {
+public:
+ FitsMosaicChannel(Tcl_Interp* interp, const char* ch, FlushMode flush)
+ : FitsChannel(interp, ch, ""), FitsMosaicStream<Tcl_Channel>(flush) {}
+};
+
+class FitsMosaicNextChannel : public FitsMosaicNextStream<Tcl_Channel> {
+public:
+ FitsMosaicNextChannel(FitsFile* prev, FlushMode flush)
+ : FitsMosaicNextStream<Tcl_Channel>(prev, flush) {}
+};
+
+#endif
+
diff --git a/fitsy++/column.C b/fitsy++/column.C
new file mode 100644
index 0000000..b6052ab
--- /dev/null
+++ b/fitsy++/column.C
@@ -0,0 +1,671 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <float.h>
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "column.h"
+#include "file.h"
+#include "head.h"
+#include "util.h"
+
+FitsColumn::FitsColumn(FitsHead* head, int i, int off)
+{
+ index_ = i;
+ width_ = 0;
+ offset_ = off;
+ type_ = ' ';
+
+ tform_ = dupstr(head->getString(keycat("TFORM",i)));
+ ttype_ = dupstr(head->getString(keycat("TTYPE",i)));
+ tunit_ = dupstr(head->getString(keycat("TUNIT",i)));
+ tscal_ = head->getReal(keycat("TSCAL",i), 1);
+ tzero_ = head->getReal(keycat("TZERO",i), 0);
+ hastnull_ = head->find(keycat("TNULL",i)) ? 1:0;
+ tnull_ = head->getInteger(keycat("TNULL",i), 0);
+
+ char* td = head->find(keycat("TDMAX",i));
+ char* tl = head->find(keycat("TLMAX",i));
+ char* ta = head->find(keycat("TALEN",i));
+ char* ax = head->find(keycat("AXLEN",i));
+
+ // this provides backward compatibility
+ if (td) {
+ hastlmin_ = head->find(keycat("TDMIN",i)) ? 1:0;
+ hastlmax_ = 1;
+ tlmin_ = head->getReal(keycat("TDMIN",i), 0);
+ tlmax_ = head->getReal(keycat("TDMAX",i), 0);
+ }
+ else if (tl) {
+ hastlmin_ = head->find(keycat("TLMIN",i)) ? 1:0;
+ hastlmax_ = 1;
+ tlmin_ = head->getReal(keycat("TLMIN",i), 0);
+ tlmax_ = head->getReal(keycat("TLMAX",i), 0);
+ }
+ else if (ta) {
+ hastlmin_ = 0;
+ hastlmax_ = 1;
+ tlmin_ = 1;
+ tlmax_ = head->getReal(keycat("TALEN",i), 0);
+ }
+ else if (ax) {
+ hastlmin_ = 0;
+ hastlmax_ = 1;
+ tlmin_ = 1;
+ tlmax_ = head->getReal(keycat("AXLEN",i), 0);
+ }
+ else {
+ hastlmin_ = 0;
+ hastlmax_ = 0;
+ tlmin_ = 0;
+ tlmax_ = 0;
+ }
+
+ // now, make sure they are valid
+ if (tlmin_>tlmax_) {
+ hastlmin_ = 0;
+ hastlmax_ = 0;
+ tlmin_ = 0;
+ tlmax_ = 0;
+ }
+
+ // use tlmin/tlmax if available
+ if (hastlmin_ || hastlmax_) {
+ min_ = tlmin_;
+ max_ = tlmax_;
+ }
+ else {
+ min_ = -DBL_MAX;
+ max_ = DBL_MAX;
+ }
+}
+
+FitsColumn::~FitsColumn()
+{
+ if (tform_)
+ delete [] tform_;
+ if (tunit_)
+ delete [] tunit_;
+ if (ttype_)
+ delete [] ttype_;
+}
+
+char* FitsColumn::keycat(const char* name, int i)
+{
+ ostringstream str;
+ str << name << i << ends;
+ memcpy(keybuf,str.str().c_str(),str.str().length());
+ return keybuf;
+}
+
+// FitsAsciiColumn
+
+FitsAsciiColumn::FitsAsciiColumn(FitsHead* head, int i, int offset)
+ : FitsColumn(head, i, offset)
+{
+ int tbcol = head->getInteger(keycat("TBCOL",i),0);
+ if (tbcol)
+ offset_ = tbcol-1;
+}
+
+char* FitsAsciiColumn::str(const char* ptr, int i)
+{
+ strncpy(buf_, ptr+offset_, width_);
+ buf_[width_] = '\0';
+ return buf_;
+}
+
+FitsAsciiColumnStr::FitsAsciiColumnStr(FitsHead* head, int i, int offset)
+ : FitsAsciiColumn(head, i, offset)
+{
+ if (tform_) {
+ string x(tform_);
+ istringstream str(x);
+ str >> type_ >> width_;
+ }
+}
+
+FitsAsciiColumnA::FitsAsciiColumnA(FitsHead* head, int i, int offset)
+ : FitsAsciiColumn(head, i, offset)
+{
+ prec_ = 0;
+
+ if (tform_) {
+ char s;
+ string x(tform_);
+ istringstream str(x);
+ str >> type_ >> width_ >> s >> prec_;
+ }
+}
+
+double FitsAsciiColumnA::value(const char* ptr, int i)
+{
+ string x(ptr+offset_);
+ istringstream str(x);
+ double r;
+ str >> r;
+
+ return r;
+}
+
+template<class T> FitsAsciiColumnT<T>::FitsAsciiColumnT(FitsHead* head,
+ int i, int off)
+ : FitsAsciiColumnA(head, i, off) {}
+
+template <> Vector FitsAsciiColumnT<int>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_,tlmax_)
+ : Vector(INT_MIN,INT_MAX);
+}
+
+template <> Vector FitsAsciiColumnT<float>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_,tlmax_)
+ : Vector(-FLT_MAX,FLT_MAX);
+}
+
+template <> Vector FitsAsciiColumnT<double>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_,tlmax_)
+ : Vector(-DBL_MAX,DBL_MAX);
+}
+
+// FitsBinColumn
+
+FitsBinColumn::FitsBinColumn(FitsHead* head, int i, int offset)
+ : FitsColumn(head, i, offset)
+{
+ tdisp_ = dupstr(head->getString(keycat("TDISP",i)));
+
+ repeat_ = 1;
+ if (tform_) {
+ string x(tform_);
+ istringstream str(x);
+ if (isalpha(tform_[0]))
+ str >> type_;
+ else
+ str >> repeat_ >> type_;
+ }
+
+ tdim_ = dupstr(head->getString(keycat("TDIM",i)));
+ tdimM_ =0;
+ tdimK_ =NULL;
+ char dummy;
+ if (tdim_) {
+ string x(tdim_);
+ istringstream str(x);
+ str >> dummy >> tdimM_;
+ if (tdimM_>0) {
+ tdimK_ = new int[tdimM_];
+ for (int ii=0; ii<tdimM_; ii++)
+ str >> dummy >> tdimK_[ii];
+ }
+ }
+}
+
+FitsBinColumn::~FitsBinColumn()
+{
+ if (tdisp_)
+ delete [] tdisp_;
+
+ if (tdim_)
+ delete [] tdim_;
+
+ if (tdimK_)
+ delete [] tdimK_;
+}
+
+// FitsBinColumnStr
+
+FitsBinColumnStr::FitsBinColumnStr(FitsHead* head, int i, int offset)
+ : FitsBinColumn(head, i, offset)
+{
+ width_ = repeat_;
+}
+
+char* FitsBinColumnStr::str(const char* ptr, int i)
+{
+ strncpy(buf_, ptr+offset_, width_);
+ buf_[width_] = '\0';
+ return buf_;
+}
+
+// FitsBinColumnLogical
+
+FitsBinColumnLogical::FitsBinColumnLogical(FitsHead* head, int i, int offset)
+ : FitsBinColumn(head, i, offset)
+{
+ width_ = repeat_;
+}
+
+char* FitsBinColumnLogical::str(const char* ptr, int i)
+{
+ strncpy(buf_, ptr+offset_+i, 1);
+ buf_[width_] = '\0';
+ return buf_;
+}
+
+// FitsBinColumnArray
+
+FitsBinColumnArray::FitsBinColumnArray(FitsHead* head, int i, int offset)
+ : FitsBinColumn(head, i, offset)
+{
+ ptype_ = ' ';
+ psize_ = 1;
+ pmax_ = 1;
+ abuf_ = NULL;
+
+ byteswap_ = lsb();
+
+ if (tform_) {
+ int rr;
+ char tt;
+ string x(tform_);
+ istringstream str(x);
+ if (isalpha(tform_[0]))
+ str >> tt;
+ else
+ str >> rr >> tt;
+
+ char s;
+ str >> ptype_ >> s >> pmax_ >> s;
+
+ switch (ptype_) {
+ case 'L':
+ psize_ = 1;
+ break;
+ case 'X':
+ psize_ = 1;
+ break;
+ case 'B':
+ psize_ = 1;
+ break;
+ case 'I':
+ psize_ = 2;
+ break;
+ case 'J':
+ psize_ = 4;
+ break;
+ case 'K':
+ psize_ = 8;
+ break;
+ case 'A':
+ psize_ = 1;
+ break;
+ case 'E':
+ psize_ = 4;
+ break;
+ case 'D':
+ psize_ = 8;
+ break;
+ case 'C':
+ psize_ = 8;
+ break;
+ case 'M':
+ psize_ = 16;
+ break;
+
+ default:
+ internalError("Fitsy++ column unknown table column type.");
+ return;
+ }
+
+ // sanity check
+ pmax_ *= psize_;
+
+ if (pmax_ > 0)
+ abuf_ = new char[pmax_];
+ }
+}
+
+FitsBinColumnArray::~FitsBinColumnArray()
+{
+ if (abuf_)
+ delete [] abuf_;
+}
+
+void* FitsBinColumnArray::get(const char* heap, const char* ptr, int* cnt)
+{
+ *cnt = swap(ptr,0);
+ if (*cnt > pmax_) {
+ // just in case
+ internalError("Fitsy++ column variable array size greater than specified");
+ *cnt = pmax_;
+ }
+ size_t pp = swap(ptr,1);
+
+ if (abuf_) {
+ memset(abuf_,0,pmax_);
+ memcpy(abuf_,heap+pp,(*cnt)*psize_);
+ }
+
+ return abuf_;
+}
+
+FitsBinColumnArrayP::FitsBinColumnArrayP(FitsHead* head, int i, int offset)
+ : FitsBinColumnArray(head, i, offset)
+{
+ width_ = 8;
+}
+
+int FitsBinColumnArrayP::swap(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*4;
+ union {
+ char c[4];
+ int i;
+ } u;
+
+ if (byteswap_) {
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,4);
+
+ return u.i;
+}
+
+FitsBinColumnArrayQ::FitsBinColumnArrayQ(FitsHead* head, int i, int offset)
+ : FitsBinColumnArray(head, i, offset)
+{
+ width_ = 16;
+}
+
+int FitsBinColumnArrayQ::swap(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*8;
+ union {
+ char c[8];
+ long l;
+ } u;
+
+ if (byteswap_) {
+ u.c[7] = *p++;
+ u.c[6] = *p++;
+ u.c[5] = *p++;
+ u.c[4] = *p++;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,8);
+
+ return u.l;
+}
+
+// FitsbinColumnBit
+
+FitsBinColumnBit::FitsBinColumnBit(FitsHead* head, int i, int off)
+ : FitsBinColumn(head, i, off)
+{
+ width_ = (repeat_+7)/8;
+}
+
+// FitsBinColumnB
+
+FitsBinColumnB::FitsBinColumnB(FitsHead* head, int i, int offset)
+ : FitsBinColumn(head, i, offset)
+{
+ byteswap_ = lsb();
+}
+
+// FitsBinColumnT
+
+template<class T> FitsBinColumnT<T>::FitsBinColumnT(FitsHead* head,
+ int i, int off)
+ : FitsBinColumnB(head, i, off)
+{
+ width_ = repeat_ * sizeof(T);
+}
+
+template <> double FitsBinColumnT<unsigned char>::value(const char* ptr, int i)
+{
+ return (unsigned char)(*(ptr+offset_+i));
+}
+
+template <> double FitsBinColumnT<short>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*2;
+ union {
+ char c[2];
+ short s;
+ } u;
+
+ if (byteswap_) {
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else {
+ u.c[0] = *p++;
+ u.c[1] = *p;
+ }
+
+ return u.s;
+}
+
+template <> double FitsBinColumnT<unsigned short>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*2;
+ union {
+ char c[2];
+ unsigned short s;
+ } u;
+
+ if (byteswap_) {
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else {
+ u.c[0] = *p++;
+ u.c[1] = *p;
+ }
+
+ return u.s;
+}
+
+template <> double FitsBinColumnT<int>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*4;
+ union {
+ char c[4];
+ int i;
+ } u;
+
+ if (byteswap_) {
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,4);
+
+ return u.i;
+}
+
+template <> double FitsBinColumnT<unsigned int>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*4;
+ union {
+ char c[4];
+ unsigned int i;
+ } u;
+
+ if (byteswap_) {
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,4);
+
+ return u.i;
+}
+
+template <> double FitsBinColumnT<long long>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*8;
+ union {
+ char c[8];
+ long long i;
+ } u;
+
+ if (byteswap_) {
+ u.c[7] = *p++;
+ u.c[6] = *p++;
+ u.c[5] = *p++;
+ u.c[4] = *p++;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,8);
+
+ return u.i;
+}
+
+template <> double FitsBinColumnT<float>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*4;
+ union {
+ char c[4];
+ float f;
+ } u;
+
+ if (byteswap_) {
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,4);
+
+ return u.f;
+}
+
+template <> double FitsBinColumnT<double>::value(const char* ptr, int i)
+{
+ const char* p = ptr+offset_+i*8;
+ union {
+ char c[8];
+ double d;
+ } u;
+
+ if (byteswap_) {
+ u.c[7] = *p++;
+ u.c[6] = *p++;
+ u.c[5] = *p++;
+ u.c[4] = *p++;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ }
+ else
+ memcpy(u.c,p,8);
+
+ return u.d;
+}
+
+template<class T> char* FitsBinColumnT<T>::str(const char* ptr, int i)
+{
+ ostringstream ost;
+ ost << value(ptr,i) << ends;
+ return (char*)dupstr(ost.str().c_str());
+}
+
+template <> Vector FitsBinColumnT<unsigned char>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_-.5,tlmax_+.5)
+ : Vector(0,UCHAR_MAX);
+}
+
+template <> Vector FitsBinColumnT<short>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_-.5,tlmax_+.5)
+ : Vector(SHRT_MIN,SHRT_MAX);
+}
+
+template <> Vector FitsBinColumnT<unsigned short>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_-.5,tlmax_+.5)
+ : Vector(0,USHRT_MAX);
+}
+
+template <> Vector FitsBinColumnT<int>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_-.5,tlmax_+.5)
+ : Vector(INT_MIN,INT_MAX);
+}
+
+template <> Vector FitsBinColumnT<unsigned int>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_-.5,tlmax_+.5)
+ : Vector(0,UINT_MAX);
+}
+
+// some older versions of gcc do not have LLONG
+#ifndef LLONG_MIN
+# ifdef LONG_LONG_MIN
+# define LLONG_MIN LONG_LONG_MIN
+# else
+# define LLONG_MIN LONG_MIN
+# endif
+#endif
+
+#ifndef LLONG_MAX
+# ifdef LONG_LONG_MAX
+# define LLONG_MAX LONG_LONG_MAX
+# else
+# define LLONG_MAX LONG_MAX
+# endif
+#endif
+
+template <> Vector FitsBinColumnT<long long>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_-.5,tlmax_+.5)
+ : Vector(LLONG_MIN,LLONG_MAX);
+}
+
+template <> Vector FitsBinColumnT<float>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_,tlmax_)
+ : Vector(-FLT_MAX,FLT_MAX);
+}
+
+template <> Vector FitsBinColumnT<double>::dimension()
+{
+ return (hastlmin_ || hastlmax_) ? Vector(tlmin_,tlmax_)
+ : Vector(-DBL_MAX,DBL_MAX);
+}
+
+template class FitsAsciiColumnT<int>;
+template class FitsAsciiColumnT<float>;
+template class FitsAsciiColumnT<double>;
+
+template class FitsBinColumnT<unsigned char>;
+template class FitsBinColumnT<short>;
+template class FitsBinColumnT<unsigned short>;
+template class FitsBinColumnT<int>;
+template class FitsBinColumnT<unsigned int>;
+template class FitsBinColumnT<long long>;
+template class FitsBinColumnT<float>;
+template class FitsBinColumnT<double>;
diff --git a/fitsy++/column.h b/fitsy++/column.h
new file mode 100644
index 0000000..12cfa61
--- /dev/null
+++ b/fitsy++/column.h
@@ -0,0 +1,207 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitscolumn_h__
+#define __fitscolumn_h__
+
+#include "vector.h"
+
+class FitsHead;
+
+class FitsColumn {
+protected:
+ int index_; // col number 1 to n
+ int width_; // overall width of field in chars
+ int offset_; // offset in chars from start of row
+ char type_; // type
+
+ char* tform_;
+ char* ttype_;
+ char* tunit_;
+ float tscal_;
+ float tzero_;
+
+ int tnull_;
+ int hastnull_;
+
+ float tlmin_;
+ float tlmax_;
+ int hastlmin_;
+ int hastlmax_;
+
+ double min_;
+ double max_;
+ int validmm_;
+
+ char buf_[128];
+
+ char keybuf[9];
+ char* keycat(const char*, int);
+
+public:
+ FitsColumn(FitsHead*, int, int);
+ virtual ~FitsColumn();
+
+ int width() {return width_;}
+ int offset() {return offset_;}
+ int index() {return index_;}
+ char type() {return type_;}
+
+ const char* tform() {return tform_;}
+ const char* ttype() {return ttype_;}
+ const char* tunit() {return tunit_;}
+ float tscal() {return tscal_;}
+ float tzero() {return tzero_;}
+ int tnull() {return tnull_;}
+ float tlmin() {return tlmin_;}
+ float tlmax() {return tlmax_;}
+
+ int hasscaling() {return tscal_ != 1 || tzero_ != 0;}
+ int hastnull() {return hastnull_;}
+
+ virtual double value(const char* ptr, int i =0) {return 0;}
+ virtual char* str(const char* ptr, int i =0) {return NULL;}
+ virtual Vector dimension() {return Vector();}
+ virtual int repeat() {return 1;}
+
+ void setMin(double m) {min_=m;}
+ void setMax(double m) {max_=m;}
+
+ double getMin() {return min_;}
+ double getMax() {return max_;}
+
+ int hasMinMax() {return min_ != -DBL_MAX ? 1 : 0;}
+ int hasTLMinTLMax() {return hastlmin_ && hastlmax_;}
+};
+
+// FitsAsciiColumn
+
+class FitsAsciiColumn : public FitsColumn {
+public:
+ FitsAsciiColumn(FitsHead*, int, int);
+
+ char* str(const char* ptr, int i =0);
+};
+
+class FitsAsciiColumnStr : public FitsAsciiColumn {
+public:
+ FitsAsciiColumnStr(FitsHead*, int, int);
+};
+
+class FitsAsciiColumnA : public FitsAsciiColumn {
+private:
+ int prec_;
+
+public:
+ FitsAsciiColumnA(FitsHead*, int, int);
+
+ double value(const char*, int i =0);
+};
+
+template<class T>
+class FitsAsciiColumnT : public FitsAsciiColumnA {
+public:
+ FitsAsciiColumnT(FitsHead*, int, int);
+
+ Vector dimension();
+};
+
+// FitsBinColumn
+
+class FitsBinColumn : public FitsColumn {
+protected:
+ char* tdisp_;
+ int repeat_; // repeat count
+ char* tdim_;
+ int tdimM_;
+ int* tdimK_;
+
+public:
+ FitsBinColumn(FitsHead*, int, int);
+ ~FitsBinColumn();
+
+ const char* tdisp() {return tdisp_;}
+ int repeat() {return repeat_;}
+ const char* tdim() {return tdim_;}
+ int tdimM() {return tdimM_;}
+ int* tdimK() {return tdimK_;}
+ int tdimK(int ii) {return tdimK_[ii];}
+};
+
+class FitsBinColumnStr : public FitsBinColumn {
+public:
+ FitsBinColumnStr(FitsHead*, int, int);
+
+ char* str(const char* ptr, int i =0);
+};
+
+class FitsBinColumnLogical : public FitsBinColumn {
+public:
+ FitsBinColumnLogical(FitsHead*, int, int);
+
+ double value(const char* ptr, int i =0)
+ {return (*(ptr+offset_+i) == 'T') ? 1 : 0;}
+ char* str(const char* ptr, int i =0);
+};
+
+class FitsBinColumnArray : public FitsBinColumn {
+ protected:
+ int byteswap_;
+ char ptype_;
+ int psize_;
+ int pmax_;
+ char* abuf_;
+
+ virtual int swap(const char* ptr, int i =0) =0;
+
+public:
+ FitsBinColumnArray(FitsHead*, int, int);
+ virtual ~FitsBinColumnArray();
+
+ virtual void* get(const char* heap, const char* ptr, int* cnt);
+};
+
+class FitsBinColumnArrayP : public FitsBinColumnArray {
+ protected:
+ int swap(const char* ptr, int i =0);
+
+public:
+ FitsBinColumnArrayP(FitsHead*, int, int);
+};
+
+class FitsBinColumnArrayQ : public FitsBinColumnArray {
+ protected:
+ int swap(const char* ptr, int i =0);
+
+public:
+ FitsBinColumnArrayQ(FitsHead*, int, int);
+};
+
+class FitsBinColumnBit : public FitsBinColumn {
+public:
+ FitsBinColumnBit(FitsHead*, int, int);
+};
+
+class FitsBinColumnB : public FitsBinColumn {
+protected:
+ int byteswap_;
+
+public:
+ FitsBinColumnB(FitsHead*, int, int);
+};
+
+template<class T>
+class FitsBinColumnT : public FitsBinColumnB {
+private:
+ T swap(T*);
+
+public:
+ FitsBinColumnT(FitsHead*, int, int);
+
+ double value(const char*, int i =0);
+ char* str(const char* ptr, int i =0);
+ Vector dimension();
+};
+
+#endif
diff --git a/fitsy++/compress.C b/fitsy++/compress.C
new file mode 100644
index 0000000..873a3d3
--- /dev/null
+++ b/fitsy++/compress.C
@@ -0,0 +1,842 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "compress.h"
+#include "head.h"
+#include "zlib.h"
+#include "util.h"
+
+FitsCompress::FitsCompress(FitsFile* fits)
+{
+ bitpix_ = fits->getInteger("ZBITPIX",0);
+ type_ = dupstr(fits->getString("ZCMPTYPE"));
+ // int naxes = fits->getInteger("ZNAXIS",0);
+ width_ = fits->getInteger("ZNAXIS1",0);
+ height_ = fits->getInteger("ZNAXIS2",0);
+ depth_ = fits->getInteger("ZNAXIS3",1);
+ if (depth_<1)
+ depth_ =1;
+ ww_ = fits->getInteger("ZTILE1",width_);
+ hh_ = fits->getInteger("ZTILE2",1);
+ dd_ = fits->getInteger("ZTILE3",1);
+ bscale_ = fits->getReal("ZSCALE",1);
+ bzero_ = fits->getReal("ZZERO",0);
+ blank_ = fits->getInteger("ZBLANK",0);
+ zmaskcmp_ = dupstr(fits->getString("ZMASKCMP"));
+
+ quantize_ = NODITHER;
+ char keyword[] = "ZQUANTIZ";
+ if (fits->find(keyword)) {
+ char* str = fits->getString(keyword);
+ if (!strncmp(str,"NONE",4))
+ quantize_ = NONE;
+ if (!strncmp(str,"NO_DITHER",4))
+ quantize_ = NODITHER;
+ else if (!strncmp(str,"SUBTRACTIVE_DITHER_1",20))
+ quantize_ = SUBDITHER1;
+ else if (!strncmp(str,"SUBTRACTIVE_DITHER_2",20))
+ quantize_ = SUBDITHER2;
+ }
+ quantOffset_ = fits->getInteger("ZDITHER0",1);
+
+ tilesize_ = (size_t)ww_*hh_*dd_;
+ size_ = (size_t)width_*height_*depth_;
+
+ FitsHead* srcHead = fits->head();
+ FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu());
+ uncompress_ = srcHDU->find("UNCOMPRESSED_DATA");
+ gzcompress_ = srcHDU->find("GZIP_COMPRESSED_DATA");
+ compress_ = srcHDU->find("COMPRESSED_DATA");
+ zscale_ = srcHDU->find("ZSCALE");
+ zzero_ = srcHDU->find("ZZERO");
+ zblank_ = srcHDU->find("ZBLANK");
+ null_ = srcHDU->find("NULL_PIXEL_MASK");
+
+ hasScaling_ = (zscale_ && zzero_) || (fits->find("ZSCALE") && fits->find("ZZERO")) ? 1 : 0;
+ hasBlank_ = zblank_ || fits->find("ZBLANK") ? 1 : 0;
+
+ // Random seq
+ double aa =16807;
+ double mm =2147483647;
+ double seed =1;
+ numRandom_ =10000;
+ random_ = new float[numRandom_];
+
+ for (int ii=0; ii<numRandom_; ii++) {
+ double tmp = aa*seed;
+ seed = tmp-mm*((int)(tmp/mm));
+ random_[ii] = (float)(seed/mm);
+ }
+
+ if (seed != 1043618065)
+ internalError("Fitsy++ generated incorrect random number sequence");
+}
+
+FitsCompress::~FitsCompress()
+{
+ if (type_)
+ delete [] type_;
+ if (zmaskcmp_)
+ delete [] zmaskcmp_;
+ if (data_)
+ delete [] (char*)data_;
+ if (random_)
+ delete [] random_;
+}
+
+int FitsCompress::initHeader(FitsFile* fits)
+{
+ // simple check
+ if (!compress_ || !width_ || !height_ || !bitpix_)
+ return 0;
+
+ // create header
+ FitsHead* srcHead = fits->head();
+ // FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu());
+
+ if (srcHead->find("ZTENSION")) {
+ char* str = srcHead->getString("ZTENSION");
+ head_ = new FitsHead(width_, height_, depth_, bitpix_, str);
+ }
+ else
+ head_ = new FitsHead(width_, height_, depth_, bitpix_);
+
+ if (!head_->isValid())
+ return 0;
+
+ char* ptr = srcHead->cards();
+ for (int ii=0; ii<srcHead->ncard(); ii++, ptr+=80) {
+ char key[9];
+ key[8] = '\0';
+ memcpy(key,ptr,8);
+ if (!strncmp(key,"ZIMAGE",6) ||
+ !strncmp(key,"ZCMPTYPE",8) ||
+ !strncmp(key,"ZBITPIX",7) ||
+ !strncmp(key,"ZNAXIS",6) ||
+ !strncmp(key,"ZTILE",5) ||
+ !strncmp(key,"ZNAME",5) ||
+ !strncmp(key,"ZVAL",4) ||
+ !strncmp(key,"ZMASKCMP",8) ||
+
+ !strncmp(key,"ZSIMPLE",7) ||
+ !strncmp(key,"ZTENSION",8) ||
+ !strncmp(key,"ZEXTEND",7) ||
+
+ !strncmp(key,"SIMPLE",6) ||
+ !strncmp(key,"BITPIX",6) ||
+ !strncmp(key,"NAXIS",5) ||
+ !strncmp(key,"END",3) ||
+ !strncmp(key,"XTENSION",8) ||
+ !strncmp(key,"PCOUNT",6) ||
+ !strncmp(key,"GCOUNT",6) ||
+ !strncmp(key,"EXTEND",6) ||
+
+ !strncmp(key,"CHECKSUM",8) ||
+ !strncmp(key,"DATASUM",7) ||
+
+ !strncmp(key,"TFIELDS",7) ||
+ !strncmp(key,"TBCOL",5) ||
+ !strncmp(key,"TFORM",5) ||
+ !strncmp(key,"TSCAL",5) ||
+ !strncmp(key,"TZERO",5) ||
+ !strncmp(key,"TNULL",5) ||
+ !strncmp(key,"TTYPE",5) ||
+ !strncmp(key,"TUNIT",5) ||
+ !strncmp(key,"TDISP",5) ||
+ !strncmp(key,"THEAP",5) ||
+ !strncmp(key,"TDIM",4))
+ continue;
+
+ // eat this one
+ if (!strncmp(key,"EXTNAME",7)) {
+ FitsCard cc(ptr);
+ char* str = cc.getString();
+ if (str) {
+ if (!strncmp(str,"COMPRESSED_IMAGE",8))
+ continue;
+ }
+ }
+
+ // substitute these
+
+ if (!strncmp(key,"ZBLOCK",6)) {
+ FitsCard cc(ptr);
+ head_->appendInteger("BLOCK",cc.getInteger(),NULL);
+ continue;
+ }
+ if (!strncmp(key,"ZPCOUNT",7)) {
+ FitsCard cc(ptr);
+ head_->appendInteger("PCOUNT",cc.getInteger(),NULL);
+ continue;
+ }
+ if (!strncmp(key,"ZGCOUNT",7)) {
+ FitsCard cc(ptr);
+ head_->appendInteger("GCOUNT",cc.getInteger(),NULL);
+ continue;
+ }
+ if (!strncmp(key,"ZHECKSUM",8)) {
+ FitsCard cc(ptr);
+ char* str = cc.getString();
+ if (str) {
+ head_->appendString("CHECKSUM",str,NULL);
+ continue;
+ }
+ }
+ if (!strncmp(key,"ZDATASUM",8)) {
+ FitsCard cc(ptr);
+ char* str = cc.getString();
+ if (str) {
+ head_->appendString("DATASUM",str,NULL);
+ continue;
+ }
+ }
+
+ // pass these unaltered
+ head_->cardins(ptr,NULL);
+ }
+
+ // we added cards
+ head_->updateHDU();
+
+ // other
+ primary_ = fits->primary();
+ managePrimary_ = 0;
+
+ inherit_ = head_->inherit();
+
+ return 1;
+}
+
+void FitsCompress::initRandom(int row)
+{
+ row++;
+ int rrow = row + quantOffset_-1;
+ randSeed_ = (int)((rrow-1) % numRandom_);
+ randNext_ = (int)(random_[randSeed_]*500);
+}
+
+double FitsCompress::unquantize(double val, double zs, double zz)
+{
+ double rr = (val-random_[randNext_]+.5)*zs + zz;
+
+ randNext_++;
+ if (randNext_ == numRandom_) {
+ randSeed_++;
+ if (randSeed_ == numRandom_)
+ randSeed_ = 0;
+ randNext_ = (int)(random_[randSeed_]*500);
+ }
+
+ return rr;
+}
+
+#define ZERO_VALUE -2147483646 /* value used to represent zero-valued pixels */
+double FitsCompress::unquantizeZero(double val, double zs, double zz)
+{
+ double rr = (val == ZERO_VALUE) ? 0 : (val-random_[randNext_]+.5)*zs + zz;
+
+ randNext_++;
+ if (randNext_ == numRandom_) {
+ randSeed_++;
+ if (randSeed_ == numRandom_)
+ randSeed_ = 0;
+ randNext_ = (int)(random_[randSeed_]*500);
+ }
+
+ return rr;
+}
+
+template<class T> FitsCompressm<T>::FitsCompressm(FitsFile* fits)
+ : FitsCompress(fits) {}
+
+template <class T> void FitsCompressm<T>::uncompress(FitsFile* fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ if (!inflate(fits))
+ return;
+
+ swapBytes();
+
+ // all done
+ valid_ = 1;
+}
+
+template <class T> int FitsCompressm<T>::inflate(FitsFile* fits)
+{
+ FitsHead* srcHead = fits->head();
+ FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu());
+
+ if (null_) {
+ internalError("Fitsy++ does not support NULL_PIXEL_MASK at this time.");
+ return 0;
+ }
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ compress unable to allocate memory");
+ return 0;
+ }
+
+ // init image
+ memset(dest, 0, size_*sizeof(T));
+
+ // src
+ char* sdata = (char*)fits->data();
+ char* sptr = sdata;
+ int heap = srcHDU->realbytes();
+ int rowlen = srcHDU->width();
+ int rows = srcHDU->rows();
+
+ // dest
+ int iistart =0;
+ int iistop =ww_;
+ if (iistop > width_)
+ iistop = width_;
+
+ int jjstart =0;
+ int jjstop =hh_;
+ if (jjstop > height_)
+ jjstop = height_;
+
+ int kkstart =0;
+ int kkstop =dd_;
+ if (kkstop > depth_)
+ kkstop = depth_;
+
+ for (int rr=0; rr<rows; rr++, sptr+=rowlen) {
+ // we can't use incr paging due to the location of the heap
+ // sptr = fits->page(sptr, rowlen);
+
+ int ok=0;
+ if (gzcompress_ && !ok) {
+ if (gzcompressed(dest, sptr, sdata+heap,
+ kkstart, kkstop, jjstart, jjstop, iistart, iistop)) {
+ ok=1;
+ }
+ }
+
+ if (compress_ && !ok) {
+ initRandom(rr);
+ if (compressed(dest, sptr, sdata+heap,
+ kkstart, kkstop, jjstart, jjstop, iistart, iistop)) {
+ ok=1;
+ }
+ }
+
+ if (uncompress_ && !ok) {
+ if (uncompressed(dest, sptr, sdata+heap,
+ kkstart, kkstop, jjstart, jjstop, iistart, iistop)) {
+ ok=1;
+ }
+ }
+
+ if (!ok)
+ return 0;
+
+ // tiles may not be an even multiple of the image size
+ iistart += ww_;
+ iistop += ww_;
+ if (iistop > width_)
+ iistop = width_;
+
+ if (iistart >= width_) {
+ iistart = 0;
+ iistop = ww_;
+ if (iistop > width_)
+ iistop = width_;
+
+ jjstart += hh_;
+ jjstop += hh_;
+ if (jjstop > height_)
+ jjstop = height_;
+
+ if (jjstart >= height_) {
+ jjstart = 0;
+ jjstop = hh_;
+ if (jjstop > height_)
+ jjstop = height_;
+
+ kkstart += dd_;
+ kkstop += dd_;
+
+ // we only do up to 3 dimensions
+ if (kkstart >= depth_)
+ break;
+ }
+ }
+ }
+
+ // we can't use incr paging due to the location of the heap
+ // fits->resetpage();
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ return 1;
+}
+
+// uncompressed
+
+template<class T> int FitsCompressm<T>::uncompressed(T* dest, char* sptr,
+ char* heap,
+ int kkstart, int kkstop,
+ int jjstart, int jjstop,
+ int iistart, int iistop)
+{
+ int ocnt=0;
+ T* obuf = (T*)(((FitsBinColumnArray*)uncompress_)->get(heap, sptr, &ocnt));
+
+ // obuf can be NULL
+ if (!obuf || !ocnt)
+ return 0;
+
+ int ll=0;
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++)
+ dest[kk*width_*height_ + jj*width_ + ii] = swap(obuf+ll);
+ return 1;
+}
+
+// gzcompressed
+
+template <class T> int FitsCompressm<T>::gzcompressed(T* dest, char* sptr,
+ char* heap,
+ int kkstart, int kkstop,
+ int jjstart, int jjstop,
+ int iistart, int iistop)
+{
+ int icnt=0;
+ unsigned char* ibuf = (unsigned char*)((FitsBinColumnArray*)gzcompress_)->get(heap, sptr, &icnt);
+
+ // ibuf can be NULL
+ if (!ibuf || !icnt)
+ return 0;
+
+ int ocnt = tilesize_;
+ char obuf[ocnt*sizeof(T)];
+
+ z_stream zstrm;
+ zstrm.next_in = NULL;
+ zstrm.avail_in = 0;
+ zstrm.zalloc = NULL;
+ zstrm.zfree = NULL;
+ zstrm.opaque = NULL;
+
+ // look for both zlib and gzcompressed headers
+ if (inflateInit2(&zstrm, MAX_WBITS+32) != Z_OK) {
+ internalError("Fitsy++ gzcompressed inflateInit error");
+ return 0;
+ }
+
+ zstrm.avail_in = icnt;
+ zstrm.next_in = ibuf;
+ zstrm.avail_out = ocnt*sizeof(T);
+ zstrm.next_out = (Bytef*)obuf;
+
+ if (DebugCompress)
+ cerr << " inflate START: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+
+ int result = ::inflate(&zstrm, Z_FINISH);
+
+ switch (result) {
+ case Z_OK:
+ if (DebugCompress)
+ cerr << " inflate OK: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_STREAM_END:
+ if (DebugCompress)
+ cerr << " inflate STREAM_END: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_BUF_ERROR:
+ if (DebugCompress)
+ cerr << " inflate BUF_ERROR: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out << endl;
+ return 0;
+ default:
+ internalError("Fitsy++ gzcompressed inflate error");
+ return 0;
+ }
+
+ inflateEnd(&zstrm);
+
+ int ll=0;
+ for (int kk=kkstart; kk<kkstop; kk++) {
+ for (int jj=jjstart; jj<jjstop; jj++) {
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // swap if needed
+ if (byteswap_)
+ *((T*)obuf+ll) = swap((T*)obuf+ll);
+ dest[kk*width_*height_ + jj*width_ + ii] = *((T*)obuf+ll);
+ }
+ }
+ }
+
+ return 1;
+}
+
+// swap
+
+template<class T> void FitsCompressm<T>::swapBytes()
+{
+ if (byteswap_) {
+ T* dest = (T*)data_;
+ for (size_t ii=0; ii<size_; ii++)
+ dest[ii] = swap(dest+ii);
+ }
+}
+
+template <> unsigned char FitsCompressm<unsigned char>::swap(unsigned char* ptr)
+{
+ return *ptr;
+}
+
+template <> short FitsCompressm<short>::swap(short* ptr)
+{
+ const char* p = (const char*)ptr;
+ union {
+ char c[2];
+ short s;
+ } u;
+
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ return u.s;
+}
+
+template <> unsigned short FitsCompressm<unsigned short>::swap(unsigned short* ptr)
+{
+ const char* p = (const char*)ptr;
+ union {
+ char c[2];
+ unsigned short s;
+ } u;
+
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ return u.s;
+}
+
+template <> int FitsCompressm<int>::swap(int* ptr)
+{
+ const char* p = (const char*)ptr;
+ union {
+ char c[4];
+ int i;
+ } u;
+
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ return u.i;
+}
+
+template <> long long FitsCompressm<long long>::swap(long long* ptr)
+{
+ const char* p = (const char*)ptr;
+ union {
+ char c[8];
+ long long i;
+ } u;
+
+ u.c[7] = *p++;
+ u.c[6] = *p++;
+ u.c[5] = *p++;
+ u.c[4] = *p++;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ return u.i;
+}
+
+template <> float FitsCompressm<float>::swap(float* ptr)
+{
+ const char* p = (const char*)ptr;
+ union {
+ char c[4];
+ float f;
+ } u;
+
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ return u.f;
+}
+
+template <> double FitsCompressm<double>::swap(double* ptr)
+{
+ const char* p = (const char*)ptr;
+ union {
+ char c[8];
+ double d;
+ } u;
+
+ u.c[7] = *p++;
+ u.c[6] = *p++;
+ u.c[5] = *p++;
+ u.c[4] = *p++;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ return u.d;
+}
+
+// getValue char
+
+template <class T> T FitsCompressm<T>::getValue(char* ptr, double zs,
+ double zz, int blank)
+{
+ return hasScaling_ ? T((*ptr)*zs + zz) : *ptr;
+}
+
+template <> float FitsCompressm<float>::getValue(char* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ case SUBDITHER2:
+ return unquantize(*ptr,zs,zz);
+ }
+}
+
+template <> double FitsCompressm<double>::getValue(char* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ case SUBDITHER2:
+ return unquantize(*ptr,zs,zz);
+ }
+}
+
+// getValue short
+
+template <class T> T FitsCompressm<T>::getValue(short* ptr, double zs,
+ double zz, int blank)
+{
+ return hasScaling_ ? T((*ptr)*zs + zz) : *ptr;
+}
+
+template <> float FitsCompressm<float>::getValue(short* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ case SUBDITHER2:
+ return unquantize(*ptr,zs,zz);
+ }
+}
+
+template <> double FitsCompressm<double>::getValue(short* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ case SUBDITHER2:
+ return unquantize(*ptr,zs,zz);
+ }
+}
+
+// getValue int
+
+template <class T> T FitsCompressm<T>::getValue(int* ptr, double zs,
+ double zz, int blank)
+{
+ return hasScaling_ ? T((*ptr)*zs + zz) : *ptr;
+}
+
+template <> float FitsCompressm<float>::getValue(int* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ return unquantize(*ptr,zs,zz);
+ case SUBDITHER2:
+ return unquantizeZero(*ptr,zs,zz);
+ }
+}
+
+template <> double FitsCompressm<double>::getValue(int* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ return unquantize(*ptr,zs,zz);
+ case SUBDITHER2:
+ return unquantizeZero(*ptr,zs,zz);
+ }
+}
+
+// getValue long long
+
+template <class T> T FitsCompressm<T>::getValue(long long* ptr, double zs,
+ double zz, int blank)
+{
+ return hasScaling_ ? T((*ptr)*zs + zz) : *ptr;
+}
+
+template <> float FitsCompressm<float>::getValue(long long* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ return unquantize(*ptr,zs,zz);
+ case SUBDITHER2:
+ return unquantizeZero(*ptr,zs,zz);
+ }
+}
+
+template <> double FitsCompressm<double>::getValue(long long* ptr, double zs,
+ double zz, int blank)
+{
+ if (!hasBlank_ && !hasScaling_ && quantize_==NONE)
+ return *ptr;
+
+ if (hasBlank_ && *ptr == blank)
+ return NAN;
+
+ switch (quantize_) {
+ case NONE:
+ case NODITHER:
+ return hasScaling_ ? (*ptr)*zs + zz : *ptr;
+ case SUBDITHER1:
+ return unquantize(*ptr,zs,zz);
+ case SUBDITHER2:
+ return unquantizeZero(*ptr,zs,zz);
+ }
+}
+
+// getValue float
+
+template <class T> T FitsCompressm<T>::getValue(float* ptr, double zs,
+ double zz, int blank)
+{
+ return hasScaling_ ? T((*ptr)*zs + zz) : *ptr;
+}
+
+// getValue double
+
+template <class T> T FitsCompressm<T>::getValue(double* ptr, double zs,
+ double zz, int blank)
+{
+ return hasScaling_ ? T((*ptr)*zs + zz) : *ptr;
+}
+
+template class FitsCompressm<unsigned char>;
+template class FitsCompressm<short>;
+template class FitsCompressm<unsigned short>;
+template class FitsCompressm<int>;
+template class FitsCompressm<long long>;
+template class FitsCompressm<float>;
+template class FitsCompressm<double>;
+
+FitsPostNext::FitsPostNext(FitsFile* p)
+{
+ FitsCompress* prev = (FitsCompress*)p;
+
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = head_->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ return;
+}
diff --git a/fitsy++/compress.h b/fitsy++/compress.h
new file mode 100644
index 0000000..627435a
--- /dev/null
+++ b/fitsy++/compress.h
@@ -0,0 +1,94 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitscompress_h__
+#define __fitscompress_h__
+
+#include "file.h"
+
+class FitsCompress : public FitsFile {
+ public:
+ enum QuantMethod {NONE,NODITHER,SUBDITHER1,SUBDITHER2};
+
+ protected:
+ int bitpix_;
+ char* type_;
+ int width_;
+ int height_;
+ int depth_;
+ int ww_;
+ int hh_;
+ int dd_;
+ double bscale_;
+ double bzero_;
+ unsigned int blank_;
+ char* zmaskcmp_;
+
+ size_t tilesize_;
+ size_t size_;
+
+ FitsColumn* gzcompress_;
+ FitsColumn* compress_;
+ FitsColumn* uncompress_;
+ FitsColumn* zscale_;
+ FitsColumn* zzero_;
+ FitsColumn* zblank_;
+ FitsColumn* null_;
+
+ int hasScaling_;
+ int hasBlank_;
+
+ QuantMethod quantize_;
+ int quantOffset_;
+
+ int numRandom_;
+ float* random_;
+ int randSeed_;
+ int randNext_;
+
+ protected:
+ int initHeader(FitsFile*);
+ void initRandom(int);
+
+ double unquantize(double, double, double);
+ double unquantizeZero(double, double, double);
+
+ public:
+ FitsCompress(FitsFile*);
+ virtual ~FitsCompress();
+};
+
+template<class T>
+class FitsCompressm : public FitsCompress {
+ private:
+ int inflate(FitsFile*);
+ void swapBytes();
+
+ protected:
+ T swap(T* ptr);
+
+ protected:
+ void uncompress(FitsFile* fits);
+ int gzcompressed(T*, char*, char*, int, int, int, int, int, int);
+ virtual int compressed(T*, char*, char*, int, int, int, int, int, int) =0;
+ int uncompressed(T*, char*, char*, int, int, int, int, int, int);
+
+ T getValue(char*, double, double, int);
+ T getValue(short*, double, double, int);
+ T getValue(int*, double, double, int);
+ T getValue(long long*, double, double, int);
+ T getValue(float*, double, double, int);
+ T getValue(double*, double, double, int);
+
+ public:
+ FitsCompressm(FitsFile*);
+};
+
+class FitsPostNext : public FitsFile {
+public:
+ FitsPostNext(FitsFile* prev);
+};
+
+#endif
+
diff --git a/fitsy++/envi.C b/fitsy++/envi.C
new file mode 100644
index 0000000..a4bcf6d
--- /dev/null
+++ b/fitsy++/envi.C
@@ -0,0 +1,142 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "envi.h"
+#include "head.h"
+#include "util.h"
+
+FitsENVI::FitsENVI(FitsFile* fits)
+{
+ byteswap_ = fits->byteswap();
+ endian_ = fits->endian();
+
+ pBitpix_ = fits->pBitpix();
+ pWidth_ = fits->pWidth();
+ pHeight_ = fits->pHeight();
+ pDepth_ = fits->pDepth();
+
+ pEncoding_ = FitsFile::BSQ;
+
+ pCRPIX3_ = fits->pCRPIX3();
+ pCRVAL3_ = fits->pCRVAL3();
+ pCDELT3_ = fits->pCDELT3();
+
+ size_ = (size_t)pWidth_*pHeight_*pDepth_;
+}
+
+FitsENVI::~FitsENVI()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+int FitsENVI::initHeader(FitsFile* fits)
+{
+ // simple check
+ if (!pWidth_ || !pHeight_ || !pBitpix_)
+ return 0;
+
+ // create header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return 0;
+
+ // WCS?
+ if (pCRPIX3_>0 || pCRVAL3_>0 || pCDELT3_!=1) {
+ head_->appendString("CTYPE1","LINEAR", NULL);
+ head_->appendReal("CRPIX1",1, 9, NULL);
+ head_->appendReal("CRVAL1",1, 9, NULL);
+ head_->appendReal("CDELT1",1, 9, NULL);
+
+ head_->appendString("CTYPE2","LINEAR", NULL);
+ head_->appendReal("CRPIX2",1, 9, NULL);
+ head_->appendReal("CRVAL2",1, 9, NULL);
+ head_->appendReal("CDELT2",1, 9, NULL);
+
+ head_->appendString("CTYPE3","WAVELENGTH", NULL);
+ head_->appendReal("CRPIX3",pCRPIX3_, 9, NULL);
+ head_->appendReal("CRVAL3",pCRVAL3_, 9, NULL);
+ head_->appendReal("CDELT3",pCDELT3_, 9, NULL);
+ }
+
+ // other
+ primary_ = fits->primary();
+ managePrimary_ = 0;
+
+ inherit_ = head_->inherit();
+
+ return 1;
+}
+
+template <class T> FitsENVIBIPm<T>::FitsENVIBIPm(FitsFile* fits)
+ : FitsENVI(fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ envi unable to allocate memory");
+ return;
+ }
+ memset(dest, 0, size_*sizeof(T));
+
+ T* ptr = (T*)fits->data();
+ for (int jj=0; jj<pHeight_; jj++)
+ for (int ii=0; ii<pWidth_; ii++)
+ for (int kk=0; kk<pDepth_; kk++)
+ dest[kk*pWidth_*pHeight_ + jj*pWidth_ + ii] = *ptr++;
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ // all done
+ valid_ = 1;
+}
+
+template class FitsENVIBIPm<unsigned char>;
+template class FitsENVIBIPm<short>;
+template class FitsENVIBIPm<unsigned short>;
+template class FitsENVIBIPm<int>;
+template class FitsENVIBIPm<long long>;
+template class FitsENVIBIPm<float>;
+template class FitsENVIBIPm<double>;
+
+template <class T> FitsENVIBILm<T>::FitsENVIBILm(FitsFile* fits)
+ : FitsENVI(fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ envi unable to allocate memory");
+ return;
+ }
+ memset(dest, 0, size_*sizeof(T));
+
+ T* ptr = (T*)fits->data();
+ for (int jj=0; jj<pHeight_; jj++)
+ for (int kk=0; kk<pDepth_; kk++)
+ for (int ii=0; ii<pWidth_; ii++)
+ dest[kk*pWidth_*pHeight_ + jj*pWidth_ + ii] = *ptr++;
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ // all done
+ valid_ = 1;
+}
+
+template class FitsENVIBILm<unsigned char>;
+template class FitsENVIBILm<short>;
+template class FitsENVIBILm<unsigned short>;
+template class FitsENVIBILm<int>;
+template class FitsENVIBILm<long long>;
+template class FitsENVIBILm<float>;
+template class FitsENVIBILm<double>;
diff --git a/fitsy++/envi.h b/fitsy++/envi.h
new file mode 100644
index 0000000..4ea2fb1
--- /dev/null
+++ b/fitsy++/envi.h
@@ -0,0 +1,35 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsenvi_h__
+#define __fitsenvi_h__
+
+#include "file.h"
+
+class FitsENVI : public FitsFile {
+ protected:
+ size_t size_;
+
+ protected:
+ int initHeader(FitsFile*);
+
+ public:
+ FitsENVI(FitsFile*);
+ virtual ~FitsENVI();
+};
+
+template<class T>
+class FitsENVIBILm : public FitsENVI {
+ public:
+ FitsENVIBILm(FitsFile*);
+};
+
+template<class T>
+class FitsENVIBIPm : public FitsENVI {
+ public:
+ FitsENVIBIPm(FitsFile*);
+};
+
+#endif
+
diff --git a/fitsy++/envilex.C b/fitsy++/envilex.C
new file mode 100644
index 0000000..8ae76fa
--- /dev/null
+++ b/fitsy++/envilex.C
@@ -0,0 +1,2223 @@
+#line 2 "../fitsy/envilex.C"
+
+#line 4 "../fitsy/envilex.C"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+ /* The c++ scanner is a mess. The FlexLexer.h header file relies on the
+ * following macro. This is required in order to pass the c++-multiple-scanners
+ * test in the regression suite. We get reports that it breaks inheritance.
+ * We will address this in a future release of flex, or omit the C++ scanner
+ * altogether.
+ */
+ #define yyFlexLexer enviFlexLexer
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+typedef uint64_t flex_uint64_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+/* begin standard C++ headers. */
+#include <iostream>
+#include <errno.h>
+#include <cstdlib>
+#include <cstring>
+/* end standard C++ headers. */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+extern yy_size_t yyleng;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+
+ std::istream* yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+void *envialloc (yy_size_t );
+void *envirealloc (void *,yy_size_t );
+void envifree (void * );
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+#define yytext_ptr yytext
+
+#include <FlexLexer.h>
+
+int yyFlexLexer::yywrap() { return 1; }
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ yyleng = (yy_size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+
+#define YY_NUM_RULES 72
+#define YY_END_OF_BUFFER 73
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[282] =
+ { 0,
+ 0, 0, 2, 2, 0, 0, 73, 71, 68, 70,
+ 71, 71, 71, 64, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 3, 2, 1, 63, 61, 62,
+ 63, 60, 59, 63, 56, 59, 4, 68, 69, 0,
+ 64, 66, 65, 64, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 67, 67, 67, 6, 67,
+ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 2, 61, 0, 56, 59,
+
+ 56, 58, 57, 59, 0, 0, 0, 65, 67, 67,
+ 11, 12, 13, 14, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
+ 67, 67, 32, 67, 67, 7, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
+ 67, 67, 0, 0, 0, 59, 57, 65, 0, 66,
+ 67, 9, 15, 17, 67, 67, 67, 16, 67, 22,
+ 67, 23, 24, 67, 67, 26, 67, 67, 67, 67,
+ 67, 67, 67, 67, 67, 40, 67, 67, 67, 67,
+ 67, 67, 67, 48, 67, 67, 51, 67, 67, 67,
+
+ 57, 0, 58, 67, 10, 5, 67, 67, 67, 21,
+ 67, 67, 67, 67, 30, 31, 33, 34, 67, 37,
+ 38, 67, 42, 67, 67, 45, 67, 67, 67, 67,
+ 52, 53, 67, 67, 67, 67, 20, 25, 27, 67,
+ 29, 35, 39, 67, 67, 67, 67, 47, 67, 50,
+ 54, 67, 8, 18, 67, 67, 36, 67, 67, 44,
+ 46, 49, 67, 67, 67, 67, 67, 67, 67, 67,
+ 67, 67, 67, 67, 28, 41, 67, 55, 19, 43,
+ 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 5, 6, 7, 8, 1, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 1, 1, 1,
+ 1, 1, 1, 1, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 1, 1, 1, 1, 1, 1, 36, 37, 38, 39,
+
+ 40, 41, 42, 43, 44, 45, 20, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
+ 59, 60, 61, 1, 62, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[63] =
+ { 0,
+ 1, 1, 2, 1, 1, 1, 3, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 1, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[287] =
+ { 0,
+ 0, 0, 806, 805, 62, 124, 807, 810, 800, 810,
+ 788, 64, 781, 66, 78, 179, 781, 68, 69, 127,
+ 71, 75, 128, 76, 77, 80, 150, 148, 132, 231,
+ 144, 91, 83, 102, 810, 0, 810, 810, 786, 810,
+ 88, 810, 92, 778, 141, 778, 810, 783, 810, 775,
+ 187, 134, 190, 197, 775, 212, 153, 202, 201, 227,
+ 200, 204, 226, 246, 228, 145, 210, 232, 236, 254,
+ 255, 258, 274, 270, 282, 286, 278, 280, 772, 297,
+ 289, 288, 296, 300, 311, 294, 303, 306, 316, 95,
+ 327, 325, 322, 323, 330, 0, 776, 768, 349, 767,
+
+ 351, 353, 359, 375, 365, 383, 765, 220, 369, 387,
+ 765, 764, 763, 761, 371, 393, 379, 394, 386, 389,
+ 398, 400, 397, 409, 402, 407, 404, 408, 427, 405,
+ 428, 414, 760, 431, 429, 437, 446, 456, 443, 439,
+ 458, 467, 451, 470, 453, 463, 465, 474, 475, 479,
+ 477, 484, 505, 512, 757, 334, 514, 756, 751, 750,
+ 494, 501, 750, 746, 518, 517, 519, 739, 520, 725,
+ 523, 687, 684, 527, 528, 636, 530, 532, 531, 535,
+ 537, 540, 562, 548, 544, 629, 565, 569, 577, 573,
+ 584, 580, 550, 570, 587, 593, 558, 598, 596, 600,
+
+ 544, 542, 541, 606, 541, 534, 604, 605, 588, 503,
+ 603, 621, 610, 619, 491, 486, 454, 440, 624, 410,
+ 626, 630, 370, 631, 644, 363, 649, 654, 652, 657,
+ 356, 658, 659, 662, 651, 663, 347, 345, 341, 669,
+ 338, 666, 268, 667, 674, 679, 685, 262, 683, 256,
+ 238, 693, 216, 206, 689, 712, 174, 690, 715, 172,
+ 156, 152, 719, 696, 589, 707, 716, 709, 721, 722,
+ 734, 738, 736, 744, 133, 110, 741, 103, 97, 94,
+ 810, 792, 796, 94, 800, 802
+ } ;
+
+static yyconst flex_int16_t yy_def[287] =
+ { 0,
+ 281, 1, 282, 282, 283, 283, 281, 281, 281, 281,
+ 281, 281, 281, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 281, 285, 281, 281, 281, 281,
+ 281, 281, 286, 281, 286, 286, 281, 281, 281, 281,
+ 281, 281, 281, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 285, 281, 281, 281, 286,
+
+ 286, 281, 281, 286, 281, 281, 281, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 281, 281, 281, 286, 286, 281, 281, 281,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+
+ 281, 281, 281, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284,
+ 0, 281, 281, 281, 281, 281
+ } ;
+
+static yyconst flex_int16_t yy_nxt[873] =
+ { 0,
+ 8, 9, 10, 11, 12, 8, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 17, 17,
+ 24, 25, 26, 27, 28, 17, 29, 30, 31, 32,
+ 33, 34, 17, 17, 17, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 17, 24, 25, 26, 27, 28,
+ 17, 29, 30, 31, 32, 33, 34, 17, 17, 17,
+ 35, 8, 38, 39, 40, 38, 41, 42, 43, 44,
+ 45, 50, 51, 53, 54, 281, 281, 63, 281, 56,
+ 70, 64, 281, 281, 281, 281, 75, 281, 71, 77,
+ 281, 65, 94, 74, 76, 98, 99, 55, 281, 98,
+
+ 101, 281, 281, 63, 281, 56, 70, 64, 57, 281,
+ 281, 95, 75, 93, 71, 77, 65, 281, 94, 74,
+ 76, 147, 38, 47, 38, 39, 40, 38, 41, 42,
+ 43, 44, 45, 57, 281, 281, 66, 95, 93, 281,
+ 281, 84, 52, 72, 67, 85, 147, 106, 103, 101,
+ 73, 281, 281, 68, 104, 281, 121, 281, 69, 281,
+ 281, 91, 66, 281, 78, 81, 109, 84, 82, 72,
+ 67, 85, 79, 106, 83, 73, 80, 92, 68, 281,
+ 104, 281, 121, 69, 38, 47, 281, 91, 58, 59,
+ 78, 81, 109, 82, 53, 51, 60, 79, 52, 83,
+
+ 105, 80, 92, 105, 53, 54, 61, 281, 281, 281,
+ 56, 281, 62, 281, 58, 59, 107, 281, 107, 281,
+ 108, 111, 60, 281, 110, 114, 105, 281, 108, 105,
+ 122, 61, 115, 281, 281, 281, 56, 62, 281, 281,
+ 86, 123, 87, 281, 88, 281, 111, 112, 89, 110,
+ 114, 113, 124, 281, 116, 122, 117, 115, 120, 90,
+ 118, 281, 281, 281, 126, 281, 86, 123, 87, 281,
+ 88, 125, 112, 119, 89, 281, 113, 281, 124, 116,
+ 127, 281, 117, 120, 90, 281, 118, 281, 128, 281,
+ 126, 130, 131, 281, 136, 281, 281, 125, 119, 135,
+
+ 132, 281, 129, 281, 281, 127, 133, 281, 134, 137,
+ 281, 139, 144, 281, 128, 143, 130, 131, 281, 140,
+ 136, 138, 141, 281, 135, 142, 132, 129, 145, 281,
+ 281, 133, 281, 134, 281, 137, 139, 281, 144, 150,
+ 143, 281, 157, 151, 140, 281, 138, 141, 281, 149,
+ 146, 142, 281, 145, 281, 148, 103, 99, 103, 101,
+ 152, 102, 153, 281, 104, 150, 154, 102, 151, 107,
+ 281, 107, 153, 158, 149, 146, 281, 281, 281, 155,
+ 148, 156, 281, 157, 163, 152, 281, 159, 153, 159,
+ 104, 160, 154, 281, 281, 161, 281, 167, 153, 162,
+
+ 281, 281, 164, 166, 281, 281, 168, 281, 165, 281,
+ 163, 281, 281, 170, 281, 281, 281, 281, 171, 174,
+ 161, 281, 178, 167, 173, 162, 169, 175, 164, 166,
+ 172, 176, 168, 165, 281, 281, 281, 180, 281, 170,
+ 177, 179, 182, 171, 281, 174, 281, 281, 178, 173,
+ 281, 169, 175, 281, 181, 172, 176, 187, 281, 184,
+ 281, 281, 180, 281, 183, 281, 177, 179, 182, 185,
+ 281, 186, 281, 188, 281, 190, 194, 281, 195, 181,
+ 193, 281, 281, 187, 281, 184, 281, 189, 197, 183,
+ 191, 281, 192, 281, 196, 185, 186, 200, 281, 188,
+
+ 190, 281, 194, 204, 195, 193, 199, 198, 281, 155,
+ 281, 155, 189, 201, 197, 191, 202, 192, 202, 196,
+ 203, 281, 157, 200, 281, 281, 281, 281, 205, 204,
+ 281, 199, 198, 206, 281, 281, 210, 281, 281, 281,
+ 211, 281, 281, 209, 281, 208, 207, 281, 281, 203,
+ 203, 281, 201, 205, 212, 281, 213, 281, 215, 206,
+ 214, 216, 210, 217, 221, 281, 211, 218, 209, 281,
+ 208, 207, 281, 228, 220, 219, 281, 281, 222, 212,
+ 281, 213, 223, 215, 281, 214, 216, 281, 217, 221,
+ 224, 281, 218, 225, 281, 281, 281, 226, 228, 220,
+
+ 281, 219, 227, 281, 222, 281, 230, 281, 223, 232,
+ 281, 281, 281, 281, 237, 229, 224, 281, 225, 270,
+ 233, 234, 236, 226, 235, 231, 281, 227, 281, 238,
+ 240, 281, 230, 281, 239, 232, 281, 281, 281, 237,
+ 229, 244, 245, 281, 270, 233, 241, 234, 236, 235,
+ 231, 281, 242, 243, 238, 240, 281, 246, 281, 281,
+ 239, 281, 247, 249, 281, 281, 281, 244, 245, 281,
+ 281, 241, 252, 281, 281, 253, 281, 242, 243, 254,
+ 248, 281, 256, 246, 250, 251, 281, 255, 247, 249,
+ 281, 281, 281, 257, 281, 258, 281, 281, 252, 262,
+
+ 281, 253, 259, 281, 254, 248, 260, 266, 256, 250,
+ 251, 261, 255, 269, 281, 263, 281, 264, 257, 281,
+ 258, 265, 281, 281, 267, 262, 281, 259, 281, 281,
+ 271, 260, 281, 266, 268, 275, 261, 273, 272, 269,
+ 263, 281, 264, 281, 274, 281, 281, 265, 281, 277,
+ 267, 281, 278, 281, 280, 271, 276, 281, 160, 160,
+ 268, 275, 273, 272, 158, 201, 279, 281, 281, 274,
+ 281, 281, 281, 158, 281, 277, 102, 97, 278, 281,
+ 280, 276, 281, 52, 48, 281, 102, 97, 281, 52,
+ 49, 279, 36, 36, 36, 36, 46, 46, 46, 46,
+
+ 96, 48, 96, 96, 100, 100, 281, 37, 37, 7,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281
+ } ;
+
+static yyconst flex_int16_t yy_chk[873] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 12, 12, 14, 14, 18, 19, 18, 21, 14,
+ 21, 18, 22, 24, 25, 15, 25, 26, 22, 26,
+ 33, 19, 33, 24, 25, 41, 41, 284, 32, 43,
+
+ 43, 280, 90, 18, 279, 14, 21, 18, 15, 34,
+ 278, 34, 25, 32, 22, 26, 19, 276, 33, 24,
+ 25, 90, 5, 5, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 15, 20, 23, 20, 34, 32, 29,
+ 275, 29, 52, 23, 20, 29, 90, 52, 45, 45,
+ 23, 31, 66, 20, 45, 28, 66, 27, 20, 262,
+ 57, 31, 20, 261, 27, 28, 57, 29, 28, 23,
+ 20, 29, 27, 52, 28, 23, 27, 31, 20, 260,
+ 45, 257, 66, 20, 6, 6, 16, 31, 16, 16,
+ 27, 28, 57, 28, 51, 51, 16, 27, 53, 28,
+
+ 51, 27, 31, 53, 54, 54, 16, 61, 59, 58,
+ 54, 62, 16, 254, 16, 16, 56, 67, 56, 56,
+ 56, 59, 16, 253, 58, 61, 51, 108, 108, 53,
+ 67, 16, 62, 63, 60, 65, 54, 16, 30, 68,
+ 30, 68, 30, 69, 30, 251, 59, 60, 30, 58,
+ 61, 60, 69, 64, 63, 67, 64, 62, 65, 30,
+ 64, 70, 71, 250, 71, 72, 30, 68, 30, 248,
+ 30, 70, 60, 64, 30, 243, 60, 74, 69, 63,
+ 72, 73, 64, 65, 30, 77, 64, 78, 73, 75,
+ 71, 74, 74, 76, 78, 82, 81, 70, 64, 77,
+
+ 75, 86, 73, 83, 80, 72, 75, 84, 76, 80,
+ 87, 82, 87, 88, 73, 86, 74, 74, 85, 83,
+ 78, 81, 84, 89, 77, 85, 75, 73, 88, 93,
+ 94, 75, 92, 76, 91, 80, 82, 95, 87, 93,
+ 86, 156, 156, 94, 83, 241, 81, 84, 239, 92,
+ 89, 85, 238, 88, 237, 91, 99, 99, 101, 101,
+ 95, 102, 99, 231, 101, 93, 102, 103, 94, 105,
+ 226, 105, 103, 105, 92, 89, 109, 223, 115, 104,
+ 91, 104, 104, 104, 115, 95, 117, 106, 99, 106,
+ 101, 106, 102, 119, 110, 109, 120, 119, 103, 110,
+
+ 116, 118, 116, 118, 123, 121, 120, 122, 117, 125,
+ 115, 127, 130, 122, 126, 128, 124, 220, 123, 126,
+ 109, 132, 130, 119, 125, 110, 121, 127, 116, 118,
+ 124, 128, 120, 117, 129, 131, 135, 132, 134, 122,
+ 129, 131, 135, 123, 136, 126, 140, 218, 130, 125,
+ 139, 121, 127, 137, 134, 124, 128, 140, 143, 137,
+ 145, 217, 132, 138, 136, 141, 129, 131, 135, 138,
+ 146, 139, 147, 141, 142, 143, 146, 144, 147, 134,
+ 145, 148, 149, 140, 151, 137, 150, 142, 149, 136,
+ 144, 152, 144, 216, 148, 138, 139, 152, 215, 141,
+
+ 143, 161, 146, 161, 147, 145, 151, 150, 162, 153,
+ 210, 153, 142, 153, 149, 144, 154, 144, 154, 148,
+ 154, 157, 157, 152, 166, 165, 167, 169, 162, 161,
+ 171, 151, 150, 165, 174, 175, 171, 177, 179, 178,
+ 174, 206, 180, 169, 181, 167, 166, 182, 205, 203,
+ 202, 185, 201, 162, 175, 184, 177, 193, 179, 165,
+ 178, 180, 171, 181, 185, 197, 174, 182, 169, 183,
+ 167, 166, 187, 193, 184, 183, 188, 194, 187, 175,
+ 190, 177, 188, 179, 189, 178, 180, 192, 181, 185,
+ 189, 191, 182, 190, 195, 209, 265, 191, 193, 184,
+
+ 196, 183, 192, 199, 187, 198, 196, 200, 188, 199,
+ 211, 207, 208, 204, 209, 195, 189, 213, 190, 265,
+ 200, 204, 208, 191, 207, 198, 214, 192, 212, 211,
+ 213, 219, 196, 221, 212, 199, 186, 222, 224, 209,
+ 195, 222, 224, 176, 265, 200, 214, 204, 208, 207,
+ 198, 225, 219, 221, 211, 213, 227, 225, 235, 229,
+ 212, 228, 227, 229, 230, 232, 233, 222, 224, 234,
+ 236, 214, 233, 242, 244, 234, 240, 219, 221, 235,
+ 228, 245, 240, 225, 230, 232, 246, 236, 227, 229,
+ 249, 173, 247, 242, 172, 244, 255, 258, 233, 249,
+
+ 252, 234, 245, 264, 235, 228, 246, 258, 240, 230,
+ 232, 247, 236, 264, 266, 252, 268, 255, 242, 256,
+ 244, 256, 259, 267, 259, 249, 263, 245, 269, 270,
+ 266, 246, 170, 258, 263, 270, 247, 268, 267, 264,
+ 252, 271, 255, 273, 269, 272, 168, 256, 277, 272,
+ 259, 274, 273, 164, 277, 266, 271, 163, 160, 159,
+ 263, 270, 268, 267, 158, 155, 274, 133, 114, 269,
+ 113, 112, 111, 107, 100, 272, 98, 97, 273, 79,
+ 277, 271, 55, 50, 48, 46, 44, 39, 17, 13,
+ 11, 274, 282, 282, 282, 282, 283, 283, 283, 283,
+
+ 285, 9, 285, 285, 286, 286, 7, 4, 3, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
+ 281, 281
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "../fitsy/envilex.L"
+/* Copyright (C) 1999-2018
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * For conditions of distribution and use, see copyright notice in "copyright"
+ */
+#line 11 "../fitsy/envilex.L"
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #include "util.h"
+ #include "enviparser.H"
+
+ extern YYSTYPE* envilval;
+ extern enviFlexLexer* envilexx;
+
+
+/* rules */
+#line 710 "../fitsy/envilex.C"
+
+#define INITIAL 0
+#define DISCARD 1
+#define BRACKET 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+#define ECHO LexerOutput( yytext, yyleng )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+\
+ if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) LexerError( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+#define YY_DECL int yyFlexLexer::yylex()
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 30 "../fitsy/envilex.L"
+
+
+#line 815 "../fitsy/envilex.C"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = & std::cin;
+
+ if ( ! yyout )
+ yyout = & std::cout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of yytext. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 282 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 281 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+/* rule 1 can match eol */
+YY_RULE_SETUP
+#line 32 "../fitsy/envilex.L"
+{ // special case-- #\n
+ BEGIN INITIAL;
+ yyless(0); // put back the terminator
+ strcpy(envilval->str,""); // feed a blank string
+ return STRING;
+ }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 39 "../fitsy/envilex.L"
+{ // Discard reset of line
+ BEGIN INITIAL;
+ int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
+ strncpy(envilval->str,yytext,ll);
+ envilval->str[ll] = '\0';
+ return STRING;
+ }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 47 "../fitsy/envilex.L"
+{
+ BEGIN BRACKET;
+ return '{';
+ }
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 52 "../fitsy/envilex.L"
+{
+ BEGIN INITIAL;
+ return '}';
+ }
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 57 "../fitsy/envilex.L"
+{return DEBUG_;}
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 58 "../fitsy/envilex.L"
+{return ON_;}
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 59 "../fitsy/envilex.L"
+{return OFF_;}
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 61 "../fitsy/envilex.L"
+{return AVERAGE_;}
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 62 "../fitsy/envilex.L"
+{return BAND_;}
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 63 "../fitsy/envilex.L"
+{return BANDS_;}
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 64 "../fitsy/envilex.L"
+{return BBL_;}
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 65 "../fitsy/envilex.L"
+{return BIL_;}
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 66 "../fitsy/envilex.L"
+{return BIP_;}
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 67 "../fitsy/envilex.L"
+{return BSQ_;}
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 68 "../fitsy/envilex.L"
+{return BYTE_;}
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 69 "../fitsy/envilex.L"
+{return ENVI_;}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 70 "../fitsy/envilex.L"
+{return DATA_;}
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 71 "../fitsy/envilex.L"
+{return DEFAULT_;}
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 72 "../fitsy/envilex.L"
+{return DESCRIPTION_;}
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 73 "../fitsy/envilex.L"
+{return FACTOR_;}
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 74 "../fitsy/envilex.L"
+{return FRAME_;}
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 75 "../fitsy/envilex.L"
+{return FILE_;}
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 76 "../fitsy/envilex.L"
+{return FWHM_;}
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 77 "../fitsy/envilex.L"
+{return GAIN_;}
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 78 "../fitsy/envilex.L"
+{return HEADER_;}
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 79 "../fitsy/envilex.L"
+{return INFO_;}
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 80 "../fitsy/envilex.L"
+{return IGNORE_;}
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 81 "../fitsy/envilex.L"
+{return INTERLEAVE_;}
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 82 "../fitsy/envilex.L"
+{return LIMITS_;}
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 83 "../fitsy/envilex.L"
+{return LINES_;}
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 84 "../fitsy/envilex.L"
+{return MAJOR_;}
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 85 "../fitsy/envilex.L"
+{return MAP_;}
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 86 "../fitsy/envilex.L"
+{return MINOR_;}
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 87 "../fitsy/envilex.L"
+{return NAMES_;}
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 88 "../fitsy/envilex.L"
+{return OFFSET_;}
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 89 "../fitsy/envilex.L"
+{return OFFSETS_;}
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 90 "../fitsy/envilex.L"
+{return ORDER_;}
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 91 "../fitsy/envilex.L"
+{return PIXEL_;}
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 92 "../fitsy/envilex.L"
+{return PIXELS_;}
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 93 "../fitsy/envilex.L"
+{return PLOT_;}
+ YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 94 "../fitsy/envilex.L"
+{return PROJECTION_;}
+ YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 95 "../fitsy/envilex.L"
+{return RANGE_;}
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 96 "../fitsy/envilex.L"
+{return REFLECTANCE_;}
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 97 "../fitsy/envilex.L"
+{return SAMPLES_;}
+ YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 98 "../fitsy/envilex.L"
+{return SCALE_;}
+ YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 99 "../fitsy/envilex.L"
+{return SCANNER_;}
+ YY_BREAK
+case 47:
+YY_RULE_SETUP
+#line 100 "../fitsy/envilex.L"
+{return SENSOR_;}
+ YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 101 "../fitsy/envilex.L"
+{return SIZE_;}
+ YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 102 "../fitsy/envilex.L"
+{return STRETCH_;}
+ YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 103 "../fitsy/envilex.L"
+{return TITLES_;}
+ YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 104 "../fitsy/envilex.L"
+{return TYPE_;}
+ YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 105 "../fitsy/envilex.L"
+{return UNITS_;}
+ YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 106 "../fitsy/envilex.L"
+{return VALUE_;}
+ YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 107 "../fitsy/envilex.L"
+{return VALUES_;}
+ YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 108 "../fitsy/envilex.L"
+{return WAVELENGTH_;}
+ YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 111 "../fitsy/envilex.L"
+{ // Integer
+ envilval->integer = atoi(yytext);
+ return INT;
+ }
+ YY_BREAK
+case 57:
+#line 117 "../fitsy/envilex.L"
+case 58:
+YY_RULE_SETUP
+#line 117 "../fitsy/envilex.L"
+{ // Real Number
+ envilval->real = atof(yytext);
+ return REAL;
+ }
+ YY_BREAK
+case 59:
+YY_RULE_SETUP
+#line 123 "../fitsy/envilex.L"
+{ // General String
+ int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
+ strncpy(envilval->str,yytext,ll);
+ envilval->str[ll] = '\0';
+ return STRING;
+ }
+ YY_BREAK
+case 60:
+YY_RULE_SETUP
+#line 130 "../fitsy/envilex.L"
+{
+ return ',';
+ }
+ YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 134 "../fitsy/envilex.L"
+{ // White Spaces
+ }
+ YY_BREAK
+case 62:
+/* rule 62 can match eol */
+YY_RULE_SETUP
+#line 137 "../fitsy/envilex.L"
+{ // linefeed
+ }
+ YY_BREAK
+case 63:
+YY_RULE_SETUP
+#line 140 "../fitsy/envilex.L"
+{ // other chars, eat it
+ }
+ YY_BREAK
+case 64:
+YY_RULE_SETUP
+#line 143 "../fitsy/envilex.L"
+{ // Integer
+ envilval->integer = atoi(yytext);
+ return INT;
+ }
+ YY_BREAK
+case 65:
+#line 149 "../fitsy/envilex.L"
+case 66:
+YY_RULE_SETUP
+#line 149 "../fitsy/envilex.L"
+{ // Real Number
+ envilval->real = atof(yytext);
+ return REAL;
+ }
+ YY_BREAK
+case 67:
+YY_RULE_SETUP
+#line 155 "../fitsy/envilex.L"
+{ // General String
+ int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
+ strncpy(envilval->str,yytext,ll);
+ envilval->str[ll] = '\0';
+ return STRING;
+ }
+ YY_BREAK
+case 68:
+YY_RULE_SETUP
+#line 162 "../fitsy/envilex.L"
+{ // White Spaces
+ }
+ YY_BREAK
+case 69:
+/* rule 69 can match eol */
+YY_RULE_SETUP
+#line 165 "../fitsy/envilex.L"
+{ // windows line feed
+ return '\n';
+ }
+ YY_BREAK
+case 70:
+/* rule 70 can match eol */
+YY_RULE_SETUP
+#line 169 "../fitsy/envilex.L"
+{ // linefeed
+ return '\n';
+ }
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(DISCARD):
+case YY_STATE_EOF(BRACKET):
+#line 173 "../fitsy/envilex.L"
+{ // eof
+ return EOF_;
+ }
+ YY_BREAK
+case 71:
+YY_RULE_SETUP
+#line 177 "../fitsy/envilex.L"
+{ // Else, return the char
+ return yytext[0];
+ }
+ YY_BREAK
+case 72:
+YY_RULE_SETUP
+#line 181 "../fitsy/envilex.L"
+ECHO;
+ YY_BREAK
+#line 1311 "../fitsy/envilex.C"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( yywrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
+{
+ yyin = arg_yyin;
+ yyout = arg_yyout;
+ yy_c_buf_p = 0;
+ yy_init = 0;
+ yy_start = 0;
+ yy_flex_debug = 0;
+ yylineno = 1; // this will only get updated if %option yylineno
+
+ yy_did_buffer_switch_on_eof = 0;
+
+ yy_looking_for_trail_begin = 0;
+ yy_more_flag = 0;
+ yy_more_len = 0;
+ yy_more_offset = yy_prev_more_offset = 0;
+
+ yy_start_stack_ptr = yy_start_stack_depth = 0;
+ yy_start_stack = NULL;
+
+ yy_buffer_stack = 0;
+ yy_buffer_stack_top = 0;
+ yy_buffer_stack_max = 0;
+
+ yy_state_buf = 0;
+
+}
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+yyFlexLexer::~yyFlexLexer()
+{
+ delete [] yy_state_buf;
+ envifree(yy_start_stack );
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ envifree(yy_buffer_stack );
+}
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out )
+{
+ if ( new_in )
+ {
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) );
+ }
+
+ if ( new_out )
+ yyout = new_out;
+}
+
+#ifdef YY_INTERACTIVE
+size_t yyFlexLexer::LexerInput( char* buf, size_t /* max_size */ )
+#else
+size_t yyFlexLexer::LexerInput( char* buf, size_t max_size )
+#endif
+{
+ if ( yyin->eof() || yyin->fail() )
+ return 0;
+
+#ifdef YY_INTERACTIVE
+ yyin->get( buf[0] );
+
+ if ( yyin->eof() )
+ return 0;
+
+ if ( yyin->bad() )
+ return -1;
+
+ return 1;
+
+#else
+ (void) yyin->read( buf, max_size );
+
+ if ( yyin->bad() )
+ return -1;
+ else
+ return yyin->gcount();
+#endif
+}
+
+void yyFlexLexer::LexerOutput( const char* buf, size_t size )
+{
+ (void) yyout->write( buf, size );
+}
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+int yyFlexLexer::yy_get_next_buffer()
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ envirealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) envirealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ yy_state_type yyFlexLexer::yy_get_previous_state()
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 282 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state )
+{
+ register int yy_is_jam;
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 282 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 281);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+ void yyFlexLexer::yyunput( int c, register char* yy_bp)
+{
+ register char *yy_cp;
+
+ yy_cp = (yy_c_buf_p);
+
+ /* undo effects of setting up yytext */
+ *yy_cp = (yy_hold_char);
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register yy_size_t number_to_move = (yy_n_chars) + 2;
+ register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ register char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+ (yytext_ptr) = yy_bp;
+ (yy_hold_char) = *yy_cp;
+ (yy_c_buf_p) = yy_cp;
+}
+
+ int yyFlexLexer::yyinput()
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap( ) )
+ return 0;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve yytext */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ return c;
+}
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void yyFlexLexer::yyrestart( std::istream* input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file );
+ yy_load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
+ */
+ yyensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ yy_load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+ void yyFlexLexer::yy_load_buffer_state()
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) envialloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) envialloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ *
+ */
+ void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ envifree((void *) b->yy_ch_buf );
+
+ envifree((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+ void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file )
+
+{
+ int oerrno = errno;
+
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = 0;
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ yy_load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer)
+{
+ if (new_buffer == NULL)
+ return;
+
+ yyensure_buffer_stack();
+
+ /* This block is copied from yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void yyFlexLexer::yypop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+void yyFlexLexer::yyensure_buffer_stack(void)
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)envialloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)envirealloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+ void yyFlexLexer::yy_push_state( int new_state )
+{
+ if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) )
+ {
+ yy_size_t new_size;
+
+ (yy_start_stack_depth) += YY_START_STACK_INCR;
+ new_size = (yy_start_stack_depth) * sizeof( int );
+
+ if ( ! (yy_start_stack) )
+ (yy_start_stack) = (int *) envialloc(new_size );
+
+ else
+ (yy_start_stack) = (int *) envirealloc((void *) (yy_start_stack),new_size );
+
+ if ( ! (yy_start_stack) )
+ YY_FATAL_ERROR( "out of memory expanding start-condition stack" );
+ }
+
+ (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START;
+
+ BEGIN(new_state);
+}
+
+ void yyFlexLexer::yy_pop_state()
+{
+ if ( --(yy_start_stack_ptr) < 0 )
+ YY_FATAL_ERROR( "start-condition stack underflow" );
+
+ BEGIN((yy_start_stack)[(yy_start_stack_ptr)]);
+}
+
+ int yyFlexLexer::yy_top_state()
+{
+ return (yy_start_stack)[(yy_start_stack_ptr) - 1];
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+void yyFlexLexer::LexerError( yyconst char msg[] )
+{
+ std::cerr << msg << std::endl;
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = (yy_hold_char); \
+ (yy_c_buf_p) = yytext + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *envialloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *envirealloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void envifree (void * ptr )
+{
+ free( (char *) ptr ); /* see envirealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 181 "../fitsy/envilex.L"
+
+
+
+void enviDiscard(int doit)
+{
+ if (envilexx)
+ envilexx->begin(DISCARD, doit);
+}
+
+void enviFlexLexer::begin(int which, int doit)
+{
+ BEGIN which;
+ if (doit)
+ yyless(0);
+}
+
diff --git a/fitsy++/envilex.L b/fitsy++/envilex.L
new file mode 100644
index 0000000..5621a04
--- /dev/null
+++ b/fitsy++/envilex.L
@@ -0,0 +1,194 @@
+/* Copyright (C) 1999-2018
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * For conditions of distribution and use, see copyright notice in "copyright"
+ */
+%option noyywrap
+%option caseless
+%option never-interactive
+%option c++
+
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #include "util.h"
+ #include "enviparser.H"
+
+ extern YYSTYPE* envilval;
+ extern enviFlexLexer* envilexx;
+%}
+
+%x DISCARD
+%x BRACKET
+
+D [0-9]
+E [Ee][+-]?{D}+
+
+/* rules */
+
+%%
+
+<DISCARD>[\n] { // special case-- #\n
+ BEGIN INITIAL;
+ yyless(0); // put back the terminator
+ strcpy(envilval->str,""); // feed a blank string
+ return STRING;
+ }
+
+<DISCARD>[^\n]* { // Discard reset of line
+ BEGIN INITIAL;
+ int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
+ strncpy(envilval->str,yytext,ll);
+ envilval->str[ll] = '\0';
+ return STRING;
+ }
+
+\{ {
+ BEGIN BRACKET;
+ return '{';
+ }
+
+<BRACKET>\} {
+ BEGIN INITIAL;
+ return '}';
+ }
+
+debug {return DEBUG_;}
+on {return ON_;}
+off {return OFF_;}
+
+average {return AVERAGE_;}
+band {return BAND_;}
+bands {return BANDS_;}
+bbl {return BBL_;}
+bil {return BIL_;}
+bip {return BIP_;}
+bsq {return BSQ_;}
+byte {return BYTE_;}
+envi {return ENVI_;}
+data {return DATA_;}
+default {return DEFAULT_;}
+description {return DESCRIPTION_;}
+factor {return FACTOR_;}
+frame {return FRAME_;}
+file {return FILE_;}
+fwhm {return FWHM_;}
+gain {return GAIN_;}
+header {return HEADER_;}
+info {return INFO_;}
+ignore {return IGNORE_;}
+interleave {return INTERLEAVE_;}
+limits {return LIMITS_;}
+lines {return LINES_;}
+major {return MAJOR_;}
+map {return MAP_;}
+minor {return MINOR_;}
+names {return NAMES_;}
+offset {return OFFSET_;}
+offsets {return OFFSETS_;}
+order {return ORDER_;}
+pixel {return PIXEL_;}
+pixels {return PIXELS_;}
+plot {return PLOT_;}
+projection {return PROJECTION_;}
+range {return RANGE_;}
+reflectance {return REFLECTANCE_;}
+samples {return SAMPLES_;}
+scale {return SCALE_;}
+scanner {return SCANNER_;}
+sensor {return SENSOR_;}
+size {return SIZE_;}
+stretch {return STRETCH_;}
+titles {return TITLES_;}
+type {return TYPE_;}
+units {return UNITS_;}
+value {return VALUE_;}
+values {return VALUES_;}
+wavelength {return WAVELENGTH_;}
+
+
+<BRACKET>[+-]?{D}+ { // Integer
+ envilval->integer = atoi(yytext);
+ return INT;
+ }
+
+<BRACKET>[+-]?{D}+"."?({E})? |
+<BRACKET>[+-]?{D}*"."{D}+({E})? { // Real Number
+ envilval->real = atof(yytext);
+ return REAL;
+ }
+
+
+<BRACKET>[0-9A-Za-z\-]+ { // General String
+ int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
+ strncpy(envilval->str,yytext,ll);
+ envilval->str[ll] = '\0';
+ return STRING;
+ }
+
+<BRACKET>, {
+ return ',';
+ }
+
+<BRACKET>[ \t]+ { // White Spaces
+ }
+
+<BRACKET>\n { // linefeed
+ }
+
+<BRACKET>. { // other chars, eat it
+ }
+
+[+-]?{D}+ { // Integer
+ envilval->integer = atoi(yytext);
+ return INT;
+ }
+
+[+-]?{D}+"."?({E})? |
+[+-]?{D}*"."{D}+({E})? { // Real Number
+ envilval->real = atof(yytext);
+ return REAL;
+ }
+
+
+[0-9A-Za-z]+ { // General String
+ int ll = yyleng <(ENVIPARSERSIZE-1) ? yyleng:(ENVIPARSERSIZE-1);
+ strncpy(envilval->str,yytext,ll);
+ envilval->str[ll] = '\0';
+ return STRING;
+ }
+
+[ \t]+ { // White Spaces
+ }
+
+\r\n { // windows line feed
+ return '\n';
+ }
+
+\n { // linefeed
+ return '\n';
+ }
+
+<<EOF>> { // eof
+ return EOF_;
+ }
+
+. { // Else, return the char
+ return yytext[0];
+ }
+
+%%
+
+void enviDiscard(int doit)
+{
+ if (envilexx)
+ envilexx->begin(DISCARD, doit);
+}
+
+void enviFlexLexer::begin(int which, int doit)
+{
+ BEGIN which;
+ if (doit)
+ yyless(0);
+}
diff --git a/fitsy++/enviparser.C b/fitsy++/enviparser.C
new file mode 100644
index 0000000..72e9449
--- /dev/null
+++ b/fitsy++/enviparser.C
@@ -0,0 +1,2017 @@
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "2.3"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* Substitute the variable and function names. */
+#define yyparse enviparse
+#define yylex envilex
+#define yyerror envierror
+#define yylval envilval
+#define yychar envichar
+#define yydebug envidebug
+#define yynerrs envinerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ EOF_ = 258,
+ INT = 259,
+ REAL = 260,
+ STRING = 261,
+ DEBUG_ = 262,
+ ON_ = 263,
+ OFF_ = 264,
+ AVERAGE_ = 265,
+ BAND_ = 266,
+ BANDS_ = 267,
+ BBL_ = 268,
+ BIL_ = 269,
+ BIP_ = 270,
+ BSQ_ = 271,
+ BYTE_ = 272,
+ DATA_ = 273,
+ DEFAULT_ = 274,
+ DESCRIPTION_ = 275,
+ ENVI_ = 276,
+ FACTOR_ = 277,
+ FRAME_ = 278,
+ FILE_ = 279,
+ FWHM_ = 280,
+ GAIN_ = 281,
+ HEADER_ = 282,
+ INFO_ = 283,
+ IGNORE_ = 284,
+ INTERLEAVE_ = 285,
+ LIMITS_ = 286,
+ LINES_ = 287,
+ MAJOR_ = 288,
+ MAP_ = 289,
+ MINOR_ = 290,
+ NAMES_ = 291,
+ OFFSET_ = 292,
+ OFFSETS_ = 293,
+ ORDER_ = 294,
+ PIXEL_ = 295,
+ PIXELS_ = 296,
+ PLOT_ = 297,
+ PROJECTION_ = 298,
+ RANGE_ = 299,
+ REFLECTANCE_ = 300,
+ SAMPLES_ = 301,
+ SCALE_ = 302,
+ SCANNER_ = 303,
+ SENSOR_ = 304,
+ SIZE_ = 305,
+ START_ = 306,
+ STRETCH_ = 307,
+ TITLES_ = 308,
+ TYPE_ = 309,
+ UNITS_ = 310,
+ VALUE_ = 311,
+ VALUES_ = 312,
+ WAVELENGTH_ = 313
+ };
+#endif
+/* Tokens. */
+#define EOF_ 258
+#define INT 259
+#define REAL 260
+#define STRING 261
+#define DEBUG_ 262
+#define ON_ 263
+#define OFF_ 264
+#define AVERAGE_ 265
+#define BAND_ 266
+#define BANDS_ 267
+#define BBL_ 268
+#define BIL_ 269
+#define BIP_ 270
+#define BSQ_ 271
+#define BYTE_ 272
+#define DATA_ 273
+#define DEFAULT_ 274
+#define DESCRIPTION_ 275
+#define ENVI_ 276
+#define FACTOR_ 277
+#define FRAME_ 278
+#define FILE_ 279
+#define FWHM_ 280
+#define GAIN_ 281
+#define HEADER_ 282
+#define INFO_ 283
+#define IGNORE_ 284
+#define INTERLEAVE_ 285
+#define LIMITS_ 286
+#define LINES_ 287
+#define MAJOR_ 288
+#define MAP_ 289
+#define MINOR_ 290
+#define NAMES_ 291
+#define OFFSET_ 292
+#define OFFSETS_ 293
+#define ORDER_ 294
+#define PIXEL_ 295
+#define PIXELS_ 296
+#define PLOT_ 297
+#define PROJECTION_ 298
+#define RANGE_ 299
+#define REFLECTANCE_ 300
+#define SAMPLES_ 301
+#define SCALE_ 302
+#define SCANNER_ 303
+#define SENSOR_ 304
+#define SIZE_ 305
+#define START_ 306
+#define STRETCH_ 307
+#define TITLES_ 308
+#define TYPE_ 309
+#define UNITS_ 310
+#define VALUE_ 311
+#define VALUES_ 312
+#define WAVELENGTH_ 313
+
+
+
+
+/* Copy the first part of user declarations. */
+#line 10 "../fitsy/enviparser.Y"
+
+#define YYDEBUG 1
+
+#define DISCARD_(x) {yyclearin; enviDiscard(x);}
+
+#include "file.h"
+
+#undef yyFlexLexer
+#define yyFlexLexer enviFlexLexer
+#include <FlexLexer.h>
+
+extern int envilex(void*, enviFlexLexer*);
+extern void envierror(FitsFile*, enviFlexLexer*, const char*);
+extern void enviDiscard(int);
+
+static int numWave;
+static float wave[MAXWAVES];
+
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+#line 30 "../fitsy/enviparser.Y"
+{
+#define ENVIPARSERSIZE 1024
+ float real;
+ int integer;
+ char str[ENVIPARSERSIZE];
+}
+/* Line 193 of yacc.c. */
+#line 247 "../fitsy/enviparser.C"
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 216 of yacc.c. */
+#line 260 "../fitsy/enviparser.C"
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions. */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int i)
+#else
+static int
+YYID (i)
+ int i;
+#endif
+{
+ return i;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined _STDLIB_H \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (YYID (0))
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (YYID (0))
+
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 3
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 202
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 70
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 28
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 77
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 200
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 313
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 66, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 63, 64, 2, 2, 69, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 65,
+ 2, 59, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 60, 61,
+ 62, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 67, 2, 68, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const yytype_uint16 yyprhs[] =
+{
+ 0, 0, 3, 4, 7, 11, 14, 15, 18, 20,
+ 22, 26, 30, 34, 38, 43, 49, 55, 56, 62,
+ 67, 71, 72, 78, 83, 88, 93, 98, 103, 108,
+ 113, 119, 125, 131, 137, 138, 145, 150, 155, 156,
+ 161, 165, 169, 175, 181, 190, 191, 195, 197, 199,
+ 201, 203, 205, 207, 209, 211, 213, 215, 217, 220,
+ 224, 227, 229, 233, 237, 239, 243, 247, 249, 268,
+ 269, 274, 277, 280, 284, 288, 291, 293
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yytype_int8 yyrhs[] =
+{
+ 71, 0, -1, -1, 72, 73, -1, 73, 74, 81,
+ -1, 74, 81, -1, -1, 7, 83, -1, 79, -1,
+ 21, -1, 20, 59, 87, -1, 46, 59, 4, -1,
+ 32, 59, 4, -1, 12, 59, 4, -1, 27, 37,
+ 59, 4, -1, 33, 23, 38, 59, 91, -1, 35,
+ 23, 38, 59, 91, -1, -1, 24, 54, 59, 75,
+ 6, -1, 18, 54, 59, 84, -1, 30, 59, 85,
+ -1, -1, 49, 54, 59, 76, 6, -1, 17, 39,
+ 59, 86, -1, 60, 51, 59, 91, -1, 61, 51,
+ 59, 91, -1, 34, 28, 59, 93, -1, 43, 28,
+ 59, 87, -1, 19, 12, 59, 91, -1, 58, 55,
+ 59, 6, -1, 45, 47, 22, 59, 82, -1, 62,
+ 42, 44, 59, 89, -1, 62, 42, 10, 59, 89,
+ -1, 62, 42, 53, 59, 87, -1, -1, 18, 29,
+ 57, 59, 77, 6, -1, 40, 50, 59, 89, -1,
+ 11, 36, 59, 87, -1, -1, 58, 59, 78, 95,
+ -1, 25, 59, 87, -1, 13, 59, 87, -1, 18,
+ 26, 57, 59, 89, -1, 18, 37, 57, 59, 89,
+ -1, 48, 31, 63, 41, 64, 59, 4, 4, -1,
+ -1, 65, 80, 6, -1, 66, -1, 3, -1, 5,
+ -1, 4, -1, 8, -1, 9, -1, 4, -1, 16,
+ -1, 15, -1, 14, -1, 4, -1, 67, 68, -1,
+ 67, 88, 68, -1, 88, 6, -1, 6, -1, 67,
+ 90, 68, -1, 90, 69, 82, -1, 82, -1, 67,
+ 92, 68, -1, 92, 69, 4, -1, 4, -1, 67,
+ 6, 69, 4, 69, 4, 69, 82, 69, 82, 69,
+ 82, 69, 82, 69, 4, 94, 68, -1, -1, 69,
+ 6, 69, 6, -1, 69, 6, -1, 67, 68, -1,
+ 67, 96, 68, -1, 96, 69, 97, -1, 96, 69,
+ -1, 97, -1, 82, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const yytype_uint16 yyrline[] =
+{
+ 0, 102, 102, 102, 104, 105, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 119, 120,
+ 121, 122, 122, 123, 124, 125, 126, 127, 128, 129,
+ 130, 131, 132, 133, 134, 134, 135, 136, 137, 137,
+ 138, 139, 140, 141, 142, 145, 145, 148, 149, 152,
+ 153, 156, 157, 160, 190, 191, 192, 195, 208, 209,
+ 212, 213, 216, 219, 220, 223, 226, 227, 230, 233,
+ 234, 235, 238, 244, 259, 260, 261, 264
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "EOF_", "INT", "REAL", "STRING",
+ "DEBUG_", "ON_", "OFF_", "AVERAGE_", "BAND_", "BANDS_", "BBL_", "BIL_",
+ "BIP_", "BSQ_", "BYTE_", "DATA_", "DEFAULT_", "DESCRIPTION_", "ENVI_",
+ "FACTOR_", "FRAME_", "FILE_", "FWHM_", "GAIN_", "HEADER_", "INFO_",
+ "IGNORE_", "INTERLEAVE_", "LIMITS_", "LINES_", "MAJOR_", "MAP_",
+ "MINOR_", "NAMES_", "OFFSET_", "OFFSETS_", "ORDER_", "PIXEL_", "PIXELS_",
+ "PLOT_", "PROJECTION_", "RANGE_", "REFLECTANCE_", "SAMPLES_", "SCALE_",
+ "SCANNER_", "SENSOR_", "SIZE_", "START_", "STRETCH_", "TITLES_", "TYPE_",
+ "UNITS_", "VALUE_", "VALUES_", "WAVELENGTH_", "'='", "'X'", "'Y'", "'Z'",
+ "'('", "')'", "';'", "'\\n'", "'{'", "'}'", "','", "$accept", "start",
+ "@1", "commands", "command", "@2", "@3", "@4", "@5", "comment", "@6",
+ "terminator", "numeric", "debug", "bitpix", "encoding", "endian",
+ "liststr", "strings", "listnum", "numerics", "listint", "ints",
+ "listmap", "listmapopt", "listwave", "aWaves", "aWave", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const yytype_uint16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
+ 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
+ 305, 306, 307, 308, 309, 310, 311, 312, 313, 61,
+ 88, 89, 90, 40, 41, 59, 10, 123, 125, 44
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 70, 72, 71, 73, 73, 74, 74, 74, 74,
+ 74, 74, 74, 74, 74, 74, 74, 75, 74, 74,
+ 74, 76, 74, 74, 74, 74, 74, 74, 74, 74,
+ 74, 74, 74, 74, 77, 74, 74, 74, 78, 74,
+ 74, 74, 74, 74, 74, 80, 79, 81, 81, 82,
+ 82, 83, 83, 84, 85, 85, 85, 86, 87, 87,
+ 88, 88, 89, 90, 90, 91, 92, 92, 93, 94,
+ 94, 94, 95, 95, 96, 96, 96, 97
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 0, 2, 3, 2, 0, 2, 1, 1,
+ 3, 3, 3, 3, 4, 5, 5, 0, 5, 4,
+ 3, 0, 5, 4, 4, 4, 4, 4, 4, 4,
+ 5, 5, 5, 5, 0, 6, 4, 4, 0, 4,
+ 3, 3, 5, 5, 8, 0, 3, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 2, 1, 3, 3, 1, 3, 3, 1, 18, 0,
+ 4, 2, 2, 3, 3, 2, 1, 1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const yytype_uint8 yydefact[] =
+{
+ 2, 0, 6, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 9, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 45, 6, 0, 8, 51, 52, 7, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 38, 0, 0, 0, 0, 0, 48,
+ 47, 5, 0, 13, 0, 41, 0, 0, 0, 0,
+ 0, 0, 10, 17, 40, 0, 56, 55, 54, 20,
+ 12, 0, 0, 0, 0, 0, 0, 11, 0, 21,
+ 0, 0, 0, 0, 0, 0, 0, 46, 4, 37,
+ 61, 58, 0, 57, 23, 0, 34, 0, 53, 19,
+ 0, 28, 0, 14, 0, 0, 26, 0, 0, 36,
+ 27, 0, 0, 0, 29, 0, 39, 24, 25, 0,
+ 0, 0, 60, 59, 42, 0, 43, 67, 0, 18,
+ 15, 0, 16, 50, 49, 64, 0, 30, 0, 22,
+ 72, 77, 0, 76, 32, 31, 33, 35, 65, 0,
+ 0, 62, 0, 0, 73, 75, 66, 0, 63, 0,
+ 74, 0, 44, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 69, 0, 0, 71, 68, 0, 70
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int16 yydefgoto[] =
+{
+ -1, 1, 2, 32, 33, 122, 133, 145, 101, 34,
+ 67, 71, 161, 37, 119, 89, 114, 75, 112, 129,
+ 156, 121, 148, 126, 195, 136, 162, 163
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -126
+static const yytype_int16 yypact[] =
+{
+ -126, 24, 68, -126, -1, 1, -6, -3, 6, -14,
+ 50, 40, -126, 12, 45, 46, 51, 53, 82, 81,
+ 92, 69, 90, 73, 63, 93, 67, -9, 72, 74,
+ 85, -126, 9, -2, -126, -126, -126, -126, 75, 127,
+ 65, 76, 79, 80, 83, 84, 86, 65, 87, 65,
+ 88, 62, 134, 101, 89, 103, 91, 94, 120, 140,
+ 95, 96, 97, -126, 98, 100, 7, 143, -2, -126,
+ -126, -126, 65, -126, 4, -126, 147, 102, 104, 105,
+ 148, 99, -126, -126, -126, 150, -126, -126, -126, -126,
+ -126, 106, 107, 108, 109, 65, 110, -126, 119, -126,
+ 156, 111, 99, 99, 112, 113, 114, -126, -126, -126,
+ -126, -126, 5, -126, -126, 109, -126, 109, -126, -126,
+ 164, -126, 169, -126, 99, 171, -126, 99, 14, -126,
+ -126, 14, 115, 174, -126, 0, -126, -126, -126, 109,
+ 109, 65, -126, -126, -126, 175, -126, -126, -37, -126,
+ -126, 116, -126, -126, -126, -126, 22, -126, 123, -126,
+ -126, -126, 28, -126, -126, -126, -126, -126, -126, 166,
+ 179, -126, 14, 180, -126, 14, -126, 117, -126, 183,
+ -126, 184, -126, 121, 14, 122, 14, 124, 14, 125,
+ 14, 126, 185, 128, 186, 130, 131, -126, 190, -126
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int16 yypgoto[] =
+{
+ -126, -126, -126, -126, 167, -126, -126, -126, -126, -126,
+ -126, 133, -125, -126, -126, -126, -126, -47, -126, -33,
+ -126, -89, -126, -126, -126, -126, -126, 27
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -4
+static const yytype_int16 yytable[] =
+{
+ 82, 69, 84, 155, 153, 154, 157, 35, 36, -3,
+ 110, 142, 42, 137, 138, 43, 4, 104, 153, 154,
+ 5, 6, 7, 44, 3, 109, 8, 9, 10, 11,
+ 12, 168, 169, 13, 14, 150, 15, 38, 152, 16,
+ 45, 17, 18, 19, 20, 41, 62, 178, 130, 21,
+ 63, 105, 22, 39, 23, 24, 40, 25, 26, 185,
+ 106, 187, 46, 189, 70, 191, 48, 27, 160, 28,
+ 29, 30, 111, 143, 31, 4, 86, 87, 88, 5,
+ 6, 7, 144, 50, 146, 8, 9, 10, 11, 12,
+ 171, 172, 13, 14, 166, 15, 174, 175, 16, 47,
+ 17, 18, 19, 20, 49, 53, 164, 165, 21, 54,
+ 51, 22, 52, 23, 24, 55, 25, 26, 57, 56,
+ 58, 61, 59, 64, 60, 65, 27, 66, 28, 29,
+ 30, 73, 74, 31, 72, 76, 77, 78, 90, 91,
+ 79, 93, 96, 80, 97, 81, 83, 85, 92, 107,
+ 94, 113, 118, 95, 123, 99, 100, 102, 98, 103,
+ 132, 115, 134, 116, 117, 124, 120, 127, 147, 131,
+ 176, 139, 140, 141, 125, 149, 128, 151, 135, 158,
+ 159, 167, 173, 177, 179, 170, 181, 182, 183, 193,
+ 184, 186, 196, 188, 190, 192, 199, 194, 197, 68,
+ 198, 108, 180
+};
+
+static const yytype_uint8 yycheck[] =
+{
+ 47, 3, 49, 128, 4, 5, 131, 8, 9, 0,
+ 6, 6, 26, 102, 103, 29, 7, 10, 4, 5,
+ 11, 12, 13, 37, 0, 72, 17, 18, 19, 20,
+ 21, 68, 69, 24, 25, 124, 27, 36, 127, 30,
+ 54, 32, 33, 34, 35, 39, 55, 172, 95, 40,
+ 59, 44, 43, 59, 45, 46, 59, 48, 49, 184,
+ 53, 186, 12, 188, 66, 190, 54, 58, 68, 60,
+ 61, 62, 68, 68, 65, 7, 14, 15, 16, 11,
+ 12, 13, 115, 37, 117, 17, 18, 19, 20, 21,
+ 68, 69, 24, 25, 141, 27, 68, 69, 30, 59,
+ 32, 33, 34, 35, 59, 23, 139, 140, 40, 28,
+ 59, 43, 59, 45, 46, 23, 48, 49, 28, 50,
+ 47, 54, 59, 51, 31, 51, 58, 42, 60, 61,
+ 62, 4, 67, 65, 59, 59, 57, 57, 4, 38,
+ 57, 38, 22, 59, 4, 59, 59, 59, 59, 6,
+ 59, 4, 4, 59, 4, 59, 59, 59, 63, 59,
+ 41, 59, 6, 59, 59, 59, 67, 59, 4, 59,
+ 4, 59, 59, 59, 67, 6, 67, 6, 67, 64,
+ 6, 6, 59, 4, 4, 69, 69, 4, 4, 4,
+ 69, 69, 6, 69, 69, 69, 6, 69, 68, 32,
+ 69, 68, 175
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 71, 72, 0, 7, 11, 12, 13, 17, 18,
+ 19, 20, 21, 24, 25, 27, 30, 32, 33, 34,
+ 35, 40, 43, 45, 46, 48, 49, 58, 60, 61,
+ 62, 65, 73, 74, 79, 8, 9, 83, 36, 59,
+ 59, 39, 26, 29, 37, 54, 12, 59, 54, 59,
+ 37, 59, 59, 23, 28, 23, 50, 28, 47, 59,
+ 31, 54, 55, 59, 51, 51, 42, 80, 74, 3,
+ 66, 81, 59, 4, 67, 87, 59, 57, 57, 57,
+ 59, 59, 87, 59, 87, 59, 14, 15, 16, 85,
+ 4, 38, 59, 38, 59, 59, 22, 4, 63, 59,
+ 59, 78, 59, 59, 10, 44, 53, 6, 81, 87,
+ 6, 68, 88, 4, 86, 59, 59, 59, 4, 84,
+ 67, 91, 75, 4, 59, 67, 93, 59, 67, 89,
+ 87, 59, 41, 76, 6, 67, 95, 91, 91, 59,
+ 59, 59, 6, 68, 89, 77, 89, 4, 92, 6,
+ 91, 6, 91, 4, 5, 82, 90, 82, 64, 6,
+ 68, 82, 96, 97, 89, 89, 87, 6, 68, 69,
+ 69, 68, 69, 59, 68, 69, 4, 4, 82, 4,
+ 97, 69, 4, 4, 69, 82, 69, 82, 69, 82,
+ 69, 82, 69, 4, 69, 94, 6, 68, 69, 6
+};
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK (1); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (envi, ll, YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (YYID (0))
+
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+# define YY_LOCATION_PRINT(File, Loc) \
+ fprintf (File, "%d.%d-%d.%d", \
+ (Loc).first_line, (Loc).first_column, \
+ (Loc).last_line, (Loc).last_column)
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval, ll)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value, envi, ll); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, FitsFile* envi, enviFlexLexer* ll)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep, envi, ll)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+ FitsFile* envi;
+ enviFlexLexer* ll;
+#endif
+{
+ if (!yyvaluep)
+ return;
+ YYUSE (envi);
+ YYUSE (ll);
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, FitsFile* envi, enviFlexLexer* ll)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep, envi, ll)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+ FitsFile* envi;
+ enviFlexLexer* ll;
+#endif
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep, envi, ll);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ yytype_int16 *bottom;
+ yytype_int16 *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule, FitsFile* envi, enviFlexLexer* ll)
+#else
+static void
+yy_reduce_print (yyvsp, yyrule, envi, ll)
+ YYSTYPE *yyvsp;
+ int yyrule;
+ FitsFile* envi;
+ enviFlexLexer* ll;
+#endif
+{
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ fprintf (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ , envi, ll);
+ fprintf (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyvsp, Rule, envi, ll); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+ const char *yystr;
+#endif
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+#endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into YYRESULT an error message about the unexpected token
+ YYCHAR while in state YYSTATE. Return the number of bytes copied,
+ including the terminating null byte. If YYRESULT is null, do not
+ copy anything; just return the number of bytes that would be
+ copied. As a special case, return 0 if an ordinary "syntax error"
+ message will do. Return YYSIZE_MAXIMUM if overflow occurs during
+ size calculation. */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+ int yyn = yypact[yystate];
+
+ if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+ return 0;
+ else
+ {
+ int yytype = YYTRANSLATE (yychar);
+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ int yysize_overflow = 0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyx;
+
+# if 0
+ /* This is so xgettext sees the translatable formats that are
+ constructed on the fly. */
+ YY_("syntax error, unexpected %s");
+ YY_("syntax error, unexpected %s, expecting %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+ char *yyfmt;
+ char const *yyf;
+ static char const yyunexpected[] = "syntax error, unexpected %s";
+ static char const yyexpecting[] = ", expecting %s";
+ static char const yyor[] = " or %s";
+ char yyformat[sizeof yyunexpected
+ + sizeof yyexpecting - 1
+ + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+ * (sizeof yyor - 1))];
+ char const *yyprefix = yyexpecting;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 1;
+
+ yyarg[0] = yytname[yytype];
+ yyfmt = yystpcpy (yyformat, yyunexpected);
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ yyformat[sizeof yyunexpected - 1] = '\0';
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+ yyfmt = yystpcpy (yyfmt, yyprefix);
+ yyprefix = yyor;
+ }
+
+ yyf = YY_(yyformat);
+ yysize1 = yysize + yystrlen (yyf);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+
+ if (yysize_overflow)
+ return YYSIZE_MAXIMUM;
+
+ if (yyresult)
+ {
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ char *yyp = yyresult;
+ int yyi = 0;
+ while ((*yyp = *yyf) != '\0')
+ {
+ if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyf += 2;
+ }
+ else
+ {
+ yyp++;
+ yyf++;
+ }
+ }
+ }
+ return yysize;
+ }
+}
+#endif /* YYERROR_VERBOSE */
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, FitsFile* envi, enviFlexLexer* ll)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep, envi, ll)
+ const char *yymsg;
+ int yytype;
+ YYSTYPE *yyvaluep;
+ FitsFile* envi;
+ enviFlexLexer* ll;
+#endif
+{
+ YYUSE (yyvaluep);
+ YYUSE (envi);
+ YYUSE (ll);
+
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (FitsFile* envi, enviFlexLexer* ll);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (FitsFile* envi, enviFlexLexer* ll)
+#else
+int
+yyparse (envi, ll)
+ FitsFile* envi;
+ enviFlexLexer* ll;
+#endif
+#endif
+{
+ /* The look-ahead symbol. */
+int yychar;
+
+/* The semantic value of the look-ahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Look-ahead token as an internal (translated) token number. */
+ int yytoken = 0;
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss = yyssa;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ look-ahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to look-ahead token. */
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a look-ahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the look-ahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 2:
+#line 102 "../fitsy/enviparser.Y"
+ {envi->setpArch(FitsFile::BIG);}
+ break;
+
+ case 11:
+#line 113 "../fitsy/enviparser.Y"
+ {envi->setpWidth((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 12:
+#line 114 "../fitsy/enviparser.Y"
+ {envi->setpHeight((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 13:
+#line 115 "../fitsy/enviparser.Y"
+ {envi->setpDepth((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 14:
+#line 116 "../fitsy/enviparser.Y"
+ {envi->setpSkip((yyvsp[(4) - (4)].integer));;}
+ break;
+
+ case 17:
+#line 119 "../fitsy/enviparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 21:
+#line 122 "../fitsy/enviparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 34:
+#line 134 "../fitsy/enviparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 38:
+#line 137 "../fitsy/enviparser.Y"
+ {numWave=0;;}
+ break;
+
+ case 45:
+#line 145 "../fitsy/enviparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 48:
+#line 149 "../fitsy/enviparser.Y"
+ {YYACCEPT;;}
+ break;
+
+ case 49:
+#line 152 "../fitsy/enviparser.Y"
+ {(yyval.real)=(yyvsp[(1) - (1)].real);;}
+ break;
+
+ case 50:
+#line 153 "../fitsy/enviparser.Y"
+ {(yyval.real)=(yyvsp[(1) - (1)].integer);;}
+ break;
+
+ case 51:
+#line 156 "../fitsy/enviparser.Y"
+ {yydebug=1;;}
+ break;
+
+ case 52:
+#line 157 "../fitsy/enviparser.Y"
+ {yydebug=0;;}
+ break;
+
+ case 53:
+#line 161 "../fitsy/enviparser.Y"
+ {
+ switch((yyvsp[(1) - (1)].integer)) {
+ case 1:
+ {envi->setpBitpix(8);}
+ break;
+ case 2:
+ {envi->setpBitpix(16);}
+ break;
+ case 12:
+ {envi->setpBitpix(-16);}
+ break;
+ case 3:
+ {envi->setpBitpix(32);}
+ break;
+ case 14:
+ {envi->setpBitpix(64);}
+ break;
+ case 4:
+ {envi->setpBitpix(-32);}
+ break;
+ case 5:
+ {envi->setpBitpix(-64);}
+ break;
+ default:
+ break;
+ }
+ ;}
+ break;
+
+ case 54:
+#line 190 "../fitsy/enviparser.Y"
+ {envi->setpEncoding(FitsFile::BSQ);;}
+ break;
+
+ case 55:
+#line 191 "../fitsy/enviparser.Y"
+ {envi->setpEncoding(FitsFile::BIP);;}
+ break;
+
+ case 56:
+#line 192 "../fitsy/enviparser.Y"
+ {envi->setpEncoding(FitsFile::BIL);;}
+ break;
+
+ case 57:
+#line 196 "../fitsy/enviparser.Y"
+ {
+ switch((yyvsp[(1) - (1)].integer)) {
+ case 0:
+ {envi->setpArch(FitsFile::LITTLE);}
+ break;
+ case 1:
+ {envi->setpArch(FitsFile::BIG);}
+ break;
+ }
+ ;}
+ break;
+
+ case 72:
+#line 239 "../fitsy/enviparser.Y"
+ {
+ envi->setpCRPIX3(1);
+ envi->setpCRVAL3(1);
+ envi->setpCDELT3(1);
+ ;}
+ break;
+
+ case 73:
+#line 245 "../fitsy/enviparser.Y"
+ {
+ if (numWave>=2) {
+ envi->setpCRPIX3(1);
+ envi->setpCRVAL3(wave[0]);
+ envi->setpCDELT3((wave[numWave-1]-wave[0])/(numWave-1));
+ }
+ else {
+ envi->setpCRPIX3(1);
+ envi->setpCRVAL3(1);
+ envi->setpCDELT3(1);
+ }
+ ;}
+ break;
+
+ case 77:
+#line 265 "../fitsy/enviparser.Y"
+ {
+ if (numWave < MAXWAVES)
+ wave[numWave++] = (yyvsp[(1) - (1)].real);
+ ;}
+ break;
+
+
+/* Line 1267 of yacc.c. */
+#line 1802 "../fitsy/enviparser.C"
+ default: break;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (envi, ll, YY_("syntax error"));
+#else
+ {
+ YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+ if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+ {
+ YYSIZE_T yyalloc = 2 * yysize;
+ if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+ yyalloc = YYSTACK_ALLOC_MAXIMUM;
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+ if (yymsg)
+ yymsg_alloc = yyalloc;
+ else
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ }
+ }
+
+ if (0 < yysize && yysize <= yymsg_alloc)
+ {
+ (void) yysyntax_error (yymsg, yystate, yychar);
+ yyerror (envi, ll, yymsg);
+ }
+ else
+ {
+ yyerror (envi, ll, YY_("syntax error"));
+ if (yysize != 0)
+ goto yyexhaustedlab;
+ }
+ }
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse look-ahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval, envi, ll);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse look-ahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp, envi, ll);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ *++yyvsp = yylval;
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (envi, ll, YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEOF && yychar != YYEMPTY)
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval, envi, ll);
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp, envi, ll);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ /* Make sure YYID is used. */
+ return YYID (yyresult);
+}
+
+
+#line 271 "../fitsy/enviparser.Y"
+
+
diff --git a/fitsy++/enviparser.H b/fitsy++/enviparser.H
new file mode 100644
index 0000000..baad11a
--- /dev/null
+++ b/fitsy++/enviparser.H
@@ -0,0 +1,179 @@
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton interface for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ EOF_ = 258,
+ INT = 259,
+ REAL = 260,
+ STRING = 261,
+ DEBUG_ = 262,
+ ON_ = 263,
+ OFF_ = 264,
+ AVERAGE_ = 265,
+ BAND_ = 266,
+ BANDS_ = 267,
+ BBL_ = 268,
+ BIL_ = 269,
+ BIP_ = 270,
+ BSQ_ = 271,
+ BYTE_ = 272,
+ DATA_ = 273,
+ DEFAULT_ = 274,
+ DESCRIPTION_ = 275,
+ ENVI_ = 276,
+ FACTOR_ = 277,
+ FRAME_ = 278,
+ FILE_ = 279,
+ FWHM_ = 280,
+ GAIN_ = 281,
+ HEADER_ = 282,
+ INFO_ = 283,
+ IGNORE_ = 284,
+ INTERLEAVE_ = 285,
+ LIMITS_ = 286,
+ LINES_ = 287,
+ MAJOR_ = 288,
+ MAP_ = 289,
+ MINOR_ = 290,
+ NAMES_ = 291,
+ OFFSET_ = 292,
+ OFFSETS_ = 293,
+ ORDER_ = 294,
+ PIXEL_ = 295,
+ PIXELS_ = 296,
+ PLOT_ = 297,
+ PROJECTION_ = 298,
+ RANGE_ = 299,
+ REFLECTANCE_ = 300,
+ SAMPLES_ = 301,
+ SCALE_ = 302,
+ SCANNER_ = 303,
+ SENSOR_ = 304,
+ SIZE_ = 305,
+ START_ = 306,
+ STRETCH_ = 307,
+ TITLES_ = 308,
+ TYPE_ = 309,
+ UNITS_ = 310,
+ VALUE_ = 311,
+ VALUES_ = 312,
+ WAVELENGTH_ = 313
+ };
+#endif
+/* Tokens. */
+#define EOF_ 258
+#define INT 259
+#define REAL 260
+#define STRING 261
+#define DEBUG_ 262
+#define ON_ 263
+#define OFF_ 264
+#define AVERAGE_ 265
+#define BAND_ 266
+#define BANDS_ 267
+#define BBL_ 268
+#define BIL_ 269
+#define BIP_ 270
+#define BSQ_ 271
+#define BYTE_ 272
+#define DATA_ 273
+#define DEFAULT_ 274
+#define DESCRIPTION_ 275
+#define ENVI_ 276
+#define FACTOR_ 277
+#define FRAME_ 278
+#define FILE_ 279
+#define FWHM_ 280
+#define GAIN_ 281
+#define HEADER_ 282
+#define INFO_ 283
+#define IGNORE_ 284
+#define INTERLEAVE_ 285
+#define LIMITS_ 286
+#define LINES_ 287
+#define MAJOR_ 288
+#define MAP_ 289
+#define MINOR_ 290
+#define NAMES_ 291
+#define OFFSET_ 292
+#define OFFSETS_ 293
+#define ORDER_ 294
+#define PIXEL_ 295
+#define PIXELS_ 296
+#define PLOT_ 297
+#define PROJECTION_ 298
+#define RANGE_ 299
+#define REFLECTANCE_ 300
+#define SAMPLES_ 301
+#define SCALE_ 302
+#define SCANNER_ 303
+#define SENSOR_ 304
+#define SIZE_ 305
+#define START_ 306
+#define STRETCH_ 307
+#define TITLES_ 308
+#define TYPE_ 309
+#define UNITS_ 310
+#define VALUE_ 311
+#define VALUES_ 312
+#define WAVELENGTH_ 313
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+#line 30 "../fitsy/enviparser.Y"
+{
+#define ENVIPARSERSIZE 1024
+ float real;
+ int integer;
+ char str[ENVIPARSERSIZE];
+}
+/* Line 1529 of yacc.c. */
+#line 172 "../fitsy/enviparser.H"
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
diff --git a/fitsy++/enviparser.Y b/fitsy++/enviparser.Y
new file mode 100644
index 0000000..d7256ff
--- /dev/null
+++ b/fitsy++/enviparser.Y
@@ -0,0 +1,271 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+%pure-parser
+%parse-param {FitsFile* envi}
+%lex-param {enviFlexLexer* ll}
+%parse-param {enviFlexLexer* ll}
+
+%{
+#define YYDEBUG 1
+
+#define DISCARD_(x) {yyclearin; enviDiscard(x);}
+
+#include "file.h"
+
+#undef yyFlexLexer
+#define yyFlexLexer enviFlexLexer
+#include <FlexLexer.h>
+
+extern int envilex(void*, enviFlexLexer*);
+extern void envierror(FitsFile*, enviFlexLexer*, const char*);
+extern void enviDiscard(int);
+
+static int numWave;
+static float wave[MAXWAVES];
+
+%}
+
+%union {
+#define ENVIPARSERSIZE 1024
+ float real;
+ int integer;
+ char str[ENVIPARSERSIZE];
+}
+
+%type <real> numeric
+
+ // Basic
+%token EOF_
+%token <integer> INT
+%token <real> REAL
+%token <str> STRING
+
+%token DEBUG_
+%token ON_
+%token OFF_
+
+%token AVERAGE_
+%token BAND_
+%token BANDS_
+%token BBL_
+%token BIL_
+%token BIP_
+%token BSQ_
+%token BYTE_
+%token DATA_
+%token DEFAULT_
+%token DESCRIPTION_
+%token ENVI_
+%token FACTOR_
+%token FRAME_
+%token FILE_
+%token FWHM_
+%token GAIN_
+%token HEADER_
+%token INFO_
+%token IGNORE_
+%token INTERLEAVE_
+%token LIMITS_
+%token LINES_
+%token MAJOR_
+%token MAP_
+%token MINOR_
+%token NAMES_
+%token OFFSET_
+%token OFFSETS_
+%token ORDER_
+%token PIXEL_
+%token PIXELS_
+%token PLOT_
+%token PROJECTION_
+%token RANGE_
+%token REFLECTANCE_
+%token SAMPLES_
+%token SCALE_
+%token SCANNER_
+%token SENSOR_
+%token SIZE_
+%token START_
+%token STRETCH_
+%token TITLES_
+%token TYPE_
+%token UNITS_
+%token VALUE_
+%token VALUES_
+%token WAVELENGTH_
+
+%%
+
+ //start : {yydebug=1;} commands
+ start : {envi->setpArch(FitsFile::BIG)} commands
+
+commands: commands command terminator
+ | command terminator
+ ;
+
+command : /* empty */
+ | DEBUG_ debug
+ | comment
+ | ENVI_
+ | DESCRIPTION_ '=' liststr
+ | SAMPLES_ '=' INT {envi->setpWidth($3);}
+ | LINES_ '=' INT {envi->setpHeight($3);}
+ | BANDS_ '=' INT {envi->setpDepth($3);}
+ | HEADER_ OFFSET_ '=' INT {envi->setpSkip($4);}
+ | MAJOR_ FRAME_ OFFSETS_ '=' listint
+ | MINOR_ FRAME_ OFFSETS_ '=' listint
+ | FILE_ TYPE_ '=' {DISCARD_(1)} STRING
+ | DATA_ TYPE_ '=' bitpix
+ | INTERLEAVE_ '=' encoding
+ | SENSOR_ TYPE_ '=' {DISCARD_(1)} STRING
+ | BYTE_ ORDER_ '=' endian
+ | 'X' START_ '=' listint
+ | 'Y' START_ '=' listint
+ | MAP_ INFO_ '=' listmap
+ | PROJECTION_ INFO_ '=' liststr
+ | DEFAULT_ BANDS_ '=' listint
+ | WAVELENGTH_ UNITS_ '=' STRING
+ | REFLECTANCE_ SCALE_ FACTOR_ '=' numeric
+ | 'Z' PLOT_ RANGE_ '=' listnum
+ | 'Z' PLOT_ AVERAGE_ '=' listnum
+ | 'Z' PLOT_ TITLES_ '=' liststr
+ | DATA_ IGNORE_ VALUES_ '=' {DISCARD_(1)} STRING
+ | PIXEL_ SIZE_ '=' listnum
+ | BAND_ NAMES_ '=' liststr
+ | WAVELENGTH_ '=' {numWave=0;} listwave
+ | FWHM_ '=' liststr
+ | BBL_ '=' liststr
+ | DATA_ GAIN_ VALUES_ '=' listnum
+ | DATA_ OFFSET_ VALUES_ '=' listnum
+ | SCANNER_ LIMITS_ '(' PIXELS_ ')' '=' INT INT
+ ;
+
+comment : ';' {DISCARD_(1)} STRING
+ ;
+
+terminator: '\n'
+ | EOF_ {YYACCEPT;}
+ ;
+
+numeric : REAL {$$=$1;}
+ | INT {$$=$1;}
+ ;
+
+debug : ON_ {yydebug=1;}
+ | OFF_ {yydebug=0;}
+ ;
+
+bitpix : INT
+ {
+ switch($1) {
+ case 1:
+ {envi->setpBitpix(8);}
+ break;
+ case 2:
+ {envi->setpBitpix(16);}
+ break;
+ case 12:
+ {envi->setpBitpix(-16);}
+ break;
+ case 3:
+ {envi->setpBitpix(32);}
+ break;
+ case 14:
+ {envi->setpBitpix(64);}
+ break;
+ case 4:
+ {envi->setpBitpix(-32);}
+ break;
+ case 5:
+ {envi->setpBitpix(-64);}
+ break;
+ default:
+ break;
+ }
+ }
+ ;
+
+encoding : BSQ_ {envi->setpEncoding(FitsFile::BSQ);}
+ | BIP_ {envi->setpEncoding(FitsFile::BIP);}
+ | BIL_ {envi->setpEncoding(FitsFile::BIL);}
+ ;
+
+endian : INT
+ {
+ switch($1) {
+ case 0:
+ {envi->setpArch(FitsFile::LITTLE);}
+ break;
+ case 1:
+ {envi->setpArch(FitsFile::BIG);}
+ break;
+ }
+ }
+ ;
+
+liststr : '{' '}'
+ | '{' strings '}'
+ ;
+
+strings : strings STRING
+ | STRING
+ ;
+
+listnum : '{' numerics '}'
+ ;
+
+numerics: numerics ',' numeric
+ | numeric
+ ;
+
+listint : '{' ints '}'
+ ;
+
+ints : ints ',' INT
+ | INT
+ ;
+
+listmap : '{' STRING ',' INT ',' INT ',' numeric ',' numeric ',' numeric ',' numeric ',' INT listmapopt '}'
+ ;
+
+listmapopt : /* empty */
+ | ',' STRING ',' STRING
+ | ',' STRING
+ ;
+
+listwave: '{' '}'
+ {
+ envi->setpCRPIX3(1);
+ envi->setpCRVAL3(1);
+ envi->setpCDELT3(1);
+ }
+ | '{' aWaves '}'
+ {
+ if (numWave>=2) {
+ envi->setpCRPIX3(1);
+ envi->setpCRVAL3(wave[0]);
+ envi->setpCDELT3((wave[numWave-1]-wave[0])/(numWave-1));
+ }
+ else {
+ envi->setpCRPIX3(1);
+ envi->setpCRVAL3(1);
+ envi->setpCDELT3(1);
+ }
+ }
+ ;
+
+aWaves : aWaves ',' aWave
+ | aWaves ','
+ | aWave
+ ;
+
+aWave : numeric
+ {
+ if (numWave < MAXWAVES)
+ wave[numWave++] = $1;
+ }
+ ;
+
+%%
diff --git a/fitsy++/file.C b/fitsy++/file.C
new file mode 100644
index 0000000..3de8dd6
--- /dev/null
+++ b/fitsy++/file.C
@@ -0,0 +1,512 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "file.h"
+#include "util.h"
+
+// extention parser
+#undef yyFlexLexer
+#define yyFlexLexer ffFlexLexer
+#include <FlexLexer.h>
+
+void* fflval;
+ffFlexLexer* fflexx;
+extern int ffparse(FitsFile*, ffFlexLexer*);
+
+int fflex(void* vval, ffFlexLexer* ll)
+{
+ fflval = vval;
+ fflexx = ll;
+ return ll ? ll->yylex() : 0;
+}
+
+void fferror(FitsFile* ff, ffFlexLexer* ll, const char* m)
+{
+ ff->error(m);
+ const char* cmd = ll ? ll->YYText() : (const char*)NULL;
+ if (cmd && cmd[0] != '\n')
+ ff->error(cmd);
+}
+
+// nrrd parser
+#undef yyFlexLexer
+#define yyFlexLexer nrrdFlexLexer
+#include <FlexLexer.h>
+
+void* nrrdlval;
+nrrdFlexLexer* nrrdlexx;
+extern int nrrdparse(FitsFile*, nrrdFlexLexer*);
+
+int nrrdlex(void* vval, nrrdFlexLexer* ll)
+{
+ nrrdlval = vval;
+ nrrdlexx = ll;
+ return ll ? ll->yylex() : 0;
+}
+
+void nrrderror(FitsFile* nrrd, nrrdFlexLexer* ll, const char* m)
+{
+ nrrd->error(m);
+ const char* cmd = ll ? ll->YYText() : (const char*)NULL;
+ if (cmd && cmd[0] != '\n')
+ nrrd->error(cmd);
+}
+
+// envi parser
+#undef yyFlexLexer
+#define yyFlexLexer enviFlexLexer
+#include <FlexLexer.h>
+
+void* envilval;
+enviFlexLexer* envilexx;
+extern int enviparse(FitsFile*, enviFlexLexer*);
+
+int envilex(void* vval, enviFlexLexer* ll)
+{
+ envilval = vval;
+ envilexx = ll;
+ return ll ? ll->yylex() : 0;
+}
+
+void envierror(FitsFile* envi, enviFlexLexer* ll, const char* m)
+{
+ envi->error(m);
+ const char* cmd = ll ? ll->YYText() : (const char*)NULL;
+ if (cmd && cmd[0] != '\n')
+ envi->error(cmd);
+}
+
+FitsFile::FitsFile()
+{
+ primary_ = NULL;
+ managePrimary_ = 0;
+
+ head_ = NULL;
+ manageHead_ = 1;
+
+ data_ = NULL;
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = 0;
+ inherit_ = 0;
+ byteswap_ = lsb();
+ endian_ = BIG;
+ valid_ = 0;
+
+ pName_ = NULL;
+ pExt_ = NULL;
+ pIndex_ = -1;
+
+ pFilter_ = NULL;
+ pBinX_ = NULL;
+ pBinY_ = NULL;
+ pBinZ_ = NULL;
+
+ pBitpix_ =0;
+ pWidth_ =0;
+ pHeight_ =0;
+ pDepth_ =1;
+ pSkip_ =0;
+ pArch_ =NATIVE;
+
+ pEncoding_ =RAW;
+
+ pHPXOrder_ =-1;
+ pHPXSystem_ =-1;
+ pHPXLayout_ =-1;
+ pHPXColumn_ =-1;
+ pHPXQuad_ =-1;
+
+ pCRPIX3_ =1;
+ pCRVAL3_ =1;
+ pCDELT3_ =1;
+
+ pcoord_ =0;
+ pxvalid_ =0;
+ pxmin_ =0;
+ pxmax_ =0;
+ pyvalid_ =0;
+ pymin_ =0;
+ pymax_ =0;
+ pzvalid_ =0;
+ pzmin_ =0;
+ pzmax_ =0;
+ pbvalid_ =0;
+ pblock_ =1;
+}
+
+FitsFile::~FitsFile()
+{
+ if (manageHead_ && head_)
+ delete head_;
+
+ if (managePrimary_ && primary_)
+ delete primary_;
+
+ if (pName_)
+ delete [] pName_;
+
+ if (pExt_)
+ delete [] pExt_;
+
+ if (pFilter_)
+ delete [] pFilter_;
+
+ if (pBinX_)
+ delete [] pBinX_;
+
+ if (pBinY_)
+ delete [] pBinY_;
+
+ if (pBinZ_)
+ delete [] pBinZ_;
+}
+
+void FitsFile::parse(const char* fn)
+{
+ if (fn) {
+ string x(fn);
+ istringstream str(x);
+
+ valid_ = 1;
+ ffFlexLexer* ll = new ffFlexLexer(&str);
+ ffparse(this, ll);
+ delete ll;
+ }
+
+ if (!pBinX_ && !pBinY_) {
+ char *env;
+ if ((env = getenv("DS9_BINKEY"))) {
+ string x(env);
+ istringstream str(x);
+
+ valid_ = 1;
+ ffFlexLexer* ll = new ffFlexLexer(&str);
+ ffparse(this, ll);
+ delete ll;
+ }
+ }
+
+ if (!pWidth_ && !pHeight_ && !pBitpix_) {
+ char *env;
+ if ((env = getenv("DS9_ARRAY"))) {
+ string x(env);
+ istringstream str(x);
+
+ valid_ = 1;
+ ffFlexLexer* ll = new ffFlexLexer(&str);
+ ffparse(this, ll);
+ delete ll;
+ }
+ }
+}
+
+void FitsFile::error(const char* m)
+{
+ valid_ = 0;
+ // cerr << m << endl;
+}
+
+int FitsFile::findEnd(const char* blk)
+{
+ for (int j=0; j<FTY_BLOCK; j+=FTY_CARDLEN)
+ // only check for 4 chars
+ if (!strncmp("END ", blk+j,4))
+ return 1;
+
+ return 0;
+}
+
+void FitsFile::setpName(const char* n)
+{
+ if (pName_)
+ delete [] pName_;
+
+ pName_ = dupstr(n);
+}
+
+void FitsFile::setpExt(const char* n)
+{
+ if (pExt_)
+ delete [] pExt_;
+
+ pExt_ = dupstr(n);
+}
+
+void FitsFile::setpBinX(const char* x)
+{
+ if (pBinX_)
+ delete [] pBinX_;
+
+ pBinX_ = dupstr(x);
+}
+
+void FitsFile::setpBinY(const char* y)
+{
+ if (pBinY_)
+ delete [] pBinY_;
+
+ pBinY_ = dupstr(y);
+}
+
+void FitsFile::setpBinZ(const char* z)
+{
+ if (pBinZ_)
+ delete [] pBinZ_;
+
+ pBinZ_ = dupstr(z);
+}
+
+void FitsFile::setpFilter(const char* filt)
+{
+ if (pFilter_)
+ delete [] pFilter_;
+
+ pFilter_ = dupstr(filt);
+}
+
+Vector FitsFile::getColMinMax(const char* name)
+{
+ if (isBinTable()) {
+ FitsTableHDU* hdu = (FitsTableHDU*)(head()->hdu());
+ FitsColumn* col = hdu->find(name);
+ if (col) {
+ if (!col->hasMinMax()) {
+ double zmin = DBL_MAX;
+ double zmax = -DBL_MAX;
+ int rowlen = hdu->width();
+ int numrow = hdu->rows();
+
+ char* ptr = (char*)data();
+ for (int i=0; i<numrow; i++, ptr+=rowlen) {
+ // for memory models that support internal paging
+ ptr = page(ptr, rowlen);
+
+ register double z = col->value(ptr);
+ if (z < zmin)
+ zmin = z;
+ if (z > zmax)
+ zmax = z;
+ }
+ // for memory models that support internal paging
+ resetpage();
+
+ col->setMin(zmin);
+ col->setMax(zmax);
+ return Vector(zmin,zmax);
+ }
+ else
+ return Vector(col->getMin(), col->getMax());
+ }
+ }
+ return Vector();
+}
+
+void FitsFile::setColMinMax(const char* name, const Vector& lim)
+{
+ if (isBinTable()) {
+ FitsTableHDU* hdu = (FitsTableHDU*)(head()->hdu());
+ FitsColumn* col = hdu->find(name);
+ if (col) {
+ Vector ll=lim;
+ col->setMin(ll[0]);
+ col->setMax(ll[1]);
+ }
+ }
+}
+
+Vector FitsFile::getColDim(const char* name)
+{
+ if (isBinTable()) {
+ FitsTableHDU* hdu = (FitsTableHDU*)(head()->hdu());
+ FitsColumn* col = hdu->find(name);
+ if (col) {
+ if (col->hasTLMinTLMax()) {
+ Vector lim = col->dimension();
+ col->setMin(lim[0]);
+ col->setMax(lim[1]);
+ return lim;
+ }
+ else
+ return getColMinMax(name);
+ }
+ }
+
+ return Vector();
+}
+
+int FitsFile::validParams()
+{
+ if (!pWidth_ || !pHeight_ || !pBitpix_)
+ return 0;
+
+ // check for valid bitpix
+ switch (pBitpix_) {
+ case 8:
+ case 16:
+ case -16:
+ case 32:
+ case 64:
+ case -32:
+ case -64:
+ break;
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
+void FitsFile::setByteSwap()
+{
+ switch (pArch_) {
+ case BIG:
+ endian_ = pArch_;
+ byteswap_ = lsb();
+ break;
+ case LITTLE:
+ endian_ = pArch_;
+ byteswap_ = !lsb();
+ break;
+ case NATIVE:
+ endian_ = lsb() ? LITTLE : BIG;
+ byteswap_ = 0;
+ break;
+ }
+}
+
+void FitsFile::parseNRRD(istream& str)
+{
+ valid_ = 1;
+ nrrdFlexLexer* ll = new nrrdFlexLexer(&str);
+ nrrdparse(this, ll);
+ delete ll;
+}
+
+void FitsFile::parseENVI(istream& str)
+{
+ valid_ = 1;
+ enviFlexLexer* ll = new enviFlexLexer(&str);
+ enviparse(this, ll);
+ delete ll;
+}
+
+int FitsFile::find(const char* name)
+{
+ if (head_)
+ if (head_->find(name))
+ return 1;
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return 1;
+
+ return 0;
+}
+
+int FitsFile::getLogical(const char* name, int def)
+{
+ if (head_)
+ if (head_->find(name))
+ return head_->getLogical(name,def);
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return primary_->getLogical(name,def);
+
+ return def;
+}
+
+int FitsFile::getInteger(const char* name, int def)
+{
+ if (head_)
+ if (head_->find(name))
+ return head_->getInteger(name,def);
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return primary_->getInteger(name,def);
+
+ return def;
+}
+
+double FitsFile::getReal(const char* name, double def)
+{
+ if (head_)
+ if (head_->find(name))
+ return head_->getReal(name,def);
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return primary_->getReal(name,def);
+
+ return def;
+}
+
+void FitsFile::getComplex(const char* name, double* real, double* img,
+ double rdef, double idef)
+{
+ if (head_)
+ if (head_->find(name)) {
+ head_->getComplex(name, real, img, rdef, idef);
+ return;
+ }
+
+ if (primary_ && inherit_)
+ if (primary_->find(name)) {
+ primary_->getComplex(name, real, img, rdef, idef);
+ return;
+ }
+
+ *real = rdef;
+ *img = idef;
+}
+
+char* FitsFile::getString(const char* name)
+{
+ if (head_)
+ if (head_->find(name))
+ return head_->getString(name);
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return primary_->getString(name);
+
+ return NULL;
+}
+
+char* FitsFile::getComment(const char* name)
+{
+ if (head_)
+ if (head_->find(name))
+ return head_->getComment(name);
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return primary_->getComment(name);
+
+ return NULL;
+}
+
+char* FitsFile::getKeyword(const char* name)
+{
+ if (head_)
+ if (head_->find(name))
+ return head_->getKeyword(name);
+
+ if (primary_ && inherit_)
+ if (primary_->find(name))
+ return primary_->getKeyword(name);
+
+ return NULL;
+}
+
+
+
diff --git a/fitsy++/file.h b/fitsy++/file.h
new file mode 100644
index 0000000..a8cfc46
--- /dev/null
+++ b/fitsy++/file.h
@@ -0,0 +1,233 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsfile_h__
+#define __fitsfile_h__
+
+#include "head.h"
+
+#define B4KB 4096
+#define B1MB 1048576
+#define MAXWAVES 2048
+
+extern int DebugGZ;
+extern int DebugCompress;
+
+class OutFitsStream;
+
+class FitsFile {
+public:
+ enum FlushMode {NOFLUSH,FLUSH};
+ enum ScanMode {RELAX, EXACT};
+ enum ArchType {NATIVE,BIG,LITTLE};
+ enum EncodingType {RAW,ASCII,HEX,GZIP,BZ2,BIP,BIL,BSQ};
+
+protected:
+ FitsHead* primary_; // pointer to primary header
+ int managePrimary_; // flag, true if we manage primary header
+
+ FitsHead* head_; // pointer to header
+ int manageHead_; // flag, true if we manage header
+
+ void* data_; // pointer to raw data
+ size_t dataSize_; // size of data memory segment
+ size_t dataSkip_; // skip into data memory segment
+
+ int ext_; // extension number
+ int inherit_; // do we have inheritence?
+ int byteswap_; // flag, true if byteswap is needed
+ ArchType endian_; // endian of data
+ int valid_; // flag, true if file is valid
+
+ char* pName_; // parsed file name
+ char* pExt_; // parsed ext name
+ int pIndex_; // parsed ext number
+
+ char* pFilter_; // unparsed filter spec
+ char* pBinX_; // parsed bin table x col name
+ char* pBinY_; // parsed bin table y col name
+ char* pBinZ_; // parsed bin table z col name
+
+ int pBitpix_; // parsed bitpix
+ int pWidth_; // parsed width
+ int pHeight_; // parsed height
+ int pDepth_; // parsed depth
+ size_t pSkip_; // parsed skip size
+ ArchType pArch_; // parsed arch type
+ EncodingType pEncoding_; // parsed encoding
+
+ int pHPXOrder_; // parsed HPX params
+ int pHPXSystem_;
+ int pHPXLayout_;
+ int pHPXColumn_;
+ int pHPXQuad_;
+
+ double pCRPIX3_; // WCS_3 axis params
+ double pCRVAL3_;
+ double pCDELT3_;
+
+ int pcoord_;
+ int pxvalid_;
+ int pxmin_;
+ int pxmax_;
+ int pyvalid_;
+ int pymin_;
+ int pymax_;
+ int pzvalid_;
+ int pzmin_;
+ int pzmax_;
+ int pbvalid_;
+ int pblock_;
+
+protected:
+ void parse(const char*);
+ void parseNRRD(istream&);
+ void parseENVI(istream&);
+ int validParams();
+ int findEnd(const char*);
+ void setByteSwap();
+ int saveFitsHeaderCards(OutFitsStream&, int, int);
+
+public:
+ FitsFile();
+ virtual ~FitsFile();
+
+ int manageHead() {return manageHead_;}
+
+ virtual void done() {}
+ virtual char* page(char* ptr, size_t r) {return ptr;}
+ virtual void resetpage() {}
+ void error(const char*);
+ void* data() {return data_;}
+ size_t dataSize() {return dataSize_;}
+ size_t dataSkip() {return dataSkip_;}
+ FitsHead* head() {return head_;}
+ FitsHead* primary() {return primary_;}
+ int ext() {return ext_;}
+ const char* extname() {return head_ ? head_->extname() : NULL;}
+ int extver() {return head_ ? head_->extver() : 1;}
+ int extlevel() {return head_ ? head_->extlevel() : 1;}
+ int inherit() {return inherit_;}
+ void setValid(int vv) {valid_=vv;}
+ int isValid() {return valid_;}
+ int isImage() {return head_ ? head_->isImage() : 0;}
+ int isTable() {return head_ ? head_->isTable() : 0;}
+ int isAsciiTable() {return head_ ? head_->isAsciiTable() : 0;}
+ int isBinTable() {return head_ ? head_->isBinTable() : 0;}
+ int byteswap() {return byteswap_;}
+ ArchType endian() {return endian_;}
+
+ void setpName(const char*);
+ void setpExt(const char*);
+ void setpIndex(int i) {pIndex_ = i;}
+ void setpFilter(const char*);
+ void setpBinX(const char*);
+ void setpBinY(const char*);
+ void setpBinZ(const char*);
+ void setpBinXY(const char* x, const char* y)
+ {setpBinX(x); setpBinY(y);}
+ void setpBinXYZ(const char* x, const char* y, const char* z)
+ {setpBinX(x); setpBinY(y); setpBinZ(z);}
+
+ const char* pName() {return pName_;}
+ const char* pExt() {return pExt_;}
+ int pIndex() {return pIndex_;}
+
+ const char* pFilter() {return pFilter_;}
+ const char* pBinX() {return pBinX_;}
+ const char* pBinY() {return pBinY_;}
+ const char* pBinZ() {return pBinZ_;}
+
+ int pBitpix() {return pBitpix_;}
+ int pWidth() {return pWidth_;}
+ int pHeight() {return pHeight_;}
+ int pDepth() {return pDepth_;}
+ size_t pSkip() {return pSkip_;}
+ ArchType pArch() {return pArch_;}
+
+ void setpWidth(int i) {pWidth_ = i;}
+ void setpHeight(int i) {pHeight_ = i;}
+ void setpDepth(int i) {pDepth_ = i;}
+ void setpBitpix(int b) {pBitpix_ = b;}
+ void setpSkip(size_t s) {pSkip_ = s;}
+ void setpArch(ArchType a) {pArch_ = a;}
+
+ EncodingType pEncoding() {return pEncoding_;}
+ void setpEncoding(EncodingType e) {pEncoding_ = e;}
+
+ int pHPXOrder() {return pHPXOrder_;}
+ int pHPXSystem() {return pHPXSystem_;}
+ int pHPXLayout() {return pHPXLayout_;}
+ int pHPXColumn() {return pHPXColumn_;}
+ int pHPXQuad() {return pHPXQuad_;}
+
+ void setpHPXOrder(int oo) {pHPXOrder_ = oo;}
+ void setpHPXSystem(int ss) {pHPXSystem_ = ss;}
+ void setpHPXLayout(int ll) {pHPXLayout_ = ll;}
+ void setpHPXColumn(int cc) {pHPXColumn_ = cc-1;}
+ void setpHPXQuad(int qq) {pHPXQuad_ = qq-1;}
+
+ double pCRPIX3() {return pCRPIX3_;}
+ double pCRVAL3() {return pCRVAL3_;}
+ double pCDELT3() {return pCDELT3_;}
+
+ void setpCRPIX3(double dd) {pCRPIX3_ = dd;}
+ void setpCRVAL3(double dd) {pCRVAL3_ = dd;}
+ void setpCDELT3(double dd) {pCDELT3_ = dd;}
+
+ int pcoord() {return pcoord_;}
+ int pxvalid() {return pxvalid_;}
+ int pxmin() {return pxmin_;}
+ int pxmax() {return pxmax_;}
+ int pyvalid() {return pyvalid_;}
+ int pymin() {return pymin_;}
+ int pymax() {return pymax_;}
+ int pzvalid() {return pzvalid_;}
+ int pzmin() {return pzmin_;}
+ int pzmax() {return pzmax_;}
+ int pbvalid() {return pbvalid_;}
+ int pblock() {return pblock_;}
+
+ void setpcoord(int vv) {pcoord_ = vv;}
+ void setpxvalid(int vv) {pxvalid_ = vv;}
+ void setpxmin(int vv) {pxmin_ = vv;}
+ void setpxmax(int vv) {pxmax_ = vv;}
+ void setpyvalid(int vv) {pyvalid_ = vv;}
+ void setpymin(int vv) {pymin_ = vv;}
+ void setpymax(int vv) {pymax_ = vv;}
+ void setpzvalid(int vv) {pzvalid_ = vv;}
+ void setpzmin(int vv) {pzmin_ = vv;}
+ void setpzmax(int vv) {pzmax_ = vv;}
+ void setpbvalid(int vv) {pbvalid_ = vv;}
+ void setpblock(int vv) {pblock_ = vv;}
+
+ Vector getColMinMax(const char*);
+ Vector getColDim(const char*);
+
+ void setColMinMax(const char*, const Vector&);
+
+ int find(const char* name);
+
+ int getLogical(const char* name, int def);
+ int getInteger(const char* name, int def);
+ double getReal(const char* name, double def);
+ void getComplex(const char* name, double* real, double* img,
+ double rdef, double idef);
+ char* getString(const char* name);
+ char* getComment(const char* name);
+ char* getKeyword(const char* name);
+
+ int saveFitsPrimHeader(OutFitsStream&);
+ int saveFitsHeader(OutFitsStream&, int);
+ int saveFitsXtHeader(OutFitsStream&, int);
+ int saveFits(OutFitsStream&);
+ int saveFitsPad(OutFitsStream&, size_t, char);
+ int saveFitsTable(OutFitsStream&);
+ int saveFitsIISHeader(OutFitsStream&);
+ int saveFitsIIS(OutFitsStream&, Vector&);
+
+ int saveArray(OutFitsStream&, ArchType);
+};
+
+#endif
diff --git a/fitsy++/gzip.C b/fitsy++/gzip.C
new file mode 100644
index 0000000..47ccb54
--- /dev/null
+++ b/fitsy++/gzip.C
@@ -0,0 +1,341 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "gzip.h"
+#include "zlib.h"
+#include "util.h"
+
+template<class T> FitsGzipm<T>::FitsGzipm(FitsFile* fits)
+ : FitsCompressm<T>(fits)
+{
+ FitsCompressm<T>::uncompress(fits);
+}
+
+template <class T> int FitsGzipm<T>::compressed(T* dest, char* sptr,
+ char* heap,
+ int kkstart, int kkstop,
+ int jjstart, int jjstop,
+ int iistart, int iistop)
+{
+ double zs = FitsCompressm<T>::bscale_;
+ if (FitsCompressm<T>::zscale_)
+ zs = FitsCompressm<T>::zscale_->value(sptr,0);
+
+ double zz = FitsCompressm<T>::bzero_;
+ if (FitsCompressm<T>::zzero_)
+ zz = FitsCompressm<T>::zzero_->value(sptr,0);
+
+ int blank = FitsCompressm<T>::blank_;
+ if (FitsCompressm<T>::zblank_)
+ blank = (int)FitsCompressm<T>::zblank_->value(sptr,0);
+
+ int icnt=0;
+ unsigned char* ibuf = (unsigned char*)((FitsBinColumnArray*)FitsCompressm<T>::compress_)->get(heap, sptr, &icnt);
+
+ // ibuf can be NULL
+ if (!ibuf || !icnt)
+ return 0;
+
+ int ocnt = FitsCompressm<T>::tilesize_;
+ char* obuf = new char[ocnt*sizeof(long long)];
+ if (!obuf) {
+ internalError("Fitsy++ gzip unable to alloc.");
+ return 0;
+ }
+
+ z_stream zstrm;
+ zstrm.next_in = NULL;
+ zstrm.avail_in = 0;
+ zstrm.zalloc = NULL;
+ zstrm.zfree = NULL;
+ zstrm.opaque = NULL;
+
+ // look for both zlib and gzip headers
+ if (inflateInit2(&zstrm, MAX_WBITS+32) != Z_OK) {
+ internalError("Fitsy++ gzip inflateInit error");
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ }
+
+ zstrm.avail_in = icnt;
+ zstrm.next_in = ibuf;
+ zstrm.avail_out = ocnt*sizeof(long long);
+ zstrm.next_out = (Bytef*)obuf;
+
+ if (DebugCompress)
+ cerr << " inflate START: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+
+ int result = ::inflate(&zstrm, Z_FINISH);
+
+ switch (result) {
+ case Z_OK:
+ if (DebugCompress)
+ cerr << " inflate OK: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_STREAM_END:
+ if (DebugCompress)
+ cerr << " inflate STREAM_END: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_BUF_ERROR:
+ if (DebugCompress)
+ cerr << " inflate BUF_ERROR: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out << endl;
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ default:
+ internalError("Fitsy++ gzip inflate error");
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ }
+
+ int bytepix = zstrm.total_out/FitsCompressm<T>::tilesize_;
+
+ inflateEnd(&zstrm);
+
+ // GZIP_2- unshuffle if needed
+ if (!strncmp(FitsCompressm<T>::type_,"GZIP_2",6)) {
+ switch (bytepix) {
+ case 1:
+ break;
+ case 2:
+ {
+ int ll = ocnt*sizeof(short);
+ char* nbuf = new char[ll];
+ if (!nbuf) {
+ internalError("Fitsy++ gzip unable to alloc.");
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ }
+ char* optr = obuf+ll-1;
+ char* nptr = nbuf+ll-1;
+
+ for (int ii=0; ii<ocnt; ii++) {
+ *nptr = *optr;
+ nptr--;
+ *nptr = *(optr-ocnt);
+ nptr--;
+
+ optr--;
+ }
+ memcpy(obuf,nbuf,ll);
+ delete [] nbuf;
+ }
+ break;
+ case 4:
+ {
+ int ll = ocnt*sizeof(int);
+ char* nbuf = new char[ll];
+ if (!nbuf) {
+ internalError("Fitsy++ gzip unable to alloc.");
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ }
+ char* optr = obuf+ll-1;
+ char* nptr = nbuf+ll-1;
+
+ for (int ii=0; ii<ocnt; ii++) {
+ *nptr = *optr;
+ nptr--;
+ *nptr = *(optr-ocnt);
+ nptr--;
+ *nptr = *(optr-(2*ocnt));
+ nptr--;
+ *nptr = *(optr-(3*ocnt));
+ nptr--;
+
+ optr--;
+ }
+ memcpy(obuf,nbuf,ll);
+ delete [] nbuf;
+ }
+ break;
+ case 8:
+ {
+ int ll = ocnt*sizeof(long long);
+ char* nbuf = new char[ll];
+ if (!nbuf) {
+ internalError("Fitsy++ gzip unable to alloc.");
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ }
+ char* optr = obuf+ll-1;
+ char* nptr = nbuf+ll-1;
+
+ for (int ii=0; ii<ocnt; ii++) {
+ *nptr = *optr;
+ nptr--;
+ *nptr = *(optr-ocnt);
+ nptr--;
+ *nptr = *(optr-(2*ocnt));
+ nptr--;
+ *nptr = *(optr-(3*ocnt));
+ nptr--;
+ *nptr = *(optr-(4*ocnt));
+ nptr--;
+ *nptr = *(optr-(5*ocnt));
+ nptr--;
+ *nptr = *(optr-(6*ocnt));
+ nptr--;
+ *nptr = *(optr-(7*ocnt));
+ nptr--;
+
+ optr--;
+ }
+ memcpy(obuf,nbuf,ll);
+ delete [] nbuf;
+ }
+ break;
+ }
+ }
+
+ int ll=0;
+ switch (bytepix) {
+ case 1:
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ size_t id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ // very carefull about type conversions
+ T val = FitsCompressm<T>::getValue(obuf+ll,zs,zz,blank);
+ dest[id] = val;
+ }
+ break;
+ case 2:
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // swap if needed
+ if (FitsCompressm<T>::byteswap_) {
+ const char* p = (const char*)((short*)obuf+ll);
+ union {
+ char c[2];
+ short s;
+ } u;
+
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ *((short*)obuf+ll) = u.s;
+ }
+ // very carefull about type conversions
+ size_t id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ T val = FitsCompressm<T>::getValue((short*)obuf+ll,zs,zz,blank);
+ dest[id] = val;
+ }
+ break;
+ case 4:
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // swap if needed
+ if (FitsCompressm<T>::byteswap_) {
+ const char* p = (const char*)((int*)obuf+ll);
+ union {
+ char c[4];
+ int i;
+ } u;
+
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ *((int*)obuf+ll) = u.i;
+ }
+ // very carefull about type conversions
+ size_t id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ T val =0;
+ switch (FitsCompressm<T>::quantize_) {
+ case FitsCompress::NONE:
+ val = FitsCompressm<T>::getValue((float*)obuf+ll,zs,zz,blank);
+ break;
+ case FitsCompress::NODITHER:
+ case FitsCompress::SUBDITHER1:
+ case FitsCompress::SUBDITHER2:
+ val = FitsCompressm<T>::getValue((int*)obuf+ll,zs,zz,blank);
+ break;
+ }
+ dest[id] = val;
+ }
+ break;
+ case 8:
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // swap if needed
+ if (FitsCompressm<T>::byteswap_) {
+ const char* p = (const char*)((long long*)obuf+ll);
+ union {
+ char c[8];
+ long long i;
+ } u;
+
+ u.c[7] = *p++;
+ u.c[6] = *p++;
+ u.c[5] = *p++;
+ u.c[4] = *p++;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ *((long long*)obuf+ll) = u.i;
+ }
+ // very carefull about type conversions
+ size_t id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ T val =0;
+ switch (FitsCompressm<T>::quantize_) {
+ case FitsCompress::NONE:
+ val = FitsCompressm<T>::getValue((double*)obuf+ll,zs,zz,blank);
+ break;
+ case FitsCompress::NODITHER:
+ case FitsCompress::SUBDITHER1:
+ case FitsCompress::SUBDITHER2:
+ val = FitsCompressm<T>::getValue((long long*)obuf+ll,zs,zz,blank);
+ break;
+ }
+ dest[id] = val;
+ }
+ break;
+
+ default:
+ internalError("Fitsy++ gzip illegal bytepix");
+ if (obuf)
+ delete [] obuf;
+ return 0;
+ }
+
+ if (obuf)
+ delete [] obuf;
+ return 1;
+}
+
+template class FitsGzipm<unsigned char>;
+template class FitsGzipm<short>;
+template class FitsGzipm<unsigned short>;
+template class FitsGzipm<int>;
+template class FitsGzipm<long long>;
+template class FitsGzipm<float>;
+template class FitsGzipm<double>;
+
diff --git a/fitsy++/gzip.h b/fitsy++/gzip.h
new file mode 100644
index 0000000..f6d2435
--- /dev/null
+++ b/fitsy++/gzip.h
@@ -0,0 +1,19 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsgzip_h__
+#define __fitsgzip_h__
+
+#include "compress.h"
+
+template<class T>
+class FitsGzipm : public FitsCompressm<T> {
+ private:
+ int compressed(T*, char*, char*, int, int, int, int, int, int);
+
+ public:
+ FitsGzipm(FitsFile*);
+};
+
+#endif
diff --git a/fitsy++/hcompress.C b/fitsy++/hcompress.C
new file mode 100644
index 0000000..577ec47
--- /dev/null
+++ b/fitsy++/hcompress.C
@@ -0,0 +1,119 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+// Note: currently, hcompress will not work with float or double data with
+// BLANK defined, due to the fact that the decompress code takes a int() and
+// not an unsigned int()
+
+#include "hcompress.h"
+#include "util.h"
+
+extern "C" {
+ int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx, int *scale, int *status);
+ int fits_hdecompress64(unsigned char *input, int smooth, long long *a, int *ny, int *nx, int *scale, int *status);
+}
+
+template<class T> FitsHcompressm<T>::FitsHcompressm(FitsFile* fits)
+ : FitsCompressm<T>(fits)
+{
+ // hcompress parameters
+ smooth_ = 0;
+ char name[] = "ZNAME ";
+ char val[] = "ZVAL ";
+ for (int ii=0; ii<9; ii++) {
+ name[5] = '0'+ii;
+ val[4] = '0'+ii;
+ if (fits->find(name)) {
+ char* str = fits->getString(name);
+ if (!strncmp(str,"SMOOTH",4))
+ smooth_ = fits->getInteger(val,4);
+ }
+ }
+
+ FitsCompressm<T>::uncompress(fits);
+}
+
+template <class T> int FitsHcompressm<T>::compressed(T* dest, char* sptr,
+ char* heap,
+ int kkstart, int kkstop,
+ int jjstart, int jjstop,
+ int iistart, int iistop)
+{
+ double zs = FitsCompressm<T>::bscale_;
+ if (FitsCompressm<T>::zscale_)
+ zs = FitsCompressm<T>::zscale_->value(sptr,0);
+
+ double zz = FitsCompressm<T>::bzero_;
+ if (FitsCompressm<T>::zzero_)
+ zz = FitsCompressm<T>::zzero_->value(sptr,0);
+
+ int blank = FitsCompressm<T>::blank_;
+ if (FitsCompressm<T>::zblank_)
+ blank = (int)FitsCompressm<T>::zblank_->value(sptr,0);
+
+ int icnt=0;
+ unsigned char* ibuf = (unsigned char*)((FitsBinColumnArray*)FitsCompressm<T>::compress_)->get(heap, sptr, &icnt);
+
+ // ibuf can be NULL
+ if (!ibuf || !icnt)
+ return 0;
+
+ int ocnt = FitsCompressm<T>::tilesize_;
+ int nx,ny,scale;
+ int status=0;
+ int ll=0;
+
+ switch (FitsCompressm<T>::bitpix_) {
+ case 8:
+ case 16:
+ {
+ int* obuf = new int[ocnt];
+ if (fits_hdecompress(ibuf, smooth_, obuf, &nx, &ny, &scale, &status)) {
+ internalError("Fitsy++ hcompress bad inflate result");
+ return 0;
+ }
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++)
+ dest[kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii] = FitsCompressm<T>::getValue(obuf+ll,zs,zz,blank);
+
+ if (obuf)
+ delete [] obuf;
+ }
+ break;
+ case 32:
+ case -32:
+ case -64:
+ {
+ long long* obuf = new long long[ocnt];
+ if (fits_hdecompress64(ibuf, smooth_, obuf, &nx, &ny, &scale, &status)) {
+ internalError("Fitsy++ hcompress bad inflate result");
+ return 0;
+ }
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++)
+ dest[kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii] = FitsCompressm<T>::getValue((int*)obuf+ll,zs,zz,blank);
+
+ if (obuf)
+ delete [] obuf;
+ }
+ break;
+ }
+
+ return 1;
+}
+
+template class FitsHcompressm<unsigned char>;
+template class FitsHcompressm<short>;
+template class FitsHcompressm<unsigned short>;
+template class FitsHcompressm<int>;
+template class FitsHcompressm<long long>;
+template class FitsHcompressm<float>;
+template class FitsHcompressm<double>;
diff --git a/fitsy++/hcompress.h b/fitsy++/hcompress.h
new file mode 100644
index 0000000..4b95aca
--- /dev/null
+++ b/fitsy++/hcompress.h
@@ -0,0 +1,22 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitshcompress_h__
+#define __fitshcompress_h__
+
+#include "compress.h"
+
+template<class T>
+class FitsHcompressm : public FitsCompressm<T> {
+ protected:
+ int smooth_;
+
+ private:
+ int compressed(T*, char*, char*, int, int, int, int, int, int);
+
+ public:
+ FitsHcompressm(FitsFile*);
+};
+
+#endif
diff --git a/fitsy++/hdecompress.c b/fitsy++/hdecompress.c
new file mode 100644
index 0000000..06d1c7a
--- /dev/null
+++ b/fitsy++/hdecompress.c
@@ -0,0 +1,2619 @@
+/* #########################################################################
+These routines to apply the H-compress decompression algorithm to a 2-D Fits
+image were written by R. White at the STScI and were obtained from the STScI at
+http://www.stsci.edu/software/hcompress.html
+
+This source file is a concatination of the following sources files in the
+original distribution
+ hinv.c
+ hsmooth.c
+ undigitize.c
+ decode.c
+ dodecode.c
+ qtree_decode.c
+ qread.c
+ bit_input.c
+
+
+The following modifications have been made to the original code:
+
+ - commented out redundant "include" statements
+ - added the nextchar global variable
+ - changed all the 'extern' declarations to 'static', since all the routines are in
+ the same source file
+ - changed the first parameter in decode (and in lower level routines from a file stream
+ to a char array
+ - modified the myread routine, and lower level byte reading routines, to copy
+ the input bytes to a char array, instead of reading them from a file stream
+ - changed the function declarations to the more modern ANSI C style
+ - changed calls to printf and perror to call the CFITSIO ffpmsg routine
+ - replace "exit" statements with "return" statements
+
+ ############################################################################ */
+
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+/*#include "fitsio2.h"*/
+#define LONGLONG long long
+#define DATA_DECOMPRESSION_ERR 0
+
+static void ffpmsg(const char* str) {}
+
+/* WDP added test to see if min and max are already defined */
+#ifndef min
+#define min(a,b) (((a)<(b))?(a):(b))
+#endif
+#ifndef max
+#define max(a,b) (((a)>(b))?(a):(b))
+#endif
+
+static long nextchar;
+
+static int decode(unsigned char *infile, int *a, int *nx, int *ny, int *scale);
+static int decode64(unsigned char *infile, LONGLONG *a, int *nx, int *ny, int *scale);
+static int hinv(int a[], int nx, int ny, int smooth ,int scale);
+static int hinv64(LONGLONG a[], int nx, int ny, int smooth ,int scale);
+static void undigitize(int a[], int nx, int ny, int scale);
+static void undigitize64(LONGLONG a[], int nx, int ny, int scale);
+static void unshuffle(int a[], int n, int n2, int tmp[]);
+static void unshuffle64(LONGLONG a[], int n, int n2, LONGLONG tmp[]);
+static void hsmooth(int a[], int nxtop, int nytop, int ny, int scale);
+static void hsmooth64(LONGLONG a[], int nxtop, int nytop, int ny, int scale);
+static void qread(unsigned char *infile,char *a, int n);
+static int readint(unsigned char *infile);
+static LONGLONG readlonglong(unsigned char *infile);
+static int dodecode(unsigned char *infile, int a[], int nx, int ny, unsigned char nbitplanes[3]);
+static int dodecode64(unsigned char *infile, LONGLONG a[], int nx, int ny, unsigned char nbitplanes[3]);
+static int qtree_decode(unsigned char *infile, int a[], int n, int nqx, int nqy, int nbitplanes);
+static int qtree_decode64(unsigned char *infile, LONGLONG a[], int n, int nqx, int nqy, int nbitplanes);
+static void start_inputing_bits();
+static int input_bit(unsigned char *infile);
+static int input_nbits(unsigned char *infile, int n);
+/* make input_nybble a separate routine, for added effiency */
+/* #define input_nybble(infile) input_nbits(infile,4) */
+static int input_nybble(unsigned char *infile);
+static int input_nnybble(unsigned char *infile, int n, unsigned char *array);
+
+static void qtree_expand(unsigned char *infile, unsigned char a[], int nx, int ny, unsigned char b[]);
+static void qtree_bitins(unsigned char a[], int nx, int ny, int b[], int n, int bit);
+static void qtree_bitins64(unsigned char a[], int nx, int ny, LONGLONG b[], int n, int bit);
+static void qtree_copy(unsigned char a[], int nx, int ny, unsigned char b[], int n);
+static void read_bdirect(unsigned char *infile, int a[], int n, int nqx, int nqy, unsigned char scratch[], int bit);
+static void read_bdirect64(unsigned char *infile, LONGLONG a[], int n, int nqx, int nqy, unsigned char scratch[], int bit);
+static int input_huffman(unsigned char *infile);
+
+/* ---------------------------------------------------------------------- */
+int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx,
+ int *scale, int *status)
+{
+ /*
+ decompress the input byte stream using the H-compress algorithm
+
+ input - input array of compressed bytes
+ a - pre-allocated array to hold the output uncompressed image
+ nx - returned X axis size
+ ny - returned Y axis size
+
+ NOTE: the nx and ny dimensions as defined within this code are reversed from
+ the usual FITS notation. ny is the fastest varying dimension, which is
+ usually considered the X axis in the FITS image display
+
+ */
+int stat;
+
+ if (*status > 0) return(*status);
+
+ /* decode the input array */
+
+ stat = decode(input, a, nx, ny, scale);
+ *status = stat;
+ if (stat) return(*status);
+
+ /*
+ * Un-Digitize
+ */
+ undigitize(a, *nx, *ny, *scale);
+
+ /*
+ * Inverse H-transform
+ */
+ stat = hinv(a, *nx, *ny, smooth, *scale);
+ *status = stat;
+
+ return(*status);
+}
+/* ---------------------------------------------------------------------- */
+int fits_hdecompress64(unsigned char *input, int smooth, LONGLONG *a, int *ny, int *nx,
+ int *scale, int *status)
+{
+ /*
+ decompress the input byte stream using the H-compress algorithm
+
+ input - input array of compressed bytes
+ a - pre-allocated array to hold the output uncompressed image
+ nx - returned X axis size
+ ny - returned Y axis size
+
+ NOTE: the nx and ny dimensions as defined within this code are reversed from
+ the usual FITS notation. ny is the fastest varying dimension, which is
+ usually considered the X axis in the FITS image display
+
+ */
+ int stat, *iarray, ii, nval;
+
+ if (*status > 0) return(*status);
+
+ /* decode the input array */
+
+ stat = decode64(input, a, nx, ny, scale);
+ *status = stat;
+ if (stat) return(*status);
+
+ /*
+ * Un-Digitize
+ */
+ undigitize64(a, *nx, *ny, *scale);
+
+ /*
+ * Inverse H-transform
+ */
+ stat = hinv64(a, *nx, *ny, smooth, *scale);
+
+ *status = stat;
+
+ /* pack the I*8 values back into an I*4 array */
+ iarray = (int *) a;
+ nval = (*nx) * (*ny);
+
+ for (ii = 0; ii < nval; ii++)
+ iarray[ii] = (int) a[ii];
+
+ return(*status);
+}
+
+/* ############################################################################ */
+/* ############################################################################ */
+
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* hinv.c Inverse H-transform of NX x NY integer image
+ *
+ * Programmer: R. White Date: 23 July 1993
+ */
+
+/* ############################################################################ */
+static int
+hinv(int a[], int nx, int ny, int smooth ,int scale)
+/*
+int smooth; 0 for no smoothing, else smooth during inversion
+int scale; used if smoothing is specified
+*/
+{
+int nmax, log2n, i, j, k;
+int nxtop,nytop,nxf,nyf,c;
+int oddx,oddy;
+int shift, bit0, bit1, bit2, mask0, mask1, mask2,
+ prnd0, prnd1, prnd2, nrnd0, nrnd1, nrnd2, lowbit0, lowbit1;
+int h0, hx, hy, hc;
+int s10, s00;
+int *tmp;
+
+ /*
+ * log2n is log2 of max(nx,ny) rounded up to next power of 2
+ */
+ nmax = (nx>ny) ? nx : ny;
+ log2n = (int) (log((float) nmax)/log(2.0)+0.5);
+ if ( nmax > (1<<log2n) ) {
+ log2n += 1;
+ }
+ /*
+ * get temporary storage for shuffling elements
+ */
+ tmp = (int *) malloc(((nmax+1)/2)*sizeof(int));
+ if (tmp == (int *) NULL) {
+ ffpmsg("hinv: insufficient memory");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ /*
+ * set up masks, rounding parameters
+ */
+ shift = 1;
+ bit0 = 1 << (log2n - 1);
+ bit1 = bit0 << 1;
+ bit2 = bit0 << 2;
+ mask0 = -bit0;
+ mask1 = mask0 << 1;
+ mask2 = mask0 << 2;
+ prnd0 = bit0 >> 1;
+ prnd1 = bit1 >> 1;
+ prnd2 = bit2 >> 1;
+ nrnd0 = prnd0 - 1;
+ nrnd1 = prnd1 - 1;
+ nrnd2 = prnd2 - 1;
+ /*
+ * round h0 to multiple of bit2
+ */
+ a[0] = (a[0] + ((a[0] >= 0) ? prnd2 : nrnd2)) & mask2;
+ /*
+ * do log2n expansions
+ *
+ * We're indexing a as a 2-D array with dimensions (nx,ny).
+ */
+ nxtop = 1;
+ nytop = 1;
+ nxf = nx;
+ nyf = ny;
+ c = 1<<log2n;
+ for (k = log2n-1; k>=0; k--) {
+ /*
+ * this somewhat cryptic code generates the sequence
+ * ntop[k-1] = (ntop[k]+1)/2, where ntop[log2n] = n
+ */
+ c = c>>1;
+ nxtop = nxtop<<1;
+ nytop = nytop<<1;
+ if (nxf <= c) { nxtop -= 1; } else { nxf -= c; }
+ if (nyf <= c) { nytop -= 1; } else { nyf -= c; }
+ /*
+ * double shift and fix nrnd0 (because prnd0=0) on last pass
+ */
+ if (k == 0) {
+ nrnd0 = 0;
+ shift = 2;
+ }
+ /*
+ * unshuffle in each dimension to interleave coefficients
+ */
+ for (i = 0; i<nxtop; i++) {
+ unshuffle(&a[ny*i],nytop,1,tmp);
+ }
+ for (j = 0; j<nytop; j++) {
+ unshuffle(&a[j],nxtop,ny,tmp);
+ }
+ /*
+ * smooth by interpolating coefficients if SMOOTH != 0
+ */
+ if (smooth) hsmooth(a,nxtop,nytop,ny,scale);
+ oddx = nxtop % 2;
+ oddy = nytop % 2;
+ for (i = 0; i<nxtop-oddx; i += 2) {
+ s00 = ny*i; /* s00 is index of a[i,j] */
+ s10 = s00+ny; /* s10 is index of a[i+1,j] */
+ for (j = 0; j<nytop-oddy; j += 2) {
+ h0 = a[s00 ];
+ hx = a[s10 ];
+ hy = a[s00+1];
+ hc = a[s10+1];
+ /*
+ * round hx and hy to multiple of bit1, hc to multiple of bit0
+ * h0 is already a multiple of bit2
+ */
+ hx = (hx + ((hx >= 0) ? prnd1 : nrnd1)) & mask1;
+ hy = (hy + ((hy >= 0) ? prnd1 : nrnd1)) & mask1;
+ hc = (hc + ((hc >= 0) ? prnd0 : nrnd0)) & mask0;
+ /*
+ * propagate bit0 of hc to hx,hy
+ */
+ lowbit0 = hc & bit0;
+ hx = (hx >= 0) ? (hx - lowbit0) : (hx + lowbit0);
+ hy = (hy >= 0) ? (hy - lowbit0) : (hy + lowbit0);
+ /*
+ * Propagate bits 0 and 1 of hc,hx,hy to h0.
+ * This could be simplified if we assume h0>0, but then
+ * the inversion would not be lossless for images with
+ * negative pixels.
+ */
+ lowbit1 = (hc ^ hx ^ hy) & bit1;
+ h0 = (h0 >= 0)
+ ? (h0 + lowbit0 - lowbit1)
+ : (h0 + ((lowbit0 == 0) ? lowbit1 : (lowbit0-lowbit1)));
+ /*
+ * Divide sums by 2 (4 last time)
+ */
+ a[s10+1] = (h0 + hx + hy + hc) >> shift;
+ a[s10 ] = (h0 + hx - hy - hc) >> shift;
+ a[s00+1] = (h0 - hx + hy - hc) >> shift;
+ a[s00 ] = (h0 - hx - hy + hc) >> shift;
+ s00 += 2;
+ s10 += 2;
+ }
+ if (oddy) {
+ /*
+ * do last element in row if row length is odd
+ * s00+1, s10+1 are off edge
+ */
+ h0 = a[s00 ];
+ hx = a[s10 ];
+ hx = ((hx >= 0) ? (hx+prnd1) : (hx+nrnd1)) & mask1;
+ lowbit1 = hx & bit1;
+ h0 = (h0 >= 0) ? (h0 - lowbit1) : (h0 + lowbit1);
+ a[s10 ] = (h0 + hx) >> shift;
+ a[s00 ] = (h0 - hx) >> shift;
+ }
+ }
+ if (oddx) {
+ /*
+ * do last row if column length is odd
+ * s10, s10+1 are off edge
+ */
+ s00 = ny*i;
+ for (j = 0; j<nytop-oddy; j += 2) {
+ h0 = a[s00 ];
+ hy = a[s00+1];
+ hy = ((hy >= 0) ? (hy+prnd1) : (hy+nrnd1)) & mask1;
+ lowbit1 = hy & bit1;
+ h0 = (h0 >= 0) ? (h0 - lowbit1) : (h0 + lowbit1);
+ a[s00+1] = (h0 + hy) >> shift;
+ a[s00 ] = (h0 - hy) >> shift;
+ s00 += 2;
+ }
+ if (oddy) {
+ /*
+ * do corner element if both row and column lengths are odd
+ * s00+1, s10, s10+1 are off edge
+ */
+ h0 = a[s00 ];
+ a[s00 ] = h0 >> shift;
+ }
+ }
+ /*
+ * divide all the masks and rounding values by 2
+ */
+ bit2 = bit1;
+ bit1 = bit0;
+ bit0 = bit0 >> 1;
+ mask1 = mask0;
+ mask0 = mask0 >> 1;
+ prnd1 = prnd0;
+ prnd0 = prnd0 >> 1;
+ nrnd1 = nrnd0;
+ nrnd0 = prnd0 - 1;
+ }
+ free(tmp);
+ return(0);
+}
+/* ############################################################################ */
+static int
+hinv64(LONGLONG a[], int nx, int ny, int smooth ,int scale)
+/*
+int smooth; 0 for no smoothing, else smooth during inversion
+int scale; used if smoothing is specified
+*/
+{
+int nmax, log2n, i, j, k;
+int nxtop,nytop,nxf,nyf,c;
+int oddx,oddy;
+int shift;
+LONGLONG mask0, mask1, mask2, prnd0, prnd1, prnd2, bit0, bit1, bit2;
+LONGLONG nrnd0, nrnd1, nrnd2, lowbit0, lowbit1;
+LONGLONG h0, hx, hy, hc;
+int s10, s00;
+LONGLONG *tmp;
+
+ /*
+ * log2n is log2 of max(nx,ny) rounded up to next power of 2
+ */
+ nmax = (nx>ny) ? nx : ny;
+ log2n = (int) (log((float) nmax)/log(2.0)+0.5);
+ if ( nmax > (1<<log2n) ) {
+ log2n += 1;
+ }
+ /*
+ * get temporary storage for shuffling elements
+ */
+ tmp = (LONGLONG *) malloc(((nmax+1)/2)*sizeof(LONGLONG));
+ if (tmp == (LONGLONG *) NULL) {
+ ffpmsg("hinv64: insufficient memory");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ /*
+ * set up masks, rounding parameters
+ */
+ shift = 1;
+ bit0 = ((LONGLONG) 1) << (log2n - 1);
+ bit1 = bit0 << 1;
+ bit2 = bit0 << 2;
+ mask0 = -bit0;
+ mask1 = mask0 << 1;
+ mask2 = mask0 << 2;
+ prnd0 = bit0 >> 1;
+ prnd1 = bit1 >> 1;
+ prnd2 = bit2 >> 1;
+ nrnd0 = prnd0 - 1;
+ nrnd1 = prnd1 - 1;
+ nrnd2 = prnd2 - 1;
+ /*
+ * round h0 to multiple of bit2
+ */
+ a[0] = (a[0] + ((a[0] >= 0) ? prnd2 : nrnd2)) & mask2;
+ /*
+ * do log2n expansions
+ *
+ * We're indexing a as a 2-D array with dimensions (nx,ny).
+ */
+ nxtop = 1;
+ nytop = 1;
+ nxf = nx;
+ nyf = ny;
+ c = 1<<log2n;
+ for (k = log2n-1; k>=0; k--) {
+ /*
+ * this somewhat cryptic code generates the sequence
+ * ntop[k-1] = (ntop[k]+1)/2, where ntop[log2n] = n
+ */
+ c = c>>1;
+ nxtop = nxtop<<1;
+ nytop = nytop<<1;
+ if (nxf <= c) { nxtop -= 1; } else { nxf -= c; }
+ if (nyf <= c) { nytop -= 1; } else { nyf -= c; }
+ /*
+ * double shift and fix nrnd0 (because prnd0=0) on last pass
+ */
+ if (k == 0) {
+ nrnd0 = 0;
+ shift = 2;
+ }
+ /*
+ * unshuffle in each dimension to interleave coefficients
+ */
+ for (i = 0; i<nxtop; i++) {
+ unshuffle64(&a[ny*i],nytop,1,tmp);
+ }
+ for (j = 0; j<nytop; j++) {
+ unshuffle64(&a[j],nxtop,ny,tmp);
+ }
+ /*
+ * smooth by interpolating coefficients if SMOOTH != 0
+ */
+ if (smooth) hsmooth64(a,nxtop,nytop,ny,scale);
+ oddx = nxtop % 2;
+ oddy = nytop % 2;
+ for (i = 0; i<nxtop-oddx; i += 2) {
+ s00 = ny*i; /* s00 is index of a[i,j] */
+ s10 = s00+ny; /* s10 is index of a[i+1,j] */
+ for (j = 0; j<nytop-oddy; j += 2) {
+ h0 = a[s00 ];
+ hx = a[s10 ];
+ hy = a[s00+1];
+ hc = a[s10+1];
+ /*
+ * round hx and hy to multiple of bit1, hc to multiple of bit0
+ * h0 is already a multiple of bit2
+ */
+ hx = (hx + ((hx >= 0) ? prnd1 : nrnd1)) & mask1;
+ hy = (hy + ((hy >= 0) ? prnd1 : nrnd1)) & mask1;
+ hc = (hc + ((hc >= 0) ? prnd0 : nrnd0)) & mask0;
+ /*
+ * propagate bit0 of hc to hx,hy
+ */
+ lowbit0 = hc & bit0;
+ hx = (hx >= 0) ? (hx - lowbit0) : (hx + lowbit0);
+ hy = (hy >= 0) ? (hy - lowbit0) : (hy + lowbit0);
+ /*
+ * Propagate bits 0 and 1 of hc,hx,hy to h0.
+ * This could be simplified if we assume h0>0, but then
+ * the inversion would not be lossless for images with
+ * negative pixels.
+ */
+ lowbit1 = (hc ^ hx ^ hy) & bit1;
+ h0 = (h0 >= 0)
+ ? (h0 + lowbit0 - lowbit1)
+ : (h0 + ((lowbit0 == 0) ? lowbit1 : (lowbit0-lowbit1)));
+ /*
+ * Divide sums by 2 (4 last time)
+ */
+ a[s10+1] = (h0 + hx + hy + hc) >> shift;
+ a[s10 ] = (h0 + hx - hy - hc) >> shift;
+ a[s00+1] = (h0 - hx + hy - hc) >> shift;
+ a[s00 ] = (h0 - hx - hy + hc) >> shift;
+ s00 += 2;
+ s10 += 2;
+ }
+ if (oddy) {
+ /*
+ * do last element in row if row length is odd
+ * s00+1, s10+1 are off edge
+ */
+ h0 = a[s00 ];
+ hx = a[s10 ];
+ hx = ((hx >= 0) ? (hx+prnd1) : (hx+nrnd1)) & mask1;
+ lowbit1 = hx & bit1;
+ h0 = (h0 >= 0) ? (h0 - lowbit1) : (h0 + lowbit1);
+ a[s10 ] = (h0 + hx) >> shift;
+ a[s00 ] = (h0 - hx) >> shift;
+ }
+ }
+ if (oddx) {
+ /*
+ * do last row if column length is odd
+ * s10, s10+1 are off edge
+ */
+ s00 = ny*i;
+ for (j = 0; j<nytop-oddy; j += 2) {
+ h0 = a[s00 ];
+ hy = a[s00+1];
+ hy = ((hy >= 0) ? (hy+prnd1) : (hy+nrnd1)) & mask1;
+ lowbit1 = hy & bit1;
+ h0 = (h0 >= 0) ? (h0 - lowbit1) : (h0 + lowbit1);
+ a[s00+1] = (h0 + hy) >> shift;
+ a[s00 ] = (h0 - hy) >> shift;
+ s00 += 2;
+ }
+ if (oddy) {
+ /*
+ * do corner element if both row and column lengths are odd
+ * s00+1, s10, s10+1 are off edge
+ */
+ h0 = a[s00 ];
+ a[s00 ] = h0 >> shift;
+ }
+ }
+ /*
+ * divide all the masks and rounding values by 2
+ */
+ bit2 = bit1;
+ bit1 = bit0;
+ bit0 = bit0 >> 1;
+ mask1 = mask0;
+ mask0 = mask0 >> 1;
+ prnd1 = prnd0;
+ prnd0 = prnd0 >> 1;
+ nrnd1 = nrnd0;
+ nrnd0 = prnd0 - 1;
+ }
+ free(tmp);
+ return(0);
+}
+
+/* ############################################################################ */
+static void
+unshuffle(int a[], int n, int n2, int tmp[])
+/*
+int a[]; array to shuffle
+int n; number of elements to shuffle
+int n2; second dimension
+int tmp[]; scratch storage
+*/
+{
+int i;
+int nhalf;
+int *p1, *p2, *pt;
+
+ /*
+ * copy 2nd half of array to tmp
+ */
+ nhalf = (n+1)>>1;
+ pt = tmp;
+ p1 = &a[n2*nhalf]; /* pointer to a[i] */
+ for (i=nhalf; i<n; i++) {
+ *pt = *p1;
+ p1 += n2;
+ pt += 1;
+ }
+ /*
+ * distribute 1st half of array to even elements
+ */
+ p2 = &a[ n2*(nhalf-1) ]; /* pointer to a[i] */
+ p1 = &a[(n2*(nhalf-1))<<1]; /* pointer to a[2*i] */
+ for (i=nhalf-1; i >= 0; i--) {
+ *p1 = *p2;
+ p2 -= n2;
+ p1 -= (n2+n2);
+ }
+ /*
+ * now distribute 2nd half of array (in tmp) to odd elements
+ */
+ pt = tmp;
+ p1 = &a[n2]; /* pointer to a[i] */
+ for (i=1; i<n; i += 2) {
+ *p1 = *pt;
+ p1 += (n2+n2);
+ pt += 1;
+ }
+}
+/* ############################################################################ */
+static void
+unshuffle64(LONGLONG a[], int n, int n2, LONGLONG tmp[])
+/*
+LONGLONG a[]; array to shuffle
+int n; number of elements to shuffle
+int n2; second dimension
+LONGLONG tmp[]; scratch storage
+*/
+{
+int i;
+int nhalf;
+LONGLONG *p1, *p2, *pt;
+
+ /*
+ * copy 2nd half of array to tmp
+ */
+ nhalf = (n+1)>>1;
+ pt = tmp;
+ p1 = &a[n2*nhalf]; /* pointer to a[i] */
+ for (i=nhalf; i<n; i++) {
+ *pt = *p1;
+ p1 += n2;
+ pt += 1;
+ }
+ /*
+ * distribute 1st half of array to even elements
+ */
+ p2 = &a[ n2*(nhalf-1) ]; /* pointer to a[i] */
+ p1 = &a[(n2*(nhalf-1))<<1]; /* pointer to a[2*i] */
+ for (i=nhalf-1; i >= 0; i--) {
+ *p1 = *p2;
+ p2 -= n2;
+ p1 -= (n2+n2);
+ }
+ /*
+ * now distribute 2nd half of array (in tmp) to odd elements
+ */
+ pt = tmp;
+ p1 = &a[n2]; /* pointer to a[i] */
+ for (i=1; i<n; i += 2) {
+ *p1 = *pt;
+ p1 += (n2+n2);
+ pt += 1;
+ }
+}
+
+/* ############################################################################ */
+/* ############################################################################ */
+
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* hsmooth.c Smooth H-transform image by adjusting coefficients toward
+ * interpolated values
+ *
+ * Programmer: R. White Date: 13 April 1992
+ */
+
+/* ############################################################################ */
+static void
+hsmooth(int a[], int nxtop, int nytop, int ny, int scale)
+/*
+int a[]; array of H-transform coefficients
+int nxtop,nytop; size of coefficient block to use
+int ny; actual 1st dimension of array
+int scale; truncation scale factor that was used
+*/
+{
+int i, j;
+int ny2, s10, s00, diff, dmax, dmin, s, smax;
+int hm, h0, hp, hmm, hpm, hmp, hpp, hx2, hy2;
+int m1,m2;
+
+ /*
+ * Maximum change in coefficients is determined by scale factor.
+ * Since we rounded during division (see digitize.c), the biggest
+ * permitted change is scale/2.
+ */
+ smax = (scale >> 1);
+ if (smax <= 0) return;
+ ny2 = ny << 1;
+ /*
+ * We're indexing a as a 2-D array with dimensions (nxtop,ny) of which
+ * only (nxtop,nytop) are used. The coefficients on the edge of the
+ * array are not adjusted (which is why the loops below start at 2
+ * instead of 0 and end at nxtop-2 instead of nxtop.)
+ */
+ /*
+ * Adjust x difference hx
+ */
+ for (i = 2; i<nxtop-2; i += 2) {
+ s00 = ny*i; /* s00 is index of a[i,j] */
+ s10 = s00+ny; /* s10 is index of a[i+1,j] */
+ for (j = 0; j<nytop; j += 2) {
+ /*
+ * hp is h0 (mean value) in next x zone, hm is h0 in previous x zone
+ */
+ hm = a[s00-ny2];
+ h0 = a[s00];
+ hp = a[s00+ny2];
+ /*
+ * diff = 8 * hx slope that would match h0 in neighboring zones
+ */
+ diff = hp-hm;
+ /*
+ * monotonicity constraints on diff
+ */
+ dmax = max( min( (hp-h0), (h0-hm) ), 0 ) << 2;
+ dmin = min( max( (hp-h0), (h0-hm) ), 0 ) << 2;
+ /*
+ * if monotonicity would set slope = 0 then don't change hx.
+ * note dmax>=0, dmin<=0.
+ */
+ if (dmin < dmax) {
+ diff = max( min(diff, dmax), dmin);
+ /*
+ * Compute change in slope limited to range +/- smax.
+ * Careful with rounding negative numbers when using
+ * shift for divide by 8.
+ */
+ s = diff-(a[s10]<<3);
+ s = (s>=0) ? (s>>3) : ((s+7)>>3) ;
+ s = max( min(s, smax), -smax);
+ a[s10] = a[s10]+s;
+ }
+ s00 += 2;
+ s10 += 2;
+ }
+ }
+ /*
+ * Adjust y difference hy
+ */
+ for (i = 0; i<nxtop; i += 2) {
+ s00 = ny*i+2;
+ s10 = s00+ny;
+ for (j = 2; j<nytop-2; j += 2) {
+ hm = a[s00-2];
+ h0 = a[s00];
+ hp = a[s00+2];
+ diff = hp-hm;
+ dmax = max( min( (hp-h0), (h0-hm) ), 0 ) << 2;
+ dmin = min( max( (hp-h0), (h0-hm) ), 0 ) << 2;
+ if (dmin < dmax) {
+ diff = max( min(diff, dmax), dmin);
+ s = diff-(a[s00+1]<<3);
+ s = (s>=0) ? (s>>3) : ((s+7)>>3) ;
+ s = max( min(s, smax), -smax);
+ a[s00+1] = a[s00+1]+s;
+ }
+ s00 += 2;
+ s10 += 2;
+ }
+ }
+ /*
+ * Adjust curvature difference hc
+ */
+ for (i = 2; i<nxtop-2; i += 2) {
+ s00 = ny*i+2;
+ s10 = s00+ny;
+ for (j = 2; j<nytop-2; j += 2) {
+ /*
+ * ------------------ y
+ * | hmp | | hpp | |
+ * ------------------ |
+ * | | h0 | | |
+ * ------------------ -------x
+ * | hmm | | hpm |
+ * ------------------
+ */
+ hmm = a[s00-ny2-2];
+ hpm = a[s00+ny2-2];
+ hmp = a[s00-ny2+2];
+ hpp = a[s00+ny2+2];
+ h0 = a[s00];
+ /*
+ * diff = 64 * hc value that would match h0 in neighboring zones
+ */
+ diff = hpp + hmm - hmp - hpm;
+ /*
+ * 2 times x,y slopes in this zone
+ */
+ hx2 = a[s10 ]<<1;
+ hy2 = a[s00+1]<<1;
+ /*
+ * monotonicity constraints on diff
+ */
+ m1 = min(max(hpp-h0,0)-hx2-hy2, max(h0-hpm,0)+hx2-hy2);
+ m2 = min(max(h0-hmp,0)-hx2+hy2, max(hmm-h0,0)+hx2+hy2);
+ dmax = min(m1,m2) << 4;
+ m1 = max(min(hpp-h0,0)-hx2-hy2, min(h0-hpm,0)+hx2-hy2);
+ m2 = max(min(h0-hmp,0)-hx2+hy2, min(hmm-h0,0)+hx2+hy2);
+ dmin = max(m1,m2) << 4;
+ /*
+ * if monotonicity would set slope = 0 then don't change hc.
+ * note dmax>=0, dmin<=0.
+ */
+ if (dmin < dmax) {
+ diff = max( min(diff, dmax), dmin);
+ /*
+ * Compute change in slope limited to range +/- smax.
+ * Careful with rounding negative numbers when using
+ * shift for divide by 64.
+ */
+ s = diff-(a[s10+1]<<6);
+ s = (s>=0) ? (s>>6) : ((s+63)>>6) ;
+ s = max( min(s, smax), -smax);
+ a[s10+1] = a[s10+1]+s;
+ }
+ s00 += 2;
+ s10 += 2;
+ }
+ }
+}
+/* ############################################################################ */
+static void
+hsmooth64(LONGLONG a[], int nxtop, int nytop, int ny, int scale)
+/*
+LONGLONG a[]; array of H-transform coefficients
+int nxtop,nytop; size of coefficient block to use
+int ny; actual 1st dimension of array
+int scale; truncation scale factor that was used
+*/
+{
+int i, j;
+int ny2, s10, s00;
+LONGLONG hm, h0, hp, hmm, hpm, hmp, hpp, hx2, hy2, diff, dmax, dmin, s, smax, m1, m2;
+
+ /*
+ * Maximum change in coefficients is determined by scale factor.
+ * Since we rounded during division (see digitize.c), the biggest
+ * permitted change is scale/2.
+ */
+ smax = (scale >> 1);
+ if (smax <= 0) return;
+ ny2 = ny << 1;
+ /*
+ * We're indexing a as a 2-D array with dimensions (nxtop,ny) of which
+ * only (nxtop,nytop) are used. The coefficients on the edge of the
+ * array are not adjusted (which is why the loops below start at 2
+ * instead of 0 and end at nxtop-2 instead of nxtop.)
+ */
+ /*
+ * Adjust x difference hx
+ */
+ for (i = 2; i<nxtop-2; i += 2) {
+ s00 = ny*i; /* s00 is index of a[i,j] */
+ s10 = s00+ny; /* s10 is index of a[i+1,j] */
+ for (j = 0; j<nytop; j += 2) {
+ /*
+ * hp is h0 (mean value) in next x zone, hm is h0 in previous x zone
+ */
+ hm = a[s00-ny2];
+ h0 = a[s00];
+ hp = a[s00+ny2];
+ /*
+ * diff = 8 * hx slope that would match h0 in neighboring zones
+ */
+ diff = hp-hm;
+ /*
+ * monotonicity constraints on diff
+ */
+ dmax = max( min( (hp-h0), (h0-hm) ), 0 ) << 2;
+ dmin = min( max( (hp-h0), (h0-hm) ), 0 ) << 2;
+ /*
+ * if monotonicity would set slope = 0 then don't change hx.
+ * note dmax>=0, dmin<=0.
+ */
+ if (dmin < dmax) {
+ diff = max( min(diff, dmax), dmin);
+ /*
+ * Compute change in slope limited to range +/- smax.
+ * Careful with rounding negative numbers when using
+ * shift for divide by 8.
+ */
+ s = diff-(a[s10]<<3);
+ s = (s>=0) ? (s>>3) : ((s+7)>>3) ;
+ s = max( min(s, smax), -smax);
+ a[s10] = a[s10]+s;
+ }
+ s00 += 2;
+ s10 += 2;
+ }
+ }
+ /*
+ * Adjust y difference hy
+ */
+ for (i = 0; i<nxtop; i += 2) {
+ s00 = ny*i+2;
+ s10 = s00+ny;
+ for (j = 2; j<nytop-2; j += 2) {
+ hm = a[s00-2];
+ h0 = a[s00];
+ hp = a[s00+2];
+ diff = hp-hm;
+ dmax = max( min( (hp-h0), (h0-hm) ), 0 ) << 2;
+ dmin = min( max( (hp-h0), (h0-hm) ), 0 ) << 2;
+ if (dmin < dmax) {
+ diff = max( min(diff, dmax), dmin);
+ s = diff-(a[s00+1]<<3);
+ s = (s>=0) ? (s>>3) : ((s+7)>>3) ;
+ s = max( min(s, smax), -smax);
+ a[s00+1] = a[s00+1]+s;
+ }
+ s00 += 2;
+ s10 += 2;
+ }
+ }
+ /*
+ * Adjust curvature difference hc
+ */
+ for (i = 2; i<nxtop-2; i += 2) {
+ s00 = ny*i+2;
+ s10 = s00+ny;
+ for (j = 2; j<nytop-2; j += 2) {
+ /*
+ * ------------------ y
+ * | hmp | | hpp | |
+ * ------------------ |
+ * | | h0 | | |
+ * ------------------ -------x
+ * | hmm | | hpm |
+ * ------------------
+ */
+ hmm = a[s00-ny2-2];
+ hpm = a[s00+ny2-2];
+ hmp = a[s00-ny2+2];
+ hpp = a[s00+ny2+2];
+ h0 = a[s00];
+ /*
+ * diff = 64 * hc value that would match h0 in neighboring zones
+ */
+ diff = hpp + hmm - hmp - hpm;
+ /*
+ * 2 times x,y slopes in this zone
+ */
+ hx2 = a[s10 ]<<1;
+ hy2 = a[s00+1]<<1;
+ /*
+ * monotonicity constraints on diff
+ */
+ m1 = min(max(hpp-h0,0)-hx2-hy2, max(h0-hpm,0)+hx2-hy2);
+ m2 = min(max(h0-hmp,0)-hx2+hy2, max(hmm-h0,0)+hx2+hy2);
+ dmax = min(m1,m2) << 4;
+ m1 = max(min(hpp-h0,0)-hx2-hy2, min(h0-hpm,0)+hx2-hy2);
+ m2 = max(min(h0-hmp,0)-hx2+hy2, min(hmm-h0,0)+hx2+hy2);
+ dmin = max(m1,m2) << 4;
+ /*
+ * if monotonicity would set slope = 0 then don't change hc.
+ * note dmax>=0, dmin<=0.
+ */
+ if (dmin < dmax) {
+ diff = max( min(diff, dmax), dmin);
+ /*
+ * Compute change in slope limited to range +/- smax.
+ * Careful with rounding negative numbers when using
+ * shift for divide by 64.
+ */
+ s = diff-(a[s10+1]<<6);
+ s = (s>=0) ? (s>>6) : ((s+63)>>6) ;
+ s = max( min(s, smax), -smax);
+ a[s10+1] = a[s10+1]+s;
+ }
+ s00 += 2;
+ s10 += 2;
+ }
+ }
+}
+
+
+/* ############################################################################ */
+/* ############################################################################ */
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* undigitize.c undigitize H-transform
+ *
+ * Programmer: R. White Date: 9 May 1991
+ */
+
+/* ############################################################################ */
+static void
+undigitize(int a[], int nx, int ny, int scale)
+{
+int *p;
+
+ /*
+ * multiply by scale
+ */
+ if (scale <= 1) return;
+ for (p=a; p <= &a[nx*ny-1]; p++) *p = (*p)*scale;
+}
+/* ############################################################################ */
+static void
+undigitize64(LONGLONG a[], int nx, int ny, int scale)
+{
+LONGLONG *p, scale64;
+
+ /*
+ * multiply by scale
+ */
+ if (scale <= 1) return;
+ scale64 = (LONGLONG) scale; /* use a 64-bit int for efficiency in the big loop */
+
+ for (p=a; p <= &a[nx*ny-1]; p++) *p = (*p)*scale64;
+}
+
+/* ############################################################################ */
+/* ############################################################################ */
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* decode.c read codes from infile and construct array
+ *
+ * Programmer: R. White Date: 2 February 1994
+ */
+
+
+static char code_magic[2] = { (char)0xDD, (char)0x99 };
+
+/* ############################################################################ */
+static int decode(unsigned char *infile, int *a, int *nx, int *ny, int *scale)
+/*
+char *infile; input file
+int *a; address of output array [nx][ny]
+int *nx,*ny; size of output array
+int *scale; scale factor for digitization
+*/
+{
+LONGLONG sumall;
+int nel, stat;
+unsigned char nbitplanes[3];
+char tmagic[2];
+
+ /* initialize the byte read position to the beginning of the array */;
+ nextchar = 0;
+
+ /*
+ * File starts either with special 2-byte magic code or with
+ * FITS keyword "SIMPLE ="
+ */
+ qread(infile, tmagic, sizeof(tmagic));
+ /*
+ * check for correct magic code value
+ */
+ if (memcmp(tmagic,code_magic,sizeof(code_magic)) != 0) {
+ ffpmsg("bad file format");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ *nx =readint(infile); /* x size of image */
+ *ny =readint(infile); /* y size of image */
+ *scale=readint(infile); /* scale factor for digitization */
+
+ nel = (*nx) * (*ny);
+
+ /* sum of all pixels */
+ sumall=readlonglong(infile);
+ /* # bits in quadrants */
+
+ qread(infile, (char *) nbitplanes, sizeof(nbitplanes));
+
+ stat = dodecode(infile, a, *nx, *ny, nbitplanes);
+ /*
+ * put sum of all pixels back into pixel 0
+ */
+ a[0] = (int) sumall;
+ return(stat);
+}
+/* ############################################################################ */
+static int decode64(unsigned char *infile, LONGLONG *a, int *nx, int *ny, int *scale)
+/*
+char *infile; input file
+LONGLONG *a; address of output array [nx][ny]
+int *nx,*ny; size of output array
+int *scale; scale factor for digitization
+*/
+{
+int nel, stat;
+LONGLONG sumall;
+unsigned char nbitplanes[3];
+char tmagic[2];
+
+ /* initialize the byte read position to the beginning of the array */;
+ nextchar = 0;
+
+ /*
+ * File starts either with special 2-byte magic code or with
+ * FITS keyword "SIMPLE ="
+ */
+ qread(infile, tmagic, sizeof(tmagic));
+ /*
+ * check for correct magic code value
+ */
+ if (memcmp(tmagic,code_magic,sizeof(code_magic)) != 0) {
+ ffpmsg("bad file format");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ *nx =readint(infile); /* x size of image */
+ *ny =readint(infile); /* y size of image */
+ *scale=readint(infile); /* scale factor for digitization */
+
+ nel = (*nx) * (*ny);
+
+ /* sum of all pixels */
+ sumall=readlonglong(infile);
+ /* # bits in quadrants */
+
+ qread(infile, (char *) nbitplanes, sizeof(nbitplanes));
+
+ stat = dodecode64(infile, a, *nx, *ny, nbitplanes);
+ /*
+ * put sum of all pixels back into pixel 0
+ */
+ a[0] = sumall;
+
+ return(stat);
+}
+
+
+/* ############################################################################ */
+/* ############################################################################ */
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* dodecode.c Decode stream of characters on infile and return array
+ *
+ * This version encodes the different quadrants separately
+ *
+ * Programmer: R. White Date: 9 May 1991
+ */
+
+/* ############################################################################ */
+static int
+dodecode(unsigned char *infile, int a[], int nx, int ny, unsigned char nbitplanes[3])
+
+/* int a[];
+ int nx,ny; Array dimensions are [nx][ny]
+ unsigned char nbitplanes[3]; Number of bit planes in quadrants
+*/
+{
+int i, nel, nx2, ny2, stat;
+
+ nel = nx*ny;
+ nx2 = (nx+1)/2;
+ ny2 = (ny+1)/2;
+
+ /*
+ * initialize a to zero
+ */
+ for (i=0; i<nel; i++) a[i] = 0;
+ /*
+ * Initialize bit input
+ */
+ start_inputing_bits();
+ /*
+ * read bit planes for each quadrant
+ */
+ stat = qtree_decode(infile, &a[0], ny, nx2, ny2, nbitplanes[0]);
+ if (stat) return(stat);
+
+ stat = qtree_decode(infile, &a[ny2], ny, nx2, ny/2, nbitplanes[1]);
+ if (stat) return(stat);
+
+ stat = qtree_decode(infile, &a[ny*nx2], ny, nx/2, ny2, nbitplanes[1]);
+ if (stat) return(stat);
+
+ stat = qtree_decode(infile, &a[ny*nx2+ny2], ny, nx/2, ny/2, nbitplanes[2]);
+ if (stat) return(stat);
+
+ /*
+ * make sure there is an EOF symbol (nybble=0) at end
+ */
+ if (input_nybble(infile) != 0) {
+ ffpmsg("dodecode: bad bit plane values");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ /*
+ * now get the sign bits
+ * Re-initialize bit input
+ */
+ start_inputing_bits();
+ for (i=0; i<nel; i++) {
+ if (a[i]) {
+ /* tried putting the input_bit code in-line here, instead of */
+ /* calling the function, but it made no difference in the speed */
+ if (input_bit(infile)) a[i] = -a[i];
+ }
+ }
+ return(0);
+}
+/* ############################################################################ */
+static int
+dodecode64(unsigned char *infile, LONGLONG a[], int nx, int ny, unsigned char nbitplanes[3])
+
+/* LONGLONG a[];
+ int nx,ny; Array dimensions are [nx][ny]
+ unsigned char nbitplanes[3]; Number of bit planes in quadrants
+*/
+{
+int i, nel, nx2, ny2, stat;
+
+ nel = nx*ny;
+ nx2 = (nx+1)/2;
+ ny2 = (ny+1)/2;
+
+ /*
+ * initialize a to zero
+ */
+ for (i=0; i<nel; i++) a[i] = 0;
+ /*
+ * Initialize bit input
+ */
+ start_inputing_bits();
+ /*
+ * read bit planes for each quadrant
+ */
+ stat = qtree_decode64(infile, &a[0], ny, nx2, ny2, nbitplanes[0]);
+ if (stat) return(stat);
+
+ stat = qtree_decode64(infile, &a[ny2], ny, nx2, ny/2, nbitplanes[1]);
+ if (stat) return(stat);
+
+ stat = qtree_decode64(infile, &a[ny*nx2], ny, nx/2, ny2, nbitplanes[1]);
+ if (stat) return(stat);
+
+ stat = qtree_decode64(infile, &a[ny*nx2+ny2], ny, nx/2, ny/2, nbitplanes[2]);
+ if (stat) return(stat);
+
+ /*
+ * make sure there is an EOF symbol (nybble=0) at end
+ */
+ if (input_nybble(infile) != 0) {
+ ffpmsg("dodecode64: bad bit plane values");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ /*
+ * now get the sign bits
+ * Re-initialize bit input
+ */
+ start_inputing_bits();
+ for (i=0; i<nel; i++) {
+ if (a[i]) {
+ if (input_bit(infile) != 0) a[i] = -a[i];
+ }
+ }
+ return(0);
+}
+
+/* ############################################################################ */
+/* ############################################################################ */
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* qtree_decode.c Read stream of codes from infile and construct bit planes
+ * in quadrant of 2-D array using binary quadtree coding
+ *
+ * Programmer: R. White Date: 7 May 1991
+ */
+
+/* ############################################################################ */
+static int
+qtree_decode(unsigned char *infile, int a[], int n, int nqx, int nqy, int nbitplanes)
+
+/*
+char *infile;
+int a[]; a is 2-D array with dimensions (n,n)
+int n; length of full row in a
+int nqx; partial length of row to decode
+int nqy; partial length of column (<=n)
+int nbitplanes; number of bitplanes to decode
+*/
+{
+int log2n, k, bit, b, nqmax;
+int nx,ny,nfx,nfy,c;
+int nqx2, nqy2;
+unsigned char *scratch;
+
+ /*
+ * log2n is log2 of max(nqx,nqy) rounded up to next power of 2
+ */
+ nqmax = (nqx>nqy) ? nqx : nqy;
+ log2n = (int) (log((float) nqmax)/log(2.0)+0.5);
+ if (nqmax > (1<<log2n)) {
+ log2n += 1;
+ }
+ /*
+ * allocate scratch array for working space
+ */
+ nqx2=(nqx+1)/2;
+ nqy2=(nqy+1)/2;
+ scratch = (unsigned char *) malloc(nqx2*nqy2);
+ if (scratch == (unsigned char *) NULL) {
+ ffpmsg("qtree_decode: insufficient memory");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ /*
+ * now decode each bit plane, starting at the top
+ * A is assumed to be initialized to zero
+ */
+ for (bit = nbitplanes-1; bit >= 0; bit--) {
+ /*
+ * Was bitplane was quadtree-coded or written directly?
+ */
+ b = input_nybble(infile);
+
+ if(b == 0) {
+ /*
+ * bit map was written directly
+ */
+ read_bdirect(infile,a,n,nqx,nqy,scratch,bit);
+ } else if (b != 0xf) {
+ ffpmsg("qtree_decode: bad format code");
+ return(DATA_DECOMPRESSION_ERR);
+ } else {
+ /*
+ * bitmap was quadtree-coded, do log2n expansions
+ *
+ * read first code
+ */
+ scratch[0] = input_huffman(infile);
+ /*
+ * now do log2n expansions, reading codes from file as necessary
+ */
+ nx = 1;
+ ny = 1;
+ nfx = nqx;
+ nfy = nqy;
+ c = 1<<log2n;
+ for (k = 1; k<log2n; k++) {
+ /*
+ * this somewhat cryptic code generates the sequence
+ * n[k-1] = (n[k]+1)/2 where n[log2n]=nqx or nqy
+ */
+ c = c>>1;
+ nx = nx<<1;
+ ny = ny<<1;
+ if (nfx <= c) { nx -= 1; } else { nfx -= c; }
+ if (nfy <= c) { ny -= 1; } else { nfy -= c; }
+ qtree_expand(infile,scratch,nx,ny,scratch);
+ }
+ /*
+ * now copy last set of 4-bit codes to bitplane bit of array a
+ */
+ qtree_bitins(scratch,nqx,nqy,a,n,bit);
+ }
+ }
+ free(scratch);
+ return(0);
+}
+/* ############################################################################ */
+static int
+qtree_decode64(unsigned char *infile, LONGLONG a[], int n, int nqx, int nqy, int nbitplanes)
+
+/*
+char *infile;
+LONGLONG a[]; a is 2-D array with dimensions (n,n)
+int n; length of full row in a
+int nqx; partial length of row to decode
+int nqy; partial length of column (<=n)
+int nbitplanes; number of bitplanes to decode
+*/
+{
+int log2n, k, bit, b, nqmax;
+int nx,ny,nfx,nfy,c;
+int nqx2, nqy2;
+unsigned char *scratch;
+
+ /*
+ * log2n is log2 of max(nqx,nqy) rounded up to next power of 2
+ */
+ nqmax = (nqx>nqy) ? nqx : nqy;
+ log2n = (int) (log((float) nqmax)/log(2.0)+0.5);
+ if (nqmax > (1<<log2n)) {
+ log2n += 1;
+ }
+ /*
+ * allocate scratch array for working space
+ */
+ nqx2=(nqx+1)/2;
+ nqy2=(nqy+1)/2;
+ scratch = (unsigned char *) malloc(nqx2*nqy2);
+ if (scratch == (unsigned char *) NULL) {
+ ffpmsg("qtree_decode64: insufficient memory");
+ return(DATA_DECOMPRESSION_ERR);
+ }
+ /*
+ * now decode each bit plane, starting at the top
+ * A is assumed to be initialized to zero
+ */
+ for (bit = nbitplanes-1; bit >= 0; bit--) {
+ /*
+ * Was bitplane was quadtree-coded or written directly?
+ */
+ b = input_nybble(infile);
+
+ if(b == 0) {
+ /*
+ * bit map was written directly
+ */
+ read_bdirect64(infile,a,n,nqx,nqy,scratch,bit);
+ } else if (b != 0xf) {
+ ffpmsg("qtree_decode64: bad format code");
+ return(DATA_DECOMPRESSION_ERR);
+ } else {
+ /*
+ * bitmap was quadtree-coded, do log2n expansions
+ *
+ * read first code
+ */
+ scratch[0] = input_huffman(infile);
+ /*
+ * now do log2n expansions, reading codes from file as necessary
+ */
+ nx = 1;
+ ny = 1;
+ nfx = nqx;
+ nfy = nqy;
+ c = 1<<log2n;
+ for (k = 1; k<log2n; k++) {
+ /*
+ * this somewhat cryptic code generates the sequence
+ * n[k-1] = (n[k]+1)/2 where n[log2n]=nqx or nqy
+ */
+ c = c>>1;
+ nx = nx<<1;
+ ny = ny<<1;
+ if (nfx <= c) { nx -= 1; } else { nfx -= c; }
+ if (nfy <= c) { ny -= 1; } else { nfy -= c; }
+ qtree_expand(infile,scratch,nx,ny,scratch);
+ }
+ /*
+ * now copy last set of 4-bit codes to bitplane bit of array a
+ */
+ qtree_bitins64(scratch,nqx,nqy,a,n,bit);
+ }
+ }
+ free(scratch);
+ return(0);
+}
+
+
+/* ############################################################################ */
+/*
+ * do one quadtree expansion step on array a[(nqx+1)/2,(nqy+1)/2]
+ * results put into b[nqx,nqy] (which may be the same as a)
+ */
+static void
+qtree_expand(unsigned char *infile, unsigned char a[], int nx, int ny, unsigned char b[])
+{
+int i;
+
+ /*
+ * first copy a to b, expanding each 4-bit value
+ */
+ qtree_copy(a,nx,ny,b,ny);
+ /*
+ * now read new 4-bit values into b for each non-zero element
+ */
+ for (i = nx*ny-1; i >= 0; i--) {
+ if (b[i]) b[i] = input_huffman(infile);
+ }
+}
+
+/* ############################################################################ */
+/*
+ * copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding
+ * each value to 2x2 pixels
+ * a,b may be same array
+ */
+static void
+qtree_copy(unsigned char a[], int nx, int ny, unsigned char b[], int n)
+/* int n; declared y dimension of b */
+{
+int i, j, k, nx2, ny2;
+int s00, s10;
+
+ /*
+ * first copy 4-bit values to b
+ * start at end in case a,b are same array
+ */
+ nx2 = (nx+1)/2;
+ ny2 = (ny+1)/2;
+ k = ny2*(nx2-1)+ny2-1; /* k is index of a[i,j] */
+ for (i = nx2-1; i >= 0; i--) {
+ s00 = 2*(n*i+ny2-1); /* s00 is index of b[2*i,2*j] */
+ for (j = ny2-1; j >= 0; j--) {
+ b[s00] = a[k];
+ k -= 1;
+ s00 -= 2;
+ }
+ }
+ /*
+ * now expand each 2x2 block
+ */
+ for (i = 0; i<nx-1; i += 2) {
+
+ /* Note:
+ Unlike the case in qtree_bitins, this code runs faster on a 32-bit linux
+ machine using the s10 intermediate variable, rather that using s00+n.
+ Go figure!
+ */
+ s00 = n*i; /* s00 is index of b[i,j] */
+ s10 = s00+n; /* s10 is index of b[i+1,j] */
+
+ for (j = 0; j<ny-1; j += 2) {
+
+ switch (b[s00]) {
+ case(0):
+ b[s10+1] = 0;
+ b[s10 ] = 0;
+ b[s00+1] = 0;
+ b[s00 ] = 0;
+
+ break;
+ case(1):
+ b[s10+1] = 1;
+ b[s10 ] = 0;
+ b[s00+1] = 0;
+ b[s00 ] = 0;
+
+ break;
+ case(2):
+ b[s10+1] = 0;
+ b[s10 ] = 1;
+ b[s00+1] = 0;
+ b[s00 ] = 0;
+
+ break;
+ case(3):
+ b[s10+1] = 1;
+ b[s10 ] = 1;
+ b[s00+1] = 0;
+ b[s00 ] = 0;
+
+ break;
+ case(4):
+ b[s10+1] = 0;
+ b[s10 ] = 0;
+ b[s00+1] = 1;
+ b[s00 ] = 0;
+
+ break;
+ case(5):
+ b[s10+1] = 1;
+ b[s10 ] = 0;
+ b[s00+1] = 1;
+ b[s00 ] = 0;
+
+ break;
+ case(6):
+ b[s10+1] = 0;
+ b[s10 ] = 1;
+ b[s00+1] = 1;
+ b[s00 ] = 0;
+
+ break;
+ case(7):
+ b[s10+1] = 1;
+ b[s10 ] = 1;
+ b[s00+1] = 1;
+ b[s00 ] = 0;
+
+ break;
+ case(8):
+ b[s10+1] = 0;
+ b[s10 ] = 0;
+ b[s00+1] = 0;
+ b[s00 ] = 1;
+
+ break;
+ case(9):
+ b[s10+1] = 1;
+ b[s10 ] = 0;
+ b[s00+1] = 0;
+ b[s00 ] = 1;
+ break;
+ case(10):
+ b[s10+1] = 0;
+ b[s10 ] = 1;
+ b[s00+1] = 0;
+ b[s00 ] = 1;
+
+ break;
+ case(11):
+ b[s10+1] = 1;
+ b[s10 ] = 1;
+ b[s00+1] = 0;
+ b[s00 ] = 1;
+
+ break;
+ case(12):
+ b[s10+1] = 0;
+ b[s10 ] = 0;
+ b[s00+1] = 1;
+ b[s00 ] = 1;
+
+ break;
+ case(13):
+ b[s10+1] = 1;
+ b[s10 ] = 0;
+ b[s00+1] = 1;
+ b[s00 ] = 1;
+
+ break;
+ case(14):
+ b[s10+1] = 0;
+ b[s10 ] = 1;
+ b[s00+1] = 1;
+ b[s00 ] = 1;
+
+ break;
+ case(15):
+ b[s10+1] = 1;
+ b[s10 ] = 1;
+ b[s00+1] = 1;
+ b[s00 ] = 1;
+
+ break;
+ }
+/*
+ b[s10+1] = b[s00] & 1;
+ b[s10 ] = (b[s00]>>1) & 1;
+ b[s00+1] = (b[s00]>>2) & 1;
+ b[s00 ] = (b[s00]>>3) & 1;
+*/
+
+ s00 += 2;
+ s10 += 2;
+ }
+
+ if (j < ny) {
+ /*
+ * row size is odd, do last element in row
+ * s00+1, s10+1 are off edge
+ */
+ /* not worth converting this to use 16 case statements */
+ b[s10 ] = (b[s00]>>1) & 1;
+ b[s00 ] = (b[s00]>>3) & 1;
+ }
+ }
+ if (i < nx) {
+ /*
+ * column size is odd, do last row
+ * s10, s10+1 are off edge
+ */
+ s00 = n*i;
+ for (j = 0; j<ny-1; j += 2) {
+ /* not worth converting this to use 16 case statements */
+ b[s00+1] = (b[s00]>>2) & 1;
+ b[s00 ] = (b[s00]>>3) & 1;
+ s00 += 2;
+ }
+ if (j < ny) {
+ /*
+ * both row and column size are odd, do corner element
+ * s00+1, s10, s10+1 are off edge
+ */
+ /* not worth converting this to use 16 case statements */
+ b[s00 ] = (b[s00]>>3) & 1;
+ }
+ }
+}
+
+/* ############################################################################ */
+/*
+ * Copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding
+ * each value to 2x2 pixels and inserting into bitplane BIT of B.
+ * A,B may NOT be same array (it wouldn't make sense to be inserting
+ * bits into the same array anyway.)
+ */
+static void
+qtree_bitins(unsigned char a[], int nx, int ny, int b[], int n, int bit)
+/*
+ int n; declared y dimension of b
+*/
+{
+int i, j, k;
+int s00;
+int plane_val;
+
+ plane_val = 1 << bit;
+
+ /*
+ * expand each 2x2 block
+ */
+ k = 0; /* k is index of a[i/2,j/2] */
+ for (i = 0; i<nx-1; i += 2) {
+ s00 = n*i; /* s00 is index of b[i,j] */
+
+ /* Note:
+ this code appears to run very slightly faster on a 32-bit linux
+ machine using s00+n rather than the s10 intermediate variable
+ */
+ /* s10 = s00+n; */ /* s10 is index of b[i+1,j] */
+ for (j = 0; j<ny-1; j += 2) {
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ b[s00+n+1] |= plane_val;
+ break;
+ case(2):
+ b[s00+n ] |= plane_val;
+ break;
+ case(3):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ break;
+ case(4):
+ b[s00+1] |= plane_val;
+ break;
+ case(5):
+ b[s00+n+1] |= plane_val;
+ b[s00+1] |= plane_val;
+ break;
+ case(6):
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ break;
+ case(7):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00+n+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00+n+1] |= plane_val;
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ }
+
+/*
+ b[s10+1] |= ( a[k] & 1) << bit;
+ b[s10 ] |= ((a[k]>>1) & 1) << bit;
+ b[s00+1] |= ((a[k]>>2) & 1) << bit;
+ b[s00 ] |= ((a[k]>>3) & 1) << bit;
+*/
+ s00 += 2;
+/* s10 += 2; */
+ k += 1;
+ }
+ if (j < ny) {
+ /*
+ * row size is odd, do last element in row
+ * s00+1, s10+1 are off edge
+ */
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ break;
+ case(2):
+ b[s00+n ] |= plane_val;
+ break;
+ case(3):
+ b[s00+n ] |= plane_val;
+ break;
+ case(4):
+ break;
+ case(5):
+ break;
+ case(6):
+ b[s00+n ] |= plane_val;
+ break;
+ case(7):
+ b[s00+n ] |= plane_val;
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ }
+
+/*
+ b[s10 ] |= ((a[k]>>1) & 1) << bit;
+ b[s00 ] |= ((a[k]>>3) & 1) << bit;
+*/
+ k += 1;
+ }
+ }
+ if (i < nx) {
+ /*
+ * column size is odd, do last row
+ * s10, s10+1 are off edge
+ */
+ s00 = n*i;
+ for (j = 0; j<ny-1; j += 2) {
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ break;
+ case(2):
+ break;
+ case(3):
+ break;
+ case(4):
+ b[s00+1] |= plane_val;
+ break;
+ case(5):
+ b[s00+1] |= plane_val;
+ break;
+ case(6):
+ b[s00+1] |= plane_val;
+ break;
+ case(7):
+ b[s00+1] |= plane_val;
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ }
+
+/*
+ b[s00+1] |= ((a[k]>>2) & 1) << bit;
+ b[s00 ] |= ((a[k]>>3) & 1) << bit;
+*/
+
+ s00 += 2;
+ k += 1;
+ }
+ if (j < ny) {
+ /*
+ * both row and column size are odd, do corner element
+ * s00+1, s10, s10+1 are off edge
+ */
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ break;
+ case(2):
+ break;
+ case(3):
+ break;
+ case(4):
+ break;
+ case(5):
+ break;
+ case(6):
+ break;
+ case(7):
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00 ] |= plane_val;
+ break;
+ }
+
+/*
+ b[s00 ] |= ((a[k]>>3) & 1) << bit;
+*/
+ k += 1;
+ }
+ }
+}
+/* ############################################################################ */
+/*
+ * Copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding
+ * each value to 2x2 pixels and inserting into bitplane BIT of B.
+ * A,B may NOT be same array (it wouldn't make sense to be inserting
+ * bits into the same array anyway.)
+ */
+static void
+qtree_bitins64(unsigned char a[], int nx, int ny, LONGLONG b[], int n, int bit)
+/*
+ int n; declared y dimension of b
+*/
+{
+int i, j, k;
+int s00;
+int plane_val;
+
+ plane_val = 1 << bit;
+
+ /*
+ * expand each 2x2 block
+ */
+ k = 0; /* k is index of a[i/2,j/2] */
+ for (i = 0; i<nx-1; i += 2) {
+ s00 = n*i; /* s00 is index of b[i,j] */
+
+ /* Note:
+ this code appears to run very slightly faster on a 32-bit linux
+ machine using s00+n rather than the s10 intermediate variable
+ */
+ /* s10 = s00+n; */ /* s10 is index of b[i+1,j] */
+ for (j = 0; j<ny-1; j += 2) {
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ b[s00+n+1] |= plane_val;
+ break;
+ case(2):
+ b[s00+n ] |= plane_val;
+ break;
+ case(3):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ break;
+ case(4):
+ b[s00+1] |= plane_val;
+ break;
+ case(5):
+ b[s00+n+1] |= plane_val;
+ b[s00+1] |= plane_val;
+ break;
+ case(6):
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ break;
+ case(7):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00+n+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00+n+1] |= plane_val;
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00+n+1] |= plane_val;
+ b[s00+n ] |= plane_val;
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ }
+
+/*
+ b[s10+1] |= ((LONGLONG) ( a[k] & 1)) << bit;
+ b[s10 ] |= ((((LONGLONG)a[k])>>1) & 1) << bit;
+ b[s00+1] |= ((((LONGLONG)a[k])>>2) & 1) << bit;
+ b[s00 ] |= ((((LONGLONG)a[k])>>3) & 1) << bit;
+*/
+ s00 += 2;
+/* s10 += 2; */
+ k += 1;
+ }
+ if (j < ny) {
+ /*
+ * row size is odd, do last element in row
+ * s00+1, s10+1 are off edge
+ */
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ break;
+ case(2):
+ b[s00+n ] |= plane_val;
+ break;
+ case(3):
+ b[s00+n ] |= plane_val;
+ break;
+ case(4):
+ break;
+ case(5):
+ break;
+ case(6):
+ b[s00+n ] |= plane_val;
+ break;
+ case(7):
+ b[s00+n ] |= plane_val;
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00+n ] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ }
+/*
+ b[s10 ] |= ((((LONGLONG)a[k])>>1) & 1) << bit;
+ b[s00 ] |= ((((LONGLONG)a[k])>>3) & 1) << bit;
+*/
+ k += 1;
+ }
+ }
+ if (i < nx) {
+ /*
+ * column size is odd, do last row
+ * s10, s10+1 are off edge
+ */
+ s00 = n*i;
+ for (j = 0; j<ny-1; j += 2) {
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ break;
+ case(2):
+ break;
+ case(3):
+ break;
+ case(4):
+ b[s00+1] |= plane_val;
+ break;
+ case(5):
+ b[s00+1] |= plane_val;
+ break;
+ case(6):
+ b[s00+1] |= plane_val;
+ break;
+ case(7):
+ b[s00+1] |= plane_val;
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00+1] |= plane_val;
+ b[s00 ] |= plane_val;
+ break;
+ }
+
+/*
+ b[s00+1] |= ((((LONGLONG)a[k])>>2) & 1) << bit;
+ b[s00 ] |= ((((LONGLONG)a[k])>>3) & 1) << bit;
+*/
+ s00 += 2;
+ k += 1;
+ }
+ if (j < ny) {
+ /*
+ * both row and column size are odd, do corner element
+ * s00+1, s10, s10+1 are off edge
+ */
+
+ switch (a[k]) {
+ case(0):
+ break;
+ case(1):
+ break;
+ case(2):
+ break;
+ case(3):
+ break;
+ case(4):
+ break;
+ case(5):
+ break;
+ case(6):
+ break;
+ case(7):
+ break;
+ case(8):
+ b[s00 ] |= plane_val;
+ break;
+ case(9):
+ b[s00 ] |= plane_val;
+ break;
+ case(10):
+ b[s00 ] |= plane_val;
+ break;
+ case(11):
+ b[s00 ] |= plane_val;
+ break;
+ case(12):
+ b[s00 ] |= plane_val;
+ break;
+ case(13):
+ b[s00 ] |= plane_val;
+ break;
+ case(14):
+ b[s00 ] |= plane_val;
+ break;
+ case(15):
+ b[s00 ] |= plane_val;
+ break;
+ }
+/*
+ b[s00 ] |= ((((LONGLONG)a[k])>>3) & 1) << bit;
+*/
+ k += 1;
+ }
+ }
+}
+
+/* ############################################################################ */
+static void
+read_bdirect(unsigned char *infile, int a[], int n, int nqx, int nqy, unsigned char scratch[], int bit)
+{
+
+
+ /*
+ * read bit image packed 4 pixels/nybble
+ */
+/*
+ int i;
+ for (i = 0; i < ((nqx+1)/2) * ((nqy+1)/2); i++) {
+ scratch[i] = input_nybble(infile);
+ }
+*/
+ input_nnybble(infile, ((nqx+1)/2) * ((nqy+1)/2), scratch);
+
+ /*
+ * insert in bitplane BIT of image A
+ */
+ qtree_bitins(scratch,nqx,nqy,a,n,bit);
+}
+/* ############################################################################ */
+static void
+read_bdirect64(unsigned char *infile, LONGLONG a[], int n, int nqx, int nqy, unsigned char scratch[], int bit)
+{
+
+ /*
+ * read bit image packed 4 pixels/nybble
+ */
+/*
+ int i;
+ for (i = 0; i < ((nqx+1)/2) * ((nqy+1)/2); i++) {
+ scratch[i] = input_nybble(infile);
+ }
+*/
+ input_nnybble(infile, ((nqx+1)/2) * ((nqy+1)/2), scratch);
+
+ /*
+ * insert in bitplane BIT of image A
+ */
+ qtree_bitins64(scratch,nqx,nqy,a,n,bit);
+}
+
+/* ############################################################################ */
+/*
+ * Huffman decoding for fixed codes
+ *
+ * Coded values range from 0-15
+ *
+ * Huffman code values (hex):
+ *
+ * 3e, 00, 01, 08, 02, 09, 1a, 1b,
+ * 03, 1c, 0a, 1d, 0b, 1e, 3f, 0c
+ *
+ * and number of bits in each code:
+ *
+ * 6, 3, 3, 4, 3, 4, 5, 5,
+ * 3, 5, 4, 5, 4, 5, 6, 4
+ */
+static int input_huffman(unsigned char *infile)
+{
+int c;
+
+ /*
+ * get first 3 bits to start
+ */
+ c = input_nbits(infile,3);
+ if (c < 4) {
+ /*
+ * this is all we need
+ * return 1,2,4,8 for c=0,1,2,3
+ */
+ return(1<<c);
+ }
+ /*
+ * get the next bit
+ */
+ c = input_bit(infile) | (c<<1);
+ if (c < 13) {
+ /*
+ * OK, 4 bits is enough
+ */
+ switch (c) {
+ case 8 : return(3);
+ case 9 : return(5);
+ case 10 : return(10);
+ case 11 : return(12);
+ case 12 : return(15);
+ }
+ }
+ /*
+ * get yet another bit
+ */
+ c = input_bit(infile) | (c<<1);
+ if (c < 31) {
+ /*
+ * OK, 5 bits is enough
+ */
+ switch (c) {
+ case 26 : return(6);
+ case 27 : return(7);
+ case 28 : return(9);
+ case 29 : return(11);
+ case 30 : return(13);
+ }
+ }
+ /*
+ * need the 6th bit
+ */
+ c = input_bit(infile) | (c<<1);
+ if (c == 62) {
+ return(0);
+ } else {
+ return(14);
+ }
+}
+
+/* ############################################################################ */
+/* ############################################################################ */
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+/* qread.c Read binary data
+ *
+ * Programmer: R. White Date: 11 March 1991
+ */
+
+static int readint(unsigned char *infile)
+{
+int a,i;
+unsigned char b[4];
+
+ /* Read integer A one byte at a time from infile.
+ *
+ * This is portable from Vax to Sun since it eliminates the
+ * need for byte-swapping.
+ *
+ * This routine is only called to read the first 3 values
+ * in the compressed file, so it doesn't have to be
+ * super-efficient
+ */
+ for (i=0; i<4; i++) qread(infile,(char *) &b[i],1);
+ a = b[0];
+ for (i=1; i<4; i++) a = (a<<8) + b[i];
+ return(a);
+}
+
+/* ############################################################################ */
+static LONGLONG readlonglong(unsigned char *infile)
+{
+int i;
+LONGLONG a;
+unsigned char b[8];
+
+ /* Read integer A one byte at a time from infile.
+ *
+ * This is portable from Vax to Sun since it eliminates the
+ * need for byte-swapping.
+ *
+ * This routine is only called to read the first 3 values
+ * in the compressed file, so it doesn't have to be
+ * super-efficient
+ */
+ for (i=0; i<8; i++) qread(infile,(char *) &b[i],1);
+ a = b[0];
+ for (i=1; i<8; i++) a = (a<<8) + b[i];
+ return(a);
+}
+
+/* ############################################################################ */
+static void qread(unsigned char *file, char buffer[], int n)
+{
+ /*
+ * read n bytes from file into buffer
+ *
+ */
+
+ memcpy(buffer, &file[nextchar], n);
+ nextchar += n;
+}
+
+/* ############################################################################ */
+/* ############################################################################ */
+/* Copyright (c) 1993 Association of Universities for Research
+ * in Astronomy. All rights reserved. Produced under National
+ * Aeronautics and Space Administration Contract No. NAS5-26555.
+ */
+
+/* BIT INPUT ROUTINES */
+
+/* THE BIT BUFFER */
+
+static int buffer2; /* Bits waiting to be input */
+static int bits_to_go; /* Number of bits still in buffer */
+
+/* INITIALIZE BIT INPUT */
+
+/* ############################################################################ */
+static void start_inputing_bits()
+{
+ /*
+ * Buffer starts out with no bits in it
+ */
+ bits_to_go = 0;
+}
+
+/* ############################################################################ */
+/* INPUT A BIT */
+
+static int input_bit(unsigned char *infile)
+{
+ if (bits_to_go == 0) { /* Read the next byte if no */
+
+ buffer2 = infile[nextchar];
+ nextchar++;
+
+ bits_to_go = 8;
+ }
+ /*
+ * Return the next bit
+ */
+ bits_to_go -= 1;
+ return((buffer2>>bits_to_go) & 1);
+}
+
+/* ############################################################################ */
+/* INPUT N BITS (N must be <= 8) */
+
+static int input_nbits(unsigned char *infile, int n)
+{
+ /* AND mask for retreiving the right-most n bits */
+ static int mask[9] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
+
+ if (bits_to_go < n) {
+ /*
+ * need another byte's worth of bits
+ */
+
+ buffer2 = (buffer2<<8) | (int) infile[nextchar];
+ nextchar++;
+ bits_to_go += 8;
+ }
+ /*
+ * now pick off the first n bits
+ */
+ bits_to_go -= n;
+
+ /* there was a slight gain in speed by replacing the following line */
+/* return( (buffer2>>bits_to_go) & ((1<<n)-1) ); */
+ return( (buffer2>>bits_to_go) & (*(mask+n)) );
+}
+/* ############################################################################ */
+/* INPUT 4 BITS */
+
+static int input_nybble(unsigned char *infile)
+{
+ if (bits_to_go < 4) {
+ /*
+ * need another byte's worth of bits
+ */
+
+ buffer2 = (buffer2<<8) | (int) infile[nextchar];
+ nextchar++;
+ bits_to_go += 8;
+ }
+ /*
+ * now pick off the first 4 bits
+ */
+ bits_to_go -= 4;
+
+ return( (buffer2>>bits_to_go) & 15 );
+}
+/* ############################################################################ */
+/* INPUT array of 4 BITS */
+
+static int input_nnybble(unsigned char *infile, int n, unsigned char array[])
+{
+ /* copy n 4-bit nybbles from infile to the lower 4 bits of array */
+
+int ii, kk, shift1, shift2;
+
+/* forcing byte alignment doesn;t help, and even makes it go slightly slower
+if (bits_to_go != 8) input_nbits(infile, bits_to_go);
+*/
+ if (n == 1) {
+ array[0] = input_nybble(infile);
+ return(0);
+ }
+
+ if (bits_to_go == 8) {
+ /*
+ already have 2 full nybbles in buffer2, so
+ backspace the infile array to reuse last char
+ */
+ nextchar--;
+ bits_to_go = 0;
+ }
+
+ /* bits_to_go now has a value in the range 0 - 7. After adding */
+ /* another byte, bits_to_go effectively will be in range 8 - 15 */
+
+ shift1 = bits_to_go + 4; /* shift1 will be in range 4 - 11 */
+ shift2 = bits_to_go; /* shift2 will be in range 0 - 7 */
+ kk = 0;
+
+ /* special case */
+ if (bits_to_go == 0)
+ {
+ for (ii = 0; ii < n/2; ii++) {
+ /*
+ * refill the buffer with next byte
+ */
+ buffer2 = (buffer2<<8) | (int) infile[nextchar];
+ nextchar++;
+ array[kk] = (int) ((buffer2>>4) & 15);
+ array[kk + 1] = (int) ((buffer2) & 15); /* no shift required */
+ kk += 2;
+ }
+ }
+ else
+ {
+ for (ii = 0; ii < n/2; ii++) {
+ /*
+ * refill the buffer with next byte
+ */
+ buffer2 = (buffer2<<8) | (int) infile[nextchar];
+ nextchar++;
+ array[kk] = (int) ((buffer2>>shift1) & 15);
+ array[kk + 1] = (int) ((buffer2>>shift2) & 15);
+ kk += 2;
+ }
+ }
+
+
+ if (ii * 2 != n) { /* have to read last odd byte */
+ array[n-1] = input_nybble(infile);
+ }
+
+ return( (buffer2>>bits_to_go) & 15 );
+}
diff --git a/fitsy++/hdu.C b/fitsy++/hdu.C
new file mode 100644
index 0000000..a3b3b4d
--- /dev/null
+++ b/fitsy++/hdu.C
@@ -0,0 +1,323 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "hdu.h"
+#include "head.h"
+#include "util.h"
+
+FitsHDU::FitsHDU(FitsHead* head)
+{
+ extname_ = dupstr(head->getString("EXTNAME"));
+ // trim any spaces at end
+ if (extname_) {
+ for (int ii=strlen(extname_)-1; ii>=0; ii--) {
+ if (extname_[ii] == ' ')
+ extname_[ii] = '\0';
+ else
+ break;
+ }
+ }
+
+ extver_ = head->getInteger("EXTVER", 1);
+ extlevel_ = head->getInteger("EXTLEVEL", 1);
+
+ bitpix_ = head->getInteger("BITPIX", 0);
+ naxes_ = head->getInteger("NAXIS", 0);
+ if (naxes_>FTY_MAXAXES)
+ naxes_ = FTY_MAXAXES;
+
+ // init naxis_
+ for(int i=0; i<FTY_MAXAXES; i++)
+ naxis_[i] = 0;
+
+ for(int i=0; i<naxes_; i++)
+ naxis_[i] = head->getInteger(keycat("NAXIS",(i+1)), 0);
+
+ // special case: 1D image
+ if (naxis_[0]>0 && naxis_[1]==0)
+ naxis_[1] = 1;
+
+ realbytes_ = 0;
+ heapbytes_ = head->getInteger("PCOUNT",0);
+ allbytes_ = 0;
+ padbytes_ = 0;
+ databytes_ = 0;
+ datablocks_ = 0;
+}
+
+FitsHDU::~FitsHDU()
+{
+ if (extname_)
+ delete [] extname_;
+}
+
+char* FitsHDU::keycat(const char* name, int i)
+{
+ ostringstream str;
+ str << name << i << ends;
+ memcpy(keybuf,str.str().c_str(),str.str().length());
+ return keybuf;
+}
+
+void FitsHDU::updateCards(FitsHead* head)
+{
+ head->setInteger("BITPIX", bitpix_, NULL);
+ head->setInteger("NAXIS", naxes_, NULL);
+
+ for (int i=1; i<=naxes_; i++)
+ head->setInteger(keycat("NAXIS", i), naxis_[i-1], NULL);
+}
+
+// FitsImageHDU
+
+FitsImageHDU::FitsImageHDU(FitsHead* head) : FitsHDU(head)
+{
+ size_t imgpixels = (size_t)naxis_[0]*naxis_[1];
+ imgbytes_ = imgpixels * (abs(bitpix_)/8);
+
+ size_t realpixels;
+ if (naxes_>0) {
+ realpixels = 1;
+ for (int i=0; i<naxes_; i++ )
+ realpixels *= naxis_[i];
+ }
+ else
+ realpixels = 0;
+
+ realbytes_ = realpixels * (abs(bitpix_)/8);
+ allbytes_ = realbytes_ + heapbytes_;
+ datablocks_ = (allbytes_ + (FTY_BLOCK-1))/FTY_BLOCK;
+ databytes_ = datablocks_ * FTY_BLOCK;
+ padbytes_ = databytes_ - allbytes_;
+
+ bzero_ = head->getReal("BZERO", 0.0);
+ bscale_ = head->getReal("BSCALE", 1.0);
+ hasblank_ = head->find("BLANK") ? 1:0;
+ blank_ = head->getInteger("BLANK", 0);
+}
+
+void FitsImageHDU::updateCards(FitsHead* head)
+{
+ FitsHDU::updateCards(head);
+ if (blank_)
+ if (bitpix_ > 0)
+ head->setInteger("BLANK", blank_, NULL);
+
+ if (bzero_)
+ head->setReal("BZERO", bzero_ , 7, NULL);
+ if (bscale_ != 1)
+ head->setReal("BSCALE", bscale_, 7, NULL);
+}
+
+// FitsTableHDU
+
+FitsTableHDU::FitsTableHDU(FitsHead* head) : FitsHDU(head)
+{
+ tfields_ = head->getInteger("TFIELDS", 0);
+ cols_ = NULL;
+
+ // number of rows * width of row in bytes
+ realbytes_ = (size_t)naxis_[0]*naxis_[1];
+ allbytes_ = realbytes_ + heapbytes_;
+ datablocks_ = (allbytes_ + (FTY_BLOCK-1))/FTY_BLOCK;
+ databytes_ = datablocks_ * FTY_BLOCK;
+ padbytes_ = databytes_ - allbytes_;
+}
+
+FitsTableHDU::~FitsTableHDU()
+{
+ if (cols_) {
+ for (int i=0; i<tfields_; i++)
+ if (cols_[i])
+ delete cols_[i];
+
+ delete [] cols_;
+ }
+}
+
+char* FitsTableHDU::list()
+{
+ ostringstream str;
+ for (int i=0; i<tfields_; i++)
+ if (cols_[i])
+ str << cols_[i]->ttype() << ' ';
+ str << ends;
+ return dupstr(str.str().c_str());
+}
+
+FitsColumn* FitsTableHDU::find(const char* name)
+{
+ char* n = toUpper(name);
+ // trim any spaces
+ char* nn = n;
+ while (*nn)
+ nn++;
+ nn--;
+ while (*nn == ' ')
+ *nn-- = '\0';
+
+ for (int i=0; i<tfields_; i++) {
+ if (cols_[i]) {
+
+ char* t = toUpper(cols_[i]->ttype());
+ // trim any spaces
+ char* tt=t;
+ while (*tt)
+ tt++;
+ tt--;
+ while (*tt == ' ')
+ *tt-- = '\0';
+
+ if (!strncmp(n,t,strlen(n)) && strlen(n)==strlen(t)) {
+ delete [] n;
+ delete [] t;
+ return cols_[i];
+ }
+
+ delete [] t;
+ }
+ }
+
+ delete [] n;
+ return NULL;
+}
+
+FitsColumn* FitsTableHDU::find(int i)
+{
+ if (i>=0 && i<tfields_)
+ return cols_[i];
+
+ return NULL;
+}
+
+Vector FitsTableHDU::dimension(const char* name)
+{
+ FitsColumn* col = find(name);
+ return col ? col->dimension() : Vector();
+}
+
+FitsAsciiTableHDU::FitsAsciiTableHDU(FitsHead* head) : FitsTableHDU(head)
+{
+ cols_ = new FitsColumn*[tfields_];
+
+ size_t offset = 0;
+ for (int i=0; i<tfields_; i++) {
+ char* tform = head->getString(keycat("TFORM",i+1));
+ char type = 'F';
+ if (tform) {
+ string x(tform);
+ istringstream str(x);
+ str >> type;
+ }
+
+ switch (type) {
+ case 'A':
+ cols_[i] = new FitsAsciiColumnStr(head, i+1, offset);
+ break;
+ case 'I':
+ cols_[i] = new FitsAsciiColumnT<int>(head, i+1, offset);
+ break;
+ case 'F':
+ cols_[i] = new FitsAsciiColumnT<float>(head, i+1, offset);
+ break;
+ case 'E':
+ cols_[i] = new FitsAsciiColumnT<float>(head, i+1, offset);
+ break;
+ case 'D':
+ cols_[i] = new FitsAsciiColumnT<double>(head, i+1, offset);
+ break;
+ }
+
+ if (cols_[i])
+ offset += cols_[i]->width();
+ }
+}
+
+FitsBinTableHDU::FitsBinTableHDU(FitsHead* head) : FitsTableHDU(head)
+{
+ cols_ = new FitsColumn*[tfields_];
+
+ int offset =0;
+ for (int i=0; i<tfields_; i++) {
+ char* tform = head->getString(keycat("TFORM",i+1));
+ int repeat;
+ char type = 'J';
+ if (tform) {
+ string x(tform);
+ istringstream str(x);
+ if (isalpha(tform[0]))
+ str >> type;
+ else
+ str >> repeat >> type;
+ }
+
+ switch (type) {
+ case 'L':
+ cols_[i] = new FitsBinColumnLogical(head, i+1, offset);
+ break;
+ case 'X':
+ cols_[i] = new FitsBinColumnBit(head, i+1, offset);
+ break;
+ case 'B':
+ cols_[i] = new FitsBinColumnT<unsigned char>(head, i+1, offset);
+ break;
+ case 'I':
+ cols_[i] = new FitsBinColumnT<short>(head, i+1, offset);
+ break;
+ case 'U':
+ cols_[i] = new FitsBinColumnT<unsigned short>(head, i+1, offset);
+ break;
+ case 'J':
+ cols_[i] = new FitsBinColumnT<int>(head, i+1, offset);
+ break;
+ case 'V':
+ cols_[i] = new FitsBinColumnT<unsigned int>(head, i+1, offset);
+ break;
+ case 'K':
+ cols_[i] = new FitsBinColumnT<long long>(head, i+1, offset);
+ break;
+ case 'A':
+ cols_[i] = new FitsBinColumnStr(head, i+1, offset);
+ break;
+ case 'E':
+ cols_[i] = new FitsBinColumnT<float>(head, i+1, offset);
+ break;
+ case 'D':
+ cols_[i] = new FitsBinColumnT<double>(head, i+1, offset);
+ break;
+ case 'C':
+ cols_[i] = NULL;
+ internalError("Fitsy++ hdu single precision complex column type not supported");
+ break;
+ case 'M':
+ cols_[i] = NULL;
+ internalError("Fitsy++ hdu double precision complex column type not supported");
+ break;
+ case 'P':
+ cols_[i] = new FitsBinColumnArrayP(head, i+1, offset);
+ break;
+ case 'Q':
+ cols_[i] = new FitsBinColumnArrayQ(head, i+1, offset);
+ break;
+
+ default:
+ cols_[i] = NULL;
+ internalError("Fitsy++ hdu unknown table column type");
+ break;
+ }
+
+ if (cols_[i])
+ offset += cols_[i]->width();
+ }
+}
+
diff --git a/fitsy++/hdu.h b/fitsy++/hdu.h
new file mode 100644
index 0000000..818f681
--- /dev/null
+++ b/fitsy++/hdu.h
@@ -0,0 +1,111 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitshdu_h__
+#define __fitshdu_h__
+
+#include <stdlib.h>
+
+#include "column.h"
+
+#define FTY_MAXAXES 10
+
+class FitsHead;
+
+class FitsHDU {
+ protected:
+ char* extname_; // EXTNAME keyword
+ int extver_; // EXTVER keyword
+ int extlevel_; // EXTLEVEL keyword
+
+ int bitpix_; // BITPIX keyword
+ int naxes_; // NAXIS keyword
+ int naxis_[FTY_MAXAXES]; // NAXIS[i] keywords
+
+ size_t realbytes_; // Number of real bytes
+ size_t heapbytes_; // Number of heap bytes
+ size_t allbytes_; // Number of real bytes + heap bytes
+ size_t padbytes_; // Number of pad bytes
+ size_t databytes_; // Number of total bytes (padded)
+ size_t datablocks_; // Number of total blocks
+
+ char keybuf[9];
+ char* keycat(const char*, int);
+
+public:
+ FitsHDU(FitsHead*);
+ virtual ~FitsHDU();
+
+ virtual void updateCards(FitsHead*);
+
+ const char* extname() {return extname_;}
+ int extver() {return extver_;}
+ int extlevel() {return extlevel_;}
+ int bitpix() {return bitpix_;}
+ int naxes() {return naxes_;}
+ int naxis(int ii) {return naxis_[ii];}
+
+ size_t realbytes() {return realbytes_;}
+ size_t heapbytes() {return heapbytes_;}
+ size_t allbytes() {return allbytes_;}
+ size_t padbytes() {return padbytes_;}
+ size_t databytes() {return databytes_;}
+ size_t datablocks() {return datablocks_;}
+};
+
+class FitsImageHDU : public FitsHDU {
+private:
+ size_t imgbytes_; // number of image bytes
+
+ double bscale_;
+ double bzero_;
+ int hasblank_;
+ int blank_;
+
+public:
+ FitsImageHDU(FitsHead*);
+
+ void updateCards(FitsHead*);
+
+ size_t imgbytes() {return imgbytes_;}
+ void setScaling(double t,double z) {bscale_=t; bzero_=z;}
+ double bscale() {return bscale_;}
+ double bzero() {return bzero_;}
+ int hasscaling() {return bscale_ != 1 || bzero_ != 0;}
+ int hasblank() {return hasblank_;}
+ int blank() {return blank_;}
+};
+
+class FitsTableHDU : public FitsHDU {
+protected:
+ int tfields_;
+ FitsColumn** cols_;
+
+public:
+ FitsTableHDU(FitsHead*);
+ virtual ~FitsTableHDU();
+
+ int tfields() {return tfields_;}
+ int rows() {return naxis_[1];}
+ int cols() {return tfields_;}
+ int width() {return naxis_[0];}
+ char* list();
+ FitsColumn* find(const char*);
+ FitsColumn* find(int);
+ Vector dimension(const char*);
+};
+
+class FitsBinTableHDU : public FitsTableHDU {
+public:
+ FitsBinTableHDU(FitsHead*);
+};
+
+class FitsAsciiTableHDU : public FitsTableHDU {
+public:
+ FitsAsciiTableHDU(FitsHead*);
+};
+
+#endif
+
+
diff --git a/fitsy++/head.C b/fitsy++/head.C
new file mode 100644
index 0000000..4cd6f4e
--- /dev/null
+++ b/fitsy++/head.C
@@ -0,0 +1,634 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+
+#ifndef __WIN32
+#include <sys/mman.h>
+#include <sys/shm.h>
+#endif
+
+#include "file.h"
+#include "head.h"
+#include "util.h"
+
+FitsHead::FitsHead(char* raw, size_t bytes, Memory mem)
+{
+ cards_ = raw;
+ mapdata_ = raw;
+ mapsize_ = bytes;
+ memory_ = mem;
+ ncard_ = 0;
+ acard_ = 0;
+ ccard_ = 0;
+
+ index_ = NULL;
+
+ valid_ = 0;
+ inherit_ = 0;
+
+ hdu_ = NULL;
+
+ char* c;
+ int i;
+ for (c = cards_, i=0; c < cards_+bytes; c+=FTY_CARDLEN, i++) {
+ // only compare 4 chars
+ if (!strncmp(c, "END ", 4)) {
+ ncard_ = i + 1;
+ acard_ = ((ncard_+FTY_CARDS-1)/FTY_CARDS) * FTY_CARDS;
+ valid_ = 1;
+
+ buildIndex();
+ updateHDU();
+ return;
+ }
+ }
+}
+
+FitsHead::FitsHead(char* raw, size_t bytes, char* mm,
+ size_t sz, Memory mem)
+{
+ cards_ = raw;
+ mapdata_ = mm;
+ mapsize_ = sz;
+ memory_ = mem;
+ ncard_ = 0;
+ acard_ = 0;
+ ccard_ = 0;
+
+ index_ = NULL;
+
+ valid_ = 0;
+ inherit_ = 0;
+
+ hdu_ = NULL;
+
+ char* c;
+ int i;
+ for (c = cards_, i=0; c < cards_+bytes; c+=FTY_CARDLEN, i++) {
+ // only compare 4 chars
+ if (!strncmp(c, "END ", 4)) {
+ ncard_ = i + 1;
+ acard_ = ((ncard_+FTY_CARDS-1)/FTY_CARDS) * FTY_CARDS;
+ valid_ = 1;
+
+ buildIndex();
+ updateHDU();
+ return;
+ }
+ }
+}
+
+// Create Image FitsHead
+
+FitsHead::FitsHead(int width, int height, int depth, int bitpix, char* xtension)
+{
+ cards_ = new char[FTY_BLOCK];
+ memset(cards_, ' ', FTY_BLOCK);
+ memcpy(cards_, "END", 3);
+
+ mapdata_ = NULL;
+ mapsize_ = 0;
+ memory_ = ALLOC;
+
+ ncard_ = 1;
+ acard_ = FTY_CARDS;
+ ccard_ = 0;
+
+ index_ = NULL;
+
+ if (!xtension)
+ appendLogical("SIMPLE", 1, "Fits Standard");
+ else
+ appendString("XTENSION", xtension, "Fits Standard");
+
+ appendInteger("BITPIX", bitpix, "Bits per pixel");
+ appendInteger("NAXIS", depth>1 ? 3 : 2, "Number of axes");
+ appendInteger("NAXIS1", width, "Axis Length");
+ appendInteger("NAXIS2", height, "Axis Length");
+ if (depth>1)
+ appendInteger("NAXIS3", depth, "Axis Length");
+
+ valid_ = 1;
+ inherit_ = 0;
+
+ hdu_ = NULL;
+
+ buildIndex();
+ updateHDU();
+}
+
+FitsHead::FitsHead(int width, int height, int depth, int bitpix,
+ char* mm, size_t sz, Memory mem)
+{
+ cards_ = new char[FTY_BLOCK];
+ memset(cards_, ' ', FTY_BLOCK);
+ memcpy(cards_, "END", 3);
+
+ mapdata_ = mm;
+ mapsize_ = sz;
+ memory_ = mem;
+
+ ncard_ = 1;
+ acard_ = FTY_CARDS;
+ ccard_ = 0;
+
+ index_ = NULL;
+
+ appendLogical("SIMPLE", 1, "Fits Standard");
+ appendInteger("BITPIX", bitpix, "Bits per pixel");
+ appendInteger("NAXIS", depth==1 ? 2 : 3, "Number of axes");
+ appendInteger("NAXIS1", width, "Axis Length");
+ appendInteger("NAXIS2", height, "Axis Length");
+ if (depth>1)
+ appendInteger("NAXIS3", depth, "Axis Length");
+
+ valid_ = 1;
+ inherit_ = 0;
+
+ hdu_ = NULL;
+
+ buildIndex();
+ updateHDU();
+}
+
+FitsHead::FitsHead(const FitsHead& a)
+{
+ cards_ = new char[a.acard_*FTY_CARDLEN];
+ memmove(cards_, a.cards_, a.acard_*FTY_CARDLEN);
+ mapdata_ = NULL;
+ mapsize_ = 0;
+ memory_ = ALLOC;
+
+ index_ = NULL;
+ acard_ = a.acard_;
+ ncard_ = a.ncard_;
+ ccard_ = a.ccard_;
+
+ valid_ = 1;
+ inherit_ = 0;
+
+ hdu_ = NULL;
+
+ buildIndex();
+ updateHDU();
+}
+
+FitsHead::~FitsHead()
+{
+ if (index_)
+ delete [] index_;
+
+ if (hdu_)
+ delete hdu_;
+
+ switch (memory_) {
+ case ALLOC:
+ if (cards_)
+ delete [] cards_;
+ break;
+ case MMAP:
+#ifndef __WIN32
+ if (mapdata_)
+ munmap((caddr_t)mapdata_, mapsize_);
+#endif
+ break;
+ case SHARE:
+#ifndef __WIN32
+ if (mapdata_)
+ shmdt(mapdata_);
+#endif
+ case EXTERNAL:
+ break;
+ }
+}
+
+int FitsHead::isImage()
+{
+ // just look for SIMPLE, if present it may be of value 'F'
+ char* xtension = getString("XTENSION");
+ char* simple = find("SIMPLE");
+ int r =
+ (simple || (xtension && !strncmp(xtension, "IMAGE", 5))) &&
+ naxes() > 0 &&
+ naxis(0) > 0 &&
+ naxis(1) > 0;
+ return r;
+}
+
+int FitsHead::isTable()
+{
+ char* xtension = getString("XTENSION");
+ int r = (xtension && (!strncmp(xtension, "TABLE", 5) ||
+ !strncmp(xtension, "BINTABLE", 8)));
+ return r;
+}
+
+int FitsHead::isAsciiTable()
+{
+ char* xtension = getString("XTENSION");
+ int r = (xtension && (!strncmp(xtension, "TABLE", 5)));
+ return r;
+}
+
+int FitsHead::isBinTable()
+{
+ char* xtension = getString("XTENSION");
+ int r = (xtension && (!strncmp(xtension, "BINTABLE", 8)));
+ return r;
+}
+
+int FitsHead::isHeap()
+{
+ return getInteger("PCOUNT",0) ? 1 : 0;
+}
+
+void FitsHead::updateHDU()
+{
+ if (hdu_)
+ delete hdu_;
+ hdu_ = NULL;
+
+ // just find simple, it might be present but of value 'F'
+ char* simple = find("SIMPLE");
+ char* xtension = getString("XTENSION");
+
+ if (xtension)
+ inherit_ = getLogical("INHERIT",0);
+
+ if (simple || (xtension && !strncmp(xtension, "IMAGE", 5)))
+ hdu_ = new FitsImageHDU(this);
+
+ if (xtension && !strncmp(xtension, "TABLE", 5))
+ hdu_ = new FitsAsciiTableHDU(this);
+
+ if (xtension && !strncmp(xtension, "BINTABLE", 8))
+ hdu_ = new FitsBinTableHDU(this);
+}
+
+int FitsHead::getLogical(const char* name, int def)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ return c.getLogical();
+ }
+ else
+ return def;
+}
+
+int FitsHead::getInteger(const char* name, int def)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ return c.getInteger();
+ }
+ else
+ return def;
+}
+
+double FitsHead::getReal(const char* name, double def)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ return c.getReal();
+ }
+ else
+ return def;
+}
+
+void FitsHead::getComplex(const char* name, double* real, double* img,
+ double rdef, double idef)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ c.getComplex(real, img);
+ }
+ else {
+ *real = rdef;
+ *img = idef;
+ }
+}
+
+char* FitsHead::getString(const char* name)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ return c.getString();
+ }
+ else
+ return NULL;
+}
+
+char* FitsHead::getComment(const char* name)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ return c.getComment();
+ }
+ else
+ return NULL;
+}
+
+char* FitsHead::getKeyword(const char* name)
+{
+ char* card = find(name);
+ if (card) {
+ FitsCard c(card);
+ return c.getKeyword();
+ }
+ else
+ return NULL;
+}
+
+char* FitsHead::setKey(const char* name, const char* value)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setKey(value);
+
+ buildIndex();
+ return card;
+}
+
+char* FitsHead::setLogical(const char* name, int value, const char* comm)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setLogical(value, comm);
+
+ return card;
+}
+
+char* FitsHead::setInteger(const char* name, int value, const char* comm)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setInteger(value, comm);
+
+ return card;
+}
+
+char* FitsHead::setReal(const char* name, double value, int prec,
+ const char* comm)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setReal(value, prec, comm);
+
+ return card;
+}
+
+char* FitsHead::setComplex(const char* name, double real, double img, int prec,
+ const char* comm)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setComplex(real, img, prec, comm);
+
+ return card;
+}
+
+char* FitsHead::setString(const char* name, const char* value, const char* comm)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setString(value, comm);
+
+ return card;
+}
+
+char* FitsHead::setComment(const char* name, const char* value)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).setComment(value);
+
+ return card;
+}
+
+char* FitsHead::cardins(char* card, char* here)
+{
+ // do we need to allocate another block?
+ if (ncard_+1 > acard_) {
+ switch (memory_) {
+ case ALLOC:
+ {
+ char* old = cards_;
+ int oldsz = acard_*FTY_CARDLEN;
+ int sz = oldsz+FTY_BLOCK;
+
+ acard_ = sz/FTY_CARDLEN;
+ cards_ = new char[sz];
+ memset(cards_, ' ', sz);
+ memcpy(cards_, old, oldsz);
+
+ // don't forget to redirect here if needed
+ if (here) {
+ size_t diff = here-old;
+ here = cards_+diff;
+ }
+ delete [] old;
+ }
+ break;
+ case MMAP:
+ case SHARE:
+ case EXTERNAL:
+ internalError("Fitsy++ head can't add card: readonly memory");
+ return NULL;
+ }
+ }
+
+ char* where = here ? here : cards_+((ncard_-1)*FTY_CARDLEN);
+ memmove(where+FTY_CARDLEN, where, (cards_+(ncard_*FTY_CARDLEN))-where);
+ memmove(where, card, FTY_CARDLEN);
+ ncard_++;
+
+ buildIndex();
+
+ return where;
+}
+
+char* FitsHead::carddel(const char* name)
+{
+ char* card = find(name);
+ if (card) {
+ char* next = card+FTY_CARDLEN;
+ char* last = cards_+((ncard_-1)*FTY_CARDLEN);
+ memmove(card, next, last-card);
+ memset(last,' ', FTY_CARDLEN);
+ }
+
+ buildIndex();
+ return card;
+}
+
+char* FitsHead::cardclear(const char* name)
+{
+ char* card = find(name);
+ if (card)
+ FitsCard(card).clear();
+
+ buildIndex();
+ return card;
+}
+
+char* FitsHead::insertLogical(const char* name, int value, const char* comm,
+ const char* here)
+{
+ FitsCard key;
+ key.setLogical(name, value, comm);
+ return cardins(key.card(), (char*)here);
+}
+
+char* FitsHead::insertInteger(const char* name, int value, const char* comm,
+ const char* here)
+{
+ FitsCard key;
+ key.setInteger(name, value, comm);
+ return cardins(key.card(), (char*)here);
+}
+
+char* FitsHead::insertReal(const char* name, double value, int prec,
+ const char* comm, const char* here)
+{
+ FitsCard key;
+ key.setReal(name, value, prec, comm);
+ return cardins(key.card(), (char*)here);
+}
+
+char* FitsHead::insertComplex(const char* name, double real, double img,
+ int prec, const char* comm, const char* here)
+{
+ FitsCard key;
+ key.setComplex(name, real, img, prec, comm);
+ return cardins(key.card(), (char*)here);
+}
+
+char* FitsHead::insertString(const char* name, const char* value,
+ const char* comm, const char* here)
+{
+ FitsCard key;
+ key.setString(name, value, comm);
+ return cardins(key.card(), (char*)here);
+}
+
+char* FitsHead::insertComment(const char* name, const char* value,
+ const char* here)
+{
+ FitsCard key;
+ key.setComment(name, value);
+ return cardins(key.card(), (char*)here);
+}
+
+char* FitsHead::first()
+{
+ ccard_ = 0;
+ return (ccard_<ncard_) ? &cards_[ccard_*FTY_CARDLEN] : NULL;
+}
+
+char* FitsHead::next()
+{
+ ccard_++;
+ return (ccard_<ncard_) ? &cards_[ccard_*FTY_CARDLEN] : NULL;
+}
+
+char* FitsHead::find(const char* key)
+{
+ if (index_)
+ return findIndex(key);
+ else
+ return findSeq(key);
+}
+
+char* FitsHead::findSeq(const char* key)
+{
+ if (key == NULL)
+ return NULL;
+
+ char k[8];
+ memset(k,' ',8);
+ int len = strlen(key);
+
+ // convert to uppercase
+ int l = (len>8 ? 8 : len);
+ for (int i=0; i<l; i++)
+ k[i] = toupper(key[i]);
+
+ for (char* card=cards_; card!=&cards_[ncard_*FTY_CARDLEN]; card+=FTY_CARDLEN)
+ if (!strncmp(k, card, 8))
+ return card;
+
+ return NULL;
+}
+
+char* FitsHead::findIndex(const char* key)
+{
+ if (key == NULL)
+ return NULL;
+
+ char k[8];
+ memset(k,' ',8);
+ int len = strlen(key);
+
+ // convert to uppercase
+ int l = (len>8 ? 8 : len);
+ for (int i=0; i<l; i++)
+ k[i] = toupper(key[i]);
+
+ char** base = index_;
+ int length = ncard_;
+
+ int lo = -1;
+ int hi = length;
+ int cut = length/2;
+
+ while (hi-lo > 1) {
+ int i = strncmp(k, base[cut], 8);
+ if (!i)
+ return base[cut];
+
+ if (i < 0) {
+ hi = cut;
+ cut = (lo+hi)/2;
+ }
+ else {
+ lo = cut;
+ cut = (lo+hi)/2;
+ }
+ }
+
+ if (!strncmp(k, base[cut], 8))
+ return base[cut];
+
+ return NULL;
+}
+
+static int compare(const void* a, const void* b)
+{
+ char** aa = (char**)a;
+ char** bb = (char**)b;
+ return strncmp(*aa, *bb, 8);
+}
+
+void FitsHead::buildIndex()
+{
+ if (index_)
+ delete [] index_;
+
+ index_ = new char*[ncard_];
+ for (int i=0; i<ncard_; i++)
+ index_[i] = cards_ + (i*FTY_CARDLEN);
+
+ qsort(index_, ncard_, sizeof(char**), compare);
+}
+
diff --git a/fitsy++/head.h b/fitsy++/head.h
new file mode 100644
index 0000000..735a8f5
--- /dev/null
+++ b/fitsy++/head.h
@@ -0,0 +1,133 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitshead_h__
+#define __fitshead_h__
+
+#define FTY_BLOCK 2880
+#define FTY_CARDS (FTY_BLOCK/FTY_CARDLEN)
+
+#include "card.h"
+#include "hdu.h"
+
+class FitsHead {
+ public:
+ enum Memory {ALLOC, EXTERNAL, MMAP, SHARE};
+
+ private:
+ char* cards_; // pointer to start of cards
+ char* mapdata_; // pointer to start of memory segment
+ size_t mapsize_; // size of memory segment
+ Memory memory_; // type memory mangement
+
+ int ncard_; // actual number of cards
+ int acard_; // number of cards block filled
+ int ccard_; // number of current card in seq
+
+ char** index_;
+
+ int valid_;
+ int inherit_;
+
+ FitsHDU* hdu_;
+
+public:
+ FitsHead(char*, size_t, Memory);
+ FitsHead(char*, size_t, char*, size_t, Memory);
+ FitsHead(int width, int height, int depth, int bitpix, char* =NULL);
+ FitsHead(int width, int height, int depth, int bitpix, char*, size_t, Memory);
+ FitsHead(const FitsHead&);
+ ~FitsHead();
+
+ char* cards() {return cards_;}
+ int ncard() {return ncard_;}
+ int acard() {return acard_;}
+ FitsHDU* hdu() {return hdu_;}
+
+ int inherit() {return inherit_;}
+ int isValid() {return valid_;}
+ int isImage();
+ int isTable();
+ int isAsciiTable();
+ int isBinTable();
+ int isHeap();
+ int cardblocks() {return ncard_/FTY_CARDS;}
+ int cardbytes() {return ncard_*FTY_CARDLEN;}
+ int headblocks() {return acard_/FTY_CARDS;}
+ int headbytes() {return acard_*FTY_CARDLEN;}
+
+ const char* extname() {return hdu_ ? hdu_->extname() : NULL;}
+ int extver() {return hdu_ ? hdu_->extver() : 1;}
+ int extlevel() {return hdu_ ? hdu_->extlevel() : 1;}
+ int bitpix() {return hdu_ ? hdu_->bitpix() : 0;}
+ int naxes() {return hdu_ ? hdu_->naxes() : 0;}
+ int naxis(int ii) {return hdu_ ? hdu_->naxis(ii) : 0;}
+
+ size_t realbytes() {return hdu_ ? hdu_->realbytes() : 0;}
+ size_t heapbytes() {return hdu_ ? hdu_->heapbytes() : 0;}
+ size_t allbytes() {return hdu_ ? hdu_->allbytes() : 0;}
+ size_t padbytes() {return hdu_ ? hdu_->padbytes() : 0;}
+ size_t databytes() {return hdu_ ? hdu_->databytes() : 0;}
+ size_t datablocks() {return hdu_ ? hdu_->datablocks() : 0;}
+
+ void buildIndex();
+ void updateHDU();
+ void updateCards() {if (hdu_) hdu_->updateCards(this);}
+
+ char* find(const char* name);
+ char* findSeq(const char* name);
+ char* findIndex(const char* name);
+
+ char* cardins(char* card, char* here);
+ char* carddel(const char* card);
+ char* cardclear(const char* card);
+
+ char* setKey(const char* name, const char* value);
+ char* setLogical(const char* name, int value, const char* comm);
+ char* setInteger(const char* name, int value, const char* comm);
+ char* setReal(const char* name, double value, int prec, const char* comm);
+ char* setComplex(const char* name, double real, double img, int prec,
+ const char* comm);
+ char* setString(const char* name, const char* value, const char* comm);
+ char* setComment(const char* name, const char* value);
+
+ char* insertLogical(const char* name, int value, const char* comm,
+ const char* here);
+ char* insertInteger(const char* name, int value, const char* comm,
+ const char* here);
+ char* insertReal(const char* name, double value,
+ int prec, const char* comm, const char* here);
+ char* insertComplex(const char* name, double real, double img,
+ int prec, const char* comm, const char* here);
+ char* insertString(const char* name, const char* value, const char* comm,
+ const char* here);
+ char* insertComment(const char* name, const char* value, const char* here);
+
+ char* appendLogical(const char* name, int value, const char* comm)
+ {return insertLogical(name, value, comm, NULL);}
+ char* appendInteger(const char* name, int value, const char* comm)
+ {return insertInteger(name, value, comm, NULL);}
+ char* appendReal(const char* name, double value, int prec, const char* comm)
+ {return insertReal(name, value, prec, comm, NULL);}
+ char* appendComplex(const char* name, double real, double img,
+ int prec, const char* comm)
+ {return insertComplex(name, real, img, prec, comm, NULL);}
+ char* appendString(const char* name, const char* value, const char* comm)
+ {return insertString(name, value, comm, NULL);}
+
+ int getLogical(const char* name, int def);
+ int getInteger(const char* name, int def);
+ double getReal(const char* name, double def);
+ void getComplex(const char* name, double* real, double* img,
+ double rdef, double idef);
+ char* getString(const char* name);
+ char* getComment(const char* name);
+
+ char* getKeyword(const char* name);
+
+ char* first();
+ char* next();
+};
+
+#endif
diff --git a/fitsy++/hist.C b/fitsy++/hist.C
new file mode 100644
index 0000000..afd71aa
--- /dev/null
+++ b/fitsy++/hist.C
@@ -0,0 +1,686 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <string.h>
+#include <ctype.h>
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "hist.h"
+#include "util.h"
+
+#include "fitsy.h"
+#include "filter.h"
+
+#ifdef __CYGWIN__
+// limit size, cygwin pipe to 64K / (4 args x 4 bytes)
+#define FILTERSIZE 2048
+#else
+#define FILTERSIZE 65536
+#endif
+#define MULTWCS 27
+
+char *gerrorstring(void);
+
+static const char* reservedKeywords[] = {
+ "SIMPLE","XTENSION","ZSIMPLE","ZTENSION","ZIMAGE","ZTABLE",
+ "BITPIX","ZBITPIX",
+ "NAXIS","ZNAXIS",
+ "NAXIS.","ZNAXIS.",
+ "END",
+ "PCOUNT","ZPCOUNT",
+ "GCOUNT","ZGCOUNT",
+ "CHECKSUM","ZHECKSUM",
+ "DATASUM","ZDATASUM",
+ /* "OBJECT", */
+ "INHERIT",
+ "BSCALE",
+ "BZERO","TZERO.",
+ /* "BUNIT", */ "TUNIT.",
+ "BLANK",
+ "DATAMAX","TDMAX.","TLMAX.",
+ "DATAMIN","TDMIN.","TLMIN.",
+ "BLOCKED","ZBLOCKED",
+ "EXTENDED","ZEXTEND",
+
+ "EXTNAME","ZNAME.",
+ "EXTVER",
+ "EXTLEVEL",
+
+ "TFIELDS",
+ "TFORM.","ZFORM.",
+ "TBCOL.",
+
+ "ZCMPTYPE","ZCTYP.","ZTILELEN","ZTILE.","ZVAL.",
+ "ZMASKCMP","ZQUANTIZ","ZDITHER0","ZTHEAP",
+ "TSCAL.","TNULL.","TTYPE.","TDISP.", "TDIM.","THEAP",
+ "FZTILELN","FZALGOR","FZALG.",
+ "PTYPE.","PSCAL.","PZERO.",
+
+ "WCSAXES.","WCSAX.?",
+ /* "CTYPE.?", */ ".CTYP.",".CTY.?","TCTYP.","TCTY.?",
+ /* "CUNIT.?", */ ".CUNI.",".CUN.?","TCUNI.","TCUN.?",
+ /* "CRVAL.?", */ ".CRVL.",".CRV.?","TCRVL.","TCRV.?",
+ /* "CDELT.?", */ ".CDLT.",".CDE.?","TCDLT.","TCDE.?",
+ /* "CRPIX.?", */ ".CRPX.",".CRP.?","TCRPX.","TCRP.?",
+ /* "CROTA.", */ ".CROT.","TCROT.",
+ /* "PC._.?", */ "..PC.?","TPC._.?","TP._.?",
+ /* "CD._.?", */ "..CD.?","TCD._.?","TC._.?",
+ "PV._.?",".PV._.?",".V._.?","TPV._.?","TV._.?",
+ ".V._X?",
+ "PS._.?",".PS._.?",".S._.?","TPS._.?","TS._.?",
+ "WCSNAME?","WCSN.?","WCS.?","TWCS.?",
+ "CNAME.?",".CNA.?","TCNA.?",
+ "CRDER.?",".CRD.?","TCRD.?",
+ "CSYER.?",".CSY.?","TCSY.?",
+ "WCST.?",
+ "WCSX.?",
+ /* "LONPOLE?", */ "LONP.?",
+ /* "LATPOLE?", */ "LATP.?",
+ /* "EQUINOX?", */ "EQUI.?",
+ /* "EPOCH", */
+ /* "RADESYS", */ "REDE.?",
+ "RESTFRQ?","RFRQ.?",
+ "RESTWAV?","RWAV.?",
+ "SPECSYS?","SPEC.?",
+ "SSYSOBS?","SOBS.?",
+ "SSYSSRC?","SSRC.?",
+ "OBSGEO-X","OBSGX.",
+ "OBSGEO-Y","OBSGY.",
+ "OBSGEO-Z","OBSGZ.",
+ "VELOSYS?","VSYS.?",
+ "ZSOURCE?","ZSOU.?",
+ "VELANGL?","VANG.?",
+
+ /* "DATE",*/
+ /* "DATE-OBS", */ "DOBS.",
+ /* "MJD-OBS", */ "MJDOB.",
+ "BEPOCH",
+ "JEPOCH",
+ /* "DATE-AVE", */ "DAVG.",
+ /* "MJD-AVG", */ "MJDA.",
+ /* "DATE-BEG", */
+ /* "MJD-BEG", */
+ /* "TSTART", "TSTOP", */
+ /* "DATE-END", */
+ /* "MJD-END", */
+ "XPOSURE",
+ "TELAPSE",
+ /* "TIMESYS",*/
+ /* "MJDREF",*/
+ /* "JDREF",*/
+ /* "DATEREF",*/
+ "TREFPOS","TRPOS.",
+ "TREFDIR","TRDIR.",
+ "PLEPHEM",
+ /* "TIMEUNIT",*/
+ /* "TIMEOFFS",*/
+ /* "TIMSYER",*/
+ /* "TIMRDER",*/
+ /* "TIMEDEL",*/
+ /* "TIMEPIXR",*/
+ "CZPHS",".CZPH.",".CZP.?","TCZPH.","TCZP.?",
+ "CPERI",".CPER.",".CPR.?","TCPER.","TCPR.?"
+};
+
+FitsHist::FitsHist(FitsFile* fits, int w, int h, int d,
+ Matrix& m, Function func, Vector block)
+ : width_(w), height_(h), depth_(d)
+{
+ size_ = (size_t)width_*height_*depth_;
+
+ xcol_ = NULL;
+ ycol_ = NULL;
+ zcol_ = NULL;
+
+ fitsy_ = NULL;
+ filter_ = NULL;
+
+ valid_ = 0;
+
+ if (!initHeader(fits))
+ return;
+
+ // we need to translate by another .5 for the offset from Data to Image
+ Matrix mm = m * Translate(.5,.5);
+
+ initLTMV(mm);
+ initWCS(fits, mm, block);
+
+ initFilter(fits);
+ bin(fits, m, func, block);
+
+ if (byteswap_)
+ swap();
+
+ deleteFilter();
+ valid_ = 1;
+}
+
+FitsHist::~FitsHist()
+{
+ if (data_)
+ delete [] (float*)data_;
+}
+
+int FitsHist::initHeader(FitsFile* fits)
+{
+ FitsHead* srcHead = fits->head();
+ FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu());
+
+ // make sure we have a table with columns, X, Y
+ if (!fits->isBinTable())
+ return 0;
+
+ // make sure we have rows and cols
+ if (!srcHDU->width() || !srcHDU->rows())
+ return 0;
+
+ // get X column
+ if (fits->pBinX())
+ xcol_ = srcHDU->find(fits->pBinX());
+
+ if (!xcol_)
+ return 0;
+
+ // get Y column
+ if (fits->pBinY())
+ ycol_ = srcHDU->find(fits->pBinY());
+
+ if (!ycol_)
+ return 0;
+
+ // get Z column (if specified)
+ if (fits->pBinZ() && depth_ > 1)
+ zcol_ = srcHDU->find(fits->pBinZ());
+ else
+ zcol_ = NULL;
+
+ // create header
+ head_ = new FitsHead(width_, height_, depth_, -32);
+ if (!head_->isValid())
+ return 0;
+
+ // now screen other KEYWORDS for addition
+ char* cc = srcHead->first();
+ while (cc) {
+ if (screenKeyword(cc))
+ head_->cardins(cc, (char*)NULL);
+ cc = srcHead->next();
+ }
+
+ // MJD-OBJ deprecated
+ double rr = srcHead->getReal("MJD_OBS",0);
+ if (rr)
+ head_->appendReal("MJD-OBS", rr, 10, NULL);
+
+ // we added cards
+ head_->updateHDU();
+
+ return 1;
+}
+
+static int mstrcmp(const char* s1, const char* s2)
+{
+ const char* p1 = s1;
+ const char* p2 = s2;
+ while (*p1 != '\0') {
+ if (*p1 == '?')
+ return 0;
+
+ if (*p2=='\0')
+ return 1;
+ if (*p1 != '.') {
+ if (*p2>*p1)
+ return -1;
+ if (*p2<*p1)
+ return 1;
+ }
+ else {
+ if (*p2<'0' || *p2>'9')
+ return 1;
+ p2++;
+ if (*p2<'0' || *p2>'9')
+ p2--;
+ }
+
+ p1++;
+ p2++;
+ }
+
+ if (*p2 != '\0')
+ return -1;
+
+ return 0;
+}
+
+int FitsHist::screenKeyword(const char* cc)
+{
+ int cnt= sizeof(reservedKeywords)/sizeof(const char*);
+
+ char key[9];
+ memset(key,0,9);
+ strncpy(key,cc,8);
+ for (int ii=8; ii>=0; ii--)
+ if (key[ii]==' ')
+ key[ii] = '\0';
+
+ const char** ptr = reservedKeywords;
+ for (int ii=0; ii<cnt; ii++) {
+ if (!mstrcmp(*ptr,key))
+ return 0;
+ ptr++;
+ }
+
+ return 1;
+}
+
+void FitsHist::initFilter(FitsFile* fits)
+{
+ FitsHead* srcHead = fits->head();
+
+ const char* filtstr = fits->pFilter();
+ if (filtstr && *filtstr) {
+
+ ostringstream str;
+ str << "bincols=(" << fits->pBinX() << ',' << fits->pBinY() << ')';
+
+ if (byteswap_)
+ str << ",convert=true";
+ str << ends;
+
+ if (!(fitsy_ = ft_headinit(srcHead->cards(), srcHead->headbytes())))
+ internalError("Fitsy++ hist bad filter head");
+ else {
+ if (!(filter_ = FilterOpen((FITSHead)fitsy_, (char*)filtstr,
+ (char*)str.str().c_str()))){
+ internalError("Fitsy++ hist unable to build filter");
+ }
+ }
+ }
+}
+
+void FitsHist::deleteFilter()
+{
+ if (filter_) {
+ FilterClose((Filter)filter_);
+ filter_ = NULL;
+ }
+
+ if (fitsy_) {
+ ft_headfree((FITSHead)fitsy_,0);
+ fitsy_ = NULL;
+ }
+}
+
+void FitsHist::bin(FitsFile* fits, Matrix& m, Function func, Vector block)
+{
+ FitsHead* srcHead = fits->head();
+ FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu());
+
+ // create image space
+ float* dest = new float[size_];
+ memset(dest, 0, size_*sizeof(float));
+
+ // bin it up
+ char* ptr = (char*)fits->data();
+ int rowlen = srcHDU->width();
+ int rows = srcHDU->rows();
+
+ // third dimension
+ double zmin;
+ double zlength;
+ if (zcol_) {
+ zmin = zcol_->getMin();
+ zlength = zcol_->getMax() - zcol_->getMin();
+ }
+
+ // filter
+ int goodincr = 0;
+ int goodindex = FILTERSIZE;
+ int* good = NULL;
+ if (filter_)
+ good = new int[FILTERSIZE];
+
+ // matrix
+ register double m00 = m.matrix(0,0);
+ register double m10 = m.matrix(1,0);
+ register double m20 = m.matrix(2,0);
+ register double m01 = m.matrix(0,1);
+ register double m11 = m.matrix(1,1);
+ register double m21 = m.matrix(2,1);
+
+ for (int ii=0; ii<rows; ii++, ptr+=rowlen, goodindex++) {
+
+ // incr filter block, if needed
+ if (good && (goodindex>=FILTERSIZE)) {
+ // for memory models that support internal paging
+ // need at lease FILTERSIZE rows
+ ptr = fits->page(ptr, rowlen*FILTERSIZE);
+
+ int diff = srcHDU->rows() - (goodincr * FILTERSIZE);
+ if (FilterEvents((Filter)filter_, ptr, srcHDU->width(),
+ (diff<FILTERSIZE) ? diff : FILTERSIZE, good)) {
+ goodincr++;
+ goodindex = 0;
+ }
+ else {
+ if (good)
+ delete [] good;
+ good = NULL;
+ internalError("Fitsy++ hist filter failed");
+ }
+ }
+ else {
+ // for memory models that support internal paging
+ // all we need is just one row
+ ptr = fits->page(ptr, rowlen);
+ }
+
+ if (!good || (good && good[goodindex])) {
+ register double x = xcol_->value(ptr);
+ register double y = ycol_->value(ptr);
+
+ register double X = x*m00 + y*m10 + m20;
+ register double Y = x*m01 + y*m11 + m21;
+
+ if (X >= 0 && X < width_ && Y >= 0 && Y < height_) {
+ if (!zcol_)
+ dest[((int)Y)*width_ + (int)X]++;
+ else {
+ int zz = (int)((zcol_->value(ptr)-zmin)/zlength*depth_);
+ if (zz>=0 && zz<depth_)
+ dest[(zz*width_*height_) + ((int)Y)*width_ + (int)X]++;
+ }
+ }
+ }
+ }
+
+ // for memory models that support internal paging
+ fits->resetpage();
+
+ // Average
+ if (func==AVERAGE)
+ for (size_t kk=0; kk<size_; kk++)
+ dest[kk] /= (block[0]*block[1]);
+
+ if (good)
+ delete [] good;
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+}
+
+void FitsHist::swap()
+{
+ if (!data_)
+ return;
+
+ // we now need to byteswap back to native form
+ float* dest = (float*)data_;
+ for (size_t ii=0; ii<size_; ii++) {
+ const char* p = (char*)(dest+ii);
+ union {
+ char c[4];
+ float f;
+ } u;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ dest[ii] = u.f;
+ }
+}
+
+void FitsHist::initLTMV(Matrix& m)
+{
+ head_->appendReal("LTM1_1", m[0][0], 10, NULL);
+ head_->appendReal("LTM1_2", m[0][1], 10, NULL);
+ head_->appendReal("LTM2_1", m[1][0], 10, NULL);
+ head_->appendReal("LTM2_2", m[1][1], 10, NULL);
+ head_->appendReal("LTV1" , m[2][0], 10, NULL);
+ head_->appendReal("LTV2" , m[2][1], 10, NULL);
+}
+
+void FitsHist::mapWCSString(FitsHead* head, char* w,
+ const char* out, const char* prim)
+{
+ ostringstream istr;
+ istr << prim << xcol_->index() << w << ends;
+
+ if (head->find(istr.str().c_str())) {
+ char* str = head->getString(istr.str().c_str());
+ head_->appendString(out, str, NULL);
+ }
+}
+
+void FitsHist::mapWCSString(FitsHead* head, char* w,
+ const char* out, const char* prim, const char* alt)
+{
+ ostringstream istr1, istr2, istr3;
+ if (!w[0]) {
+ istr1 << prim << xcol_->index() << w << ends;
+ istr2 << prim << ycol_->index() << w << ends;
+ if (zcol_)
+ istr3 << prim << zcol_->index() << w << ends;
+ }
+ else {
+ istr1 << alt << xcol_->index() << w << ends;
+ istr2 << alt << ycol_->index() << w << ends;
+ if (zcol_)
+ istr3 << alt << zcol_->index() << w << ends;
+ }
+ ostringstream ostr1, ostr2, ostr3;
+ ostr1 << out << "1" << w << ends;
+ ostr2 << out << "2" << w << ends;
+ if (zcol_)
+ ostr3 << out << "3" << w << ends;
+
+ if (head->find(istr1.str().c_str())) {
+ char* cc1 = head->getString(istr1.str().c_str());
+ head_->appendString(ostr1.str().c_str(), cc1, NULL);
+ }
+ if (head->find(istr2.str().c_str())) {
+ char* cc2 = head->getString(istr2.str().c_str());
+ head_->appendString(ostr2.str().c_str(), cc2, NULL);
+ }
+ if (zcol_) {
+ if (head->find(istr3.str().c_str())) {
+ char* cc3 = head->getString(istr3.str().c_str());
+ head_->appendString(ostr3.str().c_str(), cc3, NULL);
+ }
+ }
+}
+
+void FitsHist::mapWCSReal(FitsHead* head, const char* out, const char* in)
+{
+ ostringstream istr;
+ istr << in << xcol_->index() << ends;
+
+ if (head->find(istr.str().c_str())) {
+ float cc = head->getReal(istr.str().c_str(), 0);
+ head_->appendReal(out, cc, 10, NULL);
+ }
+}
+
+void FitsHist::mapWCSReal(FitsHead* head, char* w,
+ const char* out, const char* in)
+{
+ ostringstream istr;
+ istr << in << xcol_->index() << w << ends;
+
+ if (head->find(istr.str().c_str())) {
+ float cc = head->getReal(istr.str().c_str(), 0);
+ head_->appendReal(out, cc, 10, NULL);
+ }
+}
+
+void FitsHist::mapWCSReal(FitsHead* head, char* w,
+ const char* out, const char* prim, const char* alt,
+ Matrix mm)
+{
+ ostringstream istr1, istr2, istr3;
+ if (!w[0]) {
+ istr1 << prim << xcol_->index() << w << ends;
+ istr2 << prim << ycol_->index() << w << ends;
+ if (zcol_)
+ istr3 << prim << zcol_->index() << w << ends;
+ }
+ else {
+ istr1 << alt << xcol_->index() << w << ends;
+ istr2 << alt << ycol_->index() << w << ends;
+ if (zcol_)
+ istr3 << alt << zcol_->index() << w << ends;
+ }
+ ostringstream ostr1, ostr2, ostr3;
+ ostr1 << out << "1" << w << ends;
+ ostr2 << out << "2" << w << ends;
+ if (zcol_)
+ ostr3 << out << "3" << w << ends;
+
+ if (head->find(istr1.str().c_str()) || head->find(istr2.str().c_str())) {
+ float cc1 = head->getReal(istr1.str().c_str(),0);
+ float cc2 = head->getReal(istr2.str().c_str(),0);
+ Vector cc = Vector(cc1,cc2) * mm;
+
+ head_->appendReal(ostr1.str().c_str(), cc[0], 10, NULL);
+ head_->appendReal(ostr2.str().c_str(), cc[1], 10, NULL);
+ }
+
+ if (zcol_) {
+ if (head->find(istr3.str().c_str())) {
+ float cc3 = head->getReal(istr3.str().c_str(),0);
+ head_->appendReal(ostr3.str().c_str(), cc3, 10, NULL);
+ }
+ }
+}
+
+void FitsHist::mapWCSMatrix(FitsHead* head, char* w,
+ const char* out, const char* in,
+ Vector vv)
+{
+ ostringstream istr1, istr2, istr3, istr4;
+ istr1 << in << xcol_->index() << "_" << xcol_->index() << w << ends;
+ istr2 << in << xcol_->index() << "_" << ycol_->index() << w << ends;
+ istr3 << in << ycol_->index() << "_" << xcol_->index() << w << ends;
+ istr4 << in << ycol_->index() << "_" << ycol_->index() << w << ends;
+
+ ostringstream ostr1, ostr2, ostr3, ostr4;
+ ostr1 << out << "1_1" << w << ends;
+ ostr2 << out << "1_2" << w << ends;
+ ostr3 << out << "2_1" << w << ends;
+ ostr4 << out << "2_2" << w << ends;
+
+ if (head->find(istr1.str().c_str()) ||
+ head->find(istr2.str().c_str()) ||
+ head->find(istr3.str().c_str()) ||
+ head->find(istr4.str().c_str())) {
+ float cc11 = head->getReal(istr1.str().c_str(), 0);
+ float cc12 = head->getReal(istr2.str().c_str(), 0);
+ float cc21 = head->getReal(istr3.str().c_str(), 0);
+ float cc22 = head->getReal(istr4.str().c_str(), 0);
+ Matrix cc = Matrix(cc11*vv[0], cc12*vv[0],
+ cc21*vv[1], cc22*vv[1],
+ 0, 0);
+ head_->appendReal(ostr1.str().c_str(), cc[0][0], 10, NULL);
+ head_->appendReal(ostr2.str().c_str(), cc[0][1], 10, NULL);
+ head_->appendReal(ostr3.str().c_str(), cc[1][0], 10, NULL);
+ head_->appendReal(ostr4.str().c_str(), cc[1][1], 10, NULL);
+ }
+}
+
+void FitsHist::mapWCSVector(FitsHead* head, char* w,
+ const char* out, const char* in)
+{
+ for (int ii=0; ii<=9; ii++) {
+ ostringstream istr1, istr2;
+ istr1 << in << xcol_->index() << "_" << ii << w << ends;
+ istr2 << in << ycol_->index() << "_" << ii << w << ends;
+
+ ostringstream ostr1, ostr2;
+ ostr1 << out << "1_" << ii << ends;
+ ostr2 << out << "2_" << ii << ends;
+
+ if (head->find(istr1.str().c_str()) ||
+ head->find(istr2.str().c_str())) {
+ float cc1 = head->getReal(istr1.str().c_str(), 0);
+ float cc2 = head->getReal(istr2.str().c_str(), 0);
+ head_->appendReal(ostr1.str().c_str(), cc1, 10, NULL);
+ head_->appendReal(ostr2.str().c_str(), cc2, 10, NULL);
+ }
+ }
+}
+
+void FitsHist::initWCS(FitsFile* fits, Matrix& mm, Vector block)
+{
+ FitsHead* srcHead = fits->head();
+ char w[2];
+ w[1] = '\0';
+
+ for (int i=0; i<MULTWCS; i++) {
+ if (!i)
+ w[0] = '\0';
+ else
+ w[0] = '@'+i;
+
+ mapWCSString(srcHead, w, "CTYPE", "TCTYP", "TCTY");
+ mapWCSString(srcHead, w, "CUNIT", "TCUNI", "TCUN");
+ mapWCSReal(srcHead, w, "CRVAL", "TCRVL", "TCRV", Matrix());
+ mapWCSReal(srcHead, w, "CDELT", "TCDLT", "TCDE", Scale(block));
+ mapWCSReal(srcHead, w, "CRPIX", "TCRPX", "TCRP", mm);
+ mapWCSReal(srcHead, w, "CROTA", "TCROT", "TCRO", Matrix());
+
+ mapWCSMatrix(srcHead, w, "PC", "TP", Vector(1,1));
+ mapWCSMatrix(srcHead, w, "CD", "TC", block);
+ mapWCSVector(srcHead, w, "PV", "TV");
+ mapWCSVector(srcHead, w, "PS", "TS");
+ mapWCSString(srcHead, w, "WCSNAME", "TWCS");
+
+ // alt
+ mapWCSMatrix(srcHead, w, "PC", "TPC", Vector(1,1));
+ mapWCSMatrix(srcHead, w, "CD", "TCD", block);
+ mapWCSVector(srcHead, w, "PV", "TPV");
+ mapWCSVector(srcHead, w, "PS", "TPS");
+ mapWCSString(srcHead, w, "WCSNAME", "WCS");
+
+ mapWCSReal(srcHead, w, "LONPOLE", "LONP");
+ mapWCSReal(srcHead, w, "LATPOLE", "LATP");
+ if (!head_->find("EQUINOX"))
+ mapWCSReal(srcHead, w, "EQUINOX", "EQUI");
+ if (!head_->find("MJD-OBS"))
+ mapWCSReal(srcHead, "MJD-OBS", "MJDOB");
+ if (!head_->find("RADESYS"))
+ mapWCSString(srcHead, w, "RADESYS", "RADE");
+
+ // general
+ mapWCSString(srcHead, w, "BUNIT", "TUNIT");
+ }
+}
+
+FitsHistNext::FitsHistNext(FitsFile* prev)
+{
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = prev->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ return;
+}
diff --git a/fitsy++/hist.h b/fitsy++/hist.h
new file mode 100644
index 0000000..4def2a2
--- /dev/null
+++ b/fitsy++/hist.h
@@ -0,0 +1,59 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitshist_h__
+#define __fitshist_h__
+
+#include "vector.h"
+#include "file.h"
+
+class FitsHist : public FitsFile {
+ public:
+ enum Function {SUM, AVERAGE};
+
+ private:
+ int width_;
+ int height_;
+ int depth_;
+ size_t size_;
+
+ FitsColumn* xcol_;
+ FitsColumn* ycol_;
+ FitsColumn* zcol_;
+
+ void* fitsy_;
+ void* filter_;
+
+ int initHeader(FitsFile*);
+ int screenKeyword(const char*);
+ void initLTMV(Matrix&);
+ void initWCS(FitsFile*, Matrix&, Vector);
+ void mapWCSMatrix(FitsHead*, char* w, const char* out, const char* in,
+ Vector);
+ void mapWCSReal(FitsHead* head, const char* out, const char* in);
+ void mapWCSReal(FitsHead* head, char* w, const char* out, const char* in);
+ void mapWCSReal(FitsHead*, char* w,
+ const char* out, const char* prim, const char* alt,
+ Matrix);
+ void mapWCSString(FitsHead*, char* w, const char* out, const char* prim);
+ void mapWCSString(FitsHead*, char* w,
+ const char* out, const char* prim, const char* alt);
+ void mapWCSVector(FitsHead*, char* w, const char* out, const char* in);
+ void initFilter(FitsFile*);
+ void deleteFilter();
+ void bin(FitsFile*, Matrix&, Function, Vector);
+ void swap();
+
+ public:
+ FitsHist(FitsFile* src, int width, int height, int depth,
+ Matrix& m, Function func, Vector block);
+ ~FitsHist();
+};
+
+class FitsHistNext : public FitsFile {
+public:
+ FitsHistNext(FitsFile* prev);
+};
+
+#endif
diff --git a/fitsy++/hpx.C b/fitsy++/hpx.C
new file mode 100644
index 0000000..e2e0774
--- /dev/null
+++ b/fitsy++/hpx.C
@@ -0,0 +1,588 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+// This source has been modified from the original authored by
+// Dr. Mark Calabretta as distributed with WCSLIBS under GNU GPL version 3
+// WCSLIB 4.7 - an implementation of the FITS WCS standard.
+// Copyright (C) 1995-2011, Mark Calabretta
+
+#include <string.h>
+#include <ctype.h>
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "hpx.h"
+#include "util.h"
+#include "fitsy.h"
+
+FitsHPX::FitsHPX(FitsFile* fits, Order oo, CoordSys ss, Layout ll,
+ int cc, int qq)
+ : order_(oo), coord_(ss), layout_(ll), quad_(qq)
+{
+ FitsHead* head = fits->head();
+ FitsTableHDU* hdu = (FitsTableHDU*)(head->hdu());
+ col_ = (FitsBinColumn*)hdu->find(cc);
+ if (!col_)
+ return;
+
+ int nrow = hdu->rows();
+ int nelem = col_->repeat();
+
+ nside_ = head->getInteger("NSIDE",0);
+ long firstpix = head->getInteger("FIRSTPIX",-1);
+ long lastpix = head->getInteger("LASTPIX",-1);
+
+ if (!nside_) {
+ // Deduce NSIDE
+ if (lastpix >= 0) {
+ // If LASTPIX is present without NSIDE we can only assume it's npix.
+ nside_ = (int)(sqrt((double)((lastpix+1) / 12)) + 0.5);
+ }
+ else if (nrow)
+ nside_ = (int)(sqrt((double)((nrow * nelem) / 12)) + 0.5);
+ }
+
+ long npix = 12*nside_*nside_;
+
+ if (firstpix < 0)
+ firstpix = 0;
+ if (lastpix < 0)
+ lastpix = npix - 1;
+
+ build(fits);
+
+ if (byteswap_)
+ swap();
+
+ valid_ = 1;
+}
+
+FitsHPX::~FitsHPX()
+{
+ if (data_)
+ delete [] (float*)data_;
+}
+
+void FitsHPX::build(FitsFile* fits)
+{
+ // Number of facets on a side of each layout
+ const int NFACET[] = {5, 4, 4};
+
+ // Arrays that define the facet location and rotation for each recognised
+ // layout. Bear in mind that these appear to be upside-down, i.e. the top
+ // line contains facet numbers for the bottom row of the output image.
+ // Facets numbered -1 are blank.
+
+ // Equatorial (diagonal) facet layout.
+ const int FACETS[][5][5] = {{{ 6, 9, -1, -1, -1},
+ { 1, 5, 8, -1, -1},
+ {-1, 0, 4, 11, -1},
+ {-1, -1, 3, 7, 10},
+ {-1, -1, -1, 2, 6}},
+ // North polar (X) facet layout.
+ {{ 8, 4, 4, 11, -1},
+ { 5, 0, 3, 7, -1},
+ { 5, 1, 2, 7, -1},
+ { 9, 6, 6, 10, -1},
+ {-1, -1, -1, -1, -1}},
+ // South polar (X) facet layout.
+ {{ 1, 6, 6, 2, -1},
+ { 5, 9, 10, 7, -1},
+ { 5, 8, 11, 7, -1},
+ { 0, 4, 4, 3, -1},
+ {-1, -1, -1, -1, -1}}};
+
+ // All facets of the equatorial layout are rotated by +45 degrees with
+ // respect to the normal orientation, i.e. that with the equator running
+ // horizontally. The rotation recorded for the polar facets is the number
+ // of additional positive (anti-clockwise) 90 degree turns with respect to
+ // the equatorial layout.
+
+ // Equatorial (diagonal), no facet rotation.
+ const int FROTAT[][5][5] = {{{ 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0}},
+ // North polar (X) facet rotation.
+ {{ 3, 3, 0, 0, 0},
+ { 3, 3, 0, 0, 0},
+ { 2, 2, 1, 1, 0},
+ { 2, 2, 1, 1, 0},
+ { 0, 0, 0, 0, 0}},
+ // South polar (X) facet rotation.
+ {{ 1, 1, 2, 2, 0},
+ { 1, 1, 2, 2, 0},
+ { 0, 0, 3, 3, 0},
+ { 0, 0, 3, 3, 0},
+ { 0, 0, 0, 0, 0}}};
+
+ // Facet halving codes. 0: the facet is whole (or wholly blank),
+ // 1: blanked bottom-right, 2: top-right, 3: top-left, 4: bottom-left.
+ // Positive values mean that the diagonal is included, otherwise not.
+
+ // Equatorial (diagonal), no facet halving.
+ const int FHALVE[][5][5] = {{{ 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0}},
+ // North polar (X) facet halving.
+ {{ 0, 1, -4, 0, 0},
+ {-3, 0, 0, 2, 0},
+ { 4, 0, 0, -1, 0},
+ { 0, -2, 3, 0, 0},
+ { 0, 0, 0, 0, 0}},
+ // South polar (X) facet halving.
+ {{ 0, 1, -4, 0, 0},
+ {-3, 0, 0, 2, 0},
+ { 4, 0, 0, -1, 0},
+ { 0, -2, 3, 0, 0},
+ { 0, 0, 0, 0, 0}}};
+
+ FitsHead* head = fits->head();
+ FitsTableHDU* hdu = (FitsTableHDU*)(head->hdu());
+ int rowlen = hdu->width();
+ int nrow = hdu->rows();
+ int repeat = col_->repeat();
+ char* data = (char*)fits->data();
+
+ int nside = nside_;
+ int layout = layout_;
+ int nfacet = NFACET[layout];
+
+ pWidth_ = nfacet*nside;
+ pHeight_ = pWidth_;
+
+ // create image space
+ size_t pSize = (size_t)pWidth_*pHeight_;
+ float* dest = new float[pSize];
+ for (longlong ii=0; ii<pSize; ii++)
+ dest[ii] = NAN;
+
+ // Write WCS keyrecords
+ initHeader(fits);
+
+ // Allocate arrays
+ long healidx[nside];
+ float row[nside];
+
+ // Loop vertically facet-by-facet.
+ longlong fpixel = 1;
+ // longlong group = 0;
+ longlong nelem = (longlong)nside;
+ for (int jfacet = 0; jfacet<nfacet; jfacet++) {
+ // Loop row-by-row.
+ for (int jj = 0; jj<nside; jj++) {
+ // Loop horizontally facet-by-facet
+ for (int ifacet = 0; ifacet<nfacet; ifacet++) {
+ int facet = FACETS[layout][jfacet][ifacet];
+ int rotn = FROTAT[layout][jfacet][ifacet];
+ int halve = FHALVE[layout][jfacet][ifacet];
+
+ // Recentre longitude?
+ if (quad_ && facet >= 0) {
+ if (facet <= 3) {
+ facet += quad_;
+ if (facet > 3) facet -= 4;
+ }
+ else if (facet <= 7) {
+ facet += quad_;
+ if (facet > 7) facet -= 4;
+ }
+ else {
+ facet += quad_;
+ if (facet > 11) facet -= 4;
+ }
+ }
+
+ // Write out the data
+ if (facet < 0)
+ ;
+ else {
+ switch (order_) {
+ case NESTED:
+ NESTidx(nside, facet, rotn, jj, healidx);
+ break;
+ case RING:
+ RINGidx(nside, facet, rotn, jj, healidx);
+ break;
+ }
+
+ // Gather data into the output vector.
+ /*
+ long* healp = healidx;
+ for (float* rowp = row; rowp < row+nside; rowp++)
+ *rowp = col_->value(data+*(healp++),0);
+ */
+ for (int ii=0; ii<nside_; ii++) {
+ int aa = healidx[ii]/repeat;
+ int bb = healidx[ii] - (aa*repeat);
+ if (aa<nrow)
+ row[ii] = col_->value(data+aa*rowlen,bb);
+ else
+ row[ii] = 0;
+ }
+
+ // Apply blanking to halved facets.
+ if (halve) {
+ int i1;
+ int i2;
+ if (abs(halve) == 1) {
+ // Blank bottom-right.
+ i1 = jj;
+ i2 = nside;
+ if (halve > 0)
+ i1++;
+ } else if (abs(halve) == 2) {
+ // Blank top-right.
+ i1 = nside - jj;
+ i2 = nside;
+ if (halve < 0)
+ i1--;
+ } else if (abs(halve) == 3) {
+ // Blank top-left.
+ i1 = 0;
+ i2 = jj;
+ if (halve < 0)
+ i2++;
+ } else {
+ // Blank bottom-left.
+ i1 = 0;
+ i2 = nside - jj;
+ if (halve > 0)
+ i2--;
+ }
+
+ for (float* rowp = row+i1; rowp < row+i2; rowp++)
+ *rowp = NAN;
+ }
+
+ // Write out this facet's contribution to this row of the map.
+ memcpy(dest+fpixel-1, row, nside*sizeof(float));
+ }
+
+ fpixel += nelem;
+ }
+ }
+ }
+
+ data_ = dest;
+
+ dataSize_ = pSize;
+ dataSkip_ = 0;
+}
+
+// (imap,jmap) are 0-relative pixel coordinates in the output map with origin
+// at the bottom-left corner of the specified facet which is rotated by
+// (45 + rotn * 90) degrees from its natural orientation; imap increases to
+// the right and jmap upwards.
+
+void FitsHPX::NESTidx(int nside, int facet, int rotn, int jmap, long *healidx)
+{
+ // Nested index (0-relative) of the first pixel in this facet.
+ int hh = facet*nside*nside;
+
+ int nside1 = nside - 1;
+ long* hp = healidx;
+ for (int imap = 0; imap < nside; imap++, hp++) {
+ // (ii,jj) are 0-relative pixel coordinates with origin in the southern
+ // corner of the facet; i increases to the north-east and j to the
+ // north-west.
+ int ii =0;
+ int jj =0;
+ if (rotn == 0) {
+ ii = nside1 - imap;
+ jj = jmap;
+ }
+ else if (rotn == 1) {
+ ii = nside1 - jmap;
+ jj = nside1 - imap;
+ }
+ else if (rotn == 2) {
+ ii = imap;
+ jj = nside1 - jmap;
+ }
+ else if (rotn == 3) {
+ ii = jmap;
+ jj = imap;
+ }
+
+ *hp = 0;
+ int bit = 1;
+ while (ii || jj) {
+ if (ii & 1) *hp |= bit;
+ bit <<= 1;
+ if (jj & 1) *hp |= bit;
+ bit <<= 1;
+ ii >>= 1;
+ jj >>= 1;
+ }
+
+ *hp += hh;
+ }
+}
+
+// (imap,jmap) pixel coordinates are as described above for NESTidx(). This
+// function computes the double-pixelisation index then converts it to the
+// regular ring index.
+
+void FitsHPX::RINGidx(int nside, int facet, int rotn, int jmap, long *healidx)
+{
+ const int I0[] = { 1, 3, -3, -1, 0, 2, 4, -2, 1, 3, -3, -1};
+ const int J0[] = { 1, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1};
+
+ int n2side = 2 * nside;
+ int n8side = 8 * nside;
+
+ // Double-pixelisation index of the last pixel in the north polar cap. */
+ int npole = (n2side - 1) * (n2side - 1) - 1;
+
+ // Double-pixelisation pixel coordinates of the centre of the facet. */
+ int i0 = nside * I0[facet];
+ int j0 = nside * J0[facet];
+
+ int nside1 = nside - 1;
+ long* hp = healidx;
+ for (int imap = 0; imap < nside; imap++, hp++) {
+ // (ii,jj) are 0-relative, double-pixelisation pixel coordinates. The
+ // origin is at the intersection of the equator and prime meridian,
+ // i increases to the east (N.B.) and j to the north.
+ int ii =0;
+ int jj =0;
+ if (rotn == 0) {
+ ii = i0 + nside1 - (jmap + imap);
+ jj = j0 + jmap - imap;
+ }
+ else if (rotn == 1) {
+ ii = i0 + imap - jmap;
+ jj = j0 + nside1 - (imap + jmap);
+ }
+ else if (rotn == 2) {
+ ii = i0 + (imap + jmap) - nside1;
+ jj = j0 + imap - jmap;
+ }
+ else if (rotn == 3) {
+ ii = i0 + jmap - imap;
+ jj = j0 + jmap + imap - nside1;
+ }
+
+ // Convert i for counting pixels
+ if (ii < 0)
+ ii += n8side;
+ ii++;
+
+ if (jj > nside) {
+ // North polar regime.
+ if (jj == n2side)
+ *hp = 0;
+ else {
+ // Number of pixels in a polar facet with this value of jj.
+ int npj = 2 * (n2side - jj);
+
+ // Index of the last pixel in the row above this.
+ *hp = (npj - 1) * (npj - 1) - 1;
+
+ // Number of pixels in this row in the polar facets before this.
+ *hp += npj * (ii/n2side);
+
+ // Pixel number in this polar facet.
+ *hp += ii%n2side - (jj - nside) - 1;
+ }
+ }
+ else if (jj >= -nside) {
+ // Equatorial regime.
+ *hp = npole + n8side * (nside - jj) + ii;
+ }
+ else {
+ // South polar regime.
+ *hp = 24 * nside * nside + 1;
+
+ if (jj > -n2side) {
+ // Number of pixels in a polar facet with this value of jj.
+ int npj = 2 * (jj + n2side);
+
+ // Total number of pixels in this row or below it.
+ *hp -= (npj + 1) * (npj + 1);
+
+ // Number of pixels in this row in the polar facets before this.
+ *hp += npj * (ii/n2side);
+
+ // Pixel number in this polar facet.
+ *hp += ii%n2side + (nside + jj) - 1;
+ }
+ }
+
+ // Convert double-pixelisation index to regular.
+ *hp -= 1;
+ *hp /= 2;
+ }
+}
+
+void FitsHPX::initHeader(FitsFile* fits)
+{
+ FitsHead* src = fits->head();
+
+ // create header
+ head_ = new FitsHead(pWidth_, pHeight_, 1, -32);
+
+ // OBJECT
+ char* object = src->getString("OBJECT");
+ if (object)
+ head_->appendString("OBJECT", object, NULL);
+
+ // CRPIX1/2
+ float crpix1;
+ switch (layout_) {
+ case EQUATOR:
+ crpix1 = (5 * nside_ + 1) / 2.;
+ break;
+ case NORTH:
+ case SOUTH:
+ crpix1 = (4 * nside_ + 1) / 2.;
+ break;
+ }
+ float crpix2 = crpix1;
+ head_->appendReal("CRPIX1", crpix1, 8, "Coordinate reference pixel");
+ head_->appendReal("CRPIX2", crpix2, 8, "Coordinate reference pixel");
+
+ // PCx_y
+ float cos45 = sqrt(2.0) / 2.0;
+ if (layout_ == EQUATOR) {
+ head_->appendReal("PC1_1", cos45, 8, "Transformation matrix element");
+ head_->appendReal("PC1_2", cos45, 8, "Transformation matrix element");
+ head_->appendReal("PC2_1", -cos45, 8, "Transformation matrix element");
+ head_->appendReal("PC2_2", cos45, 8, "Transformation matrix element");
+ }
+
+ // CDELT1/2
+ float cdelt1 = -90.0 / nside_ / sqrt(2.);
+ float cdelt2 = -cdelt1;
+ head_->appendReal("CDELT1", cdelt1, 8, "[deg] Coordinate increment");
+ head_->appendReal("CDELT2", cdelt2, 8, "[deg] Coordinate increment");
+
+ // CTYPE1/2
+ const char* pcode;
+ switch (layout_) {
+ case EQUATOR:
+ pcode = "HPX";
+ break;
+ case NORTH:
+ case SOUTH:
+ pcode = "XPH";
+ break;
+ }
+ const char* ctype1;
+ const char* ctype2;
+ const char* descr1;
+ const char* descr2;
+ switch (coord_) {
+ case EQU:
+ ctype1 = "RA--";
+ ctype2 = "DEC-";
+ descr1 = "Right ascension";
+ descr2 = "Declination";
+ break;
+ case GAL:
+ ctype1 = "GLON";
+ ctype2 = "GLAT";
+ descr1 = "Galactic longitude";
+ descr2 = "Galactic latitude";
+ break;
+ case ECL:
+ ctype1 = "ELON";
+ ctype2 = "ELAT";
+ descr1 = "Ecliptic longitude";
+ descr2 = "Ecliptic latitude";
+ break;
+ case UNKNOWN:
+ ctype1 = "XLON";
+ ctype2 = "XLAT";
+ descr1 = "Longitude";
+ descr2 = " Latitude";
+ }
+ {
+ ostringstream cval;
+ cval << ctype1 << '-' << pcode << ends;
+ ostringstream comm;
+ comm << descr1 << " in an " << pcode << " projection" << ends;
+ head_->appendString("CTYPE1", cval.str().c_str(), comm.str().c_str());
+ }
+ {
+ ostringstream cval;
+ cval << ctype2 << '-' << pcode << ends;
+ ostringstream comm;
+ comm << descr2 << " in an " << pcode << " projection" << ends;
+ head_->appendString("CTYPE2", cval.str().c_str(), comm.str().c_str());
+ }
+
+ // CRVAL1/CRVAL2
+ float crval1 = 0. + 90.*quad_;
+ float crval2;
+ switch (layout_) {
+ case EQUATOR:
+ crval2 = 0.;
+ break;
+ case NORTH:
+ crval1 += 180.;
+ crval2 = 90.;
+ break;
+ case SOUTH:
+ crval1 += 180.;
+ crval2 = -90.;
+ break;
+ }
+ if (360. < crval1)
+ crval1 -= 360.;
+
+ {
+ ostringstream comm;
+ comm << "[deg] " << descr1 << " at the reference point" << ends;
+ head_->appendReal("CRVAL1", crval1, 8, comm.str().c_str());
+ }
+ {
+ ostringstream comm;
+ comm << "[deg] " << descr2 << " at the reference point" << ends;
+ head_->appendReal("CRVAL2", crval2, 8, comm.str().c_str());
+ }
+
+ // PV2_1/2
+ switch (layout_) {
+ case EQUATOR:
+ head_->appendInteger("PV2_1", 4, "HPX H parameter (longitude)");
+ head_->appendInteger("PV2_2", 3, "HPX K parameter (latitude)");
+ break;
+ case NORTH:
+ case SOUTH:
+ head_->appendReal("LONPOLE", 180., 8, "[deg] Native longitude of the celestial pole");
+ break;
+ }
+
+ // we added cards
+ head_->updateHDU();
+}
+
+void FitsHPX::swap()
+{
+ if (!data_)
+ return;
+
+ // we now need to byteswap back to native form
+ float* dest = (float*)data_;
+ for (int ii=0; ii<dataSize_; ii++) {
+ const char* p = (char*)(dest+ii);
+ union {
+ char c[4];
+ float f;
+ } u;
+ u.c[3] = *p++;
+ u.c[2] = *p++;
+ u.c[1] = *p++;
+ u.c[0] = *p;
+ dest[ii] = u.f;
+ }
+}
diff --git a/fitsy++/hpx.h b/fitsy++/hpx.h
new file mode 100644
index 0000000..bb446b7
--- /dev/null
+++ b/fitsy++/hpx.h
@@ -0,0 +1,37 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitshpx_h__
+#define __fitshpx_h__
+
+#include "vector.h"
+#include "file.h"
+
+class FitsHPX : public FitsFile {
+ public:
+ enum Order {RING, NESTED};
+ enum CoordSys {UNKNOWN, EQU, GAL, ECL};
+ enum Layout {EQUATOR=0, NORTH=1, SOUTH=2};
+
+ private:
+ Order order_;
+ CoordSys coord_;
+ Layout layout_;
+ int quad_;
+ long nside_;
+
+ FitsBinColumn* col_;
+
+ void build(FitsFile*);
+ void initHeader(FitsFile*);
+ void swap();
+ void NESTidx(int nside, int facet, int rotn, int jmap, long *healidx);
+ void RINGidx(int nside, int facet, int rotn, int jmap, long *healidx);
+
+ public:
+ FitsHPX(FitsFile*, Order, CoordSys, Layout, int, int);
+ ~FitsHPX();
+};
+
+#endif
diff --git a/fitsy++/iis.C b/fitsy++/iis.C
new file mode 100644
index 0000000..710613c
--- /dev/null
+++ b/fitsy++/iis.C
@@ -0,0 +1,81 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "iis.h"
+
+FitsIIS::FitsIIS(int width, int height)
+{
+ // new header
+ head_ = new FitsHead(width, height, 1, 8);
+ if (!head_->isValid())
+ return;
+
+ // alloc memory
+ size_t size = (size_t)width*height;
+ data_ = new char[size];
+ if (!data_)
+ return;
+
+ dataSize_ = size;
+ dataSkip_ = 0;
+
+ // clear memory
+ memset(data_, '\0', size);
+
+ // made it this far, must be valid
+ valid_ = 1;
+}
+
+FitsIIS::~FitsIIS()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+void FitsIIS::erase()
+{
+ // clear memory
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ memset(data_, '\0', hdu->realbytes());
+}
+
+char* FitsIIS::get(int xx, int yy, int dx, int dy)
+{
+ // fill-in in reverse order
+ int ll = dx*dy;
+ char* dest = new char[ll];
+ int ww = head_->naxis(0);
+ int hh = head_->naxis(1);
+
+ char* dptr = dest;
+ char* sptr = (char*)data_ + ((hh-1)-yy)*ww + xx;
+
+ while (ll>0) {
+ memcpy(dptr, sptr, ww);
+ sptr -= ww;
+ dptr += ww;
+ ll -= ww;
+ }
+
+ return dest;
+}
+
+void FitsIIS::set(const char* src, int xx, int yy, int dx, int dy)
+{
+ // fill-in in reverse order
+ int ll = dx*dy;
+ int ww = head_->naxis(0);
+ int hh = head_->naxis(1);
+
+ char* sptr = (char*)src;
+ char* dptr = (char*)data_ + ((hh-1)-yy)*ww + xx;
+
+ while (ll>0) {
+ memcpy(dptr, sptr, ww);
+ sptr += ww;
+ dptr -= ww;
+ ll -= ww;
+ }
+}
+
diff --git a/fitsy++/iis.h b/fitsy++/iis.h
new file mode 100644
index 0000000..9618602
--- /dev/null
+++ b/fitsy++/iis.h
@@ -0,0 +1,20 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsiis_h__
+#define __fitsiis_h__
+
+#include "file.h"
+
+class FitsIIS : public FitsFile {
+public:
+ FitsIIS(int, int);
+ ~FitsIIS();
+
+ void erase();
+ char* get(int xx, int yy, int dx, int dy);
+ void set(const char* src, int xx, int yy, int dx, int dy);
+};
+
+#endif
diff --git a/fitsy++/lex.C b/fitsy++/lex.C
new file mode 100644
index 0000000..a36df18
--- /dev/null
+++ b/fitsy++/lex.C
@@ -0,0 +1,1959 @@
+#line 2 "../fitsy/lex.C"
+
+#line 4 "../fitsy/lex.C"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+ /* The c++ scanner is a mess. The FlexLexer.h header file relies on the
+ * following macro. This is required in order to pass the c++-multiple-scanners
+ * test in the regression suite. We get reports that it breaks inheritance.
+ * We will address this in a future release of flex, or omit the C++ scanner
+ * altogether.
+ */
+ #define yyFlexLexer ffFlexLexer
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+typedef uint64_t flex_uint64_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+/* begin standard C++ headers. */
+#include <iostream>
+#include <errno.h>
+#include <cstdlib>
+#include <cstring>
+/* end standard C++ headers. */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+extern yy_size_t yyleng;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+
+ std::istream* yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+void *ffalloc (yy_size_t );
+void *ffrealloc (void *,yy_size_t );
+void fffree (void * );
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+#define yytext_ptr yytext
+
+#include <FlexLexer.h>
+
+int yyFlexLexer::yywrap() { return 1; }
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ yyleng = (yy_size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+
+#define YY_NUM_RULES 45
+#define YY_END_OF_BUFFER 46
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[178] =
+ { 0,
+ 0, 0, 0, 0, 42, 42, 0, 0, 46, 1,
+ 3, 1, 1, 2, 4, 41, 40, 45, 41, 39,
+ 37, 37, 36, 37, 37, 37, 37, 37, 37, 37,
+ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
+ 38, 42, 44, 44, 43, 1, 3, 1, 40, 36,
+ 37, 36, 37, 37, 37, 37, 37, 37, 37, 37,
+ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
+ 37, 37, 37, 37, 37, 42, 43, 37, 37, 7,
+ 9, 37, 13, 14, 37, 37, 37, 37, 20, 37,
+ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
+
+ 37, 37, 37, 5, 37, 37, 37, 37, 37, 15,
+ 37, 37, 37, 37, 37, 37, 37, 37, 37, 27,
+ 28, 29, 37, 37, 37, 33, 34, 35, 6, 37,
+ 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
+ 25, 26, 30, 37, 37, 37, 11, 10, 12, 37,
+ 17, 37, 37, 21, 22, 24, 31, 37, 37, 37,
+ 37, 37, 37, 32, 37, 16, 37, 19, 37, 8,
+ 37, 37, 18, 37, 37, 23, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 4, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 5, 6, 7, 8, 1, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 1, 1, 1,
+ 1, 1, 1, 1, 10, 11, 12, 13, 14, 8,
+ 15, 16, 17, 8, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 8, 29, 30, 31, 32,
+ 33, 1, 34, 1, 8, 1, 35, 36, 37, 38,
+
+ 39, 8, 40, 41, 42, 8, 43, 44, 45, 46,
+ 47, 48, 49, 50, 51, 52, 53, 8, 54, 55,
+ 56, 57, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[58] =
+ { 0,
+ 1, 2, 3, 1, 1, 1, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 2, 2, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4
+ } ;
+
+static yyconst flex_int16_t yy_base[184] =
+ { 0,
+ 0, 3, 37, 0, 339, 336, 5, 6, 119, 0,
+ 14, 0, 15, 381, 381, 381, 18, 381, 108, 381,
+ 105, 0, 101, 70, 79, 75, 81, 87, 90, 87,
+ 92, 90, 78, 77, 89, 117, 86, 100, 102, 103,
+ 381, 0, 381, 26, 23, 0, 19, 22, 23, 22,
+ 0, 21, 130, 129, 99, 125, 127, 134, 121, 132,
+ 121, 122, 127, 131, 133, 146, 151, 141, 146, 137,
+ 140, 150, 168, 172, 175, 0, 20, 178, 185, 182,
+ 185, 175, 0, 173, 183, 184, 192, 194, 0, 183,
+ 179, 180, 181, 195, 198, 197, 190, 188, 189, 197,
+
+ 215, 219, 222, 0, 213, 224, 224, 233, 231, 0,
+ 226, 240, 224, 240, 225, 235, 241, 240, 232, 0,
+ 0, 0, 242, 245, 239, 0, 0, 0, 0, 249,
+ 244, 234, 236, 241, 264, 267, 265, 267, 281, 283,
+ 0, 0, 0, 277, 269, 282, 0, 0, 0, 283,
+ 0, 276, 285, 0, 289, 0, 0, 283, 295, 294,
+ 290, 296, 288, 0, 290, 0, 302, 0, 300, 0,
+ 296, 299, 0, 308, 314, 0, 381, 360, 364, 368,
+ 372, 24, 376
+ } ;
+
+static yyconst flex_int16_t yy_def[184] =
+ { 0,
+ 178, 178, 177, 3, 179, 179, 180, 180, 177, 181,
+ 177, 181, 181, 177, 177, 177, 177, 177, 177, 177,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 177, 183, 177, 177, 177, 181, 177, 181, 177, 177,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 183, 177, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
+ 182, 182, 182, 182, 182, 182, 0, 177, 177, 177,
+ 177, 177, 177
+ } ;
+
+static yyconst flex_int16_t yy_nxt[439] =
+ { 0,
+ 177, 11, 12, 13, 11, 12, 13, 18, 18, 44,
+ 44, 44, 44, 45, 45, 47, 47, 47, 48, 49,
+ 47, 49, 47, 47, 49, 48, 49, 51, 77, 52,
+ 50, 77, 14, 15, 77, 14, 15, 16, 17, 18,
+ 17, 19, 20, 21, 22, 23, 24, 25, 26, 27,
+ 28, 29, 22, 22, 30, 31, 22, 32, 33, 22,
+ 34, 35, 36, 22, 37, 22, 38, 39, 40, 41,
+ 16, 24, 25, 26, 27, 28, 29, 22, 22, 30,
+ 31, 22, 32, 33, 22, 34, 35, 36, 22, 37,
+ 22, 38, 39, 40, 53, 54, 55, 56, 57, 60,
+
+ 61, 62, 66, 64, 67, 68, 72, 58, 63, 52,
+ 59, 65, 73, 52, 74, 75, 50, 83, 177, 53,
+ 54, 55, 56, 57, 60, 61, 62, 66, 64, 67,
+ 68, 72, 58, 63, 69, 59, 65, 73, 70, 74,
+ 75, 78, 83, 80, 84, 85, 86, 71, 87, 81,
+ 88, 89, 90, 91, 79, 82, 92, 93, 94, 69,
+ 95, 96, 97, 70, 98, 99, 78, 100, 80, 84,
+ 85, 86, 71, 87, 81, 88, 89, 90, 91, 79,
+ 82, 92, 93, 94, 101, 95, 96, 97, 102, 98,
+ 99, 103, 100, 104, 105, 106, 107, 109, 110, 111,
+
+ 112, 113, 108, 114, 115, 116, 117, 118, 119, 101,
+ 120, 121, 122, 102, 123, 124, 103, 125, 104, 105,
+ 106, 107, 109, 110, 111, 112, 113, 108, 114, 115,
+ 116, 117, 118, 119, 126, 120, 121, 122, 127, 123,
+ 124, 128, 125, 129, 130, 131, 132, 133, 134, 135,
+ 136, 137, 138, 139, 140, 141, 142, 143, 144, 126,
+ 145, 146, 147, 127, 148, 149, 128, 150, 129, 130,
+ 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
+ 141, 142, 143, 144, 151, 145, 146, 147, 152, 148,
+ 149, 153, 150, 154, 155, 156, 157, 158, 159, 160,
+
+ 161, 162, 163, 164, 165, 166, 167, 168, 169, 151,
+ 170, 171, 172, 152, 173, 174, 153, 175, 154, 155,
+ 156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
+ 166, 167, 168, 169, 176, 170, 171, 172, 18, 173,
+ 174, 18, 175, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 176,
+ 10, 10, 10, 10, 42, 42, 42, 42, 43, 43,
+ 43, 43, 46, 177, 46, 46, 76, 76, 177, 76,
+ 9, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177
+ } ;
+
+static yyconst flex_int16_t yy_chk[439] =
+ { 0,
+ 0, 1, 1, 1, 2, 2, 2, 7, 8, 7,
+ 8, 7, 8, 7, 8, 11, 13, 11, 13, 17,
+ 47, 17, 47, 48, 49, 48, 49, 182, 77, 52,
+ 50, 45, 1, 1, 44, 2, 2, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 24, 25, 26, 27, 28, 29,
+
+ 30, 31, 33, 32, 34, 35, 37, 28, 31, 23,
+ 28, 32, 38, 21, 39, 40, 19, 55, 9, 24,
+ 25, 26, 27, 28, 29, 30, 31, 33, 32, 34,
+ 35, 37, 28, 31, 36, 28, 32, 38, 36, 39,
+ 40, 53, 55, 54, 56, 57, 58, 36, 59, 54,
+ 60, 61, 62, 63, 53, 54, 64, 65, 66, 36,
+ 67, 68, 69, 36, 70, 71, 53, 72, 54, 56,
+ 57, 58, 36, 59, 54, 60, 61, 62, 63, 53,
+ 54, 64, 65, 66, 73, 67, 68, 69, 74, 70,
+ 71, 75, 72, 78, 79, 80, 81, 82, 84, 85,
+
+ 86, 87, 81, 88, 90, 91, 92, 93, 94, 73,
+ 95, 96, 97, 74, 98, 99, 75, 100, 78, 79,
+ 80, 81, 82, 84, 85, 86, 87, 81, 88, 90,
+ 91, 92, 93, 94, 101, 95, 96, 97, 102, 98,
+ 99, 103, 100, 105, 106, 107, 108, 109, 111, 112,
+ 113, 114, 115, 116, 117, 118, 119, 123, 124, 101,
+ 125, 130, 131, 102, 132, 133, 103, 134, 105, 106,
+ 107, 108, 109, 111, 112, 113, 114, 115, 116, 117,
+ 118, 119, 123, 124, 135, 125, 130, 131, 136, 132,
+ 133, 137, 134, 138, 139, 140, 144, 145, 146, 150,
+
+ 152, 153, 155, 158, 159, 160, 161, 162, 163, 135,
+ 165, 167, 169, 136, 171, 172, 137, 174, 138, 139,
+ 140, 144, 145, 146, 150, 152, 153, 155, 158, 159,
+ 160, 161, 162, 163, 175, 165, 167, 169, 6, 171,
+ 172, 5, 174, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 175,
+ 178, 178, 178, 178, 179, 179, 179, 179, 180, 180,
+ 180, 180, 181, 0, 181, 181, 183, 183, 0, 183,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177, 177, 177,
+ 177, 177, 177, 177, 177, 177, 177, 177
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "../fitsy/lex.L"
+/* Copyright (C) 1999-2018
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * For conditions of distribution and use, see copyright notice in "copyright"
+ */
+#line 11 "../fitsy/lex.L"
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #include "util.h"
+ #include "parser.H"
+
+ extern YYSTYPE* fflval;
+ extern ffFlexLexer* fflexx;
+
+ extern char ff_filter[];
+ #define RET(x) {strcat(ff_filter,yytext);return x;}
+ #define CLEARFILTER {ff_filter[0]='\0';}
+
+
+
+/* rules */
+#line 584 "../fitsy/lex.C"
+
+#define INITIAL 0
+#define EXT 1
+#define FILTER 2
+#define ARRAY 3
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+#define ECHO LexerOutput( yytext, yyleng )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+\
+ if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) LexerError( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+#define YY_DECL int yyFlexLexer::yylex()
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 32 "../fitsy/lex.L"
+
+
+#line 690 "../fitsy/lex.C"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = & std::cin;
+
+ if ( ! yyout )
+ yyout = & std::cout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of yytext. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 178 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 177 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+/* rule 1 can match eol */
+YY_RULE_SETUP
+#line 34 "../fitsy/lex.L"
+{ // File
+ strcpy(fflval->str,yytext);
+ return STRING;
+ }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 39 "../fitsy/lex.L"
+{ // first bracket
+ BEGIN EXT;
+ CLEARFILTER
+ return yytext[0];
+ }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 45 "../fitsy/lex.L"
+{ // White Spaces
+ }
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 48 "../fitsy/lex.L"
+{ // Else, return the char
+ return yytext[0];
+ }
+ YY_BREAK
+
+case 5:
+YY_RULE_SETUP
+#line 54 "../fitsy/lex.L"
+{RET(ARCH_)}
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 55 "../fitsy/lex.L"
+{RET(ARRAY_)}
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 56 "../fitsy/lex.L"
+{RET(BIG_)}
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 57 "../fitsy/lex.L"
+{RET(BIGENDIAN_)}
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 58 "../fitsy/lex.L"
+{RET(BIN_)}
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 59 "../fitsy/lex.L"
+{RET(BINKEY_)}
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 60 "../fitsy/lex.L"
+{RET(BINCOL_)}
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 61 "../fitsy/lex.L"
+{RET(BITPIX_)}
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 62 "../fitsy/lex.L"
+{RET(COL_)}
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 63 "../fitsy/lex.L"
+{RET(DIM_)}
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 64 "../fitsy/lex.L"
+{RET(DIMS_)}
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 65 "../fitsy/lex.L"
+{RET(ECLIPTIC_)}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 66 "../fitsy/lex.L"
+{RET(ENDIAN_)}
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 67 "../fitsy/lex.L"
+{RET(EQUATORIAL_)}
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 68 "../fitsy/lex.L"
+{RET(GALACTIC_)}
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 69 "../fitsy/lex.L"
+{RET(KEY_)}
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 70 "../fitsy/lex.L"
+{RET(LAYOUT_)}
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 71 "../fitsy/lex.L"
+{RET(LITTLE_)}
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 72 "../fitsy/lex.L"
+{RET(LITTLEENDIAN_)}
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 73 "../fitsy/lex.L"
+{RET(NESTED_)}
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 74 "../fitsy/lex.L"
+{RET(NORTH_)}
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 75 "../fitsy/lex.L"
+{RET(ORDER_)}
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 76 "../fitsy/lex.L"
+{RET(QUAD_)}
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 77 "../fitsy/lex.L"
+{RET(RING_)}
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 78 "../fitsy/lex.L"
+{RET(SKIP_)}
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 79 "../fitsy/lex.L"
+{RET(SOUTH_)}
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 80 "../fitsy/lex.L"
+{RET(SYSTEM_)}
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 81 "../fitsy/lex.L"
+{RET(UNKNOWN_)}
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 82 "../fitsy/lex.L"
+{RET(XDIM_)}
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 83 "../fitsy/lex.L"
+{RET(YDIM_)}
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 84 "../fitsy/lex.L"
+{RET(ZDIM_)}
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 86 "../fitsy/lex.L"
+{ // Integer
+ fflval->integer = atoi(yytext);
+ RET(INT)
+ }
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 91 "../fitsy/lex.L"
+{ // Extn/Col Name
+ strcpy(fflval->str,yytext);
+ RET(STRING)
+ }
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 96 "../fitsy/lex.L"
+{ // bracket
+ CLEARFILTER
+ return yytext[0];
+ }
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 101 "../fitsy/lex.L"
+{ // comma
+ CLEARFILTER
+ return yytext[0];
+ }
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 106 "../fitsy/lex.L"
+{ // White Spaces
+ strcat(ff_filter,yytext);
+ }
+ YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 110 "../fitsy/lex.L"
+{ // Else, return the char
+ strcat(ff_filter,yytext);
+ return yytext[0];
+ }
+ YY_BREAK
+
+case 42:
+YY_RULE_SETUP
+#line 117 "../fitsy/lex.L"
+{ // rest of Filter
+ strcpy(fflval->str,yytext);
+ fflval->str[yyleng-1] = '\0'; // Remove the ']'
+ strcat(ff_filter,fflval->str);
+ return STRING;
+ }
+ YY_BREAK
+
+case 43:
+YY_RULE_SETUP
+#line 126 "../fitsy/lex.L"
+{ // Integer
+ fflval->integer = atoi(yytext);
+ return INT;
+ }
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 131 "../fitsy/lex.L"
+{ // Else, return the char
+ return yytext[0];
+ }
+ YY_BREAK
+
+case 45:
+YY_RULE_SETUP
+#line 137 "../fitsy/lex.L"
+ECHO;
+ YY_BREAK
+#line 1036 "../fitsy/lex.C"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(EXT):
+case YY_STATE_EOF(FILTER):
+case YY_STATE_EOF(ARRAY):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( yywrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
+{
+ yyin = arg_yyin;
+ yyout = arg_yyout;
+ yy_c_buf_p = 0;
+ yy_init = 0;
+ yy_start = 0;
+ yy_flex_debug = 0;
+ yylineno = 1; // this will only get updated if %option yylineno
+
+ yy_did_buffer_switch_on_eof = 0;
+
+ yy_looking_for_trail_begin = 0;
+ yy_more_flag = 0;
+ yy_more_len = 0;
+ yy_more_offset = yy_prev_more_offset = 0;
+
+ yy_start_stack_ptr = yy_start_stack_depth = 0;
+ yy_start_stack = NULL;
+
+ yy_buffer_stack = 0;
+ yy_buffer_stack_top = 0;
+ yy_buffer_stack_max = 0;
+
+ yy_state_buf = 0;
+
+}
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+yyFlexLexer::~yyFlexLexer()
+{
+ delete [] yy_state_buf;
+ fffree(yy_start_stack );
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ fffree(yy_buffer_stack );
+}
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out )
+{
+ if ( new_in )
+ {
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) );
+ }
+
+ if ( new_out )
+ yyout = new_out;
+}
+
+#ifdef YY_INTERACTIVE
+size_t yyFlexLexer::LexerInput( char* buf, size_t /* max_size */ )
+#else
+size_t yyFlexLexer::LexerInput( char* buf, size_t max_size )
+#endif
+{
+ if ( yyin->eof() || yyin->fail() )
+ return 0;
+
+#ifdef YY_INTERACTIVE
+ yyin->get( buf[0] );
+
+ if ( yyin->eof() )
+ return 0;
+
+ if ( yyin->bad() )
+ return -1;
+
+ return 1;
+
+#else
+ (void) yyin->read( buf, max_size );
+
+ if ( yyin->bad() )
+ return -1;
+ else
+ return yyin->gcount();
+#endif
+}
+
+void yyFlexLexer::LexerOutput( const char* buf, size_t size )
+{
+ (void) yyout->write( buf, size );
+}
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+int yyFlexLexer::yy_get_next_buffer()
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ ffrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) ffrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ yy_state_type yyFlexLexer::yy_get_previous_state()
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 178 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state )
+{
+ register int yy_is_jam;
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 178 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 177);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+ void yyFlexLexer::yyunput( int c, register char* yy_bp)
+{
+ register char *yy_cp;
+
+ yy_cp = (yy_c_buf_p);
+
+ /* undo effects of setting up yytext */
+ *yy_cp = (yy_hold_char);
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register yy_size_t number_to_move = (yy_n_chars) + 2;
+ register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ register char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+ (yytext_ptr) = yy_bp;
+ (yy_hold_char) = *yy_cp;
+ (yy_c_buf_p) = yy_cp;
+}
+
+ int yyFlexLexer::yyinput()
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap( ) )
+ return 0;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve yytext */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ return c;
+}
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void yyFlexLexer::yyrestart( std::istream* input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file );
+ yy_load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
+ */
+ yyensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ yy_load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+ void yyFlexLexer::yy_load_buffer_state()
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) ffalloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) ffalloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ *
+ */
+ void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ fffree((void *) b->yy_ch_buf );
+
+ fffree((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+ void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file )
+
+{
+ int oerrno = errno;
+
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = 0;
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ yy_load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer)
+{
+ if (new_buffer == NULL)
+ return;
+
+ yyensure_buffer_stack();
+
+ /* This block is copied from yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void yyFlexLexer::yypop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+void yyFlexLexer::yyensure_buffer_stack(void)
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)ffalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)ffrealloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+ void yyFlexLexer::yy_push_state( int new_state )
+{
+ if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) )
+ {
+ yy_size_t new_size;
+
+ (yy_start_stack_depth) += YY_START_STACK_INCR;
+ new_size = (yy_start_stack_depth) * sizeof( int );
+
+ if ( ! (yy_start_stack) )
+ (yy_start_stack) = (int *) ffalloc(new_size );
+
+ else
+ (yy_start_stack) = (int *) ffrealloc((void *) (yy_start_stack),new_size );
+
+ if ( ! (yy_start_stack) )
+ YY_FATAL_ERROR( "out of memory expanding start-condition stack" );
+ }
+
+ (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START;
+
+ BEGIN(new_state);
+}
+
+ void yyFlexLexer::yy_pop_state()
+{
+ if ( --(yy_start_stack_ptr) < 0 )
+ YY_FATAL_ERROR( "start-condition stack underflow" );
+
+ BEGIN((yy_start_stack)[(yy_start_stack_ptr)]);
+}
+
+ int yyFlexLexer::yy_top_state()
+{
+ return (yy_start_stack)[(yy_start_stack_ptr) - 1];
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+void yyFlexLexer::LexerError( yyconst char msg[] )
+{
+ std::cerr << msg << std::endl;
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = (yy_hold_char); \
+ (yy_c_buf_p) = yytext + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *ffalloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *ffrealloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void fffree (void * ptr )
+{
+ free( (char *) ptr ); /* see ffrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 137 "../fitsy/lex.L"
+
+
+
+void ffFilter(int doit)
+{
+ if (fflexx)
+ fflexx->begin(FILTER, doit);
+}
+
+void ffArray(int doit)
+{
+ if (fflexx)
+ fflexx->begin(ARRAY, doit);
+}
+
+void ffFlexLexer::begin(int which, int doit)
+{
+ BEGIN which;
+ if (doit)
+ yyless(0);
+}
+
diff --git a/fitsy++/lex.L b/fitsy++/lex.L
new file mode 100644
index 0000000..2415354
--- /dev/null
+++ b/fitsy++/lex.L
@@ -0,0 +1,156 @@
+/* Copyright (C) 1999-2018
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * For conditions of distribution and use, see copyright notice in "copyright"
+ */
+%option noyywrap
+%option caseless
+%option never-interactive
+%option c++
+
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #include "util.h"
+ #include "parser.H"
+
+ extern YYSTYPE* fflval;
+ extern ffFlexLexer* fflexx;
+
+ extern char ff_filter[];
+ #define RET(x) {strcat(ff_filter,yytext);return x;}
+ #define CLEARFILTER {ff_filter[0]='\0';}
+%}
+
+%x EXT
+%x FILTER
+%x ARRAY
+
+/* rules */
+
+%%
+
+[^[\]\t]+ { // File
+ strcpy(fflval->str,yytext);
+ return STRING;
+ }
+
+\[ { // first bracket
+ BEGIN EXT;
+ CLEARFILTER
+ return yytext[0];
+ }
+
+[ \t]+ { // White Spaces
+ }
+
+. { // Else, return the char
+ return yytext[0];
+ }
+
+<EXT>{
+
+arch {RET(ARCH_)}
+array {RET(ARRAY_)}
+big {RET(BIG_)}
+bigendian {RET(BIGENDIAN_)}
+bin {RET(BIN_)}
+binkey {RET(BINKEY_)}
+bincol {RET(BINCOL_)}
+bitpix {RET(BITPIX_)}
+col {RET(COL_)}
+dim {RET(DIM_)}
+dims {RET(DIMS_)}
+ecliptic {RET(ECLIPTIC_)}
+endian {RET(ENDIAN_)}
+equatorial {RET(EQUATORIAL_)}
+galactic {RET(GALACTIC_)}
+key {RET(KEY_)}
+layout {RET(LAYOUT_)}
+little {RET(LITTLE_)}
+littleendian {RET(LITTLEENDIAN_)}
+nested {RET(NESTED_)}
+north {RET(NORTH_)}
+order {RET(ORDER_)}
+quad {RET(QUAD_)}
+ring {RET(RING_)}
+skip {RET(SKIP_)}
+south {RET(SOUTH_)}
+system {RET(SYSTEM_)}
+unknown {RET(UNKNOWN_)}
+xdim {RET(XDIM_)}
+ydim {RET(YDIM_)}
+zdim {RET(ZDIM_)}
+
+[-+]?[0-9]+ { // Integer
+ fflval->integer = atoi(yytext);
+ RET(INT)
+ }
+
+[0-9A-Za-z_.-]+ { // Extn/Col Name
+ strcpy(fflval->str,yytext);
+ RET(STRING)
+ }
+
+\[ { // bracket
+ CLEARFILTER
+ return yytext[0];
+ }
+
+, { // comma
+ CLEARFILTER
+ return yytext[0];
+ }
+
+[ \t]+ { // White Spaces
+ strcat(ff_filter,yytext);
+ }
+
+. { // Else, return the char
+ strcat(ff_filter,yytext);
+ return yytext[0];
+ }
+
+}
+
+<FILTER>.* { // rest of Filter
+ strcpy(fflval->str,yytext);
+ fflval->str[yyleng-1] = '\0'; // Remove the ']'
+ strcat(ff_filter,fflval->str);
+ return STRING;
+ }
+
+<ARRAY>{
+
+[-+]?[0-9]+ { // Integer
+ fflval->integer = atoi(yytext);
+ return INT;
+ }
+
+. { // Else, return the char
+ return yytext[0];
+ }
+
+}
+
+%%
+
+void ffFilter(int doit)
+{
+ if (fflexx)
+ fflexx->begin(FILTER, doit);
+}
+
+void ffArray(int doit)
+{
+ if (fflexx)
+ fflexx->begin(ARRAY, doit);
+}
+
+void ffFlexLexer::begin(int which, int doit)
+{
+ BEGIN which;
+ if (doit)
+ yyless(0);
+}
diff --git a/fitsy++/map.C b/fitsy++/map.C
new file mode 100644
index 0000000..6fd3d3c
--- /dev/null
+++ b/fitsy++/map.C
@@ -0,0 +1,418 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "map.h"
+#include "head.h"
+#include "util.h"
+
+FitsMap::FitsMap()
+{
+ mapdata_ = NULL;
+ mapsize_ = 0;
+}
+
+char* FitsMap::enddata()
+{
+ // return the address of the first data byte pass the end of data
+ return head_ ? (char*)data_+head_->databytes() : NULL;
+}
+
+size_t FitsMap::endsize()
+{
+ // return the size - (header+data)
+ return head_ ?
+ (mapsize_ - (size_t)((char*)data_+head_->databytes()-mapdata_)) : 0;
+}
+
+void FitsMap::found(char* here)
+{
+ data_ = here + head_->headbytes();
+
+ dataSize_ = mapsize_;
+ dataSkip_ = here - mapdata_ + head_->headbytes();
+
+ inherit_ = head_->inherit();
+ valid_ = 1;
+}
+
+void FitsMap::error()
+{
+ if (manageHead_ && head_)
+ delete head_;
+ head_ = NULL;
+
+ if (managePrimary_ && primary_)
+ delete primary_;
+ primary_ = NULL;
+
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ valid_ = 0;
+}
+
+FitsFitsMap::FitsFitsMap(ScanMode mode)
+{
+ if (!valid_)
+ return;
+
+ if (mode == EXACT || pExt_ || pIndex_>-1)
+ processExact();
+ else
+ processRelax();
+}
+
+void FitsFitsMap::processExact()
+{
+ // find head and data for specified unit
+ char* here = mapdata_;
+ size_t size = mapsize_;
+
+ // simple check for fits file
+ if (strncmp(mapdata_,"SIMPLE ",8) && strncmp(mapdata_,"XTENSION",8)) {
+ error();
+ return;
+ }
+
+ if (!(pExt_ || (pIndex_>0))) {
+
+ // we are only looking for a primary image
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (head_->isValid()) {
+ found(here);
+ return;
+ }
+ }
+ else {
+
+ // we are looking for an extension
+ // keep the primary header
+ primary_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ managePrimary_ = 1;
+ if (!primary_->isValid()) {
+ error();
+ return;
+ }
+ here += primary_->headbytes() + primary_->databytes();
+ size -= primary_->headbytes() + primary_->databytes();
+
+ if (pExt_) {
+ while (size > 0) {
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (!head_->isValid()) {
+ error();
+ return;
+ }
+ ext_++;
+
+ if (head_->extname()) {
+ char* a = toUpper(head_->extname());
+ char* b = toUpper(pExt_);
+ if (!strncmp(a,b,strlen(b))) {
+ delete [] a;
+ delete [] b;
+ found(here);
+ return;
+ }
+ delete [] a;
+ delete [] b;
+ }
+
+ here += head_->headbytes() + head_->databytes();
+ size -= head_->headbytes() + head_->databytes();
+ delete head_;
+ head_ = NULL;
+ }
+ }
+ else {
+ for (int i=1; i<pIndex_ && size>0; i++) {
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (!head_->isValid()) {
+ error();
+ return;
+ }
+ ext_++;
+
+ here += head_->headbytes() + head_->databytes();
+ size -= head_->headbytes() + head_->databytes();
+ delete head_;
+ head_ = NULL;
+ }
+
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (head_->isValid()) {
+ ext_++;
+ found(here);
+ return;
+ }
+ }
+ }
+
+ // Must have an error
+ error();
+}
+
+void FitsFitsMap::processRelax()
+{
+ char* here = mapdata_;
+ size_t size = mapsize_;
+
+ // simple check for fits file
+ if (strncmp(mapdata_,"SIMPLE ",8) && strncmp(mapdata_,"XTENSION",8)) {
+ error();
+ return;
+ }
+
+ // check to see if there is an image in the primary
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (head_->isValid() &&
+ head_->naxes() > 0 &&
+ head_->naxis(0) > 0 &&
+ head_->naxis(1) > 0) {
+ found(here);
+ return;
+ }
+
+ // ok, no image, save primary and lets check extensions
+ here += head_->headbytes() + head_->databytes();
+ size -= head_->headbytes() + head_->databytes();
+ primary_ = head_;
+ managePrimary_ = 1;
+ head_ = NULL;
+
+ while (size > 0) {
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (!head_->isValid()) {
+ error();
+ return;
+ }
+ ext_++;
+
+ // check for image
+ if (head_->isImage()) {
+ found(here);
+ return;
+ }
+
+ // else, check for compressed image
+ if (head_->isBinTable() && head_->find("ZIMAGE")) {
+ found(here);
+ return;
+ }
+
+ // else, check for bin table named STDEVT, EVENTS, RAYEVENT
+ if (head_->isBinTable() && head_->extname()) {
+ char* a = toUpper(head_->extname());
+ if (!strncmp("STDEVT", a, 6) ||
+ !strncmp("EVENTS", a, 6) ||
+ !strncmp("RAYEVENT", a, 8)) {
+ delete [] a;
+ found(here);
+ return;
+ }
+ }
+
+ // else, check for bin table with keyword PIXTYPE = 'HEALPIX '
+ if (head_->isBinTable() && head_->find("PIXTYPE") &&
+ (!strncmp(head_->getString("PIXTYPE"),"HEALPIX",4))) {
+ found(here);
+ return;
+ }
+
+ // else, check for bin table with keyword NSIDE (also HEALPIX)
+ if (head_->isBinTable() && head_->find("NSIDE")) {
+ found(here);
+ return;
+ }
+
+ here += head_->headbytes() + head_->databytes();
+ size -= head_->headbytes() + head_->databytes();
+ delete head_;
+ head_ = NULL;
+ }
+
+ // did not find anything, bail out
+ error();
+}
+
+FitsFitsNextMap::FitsFitsNextMap(FitsFile* p)
+{
+ FitsMap* prev = (FitsMap*)p;
+
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = prev->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ pcoord_ = prev->pcoord();
+ pxvalid_ = prev->pxvalid();
+ pxmin_ = prev->pxmin();
+ pxmax_ = prev->pxmax();
+ pyvalid_ = prev->pyvalid();
+ pymin_ = prev->pymin();
+ pymax_ = prev->pymax();
+ pzvalid_ = prev->pzvalid();
+ pzmin_ = prev->pzmin();
+ pzmax_ = prev->pzmax();
+ pbvalid_ = prev->pbvalid();
+ pblock_ = prev->pblock();
+
+ mapdata_ = prev->mapdata();
+ mapsize_ = prev->mapsize();
+
+ return;
+}
+
+FitsArrMap::FitsArrMap()
+{
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ = 0;
+
+ // check to see if we have a nonzero width, height, and bitpix
+ if (!validParams())
+ return;
+
+ // check to see if dimensions equal mapped space
+ if (((size_t)pWidth_*pHeight_*pDepth_*abs(pBitpix_)/8)+pSkip_ > mapsize_)
+ return;
+
+ // skip to start of data
+ data_ = mapdata_ + pSkip_;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = pSkip_;
+
+ // new header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return;
+
+ // do we byteswap?
+ setByteSwap();
+
+ // made it this far, must be valid
+ valid_ = 1;
+}
+
+FitsNRRDMap::FitsNRRDMap()
+{
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ = 0;
+
+ // header
+ {
+ char buf[1024];
+ char* dptr = buf;
+ char* sptr = mapdata_;
+ int cnt =0;
+ do {
+ *dptr++ = *sptr++;
+ if (cnt>0 && (*sptr == '\n' && *(sptr-1) == '\n')) {
+ pSkip_ = cnt+2;
+ break;
+ }
+ cnt++;
+ } while (cnt<1024);
+ *dptr = '\0';
+
+ string x(buf);
+ istringstream str(x);
+ parseNRRD(str);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+ }
+
+ // check to see if we have a nonzero width, height, and bitpix
+ if (!validParams())
+ return;
+
+ // skip to start of data
+ data_ = mapdata_ + pSkip_;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = pSkip_;
+
+ // new header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return;
+
+ // do we byteswap?
+ setByteSwap();
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsMosaicMap::FitsMosaicMap()
+{
+ if (!valid_)
+ return;
+
+ char* here = mapdata_;
+ size_t size = mapsize_;
+
+ // keep the primary header
+ primary_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ managePrimary_ = 1;
+ if (!primary_->isValid()) {
+ error();
+ return;
+ }
+
+ here += primary_->headbytes() + primary_->databytes();
+ size -= primary_->headbytes() + primary_->databytes();
+
+ // first extension
+ head_ = new FitsHead(here, size, FitsHead::EXTERNAL);
+ if (!head_->isValid()) {
+ error();
+ return;
+ }
+ ext_++;
+ found(here);
+}
+
+FitsMosaicNextMap::FitsMosaicNextMap(FitsFile* p)
+{
+ FitsMap* prev = (FitsMap*)p;
+
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+ ext_ = prev->ext();
+
+ mapdata_ = prev->enddata();
+ mapsize_ = prev->endsize();
+
+ head_ = new FitsHead(mapdata_, mapsize_, FitsHead::EXTERNAL);
+ if (!head_->isValid()) {
+ error();
+ return;
+ }
+ ext_++;
+ found(mapdata_);
+}
diff --git a/fitsy++/map.h b/fitsy++/map.h
new file mode 100644
index 0000000..6adae65
--- /dev/null
+++ b/fitsy++/map.h
@@ -0,0 +1,69 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsmap_h__
+#define __fitsmap_h__
+
+#include "file.h"
+
+class FitsMap : public FitsFile {
+protected:
+ char* mapdata_;
+ size_t mapsize_;
+
+public:
+ FitsMap();
+ virtual ~FitsMap() {}
+
+ char* mapdata() {return mapdata_;}
+ size_t mapsize() {return mapsize_;}
+ void found(char*);
+ void error();
+ char* enddata();
+ size_t endsize();
+};
+
+class FitsFitsMap : public virtual FitsMap {
+protected:
+ void processExact();
+ void processRelax();
+
+public:
+ FitsFitsMap(ScanMode);
+};
+
+class FitsFitsNextMap : public FitsMap {
+public:
+ FitsFitsNextMap(FitsFile* prev);
+};
+
+class FitsArrMap : public virtual FitsMap {
+public:
+ FitsArrMap();
+};
+
+class FitsNRRDMap : public virtual FitsMap {
+public:
+ FitsNRRDMap();
+};
+
+class FitsMosaicMap : public virtual FitsMap {
+public:
+ FitsMosaicMap();
+};
+
+class FitsMosaicNextMap : public FitsMap {
+public:
+ FitsMosaicNextMap(FitsFile* prev);
+};
+
+#endif
+
+
+
+
+
+
+
+
diff --git a/fitsy++/mapincr.C b/fitsy++/mapincr.C
new file mode 100644
index 0000000..e7d3ef6
--- /dev/null
+++ b/fitsy++/mapincr.C
@@ -0,0 +1,600 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "mapincr.h"
+#include "util.h"
+
+#ifndef __WIN32
+
+#include <unistd.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "head.h"
+
+//#define PAGELIMIT 1073741824
+#define PAGELIMIT 536870912
+
+FitsMapIncr::FitsMapIncr()
+{
+ mapdata_ = NULL;
+ mapsize_ = 0;
+ page_ = 0;
+
+ filesize_ = 0;
+ seek_ = 0;
+
+ dseek_ = 0;
+ nseek_ = 0;
+}
+
+FitsMapIncr::~FitsMapIncr()
+{
+ if (mapdata_)
+ munmap((caddr_t)mapdata_, mapsize_);
+}
+
+FitsHead* FitsMapIncr::headRead()
+{
+ // NOTE: the hdu cleans up after the hdu,
+ // here we only clean up after the data segment
+
+ // mmap will return valid if seek_ is at end of file, so check first
+ if (filesize_-seek_<=0)
+ return NULL;
+
+ // read first BLOCK
+ // seek_ needs to be an increment of getpagesize
+ int pagesize = getpagesize();
+ off_t mmseek = (seek_/pagesize)*pagesize;
+ size_t offset = seek_ - mmseek;
+
+ int fd = open(pName_, O_RDONLY);
+ size_t mmsize = offset+FTY_BLOCK;
+ char* mmdata = (char*)mmap(NULL, mmsize, PROT_READ, MAP_SHARED, fd, mmseek);
+ close(fd);
+
+ // are we valid?
+ if ((long)mmdata == -1)
+ return NULL;
+
+ // simple test
+ if (strncmp(mmdata+offset,"SIMPLE ",8) &&
+ strncmp(mmdata+offset,"XTENSION",8)) {
+ munmap((caddr_t)mmdata, mmsize);
+ return NULL;
+ }
+
+ // can we find 'END'?
+ while (mmsize-offset-FTY_BLOCK < filesize_-seek_) {
+ if (findEnd(mmdata+mmsize-FTY_BLOCK))
+ break;
+
+ // add another BLOCK
+ munmap((caddr_t)mmdata, mmsize);
+ fd = open(pName_, O_RDONLY);
+ mmdata = (char*)mmap(NULL, mmsize+FTY_BLOCK, PROT_READ, MAP_SHARED,
+ fd, mmseek);
+ close(fd);
+
+ // are we valid?
+ if ((long)mmdata == -1)
+ return NULL;
+
+ mmsize += FTY_BLOCK;
+ }
+
+ // do we have a header?
+ FitsHead* hd = new FitsHead(mmdata+offset, mmsize-offset,
+ mmdata, mmsize, FitsHead::MMAP);
+ if (!hd || !hd->isValid()) {
+ delete hd;
+ return NULL;
+ }
+
+ seek_ += mmsize-offset;
+
+ // success!
+ return hd;
+}
+
+void FitsMapIncr::dataSkip(size_t bytes)
+{
+ seek_ += bytes;
+}
+
+void FitsMapIncr::dataSkipBlock(size_t blk)
+{
+ seek_ += blk*FTY_BLOCK;
+}
+
+void FitsMapIncr::found()
+{
+ // at this point we mmap the data segment
+
+ // must find a page boundary
+ int pagesize = getpagesize();
+ off_t mmseek = (seek_/pagesize)*pagesize;
+ size_t offset = seek_ - mmseek;
+
+ int fd = open(pName_, O_RDONLY);
+
+ // determine internal page mode
+ if (!head_->isTable() || !head_->isAsciiTable() || head_->isHeap()) {
+ // no internal paging
+ mapsize_ = head_->databytes()+offset;
+ page_ = 0;
+ }
+ else {
+ // if mapsize_ will exceed our inernal page limit, turn on internal paging
+ if (head_->databytes()+offset > PAGELIMIT) {
+ mapsize_ = PAGELIMIT;
+ page_ = 1;
+
+ dseek_ = seek_;
+ nseek_ = seek_-offset;
+ }
+ else {
+ // small enough, no internal paging
+ mapsize_ = head_->databytes()+offset;
+ page_ = 0;
+ }
+ }
+ mapdata_ = (char*)mmap(NULL, mapsize_, PROT_READ, MAP_SHARED, fd, mmseek);
+ close(fd);
+
+ // are we valid? (we'd better be!)
+ if ((long)mapdata_ == -1) {
+ mapsize_ = 0;
+ mapdata_ = NULL;
+ error();
+ return;
+ }
+
+ // seek to next hdu, even if we are internal paging
+ seek_ += head_->databytes();
+ // data starts after any page boundary
+ data_ = mapdata_+offset;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = 0;
+
+ inherit_ = head_->inherit();
+ valid_ = 1;
+}
+
+char* FitsMapIncr::page(char* ptr, size_t row)
+{
+ if (!page_)
+ // no paging, just return
+ return ptr;
+ else {
+ // be sure that at least 'row' bytes are still available
+ if (ptr <= mapdata_+mapsize_-row)
+ // no problem yet
+ return ptr;
+ else {
+ // how far did we get
+ nseek_ += ptr-mapdata_;
+ // unmap the old segment
+ munmap((caddr_t)mapdata_, mapsize_);
+
+ // next mmap segment
+ int pagesize = getpagesize();
+ off_t mmseek = (nseek_/pagesize)*pagesize;
+ size_t offset = nseek_ - mmseek;
+
+ int fd = open(pName_, O_RDONLY);
+
+ // calc next internal page size
+ if (head_->databytes()+offset-(nseek_-dseek_) > PAGELIMIT)
+ mapsize_ = PAGELIMIT;
+ else
+ mapsize_ = head_->databytes()+offset-(nseek_-dseek_);
+
+ mapdata_ =(char*)mmap(NULL, mapsize_, PROT_READ, MAP_SHARED, fd, mmseek);
+ close(fd);
+
+ // are we valid? (we'd better be!)
+ if ((long)mapdata_ == -1) {
+ //*** what to do here?
+ internalError("Fitsy++ mapincr page() error");
+ mapsize_ = 0;
+ mapdata_ = NULL;
+ }
+
+ nseek_ -= offset;
+ return mapdata_+offset;
+ }
+ }
+}
+
+void FitsMapIncr::resetpage()
+{
+ if (page_) {
+ // ok, get a new page
+ munmap((caddr_t)mapdata_, mapsize_);
+
+ // remap original page
+ int pagesize = getpagesize();
+ off_t mmseek = (dseek_/pagesize)*pagesize;
+ size_t offset = dseek_ - mmseek;
+
+ int fd = open(pName_, O_RDONLY);
+
+ if (head_->databytes()+offset > PAGELIMIT)
+ mapsize_ = PAGELIMIT;
+ else
+ mapsize_ = head_->databytes()+offset;
+
+ mapdata_ =(char*)mmap(NULL, mapsize_, PROT_READ, MAP_SHARED, fd, mmseek);
+ close(fd);
+
+ // are we valid? (we'd better be!)
+ if ((long)mapdata_ == -1) {
+ //*** what to do here?
+ internalError("Fitsy++ mapincr resetpage() error");
+ mapsize_ = 0;
+ mapdata_ = NULL;
+ }
+
+ // reset, we may have moved in memory
+ // found the data, save it
+ nseek_ = dseek_-offset;
+ data_ = mapdata_+offset;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = offset;
+ }
+}
+
+void FitsMapIncr::error()
+{
+ if (manageHead_ && head_)
+ delete head_;
+ head_ = NULL;
+
+ if (managePrimary_ && primary_)
+ delete primary_;
+ primary_ = NULL;
+
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ valid_ = 0;
+}
+
+FitsFitsMapIncr::FitsFitsMapIncr(ScanMode mode)
+{
+ if (!valid_)
+ return;
+
+ if (mode == EXACT || pExt_ || pIndex_>-1)
+ processExact();
+ else
+ processRelax();
+}
+
+void FitsFitsMapIncr::processExact()
+{
+ // simple check for fits file
+ if (!(pExt_ || (pIndex_>0))) {
+
+ // we are only looking for a primary image
+ head_ = headRead();
+ if (head_ && head_->isValid()) {
+ found();
+ return;
+ }
+ }
+ else {
+
+ // we are looking for an extension
+ // keep the primary header
+ primary_ = headRead();
+ managePrimary_ = 1;
+ if (!(primary_ && primary_->isValid())) {
+ error();
+ return;
+ }
+ dataSkipBlock(primary_->datablocks());
+
+ if (pExt_) {
+ while (seek_ < filesize_) {
+ head_ = headRead();
+ if (!(head_ && head_->isValid())) {
+ error();
+ return;
+ }
+ ext_++;
+
+ if (head_->extname()) {
+ char* a = toUpper(head_->extname());
+ char* b = toUpper(pExt_);
+ if (!strncmp(a,b,strlen(b))) {
+ delete [] a;
+ delete [] b;
+ found();
+ return;
+ }
+ delete [] a;
+ delete [] b;
+ }
+ dataSkipBlock(head_->datablocks());
+ delete head_;
+ head_ = NULL;
+ }
+ }
+ else {
+ for (int i=1; i<pIndex_ && seek_<filesize_; i++) {
+ head_ = headRead();
+ if (!(head_ && head_->isValid())) {
+ error();
+ return;
+ }
+ ext_++;
+
+ dataSkipBlock(head_->datablocks());
+ delete head_;
+ head_ = NULL;
+ }
+
+ head_ = headRead();
+ if (head_ && head_->isValid()) {
+ ext_++;
+ found();
+ return;
+ }
+ }
+ }
+
+ // Must have an error
+ error();
+}
+
+void FitsFitsMapIncr::processRelax()
+{
+ // check to see if there is an image in the primary
+ head_ = headRead();
+ if (!(head_ && head_->isValid())) {
+ error();
+ return;
+ }
+
+ if (head_ &&
+ head_->isValid() &&
+ head_->naxes() > 0 &&
+ head_->naxis(0) > 0 &&
+ head_->naxis(1) > 0) {
+ found();
+ return;
+ }
+
+ // ok, no image, save primary and lets check extensions
+ primary_ = head_;
+ managePrimary_ = 1;
+ dataSkipBlock(head_->datablocks());
+ head_ = NULL;
+
+ while (seek_ < filesize_) {
+ head_ = headRead();
+ if (!(head_ && head_->isValid())) {
+ error();
+ return;
+ }
+ ext_++;
+
+ // check for image
+ if (head_->isImage()) {
+ found();
+ return;
+ }
+
+ // else, check for compressed image
+ if (head_->isBinTable() && head_->find("ZIMAGE")) {
+ found();
+ return;
+ }
+
+ // else, check for bin table named STDEVT, EVENTS, RAYEVENT
+ if (head_->isBinTable() && head_->extname()) {
+ char* a = toUpper(head_->extname());
+ if (!strncmp("STDEVT", a, 6) ||
+ !strncmp("EVENTS", a, 6) ||
+ !strncmp("RAYEVENT", a, 8)) {
+ delete [] a;
+ found();
+ return;
+ }
+ else
+ delete [] a;
+ }
+
+ // else, check for bin table with keyword PIXTYPE = 'HEALPIX '
+ if (head_->isBinTable() && head_->find("PIXTYPE") &&
+ (!strncmp(head_->getString("PIXTYPE"),"HEALPIX",4))) {
+ found();
+ return;
+ }
+
+ // else, check for bin table with keyword NSIDE (also HEALPIX)
+ if (head_->isBinTable() && head_->find("NSIDE")) {
+ found();
+ return;
+ }
+
+ dataSkipBlock(head_->datablocks());
+ delete head_;
+ head_ = NULL;
+ }
+
+ // did not find anything, bail out
+ error();
+}
+
+FitsFitsNextMapIncr::FitsFitsNextMapIncr(FitsFile* p)
+{
+ FitsMapIncr* prev = (FitsMapIncr*)p;
+
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = prev->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ pcoord_ = prev->pcoord();
+ pxvalid_ = prev->pxvalid();
+ pxmin_ = prev->pxmin();
+ pxmax_ = prev->pxmax();
+ pyvalid_ = prev->pyvalid();
+ pymin_ = prev->pymin();
+ pymax_ = prev->pymax();
+ pzvalid_ = prev->pzvalid();
+ pzmin_ = prev->pzmin();
+ pzmax_ = prev->pzmax();
+ pbvalid_ = prev->pbvalid();
+ pblock_ = prev->pblock();
+
+ filesize_ = prev->filesize();
+ seek_ = prev->seek();
+
+ return;
+}
+
+FitsArrMapIncr::FitsArrMapIncr()
+{
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ = 0;
+
+ // check to see if we have a nonzero width, height, and bitpix
+ if (!validParams())
+ return;
+
+ // check to see if dimensions equal mapped space
+ size_t mmsize = ((size_t)pWidth_*pHeight_*pDepth_*abs(pBitpix_)/8) + pSkip_;
+
+ if (mmsize > filesize_)
+ return;
+
+ // skip to start of data
+ int fd = open(pName_, O_RDONLY);
+ char* mmdata = (char*)mmap(NULL, mmsize, PROT_READ, MAP_SHARED, fd, 0);
+ close(fd);
+
+ // are we valid?
+ if ((long)mmdata == -1)
+ return;
+
+ // new header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_,
+ mmdata, mmsize, FitsHead::ALLOC);
+ if (!head_->isValid())
+ return;
+
+ seek_ = mmsize;
+ data_ = mmdata + pSkip_;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = pSkip_;
+
+ // do we byteswap?
+ setByteSwap();
+
+ // made it this far, must be valid
+ valid_ = 1;
+}
+
+FitsMosaicMapIncr::FitsMosaicMapIncr()
+{
+ if (!valid_)
+ return;
+
+ // keep the primary header
+ primary_ = headRead();
+ managePrimary_ = 1;
+ if (!(primary_ && primary_->isValid())) {
+ error();
+ return;
+ }
+ dataSkipBlock(primary_->datablocks());
+
+ // first extension
+ head_ = headRead();
+ if (!(head_ && head_->isValid())) {
+ error();
+ return;
+ }
+ ext_++;
+ found();
+}
+
+FitsMosaicNextMapIncr::FitsMosaicNextMapIncr(FitsFile* p)
+{
+ FitsMapIncr* prev = (FitsMapIncr*)p;
+
+ pName_ = dupstr(prev->pName());
+ filesize_ = prev->filesize();
+ seek_ = prev->seek();
+
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+ ext_ = prev->ext();
+
+ head_ = headRead();
+ if (!(head_ && head_->isValid())) {
+ error();
+ return;
+ }
+ ext_++;
+ found();
+}
+
+#else
+
+FitsMapIncr::FitsMapIncr()
+{
+ mapdata_ = NULL;
+ mapsize_ = 0;
+}
+
+FitsMapIncr::~FitsMapIncr() {}
+
+FitsHead* FitsMapIncr::headRead() {}
+void FitsMapIncr::dataSkip(size_t bytes) {}
+void FitsMapIncr::dataSkipBlock(size_t blk) {}
+void FitsMapIncr::found() {}
+char* FitsMapIncr::page(char* ptr, size_t row)
+{
+ return NULL;
+}
+void FitsMapIncr::resetpage() {}
+void FitsMapIncr::error() {}
+FitsFitsMapIncr::FitsFitsMapIncr(ScanMode mode) {}
+void FitsFitsMapIncr::processExact() {}
+void FitsFitsMapIncr::processRelax() {}
+
+FitsFitsNextMapIncr::FitsFitsNextMapIncr(FitsFile* p) {}
+FitsArrMapIncr::FitsArrMapIncr() {}
+FitsMosaicMapIncr::FitsMosaicMapIncr() {}
+FitsMosaicNextMapIncr::FitsMosaicNextMapIncr(FitsFile* p) {}
+#endif
diff --git a/fitsy++/mapincr.h b/fitsy++/mapincr.h
new file mode 100644
index 0000000..fcdea15
--- /dev/null
+++ b/fitsy++/mapincr.h
@@ -0,0 +1,67 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsmapincr_h__
+#define __fitsmapincr_h__
+
+#include "file.h"
+
+class FitsMapIncr : public FitsFile {
+protected:
+ char* mapdata_; // mmap segment ptr
+ size_t mapsize_; // mmap segment size
+ int page_; // flag to indicate paging mode
+
+ size_t filesize_; // size of the total segment
+ size_t seek_; // offset into segment
+ size_t dseek_; // offset to data segment
+ size_t nseek_; // offset into next page data segment
+
+ FitsHead* headRead();
+ void dataSkip(size_t);
+ void dataSkipBlock(size_t);
+ void found();
+ void error();
+
+public:
+ FitsMapIncr();
+ virtual ~FitsMapIncr();
+
+ char* page(char*, size_t);
+ void resetpage();
+ size_t filesize() {return filesize_;}
+ size_t seek() {return seek_;}
+};
+
+class FitsFitsMapIncr : public virtual FitsMapIncr {
+protected:
+ void processExact();
+ void processRelax();
+
+public:
+ FitsFitsMapIncr(ScanMode);
+};
+
+class FitsFitsNextMapIncr : public FitsMapIncr {
+public:
+ FitsFitsNextMapIncr(FitsFile* prev);
+};
+
+class FitsArrMapIncr : public virtual FitsMapIncr {
+public:
+ FitsArrMapIncr();
+};
+
+class FitsMosaicMapIncr : public virtual FitsMapIncr {
+public:
+ FitsMosaicMapIncr();
+};
+
+class FitsMosaicNextMapIncr : public FitsMapIncr {
+public:
+ FitsMosaicNextMapIncr(FitsFile* prev);
+};
+
+#endif
+
diff --git a/fitsy++/mmap.C b/fitsy++/mmap.C
new file mode 100644
index 0000000..2d7d89d
--- /dev/null
+++ b/fitsy++/mmap.C
@@ -0,0 +1,68 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "mmap.h"
+
+#ifndef __WIN32
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+FitsMMap::FitsMMap(const char* fn)
+{
+ // parse the fn and options
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ = 0;
+
+ if (!pName_)
+ return;
+
+ // Map the file.
+ int file = open(pName_, O_RDONLY);
+ if (file == -1)
+ return;
+
+ struct stat info;
+ if (fstat(file, &info) < 0)
+ return;
+
+ // check to see if we have something, we may have a small array
+ if (info.st_size <= 0)
+ return;
+
+ // map it
+ mapsize_ = info.st_size;
+ mapdata_ = (char*)mmap(NULL, mapsize_, PROT_READ, MAP_SHARED, file, 0);
+
+ // close the file
+ close(file);
+
+ // are we valid?
+ if ((long)mapdata_ == -1)
+ return;
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsMMap::~FitsMMap()
+{
+ if (mapdata_)
+ munmap((caddr_t)mapdata_, mapsize_);
+}
+
+#else
+
+FitsMMap::FitsMMap(const char* fn) {}
+FitsMMap::~FitsMMap() {}
+
+#endif
+
diff --git a/fitsy++/mmap.h b/fitsy++/mmap.h
new file mode 100644
index 0000000..b13ec63
--- /dev/null
+++ b/fitsy++/mmap.h
@@ -0,0 +1,47 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsmmap_h__
+#define __fitsmmap_h__
+
+#include "map.h"
+
+class FitsMMap : public virtual FitsMap {
+public:
+ FitsMMap(const char*);
+ virtual ~FitsMMap();
+};
+
+class FitsFitsMMap : public FitsMMap, public FitsFitsMap {
+public:
+ FitsFitsMMap(const char* fn, ScanMode mode)
+ : FitsMMap(fn), FitsFitsMap(mode) {}
+};
+
+class FitsFitsNextMMap : public FitsFitsNextMap {
+public:
+ FitsFitsNextMMap(FitsFile* prev) : FitsFitsNextMap(prev) {}
+};
+
+class FitsArrMMap : public FitsMMap, public FitsArrMap {
+public:
+ FitsArrMMap(const char* fn) : FitsMMap(fn), FitsArrMap() {}
+};
+
+class FitsNRRDMMap : public FitsMMap, public FitsNRRDMap {
+public:
+ FitsNRRDMMap(const char* fn) : FitsMMap(fn), FitsNRRDMap() {}
+};
+
+class FitsMosaicMMap : public FitsMMap, public FitsMosaicMap {
+public:
+ FitsMosaicMMap(const char* fn) : FitsMMap(fn), FitsMosaicMap() {}
+};
+
+class FitsMosaicNextMMap : public FitsMosaicNextMap {
+public:
+ FitsMosaicNextMMap(FitsFile* prev) : FitsMosaicNextMap(prev) {}
+};
+
+#endif
diff --git a/fitsy++/mmapincr.C b/fitsy++/mmapincr.C
new file mode 100644
index 0000000..b0118d3
--- /dev/null
+++ b/fitsy++/mmapincr.C
@@ -0,0 +1,53 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "mmapincr.h"
+
+#ifndef __WIN32
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+FitsMMapIncr::FitsMMapIncr(const char* fn)
+{
+ // parse the fn and options
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ if (!pName_)
+ return;
+
+ // Map the file.
+ int fd = open(pName_, O_RDONLY);
+ if (fd == -1)
+ return;
+
+ struct stat info;
+ if (fstat(fd, &info) < 0)
+ return;
+
+ close(fd);
+
+ // check to see if we have something, we may have a small array
+ if (info.st_size <= 0)
+ return;
+
+ filesize_ = info.st_size;
+
+ // so far, so good
+ valid_ = 1;
+}
+
+#else
+
+FitsMMapIncr::FitsMMapIncr(const char* fn) {}
+
+#endif
diff --git a/fitsy++/mmapincr.h b/fitsy++/mmapincr.h
new file mode 100644
index 0000000..0355e78
--- /dev/null
+++ b/fitsy++/mmapincr.h
@@ -0,0 +1,41 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsmmapincr_h__
+#define __fitsmmapincr_h__
+
+#include "mapincr.h"
+
+class FitsMMapIncr : public virtual FitsMapIncr {
+public:
+ FitsMMapIncr(const char*);
+};
+
+class FitsFitsMMapIncr : public FitsMMapIncr, public FitsFitsMapIncr {
+public:
+ FitsFitsMMapIncr(const char* fn, ScanMode mode)
+ : FitsMMapIncr(fn), FitsFitsMapIncr(mode) {}
+};
+
+class FitsFitsNextMMapIncr : public FitsFitsNextMapIncr {
+public:
+ FitsFitsNextMMapIncr(FitsFile* prev) : FitsFitsNextMapIncr(prev) {}
+};
+
+class FitsArrMMapIncr : public FitsMMapIncr, public FitsArrMapIncr {
+public:
+ FitsArrMMapIncr(const char* fn) : FitsMMapIncr(fn), FitsArrMapIncr() {}
+};
+
+class FitsMosaicMMapIncr : public FitsMMapIncr, public FitsMosaicMapIncr {
+public:
+ FitsMosaicMMapIncr(const char* fn) : FitsMMapIncr(fn), FitsMosaicMapIncr() {}
+};
+
+class FitsMosaicNextMMapIncr : public FitsMosaicNextMapIncr {
+public:
+ FitsMosaicNextMMapIncr(FitsFile* prev) : FitsMosaicNextMapIncr(prev) {}
+};
+
+#endif
diff --git a/fitsy++/nrrd.C b/fitsy++/nrrd.C
new file mode 100644
index 0000000..867f5d4
--- /dev/null
+++ b/fitsy++/nrrd.C
@@ -0,0 +1,81 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "nrrd.h"
+#include "head.h"
+#include "util.h"
+
+FitsNRRD::FitsNRRD(FitsFile* fits)
+{
+ byteswap_ = fits->byteswap();
+ endian_ = fits->endian();
+
+ pBitpix_ = fits->pBitpix();
+ pWidth_ = fits->pWidth();
+ pHeight_ = fits->pHeight();
+ pDepth_ = fits->pDepth();
+
+ size_ = (size_t)pWidth_*pHeight_*pDepth_;
+}
+
+FitsNRRD::~FitsNRRD()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+int FitsNRRD::initHeader(FitsFile* fits)
+{
+ // simple check
+ if (!pWidth_ || !pHeight_ || !pBitpix_)
+ return 0;
+
+ // create header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return 0;
+
+ // other
+ primary_ = fits->primary();
+ managePrimary_ = 0;
+
+ inherit_ = head_->inherit();
+
+ return 1;
+}
+
+template<class T> FitsNRRDm<T>::FitsNRRDm(FitsFile* fits)
+ : FitsNRRD(fits)
+{
+}
+
+template <class T> void FitsNRRDm<T>::uncompress(FitsFile* fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ nrrd unable to allocate memory");
+ return;
+ }
+ memset(dest, 0, size_*sizeof(T));
+ compressed(dest, (char*)fits->data(), fits->dataSize()-fits->dataSkip());
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ // all done
+ valid_ = 1;
+}
+
+template class FitsNRRDm<unsigned char>;
+template class FitsNRRDm<short>;
+template class FitsNRRDm<unsigned short>;
+template class FitsNRRDm<int>;
+template class FitsNRRDm<long long>;
+template class FitsNRRDm<float>;
+template class FitsNRRDm<double>;
diff --git a/fitsy++/nrrd.h b/fitsy++/nrrd.h
new file mode 100644
index 0000000..6151fee
--- /dev/null
+++ b/fitsy++/nrrd.h
@@ -0,0 +1,36 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsnrrd_h__
+#define __fitsnrrd_h__
+
+#include "file.h"
+
+class FitsNRRD : public FitsFile {
+ protected:
+ size_t size_;
+
+ protected:
+ int initHeader(FitsFile*);
+
+ public:
+ FitsNRRD(FitsFile*);
+ virtual ~FitsNRRD();
+};
+
+template<class T>
+class FitsNRRDm : public FitsNRRD {
+ private:
+ void swapBytes(FitsFile::ArchType);
+
+ protected:
+ void uncompress(FitsFile* fits);
+ virtual int compressed(T*, char*, size_t) =0;
+
+ public:
+ FitsNRRDm(FitsFile*);
+};
+
+#endif
+
diff --git a/fitsy++/nrrdgzip.C b/fitsy++/nrrdgzip.C
new file mode 100644
index 0000000..e030391
--- /dev/null
+++ b/fitsy++/nrrdgzip.C
@@ -0,0 +1,84 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "nrrdgzip.h"
+#include "zlib.h"
+#include "util.h"
+
+template<class T> FitsNRRDGzipm<T>::FitsNRRDGzipm(FitsFile* fits)
+ : FitsNRRDm<T>(fits)
+{
+ FitsNRRDm<T>::uncompress(fits);
+}
+
+template <class T> int FitsNRRDGzipm<T>::compressed(T* dest, char* src,
+ size_t sz)
+
+{
+ z_stream zstrm;
+ zstrm.zalloc = NULL;
+ zstrm.zfree = NULL;
+ zstrm.opaque = NULL;
+ zstrm.avail_in = sz;
+ zstrm.next_in = (Bytef*)src;
+ zstrm.avail_out = this->size_*sizeof(T);
+ zstrm.next_out = (Bytef*)dest;
+
+ // look for both zlib and gzip headers
+ if (inflateInit2(&zstrm, MAX_WBITS+32) != Z_OK) {
+ internalError("Fitsy++ gzip inflateInit error");
+ return 0;
+ }
+
+ if (DebugCompress)
+ cerr << " inflate START: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+
+ int result = ::inflate(&zstrm, Z_FINISH);
+
+ switch (result) {
+ case Z_OK:
+ if (DebugCompress)
+ cerr << " inflate OK: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_STREAM_END:
+ if (DebugCompress)
+ cerr << " inflate STREAM_END: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out
+ << " total_in " << zstrm.total_in
+ << " total_out " << zstrm.total_out << endl;
+ break;
+ case Z_BUF_ERROR:
+ if (DebugCompress)
+ cerr << " inflate BUF_ERROR: avail_in " << zstrm.avail_in
+ << " avail_out " << zstrm.avail_out << endl;
+ return 0;
+ default:
+ internalError("Fitsy++ gzip inflate error");
+ return 0;
+ }
+
+ inflateEnd(&zstrm);
+
+ return 1;
+}
+
+template class FitsNRRDGzipm<unsigned char>;
+template class FitsNRRDGzipm<short>;
+template class FitsNRRDGzipm<unsigned short>;
+template class FitsNRRDGzipm<int>;
+template class FitsNRRDGzipm<long long>;
+template class FitsNRRDGzipm<float>;
+template class FitsNRRDGzipm<double>;
+
diff --git a/fitsy++/nrrdgzip.h b/fitsy++/nrrdgzip.h
new file mode 100644
index 0000000..9cc955d
--- /dev/null
+++ b/fitsy++/nrrdgzip.h
@@ -0,0 +1,19 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsnrrdgzip_h__
+#define __fitsnrrdgzip_h__
+
+#include "nrrd.h"
+
+template<class T>
+class FitsNRRDGzipm : public FitsNRRDm<T> {
+ private:
+ int compressed(T*, char*, size_t);
+
+ public:
+ FitsNRRDGzipm(FitsFile*);
+};
+
+#endif
diff --git a/fitsy++/nrrdlex.C b/fitsy++/nrrdlex.C
new file mode 100644
index 0000000..a456ec6
--- /dev/null
+++ b/fitsy++/nrrdlex.C
@@ -0,0 +1,2462 @@
+#line 2 "../fitsy/nrrdlex.C"
+
+#line 4 "../fitsy/nrrdlex.C"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+ /* The c++ scanner is a mess. The FlexLexer.h header file relies on the
+ * following macro. This is required in order to pass the c++-multiple-scanners
+ * test in the regression suite. We get reports that it breaks inheritance.
+ * We will address this in a future release of flex, or omit the C++ scanner
+ * altogether.
+ */
+ #define yyFlexLexer nrrdFlexLexer
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+typedef uint64_t flex_uint64_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+/* begin standard C++ headers. */
+#include <iostream>
+#include <errno.h>
+#include <cstdlib>
+#include <cstring>
+/* end standard C++ headers. */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+extern yy_size_t yyleng;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+
+ std::istream* yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+void *nrrdalloc (yy_size_t );
+void *nrrdrealloc (void *,yy_size_t );
+void nrrdfree (void * );
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+#define yytext_ptr yytext
+
+#include <FlexLexer.h>
+
+int yyFlexLexer::yywrap() { return 1; }
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ yyleng = (yy_size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+
+#define YY_NUM_RULES 105
+#define YY_END_OF_BUFFER 106
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[359] =
+ { 0,
+ 0, 0, 2, 2, 106, 104, 100, 103, 104, 104,
+ 104, 95, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 104, 104, 2, 1, 100, 101, 0, 95, 97,
+ 96, 95, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 58, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 4, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 102, 0, 98, 2, 0, 0, 0, 96, 99, 99,
+
+ 63, 99, 99, 60, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 57, 29, 99, 99, 99, 99, 99, 69, 67, 99,
+ 99, 99, 99, 5, 66, 99, 53, 99, 99, 99,
+ 99, 99, 99, 99, 99, 54, 99, 99, 99, 99,
+ 99, 99, 99, 96, 0, 97, 99, 82, 99, 74,
+ 99, 89, 99, 22, 99, 11, 99, 99, 99, 99,
+ 99, 99, 99, 12, 99, 59, 99, 99, 99, 23,
+ 99, 99, 72, 99, 40, 85, 83, 90, 91, 99,
+ 99, 99, 99, 99, 99, 99, 50, 71, 99, 55,
+
+ 99, 19, 99, 37, 99, 99, 99, 99, 99, 56,
+ 99, 49, 99, 61, 99, 99, 3, 99, 99, 99,
+ 99, 99, 99, 47, 30, 35, 42, 0, 93, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 28,
+ 99, 79, 13, 99, 99, 25, 99, 26, 99, 14,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 48, 99, 62, 0, 0, 0, 24,
+ 92, 99, 64, 99, 99, 76, 70, 68, 16, 77,
+ 20, 99, 99, 38, 0, 99, 99, 99, 99, 32,
+ 99, 99, 99, 99, 99, 87, 65, 99, 99, 99,
+
+ 94, 99, 31, 36, 43, 99, 99, 99, 99, 99,
+ 99, 0, 27, 33, 45, 99, 99, 86, 84, 99,
+ 75, 99, 99, 99, 99, 52, 73, 41, 6, 7,
+ 8, 9, 10, 99, 80, 99, 39, 0, 0, 99,
+ 21, 51, 99, 18, 99, 99, 99, 81, 34, 46,
+ 99, 88, 15, 17, 99, 44, 78, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 5, 1, 5, 6, 1, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15, 14, 1, 1, 1,
+ 1, 1, 1, 1, 16, 17, 18, 19, 20, 21,
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 25, 32, 33, 34, 35, 25, 36, 37, 38, 39,
+ 1, 40, 1, 1, 41, 1, 42, 43, 44, 45,
+
+ 46, 47, 48, 49, 50, 25, 51, 52, 53, 54,
+ 55, 56, 25, 57, 58, 59, 60, 25, 61, 62,
+ 63, 64, 65, 1, 66, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[67] =
+ { 0,
+ 1, 1, 2, 1, 3, 4, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 6, 6, 6, 6, 7,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 1,
+ 1, 6, 6, 6, 6, 7, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 1, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[367] =
+ { 0,
+ 0, 0, 1080, 1073, 1060, 1098, 1055, 1098, 1051, 1047,
+ 60, 70, 80, 81, 91, 106, 89, 82, 85, 83,
+ 96, 1046, 104, 135, 147, 149, 141, 158, 204, 176,
+ 218, 69, 985, 0, 1098, 1047, 1098, 270, 166, 81,
+ 137, 280, 1042, 322, 174, 152, 169, 201, 101, 199,
+ 205, 210, 215, 160, 223, 290, 310, 295, 292, 244,
+ 291, 305, 314, 296, 306, 340, 346, 318, 347, 352,
+ 345, 350, 351, 360, 1040, 358, 197, 356, 355, 382,
+ 362, 377, 353, 383, 386, 385, 390, 389, 405, 411,
+ 1098, 979, 1098, 0, 1039, 1038, 457, 467, 434, 429,
+
+ 1036, 408, 195, 1035, 430, 477, 479, 482, 483, 484,
+ 485, 486, 487, 489, 491, 488, 497, 490, 493, 492,
+ 1034, 441, 496, 505, 510, 506, 522, 513, 516, 544,
+ 546, 518, 551, 1032, 547, 554, 1026, 548, 549, 553,
+ 552, 555, 571, 561, 578, 1023, 563, 572, 567, 574,
+ 587, 581, 591, 640, 649, 658, 668, 585, 593, 579,
+ 87, 1022, 669, 1021, 670, 1013, 671, 672, 673, 674,
+ 675, 676, 678, 1012, 677, 1011, 86, 239, 259, 98,
+ 679, 680, 681, 682, 698, 1010, 1009, 1008, 1005, 257,
+ 702, 707, 704, 724, 699, 723, 729, 1004, 732, 955,
+
+ 734, 949, 735, 438, 736, 738, 739, 741, 740, 889,
+ 749, 747, 753, 841, 758, 755, 840, 768, 760, 769,
+ 794, 782, 801, 837, 265, 267, 269, 391, 771, 775,
+ 777, 804, 805, 297, 780, 807, 810, 812, 811, 700,
+ 823, 697, 694, 816, 819, 693, 418, 381, 610, 691,
+ 814, 832, 815, 828, 846, 847, 848, 852, 845, 853,
+ 857, 872, 850, 690, 876, 639, 576, 833, 850, 1098,
+ 637, 882, 635, 883, 618, 634, 633, 630, 626, 881,
+ 624, 895, 874, 521, 859, 621, 354, 907, 905, 623,
+ 909, 913, 885, 908, 915, 495, 453, 893, 920, 922,
+
+ 436, 925, 1098, 1098, 1098, 923, 934, 975, 939, 930,
+ 932, 899, 1098, 921, 929, 966, 947, 431, 425, 954,
+ 422, 972, 951, 970, 983, 417, 348, 315, 311, 303,
+ 301, 299, 261, 985, 255, 989, 1098, 964, 967, 996,
+ 237, 231, 997, 181, 998, 1000, 1002, 172, 1098, 1098,
+ 991, 163, 161, 109, 1001, 94, 88, 1098, 1061, 1065,
+ 1067, 1074, 1081, 1084, 1089, 1092
+ } ;
+
+static yyconst flex_int16_t yy_def[367] =
+ { 0,
+ 358, 1, 359, 359, 358, 358, 358, 358, 358, 360,
+ 358, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 358, 362, 363, 358, 358, 358, 358, 360, 364,
+ 364, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 358, 362, 358, 363, 365, 366, 358, 361, 361, 361,
+
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 358, 358, 358, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 358, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 358, 358, 358, 358,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 358, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+
+ 361, 361, 358, 358, 358, 361, 361, 361, 361, 361,
+ 361, 358, 358, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 361, 361,
+ 361, 361, 361, 361, 361, 361, 358, 358, 358, 361,
+ 361, 361, 361, 361, 361, 361, 361, 361, 358, 358,
+ 361, 361, 361, 361, 361, 361, 361, 0, 358, 358,
+ 358, 358, 358, 358, 358, 358
+ } ;
+
+static yyconst flex_int16_t yy_nxt[1165] =
+ { 0,
+ 6, 7, 8, 9, 10, 11, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
+ 22, 28, 29, 30, 31, 22, 22, 22, 22, 32,
+ 6, 13, 14, 15, 16, 17, 18, 19, 20, 21,
+ 23, 24, 25, 26, 27, 22, 28, 29, 30, 31,
+ 22, 22, 22, 22, 33, 6, 40, 40, 40, 40,
+ 40, 40, 40, 40, 40, 41, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 358, 358, 358, 358, 44,
+ 358, 358, 358, 358, 358, 214, 358, 91, 225, 358,
+
+ 96, 358, 62, 358, 47, 59, 358, 48, 60, 358,
+ 51, 358, 45, 52, 358, 44, 46, 58, 49, 50,
+ 53, 54, 91, 61, 63, 55, 96, 64, 62, 56,
+ 47, 59, 48, 60, 103, 57, 51, 45, 228, 52,
+ 358, 46, 58, 49, 50, 53, 358, 54, 61, 63,
+ 65, 55, 358, 64, 358, 56, 95, 358, 66, 103,
+ 57, 73, 68, 358, 67, 358, 358, 74, 358, 75,
+ 69, 41, 76, 77, 358, 100, 65, 358, 70, 358,
+ 71, 358, 95, 72, 66, 95, 358, 73, 68, 67,
+ 101, 99, 74, 110, 75, 83, 69, 76, 84, 77,
+
+ 358, 100, 358, 70, 358, 71, 358, 104, 72, 358,
+ 358, 95, 85, 86, 160, 358, 101, 99, 110, 78,
+ 358, 83, 105, 358, 84, 108, 79, 80, 358, 81,
+ 102, 106, 137, 107, 82, 87, 358, 85, 86, 111,
+ 160, 88, 358, 109, 358, 78, 89, 226, 105, 358,
+ 90, 108, 79, 80, 81, 102, 106, 137, 107, 82,
+ 358, 87, 358, 234, 358, 111, 358, 88, 109, 227,
+ 358, 89, 358, 119, 358, 90, 40, 40, 40, 40,
+ 40, 40, 40, 40, 40, 41, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 358, 358, 358, 119, 44,
+
+ 358, 358, 358, 275, 358, 267, 358, 268, 358, 269,
+ 358, 358, 116, 117, 120, 358, 358, 112, 118, 358,
+ 358, 113, 124, 358, 123, 44, 97, 358, 98, 98,
+ 98, 98, 98, 98, 98, 98, 98, 114, 116, 117,
+ 120, 121, 112, 118, 115, 358, 113, 122, 124, 123,
+ 358, 358, 358, 358, 128, 358, 358, 358, 358, 358,
+ 358, 358, 114, 358, 315, 358, 121, 358, 125, 115,
+ 130, 134, 122, 126, 127, 129, 132, 133, 135, 128,
+ 131, 136, 358, 138, 139, 142, 358, 358, 358, 144,
+ 358, 358, 143, 125, 358, 358, 130, 134, 126, 127,
+
+ 129, 132, 133, 140, 135, 131, 145, 136, 138, 139,
+ 358, 142, 148, 358, 144, 147, 358, 149, 143, 146,
+ 141, 285, 358, 358, 270, 159, 284, 358, 150, 140,
+ 358, 151, 145, 153, 358, 358, 358, 152, 148, 358,
+ 147, 358, 149, 358, 146, 141, 358, 247, 177, 270,
+ 178, 159, 248, 179, 150, 180, 151, 157, 358, 153,
+ 161, 158, 152, 154, 154, 154, 154, 154, 154, 154,
+ 154, 154, 358, 98, 98, 98, 98, 98, 98, 98,
+ 98, 98, 358, 157, 358, 161, 158, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 166,
+
+ 358, 358, 358, 162, 170, 168, 169, 171, 175, 174,
+ 358, 358, 163, 164, 181, 358, 165, 172, 358, 167,
+ 173, 358, 176, 358, 182, 166, 358, 358, 162, 183,
+ 170, 168, 169, 171, 175, 174, 190, 163, 164, 184,
+ 181, 165, 172, 185, 167, 186, 173, 176, 187, 358,
+ 182, 358, 358, 358, 358, 183, 358, 358, 358, 358,
+ 358, 312, 190, 188, 184, 189, 358, 191, 358, 185,
+ 186, 197, 358, 187, 192, 193, 358, 358, 194, 358,
+ 195, 196, 202, 358, 358, 198, 358, 203, 199, 188,
+ 358, 189, 358, 191, 200, 201, 358, 197, 358, 192,
+
+ 204, 193, 205, 194, 208, 195, 196, 206, 202, 303,
+ 198, 213, 211, 203, 199, 358, 207, 286, 212, 200,
+ 209, 201, 287, 358, 308, 204, 358, 205, 358, 358,
+ 208, 358, 206, 314, 303, 358, 213, 211, 358, 358,
+ 358, 207, 358, 212, 358, 209, 154, 154, 154, 154,
+ 154, 154, 154, 154, 154, 156, 156, 156, 156, 156,
+ 156, 156, 156, 156, 156, 156, 156, 156, 156, 156,
+ 156, 156, 156, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 215, 216,
+ 219, 210, 217, 223, 222, 358, 358, 220, 358, 358,
+
+ 218, 221, 358, 358, 358, 358, 230, 358, 232, 358,
+ 224, 229, 358, 231, 215, 216, 219, 210, 217, 223,
+ 222, 235, 236, 220, 233, 218, 221, 238, 358, 358,
+ 237, 230, 240, 232, 358, 224, 229, 358, 231, 358,
+ 358, 358, 241, 358, 358, 358, 358, 235, 236, 233,
+ 239, 243, 358, 238, 358, 244, 237, 240, 358, 245,
+ 358, 242, 252, 358, 254, 358, 246, 251, 241, 249,
+ 250, 253, 255, 358, 358, 239, 358, 243, 257, 256,
+ 358, 244, 358, 259, 245, 358, 242, 358, 252, 258,
+ 254, 246, 251, 262, 249, 250, 253, 263, 255, 358,
+
+ 260, 261, 272, 257, 256, 265, 358, 271, 259, 358,
+ 358, 276, 358, 264, 258, 358, 358, 358, 262, 358,
+ 358, 358, 263, 273, 358, 260, 261, 272, 358, 266,
+ 280, 265, 271, 358, 274, 288, 276, 358, 278, 264,
+ 279, 281, 358, 277, 282, 358, 358, 283, 290, 273,
+ 358, 358, 358, 358, 266, 358, 280, 358, 358, 274,
+ 289, 288, 358, 278, 291, 279, 304, 281, 277, 282,
+ 293, 294, 283, 290, 292, 295, 298, 358, 297, 358,
+ 299, 358, 301, 305, 296, 289, 358, 358, 358, 291,
+ 358, 304, 313, 311, 358, 300, 293, 294, 358, 292,
+
+ 358, 295, 298, 297, 302, 306, 299, 301, 305, 296,
+ 358, 307, 358, 358, 358, 309, 310, 313, 358, 311,
+ 358, 300, 323, 320, 317, 358, 358, 358, 358, 302,
+ 358, 306, 337, 316, 358, 358, 307, 358, 321, 358,
+ 309, 318, 310, 322, 358, 319, 326, 323, 320, 324,
+ 317, 325, 358, 327, 358, 328, 358, 337, 316, 358,
+ 358, 338, 335, 321, 336, 341, 318, 334, 322, 339,
+ 319, 358, 326, 342, 324, 358, 325, 358, 327, 344,
+ 358, 328, 329, 330, 331, 332, 333, 335, 358, 336,
+ 358, 341, 334, 343, 358, 340, 358, 349, 345, 342,
+
+ 350, 358, 358, 358, 344, 358, 358, 358, 347, 358,
+ 358, 346, 356, 358, 358, 358, 358, 358, 358, 343,
+ 340, 348, 349, 345, 351, 350, 358, 358, 358, 352,
+ 353, 358, 354, 357, 347, 355, 346, 358, 356, 358,
+ 358, 358, 155, 97, 93, 358, 348, 358, 36, 351,
+ 93, 358, 38, 37, 352, 353, 36, 354, 357, 358,
+ 355, 34, 34, 34, 34, 34, 34, 34, 39, 39,
+ 43, 43, 43, 43, 92, 35, 92, 92, 92, 92,
+ 92, 94, 35, 94, 94, 94, 94, 94, 40, 358,
+ 40, 154, 358, 154, 156, 358, 156, 5, 358, 358,
+
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358
+ } ;
+
+static yyconst flex_int16_t yy_chk[1165] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 13, 14, 18, 20, 12,
+ 19, 177, 161, 357, 17, 161, 15, 32, 177, 356,
+
+ 40, 21, 20, 180, 14, 18, 49, 14, 18, 23,
+ 15, 16, 13, 15, 354, 12, 13, 17, 14, 14,
+ 15, 16, 32, 19, 21, 16, 40, 23, 20, 16,
+ 14, 18, 14, 18, 49, 16, 15, 13, 180, 15,
+ 24, 13, 17, 14, 14, 15, 27, 16, 19, 21,
+ 24, 16, 25, 23, 26, 16, 41, 46, 24, 49,
+ 16, 27, 25, 28, 24, 54, 353, 27, 352, 27,
+ 25, 39, 27, 28, 47, 46, 24, 348, 26, 45,
+ 26, 30, 41, 26, 24, 39, 344, 27, 25, 24,
+ 47, 45, 27, 54, 27, 30, 25, 27, 30, 28,
+
+ 103, 46, 77, 26, 50, 26, 48, 50, 26, 29,
+ 51, 39, 30, 30, 103, 52, 47, 45, 54, 29,
+ 53, 30, 50, 31, 30, 52, 29, 29, 55, 29,
+ 48, 51, 77, 51, 29, 31, 342, 30, 30, 55,
+ 103, 31, 341, 53, 178, 29, 31, 178, 50, 60,
+ 31, 52, 29, 29, 29, 48, 51, 77, 51, 29,
+ 335, 31, 190, 190, 179, 55, 333, 31, 53, 179,
+ 225, 31, 226, 60, 227, 31, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 42, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 56, 61, 59, 60, 42,
+
+ 58, 64, 234, 234, 332, 225, 331, 226, 330, 227,
+ 62, 65, 58, 58, 61, 57, 329, 56, 59, 63,
+ 328, 56, 65, 68, 64, 42, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44, 44, 57, 58, 58,
+ 61, 62, 56, 59, 57, 66, 56, 63, 65, 64,
+ 71, 67, 69, 327, 68, 72, 73, 70, 83, 287,
+ 79, 78, 57, 76, 287, 74, 62, 81, 66, 57,
+ 70, 73, 63, 66, 67, 69, 71, 72, 74, 68,
+ 70, 76, 82, 78, 79, 81, 248, 80, 84, 83,
+ 86, 85, 82, 66, 88, 87, 70, 73, 66, 67,
+
+ 69, 71, 72, 80, 74, 70, 84, 76, 78, 79,
+ 89, 81, 87, 102, 83, 86, 90, 88, 82, 85,
+ 80, 248, 326, 247, 228, 102, 247, 321, 89, 80,
+ 319, 89, 84, 90, 100, 105, 318, 89, 87, 99,
+ 86, 301, 88, 204, 85, 80, 122, 204, 122, 228,
+ 122, 102, 204, 122, 89, 122, 89, 99, 297, 90,
+ 105, 100, 89, 97, 97, 97, 97, 97, 97, 97,
+ 97, 97, 98, 98, 98, 98, 98, 98, 98, 98,
+ 98, 98, 106, 99, 107, 105, 100, 108, 109, 110,
+ 111, 112, 113, 116, 114, 118, 115, 120, 119, 110,
+
+ 296, 123, 117, 106, 114, 112, 113, 115, 119, 118,
+ 124, 126, 107, 108, 123, 125, 109, 116, 128, 111,
+ 117, 129, 120, 132, 124, 110, 284, 127, 106, 125,
+ 114, 112, 113, 115, 119, 118, 132, 107, 108, 126,
+ 123, 109, 116, 127, 111, 128, 117, 120, 129, 130,
+ 124, 131, 135, 138, 139, 125, 133, 141, 140, 136,
+ 142, 284, 132, 130, 126, 131, 144, 133, 147, 127,
+ 128, 141, 149, 129, 135, 136, 143, 148, 138, 150,
+ 139, 140, 147, 145, 160, 142, 152, 148, 143, 130,
+ 158, 131, 151, 133, 144, 145, 153, 141, 159, 135,
+
+ 149, 136, 150, 138, 152, 139, 140, 150, 147, 267,
+ 142, 160, 158, 148, 143, 249, 151, 249, 159, 144,
+ 153, 145, 249, 275, 275, 149, 286, 150, 290, 281,
+ 152, 279, 150, 286, 267, 278, 160, 158, 277, 276,
+ 273, 151, 271, 159, 266, 153, 154, 154, 154, 154,
+ 154, 154, 154, 154, 154, 155, 155, 155, 155, 155,
+ 155, 155, 155, 155, 156, 156, 156, 156, 156, 156,
+ 156, 156, 156, 157, 163, 165, 167, 168, 169, 170,
+ 171, 172, 175, 173, 181, 182, 183, 184, 163, 165,
+ 169, 157, 167, 173, 172, 264, 250, 170, 246, 243,
+
+ 168, 171, 242, 185, 195, 240, 182, 191, 184, 193,
+ 175, 181, 192, 183, 163, 165, 169, 157, 167, 173,
+ 172, 191, 192, 170, 185, 168, 171, 193, 196, 194,
+ 192, 182, 195, 184, 197, 175, 181, 199, 183, 201,
+ 203, 205, 196, 206, 207, 209, 208, 191, 192, 185,
+ 194, 199, 212, 193, 211, 199, 192, 195, 213, 201,
+ 216, 197, 208, 215, 211, 219, 203, 207, 196, 205,
+ 206, 209, 211, 218, 220, 194, 229, 199, 213, 212,
+ 230, 199, 231, 216, 201, 235, 197, 222, 208, 215,
+ 211, 203, 207, 219, 205, 206, 209, 220, 211, 221,
+
+ 218, 218, 231, 213, 212, 222, 223, 230, 216, 232,
+ 233, 235, 236, 221, 215, 237, 239, 238, 219, 251,
+ 253, 244, 220, 232, 245, 218, 218, 231, 241, 223,
+ 239, 222, 230, 254, 233, 251, 235, 252, 237, 221,
+ 238, 241, 224, 236, 244, 217, 214, 245, 253, 232,
+ 259, 255, 256, 257, 223, 263, 239, 258, 260, 233,
+ 252, 251, 261, 237, 254, 238, 268, 241, 236, 244,
+ 256, 257, 245, 253, 255, 258, 260, 262, 259, 283,
+ 261, 265, 263, 269, 258, 252, 280, 272, 274, 254,
+ 293, 268, 285, 283, 210, 262, 256, 257, 298, 255,
+
+ 282, 258, 260, 259, 265, 272, 261, 263, 269, 258,
+ 289, 274, 288, 294, 291, 280, 282, 285, 292, 283,
+ 295, 262, 298, 293, 289, 299, 314, 300, 306, 265,
+ 302, 272, 312, 288, 315, 310, 274, 311, 294, 307,
+ 280, 291, 282, 295, 309, 292, 302, 298, 293, 299,
+ 289, 300, 317, 306, 202, 307, 323, 312, 288, 320,
+ 200, 314, 310, 294, 311, 317, 291, 309, 295, 315,
+ 292, 316, 302, 320, 299, 324, 300, 322, 306, 323,
+ 308, 307, 308, 308, 308, 308, 308, 310, 325, 311,
+ 334, 317, 309, 322, 336, 316, 351, 338, 324, 320,
+
+ 339, 340, 343, 345, 323, 346, 355, 347, 334, 198,
+ 189, 325, 351, 188, 187, 186, 176, 174, 166, 322,
+ 316, 336, 338, 324, 340, 339, 164, 162, 146, 343,
+ 345, 137, 346, 355, 334, 347, 325, 134, 351, 121,
+ 104, 101, 96, 95, 92, 75, 336, 43, 36, 340,
+ 33, 22, 10, 9, 343, 345, 7, 346, 355, 5,
+ 347, 359, 359, 359, 359, 359, 359, 359, 360, 360,
+ 361, 361, 361, 361, 362, 4, 362, 362, 362, 362,
+ 362, 363, 3, 363, 363, 363, 363, 363, 364, 0,
+ 364, 365, 0, 365, 366, 0, 366, 358, 358, 358,
+
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "../fitsy/nrrdlex.L"
+/* Copyright (C) 1999-2018
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * For conditions of distribution and use, see copyright notice in "copyright"
+ */
+#line 11 "../fitsy/nrrdlex.L"
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #include "util.h"
+ #include "nrrdparser.H"
+
+ extern YYSTYPE* nrrdlval;
+ extern nrrdFlexLexer* nrrdlexx;
+
+/* rules */
+#line 799 "../fitsy/nrrdlex.C"
+
+#define INITIAL 0
+#define DISCARD 1
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+#define ECHO LexerOutput( yytext, yyleng )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+\
+ if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) LexerError( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+#define YY_DECL int yyFlexLexer::yylex()
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 29 "../fitsy/nrrdlex.L"
+
+
+#line 903 "../fitsy/nrrdlex.C"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = & std::cin;
+
+ if ( ! yyout )
+ yyout = & std::cout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of yytext. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 359 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 358 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+/* rule 1 can match eol */
+YY_RULE_SETUP
+#line 31 "../fitsy/nrrdlex.L"
+{ // special case-- #\n
+ BEGIN INITIAL;
+ yyless(0); // put back the terminator
+ strcpy(nrrdlval->str,""); // feed a blank string
+ return STRING;
+ }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 38 "../fitsy/nrrdlex.L"
+{ // Discard reset of line
+ BEGIN INITIAL;
+ int ll = yyleng <(NRRDPARSERSIZE-1) ? yyleng:(NRRDPARSERSIZE-1);
+ strncpy(nrrdlval->str,yytext,ll);
+ nrrdlval->str[ll] = '\0';
+ return STRING;
+ }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 46 "../fitsy/nrrdlex.L"
+{return DEBUG_;}
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 47 "../fitsy/nrrdlex.L"
+{return ON_;}
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 48 "../fitsy/nrrdlex.L"
+{return OFF_;}
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 50 "../fitsy/nrrdlex.L"
+{return NRRD0001_;}
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 51 "../fitsy/nrrdlex.L"
+{return NRRD0002_;}
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 52 "../fitsy/nrrdlex.L"
+{return NRRD0003_;}
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 53 "../fitsy/nrrdlex.L"
+{return NRRD0004_;}
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 54 "../fitsy/nrrdlex.L"
+{return NRRD0005_;}
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 56 "../fitsy/nrrdlex.L"
+{return DATA_;}
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 57 "../fitsy/nrrdlex.L"
+{return FILE_;}
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 59 "../fitsy/nrrdlex.L"
+{return SPACE_;}
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 60 "../fitsy/nrrdlex.L"
+{return UNITS_;}
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 61 "../fitsy/nrrdlex.L"
+{return DIMENSIONS_;}
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 62 "../fitsy/nrrdlex.L"
+{return ORIGIN_;}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 63 "../fitsy/nrrdlex.L"
+{return DIRECTIONS_;}
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 65 "../fitsy/nrrdlex.L"
+{return DIMENSION_;}
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 67 "../fitsy/nrrdlex.L"
+{return TYPE_;}
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 68 "../fitsy/nrrdlex.L"
+{return SIGNED_;}
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 69 "../fitsy/nrrdlex.L"
+{return UNSIGNED_;}
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 70 "../fitsy/nrrdlex.L"
+{return CHAR_;}
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 71 "../fitsy/nrrdlex.L"
+{return INT8_;}
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 72 "../fitsy/nrrdlex.L"
+{return INT8_T_;}
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 73 "../fitsy/nrrdlex.L"
+{return UCHAR_;}
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 74 "../fitsy/nrrdlex.L"
+{return UINT8_;}
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 75 "../fitsy/nrrdlex.L"
+{return UINT8_T_;}
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 76 "../fitsy/nrrdlex.L"
+{return SHORT_;}
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 77 "../fitsy/nrrdlex.L"
+{return INT_;}
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 78 "../fitsy/nrrdlex.L"
+{return INT16_;}
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 79 "../fitsy/nrrdlex.L"
+{return INT16_T_;}
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 80 "../fitsy/nrrdlex.L"
+{return USHORT_;}
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 81 "../fitsy/nrrdlex.L"
+{return UINT16_;}
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 82 "../fitsy/nrrdlex.L"
+{return UINT16_T_;}
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 83 "../fitsy/nrrdlex.L"
+{return INT32_;}
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 84 "../fitsy/nrrdlex.L"
+{return INT32_T_;}
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 85 "../fitsy/nrrdlex.L"
+{return UINT_;}
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 86 "../fitsy/nrrdlex.L"
+{return UINT32_;}
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 87 "../fitsy/nrrdlex.L"
+{return UINT32_T_;}
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 88 "../fitsy/nrrdlex.L"
+{return LONG_;}
+ YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 89 "../fitsy/nrrdlex.L"
+{return LONGLONG_;}
+ YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 90 "../fitsy/nrrdlex.L"
+{return INT64_;}
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 91 "../fitsy/nrrdlex.L"
+{return INT64_T_;}
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 92 "../fitsy/nrrdlex.L"
+{return ULONGLONG_;}
+ YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 93 "../fitsy/nrrdlex.L"
+{return UINT64_;}
+ YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 94 "../fitsy/nrrdlex.L"
+{return UINT64_T_;}
+ YY_BREAK
+case 47:
+YY_RULE_SETUP
+#line 95 "../fitsy/nrrdlex.L"
+{return FLOAT_;}
+ YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 96 "../fitsy/nrrdlex.L"
+{return DOUBLE_;}
+ YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 98 "../fitsy/nrrdlex.L"
+{return BLOCK_;}
+ YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 99 "../fitsy/nrrdlex.L"
+{return SIZE_;}
+ YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 100 "../fitsy/nrrdlex.L"
+{return BLOCKSIZE_;}
+ YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 102 "../fitsy/nrrdlex.L"
+{return ENCODING_;}
+ YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 103 "../fitsy/nrrdlex.L"
+{return RAW_;}
+ YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 104 "../fitsy/nrrdlex.L"
+{return TXT_;}
+ YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 105 "../fitsy/nrrdlex.L"
+{return TEXT_;}
+ YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 106 "../fitsy/nrrdlex.L"
+{return ASCII_;}
+ YY_BREAK
+case 57:
+YY_RULE_SETUP
+#line 107 "../fitsy/nrrdlex.L"
+{return HEX_;}
+ YY_BREAK
+case 58:
+YY_RULE_SETUP
+#line 108 "../fitsy/nrrdlex.L"
+{return GZ_;}
+ YY_BREAK
+case 59:
+YY_RULE_SETUP
+#line 109 "../fitsy/nrrdlex.L"
+{return GZIP_;}
+ YY_BREAK
+case 60:
+YY_RULE_SETUP
+#line 110 "../fitsy/nrrdlex.L"
+{return BZ2_;}
+ YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 111 "../fitsy/nrrdlex.L"
+{return BZIP2_;}
+ YY_BREAK
+case 62:
+YY_RULE_SETUP
+#line 113 "../fitsy/nrrdlex.L"
+{return ENDIAN_;}
+ YY_BREAK
+case 63:
+YY_RULE_SETUP
+#line 114 "../fitsy/nrrdlex.L"
+{return BIG_;}
+ YY_BREAK
+case 64:
+YY_RULE_SETUP
+#line 115 "../fitsy/nrrdlex.L"
+{return LITTLE_;}
+ YY_BREAK
+case 65:
+YY_RULE_SETUP
+#line 117 "../fitsy/nrrdlex.L"
+{return CONTENT_;}
+ YY_BREAK
+case 66:
+YY_RULE_SETUP
+#line 119 "../fitsy/nrrdlex.L"
+{return OLD_;}
+ YY_BREAK
+case 67:
+YY_RULE_SETUP
+#line 120 "../fitsy/nrrdlex.L"
+{return MIN_;}
+ YY_BREAK
+case 68:
+YY_RULE_SETUP
+#line 121 "../fitsy/nrrdlex.L"
+{return OLDMIN_;}
+ YY_BREAK
+case 69:
+YY_RULE_SETUP
+#line 122 "../fitsy/nrrdlex.L"
+{return MAX_;}
+ YY_BREAK
+case 70:
+YY_RULE_SETUP
+#line 123 "../fitsy/nrrdlex.L"
+{return OLDMAX_;}
+ YY_BREAK
+case 71:
+YY_RULE_SETUP
+#line 125 "../fitsy/nrrdlex.L"
+{return SKIP_;}
+ YY_BREAK
+case 72:
+YY_RULE_SETUP
+#line 126 "../fitsy/nrrdlex.L"
+{return LINE_;}
+ YY_BREAK
+case 73:
+YY_RULE_SETUP
+#line 127 "../fitsy/nrrdlex.L"
+{return LINESKIP_;}
+ YY_BREAK
+case 74:
+YY_RULE_SETUP
+#line 128 "../fitsy/nrrdlex.L"
+{return BYTE_;}
+ YY_BREAK
+case 75:
+YY_RULE_SETUP
+#line 129 "../fitsy/nrrdlex.L"
+{return BYTESKIP_;}
+ YY_BREAK
+case 76:
+YY_RULE_SETUP
+#line 131 "../fitsy/nrrdlex.L"
+{return NUMBER_;}
+ YY_BREAK
+case 77:
+YY_RULE_SETUP
+#line 133 "../fitsy/nrrdlex.L"
+{return SAMPLE_;}
+ YY_BREAK
+case 78:
+YY_RULE_SETUP
+#line 134 "../fitsy/nrrdlex.L"
+{return SAMPLEUNITS_;}
+ YY_BREAK
+case 79:
+YY_RULE_SETUP
+#line 136 "../fitsy/nrrdlex.L"
+{return SIZES_;}
+ YY_BREAK
+case 80:
+YY_RULE_SETUP
+#line 137 "../fitsy/nrrdlex.L"
+{return SPACINGS_;}
+ YY_BREAK
+case 81:
+YY_RULE_SETUP
+#line 138 "../fitsy/nrrdlex.L"
+{return THICKNESSES_;}
+ YY_BREAK
+case 82:
+YY_RULE_SETUP
+#line 139 "../fitsy/nrrdlex.L"
+{return AXIS_;}
+ YY_BREAK
+case 83:
+YY_RULE_SETUP
+#line 140 "../fitsy/nrrdlex.L"
+{return MINS_;}
+ YY_BREAK
+case 84:
+YY_RULE_SETUP
+#line 141 "../fitsy/nrrdlex.L"
+{return AXISMINS_;}
+ YY_BREAK
+case 85:
+YY_RULE_SETUP
+#line 142 "../fitsy/nrrdlex.L"
+{return MAXS_;}
+ YY_BREAK
+case 86:
+YY_RULE_SETUP
+#line 143 "../fitsy/nrrdlex.L"
+{return AXISMAXS_;}
+ YY_BREAK
+case 87:
+YY_RULE_SETUP
+#line 144 "../fitsy/nrrdlex.L"
+{return CENTERS_;}
+ YY_BREAK
+case 88:
+YY_RULE_SETUP
+#line 145 "../fitsy/nrrdlex.L"
+{return CENTERINGS_;}
+ YY_BREAK
+case 89:
+YY_RULE_SETUP
+#line 146 "../fitsy/nrrdlex.L"
+{return CELL_;}
+ YY_BREAK
+case 90:
+YY_RULE_SETUP
+#line 147 "../fitsy/nrrdlex.L"
+{return NODE_;}
+ YY_BREAK
+case 91:
+YY_RULE_SETUP
+#line 148 "../fitsy/nrrdlex.L"
+{return NONE_;}
+ YY_BREAK
+case 92:
+YY_RULE_SETUP
+#line 149 "../fitsy/nrrdlex.L"
+{return LABELS_;}
+ YY_BREAK
+case 93:
+YY_RULE_SETUP
+#line 150 "../fitsy/nrrdlex.L"
+{return KINDS_;}
+ YY_BREAK
+case 94:
+YY_RULE_SETUP
+#line 151 "../fitsy/nrrdlex.L"
+{return DOMAINS_;}
+ YY_BREAK
+case 95:
+YY_RULE_SETUP
+#line 153 "../fitsy/nrrdlex.L"
+{ // Integer
+ nrrdlval->integer = atoi(yytext);
+ return INT;
+ }
+ YY_BREAK
+case 96:
+#line 159 "../fitsy/nrrdlex.L"
+case 97:
+YY_RULE_SETUP
+#line 159 "../fitsy/nrrdlex.L"
+{ // Real Number
+ nrrdlval->real = atof(yytext);
+ return REAL;
+ }
+ YY_BREAK
+case 98:
+YY_RULE_SETUP
+#line 165 "../fitsy/nrrdlex.L"
+{ // Quoted String
+ int ll = (yyleng-2)<(NRRDPARSERSIZE-1) ? (yyleng-2):(NRRDPARSERSIZE-1);
+ strncpy(nrrdlval->str,yytext+1,ll); // skip the '{'
+ nrrdlval->str[ll] = '\0'; // Remove the '}'
+ return STRING;
+ }
+ YY_BREAK
+case 99:
+YY_RULE_SETUP
+#line 172 "../fitsy/nrrdlex.L"
+{ // General String
+ int ll = yyleng <(NRRDPARSERSIZE-1) ? yyleng:(NRRDPARSERSIZE-1);
+ strncpy(nrrdlval->str,yytext,ll);
+ nrrdlval->str[ll] = '\0';
+ return STRING;
+ }
+ YY_BREAK
+case 100:
+YY_RULE_SETUP
+#line 179 "../fitsy/nrrdlex.L"
+{ // White Spaces
+ }
+ YY_BREAK
+case 101:
+/* rule 101 can match eol */
+YY_RULE_SETUP
+#line 182 "../fitsy/nrrdlex.L"
+{ // windows line feed
+ return '\n';
+ }
+ YY_BREAK
+case 102:
+YY_RULE_SETUP
+#line 186 "../fitsy/nrrdlex.L"
+{ // fake line feed
+ return '\n';
+ }
+ YY_BREAK
+case 103:
+/* rule 103 can match eol */
+YY_RULE_SETUP
+#line 190 "../fitsy/nrrdlex.L"
+{ // linefeed
+ return '\n';
+ }
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(DISCARD):
+#line 194 "../fitsy/nrrdlex.L"
+{ // eof
+ return EOF_;
+ }
+ YY_BREAK
+case 104:
+YY_RULE_SETUP
+#line 198 "../fitsy/nrrdlex.L"
+{ // Else, return the char
+ return yytext[0];
+ }
+ YY_BREAK
+case 105:
+YY_RULE_SETUP
+#line 202 "../fitsy/nrrdlex.L"
+ECHO;
+ YY_BREAK
+#line 1550 "../fitsy/nrrdlex.C"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( yywrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
+{
+ yyin = arg_yyin;
+ yyout = arg_yyout;
+ yy_c_buf_p = 0;
+ yy_init = 0;
+ yy_start = 0;
+ yy_flex_debug = 0;
+ yylineno = 1; // this will only get updated if %option yylineno
+
+ yy_did_buffer_switch_on_eof = 0;
+
+ yy_looking_for_trail_begin = 0;
+ yy_more_flag = 0;
+ yy_more_len = 0;
+ yy_more_offset = yy_prev_more_offset = 0;
+
+ yy_start_stack_ptr = yy_start_stack_depth = 0;
+ yy_start_stack = NULL;
+
+ yy_buffer_stack = 0;
+ yy_buffer_stack_top = 0;
+ yy_buffer_stack_max = 0;
+
+ yy_state_buf = 0;
+
+}
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+yyFlexLexer::~yyFlexLexer()
+{
+ delete [] yy_state_buf;
+ nrrdfree(yy_start_stack );
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ nrrdfree(yy_buffer_stack );
+}
+
+/* The contents of this function are C++ specific, so the () macro is not used.
+ */
+void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out )
+{
+ if ( new_in )
+ {
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) );
+ }
+
+ if ( new_out )
+ yyout = new_out;
+}
+
+#ifdef YY_INTERACTIVE
+size_t yyFlexLexer::LexerInput( char* buf, size_t /* max_size */ )
+#else
+size_t yyFlexLexer::LexerInput( char* buf, size_t max_size )
+#endif
+{
+ if ( yyin->eof() || yyin->fail() )
+ return 0;
+
+#ifdef YY_INTERACTIVE
+ yyin->get( buf[0] );
+
+ if ( yyin->eof() )
+ return 0;
+
+ if ( yyin->bad() )
+ return -1;
+
+ return 1;
+
+#else
+ (void) yyin->read( buf, max_size );
+
+ if ( yyin->bad() )
+ return -1;
+ else
+ return yyin->gcount();
+#endif
+}
+
+void yyFlexLexer::LexerOutput( const char* buf, size_t size )
+{
+ (void) yyout->write( buf, size );
+}
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+int yyFlexLexer::yy_get_next_buffer()
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ nrrdrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) nrrdrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ yy_state_type yyFlexLexer::yy_get_previous_state()
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 359 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state )
+{
+ register int yy_is_jam;
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 359 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 358);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+ void yyFlexLexer::yyunput( int c, register char* yy_bp)
+{
+ register char *yy_cp;
+
+ yy_cp = (yy_c_buf_p);
+
+ /* undo effects of setting up yytext */
+ *yy_cp = (yy_hold_char);
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register yy_size_t number_to_move = (yy_n_chars) + 2;
+ register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ register char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+ (yytext_ptr) = yy_bp;
+ (yy_hold_char) = *yy_cp;
+ (yy_c_buf_p) = yy_cp;
+}
+
+ int yyFlexLexer::yyinput()
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap( ) )
+ return 0;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve yytext */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ return c;
+}
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void yyFlexLexer::yyrestart( std::istream* input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file );
+ yy_load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
+ */
+ yyensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ yy_load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+ void yyFlexLexer::yy_load_buffer_state()
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) nrrdalloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) nrrdalloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ *
+ */
+ void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ nrrdfree((void *) b->yy_ch_buf );
+
+ nrrdfree((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+ void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file )
+
+{
+ int oerrno = errno;
+
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = 0;
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ yy_load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer)
+{
+ if (new_buffer == NULL)
+ return;
+
+ yyensure_buffer_stack();
+
+ /* This block is copied from yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void yyFlexLexer::yypop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+void yyFlexLexer::yyensure_buffer_stack(void)
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)nrrdalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)nrrdrealloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+ void yyFlexLexer::yy_push_state( int new_state )
+{
+ if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) )
+ {
+ yy_size_t new_size;
+
+ (yy_start_stack_depth) += YY_START_STACK_INCR;
+ new_size = (yy_start_stack_depth) * sizeof( int );
+
+ if ( ! (yy_start_stack) )
+ (yy_start_stack) = (int *) nrrdalloc(new_size );
+
+ else
+ (yy_start_stack) = (int *) nrrdrealloc((void *) (yy_start_stack),new_size );
+
+ if ( ! (yy_start_stack) )
+ YY_FATAL_ERROR( "out of memory expanding start-condition stack" );
+ }
+
+ (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START;
+
+ BEGIN(new_state);
+}
+
+ void yyFlexLexer::yy_pop_state()
+{
+ if ( --(yy_start_stack_ptr) < 0 )
+ YY_FATAL_ERROR( "start-condition stack underflow" );
+
+ BEGIN((yy_start_stack)[(yy_start_stack_ptr)]);
+}
+
+ int yyFlexLexer::yy_top_state()
+{
+ return (yy_start_stack)[(yy_start_stack_ptr) - 1];
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+void yyFlexLexer::LexerError( yyconst char msg[] )
+{
+ std::cerr << msg << std::endl;
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = (yy_hold_char); \
+ (yy_c_buf_p) = yytext + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *nrrdalloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *nrrdrealloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void nrrdfree (void * ptr )
+{
+ free( (char *) ptr ); /* see nrrdrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 202 "../fitsy/nrrdlex.L"
+
+
+
+void nrrdDiscard(int doit)
+{
+ if (nrrdlexx)
+ nrrdlexx->begin(DISCARD, doit);
+}
+
+void nrrdFlexLexer::begin(int which, int doit)
+{
+ BEGIN which;
+ if (doit)
+ yyless(0);
+}
+
diff --git a/fitsy++/nrrdlex.L b/fitsy++/nrrdlex.L
new file mode 100644
index 0000000..65bb664
--- /dev/null
+++ b/fitsy++/nrrdlex.L
@@ -0,0 +1,215 @@
+/* Copyright (C) 1999-2018
+ * Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+ * For conditions of distribution and use, see copyright notice in "copyright"
+ */
+%option noyywrap
+%option caseless
+%option never-interactive
+%option c++
+
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+
+ #include "util.h"
+ #include "nrrdparser.H"
+
+ extern YYSTYPE* nrrdlval;
+ extern nrrdFlexLexer* nrrdlexx;
+%}
+
+%x DISCARD
+
+D [0-9]
+E [Ee][+-]?{D}+
+
+/* rules */
+
+%%
+
+<DISCARD>[\n] { // special case-- #\n
+ BEGIN INITIAL;
+ yyless(0); // put back the terminator
+ strcpy(nrrdlval->str,""); // feed a blank string
+ return STRING;
+ }
+
+<DISCARD>[^\n]* { // Discard reset of line
+ BEGIN INITIAL;
+ int ll = yyleng <(NRRDPARSERSIZE-1) ? yyleng:(NRRDPARSERSIZE-1);
+ strncpy(nrrdlval->str,yytext,ll);
+ nrrdlval->str[ll] = '\0';
+ return STRING;
+ }
+
+debug {return DEBUG_;}
+on {return ON_;}
+off {return OFF_;}
+
+NRRD0001 {return NRRD0001_;}
+NRRD0002 {return NRRD0002_;}
+NRRD0003 {return NRRD0003_;}
+NRRD0004 {return NRRD0004_;}
+NRRD0005 {return NRRD0005_;}
+
+data {return DATA_;}
+file {return FILE_;}
+
+space {return SPACE_;}
+units {return UNITS_;}
+dimentions {return DIMENSIONS_;}
+origin {return ORIGIN_;}
+directions {return DIRECTIONS_;}
+
+dimension {return DIMENSION_;}
+
+type {return TYPE_;}
+signed {return SIGNED_;}
+unsigned {return UNSIGNED_;}
+char {return CHAR_;}
+int8 {return INT8_;}
+int8_t {return INT8_T_;}
+uchar {return UCHAR_;}
+uint8 {return UINT8_;}
+uint8_t {return UINT8_T_;}
+short {return SHORT_;}
+int {return INT_;}
+int16 {return INT16_;}
+int16_t {return INT16_T_;}
+ushort {return USHORT_;}
+unint16 {return UINT16_;}
+unint16_t {return UINT16_T_;}
+int32 {return INT32_;}
+int32_t {return INT32_T_;}
+uint {return UINT_;}
+uint32 {return UINT32_;}
+uint32_t {return UINT32_T_;}
+long {return LONG_;}
+longlong {return LONGLONG_;}
+int64 {return INT64_;}
+int64_t {return INT64_T_;}
+unlonglong {return ULONGLONG_;}
+unint64 {return UINT64_;}
+unint64_t {return UINT64_T_;}
+float {return FLOAT_;}
+double {return DOUBLE_;}
+
+block {return BLOCK_;}
+size {return SIZE_;}
+blocksize {return BLOCKSIZE_;}
+
+encoding {return ENCODING_;}
+raw {return RAW_;}
+txt {return TXT_;}
+text {return TEXT_;}
+ascii {return ASCII_;}
+hex {return HEX_;}
+gz {return GZ_;}
+gzip {return GZIP_;}
+bz2 {return BZ2_;}
+bzip2 {return BZIP2_;}
+
+endian {return ENDIAN_;}
+big {return BIG_;}
+little {return LITTLE_;}
+
+content {return CONTENT_;}
+
+old {return OLD_;}
+min {return MIN_;}
+oldmin {return OLDMIN_;}
+max {return MAX_;}
+oldmax {return OLDMAX_;}
+
+skip {return SKIP_;}
+line {return LINE_;}
+lineskip {return LINESKIP_;}
+byte {return BYTE_;}
+byteskip {return BYTESKIP_;}
+
+number {return NUMBER_;}
+
+sample {return SAMPLE_;}
+sampleunits {return SAMPLEUNITS_;}
+
+sizes {return SIZES_;}
+spacings {return SPACINGS_;}
+thickness {return THICKNESSES_;}
+axis {return AXIS_;}
+mins {return MINS_;}
+axismins {return AXISMINS_;}
+maxs {return MAXS_;}
+axismaxs {return AXISMAXS_;}
+centers {return CENTERS_;}
+centerings {return CENTERINGS_;}
+cell {return CELL_;}
+node {return NODE_;}
+none {return NONE_;}
+labels {return LABELS_;}
+kinds {return KINDS_;}
+domains {return DOMAINS_;}
+
+[+-]?{D}+ { // Integer
+ nrrdlval->integer = atoi(yytext);
+ return INT;
+ }
+
+[+-]?{D}+"."?({E})? |
+[+-]?{D}*"."{D}+({E})? { // Real Number
+ nrrdlval->real = atof(yytext);
+ return REAL;
+ }
+
+
+\{[^\}\n]*\} { // Quoted String
+ int ll = (yyleng-2)<(NRRDPARSERSIZE-1) ? (yyleng-2):(NRRDPARSERSIZE-1);
+ strncpy(nrrdlval->str,yytext+1,ll); // skip the '{'
+ nrrdlval->str[ll] = '\0'; // Remove the '}'
+ return STRING;
+ }
+
+[0-9A-Za-z]+ { // General String
+ int ll = yyleng <(NRRDPARSERSIZE-1) ? yyleng:(NRRDPARSERSIZE-1);
+ strncpy(nrrdlval->str,yytext,ll);
+ nrrdlval->str[ll] = '\0';
+ return STRING;
+ }
+
+[ \t]+ { // White Spaces
+ }
+
+\r\n { // windows line feed
+ return '\n';
+ }
+
+\\n { // fake line feed
+ return '\n';
+ }
+
+\n { // linefeed
+ return '\n';
+ }
+
+<<EOF>> { // eof
+ return EOF_;
+ }
+
+. { // Else, return the char
+ return yytext[0];
+ }
+
+%%
+
+void nrrdDiscard(int doit)
+{
+ if (nrrdlexx)
+ nrrdlexx->begin(DISCARD, doit);
+}
+
+void nrrdFlexLexer::begin(int which, int doit)
+{
+ BEGIN which;
+ if (doit)
+ yyless(0);
+}
diff --git a/fitsy++/nrrdparser.C b/fitsy++/nrrdparser.C
new file mode 100644
index 0000000..e84807d
--- /dev/null
+++ b/fitsy++/nrrdparser.C
@@ -0,0 +1,2196 @@
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "2.3"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* Substitute the variable and function names. */
+#define yyparse nrrdparse
+#define yylex nrrdlex
+#define yyerror nrrderror
+#define yylval nrrdlval
+#define yychar nrrdchar
+#define yydebug nrrddebug
+#define yynerrs nrrdnerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ EOF_ = 258,
+ INT = 259,
+ REAL = 260,
+ STRING = 261,
+ DEBUG_ = 262,
+ ON_ = 263,
+ OFF_ = 264,
+ NRRD0001_ = 265,
+ NRRD0002_ = 266,
+ NRRD0003_ = 267,
+ NRRD0004_ = 268,
+ NRRD0005_ = 269,
+ DATA_ = 270,
+ FILE_ = 271,
+ SPACE_ = 272,
+ UNITS_ = 273,
+ DIMENSIONS_ = 274,
+ ORIGIN_ = 275,
+ DIRECTIONS_ = 276,
+ DIMENSION_ = 277,
+ TYPE_ = 278,
+ SIGNED_ = 279,
+ UNSIGNED_ = 280,
+ CHAR_ = 281,
+ INT8_ = 282,
+ INT8_T_ = 283,
+ UCHAR_ = 284,
+ UINT8_ = 285,
+ UINT8_T_ = 286,
+ SHORT_ = 287,
+ INT_ = 288,
+ INT16_ = 289,
+ INT16_T_ = 290,
+ USHORT_ = 291,
+ UINT16_ = 292,
+ UINT16_T_ = 293,
+ INT32_ = 294,
+ INT32_T_ = 295,
+ UINT_ = 296,
+ UINT32_ = 297,
+ UINT32_T_ = 298,
+ LONG_ = 299,
+ LONGLONG_ = 300,
+ INT64_ = 301,
+ INT64_T_ = 302,
+ ULONGLONG_ = 303,
+ UINT64_ = 304,
+ UINT64_T_ = 305,
+ FLOAT_ = 306,
+ DOUBLE_ = 307,
+ BLOCK_ = 308,
+ SIZE_ = 309,
+ BLOCKSIZE_ = 310,
+ ENCODING_ = 311,
+ RAW_ = 312,
+ TXT_ = 313,
+ TEXT_ = 314,
+ ASCII_ = 315,
+ HEX_ = 316,
+ GZ_ = 317,
+ GZIP_ = 318,
+ BZ2_ = 319,
+ BZIP2_ = 320,
+ ENDIAN_ = 321,
+ BIG_ = 322,
+ LITTLE_ = 323,
+ CONTENT_ = 324,
+ OLD_ = 325,
+ MIN_ = 326,
+ OLDMIN_ = 327,
+ MAX_ = 328,
+ OLDMAX_ = 329,
+ SKIP_ = 330,
+ LINE_ = 331,
+ LINESKIP_ = 332,
+ BYTE_ = 333,
+ BYTESKIP_ = 334,
+ NUMBER_ = 335,
+ SAMPLE_ = 336,
+ SAMPLEUNITS_ = 337,
+ SIZES_ = 338,
+ SPACINGS_ = 339,
+ THICKNESSES_ = 340,
+ AXIS_ = 341,
+ MINS_ = 342,
+ AXISMINS_ = 343,
+ MAXS_ = 344,
+ AXISMAXS_ = 345,
+ CENTERS_ = 346,
+ CENTERINGS_ = 347,
+ CELL_ = 348,
+ NODE_ = 349,
+ NONE_ = 350,
+ LABELS_ = 351,
+ KINDS_ = 352,
+ DOMAINS_ = 353
+ };
+#endif
+/* Tokens. */
+#define EOF_ 258
+#define INT 259
+#define REAL 260
+#define STRING 261
+#define DEBUG_ 262
+#define ON_ 263
+#define OFF_ 264
+#define NRRD0001_ 265
+#define NRRD0002_ 266
+#define NRRD0003_ 267
+#define NRRD0004_ 268
+#define NRRD0005_ 269
+#define DATA_ 270
+#define FILE_ 271
+#define SPACE_ 272
+#define UNITS_ 273
+#define DIMENSIONS_ 274
+#define ORIGIN_ 275
+#define DIRECTIONS_ 276
+#define DIMENSION_ 277
+#define TYPE_ 278
+#define SIGNED_ 279
+#define UNSIGNED_ 280
+#define CHAR_ 281
+#define INT8_ 282
+#define INT8_T_ 283
+#define UCHAR_ 284
+#define UINT8_ 285
+#define UINT8_T_ 286
+#define SHORT_ 287
+#define INT_ 288
+#define INT16_ 289
+#define INT16_T_ 290
+#define USHORT_ 291
+#define UINT16_ 292
+#define UINT16_T_ 293
+#define INT32_ 294
+#define INT32_T_ 295
+#define UINT_ 296
+#define UINT32_ 297
+#define UINT32_T_ 298
+#define LONG_ 299
+#define LONGLONG_ 300
+#define INT64_ 301
+#define INT64_T_ 302
+#define ULONGLONG_ 303
+#define UINT64_ 304
+#define UINT64_T_ 305
+#define FLOAT_ 306
+#define DOUBLE_ 307
+#define BLOCK_ 308
+#define SIZE_ 309
+#define BLOCKSIZE_ 310
+#define ENCODING_ 311
+#define RAW_ 312
+#define TXT_ 313
+#define TEXT_ 314
+#define ASCII_ 315
+#define HEX_ 316
+#define GZ_ 317
+#define GZIP_ 318
+#define BZ2_ 319
+#define BZIP2_ 320
+#define ENDIAN_ 321
+#define BIG_ 322
+#define LITTLE_ 323
+#define CONTENT_ 324
+#define OLD_ 325
+#define MIN_ 326
+#define OLDMIN_ 327
+#define MAX_ 328
+#define OLDMAX_ 329
+#define SKIP_ 330
+#define LINE_ 331
+#define LINESKIP_ 332
+#define BYTE_ 333
+#define BYTESKIP_ 334
+#define NUMBER_ 335
+#define SAMPLE_ 336
+#define SAMPLEUNITS_ 337
+#define SIZES_ 338
+#define SPACINGS_ 339
+#define THICKNESSES_ 340
+#define AXIS_ 341
+#define MINS_ 342
+#define AXISMINS_ 343
+#define MAXS_ 344
+#define AXISMAXS_ 345
+#define CENTERS_ 346
+#define CENTERINGS_ 347
+#define CELL_ 348
+#define NODE_ 349
+#define NONE_ 350
+#define LABELS_ 351
+#define KINDS_ 352
+#define DOMAINS_ 353
+
+
+
+
+/* Copy the first part of user declarations. */
+#line 10 "../fitsy/nrrdparser.Y"
+
+#define YYDEBUG 1
+
+#define DISCARD_(x) {yyclearin; nrrdDiscard(x);}
+
+#include "file.h"
+
+#undef yyFlexLexer
+#define yyFlexLexer nrrdFlexLexer
+#include <FlexLexer.h>
+
+extern int nrrdlex(void*, nrrdFlexLexer*);
+extern void nrrderror(FitsFile*, nrrdFlexLexer*, const char*);
+extern void nrrdDiscard(int);
+
+int dim;
+
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+#line 29 "../fitsy/nrrdparser.Y"
+{
+#define NRRDPARSERSIZE 256
+ float real;
+ int integer;
+ char str[NRRDPARSERSIZE];
+}
+/* Line 193 of yacc.c. */
+#line 326 "../fitsy/nrrdparser.C"
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 216 of yacc.c. */
+#line 339 "../fitsy/nrrdparser.C"
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions. */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int i)
+#else
+static int
+YYID (i)
+ int i;
+#endif
+{
+ return i;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined _STDLIB_H \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (YYID (0))
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (YYID (0))
+
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 3
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 245
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 102
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 44
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 152
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 240
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 353
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 101, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 100, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 99, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
+ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
+ 95, 96, 97, 98
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const yytype_uint16 yyprhs[] =
+{
+ 0, 0, 3, 4, 7, 11, 14, 15, 18, 20,
+ 22, 27, 30, 34, 38, 40, 44, 48, 49, 54,
+ 58, 62, 64, 66, 68, 70, 74, 78, 82, 86,
+ 91, 95, 100, 104, 108, 112, 116, 120, 124, 126,
+ 128, 130, 132, 134, 135, 139, 141, 143, 145, 147,
+ 149, 151, 152, 156, 160, 161, 166, 167, 172, 173,
+ 178, 180, 182, 184, 186, 188, 190, 192, 194, 196,
+ 198, 200, 202, 205, 207, 209, 211, 214, 216, 218,
+ 220, 223, 226, 230, 232, 234, 236, 239, 243, 245,
+ 247, 249, 252, 254, 256, 258, 261, 263, 265, 267,
+ 270, 274, 278, 283, 285, 287, 289, 293, 298, 300,
+ 302, 307, 311, 313, 315, 317, 319, 321, 323, 325,
+ 327, 329, 331, 333, 338, 342, 347, 351, 356, 360,
+ 365, 369, 372, 374, 376, 379, 381, 384, 386, 389,
+ 391, 394, 396, 399, 401, 403, 405, 407, 410, 412,
+ 415, 417, 420
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yytype_int16 yyrhs[] =
+{
+ 103, 0, -1, -1, 104, 105, -1, 105, 106, 111,
+ -1, 106, 111, -1, -1, 7, 113, -1, 108, -1,
+ 109, -1, 15, 16, 99, 6, -1, 17, 114, -1,
+ 22, 99, 4, -1, 23, 99, 119, -1, 128, -1,
+ 56, 99, 129, -1, 66, 99, 130, -1, -1, 69,
+ 99, 107, 6, -1, 71, 99, 112, -1, 73, 99,
+ 112, -1, 131, -1, 132, -1, 133, -1, 134, -1,
+ 80, 99, 6, -1, 83, 99, 135, -1, 84, 99,
+ 137, -1, 85, 99, 138, -1, 86, 87, 99, 139,
+ -1, 88, 99, 139, -1, 86, 89, 99, 140, -1,
+ 90, 99, 140, -1, 91, 99, 141, -1, 92, 99,
+ 141, -1, 96, 99, 143, -1, 18, 99, 144, -1,
+ 97, 99, 145, -1, 10, -1, 11, -1, 12, -1,
+ 13, -1, 14, -1, -1, 100, 110, 6, -1, 101,
+ -1, 3, -1, 5, -1, 4, -1, 8, -1, 9,
+ -1, -1, 99, 115, 6, -1, 22, 99, 4, -1,
+ -1, 18, 99, 116, 6, -1, -1, 20, 99, 117,
+ 6, -1, -1, 21, 99, 118, 6, -1, 120, -1,
+ 121, -1, 122, -1, 123, -1, 124, -1, 125, -1,
+ 126, -1, 127, -1, 51, -1, 52, -1, 53, -1,
+ 26, -1, 24, 26, -1, 27, -1, 28, -1, 29,
+ -1, 25, 26, -1, 30, -1, 31, -1, 32, -1,
+ 32, 33, -1, 24, 32, -1, 24, 32, 33, -1,
+ 34, -1, 35, -1, 36, -1, 25, 32, -1, 25,
+ 32, 33, -1, 37, -1, 38, -1, 33, -1, 24,
+ 33, -1, 39, -1, 40, -1, 41, -1, 25, 33,
+ -1, 42, -1, 43, -1, 45, -1, 44, 44, -1,
+ 44, 44, 33, -1, 24, 44, 44, -1, 24, 44,
+ 44, 33, -1, 46, -1, 47, -1, 48, -1, 25,
+ 44, 44, -1, 25, 44, 44, 33, -1, 49, -1,
+ 50, -1, 53, 54, 99, 4, -1, 55, 99, 4,
+ -1, 57, -1, 58, -1, 59, -1, 60, -1, 61,
+ -1, 62, -1, 63, -1, 64, -1, 65, -1, 67,
+ -1, 68, -1, 70, 71, 99, 112, -1, 72, 99,
+ 112, -1, 70, 73, 99, 112, -1, 74, 99, 112,
+ -1, 76, 75, 99, 4, -1, 77, 99, 4, -1,
+ 78, 75, 99, 4, -1, 79, 99, 4, -1, 135,
+ 136, -1, 136, -1, 4, -1, 137, 112, -1, 112,
+ -1, 138, 112, -1, 112, -1, 139, 112, -1, 112,
+ -1, 140, 112, -1, 112, -1, 141, 142, -1, 142,
+ -1, 93, -1, 94, -1, 95, -1, 143, 6, -1,
+ 6, -1, 144, 6, -1, 6, -1, 145, 6, -1,
+ 6, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const yytype_uint16 yyrline[] =
+{
+ 0, 168, 168, 168, 171, 172, 175, 176, 177, 178,
+ 179, 180, 181, 182, 183, 184, 185, 186, 186, 187,
+ 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
+ 198, 199, 200, 201, 202, 203, 204, 205, 208, 209,
+ 210, 211, 212, 215, 215, 218, 219, 222, 223, 226,
+ 227, 230, 230, 231, 232, 232, 233, 233, 234, 234,
+ 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
+ 247, 250, 251, 252, 253, 256, 257, 258, 259, 262,
+ 263, 264, 265, 266, 267, 270, 271, 272, 273, 274,
+ 277, 278, 279, 280, 283, 284, 285, 286, 289, 290,
+ 291, 292, 293, 294, 295, 298, 299, 300, 301, 302,
+ 305, 306, 309, 310, 311, 312, 313, 314, 315, 316,
+ 317, 320, 321, 324, 325, 328, 329, 332, 333, 336,
+ 337, 340, 341, 344, 361, 362, 365, 366, 369, 370,
+ 373, 374, 377, 378, 381, 382, 383, 386, 387, 390,
+ 391, 394, 395
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "EOF_", "INT", "REAL", "STRING",
+ "DEBUG_", "ON_", "OFF_", "NRRD0001_", "NRRD0002_", "NRRD0003_",
+ "NRRD0004_", "NRRD0005_", "DATA_", "FILE_", "SPACE_", "UNITS_",
+ "DIMENSIONS_", "ORIGIN_", "DIRECTIONS_", "DIMENSION_", "TYPE_",
+ "SIGNED_", "UNSIGNED_", "CHAR_", "INT8_", "INT8_T_", "UCHAR_", "UINT8_",
+ "UINT8_T_", "SHORT_", "INT_", "INT16_", "INT16_T_", "USHORT_", "UINT16_",
+ "UINT16_T_", "INT32_", "INT32_T_", "UINT_", "UINT32_", "UINT32_T_",
+ "LONG_", "LONGLONG_", "INT64_", "INT64_T_", "ULONGLONG_", "UINT64_",
+ "UINT64_T_", "FLOAT_", "DOUBLE_", "BLOCK_", "SIZE_", "BLOCKSIZE_",
+ "ENCODING_", "RAW_", "TXT_", "TEXT_", "ASCII_", "HEX_", "GZ_", "GZIP_",
+ "BZ2_", "BZIP2_", "ENDIAN_", "BIG_", "LITTLE_", "CONTENT_", "OLD_",
+ "MIN_", "OLDMIN_", "MAX_", "OLDMAX_", "SKIP_", "LINE_", "LINESKIP_",
+ "BYTE_", "BYTESKIP_", "NUMBER_", "SAMPLE_", "SAMPLEUNITS_", "SIZES_",
+ "SPACINGS_", "THICKNESSES_", "AXIS_", "MINS_", "AXISMINS_", "MAXS_",
+ "AXISMAXS_", "CENTERS_", "CENTERINGS_", "CELL_", "NODE_", "NONE_",
+ "LABELS_", "KINDS_", "DOMAINS_", "':'", "'#'", "'\\n'", "$accept",
+ "start", "@1", "commands", "command", "@2", "magic", "comment", "@3",
+ "terminator", "numeric", "debug", "space", "@4", "@5", "@6", "@7",
+ "type", "char", "uchar", "short", "ushort", "int", "uint", "long",
+ "ulong", "block", "encoding", "endian", "oldmin", "oldmax", "lineskip",
+ "byteskip", "sizes", "size", "spacings", "thicknesses", "axismins",
+ "axismaxs", "centers", "center", "labels", "units", "kinds", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const yytype_uint16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
+ 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
+ 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
+ 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
+ 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
+ 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
+ 345, 346, 347, 348, 349, 350, 351, 352, 353, 58,
+ 35, 10
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 102, 104, 103, 105, 105, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 107, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 108, 108,
+ 108, 108, 108, 110, 109, 111, 111, 112, 112, 113,
+ 113, 115, 114, 114, 116, 114, 117, 114, 118, 114,
+ 119, 119, 119, 119, 119, 119, 119, 119, 119, 119,
+ 119, 120, 120, 120, 120, 121, 121, 121, 121, 122,
+ 122, 122, 122, 122, 122, 123, 123, 123, 123, 123,
+ 124, 124, 124, 124, 125, 125, 125, 125, 126, 126,
+ 126, 126, 126, 126, 126, 127, 127, 127, 127, 127,
+ 128, 128, 129, 129, 129, 129, 129, 129, 129, 129,
+ 129, 130, 130, 131, 131, 132, 132, 133, 133, 134,
+ 134, 135, 135, 136, 137, 137, 138, 138, 139, 139,
+ 140, 140, 141, 141, 142, 142, 142, 143, 143, 144,
+ 144, 145, 145
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 0, 2, 3, 2, 0, 2, 1, 1,
+ 4, 2, 3, 3, 1, 3, 3, 0, 4, 3,
+ 3, 1, 1, 1, 1, 3, 3, 3, 3, 4,
+ 3, 4, 3, 3, 3, 3, 3, 3, 1, 1,
+ 1, 1, 1, 0, 3, 1, 1, 1, 1, 1,
+ 1, 0, 3, 3, 0, 4, 0, 4, 0, 4,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 2, 1, 1, 1, 2, 1, 1, 1,
+ 2, 2, 3, 1, 1, 1, 2, 3, 1, 1,
+ 1, 2, 1, 1, 1, 2, 1, 1, 1, 2,
+ 3, 3, 4, 1, 1, 1, 3, 4, 1, 1,
+ 4, 3, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 4, 3, 4, 3, 4, 3, 4,
+ 3, 2, 1, 1, 2, 1, 2, 1, 2, 1,
+ 2, 1, 2, 1, 1, 1, 1, 2, 1, 2,
+ 1, 2, 1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const yytype_uint8 yydefact[] =
+{
+ 2, 0, 6, 1, 0, 38, 39, 40, 41, 42,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 43, 6, 0, 8, 9, 14, 21, 22, 23, 24,
+ 49, 50, 7, 0, 0, 0, 0, 0, 51, 11,
+ 0, 0, 0, 0, 0, 0, 0, 17, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 46, 45, 5, 0, 54, 56, 58, 0,
+ 0, 150, 36, 12, 0, 0, 71, 73, 74, 75,
+ 77, 78, 79, 90, 83, 84, 85, 88, 89, 92,
+ 93, 94, 96, 97, 0, 98, 103, 104, 105, 108,
+ 109, 68, 69, 70, 13, 60, 61, 62, 63, 64,
+ 65, 66, 67, 0, 111, 112, 113, 114, 115, 116,
+ 117, 118, 119, 120, 15, 121, 122, 16, 0, 0,
+ 0, 48, 47, 19, 124, 20, 126, 0, 128, 0,
+ 130, 25, 133, 26, 132, 135, 27, 137, 28, 0,
+ 0, 139, 30, 141, 32, 144, 145, 146, 33, 143,
+ 34, 148, 35, 152, 37, 44, 4, 10, 0, 0,
+ 0, 53, 52, 149, 72, 81, 91, 0, 76, 86,
+ 95, 0, 80, 99, 110, 18, 123, 125, 127, 129,
+ 131, 134, 136, 29, 31, 138, 140, 142, 147, 151,
+ 55, 57, 59, 82, 101, 87, 106, 100, 102, 107
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int16 yydefgoto[] =
+{
+ -1, 1, 2, 41, 42, 158, 43, 44, 90, 94,
+ 181, 52, 59, 100, 198, 199, 200, 134, 135, 136,
+ 137, 138, 139, 140, 141, 142, 45, 154, 157, 46,
+ 47, 48, 49, 173, 174, 176, 178, 182, 184, 188,
+ 189, 192, 102, 194
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -138
+static const yytype_int16 yypact[] =
+{
+ -138, 4, 145, -138, 79, -138, -138, -138, -138, -138,
+ 52, -13, -36, -28, -16, 31, -4, -3, -2, -1,
+ -25, 0, 2, 6, 8, 34, 12, 53, 16, 30,
+ 35, 37, 41, -37, 42, 43, 46, 49, 50, 51,
+ -138, 47, 3, -138, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, 62, 65, 66, 67, 70, -138, -138,
+ 116, 142, -8, 71, 147, 17, 24, -138, 72, 73,
+ 89, 89, 89, 89, 74, 170, 76, 172, 171, 174,
+ 89, 89, 80, 81, 89, 89, -81, -81, 175, 176,
+ 177, 3, -138, -138, -138, 178, -138, -138, -138, 181,
+ 180, -138, 182, -138, 23, 40, -138, -138, -138, -138,
+ -138, -138, 154, -138, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, -138, 146, -138, -138, -138, -138, -138,
+ -138, -138, -138, -138, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, 185, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, -138, -138, -138, -138, -138, 186, 89,
+ 89, -138, -138, -138, -138, -138, -138, 187, -138, 189,
+ -138, -138, -138, 174, -138, -138, 89, -138, 89, 89,
+ 89, -138, 89, -138, 89, -138, -138, -138, -81, -138,
+ -81, -138, 188, -138, 190, -138, -138, -138, 191, 193,
+ 196, -138, -138, -138, -138, 162, -138, 159, -138, 173,
+ -138, 160, -138, 179, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, 89, 89, -138, -138, -138, -138, -138,
+ -138, -138, -138, -138, 194, -138, 199, -138, -138, -138
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int16 yypgoto[] =
+{
+ -138, -138, -138, -138, 164, -138, -138, -138, -138, 117,
+ -70, -138, -138, -138, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, -138, -138, -138, -138, -138, -138, -138,
+ -138, -138, -138, -138, 36, -138, -138, 28, 33, 123,
+ -137, -138, -138, -138
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -4
+static const yytype_int16 yytable[] =
+{
+ 163, 164, 165, 166, 3, 54, 92, 55, 56, 57,
+ 175, 177, 185, 186, 187, 183, 104, 105, 106, 107,
+ 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
+ 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 68, -3, 69, 204,
+ 82, 227, 83, 227, 4, 205, 206, 5, 6, 7,
+ 8, 9, 10, 60, 11, 12, 208, 207, 53, 13,
+ 14, 61, 209, 210, 145, 146, 147, 148, 149, 150,
+ 151, 152, 153, 62, 211, 63, 58, 50, 51, 216,
+ 217, 155, 156, 161, 162, 64, 65, 66, 67, 70,
+ 15, 71, 16, 17, 93, 72, 221, 73, 222, 74,
+ 183, 75, 225, 18, 226, 77, 19, 20, 21, 22,
+ 23, 24, 101, 25, 26, 27, 28, 29, 76, 78,
+ 30, 31, 32, 33, 79, 34, 80, 35, 36, 37,
+ 81, 84, 85, 38, 39, 86, 103, 40, 87, 88,
+ 89, 144, 4, 225, 226, 5, 6, 7, 8, 9,
+ 10, 95, 11, 12, 96, 97, 98, 13, 14, 99,
+ 143, 159, 160, 167, 168, 169, 170, 171, 172, 179,
+ 180, 191, 193, 195, 197, 201, 202, 212, 203, 214,
+ 213, 218, 215, 219, 228, 233, 229, 230, 15, 231,
+ 16, 17, 232, 234, 236, 91, 235, 223, 196, 220,
+ 190, 18, 237, 224, 19, 20, 21, 22, 23, 24,
+ 0, 25, 26, 27, 28, 29, 0, 238, 30, 31,
+ 32, 33, 239, 34, 0, 35, 36, 37, 0, 0,
+ 0, 38, 39, 0, 0, 40
+};
+
+static const yytype_int16 yycheck[] =
+{
+ 70, 71, 72, 73, 0, 18, 3, 20, 21, 22,
+ 80, 81, 93, 94, 95, 85, 24, 25, 26, 27,
+ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
+ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 71, 0, 73, 26,
+ 87, 188, 89, 190, 7, 32, 33, 10, 11, 12,
+ 13, 14, 15, 99, 17, 18, 26, 44, 16, 22,
+ 23, 99, 32, 33, 57, 58, 59, 60, 61, 62,
+ 63, 64, 65, 99, 44, 54, 99, 8, 9, 159,
+ 160, 67, 68, 4, 5, 99, 99, 99, 99, 99,
+ 53, 99, 55, 56, 101, 99, 176, 99, 178, 75,
+ 180, 99, 182, 66, 184, 99, 69, 70, 71, 72,
+ 73, 74, 6, 76, 77, 78, 79, 80, 75, 99,
+ 83, 84, 85, 86, 99, 88, 99, 90, 91, 92,
+ 99, 99, 99, 96, 97, 99, 4, 100, 99, 99,
+ 99, 4, 7, 223, 224, 10, 11, 12, 13, 14,
+ 15, 99, 17, 18, 99, 99, 99, 22, 23, 99,
+ 99, 99, 99, 99, 4, 99, 4, 6, 4, 99,
+ 99, 6, 6, 6, 6, 4, 6, 33, 6, 4,
+ 44, 4, 6, 4, 6, 33, 6, 6, 53, 6,
+ 55, 56, 6, 44, 44, 41, 33, 179, 91, 173,
+ 87, 66, 33, 180, 69, 70, 71, 72, 73, 74,
+ -1, 76, 77, 78, 79, 80, -1, 33, 83, 84,
+ 85, 86, 33, 88, -1, 90, 91, 92, -1, -1,
+ -1, 96, 97, -1, -1, 100
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 103, 104, 0, 7, 10, 11, 12, 13, 14,
+ 15, 17, 18, 22, 23, 53, 55, 56, 66, 69,
+ 70, 71, 72, 73, 74, 76, 77, 78, 79, 80,
+ 83, 84, 85, 86, 88, 90, 91, 92, 96, 97,
+ 100, 105, 106, 108, 109, 128, 131, 132, 133, 134,
+ 8, 9, 113, 16, 18, 20, 21, 22, 99, 114,
+ 99, 99, 99, 54, 99, 99, 99, 99, 71, 73,
+ 99, 99, 99, 99, 75, 99, 75, 99, 99, 99,
+ 99, 99, 87, 89, 99, 99, 99, 99, 99, 99,
+ 110, 106, 3, 101, 111, 99, 99, 99, 99, 99,
+ 115, 6, 144, 4, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+ 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
+ 50, 51, 52, 53, 119, 120, 121, 122, 123, 124,
+ 125, 126, 127, 99, 4, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 129, 67, 68, 130, 107, 99,
+ 99, 4, 5, 112, 112, 112, 112, 99, 4, 99,
+ 4, 6, 4, 135, 136, 112, 137, 112, 138, 99,
+ 99, 112, 139, 112, 140, 93, 94, 95, 141, 142,
+ 141, 6, 143, 6, 145, 6, 111, 6, 116, 117,
+ 118, 4, 6, 6, 26, 32, 33, 44, 26, 32,
+ 33, 44, 33, 44, 4, 6, 112, 112, 4, 4,
+ 136, 112, 112, 139, 140, 112, 112, 142, 6, 6,
+ 6, 6, 6, 33, 44, 33, 44, 33, 33, 33
+};
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK (1); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (nrrd, ll, YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (YYID (0))
+
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+# define YY_LOCATION_PRINT(File, Loc) \
+ fprintf (File, "%d.%d-%d.%d", \
+ (Loc).first_line, (Loc).first_column, \
+ (Loc).last_line, (Loc).last_column)
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval, ll)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value, nrrd, ll); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, FitsFile* nrrd, nrrdFlexLexer* ll)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep, nrrd, ll)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+ FitsFile* nrrd;
+ nrrdFlexLexer* ll;
+#endif
+{
+ if (!yyvaluep)
+ return;
+ YYUSE (nrrd);
+ YYUSE (ll);
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, FitsFile* nrrd, nrrdFlexLexer* ll)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep, nrrd, ll)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+ FitsFile* nrrd;
+ nrrdFlexLexer* ll;
+#endif
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep, nrrd, ll);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ yytype_int16 *bottom;
+ yytype_int16 *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule, FitsFile* nrrd, nrrdFlexLexer* ll)
+#else
+static void
+yy_reduce_print (yyvsp, yyrule, nrrd, ll)
+ YYSTYPE *yyvsp;
+ int yyrule;
+ FitsFile* nrrd;
+ nrrdFlexLexer* ll;
+#endif
+{
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ fprintf (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ , nrrd, ll);
+ fprintf (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyvsp, Rule, nrrd, ll); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+ const char *yystr;
+#endif
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+#endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into YYRESULT an error message about the unexpected token
+ YYCHAR while in state YYSTATE. Return the number of bytes copied,
+ including the terminating null byte. If YYRESULT is null, do not
+ copy anything; just return the number of bytes that would be
+ copied. As a special case, return 0 if an ordinary "syntax error"
+ message will do. Return YYSIZE_MAXIMUM if overflow occurs during
+ size calculation. */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+ int yyn = yypact[yystate];
+
+ if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+ return 0;
+ else
+ {
+ int yytype = YYTRANSLATE (yychar);
+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ int yysize_overflow = 0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyx;
+
+# if 0
+ /* This is so xgettext sees the translatable formats that are
+ constructed on the fly. */
+ YY_("syntax error, unexpected %s");
+ YY_("syntax error, unexpected %s, expecting %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+ char *yyfmt;
+ char const *yyf;
+ static char const yyunexpected[] = "syntax error, unexpected %s";
+ static char const yyexpecting[] = ", expecting %s";
+ static char const yyor[] = " or %s";
+ char yyformat[sizeof yyunexpected
+ + sizeof yyexpecting - 1
+ + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+ * (sizeof yyor - 1))];
+ char const *yyprefix = yyexpecting;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 1;
+
+ yyarg[0] = yytname[yytype];
+ yyfmt = yystpcpy (yyformat, yyunexpected);
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ yyformat[sizeof yyunexpected - 1] = '\0';
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+ yyfmt = yystpcpy (yyfmt, yyprefix);
+ yyprefix = yyor;
+ }
+
+ yyf = YY_(yyformat);
+ yysize1 = yysize + yystrlen (yyf);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+
+ if (yysize_overflow)
+ return YYSIZE_MAXIMUM;
+
+ if (yyresult)
+ {
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ char *yyp = yyresult;
+ int yyi = 0;
+ while ((*yyp = *yyf) != '\0')
+ {
+ if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyf += 2;
+ }
+ else
+ {
+ yyp++;
+ yyf++;
+ }
+ }
+ }
+ return yysize;
+ }
+}
+#endif /* YYERROR_VERBOSE */
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, FitsFile* nrrd, nrrdFlexLexer* ll)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep, nrrd, ll)
+ const char *yymsg;
+ int yytype;
+ YYSTYPE *yyvaluep;
+ FitsFile* nrrd;
+ nrrdFlexLexer* ll;
+#endif
+{
+ YYUSE (yyvaluep);
+ YYUSE (nrrd);
+ YYUSE (ll);
+
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (FitsFile* nrrd, nrrdFlexLexer* ll);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (FitsFile* nrrd, nrrdFlexLexer* ll)
+#else
+int
+yyparse (nrrd, ll)
+ FitsFile* nrrd;
+ nrrdFlexLexer* ll;
+#endif
+#endif
+{
+ /* The look-ahead symbol. */
+int yychar;
+
+/* The semantic value of the look-ahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Look-ahead token as an internal (translated) token number. */
+ int yytoken = 0;
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss = yyssa;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ look-ahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to look-ahead token. */
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a look-ahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the look-ahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 2:
+#line 168 "../fitsy/nrrdparser.Y"
+ {dim=0; nrrd->setpArch(FitsFile::BIG);;}
+ break;
+
+ case 17:
+#line 186 "../fitsy/nrrdparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 43:
+#line 215 "../fitsy/nrrdparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 46:
+#line 219 "../fitsy/nrrdparser.Y"
+ {YYACCEPT;;}
+ break;
+
+ case 47:
+#line 222 "../fitsy/nrrdparser.Y"
+ {(yyval.real)=(yyvsp[(1) - (1)].real);;}
+ break;
+
+ case 48:
+#line 223 "../fitsy/nrrdparser.Y"
+ {(yyval.real)=(yyvsp[(1) - (1)].integer);;}
+ break;
+
+ case 49:
+#line 226 "../fitsy/nrrdparser.Y"
+ {yydebug=1;;}
+ break;
+
+ case 50:
+#line 227 "../fitsy/nrrdparser.Y"
+ {yydebug=0;;}
+ break;
+
+ case 51:
+#line 230 "../fitsy/nrrdparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 54:
+#line 232 "../fitsy/nrrdparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 56:
+#line 233 "../fitsy/nrrdparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 58:
+#line 234 "../fitsy/nrrdparser.Y"
+ {DISCARD_(1);}
+ break;
+
+ case 60:
+#line 237 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(8);;}
+ break;
+
+ case 61:
+#line 238 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(8);;}
+ break;
+
+ case 62:
+#line 239 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(16);;}
+ break;
+
+ case 63:
+#line 240 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(16);;}
+ break;
+
+ case 64:
+#line 241 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(32);;}
+ break;
+
+ case 65:
+#line 242 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(32);;}
+ break;
+
+ case 66:
+#line 243 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(64);;}
+ break;
+
+ case 67:
+#line 244 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(64);;}
+ break;
+
+ case 68:
+#line 245 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(-32);;}
+ break;
+
+ case 69:
+#line 246 "../fitsy/nrrdparser.Y"
+ {nrrd->setpBitpix(-64);;}
+ break;
+
+ case 112:
+#line 309 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::RAW);;}
+ break;
+
+ case 113:
+#line 310 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::ASCII);;}
+ break;
+
+ case 114:
+#line 311 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::ASCII);;}
+ break;
+
+ case 115:
+#line 312 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::ASCII);;}
+ break;
+
+ case 116:
+#line 313 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::HEX);;}
+ break;
+
+ case 117:
+#line 314 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::GZIP);;}
+ break;
+
+ case 118:
+#line 315 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::GZIP);;}
+ break;
+
+ case 119:
+#line 316 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::BZ2);;}
+ break;
+
+ case 120:
+#line 317 "../fitsy/nrrdparser.Y"
+ {nrrd->setpEncoding(FitsFile::BZ2);;}
+ break;
+
+ case 121:
+#line 320 "../fitsy/nrrdparser.Y"
+ {nrrd->setpArch(FitsFile::BIG);;}
+ break;
+
+ case 122:
+#line 321 "../fitsy/nrrdparser.Y"
+ {nrrd->setpArch(FitsFile::LITTLE);;}
+ break;
+
+ case 133:
+#line 345 "../fitsy/nrrdparser.Y"
+ {
+ switch (dim) {
+ case 0:
+ nrrd->setpWidth((yyvsp[(1) - (1)].integer));
+ break;
+ case 1:
+ nrrd->setpHeight((yyvsp[(1) - (1)].integer));
+ break;
+ case 2:
+ nrrd->setpDepth((yyvsp[(1) - (1)].integer));
+ break;
+ }
+ dim++;
+ ;}
+ break;
+
+
+/* Line 1267 of yacc.c. */
+#line 1981 "../fitsy/nrrdparser.C"
+ default: break;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (nrrd, ll, YY_("syntax error"));
+#else
+ {
+ YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+ if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+ {
+ YYSIZE_T yyalloc = 2 * yysize;
+ if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+ yyalloc = YYSTACK_ALLOC_MAXIMUM;
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+ if (yymsg)
+ yymsg_alloc = yyalloc;
+ else
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ }
+ }
+
+ if (0 < yysize && yysize <= yymsg_alloc)
+ {
+ (void) yysyntax_error (yymsg, yystate, yychar);
+ yyerror (nrrd, ll, yymsg);
+ }
+ else
+ {
+ yyerror (nrrd, ll, YY_("syntax error"));
+ if (yysize != 0)
+ goto yyexhaustedlab;
+ }
+ }
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse look-ahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval, nrrd, ll);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse look-ahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp, nrrd, ll);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ *++yyvsp = yylval;
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (nrrd, ll, YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEOF && yychar != YYEMPTY)
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval, nrrd, ll);
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp, nrrd, ll);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ /* Make sure YYID is used. */
+ return YYID (yyresult);
+}
+
+
+#line 398 "../fitsy/nrrdparser.Y"
+
+
diff --git a/fitsy++/nrrdparser.H b/fitsy++/nrrdparser.H
new file mode 100644
index 0000000..250d4eb
--- /dev/null
+++ b/fitsy++/nrrdparser.H
@@ -0,0 +1,259 @@
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton interface for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ EOF_ = 258,
+ INT = 259,
+ REAL = 260,
+ STRING = 261,
+ DEBUG_ = 262,
+ ON_ = 263,
+ OFF_ = 264,
+ NRRD0001_ = 265,
+ NRRD0002_ = 266,
+ NRRD0003_ = 267,
+ NRRD0004_ = 268,
+ NRRD0005_ = 269,
+ DATA_ = 270,
+ FILE_ = 271,
+ SPACE_ = 272,
+ UNITS_ = 273,
+ DIMENSIONS_ = 274,
+ ORIGIN_ = 275,
+ DIRECTIONS_ = 276,
+ DIMENSION_ = 277,
+ TYPE_ = 278,
+ SIGNED_ = 279,
+ UNSIGNED_ = 280,
+ CHAR_ = 281,
+ INT8_ = 282,
+ INT8_T_ = 283,
+ UCHAR_ = 284,
+ UINT8_ = 285,
+ UINT8_T_ = 286,
+ SHORT_ = 287,
+ INT_ = 288,
+ INT16_ = 289,
+ INT16_T_ = 290,
+ USHORT_ = 291,
+ UINT16_ = 292,
+ UINT16_T_ = 293,
+ INT32_ = 294,
+ INT32_T_ = 295,
+ UINT_ = 296,
+ UINT32_ = 297,
+ UINT32_T_ = 298,
+ LONG_ = 299,
+ LONGLONG_ = 300,
+ INT64_ = 301,
+ INT64_T_ = 302,
+ ULONGLONG_ = 303,
+ UINT64_ = 304,
+ UINT64_T_ = 305,
+ FLOAT_ = 306,
+ DOUBLE_ = 307,
+ BLOCK_ = 308,
+ SIZE_ = 309,
+ BLOCKSIZE_ = 310,
+ ENCODING_ = 311,
+ RAW_ = 312,
+ TXT_ = 313,
+ TEXT_ = 314,
+ ASCII_ = 315,
+ HEX_ = 316,
+ GZ_ = 317,
+ GZIP_ = 318,
+ BZ2_ = 319,
+ BZIP2_ = 320,
+ ENDIAN_ = 321,
+ BIG_ = 322,
+ LITTLE_ = 323,
+ CONTENT_ = 324,
+ OLD_ = 325,
+ MIN_ = 326,
+ OLDMIN_ = 327,
+ MAX_ = 328,
+ OLDMAX_ = 329,
+ SKIP_ = 330,
+ LINE_ = 331,
+ LINESKIP_ = 332,
+ BYTE_ = 333,
+ BYTESKIP_ = 334,
+ NUMBER_ = 335,
+ SAMPLE_ = 336,
+ SAMPLEUNITS_ = 337,
+ SIZES_ = 338,
+ SPACINGS_ = 339,
+ THICKNESSES_ = 340,
+ AXIS_ = 341,
+ MINS_ = 342,
+ AXISMINS_ = 343,
+ MAXS_ = 344,
+ AXISMAXS_ = 345,
+ CENTERS_ = 346,
+ CENTERINGS_ = 347,
+ CELL_ = 348,
+ NODE_ = 349,
+ NONE_ = 350,
+ LABELS_ = 351,
+ KINDS_ = 352,
+ DOMAINS_ = 353
+ };
+#endif
+/* Tokens. */
+#define EOF_ 258
+#define INT 259
+#define REAL 260
+#define STRING 261
+#define DEBUG_ 262
+#define ON_ 263
+#define OFF_ 264
+#define NRRD0001_ 265
+#define NRRD0002_ 266
+#define NRRD0003_ 267
+#define NRRD0004_ 268
+#define NRRD0005_ 269
+#define DATA_ 270
+#define FILE_ 271
+#define SPACE_ 272
+#define UNITS_ 273
+#define DIMENSIONS_ 274
+#define ORIGIN_ 275
+#define DIRECTIONS_ 276
+#define DIMENSION_ 277
+#define TYPE_ 278
+#define SIGNED_ 279
+#define UNSIGNED_ 280
+#define CHAR_ 281
+#define INT8_ 282
+#define INT8_T_ 283
+#define UCHAR_ 284
+#define UINT8_ 285
+#define UINT8_T_ 286
+#define SHORT_ 287
+#define INT_ 288
+#define INT16_ 289
+#define INT16_T_ 290
+#define USHORT_ 291
+#define UINT16_ 292
+#define UINT16_T_ 293
+#define INT32_ 294
+#define INT32_T_ 295
+#define UINT_ 296
+#define UINT32_ 297
+#define UINT32_T_ 298
+#define LONG_ 299
+#define LONGLONG_ 300
+#define INT64_ 301
+#define INT64_T_ 302
+#define ULONGLONG_ 303
+#define UINT64_ 304
+#define UINT64_T_ 305
+#define FLOAT_ 306
+#define DOUBLE_ 307
+#define BLOCK_ 308
+#define SIZE_ 309
+#define BLOCKSIZE_ 310
+#define ENCODING_ 311
+#define RAW_ 312
+#define TXT_ 313
+#define TEXT_ 314
+#define ASCII_ 315
+#define HEX_ 316
+#define GZ_ 317
+#define GZIP_ 318
+#define BZ2_ 319
+#define BZIP2_ 320
+#define ENDIAN_ 321
+#define BIG_ 322
+#define LITTLE_ 323
+#define CONTENT_ 324
+#define OLD_ 325
+#define MIN_ 326
+#define OLDMIN_ 327
+#define MAX_ 328
+#define OLDMAX_ 329
+#define SKIP_ 330
+#define LINE_ 331
+#define LINESKIP_ 332
+#define BYTE_ 333
+#define BYTESKIP_ 334
+#define NUMBER_ 335
+#define SAMPLE_ 336
+#define SAMPLEUNITS_ 337
+#define SIZES_ 338
+#define SPACINGS_ 339
+#define THICKNESSES_ 340
+#define AXIS_ 341
+#define MINS_ 342
+#define AXISMINS_ 343
+#define MAXS_ 344
+#define AXISMAXS_ 345
+#define CENTERS_ 346
+#define CENTERINGS_ 347
+#define CELL_ 348
+#define NODE_ 349
+#define NONE_ 350
+#define LABELS_ 351
+#define KINDS_ 352
+#define DOMAINS_ 353
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+#line 29 "../fitsy/nrrdparser.Y"
+{
+#define NRRDPARSERSIZE 256
+ float real;
+ int integer;
+ char str[NRRDPARSERSIZE];
+}
+/* Line 1529 of yacc.c. */
+#line 252 "../fitsy/nrrdparser.H"
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
diff --git a/fitsy++/nrrdparser.Y b/fitsy++/nrrdparser.Y
new file mode 100644
index 0000000..9e1a658
--- /dev/null
+++ b/fitsy++/nrrdparser.Y
@@ -0,0 +1,398 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+%pure-parser
+%parse-param {FitsFile* nrrd}
+%lex-param {nrrdFlexLexer* ll}
+%parse-param {nrrdFlexLexer* ll}
+
+%{
+#define YYDEBUG 1
+
+#define DISCARD_(x) {yyclearin; nrrdDiscard(x);}
+
+#include "file.h"
+
+#undef yyFlexLexer
+#define yyFlexLexer nrrdFlexLexer
+#include <FlexLexer.h>
+
+extern int nrrdlex(void*, nrrdFlexLexer*);
+extern void nrrderror(FitsFile*, nrrdFlexLexer*, const char*);
+extern void nrrdDiscard(int);
+
+int dim;
+
+%}
+
+%union {
+#define NRRDPARSERSIZE 256
+ float real;
+ int integer;
+ char str[NRRDPARSERSIZE];
+}
+
+%type <real> numeric
+
+ // Basic
+%token EOF_
+%token <integer> INT
+%token <real> REAL
+%token <str> STRING
+
+%token DEBUG_
+%token ON_
+%token OFF_
+
+ // Magic
+%token NRRD0001_
+%token NRRD0002_
+%token NRRD0003_
+%token NRRD0004_
+%token NRRD0005_
+
+ // 3. Headers
+%token DATA_
+%token FILE_
+
+ // 4. Space
+%token SPACE_
+%token UNITS_
+%token DIMENSIONS_
+%token ORIGIN_
+%token DIRECTIONS_
+
+ // 5.1 Dimension
+%token DIMENSION_
+
+ // 5.2 Type
+%token TYPE_
+%token SIGNED_
+%token UNSIGNED_
+%token CHAR_
+%token INT8_
+%token INT8_T_
+%token UCHAR_
+%token UINT8_
+%token UINT8_T_
+%token SHORT_
+%token INT_
+%token INT16_
+%token INT16_T_
+%token USHORT_
+%token UINT16_
+%token UINT16_T_
+%token INT32_
+%token INT32_T_
+%token UINT_
+%token UINT32_
+%token UINT32_T_
+%token LONG_
+%token LONGLONG_
+%token INT64_
+%token INT64_T_
+%token ULONGLONG_
+%token UINT64_
+%token UINT64_T_
+%token FLOAT_
+%token DOUBLE_
+
+ // 5.3 Block
+%token BLOCK_
+%token SIZE_
+%token BLOCKSIZE_
+
+ // 5.4 ENCODING
+%token ENCODING_
+%token RAW_
+%token TXT_
+%token TEXT_
+%token ASCII_
+%token HEX_
+%token GZ_
+%token GZIP_
+%token BZ2_
+%token BZIP2_
+
+ // 5.5 Endian
+%token ENDIAN_
+%token BIG_
+%token LITTLE_
+
+ // 5.6 Content
+%token CONTENT_
+
+ // 5.7 MinMax
+%token OLD_
+%token MIN_
+%token OLDMIN_
+%token MAX_
+%token OLDMAX_
+
+ // 5.8 Skip
+%token SKIP_
+%token LINE_
+%token LINESKIP_
+%token BYTE_
+%token BYTESKIP_
+
+ // 5.9 Number
+%token NUMBER_
+
+ // 5.10 Sample
+%token SAMPLE_
+%token SAMPLEUNITS_
+
+ // 6 Per Axis
+
+%token SIZES_
+%token SPACINGS_
+%token THICKNESSES_
+%token AXIS_
+%token MINS_
+%token AXISMINS_
+%token MAXS_
+%token AXISMAXS_
+%token CENTERS_
+%token CENTERINGS_
+%token CELL_
+%token NODE_
+%token NONE_
+%token LABELS_
+%token KINDS_
+%token DOMAINS_
+
+%%
+
+start : {dim=0; nrrd->setpArch(FitsFile::BIG);} commands
+ ;
+
+commands: commands command terminator
+ | command terminator
+ ;
+
+command : /* empty */
+ | DEBUG_ debug
+ | magic
+ | comment
+ | DATA_ FILE_ ':' STRING
+ | SPACE_ space
+ | DIMENSION_ ':' INT
+ | TYPE_ ':' type
+ | block
+ | ENCODING_ ':' encoding
+ | ENDIAN_ ':' endian
+ | CONTENT_ ':' {DISCARD_(1)} STRING
+ | MIN_ ':' numeric
+ | MAX_ ':' numeric
+ | oldmin
+ | oldmax
+ | lineskip
+ | byteskip
+ | NUMBER_ ':' STRING
+ | SIZES_ ':' sizes
+ | SPACINGS_ ':' spacings
+ | THICKNESSES_ ':' thicknesses
+ | AXIS_ MINS_ ':' axismins
+ | AXISMINS_ ':' axismins
+ | AXIS_ MAXS_ ':' axismaxs
+ | AXISMAXS_ ':' axismaxs
+ | CENTERS_ ':' centers
+ | CENTERINGS_ ':' centers
+ | LABELS_ ':' labels
+ | UNITS_ ':' units
+ | KINDS_ ':' kinds
+ ;
+
+magic : NRRD0001_
+ | NRRD0002_
+ | NRRD0003_
+ | NRRD0004_
+ | NRRD0005_
+ ;
+
+comment : '#' {DISCARD_(1)} STRING
+ ;
+
+terminator: '\n'
+ | EOF_ {YYACCEPT;}
+ ;
+
+numeric : REAL {$$=$1;}
+ | INT {$$=$1;}
+ ;
+
+debug : ON_ {yydebug=1;}
+ | OFF_ {yydebug=0;}
+ ;
+
+space : ':' {DISCARD_(1)} STRING
+ | DIMENSION_ ':' INT
+ | UNITS_ ':' {DISCARD_(1)} STRING
+ | ORIGIN_ ':' {DISCARD_(1)} STRING
+ | DIRECTIONS_ ':' {DISCARD_(1)} STRING
+ ;
+
+type : char {nrrd->setpBitpix(8);}
+ | uchar {nrrd->setpBitpix(8);}
+ | short {nrrd->setpBitpix(16);}
+ | ushort {nrrd->setpBitpix(16);}
+ | int {nrrd->setpBitpix(32);}
+ | uint {nrrd->setpBitpix(32);}
+ | long {nrrd->setpBitpix(64);}
+ | ulong {nrrd->setpBitpix(64);}
+ | FLOAT_ {nrrd->setpBitpix(-32);}
+ | DOUBLE_ {nrrd->setpBitpix(-64);}
+ | BLOCK_
+ ;
+
+char : CHAR_
+ | SIGNED_ CHAR_
+ | INT8_
+ | INT8_T_
+ ;
+
+uchar : UCHAR_
+ | UNSIGNED_ CHAR_
+ | UINT8_
+ | UINT8_T_
+ ;
+
+short : SHORT_
+ | SHORT_ INT_
+ | SIGNED_ SHORT_
+ | SIGNED_ SHORT_ INT_
+ | INT16_
+ | INT16_T_
+ ;
+
+ushort : USHORT_
+ | UNSIGNED_ SHORT_
+ | UNSIGNED_ SHORT_ INT_
+ | UINT16_
+ | UINT16_T_
+ ;
+
+int : INT_
+ | SIGNED_ INT_
+ | INT32_
+ | INT32_T_
+ ;
+
+uint : UINT_
+ | UNSIGNED_ INT_
+ | UINT32_
+ | UINT32_T_
+ ;
+
+long : LONGLONG_
+ | LONG_ LONG_
+ | LONG_ LONG_ INT_
+ | SIGNED_ LONG_ LONG_
+ | SIGNED_ LONG_ LONG_ INT_
+ | INT64_
+ | INT64_T_
+ ;
+
+ulong : ULONGLONG_
+ | UNSIGNED_ LONG_ LONG_
+ | UNSIGNED_ LONG_ LONG_ INT_
+ | UINT64_
+ | UINT64_T_
+ ;
+
+block : BLOCK_ SIZE_ ':' INT
+ | BLOCKSIZE_ ':' INT
+ ;
+
+encoding : RAW_ {nrrd->setpEncoding(FitsFile::RAW);}
+ | TXT_ {nrrd->setpEncoding(FitsFile::ASCII);}
+ | TEXT_ {nrrd->setpEncoding(FitsFile::ASCII);}
+ | ASCII_ {nrrd->setpEncoding(FitsFile::ASCII);}
+ | HEX_ {nrrd->setpEncoding(FitsFile::HEX);}
+ | GZ_ {nrrd->setpEncoding(FitsFile::GZIP);}
+ | GZIP_ {nrrd->setpEncoding(FitsFile::GZIP);}
+ | BZ2_ {nrrd->setpEncoding(FitsFile::BZ2);}
+ | BZIP2_ {nrrd->setpEncoding(FitsFile::BZ2);}
+ ;
+
+endian : BIG_ {nrrd->setpArch(FitsFile::BIG);}
+ | LITTLE_ {nrrd->setpArch(FitsFile::LITTLE);}
+ ;
+
+oldmin : OLD_ MIN_ ':' numeric
+ | OLDMIN_ ':' numeric
+ ;
+
+oldmax : OLD_ MAX_ ':' numeric
+ | OLDMAX_ ':' numeric
+ ;
+
+lineskip : LINE_ SKIP_ ':' INT
+ | LINESKIP_ ':' INT
+ ;
+
+byteskip : BYTE_ SKIP_ ':' INT
+ | BYTESKIP_ ':' INT
+ ;
+
+sizes : sizes size
+ | size
+ ;
+
+size : INT
+ {
+ switch (dim) {
+ case 0:
+ nrrd->setpWidth($1);
+ break;
+ case 1:
+ nrrd->setpHeight($1);
+ break;
+ case 2:
+ nrrd->setpDepth($1);
+ break;
+ }
+ dim++;
+ }
+ ;
+
+spacings : spacings numeric
+ | numeric
+ ;
+
+thicknesses : thicknesses numeric
+ | numeric
+ ;
+
+axismins : axismins numeric
+ | numeric
+ ;
+
+axismaxs : axismaxs numeric
+ | numeric
+ ;
+
+centers : centers center
+ | center
+ ;
+
+center : CELL_
+ | NODE_
+ | NONE_
+ ;
+
+labels : labels STRING
+ | STRING
+ ;
+
+units : units STRING
+ | STRING
+ ;
+
+kinds : kinds STRING
+ | STRING
+ ;
+
+%%
diff --git a/fitsy++/order.C b/fitsy++/order.C
new file mode 100644
index 0000000..5caccc5
--- /dev/null
+++ b/fitsy++/order.C
@@ -0,0 +1,267 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "order.h"
+
+FitsOrder::FitsOrder(FitsFile* fits, FitsHead* hdr, char* data, size_t sz)
+{
+ head_ = hdr;
+ data_ = data;
+ dataSize_ = sz;
+
+ primary_ = fits->primary();
+ ext_ = fits->ext();
+ inherit_ = fits->inherit();
+ byteswap_ = fits->byteswap();
+ endian_ = fits->endian();
+
+ // just to make sure
+ head_->updateHDU();
+
+ valid_ = 1;
+}
+
+FitsOrder::~FitsOrder()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+
+FitsOrderNext::FitsOrderNext(FitsFile* prev)
+{
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = prev->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ return;
+}
+
+/*
+FitsOrder::FitsOrder(FitsFile* fits, int order)
+{
+ FitsHead* src = fits->head();
+
+ width_ = src->naxis(0);
+ height_ = src->naxis(1);
+ depth_ = src->naxis(2);
+ if (width_<1)
+ width_ = 1;
+ if (height_<1)
+ height_ = 1;
+ if (depth_<1)
+ depth_=1;
+ size_ = (size_t)width_*height_*depth_;
+
+ primary_ = fits->primary();
+ ext_ = fits->ext();
+ inherit_ = fits->inherit();
+ byteswap_ = fits->byteswap();
+ endian_ = fits->endian();
+
+ bitpix_ = src->hdu()->bitpix();
+ switch (bitpix_) {
+ case 8:
+ if (!(data_ = new char[size_]))
+ return;
+ dataSize_ = size_*sizeof(char);
+ pixelSize_ = 1;
+ break;
+ case 16:
+ if (!(data_ = new short[size_]))
+ return;
+ dataSize_ = size_*sizeof(short);
+ pixelSize_ = 2;
+ break;
+ case -16:
+ if (!(data_ = new unsigned short[size_]))
+ return;
+ dataSize_ = size_*sizeof(unsigned short);
+ pixelSize_ = 2;
+ break;
+ case 32:
+ if (!(data_ = new int[size_]))
+ return;
+ dataSize_ = size_*sizeof(int);
+ pixelSize_ = 4;
+ break;
+ case -32:
+ if (!(data_ = new float[size_]))
+ return;
+ dataSize_ = size_*sizeof(float);
+ pixelSize_ = 4;
+ break;
+ case 64:
+ if (!(data_ = new long long[size_]))
+ return;
+ dataSize_ = size_*sizeof(long long);
+ pixelSize_ = 8;
+ break;
+ case -64:
+ if (!(data_ = new double[size_]))
+ return;
+ dataSize_ = size_*sizeof(double);
+ pixelSize_ = 8;
+ break;
+ }
+ dataSkip_ = 0;
+ memset(data_, 0, dataSize_);
+
+ initHeader(fits, order);
+ reorder(fits, order);
+
+ // made it this far, must be valid
+ valid_ = 1;
+}
+
+FitsOrder::~FitsOrder()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+void FitsOrder::initHeader(FitsFile* fits, int order)
+{
+ head_ = new FitsHead(*(fits->head()));
+
+ // NAXIS
+ int a1 = head_->getInteger("NAXIS1",1);
+ int a2 = head_->getInteger("NAXIS2",1);
+ int a3 = head_->getInteger("NAXIS3",1);
+ int n1,n2,n3;
+
+ switch (order) {
+ case 123:
+ n1=a1;
+ n2=a2;
+ n3=a3;
+ break;
+ case 132:
+ n1=a1;
+ n2=a3;
+ n3=a2;
+ break;
+ case 213:
+ n1=a2;
+ n2=a1;
+ n3=a3;
+ break;
+ case 231:
+ n1=a2;
+ n2=a3;
+ n3=a1;
+ break;
+ case 312:
+ n1=a3;
+ n2=a1;
+ n3=a2;
+ break;
+ case 321:
+ n1=a3;
+ n2=a2;
+ n3=a1;
+ break;
+ }
+
+ head_->setInteger("NAXES", 3, "");
+ head_->setInteger("NAXIS1", n1, "");
+ head_->setInteger("NAXIS2", n2, "");
+ head_->setInteger("NAXIS3", n3, "");
+
+ head_->updateHDU();
+}
+
+void FitsOrder::reorder(FitsFile* fits, int order)
+{
+ char* src = (char*)fits->data();
+ char* dest = (char*)data_;
+ char* dptr = dest;
+ int s1 = pixelSize_;
+ int s2 = width_*pixelSize_;
+ int s3 = height_*width_*pixelSize_;
+
+ switch (order) {
+ case 123:
+ // should not be used, but just in case
+ memcpy(dest, src, dataSize_);
+ break;
+ case 132:
+ for (int jj=0; jj<height_; jj++) {
+ char* sptr =src+jj*s2;
+ for (int kk=0; kk<depth_; kk++) {
+ memcpy(dptr, sptr, s2);
+ dptr += s2;
+ sptr += s3;
+ }
+ }
+ break;
+ case 213:
+ for (int kk=0; kk<depth_; kk++) {
+ for (int ii=0; ii<width_; ii++) {
+ char* sptr =src+kk*s3+ii;
+ for (int jj=0; jj<height_; jj++) {
+ memcpy(dptr, sptr, s1);
+ dptr += s1;
+ sptr += s2;
+ }
+ }
+ }
+ break;
+ case 231:
+ for (int ii=0; ii<width_; ii++) {
+ for (int kk=0; kk<depth_; kk++) {
+ char* sptr =src+kk*s3+ii;
+ for (int jj=0; jj<height_; jj++) {
+ memcpy(dptr, sptr, s1);
+ dptr += s1;
+ sptr += s2;
+ }
+ }
+ }
+ break;
+ case 312:
+ for (int jj=0; jj<height_; jj++) {
+ for (int ii=0; ii<width_; ii++) {
+ char* sptr =src+jj*s2+ii;
+ for (int kk=0; kk<depth_; kk++) {
+ memcpy(dptr, sptr, s1);
+ dptr += s1;
+ sptr += s3;
+ }
+ }
+ }
+ break;
+ case 321:
+ for (int ii=0; ii<width_; ii++) {
+ for (int jj=0; jj<height_; jj++) {
+ char* sptr =src+jj*s2+ii;
+ for (int kk=0; kk<depth_; kk++) {
+ memcpy(dptr, sptr, s1);
+ dptr += s1;
+ sptr += s3;
+ }
+ }
+ }
+ break;
+ }
+}
+*/
diff --git a/fitsy++/order.h b/fitsy++/order.h
new file mode 100644
index 0000000..37a198c
--- /dev/null
+++ b/fitsy++/order.h
@@ -0,0 +1,21 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsorder_h__
+#define __fitsorder_h__
+
+#include "file.h"
+
+class FitsOrder : public FitsFile {
+ public:
+ FitsOrder(FitsFile*, FitsHead*, char*, size_t);
+ ~FitsOrder();
+};
+
+class FitsOrderNext : public FitsFile {
+public:
+ FitsOrderNext(FitsFile* prev);
+};
+
+#endif
diff --git a/fitsy++/outchannel.C b/fitsy++/outchannel.C
new file mode 100644
index 0000000..d79c74c
--- /dev/null
+++ b/fitsy++/outchannel.C
@@ -0,0 +1,30 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <tcl.h>
+
+#include "outchannel.h"
+
+OutFitsChannel::OutFitsChannel(Tcl_Interp* interp, const char* ch)
+{
+ int tclMode;
+ if ((ch_ = Tcl_GetChannel(interp, (char*)ch, &tclMode)))
+ valid_ = 1;
+}
+
+int OutFitsChannel::write(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = Tcl_Write(ch_, where+rr, (ss>B1MB) ? B1MB : ss);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
diff --git a/fitsy++/outchannel.h b/fitsy++/outchannel.h
new file mode 100644
index 0000000..4c847e3
--- /dev/null
+++ b/fitsy++/outchannel.h
@@ -0,0 +1,20 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __outchannel_h__
+#define __outchannel_h__
+
+#include "outfits.h"
+
+class OutFitsChannel : public virtual OutFitsStream {
+ private:
+ Tcl_Channel ch_;
+
+ public:
+ OutFitsChannel(Tcl_Interp*, const char*);
+
+ int write(char*, size_t);
+};
+
+#endif
diff --git a/fitsy++/outfile.C b/fitsy++/outfile.C
new file mode 100644
index 0000000..dd53f24
--- /dev/null
+++ b/fitsy++/outfile.C
@@ -0,0 +1,63 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdio.h>
+#include "outfile.h"
+
+OutFitsFile::OutFitsFile(const char* fn)
+{
+ if ((fd_ = fopen(fn, "wb")))
+ valid_ = 1;
+}
+
+OutFitsFile::~OutFitsFile()
+{
+ if (fd_)
+ fclose(fd_);
+}
+
+int OutFitsFile::write(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = fwrite(where+rr, 1, (ss>B1MB) ? B1MB : ss, fd_);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+OutFitsFileGZ::OutFitsFileGZ(const char* fn)
+{
+ if ((fd_ = gzopen(fn, "wb")))
+ valid_ = 1;
+}
+
+OutFitsFileGZ::~OutFitsFileGZ()
+{
+ if (fd_)
+ gzclose(fd_);
+}
+
+int OutFitsFileGZ::write(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = gzwrite(fd_, where+rr, (ss>B1MB) ? B1MB : ss);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
diff --git a/fitsy++/outfile.h b/fitsy++/outfile.h
new file mode 100644
index 0000000..d8d0051
--- /dev/null
+++ b/fitsy++/outfile.h
@@ -0,0 +1,33 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __outfile_h__
+#define __outfile_h__
+
+#include "outfits.h"
+#include "zlib.h"
+
+class OutFitsFile : public virtual OutFitsStream {
+ private:
+ FILE* fd_;
+
+ public:
+ OutFitsFile(const char*);
+ ~OutFitsFile();
+
+ int write(char*, size_t);
+};
+
+class OutFitsFileGZ : public virtual OutFitsStream {
+ private:
+ gzFile fd_;
+
+ public:
+ OutFitsFileGZ(const char*);
+ ~OutFitsFileGZ();
+
+ int write(char*, size_t);
+};
+
+#endif
diff --git a/fitsy++/outfits.C b/fitsy++/outfits.C
new file mode 100644
index 0000000..b05e098
--- /dev/null
+++ b/fitsy++/outfits.C
@@ -0,0 +1,59 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "outfits.h"
+#include "util.h"
+
+OutFitsStream::OutFitsStream()
+{
+ valid_ = 0;
+}
+
+OutFitsStream::~OutFitsStream()
+{
+}
+
+int OutFitsStream::writeSwap(char* where, int size, int bitpix)
+{
+ char* buf = new char[B4KB];
+
+ // size_t size is unsigned
+ long long ss = size;
+ size_t rr =0;
+ int r;
+ do {
+ r = (ss>B4KB) ? B4KB : ss;
+
+ switch (bitpix) {
+ case 8:
+ memcpy(buf, where+rr, r);
+ break;
+ case 16:
+ case -16:
+ for (int ii=0; ii<r; ii+=2)
+ swap2(where+rr+ii,buf+ii);
+ break;
+ case 32:
+ case -32:
+ for (int ii=0; ii<r; ii+=4)
+ swap4(where+rr+ii,buf+ii);
+ break;
+ case 64:
+ case -64:
+ for (int ii=0; ii<r; ii+=8)
+ swap8(where+rr+ii,buf+ii);
+ break;
+ }
+
+ write(buf,r);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ if (buf)
+ delete [] buf;
+
+ return rr;
+}
+
diff --git a/fitsy++/outfits.h b/fitsy++/outfits.h
new file mode 100644
index 0000000..652f8bb
--- /dev/null
+++ b/fitsy++/outfits.h
@@ -0,0 +1,27 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __outfits_h__
+#define __outfits_h__
+
+#include <stdlib.h>
+
+#define B1KB 1024
+#define B4KB 4096
+#define B1MB 1048576
+
+class OutFitsStream {
+ protected:
+ int valid_;
+
+ public:
+ OutFitsStream();
+ virtual ~OutFitsStream();
+
+ virtual int write(char*, size_t) =0;
+ int writeSwap(char*, int, int);
+ int valid() {return valid_;}
+};
+
+#endif
diff --git a/fitsy++/outsocket.C b/fitsy++/outsocket.C
new file mode 100644
index 0000000..8739499
--- /dev/null
+++ b/fitsy++/outsocket.C
@@ -0,0 +1,200 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "outsocket.h"
+#include "util.h"
+
+#ifndef __WIN32
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include "file.h"
+
+OutFitsSocket::OutFitsSocket(int s)
+{
+ id_ = s;
+ valid_ = 1;
+}
+
+int OutFitsSocket::write(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss = size;
+ size_t rr =0;
+ int r;
+ do {
+ r = (ss>B4KB) ? B4KB : ss;
+ send(id_, where+rr, r, 0);
+ if (r == -1) {
+ internalError("Fitsy++ outsocket write error");
+ return -1;
+ }
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+OutFitsSocketGZ::OutFitsSocketGZ(int s)
+{
+ id_ = s;
+ stream_ = new z_stream;
+ buf_ = new unsigned char[B4KB];
+
+ crc_ = crc32(0L, Z_NULL, 0);
+
+ stream_->next_in = NULL;
+ stream_->avail_in = 0;
+ stream_->next_out = NULL;
+ stream_->avail_out = 0;
+
+ stream_->zalloc = NULL;
+ stream_->zfree = NULL;
+ stream_->opaque = NULL;
+
+ if (deflateInit2(stream_, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+ -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
+ internalError("Fitsy++ outsocket deflateInit error");
+ return;
+ }
+
+ // dump simple header
+ unsigned char header[10] =
+ {0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x03};
+ send(id_, header, 10, 0);
+
+ stream_->next_out = buf_;
+ stream_->avail_out = B4KB;
+
+ valid_ = 1;
+}
+
+OutFitsSocketGZ::~OutFitsSocketGZ()
+{
+ // flush any pending output
+ while (deflategz(Z_FINISH) == Z_OK);
+
+ // output crc/length
+ putlong(crc_);
+ putlong(stream_->total_in);
+
+ if (deflateEnd(stream_) != Z_OK)
+ internalError("Fitsy++ outsocket deflateEnd error");
+
+ if (stream_)
+ delete stream_;
+
+ if (buf_)
+ delete [] buf_;
+}
+
+int OutFitsSocketGZ::write(char* where, size_t size)
+{
+ stream_->next_in = (unsigned char*)where;
+ stream_->avail_in = size;
+
+ if (DebugGZ)
+ cerr << "write " << size << endl;
+
+ while (stream_->avail_in > 0 && deflategz(Z_NO_FLUSH) == Z_OK);
+
+ // update crc
+ crc_ = crc32(crc_, (const Bytef *)where, size);
+
+ return size - stream_->avail_in;
+}
+
+int OutFitsSocketGZ::deflategz(int flush)
+{
+ int result = deflate(stream_, flush);
+
+ switch (result) {
+ case Z_OK:
+ if (DebugGZ)
+ cerr << "deflate OK: avail_in " << stream_->avail_in
+ << " avail_out " << stream_->avail_out << endl;
+ break;
+ case Z_STREAM_END:
+ if (DebugGZ)
+ cerr << "deflate STRM_END: avail_in " << stream_->avail_in
+ << " avail_out " << stream_->avail_out << endl;
+ break;
+ default:
+ if (DebugGZ)
+ cerr << "deflate Error " << result << endl;
+ return result;
+ }
+
+ if (stream_->avail_out == 0 || result != Z_OK) {
+ int s = B4KB - stream_->avail_out;
+ unsigned char* d = buf_;
+
+ while (s>0) {
+ int r = send(id_, d, s, 0);
+
+ if (r == -1) {
+ internalError("Fitsy++ outsocket deflate send error");
+ return Z_ERRNO;
+ }
+
+ if (DebugGZ)
+ cerr << "deflate send " << r << " out of " << s << endl;
+
+ s -= r;
+ d += r;
+ }
+
+ stream_->next_out = buf_;
+ stream_->avail_out = B4KB;
+ }
+
+ return result;
+}
+
+void OutFitsSocketGZ::putlong(unsigned long l)
+{
+ // dump in LSB order
+ for (int n = 0; n < 4; n++) {
+ unsigned char foo = (int)(l & 0xff);
+ send(id_, &foo, 1, 0);
+ l >>= 8;
+ }
+}
+
+#else
+
+OutFitsSocket::OutFitsSocket(int s)
+{
+ id_ = s;
+ valid_ = 0;
+}
+
+int OutFitsSocket::write(char* where, size_t size)
+{
+ return 0;
+}
+
+OutFitsSocketGZ::OutFitsSocketGZ(int s)
+{
+ id_ = s;
+ valid_ = 0;
+}
+
+OutFitsSocketGZ::~OutFitsSocketGZ() {}
+
+int OutFitsSocketGZ::write(char* where, size_t size)
+{
+ return 0;
+}
+
+int OutFitsSocketGZ::deflategz(int flush)
+{
+ return 0;
+}
+
+void OutFitsSocketGZ::putlong(unsigned long l) {}
+
+#endif
diff --git a/fitsy++/outsocket.h b/fitsy++/outsocket.h
new file mode 100644
index 0000000..6bdcd99
--- /dev/null
+++ b/fitsy++/outsocket.h
@@ -0,0 +1,38 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __outfitssocket_h__
+#define __outfitssocket_h__
+
+#include "outfits.h"
+#include "zlib.h"
+
+class OutFitsSocket : public virtual OutFitsStream {
+ private:
+ int id_;
+
+ public:
+ OutFitsSocket(int s);
+
+ int write(char*, size_t);
+};
+
+class OutFitsSocketGZ : public virtual OutFitsStream {
+ private:
+ int id_;
+ z_stream* stream_;
+ unsigned char* buf_;
+ unsigned long crc_;
+
+ int deflategz(int);
+ void putlong(unsigned long);
+
+ public:
+ OutFitsSocketGZ(int);
+ ~OutFitsSocketGZ();
+
+ int write(char*, size_t);
+};
+
+#endif
diff --git a/fitsy++/parser.C b/fitsy++/parser.C
new file mode 100644
index 0000000..696f64a
--- /dev/null
+++ b/fitsy++/parser.C
@@ -0,0 +1,2194 @@
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "2.3"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 1
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* Substitute the variable and function names. */
+#define yyparse ffparse
+#define yylex fflex
+#define yyerror fferror
+#define yylval fflval
+#define yychar ffchar
+#define yydebug ffdebug
+#define yynerrs ffnerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ INT = 258,
+ STRING = 259,
+ ARCH_ = 260,
+ ARRAY_ = 261,
+ BIG_ = 262,
+ BIGENDIAN_ = 263,
+ BIN_ = 264,
+ BINKEY_ = 265,
+ BINCOL_ = 266,
+ BITPIX_ = 267,
+ COL_ = 268,
+ DIM_ = 269,
+ DIMS_ = 270,
+ ECLIPTIC_ = 271,
+ ENDIAN_ = 272,
+ EQUATORIAL_ = 273,
+ GALACTIC_ = 274,
+ KEY_ = 275,
+ LAYOUT_ = 276,
+ LITTLE_ = 277,
+ LITTLEENDIAN_ = 278,
+ NESTED_ = 279,
+ NORTH_ = 280,
+ ORDER_ = 281,
+ QUAD_ = 282,
+ RING_ = 283,
+ SKIP_ = 284,
+ SOUTH_ = 285,
+ SYSTEM_ = 286,
+ UNKNOWN_ = 287,
+ XDIM_ = 288,
+ YDIM_ = 289,
+ ZDIM_ = 290
+ };
+#endif
+/* Tokens. */
+#define INT 258
+#define STRING 259
+#define ARCH_ 260
+#define ARRAY_ 261
+#define BIG_ 262
+#define BIGENDIAN_ 263
+#define BIN_ 264
+#define BINKEY_ 265
+#define BINCOL_ 266
+#define BITPIX_ 267
+#define COL_ 268
+#define DIM_ 269
+#define DIMS_ 270
+#define ECLIPTIC_ 271
+#define ENDIAN_ 272
+#define EQUATORIAL_ 273
+#define GALACTIC_ 274
+#define KEY_ 275
+#define LAYOUT_ 276
+#define LITTLE_ 277
+#define LITTLEENDIAN_ 278
+#define NESTED_ 279
+#define NORTH_ 280
+#define ORDER_ 281
+#define QUAD_ 282
+#define RING_ 283
+#define SKIP_ 284
+#define SOUTH_ 285
+#define SYSTEM_ 286
+#define UNKNOWN_ 287
+#define XDIM_ 288
+#define YDIM_ 289
+#define ZDIM_ 290
+
+
+
+
+/* Copy the first part of user declarations. */
+#line 10 "../fitsy/parser.Y"
+
+#define YYDEBUG 1
+
+#define GOTOFILT(x) {yyclearin; ffFilter(x);}
+#define GOTOARR(x) {yyclearin; ffArray(x);}
+
+#include "file.h"
+#include "hpx.h"
+
+#undef yyFlexLexer
+#define yyFlexLexer ffFlexLexer
+#include <FlexLexer.h>
+
+extern int fflex(void*, ffFlexLexer*);
+extern void fferror(FitsFile*, ffFlexLexer*, const char*);
+
+char ff_filter[512];
+extern void ffFilter(int);
+extern void ffArray(int);
+
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+#line 32 "../fitsy/parser.Y"
+{
+ float real;
+ int integer;
+ char str[256];
+ void* ptr;
+}
+/* Line 193 of yacc.c. */
+#line 203 "../fitsy/parser.C"
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 216 of yacc.c. */
+#line 216 "../fitsy/parser.C"
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions. */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int i)
+#else
+static int
+YYID (i)
+ int i;
+#endif
+{
+ return i;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined _STDLIB_H \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (YYID (0))
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (YYID (0))
+
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 6
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 250
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 56
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 34
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 121
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 203
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 290
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 38, 39, 45, 2, 40, 2, 55, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 43, 2,
+ 2, 46, 2, 2, 44, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 42, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 36, 2, 37, 2, 2, 2, 2, 47, 2,
+ 54, 2, 53, 2, 2, 50, 2, 2, 51, 2,
+ 2, 2, 41, 2, 52, 48, 2, 49, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const yytype_uint16 yyprhs[] =
+{
+ 0, 0, 3, 5, 8, 12, 15, 21, 25, 30,
+ 35, 38, 42, 46, 52, 56, 61, 66, 69, 73,
+ 77, 83, 86, 90, 94, 95, 104, 105, 109, 110,
+ 112, 116, 120, 123, 126, 131, 135, 141, 147, 155,
+ 159, 161, 165, 169, 175, 176, 178, 180, 184, 188,
+ 190, 194, 198, 200, 206, 210, 214, 216, 218, 222,
+ 226, 229, 231, 233, 235, 237, 243, 247, 255, 261,
+ 265, 267, 271, 275, 277, 281, 285, 289, 293, 297,
+ 301, 305, 309, 313, 315, 317, 319, 321, 323, 328,
+ 330, 332, 334, 336, 338, 340, 342, 344, 346, 350,
+ 356, 357, 360, 361, 363, 365, 369, 373, 375, 379,
+ 383, 387, 391, 395, 397, 399, 401, 403, 405, 407,
+ 409, 411
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yytype_int8 yyrhs[] =
+{
+ 57, 0, -1, 60, -1, 60, 61, -1, 60, 61,
+ 63, -1, 60, 63, -1, 60, 36, 62, 64, 37,
+ -1, 60, 61, 71, -1, 60, 61, 71, 63, -1,
+ 60, 61, 63, 71, -1, 60, 71, -1, 60, 71,
+ 63, -1, 60, 63, 71, -1, 60, 36, 62, 72,
+ 37, -1, 60, 61, 84, -1, 60, 61, 84, 63,
+ -1, 60, 61, 63, 84, -1, 60, 84, -1, 60,
+ 84, 63, -1, 60, 63, 84, -1, 60, 36, 62,
+ 84, 37, -1, 60, 75, -1, 60, 75, 63, -1,
+ 60, 63, 75, -1, -1, 60, 36, 6, 58, 38,
+ 79, 39, 37, -1, -1, 1, 59, 4, -1, -1,
+ 4, -1, 36, 4, 37, -1, 36, 3, 37, -1,
+ 4, 40, -1, 3, 40, -1, 36, 64, 65, 37,
+ -1, 66, 40, 67, -1, 66, 40, 67, 40, 70,
+ -1, 66, 40, 67, 40, 69, -1, 66, 40, 67,
+ 40, 70, 40, 69, -1, 66, 40, 70, -1, 68,
+ -1, 68, 40, 70, -1, 68, 40, 69, -1, 68,
+ 40, 70, 40, 69, -1, -1, 41, -1, 42, -1,
+ 3, 43, 3, -1, 3, 44, 3, -1, 45, -1,
+ 3, 43, 3, -1, 3, 44, 3, -1, 45, -1,
+ 3, 44, 3, 44, 3, -1, 3, 43, 3, -1,
+ 3, 44, 3, -1, 45, -1, 3, -1, 36, 72,
+ 37, -1, 73, 46, 74, -1, 73, 74, -1, 9,
+ -1, 10, -1, 11, -1, 20, -1, 38, 4, 40,
+ 4, 39, -1, 4, 40, 4, -1, 38, 4, 40,
+ 4, 40, 4, 39, -1, 4, 40, 4, 40, 4,
+ -1, 38, 4, 39, -1, 4, -1, 36, 76, 37,
+ -1, 76, 40, 77, -1, 77, -1, 33, 46, 3,
+ -1, 34, 46, 3, -1, 35, 46, 3, -1, 14,
+ 46, 3, -1, 15, 46, 3, -1, 12, 46, 3,
+ -1, 29, 46, 3, -1, 5, 46, 78, -1, 17,
+ 46, 78, -1, 78, -1, 7, -1, 8, -1, 22,
+ -1, 23, -1, 80, 81, 82, 83, -1, 47, -1,
+ 48, -1, 49, -1, 50, -1, 51, -1, 52, -1,
+ 53, -1, 54, -1, 3, -1, 3, 55, 3, -1,
+ 3, 55, 3, 55, 3, -1, -1, 43, 3, -1,
+ -1, 51, -1, 47, -1, 36, 85, 37, -1, 85,
+ 40, 86, -1, 86, -1, 31, 46, 87, -1, 26,
+ 46, 88, -1, 21, 46, 89, -1, 13, 46, 3,
+ -1, 27, 46, 3, -1, 18, -1, 19, -1, 16,
+ -1, 32, -1, 28, -1, 24, -1, 18, -1, 25,
+ -1, 30, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const yytype_uint16 yyrline[] =
+{
+ 0, 81, 81, 82, 83, 84, 85, 87, 88, 89,
+ 90, 91, 92, 93, 95, 96, 97, 98, 99, 100,
+ 101, 103, 104, 105, 106, 106, 108, 108, 112, 113,
+ 123, 124, 127, 128, 131, 133, 134, 135, 136, 137,
+ 138, 139, 140, 141, 144, 145, 146, 149, 156, 158,
+ 166, 168, 170, 173, 180, 182, 184, 187, 190, 192,
+ 193, 196, 197, 198, 199, 202, 203, 204, 205, 206,
+ 207, 210, 213, 214, 217, 218, 219, 220, 221, 222,
+ 223, 224, 225, 226, 229, 230, 231, 232, 235, 238,
+ 239, 240, 241, 242, 243, 244, 245, 248, 249, 250,
+ 254, 255, 258, 259, 260, 263, 266, 267, 270, 271,
+ 272, 273, 274, 277, 278, 279, 280, 283, 284, 287,
+ 288, 289
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "INT", "STRING", "ARCH_", "ARRAY_",
+ "BIG_", "BIGENDIAN_", "BIN_", "BINKEY_", "BINCOL_", "BITPIX_", "COL_",
+ "DIM_", "DIMS_", "ECLIPTIC_", "ENDIAN_", "EQUATORIAL_", "GALACTIC_",
+ "KEY_", "LAYOUT_", "LITTLE_", "LITTLEENDIAN_", "NESTED_", "NORTH_",
+ "ORDER_", "QUAD_", "RING_", "SKIP_", "SOUTH_", "SYSTEM_", "UNKNOWN_",
+ "XDIM_", "YDIM_", "ZDIM_", "'['", "']'", "'('", "')'", "','", "'p'",
+ "'P'", "':'", "'@'", "'*'", "'='", "'b'", "'s'", "'u'", "'i'", "'l'",
+ "'r'", "'f'", "'d'", "'.'", "$accept", "command", "@1", "@2", "filename",
+ "ext", "extb", "sect", "sectb", "physical", "rangex", "rangey",
+ "rangexy", "rangez", "block", "bin", "binb", "binword", "binkey", "arrs",
+ "arrsb", "arr", "endian", "array", "atype", "adims", "askip", "aendian",
+ "hpxs", "hpxsb", "hpx", "hpxSystem", "hpxOrder", "hpxLayout", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const yytype_uint16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
+ 285, 286, 287, 288, 289, 290, 91, 93, 40, 41,
+ 44, 112, 80, 58, 64, 42, 61, 98, 115, 117,
+ 105, 108, 114, 102, 100, 46
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 56, 57, 57, 57, 57, 57, 57, 57, 57,
+ 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
+ 57, 57, 57, 57, 58, 57, 59, 57, 60, 60,
+ 61, 61, 62, 62, 63, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 65, 65, 65, 66, 66, 66,
+ 67, 67, 67, 68, 69, 69, 69, 70, 71, 72,
+ 72, 73, 73, 73, 73, 74, 74, 74, 74, 74,
+ 74, 75, 76, 76, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 78, 78, 78, 78, 79, 80,
+ 80, 80, 80, 80, 80, 80, 80, 81, 81, 81,
+ 82, 82, 83, 83, 83, 84, 85, 85, 86, 86,
+ 86, 86, 86, 87, 87, 87, 87, 88, 88, 89,
+ 89, 89
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 1, 2, 3, 2, 5, 3, 4, 4,
+ 2, 3, 3, 5, 3, 4, 4, 2, 3, 3,
+ 5, 2, 3, 3, 0, 8, 0, 3, 0, 1,
+ 3, 3, 2, 2, 4, 3, 5, 5, 7, 3,
+ 1, 3, 3, 5, 0, 1, 1, 3, 3, 1,
+ 3, 3, 1, 5, 3, 3, 1, 1, 3, 3,
+ 2, 1, 1, 1, 1, 5, 3, 7, 5, 3,
+ 1, 3, 3, 1, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 1, 1, 1, 1, 1, 4, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 3, 5,
+ 0, 2, 0, 1, 1, 3, 3, 1, 3, 3,
+ 3, 3, 3, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const yytype_uint8 yydefact[] =
+{
+ 0, 26, 29, 0, 2, 0, 1, 0, 3, 5,
+ 10, 21, 17, 27, 0, 0, 0, 24, 84, 85,
+ 61, 62, 63, 0, 0, 0, 0, 0, 64, 0,
+ 86, 87, 0, 0, 0, 0, 0, 0, 0, 49,
+ 0, 44, 0, 40, 0, 0, 0, 73, 83, 0,
+ 107, 0, 4, 7, 14, 0, 12, 23, 19, 0,
+ 11, 22, 18, 31, 33, 0, 0, 30, 32, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 45,
+ 46, 0, 0, 0, 58, 70, 0, 0, 60, 71,
+ 0, 105, 0, 0, 9, 16, 8, 15, 47, 48,
+ 81, 0, 79, 111, 77, 78, 82, 119, 120, 121,
+ 110, 118, 117, 109, 112, 80, 115, 113, 114, 116,
+ 108, 74, 75, 76, 6, 13, 20, 34, 57, 52,
+ 35, 39, 57, 56, 42, 41, 0, 0, 59, 72,
+ 106, 0, 89, 90, 91, 92, 93, 94, 95, 96,
+ 0, 0, 0, 0, 0, 0, 0, 0, 66, 69,
+ 0, 53, 0, 97, 100, 50, 51, 37, 36, 54,
+ 55, 0, 43, 0, 0, 25, 0, 0, 102, 0,
+ 68, 65, 0, 98, 101, 104, 103, 88, 38, 0,
+ 0, 67, 99
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int16 yydefgoto[] =
+{
+ -1, 3, 70, 5, 4, 8, 40, 9, 41, 91,
+ 42, 140, 43, 144, 141, 10, 44, 45, 98, 11,
+ 46, 47, 48, 160, 161, 174, 188, 197, 12, 49,
+ 50, 130, 123, 120
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -114
+static const yytype_int16 yypact[] =
+{
+ 60, -114, -114, 10, -9, 44, -114, 8, 27, 29,
+ 45, 45, 45, -114, 105, 49, 37, -114, -114, -114,
+ -114, -114, -114, 55, 68, 82, 92, 94, -114, 119,
+ -114, -114, 123, 132, 136, 137, 147, 148, 149, -114,
+ 59, 75, 52, 156, 160, 36, 110, -114, -114, 139,
+ -114, 46, 162, 45, 45, 98, -114, -114, -114, -1,
+ -114, -114, -114, -114, -114, 196, 197, -114, -114, 77,
+ 163, 199, 200, 201, 202, 77, 72, 102, 203, 204,
+ 152, 205, 206, 207, 79, 67, 174, 175, 176, -114,
+ -114, 177, 30, 33, -114, 178, 211, 20, -114, -114,
+ 129, -114, 67, 146, -114, -114, -114, -114, -114, 172,
+ -114, 138, -114, -114, -114, -114, -114, -114, -114, -114,
+ -114, -114, -114, -114, -114, -114, -114, -114, -114, -114,
+ -114, -114, -114, -114, -114, -114, -114, -114, 117, -114,
+ 179, -114, 131, -114, -114, 180, 213, 114, -114, -114,
+ -114, 218, -114, -114, -114, -114, -114, -114, -114, -114,
+ 183, 220, 221, 222, 33, 223, 224, 42, 188, -114,
+ 225, -114, 193, 181, 189, -114, -114, -114, 191, -114,
+ -114, 131, -114, 229, 141, -114, 231, 232, 88, 42,
+ -114, -114, 233, 184, -114, -114, -114, -114, -114, 208,
+ 235, -114, -114
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int16 yypgoto[] =
+{
+ -114, -114, -114, -114, -114, -114, -114, -7, 209, -114,
+ -114, -114, -114, -113, -93, 0, 210, -114, 143, 234,
+ -114, 142, -43, -114, -114, -114, -114, -114, -2, -114,
+ 144, -114, -114, -114
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -29
+static const yytype_int16 yytable[] =
+{
+ 145, 52, 84, 60, 61, 62, 54, 58, 53, 56,
+ 6, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 95, 27, 110, 7, 28, 29,
+ 30, 31, 116, 138, 32, 33, 142, 34, 88, 35,
+ 95, 36, 37, 38, 39, 181, 106, 107, 13, 84,
+ 105, 177, 104, 39, 182, 20, 21, 22, 96, 24,
+ -28, 1, 84, 51, 2, 55, 28, 29, 20, 21,
+ 22, 178, 32, 33, 96, 139, 198, 35, 143, 28,
+ 24, 59, 97, 69, 18, 19, 67, 143, 29, 68,
+ 117, 39, 92, 32, 33, 85, -28, 118, 35, 30,
+ 31, 71, 119, 16, 39, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 72, 27, 89, 90, 28, 29,
+ 30, 31, 65, 66, 32, 33, 121, 34, 73, 35,
+ 122, 36, 37, 38, 16, 195, 18, 19, 74, 196,
+ 75, 23, 63, 25, 26, 64, 27, 99, 65, 66,
+ 100, 30, 31, 169, 170, 20, 21, 22, 34, 24,
+ 162, 163, 36, 37, 38, 76, 28, 29, 126, 77,
+ 127, 128, 32, 33, 165, 166, 101, 35, 78, 102,
+ 191, 192, 79, 80, 129, 152, 153, 154, 155, 156,
+ 157, 158, 159, 81, 82, 83, 93, 94, 103, 108,
+ 109, 111, 112, 113, 114, 115, 124, 125, 131, 132,
+ 133, 134, 135, 136, 137, 147, 151, 168, 146, 164,
+ 167, 171, 172, 173, 175, 176, 179, 180, 183, 184,
+ 185, 189, 187, 190, 193, 194, 186, 199, 202, 200,
+ 148, 0, 149, 57, 0, 0, 150, 201, 0, 86,
+ 87
+};
+
+static const yytype_int16 yycheck[] =
+{
+ 93, 8, 3, 10, 11, 12, 8, 9, 8, 9,
+ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 4, 17, 69, 36, 20, 21,
+ 22, 23, 75, 3, 26, 27, 3, 29, 40, 31,
+ 4, 33, 34, 35, 45, 3, 53, 54, 4, 3,
+ 52, 164, 52, 45, 167, 9, 10, 11, 38, 13,
+ 0, 1, 3, 36, 4, 36, 20, 21, 9, 10,
+ 11, 164, 26, 27, 38, 45, 189, 31, 45, 20,
+ 13, 36, 46, 46, 7, 8, 37, 45, 21, 40,
+ 18, 45, 40, 26, 27, 36, 36, 25, 31, 22,
+ 23, 46, 30, 5, 45, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 46, 17, 41, 42, 20, 21,
+ 22, 23, 43, 44, 26, 27, 24, 29, 46, 31,
+ 28, 33, 34, 35, 5, 47, 7, 8, 46, 51,
+ 46, 12, 37, 14, 15, 40, 17, 37, 43, 44,
+ 40, 22, 23, 39, 40, 9, 10, 11, 29, 13,
+ 43, 44, 33, 34, 35, 46, 20, 21, 16, 46,
+ 18, 19, 26, 27, 43, 44, 37, 31, 46, 40,
+ 39, 40, 46, 46, 32, 47, 48, 49, 50, 51,
+ 52, 53, 54, 46, 46, 46, 40, 37, 36, 3,
+ 3, 38, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 37, 37, 37, 37, 4, 44, 4, 40, 40,
+ 40, 3, 39, 3, 3, 3, 3, 3, 40, 4,
+ 37, 40, 43, 4, 3, 3, 55, 4, 3, 55,
+ 97, -1, 100, 9, -1, -1, 102, 39, -1, 40,
+ 40
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 1, 4, 57, 60, 59, 0, 36, 61, 63,
+ 71, 75, 84, 4, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 17, 20, 21,
+ 22, 23, 26, 27, 29, 31, 33, 34, 35, 45,
+ 62, 64, 66, 68, 72, 73, 76, 77, 78, 85,
+ 86, 36, 63, 71, 84, 36, 71, 75, 84, 36,
+ 63, 63, 63, 37, 40, 43, 44, 37, 40, 46,
+ 58, 46, 46, 46, 46, 46, 46, 46, 46, 46,
+ 46, 46, 46, 46, 3, 36, 64, 72, 84, 41,
+ 42, 65, 40, 40, 37, 4, 38, 46, 74, 37,
+ 40, 37, 40, 36, 71, 84, 63, 63, 3, 3,
+ 78, 38, 3, 3, 3, 3, 78, 18, 25, 30,
+ 89, 24, 28, 88, 3, 3, 16, 18, 19, 32,
+ 87, 3, 3, 3, 37, 37, 37, 37, 3, 45,
+ 67, 70, 3, 45, 69, 70, 40, 4, 74, 77,
+ 86, 44, 47, 48, 49, 50, 51, 52, 53, 54,
+ 79, 80, 43, 44, 40, 43, 44, 40, 4, 39,
+ 40, 3, 39, 3, 81, 3, 3, 69, 70, 3,
+ 3, 3, 69, 40, 4, 37, 55, 43, 82, 40,
+ 4, 39, 40, 3, 3, 47, 51, 83, 69, 4,
+ 55, 39, 3
+};
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK (1); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (ff, ll, YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (YYID (0))
+
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+# define YY_LOCATION_PRINT(File, Loc) \
+ fprintf (File, "%d.%d-%d.%d", \
+ (Loc).first_line, (Loc).first_column, \
+ (Loc).last_line, (Loc).last_column)
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval, ll)
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value, ff, ll); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, FitsFile* ff, ffFlexLexer* ll)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep, ff, ll)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+ FitsFile* ff;
+ ffFlexLexer* ll;
+#endif
+{
+ if (!yyvaluep)
+ return;
+ YYUSE (ff);
+ YYUSE (ll);
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, FitsFile* ff, ffFlexLexer* ll)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep, ff, ll)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+ FitsFile* ff;
+ ffFlexLexer* ll;
+#endif
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep, ff, ll);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ yytype_int16 *bottom;
+ yytype_int16 *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule, FitsFile* ff, ffFlexLexer* ll)
+#else
+static void
+yy_reduce_print (yyvsp, yyrule, ff, ll)
+ YYSTYPE *yyvsp;
+ int yyrule;
+ FitsFile* ff;
+ ffFlexLexer* ll;
+#endif
+{
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ fprintf (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ , ff, ll);
+ fprintf (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyvsp, Rule, ff, ll); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+ const char *yystr;
+#endif
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+#endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into YYRESULT an error message about the unexpected token
+ YYCHAR while in state YYSTATE. Return the number of bytes copied,
+ including the terminating null byte. If YYRESULT is null, do not
+ copy anything; just return the number of bytes that would be
+ copied. As a special case, return 0 if an ordinary "syntax error"
+ message will do. Return YYSIZE_MAXIMUM if overflow occurs during
+ size calculation. */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+ int yyn = yypact[yystate];
+
+ if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+ return 0;
+ else
+ {
+ int yytype = YYTRANSLATE (yychar);
+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ int yysize_overflow = 0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyx;
+
+# if 0
+ /* This is so xgettext sees the translatable formats that are
+ constructed on the fly. */
+ YY_("syntax error, unexpected %s");
+ YY_("syntax error, unexpected %s, expecting %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+ char *yyfmt;
+ char const *yyf;
+ static char const yyunexpected[] = "syntax error, unexpected %s";
+ static char const yyexpecting[] = ", expecting %s";
+ static char const yyor[] = " or %s";
+ char yyformat[sizeof yyunexpected
+ + sizeof yyexpecting - 1
+ + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+ * (sizeof yyor - 1))];
+ char const *yyprefix = yyexpecting;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 1;
+
+ yyarg[0] = yytname[yytype];
+ yyfmt = yystpcpy (yyformat, yyunexpected);
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ yyformat[sizeof yyunexpected - 1] = '\0';
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+ yyfmt = yystpcpy (yyfmt, yyprefix);
+ yyprefix = yyor;
+ }
+
+ yyf = YY_(yyformat);
+ yysize1 = yysize + yystrlen (yyf);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+
+ if (yysize_overflow)
+ return YYSIZE_MAXIMUM;
+
+ if (yyresult)
+ {
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ char *yyp = yyresult;
+ int yyi = 0;
+ while ((*yyp = *yyf) != '\0')
+ {
+ if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyf += 2;
+ }
+ else
+ {
+ yyp++;
+ yyf++;
+ }
+ }
+ }
+ return yysize;
+ }
+}
+#endif /* YYERROR_VERBOSE */
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, FitsFile* ff, ffFlexLexer* ll)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep, ff, ll)
+ const char *yymsg;
+ int yytype;
+ YYSTYPE *yyvaluep;
+ FitsFile* ff;
+ ffFlexLexer* ll;
+#endif
+{
+ YYUSE (yyvaluep);
+ YYUSE (ff);
+ YYUSE (ll);
+
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (FitsFile* ff, ffFlexLexer* ll);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (FitsFile* ff, ffFlexLexer* ll)
+#else
+int
+yyparse (ff, ll)
+ FitsFile* ff;
+ ffFlexLexer* ll;
+#endif
+#endif
+{
+ /* The look-ahead symbol. */
+int yychar;
+
+/* The semantic value of the look-ahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Look-ahead token as an internal (translated) token number. */
+ int yytoken = 0;
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss = yyssa;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ look-ahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to look-ahead token. */
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a look-ahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the look-ahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 24:
+#line 106 "../fitsy/parser.Y"
+ {GOTOARR(0);}
+ break;
+
+ case 26:
+#line 108 "../fitsy/parser.Y"
+ {GOTOFILT(0);}
+ break;
+
+ case 27:
+#line 109 "../fitsy/parser.Y"
+ {ff->setValid(1);ff->setpFilter(ff_filter);;}
+ break;
+
+ case 29:
+#line 113 "../fitsy/parser.Y"
+ {ff->setpName((yyvsp[(1) - (1)].str));;}
+ break;
+
+ case 30:
+#line 123 "../fitsy/parser.Y"
+ {ff->setpExt((yyvsp[(2) - (3)].str));;}
+ break;
+
+ case 31:
+#line 124 "../fitsy/parser.Y"
+ {ff->setpIndex((yyvsp[(2) - (3)].integer));;}
+ break;
+
+ case 32:
+#line 127 "../fitsy/parser.Y"
+ {ff->setpExt((yyvsp[(1) - (2)].str));;}
+ break;
+
+ case 33:
+#line 128 "../fitsy/parser.Y"
+ {ff->setpIndex((yyvsp[(1) - (2)].integer));;}
+ break;
+
+ case 44:
+#line 144 "../fitsy/parser.Y"
+ {ff->setpcoord(0);;}
+ break;
+
+ case 45:
+#line 145 "../fitsy/parser.Y"
+ {ff->setpcoord(1);;}
+ break;
+
+ case 46:
+#line 146 "../fitsy/parser.Y"
+ {ff->setpcoord(1);;}
+ break;
+
+ case 47:
+#line 150 "../fitsy/parser.Y"
+ {
+ // this is not a mistake
+ // need to fool parser into processing "xy0:xy1,block"
+ ff->setpxmin((yyvsp[(1) - (3)].integer)); ff->setpxmax((yyvsp[(3) - (3)].integer)); ff->setpxvalid(1);
+ ff->setpymin((yyvsp[(1) - (3)].integer)); ff->setpymax((yyvsp[(3) - (3)].integer)); ff->setpyvalid(1);
+ ;}
+ break;
+
+ case 48:
+#line 157 "../fitsy/parser.Y"
+ {ff->setpxmin((yyvsp[(3) - (3)].integer)-(yyvsp[(1) - (3)].integer)/2); ff->setpxmax((yyvsp[(3) - (3)].integer)+(yyvsp[(1) - (3)].integer)/2); ff->setpxvalid(1);;}
+ break;
+
+ case 49:
+#line 159 "../fitsy/parser.Y"
+ {
+ // this is not a mistake
+ // need to fool parser into processing "*,block"
+ ff->setpxvalid(0); ff->setpyvalid(0);
+ ;}
+ break;
+
+ case 50:
+#line 167 "../fitsy/parser.Y"
+ {ff->setpymin((yyvsp[(1) - (3)].integer)); ff->setpymax((yyvsp[(3) - (3)].integer)); ff->setpyvalid(1);;}
+ break;
+
+ case 51:
+#line 169 "../fitsy/parser.Y"
+ {ff->setpymin((yyvsp[(3) - (3)].integer)-(yyvsp[(1) - (3)].integer)/2); ff->setpymax((yyvsp[(3) - (3)].integer)+(yyvsp[(1) - (3)].integer)/2); ff->setpyvalid(1);;}
+ break;
+
+ case 52:
+#line 170 "../fitsy/parser.Y"
+ {ff->setpyvalid(0);;}
+ break;
+
+ case 53:
+#line 174 "../fitsy/parser.Y"
+ {
+ ff->setpxmin((yyvsp[(3) - (5)].integer)-(yyvsp[(1) - (5)].integer)/2); ff->setpxmax((yyvsp[(3) - (5)].integer)+(yyvsp[(1) - (5)].integer)/2); ff->setpxvalid(1);
+ ff->setpymin((yyvsp[(5) - (5)].integer)-(yyvsp[(1) - (5)].integer)/2); ff->setpymax((yyvsp[(5) - (5)].integer)+(yyvsp[(1) - (5)].integer)/2); ff->setpyvalid(1);
+ ;}
+ break;
+
+ case 54:
+#line 181 "../fitsy/parser.Y"
+ {ff->setpzmin((yyvsp[(1) - (3)].integer)); ff->setpzmax((yyvsp[(3) - (3)].integer)); ff->setpzvalid(1);;}
+ break;
+
+ case 55:
+#line 183 "../fitsy/parser.Y"
+ {ff->setpzmin((yyvsp[(3) - (3)].integer)-(yyvsp[(1) - (3)].integer)/2); ff->setpzmax((yyvsp[(3) - (3)].integer)+(yyvsp[(1) - (3)].integer)/2); ff->setpzvalid(1);;}
+ break;
+
+ case 56:
+#line 184 "../fitsy/parser.Y"
+ {ff->setpzvalid(0);;}
+ break;
+
+ case 57:
+#line 187 "../fitsy/parser.Y"
+ {ff->setpblock((yyvsp[(1) - (1)].integer)); ff->setpbvalid(1);;}
+ break;
+
+ case 65:
+#line 202 "../fitsy/parser.Y"
+ {ff->setpBinXY((yyvsp[(2) - (5)].str),(yyvsp[(4) - (5)].str));;}
+ break;
+
+ case 66:
+#line 203 "../fitsy/parser.Y"
+ {ff->setpBinXY((yyvsp[(1) - (3)].str),(yyvsp[(3) - (3)].str));;}
+ break;
+
+ case 67:
+#line 204 "../fitsy/parser.Y"
+ {ff->setpBinXYZ((yyvsp[(2) - (7)].str),(yyvsp[(4) - (7)].str),(yyvsp[(6) - (7)].str));;}
+ break;
+
+ case 68:
+#line 205 "../fitsy/parser.Y"
+ {ff->setpBinXYZ((yyvsp[(1) - (5)].str),(yyvsp[(3) - (5)].str),(yyvsp[(5) - (5)].str));;}
+ break;
+
+ case 69:
+#line 206 "../fitsy/parser.Y"
+ {ff->setpBinZ((yyvsp[(2) - (3)].str));;}
+ break;
+
+ case 70:
+#line 207 "../fitsy/parser.Y"
+ {ff->setpBinZ((yyvsp[(1) - (1)].str));;}
+ break;
+
+ case 74:
+#line 217 "../fitsy/parser.Y"
+ {ff->setpWidth((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 75:
+#line 218 "../fitsy/parser.Y"
+ {ff->setpHeight((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 76:
+#line 219 "../fitsy/parser.Y"
+ {ff->setpDepth((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 77:
+#line 220 "../fitsy/parser.Y"
+ {ff->setpWidth((yyvsp[(3) - (3)].integer));ff->setpHeight((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 78:
+#line 221 "../fitsy/parser.Y"
+ {ff->setpWidth((yyvsp[(3) - (3)].integer));ff->setpHeight((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 79:
+#line 222 "../fitsy/parser.Y"
+ {ff->setpBitpix((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 80:
+#line 223 "../fitsy/parser.Y"
+ {ff->setpSkip((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 81:
+#line 224 "../fitsy/parser.Y"
+ {ff->setpArch((FitsFile::ArchType)(yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 82:
+#line 225 "../fitsy/parser.Y"
+ {ff->setpArch((FitsFile::ArchType)(yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 83:
+#line 226 "../fitsy/parser.Y"
+ {ff->setpArch((FitsFile::ArchType)(yyvsp[(1) - (1)].integer));;}
+ break;
+
+ case 84:
+#line 229 "../fitsy/parser.Y"
+ {(yyval.integer) = FitsFile::BIG;;}
+ break;
+
+ case 85:
+#line 230 "../fitsy/parser.Y"
+ {(yyval.integer) = FitsFile::BIG;;}
+ break;
+
+ case 86:
+#line 231 "../fitsy/parser.Y"
+ {(yyval.integer) = FitsFile::LITTLE;;}
+ break;
+
+ case 87:
+#line 232 "../fitsy/parser.Y"
+ {(yyval.integer) = FitsFile::LITTLE;;}
+ break;
+
+ case 89:
+#line 238 "../fitsy/parser.Y"
+ {ff->setpBitpix(8);;}
+ break;
+
+ case 90:
+#line 239 "../fitsy/parser.Y"
+ {ff->setpBitpix(16);;}
+ break;
+
+ case 91:
+#line 240 "../fitsy/parser.Y"
+ {ff->setpBitpix(-16);;}
+ break;
+
+ case 92:
+#line 241 "../fitsy/parser.Y"
+ {ff->setpBitpix(32);;}
+ break;
+
+ case 93:
+#line 242 "../fitsy/parser.Y"
+ {ff->setpBitpix(64);;}
+ break;
+
+ case 94:
+#line 243 "../fitsy/parser.Y"
+ {ff->setpBitpix(-32);;}
+ break;
+
+ case 95:
+#line 244 "../fitsy/parser.Y"
+ {ff->setpBitpix(-32);;}
+ break;
+
+ case 96:
+#line 245 "../fitsy/parser.Y"
+ {ff->setpBitpix(-64);;}
+ break;
+
+ case 97:
+#line 248 "../fitsy/parser.Y"
+ {ff->setpWidth((yyvsp[(1) - (1)].integer));ff->setpHeight((yyvsp[(1) - (1)].integer));;}
+ break;
+
+ case 98:
+#line 249 "../fitsy/parser.Y"
+ {ff->setpWidth((yyvsp[(1) - (3)].integer));ff->setpHeight((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 99:
+#line 251 "../fitsy/parser.Y"
+ {ff->setpWidth((yyvsp[(1) - (5)].integer));ff->setpHeight((yyvsp[(3) - (5)].integer));ff->setpDepth((yyvsp[(5) - (5)].integer));;}
+ break;
+
+ case 101:
+#line 255 "../fitsy/parser.Y"
+ {ff->setpSkip((yyvsp[(2) - (2)].integer));;}
+ break;
+
+ case 103:
+#line 259 "../fitsy/parser.Y"
+ {ff->setpArch(FitsFile::LITTLE);;}
+ break;
+
+ case 104:
+#line 260 "../fitsy/parser.Y"
+ {ff->setpArch(FitsFile::BIG);;}
+ break;
+
+ case 111:
+#line 273 "../fitsy/parser.Y"
+ {ff->setpHPXColumn((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 112:
+#line 274 "../fitsy/parser.Y"
+ {ff->setpHPXQuad((yyvsp[(3) - (3)].integer));;}
+ break;
+
+ case 113:
+#line 277 "../fitsy/parser.Y"
+ {ff->setpHPXSystem(FitsHPX::EQU);;}
+ break;
+
+ case 114:
+#line 278 "../fitsy/parser.Y"
+ {ff->setpHPXSystem(FitsHPX::GAL);;}
+ break;
+
+ case 115:
+#line 279 "../fitsy/parser.Y"
+ {ff->setpHPXSystem(FitsHPX::ECL);;}
+ break;
+
+ case 116:
+#line 280 "../fitsy/parser.Y"
+ {ff->setpHPXSystem(FitsHPX::UNKNOWN);;}
+ break;
+
+ case 117:
+#line 283 "../fitsy/parser.Y"
+ {ff->setpHPXOrder(FitsHPX::RING);;}
+ break;
+
+ case 118:
+#line 284 "../fitsy/parser.Y"
+ {ff->setpHPXOrder(FitsHPX::NESTED);;}
+ break;
+
+ case 119:
+#line 287 "../fitsy/parser.Y"
+ {ff->setpHPXLayout(FitsHPX::EQUATOR);;}
+ break;
+
+ case 120:
+#line 288 "../fitsy/parser.Y"
+ {ff->setpHPXLayout(FitsHPX::NORTH);;}
+ break;
+
+ case 121:
+#line 289 "../fitsy/parser.Y"
+ {ff->setpHPXLayout(FitsHPX::SOUTH);;}
+ break;
+
+
+/* Line 1267 of yacc.c. */
+#line 1979 "../fitsy/parser.C"
+ default: break;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (ff, ll, YY_("syntax error"));
+#else
+ {
+ YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+ if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+ {
+ YYSIZE_T yyalloc = 2 * yysize;
+ if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+ yyalloc = YYSTACK_ALLOC_MAXIMUM;
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+ if (yymsg)
+ yymsg_alloc = yyalloc;
+ else
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ }
+ }
+
+ if (0 < yysize && yysize <= yymsg_alloc)
+ {
+ (void) yysyntax_error (yymsg, yystate, yychar);
+ yyerror (ff, ll, yymsg);
+ }
+ else
+ {
+ yyerror (ff, ll, YY_("syntax error"));
+ if (yysize != 0)
+ goto yyexhaustedlab;
+ }
+ }
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse look-ahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval, ff, ll);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse look-ahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp, ff, ll);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ *++yyvsp = yylval;
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (ff, ll, YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEOF && yychar != YYEMPTY)
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval, ff, ll);
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp, ff, ll);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ /* Make sure YYID is used. */
+ return YYID (yyresult);
+}
+
+
+#line 292 "../fitsy/parser.Y"
+
+
diff --git a/fitsy++/parser.H b/fitsy++/parser.H
new file mode 100644
index 0000000..17bdbb8
--- /dev/null
+++ b/fitsy++/parser.H
@@ -0,0 +1,133 @@
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton interface for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ INT = 258,
+ STRING = 259,
+ ARCH_ = 260,
+ ARRAY_ = 261,
+ BIG_ = 262,
+ BIGENDIAN_ = 263,
+ BIN_ = 264,
+ BINKEY_ = 265,
+ BINCOL_ = 266,
+ BITPIX_ = 267,
+ COL_ = 268,
+ DIM_ = 269,
+ DIMS_ = 270,
+ ECLIPTIC_ = 271,
+ ENDIAN_ = 272,
+ EQUATORIAL_ = 273,
+ GALACTIC_ = 274,
+ KEY_ = 275,
+ LAYOUT_ = 276,
+ LITTLE_ = 277,
+ LITTLEENDIAN_ = 278,
+ NESTED_ = 279,
+ NORTH_ = 280,
+ ORDER_ = 281,
+ QUAD_ = 282,
+ RING_ = 283,
+ SKIP_ = 284,
+ SOUTH_ = 285,
+ SYSTEM_ = 286,
+ UNKNOWN_ = 287,
+ XDIM_ = 288,
+ YDIM_ = 289,
+ ZDIM_ = 290
+ };
+#endif
+/* Tokens. */
+#define INT 258
+#define STRING 259
+#define ARCH_ 260
+#define ARRAY_ 261
+#define BIG_ 262
+#define BIGENDIAN_ 263
+#define BIN_ 264
+#define BINKEY_ 265
+#define BINCOL_ 266
+#define BITPIX_ 267
+#define COL_ 268
+#define DIM_ 269
+#define DIMS_ 270
+#define ECLIPTIC_ 271
+#define ENDIAN_ 272
+#define EQUATORIAL_ 273
+#define GALACTIC_ 274
+#define KEY_ 275
+#define LAYOUT_ 276
+#define LITTLE_ 277
+#define LITTLEENDIAN_ 278
+#define NESTED_ 279
+#define NORTH_ 280
+#define ORDER_ 281
+#define QUAD_ 282
+#define RING_ 283
+#define SKIP_ 284
+#define SOUTH_ 285
+#define SYSTEM_ 286
+#define UNKNOWN_ 287
+#define XDIM_ 288
+#define YDIM_ 289
+#define ZDIM_ 290
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+#line 32 "../fitsy/parser.Y"
+{
+ float real;
+ int integer;
+ char str[256];
+ void* ptr;
+}
+/* Line 1529 of yacc.c. */
+#line 126 "../fitsy/parser.H"
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
diff --git a/fitsy++/parser.Y b/fitsy++/parser.Y
new file mode 100644
index 0000000..b588ee5
--- /dev/null
+++ b/fitsy++/parser.Y
@@ -0,0 +1,292 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+%pure-parser
+%parse-param {FitsFile* ff}
+%lex-param {ffFlexLexer* ll}
+%parse-param {ffFlexLexer* ll}
+
+%{
+#define YYDEBUG 1
+
+#define GOTOFILT(x) {yyclearin; ffFilter(x);}
+#define GOTOARR(x) {yyclearin; ffArray(x);}
+
+#include "file.h"
+#include "hpx.h"
+
+#undef yyFlexLexer
+#define yyFlexLexer ffFlexLexer
+#include <FlexLexer.h>
+
+extern int fflex(void*, ffFlexLexer*);
+extern void fferror(FitsFile*, ffFlexLexer*, const char*);
+
+char ff_filter[512];
+extern void ffFilter(int);
+extern void ffArray(int);
+
+%}
+
+%union {
+ float real;
+ int integer;
+ char str[256];
+ void* ptr;
+}
+
+%type <integer> endian
+
+%token <integer> INT
+%token <str> STRING
+
+%token ARCH_
+%token ARRAY_
+%token BIG_
+%token BIGENDIAN_
+%token BIN_
+%token BINKEY_
+%token BINCOL_
+%token BITPIX_
+%token COL_
+%token DIM_
+%token DIMS_
+%token ECLIPTIC_
+%token ENDIAN_
+%token EQUATORIAL_
+%token GALACTIC_
+%token KEY_
+%token LAYOUT_
+%token LITTLE_
+%token LITTLEENDIAN_
+%token NESTED_
+%token NORTH_
+%token ORDER_
+%token QUAD_
+%token RING_
+%token SKIP_
+%token SOUTH_
+%token SYSTEM_
+%token UNKNOWN_
+%token XDIM_
+%token YDIM_
+%token ZDIM_
+
+%%
+
+ //start: {yydebug=1;} command
+
+// assume any error is the start of a filter
+command : filename
+ | filename ext
+ | filename ext sect
+ | filename sect
+ | filename '[' extb sectb ']'
+
+ | filename ext bin
+ | filename ext bin sect
+ | filename ext sect bin
+ | filename bin
+ | filename bin sect
+ | filename sect bin
+ | filename '[' extb binb ']'
+
+ | filename ext hpxs
+ | filename ext hpxs sect
+ | filename ext sect hpxs
+ | filename hpxs
+ | filename hpxs sect
+ | filename sect hpxs
+ | filename '[' extb hpxs ']'
+
+ | filename arrs
+ | filename arrs sect
+ | filename sect arrs
+ | filename '[' ARRAY_ {GOTOARR(0)} '(' array ')' ']'
+
+ | error {GOTOFILT(0)} STRING
+ {ff->setValid(1);ff->setpFilter(ff_filter);}
+ ;
+
+filename : /* empty */
+ | STRING {ff->setpName($1);}
+ ;
+
+// we must do it this way so that a bare filter will be accepted
+//ext : '[' extb ']'
+// ;
+//extb : STRING {ff->setpExt($1);}
+// | INT {ff->setpIndex($1);}
+// ;
+
+ext : '[' STRING ']' {ff->setpExt($2);}
+ | '[' INT ']' {ff->setpIndex($2);}
+ ;
+
+extb : STRING ',' {ff->setpExt($1);}
+ | INT ',' {ff->setpIndex($1);}
+ ;
+
+sect : '[' sectb physical ']'
+
+sectb : rangex ',' rangey
+ | rangex ',' rangey ',' block
+ | rangex ',' rangey ',' rangez
+ | rangex ',' rangey ',' block ',' rangez
+ | rangex ',' block
+ | rangexy
+ | rangexy ',' block
+ | rangexy ',' rangez
+ | rangexy ',' block ',' rangez
+ ;
+
+physical : /* empty */ {ff->setpcoord(0);}
+ | 'p' {ff->setpcoord(1);}
+ | 'P' {ff->setpcoord(1);}
+ ;
+
+rangex : INT ':' INT
+ {
+ // this is not a mistake
+ // need to fool parser into processing "xy0:xy1,block"
+ ff->setpxmin($1); ff->setpxmax($3); ff->setpxvalid(1);
+ ff->setpymin($1); ff->setpymax($3); ff->setpyvalid(1);
+ }
+ | INT '@' INT
+ {ff->setpxmin($3-$1/2); ff->setpxmax($3+$1/2); ff->setpxvalid(1);}
+ | '*'
+ {
+ // this is not a mistake
+ // need to fool parser into processing "*,block"
+ ff->setpxvalid(0); ff->setpyvalid(0);
+ }
+ ;
+
+rangey : INT ':' INT
+ {ff->setpymin($1); ff->setpymax($3); ff->setpyvalid(1);}
+ | INT '@' INT
+ {ff->setpymin($3-$1/2); ff->setpymax($3+$1/2); ff->setpyvalid(1);}
+ | '*' {ff->setpyvalid(0);}
+ ;
+
+rangexy : INT '@' INT '@' INT
+ {
+ ff->setpxmin($3-$1/2); ff->setpxmax($3+$1/2); ff->setpxvalid(1);
+ ff->setpymin($5-$1/2); ff->setpymax($5+$1/2); ff->setpyvalid(1);
+ }
+ ;
+
+rangez : INT ':' INT
+ {ff->setpzmin($1); ff->setpzmax($3); ff->setpzvalid(1);}
+ | INT '@' INT
+ {ff->setpzmin($3-$1/2); ff->setpzmax($3+$1/2); ff->setpzvalid(1);}
+ | '*' {ff->setpzvalid(0);}
+ ;
+
+block : INT {ff->setpblock($1); ff->setpbvalid(1);}
+ ;
+
+bin : '[' binb ']'
+
+binb : binword '=' binkey
+ | binword binkey
+ ;
+
+binword : BIN_
+ | BINKEY_
+ | BINCOL_
+ | KEY_
+ ;
+
+binkey : '(' STRING ',' STRING ')' {ff->setpBinXY($2,$4);}
+ | STRING ',' STRING {ff->setpBinXY($1,$3);}
+ | '(' STRING ',' STRING ',' STRING ')' {ff->setpBinXYZ($2,$4,$6);}
+ | STRING ',' STRING ',' STRING {ff->setpBinXYZ($1,$3,$5);}
+ | '(' STRING ')' {ff->setpBinZ($2);}
+ | STRING {ff->setpBinZ($1);}
+ ;
+
+arrs : '[' arrsb ']'
+ ;
+
+arrsb : arrsb ',' arr
+ | arr
+ ;
+
+arr : XDIM_ '=' INT {ff->setpWidth($3);}
+ | YDIM_ '=' INT {ff->setpHeight($3);}
+ | ZDIM_ '=' INT {ff->setpDepth($3);}
+ | DIM_ '=' INT {ff->setpWidth($3);ff->setpHeight($3);}
+ | DIMS_ '=' INT {ff->setpWidth($3);ff->setpHeight($3);}
+ | BITPIX_ '=' INT {ff->setpBitpix($3);}
+ | SKIP_ '=' INT {ff->setpSkip($3);}
+ | ARCH_ '=' endian {ff->setpArch((FitsFile::ArchType)$3);}
+ | ENDIAN_ '=' endian {ff->setpArch((FitsFile::ArchType)$3);}
+ | endian {ff->setpArch((FitsFile::ArchType)$1);}
+ ;
+
+endian : BIG_ {$$ = FitsFile::BIG;}
+ | BIGENDIAN_ {$$ = FitsFile::BIG;}
+ | LITTLE_ {$$ = FitsFile::LITTLE;}
+ | LITTLEENDIAN_ {$$ = FitsFile::LITTLE;}
+ ;
+
+array : atype adims askip aendian
+ ;
+
+atype : 'b' {ff->setpBitpix(8);}
+ | 's' {ff->setpBitpix(16);}
+ | 'u' {ff->setpBitpix(-16);}
+ | 'i' {ff->setpBitpix(32);}
+ | 'l' {ff->setpBitpix(64);}
+ | 'r' {ff->setpBitpix(-32);}
+ | 'f' {ff->setpBitpix(-32);}
+ | 'd' {ff->setpBitpix(-64);}
+ ;
+
+adims : INT {ff->setpWidth($1);ff->setpHeight($1);}
+ | INT '.' INT {ff->setpWidth($1);ff->setpHeight($3);}
+ | INT '.' INT '.' INT
+ {ff->setpWidth($1);ff->setpHeight($3);ff->setpDepth($5);}
+ ;
+
+askip : /* empty */
+ | ':' INT {ff->setpSkip($2);}
+ ;
+
+aendian : /* empty */
+ | 'l' {ff->setpArch(FitsFile::LITTLE);}
+ | 'b' {ff->setpArch(FitsFile::BIG);}
+ ;
+
+hpxs : '[' hpxsb ']'
+ ;
+
+hpxsb : hpxsb ',' hpx
+ | hpx
+ ;
+
+hpx : SYSTEM_ '=' hpxSystem
+ | ORDER_ '=' hpxOrder
+ | LAYOUT_ '=' hpxLayout
+ | COL_ '=' INT {ff->setpHPXColumn($3);}
+ | QUAD_ '=' INT {ff->setpHPXQuad($3);}
+ ;
+
+hpxSystem : EQUATORIAL_ {ff->setpHPXSystem(FitsHPX::EQU);}
+ | GALACTIC_ {ff->setpHPXSystem(FitsHPX::GAL);}
+ | ECLIPTIC_ {ff->setpHPXSystem(FitsHPX::ECL);}
+ | UNKNOWN_ {ff->setpHPXSystem(FitsHPX::UNKNOWN);}
+ ;
+
+hpxOrder : RING_ {ff->setpHPXOrder(FitsHPX::RING);}
+ | NESTED_ {ff->setpHPXOrder(FitsHPX::NESTED);}
+ ;
+
+hpxLayout : EQUATORIAL_ {ff->setpHPXLayout(FitsHPX::EQUATOR);}
+ | NORTH_ {ff->setpHPXLayout(FitsHPX::NORTH);}
+ | SOUTH_ {ff->setpHPXLayout(FitsHPX::SOUTH);}
+ ;
+
+%%
diff --git a/fitsy++/photo.C b/fitsy++/photo.C
new file mode 100644
index 0000000..4c62939
--- /dev/null
+++ b/fitsy++/photo.C
@@ -0,0 +1,154 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include <tk.h>
+
+#include "photo.h"
+#include "util.h"
+
+FitsPhoto::FitsPhoto(Tcl_Interp* interp, const char* ph)
+{
+ // reset
+ valid_ = 0;
+
+ if (*ph == '\0') {
+ Tcl_AppendResult(interp, "bad image name ", NULL);
+ return;
+ }
+ Tk_PhotoHandle photo = Tk_FindPhoto(interp, ph);
+ if (!photo) {
+ Tcl_AppendResult(interp, "bad image handle ", NULL);
+ return;
+ }
+ Tk_PhotoImageBlock block;
+ if (!Tk_PhotoGetImage(photo,&block)) {
+ Tcl_AppendResult(interp, "bad image block ", NULL);
+ return;
+ }
+ int width =0;
+ int height =0;
+ Tk_PhotoGetSize(photo, &width, &height);
+
+ // new header
+ head_ = new FitsHead(width, height, 1, 8);
+ if (!head_->isValid())
+ return;
+
+ size_t size = (size_t)width*height;
+ unsigned char* dest = new unsigned char[size];
+ data_ = dest;
+
+ dataSize_ = size;
+ dataSkip_ = 0;
+
+ unsigned char* src = block.pixelPtr;
+ for (int jj=height-1; jj>=0; jj--)
+ for (int ii=0; ii<width; ii++) {
+ int pp = (jj*width+ii)*block.pixelSize;
+ unsigned char rr = src[pp+block.offset[0]];
+ unsigned char gg = src[pp+block.offset[1]];
+ unsigned char bb = src[pp+block.offset[2]];
+ //unsigned char vv = (rr+gg+bb)/3.;
+ //unsigned char vv = .2126*rr + .7152*gg + .0722*bb;
+ // must round
+ unsigned char vv = (.299*rr + .587*gg + .114*bb)+.5;
+ *dest++ = vv;
+ }
+
+ // made it this far, must be valid
+ byteswap_ = 0;
+ endian_ = lsb() ? LITTLE : BIG;
+ valid_ = 1;
+}
+
+FitsPhoto::~FitsPhoto()
+{
+ if (data_)
+ delete [] (unsigned char*)data_;
+}
+
+FitsPhotoCube::FitsPhotoCube(Tcl_Interp* interp, const char* ph)
+{
+ // reset
+ valid_ = 0;
+
+ if (*ph == '\0') {
+ Tcl_AppendResult(interp, "bad image name ", NULL);
+ return;
+ }
+ Tk_PhotoHandle photo = Tk_FindPhoto(interp, ph);
+ if (!photo) {
+ Tcl_AppendResult(interp, "bad image handle ", NULL);
+ return;
+ }
+ Tk_PhotoImageBlock block;
+ if (!Tk_PhotoGetImage(photo,&block)) {
+ Tcl_AppendResult(interp, "bad image block ", NULL);
+ return;
+ }
+ int width =0;
+ int height =0;
+ int depth =3;
+ Tk_PhotoGetSize(photo, &width, &height);
+
+ // new header
+ head_ = new FitsHead(width, height, depth, 8);
+ if (!head_->isValid())
+ return;
+
+ size_t size = (size_t)width*height*depth;
+ unsigned char* dest = new unsigned char[size];
+ data_ = dest;
+
+ dataSize_ = size;
+ dataSkip_ = 0;
+
+ unsigned char* src = block.pixelPtr;
+ for (int kk=0; kk<depth; kk++) {
+ for (int jj=height-1; jj>=0; jj--) {
+ for (int ii=0; ii<width; ii++) {
+ int pp = (jj*width+ii)*block.pixelSize;
+ *dest++ = src[pp+block.offset[kk]];
+ }
+ }
+ }
+
+ // made it this far, must be valid
+ byteswap_ = 0;
+ endian_ = lsb() ? LITTLE : BIG;
+ valid_ = 1;
+}
+
+FitsPhotoCube::~FitsPhotoCube()
+{
+ if (data_)
+ delete [] (unsigned char*)data_;
+}
+
+FitsPhotoCubeNext::FitsPhotoCubeNext(FitsFile* prev)
+{
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = head_->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ return;
+}
diff --git a/fitsy++/photo.h b/fitsy++/photo.h
new file mode 100644
index 0000000..232b390
--- /dev/null
+++ b/fitsy++/photo.h
@@ -0,0 +1,31 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsphoto_h__
+#define __fitsphoto_h__
+
+#include <tcl.h>
+
+#include "vector.h"
+#include "file.h"
+
+class FitsPhoto : public FitsFile {
+ public:
+ FitsPhoto(Tcl_Interp* interp, const char*);
+ ~FitsPhoto();
+};
+
+class FitsPhotoCube : public FitsFile {
+ public:
+ FitsPhotoCube(Tcl_Interp* interp, const char*);
+ ~FitsPhotoCube();
+};
+
+class FitsPhotoCubeNext : public FitsFile {
+ public:
+ FitsPhotoCubeNext(FitsFile*);
+};
+
+#endif
+
diff --git a/fitsy++/plio.C b/fitsy++/plio.C
new file mode 100644
index 0000000..519f719
--- /dev/null
+++ b/fitsy++/plio.C
@@ -0,0 +1,91 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "plio.h"
+#include "util.h"
+
+extern "C" {
+ int pl_l2pi(short *ll_src, int xs, int *px_dst, int npix);
+}
+
+template<class T> FitsPliom<T>::FitsPliom(FitsFile* fits)
+ : FitsCompressm<T>(fits)
+{
+ FitsCompressm<T>::uncompress(fits);
+}
+
+template <class T> int FitsPliom<T>::compressed(T* dest, char* sptr,
+ char* heap,
+ int kkstart, int kkstop,
+ int jjstart, int jjstop,
+ int iistart, int iistop)
+{
+ double zs = FitsCompressm<T>::bscale_;
+ if (FitsCompressm<T>::zscale_)
+ zs = FitsCompressm<T>::zscale_->value(sptr,0);
+
+ double zz = FitsCompressm<T>::bzero_;
+ if (FitsCompressm<T>::zzero_)
+ zz = FitsCompressm<T>::zzero_->value(sptr,0);
+
+ int blank = FitsCompressm<T>::blank_;
+ if (FitsCompressm<T>::zblank_)
+ blank = (int)FitsCompressm<T>::zblank_->value(sptr,0);
+
+ int icnt=0;
+ short* ibuf = (short*)((FitsBinColumnArray*)FitsCompressm<T>::compress_)->get(heap, sptr, &icnt);
+
+ // ibuf can be NULL
+ if (!ibuf || !icnt)
+ return 0;
+
+ // swap if needed
+ if (FitsCompressm<T>::byteswap_)
+ for (int ii=0; ii<icnt; ii++) {
+ const char* p = (const char*)(ibuf+ii);
+ union {
+ char c[2];
+ short s;
+ } u;
+
+ u.c[1] = *p++;
+ u.c[0] = *p;
+
+ *(ibuf+ii) = u.s;
+ }
+
+ int ocnt = FitsCompressm<T>::tilesize_;
+ int* obuf = new int[ocnt];
+
+ int cc = pl_l2pi(ibuf, 1, obuf, ocnt);
+ if (cc != ocnt) {
+ internalError("Fitsy++ plio error");
+ return 0;
+ }
+
+ int ll=0;
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++)
+ dest[kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii] = FitsCompressm<T>::getValue(obuf+ll,zs,zz,blank);
+
+ if (obuf)
+ delete [] obuf;
+
+ return 1;
+}
+
+template class FitsPliom<unsigned char>;
+template class FitsPliom<short>;
+template class FitsPliom<unsigned short>;
+template class FitsPliom<int>;
+template class FitsPliom<long long>;
+template class FitsPliom<float>;
+template class FitsPliom<double>;
+
diff --git a/fitsy++/plio.h b/fitsy++/plio.h
new file mode 100644
index 0000000..db1865d
--- /dev/null
+++ b/fitsy++/plio.h
@@ -0,0 +1,19 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsplio_h__
+#define __fitsplio_h__
+
+#include "compress.h"
+
+template<class T>
+class FitsPliom : public FitsCompressm<T> {
+ private:
+ int compressed(T*, char*, char*, int, int, int, int, int, int);
+
+ public:
+ FitsPliom(FitsFile*);
+};
+
+#endif
diff --git a/fitsy++/pliocomp.c b/fitsy++/pliocomp.c
new file mode 100644
index 0000000..7550ed6
--- /dev/null
+++ b/fitsy++/pliocomp.c
@@ -0,0 +1,331 @@
+/* stdlib is needed for the abs function */
+#include <stdlib.h>
+/*
+ The following prototype code was provided by Doug Tody, NRAO, for
+ performing conversion between pixel arrays and line lists. The
+ compression technique is used in IRAF.
+*/
+int pl_p2li (int *pxsrc, int xs, short *lldst, int npix);
+int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix);
+
+
+/*
+ * PL_P2L -- Convert a pixel array to a line list. The length of the list is
+ * returned as the function value.
+ *
+ * Translated from the SPP version using xc -f, f2c. 8Sep99 DCT.
+ */
+
+#ifndef min
+#define min(a,b) (((a)<(b))?(a):(b))
+#endif
+#ifndef max
+#define max(a,b) (((a)>(b))?(a):(b))
+#endif
+
+int pl_p2li (int *pxsrc, int xs, short *lldst, int npix)
+/* int *pxsrc; input pixel array */
+/* int xs; starting index in pxsrc (?) */
+/* short *lldst; encoded line list */
+/* int npix; number of pixels to convert */
+{
+ /* System generated locals */
+ int ret_val, i__1, i__2, i__3;
+
+ /* Local variables */
+ static int zero, v, x1, hi, ip, dv, xe, np, op, iz, nv, pv, nz;
+
+ /* Parameter adjustments */
+ --lldst;
+ --pxsrc;
+
+ /* Function Body */
+ if (! (npix <= 0)) {
+ goto L110;
+ }
+ ret_val = 0;
+ goto L100;
+L110:
+ lldst[3] = -100;
+ lldst[2] = 7;
+ lldst[1] = 0;
+ lldst[6] = 0;
+ lldst[7] = 0;
+ xe = xs + npix - 1;
+ op = 8;
+ zero = 0;
+/* Computing MAX */
+ i__1 = zero, i__2 = pxsrc[xs];
+ pv = max(i__1,i__2);
+ x1 = xs;
+ iz = xs;
+ hi = 1;
+ i__1 = xe;
+ for (ip = xs; ip <= i__1; ++ip) {
+ if (! (ip < xe)) {
+ goto L130;
+ }
+/* Computing MAX */
+ i__2 = zero, i__3 = pxsrc[ip + 1];
+ nv = max(i__2,i__3);
+ if (! (nv == pv)) {
+ goto L140;
+ }
+ goto L120;
+L140:
+ if (! (pv == 0)) {
+ goto L150;
+ }
+ pv = nv;
+ x1 = ip + 1;
+ goto L120;
+L150:
+ goto L131;
+L130:
+ if (! (pv == 0)) {
+ goto L160;
+ }
+ x1 = xe + 1;
+L160:
+L131:
+ np = ip - x1 + 1;
+ nz = x1 - iz;
+ if (! (pv > 0)) {
+ goto L170;
+ }
+ dv = pv - hi;
+ if (! (dv != 0)) {
+ goto L180;
+ }
+ hi = pv;
+ if (! (abs(dv) > 4095)) {
+ goto L190;
+ }
+ lldst[op] = (short) ((pv & 4095) + 4096);
+ ++op;
+ lldst[op] = (short) (pv / 4096);
+ ++op;
+ goto L191;
+L190:
+ if (! (dv < 0)) {
+ goto L200;
+ }
+ lldst[op] = (short) (-dv + 12288);
+ goto L201;
+L200:
+ lldst[op] = (short) (dv + 8192);
+L201:
+ ++op;
+ if (! (np == 1 && nz == 0)) {
+ goto L210;
+ }
+ v = lldst[op - 1];
+ lldst[op - 1] = (short) (v | 16384);
+ goto L91;
+L210:
+L191:
+L180:
+L170:
+ if (! (nz > 0)) {
+ goto L220;
+ }
+L230:
+ if (! (nz > 0)) {
+ goto L232;
+ }
+ lldst[op] = (short) min(4095,nz);
+ ++op;
+/* L231: */
+ nz += -4095;
+ goto L230;
+L232:
+ if (! (np == 1 && pv > 0)) {
+ goto L240;
+ }
+ lldst[op - 1] = (short) (lldst[op - 1] + 20481);
+ goto L91;
+L240:
+L220:
+L250:
+ if (! (np > 0)) {
+ goto L252;
+ }
+ lldst[op] = (short) (min(4095,np) + 16384);
+ ++op;
+/* L251: */
+ np += -4095;
+ goto L250;
+L252:
+L91:
+ x1 = ip + 1;
+ iz = x1;
+ pv = nv;
+L120:
+ ;
+ }
+/* L121: */
+ lldst[4] = (short) ((op - 1) % 32768);
+ lldst[5] = (short) ((op - 1) / 32768);
+ ret_val = op - 1;
+ goto L100;
+L100:
+ return ret_val;
+} /* plp2li_ */
+
+/*
+ * PL_L2PI -- Translate a PLIO line list into an integer pixel array.
+ * The number of pixels output (always npix) is returned as the function
+ * value.
+ *
+ * Translated from the SPP version using xc -f, f2c. 8Sep99 DCT.
+ */
+
+int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix)
+/* short *ll_src; encoded line list */
+/* int xs; starting index in ll_src */
+/* int *px_dst; output pixel array */
+/* int npix; number of pixels to convert */
+{
+ /* System generated locals */
+ int ret_val, i__1, i__2;
+
+ /* Local variables */
+ static int data, sw0001, otop, i__, lllen, i1, i2, x1, x2, ip, xe, np,
+ op, pv, opcode, llfirt;
+ static int skipwd;
+
+ /* Parameter adjustments */
+ --px_dst;
+ --ll_src;
+
+ /* Function Body */
+ if (! (ll_src[3] > 0)) {
+ goto L110;
+ }
+ lllen = ll_src[3];
+ llfirt = 4;
+ goto L111;
+L110:
+ lllen = (ll_src[5] << 15) + ll_src[4];
+ llfirt = ll_src[2] + 1;
+L111:
+ if (! (npix <= 0 || lllen <= 0)) {
+ goto L120;
+ }
+ ret_val = 0;
+ goto L100;
+L120:
+ xe = xs + npix - 1;
+ skipwd = 0;
+ op = 1;
+ x1 = 1;
+ pv = 1;
+ i__1 = lllen;
+ for (ip = llfirt; ip <= i__1; ++ip) {
+ if (! skipwd) {
+ goto L140;
+ }
+ skipwd = 0;
+ goto L130;
+L140:
+ opcode = ll_src[ip] / 4096;
+ data = ll_src[ip] & 4095;
+ sw0001 = opcode;
+ goto L150;
+L160:
+ x2 = x1 + data - 1;
+ i1 = max(x1,xs);
+ i2 = min(x2,xe);
+ np = i2 - i1 + 1;
+ if (! (np > 0)) {
+ goto L170;
+ }
+ otop = op + np - 1;
+ if (! (opcode == 4)) {
+ goto L180;
+ }
+ i__2 = otop;
+ for (i__ = op; i__ <= i__2; ++i__) {
+ px_dst[i__] = pv;
+/* L190: */
+ }
+/* L191: */
+ goto L181;
+L180:
+ i__2 = otop;
+ for (i__ = op; i__ <= i__2; ++i__) {
+ px_dst[i__] = 0;
+/* L200: */
+ }
+/* L201: */
+ if (! (opcode == 5 && i2 == x2)) {
+ goto L210;
+ }
+ px_dst[otop] = pv;
+L210:
+L181:
+ op = otop + 1;
+L170:
+ x1 = x2 + 1;
+ goto L151;
+L220:
+ pv = (ll_src[ip + 1] << 12) + data;
+ skipwd = 1;
+ goto L151;
+L230:
+ pv += data;
+ goto L151;
+L240:
+ pv -= data;
+ goto L151;
+L250:
+ pv += data;
+ goto L91;
+L260:
+ pv -= data;
+L91:
+ if (! (x1 >= xs && x1 <= xe)) {
+ goto L270;
+ }
+ px_dst[op] = pv;
+ ++op;
+L270:
+ ++x1;
+ goto L151;
+L150:
+ ++sw0001;
+ if (sw0001 < 1 || sw0001 > 8) {
+ goto L151;
+ }
+ switch ((int)sw0001) {
+ case 1: goto L160;
+ case 2: goto L220;
+ case 3: goto L230;
+ case 4: goto L240;
+ case 5: goto L160;
+ case 6: goto L160;
+ case 7: goto L250;
+ case 8: goto L260;
+ }
+L151:
+ if (! (x1 > xe)) {
+ goto L280;
+ }
+ goto L131;
+L280:
+L130:
+ ;
+ }
+L131:
+ i__1 = npix;
+ for (i__ = op; i__ <= i__1; ++i__) {
+ px_dst[i__] = 0;
+/* L290: */
+ }
+/* L291: */
+ ret_val = npix;
+ goto L100;
+L100:
+ return ret_val;
+} /* pll2pi_ */
+
diff --git a/fitsy++/rice.C b/fitsy++/rice.C
new file mode 100644
index 0000000..6ee13dc
--- /dev/null
+++ b/fitsy++/rice.C
@@ -0,0 +1,157 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "rice.h"
+#include "util.h"
+
+extern "C" {
+ int fits_rdecomp (unsigned char *c,
+ int clen,
+ unsigned int array[],
+ int nx,
+ int nblock);
+ int fits_rdecomp_short (unsigned char *c,
+ int clen,
+ unsigned short array[],
+ int nx,
+ int nblock);
+ int fits_rdecomp_byte (unsigned char *c,
+ int clen,
+ unsigned char array[],
+ int nx,
+ int nblock);
+}
+
+template<class T> FitsRicem<T>::FitsRicem(FitsFile* fits)
+ : FitsCompressm<T>(fits)
+{
+ // rice parameters
+ block_ = 32;
+ bytepix_ = 4;
+ noisebit_ = 4;
+ char name[] = "ZNAME ";
+ char val[] = "ZVAL ";
+ for (int ii=0; ii<9; ii++) {
+ name[5] = '0'+ii;
+ val[4] = '0'+ii;
+ if (fits->find(name)) {
+ char* str = fits->getString(name);
+ if (!strncmp(str,"BLOCK",4))
+ block_ = fits->getInteger(val,32);
+ else if (!strncmp(str,"BYTEPIX",4))
+ bytepix_ = fits->getInteger(val,4);
+ else if (!strncmp(str,"NOISEBIT",4))
+ noisebit_ = fits->getInteger(val,4);
+ }
+ }
+
+ FitsCompressm<T>::uncompress(fits);
+}
+
+template <class T> int FitsRicem<T>::compressed(T* dest, char* sptr,
+ char* heap,
+ int kkstart, int kkstop,
+ int jjstart, int jjstop,
+ int iistart, int iistop)
+{
+ double zs = FitsCompressm<T>::bscale_;
+ if (FitsCompressm<T>::zscale_)
+ zs = FitsCompressm<T>::zscale_->value(sptr,0);
+
+ double zz = FitsCompressm<T>::bzero_;
+ if (FitsCompressm<T>::zzero_)
+ zz = FitsCompressm<T>::zzero_->value(sptr,0);
+
+ int blank = FitsCompressm<T>::blank_;
+ if (FitsCompressm<T>::zblank_)
+ blank = (int)FitsCompressm<T>::zblank_->value(sptr,0);
+
+ int icnt=0;
+ unsigned char* ibuf = (unsigned char*)((FitsBinColumnArray*)FitsCompressm<T>::compress_)->get(heap, sptr, &icnt);
+
+ // ibuf can be NULL
+ if (!ibuf || !icnt)
+ return 0;
+
+ int ocnt = FitsCompressm<T>::tilesize_;
+ int ll=0;
+
+ switch (bytepix_) {
+ case 1:
+ {
+ char* obuf = new char[ocnt];
+ if (fits_rdecomp_byte(ibuf, icnt, (unsigned char*)obuf, ocnt, block_)) {
+ internalError("Fitsy++ rice bad inflate result");
+ return 0;
+ }
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // very carefull about type conversions
+ size_t id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ T val = FitsCompressm<T>::getValue(obuf+ll,zs,zz,blank);
+ dest[id] = val;
+ }
+
+ if (obuf)
+ delete [] obuf;
+ }
+ break;
+ case 2:
+ {
+ short* obuf = new short[ocnt];
+ if (fits_rdecomp_short(ibuf, icnt, (unsigned short*)obuf, ocnt, block_)) {
+ internalError("Fitsy++ rice bad inflate result");
+ return 0;
+ }
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // very carefull about type conversions
+ size_t id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ T val = FitsCompressm<T>::getValue(obuf+ll,zs,zz,blank);
+ dest[id] = val;
+ }
+
+ if (obuf)
+ delete [] obuf;
+ }
+ break;
+ case 4:
+ {
+ int* obuf = new int[ocnt];
+ if (fits_rdecomp(ibuf, icnt, (unsigned int*)obuf, ocnt, block_)) {
+ internalError("Fitsy++ rice bad inflate result");
+ return 0;
+ }
+ for (int kk=kkstart; kk<kkstop; kk++)
+ for (int jj=jjstart; jj<jjstop; jj++)
+ for (int ii=iistart; ii<iistop; ii++,ll++) {
+ // very carefull about type conversions
+ int id = kk*FitsCompressm<T>::width_*FitsCompressm<T>::height_ + jj*FitsCompressm<T>::width_ + ii;
+ T val = FitsCompressm<T>::getValue(obuf+ll,zs,zz,blank);
+ dest[id] = val;
+ }
+
+ if (obuf)
+ delete [] obuf;
+ }
+ break;
+ }
+
+ return 1;
+}
+
+template class FitsRicem<unsigned char>;
+template class FitsRicem<short>;
+template class FitsRicem<unsigned short>;
+template class FitsRicem<int>;
+template class FitsRicem<long long>;
+template class FitsRicem<float>;
+template class FitsRicem<double>;
diff --git a/fitsy++/rice.h b/fitsy++/rice.h
new file mode 100644
index 0000000..46868ac
--- /dev/null
+++ b/fitsy++/rice.h
@@ -0,0 +1,24 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsrice_h__
+#define __fitsrice_h__
+
+#include "compress.h"
+
+template<class T>
+class FitsRicem : public FitsCompressm<T> {
+ protected:
+ int block_;
+ int bytepix_;
+ int noisebit_;
+
+ private:
+ int compressed(T*, char*, char*, int, int, int, int, int, int);
+
+ public:
+ FitsRicem(FitsFile*);
+};
+
+#endif
diff --git a/fitsy++/ricecomp.c b/fitsy++/ricecomp.c
new file mode 100644
index 0000000..a464d9d
--- /dev/null
+++ b/fitsy++/ricecomp.c
@@ -0,0 +1,1386 @@
+/*
+ The following code was written by Richard White at STScI and made
+ available for use in CFITSIO in July 1999. These routines were
+ originally contained in 2 source files: rcomp.c and rdecomp.c,
+ and the 'include' file now called ricecomp.h was originally called buffer.h.
+*/
+
+/*----------------------------------------------------------*/
+/* */
+/* START OF SOURCE FILE ORIGINALLY CALLED rcomp.c */
+/* */
+/*----------------------------------------------------------*/
+/* @(#) rcomp.c 1.5 99/03/01 12:40:27 */
+/* rcomp.c Compress image line using
+ * (1) Difference of adjacent pixels
+ * (2) Rice algorithm coding
+ *
+ * Returns number of bytes written to code buffer or
+ * -1 on failure
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void ffpmsg(const char* str) {}
+
+typedef unsigned char Buffer_t;
+
+typedef struct {
+ int bitbuffer; /* bit buffer */
+ int bits_to_go; /* bits to go in buffer */
+ Buffer_t *start; /* start of buffer */
+ Buffer_t *current; /* current position in buffer */
+ Buffer_t *end; /* end of buffer */
+} Buffer;
+
+#define putcbuf(c,mf) ((*(mf->current)++ = c), 0)
+
+/*#include "fitsio2.h"*/
+#define FFLOCK
+#define FFUNLOCK
+
+static void start_outputing_bits(Buffer *buffer);
+static int done_outputing_bits(Buffer *buffer);
+static int output_nbits(Buffer *buffer, int bits, int n);
+
+/* this routine used to be called 'rcomp' (WDP) */
+/*---------------------------------------------------------------------------*/
+
+int fits_rcomp(int a[], /* input array */
+ int nx, /* number of input pixels */
+ unsigned char *c, /* output buffer */
+ int clen, /* max length of output */
+ int nblock) /* coding block size */
+{
+Buffer bufmem, *buffer = &bufmem;
+/* int bsize; */
+int i, j, thisblock;
+int lastpix, nextpix, pdiff;
+int v, fs, fsmask, top, fsmax, fsbits, bbits;
+int lbitbuffer, lbits_to_go;
+unsigned int psum;
+double pixelsum, dpsum;
+unsigned int *diff;
+
+ /*
+ * Original size of each pixel (bsize, bytes) and coding block
+ * size (nblock, pixels)
+ * Could make bsize a parameter to allow more efficient
+ * compression of short & byte images.
+ */
+/* bsize = 4; */
+
+/* nblock = 32; now an input parameter*/
+ /*
+ * From bsize derive:
+ * FSBITS = # bits required to store FS
+ * FSMAX = maximum value for FS
+ * BBITS = bits/pixel for direct coding
+ */
+
+/*
+ switch (bsize) {
+ case 1:
+ fsbits = 3;
+ fsmax = 6;
+ break;
+ case 2:
+ fsbits = 4;
+ fsmax = 14;
+ break;
+ case 4:
+ fsbits = 5;
+ fsmax = 25;
+ break;
+ default:
+ ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes");
+ return(-1);
+ }
+*/
+
+ /* move out of switch block, to tweak performance */
+ fsbits = 5;
+ fsmax = 25;
+ bbits = 1<<fsbits;
+
+ /*
+ * Set up buffer pointers
+ */
+ buffer->start = c;
+ buffer->current = c;
+ buffer->end = c+clen;
+ buffer->bits_to_go = 8;
+ /*
+ * array for differences mapped to non-negative values
+ */
+ diff = (unsigned int *) malloc(nblock*sizeof(unsigned int));
+ if (diff == (unsigned int *) NULL) {
+ ffpmsg("fits_rcomp: insufficient memory");
+ return(-1);
+ }
+ /*
+ * Code in blocks of nblock pixels
+ */
+ start_outputing_bits(buffer);
+
+ /* write out first int value to the first 4 bytes of the buffer */
+ if (output_nbits(buffer, a[0], 32) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+
+ lastpix = a[0]; /* the first difference will always be zero */
+
+ thisblock = nblock;
+ for (i=0; i<nx; i += nblock) {
+ /* last block may be shorter */
+ if (nx-i < nblock) thisblock = nx-i;
+ /*
+ * Compute differences of adjacent pixels and map them to unsigned values.
+ * Note that this may overflow the integer variables -- that's
+ * OK, because we can recover when decompressing. If we were
+ * compressing shorts or bytes, would want to do this arithmetic
+ * with short/byte working variables (though diff will still be
+ * passed as an int.)
+ *
+ * compute sum of mapped pixel values at same time
+ * use double precision for sum to allow 32-bit integer inputs
+ */
+ pixelsum = 0.0;
+ for (j=0; j<thisblock; j++) {
+ nextpix = a[i+j];
+ pdiff = nextpix - lastpix;
+ diff[j] = (unsigned int) ((pdiff<0) ? ~(pdiff<<1) : (pdiff<<1));
+ pixelsum += diff[j];
+ lastpix = nextpix;
+ }
+
+ /*
+ * compute number of bits to split from sum
+ */
+ dpsum = (pixelsum - (thisblock/2) - 1)/thisblock;
+ if (dpsum < 0) dpsum = 0.0;
+ psum = ((unsigned int) dpsum ) >> 1;
+ for (fs = 0; psum>0; fs++) psum >>= 1;
+
+ /*
+ * write the codes
+ * fsbits ID bits used to indicate split level
+ */
+ if (fs >= fsmax) {
+ /* Special high entropy case when FS >= fsmax
+ * Just write pixel difference values directly, no Rice coding at all.
+ */
+ if (output_nbits(buffer, fsmax+1, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ for (j=0; j<thisblock; j++) {
+ if (output_nbits(buffer, diff[j], bbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ }
+ } else if (fs == 0 && pixelsum == 0) {
+ /*
+ * special low entropy case when FS = 0 and pixelsum=0 (all
+ * pixels in block are zero.)
+ * Output a 0 and return
+ */
+ if (output_nbits(buffer, 0, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ } else {
+ /* normal case: not either very high or very low entropy */
+ if (output_nbits(buffer, fs+1, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ fsmask = (1<<fs) - 1;
+ /*
+ * local copies of bit buffer to improve optimization
+ */
+ lbitbuffer = buffer->bitbuffer;
+ lbits_to_go = buffer->bits_to_go;
+ for (j=0; j<thisblock; j++) {
+ v = diff[j];
+ top = v >> fs;
+ /*
+ * top is coded by top zeros + 1
+ */
+ if (lbits_to_go >= top+1) {
+ lbitbuffer <<= top+1;
+ lbitbuffer |= 1;
+ lbits_to_go -= top+1;
+ } else {
+ lbitbuffer <<= lbits_to_go;
+ putcbuf(lbitbuffer & 0xff,buffer);
+
+ for (top -= lbits_to_go; top>=8; top -= 8) {
+ putcbuf(0, buffer);
+ }
+ lbitbuffer = 1;
+ lbits_to_go = 7-top;
+ }
+ /*
+ * bottom FS bits are written without coding
+ * code is output_nbits, moved into this routine to reduce overheads
+ * This code potentially breaks if FS>24, so I am limiting
+ * FS to 24 by choice of FSMAX above.
+ */
+ if (fs > 0) {
+ lbitbuffer <<= fs;
+ lbitbuffer |= v & fsmask;
+ lbits_to_go -= fs;
+ while (lbits_to_go <= 0) {
+ putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer);
+ lbits_to_go += 8;
+ }
+ }
+ }
+
+ /* check if overflowed output buffer */
+ if (buffer->current > buffer->end) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ buffer->bitbuffer = lbitbuffer;
+ buffer->bits_to_go = lbits_to_go;
+ }
+ }
+ done_outputing_bits(buffer);
+ free(diff);
+ /*
+ * return number of bytes used
+ */
+ return(buffer->current - buffer->start);
+}
+/*---------------------------------------------------------------------------*/
+
+int fits_rcomp_short(
+ short a[], /* input array */
+ int nx, /* number of input pixels */
+ unsigned char *c, /* output buffer */
+ int clen, /* max length of output */
+ int nblock) /* coding block size */
+{
+Buffer bufmem, *buffer = &bufmem;
+/* int bsize; */
+int i, j, thisblock;
+
+/*
+NOTE: in principle, the following 2 variable could be declared as 'short'
+but in fact the code runs faster (on 32-bit Linux at least) as 'int'
+*/
+int lastpix, nextpix;
+/* int pdiff; */
+short pdiff;
+int v, fs, fsmask, top, fsmax, fsbits, bbits;
+int lbitbuffer, lbits_to_go;
+/* unsigned int psum; */
+unsigned short psum;
+double pixelsum, dpsum;
+unsigned int *diff;
+
+ /*
+ * Original size of each pixel (bsize, bytes) and coding block
+ * size (nblock, pixels)
+ * Could make bsize a parameter to allow more efficient
+ * compression of short & byte images.
+ */
+/* bsize = 2; */
+
+/* nblock = 32; now an input parameter */
+ /*
+ * From bsize derive:
+ * FSBITS = # bits required to store FS
+ * FSMAX = maximum value for FS
+ * BBITS = bits/pixel for direct coding
+ */
+
+/*
+ switch (bsize) {
+ case 1:
+ fsbits = 3;
+ fsmax = 6;
+ break;
+ case 2:
+ fsbits = 4;
+ fsmax = 14;
+ break;
+ case 4:
+ fsbits = 5;
+ fsmax = 25;
+ break;
+ default:
+ ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes");
+ return(-1);
+ }
+*/
+
+ /* move these out of switch block to further tweak performance */
+ fsbits = 4;
+ fsmax = 14;
+
+ bbits = 1<<fsbits;
+
+ /*
+ * Set up buffer pointers
+ */
+ buffer->start = c;
+ buffer->current = c;
+ buffer->end = c+clen;
+ buffer->bits_to_go = 8;
+ /*
+ * array for differences mapped to non-negative values
+ */
+ diff = (unsigned int *) malloc(nblock*sizeof(unsigned int));
+ if (diff == (unsigned int *) NULL) {
+ ffpmsg("fits_rcomp: insufficient memory");
+ return(-1);
+ }
+ /*
+ * Code in blocks of nblock pixels
+ */
+ start_outputing_bits(buffer);
+
+ /* write out first short value to the first 2 bytes of the buffer */
+ if (output_nbits(buffer, a[0], 16) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+
+ lastpix = a[0]; /* the first difference will always be zero */
+
+ thisblock = nblock;
+ for (i=0; i<nx; i += nblock) {
+ /* last block may be shorter */
+ if (nx-i < nblock) thisblock = nx-i;
+ /*
+ * Compute differences of adjacent pixels and map them to unsigned values.
+ * Note that this may overflow the integer variables -- that's
+ * OK, because we can recover when decompressing. If we were
+ * compressing shorts or bytes, would want to do this arithmetic
+ * with short/byte working variables (though diff will still be
+ * passed as an int.)
+ *
+ * compute sum of mapped pixel values at same time
+ * use double precision for sum to allow 32-bit integer inputs
+ */
+ pixelsum = 0.0;
+ for (j=0; j<thisblock; j++) {
+ nextpix = a[i+j];
+ pdiff = nextpix - lastpix;
+ diff[j] = (unsigned int) ((pdiff<0) ? ~(pdiff<<1) : (pdiff<<1));
+ pixelsum += diff[j];
+ lastpix = nextpix;
+ }
+ /*
+ * compute number of bits to split from sum
+ */
+ dpsum = (pixelsum - (thisblock/2) - 1)/thisblock;
+ if (dpsum < 0) dpsum = 0.0;
+/* psum = ((unsigned int) dpsum ) >> 1; */
+ psum = ((unsigned short) dpsum ) >> 1;
+ for (fs = 0; psum>0; fs++) psum >>= 1;
+
+ /*
+ * write the codes
+ * fsbits ID bits used to indicate split level
+ */
+ if (fs >= fsmax) {
+ /* Special high entropy case when FS >= fsmax
+ * Just write pixel difference values directly, no Rice coding at all.
+ */
+ if (output_nbits(buffer, fsmax+1, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ for (j=0; j<thisblock; j++) {
+ if (output_nbits(buffer, diff[j], bbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ }
+ } else if (fs == 0 && pixelsum == 0) {
+ /*
+ * special low entropy case when FS = 0 and pixelsum=0 (all
+ * pixels in block are zero.)
+ * Output a 0 and return
+ */
+ if (output_nbits(buffer, 0, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ } else {
+ /* normal case: not either very high or very low entropy */
+ if (output_nbits(buffer, fs+1, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ fsmask = (1<<fs) - 1;
+ /*
+ * local copies of bit buffer to improve optimization
+ */
+ lbitbuffer = buffer->bitbuffer;
+ lbits_to_go = buffer->bits_to_go;
+ for (j=0; j<thisblock; j++) {
+ v = diff[j];
+ top = v >> fs;
+ /*
+ * top is coded by top zeros + 1
+ */
+ if (lbits_to_go >= top+1) {
+ lbitbuffer <<= top+1;
+ lbitbuffer |= 1;
+ lbits_to_go -= top+1;
+ } else {
+ lbitbuffer <<= lbits_to_go;
+ putcbuf(lbitbuffer & 0xff,buffer);
+ for (top -= lbits_to_go; top>=8; top -= 8) {
+ putcbuf(0, buffer);
+ }
+ lbitbuffer = 1;
+ lbits_to_go = 7-top;
+ }
+ /*
+ * bottom FS bits are written without coding
+ * code is output_nbits, moved into this routine to reduce overheads
+ * This code potentially breaks if FS>24, so I am limiting
+ * FS to 24 by choice of FSMAX above.
+ */
+ if (fs > 0) {
+ lbitbuffer <<= fs;
+ lbitbuffer |= v & fsmask;
+ lbits_to_go -= fs;
+ while (lbits_to_go <= 0) {
+ putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer);
+ lbits_to_go += 8;
+ }
+ }
+ }
+ /* check if overflowed output buffer */
+ if (buffer->current > buffer->end) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ buffer->bitbuffer = lbitbuffer;
+ buffer->bits_to_go = lbits_to_go;
+ }
+ }
+ done_outputing_bits(buffer);
+ free(diff);
+ /*
+ * return number of bytes used
+ */
+ return(buffer->current - buffer->start);
+}
+/*---------------------------------------------------------------------------*/
+
+int fits_rcomp_byte(
+ signed char a[], /* input array */
+ int nx, /* number of input pixels */
+ unsigned char *c, /* output buffer */
+ int clen, /* max length of output */
+ int nblock) /* coding block size */
+{
+Buffer bufmem, *buffer = &bufmem;
+/* int bsize; */
+int i, j, thisblock;
+
+/*
+NOTE: in principle, the following 2 variable could be declared as 'short'
+but in fact the code runs faster (on 32-bit Linux at least) as 'int'
+*/
+int lastpix, nextpix;
+/* int pdiff; */
+signed char pdiff;
+int v, fs, fsmask, top, fsmax, fsbits, bbits;
+int lbitbuffer, lbits_to_go;
+/* unsigned int psum; */
+unsigned char psum;
+double pixelsum, dpsum;
+unsigned int *diff;
+
+ /*
+ * Original size of each pixel (bsize, bytes) and coding block
+ * size (nblock, pixels)
+ * Could make bsize a parameter to allow more efficient
+ * compression of short & byte images.
+ */
+/* bsize = 1; */
+
+/* nblock = 32; now an input parameter */
+ /*
+ * From bsize derive:
+ * FSBITS = # bits required to store FS
+ * FSMAX = maximum value for FS
+ * BBITS = bits/pixel for direct coding
+ */
+
+/*
+ switch (bsize) {
+ case 1:
+ fsbits = 3;
+ fsmax = 6;
+ break;
+ case 2:
+ fsbits = 4;
+ fsmax = 14;
+ break;
+ case 4:
+ fsbits = 5;
+ fsmax = 25;
+ break;
+ default:
+ ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes");
+ return(-1);
+ }
+*/
+
+ /* move these out of switch block to further tweak performance */
+ fsbits = 3;
+ fsmax = 6;
+ bbits = 1<<fsbits;
+
+ /*
+ * Set up buffer pointers
+ */
+ buffer->start = c;
+ buffer->current = c;
+ buffer->end = c+clen;
+ buffer->bits_to_go = 8;
+ /*
+ * array for differences mapped to non-negative values
+ */
+ diff = (unsigned int *) malloc(nblock*sizeof(unsigned int));
+ if (diff == (unsigned int *) NULL) {
+ ffpmsg("fits_rcomp: insufficient memory");
+ return(-1);
+ }
+ /*
+ * Code in blocks of nblock pixels
+ */
+ start_outputing_bits(buffer);
+
+ /* write out first byte value to the first byte of the buffer */
+ if (output_nbits(buffer, a[0], 8) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+
+ lastpix = a[0]; /* the first difference will always be zero */
+
+ thisblock = nblock;
+ for (i=0; i<nx; i += nblock) {
+ /* last block may be shorter */
+ if (nx-i < nblock) thisblock = nx-i;
+ /*
+ * Compute differences of adjacent pixels and map them to unsigned values.
+ * Note that this may overflow the integer variables -- that's
+ * OK, because we can recover when decompressing. If we were
+ * compressing shorts or bytes, would want to do this arithmetic
+ * with short/byte working variables (though diff will still be
+ * passed as an int.)
+ *
+ * compute sum of mapped pixel values at same time
+ * use double precision for sum to allow 32-bit integer inputs
+ */
+ pixelsum = 0.0;
+ for (j=0; j<thisblock; j++) {
+ nextpix = a[i+j];
+ pdiff = nextpix - lastpix;
+ diff[j] = (unsigned int) ((pdiff<0) ? ~(pdiff<<1) : (pdiff<<1));
+ pixelsum += diff[j];
+ lastpix = nextpix;
+ }
+ /*
+ * compute number of bits to split from sum
+ */
+ dpsum = (pixelsum - (thisblock/2) - 1)/thisblock;
+ if (dpsum < 0) dpsum = 0.0;
+/* psum = ((unsigned int) dpsum ) >> 1; */
+ psum = ((unsigned char) dpsum ) >> 1;
+ for (fs = 0; psum>0; fs++) psum >>= 1;
+
+ /*
+ * write the codes
+ * fsbits ID bits used to indicate split level
+ */
+ if (fs >= fsmax) {
+ /* Special high entropy case when FS >= fsmax
+ * Just write pixel difference values directly, no Rice coding at all.
+ */
+ if (output_nbits(buffer, fsmax+1, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ for (j=0; j<thisblock; j++) {
+ if (output_nbits(buffer, diff[j], bbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ }
+ } else if (fs == 0 && pixelsum == 0) {
+ /*
+ * special low entropy case when FS = 0 and pixelsum=0 (all
+ * pixels in block are zero.)
+ * Output a 0 and return
+ */
+ if (output_nbits(buffer, 0, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ } else {
+ /* normal case: not either very high or very low entropy */
+ if (output_nbits(buffer, fs+1, fsbits) == EOF) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ fsmask = (1<<fs) - 1;
+ /*
+ * local copies of bit buffer to improve optimization
+ */
+ lbitbuffer = buffer->bitbuffer;
+ lbits_to_go = buffer->bits_to_go;
+ for (j=0; j<thisblock; j++) {
+ v = diff[j];
+ top = v >> fs;
+ /*
+ * top is coded by top zeros + 1
+ */
+ if (lbits_to_go >= top+1) {
+ lbitbuffer <<= top+1;
+ lbitbuffer |= 1;
+ lbits_to_go -= top+1;
+ } else {
+ lbitbuffer <<= lbits_to_go;
+ putcbuf(lbitbuffer & 0xff,buffer);
+ for (top -= lbits_to_go; top>=8; top -= 8) {
+ putcbuf(0, buffer);
+ }
+ lbitbuffer = 1;
+ lbits_to_go = 7-top;
+ }
+ /*
+ * bottom FS bits are written without coding
+ * code is output_nbits, moved into this routine to reduce overheads
+ * This code potentially breaks if FS>24, so I am limiting
+ * FS to 24 by choice of FSMAX above.
+ */
+ if (fs > 0) {
+ lbitbuffer <<= fs;
+ lbitbuffer |= v & fsmask;
+ lbits_to_go -= fs;
+ while (lbits_to_go <= 0) {
+ putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer);
+ lbits_to_go += 8;
+ }
+ }
+ }
+ /* check if overflowed output buffer */
+ if (buffer->current > buffer->end) {
+ ffpmsg("rice_encode: end of buffer");
+ free(diff);
+ return(-1);
+ }
+ buffer->bitbuffer = lbitbuffer;
+ buffer->bits_to_go = lbits_to_go;
+ }
+ }
+ done_outputing_bits(buffer);
+ free(diff);
+ /*
+ * return number of bytes used
+ */
+ return(buffer->current - buffer->start);
+}
+/*---------------------------------------------------------------------------*/
+/* bit_output.c
+ *
+ * Bit output routines
+ * Procedures return zero on success, EOF on end-of-buffer
+ *
+ * Programmer: R. White Date: 20 July 1998
+ */
+
+/* Initialize for bit output */
+
+static void start_outputing_bits(Buffer *buffer)
+{
+ /*
+ * Buffer is empty to start with
+ */
+ buffer->bitbuffer = 0;
+ buffer->bits_to_go = 8;
+}
+
+/*---------------------------------------------------------------------------*/
+/* Output N bits (N must be <= 32) */
+
+static int output_nbits(Buffer *buffer, int bits, int n)
+{
+/* local copies */
+int lbitbuffer;
+int lbits_to_go;
+ /* AND mask for the right-most n bits */
+ static unsigned int mask[33] =
+ {0,
+ 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff,
+ 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff,
+ 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff,
+ 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff};
+
+ /*
+ * insert bits at end of bitbuffer
+ */
+ lbitbuffer = buffer->bitbuffer;
+ lbits_to_go = buffer->bits_to_go;
+ if (lbits_to_go+n > 32) {
+ /*
+ * special case for large n: put out the top lbits_to_go bits first
+ * note that 0 < lbits_to_go <= 8
+ */
+ lbitbuffer <<= lbits_to_go;
+/* lbitbuffer |= (bits>>(n-lbits_to_go)) & ((1<<lbits_to_go)-1); */
+ lbitbuffer |= (bits>>(n-lbits_to_go)) & *(mask+lbits_to_go);
+ putcbuf(lbitbuffer & 0xff,buffer);
+ n -= lbits_to_go;
+ lbits_to_go = 8;
+ }
+ lbitbuffer <<= n;
+/* lbitbuffer |= ( bits & ((1<<n)-1) ); */
+ lbitbuffer |= ( bits & *(mask+n) );
+ lbits_to_go -= n;
+ while (lbits_to_go <= 0) {
+ /*
+ * bitbuffer full, put out top 8 bits
+ */
+ putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer);
+ lbits_to_go += 8;
+ }
+ buffer->bitbuffer = lbitbuffer;
+ buffer->bits_to_go = lbits_to_go;
+ return(0);
+}
+/*---------------------------------------------------------------------------*/
+/* Flush out the last bits */
+
+static int done_outputing_bits(Buffer *buffer)
+{
+ if(buffer->bits_to_go < 8) {
+ putcbuf(buffer->bitbuffer<<buffer->bits_to_go,buffer);
+
+/* if (putcbuf(buffer->bitbuffer<<buffer->bits_to_go,buffer) == EOF)
+ return(EOF);
+*/
+ }
+ return(0);
+}
+/*---------------------------------------------------------------------------*/
+/*----------------------------------------------------------*/
+/* */
+/* START OF SOURCE FILE ORIGINALLY CALLED rdecomp.c */
+/* */
+/*----------------------------------------------------------*/
+
+/* @(#) rdecomp.c 1.4 99/03/01 12:38:41 */
+/* rdecomp.c Decompress image line using
+ * (1) Difference of adjacent pixels
+ * (2) Rice algorithm coding
+ *
+ * Returns 0 on success or 1 on failure
+ */
+
+/* moved these 'includes' to the beginning of the file (WDP)
+#include <stdio.h>
+#include <stdlib.h>
+*/
+
+/*---------------------------------------------------------------------------*/
+/* this routine used to be called 'rdecomp' (WDP) */
+
+int fits_rdecomp (unsigned char *c, /* input buffer */
+ int clen, /* length of input */
+ unsigned int array[], /* output array */
+ int nx, /* number of output pixels */
+ int nblock) /* coding block size */
+{
+/* int bsize; */
+int i, k, imax;
+int nbits, nzero, fs;
+unsigned char *cend, bytevalue;
+unsigned int b, diff, lastpix;
+int fsmax, fsbits, bbits;
+static int *nonzero_count = (int *)NULL;
+
+ /*
+ * Original size of each pixel (bsize, bytes) and coding block
+ * size (nblock, pixels)
+ * Could make bsize a parameter to allow more efficient
+ * compression of short & byte images.
+ */
+/* bsize = 4; */
+
+/* nblock = 32; now an input parameter */
+ /*
+ * From bsize derive:
+ * FSBITS = # bits required to store FS
+ * FSMAX = maximum value for FS
+ * BBITS = bits/pixel for direct coding
+ */
+
+/*
+ switch (bsize) {
+ case 1:
+ fsbits = 3;
+ fsmax = 6;
+ break;
+ case 2:
+ fsbits = 4;
+ fsmax = 14;
+ break;
+ case 4:
+ fsbits = 5;
+ fsmax = 25;
+ break;
+ default:
+ ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes");
+ return 1;
+ }
+*/
+
+ /* move out of switch block, to tweak performance */
+ fsbits = 5;
+ fsmax = 25;
+
+ bbits = 1<<fsbits;
+
+ FFLOCK;
+ if (nonzero_count == (int *) NULL) {
+ /*
+ * nonzero_count is lookup table giving number of bits
+ * in 8-bit values not including leading zeros
+ */
+
+ /* NOTE!!! This memory never gets freed */
+ nonzero_count = (int *) malloc(256*sizeof(int));
+ if (nonzero_count == (int *) NULL) {
+ ffpmsg("rdecomp: insufficient memory");
+ FFUNLOCK;
+ return 1;
+ }
+ nzero = 8;
+ k = 128;
+ for (i=255; i>=0; ) {
+ for ( ; i>=k; i--) nonzero_count[i] = nzero;
+ k = k/2;
+ nzero--;
+ }
+ }
+ FFUNLOCK;
+
+ /*
+ * Decode in blocks of nblock pixels
+ */
+
+ /* first 4 bytes of input buffer contain the value of the first */
+ /* 4 byte integer value, without any encoding */
+
+ lastpix = 0;
+ bytevalue = c[0];
+ lastpix = lastpix | (bytevalue<<24);
+ bytevalue = c[1];
+ lastpix = lastpix | (bytevalue<<16);
+ bytevalue = c[2];
+ lastpix = lastpix | (bytevalue<<8);
+ bytevalue = c[3];
+ lastpix = lastpix | bytevalue;
+
+ c += 4;
+ cend = c + clen - 4;
+
+ b = *c++; /* bit buffer */
+ nbits = 8; /* number of bits remaining in b */
+ for (i = 0; i<nx; ) {
+ /* get the FS value from first fsbits */
+ nbits -= fsbits;
+ while (nbits < 0) {
+ b = (b<<8) | (*c++);
+ nbits += 8;
+ }
+ fs = (b >> nbits) - 1;
+
+ b &= (1<<nbits)-1;
+ /* loop over the next block */
+ imax = i + nblock;
+ if (imax > nx) imax = nx;
+ if (fs<0) {
+ /* low-entropy case, all zero differences */
+ for ( ; i<imax; i++) array[i] = lastpix;
+ } else if (fs==fsmax) {
+ /* high-entropy case, directly coded pixel values */
+ for ( ; i<imax; i++) {
+ k = bbits - nbits;
+ diff = b<<k;
+ for (k -= 8; k >= 0; k -= 8) {
+ b = *c++;
+ diff |= b<<k;
+ }
+ if (nbits>0) {
+ b = *c++;
+ diff |= b>>(-k);
+ b &= (1<<nbits)-1;
+ } else {
+ b = 0;
+ }
+ /*
+ * undo mapping and differencing
+ * Note that some of these operations will overflow the
+ * unsigned int arithmetic -- that's OK, it all works
+ * out to give the right answers in the output file.
+ */
+ if ((diff & 1) == 0) {
+ diff = diff>>1;
+ } else {
+ diff = ~(diff>>1);
+ }
+ array[i] = diff+lastpix;
+ lastpix = array[i];
+ }
+ } else {
+ /* normal case, Rice coding */
+ for ( ; i<imax; i++) {
+ /* count number of leading zeros */
+ while (b == 0) {
+ nbits += 8;
+ b = *c++;
+ }
+ nzero = nbits - nonzero_count[b];
+ nbits -= nzero+1;
+ /* flip the leading one-bit */
+ b ^= 1<<nbits;
+ /* get the FS trailing bits */
+ nbits -= fs;
+ while (nbits < 0) {
+ b = (b<<8) | (*c++);
+ nbits += 8;
+ }
+ diff = (nzero<<fs) | (b>>nbits);
+ b &= (1<<nbits)-1;
+
+ /* undo mapping and differencing */
+ if ((diff & 1) == 0) {
+ diff = diff>>1;
+ } else {
+ diff = ~(diff>>1);
+ }
+ array[i] = diff+lastpix;
+ lastpix = array[i];
+ }
+ }
+ if (c > cend) {
+ ffpmsg("decompression error: hit end of compressed byte stream");
+ return 1;
+ }
+ }
+ if (c < cend) {
+ ffpmsg("decompression warning: unused bytes at end of compressed buffer");
+ }
+ return 0;
+}
+/*---------------------------------------------------------------------------*/
+/* this routine used to be called 'rdecomp' (WDP) */
+
+int fits_rdecomp_short (unsigned char *c, /* input buffer */
+ int clen, /* length of input */
+ unsigned short array[], /* output array */
+ int nx, /* number of output pixels */
+ int nblock) /* coding block size */
+{
+int i, imax;
+/* int bsize; */
+int k;
+int nbits, nzero, fs;
+unsigned char *cend, bytevalue;
+unsigned int b, diff, lastpix;
+int fsmax, fsbits, bbits;
+static int *nonzero_count = (int *)NULL;
+
+ /*
+ * Original size of each pixel (bsize, bytes) and coding block
+ * size (nblock, pixels)
+ * Could make bsize a parameter to allow more efficient
+ * compression of short & byte images.
+ */
+
+/* bsize = 2; */
+
+/* nblock = 32; now an input parameter */
+ /*
+ * From bsize derive:
+ * FSBITS = # bits required to store FS
+ * FSMAX = maximum value for FS
+ * BBITS = bits/pixel for direct coding
+ */
+
+/*
+ switch (bsize) {
+ case 1:
+ fsbits = 3;
+ fsmax = 6;
+ break;
+ case 2:
+ fsbits = 4;
+ fsmax = 14;
+ break;
+ case 4:
+ fsbits = 5;
+ fsmax = 25;
+ break;
+ default:
+ ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes");
+ return 1;
+ }
+*/
+
+ /* move out of switch block, to tweak performance */
+ fsbits = 4;
+ fsmax = 14;
+
+ bbits = 1<<fsbits;
+
+ FFLOCK;
+ if (nonzero_count == (int *) NULL) {
+ /*
+ * nonzero_count is lookup table giving number of bits
+ * in 8-bit values not including leading zeros
+ */
+
+ /* NOTE!!! This memory never gets freed */
+ nonzero_count = (int *) malloc(256*sizeof(int));
+ if (nonzero_count == (int *) NULL) {
+ ffpmsg("rdecomp: insufficient memory");
+ FFUNLOCK;
+ return 1;
+ }
+ nzero = 8;
+ k = 128;
+ for (i=255; i>=0; ) {
+ for ( ; i>=k; i--) nonzero_count[i] = nzero;
+ k = k/2;
+ nzero--;
+ }
+ }
+ FFUNLOCK;
+ /*
+ * Decode in blocks of nblock pixels
+ */
+
+ /* first 2 bytes of input buffer contain the value of the first */
+ /* 2 byte integer value, without any encoding */
+
+ lastpix = 0;
+ bytevalue = c[0];
+ lastpix = lastpix | (bytevalue<<8);
+ bytevalue = c[1];
+ lastpix = lastpix | bytevalue;
+
+ c += 2;
+ cend = c + clen - 2;
+
+ b = *c++; /* bit buffer */
+ nbits = 8; /* number of bits remaining in b */
+ for (i = 0; i<nx; ) {
+ /* get the FS value from first fsbits */
+ nbits -= fsbits;
+ while (nbits < 0) {
+ b = (b<<8) | (*c++);
+ nbits += 8;
+ }
+ fs = (b >> nbits) - 1;
+
+ b &= (1<<nbits)-1;
+ /* loop over the next block */
+ imax = i + nblock;
+ if (imax > nx) imax = nx;
+ if (fs<0) {
+ /* low-entropy case, all zero differences */
+ for ( ; i<imax; i++) array[i] = lastpix;
+ } else if (fs==fsmax) {
+ /* high-entropy case, directly coded pixel values */
+ for ( ; i<imax; i++) {
+ k = bbits - nbits;
+ diff = b<<k;
+ for (k -= 8; k >= 0; k -= 8) {
+ b = *c++;
+ diff |= b<<k;
+ }
+ if (nbits>0) {
+ b = *c++;
+ diff |= b>>(-k);
+ b &= (1<<nbits)-1;
+ } else {
+ b = 0;
+ }
+
+ /*
+ * undo mapping and differencing
+ * Note that some of these operations will overflow the
+ * unsigned int arithmetic -- that's OK, it all works
+ * out to give the right answers in the output file.
+ */
+ if ((diff & 1) == 0) {
+ diff = diff>>1;
+ } else {
+ diff = ~(diff>>1);
+ }
+ array[i] = diff+lastpix;
+ lastpix = array[i];
+ }
+ } else {
+ /* normal case, Rice coding */
+ for ( ; i<imax; i++) {
+ /* count number of leading zeros */
+ while (b == 0) {
+ nbits += 8;
+ b = *c++;
+ }
+ nzero = nbits - nonzero_count[b];
+ nbits -= nzero+1;
+ /* flip the leading one-bit */
+ b ^= 1<<nbits;
+ /* get the FS trailing bits */
+ nbits -= fs;
+ while (nbits < 0) {
+ b = (b<<8) | (*c++);
+ nbits += 8;
+ }
+ diff = (nzero<<fs) | (b>>nbits);
+ b &= (1<<nbits)-1;
+
+ /* undo mapping and differencing */
+ if ((diff & 1) == 0) {
+ diff = diff>>1;
+ } else {
+ diff = ~(diff>>1);
+ }
+ array[i] = diff+lastpix;
+ lastpix = array[i];
+ }
+ }
+ if (c > cend) {
+ ffpmsg("decompression error: hit end of compressed byte stream");
+ return 1;
+ }
+ }
+ if (c < cend) {
+ ffpmsg("decompression warning: unused bytes at end of compressed buffer");
+ }
+ return 0;
+}
+/*---------------------------------------------------------------------------*/
+/* this routine used to be called 'rdecomp' (WDP) */
+
+int fits_rdecomp_byte (unsigned char *c, /* input buffer */
+ int clen, /* length of input */
+ unsigned char array[], /* output array */
+ int nx, /* number of output pixels */
+ int nblock) /* coding block size */
+{
+int i, imax;
+/* int bsize; */
+int k;
+int nbits, nzero, fs;
+unsigned char *cend;
+unsigned int b, diff, lastpix;
+int fsmax, fsbits, bbits;
+static int *nonzero_count = (int *)NULL;
+
+ /*
+ * Original size of each pixel (bsize, bytes) and coding block
+ * size (nblock, pixels)
+ * Could make bsize a parameter to allow more efficient
+ * compression of short & byte images.
+ */
+
+/* bsize = 1; */
+
+/* nblock = 32; now an input parameter */
+ /*
+ * From bsize derive:
+ * FSBITS = # bits required to store FS
+ * FSMAX = maximum value for FS
+ * BBITS = bits/pixel for direct coding
+ */
+
+/*
+ switch (bsize) {
+ case 1:
+ fsbits = 3;
+ fsmax = 6;
+ break;
+ case 2:
+ fsbits = 4;
+ fsmax = 14;
+ break;
+ case 4:
+ fsbits = 5;
+ fsmax = 25;
+ break;
+ default:
+ ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes");
+ return 1;
+ }
+*/
+
+ /* move out of switch block, to tweak performance */
+ fsbits = 3;
+ fsmax = 6;
+
+ bbits = 1<<fsbits;
+
+ FFLOCK;
+ if (nonzero_count == (int *) NULL) {
+ /*
+ * nonzero_count is lookup table giving number of bits
+ * in 8-bit values not including leading zeros
+ */
+
+ /* NOTE!!! This memory never gets freed */
+ nonzero_count = (int *) malloc(256*sizeof(int));
+ if (nonzero_count == (int *) NULL) {
+ ffpmsg("rdecomp: insufficient memory");
+ FFUNLOCK;
+ return 1;
+ }
+ nzero = 8;
+ k = 128;
+ for (i=255; i>=0; ) {
+ for ( ; i>=k; i--) nonzero_count[i] = nzero;
+ k = k/2;
+ nzero--;
+ }
+ }
+ FFUNLOCK;
+ /*
+ * Decode in blocks of nblock pixels
+ */
+
+ /* first byte of input buffer contain the value of the first */
+ /* byte integer value, without any encoding */
+
+ lastpix = c[0];
+ c += 1;
+ cend = c + clen - 1;
+
+ b = *c++; /* bit buffer */
+ nbits = 8; /* number of bits remaining in b */
+ for (i = 0; i<nx; ) {
+ /* get the FS value from first fsbits */
+ nbits -= fsbits;
+ while (nbits < 0) {
+ b = (b<<8) | (*c++);
+ nbits += 8;
+ }
+ fs = (b >> nbits) - 1;
+
+ b &= (1<<nbits)-1;
+ /* loop over the next block */
+ imax = i + nblock;
+ if (imax > nx) imax = nx;
+ if (fs<0) {
+ /* low-entropy case, all zero differences */
+ for ( ; i<imax; i++) array[i] = lastpix;
+ } else if (fs==fsmax) {
+ /* high-entropy case, directly coded pixel values */
+ for ( ; i<imax; i++) {
+ k = bbits - nbits;
+ diff = b<<k;
+ for (k -= 8; k >= 0; k -= 8) {
+ b = *c++;
+ diff |= b<<k;
+ }
+ if (nbits>0) {
+ b = *c++;
+ diff |= b>>(-k);
+ b &= (1<<nbits)-1;
+ } else {
+ b = 0;
+ }
+
+ /*
+ * undo mapping and differencing
+ * Note that some of these operations will overflow the
+ * unsigned int arithmetic -- that's OK, it all works
+ * out to give the right answers in the output file.
+ */
+ if ((diff & 1) == 0) {
+ diff = diff>>1;
+ } else {
+ diff = ~(diff>>1);
+ }
+ array[i] = diff+lastpix;
+ lastpix = array[i];
+ }
+ } else {
+ /* normal case, Rice coding */
+ for ( ; i<imax; i++) {
+ /* count number of leading zeros */
+ while (b == 0) {
+ nbits += 8;
+ b = *c++;
+ }
+ nzero = nbits - nonzero_count[b];
+ nbits -= nzero+1;
+ /* flip the leading one-bit */
+ b ^= 1<<nbits;
+ /* get the FS trailing bits */
+ nbits -= fs;
+ while (nbits < 0) {
+ b = (b<<8) | (*c++);
+ nbits += 8;
+ }
+ diff = (nzero<<fs) | (b>>nbits);
+ b &= (1<<nbits)-1;
+
+ /* undo mapping and differencing */
+ if ((diff & 1) == 0) {
+ diff = diff>>1;
+ } else {
+ diff = ~(diff>>1);
+ }
+ array[i] = diff+lastpix;
+ lastpix = array[i];
+ }
+ }
+ if (c > cend) {
+ ffpmsg("decompression error: hit end of compressed byte stream");
+ return 1;
+ }
+ }
+ if (c < cend) {
+ ffpmsg("decompression warning: unused bytes at end of compressed buffer");
+ }
+ return 0;
+}
diff --git a/fitsy++/savefits.C b/fitsy++/savefits.C
new file mode 100644
index 0000000..bfd6f94
--- /dev/null
+++ b/fitsy++/savefits.C
@@ -0,0 +1,358 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include <tcl.h>
+
+#include "file.h"
+#include "util.h"
+#include "outfile.h"
+#include "outchannel.h"
+#include "outsocket.h"
+
+int FitsFile::saveFitsPrimHeader(OutFitsStream& str)
+{
+ // write fake primary header
+ char buf[FTY_BLOCK];
+ memset(buf,' ',FTY_BLOCK);
+
+ char* hdu = buf;
+
+ memcpy(hdu,"SIMPLE = ",10);
+ memcpy(hdu+32-3,"T /",3);
+ hdu += FTY_CARDLEN;
+
+ memcpy(hdu,"BITPIX = ",10);
+ memcpy(hdu+32-3,"8 /",3);
+ hdu += FTY_CARDLEN;
+
+ memcpy(hdu,"NAXIS = ",10);
+ memcpy(hdu+32-3,"0 /",3);
+ hdu += FTY_CARDLEN;
+
+ memcpy(hdu,"END",3);
+ str.write(buf, FTY_BLOCK);
+
+ return FTY_BLOCK;
+}
+
+int FitsFile::saveFitsHeaderCards(OutFitsStream& str, int depth, int cc)
+{
+ char buf[FTY_CARDLEN];
+ int cnt = 0;
+
+ char* ptr = head()->cards() + cc;
+ char* end = head()->cards() + head()->headbytes();
+
+ while (ptr<end) {
+ if (!strncmp(ptr,"BITPIX",6) && head()->bitpix() == -16) {
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"BITPIX = ",10);
+ memcpy(buf+32-4,"32 /",4);
+ str.write(buf, FTY_CARDLEN);
+ }
+ else if (!strncmp(ptr,"NAXIS ",6)) {
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"NAXIS = ",10);
+ if (depth>1)
+ memcpy(buf+32-3,"3 /",3);
+ else
+ if (head()->naxis(1)>1)
+ memcpy(buf+32-3,"2 /",3);
+ else
+ memcpy(buf+32-3,"1 /",3);
+ str.write(buf, FTY_CARDLEN);
+ }
+ else if (!strncmp(ptr,"NAXIS2",6)) {
+ str.write(ptr, FTY_CARDLEN);
+
+ if (depth>1) {
+ ostringstream ddstr;
+ ddstr << depth << " /" << ends;
+ const char* ddptr = dupstr(ddstr.str().c_str());
+ int ll = strlen(ddptr);
+
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"NAXIS3 = ",10);
+ memcpy(buf+32-ll, ddptr, ll);
+ str.write(buf, FTY_CARDLEN);
+ cnt += FTY_CARDLEN;
+ delete [] ddptr;
+ }
+ }
+ else if (!strncmp(ptr,"NAXIS3",6)) {
+ // skip, we already take care of it above
+ cnt -= FTY_CARDLEN;
+ }
+ else if (!strncmp(ptr,"NAXIS4",6)) {
+ // skip, better not be here
+ cnt -= FTY_CARDLEN;
+ }
+ else if (!strncmp(ptr,"NAXIS5",6)) {
+ // skip, better not be here
+ cnt -= FTY_CARDLEN;
+ }
+ else if (!strncmp(ptr,"PCOUNT",6)) {
+ // skip
+ cnt -= FTY_CARDLEN;
+ }
+ else if (!strncmp(ptr,"GCOUNT",6)) {
+ // skip
+ cnt -= FTY_CARDLEN;
+ }
+ else if (!strncmp(ptr,"END ",6)) {
+ // skip, will insert at the end
+ cnt -= FTY_CARDLEN;
+ }
+ else if (!strncmp(ptr,"CRVAL3",6) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else if (!strncmp(ptr,"CRPIX3",6) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else if (!strncmp(ptr,"CDELT3",6) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else if (!strncmp(ptr,"CTYPE3",6) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else if (!strncmp(ptr,"CUNIT3",6) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else if (!strncmp(ptr,"CD3_",4) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else if (!strncmp(ptr,"PC3_",4) && depth==1)
+ // skip
+ cnt -= FTY_CARDLEN;
+ else
+ str.write(ptr, FTY_CARDLEN);
+
+ ptr += FTY_CARDLEN;
+ cnt += FTY_CARDLEN;
+ }
+
+ // final END
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"END",3);
+ str.write(buf, FTY_CARDLEN);
+ cnt += FTY_CARDLEN;
+
+ return cnt;
+}
+
+int FitsFile::saveFitsHeader(OutFitsStream& str, int depth)
+{
+ int cnt =0;
+ char buf[FTY_CARDLEN];
+
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"SIMPLE = ",10);
+ memcpy(buf+32-3,"T /",3);
+ str.write(buf, FTY_CARDLEN);
+ cnt += FTY_CARDLEN;
+
+ cnt += saveFitsHeaderCards(str,depth,cnt);
+ cnt += saveFitsPad(str,cnt,' ');
+
+ return cnt;
+}
+
+int FitsFile::saveFitsXtHeader(OutFitsStream& str, int depth)
+{
+ // write xtension header
+ // the header may be an xtension, or primary, so lets force a
+ // first line of 'SIMPLE' and then write the rest of the header
+ int cnt =0;
+ char buf[FTY_CARDLEN];
+
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"XTENSION= 'IMAGE '",20);
+ str.write(buf, FTY_CARDLEN);
+ cnt += FTY_CARDLEN;
+
+ cnt += saveFitsHeaderCards(str,depth,cnt);
+ cnt += saveFitsPad(str,cnt,' ');
+
+ return cnt;
+}
+
+int FitsFile::saveFits(OutFitsStream& str)
+{
+ FitsImageHDU* hdu = (FitsImageHDU*)(head()->hdu());
+
+ if (hdu->bitpix() != -16) {
+ switch (endian_) {
+ case BIG:
+ str.write((char*)data(), hdu->imgbytes());
+ break;
+ case LITTLE:
+ str.writeSwap((char*)data(), hdu->imgbytes(), head()->bitpix());
+ break;
+ case NATIVE:
+ break;
+ }
+
+ return hdu->imgbytes();
+ }
+
+ // convert bitpix=-16 to bitpix=32
+ int nx = head()->naxis(0);
+ int ny = head()->naxis(1);
+ int ss = nx*ny;
+ int* dest = new int[ss];
+ for(int jj=0; jj<ny; jj++) {
+ for (int ii=0; ii<nx; ii++) {
+ unsigned short* data = (unsigned short*)data_;
+ unsigned short* ptr = data + jj*nx +ii;
+
+ unsigned short vv;
+ if (byteswap_)
+ swap2((char*)ptr, (char*)&vv);
+ else
+ vv = *ptr;
+
+ dest[jj*nx + ii] = int(vv);
+ }
+ }
+
+ if (!lsb())
+ str.write((char*)dest, 4*ss);
+ else
+ str.writeSwap((char*)dest, 4*ss, 32);
+
+ delete [] dest;
+ return 4*ss;
+}
+
+int FitsFile::saveFitsPad(OutFitsStream& str, size_t cnt, char fil)
+{
+ // write any padding
+ char buf[FTY_BLOCK];
+ memset(buf,fil,FTY_BLOCK);
+
+ int npad = FTY_BLOCK - (cnt % FTY_BLOCK);
+ if (npad == FTY_BLOCK)
+ npad = 0;
+ if( npad > 0 )
+ str.write(buf, npad);
+
+ return npad;
+}
+
+int FitsFile::saveFitsTable(OutFitsStream& str)
+{
+ int cnt =0;
+ // primary header
+ str.write(primary()->cards(), primary()->headbytes());
+ cnt += primary()->headbytes();
+
+ // now, ext header
+ str.write(head()->cards(), head()->headbytes());
+ cnt += head()->headbytes();
+
+ // write valid data
+ // our data may be short (mmap or bad fits), so write valid data
+ // then write the pad, becareful with arch, if array
+
+ switch (endian_) {
+ case BIG:
+ str.write((char*)data(), head()->allbytes());
+ break;
+ case LITTLE:
+ str.writeSwap((char*)data(), head()->allbytes(), head()->bitpix());
+ break;
+ case NATIVE:
+ break;
+ }
+ cnt += head()->allbytes();
+
+ // we may need to add a buffer to round out to block size
+ int diff = head()->padbytes();
+ if (diff>0) {
+ char* buf = new char[diff];
+ memset(buf,'\0',diff);
+ str.write(buf, diff);
+ delete [] buf;
+ }
+ cnt += head()->padbytes();
+
+ return cnt;
+}
+
+int FitsFile::saveFitsIISHeader(OutFitsStream& str)
+{
+ int cnt =0;
+ char buf[FTY_CARDLEN];
+
+ char* ptr = head()->cards();
+ char* end = head()->cards() + head()->headbytes();
+ while (ptr<end) {
+ if (!strncmp(ptr,"BITPIX",6)) {
+ memset(buf,' ',FTY_CARDLEN);
+ memcpy(buf,"BITPIX = ",10);
+ memcpy(buf+32-4,"-32 /",5);
+ str.write(buf, FTY_CARDLEN);
+ }
+ else
+ str.write(ptr, FTY_CARDLEN);
+
+ ptr+=FTY_CARDLEN;
+ cnt += FTY_CARDLEN;
+ }
+
+ cnt += saveFitsPad(str,cnt,' ');
+
+ return cnt;
+}
+
+int FitsFile::saveFitsIIS(OutFitsStream& str, Vector& iisz)
+{
+ FitsImageHDU* hdu = (FitsImageHDU*)(head()->hdu());
+
+ unsigned char* src = (unsigned char*)data();
+ int size = hdu->imgbytes();
+ float* dest = new float[size];
+
+ for (int ii=0; ii<size; ii++)
+ if (src[ii] == 0)
+ dest[ii] = NAN;
+ else if (src[ii] == 1)
+ dest[ii] = iisz[0];
+ else if (src[ii] == 200)
+ dest[ii] = iisz[1];
+ else if (src[ii] > 200)
+ dest[ii] = NAN;
+ else
+ dest[ii] = ((src[ii]-1) * (iisz[1]-iisz[0]))/199 + iisz[0];
+
+ if (!lsb())
+ str.write((char*)dest, size*sizeof(float));
+ else
+ str.writeSwap((char*)dest, size*sizeof(float), -32);
+
+ if (dest)
+ delete [] dest;
+
+ return size*sizeof(float);
+}
+
+int FitsFile::saveArray(OutFitsStream& str, ArchType which)
+{
+ // only save one slice
+ size_t size = head_->naxis(0)*head_->naxis(1)*abs(head_->bitpix()/8);
+ int bitpix = head_->bitpix();
+
+ if (which == endian_)
+ str.write((char*)data(), size);
+ else
+ str.writeSwap((char*)data(), size, bitpix);
+
+ return size;
+}
+
diff --git a/fitsy++/share.C b/fitsy++/share.C
new file mode 100644
index 0000000..ca02cb6
--- /dev/null
+++ b/fitsy++/share.C
@@ -0,0 +1,103 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "share.h"
+#include "util.h"
+
+#if (HAVE_SYS_SHM_H && !__WIN32)
+#include <sys/types.h>
+#include <sys/shm.h>
+#include <sys/ipc.h>
+
+FitsShareID::FitsShareID(int shmid, const char* filter)
+{
+ parse(filter);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ share shctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ share shctl failed");
+ return;
+ }
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsShareID::~FitsShareID()
+{
+ shmdt(mapdata_);
+}
+
+FitsShareKey::FitsShareKey(int key, const char* filter)
+{
+ parse(filter);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ // get shmid
+ int shmid;
+ if ((shmid = shmget(key, 0, 0)) < 0) {
+ internalError("Fitsy++ share shmget failed");
+ return;
+ }
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ share shctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ share shmat failed");
+ return;
+ }
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsShareKey::~FitsShareKey()
+{
+ if (mapdata_)
+ shmdt(mapdata_);
+}
+
+#else
+
+FitsShareID::FitsShareID(int shmid, const char* filter)
+{
+ // shared memory not supported
+ valid_ = 0;
+}
+
+FitsShareID::~FitsShareID() {}
+
+FitsShareKey::FitsShareKey(int key, const char* filter)
+{
+ // shared memory not supported
+ valid_ = 0;
+}
+
+FitsShareKey::~FitsShareKey() {}
+
+#endif
diff --git a/fitsy++/share.h b/fitsy++/share.h
new file mode 100644
index 0000000..5fae9e3
--- /dev/null
+++ b/fitsy++/share.h
@@ -0,0 +1,98 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsshare_h__
+#define __fitsshare_h__
+
+#include "map.h"
+
+class FitsShareID : public virtual FitsMap {
+public:
+ FitsShareID(int, const char*);
+ virtual ~FitsShareID();
+};
+
+class FitsShareKey : public virtual FitsMap {
+public:
+ FitsShareKey(int, const char*);
+ virtual ~FitsShareKey();
+};
+
+class FitsFitsShare : public virtual FitsMap, public FitsFitsMap {
+ public:
+ FitsFitsShare(ScanMode mode) : FitsMap(), FitsFitsMap(mode) {}
+};
+
+class FitsFitsNextShare : public FitsFitsNextMap {
+public:
+ FitsFitsNextShare(FitsFile* prev) : FitsFitsNextMap(prev) {}
+};
+
+class FitsArrShare : public virtual FitsMap, public FitsArrMap {
+ public:
+ FitsArrShare() : FitsMap(), FitsArrMap() {}
+};
+
+class FitsNRRDShare : public virtual FitsMap, public FitsNRRDMap {
+ public:
+ FitsNRRDShare() : FitsMap(), FitsNRRDMap() {}
+};
+
+class FitsMosaicShare : public virtual FitsMap, public FitsMosaicMap {
+ public:
+ FitsMosaicShare() : FitsMap(), FitsMosaicMap() {}
+};
+
+class FitsMosaicNextShare : public FitsMosaicNextMap {
+public:
+ FitsMosaicNextShare(FitsFile* prev) : FitsMosaicNextMap(prev) {}
+};
+
+class FitsFitsShareID : public FitsShareID, public FitsFitsShare {
+public:
+ FitsFitsShareID(int shmid, const char* filter, ScanMode mode)
+ : FitsShareID(shmid, filter), FitsFitsShare(mode) {}
+};
+
+class FitsFitsShareKey : public FitsShareKey, public FitsFitsShare {
+public:
+ FitsFitsShareKey(int key, const char* filter, ScanMode mode)
+ : FitsShareKey(key, filter), FitsFitsShare(mode) {}
+};
+
+class FitsArrShareID : public FitsShareID, public FitsArrShare {
+public:
+ FitsArrShareID(int shmid, const char* filter)
+ : FitsShareID(shmid, filter), FitsArrShare() {}
+};
+
+class FitsArrShareKey : public FitsShareKey, public FitsArrShare {
+public:
+ FitsArrShareKey(int key, const char* filter)
+ : FitsShareKey(key, filter), FitsArrShare() {}
+};
+
+class FitsNRRDShareID : public FitsShareID, public FitsNRRDShare {
+public:
+ FitsNRRDShareID(int shmid, const char* filter)
+ : FitsShareID(shmid, filter), FitsNRRDShare() {}
+};
+
+class FitsNRRDShareKey : public FitsShareKey, public FitsNRRDShare {
+public:
+ FitsNRRDShareKey(int key, const char* filter)
+ : FitsShareKey(key, filter), FitsNRRDShare() {}
+};
+
+class FitsMosaicShareID : public FitsShareID, public FitsMosaicShare {
+public:
+ FitsMosaicShareID(int shmid) : FitsShareID(shmid, ""), FitsMosaicShare() {}
+};
+
+class FitsMosaicShareKey : public FitsShareKey, public FitsMosaicShare {
+public:
+ FitsMosaicShareKey(int key) : FitsShareKey(key, ""), FitsMosaicShare() {}
+};
+
+#endif
diff --git a/fitsy++/shmload.C b/fitsy++/shmload.C
new file mode 100644
index 0000000..911bafd
--- /dev/null
+++ b/fitsy++/shmload.C
@@ -0,0 +1,84 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+main(int argc, char* argv[])
+{
+ int q=0;
+
+ // check for args
+ if (argc != 2 && argc != 3){
+ cerr << "usage: shmload [-q] fits" << endl;
+ exit(1);
+ }
+
+ if (!strncmp(argv[1],"-q",2))
+ q=1;
+
+ // find the file
+ char* fn = argv[1+q];
+ struct stat statb;
+ if (stat(fn, &statb) < 0){
+ cerr << "can't find file: " << fn << endl;
+ exit(1);
+ }
+ size_t fnsize = statb.st_size;
+ if (!q)
+ cerr << fn << " size " << fnsize << endl;
+
+ // calculate shmsize
+ size_t shmsize = ((fnsize/2880)+1)*2880;
+
+ // get shmid
+ int shmid = shmget(IPC_PRIVATE, shmsize, IPC_CREAT|0666);
+
+ if (shmid == -1) {
+ // give up, its bad
+ perror("shmid is bad");
+ exit(1);
+ }
+ if (!q)
+ cerr << "shmid " << shmid << endl;
+ else
+ cout << shmid << endl;
+
+ // get shm stats
+ struct shmid_ds sbuf;
+ if (shmctl(shmid, IPC_STAT, &sbuf)<0) {
+ perror("shmctl is bad");
+ exit(1);
+ }
+ if (!q)
+ cerr << "size of shared segment: " << sbuf.shm_segsz << endl;
+
+ char* addr = (char*)shmat(shmid, NULL, 0);
+ // if (addr == -1){
+ // perror("shmat failed");
+ // exit(1);
+ // }
+
+ // load image
+ ifstream fd(fn);
+ fd.read(addr,fnsize);
+ if (!q) {
+ cerr << fd.gcount() << " bytes read" << endl;
+ if (fd.gcount() != fnsize)
+ cerr << "File read error" << endl;
+ else
+ cerr << "success!" << endl;
+ }
+}
+
diff --git a/fitsy++/smap.C b/fitsy++/smap.C
new file mode 100644
index 0000000..dffe92b
--- /dev/null
+++ b/fitsy++/smap.C
@@ -0,0 +1,187 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "smap.h"
+#include "head.h"
+
+FitsSMap::FitsSMap()
+{
+ hmapdata_ = NULL;
+ hmapsize_ = 0;
+
+ mapdata_ = NULL;
+ mapsize_ = 0;
+}
+
+FitsFitsSMap::FitsFitsSMap(FitsHead::Memory mem)
+{
+ if (!valid_)
+ return;
+
+ // simple check for fits file
+ if (strncmp(hmapdata_,"SIMPLE ",8) && strncmp(hmapdata_,"XTENSION",8)) {
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ valid_ = 0;
+ }
+
+ head_ = new FitsHead(hmapdata_, hmapsize_, mem);
+ if (head_->isValid()) {
+ data_ = mapdata_;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = 0;
+
+ inherit_ = head_->inherit();
+ valid_ = 1;
+ return;
+ }
+ else {
+ if (manageHead_ && head_)
+ delete head_;
+ head_ = NULL;
+
+ if (managePrimary_ && primary_)
+ delete primary_;
+ primary_ = NULL;
+
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ valid_ = 0;
+ }
+}
+
+FitsENVISMap::FitsENVISMap()
+{
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ = 0;
+
+ if (hmapsize_<=0 || hmapsize_>32768)
+ return;
+
+ // header
+ {
+ char* buf = new char[hmapsize_+1];
+ char* dptr = buf;
+ char* sptr = hmapdata_;
+ int cnt =0;
+ do {
+ *dptr++ = *sptr++;
+ cnt++;
+ } while (cnt<hmapsize_);
+ *dptr = '\0';
+
+ string x(buf);
+ istringstream str(x);
+ this->parseENVI(str);
+ delete [] buf;
+
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+ }
+
+ // check to see if we have a nonzero width, height, and bitpix
+ if (!validParams())
+ return;
+
+ size_t ss = (size_t)pWidth_*pHeight_*pDepth_*abs(pBitpix_)/8;
+
+ // sometimes, offset is not correct
+ if (pSkip_ == 0) {
+ if (mapsize_ > ss)
+ pSkip_ = mapsize_-ss;
+ }
+
+ // check to see if dimensions equal mapped space
+ if (ss+pSkip_ > mapsize_)
+ return;
+
+ // skip to start of data
+ data_ = mapdata_ + pSkip_;
+
+ dataSize_ = mapsize_;
+ dataSkip_ = pSkip_;
+
+ // new header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return;
+
+ // WCS?
+ if (pCRPIX3_ || pCRVAL3_ || pCDELT3_) {
+ head_->appendString("CTYPE1","LINEAR", NULL);
+ head_->appendReal("CRPIX1",1, 9, NULL);
+ head_->appendReal("CRVAL1",1, 9, NULL);
+ head_->appendReal("CDELT1",1, 9, NULL);
+
+ head_->appendString("CTYPE2","LINEAR", NULL);
+ head_->appendReal("CRPIX2",1, 9, NULL);
+ head_->appendReal("CRVAL2",1, 9, NULL);
+ head_->appendReal("CDELT2",1, 9, NULL);
+
+ head_->appendString("CTYPE3","WAVELENGTH", NULL);
+ head_->appendReal("CRPIX3",pCRPIX3_, 9, NULL);
+ head_->appendReal("CRVAL3",pCRVAL3_, 9, NULL);
+ head_->appendReal("CDELT3",pCDELT3_, 9, NULL);
+ }
+
+ // do we byteswap?
+ setByteSwap();
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsFitsNextSMap::FitsFitsNextSMap(FitsFile* p)
+{
+ FitsSMap* prev = (FitsSMap*)p;
+
+ primary_ = prev->primary();
+ managePrimary_ = 0;
+
+ head_ = prev->head();
+ manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)head_->hdu();
+ data_ = (char*)prev->data() + hdu->imgbytes();
+ dataSize_ = 0;
+ dataSkip_ = 0;
+
+ ext_ = prev->ext();
+ inherit_ = prev->inherit();
+ byteswap_ = prev->byteswap();
+ endian_ = prev->endian();
+ valid_ = 1;
+
+ pcoord_ = prev->pcoord();
+ pxvalid_ = prev->pxvalid();
+ pxmin_ = prev->pxmin();
+ pxmax_ = prev->pxmax();
+ pyvalid_ = prev->pyvalid();
+ pymin_ = prev->pymin();
+ pymax_ = prev->pymax();
+ pzvalid_ = prev->pzvalid();
+ pzmin_ = prev->pzmin();
+ pzmax_ = prev->pzmax();
+ pbvalid_ = prev->pbvalid();
+ pblock_ = prev->pblock();
+
+ mapdata_ = prev->mapdata();
+ mapsize_ = prev->mapsize();
+
+ return;
+}
+
diff --git a/fitsy++/smap.h b/fitsy++/smap.h
new file mode 100644
index 0000000..e45ecac
--- /dev/null
+++ b/fitsy++/smap.h
@@ -0,0 +1,49 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitssmap_h__
+#define __fitssmap_h__
+
+#include "file.h"
+
+class FitsSMap : public FitsFile {
+protected:
+ char* hmapdata_;
+ size_t hmapsize_;
+
+ char* mapdata_;
+ size_t mapsize_;
+
+public:
+ FitsSMap();
+ virtual ~FitsSMap() {}
+
+ char* mapdata() {return mapdata_;}
+ size_t mapsize() {return mapsize_;}
+};
+
+class FitsFitsSMap : public virtual FitsSMap {
+public:
+ FitsFitsSMap(FitsHead::Memory);
+};
+
+class FitsENVISMap : public virtual FitsSMap {
+public:
+ FitsENVISMap();
+};
+
+class FitsFitsNextSMap : public FitsSMap {
+public:
+ FitsFitsNextSMap(FitsFile* prev);
+};
+
+#endif
+
+
+
+
+
+
+
+
diff --git a/fitsy++/smmap.C b/fitsy++/smmap.C
new file mode 100644
index 0000000..5b25149
--- /dev/null
+++ b/fitsy++/smmap.C
@@ -0,0 +1,105 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "smmap.h"
+
+#ifndef __WIN32
+
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+FitsSMMap::FitsSMMap(const char* hdr, const char* fn)
+{
+ // reset
+ valid_ =0;
+
+ // header
+ {
+ // Map the header.
+ int file = open(hdr, O_RDONLY);
+ if (file == -1)
+ return;
+
+ struct stat info;
+ if (fstat(file, &info) < 0)
+ return;
+
+ // check for empty file
+ if (info.st_size == 0)
+ return;
+
+ // map it
+ hmapsize_ = info.st_size;
+ hmapdata_ = (char*)mmap(NULL, hmapsize_, PROT_READ, MAP_SHARED, file, 0);
+
+ // close the file
+ close(file);
+
+ // are we valid?
+ if ((long)hmapdata_ == -1)
+ return;
+ }
+
+ // data
+ {
+ // parse the fn and options
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ if (!pName_)
+ return;
+
+ // Map the file.
+ int file = open(pName_, O_RDONLY);
+ if (file == -1)
+ return;
+
+ struct stat info;
+ if (fstat(file, &info) < 0)
+ return;
+
+ // check for empty file
+ if (info.st_size == 0)
+ return;
+
+ // map it
+ mapsize_ = info.st_size;
+ mapdata_ = (char*)mmap(NULL, mapsize_, PROT_READ, MAP_SHARED, file, 0);
+
+ // close the file
+ close(file);
+
+ // are we valid?
+ if ((long)mapdata_ == -1)
+ return;
+ }
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsSMMap::~FitsSMMap()
+{
+ if (mapdata_)
+ munmap((caddr_t)mapdata_, mapsize_);
+}
+
+#else
+
+FitsSMMap::FitsSMMap(const char* hdr, const char* fn)
+{
+ valid_ =0;
+}
+
+FitsSMMap::~FitsSMMap() {}
+
+#endif
diff --git a/fitsy++/smmap.h b/fitsy++/smmap.h
new file mode 100644
index 0000000..eb04ca9
--- /dev/null
+++ b/fitsy++/smmap.h
@@ -0,0 +1,33 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitssmmap_h__
+#define __fitssmmap_h__
+
+#include "smap.h"
+
+class FitsSMMap : public virtual FitsSMap {
+public:
+ FitsSMMap(const char*, const char*);
+ virtual ~FitsSMMap();
+};
+
+class FitsFitsSMMap : public FitsSMMap, public FitsFitsSMap {
+public:
+ FitsFitsSMMap(const char* hdr, const char* fn)
+ : FitsSMMap(hdr,fn), FitsFitsSMap(FitsHead::MMAP) {}
+};
+
+class FitsENVISMMap : public FitsSMMap, public FitsENVISMap {
+public:
+ FitsENVISMMap(const char* hdr, const char* fn) :
+ FitsSMMap(hdr,fn), FitsENVISMap() {}
+};
+
+class FitsFitsNextSMMap : public FitsFitsNextSMap {
+public:
+ FitsFitsNextSMMap(FitsFile* prev) : FitsFitsNextSMap(prev) {}
+};
+
+#endif
diff --git a/fitsy++/socket.C b/fitsy++/socket.C
new file mode 100644
index 0000000..cbee2c4
--- /dev/null
+++ b/fitsy++/socket.C
@@ -0,0 +1,27 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "socket.h"
+
+#ifndef __WIN32
+
+FitsSocket::FitsSocket(int s, const char* ext)
+{
+ parse(ext);
+ if (!valid_)
+ return;
+
+ stream_ = s;
+
+ valid_ = stream_ ? 1 : 0;
+}
+
+#else
+
+FitsSocket::FitsSocket(int s, const char* ext)
+{
+ valid_ = 0;
+}
+
+#endif
diff --git a/fitsy++/socket.h b/fitsy++/socket.h
new file mode 100644
index 0000000..ce85942
--- /dev/null
+++ b/fitsy++/socket.h
@@ -0,0 +1,51 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitssocket_h__
+#define __fitssocket_h__
+
+#include "strm.h"
+
+class FitsSocket : public virtual FitsStream<int> {
+public:
+ FitsSocket(int, const char*);
+};
+
+class FitsFitsSocket : public FitsSocket, public FitsFitsStream<int> {
+public:
+ FitsFitsSocket(int s, const char* ext, ScanMode mode, FlushMode flush)
+ : FitsSocket(s, ext), FitsFitsStream<int>(mode, flush) {}
+};
+
+class FitsFitsNextSocket : public FitsFitsNextStream<int> {
+public:
+ FitsFitsNextSocket(FitsFile* prev) : FitsFitsNextStream<int>(prev) {}
+};
+
+class FitsArrSocket : public FitsSocket, public FitsArrStream<int> {
+public:
+ FitsArrSocket(int s, const char* ext, FlushMode flush)
+ : FitsSocket(s, ext), FitsArrStream<int>(flush) {}
+};
+
+class FitsNRRDSocket : public FitsSocket, public FitsNRRDStream<int> {
+public:
+ FitsNRRDSocket(int s, const char* ext, FlushMode flush)
+ : FitsSocket(s, ext), FitsNRRDStream<int>(flush) {}
+};
+
+class FitsMosaicSocket : public FitsSocket, public FitsMosaicStream<int> {
+public:
+ FitsMosaicSocket(int s, FlushMode flush)
+ : FitsSocket(s, ""), FitsMosaicStream<int>(flush) {}
+};
+
+class FitsMosaicNextSocket : public FitsMosaicNextStream<int> {
+public:
+ FitsMosaicNextSocket(FitsFile* prev, FlushMode flush)
+ : FitsMosaicNextStream<int>(prev, flush) {}
+};
+
+#endif
+
diff --git a/fitsy++/socketgz.C b/fitsy++/socketgz.C
new file mode 100644
index 0000000..56dc4da
--- /dev/null
+++ b/fitsy++/socketgz.C
@@ -0,0 +1,142 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "socketgz.h"
+#include "util.h"
+
+#ifndef __WIN32
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
+#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define RESERVED 0xE0 /* bits 5..7: reserved */
+
+FitsSocketGZ::FitsSocketGZ(int s, const char* ext)
+{
+ parse(ext);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ if (!s)
+ return;
+
+ stream_ = new gzStream_;
+ stream_->id = s;
+ stream_->transparent = 0;
+ memset(stream_->header,'\0',2);
+ stream_->useHeader = 0;
+ stream_->buf = new unsigned char[B4KB];
+
+ // magic bytes
+ if (recv(stream_->id , stream_->header, 2, 0) != 2) {
+ internalError("Fitsy++ socketgz can't read magic bytes in header");
+ return;
+ }
+
+ if (stream_->header[0] != 0x1f || stream_->header[1] != 0x8b) {
+ stream_->transparent = 1;
+ stream_->useHeader = 1;
+ }
+ else {
+ ((z_stream*)stream_)->next_in = NULL;
+ ((z_stream*)stream_)->avail_in = 0;
+ ((z_stream*)stream_)->zalloc = NULL;
+ ((z_stream*)stream_)->zfree = NULL;
+ ((z_stream*)stream_)->opaque = NULL;
+
+ if (inflateInit2((z_stream*)stream_, -MAX_WBITS) != Z_OK) {
+ internalError("Fitsy++ socketgz inflateInit error");
+ return;
+ }
+
+ unsigned char buf[128];
+
+ // method/flags
+ if (recv(stream_->id , buf, 2, 0) != 2) {
+ internalError("Fitsy++ socketgz can't read method/flags bytes in header");
+ return;
+ }
+ int method = buf[0];
+ int flags = buf[1];
+
+ if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
+ internalError("Fitsy++ socketgz bad method/flags");
+ return;
+ }
+
+ // Discard time, xflags and OS code
+ if (recv(stream_->id , buf, 6, 0) != 6) {
+ internalError("Fitsy++ socketgz can't read time/xflags/os bytes in header");
+ return;
+ }
+
+ // skip the extra field
+ if ((flags & EXTRA_FIELD) != 0) {
+ if (recv(stream_->id , buf, 2, 0) != 2) {
+ internalError("Fitsy++ socketgz can't read extra field length bytes in header");
+ return;
+ }
+
+ int len = buf[0];
+ len += buf[1]<<8;
+
+ if (recv(stream_->id , buf, len, 0) != len) {
+ internalError("Fitsy++ socketgz can't read extra field bytes in header");
+ return;
+ }
+ }
+
+ // skip the original file name
+ if ((flags & ORIG_NAME) != 0) {
+ while (recv(stream_->id , buf, 1, 0) == 1 && buf[0] != 0) ;
+ }
+
+ // skip the .gz file comment
+ if ((flags & COMMENT) != 0) {
+ while (recv(stream_->id , buf, 1, 0) == 1 && buf[0] != 0) ;
+ }
+
+ // skip the header crc
+ if ((flags & HEAD_CRC) != 0) {
+ if (recv(stream_->id , buf, 2, 0) != 2) {
+ internalError("Fitsy++ socketgz can't read header crc bytes in header");
+ return;
+ }
+ }
+ }
+
+ if (DebugGZ)
+ cerr << "inflateInt Complete" << endl;
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsSocketGZ::~FitsSocketGZ()
+{
+ if (stream_->buf)
+ delete [] stream_->buf;
+ if (stream_)
+ delete stream_;
+ stream_ = NULL;
+}
+
+#else
+
+FitsSocketGZ::FitsSocketGZ(int s, const char* ext)
+{
+ valid_ =0;
+}
+
+FitsSocketGZ::~FitsSocketGZ() {}
+
+#endif
diff --git a/fitsy++/socketgz.h b/fitsy++/socketgz.h
new file mode 100644
index 0000000..dc729fc
--- /dev/null
+++ b/fitsy++/socketgz.h
@@ -0,0 +1,48 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitssocketgz_h__
+#define __fitssocketgz_h__
+
+#include "strm.h"
+
+class FitsSocketGZ : public virtual FitsStream<gzStream> {
+public:
+ FitsSocketGZ(int, const char*);
+ virtual ~FitsSocketGZ();
+};
+
+class FitsFitsSocketGZ : public FitsSocketGZ,
+ public FitsFitsStream<gzStream> {
+public:
+ FitsFitsSocketGZ(int s, const char* ext, ScanMode mode, FlushMode flush)
+ : FitsSocketGZ(s, ext), FitsFitsStream<gzStream>(mode, flush) {}
+};
+
+class FitsFitsNextSocketGZ : public FitsFitsNextStream<gzStream> {
+public:
+ FitsFitsNextSocketGZ(FitsFile* prev) : FitsFitsNextStream<gzStream>(prev) {}
+};
+
+class FitsArrSocketGZ : public FitsSocketGZ, public FitsArrStream<gzStream> {
+public:
+ FitsArrSocketGZ(int s, const char* ext, FlushMode flush)
+ : FitsSocketGZ(s, ext), FitsArrStream<gzStream>(flush) {}
+};
+
+class FitsMosaicSocketGZ : public FitsSocketGZ,
+ public FitsMosaicStream<gzStream> {
+public:
+ FitsMosaicSocketGZ(int s, FlushMode flush)
+ : FitsSocketGZ(s, ""), FitsMosaicStream<gzStream>(flush) {}
+};
+
+class FitsMosaicNextSocketGZ : public FitsMosaicNextStream<gzStream> {
+public:
+ FitsMosaicNextSocketGZ(FitsFile* prev, FlushMode flush)
+ : FitsMosaicNextStream<gzStream>(prev, flush) {}
+};
+
+#endif
+
diff --git a/fitsy++/sshare.C b/fitsy++/sshare.C
new file mode 100644
index 0000000..f2b94d9
--- /dev/null
+++ b/fitsy++/sshare.C
@@ -0,0 +1,149 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "sshare.h"
+#include "util.h"
+
+#if (HAVE_SYS_SHM_H && !__WIN32)
+#include <sys/types.h>
+#include <sys/shm.h>
+#include <sys/ipc.h>
+
+FitsSShareID::FitsSShareID(int hdrid, int shmid, const char* filter)
+{
+ // reset
+ valid_ =0;
+
+ {
+ // find size
+ struct shmid_ds info;
+ if (shmctl(hdrid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shctl failed");
+ return;
+ }
+ hmapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(hmapdata_ = (char*)shmat(hdrid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ {
+ parse(filter);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ // so far so good
+ valid_ = 1;
+}
+
+FitsSShareID::~FitsSShareID()
+{
+ shmdt(mapdata_);
+}
+
+FitsSShareKey::FitsSShareKey(int hdr, int key, const char* filter)
+{
+ // reset
+ valid_ =0;
+
+ {
+ // get shmid
+ int shmid;
+ if ((shmid = shmget(hdr, 0, 0)) < 0) {
+ internalError("Fitsy++ sshare shmget failed");
+ return;
+ }
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ {
+ parse(filter);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ // get shmid
+ int shmid;
+ if ((shmid = shmget(key, 0, 0)) < 0) {
+ internalError("Fitsy++ sshare shmget failed");
+ return;
+ }
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shmctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ // so far so good
+ valid_ = 1;
+}
+
+FitsSShareKey::~FitsSShareKey()
+{
+ shmdt(mapdata_);
+}
+
+#else
+
+FitsSShareID::FitsSShareID(int hdrid, int shmid, const char* filter)
+{
+ valid_ = 0;
+}
+
+FitsSShareID::~FitsSShareID() {}
+
+FitsSShareKey::FitsSShareKey(int hdr, int key, const char* filter)
+{
+ valid_ = 0;
+}
+
+FitsSShareKey::~FitsSShareKey() {}
+
+#endif
diff --git a/fitsy++/sshare.h b/fitsy++/sshare.h
new file mode 100644
index 0000000..c223a9d
--- /dev/null
+++ b/fitsy++/sshare.h
@@ -0,0 +1,44 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitssshare_h__
+#define __fitssshare_h__
+
+#include "smap.h"
+
+class FitsSShareID : public virtual FitsSMap {
+public:
+ FitsSShareID(int, int, const char*);
+ virtual ~FitsSShareID();
+};
+
+class FitsSShareKey : public virtual FitsSMap {
+public:
+ FitsSShareKey(int, int, const char*);
+ virtual ~FitsSShareKey();
+};
+
+class FitsFitsSShare : public virtual FitsSMap, public FitsFitsSMap {
+ public:
+ FitsFitsSShare() : FitsSMap(), FitsFitsSMap(FitsHead::SHARE) {}
+};
+
+class FitsFitsNextSShare : public FitsFitsNextSMap {
+public:
+ FitsFitsNextSShare(FitsFile* prev) : FitsFitsNextSMap(prev) {}
+};
+
+class FitsFitsSShareID : public FitsSShareID, public FitsFitsSShare {
+public:
+ FitsFitsSShareID(int hdrid, int shmid, const char* filter)
+ : FitsSShareID(hdrid, shmid, filter), FitsFitsSShare() {}
+};
+
+class FitsFitsSShareKey : public FitsSShareKey, public FitsFitsSShare {
+public:
+ FitsFitsSShareKey(int hdr, int key, const char* filter)
+ : FitsSShareKey(hdr, key, filter), FitsFitsSShare() {}
+};
+
+#endif
diff --git a/fitsy++/strm.C b/fitsy++/strm.C
new file mode 100644
index 0000000..9560d5e
--- /dev/null
+++ b/fitsy++/strm.C
@@ -0,0 +1,803 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <string.h>
+#include <stdio.h>
+
+#ifndef __WIN32
+#include <sys/socket.h>
+#endif
+
+#include <tcl.h>
+
+#include "strm.h"
+#include "util.h"
+
+template<class T> FitsStream<T>::FitsStream()
+{
+ stream_ =0;
+ flush_ = NOFLUSH;
+ dataManage_ = 0;
+}
+
+template<class T> FitsStream<T>::~FitsStream()
+{
+ if (dataManage_ && data_)
+ delete [] (T*)data_;
+}
+
+// FILE*
+
+template <> size_t FitsStream<FILE*>::read(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = fread(where+rr, 1, (ss>B1MB) ? B1MB : ss, stream_);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+template <> void FitsStream<FILE*>::close()
+{
+ fclose(stream_);
+}
+
+// Socket
+
+#ifndef __WIN32
+
+template <> size_t FitsStream<int>::read(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr =0;
+ int r;
+
+ do {
+ r = recv(stream_ , where+rr, (ss>B4KB) ? B4KB : ss, 0);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+#else
+
+template <> size_t FitsStream<int>::read(char* where, size_t size)
+{
+ return 0;
+}
+
+#endif
+
+template <> void FitsStream<int>::close() {}
+
+// gzStream
+
+#ifndef __WIN32
+
+template <> size_t FitsStream<gzStream>::read(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ if (stream_->transparent) {
+ if (stream_->useHeader) {
+ memcpy(where,stream_->header,2);
+ ss -= 2;
+ rr += 2;
+ stream_->useHeader = 0;
+ }
+
+ do {
+ r = recv(stream_->id , where+rr, (ss>B4KB) ? B4KB : ss, 0);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+ }
+ else {
+ ((z_stream*)stream_)->avail_out = size;
+ ((z_stream*)stream_)->next_out = (unsigned char*)where;
+
+ if (DebugGZ)
+ cerr << "***read init " << ((z_stream*)stream_)->avail_out
+ << " bytes" << endl;
+
+ do {
+ if (((z_stream*)stream_)->avail_in == 0) {
+ ((z_stream*)stream_)->next_in = stream_->buf;
+ int aa = recv(stream_->id , stream_->buf, B4KB, 0);
+ if (aa<0)
+ return rr;
+
+ ((z_stream*)stream_)->avail_in = aa;
+ if (DebugGZ)
+ cerr << " read from socket " << aa << " bytes" << endl;
+ }
+
+ if (DebugGZ)
+ cerr << " inflate Start: avail_in "
+ << ((z_stream*)stream_)->avail_in
+ << " avail_out " << ((z_stream*)stream_)->avail_out << endl;
+
+ int before = ((z_stream*)stream_)->avail_out;
+ int result = inflate(((z_stream*)stream_), Z_NO_FLUSH);
+ r = before - ((z_stream*)stream_)->avail_out;
+ rr += r;
+
+ switch (result) {
+ case Z_OK:
+ if (DebugGZ)
+ cerr << " inflate OK: avail_in " << ((z_stream*)stream_)->avail_in
+ << " avail_out " << ((z_stream*)stream_)->avail_out << endl;
+ break;
+ case Z_STREAM_END:
+ if (DebugGZ)
+ cerr << " inflate STRM_END: avail_in "
+ << ((z_stream*)stream_)->avail_in
+ << " avail_out " << ((z_stream*)stream_)->avail_out
+ << " total_in " << ((z_stream*)stream_)->total_in
+ << " total_out " << ((z_stream*)stream_)->total_out << endl;
+ return rr;
+ default:
+ internalError("Fitsy++ strm inflate error");
+ return rr;
+ }
+ } while (r>0 && rr<size);
+
+ if (DebugGZ)
+ cerr << "***read finish" << endl;
+
+ return rr;
+ }
+}
+
+template <> void FitsStream<gzStream>::close()
+{
+ if (!stream_->transparent) {
+ if (inflateEnd((z_stream*)stream_) != Z_OK)
+ internalError("Fitsy++ strm inflateEnd error");
+
+ if (DebugGZ)
+ cerr << "inflateEnd: avail_in " << ((z_stream*)stream_)->avail_in
+ << " avail_out " << ((z_stream*)stream_)->avail_out << endl;
+ }
+}
+
+#else
+
+template <> size_t FitsStream<gzStream>::read(char* where, size_t size)
+{
+ return 0;
+}
+template <> void FitsStream<gzStream>::close() {}
+
+#endif
+
+// Tcl_Channel
+
+template <> size_t FitsStream<Tcl_Channel>::read(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = Tcl_Read(stream_, where+rr, (ss>B1MB) ? B1MB : ss);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+template <> void FitsStream<Tcl_Channel>::close() {}
+
+// gzFile
+
+template <> size_t FitsStream<gzFile>::read(char* where, size_t size)
+{
+ // size_t size is unsigned
+ long long ss =size;
+ size_t rr = 0;
+ int r = 0;
+
+ do {
+ r = gzread(stream_, where+rr, (ss>B1MB) ? B1MB : ss);
+ ss -= r;
+ rr += r;
+ } while (r>0 && rr<size);
+
+ return rr;
+}
+
+template <> void FitsStream<gzFile>::close()
+{
+ gzclose(stream_);
+}
+
+template<class T> FitsHead* FitsStream<T>::headRead()
+{
+ // read first block
+ char* cards = new char[FTY_BLOCK];
+ if (!cards)
+ return NULL;
+
+ memset(cards, ' ', FTY_BLOCK);
+ if (read(cards, FTY_BLOCK) != FTY_BLOCK) {
+ delete [] cards;
+ return NULL;
+ }
+
+ // simple FITS file check
+ if (strncmp(cards, "SIMPLE =", 9) && strncmp(cards, "XTENSION=", 9)) {
+ delete [] cards;
+ return NULL;
+ }
+
+ // read remaining blocks
+ int numblks = 1;
+ char* current = cards;
+ while (1) {
+ if (findEnd(current))
+ break;
+
+ // this is check
+ // for TCL channels, the stream gets corrupted, so END is never found
+ // so bail out after an extreme number of blocks have been read
+ //
+ // this does not work because some fits files have 100's or 1000's of
+ // history/comments. lets hope a corrupted stream is caught below
+ // if (numblks>10) {
+ // delete [] cards;
+ // return NULL;
+ // }
+
+ char* tmp = new char[(numblks+1)*FTY_BLOCK];
+ memcpy(tmp, cards, numblks*FTY_BLOCK);
+ delete [] cards;
+ cards = tmp;
+ current = cards + numblks*FTY_BLOCK;
+ memset(current, ' ', FTY_BLOCK);
+
+ if (read(current, FTY_BLOCK) != FTY_BLOCK) {
+ delete [] cards;
+ return NULL;
+ }
+
+ numblks++;
+ }
+
+ // create header
+ FitsHead* fits = new FitsHead(cards, numblks*FTY_BLOCK, FitsHead::ALLOC);
+ if (!fits->isValid()) {
+ delete fits;
+ return NULL;
+ }
+
+ return fits;
+}
+
+template<class T> int FitsStream<T>::dataRead(size_t bytes, int validate)
+{
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+ dataManage_ = 0;
+
+ if (!bytes)
+ return 0;
+
+ data_ = new char[bytes];
+ if (!data_)
+ return 0;
+
+ size_t rr = read((char*)data_, bytes);
+ if (validate && rr != bytes) {
+ delete (char*)data_;
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+ dataManage_ = 0;
+
+ return 0;
+ }
+
+ dataSize_ = bytes;
+ dataManage_ = 1;
+
+ return 1;
+}
+
+template<class T> void FitsStream<T>::dataSkip(size_t bytes)
+{
+ // size_t bytes is unsigned
+ if (bytes) {
+ char block[FTY_BLOCK];
+
+ do {
+ read(block, (bytes < FTY_BLOCK ? bytes : FTY_BLOCK));
+ if (bytes>FTY_BLOCK)
+ bytes -= FTY_BLOCK;
+ else
+ break;
+ } while (1);
+ }
+}
+
+template<class T> void FitsStream<T>::dataSkipBlock(size_t blk)
+{
+ char block[FTY_BLOCK];
+ for (size_t ii=0; ii<blk; ii++)
+ read(block, FTY_BLOCK);
+}
+
+template<class T> void FitsStream<T>::skipEnd()
+{
+ char block[FTY_BLOCK];
+
+ int bytes;
+ do
+ bytes = read(block, FTY_BLOCK);
+ while (bytes > 0);
+}
+
+template<class T> void FitsStream<T>::found()
+{
+ // only read allbytes, since the data seg maybe short
+ if (!this->dataRead(head_->allbytes())) {
+ error();
+ return;
+ }
+
+ // read any dead space til next block
+ if (head_->padbytes()>0)
+ this->dataSkip(head_->padbytes());
+
+ inherit_ = head_->inherit();
+ valid_ = 1;
+
+ if (flush_ == FLUSH)
+ skipEnd();
+}
+
+template<class T> void FitsStream<T>::error()
+{
+ // try to clean up
+ if ((flush_ == FLUSH) && (head_ || primary_))
+ skipEnd();
+
+ if (manageHead_ && head_)
+ delete head_;
+ head_ = NULL;
+
+ if (managePrimary_ && primary_)
+ delete primary_;
+ primary_ = NULL;
+
+ data_ = NULL;
+
+ dataSize_ = 0;
+ dataSkip_ = 0;
+ dataManage_ = 0;
+
+ valid_ = 0;
+}
+
+template class FitsStream<FILE*>;
+template class FitsStream<Tcl_Channel>;
+template class FitsStream<int>;
+template class FitsStream<gzFile>;
+template class FitsStream<gzStream>;
+
+template<class T> FitsFitsStream<T>::FitsFitsStream(FitsFile::ScanMode mode,
+ FitsFile::FlushMode f)
+{
+ if (!this->valid_)
+ return;
+
+ this->flush_ = f;
+
+ if (mode == this->EXACT || this->pExt_ || this->pIndex_>-1)
+ processExact();
+ else
+ processRelax();
+}
+
+template<class T> void FitsFitsStream<T>::processExact()
+{
+ if (!(this->pExt_ || (this->pIndex_>0))) {
+
+ // we are only looking for a primary image
+ if ((this->head_ = this->headRead())) {
+ this->found();
+ return;
+ }
+ }
+ else {
+
+ // we are looking for an extension
+ // keep the primary header
+ this->primary_ = this->headRead();
+ this->managePrimary_ = 1;
+ if (!this->primary_) {
+ this->error();
+ return;
+ }
+ this->dataSkipBlock(this->primary_->datablocks());
+
+ if (this->pExt_) {
+ while (1) {
+ if (!(this->head_ = this->headRead())) {
+ this->error();
+ return;
+ }
+ this->ext_++;
+
+ if (this->head_->extname()) {
+ char* a = toUpper(this->head_->extname());
+ char* b = toUpper(this->pExt_);
+ if (!strncmp(a,b,strlen(b))) {
+ delete [] a;
+ delete [] b;
+ this->found();
+ return;
+ }
+ delete [] a;
+ delete [] b;
+ }
+
+ this->dataSkipBlock(this->head_->datablocks());
+ delete this->head_;
+ this->head_ = NULL;
+ }
+ }
+ else {
+ for (int i=1; i<this->pIndex_; i++) {
+ if (!(this->head_ = this->headRead())) {
+ this->error();
+ return;
+ }
+ this->ext_++;
+
+ this->dataSkipBlock(this->head_->datablocks());
+ delete this->head_;
+ this->head_ = NULL;
+ }
+
+ if ((this->head_ = this->headRead())) {
+ this->ext_++;
+ this->found();
+ return;
+ }
+ }
+ }
+
+ // we must have an error
+ this->error();
+}
+
+template<class T> void FitsFitsStream<T>::processRelax()
+{
+ // check to see if there is an image in the primary
+ if (!(this->head_ = this->headRead())) {
+ this->error();
+ return;
+ }
+ else {
+ if (this->head_->isValid() &&
+ this->head_->naxes() > 0 &&
+ this->head_->naxis(0) > 0 &&
+ this->head_->naxis(1) > 0) {
+ this->found();
+ return;
+ }
+ }
+
+ // ok, no image, save primary and lets check extensions
+ this->primary_ = this->head_;
+ this->managePrimary_ = 1;
+ this->dataSkipBlock(this->head_->datablocks());
+ this->head_ = NULL;
+
+ // ok, no image, lets check extensions
+ while (1) {
+ if (!(this->head_ = this->headRead())) {
+ this->error();
+ return;
+ }
+ this->ext_++;
+
+ if (this->head_->isImage()) {
+ this->found();
+ return;
+ }
+
+ // else, check for compressed image
+ if (this->head_->isBinTable() && this->head_->find("ZIMAGE")) {
+ this->found();
+ return;
+ }
+
+ // else, check for bin table named STDEVT, EVENTS, RAYEVENT
+ if (this->head_->isBinTable() && this->head_->extname()) {
+ char* a = toUpper(this->head_->extname());
+ if (!strncmp("STDEVT", a, 6) ||
+ !strncmp("EVENTS", a, 6) ||
+ !strncmp("RAYEVENT", a, 8)) {
+ delete [] a;
+ this->found();
+ return;
+ }
+ else
+ delete [] a;
+ }
+
+ // else, check for bin table with keyword PIXTYPE = 'HEALPIX '
+ if (this->head_->isBinTable() && this->head_->find("PIXTYPE") &&
+ (!strncmp(this->head_->getString("PIXTYPE"),"HEALPIX",4))) {
+ this->found();
+ return;
+ }
+
+ // else, check for bin table with keyword NSIDE (also HEALPIX)
+ if (this->head_->isBinTable() && this->head_->find("NSIDE")) {
+ this->found();
+ return;
+ }
+
+ this->dataSkipBlock(this->head_->datablocks());
+ delete this->head_;
+ this->head_ = NULL;
+ }
+
+ this->error();
+}
+
+template class FitsFitsStream<FILE*>;
+template class FitsFitsStream<Tcl_Channel>;
+template class FitsFitsStream<int>;
+template class FitsFitsStream<gzFile>;
+template class FitsFitsStream<gzStream>;
+
+template<class T> FitsFitsNextStream<T>::FitsFitsNextStream(FitsFile* p)
+{
+ FitsStream<T>* prev = (FitsStream<T>*)p;
+
+ this->primary_ = prev->primary();
+ this->managePrimary_ = 0;
+
+ this->head_ = prev->head();
+ this->manageHead_ = 0;
+
+ FitsImageHDU* hdu = (FitsImageHDU*)this->head_->hdu();
+ this->data_ = (char*)prev->data() + hdu->imgbytes();
+ this->dataSize_ = 0;
+ this->dataSkip_ = 0;
+
+ this->ext_ = prev->ext();
+ this->inherit_ = prev->inherit();
+ this->byteswap_ = prev->byteswap();
+ this->endian_ = prev->endian();
+ this->valid_ = 1;
+
+ this->pcoord_ = prev->pcoord();
+ this->pxvalid_ = prev->pxvalid();
+ this->pxmin_ = prev->pxmin();
+ this->pxmax_ = prev->pxmax();
+ this->pyvalid_ = prev->pyvalid();
+ this->pymin_ = prev->pymin();
+ this->pymax_ = prev->pymax();
+ this->pzvalid_ = prev->pzvalid();
+ this->pzmin_ = prev->pzmin();
+ this->pzmax_ = prev->pzmax();
+ this->pbvalid_ = prev->pbvalid();
+ this->pblock_ = prev->pblock();
+
+ this->stream_ = prev->stream();
+ this->flush_ = prev->flush();
+ this->dataManage_ = 0;
+}
+
+template class FitsFitsNextStream<FILE*>;
+template class FitsFitsNextStream<Tcl_Channel>;
+template class FitsFitsNextStream<int>;
+template class FitsFitsNextStream<gzFile>;
+template class FitsFitsNextStream<gzStream>;
+
+template<class T> FitsArrStream<T>::FitsArrStream(FitsFile::FlushMode f)
+{
+ if (!this->valid_)
+ return;
+
+ this->flush_ = f;
+
+ this->valid_=0;
+
+ // check to see if we have a nonzero width, height, and bitpix
+ if (!this->validParams()) {
+ return;
+ }
+
+ // skip header
+ if (this->pSkip_)
+ this->dataSkip(this->pSkip_);
+
+ // read data
+ if (!this->dataRead((size_t)this->pWidth_*this->pHeight_*this->pDepth_*abs(this->pBitpix_)/8)) {
+ if ((this->flush_ == this->FLUSH) && this->data_)
+ this->skipEnd();
+ return;
+ }
+
+ // create blank header
+ this->head_ = new FitsHead(this->pWidth_, this->pHeight_,
+ this->pDepth_, this->pBitpix_);
+ if (!this->head_->isValid()) {
+ this->error();
+ return;
+ }
+
+ // do we need to byteswap?
+ this->setByteSwap();
+
+ // made it this far, must be good
+ this->valid_ = 1;
+
+ if (this->flush_ == this->FLUSH)
+ this->skipEnd();
+}
+
+template class FitsArrStream<FILE*>;
+template class FitsArrStream<Tcl_Channel>;
+template class FitsArrStream<int>;
+template class FitsArrStream<gzFile>;
+template class FitsArrStream<gzStream>;
+
+template<class T> FitsNRRDStream<T>::FitsNRRDStream(FitsFile::FlushMode f)
+{
+ if (!this->valid_)
+ return;
+
+ this->flush_ = f;
+
+ this->valid_=0;
+
+ // header
+ {
+ char buf[1024];
+ char* dptr = buf;
+ int cnt =0;
+ do {
+ int cc = this->read(dptr,1);
+ if (cc != 1 || (*dptr == '\n' && *(dptr-1) == '\n')) {
+ break;
+ }
+ cnt++;
+ dptr++;
+ } while (cnt<1024);
+ *dptr = '\0';
+
+ string x(buf);
+ istringstream str(x);
+ this->parseNRRD(str);
+ }
+
+ // check to see if we have a nonzero width, height, and bitpix
+ if (!this->validParams())
+ return;
+
+ // read data
+ this->dataRead((size_t)this->pWidth_*this->pHeight_*this->pDepth_*abs(this->pBitpix_)/8, 0);
+
+ // create blank header
+ this->head_ = new FitsHead(this->pWidth_, this->pHeight_,
+ this->pDepth_, this->pBitpix_);
+ if (!this->head_->isValid()) {
+ this->error();
+ return;
+ }
+
+ // do we need to byteswap?
+ this->setByteSwap();
+
+ // made it this far, must be good
+ this->valid_ = 1;
+
+ if (this->flush_ == this->FLUSH)
+ this->skipEnd();
+}
+
+template class FitsNRRDStream<FILE*>;
+template class FitsNRRDStream<Tcl_Channel>;
+template class FitsNRRDStream<int>;
+template class FitsNRRDStream<gzFile>;
+template class FitsNRRDStream<gzStream>;
+
+template<class T> FitsMosaicStream<T>::FitsMosaicStream(FitsFile::FlushMode f)
+{
+ if (!this->valid_)
+ return;
+
+ this->flush_ = f;
+ this->primary_ = this->headRead();
+ this->managePrimary_ = 1;
+ if (!(this->primary_ && this->primary_->isValid())) {
+ this->error();
+ return;
+ }
+ this->dataSkipBlock(this->primary_->datablocks());
+
+ // first extension
+ this->head_ = this->headRead();
+ if (!(this->head_ && this->head_->isValid())) {
+ this->error();
+ return;
+ }
+ this->ext_++;
+
+ // be sure to read all blocks, so that the next call starts on a boundary
+ if (!this->dataRead(this->head_->datablocks()*FTY_BLOCK)) {
+ this->error();
+ return;
+ }
+
+ // don't flush, more to come
+ this->inherit_ = this->head_->inherit();
+ this->valid_ = 1;
+}
+
+template class FitsMosaicStream<FILE*>;
+template class FitsMosaicStream<Tcl_Channel>;
+template class FitsMosaicStream<int>;
+template class FitsMosaicStream<gzFile>;
+template class FitsMosaicStream<gzStream>;
+
+template<class T> FitsMosaicNextStream<T>::FitsMosaicNextStream(FitsFile* p,
+ FitsFile::FlushMode f)
+{
+ this->flush_ = f;
+ FitsStream<T>* prev = (FitsStream<T>*)p;
+ this->primary_ = prev->primary();
+ this->managePrimary_ = 0;
+ this->stream_ = prev->stream();
+ this->ext_ = prev->ext();
+
+ this->head_ = this->headRead();
+ if (!(this->head_ && this->head_->isValid())) {
+ this->error();
+ return;
+ }
+ this->ext_++;
+
+ // be sure to read all blocks, so that the next call starts on a boundary
+ if (!this->dataRead(this->head_->datablocks()*FTY_BLOCK)) {
+ this->error();
+ return;
+ }
+
+ this->inherit_ = this->head_->inherit();
+ this->valid_ = 1;
+}
+
+template class FitsMosaicNextStream<FILE*>;
+template class FitsMosaicNextStream<Tcl_Channel>;
+template class FitsMosaicNextStream<int>;
+template class FitsMosaicNextStream<gzFile>;
+template class FitsMosaicNextStream<gzStream>;
diff --git a/fitsy++/strm.h b/fitsy++/strm.h
new file mode 100644
index 0000000..22274ed
--- /dev/null
+++ b/fitsy++/strm.h
@@ -0,0 +1,89 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsstream_h__
+#define __fitsstream_h__
+
+#include "file.h"
+#include "zlib.h"
+
+typedef struct gzStream_ {
+ z_stream zstream;
+ int id;
+ int transparent;
+ unsigned char header[2];
+ int useHeader;
+ unsigned char* buf;
+} *gzStream;
+
+template<class T>
+class FitsStream : public FitsFile {
+ protected:
+ T stream_;
+ FitsFile::FlushMode flush_;
+ int dataManage_; // flag, true if we manage data
+
+ FitsHead* headRead();
+ int dataRead(size_t bytes, int validate =1);
+ void dataSkip(size_t);
+ void dataSkipBlock(size_t);
+ void skipEnd();
+
+ size_t read(char*, size_t);
+ void close();
+ void found();
+ void error();
+
+public:
+ FitsStream();
+ virtual ~FitsStream();
+
+ T stream() {return stream_;}
+ FitsFile::FlushMode flush() {return flush_;}
+ int dataManage() {return dataManage_;}
+
+ void done() {close();}
+};
+
+template<class T>
+class FitsFitsStream : public virtual FitsStream<T> {
+protected:
+ void processExact();
+ void processRelax();
+
+public:
+ FitsFitsStream(FitsFile::ScanMode, FitsFile::FlushMode);
+};
+
+template<class T>
+class FitsFitsNextStream : public FitsStream<T> {
+public:
+ FitsFitsNextStream(FitsFile* prev);
+};
+
+template<class T>
+class FitsArrStream : public virtual FitsStream<T> {
+public:
+ FitsArrStream(FitsFile::FlushMode);
+};
+
+template<class T>
+class FitsNRRDStream : public virtual FitsStream<T> {
+public:
+ FitsNRRDStream(FitsFile::FlushMode);
+};
+
+template<class T>
+class FitsMosaicStream : public virtual FitsStream<T> {
+public:
+ FitsMosaicStream(FitsFile::FlushMode);
+};
+
+template<class T>
+class FitsMosaicNextStream : public FitsStream<T> {
+public:
+ FitsMosaicNextStream(FitsFile* prev, FitsFile::FlushMode);
+};
+
+#endif
diff --git a/fitsy++/var.C b/fitsy++/var.C
new file mode 100644
index 0000000..4cf1041
--- /dev/null
+++ b/fitsy++/var.C
@@ -0,0 +1,53 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include <tcl.h>
+
+#include "var.h"
+
+FitsVar::FitsVar(Tcl_Interp* interp, const char* var, const char* fn)
+{
+ parse(fn);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ obj = Tcl_GetVar2Ex(interp, (char*)var, NULL,
+ TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG);
+ if (!obj)
+ return;
+
+ // just in case
+ Tcl_ConvertToType(interp, obj, Tcl_GetObjType("bytearray"));
+
+ typedef struct ByteArray {
+ int used; /* The number of bytes used in the byte
+ * array. */
+ int allocated; /* The amount of space actually allocated
+ * minus 1 byte. */
+ unsigned char bytes[4]; /* The array of bytes. The actual size of
+ * this field depends on the 'allocated' field
+ * above. */
+ } ByteArray;
+
+ ByteArray* ba = (ByteArray*)(obj->internalRep.otherValuePtr);
+ mapsize_ = ba->used;
+ mapdata_ = (char*)ba->bytes;
+
+ Tcl_IncrRefCount(obj);
+
+ // so far, so good
+ valid_ = 1;
+}
+
+FitsVar::~FitsVar()
+{
+ if (obj)
+ Tcl_DecrRefCount(obj);
+}
+
+
+
diff --git a/fitsy++/var.h b/fitsy++/var.h
new file mode 100644
index 0000000..8d2caff
--- /dev/null
+++ b/fitsy++/var.h
@@ -0,0 +1,53 @@
+// Copyright (C) 1999-2018
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#ifndef __fitsvar_h__
+#define __fitsvar_h__
+
+#include "map.h"
+
+class FitsVar : public virtual FitsMap {
+ Tcl_Obj* obj;
+
+public:
+ FitsVar(Tcl_Interp*, const char*, const char*);
+ virtual ~FitsVar();
+};
+
+class FitsFitsVar : public FitsVar, public FitsFitsMap {
+public:
+ FitsFitsVar(Tcl_Interp* interp, const char* var, const char* fn,
+ ScanMode mode)
+ : FitsVar(interp, var, fn), FitsFitsMap(mode) {}
+};
+
+class FitsFitsNextVar : public FitsFitsNextMap {
+public:
+ FitsFitsNextVar(FitsFile* prev) : FitsFitsNextMap(prev) {}
+};
+
+class FitsArrVar : public FitsVar, public FitsArrMap {
+public:
+ FitsArrVar(Tcl_Interp* interp, const char* var, const char* fn)
+ : FitsVar(interp, var, fn), FitsArrMap() {}
+};
+
+class FitsNRRDVar : public FitsVar, public FitsNRRDMap {
+public:
+ FitsNRRDVar(Tcl_Interp* interp, const char* var, const char* fn)
+ : FitsVar(interp, var, fn), FitsNRRDMap() {}
+};
+
+class FitsMosaicVar : public FitsVar, public FitsMosaicMap {
+public:
+ FitsMosaicVar(Tcl_Interp* interp, const char* var, const char* fn)
+ : FitsVar(interp, var, fn), FitsMosaicMap() {}
+};
+
+class FitsMosaicNextVar : public FitsMosaicNextMap {
+public:
+ FitsMosaicNextVar(FitsFile* prev) : FitsMosaicNextMap(prev) {}
+};
+
+#endif
diff --git a/fitsy++/wcs.h b/fitsy++/wcs.h
new file mode 100644
index 0000000..67010df
--- /dev/null
+++ b/fitsy++/wcs.h
@@ -0,0 +1 @@
+// this is dummy include file needed for funtools/filter/filter.h