~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to preprocessor/pre-post/ecs_pre_ens.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*============================================================================
 
2
 *  Définition de la fonction
 
3
 *   de lecture d'un fichier de maillage au format EnSight 6 ou EnSight Gold
 
4
 *============================================================================*/
 
5
 
 
6
/*
 
7
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
8
 
 
9
  Copyright (C) 1998-2011 EDF S.A.
 
10
 
 
11
  This program is free software; you can redistribute it and/or modify it under
 
12
  the terms of the GNU General Public License as published by the Free Software
 
13
  Foundation; either version 2 of the License, or (at your option) any later
 
14
  version.
 
15
 
 
16
  This program is distributed in the hope that it will be useful, but WITHOUT
 
17
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
18
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
19
  details.
 
20
 
 
21
  You should have received a copy of the GNU General Public License along with
 
22
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
23
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
24
*/
 
25
 
 
26
/*----------------------------------------------------------------------------*/
 
27
 
 
28
/*============================================================================
 
29
 *                                 Visibilité
 
30
 *============================================================================*/
 
31
 
 
32
/*----------------------------------------------------------------------------
 
33
 *  Fichiers `include' librairie standard C
 
34
 *----------------------------------------------------------------------------*/
 
35
 
 
36
#include <assert.h>
 
37
#include <stdlib.h>
 
38
#include <stdio.h>
 
39
#include <string.h>
 
40
 
 
41
 
 
42
/*----------------------------------------------------------------------------
 
43
 *  Fichiers `include' visibles du  paquetage global "Utilitaire"
 
44
 *----------------------------------------------------------------------------*/
 
45
 
 
46
#include "ecs_def.h"
 
47
#include "ecs_elt_typ_liste.h"
 
48
#include "ecs_file.h"
 
49
#include "ecs_mem.h"
 
50
#include "ecs_tab.h"
 
51
 
 
52
 
 
53
/*----------------------------------------------------------------------------
 
54
 *  Fichiers `include' visibles des paquetages visibles
 
55
 *----------------------------------------------------------------------------*/
 
56
 
 
57
#include "ecs_descr.h"
 
58
#include "ecs_descr_chaine.h"
 
59
#include "ecs_maillage.h"
 
60
#include "ecs_maillage_priv.h"
 
61
 
 
62
 
 
63
/*----------------------------------------------------------------------------
 
64
 *  Fichiers `include' visibles du  paquetage courant
 
65
 *----------------------------------------------------------------------------*/
 
66
 
 
67
#include "ecs_maillage_pre.h"
 
68
 
 
69
 
 
70
/*----------------------------------------------------------------------------
 
71
 *  Fichier  `include' du  paquetage courant associe au fichier courant
 
72
 *----------------------------------------------------------------------------*/
 
73
 
 
74
#include "ecs_pre_ens.h"
 
75
 
 
76
 
 
77
/*----------------------------------------------------------------------------
 
78
 *  Fichiers `include' privés   du  paquetage courant
 
79
 *----------------------------------------------------------------------------*/
 
80
 
 
81
 
 
82
/*============================================================================
 
83
 *                    Déclaration de paramètres et macros
 
84
 *============================================================================*/
 
85
 
 
86
/* Pour une lecture de 80 caracteres par ligne  */
 
87
/* auxquels il faut ajouter le `\n' et le `\0'  */
 
88
/* pour l'affectation dans la chaîne réceptrice */
 
89
#define ECS_LOC_LNG_MAX_CHAINE_ENS  82
 
90
 
 
91
 
 
92
/*============================================================================
 
93
 *                  Définition de structures locales
 
94
 *============================================================================*/
 
95
 
 
96
/* Définition de noeuds */
 
97
 
 
98
typedef struct {
 
99
  ecs_int_t        nbr_noeuds;  /* Nombre de noeuds */
 
100
  ecs_int_t       *id_noeud;    /* Labels des noeuds */
 
101
  ecs_coord_t     *coord;       /* Coordonnées (entrelacées) */
 
102
  ecs_int_t        num_part;    /* Numéro de part associé */
 
103
} ecs_loc_noeuds_ens_t;
 
104
 
 
105
 
 
106
/* Définition de connectivités */
 
107
 
 
108
typedef struct {
 
109
  ecs_int_t        nbr_ele;   /* Nombre d'éléments */
 
110
  ecs_elt_typ_t    elt_typ;   /* Type d'élément */
 
111
  int32_t         *nbr_n;     /* Nbr. sommets/faces (polygones/polyèdres) */
 
112
  int32_t         *nbr_f;     /* Nbr. faces/elem (polyèdres) */
 
113
  int32_t         *connect;   /* Connectivité sommets */
 
114
  int              num_part;  /* Numéro de part associé */
 
115
} ecs_loc_elems_ens_t;
 
116
 
 
117
 
 
118
/*============================================================================
 
119
 *                              Fonctions privées
 
120
 *============================================================================*/
 
121
 
 
122
/*----------------------------------------------------------------------------
 
123
 * Ouverture et détermination du type du fichier geo
 
124
 *----------------------------------------------------------------------------*/
 
125
 
 
126
static ecs_file_t *
 
127
ecs_loc_pre_ens__ouverture_fic_geo(const char  *nom_fic_geo)
 
128
{
 
129
  ecs_file_t   *fic;
 
130
  ecs_int_t  nbr_char_lus;
 
131
 
 
132
  char  chaine[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
133
 
 
134
  int32_t  test_endian;
 
135
 
 
136
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
137
 
 
138
  /* Ouverture du fichier Géométrie et vérification du format */
 
139
  /*----------------------------------------------------------*/
 
140
 
 
141
  fic = ecs_file_open(nom_fic_geo,
 
142
                      ECS_FILE_MODE_READ,
 
143
                      ECS_FILE_TYPE_BINARY);
 
144
 
 
145
  /* Par défaut, on suppose un fichier binaire C */
 
146
 
 
147
  nbr_char_lus = ecs_file_read_try(chaine, sizeof(char), 80, fic);
 
148
 
 
149
  /* Si le fichier est trop court pour contenir l'entête binaire, c'est au
 
150
     mieux un fichier texte */
 
151
 
 
152
  if (nbr_char_lus < 80) {
 
153
 
 
154
    ecs_file_set_type(fic, ECS_FILE_TYPE_TEXT);
 
155
 
 
156
    ecs_file_rewind(fic);
 
157
 
 
158
  }
 
159
 
 
160
  /* Pour un fichier binaire Fortran, les 4 premiers octets correspondent à
 
161
     la taille de l'enregistrement, et le contenu vient après -> on décale */
 
162
 
 
163
  else if (strncmp(chaine + 4,
 
164
                   "Fortran Binary",
 
165
                   strlen("Fortran Binary")) == 0) {
 
166
 
 
167
    ecs_file_set_type(fic, ECS_FILE_TYPE_FORTRAN_BINARY);
 
168
 
 
169
    test_endian = *((int32_t *)chaine);
 
170
 
 
171
    if (test_endian == 80)
 
172
      ecs_file_set_swap_endian(fic, 0);
 
173
 
 
174
    else{
 
175
      ecs_file_swap_endian(&test_endian, &test_endian, 4, 1);
 
176
      if (test_endian == 80)
 
177
        ecs_file_set_swap_endian(fic, 1);
 
178
 
 
179
      else
 
180
        ecs_error(__FILE__, __LINE__, 0,
 
181
                  _("EnSight: file \"%s\" seems to be\n"
 
182
                    "of Fortran binary type but its header is of the wrong\n"
 
183
                    "size or it is of an unknown Fortran binary variant."),
 
184
                  ecs_file_get_name(fic));
 
185
    }
 
186
 
 
187
    /* On se replace après l'entête "Fortran Binary" */
 
188
 
 
189
    ecs_file_rewind(fic);
 
190
    ecs_file_read(chaine, sizeof(char), 80, fic);
 
191
 
 
192
  }
 
193
 
 
194
  /* Si le fichier est binaire, on vérifiera plus tard l'aspect
 
195
     "big-endian/little-endian" */
 
196
 
 
197
  else if (strncmp(chaine, "C Binary", strlen("C Binary") != 0)) {
 
198
 
 
199
    ecs_file_set_type(fic, ECS_FILE_TYPE_TEXT);
 
200
 
 
201
    ecs_file_rewind(fic);
 
202
 
 
203
  }
 
204
 
 
205
  return fic;
 
206
}
 
207
 
 
208
/*----------------------------------------------------------------------------
 
209
 *  Lecture d'une chaîne de caractères dans un fichier géométrique EnSight.
 
210
 *  Comme les chaînes à lire ne dépassent jamais 80 caractères, on
 
211
 *  pourra utiliser un tampon statique.
 
212
 *----------------------------------------------------------------------------*/
 
213
 
 
214
static void
 
215
ecs_loc_pre_ens__lit_chaine(const ecs_file_t  *fic_geo,
 
216
                            char   ligne[ECS_LOC_LNG_MAX_CHAINE_ENS],
 
217
                            int   *num_ligne)
 
218
{
 
219
  size_t ind;
 
220
 
 
221
  if (ecs_file_get_type(fic_geo) != ECS_FILE_TYPE_TEXT) {
 
222
 
 
223
    ecs_file_read(ligne, sizeof(char), 80, fic_geo);
 
224
    ligne[80] = '\0';
 
225
 
 
226
  }
 
227
  else {
 
228
 
 
229
    ecs_file_gets(ligne, ECS_LOC_LNG_MAX_CHAINE_ENS, fic_geo, num_ligne);
 
230
 
 
231
    for (ind = strlen(ligne) - 1;
 
232
         ind > 0 && (ligne[ind] == '\n' || ligne[ind] == '\r');
 
233
         ind--);
 
234
    ligne[ind + 1] = '\0';
 
235
 
 
236
  }
 
237
 
 
238
}
 
239
 
 
240
/*----------------------------------------------------------------------------
 
241
 *  Lecture d'une chaîne de caractères dans un fichier géométrique EnSight.
 
242
 *  Comme les chaînes à lire ne dépassent jamais 80 caractères, on
 
243
 *  pourra utiliser un tampon statique.
 
244
 *  Dans le cas d'un fichier binaire, les chaines à lire sont toujours
 
245
 *  exactement de longueur 80 caractères.
 
246
 *  Si l'on ne peut lire une chaîne (i.e. fin de fichier), on renvoie NULL;
 
247
 *  Sinon, on renvoie un pointeur sur "ligne".
 
248
 *----------------------------------------------------------------------------*/
 
249
 
 
250
static char *
 
251
ecs_loc_pre_ens__lit_chaine_essai(const ecs_file_t  *fic_geo,
 
252
                                  char ligne[ECS_LOC_LNG_MAX_CHAINE_ENS] ,
 
253
                                  int *num_ligne)
 
254
{
 
255
  char   *ret;
 
256
  size_t  ind;
 
257
 
 
258
  if (ecs_file_get_type(fic_geo) != ECS_FILE_TYPE_TEXT) {
 
259
 
 
260
    if (ecs_file_read_try(ligne, sizeof(char), 80, fic_geo) == 80) {
 
261
      ligne[80] = '\0';
 
262
      ret = ligne;
 
263
    }
 
264
    else
 
265
      ret = NULL;
 
266
 
 
267
  }
 
268
  else {
 
269
 
 
270
    ret = ecs_file_gets_try(ligne, ECS_LOC_LNG_MAX_CHAINE_ENS,
 
271
                            fic_geo, num_ligne);
 
272
 
 
273
    if (ret != NULL) {
 
274
 
 
275
      for (ind = strlen(ligne) - 1;
 
276
           ind > 0 && (ligne[ind] == '\n' || ligne[ind] == '\r');
 
277
           ind--);
 
278
      ligne[ind + 1] = '\0';
 
279
 
 
280
    }
 
281
 
 
282
  }
 
283
 
 
284
  return ret;
 
285
}
 
286
 
 
287
/*----------------------------------------------------------------------------
 
288
 *  Lecture d'un tableau d'entiers dans un fichier géométrique EnSight Gold.
 
289
 *  Si le tableau val est fourni en argument, on le suppose bien dimensionné
 
290
 *  et on le remplit; sinon, si val est à NULL, on alloue un tableau.
 
291
 *  On renvoie un pointeur sur le tableau utilisé, qu'il soit fourni en
 
292
 *  argument ou alloué ici. Dans ce dernier cas, l'utilisateur aura la
 
293
 *  responsabilité de le libérer.
 
294
 *----------------------------------------------------------------------------*/
 
295
 
 
296
static int32_t *
 
297
ecs_loc_pre_ens__lit_int(const ecs_file_t  *fic_geo,
 
298
                         ecs_int_t          nbr,
 
299
                         int32_t           *val,
 
300
                         const int          l_format,
 
301
                         int               *num_ligne)
 
302
{
 
303
  char         ligne[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
304
  char         sub[11];
 
305
  ecs_int_t    pos_ligne;
 
306
  int          ic;
 
307
  int          val_lue;
 
308
 
 
309
  ecs_int_t    cpt_lus = 0;
 
310
  int32_t    * val_loc = val;
 
311
 
 
312
  assert(l_format <= 10);
 
313
 
 
314
  if (val_loc == NULL)
 
315
    ECS_MALLOC(val_loc, nbr, int32_t);
 
316
 
 
317
 
 
318
  if (ecs_file_get_type(fic_geo) != ECS_FILE_TYPE_TEXT)
 
319
    ecs_file_read(val_loc, sizeof(int32_t), nbr, fic_geo);
 
320
 
 
321
  else {
 
322
 
 
323
    sub[l_format] = '\0';
 
324
 
 
325
    ic = 0;
 
326
 
 
327
    while (cpt_lus < nbr) {
 
328
 
 
329
      ecs_file_gets(ligne,
 
330
                    ECS_LOC_LNG_MAX_CHAINE_ENS,
 
331
                    fic_geo,
 
332
                    num_ligne);
 
333
 
 
334
      /* éventuellement plusieurs valeurs sur la ligne */
 
335
 
 
336
      pos_ligne = 0;
 
337
 
 
338
      while (   cpt_lus < nbr
 
339
             && (   ligne[pos_ligne] != '\0'
 
340
                 && ligne[pos_ligne] != '\n'
 
341
                 && ligne[pos_ligne] != '\r')) {
 
342
        sub[ic] = ligne[pos_ligne];
 
343
        ic++;
 
344
        pos_ligne++;
 
345
        if (ic == l_format) {
 
346
          val_lue = atoi(sub);
 
347
          val_loc[cpt_lus] = (int32_t)val_lue;
 
348
          cpt_lus++;
 
349
          ic = 0;
 
350
        }
 
351
      }
 
352
 
 
353
    }
 
354
 
 
355
  }
 
356
 
 
357
  return val_loc;
 
358
}
 
359
 
 
360
/*----------------------------------------------------------------------------
 
361
 *  Lecture d'un tableau de réels dans un fichier géométrique EnSight.
 
362
 *  Si le tableau val est fourni en argument, on le suppose bien dimensionné
 
363
 *  et on le remplit ; sinon, si val est à NULL, on alloue un tableau.
 
364
 *  On renvoie un pointeur sur le tableau utilisé, qu'il soit fourni en
 
365
 *  argument ou alloué ici. Dans ce dernier cas, l'utilisateur aura la
 
366
 *  responsabilité de le libérer.
 
367
 *----------------------------------------------------------------------------*/
 
368
 
 
369
static float *
 
370
ecs_loc_pre_ens__lit_float(const ecs_file_t  *fic_geo,
 
371
                           ecs_int_t          nbr,
 
372
                           float             *val,
 
373
                           int               *num_ligne)
 
374
{
 
375
  char         ligne[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
376
  char         sub[13];
 
377
  ecs_int_t    pos_ligne;
 
378
  int          ic;
 
379
  float        val_lue;
 
380
 
 
381
  const int        l_format = 12;
 
382
 
 
383
  ecs_int_t        cpt_lus = 0;
 
384
  float  * val_loc = val;
 
385
 
 
386
  if (val_loc == NULL)
 
387
    ECS_MALLOC(val_loc, nbr, float);
 
388
 
 
389
  if (ecs_file_get_type(fic_geo) != ECS_FILE_TYPE_TEXT)
 
390
    ecs_file_read(val_loc, sizeof(float), nbr, fic_geo);
 
391
 
 
392
  else {
 
393
 
 
394
    sub[l_format] = '\0';
 
395
 
 
396
    ic = 0;
 
397
 
 
398
    while (cpt_lus < nbr) {
 
399
 
 
400
      ecs_file_gets(ligne,
 
401
                    ECS_LOC_LNG_MAX_CHAINE_ENS,
 
402
                    fic_geo,
 
403
                    num_ligne);
 
404
 
 
405
      /* éventuellement plusieurs valeurs sur la ligne */
 
406
 
 
407
      pos_ligne = 0;
 
408
 
 
409
      while (   cpt_lus < nbr
 
410
             && (   ligne[pos_ligne] != '\0'
 
411
                 && ligne[pos_ligne] != '\n'
 
412
                 && ligne[pos_ligne] != '\r')) {
 
413
        sub[ic] = ligne[pos_ligne];
 
414
        ic++;
 
415
        pos_ligne++;
 
416
        if (ic == l_format) {
 
417
          val_lue = atof(sub);
 
418
          val_loc[cpt_lus] = (float)val_lue;
 
419
          cpt_lus++;
 
420
          ic = 0;
 
421
        }
 
422
      }
 
423
 
 
424
    }
 
425
 
 
426
  }
 
427
 
 
428
  return val_loc;
 
429
}
 
430
 
 
431
/*----------------------------------------------------------------------------
 
432
 *  Lecture d'un tableau de coordonnées dans un fichier géométrique EnSight 6
 
433
 *  (ids et coordonnées mixtes en mode texte : 1 entier et 3 réels par ligne) .
 
434
 *  Les tableaux val_id et val_coord sont supposés bien dimensionnés
 
435
 *  (val_id étant optionnel).
 
436
 *----------------------------------------------------------------------------*/
 
437
 
 
438
static void
 
439
ecs_loc_pre_ens__lit_tab_coo_6(const ecs_file_t  *fic_geo,
 
440
                               ecs_int_t          nbr_lignes,
 
441
                               int32_t           *val_id,
 
442
                               float             *val_coord,
 
443
                               int               *num_ligne)
 
444
{
 
445
  char         ligne[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
446
  char         sub[13];
 
447
  ecs_int_t    pos_ligne;
 
448
  int          ic;
 
449
  int          icoo;
 
450
 
 
451
  int          l_format_int = 8;
 
452
  int          l_format_real = 12;
 
453
  ecs_int_t    cpt_lignes_lues = 0;
 
454
 
 
455
  if (ecs_file_get_type(fic_geo) != ECS_FILE_TYPE_TEXT) {
 
456
 
 
457
    /* Dans le cas binaire, les tableaux des id (entiers) et coordonnées
 
458
       (réels) ne sont pas entrelacés */
 
459
 
 
460
    if (val_id != NULL)
 
461
      ecs_file_read(val_id, sizeof(int32_t), nbr_lignes, fic_geo);
 
462
 
 
463
    ecs_file_read(val_coord, sizeof(float), nbr_lignes * 3, fic_geo);
 
464
 
 
465
  }
 
466
  else {
 
467
 
 
468
    sub[l_format_real] = '\0';
 
469
 
 
470
    while (cpt_lignes_lues < nbr_lignes) {
 
471
 
 
472
      ecs_file_gets(ligne,
 
473
                    ECS_LOC_LNG_MAX_CHAINE_ENS,
 
474
                    fic_geo,
 
475
                    num_ligne);
 
476
 
 
477
      pos_ligne = 0;
 
478
 
 
479
      if (val_id != NULL) {
 
480
        for (ic = 0; ic < l_format_int; ic++)
 
481
          sub[ic] = ligne[pos_ligne++];
 
482
        sub[l_format_int] = '\0';
 
483
        val_id[cpt_lignes_lues] = (int32_t)(atoi(sub));
 
484
      }
 
485
 
 
486
      sub[l_format_real] = '\0';
 
487
      for (icoo = 0; icoo < 3; icoo++) {
 
488
        for (ic = 0; ic < l_format_real; ic++)
 
489
          sub[ic] = ligne[pos_ligne++];
 
490
        val_coord[cpt_lignes_lues*3 + icoo] = (float)(atof(sub));
 
491
      }
 
492
 
 
493
      cpt_lignes_lues++;
 
494
 
 
495
    }
 
496
  }
 
497
}
 
498
 
 
499
/*----------------------------------------------------------------------------
 
500
 *  Lecture d'un tableau de connectivités dans un fichier géométrique
 
501
 *  EnSight 6 (ids et connectivités mixtes en mode texte) .
 
502
 *  Les tableaux val_id et val_connect sont supposés bien dimensionnés.
 
503
 *----------------------------------------------------------------------------*/
 
504
 
 
505
static void
 
506
ecs_loc_pre_ens__lit_tab_connect(const ecs_file_t  *fic_geo,
 
507
                                 ecs_int_t          nbr_lignes,
 
508
                                 bool               lit_id,
 
509
                                 ecs_int_t          nbr_som_elt,
 
510
                                 int32_t           *val_id,
 
511
                                 int32_t           *val_connect,
 
512
                                 int               *num_ligne)
 
513
{
 
514
  char         ligne[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
515
  char         sub[9];
 
516
  ecs_int_t    pos_ligne;
 
517
  ecs_int_t    cpt_val_ligne;
 
518
  ecs_int_t    cpt_som_ligne;
 
519
  int          ic;
 
520
  int          val_lue;
 
521
 
 
522
  int          l_format = 8;
 
523
  ecs_int_t    cpt_lignes_lues = 0;
 
524
 
 
525
  if (ecs_file_get_type(fic_geo) != ECS_FILE_TYPE_TEXT) {
 
526
 
 
527
    /* Dans le cas binaire, les tableaux des id et les connectivités
 
528
       ne sont pas entrelacés */
 
529
 
 
530
    if (lit_id == true)
 
531
      ecs_file_read(val_id, sizeof(int32_t), nbr_lignes, fic_geo);
 
532
 
 
533
    ecs_file_read(val_connect, sizeof(int32_t),
 
534
                  nbr_lignes * nbr_som_elt, fic_geo);
 
535
 
 
536
  }
 
537
  else {
 
538
 
 
539
    sub[l_format] = '\0';
 
540
 
 
541
    cpt_som_ligne = 0;
 
542
    cpt_val_ligne = 0;
 
543
    ic = 0;
 
544
 
 
545
    while (cpt_lignes_lues < nbr_lignes) { /* Lignes entières, peuvent être
 
546
                                              lues via plusieurs appels à
 
547
                                              ecs_file_gets si plus
 
548
                                              de 80 caractères */
 
549
 
 
550
      ecs_file_gets(ligne,
 
551
                    ECS_LOC_LNG_MAX_CHAINE_ENS,
 
552
                    fic_geo,
 
553
                    num_ligne);
 
554
 
 
555
      /* éventuellement plusieurs valeurs sur la ligne */
 
556
 
 
557
      pos_ligne = 0;
 
558
 
 
559
      while (   cpt_lignes_lues < nbr_lignes
 
560
             && (   ligne[pos_ligne] != '\0'
 
561
                 && ligne[pos_ligne] != '\n'
 
562
                 && ligne[pos_ligne] != '\r')) {
 
563
 
 
564
        sub[ic] = ligne[pos_ligne];
 
565
        ic++;
 
566
        pos_ligne++;
 
567
 
 
568
        if (ic == l_format) {
 
569
 
 
570
          val_lue = atoi(sub);
 
571
 
 
572
          if (lit_id == true && cpt_val_ligne == 0)
 
573
            val_id[cpt_lignes_lues] = (int32_t)val_lue;
 
574
          else {
 
575
            val_connect[cpt_lignes_lues*nbr_som_elt + cpt_som_ligne]
 
576
              = (int32_t)val_lue;
 
577
            cpt_som_ligne++;
 
578
          }
 
579
 
 
580
          if (cpt_som_ligne == nbr_som_elt) {
 
581
            cpt_val_ligne = 0;
 
582
            cpt_som_ligne = 0;
 
583
            cpt_lignes_lues++;
 
584
          }
 
585
          else
 
586
            cpt_val_ligne++;
 
587
 
 
588
          ic = 0;
 
589
 
 
590
        }
 
591
      }
 
592
    }
 
593
  }
 
594
}
 
595
 
 
596
/*----------------------------------------------------------------------------
 
597
 *  Lecture des noeuds au format EnSight Gold ;
 
598
 *----------------------------------------------------------------------------*/
 
599
 
 
600
static void
 
601
ecs_loc_pre_ens__lit_noeuds_gold(ecs_file_t             *fic,
 
602
                                 ecs_int_t               num_part,
 
603
                                 bool                    lire_id_noeud,
 
604
                                 bool                    importer_part,
 
605
                                 ecs_int_t              *taille_noeuds,
 
606
                                 ecs_loc_noeuds_ens_t  **noeuds,
 
607
                                 char                    chaine[],
 
608
                                 int                    *num_ligne)
 
609
{
 
610
 
 
611
  ecs_int_t     ind;
 
612
  ecs_int_t     ind_coo;
 
613
  ecs_int_t     nbr_noeuds;
 
614
 
 
615
  int32_t       val_int_lue;
 
616
 
 
617
  ecs_loc_noeuds_ens_t  *noeuds_loc;
 
618
 
 
619
  int32_t      *id_noeud_loc = NULL;
 
620
  ecs_int_t    *id_noeud_tmp = NULL;
 
621
  float        *coord_loc    = NULL;
 
622
  ecs_coord_t  *coord_tmp    = NULL;
 
623
 
 
624
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
625
 
 
626
  ecs_loc_pre_ens__lit_chaine(fic, chaine, num_ligne);
 
627
 
 
628
  if (strncmp(chaine, "coordinates", strlen("coordinates")) != 0)
 
629
    ecs_error(__FILE__, __LINE__, 0,
 
630
              _("EnSight: field \"%s\" encountered where\n"
 
631
                "\"coordinates\" was expected."), chaine);
 
632
 
 
633
  ecs_loc_pre_ens__lit_int(fic, 1, &val_int_lue, 10, num_ligne);
 
634
 
 
635
  nbr_noeuds = val_int_lue;
 
636
 
 
637
  printf(_("    %10d nodes\n"), (int)nbr_noeuds);
 
638
 
 
639
  /* Lecture des labels s'il y a lieu */
 
640
 
 
641
  if (lire_id_noeud == true)
 
642
    id_noeud_loc = ecs_loc_pre_ens__lit_int(fic, nbr_noeuds,
 
643
                                            NULL, 10, num_ligne);
 
644
 
 
645
  /* Lecture des coordonnées */
 
646
 
 
647
  coord_loc = ecs_loc_pre_ens__lit_float(fic, nbr_noeuds * 3,
 
648
                                         NULL, num_ligne);
 
649
 
 
650
  if (importer_part == true) {
 
651
 
 
652
    ECS_REALLOC(*noeuds, (*taille_noeuds) + 1, ecs_loc_noeuds_ens_t);
 
653
 
 
654
    noeuds_loc = (*noeuds) + (*taille_noeuds);
 
655
 
 
656
    *taille_noeuds += 1;
 
657
 
 
658
    /* Conversion des id noeuds */
 
659
 
 
660
    if (id_noeud_loc == NULL || sizeof(int32_t) == sizeof(ecs_int_t))
 
661
      id_noeud_tmp = (ecs_int_t *)id_noeud_loc;
 
662
 
 
663
    else {
 
664
      ECS_MALLOC(id_noeud_tmp, nbr_noeuds, ecs_int_t);
 
665
      for (ind = 0; ind < nbr_noeuds; ind++)
 
666
        id_noeud_tmp[ind] = id_noeud_loc[ind];
 
667
      ECS_FREE(id_noeud_loc);
 
668
    }
 
669
 
 
670
    /* Entrelacage des coordonnées */
 
671
 
 
672
    ECS_MALLOC(coord_tmp, nbr_noeuds*3, ecs_coord_t);
 
673
 
 
674
    for (ind = 0; ind < nbr_noeuds; ind++) {
 
675
      for (ind_coo = 0; ind_coo < 3; ind_coo++)
 
676
        coord_tmp[ind*3 + ind_coo] = coord_loc[nbr_noeuds*ind_coo + ind];
 
677
    }
 
678
 
 
679
    ECS_FREE(coord_loc);
 
680
 
 
681
    noeuds_loc->nbr_noeuds = (ecs_int_t)nbr_noeuds;
 
682
    noeuds_loc->id_noeud   = id_noeud_tmp;
 
683
    noeuds_loc->coord      = coord_tmp;
 
684
    noeuds_loc->num_part   = num_part;
 
685
 
 
686
  }
 
687
  else {
 
688
 
 
689
    ECS_FREE(coord_loc);
 
690
    ECS_FREE(id_noeud_loc);
 
691
 
 
692
  }
 
693
}
 
694
 
 
695
/*----------------------------------------------------------------------------
 
696
 *  Lecture des noeuds au format EnSight 6 ;
 
697
 *----------------------------------------------------------------------------*/
 
698
 
 
699
static void
 
700
ecs_loc_pre_ens__lit_noeuds_6(ecs_file_t             *fic,
 
701
                              bool                    lire_id_noeud,
 
702
                              ecs_int_t              *taille_noeuds,
 
703
                              ecs_loc_noeuds_ens_t  **noeuds,
 
704
                              char                    chaine[],
 
705
                              int                    *num_ligne)
 
706
{
 
707
  ecs_int_t    ind;
 
708
  ecs_int_t    nbr_noeuds;
 
709
 
 
710
  int32_t      val_int_lue;
 
711
 
 
712
  int32_t       *id_noeud_loc = NULL;
 
713
  ecs_int_t     *id_noeud_tmp = NULL;
 
714
  float         *coord_loc    = NULL;
 
715
  ecs_coord_t   *coord_tmp    = NULL;
 
716
 
 
717
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
718
 
 
719
  ecs_loc_pre_ens__lit_chaine(fic, chaine, num_ligne);
 
720
 
 
721
  if (strncmp(chaine, "coordinates", strlen("coordinates")) != 0)
 
722
    ecs_error(__FILE__, __LINE__, 0,
 
723
              _("EnSight: field \"%s\" encountered where\n"
 
724
                "\"coordinates\" was expected."), chaine);
 
725
 
 
726
  ecs_loc_pre_ens__lit_int(fic, 1, &val_int_lue, 8, num_ligne);
 
727
 
 
728
  nbr_noeuds = val_int_lue;
 
729
 
 
730
  if (lire_id_noeud == true)
 
731
    ECS_MALLOC(id_noeud_loc, nbr_noeuds,  int32_t);
 
732
  else
 
733
    id_noeud_loc = NULL;
 
734
 
 
735
  ECS_MALLOC(coord_loc, nbr_noeuds*3,  float);
 
736
 
 
737
  ecs_loc_pre_ens__lit_tab_coo_6(fic,
 
738
                                 nbr_noeuds ,
 
739
                                 id_noeud_loc ,
 
740
                                 coord_loc ,
 
741
                                 num_ligne);
 
742
 
 
743
  if (coord_loc != NULL) {
 
744
    *taille_noeuds = 1;
 
745
    ECS_MALLOC(*noeuds, (*taille_noeuds),  ecs_loc_noeuds_ens_t);
 
746
  }
 
747
  else
 
748
    ecs_error(__FILE__, __LINE__, 0,
 
749
              _("EnSight: no node defined in file\n\"%s\"."),
 
750
              ecs_file_get_name(fic));
 
751
 
 
752
  /* Conversion des id noeuds */
 
753
 
 
754
  if (id_noeud_loc == NULL || sizeof(int32_t) == sizeof(ecs_int_t))
 
755
    id_noeud_tmp = (ecs_int_t *)id_noeud_loc;
 
756
 
 
757
  else {
 
758
    ECS_MALLOC(id_noeud_tmp, nbr_noeuds, ecs_int_t);
 
759
    for (ind = 0; ind < nbr_noeuds; ind++)
 
760
      id_noeud_tmp[ind] = id_noeud_loc[ind];
 
761
    ECS_FREE(id_noeud_loc);
 
762
  }
 
763
 
 
764
  /* Conversion des coordonnées */
 
765
 
 
766
  ECS_MALLOC(coord_tmp, nbr_noeuds*3, ecs_coord_t);
 
767
 
 
768
  for (ind = 0; ind < 3*nbr_noeuds; ind++) {
 
769
    coord_tmp[ind] = coord_loc[ind];
 
770
  }
 
771
 
 
772
  ECS_FREE(coord_loc);
 
773
 
 
774
  (*noeuds)->nbr_noeuds = (ecs_int_t)nbr_noeuds;
 
775
  (*noeuds)->id_noeud   = id_noeud_tmp;
 
776
  (*noeuds)->coord      = coord_tmp;
 
777
  (*noeuds)->num_part   =  -1;
 
778
}
 
779
 
 
780
/*----------------------------------------------------------------------------
 
781
 * Retourne le type de l'élément ainsi que son nombre de sommet
 
782
 *----------------------------------------------------------------------------*/
 
783
 
 
784
static void
 
785
ecs_loc_pre_ens__type_elem(ecs_file_t     *fic,
 
786
                           const char      chaine[],
 
787
                           int            *nbr_som_elt,
 
788
                           ecs_elt_typ_t  *elt_typ)
 
789
{
 
790
  /*----------------------------*/
 
791
  /* Décodage du type d'élément */
 
792
  /*----------------------------*/
 
793
 
 
794
  if (strncmp(chaine, "g_", strlen("g_")) == 0)
 
795
    ecs_error(__FILE__, __LINE__, 0,
 
796
              _("EnSight: error reading file \"%s\".\n"
 
797
                "The current \"part\" contains ghost cells,\n"
 
798
                "not currently handled."),
 
799
              ecs_file_get_name(fic));
 
800
 
 
801
  else if (strncmp(chaine, "bar", strlen("bar")) == 0) {
 
802
    *elt_typ         = ECS_ELT_TYP_NUL;
 
803
    *nbr_som_elt     = atoi(chaine+strlen("bar"));
 
804
  }
 
805
  else if (strncmp(chaine, "tria", strlen("tria")) == 0) {
 
806
    *elt_typ         = ECS_ELT_TYP_FAC_TRIA;
 
807
    *nbr_som_elt     = atoi(chaine+strlen("tria"));
 
808
  }
 
809
  else if (strncmp(chaine, "quad", strlen("quad")) == 0) {
 
810
    *elt_typ         = ECS_ELT_TYP_FAC_QUAD;
 
811
    *nbr_som_elt     = atoi(chaine+strlen("quad"));
 
812
  }
 
813
  else if (strncmp(chaine, "tetra", strlen("tetra")) == 0) {
 
814
    *elt_typ         = ECS_ELT_TYP_CEL_TETRA;
 
815
    *nbr_som_elt     = atoi(chaine+strlen("tetra"));
 
816
  }
 
817
  else if (strncmp(chaine, "pyramid", strlen("pyramid")) == 0) {
 
818
    *elt_typ         = ECS_ELT_TYP_CEL_PYRAM;
 
819
    *nbr_som_elt     = atoi(chaine+strlen("pyramid"));
 
820
  }
 
821
  else if (strncmp(chaine, "penta", strlen("penta")) == 0) {
 
822
    *elt_typ         = ECS_ELT_TYP_CEL_PRISM;
 
823
    *nbr_som_elt     = atoi(chaine+strlen("penta"));
 
824
  }
 
825
  else if (strncmp(chaine, "hexa", strlen("hexa")) == 0) {
 
826
    *elt_typ         = ECS_ELT_TYP_CEL_HEXA;
 
827
    *nbr_som_elt     = atoi(chaine+strlen("hexa"));
 
828
  }
 
829
  else if (strncmp(chaine, "nsided", strlen("nsided")) == 0) {
 
830
    *elt_typ         = ECS_ELT_TYP_FAC_POLY;
 
831
    *nbr_som_elt     = 0;
 
832
  }
 
833
  else if (strncmp(chaine, "nfaced", strlen("nfaced")) == 0) {
 
834
    *elt_typ         = ECS_ELT_TYP_CEL_POLY;
 
835
    *nbr_som_elt     = 0;
 
836
  }
 
837
  else {
 
838
    ecs_error(__FILE__, __LINE__, 0,
 
839
              _("EnSight: error reading file \"%s\".\n"
 
840
                "The current \"part\" contains a section of type:\n"
 
841
                "\"%s\"\n"
 
842
                "not currently handled."),
 
843
              ecs_file_get_name(fic), chaine);
 
844
  }
 
845
}
 
846
 
 
847
/*----------------------------------------------------------------------------
 
848
 * Transformation des éléments en éléments linéaires.
 
849
 * Cette fonction renvoie un pointeur sur le tableau de connectivité réalloué.
 
850
 *----------------------------------------------------------------------------*/
 
851
 
 
852
static int32_t *
 
853
ecs_loc_pre_ens__ele_lin(int32_t     *connect_loc,
 
854
                         ecs_int_t    nbr_ele,
 
855
                         ecs_int_t    taille_ele,
 
856
                         ecs_int_t    taille_ele_lin)
 
857
{
 
858
  ecs_int_t    ielt;
 
859
  ecs_int_t    iloc;
 
860
  ecs_int_t    ipos_lin;
 
861
  ecs_int_t    ipos_ens;
 
862
 
 
863
  ipos_lin = 0;
 
864
 
 
865
  for (ielt = 0; ielt < nbr_ele; ielt++) {
 
866
 
 
867
    ipos_ens = ielt * taille_ele;
 
868
 
 
869
    for (iloc = 0; iloc < taille_ele_lin; iloc++)
 
870
      connect_loc[ipos_lin++] = connect_loc[ipos_ens++];
 
871
 
 
872
    ECS_REALLOC(connect_loc, ipos_lin, int32_t);
 
873
  }
 
874
 
 
875
  return connect_loc;
 
876
}
 
877
 
 
878
/*----------------------------------------------------------------------------
 
879
 * Lecture des éléments format EnSight Gold; renvoie le nombre d'éléments lus,
 
880
 * ou -1 si l'on a affaire à une "part"
 
881
 *----------------------------------------------------------------------------*/
 
882
 
 
883
static ecs_int_t
 
884
ecs_loc_pre_ens__lit_elem_gold(ecs_file_t                   *fic,
 
885
                               ecs_int_t                     num_part,
 
886
                               bool                          lire_id_elem,
 
887
                               bool                          importer_part,
 
888
                               const ecs_loc_noeuds_ens_t   *noeuds,
 
889
                               ecs_int_t                    *taille_elems,
 
890
                               ecs_loc_elems_ens_t         **elems,
 
891
                               char                          chaine[],
 
892
                               int                          *num_ligne)
 
893
{
 
894
  int            nbr_som_elt;
 
895
 
 
896
  ecs_int_t      ind;
 
897
  ecs_int_t      nbr_som_elt_lin;
 
898
  ecs_int_t      taille_connect;
 
899
  ecs_int_t      taille_lect;
 
900
 
 
901
  ecs_elt_typ_t   elt_typ;
 
902
 
 
903
  int32_t     * id_elem;
 
904
 
 
905
  ecs_loc_elems_ens_t  *elems_loc;
 
906
 
 
907
  int32_t    nbr_elt_loc = 0;
 
908
  int32_t  * nbr_n_loc = NULL;
 
909
  int32_t  * nbr_f_loc = NULL;
 
910
  int32_t  * connect_loc = NULL;
 
911
 
 
912
  const ecs_int_t  l_fmt_int = 10;
 
913
 
 
914
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
915
 
 
916
  /* On s'assure qu'on n'a pas affaire à une "part" */
 
917
 
 
918
  if (strncmp(chaine, "part", strlen("part")) == 0)
 
919
    return -1;
 
920
 
 
921
  /*----------------------------*/
 
922
  /* Décodage du type d'élément */
 
923
  /*----------------------------*/
 
924
 
 
925
  ecs_loc_pre_ens__type_elem(fic, chaine, &nbr_som_elt, &elt_typ);
 
926
 
 
927
  /* Lecture du nombre d'éléments */
 
928
  /*------------------------------*/
 
929
 
 
930
  ecs_loc_pre_ens__lit_int(fic, 1, &nbr_elt_loc, l_fmt_int, num_ligne);
 
931
 
 
932
  printf(_("    %10d %-10s elements\n"), (int)nbr_elt_loc, chaine);
 
933
 
 
934
  /*------------------------------------------------*/
 
935
  /* Lecture éventuelle des labels des éléments     */
 
936
  /*------------------------------------------------*/
 
937
 
 
938
  if (lire_id_elem == true) {
 
939
    id_elem = ecs_loc_pre_ens__lit_int(fic,
 
940
                                       (ecs_int_t)nbr_elt_loc,
 
941
                                       NULL,
 
942
                                       l_fmt_int,
 
943
                                       num_ligne);
 
944
    ECS_FREE(id_elem);
 
945
  }
 
946
 
 
947
  /*------------------------------------------------*/
 
948
  /* Lecture de la connectivité nodale des elements */
 
949
  /*------------------------------------------------*/
 
950
 
 
951
  if (elt_typ == ECS_ELT_TYP_FAC_POLY) {
 
952
 
 
953
    nbr_n_loc = ecs_loc_pre_ens__lit_int(fic,
 
954
                                         (ecs_int_t)nbr_elt_loc,
 
955
                                         NULL,
 
956
                                         l_fmt_int,
 
957
                                         num_ligne);
 
958
    taille_lect = 0;
 
959
    for (ind = 0; ind < (ecs_int_t)nbr_elt_loc; ind++)
 
960
      taille_lect += nbr_n_loc[ind];
 
961
 
 
962
    taille_connect = taille_lect;
 
963
 
 
964
  }
 
965
  else if (elt_typ == ECS_ELT_TYP_CEL_POLY) {
 
966
 
 
967
    ecs_int_t taille_int = 0;
 
968
 
 
969
    nbr_f_loc = ecs_loc_pre_ens__lit_int(fic,
 
970
                                         (ecs_int_t)nbr_elt_loc,
 
971
                                         NULL,
 
972
                                         l_fmt_int,
 
973
                                         num_ligne);
 
974
    taille_lect = 0;
 
975
 
 
976
    for (ind = 0; ind < (ecs_int_t)nbr_elt_loc; ind++)
 
977
      taille_int += nbr_f_loc[ind];
 
978
 
 
979
    nbr_n_loc = ecs_loc_pre_ens__lit_int(fic,
 
980
                                         taille_int,
 
981
                                         NULL,
 
982
                                         l_fmt_int,
 
983
                                         num_ligne);
 
984
 
 
985
    for (ind = 0; ind < taille_int; ind++)
 
986
      taille_lect += nbr_n_loc[ind];
 
987
 
 
988
    taille_connect = taille_lect;
 
989
 
 
990
  }
 
991
  else  {
 
992
    nbr_som_elt_lin = ecs_fic_elt_typ_liste_c[elt_typ].nbr_som;
 
993
    taille_lect    = nbr_elt_loc * nbr_som_elt;
 
994
    taille_connect = nbr_elt_loc * nbr_som_elt_lin;
 
995
  }
 
996
  connect_loc = ecs_loc_pre_ens__lit_int(fic,
 
997
                                         taille_lect,
 
998
                                         NULL,
 
999
                                         l_fmt_int,
 
1000
                                         num_ligne);
 
1001
 
 
1002
  if (importer_part == true && elt_typ != ECS_ELT_TYP_NUL) {
 
1003
 
 
1004
    ECS_REALLOC(*elems, (*taille_elems) + 1, ecs_loc_elems_ens_t);
 
1005
 
 
1006
    elems_loc = (*elems) + (*taille_elems);
 
1007
 
 
1008
    *taille_elems += 1;
 
1009
 
 
1010
    /* Suppression références noeuds non sommets éventuels */
 
1011
 
 
1012
    if (taille_lect > taille_connect) {
 
1013
      connect_loc = ecs_loc_pre_ens__ele_lin(connect_loc,
 
1014
                                             (ecs_int_t)nbr_elt_loc,
 
1015
                                             nbr_som_elt,
 
1016
                                             nbr_som_elt_lin);
 
1017
 
 
1018
    }
 
1019
 
 
1020
    /* Application des labels des sommets */
 
1021
 
 
1022
    if (noeuds->id_noeud != NULL) {
 
1023
 
 
1024
      for (ind = 0; ind < taille_connect; ind++){
 
1025
        assert(   (connect_loc[ind]-1) >= 0
 
1026
               && (connect_loc[ind]-1) < noeuds->nbr_noeuds);
 
1027
        connect_loc[ind] = noeuds->id_noeud[connect_loc[ind]-1];
 
1028
      }
 
1029
    }
 
1030
 
 
1031
    elems_loc->nbr_ele  = nbr_elt_loc;
 
1032
    elems_loc->elt_typ  = elt_typ;
 
1033
    elems_loc->nbr_n    = nbr_n_loc;
 
1034
    elems_loc->nbr_f    = nbr_f_loc;
 
1035
    elems_loc->connect  = connect_loc;
 
1036
    elems_loc->num_part = num_part;
 
1037
 
 
1038
  }
 
1039
  else {
 
1040
 
 
1041
    if (nbr_n_loc != NULL)
 
1042
      ECS_FREE(nbr_n_loc);
 
1043
 
 
1044
    if (nbr_f_loc != NULL)
 
1045
      ECS_FREE(nbr_f_loc);
 
1046
 
 
1047
    ECS_FREE(connect_loc);
 
1048
 
 
1049
  }
 
1050
 
 
1051
  return nbr_elt_loc;
 
1052
 
 
1053
}
 
1054
 
 
1055
/*----------------------------------------------------------------------------
 
1056
 * Lecture des éléments format EnSight 6; renvoie le nombre d'éléments lus,
 
1057
 * ou -1 si l'on a affaire à une "part"
 
1058
 *----------------------------------------------------------------------------*/
 
1059
 
 
1060
static ecs_int_t
 
1061
ecs_loc_pre_ens__lit_elem_6(ecs_file_t            *fic,
 
1062
                            int                    num_part,
 
1063
                            bool                   lire_id_elem,
 
1064
                            bool                   importer_part,
 
1065
                            ecs_int_t             *taille_elems,
 
1066
                            ecs_loc_elems_ens_t  **elems,
 
1067
                            char                   chaine[],
 
1068
                            int                   *num_ligne)
 
1069
{
 
1070
  int            nbr_som_elt;
 
1071
 
 
1072
  ecs_int_t      nbr_som_elt_lin;
 
1073
  ecs_int_t      taille_connect;
 
1074
  ecs_int_t      taille_lect;
 
1075
 
 
1076
  ecs_elt_typ_t   elt_typ;
 
1077
 
 
1078
  int32_t  * id_elem;
 
1079
 
 
1080
  ecs_loc_elems_ens_t  *elems_loc;
 
1081
 
 
1082
  int32_t    nbr_elt_loc = 0;
 
1083
  int32_t  * nbr_n_loc = NULL;
 
1084
  int32_t  * nbr_f_loc = NULL;
 
1085
  int32_t  * connect_loc = NULL;
 
1086
 
 
1087
  const ecs_int_t  l_fmt_int = 8;
 
1088
 
 
1089
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
1090
 
 
1091
  /* On s'assure qu'on n'a pas affaire à une "part" */
 
1092
 
 
1093
  if (strncmp(chaine, "part", strlen("part")) == 0)
 
1094
    return -1;
 
1095
 
 
1096
  /*----------------------------*/
 
1097
  /* Décodage du type d'élément */
 
1098
  /*----------------------------*/
 
1099
 
 
1100
  ecs_loc_pre_ens__type_elem(fic, chaine, &nbr_som_elt, &elt_typ);
 
1101
 
 
1102
  /* Lecture du nombre d'éléments */
 
1103
  /*------------------------------*/
 
1104
 
 
1105
  ecs_loc_pre_ens__lit_int(fic, 1, &nbr_elt_loc, l_fmt_int, num_ligne);
 
1106
 
 
1107
  printf(_("    %10d %-10s elements\n"), (int)nbr_elt_loc, chaine);
 
1108
 
 
1109
  /*------------------------------------------------*/
 
1110
  /* Lecture éventuelle des labels des éléments     */
 
1111
  /* et Lecture de la connectivité                  */
 
1112
  /*------------------------------------------------*/
 
1113
 
 
1114
  ECS_MALLOC(id_elem, nbr_elt_loc, int32_t);
 
1115
  ECS_MALLOC(connect_loc, nbr_elt_loc * nbr_som_elt, int32_t);
 
1116
 
 
1117
  ecs_loc_pre_ens__lit_tab_connect(fic ,
 
1118
                                   nbr_elt_loc  ,
 
1119
                                   lire_id_elem ,
 
1120
                                   nbr_som_elt ,
 
1121
                                   id_elem ,
 
1122
                                   connect_loc ,
 
1123
                                   num_ligne);
 
1124
  ECS_FREE(id_elem);
 
1125
 
 
1126
  nbr_som_elt_lin = ecs_fic_elt_typ_liste_c[elt_typ].nbr_som;
 
1127
  taille_lect    = nbr_elt_loc * nbr_som_elt;
 
1128
  taille_connect = nbr_elt_loc * nbr_som_elt_lin;
 
1129
 
 
1130
  if (importer_part == true && elt_typ != ECS_ELT_TYP_NUL) {
 
1131
 
 
1132
    ECS_REALLOC(*elems, (*taille_elems) + 1, ecs_loc_elems_ens_t);
 
1133
 
 
1134
    elems_loc = (*elems) + (*taille_elems);
 
1135
 
 
1136
    *taille_elems += 1;
 
1137
 
 
1138
    /* Suppression références noeuds non sommets éventuels */
 
1139
 
 
1140
    if (taille_lect > taille_connect) {
 
1141
      connect_loc = ecs_loc_pre_ens__ele_lin(connect_loc,
 
1142
                                             (ecs_int_t)nbr_elt_loc,
 
1143
                                             nbr_som_elt,
 
1144
                                             nbr_som_elt_lin);
 
1145
 
 
1146
    }
 
1147
 
 
1148
    elems_loc->nbr_ele  = nbr_elt_loc;
 
1149
    elems_loc->elt_typ  = elt_typ;
 
1150
    elems_loc->nbr_n    = nbr_n_loc;
 
1151
    elems_loc->nbr_f    = nbr_f_loc;
 
1152
    elems_loc->connect  = connect_loc;
 
1153
    elems_loc->num_part = num_part;
 
1154
 
 
1155
  }
 
1156
  else {
 
1157
 
 
1158
    ECS_FREE(connect_loc);
 
1159
 
 
1160
  }
 
1161
  return nbr_elt_loc;
 
1162
}
 
1163
 
 
1164
/*----------------------------------------------------------------------------
 
1165
 *  Vérification qu'un groupe de noeuds est bien défini avec des
 
1166
 *  labels croissants, et tri le cas échéant.
 
1167
 *----------------------------------------------------------------------------*/
 
1168
 
 
1169
static void
 
1170
ecs_loc_pre_ens__trie_noeuds(ecs_loc_noeuds_ens_t  *noeuds)
 
1171
{
 
1172
  ecs_int_t         ind;
 
1173
  ecs_int_t         ind_coo;
 
1174
 
 
1175
  ecs_tab_int_t     id_noeud_loc;
 
1176
  ecs_tab_int_t     id_trie;
 
1177
  ecs_tab_int_t     renum;
 
1178
 
 
1179
  bool              a_trier = false;
 
1180
 
 
1181
  ecs_coord_t      *coord_tmp    = NULL;
 
1182
 
 
1183
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
1184
 
 
1185
  if (noeuds->id_noeud == NULL)
 
1186
    return;
 
1187
 
 
1188
  a_trier = false;
 
1189
 
 
1190
  for (ind = 0; ind < noeuds->nbr_noeuds - 1; ind++) {
 
1191
 
 
1192
    if (noeuds->id_noeud[ind + 1] <= noeuds->id_noeud[ind]) {
 
1193
 
 
1194
      a_trier = true;
 
1195
      break;
 
1196
 
 
1197
    }
 
1198
 
 
1199
  }
 
1200
 
 
1201
  /* Si l'on a des sommets à trier */
 
1202
 
 
1203
  if (a_trier == true) {
 
1204
 
 
1205
    id_noeud_loc.nbr = noeuds->nbr_noeuds;
 
1206
    id_noeud_loc.val = noeuds->id_noeud;
 
1207
 
 
1208
    /* Tri effectif */
 
1209
 
 
1210
    ECS_MALLOC(renum.val, noeuds->nbr_noeuds, ecs_int_t);
 
1211
    renum.nbr = noeuds->nbr_noeuds;
 
1212
 
 
1213
    id_trie = ecs_tab_int__trie_et_renvoie(id_noeud_loc,
 
1214
                                           renum);
 
1215
 
 
1216
    ECS_FREE(noeuds->id_noeud);
 
1217
 
 
1218
    noeuds->id_noeud = id_trie.val;
 
1219
 
 
1220
    ECS_MALLOC(coord_tmp, noeuds->nbr_noeuds*3, ecs_coord_t);
 
1221
 
 
1222
    for (ind = 0; ind < noeuds->nbr_noeuds; ind++) {
 
1223
      for (ind_coo = 0; ind_coo < 3; ind_coo++)
 
1224
        coord_tmp[ind*3 + ind_coo]
 
1225
          = noeuds->coord[(renum.val[ind])*3 + ind_coo];
 
1226
 
 
1227
    }
 
1228
 
 
1229
    ECS_FREE(renum.val);
 
1230
 
 
1231
    ECS_FREE(noeuds->coord);
 
1232
 
 
1233
    noeuds->coord = coord_tmp;
 
1234
 }
 
1235
}
 
1236
 
 
1237
/*----------------------------------------------------------------------------
 
1238
 *  Fusion de deux blocs de définitions de noeuds ; le premier ensemble
 
1239
 *  (noeuds_ref) est étendu au besoin, le deuxième est supprimé (i.e.
 
1240
 *  ses tableaux sont libérés, et il n'est plus valide à l'issue de
 
1241
 *  cette fonction).
 
1242
 *----------------------------------------------------------------------------*/
 
1243
 
 
1244
static void
 
1245
ecs_loc_pre_ens__fusion_noeuds(ecs_loc_noeuds_ens_t  *noeuds_ref,
 
1246
                               ecs_loc_noeuds_ens_t  *noeuds_add)
 
1247
{
 
1248
  ecs_int_t          cpt_add;
 
1249
  ecs_int_t          ind_add;
 
1250
  ecs_int_t          ind_ref;
 
1251
  ecs_int_t          ind_tot;
 
1252
  ecs_int_t          ind_coo;
 
1253
  ecs_int_t          nbr_noeuds_tot;
 
1254
 
 
1255
  ecs_int_t        * id_new    = NULL;
 
1256
  ecs_coord_t      * coord_new = NULL;
 
1257
 
 
1258
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
1259
 
 
1260
  if (noeuds_ref->id_noeud == NULL || noeuds_ref->id_noeud == NULL)
 
1261
    ecs_error(__FILE__, __LINE__, 0,
 
1262
              _("EnSight: error merging node groups.\n"
 
1263
                "At least one of the groups has no \"id\", and they\n"
 
1264
                "should not be merged (internal logic problem)."));
 
1265
 
 
1266
 
 
1267
  ind_ref = 0;
 
1268
  cpt_add = 0;
 
1269
 
 
1270
  for (ind_add = 0; ind_add < noeuds_add->nbr_noeuds; ind_add++) {
 
1271
 
 
1272
    while (   ind_ref < noeuds_ref->nbr_noeuds
 
1273
           && noeuds_ref->id_noeud[ind_ref] < noeuds_add->id_noeud[ind_add])
 
1274
      ind_ref++;
 
1275
 
 
1276
    if (   ind_ref == noeuds_ref->nbr_noeuds
 
1277
        || (ind_ref < noeuds_ref->nbr_noeuds
 
1278
            && (   noeuds_ref->id_noeud[ind_ref]
 
1279
                != noeuds_add->id_noeud[ind_add])))
 
1280
      cpt_add++;
 
1281
 
 
1282
  }
 
1283
 
 
1284
  /* Si l'on a des sommets à fusionner */
 
1285
 
 
1286
  if (cpt_add > 0) {
 
1287
 
 
1288
    nbr_noeuds_tot = noeuds_ref->nbr_noeuds + cpt_add;
 
1289
 
 
1290
    ECS_MALLOC(id_new,    nbr_noeuds_tot,   ecs_int_t);
 
1291
    ECS_MALLOC(coord_new, nbr_noeuds_tot*3, ecs_coord_t);
 
1292
 
 
1293
    ind_ref = 0;
 
1294
    ind_tot = 0;
 
1295
    cpt_add = 0;
 
1296
 
 
1297
    for (ind_add = 0; ind_add < noeuds_add->nbr_noeuds; ind_add++) {
 
1298
 
 
1299
      while (   ind_ref < noeuds_ref->nbr_noeuds
 
1300
             && noeuds_ref->id_noeud[ind_ref] < noeuds_add->id_noeud[ind_add]) {
 
1301
        id_new[ind_tot] = noeuds_ref->id_noeud[ind_ref];
 
1302
        for (ind_coo = 0; ind_coo < 3; ind_coo++)
 
1303
          coord_new[ind_tot*3 + ind_coo]
 
1304
            = noeuds_ref->coord[ind_ref*3 + ind_coo];
 
1305
        ind_tot++;
 
1306
        ind_ref++;
 
1307
      }
 
1308
 
 
1309
      if (   ind_ref == noeuds_ref->nbr_noeuds
 
1310
          || (ind_ref < noeuds_ref->nbr_noeuds
 
1311
              && (   noeuds_ref->id_noeud[ind_ref]
 
1312
                  != noeuds_add->id_noeud[ind_add]))) {
 
1313
        id_new[ind_tot] = noeuds_add->id_noeud[ind_add];
 
1314
        for (ind_coo = 0; ind_coo < 3; ind_coo++)
 
1315
          coord_new[ind_tot*3 + ind_coo]
 
1316
            = noeuds_add->coord[ind_add*3 + ind_coo];
 
1317
        ind_tot++;
 
1318
      }
 
1319
 
 
1320
    }
 
1321
 
 
1322
    /* Il peut rester des éléments dans la liste de référence */
 
1323
 
 
1324
    while (   ind_ref < noeuds_ref->nbr_noeuds ) {
 
1325
      id_new[ind_tot] = noeuds_ref->id_noeud[ind_ref];
 
1326
      for (ind_coo = 0; ind_coo < 3; ind_coo++)
 
1327
        coord_new[ind_tot*3 + ind_coo]
 
1328
          = noeuds_ref->coord[ind_ref*3 + ind_coo];
 
1329
      ind_tot++;
 
1330
      ind_ref++;
 
1331
    }
 
1332
 
 
1333
    ECS_FREE(noeuds_ref->id_noeud);
 
1334
    ECS_FREE(noeuds_ref->coord);
 
1335
 
 
1336
    /* On remplace les anciennes valeurs de référence par les
 
1337
       valeurs fusionnées */
 
1338
 
 
1339
    noeuds_ref->nbr_noeuds = ind_tot;
 
1340
    noeuds_ref->id_noeud   = id_new;
 
1341
    noeuds_ref->coord      = coord_new;
 
1342
 
 
1343
  }
 
1344
 
 
1345
  /* On libère les valeurs à fusionner */
 
1346
 
 
1347
  ECS_FREE(noeuds_add->id_noeud);
 
1348
  ECS_FREE(noeuds_add->coord);
 
1349
}
 
1350
 
 
1351
/*----------------------------------------------------------------------------
 
1352
 *  Concaténation des éléments pour préparer le transfert dans la structure
 
1353
 *   de maillage ; la liste des élémens liste_elems est libérée, et remplacée
 
1354
 *   par la structure renvoyée.
 
1355
 *
 
1356
 *  Les références aux ids des noeuds sont transformés en indices, et
 
1357
 *   les ids des noeuds ensuite supprimés.
 
1358
 *----------------------------------------------------------------------------*/
 
1359
 
 
1360
static void
 
1361
ecs_loc_pre_ens__concat_elems(ecs_maillage_t         *maillage,
 
1362
                              ecs_int_t               taille_liste_elems,
 
1363
                              ecs_loc_noeuds_ens_t   *liste_noeuds,
 
1364
                              ecs_loc_elems_ens_t   **liste_elems)
 
1365
{
 
1366
  ecs_entmail_t    entmail_e;
 
1367
 
 
1368
  ecs_int_t      ient;
 
1369
  ecs_int_t      ielt;
 
1370
  ecs_int_t      ielts_loc;
 
1371
  ecs_int_t      ifac;
 
1372
  ecs_int_t      isom;
 
1373
  ecs_int_t      nbr_som_elt;
 
1374
  ecs_int_t      nbr_som_fac;
 
1375
  ecs_int_t      pos_elt;
 
1376
 
 
1377
  ecs_loc_elems_ens_t  * elems_loc;
 
1378
  ecs_elt_typ_t          typ_geo;
 
1379
 
 
1380
  /* Déclarations des variables de stockage        */
 
1381
  /* avant transfert dans la structure du maillage */
 
1382
  /*-----------------------------------------------*/
 
1383
 
 
1384
  size_t       cpt_elt_ent        [ECS_N_ENTMAIL]; /* Nbr. elts par entité */
 
1385
  ecs_int_t    cpt_coul_ent       [ECS_N_ENTMAIL]; /* Compteur de couleurs */
 
1386
  ecs_int_t    cpt_val_som_ent    [ECS_N_ENTMAIL]; /* Taille connect.      */
 
1387
  ecs_int_t    icoul              [ECS_N_ENTMAIL]; /* Couleur en cours     */
 
1388
  ecs_int_t  * val_coul_ent       [ECS_N_ENTMAIL]; /* Tableau des couleurs */
 
1389
  ecs_size_t * cpt_elt_coul_ent   [ECS_N_ENTMAIL];
 
1390
  ecs_size_t * elt_pos_som_ent    [ECS_N_ENTMAIL]; /* Positions sommets    */
 
1391
  ecs_int_t  * elt_val_som_ent    [ECS_N_ENTMAIL]; /* Numéros des sommets  */
 
1392
  ecs_int_t  * elt_val_color_ent  [ECS_N_ENTMAIL]; /* Couleurs éléments    */
 
1393
 
 
1394
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
1395
 
 
1396
  /*====================================================*/
 
1397
  /* Initialisations et allocations des tableaux locaux */
 
1398
  /*====================================================*/
 
1399
 
 
1400
  /* Attention au decalage de `1' !!!         */
 
1401
  /* On n'alloue pas les tableaux locaux pour */
 
1402
  /* `ECS_ENTMAIL_DEB = ECS_ENTMAIL_SOM'      */
 
1403
 
 
1404
  for (ient = ECS_ENTMAIL_FAC; ient < ECS_N_ENTMAIL; ient++) {
 
1405
 
 
1406
    cpt_elt_ent        [ient] = 0;
 
1407
    cpt_val_som_ent    [ient] = 0;
 
1408
 
 
1409
    elt_pos_som_ent    [ient] = NULL;
 
1410
    elt_val_som_ent    [ient] = NULL;
 
1411
    elt_val_color_ent  [ient] = NULL;
 
1412
 
 
1413
    cpt_coul_ent       [ient] = 0;
 
1414
    val_coul_ent       [ient] = NULL;
 
1415
    cpt_elt_coul_ent   [ient] = NULL;
 
1416
 
 
1417
  }
 
1418
 
 
1419
  /* Vérification que la liste des éléments n'est pas vide */
 
1420
 
 
1421
  assert(taille_liste_elems != 0);
 
1422
  assert(liste_elems != NULL);
 
1423
 
 
1424
  /* Boucle sur la liste des éléments pour le dimensionnement */
 
1425
  /*----------------------------------------------------------*/
 
1426
 
 
1427
  for (ielts_loc = 0; ielts_loc < taille_liste_elems; ielts_loc++) {
 
1428
 
 
1429
    elems_loc = (*liste_elems) + ielts_loc;
 
1430
 
 
1431
    /* Identification de l'entité concernée */
 
1432
 
 
1433
    typ_geo = elems_loc->elt_typ;
 
1434
    entmail_e = ecs_maillage_pre__ret_typ_geo(elems_loc->elt_typ);
 
1435
 
 
1436
    /* Nombre d'éléments à ajouter */
 
1437
 
 
1438
    cpt_elt_ent[entmail_e] += elems_loc->nbr_ele;
 
1439
 
 
1440
    /* Traitement des éléments "classiques" */
 
1441
 
 
1442
    if (typ_geo != ECS_ELT_TYP_CEL_POLY && typ_geo != ECS_ELT_TYP_FAC_POLY) {
 
1443
 
 
1444
      nbr_som_elt = ecs_fic_elt_typ_liste_c[typ_geo].nbr_som;
 
1445
 
 
1446
      cpt_val_som_ent[entmail_e] += (elems_loc->nbr_ele * nbr_som_elt);
 
1447
 
 
1448
    }
 
1449
 
 
1450
    /* Traitement des Polygones */
 
1451
 
 
1452
    else if (typ_geo == ECS_ELT_TYP_FAC_POLY) {
 
1453
 
 
1454
      for (ielt = 0; ielt < elems_loc->nbr_ele; ielt++)
 
1455
 
 
1456
        cpt_val_som_ent[entmail_e] += (elems_loc->nbr_n[ielt]);
 
1457
 
 
1458
    }
 
1459
 
 
1460
    /* Traitement des Polyèdres */
 
1461
 
 
1462
    else if (typ_geo == ECS_ELT_TYP_CEL_POLY) {
 
1463
 
 
1464
      ecs_int_t  cpt_fac_loc = 0;
 
1465
 
 
1466
      for (ielt = 0; ielt < elems_loc->nbr_ele; ielt++) {
 
1467
 
 
1468
        for (ifac = 0; ifac < elems_loc->nbr_f[ielt]; ifac++) {
 
1469
 
 
1470
          /* Le premier noeud de chaque face est répété en queue pour la
 
1471
             détection de fin de face -> + 1 pour la taille */
 
1472
 
 
1473
          cpt_val_som_ent[entmail_e] += elems_loc->nbr_n[cpt_fac_loc] + 1;
 
1474
 
 
1475
          cpt_fac_loc++;
 
1476
 
 
1477
        }
 
1478
 
 
1479
      }
 
1480
 
 
1481
    } /* Fin du traitement selon le type d'entité */
 
1482
 
 
1483
  }
 
1484
 
 
1485
  /* Allocations et initialisation */
 
1486
  /*-------------------------------*/
 
1487
 
 
1488
  for (ient = ECS_ENTMAIL_FAC; ient < ECS_N_ENTMAIL; ient++) {
 
1489
 
 
1490
    if (cpt_elt_ent[ient] > 0) {
 
1491
 
 
1492
      ECS_MALLOC(elt_pos_som_ent[ient],
 
1493
                 cpt_elt_ent[ient] + 1,
 
1494
                 ecs_size_t);
 
1495
 
 
1496
      elt_pos_som_ent[ient][0] = 1;
 
1497
 
 
1498
      ECS_MALLOC(elt_val_som_ent[ient],
 
1499
                 cpt_val_som_ent[ient],
 
1500
                 ecs_int_t);
 
1501
 
 
1502
      ECS_MALLOC(elt_val_color_ent[ient]  ,
 
1503
                 cpt_elt_ent[ient],
 
1504
                 ecs_int_t);
 
1505
    }
 
1506
  }
 
1507
 
 
1508
  /* Remise à zéro des compteurs de dimensionnement */
 
1509
 
 
1510
  for (ient = ECS_ENTMAIL_FAC; ient < ECS_N_ENTMAIL; ient++) {
 
1511
 
 
1512
    cpt_elt_ent[ient]     = 0;
 
1513
    cpt_val_som_ent[ient] = 0;
 
1514
 
 
1515
  }
 
1516
 
 
1517
  /* Boucle sur la liste des éléments pour construction */
 
1518
  /* des variables de stockage pour le transfert dans   */
 
1519
  /* la structure de maillage                           */
 
1520
  /*----------------------------------------------------*/
 
1521
 
 
1522
  for (ielts_loc = 0; ielts_loc < taille_liste_elems; ielts_loc++) {
 
1523
 
 
1524
    elems_loc = (*liste_elems) + ielts_loc;
 
1525
 
 
1526
    /* Identification de l'entité concernée */
 
1527
    /*--------------------------------------*/
 
1528
 
 
1529
    typ_geo = elems_loc->elt_typ;
 
1530
    entmail_e = ecs_maillage_pre__ret_typ_geo(elems_loc->elt_typ);
 
1531
 
 
1532
 
 
1533
    /* Couleur des éléments lus positionnée au numéro du part auquel
 
1534
       appartiennent les éléments */
 
1535
 
 
1536
    for (icoul[entmail_e] = 0;
 
1537
         icoul[entmail_e] < cpt_coul_ent[entmail_e]
 
1538
           && val_coul_ent[entmail_e][icoul[entmail_e]] != elems_loc->num_part;
 
1539
         icoul[entmail_e]++);
 
1540
 
 
1541
    if (icoul[entmail_e] == cpt_coul_ent[entmail_e]) {
 
1542
 
 
1543
      /* La valeur de la couleur n'a pas encore été stockée */
 
1544
 
 
1545
      ECS_REALLOC(val_coul_ent[entmail_e],
 
1546
                  cpt_coul_ent[entmail_e] + 1,
 
1547
                  ecs_int_t);
 
1548
      ECS_REALLOC(cpt_elt_coul_ent[entmail_e],
 
1549
                  cpt_coul_ent[entmail_e] + 1,
 
1550
                  ecs_size_t);
 
1551
 
 
1552
      cpt_elt_coul_ent[entmail_e][icoul[entmail_e]] = 0;
 
1553
      val_coul_ent[entmail_e][icoul[entmail_e]] = elems_loc->num_part;
 
1554
      cpt_coul_ent[entmail_e]++;
 
1555
    }
 
1556
 
 
1557
    /* Traitement des éléments "classiques" */
 
1558
    /*--------------------------------------*/
 
1559
 
 
1560
    if (typ_geo != ECS_ELT_TYP_CEL_POLY && typ_geo != ECS_ELT_TYP_FAC_POLY) {
 
1561
 
 
1562
      nbr_som_elt = ecs_fic_elt_typ_liste_c[typ_geo].nbr_som;
 
1563
 
 
1564
      for (ielt = 0; ielt < elems_loc->nbr_ele; ielt++) {
 
1565
 
 
1566
        /* Construction connectivité */
 
1567
 
 
1568
        pos_elt = elt_pos_som_ent[entmail_e][cpt_elt_ent[entmail_e]];
 
1569
 
 
1570
        elt_pos_som_ent[entmail_e][cpt_elt_ent[entmail_e] + 1]
 
1571
          = pos_elt + nbr_som_elt;
 
1572
 
 
1573
        for (isom = 0; isom < nbr_som_elt; isom++)
 
1574
          elt_val_som_ent[entmail_e][pos_elt - 1 + isom]
 
1575
            = elems_loc->connect[ielt*nbr_som_elt + isom];
 
1576
 
 
1577
        /* Affectation couleurs */
 
1578
 
 
1579
        cpt_elt_coul_ent[entmail_e][icoul[entmail_e]]++;
 
1580
        elt_val_color_ent[entmail_e][cpt_elt_ent[entmail_e]]
 
1581
          = icoul[entmail_e] + 1;
 
1582
 
 
1583
        /* Mise à jour compteurs */
 
1584
 
 
1585
        cpt_elt_ent[entmail_e] += 1;
 
1586
        cpt_val_som_ent[entmail_e] += nbr_som_elt;
 
1587
 
 
1588
      }
 
1589
 
 
1590
    }
 
1591
 
 
1592
    /* Traitement des Polygones */
 
1593
    /*--------------------------*/
 
1594
 
 
1595
    else if (typ_geo == ECS_ELT_TYP_FAC_POLY) {
 
1596
 
 
1597
      ecs_int_t  cpt_som_loc = 0;
 
1598
 
 
1599
      for (ielt = 0; ielt < elems_loc->nbr_ele; ielt++) {
 
1600
 
 
1601
        nbr_som_elt = elems_loc->nbr_n[ielt];
 
1602
 
 
1603
        /* Construction connectivité */
 
1604
 
 
1605
        pos_elt = elt_pos_som_ent[entmail_e][cpt_elt_ent[entmail_e]];
 
1606
 
 
1607
        elt_pos_som_ent[entmail_e][cpt_elt_ent[entmail_e] + 1]
 
1608
          = pos_elt + nbr_som_elt;
 
1609
 
 
1610
        for (isom = 0; isom < nbr_som_elt; isom++)
 
1611
          elt_val_som_ent[entmail_e][pos_elt - 1 + isom]
 
1612
            = elems_loc->connect[cpt_som_loc++];
 
1613
 
 
1614
        /* Affectation couleurs */
 
1615
 
 
1616
        cpt_elt_coul_ent[entmail_e][icoul[entmail_e]]++;
 
1617
        elt_val_color_ent[entmail_e][cpt_elt_ent[entmail_e]]
 
1618
          = icoul[entmail_e] + 1;
 
1619
 
 
1620
        /* Mise à jour compteurs */
 
1621
 
 
1622
        cpt_elt_ent[entmail_e] += 1;
 
1623
        cpt_val_som_ent[entmail_e] += nbr_som_elt;
 
1624
 
 
1625
      }
 
1626
    }
 
1627
 
 
1628
    /* Traitement des Polyèdres */
 
1629
    /*--------------------------*/
 
1630
 
 
1631
    else if (typ_geo == ECS_ELT_TYP_CEL_POLY) {
 
1632
 
 
1633
      ecs_int_t nbr_fac_elt;       /* nombre de faces par élément */
 
1634
      ecs_int_t ifac_elt;
 
1635
 
 
1636
      ecs_int_t  num_som_deb_fac;
 
1637
      ecs_int_t  cpt_fac_loc = 0;
 
1638
      ecs_int_t  cpt_som_loc = 0;
 
1639
 
 
1640
      /* Remplissage de la connectivité */
 
1641
 
 
1642
      for (ielt = 0; ielt < elems_loc->nbr_ele; ielt++) {
 
1643
 
 
1644
        nbr_fac_elt = elems_loc->nbr_f[ielt];
 
1645
 
 
1646
        /* Construction connectivité */
 
1647
 
 
1648
        pos_elt = elt_pos_som_ent[entmail_e][cpt_elt_ent[entmail_e]];
 
1649
 
 
1650
        for (ifac_elt = 0; ifac_elt < nbr_fac_elt; ifac_elt++) {
 
1651
 
 
1652
          nbr_som_fac = elems_loc->nbr_n[cpt_fac_loc];
 
1653
 
 
1654
          /* Le premier noeud de chaque face est répété en queue pour la
 
1655
             détection de fin de face */
 
1656
 
 
1657
          num_som_deb_fac = elems_loc->connect[cpt_som_loc];
 
1658
 
 
1659
          for (isom = 0; isom < nbr_som_fac; isom++)
 
1660
            elt_val_som_ent[entmail_e][cpt_val_som_ent[entmail_e] + isom]
 
1661
              = elems_loc->connect[cpt_som_loc++];
 
1662
 
 
1663
          elt_val_som_ent[entmail_e][cpt_val_som_ent[entmail_e] + isom]
 
1664
              = num_som_deb_fac;
 
1665
 
 
1666
          /* Mise à jour partielle compteurs */
 
1667
 
 
1668
          cpt_val_som_ent[entmail_e] += nbr_som_fac + 1;
 
1669
 
 
1670
          cpt_fac_loc++;
 
1671
 
 
1672
        }
 
1673
 
 
1674
        elt_pos_som_ent[entmail_e][cpt_elt_ent[entmail_e] + 1]
 
1675
          = cpt_val_som_ent[entmail_e] + 1;
 
1676
 
 
1677
        /* Affectation couleurs */
 
1678
 
 
1679
        cpt_elt_coul_ent[entmail_e][icoul[entmail_e]]++;
 
1680
        elt_val_color_ent[entmail_e][cpt_elt_ent[entmail_e]]
 
1681
          = icoul[entmail_e] + 1;
 
1682
 
 
1683
        /* Mise à jour partielle compteurs */
 
1684
 
 
1685
        cpt_elt_ent[entmail_e] += 1;
 
1686
 
 
1687
      }
 
1688
 
 
1689
    } /* Fin du traitement selon le type d'entité */
 
1690
 
 
1691
    /* Libération mémoire */
 
1692
 
 
1693
    if (elems_loc->nbr_n != NULL)
 
1694
      ECS_FREE(elems_loc->nbr_n);
 
1695
 
 
1696
    if (elems_loc->nbr_f != NULL)
 
1697
      ECS_FREE(elems_loc->nbr_f);
 
1698
 
 
1699
    ECS_FREE(elems_loc->connect);
 
1700
 
 
1701
  }
 
1702
 
 
1703
  ECS_FREE(*liste_elems);
 
1704
 
 
1705
 
 
1706
  /* Transformation des références en indices */
 
1707
  /*==========================================*/
 
1708
 
 
1709
  if (liste_noeuds->id_noeud != NULL) {
 
1710
 
 
1711
    for (ient = ECS_ENTMAIL_FAC ; ient < ECS_N_ENTMAIL ; ient++)
 
1712
      ecs_maillage_pre__label_en_indice
 
1713
        (liste_noeuds->nbr_noeuds,
 
1714
         elt_pos_som_ent[ient][cpt_elt_ent[ient]] - 1,
 
1715
         liste_noeuds->id_noeud,
 
1716
         elt_val_som_ent[ient]) ;
 
1717
 
 
1718
    ECS_FREE(liste_noeuds->id_noeud) ;
 
1719
  }
 
1720
 
 
1721
  /* Transfert des valeurs lues dans les structures d'entité de maillage */
 
1722
  /*=====================================================================*/
 
1723
 
 
1724
  ecs_maillage_pre__cree_elt(maillage,
 
1725
                             cpt_elt_ent,
 
1726
                             elt_pos_som_ent,
 
1727
                             elt_val_som_ent,
 
1728
                             NULL,
 
1729
                             elt_val_color_ent,
 
1730
                             cpt_coul_ent,
 
1731
                             val_coul_ent,
 
1732
                             cpt_elt_coul_ent);
 
1733
}
 
1734
 
 
1735
/*----------------------------------------------------------------------------
 
1736
 *  Détection big-endian/Little-endian au format EnSight 6 binaire C ;
 
1737
 *  On se place au moment de l'appel au début de la définition des noeuds.
 
1738
 *----------------------------------------------------------------------------*/
 
1739
 
 
1740
static void
 
1741
ecs_loc_pre_ens__c_bin_endian_6(ecs_file_t  *fic,
 
1742
                                bool         lire_id_noeud)
 
1743
{
 
1744
  char          chaine[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
1745
 
 
1746
  ecs_int_t     nbr_noeuds;
 
1747
  int32_t       val_int_lue;
 
1748
 
 
1749
  ecs_int_t     ret = 0;
 
1750
 
 
1751
  bool          swap_endian = false;
 
1752
 
 
1753
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
1754
 
 
1755
  if (ecs_file_get_type(fic) != ECS_FILE_TYPE_BINARY)
 
1756
    return;
 
1757
 
 
1758
  ecs_loc_pre_ens__lit_chaine(fic, chaine, NULL);
 
1759
 
 
1760
  if (strncmp(chaine, "coordinates", strlen("coordinates")) != 0)
 
1761
    ecs_error(__FILE__, __LINE__, 0,
 
1762
              _("EnSight: field \"%s\" encountered where\n"
 
1763
                "\"coordinates\" was expected."), chaine);
 
1764
 
 
1765
  ecs_loc_pre_ens__lit_int(fic, 1, &val_int_lue, 8, NULL);
 
1766
 
 
1767
  nbr_noeuds = (ecs_int_t)val_int_lue;
 
1768
 
 
1769
  /* Première permutation big-endian/little-endian si valeur impossible */
 
1770
 
 
1771
  if (nbr_noeuds < 0) {
 
1772
 
 
1773
    swap_endian = true;
 
1774
 
 
1775
    /* On revient en arrière pour la suite */
 
1776
 
 
1777
    ret = ecs_file_seek(fic, -1 * sizeof(int32_t), ECS_FILE_SEEK_CUR);
 
1778
 
 
1779
    if (ret == 0)
 
1780
      ret = ecs_file_seek(fic, -80 * sizeof(char), ECS_FILE_SEEK_CUR);
 
1781
  }
 
1782
 
 
1783
  /* Sinon, si la valeur lue pour le nombre de noeuds est plausible,
 
1784
     on vérifie si elle est effectivement possible */
 
1785
 
 
1786
  else {
 
1787
 
 
1788
    if (lire_id_noeud == true)
 
1789
      ret = ecs_file_seek(fic,
 
1790
                          nbr_noeuds * sizeof(int32_t),
 
1791
                          ECS_FILE_SEEK_CUR);
 
1792
 
 
1793
    if (ret == 0)
 
1794
      ret = ecs_file_seek(fic,
 
1795
                          nbr_noeuds * 3 * sizeof(float),
 
1796
                          ECS_FILE_SEEK_CUR);
 
1797
 
 
1798
    /* Si on arrive effectivement à la fin de fichier, c'est
 
1799
       que le fichier contient des noeuds, mais pas de "parts" ;
 
1800
       sinon, on doit avoir un "part", ou c'est que l'on n'a
 
1801
       pas les bonnes dimensions de tableaux, et donc probablement
 
1802
       pas la bonne interprétation du nombre de noeuds lus
 
1803
       -> on doit inverser le paramétrage big-endian/little-endian */
 
1804
 
 
1805
    if (ret == 0 && ecs_file_eof(fic) == 0) {
 
1806
 
 
1807
      if (ecs_file_read_try(chaine, sizeof(char), 80, fic) == 80) {
 
1808
 
 
1809
        if (strncmp(chaine, "part", strlen("part")) != 0)
 
1810
          swap_endian = true;
 
1811
      }
 
1812
      else
 
1813
        swap_endian = true;
 
1814
    }
 
1815
 
 
1816
    /* Si l'on n'a pu se positionner, c'est probablement que l'on n'a
 
1817
       probablement pas la bonne interprétation du nombre de noeuds lus,
 
1818
       et que l'on a cherché à dépasser la fin du fichier
 
1819
       -> on doit inverser le paramétrage big-endian/little-endian */
 
1820
 
 
1821
    else if (ret != 0)
 
1822
      swap_endian = true;
 
1823
 
 
1824
    /* On revient à la position de départ */
 
1825
 
 
1826
    ecs_file_rewind(fic);
 
1827
 
 
1828
    ret = ecs_file_seek(fic, 80 * 5 * sizeof(char), ECS_FILE_SEEK_CUR);
 
1829
  }
 
1830
 
 
1831
  /* Si l'on n'a pas pu se repositionner, on a une erreur */
 
1832
 
 
1833
  if (ret != 0) {
 
1834
 
 
1835
    ecs_file_read_check_error(fic, 0);
 
1836
 
 
1837
    ecs_error(__FILE__, __LINE__, 0,
 
1838
              _("EnSight: positionning (seek) error\n"
 
1839
                "in file \"%s\"."), ecs_file_get_name(fic));
 
1840
  }
 
1841
 
 
1842
  /* Modification bi-endian/little-endian si nécessaire */
 
1843
 
 
1844
  if (swap_endian == true) {
 
1845
 
 
1846
    if (ecs_file_get_swap_endian(fic) == 1)
 
1847
      ecs_file_set_swap_endian(fic, 0);
 
1848
    else
 
1849
      ecs_file_set_swap_endian(fic, 1);
 
1850
 
 
1851
  }
 
1852
}
 
1853
 
 
1854
/*----------------------------------------------------------------------------
 
1855
 *  Lecture d'un fichier au format EnSight Gold
 
1856
 *   et affectation des données dans la structure de maillage
 
1857
 *----------------------------------------------------------------------------*/
 
1858
 
 
1859
static ecs_maillage_t  *
 
1860
ecs_loc_pre_ens__lit_geo_gold(const char       *nom_fic_geo,
 
1861
                              int               num_part)
 
1862
{
 
1863
  char   chaine[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
1864
  char   chaine_aux[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
1865
 
 
1866
  char    *ret = NULL;
 
1867
 
 
1868
  ecs_int_t   nbr_elt_lus = 0;
 
1869
  bool        pb_rub;
 
1870
  bool        lire_node_id;
 
1871
  bool        lire_elem_id;
 
1872
  bool        importer_part;
 
1873
 
 
1874
  bool         swap_endian;
 
1875
  ecs_file_t  *fic;
 
1876
 
 
1877
  float    coo_min_max[6];
 
1878
 
 
1879
  ecs_int_t        taille_liste_noeuds = 0;
 
1880
  ecs_int_t        taille_liste_elems = 0;
 
1881
 
 
1882
  ecs_loc_noeuds_ens_t  *liste_noeuds = NULL;
 
1883
  ecs_loc_elems_ens_t   *liste_elems = NULL;
 
1884
 
 
1885
  int         num_ligne = 1;
 
1886
  bool        fin_lecture = false;
 
1887
  bool        affiche_extents = false;
 
1888
 
 
1889
  /* Création d'un maillage initialement vide (valeur de retour) */
 
1890
 
 
1891
  ecs_maillage_t  *maillage = ecs_maillage__cree_nodal();
 
1892
 
 
1893
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
1894
 
 
1895
  /* Ouverture du fichier geo */
 
1896
  /*--------------------------*/
 
1897
 
 
1898
  fic = ecs_loc_pre_ens__ouverture_fic_geo(nom_fic_geo);
 
1899
 
 
1900
  /* Lecture de l'entête */
 
1901
  /*---------------------*/
 
1902
 
 
1903
  /* 2 lignes de description */
 
1904
 
 
1905
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
1906
 
 
1907
  printf(_("\n"
 
1908
           "  Description:\n\n  %s\n"), chaine);
 
1909
 
 
1910
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
1911
 
 
1912
  printf("  %s\n\n", chaine);
 
1913
 
 
1914
  /* Infos sur ids sommets */
 
1915
 
 
1916
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
1917
 
 
1918
  pb_rub = false;
 
1919
 
 
1920
  if (strncmp(chaine, "node id", strlen("node id")) != 0)
 
1921
    pb_rub = true;
 
1922
  else if (sscanf(chaine, "%*s %*s %s", chaine_aux) != 1)
 
1923
    pb_rub = true;
 
1924
 
 
1925
  if (pb_rub == true)
 
1926
    ecs_error(__FILE__, __LINE__, 0,
 
1927
              _("EnSight: \"node id\" field missing or badly placed."));
 
1928
  else
 
1929
    printf("  node id :    %s\n", chaine_aux);
 
1930
 
 
1931
  if (   (strncmp(chaine_aux, "given",  strlen("given"))   == 0)
 
1932
      || (strncmp(chaine_aux, "ignore", strlen("ignore"))  == 0))
 
1933
    lire_node_id = true;
 
1934
  else
 
1935
    lire_node_id = false;
 
1936
 
 
1937
  /* Infos sur ids éléments */
 
1938
 
 
1939
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
1940
 
 
1941
  pb_rub = false;
 
1942
 
 
1943
  if (strncmp(chaine, "element id", strlen("element id")) != 0)
 
1944
    pb_rub = true;
 
1945
  else if (sscanf(chaine, "%*s %*s %s", chaine_aux) != 1)
 
1946
    pb_rub = true;
 
1947
 
 
1948
  if (pb_rub == true)
 
1949
    ecs_error(__FILE__, __LINE__, 0,
 
1950
              _("EnSight: \"element id\" field missing or badly placed"));
 
1951
  else
 
1952
    printf("  element id : %s\n\n", chaine_aux);
 
1953
 
 
1954
  if (   (strncmp(chaine_aux, "given",  strlen("given"))   == 0)
 
1955
      || (strncmp(chaine_aux, "ignore", strlen("ignore"))  == 0))
 
1956
    lire_elem_id = true;
 
1957
  else
 
1958
    lire_elem_id = false;
 
1959
 
 
1960
  /* "Extents" ou début de "part" */
 
1961
 
 
1962
  ret = ecs_loc_pre_ens__lit_chaine_essai(fic, chaine, &num_ligne);
 
1963
 
 
1964
  if (ret != NULL && strncmp(chaine, "extents", strlen("extents")) == 0) {
 
1965
 
 
1966
    ecs_loc_pre_ens__lit_float(fic, 6, coo_min_max, &num_ligne);
 
1967
 
 
1968
    /* On ne peut pas encore afficher les "extents", car l'on n'a
 
1969
       pas encoré détecté l'aspect "big-endian/little-endian"
 
1970
       d'un fichier binaire C, et les octets peuvent donc être permutés */
 
1971
 
 
1972
    affiche_extents = true;
 
1973
 
 
1974
    ret = ecs_loc_pre_ens__lit_chaine_essai(fic, chaine, &num_ligne);
 
1975
 
 
1976
  }
 
1977
  else if (ret != NULL && strncmp(chaine, "part", strlen("part")) != 0)
 
1978
    ecs_error(__FILE__, __LINE__, 0,
 
1979
              _("EnSight: \"%s\" field encountered where\n"
 
1980
                "\"extents\" or \"part\" was expected."), chaine);
 
1981
 
 
1982
  if (ret == NULL)
 
1983
    ecs_error(__FILE__, __LINE__, 0,
 
1984
              _("File \"%s\"\n"
 
1985
                "defines no \"part\" (i.e. mesh)."),
 
1986
              ecs_file_get_name(fic));
 
1987
 
 
1988
  /* Début des "parts" */
 
1989
  /*-------------------*/
 
1990
 
 
1991
  while (fin_lecture == false)  {
 
1992
 
 
1993
    int32_t  num_part_lu;
 
1994
    int32_t  cpt_part_lu = 0;
 
1995
 
 
1996
    /* Numéro de part */
 
1997
 
 
1998
    ecs_loc_pre_ens__lit_int(fic, 1, &num_part_lu, 10, &num_ligne);
 
1999
 
 
2000
    /* Détection "big-endian/little-endian" pour un fichier binaire C */
 
2001
 
 
2002
    if (cpt_part_lu == 0 && ecs_file_get_type(fic) == ECS_FILE_TYPE_BINARY) {
 
2003
 
 
2004
      if (num_part_lu < 0 || num_part_lu > 1000) {
 
2005
        ecs_file_swap_endian(&num_part_lu, &num_part_lu, 4, 1);
 
2006
        if (num_part_lu < 0 || num_part_lu > 1000)
 
2007
          ecs_error
 
2008
            (__FILE__, __LINE__, 0,
 
2009
             _("EnSight: file \"%s\" seems to be\n"
 
2010
               "of C binary type but the number of the first \"part\"\n"
 
2011
               "is < 0 ou > 1000 and provokes the failure of the automatic\n"
 
2012
               "\"big-endian/little-endian\" detection."),
 
2013
             ecs_file_get_name(fic));
 
2014
        else {
 
2015
          swap_endian = true;
 
2016
          if (ecs_file_get_swap_endian(fic) == 1)
 
2017
            ecs_file_set_swap_endian(fic, 0);
 
2018
          else
 
2019
            ecs_file_set_swap_endian(fic, 1);
 
2020
          /* Correction extents */
 
2021
          ecs_file_swap_endian(coo_min_max,
 
2022
                               coo_min_max,
 
2023
                               sizeof(float),
 
2024
                               6);
 
2025
        }
 
2026
      }
 
2027
 
 
2028
    }
 
2029
 
 
2030
    /* On peut maintenant afficher les "extents" */
 
2031
 
 
2032
    if (affiche_extents == true) {
 
2033
      printf(_("  xmin = %12.5e; xmax = %12.5e\n"
 
2034
               "  ymin = %12.5e; ymax = %12.5e\n"
 
2035
               "  zmin = %12.5e; zmax = %12.5e\n\n"),
 
2036
             coo_min_max[0], coo_min_max[1], coo_min_max[2],
 
2037
             coo_min_max[3], coo_min_max[4], coo_min_max[5]);
 
2038
      affiche_extents = false;
 
2039
    }
 
2040
 
 
2041
    if (taille_liste_elems > 0 && lire_node_id == false) {
 
2042
      printf(_("  Remark: no vertex ids given\n"
 
2043
               "  --> impossible to merge EnSight \"parts\",\n"
 
2044
               "      so the following \"parts\" are ignored.\n\n"));
 
2045
      break;
 
2046
    }
 
2047
    else if (num_part > 0 && num_part != num_part_lu) {
 
2048
      importer_part = false;
 
2049
      printf(_("  part %2d (ignored): "), (int)num_part_lu);
 
2050
    }
 
2051
    else {
 
2052
      importer_part = true;
 
2053
      printf(_("  part %2d: "), (int)num_part_lu);
 
2054
    }
 
2055
 
 
2056
    /* Description */
 
2057
 
 
2058
    ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
2059
 
 
2060
    printf("%s\n\n", chaine);
 
2061
 
 
2062
    /* Lecture des noeuds */
 
2063
    /*--------------------*/
 
2064
 
 
2065
    ecs_loc_pre_ens__lit_noeuds_gold(fic,
 
2066
                                     (ecs_int_t)num_part_lu,
 
2067
                                     lire_node_id,
 
2068
                                     importer_part,
 
2069
                                     &taille_liste_noeuds,
 
2070
                                     &liste_noeuds,
 
2071
                                     chaine,
 
2072
                                     &num_ligne);
 
2073
 
 
2074
    /* Lecture des éléments */
 
2075
    /*----------------------*/
 
2076
 
 
2077
    do {
 
2078
 
 
2079
      ret = ecs_loc_pre_ens__lit_chaine_essai(fic, chaine, &num_ligne);
 
2080
 
 
2081
      if (ret == NULL)
 
2082
        fin_lecture = true;
 
2083
 
 
2084
      else
 
2085
 
 
2086
        nbr_elt_lus = ecs_loc_pre_ens__lit_elem_gold
 
2087
                        (fic,
 
2088
                         (ecs_int_t)num_part_lu,
 
2089
                         lire_elem_id,
 
2090
                         importer_part,
 
2091
                         liste_noeuds + taille_liste_noeuds - 1,
 
2092
                         &taille_liste_elems,
 
2093
                         &liste_elems,
 
2094
                         chaine,
 
2095
                         &num_ligne);
 
2096
 
 
2097
    } while (nbr_elt_lus > -1 && fin_lecture == false);
 
2098
 
 
2099
    printf("\n");
 
2100
 
 
2101
    /* Fusion des définitions des noeuds */
 
2102
 
 
2103
    if (importer_part)
 
2104
 
 
2105
      ecs_loc_pre_ens__trie_noeuds(liste_noeuds + taille_liste_noeuds - 1);
 
2106
 
 
2107
    if (taille_liste_noeuds == 2) {
 
2108
 
 
2109
      ecs_loc_pre_ens__fusion_noeuds(liste_noeuds,
 
2110
                                     liste_noeuds + 1);
 
2111
 
 
2112
      taille_liste_noeuds = 1; /* La réallocation éventuelle à 2 entités
 
2113
                                   de liste_noeuds[] sera inutile mais
 
2114
                                   triviale et sans risque */
 
2115
    }
 
2116
 
 
2117
    /* Autres parts ? */
 
2118
 
 
2119
    cpt_part_lu++;
 
2120
 
 
2121
    if (num_part > 0 && num_part == num_part_lu)
 
2122
      fin_lecture = true;
 
2123
  }
 
2124
 
 
2125
  /* Si l'on n'a pas trouvé de "part" (ou pas celle demandée),
 
2126
     la liste des noeuds n'est encore pas définie */
 
2127
 
 
2128
  if (liste_noeuds == NULL) {
 
2129
    if (num_part > 0)
 
2130
      ecs_error(__FILE__, __LINE__, 0,
 
2131
                _("EnSight: file \"%s\" does not contain a\n"
 
2132
                  "\"part\" with the required number (%d)."),
 
2133
                ecs_file_get_name(fic), (int)num_part);
 
2134
    else
 
2135
      ecs_error(__FILE__, __LINE__, 0,
 
2136
                _("EnSight: file \"%s\" does not contain any \"part\"."),
 
2137
                ecs_file_get_name(fic));
 
2138
  }
 
2139
 
 
2140
  /* Fermeture du fichier de lecture du maillage */
 
2141
 
 
2142
  ecs_file_free(fic);
 
2143
 
 
2144
  /* Remplissage de la structure de maillage */
 
2145
  /*-----------------------------------------*/
 
2146
 
 
2147
  /* Traitement des sommets */
 
2148
 
 
2149
  ecs_maillage_pre__cree_som(maillage,
 
2150
                             liste_noeuds[0].nbr_noeuds,
 
2151
                             liste_noeuds[0].coord);
 
2152
 
 
2153
  /* Traitement des éléments */
 
2154
 
 
2155
  /* Concaténation des éléments par leur dimension */
 
2156
 
 
2157
  ecs_loc_pre_ens__concat_elems(maillage,
 
2158
                                taille_liste_elems,
 
2159
                                &(liste_noeuds[0]),
 
2160
                                &liste_elems);
 
2161
 
 
2162
  ECS_FREE(liste_noeuds);
 
2163
 
 
2164
  /* Renvoi de la structure de maillage */
 
2165
 
 
2166
  return maillage;
 
2167
}
 
2168
 
 
2169
/*----------------------------------------------------------------------------
 
2170
 *  Lecture d'un fichier au format EnSight 6
 
2171
 *   et affectation des données dans la structure de maillage
 
2172
 *----------------------------------------------------------------------------*/
 
2173
 
 
2174
static ecs_maillage_t  *
 
2175
ecs_loc_pre_ens__lit_geo_6(const char       *nom_fic_geo,
 
2176
                           const ecs_int_t   num_part)
 
2177
{
 
2178
  char              chaine[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
2179
  char              chaine_aux[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
2180
 
 
2181
  char             *ret = NULL;
 
2182
 
 
2183
  ecs_int_t         nbr_elt_lus = 0;
 
2184
  bool              pb_rub;
 
2185
  bool              lire_node_id;
 
2186
  bool              lire_elem_id;
 
2187
  bool              importer_part;
 
2188
 
 
2189
  ecs_file_t       *fic;
 
2190
 
 
2191
  ecs_int_t         taille_liste_noeuds = 0;
 
2192
  ecs_int_t         taille_liste_elems = 0;
 
2193
 
 
2194
  ecs_loc_noeuds_ens_t  *liste_noeuds = NULL;
 
2195
  ecs_loc_elems_ens_t   *liste_elems = NULL;
 
2196
 
 
2197
  int         num_ligne   = 1;
 
2198
  bool        fin_lecture = false;
 
2199
 
 
2200
  /* Création d'un maillage initialament vide (valeur de retour) */
 
2201
 
 
2202
  ecs_maillage_t  *maillage = ecs_maillage__cree_nodal();
 
2203
 
 
2204
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
2205
 
 
2206
  /* Ouverture du fichier Géométrie et vérification du format */
 
2207
  /*----------------------------------------------------------*/
 
2208
 
 
2209
  fic = ecs_loc_pre_ens__ouverture_fic_geo(nom_fic_geo);
 
2210
 
 
2211
  /* Lecture de l'entête */
 
2212
  /*---------------------*/
 
2213
 
 
2214
  /* 2 lignes de description */
 
2215
 
 
2216
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
2217
 
 
2218
  printf(_("\n"
 
2219
           "  Description:\n\n  %s\n"), chaine);
 
2220
 
 
2221
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
2222
 
 
2223
  printf("  %s\n\n", chaine);
 
2224
 
 
2225
  /* Infos sur ids sommets */
 
2226
 
 
2227
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
2228
 
 
2229
  pb_rub = false;
 
2230
 
 
2231
  if (strncmp(chaine, "node id", strlen("node id")) != 0)
 
2232
    pb_rub = true;
 
2233
  else if (sscanf(chaine, "%*s %*s %s", chaine_aux) != 1)
 
2234
    pb_rub = true;
 
2235
 
 
2236
  if (pb_rub == true)
 
2237
    ecs_error(__FILE__, __LINE__, 0,
 
2238
              _("EnSight: \"node id\" field missing or badly placed."));
 
2239
  else
 
2240
    printf("  node id:    %s\n", chaine_aux);
 
2241
 
 
2242
  if (   (strncmp(chaine_aux, "given",  strlen("given"))   == 0)
 
2243
      || (strncmp(chaine_aux, "ignore", strlen("ignore"))  == 0))
 
2244
    lire_node_id = true;
 
2245
  else
 
2246
    lire_node_id = false;
 
2247
 
 
2248
 
 
2249
  /* Infos sur ids éléments */
 
2250
 
 
2251
  ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
2252
 
 
2253
  pb_rub = false;
 
2254
 
 
2255
  if (strncmp(chaine, "element id", strlen("element id")) != 0)
 
2256
    pb_rub = true;
 
2257
  else if (sscanf(chaine, "%*s %*s %s", chaine_aux) != 1)
 
2258
    pb_rub = true;
 
2259
 
 
2260
  if (pb_rub == true)
 
2261
    ecs_error(__FILE__, __LINE__, 0,
 
2262
              _("EnSight: \"element id\" field missing or badly placed"));
 
2263
  else
 
2264
    printf("  element id: %s\n\n", chaine_aux);
 
2265
 
 
2266
  if (   (strncmp(chaine_aux, "given",  strlen("given"))   == 0)
 
2267
      || (strncmp(chaine_aux, "ignore", strlen("ignore"))  == 0))
 
2268
    lire_elem_id = true;
 
2269
  else
 
2270
    lire_elem_id = false;
 
2271
 
 
2272
  /* Détection big-endian/little-endian en cas de fichier binaire C */
 
2273
  /*----------------------------------------------------------------*/
 
2274
 
 
2275
  if (ecs_file_get_type(fic) == ECS_FILE_TYPE_BINARY)
 
2276
 
 
2277
    ecs_loc_pre_ens__c_bin_endian_6(fic, lire_node_id);
 
2278
 
 
2279
 
 
2280
  /* Lecture des noeuds */
 
2281
  /*--------------------*/
 
2282
 
 
2283
  ecs_loc_pre_ens__lit_noeuds_6(fic,
 
2284
                                lire_node_id,
 
2285
                                &taille_liste_noeuds,
 
2286
                                &liste_noeuds,
 
2287
                                chaine,
 
2288
                                &num_ligne);
 
2289
 
 
2290
  ret = ecs_loc_pre_ens__lit_chaine_essai(fic, chaine, &num_ligne);
 
2291
 
 
2292
  if (ret == NULL)
 
2293
    ecs_error(__FILE__, __LINE__, 0,
 
2294
              _("File \"%s\"\n"
 
2295
                "defines no \"part\" (i.e. mesh)."),
 
2296
              ecs_file_get_name(fic));
 
2297
 
 
2298
  else if (ret != NULL && strncmp(chaine, "part", strlen("part")) != 0)
 
2299
    ecs_error(__FILE__, __LINE__, 0,
 
2300
              _("EnSight: \"%s\" field encountered where\n"
 
2301
                "\"part\" was expected."), chaine);
 
2302
 
 
2303
 
 
2304
  /* Début des "parts" */
 
2305
  /*-------------------*/
 
2306
 
 
2307
  while (fin_lecture == false)  {
 
2308
 
 
2309
    int32_t  num_part_lu;
 
2310
    int32_t  cpt_part_lu = 0;
 
2311
 
 
2312
    /* Numéro de part */
 
2313
 
 
2314
    num_part_lu = atoi(chaine+strlen("part"));
 
2315
 
 
2316
    /* Détection "big-endian/little-endian" pour un fichier binaire C */
 
2317
 
 
2318
 
 
2319
    /* Pour EnSight6 on peut toujours fusionner */
 
2320
 
 
2321
    if (num_part > 0 && num_part != num_part_lu) {
 
2322
      importer_part = false;
 
2323
      printf(_("  part %2d (ignored): "), (int)num_part_lu);
 
2324
    }
 
2325
    else {
 
2326
      importer_part = true;
 
2327
      printf(_("  part %2d: "), (int)num_part_lu);
 
2328
    }
 
2329
 
 
2330
    /* Description */
 
2331
 
 
2332
    ecs_loc_pre_ens__lit_chaine(fic, chaine, &num_ligne);
 
2333
 
 
2334
    printf("%s\n\n", chaine);
 
2335
 
 
2336
    /* Tri des noeuds */
 
2337
 
 
2338
    ecs_loc_pre_ens__trie_noeuds(liste_noeuds + taille_liste_noeuds - 1);
 
2339
 
 
2340
    /* Lecture des éléments */
 
2341
    /*----------------------*/
 
2342
 
 
2343
    do {
 
2344
 
 
2345
      ret = ecs_loc_pre_ens__lit_chaine_essai(fic, chaine, &num_ligne);
 
2346
 
 
2347
      if (ret == NULL)
 
2348
        fin_lecture = true;
 
2349
 
 
2350
      else
 
2351
 
 
2352
        nbr_elt_lus
 
2353
          = ecs_loc_pre_ens__lit_elem_6(fic,
 
2354
                                        (ecs_int_t)num_part_lu,
 
2355
                                        lire_elem_id,
 
2356
                                        importer_part,
 
2357
                                        &taille_liste_elems,
 
2358
                                        &liste_elems,
 
2359
                                        chaine,
 
2360
                                        &num_ligne);
 
2361
 
 
2362
    } while (nbr_elt_lus > -1 && fin_lecture == false);
 
2363
 
 
2364
    printf("\n");
 
2365
 
 
2366
    /* Autres parts ? */
 
2367
 
 
2368
    cpt_part_lu++;
 
2369
 
 
2370
    if (num_part > 0 && num_part == num_part_lu)
 
2371
      fin_lecture = true;
 
2372
 
 
2373
  }
 
2374
 
 
2375
  /* Si l'on n'a pas trouvé de "part" (ou pas celle demandée),
 
2376
     la liste des noeuds n'est encore pas définie */
 
2377
 
 
2378
  if (liste_elems == NULL) {
 
2379
    if (num_part > 0)
 
2380
      ecs_error(__FILE__, __LINE__, 0,
 
2381
                _("EnSight: file \"%s\" does not contain a\n"
 
2382
                  "\"part\" with the required number (%d)."),
 
2383
                ecs_file_get_name(fic), (int)num_part);
 
2384
    else
 
2385
      ecs_error(__FILE__, __LINE__, 0,
 
2386
                _("EnSight: file \"%s\" does not contain any \"part\"."),
 
2387
                ecs_file_get_name(fic));
 
2388
  }
 
2389
 
 
2390
  /* Fermeture du fichier de lecture du maillage */
 
2391
 
 
2392
  ecs_file_free(fic);
 
2393
 
 
2394
  /* Remplissage de la structure de maillage */
 
2395
  /*-----------------------------------------*/
 
2396
 
 
2397
  /* Traitement des sommets */
 
2398
 
 
2399
  ecs_maillage_pre__cree_som(maillage,
 
2400
                             liste_noeuds[0].nbr_noeuds,
 
2401
                             liste_noeuds[0].coord);
 
2402
 
 
2403
  /* Traitement des éléments */
 
2404
 
 
2405
  /* Concaténation des éléments par leur dimension */
 
2406
 
 
2407
  ecs_loc_pre_ens__concat_elems(maillage,
 
2408
                                taille_liste_elems,
 
2409
                                &(liste_noeuds[0]),
 
2410
                                &liste_elems);
 
2411
 
 
2412
  ECS_FREE(liste_noeuds);
 
2413
 
 
2414
  /* Renvoi de la structure de maillage */
 
2415
 
 
2416
  return maillage;
 
2417
}
 
2418
 
 
2419
/*============================================================================
 
2420
 *                             Fonctions publiques
 
2421
 *============================================================================*/
 
2422
 
 
2423
/*----------------------------------------------------------------------------
 
2424
 *  Lecture d'un fichier au format EnSight Gold
 
2425
 *   et affectation des données dans la structure de maillage
 
2426
 *----------------------------------------------------------------------------*/
 
2427
 
 
2428
ecs_maillage_t *
 
2429
ecs_pre_ens__lit_maillage(const char  *nom_fic_case,
 
2430
                          int          num_maillage)
 
2431
{
 
2432
  char             *nom_fic_geo;
 
2433
  int               timeset;
 
2434
  int               fileset;
 
2435
  size_t            ind;
 
2436
  ecs_file_t       *fic;
 
2437
 
 
2438
  char              ligne[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
2439
  char              nom_fic_geo_base[ECS_LOC_LNG_MAX_CHAINE_ENS];
 
2440
 
 
2441
  int               num_ligne = 1;
 
2442
 
 
2443
  bool              fmt_ensight      = false;
 
2444
  bool              fmt_ensight_gold = false;
 
2445
 
 
2446
  char             *ret = NULL;
 
2447
 
 
2448
  ecs_maillage_t   *maillage = NULL;
 
2449
 
 
2450
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
2451
 
 
2452
  printf(_("\n\n"
 
2453
           "Reading mesh from file in EnSight format\n"
 
2454
           "----------------------\n"));
 
2455
 
 
2456
  printf(_("  \"case\" file: %s\n"), nom_fic_case);
 
2457
 
 
2458
  /* Ouverture du fichier Case */
 
2459
 
 
2460
  fic = ecs_file_open(nom_fic_case,
 
2461
                      ECS_FILE_MODE_READ,
 
2462
                      ECS_FILE_TYPE_TEXT);
 
2463
 
 
2464
  /* Vérification du format */
 
2465
 
 
2466
  do {
 
2467
    ret = ecs_file_gets_try(ligne, ECS_LOC_LNG_MAX_CHAINE_ENS, fic, &num_ligne);
 
2468
  } while (ret != NULL && strncmp(ligne, "FORMAT", strlen("FORMAT")) != 0);
 
2469
 
 
2470
  if (ret != NULL) {
 
2471
 
 
2472
    do {
 
2473
      ret = ecs_file_gets_try(ligne, ECS_LOC_LNG_MAX_CHAINE_ENS,
 
2474
                              fic, &num_ligne);
 
2475
    } while (ret != NULL && strncmp(ligne, "type:", strlen("type:")) != 0);
 
2476
 
 
2477
  }
 
2478
 
 
2479
  if (ret != NULL) {
 
2480
 
 
2481
    for (ind = strlen("type:");
 
2482
         ligne[ind] != '\0' && (ligne[ind] == ' ' || ligne[ind] == '\t');
 
2483
         ind++);
 
2484
 
 
2485
    if (strncmp(ligne + ind, "ensight", strlen("ensight")) == 0) {
 
2486
 
 
2487
      fmt_ensight = true;
 
2488
 
 
2489
      ind += strlen("ensight");
 
2490
      while (ligne[ind] != '\0' && (ligne[ind] == ' ' || ligne[ind] == '\t'))
 
2491
        ind++;
 
2492
 
 
2493
      if (strncmp(ligne + ind, "gold", strlen("gold")) == 0)
 
2494
 
 
2495
        fmt_ensight_gold = true;
 
2496
 
 
2497
    }
 
2498
 
 
2499
  }
 
2500
 
 
2501
  if (fmt_ensight == false)
 
2502
    ecs_error(__FILE__, __LINE__, 0,
 
2503
              _("File \"%s\" does not seem to be a valid\n"
 
2504
                "EnSight 6 or Gold case file."),
 
2505
              nom_fic_case);
 
2506
 
 
2507
  /* Recherche des infos sur le fichier géométrique */
 
2508
 
 
2509
  do {
 
2510
    ret = ecs_file_gets_try(ligne, ECS_LOC_LNG_MAX_CHAINE_ENS,
 
2511
                            fic, &num_ligne);
 
2512
  } while (ret != NULL && strncmp(ligne, "GEOMETRY", strlen("GEOMETRY")) != 0);
 
2513
 
 
2514
  if (ret != NULL) {
 
2515
 
 
2516
    do {
 
2517
      ret = ecs_file_gets_try(ligne, ECS_LOC_LNG_MAX_CHAINE_ENS,
 
2518
                              fic, &num_ligne);
 
2519
    } while (ret != NULL && strncmp(ligne, "model:", strlen("model:")) != 0);
 
2520
 
 
2521
  }
 
2522
 
 
2523
  if (ret != NULL) {
 
2524
 
 
2525
    /* La rubrique model: contient deux numéros optionnels (numéro de pas de
 
2526
       temps et de jeux de fichiers), le nom de base du ou des fichiers
 
2527
       géométriques, et éventuellement l'option "change_coords_only" */
 
2528
 
 
2529
    if (sscanf(ligne, "%*s %d %d %s",
 
2530
               &timeset, &fileset, nom_fic_geo_base) != 3) {
 
2531
      if (sscanf(ligne, "%*s %d %s",
 
2532
                 &timeset, nom_fic_geo_base) != 2) {
 
2533
        if (sscanf(ligne, "%*s %s",
 
2534
                   nom_fic_geo_base) != 1)
 
2535
          ecs_error(__FILE__, __LINE__, 0,
 
2536
                    _("The \"%s\" case file does not seem to\n"
 
2537
                      "indicate a geometry file"),
 
2538
                    nom_fic_case);
 
2539
      }
 
2540
    }
 
2541
 
 
2542
    /* On vérifie que le nom ne contienne pas de caractères "*" */
 
2543
 
 
2544
    for (ind = 0; nom_fic_geo_base[ind] != '\0'; ind++)
 
2545
      if (nom_fic_geo_base[ind] == '*')
 
2546
        ecs_error(__FILE__, __LINE__, 0,
 
2547
                  _("The \"%s\" case file seems to indicate the\n"
 
2548
                    "series of geometric files named:\n"
 
2549
                    "\"%s\".\n"
 
2550
                    "A single file must be chosen."),
 
2551
                  nom_fic_case, nom_fic_geo_base);
 
2552
 
 
2553
  }
 
2554
 
 
2555
  /* On n'a plus besoin du fichier ".case" */
 
2556
 
 
2557
  ecs_file_free(fic);
 
2558
 
 
2559
  /* Maintenant, on extrait le préfixe du nom du fichier ".case" */
 
2560
 
 
2561
  for (ind = strlen(nom_fic_case) - 1;
 
2562
       ind > 0 && nom_fic_case[ind] != ECS_PATH_SEP;
 
2563
       ind--);
 
2564
 
 
2565
  if (nom_fic_case[ind] == ECS_PATH_SEP)
 
2566
    ind++;
 
2567
 
 
2568
  ECS_MALLOC(nom_fic_geo, ind + strlen(nom_fic_geo_base) + 1, char);
 
2569
  strncpy(nom_fic_geo, nom_fic_case, ind);
 
2570
  strcpy(nom_fic_geo + ind, nom_fic_geo_base);
 
2571
 
 
2572
  /* On connaît maintenant le nom du fichier géométrique */
 
2573
 
 
2574
  printf(_("  \"geo\"  file: %s\n\n"), nom_fic_geo);
 
2575
 
 
2576
  /* Lecture du fichier géométrique associé */
 
2577
  /*----------------------------------------*/
 
2578
 
 
2579
  if (fmt_ensight_gold == true)
 
2580
    maillage = ecs_loc_pre_ens__lit_geo_gold(nom_fic_geo,
 
2581
                                             num_maillage);
 
2582
 
 
2583
  else if (fmt_ensight == true)
 
2584
    maillage = ecs_loc_pre_ens__lit_geo_6(nom_fic_geo,
 
2585
                                          num_maillage);
 
2586
 
 
2587
  /* Libération mémoire et retour */
 
2588
 
 
2589
  ECS_FREE(nom_fic_geo);
 
2590
 
 
2591
  return maillage;
 
2592
}
 
2593
 
 
2594
/*----------------------------------------------------------------------------*/
 
2595