next up previous contents index
Next: 6.3.1.0.7 Using lists as Up: 6.3.1 Using Intersci Previous: 6.3.1.0.5 Dimensions of non

   
6.3.1.0.6 Fortran variables with external type

External types are used when the dimension of the Fortran variable is unknown when calling the Fortran subroutine and when its memory size is allocated in this subroutine. This dimension must be an output of the Fortran subroutine. In fact, this will typically happen when we want to interface a C function in which memory is dynamically allocated.

Existing external types:

cchar
character string allocated by a C function to be copied into the corresponding Scilab variable.
ccharf
the same as cchar but the C character string is freed after the copy.
cdouble
C double array allocated by a C function to be copied into the corresponding Scilab variable.
cdoublef
the same as cdouble but the C double array is freed after the copy.
cint
C integer array allocated by a C function to be copied into the corresponding Scilab variable.
cintf
the same as cint but the C integer array is freed after the copy.


In fact, the name of an external type corresponds to the name of a C function. This C function has three arguments: the dimension of the variable, an input pointer and an output pointer.

For instance, below is the code for external type cintf:

#include "../machine.h"   

/* ip is a pointer to a Fortran variable coming from SCILAB
which is itself a pointer to an array of n integers typically
coming from a C function
   cintf converts this integer array into a double array in op 
   moreover, pointer ip is freed */

void C2F(cintf)(n,ip,op)
int *n;
int *ip[];
double *op;
{
  int i;
  for (i = 0; i < *n; i++)
    op[i]=(double)(*ip)[i];
  free((char *)(*ip));
}

For the meaning of #include "../machine.h" and C2F see 6.3.1.

Then, the user can create its own external types by creating its own C functions with the same arguments. Intersci will generate the call of the function.


next up previous contents index
Next: 6.3.1.0.7 Using lists as Up: 6.3.1 Using Intersci Previous: 6.3.1.0.5 Dimensions of non
Scilab Group