From d37ed2e251ae1396e411b4c294965e7c795dcc9f Mon Sep 17 00:00:00 2001 From: caremoli Date: Fri, 12 Mar 2010 07:59:13 +0000 Subject: [PATCH] CCAR: complete Calcium C API with cp_lln, cp_eln and remove some bugs in fortran and python interfaces add CALCIUM_long as SALOME type --- resources/KERNELCatalog.xml.in | 1 + src/DSC/DSC_Python/calcium.i | 79 ++++++++++--- src/DSC/DSC_User/Datastream/Calcium/Calcium.c | 66 ++++++----- .../DSC_User/Datastream/Calcium/Calcium.cxx | 6 +- src/DSC/DSC_User/Datastream/Calcium/calcium.h | 59 ++++++++++ .../DSC_User/Datastream/Calcium/calciumf.c | 109 ++++++++++++------ .../DSC_User/Datastream/Calcium/calciumf.h | 5 +- 7 files changed, 247 insertions(+), 78 deletions(-) diff --git a/resources/KERNELCatalog.xml.in b/resources/KERNELCatalog.xml.in index 35b2edea4..c60881e17 100644 --- a/resources/KERNELCatalog.xml.in +++ b/resources/KERNELCatalog.xml.in @@ -27,6 +27,7 @@ + diff --git a/src/DSC/DSC_Python/calcium.i b/src/DSC/DSC_Python/calcium.i index bc504c30f..215ad0ab4 100644 --- a/src/DSC/DSC_Python/calcium.i +++ b/src/DSC/DSC_Python/calcium.i @@ -28,6 +28,8 @@ %feature("autodoc", "1"); +%include cstring.i + %{ //C++ Includes #include @@ -118,6 +120,19 @@ typedef PyArrayObject ArrayObject; #define array_size(a,i) (((PyArrayObject *)a)->dimensions[i]) #define array_is_contiguous(a) (PyArray_ISCONTIGUOUS(a)) +const char* pytype_string(PyObject*); +const char* typecode_string(int); +int type_match(int, int); +int require_size(PyArrayObject*, int*, int); +int require_dimensions_n(PyArrayObject*, int*, int); +int require_dimensions(PyArrayObject*, int); +int require_contiguous(PyArrayObject*); +PyArrayObject* make_contiguous(PyArrayObject*, int*, int, int); +PyArrayObject* obj_to_array_no_conversion(PyObject*, int); +PyArrayObject* obj_to_array_allow_conversion(PyObject*, int, int*); +PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject*, int, int*); +PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject*, int, int*); + /* Given a PyObject, return a string describing its type. */ const char* pytype_string(PyObject* py_obj) { @@ -400,8 +415,9 @@ typedef PyObject ArrayObject; %include "carrays.i" -%array_class(int, intArray); -%array_class(float, floatArray); +%array_class(int, intArray); +%array_class(long, longArray); +%array_class(float, floatArray); %array_class(double, doubleArray); /* special struct to handle string arrays */ @@ -410,6 +426,7 @@ struct stringArray { stringArray(int nelements,int size=0) { nelem=nelements; + size=size; data= new char*[nelements]; for(int i=0;istrides[0]; for(int i=0;idata + i* array->strides[0]; + { + $1[i]=(char*) malloc(sizeof(char)*(array->strides[0]+1)); + strncpy($1[i],(char*) array->data + i* array->strides[0],array->strides[0]); + *($1[i]+array->strides[0])='\0'; + } %#else SWIG_exception(SWIG_TypeError, "string array expected"); %#endif @@ -512,12 +543,21 @@ TYPEMAP_IN3(double, PyArray_DOUBLE) else { $1=sarray->data; + $2=sarray->size; } } -%typemap(freearg) char** eval { - if (array$argnum) free($1); - if (is_new_object$argnum && array$argnum) Py_DECREF(array$argnum); +%typemap(freearg) (char** eval,int strSize) { + if (array$argnum) + { + for(int i=0;istrides[0]; for(int i=0;idata+i*temp->strides[0]; + { + $1[i]=(char*) temp->data+i*temp->strides[0]; + memset($1[i],0,temp->strides[0]); //numpy strings must be completed with 0 up to elsize + } %#else temp = NULL; SWIG_exception(SWIG_TypeError, "string array expected"); @@ -589,9 +635,10 @@ TYPEMAP_INPLACE3(double, PyArray_DOUBLE) else { $1=sarray->data; + $2=sarray->size; } } -%typemap(freearg) char** lval { +%typemap(freearg) (char** lval,int strSize) { if (temp$argnum) free($1); } /* End of typemap for array of strings on input/output */ @@ -828,7 +875,9 @@ extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* t %ignore CPMESSAGE; %include "calciumP.h" -int cp_cd(Superv_Component_i *component,char *name); +%cstring_bounded_output(char *instanceName, 1024); + +int cp_cd(Superv_Component_i *component,char *instanceName); int cp_een(Superv_Component_i *component,int dep,float t,int n,char *nom,int nval,int *eval); int cp_edb(Superv_Component_i *component,int dep,double t,int n,char *nom,int nval,double *eval); @@ -836,6 +885,8 @@ int cp_ere(Superv_Component_i *component,int dep,float t,int n,char *nom,int nv int cp_ecp(Superv_Component_i *component,int dep,float t,int n,char *nom,int nval,float *ecpval); int cp_elo(Superv_Component_i *component,int dep,float t,int n,char *nom,int nval,int *eval); int cp_ech(Superv_Component_i *component,int dep,float t,int n,char *nom,int nval,char** eval,int strSize); +int cp_elg(Superv_Component_i *component,int dep,float t,int n,char *nom,int nval,long *eval); +int cp_eln(Superv_Component_i *component,int dep,float t,int n,char *nom,int nval,long *eval); int cp_len(Superv_Component_i *component,int dep,float *ti,float *tf,int *niter,char *nom,int nmax,int *nval,int *lval); @@ -844,6 +895,8 @@ int cp_lre(Superv_Component_i *component,int dep,float *ti,float *tf,int *nite int cp_lcp(Superv_Component_i *component,int dep,float *ti,float *tf,int *niter,char *nom,int nmax,int *nval,float *lcpval); int cp_llo(Superv_Component_i *component,int dep,float *ti,float *tf,int *niter,char *nom,int nmax,int *nval,int *lval); int cp_lch(Superv_Component_i *component,int dep,float *ti,float *tf,int *niter,char *nom,int nmax,int *nval,char** lval,int strSize); +int cp_llg(Superv_Component_i *component,int dep,float *ti,float *tf,int *niter,char *nom,int nmax,int *nval,long *lval); +int cp_lln(Superv_Component_i *component,int dep,float *ti,float *tf,int *niter,char *nom,int nmax,int *nval,long *lval); int cp_fin(Superv_Component_i *component,int cp_end); diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.c b/src/DSC/DSC_User/Datastream/Calcium/Calcium.c index b9ce3521e..86064a721 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/Calcium.c +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.c @@ -31,7 +31,7 @@ #include #include -// Interface C de SalomeCalcium +// Interface C de SalomeCalcium typedef int InfoType; typedef char bool; @@ -89,22 +89,21 @@ InfoType ecp_lch(void * component, int mode, float * ti, float * tf, int char * nomvar, int bufferLength, int * nRead, char *** data, int strSize) { - size_t _nRead; - long _i=*i; - fflush(stdout);fflush(stderr); - - InfoType info = ecp_lecture_str (component, mode, ti, tf, &_i, - nomvar, bufferLength, &_nRead, - data);/*, strSize ); + size_t _nRead; + long _i=*i; + fflush(stdout);fflush(stderr); + + InfoType info = ecp_lecture_str (component, mode, ti, tf, &_i, + nomvar, bufferLength, &_nRead, + data);/*, strSize ); strSize est inutile pour les ports CALCIUM qui gèrent des tailles quelconques de chaines. */ - if(mode == CP_SEQUENTIEL) - *i = _i; - *nRead=_nRead; - fflush(stdout);fflush(stderr); - - return info; -}; + if(mode == CP_SEQUENTIEL) + *i = _i; + *nRead=_nRead; + fflush(stdout);fflush(stderr); + return info; +}; void ecp_lch_free (char* * data) { \ ecp_lecture_str_free(data); \ @@ -171,9 +170,7 @@ CALCIUM_EXT_LECT_INTERFACE_C_(lcp,float,float,cplx,); /* long _i=*i; */ /* fflush(stdout);fflush(stderr); */ /* fprintf(stderr,"Beginning of cp_lch: %s %d %f\n",nomvar,*i,*ti); */ - /* if ( (data == NULL) || (bufferLength < 1) ) return CPNTNULL; */ - /* InfoType info = ecp_lecture_str (component, mode, ti, tf, &_i, */ /* nomvar, bufferLength, &_nRead, */ /* &data);*/ @@ -185,7 +182,6 @@ CALCIUM_EXT_LECT_INTERFACE_C_(lcp,float,float,cplx,); /* *nRead=_nRead; */ /* fprintf(stderr,"End of cp_lch: %s %d \n",nomvar,*i); */ /* fflush(stdout);fflush(stderr); */ - /* return info; */ /* }; */ @@ -195,13 +191,15 @@ CALCIUM_EXT_LECT_INTERFACE_C_(lcp,float,float,cplx,); , , ,)*/ CALCIUM_LECT_INTERFACE_C_(len,float ,int,int ,int2integer,,); -/*llg ne sera pas disponible si sizeof(long) == 64 bits && cal_int==int - sinon problème de conversion de 64bits vers 32bits */ +/*llg ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits) + sinon problème de conversion de 64bits vers 32bits */ CALCIUM_LECT_INTERFACE_C_(llg,float ,int,long ,long2integer,,); +CALCIUM_LECT_INTERFACE_C_(lln,float ,int,long ,long,,); + CALCIUM_LECT_INTERFACE_C_(lre,float ,int,float ,float,,); CALCIUM_LECT_INTERFACE_C_(ldb,double,int,double ,double,,); -CALCIUM_LECT_INTERFACE_C_(llo,float ,int,int ,bool,,); +CALCIUM_LECT_INTERFACE_C_(llo,float ,int,int ,bool,,); CALCIUM_LECT_INTERFACE_C_(lcp,float ,int,float ,cplx,,); #define STAR * #define LCH_LAST_PARAM ,int strsize @@ -213,8 +211,8 @@ CALCIUM_LECT_INTERFACE_C_(lch,float ,int,char ,str,STAR, LCH_LAST_PARAM ); CALCIUM_LECT_INTERFACE_C_(len_fort_,float ,cal_int,cal_int ,integer,,); CALCIUM_LECT_INTERFACE_C_(lin_fort_,float ,cal_int,int ,int2integer,,); -/*llg ne sera pas disponible si sizeof(long) == 64 bits && cal_int==int - sinon problème de conversion de 64bits vers 32bits */ +/*llg_fort_ ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits) + sinon problème de conversion de 64bits vers 32bits */ CALCIUM_LECT_INTERFACE_C_(llg_fort_,float ,cal_int,long ,long2integer,,); CALCIUM_LECT_INTERFACE_C_(lre_fort_,float ,cal_int,float ,float,,); @@ -223,6 +221,7 @@ CALCIUM_LECT_INTERFACE_C_(llo_fort_,float ,cal_int,int ,bool,,); /*int pou CALCIUM_LECT_INTERFACE_C_(lcp_fort_,float ,cal_int,float ,cplx,,); CALCIUM_LECT_INTERFACE_C_(lch_fort_,float ,cal_int,char ,str,STAR, LCH_LAST_PARAM ); +CALCIUM_LECT_INTERFACE_C_(lln_fort_,float ,cal_int,long ,long,,); /**********************************************/ /* INTERFACES DE DÉBUT ET DE FIN DE COUPLAGE */ @@ -235,9 +234,9 @@ InfoType cp_cd (void * component, char * instanceName) { InfoType cp_fin (void * component, int code) { /* TODO : gérer avec les callbacks des ports DSC */ - + InfoType info = ecp_fin_(component,code); - + return info; } @@ -276,12 +275,12 @@ InfoType cp_fin (void * component, int code) { /* InfoType cp_ech(void * component, int mode, float t, int i, */ /* char * nomvar, int nbelem, */ /* char ** data, int strSize) { */ - -/*long _i=i;*/ + +/*long _i=i;*/ /* fflush(stdout);fflush(stderr); */ /* fprintf(stderr,"Beginning of cp_ech: %s %d %f\n",nomvar,i,t); */ /* if ( (data == NULL) || (nbelem < 1) ) return CPNTNULL; */ - + /* InfoType info = ecp_ecriture_str (component, mode, &t, i, */ /* nomvar, nbelem, */ /* data); */ @@ -289,13 +288,15 @@ InfoType cp_fin (void * component, int code) { /* fprintf(stderr,"End of cp_ech: %s %d \n",nomvar,i); */ /* fflush(stdout); */ /* fflush(stderr); */ - + /* return info; */ /* }; */ /* Definition des méthodes calcium standard */ /* CALCIUM_ECR_INTERFACE_C_(_name,_timeType,_calInt,type,_typeName,_qual) */ CALCIUM_ECR_INTERFACE_C_(een,float ,int,int ,int2integer,,); +/*elg ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits) + sinon problème de conversion de 64bits vers 32bits */ CALCIUM_ECR_INTERFACE_C_(elg,float ,int,long ,long2integer,,); CALCIUM_ECR_INTERFACE_C_(ere,float ,int,float ,float,,); CALCIUM_ECR_INTERFACE_C_(edb,double,int,double,double,,); @@ -303,10 +304,14 @@ CALCIUM_ECR_INTERFACE_C_(elo,float ,int,int ,bool,,); CALCIUM_ECR_INTERFACE_C_(ecp,float ,int,float ,cplx,,); CALCIUM_ECR_INTERFACE_C_(ech,float ,int,char ,str,STAR,LCH_LAST_PARAM ); +CALCIUM_ECR_INTERFACE_C_(eln,float ,int,long ,long,,); + /* Definition des méthodes calcium destinées à l'interfaçage fortran avec une taille des INTEGER fortran paramétrés à la configuration du KERNEL */ CALCIUM_ECR_INTERFACE_C_(een_fort_,float ,cal_int,cal_int,integer,,); +/*elg_fort_ ne fonctionnera pas toujours correctement (port calcium_integer) si sizeof(long) == 64 bits && cal_int==int (32 bits) + sinon problème de conversion de 64bits vers 32bits */ CALCIUM_ECR_INTERFACE_C_(elg_fort_,float ,cal_int,long ,long2integer,,); CALCIUM_ECR_INTERFACE_C_(ein_fort_,float ,cal_int,int ,int2integer,,); CALCIUM_ECR_INTERFACE_C_(ere_fort_,float ,cal_int,float ,float,,); @@ -314,3 +319,6 @@ CALCIUM_ECR_INTERFACE_C_(edb_fort_,double,cal_int,double,double,,); CALCIUM_ECR_INTERFACE_C_(elo_fort_,float ,cal_int,int ,bool,,); CALCIUM_ECR_INTERFACE_C_(ecp_fort_,float ,cal_int,float ,cplx,,); CALCIUM_ECR_INTERFACE_C_(ech_fort_,float ,cal_int,char ,str,STAR,LCH_LAST_PARAM ); + +CALCIUM_ECR_INTERFACE_C_(eln_fort_,float ,cal_int,long ,long,,); + diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx index 2b6429f8a..26943cfde 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx @@ -42,7 +42,7 @@ PySupervCompo::~PySupervCompo() } -extern "C" +extern "C" { void cp_exit(int); void setDependency(provides_port*, char*, CalciumTypes::DependencyType); @@ -66,6 +66,10 @@ extern "C" { dynamic_cast(port)->setDependencyType(depend); } + else if(std::string(type)=="CALCIUM_long") + { + dynamic_cast(port)->setDependencyType(depend); + } else if(std::string(type)=="CALCIUM_string") { dynamic_cast(port)->setDependencyType(depend); diff --git a/src/DSC/DSC_User/Datastream/Calcium/calcium.h b/src/DSC/DSC_User/Datastream/Calcium/calcium.h index f547f3bce..bc7a2b55c 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/calcium.h +++ b/src/DSC/DSC_User/Datastream/Calcium/calcium.h @@ -102,6 +102,50 @@ extern int cp_len( #endif ); +extern int cp_llg( +/* ------ */ +#if CPNeedPrototype + void * component /* Pointeur de type Superv_Component_i* sur le */ + /* composant SALOME Supervisable */, + int /* E Type de dependance ou de lecture */ + /* CP_TEMPS, CP_ITERATION, CP_SEQUENTIEL */, + float * /* E/S Borne inf de l'intervalle de lecture */ + /* Retourne le pas lu dans le cas de */ + /* lecture sequentielle */, + float * /* E Borne Sup de l'intervalle de lecture */, + int * /* E/S Pas d'iteration a lire */ + /* Retourne le pas lu dans le cas de */ + /* lecture sequentielle */, + char * /* E Nom de la variable a lire */, + int /* E Nombre max de valeurs a lire */, + int * /* S Nombre de valeurs rellement lues */, + long * /* S Tableau d'entiers pour stocker les */ + /* valeurs lues */ +#endif +); + +extern int cp_lln( +/* ------ */ +#if CPNeedPrototype + void * component /* Pointeur de type Superv_Component_i* sur le */ + /* composant SALOME Supervisable */, + int /* E Type de dependance ou de lecture */ + /* CP_TEMPS, CP_ITERATION, CP_SEQUENTIEL */, + float * /* E/S Borne inf de l'intervalle de lecture */ + /* Retourne le pas lu dans le cas de */ + /* lecture sequentielle */, + float * /* E Borne Sup de l'intervalle de lecture */, + int * /* E/S Pas d'iteration a lire */ + /* Retourne le pas lu dans le cas de */ + /* lecture sequentielle */, + char * /* E Nom de la variable a lire */, + int /* E Nombre max de valeurs a lire */, + int * /* S Nombre de valeurs rellement lues */, + long * /* S Tableau d'entiers pour stocker les */ + /* valeurs lues */ +#endif +); + extern int cp_lre( /* ------ */ #if CPNeedPrototype @@ -395,6 +439,21 @@ extern int cp_elg( #endif ); +extern int cp_eln( +/* ------ */ +#if CPNeedPrototype + void * component /* Pointeur de type Superv_Component_i* sur le */ + /* composant SALOME Supervisable */, + int /* E Type de dependance */ + /* CP_TEMPS, CP_ITERATION */, + float /* E Pas de temps a ecrire */, + int /* E Pas d'iteration a ecrire */, + char * /* E Nom de la variable a ecrire */, + int /* E Nombre de valeurs a ecrire */, + long * /* E Tableau d'entiers a ecrire */ +#endif +); + extern int cp_ere( /* ------ */ #if CPNeedPrototype diff --git a/src/DSC/DSC_User/Datastream/Calcium/calciumf.c b/src/DSC/DSC_User/Datastream/Calcium/calciumf.c index b73dba9fa..fedab9d34 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/calciumf.c +++ b/src/DSC/DSC_User/Datastream/Calcium/calciumf.c @@ -27,24 +27,22 @@ #include "CalciumFortranInt.h" #include -static void* COMPO=0; - #ifdef __cplusplus extern "C" { #endif -static void fstrtocstr(char *cstr, char *fstr,cal_int fstr_len) +static void fstrtocstr(char *cstr, char *fstr,cal_int fstr_len) { cal_int i,iend; - for (iend = fstr_len-1; iend >= 0; iend--) + for (iend = fstr_len-1; iend >= 0; iend--) if (fstr[iend] != ' ') break; for (i = 0; i <= iend; i++) cstr[i] = fstr[i]; cstr[i] = '\0'; } -static void cstrtofstr(char *cstr, char *fstr,cal_int fstr_len) +static void cstrtofstr(char *cstr, char *fstr,cal_int fstr_len) { cal_int i, len; len = strlen(cstr); @@ -95,6 +93,8 @@ void F_FUNC(cplin,CPLIN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *i cal_int *max,cal_int *n, int *tab,cal_int *err STR_PLEN(nom)); void F_FUNC(cpllg,CPLLG)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom), cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom)); +void F_FUNC(cplln,CPLLN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom), + cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom)); void F_FUNC(cplen,CPLEN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom), cal_int *max,cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom)); void F_FUNC(cpllo,CPLLO)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom), @@ -115,7 +115,7 @@ void F_FUNC(cplin,CPLIN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *i char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); #if !SIZEOF_INT -#error "The macro SIZEOF_INT must be defined." +#error "The macro SIZEOF_INT must be defined." #elif SIZEOF_INT == 4 *err=cp_lin_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab); #else @@ -130,7 +130,7 @@ void F_FUNC(cpllg,CPLLG)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *i { char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); #if !SIZEOF_LONG -#error "The macro SIZEOF_LONG must be defined." +#error "The macro SIZEOF_LONG must be defined." #elif SIZEOF_LONG == 8 *err=cp_llg_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab); #else @@ -140,6 +140,22 @@ void F_FUNC(cpllg,CPLLG)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *i free_str1(cnom); } +void F_FUNC(cplln,CPLLN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom), + cal_int *max,cal_int *n, long *tab,cal_int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); +#if !SIZEOF_LONG +#error "The macro SIZEOF_LONG must be defined." +#elif SIZEOF_LONG == 8 + *err=cp_lln_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab); +#else + fprintf(stderr,"End of CPLLN: %s : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n", + cnom); +#endif + free_str1(cnom); +} + + void F_FUNC(cplen,CPLEN)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *iter,STR_PSTR(nom), cal_int *max,cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom)) { @@ -194,14 +210,22 @@ void F_FUNC(cplch,CPLCH)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *i *err=cp_lch_fort_((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tabChaine,STR_LEN(tab)); - for (index = 0; index < *n; index++) - strncpy(&tab[index * STR_LEN(tab)], tabChaine[index], strlen(tabChaine[index])); + if (*err == CPOK ) + { + for (index = 0; index < *n; index++) + { + strncpy(&tab[index * STR_LEN(tab)], tabChaine[index], strlen(tabChaine[index])); + if(STR_LEN(tab) > strlen(tabChaine[index])) + memset(&tab[index * STR_LEN(tab)+strlen(tabChaine[index])],' ',STR_LEN(tab)-strlen(tabChaine[index])); + } + } - if (tabChaine != (char **) NULL) { - for (index = 0; index < *n; index++) - free(tabChaine[index]); - free(tabChaine); - } + if (tabChaine != (char **) NULL) + { + for (index = 0; index < *max; index++) + free(tabChaine[index]); + free(tabChaine); + } free_str1(cnom); } @@ -209,17 +233,18 @@ void F_FUNC(cplch,CPLCH)(long *compo,cal_int *dep,float *ti,float *tf,cal_int *i /***************************/ /* INTERFACES D'ECRITURE */ /***************************/ -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 +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 STR_PLEN(nom) STR_PLEN(tab)); 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)); 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)); 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)); 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)); 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)); +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)); 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)); 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)); -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 +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 STR_PLEN(nom) STR_PLEN(tab)) { char ** tabChaine=NULL; @@ -227,26 +252,26 @@ void F_FUNC(cpech,CPECH)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); tabChaine = (char **) malloc(sizeof(char *) * *n); - for (index = 0; index < *n; index++) { - - tabChaine[index] = (char *) malloc(sizeof(char) * (STR_LEN(tab) + 1)); - strncpy(tabChaine[index],&tab[STR_LEN(tab) * index],STR_LEN(tab)); - tabChaine[index][STR_LEN(tab)]='\0'; - for (index2 = STR_LEN(tab) - 1; index2 >= 0; index2--) { - if ( tabChaine[index][index2] == ' ' || - tabChaine[index][index2] == '\0' ) - tabChaine[index][index2]='\0'; + for (index = 0; index < *n; index++) + { + tabChaine[index] = (char *) malloc(sizeof(char) * (STR_LEN(tab) + 1)); + strncpy(tabChaine[index],&tab[STR_LEN(tab) * index],STR_LEN(tab)); + tabChaine[index][STR_LEN(tab)]='\0'; + for (index2 = STR_LEN(tab) - 1; index2 >= 0; index2--) + { + if ( tabChaine[index][index2] == ' ' || tabChaine[index][index2] == '\0' ) + tabChaine[index][index2]='\0'; + } } - } *err=cp_ech_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tabChaine,STR_LEN(tab) ); - if (tabChaine != (char **) NULL) { - for (index = 0; index < *n; index++) - free(tabChaine[index]); - - free(tabChaine); - } + if (tabChaine != (char **) NULL) + { + for (index = 0; index < *n; index++) + free(tabChaine[index]); + free(tabChaine); + } free_str1(cnom); } @@ -277,7 +302,7 @@ void F_FUNC(cpein,CPEIN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); #if !SIZEOF_INT -#error "The macro SIZEOF_INT must be defined." +#error "The macro SIZEOF_INT must be defined." #elif SIZEOF_INT == 4 *err=cp_ein_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab); #else @@ -292,7 +317,7 @@ void F_FUNC(cpelg,CPELG)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); #if !SIZEOF_LONG -#error "The macro SIZEOF_LONG must be defined." +#error "The macro SIZEOF_LONG must be defined." #elif SIZEOF_LONG == 8 *err=cp_elg_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab); #else @@ -302,6 +327,22 @@ void F_FUNC(cpelg,CPELG)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS free_str1(cnom); } +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)) +{ + + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); +#if !SIZEOF_LONG +#error "The macro SIZEOF_LONG must be defined." +#elif SIZEOF_LONG == 8 + *err=cp_eln_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab); +#else + fprintf(stderr,"CPELN: %s %f %d : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n", + cnom, *ti,*iter); +#endif + free_str1(cnom); +} + + 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)) { char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); diff --git a/src/DSC/DSC_User/Datastream/Calcium/calciumf.h b/src/DSC/DSC_User/Datastream/Calcium/calciumf.h index 61ad82cba..1fd5bb248 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/calciumf.h +++ b/src/DSC/DSC_User/Datastream/Calcium/calciumf.h @@ -46,6 +46,7 @@ CALCIUM_ECR_INTERFACE_C_H(een_fort_,float ,cal_int,cal_int,integer,,); CALCIUM_ECR_INTERFACE_C_H(elg_fort_,float ,cal_int,long ,long2integer,,); +CALCIUM_ECR_INTERFACE_C_H(eln_fort_,float ,cal_int,long ,long,,); CALCIUM_ECR_INTERFACE_C_H(ein_fort_,float ,cal_int,int ,int2integer,,); CALCIUM_ECR_INTERFACE_C_H(ere_fort_,float ,cal_int,float ,float,,); CALCIUM_ECR_INTERFACE_C_H(edb_fort_,double,cal_int,double,double,,); @@ -56,16 +57,18 @@ CALCIUM_ECR_INTERFACE_C_H(ech_fort_,float ,cal_int,char ,str,STAR,LCH_LAST_PARA #define CALCIUM_LECT_INTERFACE_C_H(_name,_timeType,_calInt,_type,_typeName,_qual,lastarg) \ + extern void cp_##_name##_free ( _type _qual * data); \ extern _calInt cp_##_name (void * component, _calInt mode, \ _timeType * ti, _timeType * tf, _calInt * i, \ char * nomvar, _calInt bufferLength, \ _calInt * nRead, _type _qual * data \ lastarg ) ; \ \ - + CALCIUM_LECT_INTERFACE_C_H(len_fort_,float ,cal_int,cal_int ,integer,,); CALCIUM_LECT_INTERFACE_C_H(llg_fort_,float ,cal_int,long ,long2integer,,); +CALCIUM_LECT_INTERFACE_C_H(lln_fort_,float ,cal_int,long ,long,,); CALCIUM_LECT_INTERFACE_C_H(lin_fort_,float ,cal_int,int ,int2integer,,); CALCIUM_LECT_INTERFACE_C_H(lre_fort_,float ,cal_int,float ,float,,); CALCIUM_LECT_INTERFACE_C_H(ldb_fort_,double,cal_int,double ,double,,); -- 2.39.2