eos_bf_file.C

00001 /*
00002  * Methods for Eos_bifluid and file manipulation
00003  *
00004  * (see file eos_bifluid.h for documentation)
00005  */
00006 
00007 /*
00008  *   Copyright (c) 2001 Jerome Novak
00009  *
00010  *   This file is part of LORENE.
00011  *
00012  *   LORENE is free software; you can redistribute it and/or modify
00013  *   it under the terms of the GNU General Public License as published by
00014  *   the Free Software Foundation; either version 2 of the License, or
00015  *   (at your option) any later version.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 
00029 char eos_bf_file_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_file.C,v 1.6 2008/08/19 06:42:00 j_novak Exp $" ;
00030 
00031 /*
00032  * $Id: eos_bf_file.C,v 1.6 2008/08/19 06:42:00 j_novak Exp $
00033  * $Log: eos_bf_file.C,v $
00034  * Revision 1.6  2008/08/19 06:42:00  j_novak
00035  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00036  * cast-type operations, and constant strings that must be defined as const char*
00037  *
00038  * Revision 1.5  2003/12/05 15:09:47  r_prix
00039  * adapted Eos_bifluid class and subclasses to use read_variable() for
00040  * (formatted) file-reading.
00041  *
00042  * Revision 1.4  2002/10/16 14:36:34  j_novak
00043  * Reorganization of #include instructions of standard C++, in order to
00044  * use experimental version 3 of gcc.
00045  *
00046  * Revision 1.3  2002/01/11 14:09:34  j_novak
00047  * Added newtonian version for 2-fluid stars
00048  *
00049  * Revision 1.2  2001/12/04 21:27:53  e_gourgoulhon
00050  *
00051  * All writing/reading to a binary file are now performed according to
00052  * the big endian convention, whatever the system is big endian or
00053  * small endian, thanks to the functions fwrite_be and fread_be
00054  *
00055  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00056  * LORENE
00057  *
00058  * Revision 1.1  2001/06/21  15:22:15  novak
00059  * Initial revision
00060  *
00061  *
00062  * $Header: /cvsroot/Lorene/C++/Source/Eos/eos_bf_file.C,v 1.6 2008/08/19 06:42:00 j_novak Exp $
00063  *
00064  */
00065  
00066 // Headers C
00067 #include <stdlib.h>
00068 
00069 // Header Lorene
00070 #include "headcpp.h"
00071 #include "eos_bifluid.h"
00072 #include "utilitaires.h"
00073 
00074         //--------------------------------------//
00075         //  Identification virtual functions    //
00076         //--------------------------------------//
00077 
00078 
00079 int Eos_bf_poly::identify() const   { return 1; }
00080 
00081 int Eos_bf_poly_newt::identify() const  { return 2; }
00082 
00083 
00084         //---------------------------------------------//
00085         //    EOS construction from a binary file      //
00086         //---------------------------------------------//
00087 
00088 Eos_bifluid* Eos_bifluid::eos_from_file(FILE* fich) {
00089     
00090     Eos_bifluid* p_eos ; 
00091     
00092     // Type (class) of EOS :
00093     int identificator ;     
00094     fread_be(&identificator, sizeof(int), 1, fich) ;        
00095 
00096     switch(identificator) {
00097     
00098     case 1 : {
00099         p_eos = new Eos_bf_poly(fich) ; 
00100         break ; 
00101     }
00102     
00103     default : {
00104         cout << "Eos_bifluid::eos_from_file : unknown type of EOS !" << endl ; 
00105         cout << " identificator = " << identificator << endl ; 
00106         abort() ; 
00107         break ; 
00108     }
00109     
00110     }
00111     
00112     return p_eos ; 
00113     
00114 }
00115 
00116         //----------------------------------------------//
00117         //    EOS construction from a formatted file    //
00118         //----------------------------------------------//
00119 
00120 Eos_bifluid* Eos_bifluid::eos_from_file(char *fname) {
00121     
00122     int identificator ; 
00123 
00124     // EOS identificator : 
00125     if (read_variable (fname, const_cast<char*>("ident"), identificator) != 0)
00126       {
00127     cerr << "ERROR: Could not read the required variable 'ident' in " << fname << endl;
00128     exit (-1);
00129       }
00130 
00131     Eos_bifluid* p_eos ; 
00132     
00133     switch(identificator) {
00134     
00135     case 1 : {
00136         p_eos = new Eos_bf_poly(fname) ; 
00137         break ; 
00138     }
00139     
00140     case 2 : {
00141         p_eos = new Eos_bf_poly_newt(fname) ; 
00142         break ; 
00143     }
00144     
00145     default : {
00146         cout << "Eos_bifluid::eos_from_file : unknown type of EOS !" << endl ; 
00147         cout << " identificator = " << identificator << endl ; 
00148         abort() ; 
00149         break ; 
00150     }
00151     
00152     }
00153     
00154     return p_eos ; 
00155     
00156 }
00157 
00158 
00159 
00160 
00161 
00162 

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