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)
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.
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
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.
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.