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

Last change on this file since 903 was 874, checked in by ansari, 25 years ago

modif utilisation typeid

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