TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Read_unsupported_ASCII_file_from_ICEM.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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 <Read_unsupported_ASCII_file_from_ICEM.h>
17#include <Lire_Fichier.h>
18#include <SFichierBin.h>
19#include <EFichierBin.h>
20#include <Interprete.h>
21#include <TRUSTTab.h>
22#include <Objet_U.h>
23#include <Motcle.h>
24
25
26// PLEASE DO NOT REMOVE Read_unsupported_ASCII_file_from_ICEM KEYWORD FROM TRUST
27// IT IS STILL USEFUL (in v1.9.7) TO READ OLD ICEM FILES (ND, 07/11/2025)
28
29Implemente_instanciable(Read_unsupported_ASCII_file_from_ICEM,"Read_unsupported_ASCII_file_from_ICEM",Lire_Fichier);
30// XD read_unsupported_ascii_file_from_icem read_file read_unsupported_ascii_file_from_icem INHERITS_BRACE not_set
31
33{
34 return os;
35}
36
38{
39 return is;
40}
41
42// Fonction utilisee
43inline char read_write_string_from(EFichierBin& s,SFichierBin& o, const char* first_caracter)
44{
45 // La regle est :
46 // On lit jusqu'a first_caracter s'il est defini
47 // On complete par le separateur 00
48 // On retourne le dernier caractere (avant l'espace)
49 char octet;
50 char zero=0;
51 char last_caracter;
52 // Si first_caracter est defini on lit jusqu'a lui
53 if (*first_caracter!=0)
54 {
55#ifndef NDEBUG
56 Cerr << " -> Look for the byte:";
57 fprintf(stderr," %02x <=> ",*first_caracter);
58 Cerr << (Nom)*first_caracter << finl;
59 Cerr << " -> Read the bytes :";
60#endif
61 //while (s.good() && s.get_istream().read(&octet,1)!=0 && octet!=*first_caracter)
62 while (s.good() && s.get_istream().read(&octet,1) && octet!=*first_caracter)
63 {
64#ifndef NDEBUG
65 fprintf(stderr," %02x",octet);
66#endif
67 };
68 }
69 else
70 {
71 // Si first caracter n'est pas defini, on se contente de passer
72 // les espaces (32, 20 en hexa) et separateurs (00) et delete (127, 7F en hexa)
73#ifndef NDEBUG
74 Cerr << " -> Read the bytes :";
75#endif
76 //while (s.good() && s.get_istream().read(&octet,1)!=0 && (octet==32 || octet==0 || octet==127) )
77 while (s.good() && s.get_istream().read(&octet,1) && (octet==32 || octet==0 || octet==127) )
78 {
79#ifndef NDEBUG
80 fprintf(stderr," %02x",octet);
81#endif
82 };
83 }
84#ifndef NDEBUG
85 fprintf(stderr," %02x",octet);
86#endif
87 o.get_ostream().write(&octet,1);
88 last_caracter = octet;
89 Nom chaine(octet);
90 // On lit jusqu'a l'espace:
91 //while (s.good() && s.get_istream().read(&octet,1)!=0 && octet!=32)
92 while (s.good() && s.get_istream().read(&octet,1) && octet!=32)
93 {
94#ifndef NDEBUG
95 fprintf(stderr," %02x",octet);
96#endif
97 o.get_ostream().write(&octet,1);
98 last_caracter = octet;
99 chaine+=octet;
100 }
101#ifndef NDEBUG
102 fprintf(stderr," %02x",octet);
103#endif
104 o.get_ostream().write(&zero,1);
105#ifndef NDEBUG
106 Cerr << finl;
107 Cerr << " -> Read the string: " << chaine << finl;
108#endif
109 return last_caracter;
110}
111// Fonction qui verifie si on lit un binaire d'ICEM et si oui
112// cree un fichier compatible TRUST
113void check_ICEM_binary_file(Nom& filename, const Nom& nom_objet_lu)
114{
115 // On verifie que l'objet lu est un domaine
116 Objet_U& objet_lu = Interprete::objet(nom_objet_lu);
117 // [ABN] hmmmm ... hopefully the only place where we have this sort of things....:
118 if (!(objet_lu.que_suis_je()=="Domaine" || objet_lu.que_suis_je()=="Domaine")) return;
119
120 EFichierBin tmp(filename);
121 // Un fichier binaire ASCII est reconnaissable par le fait que le nom du
122 // domaine est suivi d'un espace donc l'octet est 32 (= 20 en hexa = space)
123 // Dans un binaire classique le nom du domaine est suivi par 0
124 char octet=(char)-1;
125 while(octet!=32 && octet!=0)
126 tmp.get_istream().read(&octet,1);
127 tmp.close();
128 if (octet==32) // C'est un fichier binaire ICEM
129 {
130 char zero=0;
131 Cerr << "==============================================" << finl;
132 Cerr << filename << " is an ICEM binary file." << finl;
133 Cerr << "To save space, you can now delete this file and use" << finl;
134 // Suppression de certains espaces du fichier binaire
135 Nom new_filename(filename);
136 new_filename+=".cleaned";
137 Cerr << "instead, the newly created " << new_filename << " file." << finl;
138 Cerr << "==============================================" << finl;
139 EFichierBin s(filename);
140 SFichierBin o(new_filename);
141 s.get_istream().read(&octet,1);
142 while(octet!=32)
143 {
144 o.get_ofstream().write(&octet,1);
145 s.get_istream().read(&octet,1);
146 }
147 // Ecriture de 00 a la place de 32
148 o.get_ostream().write(&zero,1);
149 // Ensuite on va jusqu'a l'entier 2
150 s.get_istream().read(&octet,1);
151 while(octet!=2)
152 s.get_istream().read(&octet,1);
153 // On revient en arriere et on peut commencer a lire le DoubleTab
154 s.get_istream().unget();
155 // Lecture des sommets
156 DoubleTab sommets;
157 s >> sommets;
158 o << sommets;
159 Cerr << "End of the read of the nodes." << finl;
160 // "{"
161 if (read_write_string_from(s,o,"{")!=123)
162 {
163 Cerr << "Error in is_a_ICEM_binary_file : { is waited." << finl;
165 }
166 // Nom du domaine
167 read_write_string_from(s,o,"");
168 // Lecture du type d'element
169 read_write_string_from(s,o,"T"); // TETRAEDRE
170 // Lecture des elements
171 IntTab elems;
172 s >> elems;
173 o << elems;
174 Cerr << "End of the read of the cells." << finl;
175 // Boucle sur les frontieres
176 // { : 7b en hexa, 123 en decimal
177 // , : 2C en hexa, 44 en decimal
178 // } : 7D en haxe, 125 en decimal
179 const char* sep="{";
180 while(read_write_string_from(s,o,sep)!=125)
181 {
182 // Nom de frontiere
183 read_write_string_from(s,o,"");
184 // Type de l'element
185 read_write_string_from(s,o,"T"); // TRIANGLE_3D
186 // Elements de la frontiere
187 s >> elems;
188 o << elems;
189 // Faces voisines
190 IntTab faces_voisins;
191 s >> faces_voisins;
192 o << faces_voisins;
193 Cerr << "End of the read of a boundary." << finl;
194 sep=""; // , ou } on ne peut savoir a l'avance...
195 }
196 // Lecture des 3 "vide"
197 for (int i=0; i<3; i++)
198 {
199 if (read_write_string_from(s,o,"v")!=101)
200 {
201 Cerr << "Error in is_a_ICEM_binary_file : 'vide' is waited." << finl;
203 }
204 }
205 // Lecture de }
206 if (read_write_string_from(s,o,"}")!=125)
207 {
208 Cerr << "Error in is_a_ICEM_binary_file : } is waited." << finl;
210 }
211 // Lecture du dernier "vide"
212 read_write_string_from(s,o,"v");
213 o.close();
214 s.close();
215 // On pointe vers le nouveau fichier
216 filename=new_filename;
217 Cerr << "=============================================" << finl;
218 Cerr << "You can use now: " << finl;
219 Cerr << "Lire_fichier " << nom_objet_lu << " "<< filename << finl;
220 Cerr << "=============================================" << finl;
221 }
222}
223
224void check_ICEM_ascii_file(const Nom& filename, const Lire_Fichier& keyword)
225{
226 Nom ICEM(filename);
227 if (ICEM.finit_par(".asc") && !sub_type(Read_unsupported_ASCII_file_from_ICEM,keyword))
228 {
229 Cerr << "Since the 1.6.7 version, the read of an ASCII file from ICEM mesh tool is not" << finl;
230 Cerr << "supported anymore cause insufficient number of digits to define the node coordinates." <<finl;
231 Cerr << "Please, use the TRUST binary export from ICEM." << finl;
233 }
234 else if (sub_type(Read_unsupported_ASCII_file_from_ICEM,keyword))
235 {
236 Cerr << "====================================================" << finl;
237 Cerr << "Warning: You are using an obsolete feature of TRUST" << finl;
238 Cerr << "with Unsupported_ASCII_file_read_from_ICEM keyword." << finl;
239 Cerr << "Use binary format for ICEM file!" << finl;
240 Cerr << "====================================================" << finl;
241 }
242}
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
virtual istream & get_istream()
Definition Entree.cpp:41
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
class Lire_Fichier Lecture d'un fichier
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
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
Ecriture dans un fichier d'objets ecrits au format binaire.
Definition SFichierBin.h:26
Classe de base des flux de sortie.
Definition Sortie.h:52
ostream & get_ostream()
Definition Sortie.h:64