File: mod_ideas.c

package info (click to toggle)
code-saturne 6.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 63,340 kB
  • sloc: ansic: 354,724; f90: 119,812; python: 87,716; makefile: 4,653; cpp: 4,272; xml: 2,839; sh: 1,228; lex: 170; yacc: 100
file content (226 lines) | stat: -rw-r--r-- 5,126 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*============================================================================
 *  Modification des coordonnées d'un fichier de maillage
 *  IDEAS-MS au format "universel"
 *============================================================================*/

/*
  This file is part of the Code_Saturne Preprocessor, element of the
  Code_Saturne CFD tool.

  Copyright (C) 1999-2007 EDF S.A., France

  contact: saturne-support@edf.fr

  The Code_Saturne Preprocessor is free software; you can redistribute it
  and/or modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2 of
  the License, or (at your option) any later version.

  The Code_Saturne Preprocessor is distributed in the hope that it will be
  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with the Code_Saturne Preprocessor; if not, write to the
  Free Software Foundation, Inc.,
  51 Franklin St, Fifth Floor,
  Boston, MA  02110-1301  USA
*/


#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* Pour une lecture de 80 caracteres par ligne  */
/* auxquels il faut ajouter le `\n' et le `\0'  */
/* pour l'affectation dans la chaine receptrice */
#define LNG_MAX_CHAINE_IDEAS  82                /* Dimension des chaînes */

typedef enum {
  HORS_DATASET,
  MARQUE_DEB,
  NUM_DATASET,
  CONTENU,
  MARQUE_FIN
} ligne_data_t;


/*----------------------------------------------------------------------------
 *  Fonction utilitaire pour la lecture/écriture des réels d'un fichier
 *  I-DEAS.
 *
 *  La chaîne contenant un réel avec (ou non) un exposant `d' ou `D'
 *  est convertie en réel avec un exposant `e'
 *----------------------------------------------------------------------------*/

static void transf_geo
(
 double *x,
 double *y,
 double *z
)
{
  *x = (*x) * 1.0;
  *y = (*y) * 1.0;
  *z = (*z) * 1.0;
}

/*============================================================================
 *                             Fonction principale
 *============================================================================*/

int main
(
 int    argc   ,
 char * argv[]
)
{

  char  chaine[LNG_MAX_CHAINE_IDEAS + 2];
  char *s;
  FILE *fic_lec, *fic_ecr;
  int   ret;

  char         *res = NULL;
  ligne_data_t ind_rub = HORS_DATASET;
  int          ds_nod = 0;
  int          ind_pair = 0;


  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/

  if  (argc < 3) {
    printf("Utilisation :\n%s nom_fic nom_fic_conv\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  fic_lec = fopen(argv[1], "rb");
  if (fic_lec == NULL) {
    fprintf(stderr, "Erreur à l'ouverture en lecture du fichier %s\n",
	    argv[1]);
    return EXIT_FAILURE;
  }
  fic_ecr = fopen(argv[2], "wb");
  if (fic_ecr == NULL) {
    fprintf(stderr, "Erreur à l'ouverture en écriture du fichier %s\n",
	    argv[2]);
    return EXIT_FAILURE;
  }

  while (ds_nod == 0 && feof(fic_lec) == 0) {

    res = fgets(chaine, LNG_MAX_CHAINE_IDEAS, fic_lec) ;

    if (res != NULL) {

      /* Début ou fin de rubrique */
      if ((ind_rub == HORS_DATASET || ind_rub == CONTENU)
	  && strlen(chaine) < 8) {
	if (strncmp(chaine, "    -1", 6) == 0) {
	  if (ind_rub == HORS_DATASET)
	    ind_rub = MARQUE_DEB;
	  else
	    ind_rub = MARQUE_FIN;
	}
      }

      /* Numéro de rubrique */
      else if (ind_rub == NUM_DATASET) {
	if (strncmp(chaine, "  2411", 6) == 0) {
	  fprintf(fic_ecr, "%s", chaine);
	  break;
	}
      }

      fprintf(fic_ecr, "%s", chaine);

      /* Préparation ligne suivante */
      switch(ind_rub) {
      case MARQUE_DEB:
	ind_rub = NUM_DATASET;
	break;
      case NUM_DATASET:
	ind_rub = CONTENU;
	break;
      case MARQUE_FIN:
	ind_rub = HORS_DATASET;
	break;
      default:
	break;
      }

    }

  }

  while (feof(fic_lec) == 0) {

    res = fgets(chaine, LNG_MAX_CHAINE_IDEAS, fic_lec) ;

    if (res != NULL) {

      if (strlen(chaine) < 8 && strncmp(chaine, "    -1", 6) == 0) {
	fprintf(fic_ecr, "%s", chaine);
	break;
      }

      /* Ligne paire ou impaire ? */

      if (ind_pair == 0)
	ind_pair = 1;

      else {

	char   ch_coord[3][LNG_MAX_CHAINE_IDEAS];
	double coord[3];
	ind_pair = 0;

	s = chaine ;

	while(*s != '\0' ) {
	  if (*s == 'D' || *s == 'd')
	    *s = 'e' ;
	  s++ ;
	}

	ret = sscanf(chaine, " %lf %lf %lf", coord, coord+1, coord+2);

	transf_geo(coord, coord+1, coord+2);

	sprintf(chaine, " %24.16E %24.16E %24.16E\n",
		coord[0], coord[1], coord[2]);

	s = chaine ;

	while(*s != '\0' ) {
	  if (*s == 'E' || *s == 'e')
	    *s = 'D' ;
	  s++ ;
	}

      }

      fprintf(fic_ecr, "%s", chaine);

    }

  }

  /* Recopie simple de la suite du fichier */
  while (feof(fic_lec) == 0) {
    res = fgets(chaine, LNG_MAX_CHAINE_IDEAS, fic_lec) ;
    if (res != NULL)
      fprintf(fic_ecr, "%s", chaine);
  }

  /* Fin */
  fclose(fic_lec);
  fclose(fic_ecr);

  return EXIT_SUCCESS ;

}