1
subroutine intex8f(fname)
3
C --------------------------------------------
6
c An example of an hand written interface
7
c passing a Scilab function as input of function ex8f
9
c call in Scilab:-->ex8f(x1,x2,a_function)
10
c x1<->1 (double array)
11
c x2<->2 (double array)
12
c a_function <-> 3 (a scilab function).
13
c a_function is the function "myfunction" defined
14
c in ex8f.sce. It has mlhs=2 inputs and mrhs=3 outputs.
16
logical getrhsvar,createvar,scifunction
17
logical checklhs,checkrhs
18
common/ ierfeval / iero
20
if(.not.checkrhs(fname,3,3)) return
21
if(.not.checklhs(fname,1,3)) return
24
if (.not.getrhsvar(1,'d',m1,n1,l1)) return
26
if (.not.getrhsvar(2,'d',m2,n2,l2)) return
27
c lf is the adress of a_function
28
c mlhs (resp. mrhs) is its number of outputs (resp. inputs)
29
c 3 and 'f' are inputs of getrhsvar
30
c mlhs,mrhs,lf are outputs of getrhsvar
32
if (.not.getrhsvar(3,'f',mlhs,mrhs,lf)) return
35
buf='invalid rhs for Scilab function'
39
c To call a_function it is required that its input arguments are
40
c stored in the last positions of the variables stack. NOTE that when
41
c called, the function destroys its input variables and replaces them by
42
c the output variables. so in this case we need to make a copy of
44
c Remark: if the calling sequence of geval had been geval(a_function,x1,x2)
45
c the following two copies would be un-necessary.
48
if(.not.createvar(3+1,'d',m1,n1,l4)) return
49
call dcopy(m1*n1,stk(l1),1,stk(l4),1)
52
if(.not.createvar(3+mrhs,'d',m2,n2,l5)) return
53
call dcopy(m2*n2,stk(l2),1,stk(l5),1)
55
c Here a_function takes variables 4 and 5 as inputs and generates output
56
c variables at positions 4 to 4-1+mlhs
58
c ibegin must be the index of the first input variable of a_function
62
if(.not.scifunction(ibegin,lf,mlhs,mrhs)) return
64
c check if an error has occured while running a_function
67
c output variables: 4 and 5 (created by a_function) and possibly 6
68
c if a_function has 3 output parameters
70
c select index of variables to return
73
if(mlhs.eq.3) lhsvar(3)=6