TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Lire_Fichier.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <Lire_Fichier.h>
17#include <Interprete_bloc.h>
18#include <EFichierBin.h>
19#include <LecFicDiffuse_JDD.h>
20#include <LecFicDiffuse.h>
21#include <Read_unsupported_ASCII_file_from_ICEM.h>
22
23Implemente_instanciable(Lire_Fichier,"Lire_Fichier|Read_file",Interprete);
24// XD read_file interprete lire_fichier INHERITS_BRACE Keyword to read the object name_obj contained in the file
25// XD_CONT filename. NL2 This is notably used when the calculation domain has already been meshed and the mesh contains
26// XD_CONT the file filename, simply write read_file dom filename (where dom is the name of the meshed domain). NL2 If
27// XD_CONT the filename is ;, is to execute a data set given in the file of name name_obj (a space must be entered
28// XD_CONT between the semi-colon and the file name).
29// XD attr name_obj chaine name_obj REQ Name of the object to be read.
30// XD attr filename chaine filename REQ Name of the file.
31
32/*! @brief Not implemented: calls exit().
33 *
34 */
36{
37 Cerr << "Error in Lire_Fichier::printOn()" << finl;
38 exit();
39 return os;
40}
41
42/*! @brief Not implemented: calls exit().
43 *
44 */
46{
47 Cerr << "Error in Lire_Fichier::readOn()" << finl;
48 exit();
49 return is;
50}
51
52/*! @brief Two possible syntaxes in the data file: Lire_fichier NOM_OBJET NOM_FICHIER
53 *
54 * (reads the file content into the object using the object's readOn method)
55 * Lire_fichier NOM_FICHIER ;
56 * (interprets the file in a local interpreter: objects declared
57 * in the file are destroyed at the end of the file reading)
58 *
59 */
61{
62 Nom nom1, nom2;
63 is >> nom1 >> nom2;
64 if (nom2 != ";")
65 {
66 if (is_a_binary_file(nom2))
67 {
68 check_ICEM_binary_file(nom2,nom1);
69 Cerr << "Lire_Fichier: reading binary file " << nom2 << " to object " << nom1 << finl;
70 Objet_U& ob1=objet(nom1);
71 EFichierBin fic(nom2);
72 if(!fic.get_ifstream())
73 {
74 Cerr << "Unable to open the file " << nom2 << finl;
75 Cerr << "Enter a different file name please ... ";
76 exit();
77 }
78 fic >> ob1;
79 }
80 else
81 {
82 check_ICEM_ascii_file(nom2,*this);
83 Cerr << "Lire_Fichier: reading ASCII file " << nom2 << " to object " << nom1 << finl;
84 LecFicDiffuse fic(nom2);
85 // Cannot activate check_types because some geom files have a strange format
86 // where everything is concatenated like: -0.12000000E+01-0.25000000E+00-0.25000000E+00
87 // (exemple croix.geom)
88 fic.set_check_types(0);
89 Objet_U& ob1 = objet(nom1);
90 fic >> ob1;
91 }
92 }
93 else
94 {
95 Cerr << "Lire_Fichier: interpreting file " << nom1 << finl;
96 // Not counting lines inside this file
97 LecFicDiffuse_JDD data_file(nom1);
98 data_file.track_lines(false);
99 data_file.set_check_types(1);
100 // Create a new interpreter. At the end of reading,
101 // the objects will be destroyed.
102 Interprete_bloc interp;
103 interp.interpreter_bloc(data_file,
104 Interprete_bloc::BLOC_EOF /* end of block at end of file */,
105 0 /* check_without_interpreting=0 */);
106 Cerr << "Lire_Fichier: end of file " << nom1 << finl;
107 }
108 Cerr << "Lire_Fichier: end of file " << nom1 << finl;
109 return is;
110}
Reading from a file of objects written in binary format.
Definition EFichierBin.h:30
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Interprets a block of instructions in the data set.
Entree & interpreter_bloc(Entree &is, Bloc_Type bloc_type, int verifier_sans_interpreter)
Interprets a block of instructions read from input is.
Base class for "interpreter" objects.
Definition Interprete.h:38
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
void track_lines(bool b)
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
void set_check_types(bool flag) override
Calls get_entree_master().
class Lire_Fichier: reads a file.
Entree & interpreter(Entree &) override
Two possible syntaxes in the data file: Lire_fichier NOM_OBJET NOM_FICHIER.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:71
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52