| [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"
 | 
|---|
 | 400 |           if BINARY_TBL and tform="" or tform=NULL)
 | 
|---|
| [1659] | 401 |   \param tunit : fits tunit definition (optional)
 | 
|---|
| [2169] | 402 |   \param datatype : TBYTE TSHORT TLONG (TINT32BIT) TLONGLONG TFLOAT TDOUBLE
 | 
|---|
| [2493] | 403 |                     TUSHORT TULONG TSBYTE. That parameter is only use in case
 | 
|---|
| [1660] | 404 |                     of a BINARY_TBL table when tform is not defined).
 | 
|---|
| [1659] | 405 |   \return The number of the new added column in the table.
 | 
|---|
 | 406 |   \warning col = [0,ncol-1]
 | 
|---|
| [1654] | 407 | */
 | 
|---|
| [1660] | 408 | int FitsABTWriter::addcol(const char* label,const char* tform
 | 
|---|
 | 409 |                          ,const char* tunit,int datatype)
 | 
|---|
| [1654] | 410 | {
 | 
|---|
| [2453] | 411 |  if(!FirstTime)
 | 
|---|
 | 412 |    throw AllocationError("FitsABTWriter::addcol: table already created\n");
 | 
|---|
| [1654] | 413 |  
 | 
|---|
| [1660] | 414 |  // Gestion auto du tform pour les tables binaires avec le datatype (si non-definie)
 | 
|---|
 | 415 |  bool tformauto = false;
 | 
|---|
| [2174] | 416 |  if(HduType==BINARY_TBL || HduType==ASCII_TBL) {
 | 
|---|
| [1669] | 417 |    if(tform==NULL)           tformauto = true;
 | 
|---|
 | 418 |    else if(strlen(tform)<=0) tformauto = true;
 | 
|---|
| [1660] | 419 |  }
 | 
|---|
| [2174] | 420 |  if(tformauto && HduType==BINARY_TBL) {
 | 
|---|
| [1660] | 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");
 | 
|---|
| [2169] | 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
 | 
|---|
| [1657] | 431 |    else if(datatype==TFLOAT)    strcpy(str,"1E");
 | 
|---|
 | 432 |    else if(datatype==TDOUBLE)   strcpy(str,"1D");
 | 
|---|
| [1660] | 433 |    else if(datatype==TUSHORT)   strcpy(str,"1U");
 | 
|---|
 | 434 |    else if(datatype==TULONG)    strcpy(str,"1V");
 | 
|---|
| [2493] | 435 | #ifdef TSBYTE
 | 
|---|
 | 436 |    else if(datatype==TSBYTE)    strcpy(str,"1S");
 | 
|---|
 | 437 | #endif
 | 
|---|
| [1660] | 438 |    else
 | 
|---|
 | 439 |      throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
 | 
|---|
| [1654] | 440 |    TForm.push_back(str);
 | 
|---|
| [2174] | 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");
 | 
|---|
| [2493] | 456 | #ifdef TSBYTE
 | 
|---|
 | 457 |    else if(datatype==TSBYTE)    strcpy(str,"I5");
 | 
|---|
 | 458 | #endif
 | 
|---|
| [2174] | 459 |    else
 | 
|---|
 | 460 |      throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
 | 
|---|
 | 461 |    TForm.push_back(str);
 | 
|---|
| [1660] | 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("");
 | 
|---|
| [1654] | 468 | 
 | 
|---|
 | 469 |  int n = (int) Label.size() -1;
 | 
|---|
 | 470 | 
 | 
|---|
 | 471 |  if(DbgLevel)
 | 
|---|
 | 472 |    cout<<"FitsABTWriter::addcol["<<n<<"] Label="<<Label[n]
 | 
|---|
 | 473 |        <<" TForm="<<TForm[n]
 | 
|---|
| [1660] | 474 |        <<" TUnit="<<TUnit[n]
 | 
|---|
 | 475 |        <<" datatype="<<datatype<<endl;
 | 
|---|
| [1654] | 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 | 
 | 
|---|
| [3128] | 489 |  LONGLONG nrows = 0;
 | 
|---|
| [1654] | 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 |  }
 | 
|---|
| [3128] | 499 |  for(int i=0;i<tfields;i++) {
 | 
|---|
| [1654] | 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;
 | 
|---|
| [3128] | 517 |  for(int i=0;i<tfields;i++) {
 | 
|---|
| [1654] | 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 | /*!
 | 
|---|
| [2173] | 531 |   Write a data to FITS file.
 | 
|---|
| [1659] | 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"
 | 
|---|
| [1654] | 536 |            which could have been defined with an other type.
 | 
|---|
 | 537 |            Cast is performed by the cfitsio package.
 | 
|---|
| [1659] | 538 |   \verbatim
 | 
|---|
| [1654] | 539 |   WARNING: suppose that the column has be defined to be TSHORT
 | 
|---|
| [1660] | 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
 | 
|---|
| [1654] | 543 |        the cast is performed by the C++ language.
 | 
|---|
 | 544 |    - If you write dummy.Write(col,row,val) where val is double
 | 
|---|
| [1660] | 545 |        the Write(int,long,double) routine is called and
 | 
|---|
| [1654] | 546 |        the cast is performed by the cfistio package.
 | 
|---|
 | 547 |   \endverbatim
 | 
|---|
 | 548 | */
 | 
|---|
| [2173] | 549 | 
 | 
|---|
| [2493] | 550 | /*! Write signed char (1 Byte) data to FITS file (see below) */
 | 
|---|
| [3128] | 551 | void FitsABTWriter::Write(int col,LONGLONG row,int_1 val)
 | 
|---|
| [2493] | 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
 | 
|---|
| [2789] | 559 |   throw PException("FitsABTWriter::Write(..,int_1) Not in that cfitsio version");
 | 
|---|
| [2493] | 560 | #endif
 | 
|---|
 | 561 | }
 | 
|---|
 | 562 | 
 | 
|---|
| [2174] | 563 | /*! Write unsigned char (1 Byte) data to FITS file (see below) */
 | 
|---|
| [3128] | 564 | void FitsABTWriter::Write(int col,LONGLONG row,uint_1 val)
 | 
|---|
| [2173] | 565 | {
 | 
|---|
 | 566 |   if(FirstTime) createtbl();
 | 
|---|
 | 567 |   int sta=0;
 | 
|---|
 | 568 |   if(fits_write_col(FitsPtr,TBYTE,col+1,row+1,1,1,&val,&sta))
 | 
|---|
| [2174] | 569 |     printerrorwrite("unsigned char",col,row,sta);
 | 
|---|
| [2173] | 570 | }
 | 
|---|
 | 571 | 
 | 
|---|
 | 572 | /*! Write short (2 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 573 | void FitsABTWriter::Write(int col,LONGLONG row,int_2 val)
 | 
|---|
| [1654] | 574 | {
 | 
|---|
 | 575 |   if(FirstTime) createtbl();
 | 
|---|
 | 576 |   int sta=0;
 | 
|---|
| [1657] | 577 |   if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,&val,&sta))
 | 
|---|
| [1654] | 578 |     printerrorwrite("short",col,row,sta);
 | 
|---|
 | 579 | }
 | 
|---|
 | 580 | 
 | 
|---|
| [2170] | 581 | /*! Write unsigned short (2 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 582 | void FitsABTWriter::Write(int col,LONGLONG row,uint_2 val)
 | 
|---|
| [2170] | 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 | 
 | 
|---|
| [2169] | 590 | /*! Write long (4 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 591 | void FitsABTWriter::Write(int col,LONGLONG row,int_4 val)
 | 
|---|
| [1654] | 592 | {
 | 
|---|
 | 593 |   if(FirstTime) createtbl();
 | 
|---|
 | 594 |   int sta=0;
 | 
|---|
| [1657] | 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))
 | 
|---|
| [1654] | 598 |     printerrorwrite("long",col,row,sta);
 | 
|---|
 | 599 | }
 | 
|---|
 | 600 | 
 | 
|---|
| [2173] | 601 | /*! Write unsigned long (4 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 602 | void FitsABTWriter::Write(int col,LONGLONG row,uint_4 val)
 | 
|---|
| [2173] | 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 | 
 | 
|---|
| [2169] | 612 | /*! Write long long (8 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 613 | void FitsABTWriter::Write(int col,LONGLONG row,int_8 val)
 | 
|---|
| [2169] | 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 | 
 | 
|---|
| [1654] | 625 | /*! Write float data to FITS file (see below) */
 | 
|---|
| [3128] | 626 | void FitsABTWriter::Write(int col,LONGLONG row,float val)
 | 
|---|
| [1654] | 627 | {
 | 
|---|
 | 628 |   if(FirstTime) createtbl();
 | 
|---|
 | 629 |   int sta=0;
 | 
|---|
| [1657] | 630 |   if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,&val,&sta))
 | 
|---|
| [1654] | 631 |     printerrorwrite("float",col,row,sta);
 | 
|---|
 | 632 | }
 | 
|---|
 | 633 | 
 | 
|---|
 | 634 | /*! Write double data to FITS file (see below) */
 | 
|---|
| [3128] | 635 | void FitsABTWriter::Write(int col,LONGLONG row,double val)
 | 
|---|
| [1654] | 636 | {
 | 
|---|
 | 637 |   if(FirstTime) createtbl();
 | 
|---|
 | 638 |   int sta=0;
 | 
|---|
| [1657] | 639 |   if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,&val,&sta))
 | 
|---|
| [1654] | 640 |     printerrorwrite("double",col,row,sta);
 | 
|---|
 | 641 | }
 | 
|---|
 | 642 | 
 | 
|---|
| [1657] | 643 | //////////////////////////////////////////////////////////////
 | 
|---|
 | 644 | /*!
 | 
|---|
| [2173] | 645 |   Write a vector of data to FITS file.
 | 
|---|
| [1659] | 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.
 | 
|---|
| [1657] | 651 | */
 | 
|---|
| [2173] | 652 | 
 | 
|---|
| [2170] | 653 | /*! Write a vector of unsigned short (2 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 654 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<uint_2>& val)
 | 
|---|
| [2170] | 655 | {
 | 
|---|
 | 656 |   if(FirstTime) createtbl();
 | 
|---|
| [3128] | 657 |   LONGLONG nel = val.Size();
 | 
|---|
| [2170] | 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 | 
 | 
|---|
| [2169] | 664 | /*! Write a vector of long (4 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 665 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_4>& val)
 | 
|---|
| [1657] | 666 | {
 | 
|---|
 | 667 |   if(FirstTime) createtbl();
 | 
|---|
| [3128] | 668 |   LONGLONG nel = val.Size();
 | 
|---|
| [1657] | 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 | 
 | 
|---|
| [2169] | 677 | /*! Write a vector of long long (8 Bytes) data to FITS file (see below) */
 | 
|---|
| [3128] | 678 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_8>& val)
 | 
|---|
| [2169] | 679 | {
 | 
|---|
 | 680 | #ifdef TLONGLONG
 | 
|---|
 | 681 |   if(FirstTime) createtbl();
 | 
|---|
| [3128] | 682 |   LONGLONG nel = val.Size();
 | 
|---|
| [2169] | 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
 | 
|---|
| [2170] | 688 |   throw PException("FitsABTWriter::Write(..,TVector<int_8>&) Not in that cfitsio version");
 | 
|---|
| [2169] | 689 | #endif
 | 
|---|
 | 690 | }
 | 
|---|
 | 691 | 
 | 
|---|
| [1657] | 692 | /*! Write a vector of float data to FITS file (see below) */
 | 
|---|
| [3128] | 693 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<float>&  val)
 | 
|---|
| [1657] | 694 | {
 | 
|---|
 | 695 |   if(FirstTime) createtbl();
 | 
|---|
| [3128] | 696 |   LONGLONG nel = val.Size();
 | 
|---|
| [1657] | 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) */
 | 
|---|
| [3128] | 704 | LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<double>& val)
 | 
|---|
| [1657] | 705 | {
 | 
|---|
 | 706 |   if(FirstTime) createtbl();
 | 
|---|
| [3128] | 707 |   LONGLONG nel = val.Size();
 | 
|---|
| [1657] | 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 | 
 | 
|---|
| [1654] | 714 | /////////////////////////////////////////////////
 | 
|---|
| [1677] | 715 | void FitsABTWriter::Print(ostream& os,int lp) const
 | 
|---|
| [1673] | 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 | }
 | 
|---|
| [2453] | 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)
 | 
|---|
| [3668] | 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)
 | 
|---|
| [2453] | 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)
 | 
|---|
| [3668] | 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)
 | 
|---|
| [2453] | 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
 | 
|---|
| [3668] | 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)
 | 
|---|
| [2453] | 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
 | 
|---|
| [3668] | 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)
 | 
|---|
| [2453] | 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;
 | 
|---|
| [3128] | 815 |  if(fits_create_imgll(FitsPtr,BitPix,2,Naxis,&sta)) {
 | 
|---|
| [2453] | 816 |    printerror(sta);
 | 
|---|
 | 817 |    throw NullPtrError("FitsImg2DWriter::createimg: Error creating image extension\n");
 | 
|---|
 | 818 |  }
 | 
|---|
 | 819 | 
 | 
|---|
 | 820 |  FirstTime = false;
 | 
|---|
 | 821 | }
 | 
|---|
 | 822 | 
 | 
|---|
 | 823 | /*!
 | 
|---|
| [3668] | 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 | /*!
 | 
|---|
| [2455] | 847 |   Write an unsigned short image to FITS file.
 | 
|---|
 | 848 |   \warning TMatrix data(Naxis2,Naxis1) means Data(row,column)
 | 
|---|
| [2453] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [2453] | 858 |    fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
 | 
|---|
 | 859 |    if(sta) {
 | 
|---|
| [2455] | 860 |      printerrorwrite("uint_2",0,l,sta); delete [] arr;
 | 
|---|
| [2453] | 861 |      throw
 | 
|---|
 | 862 |        NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_2>): Error Writing Fits file\n");
 | 
|---|
 | 863 |    }
 | 
|---|
 | 864 |  }
 | 
|---|
 | 865 | 
 | 
|---|
 | 866 |  delete [] arr;
 | 
|---|
 | 867 | }
 | 
|---|
 | 868 | 
 | 
|---|
| [2455] | 869 | /*! Write a long image to FITS file. */
 | 
|---|
| [2453] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [2453] | 879 |    fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
 | 
|---|
 | 880 |    if(sta) {
 | 
|---|
| [2455] | 881 |      printerrorwrite("int_4",0,l,sta); delete [] arr;
 | 
|---|
| [2453] | 882 |      throw
 | 
|---|
 | 883 |        NotAvailableOperation("FitsImg2DRd::Write(TMatrix<int_4>): Error Writing Fits file\n");
 | 
|---|
 | 884 |    }
 | 
|---|
 | 885 |  }
 | 
|---|
 | 886 | 
 | 
|---|
 | 887 |  delete [] arr;
 | 
|---|
 | 888 | }
 | 
|---|
 | 889 | 
 | 
|---|
| [2455] | 890 | /*! Write a float image to FITS file. */
 | 
|---|
| [2453] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [2453] | 899 |    fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
 | 
|---|
 | 900 |    if(sta) {
 | 
|---|
| [2455] | 901 |      printerrorwrite("float",0,l,sta); delete [] arr;
 | 
|---|
| [2453] | 902 |      throw
 | 
|---|
 | 903 |        NotAvailableOperation("FitsImg2DRd::Write(TMatrix<float>): Error Writing Fits file\n");
 | 
|---|
 | 904 |    }
 | 
|---|
 | 905 |  }
 | 
|---|
 | 906 | 
 | 
|---|
 | 907 |  delete [] arr;
 | 
|---|
 | 908 | }
 | 
|---|
 | 909 | 
 | 
|---|
| [2455] | 910 | /*! Write a double image to FITS file. */
 | 
|---|
| [2453] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [2453] | 919 |    fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
 | 
|---|
 | 920 |    if(sta) {
 | 
|---|
| [2455] | 921 |      printerrorwrite("double",0,l,sta); delete [] arr;
 | 
|---|
| [2453] | 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 | }
 | 
|---|
| [3114] | 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)
 | 
|---|
| [3668] | 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)
 | 
|---|
| [3114] | 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)
 | 
|---|
| [3668] | 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)
 | 
|---|
| [3114] | 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
 | 
|---|
| [3668] | 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)
 | 
|---|
| [3114] | 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
 | 
|---|
| [3668] | 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)
 | 
|---|
| [3114] | 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;
 | 
|---|
| [3128] | 1029 |  if(fits_create_imgll(FitsPtr,BitPix,3,Naxis,&sta)) {
 | 
|---|
| [3114] | 1030 |    printerror(sta);
 | 
|---|
 | 1031 |    throw NullPtrError("FitsImg3DWriter::createimg: Error creating 3D image extension\n");
 | 
|---|
 | 1032 |  }
 | 
|---|
 | 1033 | 
 | 
|---|
 | 1034 |  FirstTime = false;
 | 
|---|
 | 1035 | }
 | 
|---|
 | 1036 | 
 | 
|---|
| [3668] | 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 | 
 | 
|---|
| [3114] | 1046 | /*!
 | 
|---|
| [3668] | 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 | /*!
 | 
|---|
| [3114] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [3114] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [3114] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [3114] | 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 | 
 | 
|---|
| [3128] | 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;
 | 
|---|
| [3114] | 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 | 
 | 
|---|
| [3668] | 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 | 
 | 
|---|
| [3114] | 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 | }
 | 
|---|