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

Last change on this file since 1353 was 1334, checked in by ansari, 25 years ago

modifs returns de autoreader

File size: 3.9 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 sa_size_t * siz = new sa_size_t[dimension];
76 for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
77 if(dobj_ == NULL)
78 {
79 dobj_ = new TArray<T>(dimension,siz);
80 ownobj_ = true;
81 }
82 else
83 dobj_->ReSize(dimension,siz);
84
85 delete [] siz;
86 if (dobj_->Size() != is.nbOfImageData() )
87 {
88 cout << " total size of TArray: " << dobj_->Size() << endl;
89 cout << " total size from fits file: " << is.nbOfImageData() << endl;
90 throw PException("ReadFromFits: size conflict");
91 }
92 // On lit le tableau
93 is.GetSingleColumn( dobj_->Data(),dobj_->Size());
94 dobj_->Info() = is.DVListFromFits();
95
96}
97
98
99template <class T>
100void FITS_TArray<T>::WriteToFits(FitsOutFile& os)
101{
102 if(dobj_ == NULL) return;
103 uint_4 nbdim = dobj_->NbDimensions();
104 if ( nbdim == 0)
105 {
106 throw PException(" FITS_TARRAY: number of dimensions of the array = 0?");
107 }
108 cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
109 int* naxisn = new int[nbdim];
110 int k;
111 for (k=0; k< nbdim; k++)
112 {
113 naxisn[k] = dobj_->Size(k);
114 cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
115 }
116 char type;
117 if ( typeid(T) == typeid(r_8) ) type='D';
118 else
119 if ( typeid(T) == typeid(r_4) ) type='E';
120 else
121 if ( typeid(T) == typeid(int_4) ) type='I';
122 else
123 {
124 cout << " type du tableau= " << typeid(T).name() << endl;
125 throw IOExc("FITS_TArray:: unknown type");
126 }
127
128 int nbels = 1;
129 for (k=0; k< nbdim; k++)
130 {
131 if (naxisn[k] > 0) nbels *= naxisn[k];
132 }
133 cout << " nombre total d'elements a copier " << nbels << endl;
134 DVList dvl( dobj_->Info() );
135 dvl["Content"]= "TArray";
136 dvl.SetComment("Content", "name of SOPHYA object");
137 os.makeHeaderImageOnFits(type, nbdim, naxisn, &dvl);
138 if (!dobj_->IsPacked())
139 {
140 cout << " IsPacked() = " << dobj_->IsPacked() << endl;
141 throw PException(" FITS_TARRAY: this case is not yet programmed");
142
143 }
144 if (dobj_->MinStep() != 1)
145 {
146 cout << " MinStep()) = " << dobj_->MinStep() << endl;
147 throw PException(" FITS_TARRAY: this case is not yet programmed");
148
149 }
150 os.PutImageToFits(nbels, dobj_->Data());
151
152 delete [] naxisn;
153}
154
155
156#ifdef __CXX_PRAGMA_TEMPLATES__
157#pragma define_template FITS_TArray<r_8>
158#pragma define_template FITS_TArray<r_4>
159#pragma define_template FITS_TArray<int_4>
160#endif
161#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
162template class FITS_TArray<r_8>;
163template class FITS_TArray<r_4>;
164template class FITS_TArray<int_4>;
165#endif
Note: See TracBrowser for help on using the repository browser.