- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Colleagues,
I have (very) distant memory of encountering this problem before. Cannot recall the solution.
P is declared a pointer P(: ,
D is target and dimensioned: D(-180:180, -180:180)
F is target and dimensioned: F(-180:180, -180:180,10)
Assigning P to D
P => D P has negative indices and works in subsequent code expecting (-180:180, -180:180)
Assigning P to a page of F
P => F(: , : , 3) P does not have indices: (1:361, 1:361). Using P in subsequent code fails.
Is there a way to point to a slice of an array with negative indices?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May be if you try this minimal working example and modify it to illustrate the problem, it will be easier for readers to provide some guidance:
integer, target :: F(-2:2,-2:2,2)
integer, pointer :: P(:,:)
F = reshape( source=[( i, integer :: i = 1, size(F) )], shape=shape(F) )
P => F(:,:,2)
print *, "shape(P) = ", shape(P), "expected is [5,5] "
print *, "P(2,4) = ", P(2,4), "expected is ", F(-1,1,2)
end
C:\temp>ifort /standard-semantics t.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.30.30706.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:t.exe
-subsystem:console
t.obj
C:\temp>t.exe
shape(P) = 5 5 expected is [5,5]
P(2,4) = 42 expected is 42
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May be if you try this minimal working example and modify it to illustrate the problem, it will be easier for readers to provide some guidance:
integer, target :: F(-2:2,-2:2,2)
integer, pointer :: P(:,:)
F = reshape( source=[( i, integer :: i = 1, size(F) )], shape=shape(F) )
P => F(:,:,2)
print *, "shape(P) = ", shape(P), "expected is [5,5] "
print *, "P(2,4) = ", P(2,4), "expected is ", F(-1,1,2)
end
C:\temp>ifort /standard-semantics t.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.30.30706.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:t.exe
-subsystem:console
t.obj
C:\temp>t.exe
shape(P) = 5 5 expected is [5,5]
P(2,4) = 42 expected is 42
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also for general Fortran language related discussion, you may find the Fortran Discourse site also helpful:
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page