Salome HOME
#18963 Minimize compiler warnings
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumC.c
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : Calcium.c
24 //  Author : Eric Fayolle (EDF)
25 //  Module : KERNEL
26 //
27 #include "calcium.h"
28 #include "calciumf.h"
29 #include "CalciumFortranInt.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <stddef.h>
34
35 // Interface C de SalomeCalcium
36
37 typedef int InfoType;
38 typedef char bool;
39
40 //TODO: ajouter les prototypes pour eviter les pbs de passage par valeur
41 InfoType ecp_fint_ (void * component, char* nomVar, float t);
42 InfoType ecp_fini_ (void * component, char* nomVar, int i);
43 InfoType ecp_efft_ (void * component, char* nomVar, float t);
44 InfoType ecp_effi_ (void * component, char* nomVar, int i);
45
46 /************************************/
47 /* INTERFACES DE LECTURE EN 0 COPIE */
48 /************************************/
49
50 /* Definition des méthodes calcium étendues en 0 copie */
51 /* Le buffer est alloué par le port pas par l'utilisateur */
52 /* Remarquer le type ** de data */
53 /* L'utilisateur devra appeler ecp_..._free pour désallouer le buffer interne */
54 /* Attention en cas de lectures multiples : le buffer retourné est le même */
55 /* Attention si les niveaux sont actifs le buffer peut être supprimé automatiquement par calcium. */
56
57 #define CALCIUM_EXT_LECT_INTERFACE_C_(_name,_timeType,_type,_typeName,_qual) \
58   InfoType ecp_##_name (void * component, int mode,                     \
59                         _timeType * ti, _timeType * tf, int * i,        \
60                         char * nomvar, int bufferLength,                \
61                         int * nRead, _type _qual ** data ) {            \
62     size_t _nRead;                                                      \
63     long   _i=*i;                                                       \
64     fflush(stdout);                                                     \
65     fflush(stderr);                                                     \
66                                                                         \
67     InfoType info =  ecp_lecture_##_typeName (component, mode, ti, tf, &_i, \
68                                               nomvar, bufferLength, &_nRead, \
69                                               data );                   \
70     /*    std::cout << "-------- CalciumInterface(C Part), Valeur de data : " << std::endl; */ \
71     /*    std::cout << "Ptr :" << *data << std::endl;                           */ \
72     /*    for (int j=0; j<_nRead;++j)                                           */ \
73     /*      printf("--- Valeur de data[%d] : %d \n",j,(*data)[j]);              */ \
74     /*    std::cout << "Ptr :" << *data << std::endl;                           */ \
75     /*                                                                  */ \
76     /*    std::cerr << "-------- CalciumInterface(C Part) MARK 2 ------------------" << std::endl; */ \
77     if(mode == CP_SEQUENTIEL)   \
78       *i = _i;                                                          \
79     *nRead=_nRead;                                                      \
80     /*    std::cerr << "-------- CalciumInterface(C Part) MARK 3 ------------------" << std::endl; */ \
81                                                                         \
82     return info;                                                        \
83   }                                                                    \
84   void ecp_##_name##_free ( _type _qual * data) {                       \
85     ecp_lecture_##_typeName##_free(data);                               \
86   }
87
88
89 /* L'interface de cette routine diffère de celle obtenue par la macro :
90    CALCIUM_LECT_INTERFACE_C_.
91    Le paramètre supplémentaire strSize indique la taille fixe et identique
92    des chaînes stockées dans data (les ports CALCIUM n'en n'ont pas besoin)
93 */
94 InfoType ecp_lch(void * component, int mode, float * ti,        float * tf, int * i,
95                 char  * nomvar, int bufferLength, int * nRead,
96                 char *** data, int strSize) {
97
98   size_t _nRead;
99   long   _i=*i;
100   (void)strSize; // unused parameter
101   fflush(stdout);fflush(stderr);
102
103   InfoType info =  ecp_lecture_str (component, mode, ti, tf, &_i,
104                                     nomvar, bufferLength, &_nRead,
105                                     data);/*, strSize );
106                                              strSize est  inutile pour les ports CALCIUM
107                                              qui gèrent des tailles quelconques de chaines. */
108   if(mode == CP_SEQUENTIEL)
109     *i = _i;
110   *nRead=_nRead;
111   fflush(stdout);fflush(stderr);
112   return info;
113 }
114
115 void ecp_lch_free (char* * data) {                              \
116   ecp_lecture_str_free(data);                                   \
117 }
118
119
120 #define STAR *
121 /*REVERIFIER MAINTENANT 0 COPY avec int2integer*/
122 CALCIUM_EXT_LECT_INTERFACE_C_(len,float,int,int2integer,)
123 CALCIUM_EXT_LECT_INTERFACE_C_(lre,float,float,float,)
124 /*Permet d'envoyer/recevoir des réels sur un port Double  */
125 CALCIUM_EXT_LECT_INTERFACE_C_(lrd,float ,float  ,float2double,)
126 CALCIUM_EXT_LECT_INTERFACE_C_(ldb,double,double,double,)
127
128 CALCIUM_EXT_LECT_INTERFACE_C_(llo,float,int,bool,)
129 CALCIUM_EXT_LECT_INTERFACE_C_(lcp,float,float,cplx,)
130 /* CALCIUM_EXT_LECT_INTERFACE_C_(lch,float,char,STAR[]);  */
131
132
133
134 /**************************************/
135 /* INTERFACES DE LECTURE AVEC RECOPIE */
136 /**************************************/
137
138 #define CALCIUM_LECT_INTERFACE_C_(_name,_timeType,_calInt,_type,_typeName,_qual,lastarg) \
139   _calInt cp_##_name (void * component, _calInt mode,                   \
140                        _timeType * ti, _timeType * tf, _calInt * i,     \
141                        char * nomvar, _calInt bufferLength,             \
142                        _calInt * nRead, _type _qual * data              \
143                        lastarg ) {                                      \
144                                                                         \
145     int    _mode         = (int) mode;                                  \
146     size_t _bufferLength = bufferLength;                                \
147     size_t _nRead;                                                      \
148     long   _i            =*i;                                           \
149     fflush(stdout);                                                     \
150     fflush(stderr);                                                     \
151                                                                         \
152     if ( (data == NULL) || (_bufferLength < 1) ) return CPNTNULL;       \
153                                                                         \
154     _calInt info =  ecp_lecture_##_typeName (component, _mode, ti, tf, &_i, \
155                                               nomvar, _bufferLength, &_nRead, \
156                                               &data );                  \
157     if(mode == CP_SEQUENTIEL)                                           \
158       *i = _i;                                                          \
159     *nRead=_nRead;                                                      \
160     fflush(stdout);                                                     \
161     fflush(stderr);                                                     \
162                                                                         \
163     return info;                                                        \
164   }                                                                    \
165   void cp_##_name##_free ( _type _qual * data) {                        \
166     ecp_lecture_##_typeName##_free(data);                               \
167   }
168
169
170 /* L'interface de cette routine diffère de celle obtenue par la macro :
171    CALCIUM_LECT_INTERFACE_C_.
172    Le paramètre supplémentaire strSize indique la taille fixe et identique
173    des chaînes stockées dans data (les ports CALCIUM n'en n'ont pas besoin)
174 */
175
176 /* InfoType cp_lch(void * component, int mode, float * ti,      float * tf, int * i, */
177 /*              char  * nomvar, int bufferLength, int * nRead, */
178 /*              char ** data, int strSize) { */
179
180 /*   size_t _nRead;                                                      */
181 /*   long   _i=*i;                                                       */
182 /*   fflush(stdout);fflush(stderr);                                                      */
183 /*   fprintf(stderr,"Beginning of cp_lch: %s %d %f\n",nomvar,*i,*ti);    */
184 /*   if ( (data == NULL) || (bufferLength < 1) ) return CPNTNULL;        */
185 /*   InfoType info =  ecp_lecture_str (component, mode, ti, tf, &_i,  */
186 /*                                  nomvar, bufferLength, &_nRead,  */
187 /*                                  &data);*/
188 /*, strSize );  */
189 /*                                           strSize est  inutile pour les ports CALCIUM */
190 /*                                           qui gèrent des tailles quelconques de chaines.  */
191 /*   if(mode == CP_SEQUENTIEL)                                           */
192 /*     *i = _i;                                                          */
193 /*   *nRead=_nRead;                                                      */
194 /*   fprintf(stderr,"End of cp_lch: %s %d \n",nomvar,*i);                        */
195 /*   fflush(stdout);fflush(stderr);                                                      */
196 /*   return info;                                                        */
197 /* };                                                                    */
198
199
200 /* Definition des méthodes calcium standard  */
201 /* CALCIUM_LECT_INTERFACE_C_( <suffixe du nom de l'interface à générer>, <type du paramètre temporel>, <type d'entier à utiliser pour les paramètres de type entier>,
202                               <type de données>, <nom de l'interface C2CPP à utiliser>, <qualificateur de type optionnel des données>,<paramètres supplémentaire ignoré>)*/
203
204 CALCIUM_LECT_INTERFACE_C_(len,float ,int,int    ,int2integer,,)
205 /*llg ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits)
206   sinon problème de conversion de 64bits vers 32bits */
207 CALCIUM_LECT_INTERFACE_C_(llg,float ,int,long   ,long2integer,,)
208
209 CALCIUM_LECT_INTERFACE_C_(lln,float ,int,long   ,long,,)
210
211 CALCIUM_LECT_INTERFACE_C_(lre,float ,int,float  ,float,,)
212 /*Permet d'envoyer/recevoir des réels sur un port Double  */
213 CALCIUM_LECT_INTERFACE_C_(lrd,float ,int,float  ,float2double,,)
214 CALCIUM_LECT_INTERFACE_C_(ldb,double,int,double ,double,,)
215
216 CALCIUM_LECT_INTERFACE_C_(llo,float ,int,int    ,bool,,)
217 CALCIUM_LECT_INTERFACE_C_(lcp,float ,int,float  ,cplx,,)
218 #define STAR *
219 #define LCH_LAST_PARAM ,int strsize
220 CALCIUM_LECT_INTERFACE_C_(lch,float ,int,char   ,str,STAR, LCH_LAST_PARAM )
221
222
223 /* Definition des méthodes calcium destinées à l'interfaçage fortran
224    avec une taille des INTEGER fortran paramétrés à la configuration du KERNEL  */
225
226 CALCIUM_LECT_INTERFACE_C_(len_fort_,float ,cal_int,cal_int ,integer,,)
227 CALCIUM_LECT_INTERFACE_C_(lin_fort_,float ,cal_int,int     ,int2integer,,)
228 /*llg_fort_ ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits)
229   sinon problème de conversion de 64bits vers 32bits */
230 CALCIUM_LECT_INTERFACE_C_(llg_fort_,float ,cal_int,long    ,long2integer,,)
231
232 CALCIUM_LECT_INTERFACE_C_(lre_fort_,float ,cal_int,float   ,float,,)
233 CALCIUM_LECT_INTERFACE_C_(lrd_fort_,float ,cal_int,float   ,float2double,,)
234 CALCIUM_LECT_INTERFACE_C_(ldb_fort_,double,cal_int,double  ,double,,)
235 CALCIUM_LECT_INTERFACE_C_(llo_fort_,float ,cal_int,int     ,bool,,)   /*int pour bool ou cal_int */
236 CALCIUM_LECT_INTERFACE_C_(lcp_fort_,float ,cal_int,float   ,cplx,,)
237 CALCIUM_LECT_INTERFACE_C_(lch_fort_,float ,cal_int,char    ,str,STAR, LCH_LAST_PARAM )
238
239 CALCIUM_LECT_INTERFACE_C_(lln_fort_,float ,cal_int,long    ,long,,)
240
241 /**********************************************/
242 /*  INTERFACES DE DÉBUT ET DE FIN DE COUPLAGE */
243 /**********************************************/
244
245 InfoType cp_cd (void * component, char * instanceName) {
246   InfoType info =  ecp_cd_(component,instanceName);
247   return info;
248 }
249
250 InfoType cp_fin (void * component, int code) {
251   /* TODO : gérer avec les callbacks des ports DSC */
252
253   InfoType info =  ecp_fin_(component,code);
254
255   return info;
256 }
257
258
259 /***************************/
260 /*  INTERFACES D'ECRITURE  */
261 /***************************/
262
263 #define CALCIUM_ECR_INTERFACE_C_(_name,_timeType,_calInt,_type,_typeName,_qual,lastarg) \
264   _calInt cp_##_name (void * component, _calInt mode,                   \
265                        _timeType t, _calInt i,                          \
266                        char * nomvar, _calInt nbelem,                   \
267                        _type _qual * data                               \
268                        lastarg ) {                                      \
269                                                                         \
270     int     _mode         =  mode;                                      \
271     long    _i            =  i;                                         \
272     size_t  _nbelem       =  nbelem;                                    \
273     _timeType _t          =  t;                                         \
274     fflush(stdout);                                                     \
275     fflush(stderr);                                                     \
276     if ( (data == NULL) || (nbelem < 1) ) return CPNTNULL;              \
277                                                                         \
278     _calInt info =  ecp_ecriture_##_typeName (component, _mode, &_t, _i, \
279                                                nomvar, _nbelem,         \
280                                                data );                  \
281     fflush(stdout);                                                     \
282     fflush(stderr);                                                     \
283                                                                         \
284     return info;                                                        \
285   }                                                                    \
286
287
288
289
290 /* InfoType cp_ech(void * component, int mode, float t, int i, */
291 /*              char  * nomvar,  int nbelem, */
292 /*              char ** data, int strSize) { */
293
294 /*long   _i=i;*/
295 /*   fflush(stdout);fflush(stderr);                                                      */
296 /*   fprintf(stderr,"Beginning of cp_ech: %s %d %f\n",nomvar,i,t);       */
297 /*   if ( (data == NULL) || (nbelem < 1) ) return CPNTNULL;              */
298
299 /*   InfoType info =  ecp_ecriture_str (component, mode, &t, i,  */
300 /*                                   nomvar, nbelem,             */
301 /*                                   data); */
302 /*, strSize );*/
303 /*   fprintf(stderr,"End of cp_ech: %s %d \n",nomvar,i);                         */
304 /*   fflush(stdout);                                                     */
305 /*   fflush(stderr);                                                     */
306
307 /*   return info;                                                        */
308 /* };                                                                    */
309
310 /*  Definition des méthodes calcium standard  */
311 /*  CALCIUM_ECR_INTERFACE_C_(_name,_timeType,_calInt,type,_typeName,_qual) */
312 CALCIUM_ECR_INTERFACE_C_(een,float ,int,int   ,int2integer,,)
313 /*elg ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits)
314   sinon problème de conversion de 64bits vers 32bits */
315 CALCIUM_ECR_INTERFACE_C_(elg,float ,int,long  ,long2integer,,)
316 CALCIUM_ECR_INTERFACE_C_(ere,float ,int,float ,float,,)
317 /*Permet d'envoyer/recevoir des réels sur un port Double  */
318 CALCIUM_ECR_INTERFACE_C_(erd,float ,int,float ,float2double,,)
319 CALCIUM_ECR_INTERFACE_C_(edb,double,int,double,double,,)
320
321 CALCIUM_ECR_INTERFACE_C_(elo,float ,int,int   ,bool,,)
322 CALCIUM_ECR_INTERFACE_C_(ecp,float ,int,float ,cplx,,)
323 CALCIUM_ECR_INTERFACE_C_(ech,float ,int,char  ,str,STAR,LCH_LAST_PARAM )
324
325 CALCIUM_ECR_INTERFACE_C_(eln,float ,int,long  ,long,,)
326
327 /* Definition des méthodes calcium destinées à l'interfaçage fortran
328    avec une taille des INTEGER fortran paramétrés à la configuration du KERNEL  */
329
330 CALCIUM_ECR_INTERFACE_C_(een_fort_,float ,cal_int,cal_int,integer,,)
331 /*elg_fort_ ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits)
332   sinon problème de conversion de 64bits vers 32bits */
333 CALCIUM_ECR_INTERFACE_C_(elg_fort_,float ,cal_int,long   ,long2integer,,)
334 CALCIUM_ECR_INTERFACE_C_(ein_fort_,float ,cal_int,int    ,int2integer,,)
335 CALCIUM_ECR_INTERFACE_C_(ere_fort_,float ,cal_int,float ,float,,)
336 CALCIUM_ECR_INTERFACE_C_(erd_fort_,float ,cal_int,float ,float2double,,)
337 CALCIUM_ECR_INTERFACE_C_(edb_fort_,double,cal_int,double,double,,)
338 CALCIUM_ECR_INTERFACE_C_(elo_fort_,float ,cal_int,int   ,bool,,)
339 CALCIUM_ECR_INTERFACE_C_(ecp_fort_,float ,cal_int,float ,cplx,,)
340 CALCIUM_ECR_INTERFACE_C_(ech_fort_,float ,cal_int,char  ,str,STAR,LCH_LAST_PARAM )
341
342 CALCIUM_ECR_INTERFACE_C_(eln_fort_,float ,cal_int,long   ,long,,)
343
344 /***************************/
345 /*  Interface for cleaning */
346 /***************************/
347
348 InfoType cp_fini (void * component, char * nomvar, int i)
349 {
350   InfoType info =  ecp_fini_(component,nomvar,i);
351   return info;
352 }
353
354 InfoType cp_fint (void * component, char * nomvar, float t)
355 {
356   InfoType info =  ecp_fint_(component,nomvar,t);
357   return info;
358 }
359
360 InfoType cp_effi (void * component, char * nomvar, int i)
361 {
362   InfoType info =  ecp_effi_(component,nomvar,i);
363   return info;
364 }
365
366 InfoType cp_efft (void * component, char * nomvar, float t)
367 {
368   InfoType info =  ecp_efft_(component,nomvar,t);
369   return info;
370 }