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

Last change on this file since 1138 was 1136, checked in by ansari, 25 years ago

structuration a la ppersist+ convention sur hdu

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