Debian Codegraph @

C++/Source/Eos/hoteos_from_file.C

raw
1 /*
2 * Methods for Hot_eos and file manipulation
3 *
4 * (see file hoteos.h for documentation)
5 */
6
7 /*
8 * Copyright (c) 2015 Jerome Novak
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28
29 char hoteos_from_file_C[] = "$Header: /cvsroot/Lorene/C++/Source/Eos/hoteos_from_file.C,v 1.2 2015/12/08 10:52:18 j_novak Exp $" ;
30
31 /*
32 * $Id: hoteos_from_file.C,v 1.2 2015/12/08 10:52:18 j_novak Exp $
33 * $Log: hoteos_from_file.C,v $
34 * Revision 1.2 2015/12/08 10:52:18 j_novak
35 * New class Hoteos_tabul for tabulated temperature-dependent EoSs.
36 *
37 * Revision 1.1 2015/03/17 14:20:00 j_novak
38 * New class Hot_eos to deal with temperature-dependent EOSs.
39 *
40 * $Header: /cvsroot/Lorene/C++/Source/Eos/hoteos_from_file.C,v 1.2 2015/12/08 10:52:18 j_novak Exp $
41 *
42 */
43
44 // Headers C
45 #include <cstdlib>
46
47 // Header Lorene
48 #include "headcpp.h"
49 #include "hoteos.h"
50 #include "utilitaires.h"
51
52 namespace Lorene {
53
54 //--------------------------------------//
55 // Identification virtual functions //
56 //--------------------------------------//
57
58 int Ideal_gas::identify() const { return 1; }
59
60 int Hoteos_tabul::identify() const { return 2; }
61
62
63 //-------------------------------------------------//
64 // Hot EOS construction from a binary file //
65 //-------------------------------------------------//
66
67 Hot_eos* Hot_eos::hoteos_from_file(FILE* fich) {
68
69 Hot_eos* p_eos ;
70
71 // Type (class) of EOS :
72 int identificator ;
73 fread_be(&identificator, sizeof(int), 1, fich) ;
74
75 switch(identificator) {
76
77 case 1 : {
78 p_eos = new Ideal_gas(fich) ;
79 break ;
80 }
81
82 case 2 : {
83 p_eos = new Hoteos_tabul(fich) ;
84 break ;
85 }
86
87 default : {
88 cout << "Hot_eos::hoteos_from_file : unknown type of EOS !" << endl ;
89 cout << " identificator = " << identificator << endl ;
90 abort() ;
91 break ;
92 }
93
94 }
95
96 return p_eos ;
97
98 }
99
100 //--------------------------------------------------//
101 // Hot EOS construction from a formatted file //
102 //--------------------------------------------------//
103
104 Hot_eos* Hot_eos::hoteos_from_file(ifstream& fich) {
105
106 int identificator ;
107 if (!fich) {
108 cerr << "Hot_eos::hoteos_from_file: file cannot be opened!" << endl ;
109 abort() ;
110 }
111
112 // EOS identificator :
113 fich >> identificator ; fich.ignore(1000, '\n') ;
114
115 Hot_eos* p_eos ;
116
117 switch(identificator) {
118
119 case 1 : {
120 p_eos = new Ideal_gas(fich) ;
121 break ;
122 }
123
124 case 2 : {
125 p_eos = new Hoteos_tabul(fich) ;
126 break ;
127 }
128
129 default : {
130 cout << "Hot_eos::hoteos_from_file : unknown type of EOS !" << endl ;
131 cout << " identificator = " << identificator << endl ;
132 abort() ;
133 break ;
134 }
135
136 }
137
138 return p_eos ;
139
140 }
141
142
143 }