Is there a way to specify a user-supplied routine when using the define_external command?

Here is a simple Fortran program to show what I want.

      integer n
      real*8 x(2),res
      n=2
      external sub1
      x(1)=1.
      x(2)=2.
      call sub(n,x,sub1,res)
      write(*,*)res
      stop
      end
      subroutine sub(n,x,usersub,res)
      integer n
      real*8 x(*),res
      external usersub
      call usersub(n,x,res)
      return
      end
      subroutine sub1(n,x,res)
      integer i,n,nmax
      parameter (nmax=10)
      real*8 x(*),res,f(nmax)
      f(1)=x(1)+x(2)
      f(2)=x(1)-x(2)
      res=1.
      do 10 i=1,n
        res=res*f(i)
10    continue
      return
      end
 

I want to use the routine sub from Maple. It needs the user-supplied routine usersub (called sub1 above). The Maple program should calculate the formulas for f in sub1, create sub1 and then call sub to do the calculations.

In the real problem, the formulas for f will change from run to run and the calculations are more complicated, so this all needs to be automatic.

Is this possible to do?

Thanks.

 

 

 


Please Wait...