[1654] | 1 | /* Writer de table Fits (binaire ou ASCII) */
|
---|
[2615] | 2 | #include "sopnamsp.h"
|
---|
[1654] | 3 | #include "machdefs.h"
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 | #include <stdio.h>
|
---|
| 6 | #include "pexceptions.h"
|
---|
| 7 | #include "fabtwriter.h"
|
---|
| 8 |
|
---|
[2453] | 9 | //////////////////////////////////////////////////////////////
|
---|
| 10 | //////////////////////////////////////////////////////////////
|
---|
| 11 | //////////////////////////////////////////////////////////////
|
---|
| 12 | //////////////////////////////////////////////////////////////
|
---|
[1654] | 13 | /*!
|
---|
[2453] | 14 | \class SOPHYA::FitsWriter
|
---|
| 15 | \ingroup FitsIOServer
|
---|
| 16 | Class for writing into a FITS file (DO NOT USE)
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | /*! Constructor (DO NOT USE). */
|
---|
| 20 | FitsWriter::FitsWriter(string fname,int lp)
|
---|
| 21 | {
|
---|
| 22 | cr_or_upd_fits(fname.c_str(),false,lp);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /*! Constructor (DO NOT USE). */
|
---|
| 26 | FitsWriter::FitsWriter(const char* cfname,int lp)
|
---|
| 27 | {
|
---|
| 28 | cr_or_upd_fits(cfname,false,lp);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /*! Constructor (DO NOT USE). */
|
---|
| 32 | FitsWriter::FitsWriter(string fname,bool update,int lp)
|
---|
| 33 | {
|
---|
| 34 | cr_or_upd_fits(fname.c_str(),update,lp);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | /*! Constructor (DO NOT USE). */
|
---|
| 38 | FitsWriter::FitsWriter(const char* cfname,bool update,int lp)
|
---|
| 39 | {
|
---|
| 40 | cr_or_upd_fits(cfname,update,lp);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /*! See FitsWriter() */
|
---|
| 44 | void FitsWriter::cr_or_upd_fits(const char *cfname,bool update,int lp)
|
---|
| 45 | {
|
---|
| 46 | FitsPtr = NULL;
|
---|
| 47 | HduType = 0;
|
---|
| 48 | SetDebug(lp);
|
---|
| 49 | FitsFN = cfname;
|
---|
| 50 | NOverFlow = 0;
|
---|
| 51 | Update = update;
|
---|
| 52 | // Init key structure
|
---|
| 53 | DoubleKey.resize(0);
|
---|
| 54 | LongKey.resize(0);
|
---|
[3128] | 55 | LongLongKey.resize(0);
|
---|
[2453] | 56 | StringKey.resize(0);
|
---|
| 57 |
|
---|
| 58 | if(DbgLevel)
|
---|
| 59 | cout<<"FitsWriter::cr_or_upd_fits FitsFN="<<FitsFN<<endl;
|
---|
| 60 |
|
---|
| 61 | if(FitsFN.size() <= 0 )
|
---|
| 62 | throw ParmError("FitsWriter::cr_or_upd_fits: Fits file name error\n");
|
---|
| 63 |
|
---|
| 64 | // create or update FITS file
|
---|
| 65 | int sta=0;
|
---|
| 66 | if(Update) {
|
---|
| 67 | if(fits_open_file(&FitsPtr,FitsFN.c_str(),READWRITE,&sta)) {
|
---|
| 68 | printerror(sta);
|
---|
| 69 | throw NullPtrError("FitsWriter::cr_or_upd_fits: Error opening Fits file for update\n");
|
---|
| 70 | }
|
---|
| 71 | if(DbgLevel) cout<<"FitsWriter::cr_or_upd_fits: fits file has been opened for update"<<endl;
|
---|
| 72 | } else {
|
---|
| 73 | if(fits_create_file(&FitsPtr,FitsFN.c_str(),&sta)) {
|
---|
| 74 | printerror(sta);
|
---|
| 75 | throw NullPtrError("FitsWriter::cr_or_upd_fits: Error creating new Fits file\n");
|
---|
| 76 | }
|
---|
| 77 | if(DbgLevel) cout<<"FitsWriter::cr_or_upd_fits: a new fits file has been created"<<endl;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | // create d'un Primary HDU
|
---|
[3128] | 81 | //LONGLONG naxes[1] = {0};
|
---|
| 82 | //if(fits_create_imgll(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
|
---|
[2453] | 83 | // printerror(sta);
|
---|
| 84 | // throw NullPtrError("FitsWriter::cr_or_upd_fits: Error creating Primary extension\n");
|
---|
| 85 | //}
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /*! Destructor */
|
---|
| 89 | FitsWriter::~FitsWriter()
|
---|
| 90 | {
|
---|
| 91 | int sta = 0;
|
---|
| 92 | writekeys();
|
---|
| 93 | if(fits_close_file(FitsPtr,&sta)) printerror(sta);
|
---|
| 94 | FitsPtr = NULL;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /*! Flush the FitsIO buffer to set good Fits file in case of problems */
|
---|
| 98 | void FitsWriter::Flush(void)
|
---|
| 99 | {
|
---|
| 100 | if(FitsPtr==NULL) return;
|
---|
| 101 | int sta = 0;
|
---|
| 102 | if(fits_flush_file(FitsPtr,&sta)) printerror(sta);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | /*! Write a double value into Fits Header */
|
---|
[3572] | 107 | void FitsWriter::WriteKey(const char *keyname,double val,const char* comment)
|
---|
[2453] | 108 | {
|
---|
| 109 | if(keyname==NULL || strlen(keyname)<=0) return;
|
---|
| 110 | KeyDouble k;
|
---|
| 111 | k.keyname=keyname;
|
---|
| 112 | k.val=val;
|
---|
| 113 | if(comment) k.comment=comment; else k.comment="";
|
---|
| 114 | DoubleKey.push_back(k);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /*! Write a long value into Fits Header */
|
---|
[3572] | 118 | void FitsWriter::WriteKey(const char *keyname,long val,const char* comment)
|
---|
[2453] | 119 | {
|
---|
| 120 | if(keyname==NULL || strlen(keyname)<=0) return;
|
---|
| 121 | KeyLong k;
|
---|
| 122 | k.keyname=keyname;
|
---|
| 123 | k.val=val;
|
---|
| 124 | if(comment) k.comment=comment; else k.comment="";
|
---|
| 125 | LongKey.push_back(k);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[3128] | 128 | /*! Write a long long value into Fits Header */
|
---|
[3572] | 129 | void FitsWriter::WriteKey(const char *keyname,LONGLONG val,const char* comment)
|
---|
[3128] | 130 | {
|
---|
| 131 | if(keyname==NULL || strlen(keyname)<=0) return;
|
---|
| 132 | KeyLongLong k;
|
---|
| 133 | k.keyname=keyname;
|
---|
| 134 | k.val=val;
|
---|
| 135 | if(comment) k.comment=comment; else k.comment="";
|
---|
| 136 | LongLongKey.push_back(k);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[2453] | 139 | /*! Write a string value into Fits Header */
|
---|
[3572] | 140 | void FitsWriter::WriteKey(const char *keyname,string val,const char* comment)
|
---|
[2453] | 141 | {
|
---|
| 142 | if(keyname==NULL || strlen(keyname)<=0) return;
|
---|
| 143 | KeyString k;
|
---|
| 144 | k.keyname=keyname;
|
---|
| 145 | k.val=val;
|
---|
| 146 | if(comment) k.comment=comment; else k.comment="";
|
---|
| 147 | StringKey.push_back(k);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void FitsWriter::writekeys(void)
|
---|
| 151 | // Ecriture effective des clefs
|
---|
| 152 | {
|
---|
| 153 | if(FitsPtr==NULL) return;
|
---|
| 154 | int sta=0;
|
---|
| 155 | if(DoubleKey.size()>0)
|
---|
[3128] | 156 | for(unsigned long i=0;i<DoubleKey.size();i++) {
|
---|
[2453] | 157 | char* key = const_cast<char*>(DoubleKey[i].keyname.c_str());
|
---|
| 158 | char* com = const_cast<char*>(DoubleKey[i].comment.c_str());
|
---|
| 159 | double val = DoubleKey[i].val;
|
---|
| 160 | if(fits_update_key(FitsPtr,TDOUBLE,key,&val,com,&sta))
|
---|
| 161 | printerror(sta);
|
---|
| 162 | }
|
---|
| 163 | if(LongKey.size()>0)
|
---|
[3128] | 164 | for(unsigned long i=0;i<LongKey.size();i++) {
|
---|
[2453] | 165 | char* key = const_cast<char*>(LongKey[i].keyname.c_str());
|
---|
| 166 | char* com = const_cast<char*>(LongKey[i].comment.c_str());
|
---|
| 167 | long val = LongKey[i].val;
|
---|
| 168 | if(fits_update_key(FitsPtr,TLONG,key,&val,com,&sta))
|
---|
| 169 | printerror(sta);
|
---|
| 170 | }
|
---|
[3128] | 171 | if(LongLongKey.size()>0)
|
---|
| 172 | for(unsigned long i=0;i<LongLongKey.size();i++) {
|
---|
| 173 | char* key = const_cast<char*>(LongLongKey[i].keyname.c_str());
|
---|
| 174 | char* com = const_cast<char*>(LongLongKey[i].comment.c_str());
|
---|
| 175 | LONGLONG val = LongLongKey[i].val;
|
---|
| 176 | if(fits_update_key(FitsPtr,TLONGLONG,key,&val,com,&sta))
|
---|
| 177 | printerror(sta);
|
---|
| 178 | }
|
---|
[2453] | 179 | if(StringKey.size()>0)
|
---|
[3128] | 180 | for(unsigned long i=0;i<StringKey.size();i++) {
|
---|
[2453] | 181 | char* key = const_cast<char*>(StringKey[i].keyname.c_str());
|
---|
| 182 | char* com = const_cast<char*>(StringKey[i].comment.c_str());
|
---|
| 183 | char* val = const_cast<char*>(StringKey[i].val.c_str());
|
---|
| 184 | if(fits_update_key(FitsPtr,TSTRING,key,val,com,&sta))
|
---|
| 185 | printerror(sta);
|
---|
| 186 | }
|
---|
| 187 | DoubleKey.resize(0);
|
---|
| 188 | LongKey.resize(0);
|
---|
[3128] | 189 | LongLongKey.resize(0);
|
---|
[2453] | 190 | StringKey.resize(0);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[3128] | 193 | void FitsWriter::printerrorwrite(const char* type,int col,LONGLONG row,int sta)
|
---|
[2453] | 194 | {
|
---|
| 195 | if(sta==NUM_OVERFLOW) {NOverFlow++; return;}
|
---|
| 196 | printerror(sta);
|
---|
| 197 | char str[256];
|
---|
| 198 | sprintf(str,"FitsWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d"
|
---|
[3128] | 199 | ,type,col,(long)row,sta);
|
---|
[2453] | 200 | throw NotAvailableOperation(str);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void FitsWriter::printerror(int sta) const
|
---|
| 204 | {
|
---|
| 205 | int stat = sta;
|
---|
| 206 | fits_report_error(stdout,stat);
|
---|
| 207 | fflush(stdout);
|
---|
| 208 | return;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | //////////////////////////////////////////////////////////////////
|
---|
| 212 | //////////////////////////////////////////////////////////////////
|
---|
| 213 | //////////////////////////////////////////////////////////////////
|
---|
| 214 | //////////////////////////////////////////////////////////////////
|
---|
| 215 | /*!
|
---|
[1654] | 216 | \class SOPHYA::FitsABTWriter
|
---|
| 217 | \ingroup FitsIOServer
|
---|
| 218 | Class for writing a FITS ASCII or BINARY table
|
---|
[1659] | 219 | \verbatim
|
---|
| 220 | //-----------------------------------------------------------
|
---|
[2450] | 221 | OPENING A NEW FILE AND WRITING INTO
|
---|
[1659] | 222 | -- Exemple 1: Writing element by element
|
---|
| 223 | FitsABTWriter fbtw(fitswrit,BINARY_TBL);
|
---|
[1654] | 224 | fbtw.SetExtName("MY_OWN_EXTENSION");
|
---|
[2450] | 225 | int c1 = fbtw.AddCol("vars",NULL,"km",TSHORT); // col=0
|
---|
| 226 | int c2 = fbtw.AddCol("vars2",NULL,"km",TSHORT); // col=1
|
---|
| 227 | int c3 = fbtw.AddCol("varl",NULL,"Degre",TLONG); // col=2
|
---|
| 228 | int c4 = fbtw.AddCol("varf",NULL,"",TFLOAT); // col=3
|
---|
| 229 | int c5 = fbtw.AddCol("vard","","arcmin",TDOUBLE); // col=4
|
---|
[1654] | 230 | fbtw.SetDebug(3);
|
---|
[3128] | 231 | for(LONGLONG i=0;i<1000;i++) {
|
---|
[1654] | 232 | double x = i;
|
---|
[2450] | 233 | fbtw.Write(c1,i,1000.*x); // if overflow, managed by cfitsio
|
---|
[1654] | 234 | // Write(int,long,double) is called
|
---|
[2450] | 235 | fbtw.Write(c2,i,(short)(1000.*x));
|
---|
[1654] | 236 | // if overflow, managed by language
|
---|
| 237 | // Write(int,long,short) is called
|
---|
[2450] | 238 | fbtw.Write(c3,i,x);
|
---|
| 239 | fbtw.Write(c4,i,x);
|
---|
| 240 | fbtw.Write(c5,i,x);
|
---|
[1654] | 241 | }
|
---|
| 242 | cout<<"Number of Overflows when writing: "
|
---|
| 243 | <<fbtw.GetNOverFlow()<<endl;
|
---|
[1659] | 244 |
|
---|
| 245 | //-----------------------------------------------------------
|
---|
| 246 | -- Exemple 2: Writing into TVector
|
---|
| 247 | ...
|
---|
| 248 | TVector<double> datad(100);
|
---|
| 249 | TVector<float> dataf(100);
|
---|
| 250 | TVector<int_4> datal(100);
|
---|
[3128] | 251 | for(LONGLONG i=0;i<9990;i+=100) {
|
---|
| 252 | LONGLONG i2=i+100-1; if(i2>=9990) i2=9990-1;
|
---|
| 253 | for(LONGLONG j=0;j<100;j++) datad(i) = ...;
|
---|
| 254 | for(LONGLONG j=0;j<100;j++) dataf(i) = ...;
|
---|
| 255 | for(LONGLONG j=0;j<100;j++) datal(i) = ...;
|
---|
[1659] | 256 | fbtw.Write(1,i,datal);
|
---|
| 257 | fbtw.Write(2,i,dataf);
|
---|
| 258 | fbtw.Write(3,i,datad);
|
---|
| 259 | }
|
---|
[1654] | 260 | \endverbatim
|
---|
[2450] | 261 | \verbatim
|
---|
| 262 | //-----------------------------------------------------------
|
---|
| 263 | //-----------------------------------------------------------
|
---|
| 264 | //-----------------------------------------------------------
|
---|
| 265 | OPENING A NEW FILE AND WRITING 2 TABLE EXTENSIONS SIMULTANEOUSLY INTO
|
---|
| 266 | try {
|
---|
| 267 |
|
---|
| 268 | cout<<">>>>> Creating a new fits file with FitsABTWriter"<<endl;
|
---|
| 269 | FitsABTWriter fbtw("!cmvtstfits3.fits",BINARY_TBL,3);
|
---|
| 270 | //FitsABTWriter fbtw("!cmvtstfits3.fits",false,BINARY_TBL,3);
|
---|
| 271 | fbtw.SetExtName("Test fits table 1");
|
---|
| 272 | cout<<"Writing Keys"<<endl;
|
---|
| 273 | fbtw.WriteKey("MYKEYL",(long)123456789,"my LONG key");
|
---|
[3128] | 274 | fbtw.WriteKey("MYKEYLL",(LONGLONG)123456789,"my LONGLONG key");
|
---|
[2450] | 275 | fbtw.WriteKey("MYKEYD",1.9999999,"my DOUBLE key");
|
---|
| 276 | fbtw.WriteKey("MYKEYC","how are you ?","my CHAR* key");
|
---|
| 277 | dum="do you feel better ?";
|
---|
| 278 | fbtw.WriteKey("MYKEYS",dum,"my STRING key");
|
---|
| 279 | i1 = fbtw.AddCol("x1",NULL,"unit1",TDOUBLE);
|
---|
| 280 | i2 = fbtw.AddCol("x2",NULL,"unit2",TDOUBLE);
|
---|
| 281 | i3 = fbtw.AddCol("x3",NULL,"unit3",TDOUBLE);
|
---|
| 282 | fbtw.Print();
|
---|
| 283 |
|
---|
| 284 | cout<<">>>>> Another extension fits table with FitsABTWriter"<<endl;
|
---|
| 285 | FitsABTWriter fbtw2("cmvtstfits3.fits",true,BINARY_TBL,3);
|
---|
| 286 | fbtw2.SetExtName("Test fits table 2");
|
---|
| 287 | cout<<"Writing Keys"<<endl;
|
---|
| 288 | fbtw2.WriteKey("MYKEYL",(long)-123456789,"my new LONG key");
|
---|
[3128] | 289 | fbtw2.WriteKey("MYKEYLL",(LONGLONG)-123456789,"my new LONGLONG key");
|
---|
[2450] | 290 | fbtw2.WriteKey("MYKEYD",-1.9999999,"my new clef DOUBLE key");
|
---|
| 291 | fbtw2.WriteKey("MYKEYC","how are you NOW ?","my new CHAR* key");
|
---|
| 292 | dum="do you feel better NOW ?";
|
---|
| 293 | fbtw2.WriteKey("MYKEYS",dum,"my new STRING key");
|
---|
| 294 | i11 = fbtw2.AddCol("x11",NULL,"unit11",TDOUBLE);
|
---|
| 295 | i12 = fbtw2.AddCol("x12",NULL,"unit12",TDOUBLE);
|
---|
| 296 | i13 = fbtw2.AddCol("x13",NULL,"unit13",TDOUBLE);
|
---|
| 297 | fbtw2.Print();
|
---|
| 298 |
|
---|
| 299 | cout<<">>>>> Write into the 2 tables simultaneously"<<endl;
|
---|
[3128] | 300 | for(LONGLONG i=0;i<NNN;i++) {
|
---|
[2450] | 301 | fbtw.Write(i1,i,i+1.);
|
---|
| 302 | fbtw.Write(i2,i,i+11.);
|
---|
| 303 | fbtw.Write(i3,i,i+101.);
|
---|
| 304 | fbtw2.Write(i11,i,-(i+1.));
|
---|
| 305 | fbtw2.Write(i12,i,-(i+11.));
|
---|
| 306 | fbtw2.Write(i13,i,-(i+101.));
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | } catch (PThrowable & exc) {
|
---|
| 310 | cout<<"Exception : "<<(string)typeid(exc).name()
|
---|
| 311 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 312 | return -2;
|
---|
| 313 | } catch (...) {
|
---|
| 314 | cout<<" some other exception was caught !"<<endl;
|
---|
| 315 | return -2;
|
---|
| 316 | }
|
---|
| 317 | \endverbatim
|
---|
[1654] | 318 | */
|
---|
| 319 |
|
---|
| 320 | //////////////////////////////////////////////////////////////
|
---|
| 321 | /*!
|
---|
| 322 | Constructor.
|
---|
[2450] | 323 | \param fname : FITS file name to be written (a new fits file is created)
|
---|
[1659] | 324 | \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
|
---|
| 325 | \param lp : debug level
|
---|
[1654] | 326 | */
|
---|
| 327 | FitsABTWriter::FitsABTWriter(string fname,int hdutype,int lp)
|
---|
[2453] | 328 | : FitsWriter(fname,lp)
|
---|
[1654] | 329 | {
|
---|
[2453] | 330 | FirstTime = true;
|
---|
| 331 | HduType = hdutype;
|
---|
| 332 | if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
|
---|
| 333 | throw
|
---|
| 334 | TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n");
|
---|
[1654] | 335 | }
|
---|
| 336 |
|
---|
[2450] | 337 | /*!
|
---|
| 338 | Constructor.
|
---|
| 339 | \param cfname : FITS file name to be written (a new fits file is created)
|
---|
| 340 | \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
|
---|
| 341 | \param lp : debug level
|
---|
| 342 | */
|
---|
[1654] | 343 | FitsABTWriter::FitsABTWriter(const char* cfname,int hdutype,int lp)
|
---|
[2453] | 344 | : FitsWriter(cfname,lp)
|
---|
[1654] | 345 | {
|
---|
[2453] | 346 | FirstTime = true;
|
---|
| 347 | HduType = hdutype;
|
---|
| 348 | if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
|
---|
| 349 | throw
|
---|
| 350 | TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n");
|
---|
[1654] | 351 | }
|
---|
| 352 |
|
---|
[2450] | 353 | /*!
|
---|
| 354 | Constructor.
|
---|
| 355 | \param fname : FITS file name to be written (created or updated)
|
---|
| 356 | \param update : file is created if FALSE, open for update if TRUE
|
---|
| 357 | \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
|
---|
| 358 | \param lp : debug level
|
---|
| 359 | */
|
---|
| 360 | FitsABTWriter::FitsABTWriter(string fname,bool update,int hdutype,int lp)
|
---|
[2453] | 361 | : FitsWriter(fname,update,lp)
|
---|
[2450] | 362 | {
|
---|
[2453] | 363 | FirstTime = true;
|
---|
| 364 | HduType = hdutype;
|
---|
| 365 | if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
|
---|
| 366 | throw
|
---|
| 367 | TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n");
|
---|
[2450] | 368 | }
|
---|
| 369 |
|
---|
| 370 | /*!
|
---|
| 371 | Constructor.
|
---|
| 372 | \param cfname : FITS file name to be written (created or updated)
|
---|
| 373 | \param update : file is created if FALSE, open for update if TRUE
|
---|
| 374 | \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
|
---|
| 375 | \param lp : debug level
|
---|
| 376 | */
|
---|
| 377 | FitsABTWriter::FitsABTWriter(const char* cfname,bool update,int hdutype,int lp)
|
---|
[2453] | 378 | : FitsWriter(cfname,update,lp)
|
---|
[2450] | 379 | {
|
---|
[1654] | 380 | FirstTime = true;
|
---|
| 381 | HduType = hdutype;
|
---|
| 382 | if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
|
---|
[2453] | 383 | throw
|
---|
| 384 | TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n");
|
---|
[1654] | 385 | }
|
---|
| 386 |
|
---|
| 387 | /*! Destructor */
|
---|
| 388 | FitsABTWriter::~FitsABTWriter()
|
---|
| 389 | {
|
---|
[3660] | 390 | // On cree la table avant de fermer le fichier si pas deja fait
|
---|
| 391 | if(FirstTime) createtbl();
|
---|
[1654] | 392 | }
|
---|
| 393 |
|
---|
| 394 | //////////////////////////////////////////////////////////////
|
---|
| 395 | /*!
|
---|
| 396 | Add a new column to the FITS table
|
---|
[1659] | 397 | \param label : column label
|
---|
[1660] | 398 | \param tform : fits tform definition ("1I","1J","1E","1J",...)
|
---|
| 399 | (can be automatically set as "datatype"
|
---|
[4024] | 400 | if BINARY_TBL and tform="" or tform=NULL).
|
---|
| 401 | character string can be written using the tform=":nA" with "n" the number of characters
|
---|
[1659] | 402 | \param tunit : fits tunit definition (optional)
|
---|
[2169] | 403 | \param datatype : TBYTE TSHORT TLONG (TINT32BIT) TLONGLONG TFLOAT TDOUBLE
|
---|
[2493] | 404 | TUSHORT TULONG TSBYTE. That parameter is only use in case
|
---|
[1660] | 405 | of a BINARY_TBL table when tform is not defined).
|
---|
[1659] | 406 | \return The number of the new added column in the table.
|
---|
| 407 | \warning col = [0,ncol-1]
|
---|
[1654] | 408 | */
|
---|
[1660] | 409 | int FitsABTWriter::addcol(const char* label,const char* tform
|
---|
| 410 | ,const char* tunit,int datatype)
|
---|
[1654] | 411 | {
|
---|
[2453] | 412 | if(!FirstTime)
|
---|
| 413 | throw AllocationError("FitsABTWriter::addcol: table already created\n");
|
---|
[1654] | 414 |
|
---|
[1660] | 415 | // Gestion auto du tform pour les tables binaires avec le datatype (si non-definie)
|
---|
| 416 | bool tformauto = false;
|
---|
[2174] | 417 | if(HduType==BINARY_TBL || HduType==ASCII_TBL) {
|
---|
[1669] | 418 | if(tform==NULL) tformauto = true;
|
---|
| 419 | else if(strlen(tform)<=0) tformauto = true;
|
---|
[1660] | 420 | }
|
---|
[2174] | 421 | if(tformauto && HduType==BINARY_TBL) {
|
---|
[1660] | 422 | char str[8];
|
---|
| 423 | if(datatype==TBYTE) strcpy(str,"1B");
|
---|
| 424 | else if(datatype==TSHORT) strcpy(str,"1I");
|
---|
| 425 | else if(datatype==TLONG) strcpy(str,"1J");
|
---|
[2169] | 426 | #ifdef TINT32BIT
|
---|
| 427 | else if(datatype==TINT32BIT) strcpy(str,"1J");
|
---|
| 428 | #endif
|
---|
| 429 | #ifdef TLONGLONG
|
---|
| 430 | else if(datatype==TLONGLONG) strcpy(str,"1K");
|
---|
| 431 | #endif
|
---|
[1657] | 432 | else if(datatype==TFLOAT) strcpy(str,"1E");
|
---|
| 433 | else if(datatype==TDOUBLE) strcpy(str,"1D");
|
---|
[1660] | 434 | else if(datatype==TUSHORT) strcpy(str,"1U");
|
---|
| 435 | else if(datatype==TULONG) strcpy(str,"1V");
|
---|
[2493] | 436 | #ifdef TSBYTE
|
---|
| 437 | else if(datatype==TSBYTE) strcpy(str,"1S");
|
---|
| 438 | #endif
|
---|
[1660] | 439 | else
|
---|
| 440 | throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
|
---|
[1654] | 441 | TForm.push_back(str);
|
---|
[2174] | 442 | } else if(tformauto && HduType==ASCII_TBL) {
|
---|
| 443 | char str[8];
|
---|
| 444 | if(datatype==TBYTE) strcpy(str,"I5");
|
---|
| 445 | else if(datatype==TSHORT) strcpy(str,"I7");
|
---|
| 446 | else if(datatype==TLONG) strcpy(str,"I11");
|
---|
| 447 | #ifdef TINT32BIT
|
---|
| 448 | else if(datatype==TINT32BIT) strcpy(str,"I11");
|
---|
| 449 | #endif
|
---|
| 450 | #ifdef TLONGLONG
|
---|
| 451 | else if(datatype==TLONGLONG) strcpy(str,"I21");
|
---|
| 452 | #endif
|
---|
| 453 | else if(datatype==TFLOAT) strcpy(str,"E29.20");
|
---|
| 454 | else if(datatype==TDOUBLE) strcpy(str,"E29.20");
|
---|
| 455 | else if(datatype==TUSHORT) strcpy(str,"I7");
|
---|
| 456 | else if(datatype==TULONG) strcpy(str,"I11");
|
---|
[2493] | 457 | #ifdef TSBYTE
|
---|
| 458 | else if(datatype==TSBYTE) strcpy(str,"I5");
|
---|
| 459 | #endif
|
---|
[2174] | 460 | else
|
---|
| 461 | throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
|
---|
| 462 | TForm.push_back(str);
|
---|
[1660] | 463 | } else {
|
---|
| 464 | if(tform) TForm.push_back(tform); else TForm.push_back("");
|
---|
| 465 | datatype = 0;
|
---|
| 466 | }
|
---|
| 467 | Label.push_back(label);
|
---|
| 468 | if(tunit) TUnit.push_back(tunit); else TUnit.push_back("");
|
---|
[1654] | 469 |
|
---|
| 470 | int n = (int) Label.size() -1;
|
---|
| 471 |
|
---|
| 472 | if(DbgLevel)
|
---|
| 473 | cout<<"FitsABTWriter::addcol["<<n<<"] Label="<<Label[n]
|
---|
| 474 | <<" TForm="<<TForm[n]
|
---|
[1660] | 475 | <<" TUnit="<<TUnit[n]
|
---|
| 476 | <<" datatype="<<datatype<<endl;
|
---|
[1654] | 477 |
|
---|
| 478 | return n;
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | /*! Create the table. Done at the first write request. */
|
---|
| 482 | void FitsABTWriter::createtbl(void)
|
---|
| 483 | {
|
---|
| 484 | if(!FirstTime) return;
|
---|
| 485 |
|
---|
| 486 | int tfields = Label.size();
|
---|
| 487 | if(tfields<=0)
|
---|
| 488 | throw ParmError("FitsABTWriter::createtbl: Zero column asked !\n");
|
---|
| 489 |
|
---|
[3128] | 490 | LONGLONG nrows = 0;
|
---|
[1654] | 491 | char *extname = NULL;
|
---|
| 492 | char **ttype = (char **) malloc(tfields*sizeof(char *));
|
---|
| 493 | char **tform = (char **) malloc(tfields*sizeof(char *));
|
---|
| 494 | char **tunit = (char **) malloc(tfields*sizeof(char *));
|
---|
| 495 |
|
---|
| 496 | if(ExtName.size()>0) {
|
---|
| 497 | extname = (char *) malloc((strlen(ExtName.c_str())+1)*sizeof(char));
|
---|
| 498 | strcpy(extname,ExtName.c_str());
|
---|
| 499 | }
|
---|
[3128] | 500 | for(int i=0;i<tfields;i++) {
|
---|
[1654] | 501 | ttype[i] = (char *) malloc((strlen(Label[i].c_str())+1)*sizeof(char));
|
---|
| 502 | strcpy(ttype[i],Label[i].c_str());
|
---|
| 503 | tform[i] = (char *) malloc((strlen(TForm[i].c_str())+1)*sizeof(char));
|
---|
| 504 | strcpy(tform[i],TForm[i].c_str());
|
---|
| 505 | tunit[i] = (char *) malloc((strlen(TUnit[i].c_str())+1)*sizeof(char));
|
---|
| 506 | strcpy(tunit[i],TUnit[i].c_str());
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | // append a new empty binary/ascii table onto the FITS file
|
---|
| 510 | int sta=0;
|
---|
| 511 | if(fits_create_tbl(FitsPtr,HduType,nrows,tfields,ttype,tform,tunit,extname,&sta)) {
|
---|
| 512 | printerror(sta);
|
---|
| 513 | throw NullPtrError("FitsABTWriter::createtbl: Error creating Table extension\n");
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | // menage
|
---|
| 517 | if(extname) delete [] extname;
|
---|
[3128] | 518 | for(int i=0;i<tfields;i++) {
|
---|
[1654] | 519 | if(ttype[i]) delete [] ttype[i];
|
---|
| 520 | if(tform[i]) delete [] tform[i];
|
---|
| 521 | if(tunit[i]) delete [] tunit[i];
|
---|
| 522 | }
|
---|
| 523 | if(ttype) delete [] ttype;
|
---|
| 524 | if(tform) delete [] tform;
|
---|
| 525 | if(tunit) delete [] tunit;
|
---|
| 526 |
|
---|
| 527 | FirstTime = false;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | //////////////////////////////////////////////////////////////
|
---|
| 531 | /*!
|
---|
[2173] | 532 | Write a data to FITS file.
|
---|
[1659] | 533 | \param col : column number [0,ncol[
|
---|
| 534 | \param row : row number [0,nrow[
|
---|
[4023] | 535 | \param nfirstel : element number [0,repeat[
|
---|
[1659] | 536 | \param val : value to be written
|
---|
| 537 | \warning that routine write a SHORT value into column "col"
|
---|
[1654] | 538 | which could have been defined with an other type.
|
---|
| 539 | Cast is performed by the cfitsio package.
|
---|
[1659] | 540 | \verbatim
|
---|
[1654] | 541 | WARNING: suppose that the column has be defined to be TSHORT
|
---|
[1660] | 542 | and suppose that you wanted to write a double value "val"
|
---|
[4023] | 543 | - If you write dummy.Write(col,row,nfirstel,(short)(val))
|
---|
| 544 | the Write(int,long,long,short) routine is called and
|
---|
[1654] | 545 | the cast is performed by the C++ language.
|
---|
[4023] | 546 | - If you write dummy.Write(col,row,nfirstel,val) where val is double
|
---|
| 547 | the Write(int,long,long,double) routine is called and
|
---|
[1654] | 548 | the cast is performed by the cfistio package.
|
---|
| 549 | \endverbatim
|
---|
| 550 | */
|
---|
[2173] | 551 |
|
---|
[4024] | 552 | /*! Write a character string to FITS file */
|
---|
[4025] | 553 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,const char* val)
|
---|
[4024] | 554 | {
|
---|
| 555 | if(FirstTime) createtbl();
|
---|
| 556 | int sta=0;
|
---|
[4025] | 557 | if(fits_write_col(FitsPtr,TSTRING,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[4024] | 558 | printerrorwrite("char*",col,row,sta);
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[2493] | 561 | /*! Write signed char (1 Byte) data to FITS file (see below) */
|
---|
[4023] | 562 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,int_1 val)
|
---|
[2493] | 563 | {
|
---|
| 564 | #ifdef TSBYTE
|
---|
| 565 | if(FirstTime) createtbl();
|
---|
| 566 | int sta=0;
|
---|
[4023] | 567 | if(fits_write_col(FitsPtr,TSBYTE,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[2493] | 568 | printerrorwrite("signed char",col,row,sta);
|
---|
| 569 | #else
|
---|
[2789] | 570 | throw PException("FitsABTWriter::Write(..,int_1) Not in that cfitsio version");
|
---|
[2493] | 571 | #endif
|
---|
| 572 | }
|
---|
| 573 |
|
---|
[2174] | 574 | /*! Write unsigned char (1 Byte) data to FITS file (see below) */
|
---|
[4023] | 575 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,uint_1 val)
|
---|
[2173] | 576 | {
|
---|
| 577 | if(FirstTime) createtbl();
|
---|
| 578 | int sta=0;
|
---|
[4023] | 579 | if(fits_write_col(FitsPtr,TBYTE,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[2174] | 580 | printerrorwrite("unsigned char",col,row,sta);
|
---|
[2173] | 581 | }
|
---|
| 582 |
|
---|
| 583 | /*! Write short (2 Bytes) data to FITS file (see below) */
|
---|
[4023] | 584 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,int_2 val)
|
---|
[1654] | 585 | {
|
---|
| 586 | if(FirstTime) createtbl();
|
---|
| 587 | int sta=0;
|
---|
[4023] | 588 | if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[1654] | 589 | printerrorwrite("short",col,row,sta);
|
---|
| 590 | }
|
---|
| 591 |
|
---|
[2170] | 592 | /*! Write unsigned short (2 Bytes) data to FITS file (see below) */
|
---|
[4023] | 593 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,uint_2 val)
|
---|
[2170] | 594 | {
|
---|
| 595 | if(FirstTime) createtbl();
|
---|
| 596 | int sta=0;
|
---|
[4023] | 597 | if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[2170] | 598 | printerrorwrite("unsigned short",col,row,sta);
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[2169] | 601 | /*! Write long (4 Bytes) data to FITS file (see below) */
|
---|
[4023] | 602 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,int_4 val)
|
---|
[1654] | 603 | {
|
---|
| 604 | if(FirstTime) createtbl();
|
---|
| 605 | int sta=0;
|
---|
[1657] | 606 | // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
|
---|
| 607 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
[4023] | 608 | if(fits_write_col(FitsPtr,T,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[1654] | 609 | printerrorwrite("long",col,row,sta);
|
---|
| 610 | }
|
---|
| 611 |
|
---|
[2173] | 612 | /*! Write unsigned long (4 Bytes) data to FITS file (see below) */
|
---|
[4023] | 613 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,uint_4 val)
|
---|
[2173] | 614 | {
|
---|
| 615 | if(FirstTime) createtbl();
|
---|
| 616 | int sta=0;
|
---|
| 617 | // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
|
---|
| 618 | int T = (sizeof(unsigned long)==4) ? TULONG: TUINT;
|
---|
[4023] | 619 | if(fits_write_col(FitsPtr,T,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[2173] | 620 | printerrorwrite("long",col,row,sta);
|
---|
| 621 | }
|
---|
| 622 |
|
---|
[2169] | 623 | /*! Write long long (8 Bytes) data to FITS file (see below) */
|
---|
[4023] | 624 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,int_8 val)
|
---|
[2169] | 625 | {
|
---|
| 626 | #ifdef TLONGLONG
|
---|
| 627 | if(FirstTime) createtbl();
|
---|
| 628 | int sta=0;
|
---|
[4023] | 629 | if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[2169] | 630 | printerrorwrite("long long",col,row,sta);
|
---|
| 631 | #else
|
---|
| 632 | throw PException("FitsABTWriter::Write(..,int_8) Not in that cfitsio version");
|
---|
| 633 | #endif
|
---|
| 634 | }
|
---|
| 635 |
|
---|
[1654] | 636 | /*! Write float data to FITS file (see below) */
|
---|
[4023] | 637 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,float val)
|
---|
[1654] | 638 | {
|
---|
| 639 | if(FirstTime) createtbl();
|
---|
| 640 | int sta=0;
|
---|
[4023] | 641 | if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[1654] | 642 | printerrorwrite("float",col,row,sta);
|
---|
| 643 | }
|
---|
| 644 |
|
---|
| 645 | /*! Write double data to FITS file (see below) */
|
---|
[4023] | 646 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,double val)
|
---|
[1654] | 647 | {
|
---|
| 648 | if(FirstTime) createtbl();
|
---|
| 649 | int sta=0;
|
---|
[4023] | 650 | if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,nfirstel+1,1,&val,&sta))
|
---|
[1654] | 651 | printerrorwrite("double",col,row,sta);
|
---|
| 652 | }
|
---|
| 653 |
|
---|
[4025] | 654 | /*! Write complex float data to FITS file (see below) */
|
---|
| 655 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,complex<r_4> val)
|
---|
| 656 | {
|
---|
| 657 | if(FirstTime) createtbl();
|
---|
| 658 | int sta=0;
|
---|
| 659 | r_4 tval[2]; tval[0] = val.real(); tval[1] = val.imag();
|
---|
| 660 | if(fits_write_col(FitsPtr,TCOMPLEX,col+1,row+1,nfirstel+1,1,&tval,&sta))
|
---|
| 661 | printerrorwrite("double",col,row,sta);
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | /*! Write complex double data to FITS file (see below) */
|
---|
| 665 | void FitsABTWriter::Write(int col,LONGLONG row,long nfirstel,complex<r_8> val)
|
---|
| 666 | {
|
---|
| 667 | if(FirstTime) createtbl();
|
---|
| 668 | int sta=0;
|
---|
| 669 | r_8 tval[2]; tval[0] = val.real(); tval[1] = val.imag();
|
---|
| 670 | if(fits_write_col(FitsPtr,TDBLCOMPLEX,col+1,row+1,nfirstel+1,1,&tval,&sta))
|
---|
| 671 | printerrorwrite("double",col,row,sta);
|
---|
| 672 | }
|
---|
| 673 |
|
---|
[1657] | 674 | //////////////////////////////////////////////////////////////
|
---|
| 675 | /*!
|
---|
[2173] | 676 | Write a vector of data to FITS file.
|
---|
[1659] | 677 | \param col : column number [0,ncol[
|
---|
| 678 | \param row : starting row number [0,nrow[
|
---|
| 679 | \param val : vector to be written
|
---|
| 680 | \return "N" = number of the next row to be written,
|
---|
| 681 | that is "N-1" is the number of the last row written.
|
---|
[4023] | 682 | \warning : be carefull if "repeat" not egal to 1
|
---|
[1657] | 683 | */
|
---|
[2173] | 684 |
|
---|
[2170] | 685 | /*! Write a vector of unsigned short (2 Bytes) data to FITS file (see below) */
|
---|
[3128] | 686 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<uint_2>& val)
|
---|
[2170] | 687 | {
|
---|
| 688 | if(FirstTime) createtbl();
|
---|
[3128] | 689 | LONGLONG nel = val.Size();
|
---|
[2170] | 690 | int sta=0;
|
---|
| 691 | if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,1,nel,val.Data(),&sta))
|
---|
| 692 | printerrorwrite("long",col,row,sta);
|
---|
| 693 | return row+nel;
|
---|
| 694 | }
|
---|
| 695 |
|
---|
[2169] | 696 | /*! Write a vector of long (4 Bytes) data to FITS file (see below) */
|
---|
[3128] | 697 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_4>& val)
|
---|
[1657] | 698 | {
|
---|
| 699 | if(FirstTime) createtbl();
|
---|
[3128] | 700 | LONGLONG nel = val.Size();
|
---|
[1657] | 701 | int sta=0;
|
---|
| 702 | // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
|
---|
| 703 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
| 704 | if(fits_write_col(FitsPtr,T,col+1,row+1,1,nel,val.Data(),&sta))
|
---|
| 705 | printerrorwrite("long",col,row,sta);
|
---|
| 706 | return row+nel;
|
---|
| 707 | }
|
---|
| 708 |
|
---|
[2169] | 709 | /*! Write a vector of long long (8 Bytes) data to FITS file (see below) */
|
---|
[3128] | 710 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_8>& val)
|
---|
[2169] | 711 | {
|
---|
| 712 | #ifdef TLONGLONG
|
---|
| 713 | if(FirstTime) createtbl();
|
---|
[3128] | 714 | LONGLONG nel = val.Size();
|
---|
[2169] | 715 | int sta=0;
|
---|
| 716 | if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,1,nel,val.Data(),&sta))
|
---|
| 717 | printerrorwrite("long long",col,row,sta);
|
---|
| 718 | return row+nel;
|
---|
| 719 | #else
|
---|
[2170] | 720 | throw PException("FitsABTWriter::Write(..,TVector<int_8>&) Not in that cfitsio version");
|
---|
[2169] | 721 | #endif
|
---|
| 722 | }
|
---|
| 723 |
|
---|
[1657] | 724 | /*! Write a vector of float data to FITS file (see below) */
|
---|
[3128] | 725 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<float>& val)
|
---|
[1657] | 726 | {
|
---|
| 727 | if(FirstTime) createtbl();
|
---|
[3128] | 728 | LONGLONG nel = val.Size();
|
---|
[1657] | 729 | int sta=0;
|
---|
| 730 | if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta))
|
---|
| 731 | printerrorwrite("float",col,row,sta);
|
---|
| 732 | return row+nel;
|
---|
| 733 | }
|
---|
| 734 |
|
---|
| 735 | /*! Write a vector of double data to FITS file (see below) */
|
---|
[3128] | 736 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<double>& val)
|
---|
[1657] | 737 | {
|
---|
| 738 | if(FirstTime) createtbl();
|
---|
[3128] | 739 | LONGLONG nel = val.Size();
|
---|
[1657] | 740 | int sta=0;
|
---|
| 741 | if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta))
|
---|
| 742 | printerrorwrite("double",col,row,sta);
|
---|
| 743 | return row+nel;
|
---|
| 744 | }
|
---|
| 745 |
|
---|
[1654] | 746 | /////////////////////////////////////////////////
|
---|
[1677] | 747 | void FitsABTWriter::Print(ostream& os,int lp) const
|
---|
[1673] | 748 | {
|
---|
| 749 | os<<"FitsABTWriter::Print: FitsFN "<<FitsFN<<endl
|
---|
| 750 | <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow
|
---|
| 751 | <<" NCol "<<Label.size()<<endl;
|
---|
| 752 | if(Label.size()>0 && lp>=1)
|
---|
| 753 | for(int i=0;i<(int)Label.size();i++)
|
---|
| 754 | os<<i<<"... Label="<<Label[i]<<" TForm="<<TForm[i]<<" TUnit="<<TUnit[i]<<endl;
|
---|
| 755 | }
|
---|
[2453] | 756 |
|
---|
| 757 | //////////////////////////////////////////////////////////////////
|
---|
| 758 | //////////////////////////////////////////////////////////////////
|
---|
| 759 | //////////////////////////////////////////////////////////////////
|
---|
| 760 | //////////////////////////////////////////////////////////////////
|
---|
| 761 | /*!
|
---|
| 762 | \class SOPHYA::FitsImg2DWriter
|
---|
| 763 | \ingroup FitsIOServer
|
---|
| 764 | Class for writing an image into FITS file
|
---|
| 765 | */
|
---|
| 766 |
|
---|
| 767 | /*!
|
---|
| 768 | Constructor.
|
---|
| 769 | \param fname : FITS file name to be written (a new fits file is created)
|
---|
[3668] | 770 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 771 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[2453] | 772 | \param lp : debug level
|
---|
| 773 | */
|
---|
| 774 | FitsImg2DWriter::FitsImg2DWriter(string fname,int bitpix,int lp)
|
---|
| 775 | : FitsWriter(fname,lp)
|
---|
| 776 | {
|
---|
| 777 | BitPix = bitpix;
|
---|
| 778 | HduType = IMAGE_HDU;
|
---|
| 779 | FirstTime = true;
|
---|
| 780 | Naxis[0] = Naxis[1] = 0;
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | /*!
|
---|
| 784 | Constructor.
|
---|
| 785 | \param cfname : FITS file name to be written (a new fits file is created)
|
---|
[3668] | 786 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 787 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[2453] | 788 | \param lp : debug level
|
---|
| 789 | */
|
---|
| 790 | FitsImg2DWriter::FitsImg2DWriter(const char* cfname,int bitpix,int lp)
|
---|
| 791 | : FitsWriter(cfname,lp)
|
---|
| 792 | {
|
---|
| 793 | BitPix = bitpix;
|
---|
| 794 | HduType = IMAGE_HDU;
|
---|
| 795 | FirstTime = true;
|
---|
| 796 | Naxis[0] = Naxis[1] = 0;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
| 799 | /*!
|
---|
| 800 | Constructor.
|
---|
| 801 | \param fname : FITS file name to be written (created or updated)
|
---|
| 802 | \param update : file is created if FALSE, open for update if TRUE
|
---|
[3668] | 803 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 804 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[2453] | 805 | \param lp : debug level
|
---|
| 806 | */
|
---|
| 807 | FitsImg2DWriter::FitsImg2DWriter(string fname,bool update,int bitpix,int lp)
|
---|
| 808 | : FitsWriter(fname,update,lp)
|
---|
| 809 | {
|
---|
| 810 | BitPix = bitpix;
|
---|
| 811 | HduType = IMAGE_HDU;
|
---|
| 812 | FirstTime = true;
|
---|
| 813 | Naxis[0] = Naxis[1] = 0;
|
---|
| 814 | }
|
---|
| 815 |
|
---|
| 816 | /*!
|
---|
| 817 | Constructor.
|
---|
| 818 | \param cfname : FITS file name to be written (created or updated)
|
---|
| 819 | \param update : file is created if FALSE, open for update if TRUE
|
---|
[3668] | 820 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 821 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[2453] | 822 | \param lp : debug level
|
---|
| 823 | */
|
---|
| 824 | FitsImg2DWriter::FitsImg2DWriter(const char* cfname,bool update,int bitpix,int lp)
|
---|
| 825 | : FitsWriter(cfname,update,lp)
|
---|
| 826 | {
|
---|
| 827 | BitPix = bitpix;
|
---|
| 828 | HduType = IMAGE_HDU;
|
---|
| 829 | FirstTime = true;
|
---|
| 830 | Naxis[0] = Naxis[1] = 0;
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | /*! Destructor */
|
---|
| 834 | FitsImg2DWriter::~FitsImg2DWriter()
|
---|
| 835 | {
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | /*! Create the image. Done at the first write request. */
|
---|
| 839 | void FitsImg2DWriter::createimg(void)
|
---|
| 840 | {
|
---|
| 841 | if(!FirstTime)
|
---|
| 842 | throw NotAvailableOperation("FitsImg2DWriter::createimg: already created image\n");
|
---|
| 843 | if(Naxis[0]<=0 || Naxis[1]<=0)
|
---|
| 844 | throw ParmError("FitsImg2DWriter::createimg: bad Naxis 1 or 2 value\n");
|
---|
| 845 |
|
---|
| 846 | int sta=0;
|
---|
[3128] | 847 | if(fits_create_imgll(FitsPtr,BitPix,2,Naxis,&sta)) {
|
---|
[2453] | 848 | printerror(sta);
|
---|
| 849 | throw NullPtrError("FitsImg2DWriter::createimg: Error creating image extension\n");
|
---|
| 850 | }
|
---|
| 851 |
|
---|
| 852 | FirstTime = false;
|
---|
| 853 | }
|
---|
| 854 |
|
---|
| 855 | /*!
|
---|
[3668] | 856 | Write an unsigned byte image to FITS file.
|
---|
| 857 | \warning TMatrix data(Naxis2,Naxis1) means Data(row,column)
|
---|
| 858 | */
|
---|
| 859 | void FitsImg2DWriter::Write(TMatrix<uint_1>& data)
|
---|
| 860 | {
|
---|
| 861 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
---|
| 862 | uint_1* arr = new uint_1[Naxis[0]];
|
---|
| 863 |
|
---|
| 864 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
---|
| 865 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
---|
| 866 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
---|
| 867 | fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
|
---|
| 868 | if(sta) {
|
---|
| 869 | printerrorwrite("uint_1",0,l,sta); delete [] arr;
|
---|
| 870 | throw
|
---|
| 871 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_1>): Error Writing Fits file\n");
|
---|
| 872 | }
|
---|
| 873 | }
|
---|
| 874 |
|
---|
| 875 | delete [] arr;
|
---|
| 876 | }
|
---|
| 877 |
|
---|
| 878 | /*!
|
---|
[2455] | 879 | Write an unsigned short image to FITS file.
|
---|
| 880 | \warning TMatrix data(Naxis2,Naxis1) means Data(row,column)
|
---|
[2453] | 881 | */
|
---|
| 882 | void FitsImg2DWriter::Write(TMatrix<uint_2>& data)
|
---|
| 883 | {
|
---|
| 884 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
---|
| 885 | uint_2* arr = new uint_2[Naxis[0]];
|
---|
| 886 |
|
---|
[3128] | 887 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
---|
| 888 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
---|
| 889 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
---|
[2453] | 890 | fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
|
---|
| 891 | if(sta) {
|
---|
[2455] | 892 | printerrorwrite("uint_2",0,l,sta); delete [] arr;
|
---|
[2453] | 893 | throw
|
---|
| 894 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_2>): Error Writing Fits file\n");
|
---|
| 895 | }
|
---|
| 896 | }
|
---|
| 897 |
|
---|
| 898 | delete [] arr;
|
---|
| 899 | }
|
---|
| 900 |
|
---|
[2455] | 901 | /*! Write a long image to FITS file. */
|
---|
[2453] | 902 | void FitsImg2DWriter::Write(TMatrix<int_4>& data)
|
---|
| 903 | {
|
---|
| 904 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
| 905 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
---|
| 906 | int_4* arr = new int_4[Naxis[0]];
|
---|
| 907 |
|
---|
[3128] | 908 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
---|
| 909 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
---|
| 910 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
---|
[2453] | 911 | fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
|
---|
| 912 | if(sta) {
|
---|
[2455] | 913 | printerrorwrite("int_4",0,l,sta); delete [] arr;
|
---|
[2453] | 914 | throw
|
---|
| 915 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<int_4>): Error Writing Fits file\n");
|
---|
| 916 | }
|
---|
| 917 | }
|
---|
| 918 |
|
---|
| 919 | delete [] arr;
|
---|
| 920 | }
|
---|
| 921 |
|
---|
[2455] | 922 | /*! Write a float image to FITS file. */
|
---|
[2453] | 923 | void FitsImg2DWriter::Write(TMatrix<float>& data)
|
---|
| 924 | {
|
---|
| 925 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
---|
| 926 | float* arr = new float[Naxis[0]];
|
---|
| 927 |
|
---|
[3128] | 928 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
---|
| 929 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
---|
| 930 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
---|
[2453] | 931 | fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
|
---|
| 932 | if(sta) {
|
---|
[2455] | 933 | printerrorwrite("float",0,l,sta); delete [] arr;
|
---|
[2453] | 934 | throw
|
---|
| 935 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<float>): Error Writing Fits file\n");
|
---|
| 936 | }
|
---|
| 937 | }
|
---|
| 938 |
|
---|
| 939 | delete [] arr;
|
---|
| 940 | }
|
---|
| 941 |
|
---|
[2455] | 942 | /*! Write a double image to FITS file. */
|
---|
[2453] | 943 | void FitsImg2DWriter::Write(TMatrix<double>& data)
|
---|
| 944 | {
|
---|
| 945 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
---|
| 946 | double* arr = new double[Naxis[0]];
|
---|
| 947 |
|
---|
[3128] | 948 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
---|
| 949 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
---|
| 950 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
---|
[2453] | 951 | fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
|
---|
| 952 | if(sta) {
|
---|
[2455] | 953 | printerrorwrite("double",0,l,sta); delete [] arr;
|
---|
[2453] | 954 | throw
|
---|
| 955 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<double>): Error Writing Fits file\n");
|
---|
| 956 | }
|
---|
| 957 | }
|
---|
| 958 |
|
---|
| 959 | delete [] arr;
|
---|
| 960 | }
|
---|
| 961 |
|
---|
| 962 | /*! Print infos. */
|
---|
| 963 | void FitsImg2DWriter::Print(ostream& os) const
|
---|
| 964 | {
|
---|
| 965 | os<<"FitsImg2DWriter::Print: FitsFN "<<FitsFN<<endl
|
---|
| 966 | <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow<<" BitPix "<<BitPix
|
---|
| 967 | <<" Naxis1 "<<Naxis[0]<<" Naxis2 "<<Naxis[1]<<endl;
|
---|
| 968 | }
|
---|
[3114] | 969 |
|
---|
| 970 |
|
---|
| 971 | //////////////////////////////////////////////////////////////////
|
---|
| 972 | //////////////////////////////////////////////////////////////////
|
---|
| 973 | //////////////////////////////////////////////////////////////////
|
---|
| 974 | //////////////////////////////////////////////////////////////////
|
---|
| 975 | /*!
|
---|
| 976 | \class SOPHYA::FitsImg3DWriter
|
---|
| 977 | \ingroup FitsIOServer
|
---|
| 978 | Class for writing an 3D image into FITS file
|
---|
| 979 | */
|
---|
| 980 |
|
---|
| 981 | /*!
|
---|
| 982 | Constructor.
|
---|
| 983 | \param fname : FITS file name to be written (a new fits file is created)
|
---|
[3668] | 984 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 985 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[3114] | 986 | \param lp : debug level
|
---|
| 987 | */
|
---|
| 988 | FitsImg3DWriter::FitsImg3DWriter(string fname,int bitpix,int lp)
|
---|
| 989 | : FitsWriter(fname,lp)
|
---|
| 990 | {
|
---|
| 991 | BitPix = bitpix;
|
---|
| 992 | HduType = IMAGE_HDU;
|
---|
| 993 | FirstTime = true;
|
---|
| 994 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 995 | }
|
---|
| 996 |
|
---|
| 997 | /*!
|
---|
| 998 | Constructor.
|
---|
| 999 | \param cfname : FITS file name to be written (a new fits file is created)
|
---|
[3668] | 1000 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 1001 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[3114] | 1002 | \param lp : debug level
|
---|
| 1003 | */
|
---|
| 1004 | FitsImg3DWriter::FitsImg3DWriter(const char* cfname,int bitpix,int lp)
|
---|
| 1005 | : FitsWriter(cfname,lp)
|
---|
| 1006 | {
|
---|
| 1007 | BitPix = bitpix;
|
---|
| 1008 | HduType = IMAGE_HDU;
|
---|
| 1009 | FirstTime = true;
|
---|
| 1010 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 1011 | }
|
---|
| 1012 |
|
---|
| 1013 | /*!
|
---|
| 1014 | Constructor.
|
---|
| 1015 | \param fname : FITS file name to be written (created or updated)
|
---|
| 1016 | \param update : file is created if FALSE, open for update if TRUE
|
---|
[3668] | 1017 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 1018 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[3114] | 1019 | \param lp : debug level
|
---|
| 1020 | */
|
---|
| 1021 | FitsImg3DWriter::FitsImg3DWriter(string fname,bool update,int bitpix,int lp)
|
---|
| 1022 | : FitsWriter(fname,update,lp)
|
---|
| 1023 | {
|
---|
| 1024 | BitPix = bitpix;
|
---|
| 1025 | HduType = IMAGE_HDU;
|
---|
| 1026 | FirstTime = true;
|
---|
| 1027 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 1028 | }
|
---|
| 1029 |
|
---|
| 1030 | /*!
|
---|
| 1031 | Constructor.
|
---|
| 1032 | \param cfname : FITS file name to be written (created or updated)
|
---|
| 1033 | \param update : file is created if FALSE, open for update if TRUE
|
---|
[3668] | 1034 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
---|
| 1035 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
---|
[3114] | 1036 | \param lp : debug level
|
---|
| 1037 | */
|
---|
| 1038 | FitsImg3DWriter::FitsImg3DWriter(const char* cfname,bool update,int bitpix,int lp)
|
---|
| 1039 | : FitsWriter(cfname,update,lp)
|
---|
| 1040 | {
|
---|
| 1041 | BitPix = bitpix;
|
---|
| 1042 | HduType = IMAGE_HDU;
|
---|
| 1043 | FirstTime = true;
|
---|
| 1044 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
| 1047 | /*! Destructor */
|
---|
| 1048 | FitsImg3DWriter::~FitsImg3DWriter()
|
---|
| 1049 | {
|
---|
| 1050 | }
|
---|
| 1051 |
|
---|
| 1052 | /*! Create the 3D image. Done at the first write request. */
|
---|
| 1053 | void FitsImg3DWriter::createimg(void)
|
---|
| 1054 | {
|
---|
| 1055 | if(!FirstTime)
|
---|
| 1056 | throw NotAvailableOperation("FitsImg3DWriter::createimg: already created 3D image\n");
|
---|
| 1057 | if(Naxis[0]<=0 || Naxis[1]<=0 || Naxis[2]<=0)
|
---|
| 1058 | throw ParmError("FitsImg3DWriter::createimg: bad Naxis 1 or 2 or 3 value\n");
|
---|
| 1059 |
|
---|
| 1060 | int sta=0;
|
---|
[3128] | 1061 | if(fits_create_imgll(FitsPtr,BitPix,3,Naxis,&sta)) {
|
---|
[3114] | 1062 | printerror(sta);
|
---|
| 1063 | throw NullPtrError("FitsImg3DWriter::createimg: Error creating 3D image extension\n");
|
---|
| 1064 | }
|
---|
| 1065 |
|
---|
| 1066 | FirstTime = false;
|
---|
| 1067 | }
|
---|
| 1068 |
|
---|
[3668] | 1069 | /*! Create the 3D imageby yourself, ONLY use it with Write(TVector<>& data) */
|
---|
| 1070 | void FitsImg3DWriter::CreateImg(LONGLONG naxis1,LONGLONG naxis2,LONGLONG naxis3)
|
---|
| 1071 | {
|
---|
| 1072 | Naxis[0]=naxis1;
|
---|
| 1073 | Naxis[1]=naxis2;
|
---|
| 1074 | Naxis[2]=naxis3;
|
---|
| 1075 | createimg();
|
---|
| 1076 | }
|
---|
| 1077 |
|
---|
[3114] | 1078 | /*!
|
---|
[3668] | 1079 | Write an unsigned byte 3D image to FITS file.
|
---|
| 1080 | */
|
---|
| 1081 | void FitsImg3DWriter::Write(TArray<uint_1>& data)
|
---|
| 1082 | {
|
---|
| 1083 | if(data.Rank()!=3)
|
---|
| 1084 | throw ParmError("FitsImg3DRd::Write(TArray<uint_1>): not a 3D array\n");
|
---|
| 1085 |
|
---|
| 1086 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
---|
| 1087 | uint_1* arr = new uint_1[Naxis[0]];
|
---|
| 1088 |
|
---|
| 1089 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1090 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
---|
| 1091 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
| 1092 | fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
|
---|
| 1093 | if(sta) {
|
---|
| 1094 | printerrorwrite("uint_1",j,k,sta); delete [] arr;
|
---|
| 1095 | throw
|
---|
| 1096 | NotAvailableOperation("FitsImg3DRd::Write(TArray<uint_1>): Error Writing Fits file\n");
|
---|
| 1097 | }
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
| 1100 | delete [] arr;
|
---|
| 1101 | }
|
---|
| 1102 |
|
---|
| 1103 | /*!
|
---|
[3114] | 1104 | Write an unsigned short 3D image to FITS file.
|
---|
| 1105 | */
|
---|
| 1106 | void FitsImg3DWriter::Write(TArray<uint_2>& data)
|
---|
| 1107 | {
|
---|
| 1108 | if(data.Rank()!=3)
|
---|
| 1109 | throw ParmError("FitsImg3DRd::Write(TArray<uint_2>): not a 3D array\n");
|
---|
| 1110 |
|
---|
| 1111 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
---|
| 1112 | uint_2* arr = new uint_2[Naxis[0]];
|
---|
| 1113 |
|
---|
[3128] | 1114 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1115 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
---|
| 1116 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
[3114] | 1117 | fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
|
---|
| 1118 | if(sta) {
|
---|
| 1119 | printerrorwrite("uint_2",j,k,sta); delete [] arr;
|
---|
| 1120 | throw
|
---|
| 1121 | NotAvailableOperation("FitsImg3DRd::Write(TArray<uint_2>): Error Writing Fits file\n");
|
---|
| 1122 | }
|
---|
| 1123 | }
|
---|
| 1124 |
|
---|
| 1125 | delete [] arr;
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
| 1128 | /*! Write a long 3D image to FITS file. */
|
---|
| 1129 | void FitsImg3DWriter::Write(TArray<int_4>& data)
|
---|
| 1130 | {
|
---|
| 1131 | if(data.Rank()!=3)
|
---|
| 1132 | throw ParmError("FitsImg3DRd::Write(TArray<int_4>): not a 3D array\n");
|
---|
| 1133 |
|
---|
| 1134 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
| 1135 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
---|
| 1136 | int_4* arr = new int_4[Naxis[0]];
|
---|
| 1137 |
|
---|
[3128] | 1138 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1139 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
---|
| 1140 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
[3114] | 1141 | fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
|
---|
| 1142 | if(sta) {
|
---|
| 1143 | printerrorwrite("int_4",j,k,sta); delete [] arr;
|
---|
| 1144 | throw
|
---|
| 1145 | NotAvailableOperation("FitsImg3DRd::Write(TArray<int_4>): Error Writing Fits file\n");
|
---|
| 1146 | }
|
---|
| 1147 | }
|
---|
| 1148 |
|
---|
| 1149 | delete [] arr;
|
---|
| 1150 | }
|
---|
| 1151 |
|
---|
| 1152 | /*! Write a float 3D image to FITS file. */
|
---|
| 1153 | void FitsImg3DWriter::Write(TArray<float>& data)
|
---|
| 1154 | {
|
---|
| 1155 | if(data.Rank()!=3)
|
---|
| 1156 | throw ParmError("FitsImg3DRd::Write(TArray<float>): not a 3D array\n");
|
---|
| 1157 |
|
---|
| 1158 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
---|
| 1159 | float* arr = new float[Naxis[0]];
|
---|
| 1160 |
|
---|
[3128] | 1161 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1162 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
---|
| 1163 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
[3114] | 1164 | fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
|
---|
| 1165 | if(sta) {
|
---|
| 1166 | printerrorwrite("float",j,k,sta); delete [] arr;
|
---|
| 1167 | throw
|
---|
| 1168 | NotAvailableOperation("FitsImg3DRd::Write(TArray<float>): Error Writing Fits file\n");
|
---|
| 1169 | }
|
---|
| 1170 | }
|
---|
| 1171 |
|
---|
| 1172 | delete [] arr;
|
---|
| 1173 | }
|
---|
| 1174 |
|
---|
| 1175 | /*! Write a double 3D image to FITS file. */
|
---|
| 1176 | void FitsImg3DWriter::Write(TArray<double>& data)
|
---|
| 1177 | {
|
---|
| 1178 | if(data.Rank()!=3)
|
---|
| 1179 | throw ParmError("FitsImg3DRd::Write(TArray<double>): not a 3D array\n");
|
---|
| 1180 |
|
---|
| 1181 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
---|
| 1182 | double* arr = new double[Naxis[0]];
|
---|
| 1183 |
|
---|
[3128] | 1184 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1185 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
---|
| 1186 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
[3114] | 1187 | fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
|
---|
| 1188 | if(sta) {
|
---|
| 1189 | printerrorwrite("double",j,k,sta); delete [] arr;
|
---|
| 1190 | throw
|
---|
| 1191 | NotAvailableOperation("FitsImg3DRd::Write(TArray<double>): Error Writing Fits file\n");
|
---|
| 1192 | }
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
| 1195 | delete [] arr;
|
---|
| 1196 | }
|
---|
| 1197 |
|
---|
[3668] | 1198 | /*!
|
---|
| 1199 | Write an unsigned byte Vector<> image to 3D FITS file.
|
---|
| 1200 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
---|
| 1201 | so IMG(i,j,k) = Vector(i)
|
---|
| 1202 | */
|
---|
| 1203 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<uint_1>& data)
|
---|
| 1204 | {
|
---|
| 1205 | if(FirstTime)
|
---|
| 1206 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): use CreateImg first !\n");
|
---|
| 1207 | if(data.Size()!=Naxis[0])
|
---|
| 1208 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): wrong vector size\n");
|
---|
| 1209 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
---|
| 1210 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): j or k out of range\n");
|
---|
| 1211 | uint_1* arr = const_cast<uint_1 *>(data.Data());
|
---|
| 1212 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
| 1213 | fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
|
---|
| 1214 | if(sta) {
|
---|
| 1215 | printerrorwrite("uint_1",j,k,sta); delete [] arr;
|
---|
| 1216 | throw
|
---|
| 1217 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): Error Writing Fits file\n");
|
---|
| 1218 | }
|
---|
| 1219 | }
|
---|
| 1220 |
|
---|
| 1221 | /*!
|
---|
| 1222 | Write an unsigned short Vector<> image to 3D FITS file.
|
---|
| 1223 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
---|
| 1224 | so IMG(i,j,k) = Vector(i)
|
---|
| 1225 | */
|
---|
| 1226 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<uint_2>& data)
|
---|
| 1227 | {
|
---|
| 1228 | if(FirstTime)
|
---|
| 1229 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): use CreateImg first !\n");
|
---|
| 1230 | if(data.Size()!=Naxis[0])
|
---|
| 1231 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): wrong vector size\n");
|
---|
| 1232 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
---|
| 1233 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): j or k out of range\n");
|
---|
| 1234 | uint_2* arr = const_cast<uint_2 *>(data.Data());
|
---|
| 1235 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
| 1236 | fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
|
---|
| 1237 | if(sta) {
|
---|
| 1238 | printerrorwrite("uint_2",j,k,sta); delete [] arr;
|
---|
| 1239 | throw
|
---|
| 1240 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): Error Writing Fits file\n");
|
---|
| 1241 | }
|
---|
| 1242 | }
|
---|
| 1243 |
|
---|
| 1244 | /*!
|
---|
| 1245 | Write an long Vector<> image to 3D FITS file.
|
---|
| 1246 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
---|
| 1247 | so IMG(i,j,k) = Vector(i)
|
---|
| 1248 | */
|
---|
| 1249 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<int_4>& data)
|
---|
| 1250 | {
|
---|
| 1251 | if(FirstTime)
|
---|
| 1252 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): use CreateImg first !\n");
|
---|
| 1253 | if(data.Size()!=Naxis[0])
|
---|
| 1254 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): wrong vector size\n");
|
---|
| 1255 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
---|
| 1256 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): j or k out of range\n");
|
---|
| 1257 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
| 1258 | int_4* arr = const_cast<int_4 *>(data.Data());
|
---|
| 1259 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
| 1260 | fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
|
---|
| 1261 | if(sta) {
|
---|
| 1262 | printerrorwrite("int_4",j,k,sta); delete [] arr;
|
---|
| 1263 | throw
|
---|
| 1264 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): Error Writing Fits file\n");
|
---|
| 1265 | }
|
---|
| 1266 | }
|
---|
| 1267 |
|
---|
| 1268 | /*!
|
---|
| 1269 | Write an float Vector<> image to 3D FITS file.
|
---|
| 1270 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
---|
| 1271 | so IMG(i,j,k) = Vector(i)
|
---|
| 1272 | */
|
---|
| 1273 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<float>& data)
|
---|
| 1274 | {
|
---|
| 1275 | if(FirstTime)
|
---|
| 1276 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): use CreateImg first !\n");
|
---|
| 1277 | if(data.Size()!=Naxis[0])
|
---|
| 1278 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): wrong vector size\n");
|
---|
| 1279 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
---|
| 1280 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): j or k out of range\n");
|
---|
| 1281 | float* arr = const_cast<float *>(data.Data());
|
---|
| 1282 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
| 1283 | fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
|
---|
| 1284 | if(sta) {
|
---|
| 1285 | printerrorwrite("float",j,k,sta); delete [] arr;
|
---|
| 1286 | throw
|
---|
| 1287 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): Error Writing Fits file\n");
|
---|
| 1288 | }
|
---|
| 1289 | }
|
---|
| 1290 |
|
---|
| 1291 | /*!
|
---|
| 1292 | Write an double Vector<> image to 3D FITS file.
|
---|
| 1293 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
---|
| 1294 | so IMG(i,j,k) = Vector(i)
|
---|
| 1295 | */
|
---|
| 1296 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<double>& data)
|
---|
| 1297 | {
|
---|
| 1298 | if(FirstTime)
|
---|
| 1299 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): use CreateImg first !\n");
|
---|
| 1300 | if(data.Size()!=Naxis[0])
|
---|
| 1301 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): wrong vector size\n");
|
---|
| 1302 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
---|
| 1303 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): j or k out of range\n");
|
---|
| 1304 | double* arr = const_cast<double *>(data.Data());
|
---|
| 1305 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
---|
| 1306 | fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
|
---|
| 1307 | if(sta) {
|
---|
| 1308 | printerrorwrite("double",j,k,sta); delete [] arr;
|
---|
| 1309 | throw
|
---|
| 1310 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): Error Writing Fits file\n");
|
---|
| 1311 | }
|
---|
| 1312 | }
|
---|
| 1313 |
|
---|
[3114] | 1314 | /*! Print infos. */
|
---|
| 1315 | void FitsImg3DWriter::Print(ostream& os) const
|
---|
| 1316 | {
|
---|
| 1317 | os<<"FitsImg3DWriter::Print: FitsFN "<<FitsFN<<endl
|
---|
| 1318 | <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow<<" BitPix "<<BitPix
|
---|
| 1319 | <<" Naxis1 "<<Naxis[0]<<" Naxis2 "<<Naxis[1]<<" Naxis3 "<<Naxis[2]<<endl;
|
---|
| 1320 | }
|
---|