- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have an array that is defined to be ALLOCATABLE (defined in my main program). A subroutine is call and that is where it will be allocated. So the dummy argument of the subroutine also needs to be ALLOCATABLE. For this work correctly, the subroutine needs an explicit interface and I have that in a module.
After that, the array will need to be passed into other subroutines. These subroutines will never be messing around with allocation -- simply using the contents of the array.
Currently, I have the dummy argument for the array in other subroutines sizing the array explicitly. The scalar that sizes the dummy array argument is the same value that allocated the array.
The question is...is this "safe" to do? My program compiles and executes successfully, but I'd like to have some opinions and thoughts on the matter.
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you are doing is fine.
Just remember that, in the subroutines to which a previously allocated array has been passed as an argument without the ALLOCATABLE attribute, you cannot, for instance, query whether the array has been allocated by using the ALLOCATED intrinsic. If these subroutines do not have other allocatable arguments, or have other features that mandate providing an explicit interface, you do not need the subroutines to be in USEd modules or to provide explicit interfaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is safe to do provided that the extents of the dimension are correct in the caller.
An alternative is to use Assumed-Shape specifications... but this requires the use of an explicit interface (generally in a module).
Assumed-Shape may incur a little more overhead in calling. IOW do not use Assumed-Shape on arrays with known dimensions (e.g. a rotational matrix).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the replies and information!

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