Re: Manage external functions



On Oct 24, 2:41 pm, Arjen Markus <arjen.mar...@xxxxxxxxxx> wrote:
On 24 okt, 07:01, Mike <Sulfate...@xxxxxxxxx> wrote:



On Oct 24, 12:17 pm, Mike <Sulfate...@xxxxxxxxx> wrote:

Hi

   Is there a way to better manage some similar external functions as
input arguments in IMSL?
  Let's say I use method1 and method2 in IMSL to solve the roots.
There should be different FUNCs for method 1 and method2.  Currently I
create two projects for two methods and append the FUNC in the main
program, like:

proj1
module  MyStuff1
contains
 subroutine myMethod1()
    call IMSLMethod1()
end module  MyStuff1
program main
   use imsl_stuff
   use MyStuff
   call IMSLMethod1()
end program main
FUNCTION FUNC()
================================
proj2
module  MyStuff2
contains
 subroutine myMethod2()
    call IMSLMethod2()
end module  MyStuff2
program main
   use imsl_stuff
   use MyStuff2
   call IMSLMethod2()
end program main
FUNCTION FUNC()   <==same FUNC name

I'd like to manage them better, since two projects contains similar
modules.
I also try to put FUNC into module MyStuff, however, if I use both
MuStuff modules
then may be two FUNCs will be used.  That will be a bad idea.

Mike

If I do :
program main
   use imsl_stuff
   use MyStuff1
   use MyStuff2
   call IMSLMethod1()
   call IMSLMethod2()
end program main
FUNCTION FUNC()   <==how to specify different FUNCs here?

thank you a million.

Mike- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

That sort of functionality has been around for a very long
time in Fortran. For instance (using Fortran 90 features):

program integrate_a_bit

    call integrate( f, 1.0, 2.0, result )
    call integrate( g, 1.0, 10.0, result )

containing
subroutine integrate( f, a, b, result )
    real :: a, b, result
    interface
        real function f(x)
            real :: x
    end interface

    ! compute a rough approximation of the integral over [a,b]
    do i = 1,10
        xc     = a + (i-0.5) * (b-a)/10.0
        result = result + f(x)
    enddo
    result = result * (b-a)/10.0

end subroutine

real function f(x)
    real :: x
    f = x**2
end function

real function g(x)
    real :: x
    g = x*expr(-x)
end function

end program

The method: you pass the function as an argument

Regards,

Arjen

Oh. The problem is the "f" function must be "f", I cannot modify it
to other names (It's defined by some library such as Numerical Recipe
or IMSL).
So two f? How to manage them, such that one f w.r.t. Method1 and
other f w.r.t. Method2?

Thanks.

Mike
.



Relevant Pages

  • Re: Manage external functions
    ... input arguments in IMSL? ...   Let's say I use method1 and method2 in IMSL to solve the roots. ... There should be different FUNCs for method 1 and method2. ...
    (comp.lang.fortran)
  • Re: Manage external functions
    ...   Let's say I use method1 and method2 in IMSL to solve the roots. ... There should be different FUNCs for method 1 and method2. ... I also try to put FUNC into module MyStuff, however, if I use both ...
    (comp.lang.fortran)
  • Re: solving two of nonlinear equations and two unknwons.
    ...  I use IMSL and fortran. ... Solves a nonlinear least squares problem subject to bounds on the ... this would yield horribly wrong derivatives and hence chaotic ...
    (sci.math.num-analysis)
  • Re: search a sorted vector
    ...     In IMSL, there is a function SRCH which can search a sorted vector ... for a given scalar and return its index. ... I don't find one in IMSL. ...
    (sci.math)
  • Re: Manage external functions
    ... What version of gfortran do you have? ...    implicit none ... end module mykinds ... end module funcs ...
    (comp.lang.fortran)