For Programmers: Free Programming Magazines  


Home > Archive > Fortran > September 2006 > Re: how can I parameterize a 1d function by extracting it from a









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: how can I parameterize a 1d function by extracting it from a
Craig Powers

2006-09-28, 7:00 pm

Nye wrote:
> In case I have a subroutine A that needs a 1d function f(x) as its
> parameter, and f(x) could be derived from a 2d function g(x,y) by
> keeping the other variable y as a constant.
>
> The situation is, I have g(x,y) already well defined in the program, and
> I need to call A from time to time when the y changes thus need f(x) to
> be a dynamically changing function. I wonder is there any simple way to
> achieve this?
>
>
> do i=1,100
> y=y*1.2
> call A(f)
> continue
> end
>
> function g(x,y)
>
> so how to define f(x)?


Define f as a module function, with the value of y kept as a module
variable, e.g.

MODULE mod_f
! etc.
REAL y

CONTAINS
REAL FUNCTION f(x)
f = g(x,y)
END FUNCTION f
END MODULE mod_f

! etc.
Brooks Moses

2006-09-28, 9:59 pm

Nye wrote:
> Craig Powers <enigma@hal-pc.org> writes:
>
> Thanks, but my compiler is f77, I'm afraid there is no MODULE support within......
> Is there any other way of doing this?


Yup. Use a named COMMON block.

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com