File: ecs_fic.c

package info (click to toggle)
code-saturne 5.3.2%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 76,868 kB
  • sloc: ansic: 338,582; f90: 118,487; python: 65,227; makefile: 4,429; cpp: 3,826; xml: 3,078; sh: 1,205; lex: 170; yacc: 100
file content (201 lines) | stat: -rw-r--r-- 5,961 bytes parent folder | download
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
/*============================================================================
 *  Définitions des fonctions de base
 *   associées aux impressions dans un fichier
 *============================================================================*/

/*
  This file is part of Code_Saturne, a general-purpose CFD tool.

  Copyright (C) 1998-2018 EDF S.A.

  This program 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.

  This program 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
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*----------------------------------------------------------------------------*/

#include "ecs_def.h"

/*----------------------------------------------------------------------------
 * Standard C library headers
 *----------------------------------------------------------------------------*/

#include <assert.h>
#include <stdarg.h>
#include <string.h>

/*----------------------------------------------------------------------------
 *  Local headers
 *----------------------------------------------------------------------------*/

#include "ecs_file.h"
#include "ecs_mem.h"

/*----------------------------------------------------------------------------
 *  Headers for the current file
 *----------------------------------------------------------------------------*/

#include "ecs_fic.h"

/*----------------------------------------------------------------------------*/

BEGIN_C_DECLS

/*============================================================================
 * Local macro definitions
 *============================================================================*/

/* Formats pour impressions de tableaux dans un fichier */

#define ECS_LOC_IMP_FMT_INT             "%12d"
#define ECS_LOC_IMP_FMT_REAL         "%#12.5E"
#define ECS_LOC_IMP_FMT_CHAR            "%12s"
#define ECS_LOC_IMP_FMT_SIZE_T         "%12lu"
#define ECS_LOC_IMP_FMT_PTR             "%12p"
#define ECS_LOC_IMP_FMT_CONT    "............"
#define ECS_LOC_IMP_FMT_WIDTH               12

#define ECS_LOC_IMP_INDENT                   8

#define ECS_LOC_IMP_COL_VAL                  9
#define ECS_LOC_IMP_COL_IND                 51

/*============================================================================
 * Local function definitions
 *============================================================================*/

/*============================================================================
 * Public function definitions
 *============================================================================*/

/*----------------------------------------------------------------------------
 *  Fonction d'impression du nom et de la valeur d'un pointeur
 *----------------------------------------------------------------------------*/

void
ecs_fic__imprime_ptr(FILE         *fic_imp,
                     const int     profondeur_imp,
                     const char   *nom_ptr,
                     const void   *ptr)
{
  /* Instructions */

  assert(fic_imp != NULL);

  fprintf(fic_imp,
          "%-*s%s  & ", ECS_LOC_IMP_INDENT * profondeur_imp, "",
          nom_ptr);

  if (ptr == NULL)
    fprintf(fic_imp, "%s\n", "NULL");

  else
    fprintf(fic_imp, "%p\n", ptr);
}

/*----------------------------------------------------------------------------
 *  Fonction d'impression du nom et de la valeur d'une variable
 *----------------------------------------------------------------------------*/

void
ecs_fic__imprime_val(FILE         *fic_imp,
                     const int     profondeur_imp_nom,
                     const char   *nom,
                     ecs_type_t    typ_e,
                     const void   *val)
{
  /* Variables locales */

  int  nb_col_nom;
  int  profondeur_imp_val;

  /* Instructions */

  assert(fic_imp != NULL);

  if ((int)strlen(nom) < ECS_LOC_IMP_INDENT)
    nb_col_nom = 1;
  else
    nb_col_nom = 2;

  profondeur_imp_val
    = ECS_LOC_IMP_COL_VAL - profondeur_imp_nom - nb_col_nom - 1;

  fprintf(fic_imp,
          "%-*s%-*s%-*s",
          ECS_LOC_IMP_INDENT * profondeur_imp_nom, "" ,
          ECS_LOC_IMP_INDENT * nb_col_nom        , nom,
          ECS_LOC_IMP_INDENT * profondeur_imp_val, "");

  if (val == NULL)

    fprintf(fic_imp, ECS_LOC_IMP_FMT_CHAR "\n", "NULL");

  else {

    switch(typ_e) {

    case ECS_TYPE_ecs_int_t:

      {
        const int val_imp = *(const int *)val;
        fprintf(fic_imp, ECS_LOC_IMP_FMT_INT "\n", val_imp);
      }
      break;

    case ECS_TYPE_ecs_coord_t:

      {
        const ecs_coord_t val_imp = *(const ecs_coord_t *)val;
        fprintf(fic_imp, ECS_LOC_IMP_FMT_REAL "\n", val_imp);
      }
      break;

    case ECS_TYPE_char:

      {
        const char *val_imp = (const char *)val;
        fprintf(fic_imp, ECS_LOC_IMP_FMT_CHAR "\n", val_imp);
      }
      break;

    case ECS_TYPE_size_t:

      {
        const size_t val_imp = *(const size_t *)val;
        fprintf(fic_imp, ECS_LOC_IMP_FMT_SIZE_T "\n", (unsigned long)val_imp);
      }
      break;

    case ECS_TYPE_void:

      fprintf(fic_imp, ECS_LOC_IMP_FMT_PTR  "\n", val);
      break;

    default:
      assert(   typ_e == ECS_TYPE_ecs_int_t
             || typ_e == ECS_TYPE_ecs_coord_t
             || typ_e == ECS_TYPE_char
             || typ_e == ECS_TYPE_size_t
             || typ_e == ECS_TYPE_void);
    }

  }

  fflush(fic_imp);
}

/*----------------------------------------------------------------------------*/

END_C_DECLS