The argument to my fortran 95 routine is the intended array of the form with the intent inout:
the_subroutine(my_argument) real, dimension(:,:), intent(inout) :: my_argument (...)
In the main program, I have a allocated array. I highlight it and also rename indexes . Then I call the subroutine and pass this (correctly allocated) array to the subroutine:
allocate(the_array( 5:1005 , 5:1005 )) call the_subroutine(my_argument=the_array)
The routine performs certain calculations and populates the array with values. In the very last line, until the end of the subroutine, I check a random value:
(...) print*, my_argument(213,126) ! I get 2.873... end subroutine the_subroutine
Then, in the very first line after calling the subroutine , I will check whether this value is correctly transferred by the subroutine to the outside world, but this is not so:
call the_subroutine(my_argument=the_array) print*, the_array(213,126) ! I get 3.798... A completely different value.
The problem arises due to reindexing the array in the main program as follows:
allocate(the_array( 5:1005 , 5:1005 ))
where max_index is min_index = 1000-1, but the routine "sees" the array internally, as if I had declared a normal path, that is:
allocate(the_array( 1:1000, 1:1000))
Or just select (the_array (1000, 1000))
Therefore, the element (213,126) in the internal array is in a different place, as in the main program array. Is there a simple way out of this?