TRUST 1.9.8
HPC thermohydraulic platform
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 Pas code: exit()
33 *
34 */
36{
37 Cerr << "Error in Lire_Fichier::printOn()" << finl;
38 exit();
39 return os;
40}
41
42/*! @brief Pas code: exit()
43 *
44 */
46{
47 Cerr << "Error in Lire_Fichier::readOn()" << finl;
48 exit();
49 return is;
50}
51
52/*! @brief Deux syntaxes possibles dans le jeu de donnees: Lire_fichier NOM_OBJET NOM_FICHIER
53 *
54 * (lit le contenu du fichier dans l'objet avec readOn de l'objet)
55 * Lire_fichier NOM_FICHIER ;
56 * (interprete le fichier dans un interprete local: les objets declares
57 * dans le fichier sont detruits a la fin de la lecture du fichier)
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 // On ne peut pas activer check_types car certains fichiers geom ont un format louche
86 // ou tout est colle comme ceci : -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 // On cree un nouvel interprete. A la fin de la lecture
101 // les objets seront detruits.
102 Interprete_bloc interp;
103 interp.interpreter_bloc(data_file,
104 Interprete_bloc::BLOC_EOF /* fin du bloc a la fin du fichier */,
105 0 /* verifie_sans_interpreter=0 */);
106 Cerr << "Lire_Fichier: end of file " << nom1 << finl;
107 }
108 Cerr << "Lire_Fichier: end of file " << nom1 << finl;
109 return is;
110}
Lecture dans un fichier d'objets ecrits au format binaire.
Definition EFichierBin.h:30
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Interprete un bloc d'instructions dans le jeu de donnees.
Entree & interpreter_bloc(Entree &is, Bloc_Type bloc_type, int verifier_sans_interpreter)
Interpretation d'un bloc d'instructions prises dans l'entree is.
Classe de base des objets "interprete".
Definition Interprete.h:38
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
void track_lines(bool b)
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
void set_check_types(bool flag) override
appelle get_entree_master().
class Lire_Fichier Lecture d'un fichier
Entree & interpreter(Entree &) override
Deux syntaxes possibles dans le jeu de donnees: Lire_fichier NOM_OBJET NOM_FICHIER.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:76
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52