| 1 |
/* |
| 2 |
* Methods of class Mtbl |
| 3 |
* |
| 4 |
* (see file mtbl.h for documentation) |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright (c) 1999-2000 Jean-Alain Marck |
| 10 |
* Copyright (c) 1999-2001 Eric Gourgoulhon |
| 11 |
* |
| 12 |
* This file is part of LORENE. |
| 13 |
* |
| 14 |
* LORENE is free software; you can redistribute it and/or modify |
| 15 |
* it under the terms of the GNU General Public License as published by |
| 16 |
* the Free Software Foundation; either version 2 of the License, or |
| 17 |
* (at your option) any later version. |
| 18 |
* |
| 19 |
* LORENE is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with LORENE; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 |
* |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
char mtbl_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mtbl/mtbl.C,v 1.9 2014/10/13 08:53:08 j_novak Exp $" ; |
| 32 |
|
| 33 |
/* |
| 34 |
* $Id: mtbl.C,v 1.9 2014/10/13 08:53:08 j_novak Exp $ |
| 35 |
* $Log: mtbl.C,v $ |
| 36 |
* Revision 1.9 2014/10/13 08:53:08 j_novak |
| 37 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 38 |
* |
| 39 |
* Revision 1.8 2014/10/06 15:13:15 j_novak |
| 40 |
* Modified #include directives to use c++ syntax. |
| 41 |
* |
| 42 |
* Revision 1.7 2008/08/19 06:42:00 j_novak |
| 43 |
* Minor modifications to avoid warnings with gcc 4.3. Most of them concern |
| 44 |
* cast-type operations, and constant strings that must be defined as const char* |
| 45 |
* |
| 46 |
* Revision 1.6 2008/02/18 13:53:40 j_novak |
| 47 |
* Removal of special indentation instructions. |
| 48 |
* |
| 49 |
* Revision 1.5 2002/10/16 14:36:43 j_novak |
| 50 |
* Reorganization of #include instructions of standard C++, in order to |
| 51 |
* use experimental version 3 of gcc. |
| 52 |
* |
| 53 |
* Revision 1.4 2002/09/06 15:37:46 e_gourgoulhon |
| 54 |
* Performed a forgotten replacement |
| 55 |
* t = new (Tbl *[nzone]) --> t = new Tbl*[nzone] |
| 56 |
* to ensure compatibility with the xlC_r compiler on IBM Regatta |
| 57 |
* |
| 58 |
* Revision 1.3 2002/05/07 07:36:03 e_gourgoulhon |
| 59 |
* Compatibilty with xlC compiler on IBM SP2: |
| 60 |
* suppressed the parentheses around argument of instruction new: |
| 61 |
* e.g. t = new (Tbl *[nzone]) --> t = new Tbl*[nzone] |
| 62 |
* |
| 63 |
* Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon |
| 64 |
* |
| 65 |
* All writing/reading to a binary file are now performed according to |
| 66 |
* the big endian convention, whatever the system is big endian or |
| 67 |
* small endian, thanks to the functions fwrite_be and fread_be |
| 68 |
* |
| 69 |
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon |
| 70 |
* LORENE |
| 71 |
* |
| 72 |
* Revision 2.10 2000/08/16 10:30:04 eric |
| 73 |
* Suppression du membre dzpuis. |
| 74 |
* |
| 75 |
* Revision 2.9 1999/11/23 13:33:04 eric |
| 76 |
* Le constructeur Tbl::Tbl(const Grille3d* ) est devenu Tbl::Tbl(const Grille3d& ). |
| 77 |
* |
| 78 |
* Revision 2.8 1999/10/29 15:06:24 eric |
| 79 |
* Suppression des fonctions membres min() et max(): |
| 80 |
* elles deviennent des fonctions externes. |
| 81 |
* |
| 82 |
* Revision 2.7 1999/10/18 15:16:05 eric |
| 83 |
* *** empty log message *** |
| 84 |
* |
| 85 |
* Revision 2.6 1999/10/18 15:08:22 eric |
| 86 |
* La fonction membre annule() est rebaptisee annule_hard(). |
| 87 |
* Introduction de la fonction membre annule(int, int). |
| 88 |
* |
| 89 |
* Revision 2.5 1999/10/01 12:35:54 eric |
| 90 |
* Ajout de la fonction affiche_seuil. |
| 91 |
* |
| 92 |
* Revision 2.4 1999/10/01 10:08:41 eric |
| 93 |
* Depoussierage. |
| 94 |
* Documentation. |
| 95 |
* |
| 96 |
* Revision 2.3 1999/03/02 16:26:26 eric |
| 97 |
* Modif des indentations dans << |
| 98 |
* |
| 99 |
* Revision 2.2 1999/03/02 15:34:08 eric |
| 100 |
* Anglicisation des commentaires... |
| 101 |
* |
| 102 |
* Revision 2.1 1999/02/22 15:24:13 hyc |
| 103 |
* *** empty log message *** |
| 104 |
* |
| 105 |
* |
| 106 |
* Revision 2.0 1999/01/15 09:10:39 hyc |
| 107 |
* *** empty log message *** |
| 108 |
* |
| 109 |
* $Header: /cvsroot/Lorene/C++/Source/Mtbl/mtbl.C,v 1.9 2014/10/13 08:53:08 j_novak Exp $ |
| 110 |
* |
| 111 |
*/ |
| 112 |
// headers C |
| 113 |
#include <cassert> |
| 114 |
|
| 115 |
// headers Lorene |
| 116 |
#include "mtbl.h" |
| 117 |
#include "coord.h" |
| 118 |
#include "type_parite.h" |
| 119 |
#include "utilitaires.h" |
| 120 |
|
| 121 |
// Constructeurs |
| 122 |
// ------------- |
| 123 |
namespace Lorene { |
| 124 |
Mtbl::Mtbl(const Mg3d& g) : mg(&g), etat(ETATNONDEF), t(0x0) { |
| 125 |
|
| 126 |
nzone = g.get_nzone() ; |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
Mtbl::Mtbl(const Mg3d* g) : mg(g), etat(ETATNONDEF), t(0x0) { |
| 131 |
|
| 132 |
nzone = g->get_nzone() ; |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
Mtbl::Mtbl(const Coord& c1) { |
| 137 |
|
| 138 |
// La coordonnee est-elle a jour ? |
| 139 |
if (c1.c == 0x0) c1.fait() ; |
| 140 |
|
| 141 |
// Les donnees fixes |
| 142 |
mg = c1.c->get_mg() ; |
| 143 |
nzone = mg->get_nzone() ; |
| 144 |
|
| 145 |
// L'etat |
| 146 |
t = 0x0 ; |
| 147 |
etat = ETATNONDEF ; |
| 148 |
|
| 149 |
// La transformation |
| 150 |
*this = *(c1.c) ; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
// Destructeur |
| 155 |
// ----------- |
| 156 |
Mtbl::~Mtbl() { |
| 157 |
del_t() ; |
| 158 |
} |
| 159 |
|
| 160 |
// Copie |
| 161 |
// ----- |
| 162 |
Mtbl::Mtbl(const Mtbl& mtc) : mg(mtc.mg), nzone(mtc.nzone) { |
| 163 |
|
| 164 |
// Protection |
| 165 |
assert(mtc.get_etat() != ETATNONDEF) ; |
| 166 |
|
| 167 |
t = 0x0 ; |
| 168 |
etat = ETATNONDEF ; |
| 169 |
if (mtc.etat == ETATQCQ) { |
| 170 |
set_etat_qcq() ; |
| 171 |
for (int i=0 ; i<nzone ; i++) { |
| 172 |
*t[i] = *mtc.t[i] ; |
| 173 |
} |
| 174 |
} |
| 175 |
else { |
| 176 |
assert(mtc.etat == ETATZERO) ; // sinon... |
| 177 |
} |
| 178 |
etat = mtc.etat ; |
| 179 |
} |
| 180 |
|
| 181 |
// Constructeur a partir d'une grille et d'un fichier |
| 182 |
Mtbl::Mtbl(const Mg3d & g, FILE* fd) : mg(&g) { |
| 183 |
|
| 184 |
// La multi-grille |
| 185 |
Mg3d* mg_tmp = new Mg3d(fd) ; // la multi-grille d'origine |
| 186 |
if (*mg != *mg_tmp) { |
| 187 |
cout << "Mtbl::Mtbl(Mg3d & , FILE*): grid not consistent !" << endl ; |
| 188 |
abort() ; |
| 189 |
} |
| 190 |
delete mg_tmp ; |
| 191 |
|
| 192 |
// Lecture |
| 193 |
nzone = mg->get_nzone() ; |
| 194 |
fread_be(&etat, sizeof(int), 1, fd) ; // etat |
| 195 |
|
| 196 |
// Le tableau |
| 197 |
t = 0x0 ; |
| 198 |
if (etat == ETATQCQ) { |
| 199 |
t = new Tbl*[nzone] ; |
| 200 |
for (int i=0 ; i<nzone ; i++) { |
| 201 |
t[i] = new Tbl(fd) ; |
| 202 |
} |
| 203 |
} |
| 204 |
int dzpuis_vieux ; |
| 205 |
fread_be(&dzpuis_vieux, sizeof(int), 1, fd) ; // le vieux dzpuis |
| 206 |
} |
| 207 |
|
| 208 |
// Sauvegarde sur un fichier |
| 209 |
void Mtbl::sauve(FILE* fd) const { |
| 210 |
|
| 211 |
mg->sauve(fd) ; // la multi-grille |
| 212 |
fwrite_be(&etat, sizeof(int), 1, fd) ; // etat |
| 213 |
if (etat == ETATQCQ) { |
| 214 |
for (int i=0 ; i<nzone ; i++) { |
| 215 |
t[i]->sauve(fd) ; |
| 216 |
} |
| 217 |
} |
| 218 |
int dzpuis_vieux = 0 ; |
| 219 |
fwrite_be(&dzpuis_vieux, sizeof(int), 1, fd) ; // le vieux dzpuis |
| 220 |
} |
| 221 |
|
| 222 |
// Affectations |
| 223 |
// ------------ |
| 224 |
void Mtbl::operator=(const Mtbl& mtc) |
| 225 |
{ |
| 226 |
// Protection |
| 227 |
assert (mg == mtc.mg) ; |
| 228 |
assert(mtc.get_etat() != ETATNONDEF) ; |
| 229 |
|
| 230 |
// Gestion des donnees |
| 231 |
if (mtc.get_etat() == ETATZERO) { |
| 232 |
set_etat_zero() ; |
| 233 |
} |
| 234 |
else { |
| 235 |
assert(mtc.get_etat() == ETATQCQ) ; // sinon... |
| 236 |
set_etat_qcq() ; |
| 237 |
for (int i=0 ; i<nzone ; i++) { |
| 238 |
*t[i] = *mtc.t[i] ; |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
void Mtbl::operator=(double x) |
| 244 |
{ |
| 245 |
if (x == double(0)) { |
| 246 |
set_etat_zero() ; |
| 247 |
} |
| 248 |
else { |
| 249 |
set_etat_qcq() ; |
| 250 |
for (int i=0 ; i<nzone ; i++) { |
| 251 |
*t[i] = x ; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
void Mtbl::operator=(int m) |
| 258 |
{ |
| 259 |
if (m == 0) { |
| 260 |
set_etat_zero() ; |
| 261 |
} |
| 262 |
else { |
| 263 |
set_etat_qcq() ; |
| 264 |
for (int i=0 ; i<nzone ; i++) { |
| 265 |
*t[i] = m ; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
//-----------------// |
| 273 |
// Gestion memoire // |
| 274 |
//-----------------// |
| 275 |
|
| 276 |
// Destructeur logique |
| 277 |
void Mtbl::del_t() { |
| 278 |
if (t != 0x0) { |
| 279 |
for (int l=0 ; l<nzone ; l++) { |
| 280 |
delete t[l] ; |
| 281 |
} |
| 282 |
delete [] t ; |
| 283 |
t = 0x0 ; |
| 284 |
} |
| 285 |
} |
| 286 |
// ETATZERO |
| 287 |
void Mtbl::set_etat_zero() { |
| 288 |
if (etat == ETATZERO) return ; |
| 289 |
del_t() ; |
| 290 |
etat = ETATZERO ; |
| 291 |
} |
| 292 |
// ETATNONDEF |
| 293 |
void Mtbl::set_etat_nondef() { |
| 294 |
if (etat == ETATNONDEF) return ; |
| 295 |
del_t() ; |
| 296 |
etat = ETATNONDEF ; |
| 297 |
} |
| 298 |
// ETATQCQ |
| 299 |
void Mtbl::set_etat_qcq() { |
| 300 |
if (etat == ETATQCQ) return ; |
| 301 |
|
| 302 |
// Protection |
| 303 |
assert( (etat == ETATZERO) || (etat == ETATNONDEF) ) ; // sinon... |
| 304 |
|
| 305 |
t = new Tbl*[nzone] ; |
| 306 |
for (int i=0 ; i<nzone ; i++) { |
| 307 |
t[i] = new Tbl( *(mg->get_grille3d(i)) ) ; |
| 308 |
} |
| 309 |
etat = ETATQCQ ; |
| 310 |
} |
| 311 |
// ZERO hard |
| 312 |
void Mtbl::annule_hard() { |
| 313 |
if (t == 0x0) { |
| 314 |
t = new Tbl*[nzone] ; |
| 315 |
for (int i=0 ; i<nzone ; i++) { |
| 316 |
t[i] = new Tbl( *(mg->get_grille3d(i)) ) ; |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
for (int i=0 ; i<nzone ; i++) { |
| 321 |
t[i]->annule_hard() ; |
| 322 |
} |
| 323 |
etat = ETATQCQ ; |
| 324 |
} |
| 325 |
|
| 326 |
// Sets the {\tt Mtbl} to zero in some domains |
| 327 |
// ------------------------------------------- |
| 328 |
|
| 329 |
void Mtbl::annule(int l_min, int l_max) { |
| 330 |
|
| 331 |
assert( (l_min >= 0) && (l_min < nzone) ) ; |
| 332 |
assert( (l_max >= 0) && (l_max < nzone) ) ; |
| 333 |
|
| 334 |
// Cas particulier: annulation globale : |
| 335 |
if ( (l_min == 0) && (l_max == nzone-1) ) { |
| 336 |
set_etat_zero() ; |
| 337 |
return ; |
| 338 |
} |
| 339 |
|
| 340 |
assert( etat != ETATNONDEF ) ; |
| 341 |
|
| 342 |
if ( etat == ETATZERO ) { |
| 343 |
return ; // rien n'a faire si c'est deja zero |
| 344 |
} |
| 345 |
else { |
| 346 |
assert( etat == ETATQCQ ) ; // sinon... |
| 347 |
for (int l=l_min; l<=l_max; l++) { |
| 348 |
t[l]->set_etat_zero() ; |
| 349 |
} |
| 350 |
|
| 351 |
} |
| 352 |
|
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
//------------------------// |
| 358 |
// Display // |
| 359 |
//------------------------// |
| 360 |
|
| 361 |
//----------- |
| 362 |
// Operator<< |
| 363 |
//----------- |
| 364 |
|
| 365 |
ostream& operator<<(ostream& o, const Mtbl& mt) { |
| 366 |
// Protection |
| 367 |
assert(mt.get_etat() != ETATNONDEF) ; |
| 368 |
|
| 369 |
int nzone = mt.get_nzone() ; |
| 370 |
o.precision(4); |
| 371 |
o.setf(ios::showpoint); |
| 372 |
o << "*** Mtbl " << nzone << " domains" << endl ; |
| 373 |
|
| 374 |
if (mt.get_etat() == ETATZERO) { |
| 375 |
o << "Logically NULL" << endl ; |
| 376 |
} |
| 377 |
else { |
| 378 |
for (int l=0 ; l<nzone ; l++) { |
| 379 |
o << " Domain #" << l << endl ; |
| 380 |
o << *(mt.t[l]) ; |
| 381 |
o << endl ; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
o << endl ; |
| 386 |
return o ; |
| 387 |
} |
| 388 |
|
| 389 |
//--------------- |
| 390 |
// Affiche_seuil |
| 391 |
//--------------- |
| 392 |
|
| 393 |
void Mtbl::affiche_seuil(ostream& ost, int precis, double seuil) const { |
| 394 |
ost << "*** Mtbl " << nzone << " domains" << endl ; |
| 395 |
|
| 396 |
// Cas particuliers |
| 397 |
//----------------- |
| 398 |
|
| 399 |
if (etat == ETATNONDEF) { |
| 400 |
ost << " state: UNDEFINED" << endl ; |
| 401 |
return ; |
| 402 |
} |
| 403 |
|
| 404 |
if (etat == ETATZERO) { |
| 405 |
ost << " state: ZERO" << endl ; |
| 406 |
return ; |
| 407 |
} |
| 408 |
|
| 409 |
// Affichage des Tbl |
| 410 |
//------------------ |
| 411 |
|
| 412 |
for (int l=0; l < nzone; l++) { |
| 413 |
t[l]->affiche_seuil( ost , precis, seuil ) ; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
// To be done |
| 421 |
//----------- |
| 422 |
|
| 423 |
void Mtbl::operator+=(double ) { |
| 424 |
const char* f = __FILE__ ; |
| 425 |
c_est_pas_fait(f) ; |
| 426 |
} |
| 427 |
|
| 428 |
void Mtbl::operator-=(double ) { |
| 429 |
const char* f = __FILE__ ; |
| 430 |
c_est_pas_fait(f) ; |
| 431 |
} |
| 432 |
|
| 433 |
void Mtbl::operator*=(double ) { |
| 434 |
const char* f = __FILE__ ; |
| 435 |
c_est_pas_fait(f) ; |
| 436 |
} |
| 437 |
|
| 438 |
void Mtbl::operator/=(double ) { |
| 439 |
const char* f = __FILE__ ; |
| 440 |
c_est_pas_fait(f) ; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
} |