| 1 | /* Writer de table Fits (binaire ou ASCII) */
|
|---|
| 2 | #include "sopnamsp.h"
|
|---|
| 3 | #include "machdefs.h"
|
|---|
| 4 | #include <stdlib.h>
|
|---|
| 5 | #include <stdio.h>
|
|---|
| 6 | #include "pexceptions.h"
|
|---|
| 7 | #include "fabtwriter.h"
|
|---|
| 8 |
|
|---|
| 9 | //////////////////////////////////////////////////////////////
|
|---|
| 10 | //////////////////////////////////////////////////////////////
|
|---|
| 11 | //////////////////////////////////////////////////////////////
|
|---|
| 12 | //////////////////////////////////////////////////////////////
|
|---|
| 13 | /*!
|
|---|
| 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);
|
|---|
| 55 | LongLongKey.resize(0);
|
|---|
| 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
|
|---|
| 81 | //LONGLONG naxes[1] = {0};
|
|---|
| 82 | //if(fits_create_imgll(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
|
|---|
| 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 */
|
|---|
| 107 | void FitsWriter::WriteKey(const char *keyname,double val,const char* comment)
|
|---|
| 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 */
|
|---|
| 118 | void FitsWriter::WriteKey(const char *keyname,long val,const char* comment)
|
|---|
| 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 |
|
|---|
| 128 | /*! Write a long long value into Fits Header */
|
|---|
| 129 | void FitsWriter::WriteKey(const char *keyname,LONGLONG val,const char* comment)
|
|---|
| 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 |
|
|---|
| 139 | /*! Write a string value into Fits Header */
|
|---|
| 140 | void FitsWriter::WriteKey(const char *keyname,string val,const char* comment)
|
|---|
| 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)
|
|---|
| 156 | for(unsigned long i=0;i<DoubleKey.size();i++) {
|
|---|
| 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)
|
|---|
| 164 | for(unsigned long i=0;i<LongKey.size();i++) {
|
|---|
| 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 | }
|
|---|
| 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 | }
|
|---|
| 179 | if(StringKey.size()>0)
|
|---|
| 180 | for(unsigned long i=0;i<StringKey.size();i++) {
|
|---|
| 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);
|
|---|
| 189 | LongLongKey.resize(0);
|
|---|
| 190 | StringKey.resize(0);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | void FitsWriter::printerrorwrite(const char* type,int col,LONGLONG row,int sta)
|
|---|
| 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"
|
|---|
| 199 | ,type,col,(long)row,sta);
|
|---|
| 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 | /*!
|
|---|
| 216 | \class SOPHYA::FitsABTWriter
|
|---|
| 217 | \ingroup FitsIOServer
|
|---|
| 218 | Class for writing a FITS ASCII or BINARY table
|
|---|
| 219 | \verbatim
|
|---|
| 220 | //-----------------------------------------------------------
|
|---|
| 221 | OPENING A NEW FILE AND WRITING INTO
|
|---|
| 222 | -- Exemple 1: Writing element by element
|
|---|
| 223 | FitsABTWriter fbtw(fitswrit,BINARY_TBL);
|
|---|
| 224 | fbtw.SetExtName("MY_OWN_EXTENSION");
|
|---|
| 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
|
|---|
| 230 | fbtw.SetDebug(3);
|
|---|
| 231 | for(LONGLONG i=0;i<1000;i++) {
|
|---|
| 232 | double x = i;
|
|---|
| 233 | fbtw.Write(c1,i,1000.*x); // if overflow, managed by cfitsio
|
|---|
| 234 | // Write(int,long,double) is called
|
|---|
| 235 | fbtw.Write(c2,i,(short)(1000.*x));
|
|---|
| 236 | // if overflow, managed by language
|
|---|
| 237 | // Write(int,long,short) is called
|
|---|
| 238 | fbtw.Write(c3,i,x);
|
|---|
| 239 | fbtw.Write(c4,i,x);
|
|---|
| 240 | fbtw.Write(c5,i,x);
|
|---|
| 241 | }
|
|---|
| 242 | cout<<"Number of Overflows when writing: "
|
|---|
| 243 | <<fbtw.GetNOverFlow()<<endl;
|
|---|
| 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);
|
|---|
| 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) = ...;
|
|---|
| 256 | fbtw.Write(1,i,datal);
|
|---|
| 257 | fbtw.Write(2,i,dataf);
|
|---|
| 258 | fbtw.Write(3,i,datad);
|
|---|
| 259 | }
|
|---|
| 260 | \endverbatim
|
|---|
| 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");
|
|---|
| 274 | fbtw.WriteKey("MYKEYLL",(LONGLONG)123456789,"my LONGLONG key");
|
|---|
| 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");
|
|---|
| 289 | fbtw2.WriteKey("MYKEYLL",(LONGLONG)-123456789,"my new LONGLONG key");
|
|---|
| 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;
|
|---|
| 300 | for(LONGLONG i=0;i<NNN;i++) {
|
|---|
| 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
|
|---|
| 318 | */
|
|---|
| 319 |
|
|---|
| 320 | //////////////////////////////////////////////////////////////
|
|---|
| 321 | /*!
|
|---|
| 322 | Constructor.
|
|---|
| 323 | \param fname : FITS file name to be written (a new fits file is created)
|
|---|
| 324 | \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
|
|---|
| 325 | \param lp : debug level
|
|---|
| 326 | */
|
|---|
| 327 | FitsABTWriter::FitsABTWriter(string fname,int hdutype,int lp)
|
|---|
| 328 | : FitsWriter(fname,lp)
|
|---|
| 329 | {
|
|---|
| 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");
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 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 | */
|
|---|
| 343 | FitsABTWriter::FitsABTWriter(const char* cfname,int hdutype,int lp)
|
|---|
| 344 | : FitsWriter(cfname,lp)
|
|---|
| 345 | {
|
|---|
| 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");
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 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)
|
|---|
| 361 | : FitsWriter(fname,update,lp)
|
|---|
| 362 | {
|
|---|
| 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");
|
|---|
| 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)
|
|---|
| 378 | : FitsWriter(cfname,update,lp)
|
|---|
| 379 | {
|
|---|
| 380 | FirstTime = true;
|
|---|
| 381 | HduType = hdutype;
|
|---|
| 382 | if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
|
|---|
| 383 | throw
|
|---|
| 384 | TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n");
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | /*! Destructor */
|
|---|
| 388 | FitsABTWriter::~FitsABTWriter()
|
|---|
| 389 | {
|
|---|
| 390 | // On cree la table avant de fermer le fichier si pas deja fait
|
|---|
| 391 | if(FirstTime) createtbl();
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | //////////////////////////////////////////////////////////////
|
|---|
| 395 | /*!
|
|---|
| 396 | Add a new column to the FITS table
|
|---|
| 397 | \param label : column label
|
|---|
| 398 | \param tform : fits tform definition ("1I","1J","1E","1J",...)
|
|---|
| 399 | (can be automatically set as "datatype"
|
|---|
| 400 | if BINARY_TBL and tform="" or tform=NULL)
|
|---|
| 401 | \param tunit : fits tunit definition (optional)
|
|---|
| 402 | \param datatype : TBYTE TSHORT TLONG (TINT32BIT) TLONGLONG TFLOAT TDOUBLE
|
|---|
| 403 | TUSHORT TULONG TSBYTE. That parameter is only use in case
|
|---|
| 404 | of a BINARY_TBL table when tform is not defined).
|
|---|
| 405 | \return The number of the new added column in the table.
|
|---|
| 406 | \warning col = [0,ncol-1]
|
|---|
| 407 | */
|
|---|
| 408 | int FitsABTWriter::addcol(const char* label,const char* tform
|
|---|
| 409 | ,const char* tunit,int datatype)
|
|---|
| 410 | {
|
|---|
| 411 | if(!FirstTime)
|
|---|
| 412 | throw AllocationError("FitsABTWriter::addcol: table already created\n");
|
|---|
| 413 |
|
|---|
| 414 | // Gestion auto du tform pour les tables binaires avec le datatype (si non-definie)
|
|---|
| 415 | bool tformauto = false;
|
|---|
| 416 | if(HduType==BINARY_TBL || HduType==ASCII_TBL) {
|
|---|
| 417 | if(tform==NULL) tformauto = true;
|
|---|
| 418 | else if(strlen(tform)<=0) tformauto = true;
|
|---|
| 419 | }
|
|---|
| 420 | if(tformauto && HduType==BINARY_TBL) {
|
|---|
| 421 | char str[8];
|
|---|
| 422 | if(datatype==TBYTE) strcpy(str,"1B");
|
|---|
| 423 | else if(datatype==TSHORT) strcpy(str,"1I");
|
|---|
| 424 | else if(datatype==TLONG) strcpy(str,"1J");
|
|---|
| 425 | #ifdef TINT32BIT
|
|---|
| 426 | else if(datatype==TINT32BIT) strcpy(str,"1J");
|
|---|
| 427 | #endif
|
|---|
| 428 | #ifdef TLONGLONG
|
|---|
| 429 | else if(datatype==TLONGLONG) strcpy(str,"1K");
|
|---|
| 430 | #endif
|
|---|
| 431 | else if(datatype==TFLOAT) strcpy(str,"1E");
|
|---|
| 432 | else if(datatype==TDOUBLE) strcpy(str,"1D");
|
|---|
| 433 | else if(datatype==TUSHORT) strcpy(str,"1U");
|
|---|
| 434 | else if(datatype==TULONG) strcpy(str,"1V");
|
|---|
| 435 | #ifdef TSBYTE
|
|---|
| 436 | else if(datatype==TSBYTE) strcpy(str,"1S");
|
|---|
| 437 | #endif
|
|---|
| 438 | else
|
|---|
| 439 | throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
|
|---|
| 440 | TForm.push_back(str);
|
|---|
| 441 | } else if(tformauto && HduType==ASCII_TBL) {
|
|---|
| 442 | char str[8];
|
|---|
| 443 | if(datatype==TBYTE) strcpy(str,"I5");
|
|---|
| 444 | else if(datatype==TSHORT) strcpy(str,"I7");
|
|---|
| 445 | else if(datatype==TLONG) strcpy(str,"I11");
|
|---|
| 446 | #ifdef TINT32BIT
|
|---|
| 447 | else if(datatype==TINT32BIT) strcpy(str,"I11");
|
|---|
| 448 | #endif
|
|---|
| 449 | #ifdef TLONGLONG
|
|---|
| 450 | else if(datatype==TLONGLONG) strcpy(str,"I21");
|
|---|
| 451 | #endif
|
|---|
| 452 | else if(datatype==TFLOAT) strcpy(str,"E29.20");
|
|---|
| 453 | else if(datatype==TDOUBLE) strcpy(str,"E29.20");
|
|---|
| 454 | else if(datatype==TUSHORT) strcpy(str,"I7");
|
|---|
| 455 | else if(datatype==TULONG) strcpy(str,"I11");
|
|---|
| 456 | #ifdef TSBYTE
|
|---|
| 457 | else if(datatype==TSBYTE) strcpy(str,"I5");
|
|---|
| 458 | #endif
|
|---|
| 459 | else
|
|---|
| 460 | throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
|
|---|
| 461 | TForm.push_back(str);
|
|---|
| 462 | } else {
|
|---|
| 463 | if(tform) TForm.push_back(tform); else TForm.push_back("");
|
|---|
| 464 | datatype = 0;
|
|---|
| 465 | }
|
|---|
| 466 | Label.push_back(label);
|
|---|
| 467 | if(tunit) TUnit.push_back(tunit); else TUnit.push_back("");
|
|---|
| 468 |
|
|---|
| 469 | int n = (int) Label.size() -1;
|
|---|
| 470 |
|
|---|
| 471 | if(DbgLevel)
|
|---|
| 472 | cout<<"FitsABTWriter::addcol["<<n<<"] Label="<<Label[n]
|
|---|
| 473 | <<" TForm="<<TForm[n]
|
|---|
| 474 | <<" TUnit="<<TUnit[n]
|
|---|
| 475 | <<" datatype="<<datatype<<endl;
|
|---|
| 476 |
|
|---|
| 477 | return n;
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | /*! Create the table. Done at the first write request. */
|
|---|
| 481 | void FitsABTWriter::createtbl(void)
|
|---|
| 482 | {
|
|---|
| 483 | if(!FirstTime) return;
|
|---|
| 484 |
|
|---|
| 485 | int tfields = Label.size();
|
|---|
| 486 | if(tfields<=0)
|
|---|
| 487 | throw ParmError("FitsABTWriter::createtbl: Zero column asked !\n");
|
|---|
| 488 |
|
|---|
| 489 | LONGLONG nrows = 0;
|
|---|
| 490 | char *extname = NULL;
|
|---|
| 491 | char **ttype = (char **) malloc(tfields*sizeof(char *));
|
|---|
| 492 | char **tform = (char **) malloc(tfields*sizeof(char *));
|
|---|
| 493 | char **tunit = (char **) malloc(tfields*sizeof(char *));
|
|---|
| 494 |
|
|---|
| 495 | if(ExtName.size()>0) {
|
|---|
| 496 | extname = (char *) malloc((strlen(ExtName.c_str())+1)*sizeof(char));
|
|---|
| 497 | strcpy(extname,ExtName.c_str());
|
|---|
| 498 | }
|
|---|
| 499 | for(int i=0;i<tfields;i++) {
|
|---|
| 500 | ttype[i] = (char *) malloc((strlen(Label[i].c_str())+1)*sizeof(char));
|
|---|
| 501 | strcpy(ttype[i],Label[i].c_str());
|
|---|
| 502 | tform[i] = (char *) malloc((strlen(TForm[i].c_str())+1)*sizeof(char));
|
|---|
| 503 | strcpy(tform[i],TForm[i].c_str());
|
|---|
| 504 | tunit[i] = (char *) malloc((strlen(TUnit[i].c_str())+1)*sizeof(char));
|
|---|
| 505 | strcpy(tunit[i],TUnit[i].c_str());
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | // append a new empty binary/ascii table onto the FITS file
|
|---|
| 509 | int sta=0;
|
|---|
| 510 | if(fits_create_tbl(FitsPtr,HduType,nrows,tfields,ttype,tform,tunit,extname,&sta)) {
|
|---|
| 511 | printerror(sta);
|
|---|
| 512 | throw NullPtrError("FitsABTWriter::createtbl: Error creating Table extension\n");
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | // menage
|
|---|
| 516 | if(extname) delete [] extname;
|
|---|
| 517 | for(int i=0;i<tfields;i++) {
|
|---|
| 518 | if(ttype[i]) delete [] ttype[i];
|
|---|
| 519 | if(tform[i]) delete [] tform[i];
|
|---|
| 520 | if(tunit[i]) delete [] tunit[i];
|
|---|
| 521 | }
|
|---|
| 522 | if(ttype) delete [] ttype;
|
|---|
| 523 | if(tform) delete [] tform;
|
|---|
| 524 | if(tunit) delete [] tunit;
|
|---|
| 525 |
|
|---|
| 526 | FirstTime = false;
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | //////////////////////////////////////////////////////////////
|
|---|
| 530 | /*!
|
|---|
| 531 | Write a data to FITS file.
|
|---|
| 532 | \param col : column number [0,ncol[
|
|---|
| 533 | \param row : row number [0,nrow[
|
|---|
| 534 | \param val : value to be written
|
|---|
| 535 | \warning that routine write a SHORT value into column "col"
|
|---|
| 536 | which could have been defined with an other type.
|
|---|
| 537 | Cast is performed by the cfitsio package.
|
|---|
| 538 | \verbatim
|
|---|
| 539 | WARNING: suppose that the column has be defined to be TSHORT
|
|---|
| 540 | and suppose that you wanted to write a double value "val"
|
|---|
| 541 | - If you write dummy.Write(col,row,(short)(val))
|
|---|
| 542 | the Write(int,long,short) routine is called and
|
|---|
| 543 | the cast is performed by the C++ language.
|
|---|
| 544 | - If you write dummy.Write(col,row,val) where val is double
|
|---|
| 545 | the Write(int,long,double) routine is called and
|
|---|
| 546 | the cast is performed by the cfistio package.
|
|---|
| 547 | \endverbatim
|
|---|
| 548 | */
|
|---|
| 549 |
|
|---|
| 550 | /*! Write signed char (1 Byte) data to FITS file (see below) */
|
|---|
| 551 | void FitsABTWriter::Write(int col,LONGLONG row,int_1 val)
|
|---|
| 552 | {
|
|---|
| 553 | #ifdef TSBYTE
|
|---|
| 554 | if(FirstTime) createtbl();
|
|---|
| 555 | int sta=0;
|
|---|
| 556 | if(fits_write_col(FitsPtr,TSBYTE,col+1,row+1,1,1,&val,&sta))
|
|---|
| 557 | printerrorwrite("signed char",col,row,sta);
|
|---|
| 558 | #else
|
|---|
| 559 | throw PException("FitsABTWriter::Write(..,int_1) Not in that cfitsio version");
|
|---|
| 560 | #endif
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | /*! Write unsigned char (1 Byte) data to FITS file (see below) */
|
|---|
| 564 | void FitsABTWriter::Write(int col,LONGLONG row,uint_1 val)
|
|---|
| 565 | {
|
|---|
| 566 | if(FirstTime) createtbl();
|
|---|
| 567 | int sta=0;
|
|---|
| 568 | if(fits_write_col(FitsPtr,TBYTE,col+1,row+1,1,1,&val,&sta))
|
|---|
| 569 | printerrorwrite("unsigned char",col,row,sta);
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | /*! Write short (2 Bytes) data to FITS file (see below) */
|
|---|
| 573 | void FitsABTWriter::Write(int col,LONGLONG row,int_2 val)
|
|---|
| 574 | {
|
|---|
| 575 | if(FirstTime) createtbl();
|
|---|
| 576 | int sta=0;
|
|---|
| 577 | if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,&val,&sta))
|
|---|
| 578 | printerrorwrite("short",col,row,sta);
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | /*! Write unsigned short (2 Bytes) data to FITS file (see below) */
|
|---|
| 582 | void FitsABTWriter::Write(int col,LONGLONG row,uint_2 val)
|
|---|
| 583 | {
|
|---|
| 584 | if(FirstTime) createtbl();
|
|---|
| 585 | int sta=0;
|
|---|
| 586 | if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,1,1,&val,&sta))
|
|---|
| 587 | printerrorwrite("unsigned short",col,row,sta);
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | /*! Write long (4 Bytes) data to FITS file (see below) */
|
|---|
| 591 | void FitsABTWriter::Write(int col,LONGLONG row,int_4 val)
|
|---|
| 592 | {
|
|---|
| 593 | if(FirstTime) createtbl();
|
|---|
| 594 | int sta=0;
|
|---|
| 595 | // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
|
|---|
| 596 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
|---|
| 597 | if(fits_write_col(FitsPtr,T,col+1,row+1,1,1,&val,&sta))
|
|---|
| 598 | printerrorwrite("long",col,row,sta);
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | /*! Write unsigned long (4 Bytes) data to FITS file (see below) */
|
|---|
| 602 | void FitsABTWriter::Write(int col,LONGLONG row,uint_4 val)
|
|---|
| 603 | {
|
|---|
| 604 | if(FirstTime) createtbl();
|
|---|
| 605 | int sta=0;
|
|---|
| 606 | // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
|
|---|
| 607 | int T = (sizeof(unsigned long)==4) ? TULONG: TUINT;
|
|---|
| 608 | if(fits_write_col(FitsPtr,T,col+1,row+1,1,1,&val,&sta))
|
|---|
| 609 | printerrorwrite("long",col,row,sta);
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | /*! Write long long (8 Bytes) data to FITS file (see below) */
|
|---|
| 613 | void FitsABTWriter::Write(int col,LONGLONG row,int_8 val)
|
|---|
| 614 | {
|
|---|
| 615 | #ifdef TLONGLONG
|
|---|
| 616 | if(FirstTime) createtbl();
|
|---|
| 617 | int sta=0;
|
|---|
| 618 | if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,1,1,&val,&sta))
|
|---|
| 619 | printerrorwrite("long long",col,row,sta);
|
|---|
| 620 | #else
|
|---|
| 621 | throw PException("FitsABTWriter::Write(..,int_8) Not in that cfitsio version");
|
|---|
| 622 | #endif
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 | /*! Write float data to FITS file (see below) */
|
|---|
| 626 | void FitsABTWriter::Write(int col,LONGLONG row,float val)
|
|---|
| 627 | {
|
|---|
| 628 | if(FirstTime) createtbl();
|
|---|
| 629 | int sta=0;
|
|---|
| 630 | if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,&val,&sta))
|
|---|
| 631 | printerrorwrite("float",col,row,sta);
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | /*! Write double data to FITS file (see below) */
|
|---|
| 635 | void FitsABTWriter::Write(int col,LONGLONG row,double val)
|
|---|
| 636 | {
|
|---|
| 637 | if(FirstTime) createtbl();
|
|---|
| 638 | int sta=0;
|
|---|
| 639 | if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,&val,&sta))
|
|---|
| 640 | printerrorwrite("double",col,row,sta);
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | //////////////////////////////////////////////////////////////
|
|---|
| 644 | /*!
|
|---|
| 645 | Write a vector of data to FITS file.
|
|---|
| 646 | \param col : column number [0,ncol[
|
|---|
| 647 | \param row : starting row number [0,nrow[
|
|---|
| 648 | \param val : vector to be written
|
|---|
| 649 | \return "N" = number of the next row to be written,
|
|---|
| 650 | that is "N-1" is the number of the last row written.
|
|---|
| 651 | */
|
|---|
| 652 |
|
|---|
| 653 | /*! Write a vector of unsigned short (2 Bytes) data to FITS file (see below) */
|
|---|
| 654 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<uint_2>& val)
|
|---|
| 655 | {
|
|---|
| 656 | if(FirstTime) createtbl();
|
|---|
| 657 | LONGLONG nel = val.Size();
|
|---|
| 658 | int sta=0;
|
|---|
| 659 | if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,1,nel,val.Data(),&sta))
|
|---|
| 660 | printerrorwrite("long",col,row,sta);
|
|---|
| 661 | return row+nel;
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | /*! Write a vector of long (4 Bytes) data to FITS file (see below) */
|
|---|
| 665 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_4>& val)
|
|---|
| 666 | {
|
|---|
| 667 | if(FirstTime) createtbl();
|
|---|
| 668 | LONGLONG nel = val.Size();
|
|---|
| 669 | int sta=0;
|
|---|
| 670 | // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
|
|---|
| 671 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
|---|
| 672 | if(fits_write_col(FitsPtr,T,col+1,row+1,1,nel,val.Data(),&sta))
|
|---|
| 673 | printerrorwrite("long",col,row,sta);
|
|---|
| 674 | return row+nel;
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | /*! Write a vector of long long (8 Bytes) data to FITS file (see below) */
|
|---|
| 678 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_8>& val)
|
|---|
| 679 | {
|
|---|
| 680 | #ifdef TLONGLONG
|
|---|
| 681 | if(FirstTime) createtbl();
|
|---|
| 682 | LONGLONG nel = val.Size();
|
|---|
| 683 | int sta=0;
|
|---|
| 684 | if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,1,nel,val.Data(),&sta))
|
|---|
| 685 | printerrorwrite("long long",col,row,sta);
|
|---|
| 686 | return row+nel;
|
|---|
| 687 | #else
|
|---|
| 688 | throw PException("FitsABTWriter::Write(..,TVector<int_8>&) Not in that cfitsio version");
|
|---|
| 689 | #endif
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 | /*! Write a vector of float data to FITS file (see below) */
|
|---|
| 693 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<float>& val)
|
|---|
| 694 | {
|
|---|
| 695 | if(FirstTime) createtbl();
|
|---|
| 696 | LONGLONG nel = val.Size();
|
|---|
| 697 | int sta=0;
|
|---|
| 698 | if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta))
|
|---|
| 699 | printerrorwrite("float",col,row,sta);
|
|---|
| 700 | return row+nel;
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | /*! Write a vector of double data to FITS file (see below) */
|
|---|
| 704 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<double>& val)
|
|---|
| 705 | {
|
|---|
| 706 | if(FirstTime) createtbl();
|
|---|
| 707 | LONGLONG nel = val.Size();
|
|---|
| 708 | int sta=0;
|
|---|
| 709 | if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta))
|
|---|
| 710 | printerrorwrite("double",col,row,sta);
|
|---|
| 711 | return row+nel;
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | /////////////////////////////////////////////////
|
|---|
| 715 | void FitsABTWriter::Print(ostream& os,int lp) const
|
|---|
| 716 | {
|
|---|
| 717 | os<<"FitsABTWriter::Print: FitsFN "<<FitsFN<<endl
|
|---|
| 718 | <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow
|
|---|
| 719 | <<" NCol "<<Label.size()<<endl;
|
|---|
| 720 | if(Label.size()>0 && lp>=1)
|
|---|
| 721 | for(int i=0;i<(int)Label.size();i++)
|
|---|
| 722 | os<<i<<"... Label="<<Label[i]<<" TForm="<<TForm[i]<<" TUnit="<<TUnit[i]<<endl;
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | //////////////////////////////////////////////////////////////////
|
|---|
| 726 | //////////////////////////////////////////////////////////////////
|
|---|
| 727 | //////////////////////////////////////////////////////////////////
|
|---|
| 728 | //////////////////////////////////////////////////////////////////
|
|---|
| 729 | /*!
|
|---|
| 730 | \class SOPHYA::FitsImg2DWriter
|
|---|
| 731 | \ingroup FitsIOServer
|
|---|
| 732 | Class for writing an image into FITS file
|
|---|
| 733 | */
|
|---|
| 734 |
|
|---|
| 735 | /*!
|
|---|
| 736 | Constructor.
|
|---|
| 737 | \param fname : FITS file name to be written (a new fits file is created)
|
|---|
| 738 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 739 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 740 | \param lp : debug level
|
|---|
| 741 | */
|
|---|
| 742 | FitsImg2DWriter::FitsImg2DWriter(string fname,int bitpix,int lp)
|
|---|
| 743 | : FitsWriter(fname,lp)
|
|---|
| 744 | {
|
|---|
| 745 | BitPix = bitpix;
|
|---|
| 746 | HduType = IMAGE_HDU;
|
|---|
| 747 | FirstTime = true;
|
|---|
| 748 | Naxis[0] = Naxis[1] = 0;
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | /*!
|
|---|
| 752 | Constructor.
|
|---|
| 753 | \param cfname : FITS file name to be written (a new fits file is created)
|
|---|
| 754 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 755 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 756 | \param lp : debug level
|
|---|
| 757 | */
|
|---|
| 758 | FitsImg2DWriter::FitsImg2DWriter(const char* cfname,int bitpix,int lp)
|
|---|
| 759 | : FitsWriter(cfname,lp)
|
|---|
| 760 | {
|
|---|
| 761 | BitPix = bitpix;
|
|---|
| 762 | HduType = IMAGE_HDU;
|
|---|
| 763 | FirstTime = true;
|
|---|
| 764 | Naxis[0] = Naxis[1] = 0;
|
|---|
| 765 | }
|
|---|
| 766 |
|
|---|
| 767 | /*!
|
|---|
| 768 | Constructor.
|
|---|
| 769 | \param fname : FITS file name to be written (created or updated)
|
|---|
| 770 | \param update : file is created if FALSE, open for update if TRUE
|
|---|
| 771 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 772 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 773 | \param lp : debug level
|
|---|
| 774 | */
|
|---|
| 775 | FitsImg2DWriter::FitsImg2DWriter(string fname,bool update,int bitpix,int lp)
|
|---|
| 776 | : FitsWriter(fname,update,lp)
|
|---|
| 777 | {
|
|---|
| 778 | BitPix = bitpix;
|
|---|
| 779 | HduType = IMAGE_HDU;
|
|---|
| 780 | FirstTime = true;
|
|---|
| 781 | Naxis[0] = Naxis[1] = 0;
|
|---|
| 782 | }
|
|---|
| 783 |
|
|---|
| 784 | /*!
|
|---|
| 785 | Constructor.
|
|---|
| 786 | \param cfname : FITS file name to be written (created or updated)
|
|---|
| 787 | \param update : file is created if FALSE, open for update if TRUE
|
|---|
| 788 | \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 789 | \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 790 | \param lp : debug level
|
|---|
| 791 | */
|
|---|
| 792 | FitsImg2DWriter::FitsImg2DWriter(const char* cfname,bool update,int bitpix,int lp)
|
|---|
| 793 | : FitsWriter(cfname,update,lp)
|
|---|
| 794 | {
|
|---|
| 795 | BitPix = bitpix;
|
|---|
| 796 | HduType = IMAGE_HDU;
|
|---|
| 797 | FirstTime = true;
|
|---|
| 798 | Naxis[0] = Naxis[1] = 0;
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | /*! Destructor */
|
|---|
| 802 | FitsImg2DWriter::~FitsImg2DWriter()
|
|---|
| 803 | {
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | /*! Create the image. Done at the first write request. */
|
|---|
| 807 | void FitsImg2DWriter::createimg(void)
|
|---|
| 808 | {
|
|---|
| 809 | if(!FirstTime)
|
|---|
| 810 | throw NotAvailableOperation("FitsImg2DWriter::createimg: already created image\n");
|
|---|
| 811 | if(Naxis[0]<=0 || Naxis[1]<=0)
|
|---|
| 812 | throw ParmError("FitsImg2DWriter::createimg: bad Naxis 1 or 2 value\n");
|
|---|
| 813 |
|
|---|
| 814 | int sta=0;
|
|---|
| 815 | if(fits_create_imgll(FitsPtr,BitPix,2,Naxis,&sta)) {
|
|---|
| 816 | printerror(sta);
|
|---|
| 817 | throw NullPtrError("FitsImg2DWriter::createimg: Error creating image extension\n");
|
|---|
| 818 | }
|
|---|
| 819 |
|
|---|
| 820 | FirstTime = false;
|
|---|
| 821 | }
|
|---|
| 822 |
|
|---|
| 823 | /*!
|
|---|
| 824 | Write an unsigned byte image to FITS file.
|
|---|
| 825 | \warning TMatrix data(Naxis2,Naxis1) means Data(row,column)
|
|---|
| 826 | */
|
|---|
| 827 | void FitsImg2DWriter::Write(TMatrix<uint_1>& data)
|
|---|
| 828 | {
|
|---|
| 829 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
|---|
| 830 | uint_1* arr = new uint_1[Naxis[0]];
|
|---|
| 831 |
|
|---|
| 832 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
|---|
| 833 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
|---|
| 834 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
|---|
| 835 | fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
|
|---|
| 836 | if(sta) {
|
|---|
| 837 | printerrorwrite("uint_1",0,l,sta); delete [] arr;
|
|---|
| 838 | throw
|
|---|
| 839 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_1>): Error Writing Fits file\n");
|
|---|
| 840 | }
|
|---|
| 841 | }
|
|---|
| 842 |
|
|---|
| 843 | delete [] arr;
|
|---|
| 844 | }
|
|---|
| 845 |
|
|---|
| 846 | /*!
|
|---|
| 847 | Write an unsigned short image to FITS file.
|
|---|
| 848 | \warning TMatrix data(Naxis2,Naxis1) means Data(row,column)
|
|---|
| 849 | */
|
|---|
| 850 | void FitsImg2DWriter::Write(TMatrix<uint_2>& data)
|
|---|
| 851 | {
|
|---|
| 852 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
|---|
| 853 | uint_2* arr = new uint_2[Naxis[0]];
|
|---|
| 854 |
|
|---|
| 855 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
|---|
| 856 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
|---|
| 857 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
|---|
| 858 | fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
|
|---|
| 859 | if(sta) {
|
|---|
| 860 | printerrorwrite("uint_2",0,l,sta); delete [] arr;
|
|---|
| 861 | throw
|
|---|
| 862 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_2>): Error Writing Fits file\n");
|
|---|
| 863 | }
|
|---|
| 864 | }
|
|---|
| 865 |
|
|---|
| 866 | delete [] arr;
|
|---|
| 867 | }
|
|---|
| 868 |
|
|---|
| 869 | /*! Write a long image to FITS file. */
|
|---|
| 870 | void FitsImg2DWriter::Write(TMatrix<int_4>& data)
|
|---|
| 871 | {
|
|---|
| 872 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
|---|
| 873 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
|---|
| 874 | int_4* arr = new int_4[Naxis[0]];
|
|---|
| 875 |
|
|---|
| 876 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
|---|
| 877 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
|---|
| 878 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
|---|
| 879 | fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
|
|---|
| 880 | if(sta) {
|
|---|
| 881 | printerrorwrite("int_4",0,l,sta); delete [] arr;
|
|---|
| 882 | throw
|
|---|
| 883 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<int_4>): Error Writing Fits file\n");
|
|---|
| 884 | }
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 887 | delete [] arr;
|
|---|
| 888 | }
|
|---|
| 889 |
|
|---|
| 890 | /*! Write a float image to FITS file. */
|
|---|
| 891 | void FitsImg2DWriter::Write(TMatrix<float>& data)
|
|---|
| 892 | {
|
|---|
| 893 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
|---|
| 894 | float* arr = new float[Naxis[0]];
|
|---|
| 895 |
|
|---|
| 896 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
|---|
| 897 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
|---|
| 898 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
|---|
| 899 | fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
|
|---|
| 900 | if(sta) {
|
|---|
| 901 | printerrorwrite("float",0,l,sta); delete [] arr;
|
|---|
| 902 | throw
|
|---|
| 903 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<float>): Error Writing Fits file\n");
|
|---|
| 904 | }
|
|---|
| 905 | }
|
|---|
| 906 |
|
|---|
| 907 | delete [] arr;
|
|---|
| 908 | }
|
|---|
| 909 |
|
|---|
| 910 | /*! Write a double image to FITS file. */
|
|---|
| 911 | void FitsImg2DWriter::Write(TMatrix<double>& data)
|
|---|
| 912 | {
|
|---|
| 913 | Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
|
|---|
| 914 | double* arr = new double[Naxis[0]];
|
|---|
| 915 |
|
|---|
| 916 | for(LONGLONG l=0;l<Naxis[1];l++) {
|
|---|
| 917 | for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
|
|---|
| 918 | LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
|
|---|
| 919 | fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
|
|---|
| 920 | if(sta) {
|
|---|
| 921 | printerrorwrite("double",0,l,sta); delete [] arr;
|
|---|
| 922 | throw
|
|---|
| 923 | NotAvailableOperation("FitsImg2DRd::Write(TMatrix<double>): Error Writing Fits file\n");
|
|---|
| 924 | }
|
|---|
| 925 | }
|
|---|
| 926 |
|
|---|
| 927 | delete [] arr;
|
|---|
| 928 | }
|
|---|
| 929 |
|
|---|
| 930 | /*! Print infos. */
|
|---|
| 931 | void FitsImg2DWriter::Print(ostream& os) const
|
|---|
| 932 | {
|
|---|
| 933 | os<<"FitsImg2DWriter::Print: FitsFN "<<FitsFN<<endl
|
|---|
| 934 | <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow<<" BitPix "<<BitPix
|
|---|
| 935 | <<" Naxis1 "<<Naxis[0]<<" Naxis2 "<<Naxis[1]<<endl;
|
|---|
| 936 | }
|
|---|
| 937 |
|
|---|
| 938 |
|
|---|
| 939 | //////////////////////////////////////////////////////////////////
|
|---|
| 940 | //////////////////////////////////////////////////////////////////
|
|---|
| 941 | //////////////////////////////////////////////////////////////////
|
|---|
| 942 | //////////////////////////////////////////////////////////////////
|
|---|
| 943 | /*!
|
|---|
| 944 | \class SOPHYA::FitsImg3DWriter
|
|---|
| 945 | \ingroup FitsIOServer
|
|---|
| 946 | Class for writing an 3D image into FITS file
|
|---|
| 947 | */
|
|---|
| 948 |
|
|---|
| 949 | /*!
|
|---|
| 950 | Constructor.
|
|---|
| 951 | \param fname : FITS file name to be written (a new fits file is created)
|
|---|
| 952 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 953 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 954 | \param lp : debug level
|
|---|
| 955 | */
|
|---|
| 956 | FitsImg3DWriter::FitsImg3DWriter(string fname,int bitpix,int lp)
|
|---|
| 957 | : FitsWriter(fname,lp)
|
|---|
| 958 | {
|
|---|
| 959 | BitPix = bitpix;
|
|---|
| 960 | HduType = IMAGE_HDU;
|
|---|
| 961 | FirstTime = true;
|
|---|
| 962 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
|---|
| 963 | }
|
|---|
| 964 |
|
|---|
| 965 | /*!
|
|---|
| 966 | Constructor.
|
|---|
| 967 | \param cfname : FITS file name to be written (a new fits file is created)
|
|---|
| 968 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 969 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 970 | \param lp : debug level
|
|---|
| 971 | */
|
|---|
| 972 | FitsImg3DWriter::FitsImg3DWriter(const char* cfname,int bitpix,int lp)
|
|---|
| 973 | : FitsWriter(cfname,lp)
|
|---|
| 974 | {
|
|---|
| 975 | BitPix = bitpix;
|
|---|
| 976 | HduType = IMAGE_HDU;
|
|---|
| 977 | FirstTime = true;
|
|---|
| 978 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
|---|
| 979 | }
|
|---|
| 980 |
|
|---|
| 981 | /*!
|
|---|
| 982 | Constructor.
|
|---|
| 983 | \param fname : FITS file name to be written (created or updated)
|
|---|
| 984 | \param update : file is created if FALSE, open for update if TRUE
|
|---|
| 985 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 986 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 987 | \param lp : debug level
|
|---|
| 988 | */
|
|---|
| 989 | FitsImg3DWriter::FitsImg3DWriter(string fname,bool update,int bitpix,int lp)
|
|---|
| 990 | : FitsWriter(fname,update,lp)
|
|---|
| 991 | {
|
|---|
| 992 | BitPix = bitpix;
|
|---|
| 993 | HduType = IMAGE_HDU;
|
|---|
| 994 | FirstTime = true;
|
|---|
| 995 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
|---|
| 996 | }
|
|---|
| 997 |
|
|---|
| 998 | /*!
|
|---|
| 999 | Constructor.
|
|---|
| 1000 | \param cfname : FITS file name to be written (created or updated)
|
|---|
| 1001 | \param update : file is created if FALSE, open for update if TRUE
|
|---|
| 1002 | \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
|
|---|
| 1003 | \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
|
|---|
| 1004 | \param lp : debug level
|
|---|
| 1005 | */
|
|---|
| 1006 | FitsImg3DWriter::FitsImg3DWriter(const char* cfname,bool update,int bitpix,int lp)
|
|---|
| 1007 | : FitsWriter(cfname,update,lp)
|
|---|
| 1008 | {
|
|---|
| 1009 | BitPix = bitpix;
|
|---|
| 1010 | HduType = IMAGE_HDU;
|
|---|
| 1011 | FirstTime = true;
|
|---|
| 1012 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
|---|
| 1013 | }
|
|---|
| 1014 |
|
|---|
| 1015 | /*! Destructor */
|
|---|
| 1016 | FitsImg3DWriter::~FitsImg3DWriter()
|
|---|
| 1017 | {
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 | /*! Create the 3D image. Done at the first write request. */
|
|---|
| 1021 | void FitsImg3DWriter::createimg(void)
|
|---|
| 1022 | {
|
|---|
| 1023 | if(!FirstTime)
|
|---|
| 1024 | throw NotAvailableOperation("FitsImg3DWriter::createimg: already created 3D image\n");
|
|---|
| 1025 | if(Naxis[0]<=0 || Naxis[1]<=0 || Naxis[2]<=0)
|
|---|
| 1026 | throw ParmError("FitsImg3DWriter::createimg: bad Naxis 1 or 2 or 3 value\n");
|
|---|
| 1027 |
|
|---|
| 1028 | int sta=0;
|
|---|
| 1029 | if(fits_create_imgll(FitsPtr,BitPix,3,Naxis,&sta)) {
|
|---|
| 1030 | printerror(sta);
|
|---|
| 1031 | throw NullPtrError("FitsImg3DWriter::createimg: Error creating 3D image extension\n");
|
|---|
| 1032 | }
|
|---|
| 1033 |
|
|---|
| 1034 | FirstTime = false;
|
|---|
| 1035 | }
|
|---|
| 1036 |
|
|---|
| 1037 | /*! Create the 3D imageby yourself, ONLY use it with Write(TVector<>& data) */
|
|---|
| 1038 | void FitsImg3DWriter::CreateImg(LONGLONG naxis1,LONGLONG naxis2,LONGLONG naxis3)
|
|---|
| 1039 | {
|
|---|
| 1040 | Naxis[0]=naxis1;
|
|---|
| 1041 | Naxis[1]=naxis2;
|
|---|
| 1042 | Naxis[2]=naxis3;
|
|---|
| 1043 | createimg();
|
|---|
| 1044 | }
|
|---|
| 1045 |
|
|---|
| 1046 | /*!
|
|---|
| 1047 | Write an unsigned byte 3D image to FITS file.
|
|---|
| 1048 | */
|
|---|
| 1049 | void FitsImg3DWriter::Write(TArray<uint_1>& data)
|
|---|
| 1050 | {
|
|---|
| 1051 | if(data.Rank()!=3)
|
|---|
| 1052 | throw ParmError("FitsImg3DRd::Write(TArray<uint_1>): not a 3D array\n");
|
|---|
| 1053 |
|
|---|
| 1054 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
|---|
| 1055 | uint_1* arr = new uint_1[Naxis[0]];
|
|---|
| 1056 |
|
|---|
| 1057 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
|---|
| 1058 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
|---|
| 1059 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1060 | fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
|
|---|
| 1061 | if(sta) {
|
|---|
| 1062 | printerrorwrite("uint_1",j,k,sta); delete [] arr;
|
|---|
| 1063 | throw
|
|---|
| 1064 | NotAvailableOperation("FitsImg3DRd::Write(TArray<uint_1>): Error Writing Fits file\n");
|
|---|
| 1065 | }
|
|---|
| 1066 | }
|
|---|
| 1067 |
|
|---|
| 1068 | delete [] arr;
|
|---|
| 1069 | }
|
|---|
| 1070 |
|
|---|
| 1071 | /*!
|
|---|
| 1072 | Write an unsigned short 3D image to FITS file.
|
|---|
| 1073 | */
|
|---|
| 1074 | void FitsImg3DWriter::Write(TArray<uint_2>& data)
|
|---|
| 1075 | {
|
|---|
| 1076 | if(data.Rank()!=3)
|
|---|
| 1077 | throw ParmError("FitsImg3DRd::Write(TArray<uint_2>): not a 3D array\n");
|
|---|
| 1078 |
|
|---|
| 1079 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
|---|
| 1080 | uint_2* arr = new uint_2[Naxis[0]];
|
|---|
| 1081 |
|
|---|
| 1082 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
|---|
| 1083 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
|---|
| 1084 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1085 | fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
|
|---|
| 1086 | if(sta) {
|
|---|
| 1087 | printerrorwrite("uint_2",j,k,sta); delete [] arr;
|
|---|
| 1088 | throw
|
|---|
| 1089 | NotAvailableOperation("FitsImg3DRd::Write(TArray<uint_2>): Error Writing Fits file\n");
|
|---|
| 1090 | }
|
|---|
| 1091 | }
|
|---|
| 1092 |
|
|---|
| 1093 | delete [] arr;
|
|---|
| 1094 | }
|
|---|
| 1095 |
|
|---|
| 1096 | /*! Write a long 3D image to FITS file. */
|
|---|
| 1097 | void FitsImg3DWriter::Write(TArray<int_4>& data)
|
|---|
| 1098 | {
|
|---|
| 1099 | if(data.Rank()!=3)
|
|---|
| 1100 | throw ParmError("FitsImg3DRd::Write(TArray<int_4>): not a 3D array\n");
|
|---|
| 1101 |
|
|---|
| 1102 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
|---|
| 1103 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
|---|
| 1104 | int_4* arr = new int_4[Naxis[0]];
|
|---|
| 1105 |
|
|---|
| 1106 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
|---|
| 1107 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
|---|
| 1108 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1109 | fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
|
|---|
| 1110 | if(sta) {
|
|---|
| 1111 | printerrorwrite("int_4",j,k,sta); delete [] arr;
|
|---|
| 1112 | throw
|
|---|
| 1113 | NotAvailableOperation("FitsImg3DRd::Write(TArray<int_4>): Error Writing Fits file\n");
|
|---|
| 1114 | }
|
|---|
| 1115 | }
|
|---|
| 1116 |
|
|---|
| 1117 | delete [] arr;
|
|---|
| 1118 | }
|
|---|
| 1119 |
|
|---|
| 1120 | /*! Write a float 3D image to FITS file. */
|
|---|
| 1121 | void FitsImg3DWriter::Write(TArray<float>& data)
|
|---|
| 1122 | {
|
|---|
| 1123 | if(data.Rank()!=3)
|
|---|
| 1124 | throw ParmError("FitsImg3DRd::Write(TArray<float>): not a 3D array\n");
|
|---|
| 1125 |
|
|---|
| 1126 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
|---|
| 1127 | float* arr = new float[Naxis[0]];
|
|---|
| 1128 |
|
|---|
| 1129 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
|---|
| 1130 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
|---|
| 1131 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1132 | fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
|
|---|
| 1133 | if(sta) {
|
|---|
| 1134 | printerrorwrite("float",j,k,sta); delete [] arr;
|
|---|
| 1135 | throw
|
|---|
| 1136 | NotAvailableOperation("FitsImg3DRd::Write(TArray<float>): Error Writing Fits file\n");
|
|---|
| 1137 | }
|
|---|
| 1138 | }
|
|---|
| 1139 |
|
|---|
| 1140 | delete [] arr;
|
|---|
| 1141 | }
|
|---|
| 1142 |
|
|---|
| 1143 | /*! Write a double 3D image to FITS file. */
|
|---|
| 1144 | void FitsImg3DWriter::Write(TArray<double>& data)
|
|---|
| 1145 | {
|
|---|
| 1146 | if(data.Rank()!=3)
|
|---|
| 1147 | throw ParmError("FitsImg3DRd::Write(TArray<double>): not a 3D array\n");
|
|---|
| 1148 |
|
|---|
| 1149 | Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
|
|---|
| 1150 | double* arr = new double[Naxis[0]];
|
|---|
| 1151 |
|
|---|
| 1152 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
|---|
| 1153 | for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
|
|---|
| 1154 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1155 | fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
|
|---|
| 1156 | if(sta) {
|
|---|
| 1157 | printerrorwrite("double",j,k,sta); delete [] arr;
|
|---|
| 1158 | throw
|
|---|
| 1159 | NotAvailableOperation("FitsImg3DRd::Write(TArray<double>): Error Writing Fits file\n");
|
|---|
| 1160 | }
|
|---|
| 1161 | }
|
|---|
| 1162 |
|
|---|
| 1163 | delete [] arr;
|
|---|
| 1164 | }
|
|---|
| 1165 |
|
|---|
| 1166 | /*!
|
|---|
| 1167 | Write an unsigned byte Vector<> image to 3D FITS file.
|
|---|
| 1168 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
|---|
| 1169 | so IMG(i,j,k) = Vector(i)
|
|---|
| 1170 | */
|
|---|
| 1171 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<uint_1>& data)
|
|---|
| 1172 | {
|
|---|
| 1173 | if(FirstTime)
|
|---|
| 1174 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): use CreateImg first !\n");
|
|---|
| 1175 | if(data.Size()!=Naxis[0])
|
|---|
| 1176 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): wrong vector size\n");
|
|---|
| 1177 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
|---|
| 1178 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): j or k out of range\n");
|
|---|
| 1179 | uint_1* arr = const_cast<uint_1 *>(data.Data());
|
|---|
| 1180 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1181 | fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
|
|---|
| 1182 | if(sta) {
|
|---|
| 1183 | printerrorwrite("uint_1",j,k,sta); delete [] arr;
|
|---|
| 1184 | throw
|
|---|
| 1185 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): Error Writing Fits file\n");
|
|---|
| 1186 | }
|
|---|
| 1187 | }
|
|---|
| 1188 |
|
|---|
| 1189 | /*!
|
|---|
| 1190 | Write an unsigned short Vector<> image to 3D FITS file.
|
|---|
| 1191 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
|---|
| 1192 | so IMG(i,j,k) = Vector(i)
|
|---|
| 1193 | */
|
|---|
| 1194 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<uint_2>& data)
|
|---|
| 1195 | {
|
|---|
| 1196 | if(FirstTime)
|
|---|
| 1197 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): use CreateImg first !\n");
|
|---|
| 1198 | if(data.Size()!=Naxis[0])
|
|---|
| 1199 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): wrong vector size\n");
|
|---|
| 1200 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
|---|
| 1201 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): j or k out of range\n");
|
|---|
| 1202 | uint_2* arr = const_cast<uint_2 *>(data.Data());
|
|---|
| 1203 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1204 | fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
|
|---|
| 1205 | if(sta) {
|
|---|
| 1206 | printerrorwrite("uint_2",j,k,sta); delete [] arr;
|
|---|
| 1207 | throw
|
|---|
| 1208 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): Error Writing Fits file\n");
|
|---|
| 1209 | }
|
|---|
| 1210 | }
|
|---|
| 1211 |
|
|---|
| 1212 | /*!
|
|---|
| 1213 | Write an long Vector<> image to 3D FITS file.
|
|---|
| 1214 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
|---|
| 1215 | so IMG(i,j,k) = Vector(i)
|
|---|
| 1216 | */
|
|---|
| 1217 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<int_4>& data)
|
|---|
| 1218 | {
|
|---|
| 1219 | if(FirstTime)
|
|---|
| 1220 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): use CreateImg first !\n");
|
|---|
| 1221 | if(data.Size()!=Naxis[0])
|
|---|
| 1222 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): wrong vector size\n");
|
|---|
| 1223 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
|---|
| 1224 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): j or k out of range\n");
|
|---|
| 1225 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
|---|
| 1226 | int_4* arr = const_cast<int_4 *>(data.Data());
|
|---|
| 1227 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1228 | fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
|
|---|
| 1229 | if(sta) {
|
|---|
| 1230 | printerrorwrite("int_4",j,k,sta); delete [] arr;
|
|---|
| 1231 | throw
|
|---|
| 1232 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): Error Writing Fits file\n");
|
|---|
| 1233 | }
|
|---|
| 1234 | }
|
|---|
| 1235 |
|
|---|
| 1236 | /*!
|
|---|
| 1237 | Write an float Vector<> image to 3D FITS file.
|
|---|
| 1238 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
|---|
| 1239 | so IMG(i,j,k) = Vector(i)
|
|---|
| 1240 | */
|
|---|
| 1241 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<float>& data)
|
|---|
| 1242 | {
|
|---|
| 1243 | if(FirstTime)
|
|---|
| 1244 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): use CreateImg first !\n");
|
|---|
| 1245 | if(data.Size()!=Naxis[0])
|
|---|
| 1246 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): wrong vector size\n");
|
|---|
| 1247 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
|---|
| 1248 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): j or k out of range\n");
|
|---|
| 1249 | float* arr = const_cast<float *>(data.Data());
|
|---|
| 1250 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1251 | fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
|
|---|
| 1252 | if(sta) {
|
|---|
| 1253 | printerrorwrite("float",j,k,sta); delete [] arr;
|
|---|
| 1254 | throw
|
|---|
| 1255 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): Error Writing Fits file\n");
|
|---|
| 1256 | }
|
|---|
| 1257 | }
|
|---|
| 1258 |
|
|---|
| 1259 | /*!
|
|---|
| 1260 | Write an double Vector<> image to 3D FITS file.
|
|---|
| 1261 | Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
|
|---|
| 1262 | so IMG(i,j,k) = Vector(i)
|
|---|
| 1263 | */
|
|---|
| 1264 | void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<double>& data)
|
|---|
| 1265 | {
|
|---|
| 1266 | if(FirstTime)
|
|---|
| 1267 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): use CreateImg first !\n");
|
|---|
| 1268 | if(data.Size()!=Naxis[0])
|
|---|
| 1269 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): wrong vector size\n");
|
|---|
| 1270 | if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
|
|---|
| 1271 | throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): j or k out of range\n");
|
|---|
| 1272 | double* arr = const_cast<double *>(data.Data());
|
|---|
| 1273 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
|
|---|
| 1274 | fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
|
|---|
| 1275 | if(sta) {
|
|---|
| 1276 | printerrorwrite("double",j,k,sta); delete [] arr;
|
|---|
| 1277 | throw
|
|---|
| 1278 | NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): Error Writing Fits file\n");
|
|---|
| 1279 | }
|
|---|
| 1280 | }
|
|---|
| 1281 |
|
|---|
| 1282 | /*! Print infos. */
|
|---|
| 1283 | void FitsImg3DWriter::Print(ostream& os) const
|
|---|
| 1284 | {
|
|---|
| 1285 | os<<"FitsImg3DWriter::Print: FitsFN "<<FitsFN<<endl
|
|---|
| 1286 | <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow<<" BitPix "<<BitPix
|
|---|
| 1287 | <<" Naxis1 "<<Naxis[0]<<" Naxis2 "<<Naxis[1]<<" Naxis3 "<<Naxis[2]<<endl;
|
|---|
| 1288 | }
|
|---|