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