1 | // $Id: tvector.cc,v 1.4 1999-05-19 10:17:42 ansari Exp $
|
---|
2 | // C.Magneville 04/99
|
---|
3 | #include "machdefs.h"
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <iostream.h>
|
---|
7 | #include <complex>
|
---|
8 | #include "pexceptions.h"
|
---|
9 | #include "tvector.h"
|
---|
10 | #include "objfio.h"
|
---|
11 |
|
---|
12 | using namespace PlanckDPC;
|
---|
13 |
|
---|
14 | template <class T>
|
---|
15 | TVector<T>::TVector(uint_4 n)
|
---|
16 | // Constructeur d'un vecteur de "n" elements
|
---|
17 | : TMatrix<T>(n,1)
|
---|
18 | {
|
---|
19 | }
|
---|
20 |
|
---|
21 | template <class T>
|
---|
22 | TVector<T>::TVector(uint_4 n, T* values,Bridge* br)
|
---|
23 | // Construit un vecteur de n elements. On fournit
|
---|
24 | // le tableau des valeurs et eventuellement un Bridge.
|
---|
25 | : TMatrix<T>(n,1,values,br)
|
---|
26 | {
|
---|
27 | }
|
---|
28 |
|
---|
29 | template <class T>
|
---|
30 | TVector<T>::TVector(const TVector<T>& v)
|
---|
31 | // Constructeur par copie (partage si "v" temporaire).
|
---|
32 | : TMatrix<T>(v)
|
---|
33 | {
|
---|
34 | }
|
---|
35 |
|
---|
36 | template <class T>
|
---|
37 | TVector<T>::TVector(const TVector<T>& v,bool share)
|
---|
38 | // Constructeur par copie avec possibilite de forcer le partage ou non.
|
---|
39 | : TMatrix<T>(v,share)
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | template <class T>
|
---|
44 | TVector<T>::TVector(const TMatrix<T>& a)
|
---|
45 | // Constructeur a partir d'une matrice "a" de dimension (n,1)
|
---|
46 | : TMatrix<T>(a)
|
---|
47 | {
|
---|
48 | if(a.NCols() != 1)
|
---|
49 | throw(SzMismatchError("TVector(const TMatrix<T>& a) size mismatch, ncol!=1"));
|
---|
50 | }
|
---|
51 |
|
---|
52 | #include "generalfit.h"
|
---|
53 | //////////////////////////////////////////////////////////
|
---|
54 | //**** Residus des fits
|
---|
55 | TVector<r_8> TVector<r_8>::FitResidus(GeneralFit& gfit,double xorg,double dx)
|
---|
56 | // Retourne une classe contenant les residus du fit ``gfit''.
|
---|
57 | // La coordonnee de l'element (i) est -> x = xorg + i*dx
|
---|
58 | {
|
---|
59 | if(NElts()<=0)
|
---|
60 | throw(SzMismatchError("TVector::FitResidus size mismatch\n"));
|
---|
61 | GeneralFunction* f = gfit.GetFunction();
|
---|
62 | if(f==NULL)
|
---|
63 | throw(NullPtrError("TVector::FitResidus GeneraFit==NULL\n"));
|
---|
64 | int npar = gfit.GetNPar();
|
---|
65 | if(npar==0)
|
---|
66 | throw(SzMismatchError("TVector::FitResidus GeneraFit 0 parametre\n"));
|
---|
67 | double* par = new double[npar];
|
---|
68 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
69 | TVector<r_8> v(*this);
|
---|
70 | for(uint_4 i=0;i<NElts();i++) {
|
---|
71 | double x = xorg+i*dx;
|
---|
72 | v(i) -= f->Value(&x,par);
|
---|
73 | }
|
---|
74 | delete [] par;
|
---|
75 | return v;
|
---|
76 | }
|
---|
77 |
|
---|
78 | TVector<r_8> TVector<r_8>::FitFunction(GeneralFit& gfit,double xorg,double dx)
|
---|
79 | // Retourne une classe contenant la fonction du fit ``gfit''.
|
---|
80 | // La coordonnee de l'element (i) est -> x = xorg + i*dx
|
---|
81 | {
|
---|
82 | if(NElts()<=0)
|
---|
83 | throw(SzMismatchError("TVector::FitFunction size mismatch\n"));
|
---|
84 | GeneralFunction* f = gfit.GetFunction();
|
---|
85 | if(f==NULL)
|
---|
86 | throw(NullPtrError("TVector::FitFunction GeneraFit==NULL\n"));
|
---|
87 | int npar = gfit.GetNPar();
|
---|
88 | if(npar==0)
|
---|
89 | throw(SzMismatchError("TVector::FitFunction GeneraFit 0 parametre\n"));
|
---|
90 | double* par = new double[npar];
|
---|
91 | {for(int i=0;i<npar;i++) par[i] = gfit.GetParm(i);}
|
---|
92 | TVector<r_8> v(*this);
|
---|
93 | for(uint_4 i=0;i<NElts();i++) {
|
---|
94 | double x = xorg+i*dx;
|
---|
95 | v(i) = f->Value(&x,par);
|
---|
96 | }
|
---|
97 | delete [] par;
|
---|
98 | return v;
|
---|
99 | }
|
---|
100 |
|
---|
101 | ///////////////////////////////////////////////////////////
|
---|
102 | // --------------------------------------------------------
|
---|
103 | // Les objets delegues pour la gestion de persistance
|
---|
104 | // --------------------------------------------------------
|
---|
105 | ///////////////////////////////////////////////////////////
|
---|
106 |
|
---|
107 | template <class T>
|
---|
108 | FIO_TVector<T>::FIO_TVector()
|
---|
109 | {
|
---|
110 | dobj=new TVector<T>;
|
---|
111 | ownobj=true;
|
---|
112 | }
|
---|
113 |
|
---|
114 | template <class T>
|
---|
115 | FIO_TVector<T>::FIO_TVector(string const & filename)
|
---|
116 | {
|
---|
117 | dobj=new TVector<T>;
|
---|
118 | ownobj=true;
|
---|
119 | Read(filename);
|
---|
120 | }
|
---|
121 |
|
---|
122 | template <class T>
|
---|
123 | FIO_TVector<T>::FIO_TVector(const TVector<T> & obj)
|
---|
124 | {
|
---|
125 | dobj = new TVector<T>(obj);
|
---|
126 | ownobj=true;
|
---|
127 | }
|
---|
128 |
|
---|
129 | template <class T>
|
---|
130 | FIO_TVector<T>::FIO_TVector(TVector<T> * obj)
|
---|
131 | {
|
---|
132 | dobj = obj;
|
---|
133 | ownobj=false;
|
---|
134 | }
|
---|
135 |
|
---|
136 | template <class T>
|
---|
137 | FIO_TVector<T>::~FIO_TVector()
|
---|
138 | {
|
---|
139 | if (ownobj && dobj) delete dobj;
|
---|
140 | }
|
---|
141 |
|
---|
142 | template <class T>
|
---|
143 | AnyDataObj* FIO_TVector<T>::DataObj()
|
---|
144 | {
|
---|
145 | return(dobj);
|
---|
146 | }
|
---|
147 |
|
---|
148 | template <class T>
|
---|
149 | void FIO_TVector<T>::ReadSelf(PInPersist& is)
|
---|
150 | {
|
---|
151 | // On lit les 3 premiers uint_4
|
---|
152 | // 0: Numero de version, 1 : NRows=NElts, 2 : NCol=1
|
---|
153 | uint_4 itab[3];
|
---|
154 | is.Get(itab,3);
|
---|
155 | if (dobj == NULL) dobj = new TVector<T>(itab[1]);
|
---|
156 | else dobj->ReSize(itab[1]);
|
---|
157 | // On lit le NDataBlock
|
---|
158 | FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
|
---|
159 | fio_nd.Read(is);
|
---|
160 | }
|
---|
161 |
|
---|
162 | template <class T>
|
---|
163 | void FIO_TVector<T>::WriteSelf(POutPersist& os) const
|
---|
164 | {
|
---|
165 | if (dobj == NULL) return;
|
---|
166 | // On ecrit 3 uint_4 ....
|
---|
167 | // 0: Numero de version, 1 : NRows=NElts, 2 : NCol=1
|
---|
168 | uint_4 itab[3];
|
---|
169 | itab[0] = 1; // Numero de version a 1
|
---|
170 | itab[1] = dobj->NElts();
|
---|
171 | itab[2] = 1;
|
---|
172 | os.Put(itab,3);
|
---|
173 | // On ecrit le NDataBlock
|
---|
174 | FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
|
---|
175 | fio_nd.Write(os);
|
---|
176 | }
|
---|
177 |
|
---|
178 | ///////////////////////////////////////////////////////////////
|
---|
179 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
180 | #pragma define_template TVector<uint_1>
|
---|
181 | #pragma define_template TVector<uint_2>
|
---|
182 | #pragma define_template TVector<int_2>
|
---|
183 | #pragma define_template TVector<int_4>
|
---|
184 | #pragma define_template TVector<int_8>
|
---|
185 | #pragma define_template TVector<uint_4>
|
---|
186 | #pragma define_template TVector<uint_8>
|
---|
187 | #pragma define_template TVector<r_4>
|
---|
188 | #pragma define_template TVector<r_8>
|
---|
189 | #pragma define_template TVector< complex<float> >
|
---|
190 | #pragma define_template TVector< complex<double> >
|
---|
191 | // Instances des delegues FileIO (PPersist)
|
---|
192 | #pragma define_template FIO_TVector<uint_1>
|
---|
193 | #pragma define_template FIO_TVector<uint_2>
|
---|
194 | #pragma define_template FIO_TVector<int_2>
|
---|
195 | #pragma define_template FIO_TVector<int_4>
|
---|
196 | #pragma define_template FIO_TVector<int_8>
|
---|
197 | #pragma define_template FIO_TVector<uint_4>
|
---|
198 | #pragma define_template FIO_TVector<uint_8>
|
---|
199 | #pragma define_template FIO_TVector<r_8>
|
---|
200 | #pragma define_template FIO_TVector<r_4>
|
---|
201 | #pragma define_template FIO_TVector< complex<float> >
|
---|
202 | #pragma define_template FIO_TVector< complex<double> >
|
---|
203 | #endif
|
---|
204 |
|
---|
205 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
206 | template class TVector<uint_1>;
|
---|
207 | template class TVector<uint_2>;
|
---|
208 | template class TVector<int_2>;
|
---|
209 | template class TVector<int_4>;
|
---|
210 | template class TVector<int_8>;
|
---|
211 | template class TVector<uint_4>;
|
---|
212 | template class TVector<uint_8>;
|
---|
213 | template class TVector<r_4>;
|
---|
214 | template class TVector<r_8>;
|
---|
215 | template class TVector< complex<float> >;
|
---|
216 | template class TVector< complex<double> >;
|
---|
217 | // Instances des delegues FileIO (PPersist)
|
---|
218 | template class FIO_TVector<uint_1>;
|
---|
219 | template class FIO_TVector<uint_2>;
|
---|
220 | template class FIO_TVector<int_2>;
|
---|
221 | template class FIO_TVector<int_4>;
|
---|
222 | template class FIO_TVector<int_8>;
|
---|
223 | template class FIO_TVector<uint_4>;
|
---|
224 | template class FIO_TVector<uint_8>;
|
---|
225 | template class FIO_TVector<r_8>;
|
---|
226 | template class FIO_TVector<r_4>;
|
---|
227 | template class FIO_TVector< complex<float> >;
|
---|
228 | template class FIO_TVector< complex<double> >;
|
---|
229 | #endif
|
---|