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

Last change on this file since 1011 was 972, checked in by ansari, 25 years ago

mise a jour 27/04/00 GLM

File size: 3.6 KB
RevLine 
[863]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>
[972]48void FITS_TArray<T>::Write(char outputfile[], bool OldFile)
[863]49{
[972]50 WriteF(outputfile, OldFile);
[863]51}
52
53
54
55template <class T>
56AnyDataObj* FITS_TArray<T>::DataObj()
57{
58 return(dobj_);
59}
60
61template <class T>
[972]62void FITS_TArray<T>::ReadFromFits(FitsFile& fn)
[863]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>
[972]93void FITS_TArray<T>::WriteToFits(FitsFile& fn)
[863]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 }
[873]101 cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
[863]102 int* naxisn = new int[nbdim];
[923]103 int k;
104 for (k=0; k< nbdim; k++)
[863]105 {
106 naxisn[k] = dobj_->Size(k);
[873]107 cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
[863]108 }
109 char type;
[874]110 if ( typeid(T) == typeid(r_8) ) type='D';
[863]111 else
[874]112 if ( typeid(T) == typeid(r_4) ) type='E';
[863]113 else
[874]114 if ( typeid(T) == typeid(int_4) ) type='I';
[863]115 else
116 {
117 cout << " type du tableau= " << typeid(T).name() << endl;
118 throw IOExc("FITS_TArray:: unknown type");
119 }
120
121 int nbels = 1;
[923]122 for (k=0; k< nbdim; k++)
[863]123 {
124 if (naxisn[k] > 0) nbels *= naxisn[k];
125 }
126 cout << " nombre total d'elements a copier " << nbels << endl;
127 fn.makeHeaderImageOnFits(type, nbdim, naxisn);
128 if (!dobj_->IsPacked())
129 {
130 cout << " IsPacked() = " << dobj_->IsPacked() << endl;
131 throw PException(" FITS_TARRAY: this case is not yet programmed");
132
133 }
134 if (dobj_->MinStep() != 1)
135 {
136 cout << " MinStep()) = " << dobj_->MinStep() << endl;
137 throw PException(" FITS_TARRAY: this case is not yet programmed");
138
139 }
140 fn.putImageToFits(nbels, dobj_->Data());
141
142 delete [] naxisn;
143}
144
145
146#ifdef __CXX_PRAGMA_TEMPLATES__
147#pragma define_template FITS_TArray<r_8>
148#pragma define_template FITS_TArray<r_4>
149#endif
150#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
151template class FITS_TArray<r_8>;
152template class FITS_TArray<r_4>;
153#endif
Note: See TracBrowser for help on using the repository browser.