| 1 | #include <stdio.h>
 | 
|---|
| 2 | #include <string.h>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include "strutil.h"
 | 
|---|
| 5 | #include "perrors.h"
 | 
|---|
| 6 | #include "ntuple.h"
 | 
|---|
| 7 | 
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #define BADVAL -1.e19
 | 
|---|
| 10 | #define LENNAME 8
 | 
|---|
| 11 | #define LENNAME1  (LENNAME+1)
 | 
|---|
| 12 | 
 | 
|---|
| 13 | //++
 | 
|---|
| 14 | // Class        NTuple
 | 
|---|
| 15 | // Lib  Outils++ 
 | 
|---|
| 16 | // include      ntuple.h
 | 
|---|
| 17 | //
 | 
|---|
| 18 | //      Classe de ntuples
 | 
|---|
| 19 | //--
 | 
|---|
| 20 | //++
 | 
|---|
| 21 | // Links        Parents
 | 
|---|
| 22 | // PPersist
 | 
|---|
| 23 | // NTupleInterface
 | 
|---|
| 24 | //--
 | 
|---|
| 25 | 
 | 
|---|
| 26 | /* --Methode-- */
 | 
|---|
| 27 | //++
 | 
|---|
| 28 | NTuple::NTuple()
 | 
|---|
| 29 | //
 | 
|---|
| 30 | //      Createur par defaut
 | 
|---|
| 31 | //--
 | 
|---|
| 32 | {
 | 
|---|
| 33 | mNVar = mNEnt = mBlk = mNBlk = 0;
 | 
|---|
| 34 | mVar = NULL;
 | 
|---|
| 35 | mVarD = NULL;
 | 
|---|
| 36 | mNames = NULL;
 | 
|---|
| 37 | mInfo = NULL;
 | 
|---|
| 38 | }
 | 
|---|
| 39 | 
 | 
|---|
| 40 | 
 | 
|---|
| 41 | //++
 | 
|---|
| 42 | NTuple::NTuple(int nvar, char** noms, int blk)
 | 
|---|
| 43 | //
 | 
|---|
| 44 | //      Createur d'un ntuple de `nvar' variables dont les
 | 
|---|
| 45 | //      noms sont dans le tableau de cahines de caracteres `noms'
 | 
|---|
| 46 | //      avec `blk' d'evenements par blocks.
 | 
|---|
| 47 | //--
 | 
|---|
| 48 | {
 | 
|---|
| 49 | mNVar = mNEnt = mBlk = mNBlk = 0;
 | 
|---|
| 50 | mVar = NULL;
 | 
|---|
| 51 | mVarD = NULL;
 | 
|---|
| 52 | mNames = NULL;
 | 
|---|
| 53 | mInfo = NULL;
 | 
|---|
| 54 | if (nvar <= 0)  THROW(sizeMismatchErr); 
 | 
|---|
| 55 | mNVar = nvar;
 | 
|---|
| 56 | mVar = new r_4[nvar];
 | 
|---|
| 57 | mVarD = new r_8[nvar];
 | 
|---|
| 58 | if (blk < 10) blk = 10;
 | 
|---|
| 59 | mBlk = blk;
 | 
|---|
| 60 | // On prend des noms de LENNAME char pour le moment
 | 
|---|
| 61 | mNames = new char[nvar*LENNAME1];
 | 
|---|
| 62 | r_4* pt = new r_4[nvar*blk];
 | 
|---|
| 63 | mNBlk = 1;
 | 
|---|
| 64 | mPtr.push_back(pt);
 | 
|---|
| 65 | int i;
 | 
|---|
| 66 | for(i=0; i<nvar; i++)
 | 
|---|
| 67 |   { strncpy(mNames+i*LENNAME1, noms[i], LENNAME);  
 | 
|---|
| 68 |   mNames[i*LENNAME1+LENNAME] = '\0'; }
 | 
|---|
| 69 | return;
 | 
|---|
| 70 | }
 | 
|---|
| 71 | 
 | 
|---|
| 72 | //                                       cmv 8/10/99
 | 
|---|
| 73 | //++
 | 
|---|
| 74 | NTuple::NTuple(const NTuple& NT)
 | 
|---|
| 75 | //
 | 
|---|
| 76 | //      Createur par copie (clone).
 | 
|---|
| 77 | //--
 | 
|---|
| 78 | : mNVar(0), mNEnt(0), mBlk(0), mNBlk(0)
 | 
|---|
| 79 | , mVar(NULL), mVarD(NULL), mNames(NULL), mInfo(NULL)
 | 
|---|
| 80 | {
 | 
|---|
| 81 | if(NT.mNVar<=0) return; // cas ou NT est cree par defaut
 | 
|---|
| 82 | mNVar = NT.mNVar;
 | 
|---|
| 83 | mBlk = NT.mBlk;
 | 
|---|
| 84 | mVar = new r_4[NT.mNVar];
 | 
|---|
| 85 | mVarD = new r_8[NT.mNVar];
 | 
|---|
| 86 | mNames = new char[NT.mNVar*LENNAME1];
 | 
|---|
| 87 | 
 | 
|---|
| 88 | int i;
 | 
|---|
| 89 | r_4* pt = new r_4[mNVar*mBlk];
 | 
|---|
| 90 | mNBlk = 1; mPtr.push_back(pt);
 | 
|---|
| 91 | 
 | 
|---|
| 92 | for(i=0;i<mNVar;i++) strcpy(mNames+i*LENNAME1,NT.NomIndex(i)); 
 | 
|---|
| 93 | 
 | 
|---|
| 94 | if(NT.mInfo!=NULL) {mInfo = new DVList; *mInfo = *(NT.mInfo);}
 | 
|---|
| 95 | 
 | 
|---|
| 96 | if(NT.mNEnt<=0) return;
 | 
|---|
| 97 | for(i=0;i<NT.mNEnt;i++) {r_4* x=NT.GetVec(i,NULL); Fill(x);}
 | 
|---|
| 98 | 
 | 
|---|
| 99 | return;
 | 
|---|
| 100 | }
 | 
|---|
| 101 | 
 | 
|---|
| 102 | /* --Methode-- */
 | 
|---|
| 103 | //++
 | 
|---|
| 104 | NTuple::NTuple(char *flnm)
 | 
|---|
| 105 | //
 | 
|---|
| 106 | //      Createur lecture fichier ppersist.
 | 
|---|
| 107 | //--
 | 
|---|
| 108 | {
 | 
|---|
| 109 | mNVar = mNEnt = mBlk = mNBlk = 0;
 | 
|---|
| 110 | mVar = NULL;
 | 
|---|
| 111 | mVarD = NULL;
 | 
|---|
| 112 | mNames = NULL;
 | 
|---|
| 113 | mInfo = NULL;
 | 
|---|
| 114 | PInPersist s(flnm);
 | 
|---|
| 115 | ObjFileIO<NTuple> fiont(this);
 | 
|---|
| 116 | fiont.Read(s);
 | 
|---|
| 117 | }
 | 
|---|
| 118 | 
 | 
|---|
| 119 | /* --Methode-- */
 | 
|---|
| 120 | NTuple::~NTuple()
 | 
|---|
| 121 | {
 | 
|---|
| 122 | Clean();
 | 
|---|
| 123 | }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | /* --Methode-- */
 | 
|---|
| 126 | void NTuple::Clean()
 | 
|---|
| 127 | {
 | 
|---|
| 128 | if (mVar) delete[] mVar;
 | 
|---|
| 129 | if (mVarD) delete[] mVarD;
 | 
|---|
| 130 | if (mNames)  delete[] mNames;
 | 
|---|
| 131 | if (mInfo) delete mInfo;
 | 
|---|
| 132 | int i;
 | 
|---|
| 133 | if(mNBlk>0) for(i=0; i<mNBlk; i++)  delete[] mPtr[i];
 | 
|---|
| 134 | mPtr.erase(mPtr.begin(), mPtr.end());
 | 
|---|
| 135 | mNVar = mNEnt = mBlk = mNBlk = 0;
 | 
|---|
| 136 | mVar = NULL;
 | 
|---|
| 137 | mVarD = NULL;
 | 
|---|
| 138 | mNames = NULL;
 | 
|---|
| 139 | mInfo = NULL;
 | 
|---|
| 140 | return;
 | 
|---|
| 141 | }
 | 
|---|
| 142 | 
 | 
|---|
| 143 | /* --Methode--        cmv 08/10/99 */
 | 
|---|
| 144 | //++
 | 
|---|
| 145 | NTuple& NTuple::operator = (const NTuple& NT)
 | 
|---|
| 146 | //
 | 
|---|
| 147 | //      Operateur egal (clone).
 | 
|---|
| 148 | //--
 | 
|---|
| 149 | {
 | 
|---|
| 150 | if(this == &NT) return *this;
 | 
|---|
| 151 | Clean();
 | 
|---|
| 152 | if(NT.mNVar<=0) return *this; // cas ou NT est cree par defaut
 | 
|---|
| 153 | mNVar = NT.mNVar;
 | 
|---|
| 154 | mBlk = NT.mBlk;
 | 
|---|
| 155 | mVar = new r_4[NT.mNVar];
 | 
|---|
| 156 | mVarD = new r_8[NT.mNVar];
 | 
|---|
| 157 | mNames = new char[NT.mNVar*LENNAME1];
 | 
|---|
| 158 | 
 | 
|---|
| 159 | int i;
 | 
|---|
| 160 | r_4* pt = new r_4[mNVar*mBlk];
 | 
|---|
| 161 | mNBlk = 1; mPtr.push_back(pt);
 | 
|---|
| 162 | 
 | 
|---|
| 163 | for(i=0;i<mNVar;i++) strcpy(mNames+i*LENNAME1,NT.NomIndex(i)); 
 | 
|---|
| 164 | 
 | 
|---|
| 165 | if(NT.mInfo!=NULL) {mInfo = new DVList; *mInfo = *(NT.mInfo);}
 | 
|---|
| 166 | 
 | 
|---|
| 167 | if(NT.mNEnt<=0) return *this;
 | 
|---|
| 168 | for(i=0;i<NT.mNEnt;i++) {r_4* x=NT.GetVec(i,NULL); Fill(x);}
 | 
|---|
| 169 | 
 | 
|---|
| 170 | // En fait il faudrait un createur par copie qui partage les donnees
 | 
|---|
| 171 | // quand l'objet est temporaire... trop complique A FAIRE !  cmv.
 | 
|---|
| 172 | return *this;
 | 
|---|
| 173 | }
 | 
|---|
| 174 | 
 | 
|---|
| 175 | /* --Methode-- */
 | 
|---|
| 176 | //++
 | 
|---|
| 177 | void  NTuple::Fill(r_4* x)
 | 
|---|
| 178 | //
 | 
|---|
| 179 | //      Remplit le ntuple avec le tableau cd reels `x'.
 | 
|---|
| 180 | //--
 | 
|---|
| 181 | {
 | 
|---|
| 182 | int numb = mNEnt/mBlk;
 | 
|---|
| 183 | if (numb >= mNBlk) {
 | 
|---|
| 184 |   r_4* pt = new r_4[mNVar*mBlk];
 | 
|---|
| 185 |   mNBlk++;
 | 
|---|
| 186 |   mPtr.push_back(pt);
 | 
|---|
| 187 | }
 | 
|---|
| 188 | int offb = mNEnt-numb*mBlk;
 | 
|---|
| 189 | memcpy((mPtr[numb]+offb*mNVar), x, mNVar*sizeof(r_4));
 | 
|---|
| 190 | mNEnt++;
 | 
|---|
| 191 | return;
 | 
|---|
| 192 | }
 | 
|---|
| 193 | 
 | 
|---|
| 194 | 
 | 
|---|
| 195 | /* --Methode-- */
 | 
|---|
| 196 | //++
 | 
|---|
| 197 | float NTuple::GetVal(int n, int k)  const
 | 
|---|
| 198 | //
 | 
|---|
| 199 | //      Retourne la valeur de la variable `k' de l'evenement `n'.
 | 
|---|
| 200 | //--
 | 
|---|
| 201 | {
 | 
|---|
| 202 | if (n >= mNEnt)   return(BADVAL);
 | 
|---|
| 203 | if ( (k < 0) || (k >= mNVar) )    return(BADVAL);
 | 
|---|
| 204 | int numb = n/mBlk;
 | 
|---|
| 205 | int offb = n-numb*mBlk;
 | 
|---|
| 206 | return(*(mPtr[numb]+offb*mNVar+k));
 | 
|---|
| 207 | }
 | 
|---|
| 208 | 
 | 
|---|
| 209 | 
 | 
|---|
| 210 | /* --Methode-- */
 | 
|---|
| 211 | //++
 | 
|---|
| 212 | int NTuple::IndexNom(const char* nom)  const
 | 
|---|
| 213 | //
 | 
|---|
| 214 | //      Retourne le numero de la variable de nom `nom'.
 | 
|---|
| 215 | //--
 | 
|---|
| 216 | {
 | 
|---|
| 217 | int i;
 | 
|---|
| 218 | for(i=0; i<mNVar; i++)  
 | 
|---|
| 219 |   if ( strcmp(nom, mNames+i*LENNAME1) == 0)  return(i);
 | 
|---|
| 220 | return(-1);
 | 
|---|
| 221 | }
 | 
|---|
| 222 | 
 | 
|---|
| 223 | 
 | 
|---|
| 224 | static char nomretour[2*LENNAME1];
 | 
|---|
| 225 | /* --Methode-- */
 | 
|---|
| 226 | //++
 | 
|---|
| 227 | char* NTuple::NomIndex(int k)  const
 | 
|---|
| 228 | //
 | 
|---|
| 229 | //      Retourne le nom de la variable numero 'k'
 | 
|---|
| 230 | //--
 | 
|---|
| 231 | {
 | 
|---|
| 232 | nomretour[0] = '\0';
 | 
|---|
| 233 | if ((k >= 0) && (k < mNVar))  strcpy(nomretour, mNames+k*LENNAME1);
 | 
|---|
| 234 | return(nomretour);
 | 
|---|
| 235 | }
 | 
|---|
| 236 | 
 | 
|---|
| 237 |   
 | 
|---|
| 238 | /* --Methode-- */
 | 
|---|
| 239 | //++
 | 
|---|
| 240 | r_4* NTuple::GetVec(int n, r_4* ret)   const
 | 
|---|
| 241 | //
 | 
|---|
| 242 | //      Retourne l'evenement `n' dans le vecteur `ret'.
 | 
|---|
| 243 | //--
 | 
|---|
| 244 | {
 | 
|---|
| 245 | int i;
 | 
|---|
| 246 | if (ret == NULL)   ret = mVar;
 | 
|---|
| 247 | if (n >= mNEnt) {
 | 
|---|
| 248 |   for(i=0; i<mNVar; i++)   ret[i] = BADVAL;
 | 
|---|
| 249 |   return(ret);
 | 
|---|
| 250 | }
 | 
|---|
| 251 |   
 | 
|---|
| 252 | int numb = n/mBlk;
 | 
|---|
| 253 | int offb = n-numb*mBlk;
 | 
|---|
| 254 | memcpy(ret, (mPtr[numb]+offb*mNVar), mNVar*sizeof(r_4));
 | 
|---|
| 255 | return(ret);
 | 
|---|
| 256 | }
 | 
|---|
| 257 | 
 | 
|---|
| 258 | /* --Methode-- */
 | 
|---|
| 259 | //++
 | 
|---|
| 260 | r_8* NTuple::GetVecD(int n, r_8* ret)   const
 | 
|---|
| 261 | //
 | 
|---|
| 262 | //      Retourne l'evenement `n' dans le vecteur `ret'.
 | 
|---|
| 263 | //--
 | 
|---|
| 264 | {
 | 
|---|
| 265 | int i;
 | 
|---|
| 266 | if (ret == NULL)   ret = mVarD;
 | 
|---|
| 267 | float *  fr = GetVec(n);
 | 
|---|
| 268 | for(i=0; i<mNVar; i++)   ret[i] = fr[i];
 | 
|---|
| 269 | return(ret);
 | 
|---|
| 270 | }
 | 
|---|
| 271 | 
 | 
|---|
| 272 | 
 | 
|---|
| 273 | 
 | 
|---|
| 274 | /* --Methode-- */
 | 
|---|
| 275 | //++
 | 
|---|
| 276 | DVList&  NTuple::Info()
 | 
|---|
| 277 | //
 | 
|---|
| 278 | //      Renvoie une référence sur l'objet DVList Associé
 | 
|---|
| 279 | //--
 | 
|---|
| 280 | {
 | 
|---|
| 281 | if (mInfo == NULL)  mInfo = new DVList;
 | 
|---|
| 282 | return(*mInfo);
 | 
|---|
| 283 | }
 | 
|---|
| 284 | 
 | 
|---|
| 285 | /* --Methode-- */
 | 
|---|
| 286 | //++
 | 
|---|
| 287 | void  NTuple::Print(int num, int nmax)  const
 | 
|---|
| 288 | //
 | 
|---|
| 289 | //      Imprime `nmax' evenements a partir du numero `num'.
 | 
|---|
| 290 | //--
 | 
|---|
| 291 | {
 | 
|---|
| 292 | int i,j;
 | 
|---|
| 293 | 
 | 
|---|
| 294 | printf("Num     ");
 | 
|---|
| 295 | for(i=0; i<mNVar; i++)  printf("%8s ", mNames+i*LENNAME1);
 | 
|---|
| 296 | putchar('\n');
 | 
|---|
| 297 | 
 | 
|---|
| 298 | if (nmax <= 0)  nmax = 1;
 | 
|---|
| 299 | if (num < 0)  num = 0;
 | 
|---|
| 300 | nmax += num;
 | 
|---|
| 301 | if (nmax > mNEnt) nmax = mNEnt;
 | 
|---|
| 302 | for(i=num; i<nmax; i++) {
 | 
|---|
| 303 |   GetVec(i, NULL); 
 | 
|---|
| 304 |   printf("%6d  ", i);  
 | 
|---|
| 305 |   for(j=0; j<mNVar; j++)  printf("%8g ", (float)mVar[j]);
 | 
|---|
| 306 |   putchar('\n');
 | 
|---|
| 307 | }
 | 
|---|
| 308 | return;
 | 
|---|
| 309 | }
 | 
|---|
| 310 | 
 | 
|---|
| 311 | /* --Methode-- */
 | 
|---|
| 312 | //++
 | 
|---|
| 313 | void  NTuple::Show(ostream& os)  const
 | 
|---|
| 314 | //
 | 
|---|
| 315 | //      Imprime l'information generale sur le ntuple.
 | 
|---|
| 316 | //--
 | 
|---|
| 317 | {
 | 
|---|
| 318 | os << "NTuple: NVar= " << mNVar << " NEnt=" << mNEnt  
 | 
|---|
| 319 |    << " (Blk Sz,Nb= " << mBlk << " ," << mNBlk << ")\n";
 | 
|---|
| 320 | os << "            Variables       Min      Max       \n";
 | 
|---|
| 321 | int i;
 | 
|---|
| 322 | double min, max;
 | 
|---|
| 323 | char buff[128];
 | 
|---|
| 324 | for(i=0; i<mNVar; i++) {
 | 
|---|
| 325 |   GetMinMax(i, min, max);
 | 
|---|
| 326 |   sprintf(buff, "%3d  %16s  %10lg  %10lg \n", i, mNames+i*LENNAME1, min, max);
 | 
|---|
| 327 |   os << (string)buff ;
 | 
|---|
| 328 |   }
 | 
|---|
| 329 | os << endl;
 | 
|---|
| 330 | }
 | 
|---|
| 331 | 
 | 
|---|
| 332 | 
 | 
|---|
| 333 | /* --Methode-- */
 | 
|---|
| 334 | //++
 | 
|---|
| 335 | int  NTuple::FillFromASCIIFile(string const& fn, float defval)
 | 
|---|
| 336 | //
 | 
|---|
| 337 | //      Remplit le ntuple a partir d'un fichier ASCII.
 | 
|---|
| 338 | //      Renvoie le nombre de lignes ajoutees.
 | 
|---|
| 339 | //--
 | 
|---|
| 340 | {
 | 
|---|
| 341 | if (NbColumns() < 1)  { 
 | 
|---|
| 342 |   cout << "NTuple::FillFromASCIIFile() Ntuple has " << NbColumns() << " columns" << endl;
 | 
|---|
| 343 |   return(-1);
 | 
|---|
| 344 |   }
 | 
|---|
| 345 | FILE * fip = fopen(fn.c_str(), "r");
 | 
|---|
| 346 | if (fip == NULL) {
 | 
|---|
| 347 |   cout << "NTuple::FillFromASCIIFile() Error opening file " << fn << endl;
 | 
|---|
| 348 |   return(-2);
 | 
|---|
| 349 |   }
 | 
|---|
| 350 | 
 | 
|---|
| 351 | char lineb[4096];
 | 
|---|
| 352 | char *line;
 | 
|---|
| 353 | char buff[64];
 | 
|---|
| 354 | char* ccp;
 | 
|---|
| 355 | int i,j,l,kk;
 | 
|---|
| 356 | int postab, posb;
 | 
|---|
| 357 | float* xv = new float[NbColumns()];
 | 
|---|
| 358 | 
 | 
|---|
| 359 | int nlread = 0;
 | 
|---|
| 360 | int nvar = NbColumns();
 | 
|---|
| 361 | // On boucle sur toutes les lignes
 | 
|---|
| 362 | while (fgets(lineb,4096,fip) != NULL) {
 | 
|---|
| 363 |   lineb[4095] = '\0';
 | 
|---|
| 364 |   j = 0; line = lineb;
 | 
|---|
| 365 | //  On enleve les espaces et tab de debut 
 | 
|---|
| 366 |   while ( (line[j] != '\0') && ((line[j] == ' ') || (line[j] == '\t')) )  j++;
 | 
|---|
| 367 |   line = lineb+j; 
 | 
|---|
| 368 | // Il faut que le premier caractere non-espace soit un digit, ou + ou - ou .
 | 
|---|
| 369 |   if (!( isdigit(line[0]) || (line[0] == '+') || (line[0] == '-') || (line[0] == '.') ))  continue;
 | 
|---|
| 370 |   ccp = line;
 | 
|---|
| 371 |   for(kk=0; kk<nvar; kk++)  xv[kk] = defval;
 | 
|---|
| 372 |   for(kk=0; kk<nvar; kk++) {
 | 
|---|
| 373 | // Les mots sont separes par des espaces ou des tab
 | 
|---|
| 374 |     postab = posc(ccp, '\t' );
 | 
|---|
| 375 |     posb = posc(ccp, ' ' );
 | 
|---|
| 376 |     if (postab >= 0) { 
 | 
|---|
| 377 |        if (posb < 0) posb = postab;
 | 
|---|
| 378 |        else if (postab < posb)  posb = postab; 
 | 
|---|
| 379 |        } 
 | 
|---|
| 380 |     if (posb >= 0)  ccp[posb] = '\0';
 | 
|---|
| 381 |     if ( isdigit(line[0]) || (line[0] == '+') || (line[0] == '-') || (line[0] == '.') ) 
 | 
|---|
| 382 |       xv[kk] = atof(ccp);
 | 
|---|
| 383 |     if (posb < 0)  break;
 | 
|---|
| 384 |     ccp += posb+1;   j = 0;
 | 
|---|
| 385 |     while ( (ccp[j] != '\0') && ((ccp[j] == ' ') || (ccp[j] == '\t')) )  j++;
 | 
|---|
| 386 |     ccp += j;
 | 
|---|
| 387 |     }
 | 
|---|
| 388 |   Fill(xv);
 | 
|---|
| 389 |   nlread++;
 | 
|---|
| 390 |   }
 | 
|---|
| 391 | 
 | 
|---|
| 392 | delete[] xv;
 | 
|---|
| 393 | cout << "NTuple::FillFromASCIIFile( " << fn << ") " << nlread << " fill from file " << endl;
 | 
|---|
| 394 | return(nlread);
 | 
|---|
| 395 | }
 | 
|---|
| 396 | 
 | 
|---|
| 397 | 
 | 
|---|
| 398 | // ------- Implementation de  l interface NTuple  ---------
 | 
|---|
| 399 | 
 | 
|---|
| 400 | /* --Methode-- */
 | 
|---|
| 401 | uint_4 NTuple::NbLines() const
 | 
|---|
| 402 | {
 | 
|---|
| 403 | return(NEntry());
 | 
|---|
| 404 | }
 | 
|---|
| 405 | /* --Methode-- */
 | 
|---|
| 406 | uint_4 NTuple::NbColumns() const
 | 
|---|
| 407 | {
 | 
|---|
| 408 | return(NVar());
 | 
|---|
| 409 | }
 | 
|---|
| 410 | 
 | 
|---|
| 411 | /* --Methode-- */
 | 
|---|
| 412 | r_8 * NTuple::GetLineD(int n) const
 | 
|---|
| 413 | {
 | 
|---|
| 414 | return(GetVecD(n));
 | 
|---|
| 415 | }
 | 
|---|
| 416 | 
 | 
|---|
| 417 | /* --Methode-- */
 | 
|---|
| 418 | r_8 NTuple::GetCell(int n, int k) const
 | 
|---|
| 419 | {
 | 
|---|
| 420 | return(GetVal(n, k));
 | 
|---|
| 421 | }
 | 
|---|
| 422 | 
 | 
|---|
| 423 | /* --Methode-- */
 | 
|---|
| 424 | r_8 NTuple::GetCell(int n, string const & nom) const
 | 
|---|
| 425 | {
 | 
|---|
| 426 | return(GetVal(n, nom.c_str()));
 | 
|---|
| 427 | }
 | 
|---|
| 428 | 
 | 
|---|
| 429 | /* --Methode-- */
 | 
|---|
| 430 | //++
 | 
|---|
| 431 | void  NTuple::GetMinMax(int k, double& min, double& max)  const
 | 
|---|
| 432 | //
 | 
|---|
| 433 | //      Retourne le minimum et le maximum de la variable `k'.
 | 
|---|
| 434 | //--
 | 
|---|
| 435 | {
 | 
|---|
| 436 | min = 9.e19; max = -9.e19;
 | 
|---|
| 437 | if ( (k < 0) || (k >= mNVar) )    return;
 | 
|---|
| 438 | int jb,ib,i;
 | 
|---|
| 439 | double x;
 | 
|---|
| 440 | i=0;
 | 
|---|
| 441 | for(jb=0; jb< mNBlk; jb++)
 | 
|---|
| 442 |   for(ib=0; ib< mBlk; ib++) {
 | 
|---|
| 443 |     if (i >= mNEnt)  break;
 | 
|---|
| 444 |     i++;
 | 
|---|
| 445 |     x = *(mPtr[jb]+ib*mNVar+k);
 | 
|---|
| 446 |     if(i==1) {min = x; max = x;}
 | 
|---|
| 447 |     if (x < min)  min = x;
 | 
|---|
| 448 |     if (x > max)  max = x;
 | 
|---|
| 449 |   }
 | 
|---|
| 450 | return;
 | 
|---|
| 451 | }
 | 
|---|
| 452 | 
 | 
|---|
| 453 | /* --Methode-- */
 | 
|---|
| 454 | void NTuple::GetMinMax(string const & nom, double& min, double& max)   const
 | 
|---|
| 455 | {
 | 
|---|
| 456 | GetMinMax(IndexNom(nom.c_str()), min, max);
 | 
|---|
| 457 | }
 | 
|---|
| 458 | 
 | 
|---|
| 459 | /* --Methode-- */
 | 
|---|
| 460 | int NTuple::ColumnIndex(string const & nom)  const
 | 
|---|
| 461 | {
 | 
|---|
| 462 | return(IndexNom(nom.c_str()));
 | 
|---|
| 463 | }
 | 
|---|
| 464 | 
 | 
|---|
| 465 | /* --Methode-- */
 | 
|---|
| 466 | string NTuple::ColumnName(int k) const
 | 
|---|
| 467 | {
 | 
|---|
| 468 | return(NomIndex(k));
 | 
|---|
| 469 | }
 | 
|---|
| 470 | 
 | 
|---|
| 471 | /* --Methode-- */
 | 
|---|
| 472 | //++
 | 
|---|
| 473 | string NTuple::VarList_C(const char* nomx)  const
 | 
|---|
| 474 | //
 | 
|---|
| 475 | //      Retourne une chaine de caracteres avec la declaration des noms de 
 | 
|---|
| 476 | //      variables. si "nomx!=NULL" , des instructions d'affectation
 | 
|---|
| 477 | //      a partir d'un tableau "nomx[i]" sont ajoutees. 
 | 
|---|
| 478 | //--
 | 
|---|
| 479 | {
 | 
|---|
| 480 | string rets="";
 | 
|---|
| 481 | int i;
 | 
|---|
| 482 | for(i=0; i<mNVar; i++) {
 | 
|---|
| 483 |   if ( (i%5 == 0) && (i > 0) )  rets += ";";  
 | 
|---|
| 484 |   if (i%5 == 0)   rets += "\ndouble "; 
 | 
|---|
| 485 |   else rets += ",";
 | 
|---|
| 486 |   rets += mNames+i*LENNAME1;
 | 
|---|
| 487 |   }
 | 
|---|
| 488 | rets += "; \n";
 | 
|---|
| 489 | if (nomx) { 
 | 
|---|
| 490 |   char buff[256];
 | 
|---|
| 491 |   for(i=0; i<mNVar; i++) {
 | 
|---|
| 492 |     sprintf(buff,"%s=%s[%d]; ",  mNames+i*LENNAME1, nomx, i);
 | 
|---|
| 493 |     rets += buff;
 | 
|---|
| 494 |     if ( (i%3 == 0) && (i > 0) )  rets += "\n"; 
 | 
|---|
| 495 |     }
 | 
|---|
| 496 |   }
 | 
|---|
| 497 | 
 | 
|---|
| 498 | return(rets);
 | 
|---|
| 499 | }
 | 
|---|
| 500 | 
 | 
|---|
| 501 | 
 | 
|---|
| 502 | /* --Methode-- */
 | 
|---|
| 503 | //++
 | 
|---|
| 504 | string NTuple::LineHeaderToString() const 
 | 
|---|
| 505 | //      Retourne une chaine de caracteres avec la liste des noms de  
 | 
|---|
| 506 | //      variables, utilisables pour une impression
 | 
|---|
| 507 | //--
 | 
|---|
| 508 | {
 | 
|---|
| 509 | char buff[32];
 | 
|---|
| 510 | string rets=" Num    ";
 | 
|---|
| 511 | for(int i=0; i<mNVar; i++) {
 | 
|---|
| 512 |   sprintf(buff, "%8s ", mNames+i*LENNAME1);
 | 
|---|
| 513 |   rets += buff;
 | 
|---|
| 514 |   }
 | 
|---|
| 515 | rets += '\n';
 | 
|---|
| 516 | return(rets);
 | 
|---|
| 517 | }
 | 
|---|
| 518 | 
 | 
|---|
| 519 | /* --Methode-- */
 | 
|---|
| 520 | //++
 | 
|---|
| 521 | string NTuple::LineToString(int n) const
 | 
|---|
| 522 | //      Retourne une chaine de caracteres avec le contenu de la ligne "n"
 | 
|---|
| 523 | //      utilisable pour une impression
 | 
|---|
| 524 | //--
 | 
|---|
| 525 | {
 | 
|---|
| 526 | char buff[32];
 | 
|---|
| 527 | double* val;
 | 
|---|
| 528 | val = GetLineD(n);
 | 
|---|
| 529 | sprintf(buff,"%6d: ",n);  
 | 
|---|
| 530 | string rets=buff;
 | 
|---|
| 531 | int i;
 | 
|---|
| 532 | for(i=0; i<mNVar; i++) {
 | 
|---|
| 533 |   sprintf(buff, "%8.3g ", val[i]);
 | 
|---|
| 534 |   rets += buff;
 | 
|---|
| 535 |   }
 | 
|---|
| 536 | rets += '\n';
 | 
|---|
| 537 | return(rets);
 | 
|---|
| 538 | }
 | 
|---|
| 539 | 
 | 
|---|
| 540 | 
 | 
|---|
| 541 | /* --Methode-- */
 | 
|---|
| 542 | //++
 | 
|---|
| 543 | void   ObjFileIO<NTuple>::WriteSelf(POutPersist& s)  const
 | 
|---|
| 544 | //
 | 
|---|
| 545 | //      Ecriture ppersist du ntuple.
 | 
|---|
| 546 | //--
 | 
|---|
| 547 | {
 | 
|---|
| 548 | char strg[256];
 | 
|---|
| 549 | if (dobj->mInfo)  sprintf(strg, "NVar=%6d  NEnt=%9d  BlkSz=%6d NBlk=%6d  HasInfo", 
 | 
|---|
| 550 |                           (int)dobj->mNVar, (int)dobj->mNEnt, (int)dobj->mBlk, (int)dobj->mNBlk);
 | 
|---|
| 551 | else sprintf(strg, "NVar=%6d  NEnt=%9d  BlkSz=%6d NBlk=%6d ", 
 | 
|---|
| 552 |                    (int)dobj->mNVar, (int)dobj->mNEnt, (int)dobj->mBlk, (int)dobj->mNBlk);
 | 
|---|
| 553 | s.PutLine(strg);
 | 
|---|
| 554 | s.PutI4(dobj->mNVar);
 | 
|---|
| 555 | s.PutBytes(dobj->mNames, dobj->mNVar*LENNAME1);
 | 
|---|
| 556 | s.PutI4(dobj->mNEnt);
 | 
|---|
| 557 | s.PutI4(dobj->mBlk);
 | 
|---|
| 558 | s.PutI4(dobj->mNBlk);
 | 
|---|
| 559 | if (dobj->mInfo)  s << (*(dobj->mInfo));
 | 
|---|
| 560 | int jb;
 | 
|---|
| 561 | for(jb=0; jb<dobj->mNBlk; jb++)
 | 
|---|
| 562 |   s.PutR4s(dobj->mPtr[jb], dobj->mNVar*dobj->mBlk); 
 | 
|---|
| 563 | return;
 | 
|---|
| 564 | }
 | 
|---|
| 565 | 
 | 
|---|
| 566 | /* --Methode-- */
 | 
|---|
| 567 | //++
 | 
|---|
| 568 | void  ObjFileIO<NTuple>::ReadSelf(PInPersist& s)
 | 
|---|
| 569 | //
 | 
|---|
| 570 | //      Lecture ppersist du ntuple.
 | 
|---|
| 571 | //--
 | 
|---|
| 572 | {
 | 
|---|
| 573 | 
 | 
|---|
| 574 | dobj->Clean();
 | 
|---|
| 575 | 
 | 
|---|
| 576 | char strg[256];
 | 
|---|
| 577 | s.GetLine(strg, 255);
 | 
|---|
| 578 | // Pour savoir s'il y avait un DVList Info associe
 | 
|---|
| 579 | bool hadinfo = false;
 | 
|---|
| 580 | if (strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0)  hadinfo = true;
 | 
|---|
| 581 | 
 | 
|---|
| 582 | s.GetI4(dobj->mNVar);
 | 
|---|
| 583 | dobj->mNames = new char[dobj->mNVar*LENNAME1];
 | 
|---|
| 584 | dobj->mVar = new r_4[dobj->mNVar];
 | 
|---|
| 585 | dobj->mVarD = new r_8[dobj->mNVar];
 | 
|---|
| 586 | s.GetBytes(dobj->mNames, dobj->mNVar*LENNAME1);
 | 
|---|
| 587 | s.GetI4(dobj->mNEnt);
 | 
|---|
| 588 | s.GetI4(dobj->mBlk);
 | 
|---|
| 589 | s.GetI4(dobj->mNBlk);
 | 
|---|
| 590 | 
 | 
|---|
| 591 | if (hadinfo) {    // Lecture eventuelle du DVList Info
 | 
|---|
| 592 |   if (dobj->mInfo == NULL)  dobj->mInfo = new DVList;
 | 
|---|
| 593 |   s >> (*(dobj->mInfo));
 | 
|---|
| 594 |   }
 | 
|---|
| 595 | 
 | 
|---|
| 596 | int jb; 
 | 
|---|
| 597 | for(jb=0; jb<dobj->mNBlk; jb++) {
 | 
|---|
| 598 |   r_4* pt = new r_4[dobj->mNVar*dobj->mBlk];
 | 
|---|
| 599 |   dobj->mPtr.push_back(pt);
 | 
|---|
| 600 |   s.GetR4s(dobj->mPtr[jb], dobj->mNVar*dobj->mBlk); 
 | 
|---|
| 601 | }
 | 
|---|
| 602 | 
 | 
|---|
| 603 | }
 | 
|---|
| 604 | 
 | 
|---|
| 605 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 606 | #pragma define_template ObjFileIO<NTuple>
 | 
|---|
| 607 | #endif
 | 
|---|
| 608 | 
 | 
|---|
| 609 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| 610 | template class ObjFileIO<NTuple>;
 | 
|---|
| 611 | #endif
 | 
|---|