MED fichier
MED1cstring.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2016 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 
20 #include <stdlib.h>
21 #include "med_config.h"
22 #include "med_outils.h"
23 
24 /*
25  * - Nom de la fonction : _MED1cstring
26  * - Description : convertit une chaine de caracteres FORTRAN
27  * en une nouvelle chaine de caracteres C
28  * dont la longueur est passee en parametre.
29  * Les caracteres completes sont des blancs
30  * Cette routine est utile au les paramètres chaînes f77 au format chaînes de taille fixe de l'API C.
31  * - Parametres :
32  * - chaine (IN) : la chaine FORTRAN
33  * - longueur_reelle (IN) : la longueur de la chaine FORTRAN
34  * - longueur_fixee (IN) : longueur de la chaine C a construire
35  * - Resultat : la nouvelle chaine C en cas de succes, NULL sinon
36  */
37 char *_MED1cstring(char *chaine,int longueur_reelle,int longueur_fixee)
38 {
39  char *nouvelle;
40  int i;
41  med_err _ret = 0;
42 
43  if (longueur_reelle > longueur_fixee) {
44  fprintf(stderr,"Erreur n°1 ds _MED1cstring\n");
45  return NULL;
46  }
47  if ((nouvelle = (char *) malloc(sizeof(char)*(longueur_fixee+1))) == NULL) {
48  fprintf(stderr,"Erreur n°2 ds _MED1cstring : longueur_reelle %d, longueur_fixee %d\n",longueur_reelle,longueur_fixee);
50  return NULL;
51  }
52 
53  for (i=0;i<longueur_reelle;i++)
54  *(nouvelle+i) = *(chaine+i);
55 
56  for (i=longueur_reelle;i<longueur_fixee;i++)
57  *(nouvelle+i) = ' ';
58 
59  *(nouvelle+longueur_fixee) = '\0';
60 
61  return nouvelle;
62 }
63 
herr_t med_err
Definition: med.h:310
char * _MED1cstring(char *chaine, int longueur_reelle, int longueur_fixee)
Definition: MED1cstring.c:37
#define MED_ERR_NOTNULL
Definition: med_err.h:33
#define MED_ERR_NAME_MSG
Definition: med_err.h:190
#define MED_ERR_API
Definition: med_err.h:108
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:158