/* * Methods for the class Grille_val, and its derivative classes. * * See the file grille_val.h for documentation * */ /* * Copyright (c) 2001 Jerome Novak * * This file is part of LORENE. * * LORENE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * LORENE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LORENE; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ char Grille_val_C[] = "$Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.7 2014/10/13 08:53:48 j_novak Exp $" ; /* * $Id: grille_val.C,v 1.7 2014/10/13 08:53:48 j_novak Exp $ * $Log: grille_val.C,v $ * Revision 1.7 2014/10/13 08:53:48 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.6 2013/07/15 13:14:41 j_novak * Correcting copy constructor and operator = * * Revision 1.5 2008/02/18 13:53:48 j_novak * Removal of special indentation instructions. * * Revision 1.4 2003/12/19 15:05:14 j_novak * Trying to avoid shadowed variables * * Revision 1.3 2003/10/03 16:17:17 j_novak * Corrected some const qualifiers * * Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon * * All writing/reading to a binary file are now performed according to * the big endian convention, whatever the system is big endian or * small endian, thanks to the functions fwrite_be and fread_be * * Revision 1.1 2001/11/22 13:41:54 j_novak * Added all source files for manipulating Valencia type objects and making * interpolations to and from Meudon grids. * * * $Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.7 2014/10/13 08:53:48 j_novak Exp $ * */ // Fichier includes #include "grille_val.h" #include "utilitaires.h" //---------------// // Constructeurs // //---------------// // Fonction auxilliaire namespace Lorene { Tbl* Grille_val::fait_grille1D(const double rmin, const double rmax, const int n) { assert(rminset_etat_qcq() ; for (int i=0; iset(i) = rmin + i*step ; return resu ; } // Constructeur 1D Grille_val::Grille_val(const double izrmin, const double izrmax, const int n1, const int fantome): dim(n1), nfantome(fantome), type_t(SYM), type_p(SYM) { assert (n1 > 0) ; zrmin = new double(izrmin) ; zrmax = new double(izrmax) ; double amin = ((n1 + nfantome - 0.5)*izrmin - (nfantome-0.5)*izrmax) / n1 ; double amax = ((n1 + nfantome - 0.5)*izrmax - (nfantome-0.5)*izrmin) / n1 ; zr = fait_grille1D(amin, amax, n1+2*fantome) ; amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ; amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ; zri = fait_grille1D(amin, amax, n1+2*fantome+1) ; } // Constructeur 2D Grille_val::Grille_val(const double izrmin, const double izrmax, const int n2, const int n1, const int itype_t, const int fantome): dim(n2,n1), nfantome(fantome), type_t(itype_t), type_p(SYM) { zrmin = new double(izrmin) ; zrmax = new double(izrmax) ; double amin = ((n1 + nfantome - 0.5)*izrmin - (nfantome-0.5)*izrmax) / n1 ; double amax = ((n1 + nfantome - 0.5)*izrmax - (nfantome-0.5)*izrmin) / n1 ; zr = fait_grille1D(amin, amax, n1+2*fantome) ; amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ; amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ; zri = fait_grille1D(amin, amax, n1+2*fantome+1) ; } // Constructeur 3D Grille_val::Grille_val(const double izrmin, const double izrmax, const int n3, const int n2, const int n1, const int itype_t, const int itype_p, const int fantome ): dim(n3,n2,n1), nfantome(fantome), type_t(itype_t), type_p(itype_p) { zrmin = new double(izrmin) ; zrmax = new double(izrmax) ; double amin = ((n1 + nfantome - 0.5)*izrmin - (nfantome-0.5)*izrmax) / n1 ; double amax = ((n1 + nfantome - 0.5)*izrmax - (nfantome-0.5)*izrmin) / n1 ; zr = fait_grille1D(amin, amax, n1+2*fantome) ; amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ; amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ; zri = fait_grille1D(amin, amax, n1+2*fantome+1) ; } // Constructeur par recopie Grille_val::Grille_val(const Grille_val & titi): dim(titi.dim), nfantome(titi.nfantome), type_t(titi.type_t), type_p(titi.type_p) { assert(titi.zr != 0x0) ; assert(titi.zri != 0x0) ; assert(titi.zrmin != 0x0) ; assert(titi.zrmax != 0x0) ; zr = new Tbl(*titi.zr) ; zri = new Tbl(*titi.zri) ; zrmin = new double(*titi.zrmin) ; zrmax = new double(*titi.zrmax) ; } // Depuis un fichier Grille_val::Grille_val(FILE* fd):dim(fd) { fread_be(&nfantome, sizeof(int), 1, fd) ; fread_be(&type_t, sizeof(int), 1, fd) ; fread_be(&type_p, sizeof(int), 1, fd) ; double amin, amax ; fread_be(&amin, sizeof(double), 1, fd) ; fread_be(&amax, sizeof(double), 1, fd) ; zrmin = new double(amin) ; zrmax = new double(amax) ; zr = new Tbl(fd) ; zri = new Tbl(fd) ; } //--------------// // Destructeurs // //--------------// // Destructeur Grille_val::~Grille_val() { assert(zr != 0x0) ; assert(zri != 0x0) ; assert(zrmin != 0x0) ; assert(zrmax != 0x0) ; delete zr ; delete zri ; delete zrmin ; delete zrmax ; } //-------------// // Affectation // //-------------// // Depuis une autre Grille_val void Grille_val::operator=(const Grille_val & titi) { dim = titi.dim ; nfantome = titi.nfantome ; type_t = titi.type_t ; type_p = titi.type_p ; assert(titi.zr != 0x0) ; assert(titi.zri != 0x0) ; assert(titi.zrmin != 0x0) ; assert(titi.zrmax != 0x0) ; for (int i=0; it[i] = titi.zr->t[i] ; for (int i=0; it[i] = titi.zri->t[i] ; *zrmin = *titi.zrmin ; *zrmax = *titi.zrmax ; } //------------// // Sauvegarde // //------------// // Sauve dans un fchier void Grille_val::sauve(FILE* fd) const { dim.sauve(fd) ; fwrite_be(&nfantome, sizeof(int), 1, fd) ; fwrite_be(&type_t, sizeof(int), 1, fd) ; fwrite_be(&type_p, sizeof(int), 1, fd) ; fwrite_be(zrmin, sizeof(double), 1, fd) ; fwrite_be(zrmax, sizeof(double), 1, fd) ; zr->sauve(fd) ; zri->sauve(fd) ; } //------------// // Impression // //------------// // Operateurs << ostream& operator<<(ostream& o, const Grille_val & titi) { titi >> o ; return o ; } ostream& Grille_val::operator>>(ostream& o) const { int ndim = dim.ndim ; int nfant = nfantome ; o.precision(4); o.setf(ios::showpoint); o << "*** Grille_val " << ndim << "D" << " size: " ; for (int i = 0; i