- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wish to pass an array length implicitly, for example:
real A(12,12),avg
call average(a(3:8,5),avg)
in this case AVERAGE would take the average of 6 elements of column 5.
Or we could have
real c(5)
call average(c,avg)
Where we take the average of all 5 elements of array C.
How would one do this without having to SAY HOW MANY elements to process?
Actually AVERAGE could be a function, and I suppose there is one already in the math library.
This is just an example - - -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is done using assumed-shape arrays, which require an explicit interface. An example:
module myfuncs contains subroutine average (a,avg) real, intent(in) :: a(:,:) real, intent(out) :: avg avg = sum(array)/real(size(array)) end subroutine average end module myfuncs
You would then add "use myfuncs" to make the declaration visible. Note that this example requires a two-dimension array. In order to allow arrays of other dimensions, you'd need to define one routine for each number of dimensions and then have a generic declaration to allow the compiler to pick.
Fortran 2015 will have a new feature called assumed-rank where you can have one routine accept an array of any rank (number of dimensions), but there are severe restrictions on what you can do with the argument when you get it. We don't support this feature yet.

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