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
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>
[1047]62void FITS_TArray<T>::ReadFromFits()
[863]63{
64
[1047]65 // if (!fn.IsFitsImage())
66 if (!IsFitsImage())
[863]67 {
68 throw PException("ReadFromFits: the fits file seems not to be an image");
69 }
[1047]70 // int dimension = fn.nbDimOfImage();
71 int dimension = nbDimOfImage();
[863]72 cout << " dimension de l'image a lire: " << dimension << endl;
73
74 uint_4* siz = new uint_4[dimension];
[1047]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];
[863]77 if(dobj_ == NULL)
78 dobj_ = new TArray<T>(dimension,siz);
79 else
80 dobj_->ReSize(dimension,siz);
81
82 delete [] siz;
[1047]83 // if (dobj_->Size() != fn.nbOfImageData() )
84 if (dobj_->Size() != nbOfImageData() )
[863]85 {
86 cout << " total size of TArray: " << dobj_->Size() << endl;
[1047]87 cout << " total size from fits file: " << nbOfImageData() << endl;
[863]88 throw PException("ReadFromFits: size conflict");
89 }
90 // On lit le tableau
[1047]91 // fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
92 GetSingleColumn( dobj_->Data(),dobj_->Size());
[863]93
94}
95
96
97 template <class T>
[1047]98void FITS_TArray<T>::WriteToFits()
[863]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 }
[873]106 cout << "FITS_TARRAY: nombre de dimension du tableau a ecrire: " << nbdim << endl;
[863]107 int* naxisn = new int[nbdim];
[923]108 int k;
109 for (k=0; k< nbdim; k++)
[863]110 {
111 naxisn[k] = dobj_->Size(k);
[873]112 cout << " nombre de donnees dans la la dimension " << k << " : " << naxisn[k] << endl;
[863]113 }
114 char type;
[874]115 if ( typeid(T) == typeid(r_8) ) type='D';
[863]116 else
[874]117 if ( typeid(T) == typeid(r_4) ) type='E';
[863]118 else
[874]119 if ( typeid(T) == typeid(int_4) ) type='I';
[863]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;
[923]127 for (k=0; k< nbdim; k++)
[863]128 {
129 if (naxisn[k] > 0) nbels *= naxisn[k];
130 }
131 cout << " nombre total d'elements a copier " << nbels << endl;
[1047]132 // fn.makeHeaderImageOnFits(type, nbdim, naxisn);
133 makeHeaderImageOnFits(type, nbdim, naxisn);
[863]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 }
[1047]146 // fn.putImageToFits(nbels, dobj_->Data());
147 putImageToFits(nbels, dobj_->Data());
[863]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.