From d3740b78ecc6e648c62d89bf50f700eb1e4f6845 Mon Sep 17 00:00:00 2001 From: William Joye Date: Sat, 20 Jan 2018 16:04:00 -0500 Subject: support WCS-TAB --- tksao/frame/fitsimage.C | 116 ++++++++++++++++++++++++++---------------------- 1 file 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; iicols(); ii++) { - FitsBinColumn* col = (FitsBinColumn*)hdu->find(ii); + astPutFits(header, buf, 0); + } + AstFitsTable* table = (AstFitsTable*)astFitsTable(header,""); - int arr = 1; - for (int ii=0; iitdimM(); ii++) - arr *= col->tdimK(ii); + for (int ii=0; iifind(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; iitdimK(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; iivalue(ptr,jj); + memcpy(data+ii*width+jj*2,&vv,2); } - } + break; + case 'J': + for (int ii=0; iivalue(ptr,jj); + memcpy(data+ii*width+jj*4,&vv,4); + } + break; + case 'E': + for (int ii=0; iivalue(ptr,jj); + memcpy(data+ii*width+jj*4,&vv,4); + } + break; + case 'D': + for (int ii=0; iivalue(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