After using C for a while, I went back to Fortran and allocated the arrays in my code from index 0 to N:
real(kind=dp), dimension(:), allocatable :: a
allocate(a(0:50))
I needed to find the index of the minimum absolute value of the array, so I used MINLOC, and to check this I compared it to MINVAL:
minloc(abs(a(:)))
minval(abs(a))
The result of MINLOC was index 42
but the result of MINVAL corresponded to 41
. Here is the relevant section from the output:
Index i a(i)
39 0.04667
40 0.02222
41 0.00222 !This was clearly the minimum value
42 0.02667
MINLOC = 42
MINVAL = 0.00222
I assume this is something to do with the Fortran intrinsic not handling arrays with index 0 correctly, since it is not standard Fortran style to declare arrays in this way (but it is still permitted!).
Can anyone confirm this or offer a workaround?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…