1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 #include "CalciumFortranInt.h"
33 static void fstrtocstr(char *cstr, char *fstr,cal_int fstr_len)
36 for (iend = fstr_len-1; iend >= 0; iend--)
37 if (fstr[iend] != ' ') break;
38 for (i = 0; i <= iend; i++)
43 static void cstrtofstr(char *cstr, char *fstr,cal_int fstr_len)
47 if (len > fstr_len) len = fstr_len;
48 for (i = 0; i < len; i++)
54 static char * fstr1(char *nom,cal_int nnom)
56 char * cnom=(char*)malloc((nnom+1)*sizeof(char));
57 fstrtocstr(cnom,nom,nnom);
61 static void free_str1(char *nom)
67 #define POS_INFINITY 1
68 #define NEG_INFINITY 2
70 #define SIGNALING_NAN 4
72 int CheckFloat(float* value)
74 unsigned long L1 = *(unsigned long*)value;
75 unsigned long L2 = L1 & 0x7fffffff;
76 if (L2 < 0x7f800000) return (FLOAT_OK); // Short circuit for most values
77 if (L1 == 0x7f800000) return (POS_INFINITY);
78 else if (L1 == 0xff800000) return (NEG_INFINITY);
79 else if (L2 >= 0x7fc00000) return (QUIET_NAN);
80 else if ((L2 >= 0x7f800001) && (L2 <= 0x7fbfffff)) return (SIGNALING_NAN);
81 else return (FLOAT_OK);
84 /**********************************************/
85 /* INTERFACES DE DÉBUT ET DE FIN DE COUPLAGE */
86 /**********************************************/
88 void F_FUNC(cpcd,CPCD)(long *compo,STR_PSTR(nom),cal_int *info STR_PLEN(nom));
89 void F_FUNC(cpfin,CPFIN)(long *compo,cal_int *dep,cal_int *err);
91 void F_FUNC(cpcd,CPCD)(long *compo,STR_PSTR(nom),cal_int *info STR_PLEN(nom))
93 /* nom is OUT argument */
94 cp_cd((void *)*compo,STR_PTR(nom));
95 /* replace in place ??? */
96 cstrtofstr(STR_PTR(nom),STR_PTR(nom),STR_LEN(nom));
99 void F_FUNC(cpfin,CPFIN)(long *compo,cal_int *dep,cal_int *err)
101 *err=cp_fin((void *)*compo,(int)*dep);
104 /**************************************/
105 /* ERASE INTERFACE */
106 /**************************************/
107 void F_FUNC(cpfini,CPFINI)(long *compo,STR_PSTR(nom),cal_int *i, cal_int *err STR_PLEN(nom));
108 void F_FUNC(cpfint,CPFINT)(long *compo,STR_PSTR(nom),float *t, cal_int *err STR_PLEN(nom));
109 void F_FUNC(cpeffi,CPEFFI)(long *compo,STR_PSTR(nom),cal_int *i, cal_int *err STR_PLEN(nom));
110 void F_FUNC(cpefft,CPEFFT)(long *compo,STR_PSTR(nom),float *t, cal_int *err STR_PLEN(nom));
112 void F_FUNC(cpfini,CPFINI)(long *compo,STR_PSTR(nom),cal_int *i, cal_int *err STR_PLEN(nom))
114 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
115 *err=cp_fini((void *)*compo,cnom,*i);
119 void F_FUNC(cpfint,CPFINT)(long *compo,STR_PSTR(nom),float *t, cal_int *err STR_PLEN(nom))
121 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
122 *err=cp_fint((void *)*compo,cnom,*t);
126 void F_FUNC(cpeffi,CPEFFI)(long *compo,STR_PSTR(nom),cal_int *i, cal_int *err STR_PLEN(nom))
128 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
129 *err=cp_effi((void *)*compo,cnom,*i);
133 void F_FUNC(cpefft,CPEFFT)(long *compo,STR_PSTR(nom),float *t, cal_int *err STR_PLEN(nom))
135 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
136 *err=cp_efft((void *)*compo,cnom,*t);
140 /**************************************/
141 /* INTERFACES DE LECTURE */
142 /**************************************/
144 void F_FUNC(cplin,CPLIN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
145 cal_int *max,cal_int *n, int *tab,cal_int *err STR_PLEN(nom));
146 void F_FUNC(cpllg,CPLLG)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
147 cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom));
148 void F_FUNC(cplln,CPLLN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
149 cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom));
150 void F_FUNC(cplen,CPLEN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
151 cal_int *max,cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom));
152 void F_FUNC(cpllo,CPLLO)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
153 cal_int *max,cal_int *n, int *tab,cal_int *err STR_PLEN(nom));
154 void F_FUNC(cpldb,CPLDB)(long *compo,cal_int *dep,double *ti,double *tf,cal_int *iter,STR_PSTR(nom),
155 cal_int *max,cal_int *n, double *tab,cal_int *err STR_PLEN(nom));
156 void F_FUNC(cplre,CPLRE)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
157 cal_int *max,cal_int *n, float *tab,cal_int *err STR_PLEN(nom));
158 void F_FUNC(cplrd,CPLRD)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
159 cal_int *max,cal_int *n, double *tab,cal_int *err STR_PLEN(nom));
160 void F_FUNC(cplcp,CPLCP)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
161 cal_int *max,cal_int *n, float *tab,cal_int *err STR_PLEN(nom));
162 void F_FUNC(cplch,CPLCH)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
163 cal_int *max,cal_int *n, char *tab,cal_int *err STR_PLEN(nom) STR_PLEN(tab) );
166 void F_FUNC(cplin,CPLIN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
167 cal_int *max,cal_int *n, int *tab,cal_int *err STR_PLEN(nom))
169 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
172 #error "The macro SIZEOF_INT must be defined."
173 #elif SIZEOF_INT == 4
174 *err=cp_lin_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
176 fprintf(stderr,"End of CPLIN: %s : Can't use fortran INTEGER*4 because int C is not 32bits long on this machine.\n",
182 void F_FUNC(cpllg,CPLLG)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
183 cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom))
185 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
187 #error "The macro SIZEOF_LONG must be defined."
188 #elif SIZEOF_LONG == 8
189 *err=cp_llg_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
191 fprintf(stderr,"End of CPLLG: %s : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n",
197 void F_FUNC(cplln,CPLLN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
198 cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom))
200 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
202 #error "The macro SIZEOF_LONG must be defined."
203 #elif SIZEOF_LONG == 8
204 *err=cp_lln_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
206 fprintf(stderr,"End of CPLLN: %s : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n",
213 void F_FUNC(cplen,CPLEN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
214 cal_int *max,cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom))
216 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
217 *err=cp_len_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
222 void F_FUNC(cpllo,CPLLO)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
223 cal_int *max,cal_int *n, int *tab,cal_int *err STR_PLEN(nom))
225 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
226 *err=cp_llo_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
230 void F_FUNC(cpldb,CPLDB)(long *compo,cal_int *dep,double *ti,double *tf,cal_int *iter,STR_PSTR(nom),
231 cal_int *max,cal_int *n, double *tab,cal_int *err STR_PLEN(nom))
233 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
234 *err=cp_ldb_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
238 void F_FUNC(cplre,CPLRE)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
239 cal_int *max,cal_int *n, float *tab,cal_int *err STR_PLEN(nom))
241 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
242 *err=cp_lre_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
246 void F_FUNC(cplrd,CPLRD)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
247 cal_int *max,cal_int *n, double *tab,cal_int *err STR_PLEN(nom))
249 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
250 *err=cp_lrd_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,(float *)tab);
254 void F_FUNC(cplcp,CPLCP)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
255 cal_int *max,cal_int *n, float *tab,cal_int *err STR_PLEN(nom))
257 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
258 *err=cp_lcp_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab);
262 void F_FUNC(cplch,CPLCH)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom),
263 cal_int *max,cal_int *n, char *tab,cal_int *err STR_PLEN(nom) STR_PLEN(tab) )
265 char **tabChaine = NULL;
267 char* cnom = fstr1(STR_PTR(nom),STR_LEN(nom));
269 tabChaine = (char **) malloc(sizeof(char *) * (*max));
270 for (index = 0; index < *max; index++)
271 tabChaine[index] = (char *) malloc(sizeof(char) * (STR_LEN(tab)+1));
273 *err=cp_lch_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tabChaine,STR_LEN(tab));
277 for (index = 0; index < *n; index++)
279 strncpy(&tab[index * STR_LEN(tab)], tabChaine[index], strlen(tabChaine[index]));
280 if(STR_LEN(tab) > strlen(tabChaine[index]))
281 memset(&tab[index * STR_LEN(tab)+strlen(tabChaine[index])],' ',STR_LEN(tab)-strlen(tabChaine[index]));
285 if (tabChaine != (char **) NULL)
287 for (index = 0; index < *max; index++)
288 free(tabChaine[index]);
295 /***************************/
296 /* INTERFACES D'ECRITURE */
297 /***************************/
298 void F_FUNC(cpech,CPECH)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, char *tab,cal_int *err
299 STR_PLEN(nom) STR_PLEN(tab));
300 void F_FUNC(cpedb,CPEDB)(long *compo,cal_int *dep,double *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, double *tab,cal_int *err STR_PLEN(nom));
301 void F_FUNC(cpere,CPERE)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, float *tab,cal_int *err STR_PLEN(nom));
302 void F_FUNC(cperd,CPERD)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, double *tab,cal_int *err STR_PLEN(nom));
303 void F_FUNC(cpecp,CPECP)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, float *tab,cal_int *err STR_PLEN(nom));
304 void F_FUNC(cpein,CPEIN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, int *tab,cal_int *err STR_PLEN(nom));
305 void F_FUNC(cpelg,CPELG)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, long *tab,cal_int *err STR_PLEN(nom));
306 void F_FUNC(cpeln,CPELN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, long *tab,cal_int *err STR_PLEN(nom));
307 void F_FUNC(cpeen,CPEEN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom));
308 void F_FUNC(cpelo,CPELO)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, int *tab,cal_int *err STR_PLEN(nom));
310 void F_FUNC(cpech,CPECH)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, char *tab,cal_int *err
311 STR_PLEN(nom) STR_PLEN(tab))
313 char ** tabChaine=NULL;
314 cal_int index=0,index2=0;
315 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
317 if(*dep == CP_TEMPS)tti=*ti;
319 tabChaine = (char **) malloc(sizeof(char *) * *n);
320 for (index = 0; index < *n; index++)
322 tabChaine[index] = (char *) malloc(sizeof(char) * (STR_LEN(tab) + 1));
323 strncpy(tabChaine[index],&tab[STR_LEN(tab) * index],STR_LEN(tab));
324 tabChaine[index][STR_LEN(tab)]='\0';
325 for (index2 = STR_LEN(tab) - 1; index2 >= 0; index2--)
327 if ( tabChaine[index][index2] == ' ' || tabChaine[index][index2] == '\0' )
328 tabChaine[index][index2]='\0';
332 *err=cp_ech_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tabChaine,STR_LEN(tab) );
334 if (tabChaine != (char **) NULL)
336 for (index = 0; index < *n; index++)
337 free(tabChaine[index]);
343 void F_FUNC(cpedb,CPEDB)(long *compo,cal_int *dep,double *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, double *tab,cal_int *err STR_PLEN(nom))
346 if(*dep == CP_TEMPS)tti=*ti;
347 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
348 *err=cp_edb_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
352 void F_FUNC(cpere,CPERE)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, float *tab,cal_int *err STR_PLEN(nom))
355 if(*dep == CP_TEMPS)tti=*ti;
356 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
357 *err=cp_ere_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
361 void F_FUNC(cperd,CPERD)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, double *tab,cal_int *err STR_PLEN(nom))
364 if(*dep == CP_TEMPS)tti=*ti;
365 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
366 *err=cp_erd_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,(float *)tab);
370 void F_FUNC(cpecp,CPECP)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, float *tab,cal_int *err STR_PLEN(nom))
373 if(*dep == CP_TEMPS)tti=*ti;
374 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
375 *err=cp_ecp_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
380 void F_FUNC(cpein,CPEIN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, int *tab,cal_int *err STR_PLEN(nom))
383 if(*dep == CP_TEMPS)tti=*ti;
384 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
386 #error "The macro SIZEOF_INT must be defined."
387 #elif SIZEOF_INT == 4
388 *err=cp_ein_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
390 fprintf(stderr,"CPEIN: %s %f %d : Can't use fortran INTEGER*4 because int C is not 32bits long on this machine.\n",
396 void F_FUNC(cpelg,CPELG)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, long *tab,cal_int *err STR_PLEN(nom))
399 if(*dep == CP_TEMPS)tti=*ti;
400 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
402 #error "The macro SIZEOF_LONG must be defined."
403 #elif SIZEOF_LONG == 8
404 *err=cp_elg_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
406 fprintf(stderr,"CPELG: %s %f %d : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n",
412 void F_FUNC(cpeln,CPELN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, long *tab,cal_int *err STR_PLEN(nom))
415 if(*dep == CP_TEMPS)tti=*ti;
416 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
418 #error "The macro SIZEOF_LONG must be defined."
419 #elif SIZEOF_LONG == 8
420 *err=cp_eln_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
422 fprintf(stderr,"CPELN: %s %f %d : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n",
429 void F_FUNC(cpeen,CPEEN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom))
432 if(*dep == CP_TEMPS)tti=*ti;
433 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
434 *err=cp_een_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
438 void F_FUNC(cpelo,CPELO)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, int *tab,cal_int *err STR_PLEN(nom))
441 if(*dep == CP_TEMPS)tti=*ti;
442 char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
443 *err=cp_elo_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);