- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any caveat in using custom indices for allocatables? For example
real, dimension (:,:), allocatable :: T
allocate ( T(0:2,5:7) )
T = 0
T(0,5) = 1
T(2,7) = 9
print *, T
works great, but it would be to be sure there is no side effects
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The one caveat I can think of is that if you pass the array to a function or subroutine (including intrinsic ones!) the custom indices are not automatically passed on (for good reasons in Here is a small demonstration:
! find_elem.f90 --
! Demonstrate (minor) problem with custom lower-bound
!
program find_elem
implicit none
integer, dimension(-3:3) :: value
integer, dimension(7) :: basic
value = 0
value(1) = 1 ! Note: fifth element in the array
basic = value ! Copy, starts at start of the array
write(*,*) findloc(value, 1), findloc(basic,1)
end program find_elem
The output is NOT "1 5", but "5 5" - the lower bound is not passed to the intrinsic findloc. If you want to use no-default lower/upper bounds in your own routines, you have to explicit use them in the declaration.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The one caveat I can think of is that if you pass the array to a function or subroutine (including intrinsic ones!) the custom indices are not automatically passed on (for good reasons in Here is a small demonstration:
! find_elem.f90 --
! Demonstrate (minor) problem with custom lower-bound
!
program find_elem
implicit none
integer, dimension(-3:3) :: value
integer, dimension(7) :: basic
value = 0
value(1) = 1 ! Note: fifth element in the array
basic = value ! Copy, starts at start of the array
write(*,*) findloc(value, 1), findloc(basic,1)
end program find_elem
The output is NOT "1 5", but "5 5" - the lower bound is not passed to the intrinsic findloc. If you want to use no-default lower/upper bounds in your own routines, you have to explicit use them in the declaration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For my use case, it should be ok then. But it's good to know functions and subroutines need to be more cautious.
Thank you
![](/skins/images/872293744008A34B36F8ABF94A46CC66/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page