/* Writer de table Fits (binaire ou ASCII) */ #include "machdefs.h" #include #include #include "pexceptions.h" #include "fabtwriter.h" /*! \class SOPHYA::FitsABTWriter \ingroup FitsIOServer Class for writing a FITS ASCII or BINARY table \verbatim\ Exemple: FitsABTWriter fbtw("myfits.fits",BINARY_TBL,3); fbtw.SetExtName("MY_OWN_EXTENSION"); fbtw.AddCol("vars",TSHORT,"","km"); // col=0 fbtw.AddCol("vars2",TSHORT,"","km"); // col=1 fbtw.AddCol("varl",TINT32BIT,"","Degre"); // col=2 fbtw.AddCol("varf",TFLOAT,"",""); // col=3 fbtw.AddCol("vard",TDOUBLE,"","arcmin"); // col=4 fbtw.SetDebug(3); for(long i=0;i<1000;i++) { double x = i; fbtw.Write(0,i,1000.*x); // if overflow, managed by cfitsio // Write(int,long,double) is called fbtw.Write(1,i,(short)(1000.*x)); // if overflow, managed by language // Write(int,long,short) is called fbtw.Write(2,i,x); fbtw.Write(3,i,x); fbtw.Write(4,i,x); } cout<<"Number of Overflows when writing: " <0) { extname = (char *) malloc((strlen(ExtName.c_str())+1)*sizeof(char)); strcpy(extname,ExtName.c_str()); } for(int i=0;i& val) { if(FirstTime) createtbl(); long nel = val.Size(); int sta=0; // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ? int T = (sizeof(long)==4) ? TLONG: TINT; if(fits_write_col(FitsPtr,T,col+1,row+1,1,nel,val.Data(),&sta)) printerrorwrite("long",col,row,sta); return row+nel; } /*! Write a vector of float data to FITS file (see below) */ long FitsABTWriter::Write(int col,long row,TVector& val) { if(FirstTime) createtbl(); long nel = val.Size(); int sta=0; if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta)) printerrorwrite("float",col,row,sta); return row+nel; } /*! Write a vector of double data to FITS file (see below) */ long FitsABTWriter::Write(int col,long row,TVector& val) { if(FirstTime) createtbl(); long nel = val.Size(); int sta=0; if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta)) printerrorwrite("double",col,row,sta); return row+nel; } ////////////////////////////////////////////////////////////// void FitsABTWriter::printerrorwrite(char* type,int col,long row,int sta) { if(sta==NUM_OVERFLOW) {NOverFlow++; return;} printerror(sta); char str[256]; sprintf(str,"FitsABTWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d" ,type,col,row,sta); throw NotAvailableOperation(str); } ///////////////////////////////////////////////// void FitsABTWriter::printerror(int sta) const { int stat = sta; fits_report_error(stdout,stat); fflush(stdout); return; }