- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TWIMC
I was given a program that had this subroutine:
subroutine writePointsNMBGA2(fileName,x, y, values, npts, metric, iun, singleLongLat,ntraj,trajx,trajy, npemp, pemps, metric2, hasCart)
use pempContents
real x(*),y(*),values(*)
real trajx(*),trajy(*)
double precision xtmp(npts),ytmp(npts)
double precision trajxtmp(npts),trajytmp(npts)
double precision singleLongLat(5)
How is it that the declaration of trajxtmps(npts) works? I would have thought that even if the compiler didn't through an error compiling it, it would blow at run time.
If this is fine now, please let me know. Thank you.
Sincerely,
CHobbs
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The subroutine declaration is .NOT. using IMPLICIT NONE, therefore the argument npts is implicitly declared as integer and whatever the value of the integer npts is, declares the size of the arrays using (npts). I am assuming npts is the number of points. For the variables declared with (*) the size is permitted to be unknown but indexible (it is your responsibility to not access beyond bounds of the array).
Added: In the IVF documentation index, search for: assumed-size arrays
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Jim. I'm just surprised that the program will have the foresight to allocate the required memory when it gets to that subroutine. I did not think that was allowed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note 2,
When npts, in the above example, requires a stack allocation (for local arrays dimensioned with npts), larger than remaining stack, then the call will fail. You can use allocatable or heap arrays to avoid this.
Jim Dempsey

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