- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a statement function in the form of
DS2(XT,YT,XM,YM) = ((XT-XM)/XOM)**2+((YT-YM)/YOM)**2
So I know I can write:
REAL(KIND=4) FUNCTION DS2(XT,YT,XM,YM)
REAL(KIND=4) XT,YT,XM,YM
DS2= ((XT-XM)/XOM)**2+((YT-YM)/YOM)**2
END FUNCTION DS2
But where does XOM,YOM get it's declaration/value in the statement function? Does it just assume values from surrounding code, ignoring the fact that "call parameters" don't include XOM,YOM?
Is this behavior defned by the standard at all?
Regards
Carl
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't understand your sample code, though. It seems you have both a statement function and a regular function named DS2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't understand your sample code, though. It seems you have both a statement function and a regular function named DS2.
Steve:
Thanks for the prompt reply...
My statement function was orginally: DS2(XT,YT,XM,YM) = ((XT-XM)/XOM)**2+((YT-YM)/YOM)**2
and the left hand side lacked the XOM, YOM values. So from what you have said replacing DS2(XT,YT,XM,YM) with DS2(XT,YT,XM,YM,XOM,YOM ) everywhere should be just fine, as XOM,YOM should be defined in that section of code.
As it was explained to me by local grey beards the statement function worked something along the lines of apreprocessormacro ....the classic example in Cwould be:
#define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
So what you have said makes sense.
Which means I could do thesame approach here using fpp
#define DS2(XT,YT,XM,YM) ( ((XT-XM)/XOM)**2+((YT-YM)/YOM)**2 )
The effect is basically "in-lining" the function call hopefully making for faster code, by eliminating a function call. Is thismacro definition a better approach ?
But now you mention ...`internal function and it will "host associate" variables from the caller`... this opens a few questions.
Internal functionhere I assume means thescope of the function name only be valid within a limited context, as in within a single F90+ module?
Thanks for you insight
Regards
Carl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't recommend using #define as that requires using the preprocessor and is not standard at all.
Internal procedures are not module procedures, though they look like that. You'd write something like this:
[plain]program main real xom, yom ... y = ds2(a,b,c,d) ... contains real function ds2 (xt,xm,yt,ym) real xt,xm,yt,ym ds2 = ( ((XT-XM)/XOM)**2+((YT-YM)/YOM)**2 ) return end function ds2 end program main[/plain]When ds2 is called, it will "host associate" variables declared in the outer scope such as XOM and YOM and take whatever the current values are.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page