summaryrefslogtreecommitdiffstats
path: root/tksao
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2018-01-19 22:30:54 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2018-01-19 22:30:54 (GMT)
commit674b5acf07b88489b245d074f9c238e6ae55ce05 (patch)
treef75e57d5b043696366029207b2c35e270fdefba8 /tksao
parentaf56db7f8599b9604e1191927005967437091ebc (diff)
downloadblt-674b5acf07b88489b245d074f9c238e6ae55ce05.zip
blt-674b5acf07b88489b245d074f9c238e6ae55ce05.tar.gz
blt-674b5acf07b88489b245d074f9c238e6ae55ce05.tar.bz2
support WCS-TAB
Diffstat (limited to 'tksao')
-rw-r--r--tksao/fitsy++/column.C21
-rw-r--r--tksao/fitsy++/column.h9
-rw-r--r--tksao/fitsy++/file.h2
-rw-r--r--tksao/fitsy++/hdu.C3
-rw-r--r--tksao/fitsy++/hdu.h2
-rw-r--r--tksao/fitsy++/head.h3
-rw-r--r--tksao/frame/fitsimage.C160
7 files changed, 195 insertions, 5 deletions
diff --git a/tksao/fitsy++/column.C b/tksao/fitsy++/column.C
index 5766bf2..b63b06a 100644
--- a/tksao/fitsy++/column.C
+++ b/tksao/fitsy++/column.C
@@ -195,12 +195,33 @@ FitsBinColumn::FitsBinColumn(FitsHead* head, int i, int offset)
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
diff --git a/tksao/fitsy++/column.h b/tksao/fitsy++/column.h
index 7d55805..358b77e 100644
--- a/tksao/fitsy++/column.h
+++ b/tksao/fitsy++/column.h
@@ -46,6 +46,7 @@ public:
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_;}
@@ -112,12 +113,20 @@ 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 {
diff --git a/tksao/fitsy++/file.h b/tksao/fitsy++/file.h
index e410d92..5b245d0 100644
--- a/tksao/fitsy++/file.h
+++ b/tksao/fitsy++/file.h
@@ -106,6 +106,8 @@ public:
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_;}
diff --git a/tksao/fitsy++/hdu.C b/tksao/fitsy++/hdu.C
index a3e2153..bff1735 100644
--- a/tksao/fitsy++/hdu.C
+++ b/tksao/fitsy++/hdu.C
@@ -28,7 +28,8 @@ FitsHDU::FitsHDU(FitsHead* head)
}
}
- extver_ = head->getInteger("EXTVER", 0);
+ extver_ = head->getInteger("EXTVER", 1);
+ extlevel_ = head->getInteger("EXTLEVEL", 1);
bitpix_ = head->getInteger("BITPIX", 0);
naxes_ = head->getInteger("NAXIS", 0);
diff --git a/tksao/fitsy++/hdu.h b/tksao/fitsy++/hdu.h
index 54863d4..5d957a5 100644
--- a/tksao/fitsy++/hdu.h
+++ b/tksao/fitsy++/hdu.h
@@ -17,6 +17,7 @@ class FitsHDU {
protected:
char* extname_; // EXTNAME keyword
int extver_; // EXTVER keyword
+ int extlevel_; // EXTLEVEL keyword
int bitpix_; // BITPIX keyword
int naxes_; // NAXIS keyword
@@ -40,6 +41,7 @@ public:
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];}
diff --git a/tksao/fitsy++/head.h b/tksao/fitsy++/head.h
index ad61a2a..f5dfdc1 100644
--- a/tksao/fitsy++/head.h
+++ b/tksao/fitsy++/head.h
@@ -59,7 +59,8 @@ public:
int headbytes() {return acard_*FTY_CARDLEN;}
const char* extname() {return hdu_ ? hdu_->extname() : NULL;}
- int extver() {return hdu_ ? hdu_->extver() : 0;}
+ 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;}
diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C
index 78a4dd2..7cee903 100644
--- a/tksao/frame/fitsimage.C
+++ b/tksao/frame/fitsimage.C
@@ -4481,6 +4481,155 @@ double FitsImage::wcsAxAngle(const Vector& vv1, const Vector& vv2)
}
#endif
+static FitsImage* fitsImagePtr =NULL;
+static void fits2TAB(AstFitsChan* chan, const char* extname,
+ int extver, int extlevel, int* status)
+{
+ if (!fitsImagePtr) {
+ *status = 1;
+ return;
+ }
+
+ FitsFile* ptr = fitsImagePtr->fitsFile();
+ FitsFile* ext =NULL;
+ bool first=true;
+ bool found=false;
+ while (!found) {
+ ext = new FitsMosaicNextMMapIncr(ptr);
+ if (!first)
+ delete ptr;
+ first =false;
+
+ // EOF?
+ if (!ext || !ext->isValid()) {
+ if (ext)
+ delete ext;
+
+ *status = 1;
+ return;
+ }
+
+ if (!ext->isBinTable())
+ break;
+
+ const char* name = ext->extname();
+ int ver = ext->extver();
+ int level = ext->extlevel();
+
+ if (name) {
+ if (!strncmp(extname,name,7) && extver==ver && extlevel==level) {
+ found =true;
+ break;
+ }
+ }
+
+ ptr = ext;
+ }
+
+ // ok, found it
+ astClearStatus; // just to make sure
+ astBegin; // start memory management
+
+ AstFitsTable* table = (AstFitsTable*)astFitsTable(NULL,"");
+ FitsBinTableHDU* hdu = (FitsBinTableHDU*)ext->head()->hdu();
+
+ for (int ii=0; ii<hdu->cols(); ii++) {
+ FitsBinColumn* col = (FitsBinColumn*)hdu->find(ii);
+
+ int arr = 1;
+ for (int ii=0; ii<col->tdimM(); ii++)
+ arr *= col->tdimK(ii);
+
+ int type;
+ int size;
+ char* data =NULL;
+ switch (col->type()) {
+ case 'I':
+ type = AST__SINTTYPE;
+ data = (char*)new short[arr];
+ size = 2;
+ break;
+ case 'J':
+ type = AST__INTTYPE;
+ data = (char*)new int[arr];
+ size = 4;
+ break;
+ case 'E':
+ type = AST__FLOATTYPE;
+ data = (char*)new float[arr];
+ size = 4;
+ break;
+ case 'D':
+ type = AST__DOUBLETYPE;
+ data = (char*)new double[arr];
+ size = 8;
+ break;
+ default:
+ // not supported
+ astEnd;
+ if (ext)
+ delete ext;
+ *status = 1;
+ return;
+ }
+
+ char blank[] = "";
+ const char* unit = col->tunit();
+ if (!unit)
+ unit = blank;
+ astAddColumn(table, col->ttype(), type, col->tdimM(), col->tdimK(), unit);
+
+ char* ptr = (char*)ext->data();
+ int rows = hdu->rows();
+ int rowlen = hdu->width();
+
+ // will only handle 1d and 2d array
+ int dd = col->tdimK(0);
+ for (int ii=0; ii<rows; ii++, ptr+=rowlen) {
+ for (int jj=0; jj<col->tdimK(1); jj++) {
+ switch (col->type()) {
+ case 'I':
+ {
+ short vv = col->value(ptr,jj);
+ memcpy(data+ii*dd+jj,&vv,2);
+ }
+ break;
+ case 'J':
+ {
+ int vv = col->value(ptr,jj);
+ memcpy(data+ii*dd+jj,&vv,4);
+ }
+ break;
+ case 'E':
+ {
+ float vv = col->value(ptr,jj);
+ memcpy(data+ii*dd+jj,&vv,4);
+ }
+ break;
+ case 'D':
+ {
+ double vv = col->value(ptr,jj);
+ memcpy(data+ii*dd+jj,&vv,8);
+ }
+ break;
+ }
+ }
+ }
+ astPutColumnData(table, col->ttype(), 0, dd*size, data);
+
+ if (data)
+ delete [] data;
+ }
+
+ astPutTable(chan, table, extname);
+ astEnd; // now, clean up memory
+
+ if (ext)
+ delete ext;
+
+ *status = 0;
+}
+
AstFrameSet* FitsImage::fits2ast(FitsHead* hd)
{
// we may have an error, just reset
@@ -4491,6 +4640,11 @@ AstFrameSet* FitsImage::fits2ast(FitsHead* hd)
if (!astOK || chan == AST__NULL)
return NULL;
+ // enable -TAB
+ astSetI(chan,"TabOK",1);
+ fitsImagePtr = this;
+ astTableSource(chan, fits2TAB);
+
// no warning messages
astClear(chan,"Warnings");
@@ -4517,9 +4671,6 @@ AstFrameSet* FitsImage::fits2ast(FitsHead* hd)
astClearStatus;
}
- // enable -TAB
- //astSetI(chan,"TabOK",1);
-
// we may have an error, just reset
astClearStatus;
astClear(chan, "Card");
@@ -4527,6 +4678,9 @@ AstFrameSet* FitsImage::fits2ast(FitsHead* hd)
// parse header
AstFrameSet* frameSet = (AstFrameSet*)astRead(chan);
+ // clear pointer
+ fitsImagePtr = NULL;
+
// do we have anything?
if (!astOK || frameSet == AST__NULL ||
strncmp(astGetC(frameSet,"Class"), "FrameSet", 8))