<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 18/07/2012 14:34, Eduardo
Torrecillas a écrit :<br>
</div>
<blockquote
cite="mid:CADqPe=uwR6TrzGws7vqqu1iW98_t31VqgV28uY2eD3imXsc8TQ@mail.gmail.com"
type="cite">Hello Serge,<br>
<br>
Thanks for your reply, the solution is really clever.
Unfortunately, I am having some troubles on implementing it.
Please see below:<br>
<br>
I tried using global variables using modules, for example, the
file mod_01.f90:<br>
<br>
module mod01<br>
implicit none<br>
integer, parameter,public :: dp=8<br>
real(kind=dp),parameter,public::pi=ATAN(1.0_dp)*4.0_dp<br>
real(kind=dp),public::Apub<br>
<br>
end module mod01<br>
<br>
<br>
And then, tried using it on another f90 subroutine, <br>
<br>
subroutine fprepara_var_equil(a,dummyout)<br>
use mod01<br>
implicit none<br>
real(kind=dp),intent(in)::a<br>
real(kind=dp),intent(out)::dummysai<br>
<br>
Apub=a<br>
dummysai=0.0_dp<br>
<br>
end subroutine fprepara_var_equil<br>
<br>
Everything goes fine during compilation, but when trying to link
libraries "exec floader.sce", I get the following message:<br>
<br>
undefined symbol: __mod01_MOD_apub<br>
<br>
When trying to use the same strategy using pure fortran, the code
compiles and runs perfectly. Any suggestion?<br>
<br>
</blockquote>
Sorry I know very few thing about f90. May be some one else can help
you...<br>
<br>
Serge<br>
<blockquote
cite="mid:CADqPe=uwR6TrzGws7vqqu1iW98_t31VqgV28uY2eD3imXsc8TQ@mail.gmail.com"
type="cite">Regards,<br>
<br>
<div class="gmail_quote">On Mon, Jul 16, 2012 at 12:15 PM, Serge
Steer <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:Serge.Steer@inria.fr" target="_blank">Serge.Steer@inria.fr</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Le 16/07/2012 16:04, Eduardo Torrecillas a écrit :
<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hi everybody,<br>
<br>
I am trying to use fsolve with a fortran subroutine as
argument. For example, consider the following calling
sequence:<br>
<br>
X0=[0 0]<br>
<br>
tol=1E-15<br>
<br>
[X,v]=fsolve(X0,'fequil_fortran',tol)<br>
<br>
In this case 'fequil_fortran' is my external fortran
subroutine, given below:<br>
<br>
--------------------------------------------------------------------<br>
<br>
subroutine fequil_fortran(n,x,v,iflag)<br>
<br>
implicit none<br>
<br>
integer,intent(in)::n,iflag<br>
<br>
real(kind=8),dimension(n),intent(in)::x<br>
<br>
real(kind=8),dimension(n),intent(out)::vreal(kind=8)::a,b<br>
<br>
a=1.0_dp<br>
<br>
b=2.0_dp<br>
<br>
v(1)=a*x(1)+b*x(2)-1.0_dp<br>
<br>
v(2)=2.0_dp*a*x(1)-b*x(2)-5.0_dp<br>
<br>
end subroutine fequil_fortran<br>
<br>
---------------------------------------------------------------------<br>
<br>
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?<br>
<br>
</blockquote>
</div>
</div>
The answer is no, the underlying code does not handle extra
arguments for the external function.<br>
<br>
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<br>
<br>
something like<br>
subroutine fequil_settings(a,b)<br>
...<br>
end<br>
<br>
Also add the common declaration in fequil_fortran, compile and
link both function with Scilab<br>
<br>
And then in Scilab you can do<br>
a=...<br>
b=...<br>
call("fequil_settings",a,1,"d",b,2,"d","out",[1 1],"d");<br>
[X,v]=fsolve(X0,'fequil_fortran',tol)
<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Regards,<br>
<br>
-- <br>
Eduardo Torrecillas<br>
AER-09<br>
</blockquote>
<br>
<br>
<br>
</div>
--<br>
To unsubscribe from this mailing-list, please send an empty
mail to<br>
<a moz-do-not-send="true"
href="mailto:users-unsubscribe@lists.scilab.org"
target="_blank">users-unsubscribe@lists.scilab.org</a><br>
To check the archives of this mailing list, see<br>
<a moz-do-not-send="true"
href="http://mailinglists.scilab.org/" target="_blank">http://mailinglists.scilab.org/</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
Eduardo Torrecillas<br>
AER-09<br>
</blockquote>
<br>
</body>
</html>