source: Sophya/trunk/SophyaExt/FitsIOServer/fitsioserver.cc@ 482

Last change on this file since 482 was 482, checked in by ansari, 26 years ago

dans meth. sinus_picture_projection, declaration map=new... au lieu de map[...] 20-OCT-99 GLM

File size: 37.4 KB
Line 
1//************************************************************************
2// Class for loadind and saving from FITS-formatted file to DPC objects
3//
4// methods 'load(X& x, char f[])' get from FITS file "f" a DPC object x
5// from DPC class X.
6// methods 'save(X& x, char f[])' save a DPC object x from DPC // class X
7// onto a FITS file "f" .
8
9//************************************************************************
10
11#include <iostream.h>
12#include <list>
13
14#include "fitsioserver.h"
15#include "strutil.h"
16
17void FitsIoServer::load(TMatrix<double>& mat,char flnm[])
18{
19 int nbrows=0;
20 int nbcols=0;
21 FITS_tab_typ_ = TDOUBLE;
22 long naxis;
23 int n1, n2, n3;
24 DVList dvl;
25 planck_read_img(flnm, naxis, n1, n2, n3, dvl);
26
27 nbrows=n1;
28 nbcols=n2;
29 if (naxis == 1) nbcols=1;
30 //dvl.Print();
31 DVList::ValList::const_iterator it;
32 for(it = dvl.Begin(); it != dvl.End(); it++)
33 {
34 char datatype= (*it).second.typ;
35 char keyname[]="";
36 strcpy(keyname, (*it).first.substr(0,64).c_str());
37 int ival=0;
38 double dval=0.;
39 char strval[]="";
40 switch (datatype)
41 {
42 case 'I' :
43 ival=(*it).second.mtv.iv;
44 break;
45 case 'D' :
46 dval=(*it).second.mtv.dv;
47 break;
48 case 'S' :
49 strcpy(strval, (*it).second.mtv.strv);
50 break;
51 default :
52 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
53 break;
54 }
55 }
56
57 if (naxis > 2)
58 {
59 cout<<" FitsIOServer : le fichier fits n'est pas une matrice, naxis= " <<naxis<< endl;
60 }
61
62 // number of components
63 if (mat.NRows() != nbrows || mat.NCols() != nbcols )
64 {
65 cout << " found " << nbrows << " rows ";
66 cout << " expected " << mat.NRows() << endl;
67 cout << " found " << nbcols << " columns " ;
68 cout << " expected " << mat.NCols() << endl;
69 mat.ReSize(nbrows,nbcols);
70 cout << " resize the vector to nbrows= " << nbrows << " nbcols= " << nbcols << endl;
71 }
72 int ij=0;
73 for (int j=0; j< nbcols; j++)
74 for (int i = 0; i < nbrows; i++) mat(i,j) = dtab_[ij++];
75}
76
77void FitsIoServer::load(NTuple& ntpl,char flnm[],int hdunum)
78
79 //********************************************************/
80 //* move to the HDU which has the specified number hdunum*/
81 //* in the FITS file, perform read operations and write */
82 //* the elements in an NTuple. */
83 //********************************************************/
84{
85
86 // pointer to the FITS file, defined in fitsio.h
87 fitsfile *fptr;
88 int status = 0;
89 if( fits_open_file(&fptr,flnm,READONLY,&status) )
90 printerror( status );
91
92 // move to the HDU
93 int hdutype;
94 if( fits_movabs_hdu(fptr,hdunum,&hdutype,&status) )
95 printerror( status );
96
97 // get number of keywords
98 int nkeys,keypos;
99 if( fits_get_hdrpos(fptr,&nkeys,&keypos,&status) )
100 printerror( status );
101
102 /*
103 printf("Move to extensions by name and version number: (ffmnhd)\n");
104 char* binname= "Test-BINTABLE";
105 int extvers = 1;
106 fits_movnam_hdu(fptr,ANY_HDU, binname,extvers,&status);
107 fits_get_hdu_num(fptr,&hdunum);
108 printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);
109 */
110
111 if (hdutype == BINARY_TBL)
112 printf("\nReading binary table in HDU %d:\n",hdunum);
113 else
114 {
115 printf("Error:: this HDU is not a binary table\n");
116 exit ( status );
117 }
118
119 // number of columns
120 int tfields;
121 if( fits_get_num_cols(fptr,&tfields,&status) )
122 printerror( status );
123
124 // to get table size
125 long naxis[2];
126 int nfound;
127 if( fits_read_keys_lng(fptr, "NAXIS", 1, 2, naxis, &nfound, &status) )
128 printerror( status );
129 int nrows= naxis[1];
130
131 printf("\nInformation about each column:\n");
132
133 //Information about each column
134 char **ttype, **tform;
135 ttype= new char*[tfields];
136 tform= new char*[tfields];
137 for( int ii = 0; ii < tfields; ii++)
138 {
139 ttype[ii]= new char[FLEN_VALUE];
140 tform[ii]= new char[FLEN_VALUE];
141 }
142
143 // number of TTYPEn,TFORMn and TUNITn keywords found
144 int num= 0;
145
146 // read the column names from the TTYPEn keywords
147 fits_read_keys_str(fptr,"TTYPE",1,tfields,ttype,&nfound,&status);
148 num += nfound;
149 // read the column names from the TFORMn keywords
150 fits_read_keys_str(fptr,"TFORM",1,tfields,tform,&nfound,&status);
151 num += nfound;
152
153 for(int ii = 0; ii < tfields; ii++)
154 printf("\nColumn name & Format %8s %8s", ttype[ii],tform[ii]);
155
156 // select the columns with float data values (typecode = 42)
157 int typecode;
158 long repeat,width;
159 list<int> column;
160 for( int ii = 0; ii < tfields; ii++)
161 {
162 fits_binary_tform(tform[ii],&typecode, &repeat, &width, &status);
163 //printf("\n%4s %3d %2ld %2ld", tform[ii], typecode, repeat, width);
164 if(typecode == 42)
165 column.push_back(ii+1);
166 }
167
168 // get input elements to create the NTuple
169 char **clname;
170 clname= new char*[column.size()];
171 for(int ii = 0; ii < column.size(); ii++)
172 clname[ii]= new char[FLEN_VALUE];
173
174 list<int>::iterator itr;
175 int index= 0;
176 for(itr= column.begin(); itr != column.end(); itr++)
177 strcpy(clname[index++],ttype[*itr-1]);
178
179 // check if the specified keyword BLK exists
180 int blk= 512;
181 if(check_keyword(fptr,nkeys,"BLK"))
182 {
183 if( fits_read_key(fptr,TINT,"BLK",&blk,NULL,&status) )
184 printerror( status );
185 }
186
187 // create a NTuple
188 NTuple nt0(column.size(),clname,blk);
189
190 float value[1];
191 long felem = 1;
192 char strnull[10];
193 strcpy(strnull, " ");
194 int anynull= 0;
195 long longnull = 0;
196
197 // value to represent undefined array elements
198 float floatnull = FLOATNULLVALUE;
199
200 // read elements from columns and fill NTuple
201 for (int k = 0; k < nrows; k++)
202 {
203 int j= 0;
204 float *xnt= new float[column.size()];
205 list<int>::iterator itr;
206 for(itr= column.begin(); itr != column.end(); itr++)
207 {
208 fits_read_col(fptr,TFLOAT,*itr,k+1,felem,1,&floatnull,value,
209 &anynull, &status);
210 xnt[j++]= value[0];
211 }
212 nt0.Fill(xnt);
213 delete[] xnt;
214 }
215
216 // the TUNITn keywords are optional, if they exist they are put
217 // in the DVLIst object
218 char keyname[LEN_KEYWORD]= "";
219 char strval[FLEN_VALUE];
220 for(int ii = 0; ii < tfields; ii++)
221 {
222 fits_make_keyn("TUNIT",ii+1,keyname,&status);
223 if(check_keyword(fptr,nkeys,keyname))
224 {
225 num++;
226 if( fits_read_key_str(fptr,keyname,strval,NULL,&status) )
227 printerror(status);
228 strip (keyname, 'B',' ');
229 strip(strval, 'B',' ');
230 nt0.Info()[keyname]= strval;
231 }
232 }
233
234 // add the number of mandatory keywords of a binary table
235 num += 8;
236
237 // put names and values of other reserved keywords in a DVList object
238 char comment[FLEN_COMMENT];
239 char dtype;
240 for(int j = num+1; j <= nkeys; j++)
241 {
242 fits_read_keyn(fptr,j,keyname,strval,comment,&status);
243 fits_get_keytype(strval,&dtype,&status);
244 strip (keyname, 'B',' ');
245 strip(strval, 'B',' ');
246
247 switch( dtype )
248 {
249 case 'C':
250 nt0.Info()[keyname]= strval;
251 break;
252 case 'I':
253 int ival;
254 ctoi(strval,&ival);
255 nt0.Info()[keyname]= (int_4)ival;
256 break;
257 case 'F':
258 double dval;
259 ctof(strval,&dval);
260 nt0.Info()[keyname]= dval;
261 break;
262 }
263 }
264
265 // copy in the input NTuple
266 ntpl= nt0;
267
268 if( fits_close_file(fptr, &status) )
269 printerror(status);
270
271 printf("\n");
272 return;
273}
274
275
276void FitsIoServer::load(SphericalMap<double>& sph, char flnm[])
277{
278 int npixels=0;
279 int nside=0;
280 FITS_tab_typ_ = TDOUBLE;
281 read_sphere(flnm, npixels, nside);
282
283 // number of pixels in the sphere
284 if (sph.NbPixels() != npixels)
285 {
286 cout << " found " << npixels << " pixels" << endl;
287 cout << " expected " << sph.NbPixels() << endl;
288 if (nside <= 0 )
289 {
290 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl;
291 exit(0);
292 }
293 if (nside != sph.SizeIndex())
294 {
295 sph.Resize(nside);
296 cout << " resizing the sphere to nside= " << nside << endl;
297 }
298 else
299 {
300 cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
301 exit(0);
302 }
303 }
304 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= dtab_[j];
305}
306void FitsIoServer::load(SphericalMap<float>& sph, char flnm[])
307{
308 int npixels=0;
309 int nside=0;
310 FITS_tab_typ_ = TFLOAT;
311 read_sphere(flnm, npixels, nside);
312 // number of pixels in the sphere
313 if (sph.NbPixels() != npixels)
314 {
315 cout << " found " << npixels << " pixels" << endl;
316 cout << " expected " << sph.NbPixels() << endl;
317 if (nside <= 0 )
318 {
319 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl;
320 exit(0);
321 }
322 if (nside != sph.SizeIndex())
323 {
324 sph.Resize(nside);
325 cout << " resizing the sphere to nside= " << nside << endl;
326 }
327 else
328 {
329 cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
330 exit(0);
331 }
332 }
333 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= ftab_[j];
334}
335
336void FitsIoServer::load(LocalMap<double>& lcm, char flnm[])
337{
338 int nside;
339 int nbrows=0;
340 int nbcols=0;
341 FITS_tab_typ_ = TDOUBLE;
342 long naxis;
343 int n1, n2, n3;
344 DVList dvl;
345 planck_read_img(flnm, naxis, n1, n2, n3, dvl);
346
347 nbrows=n1;
348 nbcols=n2;
349 if (naxis != 2)
350 {
351 cout<<" FitsIOServer : le fichier fits n'est pas une localmap, naxis= "<<naxis<<endl;
352 }
353 //dvl.Print();
354 DVList::ValList::const_iterator it;
355 for(it = dvl.Begin(); it != dvl.End(); it++)
356 {
357 char datatype= (*it).second.typ;
358 char keyname[]="";
359 strcpy(keyname, (*it).first.substr(0,64).c_str());
360 int ival=0;
361 double dval=0.;
362 char strval[]="";
363 switch (datatype)
364 {
365 case 'I' :
366 ival=(*it).second.mtv.iv;
367 break;
368 case 'D' :
369 dval=(*it).second.mtv.dv;
370 break;
371 case 'S' :
372 strcpy(strval, (*it).second.mtv.strv);
373 break;
374 default :
375 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
376 break;
377 }
378 if (!strcmp(keyname, "NSIDE") )
379 {
380 nside = ival;
381 }
382 //if (!strcmp(keyname, "ORDERING") )
383 // {
384 // cout << " j'ai trouve ORDERING " << endl;
385 // }
386 }
387 float theta0 = dvl.GetD("THETA0");
388 float phi0 = dvl.GetD("PHI0");
389 int x0 = dvl.GetI("X0");
390 int y0 = dvl.GetI("Y0");
391 int xo = dvl.GetI("XO");
392 int yo = dvl.GetI("YO");
393 float anglex=dvl.GetD("ANGLEX");
394 float angley=dvl.GetD("ANGLEY");
395 float angle = dvl.GetD("ANGLE");
396
397 // number of components
398
399 if (lcm.Size_x() != nbrows || lcm.Size_y() != nbcols )
400 {
401 cout << " found " << nbrows << " x-pixels ";
402 cout << " expected " << lcm.Size_x() << endl;
403 cout << " found " << nbcols << " y-pixels " ;
404 cout << " expected " << lcm.Size_y() << endl;
405 lcm.ReSize(nbrows,nbcols);
406 cout << " resizing the map to x-size= " << nbrows << " y-size= " << nbcols << endl;
407 }
408 lcm.SetSize(anglex, angley);
409 lcm.SetOrigin(theta0, phi0, x0, y0, angle);
410 int ij=0;
411 for (int j=0; j< nbcols; j++)
412 for (int i = 0; i < nbrows; i++) lcm(i,j) = dtab_[ij++];
413}
414
415void FitsIoServer::load(ImageR4& DpcImg,char flnm[])
416{
417 FITS_tab_typ_ = TFLOAT;
418 long naxis;
419 int siz_x;
420 int siz_y;
421 int n3;
422 DVList dvl;
423
424 planck_read_img(flnm, naxis, siz_x, siz_y, n3, dvl);
425
426
427 if (naxis != 2)
428 {
429 cout << " FitsIOServer : naxis= " << naxis << " not equal to 2 ?" << endl;
430 }
431
432 DpcImg.Allocate(siz_x, siz_y, 0., 0);
433 float* pixelPtr=DpcImg.ImagePtr();
434 //for (int i=0; i < siz_x*siz_y; i++) pixelPtr[i]=ftab_[i];
435 // verifications de type
436 PBaseDataTypes dataT=DataType((r_4)0);
437 int TypeDonnees=dvl.GetI("DATATYPE");
438 if (int(dataT) != TypeDonnees)
439 {
440 cout << " FitsIOServer : parameter DATATYPE on file is not float " << endl;
441 cout << " eventual conversion to float is achieved by cfitsio lib " << endl;
442 }
443
444 memcpy(pixelPtr, ftab_, siz_x*siz_y*DataSize(dataT));
445 const char* nom=dvl.GetS("NAME").c_str();
446 DpcImg.SetNameId(dvl.GetI("IDENT"), nom);
447 DpcImg.SetOrg(dvl.GetI("ORG_X"), dvl.GetI("ORG_Y"));
448 DpcImg.SetPxSize(dvl.GetD("PIXSZ_X"), dvl.GetD("PIXSZ_Y"));
449 DpcImg.SetAtt(dvl.GetI("NBNUL"), dvl.GetI("NBSAT"),
450 dvl.GetD("MINPIX"), dvl.GetD("MAXPIX"), dvl.GetD("MOYPIX"),
451 dvl.GetD("SIGPIX"),dvl.GetD("FOND"), dvl.GetD("SIGFON"));
452
453}
454
455
456void FitsIoServer::load(ImageI4& DpcImg,char flnm[])
457{
458 FITS_tab_typ_ = TINT;
459 long naxis;
460 int siz_x;
461 int siz_y;
462 int n3;
463 DVList dvl;
464
465 // pointer to the FITS file, defined in fitsio.h
466 //fitsfile *fptr;
467 // initialize status before calling fitsio routines
468 //int status = 0;
469
470 //fits_open_file(&fptr, flnm, READONLY, &status);
471 //if( status ) printerror( status );
472 planck_read_img(flnm, naxis, siz_x, siz_y, n3, dvl);
473 // close the file
474 //fits_close_file(fptr, &status);
475 //if( status ) printerror( status );
476
477 if (naxis != 2)
478 {
479 cout << " FitsIOServer : naxis= " << naxis << " not equal to 2 ?" << endl;
480 }
481
482 DpcImg.Allocate(siz_x, siz_y, 0., 0);
483 int_4* pixelPtr=DpcImg.ImagePtr();
484
485
486 // verifications de type
487 PBaseDataTypes dataT=DataType((int_4)0);
488 int TypeDonnees=dvl.GetI("DATATYPE");
489 if (int(dataT) != TypeDonnees)
490 {
491 cout << " FitsIOServer : parameter DATATYPE on file is not int_4 " << endl;
492 cout << " eventual conversion to float is achieved by cfitsio lib " << endl;
493 }
494 memcpy(pixelPtr, i_4tab_, siz_x*siz_y*DataSize(dataT));
495 const char* nom=dvl.GetS("NAME").c_str();
496 DpcImg.SetNameId(dvl.GetI("IDENT"), nom);
497 DpcImg.SetOrg(dvl.GetI("ORG_X"), dvl.GetI("ORG_Y"));
498 DpcImg.SetPxSize(dvl.GetD("PIXSZ_X"), dvl.GetD("PIXSZ_Y"));
499 DpcImg.SetAtt(dvl.GetI("NBNUL"), dvl.GetI("NBSAT"),
500 dvl.GetD("MINPIX"), dvl.GetD("MAXPIX"), dvl.GetD("MOYPIX"),
501 dvl.GetD("SIGPIX"),dvl.GetD("FOND"), dvl.GetD("SIGFON"));
502}
503
504
505void FitsIoServer::save( TMatrix<double>& mat, char filename[])
506{
507 int nbrows = mat.NRows();
508 int nbcols = mat.NCols();
509 long naxis = nbcols > 1 ? 2 : 1;
510 cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl;
511 FITS_tab_typ_ = TDOUBLE;
512 if (dtab_ != NULL ) delete[] dtab_;
513 dtab_=new double[nbrows*nbcols];
514
515
516 int ij=0;
517 for (int j=0; j< nbcols; j++)
518 for (int i = 0; i < nbrows; i++) dtab_[ij++]= mat(i,j);
519
520 DVList dvl;
521
522 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
523
524}
525
526void FitsIoServer::save(NTuple& ntpl,char flnm[])
527
528 //****************************************************/
529 //* read the elements of the NTuple ntpl, and create */
530 //* a FITS file with a binary table extension */
531 //****************************************************/
532{
533
534 // delete old file if it already exists
535 remove(flnm);
536
537 // pointer to the FITS file, defined in fitsio.h
538 fitsfile *fptr;
539 int status = 0;
540 if( fits_create_file(&fptr, flnm, &status) )
541 printerror( status );
542
543 // table will have tfields columns
544 int tfields= ntpl.NVar();
545
546 // table will have nrows rows
547 int nrows= ntpl.NEntry();
548
549 // extension name
550 char extname[] = "NTuple_Binary_tbl";
551
552 // define the name, and the datatype for the tfields columns
553 char **ttype, **tform;
554 ttype= new char*[tfields];
555 tform= new char*[tfields];
556 for(int i = 0; i < tfields; i++)
557 {
558 ttype[i]= new char[FLEN_VALUE];
559 strcpy(ttype[i], ntpl.NomIndex(i));
560 tform[i]= new char[FLEN_VALUE];
561 strcpy(tform[i], "1E");
562 }
563
564 // create a new empty binary table onto the FITS file
565 // physical units if they exist, are defined in the DVList object
566 // so the null pointer is given for the tunit parameters.
567 if ( fits_create_tbl(fptr,BINARY_TBL,nrows,tfields,ttype,tform,
568 NULL,extname,&status) )
569 printerror( status );
570
571 // first row in table to write
572 int firstrow = 1;
573
574 // first element in row (ignored in ASCII tables)
575 int firstelem = 1;
576
577 for(int i = 0; i < tfields; i++)
578 {
579 float *dens= new float[nrows];
580 for(int j = 0; j < nrows; j++)
581 {
582 dens[j]= ntpl.GetVal(j,i);
583 }
584 fits_write_col(fptr,TFLOAT,i+1,firstrow,firstelem,nrows,dens,&status);
585 delete []dens;
586 }
587
588 // number of blocks per event
589 int blk= ntpl.BLock();
590 fits_write_key(fptr,TINT,"BLK",&blk,"number of blocks per evt",&status);
591
592 // get names and values from the join DVList object
593 DVList dvl= ntpl.Info();
594 dvl.Print();
595 DVList::ValList::const_iterator it;
596 for(it = dvl.Begin(); it != dvl.End(); it++)
597 {
598 char keytype= (*it).second.typ;
599 char keyname[9]="";
600 strncpy(keyname,(*it).first.substr(0,64).c_str(),8);
601 char comment[FLEN_COMMENT]="";
602
603 switch (keytype)
604 {
605 case 'I' :
606 {
607 int ival=(*it).second.mtv.iv;
608 strcpy(comment,"I entier");
609 fits_write_key(fptr,TINT,keyname,&ival,comment,&status);
610 break;
611 }
612 case 'D' :
613 {
614 double dval=(*it).second.mtv.dv;
615 strcpy(comment,"D double");
616 fits_write_key(fptr,TDOUBLE,keyname,&dval,comment,&status);
617 break;
618 }
619 case 'S' :
620 {
621 char strval[]="";
622 strcpy(strval,(*it).second.mtv.strv);
623 strcpy(comment,"S character string");
624 fits_write_key(fptr,TSTRING,keyname,&strval,comment,&status);
625 break;
626 }
627 }
628 }
629
630 //close the FITS file
631 if ( fits_close_file(fptr, &status) )
632 printerror( status );
633 return;
634}
635
636
637
638
639//void FitsIoServer::save(SphericalMap<double>& sph, char filename[])
640void FitsIoServer::save(SphericalMap<double>& sph, char filename[])
641{
642 int npixels = sph.NbPixels();
643 FITS_tab_typ_ = TDOUBLE;
644 if (dtab_ != NULL ) delete[] dtab_;
645 dtab_=new double[npixels];
646
647
648 for (int j = 0; j < npixels; j++) dtab_[j]= sph(j);
649 DVList dvl;
650 dvl["NSIDE"] = sph.SizeIndex();
651 dvl["ORDERING"]=sph.TypeOfMap();
652
653 planck_write_img(filename, 1, npixels, 0, 0, dvl);
654
655 // decider ulterieurement ce qu'on fait de ce qui suit, specifique
656 // pour l'instant, aux spheres gorski.
657
658 /*
659 // write supplementary keywords
660 fits_write_comment(fptr, " ", &status);
661 if( status ) printerror( status );
662
663
664 strcpy(comment,"HEALPIX Pixelisation");
665 strcpy(svalue, "HEALPIX");
666 fits_write_key(fptr, TSTRING, "PIXTYPE", svalue, comment, &status);
667 if( status ) printerror( status );
668
669
670 strcpy(comment,"pixel ordering scheme, either RING or NESTED");
671 strcpy(svalue, "RING");
672 fits_write_key(fptr, TSTRING, "ORDERING", svalue, comment, &status);
673 if( status ) printerror( status );
674
675
676 strcpy(comment,"Random generator seed");
677 int iseed= sph.iseed();
678 fits_write_key(fptr, TINT, "RANDSEED", &iseed, comment, &status);
679 if( status ) printerror( status );
680
681
682 strcpy(comment,"--------------------------------------------");
683 fits_write_comment(fptr, comment, &status);
684 if( status ) printerror( status );
685
686 strcpy(comment," Above keywords are still likely to change !");
687 fits_write_comment(fptr, comment, &status);
688 if( status ) printerror( status );
689
690 strcpy(comment,"--------------------------------------------");
691 fits_write_comment(fptr, comment, &status);
692 if( status ) printerror( status );
693
694 */
695
696
697}
698
699void FitsIoServer::save(SphericalMap<float>& sph, char filename[])
700{
701 int npixels = sph.NbPixels();
702 FITS_tab_typ_ = TFLOAT;
703 if (ftab_ != NULL ) delete[] ftab_;
704 ftab_=new float[npixels];
705
706
707 for (int j = 0; j < npixels; j++) ftab_[j]= sph(j);
708 DVList dvl;
709 dvl["NSIDE"] = sph.SizeIndex();
710 dvl["ORDERING"]=sph.TypeOfMap();
711
712 planck_write_img(filename, 1, npixels, 0, 0, dvl);
713
714
715}
716
717void FitsIoServer::save(LocalMap<double>& locm, char filename[])
718{
719 int nbrows = locm.Size_x();
720 int nbcols = locm.Size_y();
721 long naxis = 2;
722 cout << " nombre de pts en x : " << nbrows << " en y " << nbcols << endl;
723 FITS_tab_typ_ = TDOUBLE;
724 if (dtab_ != NULL ) delete[] dtab_;
725 dtab_=new double[nbrows*nbcols];
726
727 int ij=0;
728 for (int j=0; j< nbcols; j++)
729 for (int i = 0; i < nbrows; i++) dtab_[ij++]= locm(i,j);
730
731 DVList dvl;
732 dvl["NSIDE"] = locm.SizeIndex();
733 dvl["ORDERING"]=locm.TypeOfMap();
734 double theta0;
735 double phi0;
736 int x0;
737 int y0;
738 double angle;
739 locm.Origin(theta0,phi0,x0,y0,angle);
740 double anglex;
741 double angley;
742 locm.Aperture(anglex,angley);
743 dvl["THETA0"] = theta0;
744 dvl["PHI0"] = phi0;
745 dvl["X0"] = (int_4)x0;
746 dvl["Y0"] = (int_4)y0;
747 dvl["ANGLE"] = angle;
748 dvl["ANGLEX"] = anglex;
749 dvl["ANGLEY"] = angley;
750 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
751}
752
753
754void FitsIoServer::save(ImageR4& DpcImg,char flnm[])
755{
756 long naxis=2;
757 int siz_x = DpcImg.XSize();
758 int siz_y = DpcImg.YSize();
759 int nbpixels = siz_x*siz_y;
760 FITS_tab_typ_ = TFLOAT;
761
762
763 // get the values of the DpcImage
764 if (ftab_ != NULL) delete [] ftab_;
765 ftab_=DpcImg.ImagePtr();
766
767 // write FITS image
768 DVList dvl;
769
770 dvl["DATATYPE"] = (int_4)DpcImg.PixelType();
771 dvl["ORG_X"] = DpcImg.XOrg();
772 dvl["ORG_Y"] = DpcImg.YOrg();
773 dvl["PIXSZ_X"] = DpcImg.XPxSize();
774 dvl["PIXSZ_Y"] = DpcImg.YPxSize();
775 dvl["IDENT"] = DpcImg.Ident();
776 dvl["NAME"] = DpcImg.Nom();
777 dvl["NBSAT"] = DpcImg.nbSat;
778 dvl["NBNUL"] = DpcImg.nbNul;
779 dvl["MINPIX"] = DpcImg.minPix;
780 dvl["MAXPIX"] = DpcImg.maxPix;
781 dvl["MOYPIX"] = DpcImg.moyPix;
782 dvl["SIGPIX"] = DpcImg.sigPix;
783 dvl["FOND"] = DpcImg.fond;
784 dvl["SIGFON"] = DpcImg.sigmaFond;
785
786
787 planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl);
788
789
790 ftab_=NULL;
791}
792
793
794void FitsIoServer::save(ImageI4& DpcImg,char flnm[])
795{
796 long naxis=2;
797 int siz_x = DpcImg.XSize();
798 int siz_y = DpcImg.YSize();
799 int nbpixels = siz_x*siz_y;
800 FITS_tab_typ_ = TINT;
801
802 // pointer to the FITS file, defined in fitsio.h
803 //fitsfile *fptr;
804
805 // initialize status before calling fitsio routines
806 //int status = 0;
807
808 // delete old file if it already exists
809 //remove(flnm);
810
811 // create new FITS file
812 //fits_create_file(&fptr, flnm, &status);
813 //if( status ) printerror( status );
814
815 // get the values of the DpcImage
816 if (i_4tab_ != NULL) delete [] i_4tab_;
817 i_4tab_=DpcImg.ImagePtr();
818
819 // write FITS image
820 DVList dvl;
821
822 dvl["DATATYPE"] = (int_4)DpcImg.PixelType();
823 dvl["ORG_X"] = DpcImg.XOrg();
824 dvl["ORG_Y"] = DpcImg.YOrg();
825 dvl["PIXSZ_X"] = DpcImg.XPxSize();
826 dvl["PIXSZ_Y"] = DpcImg.YPxSize();
827 dvl["IDENT"] = DpcImg.Ident();
828 dvl["NAME"] = DpcImg.Nom();
829 dvl["NBSAT"] = DpcImg.nbSat;
830 dvl["NBNUL"] = DpcImg.nbNul;
831 dvl["MINPIX"] = DpcImg.minPix;
832 dvl["MAXPIX"] = DpcImg.maxPix;
833 dvl["MOYPIX"] = DpcImg.moyPix;
834 dvl["SIGPIX"] = DpcImg.sigPix;
835 dvl["FOND"] = DpcImg.fond;
836 dvl["SIGFON"] = DpcImg.sigmaFond;
837
838
839 planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl);
840
841 // close the file
842 //fits_close_file(fptr, &status);
843 //if( status ) printerror( status );
844
845 i_4tab_=NULL;
846}
847
848
849
850
851void FitsIoServer::planck_write_img(char flnm[], int naxis,int n1, int n2, int n3, DVList& dvl)
852{
853
854 cout << " nouveau write_img" << endl;
855
856 // pointer to the FITS file, defined in fitsio.h
857 fitsfile *fptr;
858
859 // initialize status before calling fitsio routines
860 int status = 0;
861
862 // delete old file if it already exists
863 remove(flnm);
864
865 // create new FITS file
866 fits_create_file(&fptr, flnm, &status);
867 if( status ) printerror( status );
868
869 int bitpix=0;
870 if ( FITS_tab_typ_ == TDOUBLE) bitpix = DOUBLE_IMG;
871 if ( FITS_tab_typ_ == TFLOAT) bitpix = FLOAT_IMG;
872 if ( FITS_tab_typ_ == TINT) bitpix = LONG_IMG;
873 long naxes[3];
874 naxes[0] = n1;
875 naxes[1] = n2;
876 naxes[2] = n3;
877 if (n2 > 0 && naxis < 2) cout << " FitsIoServer:: n2 = " << n2 << " seems to be incompatible with naxis = " << naxis << endl;
878 if (n3 > 0 && naxis < 3) cout << " FitsIoServer:: n3 = " << n3 << " seems to be incompatible with naxis = " << naxis << endl;
879 fits_create_img(fptr, bitpix, naxis, naxes, &status);
880 if( status ) printerror( status );
881
882
883
884 long nelements= naxes[0];
885 if (naxis >=2) nelements*=naxes[1];
886 if (naxis == 3) nelements*=naxes[2];
887 switch (FITS_tab_typ_)
888 {
889 case TDOUBLE :
890 fits_write_img(fptr, TDOUBLE, 1, nelements, dtab_, &status);
891 if( status ) printerror( status );
892 break;
893 case TFLOAT :
894 fits_write_img(fptr, TFLOAT, 1, nelements, ftab_, &status);
895 if( status ) printerror( status );
896 break;
897 case TINT :
898 fits_write_img(fptr, TINT, 1, nelements, i_4tab_, &status);
899 if( status ) printerror( status );
900 break;
901 default :
902 cout << " FitsIOServer : type de tableau non traite en ecriture " << endl;
903 break;
904 }
905
906 // write the current date
907 fits_write_date(fptr, &status);
908 if( status ) printerror( status );
909 // on convient d ecrire apres la date, les mots cles utilisateur.
910 // la date servira de repere pour relire ces mots cles.
911
912 //dvl.Print();
913 DVList::ValList::const_iterator it;
914 for(it = dvl.Begin(); it != dvl.End(); it++)
915 {
916 int datatype= key_type_PL2FITS( (*it).second.typ);
917 char keyname[]="";
918 int flen_keyword = 9;
919 // FLEN_KEYWORD est la longueur max d'un mot-cle. Il doit y avoir une
920 // erreur dans la librairie fits qui donne FLEN_KEYWORD=72
921 // contrairement a la notice qui donne FLEN_KEYWORD=9 (ch. 5, p.39)
922 strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword-1);
923 char comment[FLEN_COMMENT]="";
924 int ival=0;
925 double dval=0.;
926 char strval[]="";
927 switch (datatype)
928 {
929 case TINT :
930 ival=(*it).second.mtv.iv;
931 strcpy(comment,"I entier");
932 fits_write_key(fptr, datatype, keyname, &ival, comment, &status);
933 break;
934 case TDOUBLE :
935 dval=(*it).second.mtv.dv;
936 strcpy(comment,"D double");
937 fits_write_key(fptr, datatype, keyname, &dval, comment, &status);
938 break;
939 case TSTRING :
940 strcpy(strval, (*it).second.mtv.strv);
941 strcpy(comment,"S character string");
942 fits_write_key(fptr, datatype, keyname, &strval, comment, &status);
943 break;
944 default :
945 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
946 break;
947 }
948 if( status ) printerror( status );
949 }
950 // close the file
951 fits_close_file(fptr, &status);
952 if( status ) printerror( status );
953}
954
955void FitsIoServer::planck_read_img(char flnm[], long& naxis,int& n1, int& n2, int& n3, DVList& dvl)
956{
957 int status=0;
958 long bitpix;
959 long naxes[3]={0,0,0};
960 char* comment=NULL;
961
962 // pointer to the FITS file, defined in fitsio.h
963 fitsfile *fptr;
964 // initialize status before calling fitsio routines
965 fits_open_file(&fptr, flnm, READONLY, &status);
966 if( status ) printerror( status );
967
968
969 fits_read_key_lng(fptr, "BITPIX", &bitpix, comment, &status);
970 if( status ) printerror( status );
971 fits_read_key_lng(fptr, "NAXIS", &naxis, comment, &status);
972 if( status ) printerror( status );
973 int nfound;
974 int nkeys=(int)naxis;
975 fits_read_keys_lng(fptr, "NAXIS", 1, nkeys, naxes, &nfound, &status);
976 if( status ) printerror( status );
977
978 n1 = naxes[0] ;
979 n2 = naxes[1] ;
980 n3 = naxes[2] ;
981
982
983 long nelements= naxes[0];
984 if (naxis >=2) nelements*=naxes[1];
985 if (naxis == 3) nelements*=naxes[2];
986 int anynull;
987 double dnullval=0.;
988 float fnullval=0.;
989 // on laisse a fits le soin de convertir le type du tableau lu vers
990 // le type suppose par l'utilisateur de fitsioserver
991 //
992 switch ( FITS_tab_typ_)
993 {
994 case TDOUBLE :
995 if (bitpix != DOUBLE_IMG)
996 {
997 cout << " FitsIOServer : the data type on fits file is not double, "
998 << " conversion to double will be achieved by cfitsio lib " << endl;
999 }
1000 if (dtab_ != NULL) delete [] dtab_;
1001 dtab_=new double[nelements];
1002 fits_read_img(fptr, TDOUBLE, 1, nelements, &dnullval, dtab_,
1003 &anynull, &status);
1004 if( status ) printerror( status );
1005 break;
1006 case TFLOAT :
1007 if (bitpix != FLOAT_IMG)
1008 {
1009 cout << " FitsIOServer : the data type on fits file is not float, "
1010 << " conversion to float will be achieved by cfitsio lib " << endl;
1011 }
1012 if (ftab_ != NULL) delete [] ftab_;
1013 ftab_=new float[nelements];
1014 fits_read_img(fptr, TFLOAT, 1, nelements, &fnullval, ftab_,
1015 &anynull, &status);
1016 if( status ) printerror( status );
1017 break;
1018
1019
1020 case TINT :
1021 if (bitpix != LONG_IMG)
1022 {
1023 cout << " FitsIOServer : the data type on fits file is not long, "
1024 << " conversion to long will be achieved by cfitsio lib " << endl;
1025 }
1026 if (i_4tab_ != NULL) delete [] i_4tab_;
1027 i_4tab_=new int_4[nelements];
1028 fits_read_img(fptr, TINT, 1, nelements, &fnullval, i_4tab_,
1029 &anynull, &status);
1030 if( status ) printerror( status );
1031 break;
1032
1033
1034 default :
1035 cout << " FitsIOServer::read_img : type non traite: " << FITS_tab_typ_ << endl;
1036 break;
1037 }
1038 status = 0;
1039 char card[FLEN_CARD];
1040 int num = 0;
1041 char comment2[FLEN_COMMENT] = "x";
1042 char keyname[]= "";
1043 char datekey[]= "DATE";
1044 char endkey[] = "END";
1045 char typ='x';
1046 int ival;
1047 double dval;
1048 char strval[]="";
1049 // on a convenu que les mots cles utilisateur sont apres le mot cle DATE
1050 // on va jusqu'au mot cle DATE
1051 int flen_keyword = 9;
1052 // FLEN_KEYWORD est la longueur max d'un mot-cle. Il doit y avoir une
1053 // erreur dans la librairie fits qui donne FLEN_KEYWORD=72
1054 // contrairement a la notice qui donne FLEN_KEYWORD=9 (ch. 5, p.39)
1055 while (status == 0 && strncmp(keyname, datekey,4) != 0 )
1056 {
1057 num++;
1058 fits_read_record(fptr, num, card, &status);
1059 strncpy(keyname,card,flen_keyword-1);
1060 }
1061 if (status != 0 )
1062 {
1063 cout << " fitsio::planck_read_img : erreur, mot cle DATE absent " << endl;
1064 }
1065 // on recupere la liste des mots-cles utilisateurs
1066 while (status == 0)
1067 {
1068 num++;
1069 // on lit un record pour recuperer le nom du mot-cle
1070 fits_read_record(fptr, num, card, &status);
1071 strncpy(keyname,card,flen_keyword-1);
1072 char value[FLEN_VALUE];
1073 // on recupere le premier caractere du commentaire, qui contient
1074 // le code du type de la valeur
1075 // (tant que ce n est pas le mot cle END)
1076 fits_read_keyword(fptr, keyname, value, comment2, &status);
1077 if ( strncmp(keyname, endkey,flen_keyword-1) != 0)
1078 {
1079 typ = comment2[0];
1080 // quand le type est connu, on lit la valeur
1081 switch (typ)
1082 {
1083 case 'I' :
1084 fits_read_key(fptr, TINT, keyname, &ival, comment2, &status);
1085 if( status ) printerror( status );
1086 strip (keyname, 'B',' ');
1087 dvl[keyname] = (int_4)ival;
1088 break;
1089 case 'D' :
1090 fits_read_key(fptr, TDOUBLE, keyname, &dval, comment2, &status);
1091 if( status ) printerror( status );
1092 strip (keyname, 'B',' ');
1093 dvl[keyname] = dval;
1094 break;
1095 case 'S' :
1096 fits_read_key(fptr, TSTRING, keyname, strval, comment2, &status);
1097 if( status ) printerror( status );
1098 strip (keyname, 'B',' ');
1099 strip(strval, 'B',' ');
1100 dvl[keyname]=strval;
1101 break;
1102 default :
1103 cout << " FITSIOSERVER::planck_read_img : type de donnee non prevu " << endl;
1104 break;
1105 }
1106 }
1107 }
1108
1109 // close the file
1110 status=0;
1111 fits_close_file(fptr, &status);
1112 if( status ) printerror( status );
1113}
1114
1115
1116
1117// projects a SphericalMap<double>, according sinus-method, and saves onto
1118// a FITS-file
1119void FitsIoServer::sinus_picture_projection(SphericalMap<double>& sph, char filename[])
1120{
1121
1122 long naxes[2]={600, 300};
1123 float* map =new float[ 600*300 ];
1124 int npixels= naxes[0]*naxes[1];
1125
1126 cout << " image FITS en projection SINUS" << endl;
1127 // table will have npixels rows
1128 for(int j=0; j < npixels; j++) map[j]=0.;
1129 for(int j=0; j<naxes[1]; j++)
1130 {
1131 double yd = (j+0.5)/naxes[1]-0.5;
1132 double theta = (0.5-yd)*Pi;
1133 double facteur=1./sin(theta);
1134 for(int i=0; i<naxes[0]; i++)
1135 {
1136 double xa = (i+0.5)/naxes[0]-0.5;
1137 double phi = 2.*Pi*xa*facteur+Pi;
1138 float th=float(theta);
1139 float ff=float(phi);
1140 if (phi<2*Pi && phi>= 0)
1141 {
1142 map[j*naxes[0]+i] = sph.PixValSph(th, ff);
1143 }
1144 }
1145 }
1146
1147 write_picture(naxes, map, filename);
1148 delete [] map;
1149}
1150
1151// projects a SphericalMap<double>, according sinus-method, and saves onto
1152// a FITS-file
1153void FitsIoServer::sinus_picture_projection(SphericalMap<float>& sph, char filename[])
1154{
1155 // le code de cete methode duplique celui de la precedente, la seule
1156 //difference etant le type de sphere en entree. Ces methodes de projection
1157 // sont provisoires, et ne servent que pour les tests. C est pourquoi je
1158 // ne me suis pas casse la tete, pour l instant
1159
1160 long naxes[2]={600, 300};
1161 float* map = new float[ 600*300 ];
1162 int npixels= naxes[0]*naxes[1];
1163
1164 cout << " image FITS en projection SINUS" << endl;
1165 // table will have npixels rows
1166 for(int j=0; j < npixels; j++) map[j]=0.;
1167 for(int j=0; j<naxes[1]; j++)
1168 {
1169 double yd = (j+0.5)/naxes[1]-0.5;
1170 double theta = (0.5-yd)*Pi;
1171 double facteur=1./sin(theta);
1172 for(int i=0; i<naxes[0]; i++)
1173 {
1174 double xa = (i+0.5)/naxes[0]-0.5;
1175 double phi = 2.*Pi*xa*facteur+Pi;
1176 float th=float(theta);
1177 float ff=float(phi);
1178 if (phi<2*Pi && phi>= 0)
1179 {
1180 map[j*naxes[0]+i] = sph.PixValSph(th, ff);
1181 }
1182 }
1183 }
1184
1185 write_picture(naxes, map, filename);
1186 delete [] map;
1187
1188}
1189
1190// saves a (LocalMap<double> on a FITS-file in order to be visualized
1191// (for tests)
1192void FitsIoServer::picture(LocalMap<double>& lcm, char filename[])
1193{
1194
1195 long naxes[2];
1196 naxes[0] = lcm.Size_x();
1197 naxes[1] = lcm.Size_y();
1198 int npixels= naxes[0]*naxes[1];
1199 float* map = new float[npixels];
1200
1201 // table will have npixels rows
1202 for(int j=0; j < npixels; j++) map[j]=0.;
1203 for(int j=0; j<naxes[1]; j++)
1204 {
1205 for(int i=0; i<naxes[0]; i++)
1206 {
1207 map[j*naxes[0]+i] = lcm(i, j);
1208 }
1209 }
1210
1211 write_picture(naxes, map, filename);
1212 delete [] map;
1213}
1214
1215void FitsIoServer::read_sphere(char flnm[], int& npixels, int& nside)
1216{
1217 long naxis;
1218 nside=0;
1219 int n1, n2, n3;
1220 DVList dvl;
1221 planck_read_img(flnm, naxis, n1, n2, n3, dvl);
1222
1223 npixels=n1;
1224 //dvl.Print();
1225 DVList::ValList::const_iterator it;
1226 for(it = dvl.Begin(); it != dvl.End(); it++)
1227 {
1228 char datatype= (*it).second.typ;
1229 char keyname[]="";
1230 strcpy(keyname, (*it).first.substr(0,64).c_str());
1231 int ival=0;
1232 double dval=0.;
1233 char strval[]="";
1234 switch (datatype)
1235 {
1236 case 'I' :
1237 ival=(*it).second.mtv.iv;
1238 break;
1239 case 'D' :
1240 dval=(*it).second.mtv.dv;
1241 break;
1242 case 'S' :
1243 strcpy(strval, (*it).second.mtv.strv);
1244 break;
1245 default :
1246 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
1247 break;
1248 }
1249 if (!strcmp(keyname, "NSIDE") )
1250 {
1251 nside = ival;
1252 }
1253 //if (!strcmp(keyname, "ORDERING") )
1254 // {
1255 // cout << " j'ai trouve ORDERING " << endl;
1256 // }
1257 }
1258
1259 if (naxis != 1)
1260 {
1261 cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl;
1262 }
1263}
1264
1265
1266void FitsIoServer::write_picture(long* naxes, float* map, char* filename) const
1267{
1268
1269 int bitpix = FLOAT_IMG;
1270 long naxis = 2;
1271
1272 //pointer to the FITS file, defined in fitsio.h
1273 fitsfile *fptr;
1274 // delete old file if it already exists
1275 remove(filename);
1276 // initialize status before calling fitsio routines
1277 int status = 0;
1278
1279 // create new FITS file
1280 fits_create_file(&fptr, filename, &status);
1281 if( status ) printerror( status );
1282
1283 // write the required header keywords
1284 fits_create_img(fptr, bitpix, naxis, naxes, &status);
1285 if( status ) printerror( status );
1286
1287 // write the current date
1288 fits_write_date(fptr, &status);
1289 if( status ) printerror( status );
1290
1291
1292 // first row in table to write
1293 long firstrow = 1;
1294 // first element in row
1295 long firstelem = 1;
1296 int colnum = 1;
1297 int nelements=naxes[0]*naxes[1];
1298 fits_write_img(fptr, TFLOAT, firstelem, nelements, map, &status);
1299 if( status ) printerror( status );
1300
1301 // close the file
1302 fits_close_file(fptr, &status);
1303 if( status ) printerror( status );
1304}
1305
1306
1307bool FitsIoServer::check_keyword(fitsfile *fptr,int nkeys,char keyword[])
1308
1309 //*****************************************************/
1310 //* check if the specified keyword exits in the CHU */
1311 //*****************************************************/
1312{
1313
1314 bool KEY_EXIST = false;
1315 int status = 0;
1316 char strbide[FLEN_VALUE];
1317 char keybide[LEN_KEYWORD]= "";
1318 for(int jj = 1; jj <= nkeys; jj++)
1319 {
1320 if( fits_read_keyn(fptr,jj,keybide,strbide,NULL,&status) )
1321 printerror( status );
1322 if( !strcmp(keybide,keyword) )
1323 {
1324 KEY_EXIST= true;
1325 break;
1326 }
1327 }
1328 return(KEY_EXIST);
1329}
1330
1331void FitsIoServer::readheader ( char filename[] )
1332
1333 //**********************************************************************/
1334 //* Print out all the header keywords in all extensions of a FITS file */
1335 //**********************************************************************/
1336{
1337
1338 // standard string lengths defined in fitsioc.h
1339 char card[FLEN_CARD];
1340
1341 // pointer to the FITS file, defined in fitsio.h
1342 fitsfile *fptr;
1343
1344 int status = 0;
1345 if ( fits_open_file(&fptr, filename, READONLY, &status) )
1346 printerror( status );
1347
1348 // attempt to move to next HDU, until we get an EOF error
1349 int hdutype;
1350 for (int ii = 1; !(fits_movabs_hdu(fptr,ii,&hdutype,&status));ii++)
1351 {
1352 if (hdutype == ASCII_TBL)
1353 printf("\nReading ASCII table in HDU %d:\n", ii);
1354 else if (hdutype == BINARY_TBL)
1355 printf("\nReading binary table in HDU %d:\n", ii);
1356 else if (hdutype == IMAGE_HDU)
1357 printf("\nReading FITS image in HDU %d:\n", ii);
1358 else
1359 {
1360 printf("Error: unknown type of this HDU \n");
1361 printerror( status );
1362 }
1363
1364 // get the number of keywords
1365 int nkeys, keypos;
1366 if ( fits_get_hdrpos(fptr, &nkeys, &keypos, &status) )
1367 printerror( status );
1368
1369 printf("Header listing for HDU #%d:\n", ii);
1370 for (int jj = 1; jj <= nkeys; jj++)
1371 {
1372 if ( fits_read_record(fptr, jj, card, &status) )
1373 printerror( status );
1374
1375 // print the keyword card
1376 printf("%s\n", card);
1377 }
1378 printf("END\n\n");
1379 }
1380
1381 // got the expected EOF error; reset = 0
1382 if (status == END_OF_FILE)
1383 status = 0;
1384 else
1385 printerror( status );
1386
1387 if ( fits_close_file(fptr, &status) )
1388 printerror( status );
1389
1390 return;
1391}
1392
1393void FitsIoServer::printerror(int status) const
1394
1395 //*****************************************************/
1396 //* Print out cfitsio error messages and exit program */
1397 //*****************************************************/
1398{
1399
1400 // print out cfitsio error messages and exit program
1401 if( status )
1402 {
1403 // print error report
1404 fits_report_error(stderr, status);
1405 // terminate the program, returning error status
1406 exit( status );
1407 }
1408 return;
1409}
1410
1411
1412
Note: See TracBrowser for help on using the repository browser.