diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2018-01-20 21:04:00 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2018-01-20 21:04:00 (GMT) |
commit | d3740b78ecc6e648c62d89bf50f700eb1e4f6845 (patch) | |
tree | 66823809e7ea2d34bbe2842ef5d4f2b1b07a20f7 /tksao/frame/fitsimage.C | |
parent | 674b5acf07b88489b245d074f9c238e6ae55ce05 (diff) | |
download | blt-d3740b78ecc6e648c62d89bf50f700eb1e4f6845.zip blt-d3740b78ecc6e648c62d89bf50f700eb1e4f6845.tar.gz blt-d3740b78ecc6e648c62d89bf50f700eb1e4f6845.tar.bz2 |
support WCS-TAB
Diffstat (limited to 'tksao/frame/fitsimage.C')
-rw-r--r-- | tksao/frame/fitsimage.C | 116 |
1 files changed, 62 insertions, 54 deletions
diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index 7cee903..ad7ad26 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -4530,39 +4530,45 @@ static void fits2TAB(AstFitsChan* chan, const char* extname, astClearStatus; // just to make sure astBegin; // start memory management - AstFitsTable* table = (AstFitsTable*)astFitsTable(NULL,""); - FitsBinTableHDU* hdu = (FitsBinTableHDU*)ext->head()->hdu(); + FitsHead* hd = ext->head(); + FitsBinTableHDU* hdu = (FitsBinTableHDU*)hd->hdu(); + int cols = hdu->cols(); + int rows = hdu->rows(); + int rowlen = hdu->width(); + + // create fitstable + AstFitsChan* header = astFitsChan(NULL, NULL, ""); + char* cards = hd->cards(); + int ncards = hd->ncard(); + + for (int ii=0; ii<ncards; ii++) { + char buf[81]; + strncpy(buf,cards+(ii*80),80); + buf[80] = '\0'; - for (int ii=0; ii<hdu->cols(); ii++) { - FitsBinColumn* col = (FitsBinColumn*)hdu->find(ii); + astPutFits(header, buf, 0); + } + AstFitsTable* table = (AstFitsTable*)astFitsTable(header,""); - int arr = 1; - for (int ii=0; ii<col->tdimM(); ii++) - arr *= col->tdimK(ii); + for (int ii=0; ii<cols; ii++) { + FitsBinColumn* col = (FitsBinColumn*)hdu->find(ii); + int width = col->width(); + int repeat = col->repeat(); + if (0) { 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 @@ -4578,52 +4584,54 @@ static void fits2TAB(AstFitsChan* chan, const char* extname, 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; + unsigned char* data = new unsigned char[width*rows]; + switch (col->type()) { + case 'I': + for (int ii=0; ii<rows; ii++, ptr+=rowlen) + for (int jj=0; jj<repeat; jj++) { + short vv = col->value(ptr,jj); + memcpy(data+ii*width+jj*2,&vv,2); } - } + break; + case 'J': + for (int ii=0; ii<rows; ii++, ptr+=rowlen) + for (int jj=0; jj<repeat; jj++) { + int vv = col->value(ptr,jj); + memcpy(data+ii*width+jj*4,&vv,4); + } + break; + case 'E': + for (int ii=0; ii<rows; ii++, ptr+=rowlen) + for (int jj=0; jj<repeat; jj++) { + float vv = col->value(ptr,jj); + memcpy(data+ii*width+jj*4,&vv,4); + } + break; + case 'D': + for (int ii=0; ii<rows; ii++, ptr+=rowlen) + for (int jj=0; jj<repeat; jj++) { + double vv = col->value(ptr,jj); + memcpy(data+ii*width+jj*8,&vv,8); + } + break; } - astPutColumnData(table, col->ttype(), 0, dd*size, data); - + astPutColumnData(table, col->ttype(), 0, width*rows, data); if (data) delete [] data; } astPutTable(chan, table, extname); - astEnd; // now, clean up memory + for (int ii=0; ii<cols; ii++) { + const char* name = astColumnName(table, ii+1); + int size = astColumnSize(table, name); + cerr << name << ' ' << size << endl; + } + + astEnd; // now, clean up memory if (ext) delete ext; |