source: Sophya/trunk/SophyaExt/FitsIOServer/fitstarray.cc@ 2163

Last change on this file since 2163 was 1388, checked in by yvon, 25 years ago

Quelques cout desagreables sont commentes.
Dominique

File size: 4.0 KB
Line 
1#include "machdefs.h"
2#include "pexceptions.h"
3#include "fitstarray.h"
4///////////////////////////////////////////////////////////
5// Les objets delegues pour la gestion de persistance sur fichiers fits
6// pout TArray
7///////////////////////////////////////////////////////////
8
9/*!
10 \class SOPHYA::FITS_TArray
11 \ingroup FitsIOServer
12 FITS format I/O handler for SOPHYA::TArray objects in Sophya.
13*/
14
15using namespace SOPHYA;
16
17template <class T>
18FITS_TArray<T>::FITS_TArray()
19{
20 dobj_= NULL;
21 ownobj_=false;
22}
23
24template <class T>
25FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
26{
27 dobj_=NULL;
28 ownobj_=false;
29 Read(inputfile,hdunum);
30}
31
32template <class T>
33FITS_TArray<T>::FITS_TArray(const TArray<T> & obj)
34{
35 dobj_ = new TArray<T>(obj);
36 ownobj_=true;
37}
38
39template <class T>
40FITS_TArray<T>::FITS_TArray(TArray<T> *obj)
41{
42 dobj_ = obj;
43 ownobj_=false;
44}
45
46
47template <class T>
48FITS_TArray<T>::~FITS_TArray()
49{
50 if (ownobj_ && dobj_) delete dobj_;
51}
52
53
54template <class T>
55AnyDataObj* FITS_TArray<T>::DataObj()
56{
57 return(dobj_);
58}
59
60
61template <class T>
62void FITS_TArray<T>::SetDataObj(AnyDataObj & o)
63 {
64 TArray<T>* po = dynamic_cast< TArray<T>* >(& o);
65 if (po == NULL) return;
66 if (ownobj_ && dobj_) delete dobj_;
67 dobj_ = po;
68 ownobj_ = false;
69 }
70
71
72
73template <class T>
74void FITS_TArray<T>::ReadFromFits(FitsInFile& is)
75{
76 if (!is.IsFitsImage())
77 {
78 throw PException("ReadFromFits: the fits file seems not to be an image");
79 }
80 int dimension = is.nbDimOfImage();
81 sa_size_t * siz = new sa_size_t[dimension];
82 for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
83 if(dobj_ == NULL)
84 {
85 dobj_ = new TArray<T>(dimension,siz);
86 ownobj_ = true;
87 }
88 else
89 dobj_->ReSize(dimension,siz);
90
91 delete [] siz;
92 if (dobj_->Size() != is.nbOfImageData() )
93 {
94 cout << " total size of TArray: " << dobj_->Size() << endl;
95 cout << " total size from fits file: " << is.nbOfImageData() << endl;
96 throw PException("ReadFromFits: size conflict");
97 }
98 // On lit le tableau
99 is.GetSingleColumn( dobj_->Data(),dobj_->Size());
100 dobj_->Info() = is.DVListFromFits();
101
102}
103
104
105template <class T>
106void FITS_TArray<T>::WriteToFits(FitsOutFile& os)
107{
108 if(dobj_ == NULL) return;
109 uint_4 nbdim = dobj_->NbDimensions();
110 if ( nbdim == 0)
111 {
112 throw PException(" FITS_TARRAY: number of dimensions of the array = 0?");
113 }
114 //cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
115 int* naxisn = new int[nbdim];
116 int k;
117 for (k=0; k< nbdim; k++)
118 {
119 naxisn[k] = dobj_->Size(k);
120 // cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
121 }
122 char type;
123 if ( typeid(T) == typeid(r_8) ) type='D';
124 else
125 if ( typeid(T) == typeid(r_4) ) type='E';
126 else
127 if ( typeid(T) == typeid(int_4) ) type='I';
128 else
129 {
130 cout << " type du tableau= " << typeid(T).name() << endl;
131 throw IOExc("FITS_TArray:: unknown type");
132 }
133
134 int nbels = 1;
135 for (k=0; k< nbdim; k++)
136 {
137 if (naxisn[k] > 0) nbels *= naxisn[k];
138 }
139 // cout << " nombre total d'elements a copier " << nbels << endl;
140 DVList dvl( dobj_->Info() );
141 dvl["Content"]= "TArray";
142 dvl.SetComment("Content", "name of SOPHYA object");
143 os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl);
144 if (!dobj_->IsPacked())
145 {
146 cout << " IsPacked() = " << dobj_->IsPacked() << endl;
147 throw PException(" FITS_TARRAY: this case is not yet programmed");
148
149 }
150 if (dobj_->MinStep() != 1)
151 {
152 cout << " MinStep()) = " << dobj_->MinStep() << endl;
153 throw PException(" FITS_TARRAY: this case is not yet programmed");
154
155 }
156 os.PutImageToFits(nbels, dobj_->Data());
157
158 delete [] naxisn;
159}
160
161
162#ifdef __CXX_PRAGMA_TEMPLATES__
163#pragma define_template FITS_TArray<r_8>
164#pragma define_template FITS_TArray<r_4>
165#pragma define_template FITS_TArray<int_4>
166#endif
167#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
168template class FITS_TArray<r_8>;
169template class FITS_TArray<r_4>;
170template class FITS_TArray<int_4>;
171#endif
Note: See TracBrowser for help on using the repository browser.