mtbl.C

00001 /*
00002  *  Methods of class Mtbl
00003  *
00004  *   (see file mtbl.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 1999-2000 Jean-Alain Marck
00010  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00011  *
00012  *   This file is part of LORENE.
00013  *
00014  *   LORENE is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   LORENE is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with LORENE; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  */
00029 
00030 
00031 char mtbl_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mtbl/mtbl.C,v 1.7 2008/08/19 06:42:00 j_novak Exp $" ;
00032 
00033 /*
00034  * $Id: mtbl.C,v 1.7 2008/08/19 06:42:00 j_novak Exp $
00035  * $Log: mtbl.C,v $
00036  * Revision 1.7  2008/08/19 06:42:00  j_novak
00037  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00038  * cast-type operations, and constant strings that must be defined as const char*
00039  *
00040  * Revision 1.6  2008/02/18 13:53:40  j_novak
00041  * Removal of special indentation instructions.
00042  *
00043  * Revision 1.5  2002/10/16 14:36:43  j_novak
00044  * Reorganization of #include instructions of standard C++, in order to
00045  * use experimental version 3 of gcc.
00046  *
00047  * Revision 1.4  2002/09/06 15:37:46  e_gourgoulhon
00048  * Performed a forgotten replacement
00049  *  t = new (Tbl *[nzone])  -->   t = new Tbl*[nzone]
00050  * to ensure compatibility with the xlC_r compiler on IBM Regatta
00051  *
00052  * Revision 1.3  2002/05/07 07:36:03  e_gourgoulhon
00053  * Compatibilty with xlC compiler on IBM SP2:
00054  *    suppressed the parentheses around argument of instruction new:
00055  *  e.g.   t = new (Tbl *[nzone])  -->   t = new Tbl*[nzone]
00056  *
00057  * Revision 1.2  2001/12/04 21:27:54  e_gourgoulhon
00058  *
00059  * All writing/reading to a binary file are now performed according to
00060  * the big endian convention, whatever the system is big endian or
00061  * small endian, thanks to the functions fwrite_be and fread_be
00062  *
00063  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00064  * LORENE
00065  *
00066  * Revision 2.10  2000/08/16  10:30:04  eric
00067  * Suppression du membre dzpuis.
00068  *
00069  * Revision 2.9  1999/11/23  13:33:04  eric
00070  *  Le constructeur Tbl::Tbl(const Grille3d* ) est devenu Tbl::Tbl(const Grille3d& ).
00071  *
00072  * Revision 2.8  1999/10/29  15:06:24  eric
00073  * Suppression des fonctions membres min() et max():
00074  * elles deviennent des fonctions externes.
00075  *
00076  * Revision 2.7  1999/10/18  15:16:05  eric
00077  * *** empty log message ***
00078  *
00079  * Revision 2.6  1999/10/18  15:08:22  eric
00080  * La fonction membre annule() est rebaptisee annule_hard().
00081  * Introduction de la fonction membre annule(int, int).
00082  *
00083  * Revision 2.5  1999/10/01  12:35:54  eric
00084  * Ajout de la fonction affiche_seuil.
00085  *
00086  * Revision 2.4  1999/10/01  10:08:41  eric
00087  * Depoussierage.
00088  * Documentation.
00089  *
00090  * Revision 2.3  1999/03/02  16:26:26  eric
00091  * Modif des indentations dans <<
00092  *
00093  * Revision 2.2  1999/03/02  15:34:08  eric
00094  * Anglicisation des commentaires...
00095  *
00096  * Revision 2.1  1999/02/22  15:24:13  hyc
00097  * *** empty log message ***
00098  *
00099  *
00100  * Revision 2.0  1999/01/15  09:10:39  hyc
00101  * *** empty log message ***
00102  *
00103  * $Header: /cvsroot/Lorene/C++/Source/Mtbl/mtbl.C,v 1.7 2008/08/19 06:42:00 j_novak Exp $
00104  *
00105  */
00106 // headers C
00107 #include <assert.h>
00108 
00109 // headers Lorene
00110 #include "mtbl.h"
00111 #include "coord.h"
00112 #include "type_parite.h"
00113 #include "utilitaires.h"
00114 
00115 // Constructeurs
00116 // -------------
00117 Mtbl::Mtbl(const Mg3d& g) : mg(&g), etat(ETATNONDEF), t(0x0) {
00118 
00119     nzone = g.get_nzone() ;
00120     
00121 }
00122 
00123 Mtbl::Mtbl(const Mg3d* g) : mg(g), etat(ETATNONDEF), t(0x0) {
00124 
00125     nzone = g->get_nzone() ;
00126 
00127 }
00128 
00129 Mtbl::Mtbl(const Coord& c1) {
00130     
00131     // La coordonnee est-elle a jour ?
00132     if (c1.c == 0x0) c1.fait() ;
00133 
00134     // Les donnees fixes
00135     mg = c1.c->get_mg() ;
00136     nzone = mg->get_nzone() ;
00137 
00138     // L'etat
00139     t = 0x0 ;
00140     etat = ETATNONDEF ;
00141         
00142     // La transformation
00143     *this = *(c1.c) ;
00144 }
00145 
00146 
00147 // Destructeur
00148 // -----------
00149 Mtbl::~Mtbl() {
00150     del_t() ;
00151 }
00152 
00153 // Copie
00154 // -----
00155 Mtbl::Mtbl(const Mtbl& mtc) : mg(mtc.mg), nzone(mtc.nzone) {
00156 
00157     // Protection
00158     assert(mtc.get_etat() != ETATNONDEF) ;
00159     
00160     t = 0x0 ;
00161     etat = ETATNONDEF ;
00162     if (mtc.etat == ETATQCQ) {
00163     set_etat_qcq() ;
00164     for (int i=0 ; i<nzone ; i++) {
00165         *t[i] = *mtc.t[i] ;
00166     }
00167     }
00168     else {
00169     assert(mtc.etat == ETATZERO) ;  // sinon...
00170     }
00171     etat = mtc.etat ;
00172 }
00173 
00174 // Constructeur a partir d'une grille et d'un fichier
00175 Mtbl::Mtbl(const Mg3d & g, FILE* fd) : mg(&g) {
00176     
00177     // La multi-grille
00178     Mg3d* mg_tmp = new Mg3d(fd) ;   // la multi-grille d'origine
00179     if (*mg != *mg_tmp) {
00180     cout << "Mtbl::Mtbl(Mg3d & , FILE*): grid not consistent !" << endl ;
00181     abort() ;
00182     }
00183     delete mg_tmp ;
00184     
00185     // Lecture
00186     nzone = mg->get_nzone() ;
00187     fread_be(&etat, sizeof(int), 1, fd) ;       // etat
00188     
00189     // Le tableau
00190     t = 0x0 ;
00191     if (etat == ETATQCQ) {
00192     t = new Tbl*[nzone] ;
00193     for (int i=0 ; i<nzone ; i++) {
00194         t[i] = new Tbl(fd) ;
00195     }
00196     }
00197     int dzpuis_vieux ; 
00198     fread_be(&dzpuis_vieux, sizeof(int), 1, fd) ;       // le vieux dzpuis
00199 }
00200 
00201 // Sauvegarde sur un fichier
00202 void Mtbl::sauve(FILE* fd) const {
00203 
00204     mg->sauve(fd) ;             // la multi-grille
00205     fwrite_be(&etat, sizeof(int), 1, fd) ;          // etat
00206     if (etat == ETATQCQ) {
00207     for (int i=0 ; i<nzone ; i++) {
00208         t[i]->sauve(fd) ;
00209     }
00210     }
00211     int dzpuis_vieux = 0 ; 
00212     fwrite_be(&dzpuis_vieux, sizeof(int), 1, fd) ;      // le vieux dzpuis
00213 }
00214 
00215 // Affectations
00216 // ------------
00217 void Mtbl::operator=(const Mtbl& mtc)
00218 {
00219     // Protection
00220     assert (mg == mtc.mg) ;
00221     assert(mtc.get_etat() != ETATNONDEF) ;
00222 
00223     // Gestion des donnees
00224     if (mtc.get_etat() == ETATZERO) {
00225     set_etat_zero() ;
00226     }
00227     else {
00228         assert(mtc.get_etat() == ETATQCQ) ; // sinon...
00229     set_etat_qcq() ;
00230     for (int i=0 ; i<nzone ; i++) {
00231         *t[i] = *mtc.t[i] ;
00232     }
00233     }
00234 }
00235 
00236 void Mtbl::operator=(double x)
00237 {
00238     if (x == double(0)) {
00239     set_etat_zero() ;
00240     }
00241     else {
00242     set_etat_qcq() ;
00243     for (int i=0 ; i<nzone ; i++) {
00244         *t[i] = x ;
00245     }
00246     }
00247 
00248 }
00249 
00250 void Mtbl::operator=(int m)
00251 {
00252     if (m == 0) {
00253     set_etat_zero() ;
00254     }
00255     else {
00256     set_etat_qcq() ;
00257     for (int i=0 ; i<nzone ; i++) {
00258         *t[i] = m ;
00259     }
00260     }
00261 
00262 }
00263 
00264 
00265             //-----------------//
00266                     // Gestion memoire //
00267             //-----------------//
00268 
00269 // Destructeur logique
00270 void Mtbl::del_t() {
00271     if (t != 0x0) {
00272     for (int l=0 ; l<nzone ; l++) {
00273     delete t[l] ;
00274     }
00275     delete [] t ;
00276     t = 0x0 ;
00277     }
00278 }
00279 // ETATZERO
00280 void Mtbl::set_etat_zero() {
00281     if (etat == ETATZERO) return ;
00282     del_t() ;
00283     etat = ETATZERO ;
00284 }
00285 // ETATNONDEF
00286 void Mtbl::set_etat_nondef() {
00287     if (etat == ETATNONDEF) return ;
00288     del_t() ;
00289     etat = ETATNONDEF ;
00290 }
00291 // ETATQCQ
00292 void Mtbl::set_etat_qcq() {
00293     if (etat == ETATQCQ) return ;
00294 
00295     // Protection
00296     assert( (etat == ETATZERO) || (etat == ETATNONDEF) ) ; // sinon...
00297     
00298     t = new Tbl*[nzone] ;
00299     for (int i=0 ; i<nzone ; i++) {
00300     t[i] = new Tbl( *(mg->get_grille3d(i)) ) ;
00301     }
00302     etat = ETATQCQ ;
00303 }
00304 // ZERO hard
00305 void Mtbl::annule_hard() {
00306     if (t == 0x0) {
00307     t = new Tbl*[nzone] ;
00308     for (int i=0 ; i<nzone ; i++) {
00309         t[i] = new Tbl( *(mg->get_grille3d(i)) ) ;
00310     }
00311     }
00312     
00313     for (int i=0 ; i<nzone ; i++) {
00314     t[i]->annule_hard() ;
00315     }
00316     etat = ETATQCQ ;
00317 }
00318 
00319 // Sets the {\tt Mtbl} to zero in some domains
00320 // -------------------------------------------
00321 
00322 void Mtbl::annule(int l_min, int l_max) {
00323 
00324     assert( (l_min >= 0) && (l_min < nzone) ) ; 
00325     assert( (l_max >= 0) && (l_max < nzone) ) ; 
00326     
00327     // Cas particulier: annulation globale : 
00328     if ( (l_min == 0) && (l_max == nzone-1) ) {
00329     set_etat_zero() ;
00330     return ; 
00331     }
00332     
00333     assert( etat != ETATNONDEF ) ; 
00334     
00335     if ( etat == ETATZERO ) {
00336     return ;        // rien n'a faire si c'est deja zero
00337     }
00338     else {
00339     assert( etat == ETATQCQ ) ; // sinon...
00340     for (int l=l_min; l<=l_max; l++) {
00341         t[l]->set_etat_zero() ; 
00342     }
00343      
00344     }
00345     
00346 }
00347 
00348 
00349 
00350             //------------------------//
00351             //  Display       //
00352             //------------------------//
00353             
00354 //-----------           
00355 // Operator<<
00356 //-----------           
00357 
00358 ostream& operator<<(ostream& o, const Mtbl& mt) {
00359     // Protection
00360     assert(mt.get_etat() != ETATNONDEF) ;
00361     
00362     int nzone = mt.get_nzone() ;
00363     o.precision(4);
00364     o.setf(ios::showpoint);
00365     o << "*** Mtbl " << nzone << " domains" << endl ;
00366 
00367     if (mt.get_etat() == ETATZERO) {
00368     o << "Logically NULL" << endl ;
00369     }
00370     else {
00371     for (int l=0 ; l<nzone ; l++) {
00372         o << " Domain #" << l << endl ;
00373         o << *(mt.t[l]) ;
00374         o << endl ;
00375     }
00376     }
00377 
00378     o << endl ;
00379     return o ;
00380 }
00381 
00382 //---------------
00383 // Affiche_seuil
00384 //---------------
00385 
00386 void Mtbl::affiche_seuil(ostream& ost, int precis,  double seuil) const {
00387     ost << "*** Mtbl " << nzone << " domains" << endl ;
00388     
00389     // Cas particuliers
00390     //-----------------
00391 
00392     if (etat == ETATNONDEF) {
00393     ost << "    state: UNDEFINED" << endl ;
00394     return ;
00395     }
00396 
00397     if (etat == ETATZERO) {
00398     ost << "    state: ZERO" << endl ;
00399     return ;
00400     }
00401 
00402     // Affichage des Tbl
00403     //------------------
00404     
00405     for (int l=0; l < nzone; l++) {
00406     t[l]->affiche_seuil( ost , precis, seuil ) ;
00407     }
00408 
00409 
00410 }
00411 
00412 
00413 // To be done
00414 //-----------
00415 
00416 void Mtbl::operator+=(double ) {
00417     const char* f = __FILE__ ;
00418     c_est_pas_fait(f) ;
00419 }
00420 
00421 void Mtbl::operator-=(double ) {
00422     const char* f = __FILE__ ;
00423     c_est_pas_fait(f) ;
00424 }
00425 
00426 void Mtbl::operator*=(double ) {
00427     const char* f = __FILE__ ;
00428     c_est_pas_fait(f) ;
00429 }
00430 
00431 void Mtbl::operator/=(double ) {
00432     const char* f = __FILE__ ;
00433     c_est_pas_fait(f) ;
00434 }
00435 
00436 

Generated on Tue Feb 7 01:35:18 2012 for LORENE by  doxygen 1.4.6