source: Sophya/trunk/SophyaExt/FitsIOServer/fabtwriter.cc@ 2450

Last change on this file since 2450 was 2450, checked in by cmv, 22 years ago

possibilite d extension fits ds le writer cmv 29/10/2003

File size: 19.9 KB
Line 
1/* Writer de table Fits (binaire ou ASCII) */
2#include "machdefs.h"
3#include <stdlib.h>
4#include <stdio.h>
5#include "pexceptions.h"
6#include "fabtwriter.h"
7
8/*!
9 \class SOPHYA::FitsABTWriter
10 \ingroup FitsIOServer
11 Class for writing a FITS ASCII or BINARY table
12 \verbatim
13 //-----------------------------------------------------------
14 OPENING A NEW FILE AND WRITING INTO
15 -- Exemple 1: Writing element by element
16 FitsABTWriter fbtw(fitswrit,BINARY_TBL);
17 fbtw.SetExtName("MY_OWN_EXTENSION");
18 int c1 = fbtw.AddCol("vars",NULL,"km",TSHORT); // col=0
19 int c2 = fbtw.AddCol("vars2",NULL,"km",TSHORT); // col=1
20 int c3 = fbtw.AddCol("varl",NULL,"Degre",TLONG); // col=2
21 int c4 = fbtw.AddCol("varf",NULL,"",TFLOAT); // col=3
22 int c5 = fbtw.AddCol("vard","","arcmin",TDOUBLE); // col=4
23 fbtw.SetDebug(3);
24 for(long i=0;i<1000;i++) {
25 double x = i;
26 fbtw.Write(c1,i,1000.*x); // if overflow, managed by cfitsio
27 // Write(int,long,double) is called
28 fbtw.Write(c2,i,(short)(1000.*x));
29 // if overflow, managed by language
30 // Write(int,long,short) is called
31 fbtw.Write(c3,i,x);
32 fbtw.Write(c4,i,x);
33 fbtw.Write(c5,i,x);
34 }
35 cout<<"Number of Overflows when writing: "
36 <<fbtw.GetNOverFlow()<<endl;
37
38 //-----------------------------------------------------------
39 -- Exemple 2: Writing into TVector
40 ...
41 TVector<double> datad(100);
42 TVector<float> dataf(100);
43 TVector<int_4> datal(100);
44 for(long i=0;i<9990;i+=100) {
45 long i2=i+100-1; if(i2>=9990) i2=9990-1;
46 for(long j=0;j<100;j++) datad(i) = ...;
47 for(long j=0;j<100;j++) dataf(i) = ...;
48 for(long j=0;j<100;j++) datal(i) = ...;
49 fbtw.Write(1,i,datal);
50 fbtw.Write(2,i,dataf);
51 fbtw.Write(3,i,datad);
52 }
53 \endverbatim
54 \verbatim
55 //-----------------------------------------------------------
56 //-----------------------------------------------------------
57 //-----------------------------------------------------------
58 OPENING A NEW FILE AND WRITING 2 TABLE EXTENSIONS SIMULTANEOUSLY INTO
59 try {
60
61 cout<<">>>>> Creating a new fits file with FitsABTWriter"<<endl;
62 FitsABTWriter fbtw("!cmvtstfits3.fits",BINARY_TBL,3);
63 //FitsABTWriter fbtw("!cmvtstfits3.fits",false,BINARY_TBL,3);
64 fbtw.SetExtName("Test fits table 1");
65 cout<<"Writing Keys"<<endl;
66 fbtw.WriteKey("MYKEYL",(long)123456789,"my LONG key");
67 fbtw.WriteKey("MYKEYD",1.9999999,"my DOUBLE key");
68 fbtw.WriteKey("MYKEYC","how are you ?","my CHAR* key");
69 dum="do you feel better ?";
70 fbtw.WriteKey("MYKEYS",dum,"my STRING key");
71 i1 = fbtw.AddCol("x1",NULL,"unit1",TDOUBLE);
72 i2 = fbtw.AddCol("x2",NULL,"unit2",TDOUBLE);
73 i3 = fbtw.AddCol("x3",NULL,"unit3",TDOUBLE);
74 fbtw.Print();
75
76 cout<<">>>>> Another extension fits table with FitsABTWriter"<<endl;
77 FitsABTWriter fbtw2("cmvtstfits3.fits",true,BINARY_TBL,3);
78 fbtw2.SetExtName("Test fits table 2");
79 cout<<"Writing Keys"<<endl;
80 fbtw2.WriteKey("MYKEYL",(long)-123456789,"my new LONG key");
81 fbtw2.WriteKey("MYKEYD",-1.9999999,"my new clef DOUBLE key");
82 fbtw2.WriteKey("MYKEYC","how are you NOW ?","my new CHAR* key");
83 dum="do you feel better NOW ?";
84 fbtw2.WriteKey("MYKEYS",dum,"my new STRING key");
85 i11 = fbtw2.AddCol("x11",NULL,"unit11",TDOUBLE);
86 i12 = fbtw2.AddCol("x12",NULL,"unit12",TDOUBLE);
87 i13 = fbtw2.AddCol("x13",NULL,"unit13",TDOUBLE);
88 fbtw2.Print();
89
90 cout<<">>>>> Write into the 2 tables simultaneously"<<endl;
91 for(int i=0;i<NNN;i++) {
92 fbtw.Write(i1,i,i+1.);
93 fbtw.Write(i2,i,i+11.);
94 fbtw.Write(i3,i,i+101.);
95 fbtw2.Write(i11,i,-(i+1.));
96 fbtw2.Write(i12,i,-(i+11.));
97 fbtw2.Write(i13,i,-(i+101.));
98 }
99
100 } catch (PThrowable & exc) {
101 cout<<"Exception : "<<(string)typeid(exc).name()
102 <<" - Msg= "<<exc.Msg()<<endl;
103 return -2;
104 } catch (...) {
105 cout<<" some other exception was caught !"<<endl;
106 return -2;
107 }
108 \endverbatim
109*/
110
111//////////////////////////////////////////////////////////////
112/*!
113 Constructor.
114 \param fname : FITS file name to be written (a new fits file is created)
115 \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
116 \param lp : debug level
117*/
118FitsABTWriter::FitsABTWriter(string fname,int hdutype,int lp)
119{
120 cr_or_upd_fits(fname.c_str(),false,hdutype,lp);
121}
122
123/*!
124 Constructor.
125 \param cfname : FITS file name to be written (a new fits file is created)
126 \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
127 \param lp : debug level
128*/
129FitsABTWriter::FitsABTWriter(const char* cfname,int hdutype,int lp)
130{
131 cr_or_upd_fits(cfname,false,hdutype,lp);
132}
133
134/*!
135 Constructor.
136 \param fname : FITS file name to be written (created or updated)
137 \param update : file is created if FALSE, open for update if TRUE
138 \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
139 \param lp : debug level
140*/
141FitsABTWriter::FitsABTWriter(string fname,bool update,int hdutype,int lp)
142{
143 cr_or_upd_fits(fname.c_str(),update,hdutype,lp);
144}
145
146/*!
147 Constructor.
148 \param cfname : FITS file name to be written (created or updated)
149 \param update : file is created if FALSE, open for update if TRUE
150 \param hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
151 \param lp : debug level
152*/
153FitsABTWriter::FitsABTWriter(const char* cfname,bool update,int hdutype,int lp)
154{
155 cr_or_upd_fits(cfname,update,hdutype,lp);
156}
157
158/*! See FitsABTWriter() */
159void FitsABTWriter::cr_or_upd_fits(const char *cfname,bool update,int hdutype,int lp)
160{
161 FirstTime = true;
162 FitsPtr = NULL;
163 HduType = hdutype;
164 SetDebug(lp);
165 FitsFN = cfname;
166 NOverFlow = 0;
167 Update = update;
168
169 if(DbgLevel)
170 cout<<"FitsABTWriter::cr_or_upd_fits FitsFN="<<FitsFN
171 <<" HduType="<<HduType<<endl;
172
173 if(FitsFN.size() <= 0 )
174 throw ParmError("FitsABTWriter::cr_or_upd_fits: Fits file name error\n");
175
176 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
177 throw TypeMismatchExc("FitsABTWriter::cr_or_upd_fits: Only BINARY or ASCII table permitted\n");
178
179 // create or update FITS file
180 int sta=0;
181 if(Update) {
182 if(fits_open_file(&FitsPtr,FitsFN.c_str(),READWRITE,&sta)) {
183 printerror(sta);
184 throw NullPtrError("FitsABTWriter::cr_or_upd_fits: Error opening Fits file for update\n");
185 }
186 if(DbgLevel) cout<<"FitsABTWriter::cr_or_upd_fits: fits file has been opened for update"<<endl;
187 } else {
188 if(fits_create_file(&FitsPtr,FitsFN.c_str(),&sta)) {
189 printerror(sta);
190 throw NullPtrError("FitsABTWriter::cr_or_upd_fits: Error creating new Fits file\n");
191 }
192 if(DbgLevel) cout<<"FitsABTWriter::cr_or_upd_fits: a new fits file has been created"<<endl;
193 }
194
195 // create d'un Primary HDU
196 //long naxes[1] = {0};
197 //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
198 // printerror(sta);
199 // throw NullPtrError("FitsABTWriter::cr_or_upd_fits: Error creating Primary extension\n");
200 //}
201
202}
203
204/*! Destructor */
205FitsABTWriter::~FitsABTWriter()
206{
207 int sta = 0;
208 writekeys();
209 if(fits_close_file(FitsPtr,&sta)) printerror(sta);
210 FitsPtr = NULL;
211}
212
213/*! Flush the FitsIO buffer to set good Fits file in case of problems */
214void FitsABTWriter::Flush(void)
215{
216 if(FitsPtr==NULL) return;
217 int sta = 0;
218 if(fits_flush_file(FitsPtr,&sta)) printerror(sta);
219}
220
221/*! Write a double value into Fits Header */
222void FitsABTWriter::WriteKey(const char *keyname,double val,char* comment)
223{
224 if(keyname==NULL || strlen(keyname)<=0) return;
225 KeyDouble k;
226 k.keyname=keyname;
227 k.val=val;
228 if(comment) k.comment=comment; else k.comment="";
229 DoubleKey.push_back(k);
230}
231
232/*! Write a long value into Fits Header */
233void FitsABTWriter::WriteKey(const char *keyname,long val,char* comment)
234{
235 if(keyname==NULL || strlen(keyname)<=0) return;
236 KeyLong k;
237 k.keyname=keyname;
238 k.val=val;
239 if(comment) k.comment=comment; else k.comment="";
240 LongKey.push_back(k);
241}
242
243/*! Write a string value into Fits Header */
244void FitsABTWriter::WriteKey(const char *keyname,string val,char* comment)
245{
246 if(keyname==NULL || strlen(keyname)<=0) return;
247 KeyString k;
248 k.keyname=keyname;
249 k.val=val;
250 if(comment) k.comment=comment; else k.comment="";
251 StringKey.push_back(k);
252}
253
254void FitsABTWriter::writekeys(void)
255// Ecriture effective des clefs
256{
257 if(FitsPtr==NULL) return;
258 int sta=0;
259 if(DoubleKey.size()>0)
260 for(unsigned int i=0;i<DoubleKey.size();i++) {
261 char* key = const_cast<char*>(DoubleKey[i].keyname.c_str());
262 char* com = const_cast<char*>(DoubleKey[i].comment.c_str());
263 double val = DoubleKey[i].val;
264 if(fits_update_key(FitsPtr,TDOUBLE,key,&val,com,&sta))
265 printerror(sta);
266 }
267 if(LongKey.size()>0)
268 for(unsigned int i=0;i<LongKey.size();i++) {
269 char* key = const_cast<char*>(LongKey[i].keyname.c_str());
270 char* com = const_cast<char*>(LongKey[i].comment.c_str());
271 long val = LongKey[i].val;
272 if(fits_update_key(FitsPtr,TLONG,key,&val,com,&sta))
273 printerror(sta);
274 }
275 if(StringKey.size()>0)
276 for(unsigned int i=0;i<StringKey.size();i++) {
277 char* key = const_cast<char*>(StringKey[i].keyname.c_str());
278 char* com = const_cast<char*>(StringKey[i].comment.c_str());
279 char* val = const_cast<char*>(StringKey[i].val.c_str());
280 if(fits_update_key(FitsPtr,TSTRING,key,val,com,&sta))
281 printerror(sta);
282 }
283 DoubleKey.resize(0);
284 LongKey.resize(0);
285 StringKey.resize(0);
286}
287
288//////////////////////////////////////////////////////////////
289/*!
290 Add a new column to the FITS table
291 \param label : column label
292 \param tform : fits tform definition ("1I","1J","1E","1J",...)
293 (can be automatically set as "datatype"
294 if BINARY_TBL and tform="" or tform=NULL)
295 \param tunit : fits tunit definition (optional)
296 \param datatype : TBYTE TSHORT TLONG (TINT32BIT) TLONGLONG TFLOAT TDOUBLE
297 TUSHORT TULONG. That parameter is only use in case
298 of a BINARY_TBL table when tform is not defined).
299 \return The number of the new added column in the table.
300 \warning col = [0,ncol-1]
301*/
302int FitsABTWriter::addcol(const char* label,const char* tform
303 ,const char* tunit,int datatype)
304{
305 if(!FirstTime)
306 throw AllocationError("FitsABTWriter::addcol: table already created\n");
307
308 // Gestion auto du tform pour les tables binaires avec le datatype (si non-definie)
309 bool tformauto = false;
310 if(HduType==BINARY_TBL || HduType==ASCII_TBL) {
311 if(tform==NULL) tformauto = true;
312 else if(strlen(tform)<=0) tformauto = true;
313 }
314 if(tformauto && HduType==BINARY_TBL) {
315 char str[8];
316 if(datatype==TBYTE) strcpy(str,"1B");
317 else if(datatype==TSHORT) strcpy(str,"1I");
318 else if(datatype==TLONG) strcpy(str,"1J");
319#ifdef TINT32BIT
320 else if(datatype==TINT32BIT) strcpy(str,"1J");
321#endif
322#ifdef TLONGLONG
323 else if(datatype==TLONGLONG) strcpy(str,"1K");
324#endif
325 else if(datatype==TFLOAT) strcpy(str,"1E");
326 else if(datatype==TDOUBLE) strcpy(str,"1D");
327 else if(datatype==TUSHORT) strcpy(str,"1U");
328 else if(datatype==TULONG) strcpy(str,"1V");
329 else
330 throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
331 TForm.push_back(str);
332 } else if(tformauto && HduType==ASCII_TBL) {
333 char str[8];
334 if(datatype==TBYTE) strcpy(str,"I5");
335 else if(datatype==TSHORT) strcpy(str,"I7");
336 else if(datatype==TLONG) strcpy(str,"I11");
337#ifdef TINT32BIT
338 else if(datatype==TINT32BIT) strcpy(str,"I11");
339#endif
340#ifdef TLONGLONG
341 else if(datatype==TLONGLONG) strcpy(str,"I21");
342#endif
343 else if(datatype==TFLOAT) strcpy(str,"E29.20");
344 else if(datatype==TDOUBLE) strcpy(str,"E29.20");
345 else if(datatype==TUSHORT) strcpy(str,"I7");
346 else if(datatype==TULONG) strcpy(str,"I11");
347 else
348 throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
349 TForm.push_back(str);
350 } else {
351 if(tform) TForm.push_back(tform); else TForm.push_back("");
352 datatype = 0;
353 }
354 Label.push_back(label);
355 if(tunit) TUnit.push_back(tunit); else TUnit.push_back("");
356
357 int n = (int) Label.size() -1;
358
359 if(DbgLevel)
360 cout<<"FitsABTWriter::addcol["<<n<<"] Label="<<Label[n]
361 <<" TForm="<<TForm[n]
362 <<" TUnit="<<TUnit[n]
363 <<" datatype="<<datatype<<endl;
364
365 return n;
366}
367
368/*! Create the table. Done at the first write request. */
369void FitsABTWriter::createtbl(void)
370{
371 if(!FirstTime) return;
372
373 int tfields = Label.size();
374 if(tfields<=0)
375 throw ParmError("FitsABTWriter::createtbl: Zero column asked !\n");
376
377 long nrows = 0;
378 char *extname = NULL;
379 char **ttype = (char **) malloc(tfields*sizeof(char *));
380 char **tform = (char **) malloc(tfields*sizeof(char *));
381 char **tunit = (char **) malloc(tfields*sizeof(char *));
382
383 if(ExtName.size()>0) {
384 extname = (char *) malloc((strlen(ExtName.c_str())+1)*sizeof(char));
385 strcpy(extname,ExtName.c_str());
386 }
387 int i;
388 for(i=0;i<tfields;i++) {
389 ttype[i] = (char *) malloc((strlen(Label[i].c_str())+1)*sizeof(char));
390 strcpy(ttype[i],Label[i].c_str());
391 tform[i] = (char *) malloc((strlen(TForm[i].c_str())+1)*sizeof(char));
392 strcpy(tform[i],TForm[i].c_str());
393 tunit[i] = (char *) malloc((strlen(TUnit[i].c_str())+1)*sizeof(char));
394 strcpy(tunit[i],TUnit[i].c_str());
395 }
396
397 // append a new empty binary/ascii table onto the FITS file
398 int sta=0;
399 if(fits_create_tbl(FitsPtr,HduType,nrows,tfields,ttype,tform,tunit,extname,&sta)) {
400 printerror(sta);
401 throw NullPtrError("FitsABTWriter::createtbl: Error creating Table extension\n");
402 }
403
404 // Append Fits key
405 writekeys();
406
407 // menage
408 if(extname) delete [] extname;
409 for(i=0;i<tfields;i++) {
410 if(ttype[i]) delete [] ttype[i];
411 if(tform[i]) delete [] tform[i];
412 if(tunit[i]) delete [] tunit[i];
413 }
414 if(ttype) delete [] ttype;
415 if(tform) delete [] tform;
416 if(tunit) delete [] tunit;
417
418 FirstTime = false;
419}
420
421//////////////////////////////////////////////////////////////
422/*!
423 Write a data to FITS file.
424 \param col : column number [0,ncol[
425 \param row : row number [0,nrow[
426 \param val : value to be written
427 \warning that routine write a SHORT value into column "col"
428 which could have been defined with an other type.
429 Cast is performed by the cfitsio package.
430 \verbatim
431 WARNING: suppose that the column has be defined to be TSHORT
432 and suppose that you wanted to write a double value "val"
433 - If you write dummy.Write(col,row,(short)(val))
434 the Write(int,long,short) routine is called and
435 the cast is performed by the C++ language.
436 - If you write dummy.Write(col,row,val) where val is double
437 the Write(int,long,double) routine is called and
438 the cast is performed by the cfistio package.
439 \endverbatim
440*/
441
442/*! Write unsigned char (1 Byte) data to FITS file (see below) */
443void FitsABTWriter::Write(int col,long row,uint_1 val)
444{
445 if(FirstTime) createtbl();
446 int sta=0;
447 if(fits_write_col(FitsPtr,TBYTE,col+1,row+1,1,1,&val,&sta))
448 printerrorwrite("unsigned char",col,row,sta);
449}
450
451/*! Write short (2 Bytes) data to FITS file (see below) */
452void FitsABTWriter::Write(int col,long row,int_2 val)
453{
454 if(FirstTime) createtbl();
455 int sta=0;
456 if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,&val,&sta))
457 printerrorwrite("short",col,row,sta);
458}
459
460/*! Write unsigned short (2 Bytes) data to FITS file (see below) */
461void FitsABTWriter::Write(int col,long row,uint_2 val)
462{
463 if(FirstTime) createtbl();
464 int sta=0;
465 if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,1,1,&val,&sta))
466 printerrorwrite("unsigned short",col,row,sta);
467}
468
469/*! Write long (4 Bytes) data to FITS file (see below) */
470void FitsABTWriter::Write(int col,long row,int_4 val)
471{
472 if(FirstTime) createtbl();
473 int sta=0;
474 // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
475 int T = (sizeof(long)==4) ? TLONG: TINT;
476 if(fits_write_col(FitsPtr,T,col+1,row+1,1,1,&val,&sta))
477 printerrorwrite("long",col,row,sta);
478}
479
480/*! Write unsigned long (4 Bytes) data to FITS file (see below) */
481void FitsABTWriter::Write(int col,long row,uint_4 val)
482{
483 if(FirstTime) createtbl();
484 int sta=0;
485 // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
486 int T = (sizeof(unsigned long)==4) ? TULONG: TUINT;
487 if(fits_write_col(FitsPtr,T,col+1,row+1,1,1,&val,&sta))
488 printerrorwrite("long",col,row,sta);
489}
490
491/*! Write long long (8 Bytes) data to FITS file (see below) */
492void FitsABTWriter::Write(int col,long row,int_8 val)
493{
494#ifdef TLONGLONG
495 if(FirstTime) createtbl();
496 int sta=0;
497 if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,1,1,&val,&sta))
498 printerrorwrite("long long",col,row,sta);
499#else
500 throw PException("FitsABTWriter::Write(..,int_8) Not in that cfitsio version");
501#endif
502}
503
504/*! Write float data to FITS file (see below) */
505void FitsABTWriter::Write(int col,long row,float val)
506{
507 if(FirstTime) createtbl();
508 int sta=0;
509 if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,&val,&sta))
510 printerrorwrite("float",col,row,sta);
511}
512
513/*! Write double data to FITS file (see below) */
514void FitsABTWriter::Write(int col,long row,double val)
515{
516 if(FirstTime) createtbl();
517 int sta=0;
518 if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,&val,&sta))
519 printerrorwrite("double",col,row,sta);
520}
521
522//////////////////////////////////////////////////////////////
523/*!
524 Write a vector of data to FITS file.
525 \param col : column number [0,ncol[
526 \param row : starting row number [0,nrow[
527 \param val : vector to be written
528 \return "N" = number of the next row to be written,
529 that is "N-1" is the number of the last row written.
530*/
531
532/*! Write a vector of unsigned short (2 Bytes) data to FITS file (see below) */
533long FitsABTWriter::Write(int col,long row,TVector<uint_2>& val)
534{
535 if(FirstTime) createtbl();
536 long nel = val.Size();
537 int sta=0;
538 if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,1,nel,val.Data(),&sta))
539 printerrorwrite("long",col,row,sta);
540 return row+nel;
541}
542
543/*! Write a vector of long (4 Bytes) data to FITS file (see below) */
544long FitsABTWriter::Write(int col,long row,TVector<int_4>& val)
545{
546 if(FirstTime) createtbl();
547 long nel = val.Size();
548 int sta=0;
549 // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
550 int T = (sizeof(long)==4) ? TLONG: TINT;
551 if(fits_write_col(FitsPtr,T,col+1,row+1,1,nel,val.Data(),&sta))
552 printerrorwrite("long",col,row,sta);
553 return row+nel;
554}
555
556/*! Write a vector of long long (8 Bytes) data to FITS file (see below) */
557long FitsABTWriter::Write(int col,long row,TVector<int_8>& val)
558{
559#ifdef TLONGLONG
560 if(FirstTime) createtbl();
561 long nel = val.Size();
562 int sta=0;
563 if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,1,nel,val.Data(),&sta))
564 printerrorwrite("long long",col,row,sta);
565 return row+nel;
566#else
567 throw PException("FitsABTWriter::Write(..,TVector<int_8>&) Not in that cfitsio version");
568#endif
569}
570
571/*! Write a vector of float data to FITS file (see below) */
572long FitsABTWriter::Write(int col,long row,TVector<float>& val)
573{
574 if(FirstTime) createtbl();
575 long nel = val.Size();
576 int sta=0;
577 if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta))
578 printerrorwrite("float",col,row,sta);
579 return row+nel;
580}
581
582/*! Write a vector of double data to FITS file (see below) */
583long FitsABTWriter::Write(int col,long row,TVector<double>& val)
584{
585 if(FirstTime) createtbl();
586 long nel = val.Size();
587 int sta=0;
588 if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta))
589 printerrorwrite("double",col,row,sta);
590 return row+nel;
591}
592
593//////////////////////////////////////////////////////////////
594void FitsABTWriter::printerrorwrite(const char* type,int col,long row,int sta)
595{
596 if(sta==NUM_OVERFLOW) {NOverFlow++; return;}
597 printerror(sta);
598 char str[256];
599 sprintf(str,"FitsABTWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d"
600 ,type,col,row,sta);
601 throw NotAvailableOperation(str);
602}
603
604/////////////////////////////////////////////////
605void FitsABTWriter::printerror(int sta) const
606{
607 int stat = sta;
608 fits_report_error(stdout,stat);
609 fflush(stdout);
610 return;
611}
612
613/////////////////////////////////////////////////
614void FitsABTWriter::Print(ostream& os,int lp) const
615{
616os<<"FitsABTWriter::Print: FitsFN "<<FitsFN<<endl
617 <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow
618 <<" NCol "<<Label.size()<<endl;
619if(Label.size()>0 && lp>=1)
620 for(int i=0;i<(int)Label.size();i++)
621 os<<i<<"... Label="<<Label[i]<<" TForm="<<TForm[i]<<" TUnit="<<TUnit[i]<<endl;
622}
Note: See TracBrowser for help on using the repository browser.