[scilab-Users] fsolve with external fortran subroutine

Serge Steer Serge.Steer at inria.fr
Wed Jul 18 16:14:06 CEST 2012


Le 18/07/2012 14:34, Eduardo Torrecillas a écrit :
> Hello Serge,
>
> Thanks for your reply, the solution is really clever. Unfortunately, I 
> am having some troubles on implementing it. Please see below:
>
> I tried using global variables using modules, for example, the file 
> mod_01.f90:
>
> module mod01
> implicit none
> integer, parameter,public :: dp=8
> real(kind=dp),parameter,public::pi=ATAN(1.0_dp)*4.0_dp
> real(kind=dp),public::Apub
>
> end module mod01
>
>
> And then, tried using it on another f90 subroutine,
>
> subroutine fprepara_var_equil(a,dummyout)
> use mod01
> implicit none
> real(kind=dp),intent(in)::a
> real(kind=dp),intent(out)::dummysai
>
> Apub=a
> dummysai=0.0_dp
>
> end subroutine fprepara_var_equil
>
> Everything goes fine during compilation, but when trying to link 
> libraries "exec floader.sce", I get the following message:
>
> undefined symbol: __mod01_MOD_apub
>
> When trying to use the same strategy using pure fortran, the code 
> compiles and runs perfectly. Any suggestion?
>
Sorry I know very few thing about f90. May be some one else can help you...

Serge
> Regards,
>
> On Mon, Jul 16, 2012 at 12:15 PM, Serge Steer <Serge.Steer at inria.fr 
> <mailto:Serge.Steer at inria.fr>> wrote:
>
>     Le 16/07/2012 16:04, Eduardo Torrecillas a écrit :
>
>
>         Hi everybody,
>
>         I am trying to use fsolve with a fortran subroutine as
>         argument. For example, consider the following calling sequence:
>
>         X0=[0 0]
>
>         tol=1E-15
>
>         [X,v]=fsolve(X0,'fequil_fortran',tol)
>
>         In this case 'fequil_fortran' is my external fortran
>         subroutine, given below:
>
>         --------------------------------------------------------------------
>
>         subroutine fequil_fortran(n,x,v,iflag)
>
>         implicit none
>
>         integer,intent(in)::n,iflag
>
>         real(kind=8),dimension(n),intent(in)::x
>
>         real(kind=8),dimension(n),intent(out)::vreal(kind=8)::a,b
>
>          a=1.0_dp
>
>         b=2.0_dp
>
>         v(1)=a*x(1)+b*x(2)-1.0_dp
>
>         v(2)=2.0_dp*a*x(1)-b*x(2)-5.0_dp
>
>         end subroutine fequil_fortran
>
>         ---------------------------------------------------------------------
>
>         It worked fine and fsolve found the solution. Now, suppose I
>         have to pass arguments to the fortran subroutine, in addition
>         to the default (n,x,v,iflag). For instance, imagine I had to
>         pass the 'a' and 'b' variables from Scilab to the fortran
>         subroutine in the code above. I have already performed
>         something like this but with "optim". In fact, "optim" gives
>         you the possibility to pass a list of integer, real or double
>         variables to the external code. Is there anything similar to
>         be used with fsolve?
>
>     The answer is no, the underlying code does not handle extra
>     arguments for the external function.
>
>     It is however possible to declare a and b as elements of a common
>     and to set their value using another fortran code called using the
>     function call
>
>     something like
>     subroutine fequil_settings(a,b)
>     ...
>     end
>
>     Also add the common declaration in fequil_fortran, compile and
>     link both function with Scilab
>
>     And then in Scilab you can do
>     a=...
>     b=...
>     call("fequil_settings",a,1,"d",b,2,"d","out",[1 1],"d");
>     [X,v]=fsolve(X0,'fequil_fortran',tol)
>
>         Regards,
>
>         -- 
>         Eduardo Torrecillas
>         AER-09
>
>
>
>
>     --
>     To unsubscribe from this mailing-list, please send an empty mail to
>     users-unsubscribe at lists.scilab.org
>     <mailto:users-unsubscribe at lists.scilab.org>
>     To check the archives of this mailing list, see
>     http://mailinglists.scilab.org/
>
>
>
>
> -- 
> Eduardo Torrecillas
> AER-09

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20120718/6b77ae4d/attachment.htm>


More information about the users mailing list