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

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

modifs pour introduction lecteur de fits par lignes

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