question on intent(in) and changing the input inside a subroutine



I was looking at this web page of best practices in Fortran

http://fortran90.org/src/best-practices.html#arrays

and it shows this code fragment:

-----------------------------
subroutine f(r)
real(dp), intent(in) :: r(:)
integer :: n, i
n = size(r)
do i = 1, n
r(i) = 1.0_dp / i**2
enddo
end subroutine
--------------------------

The first strange thing I noticed is that the formal
parameter r is declared as 'in' yet it is being written
to inside the subroutine. But based on Fortran standard:

"intent(in) means that the variable value can enter, but not be changed"


So, what is going on here?

When I tried it on my end, I am getting an error.

Here is my code to test the above. all in same one file.

------------ t6.f90 -------------------------
module inc
implicit none
contains

subroutine f(r)
integer, parameter:: dp=kind(0.d0)
real(dp), intent(in) :: r(:)
integer :: n, i
n = size(r)
do i = 1, n
r(i) = 1.0_dp / i**2
enddo
end subroutine f
end module inc

program main
use inc
implicit none

integer, parameter:: dp=kind(0.d0)
real(dp) :: r(5)
call f(r)
end program main
----------------------------

---------------------------
gfortran -fcheck=all -Wall t6.f90
t6.f90:11.10:

r(i) = 1.0_dp / i**2
1
Error: Dummy argument 'r' with INTENT(IN) in variable definition context (assignment) at (1)
t6.f90:17.8:

use inc
1
Fatal Error: Can't open module file 'inc.mod' for reading at (1): No such file or directory

------------------------------

Am I doing something wrong? could the web page really be wrong?
Has the standard changed and once it was allowed to write
to an 'in' parameter? does not make much sense.

I am not good enough in Fortran to say that a Fortran90.org
'best practices' page is wrong ! But it sure looks like it.

thanks,
--Nasser
.



Relevant Pages

  • Re: Fortran based MEX w/ COMMON/SAVE
    ... I believe dat (pointer to the array) and the ... SAVE at the begining of each subroutine is a bit unusual to me. ... > to unload it if there isn't a Fortran END or STOP statement. ... interaction w/ Matlab). ...
    (comp.soft-sys.matlab)
  • Re: Help Constructing Fictional Cross-Religious Movement
    ... You know how to do something in Fortran that I ... >don't know how to do despite being pretty familiar with it, COBOL ... > subroutine point ... >was finding a programming problem that seemed reasonably amenable to ...
    (rec.arts.sf.composition)
  • Re: Callbacks - Delphi and CVF
    ... | I have a FORTRAN DLL that does the computations and takes about hours ... | want to be able to access the callback functions address from every ... | subroutine in the fortran dll. ... SUBROUTINE ReportProgress ...
    (comp.lang.fortran)
  • I cant compile the source
    ... I needed hash table source code in Fortran ... Module implementing an OO hash table in Fortran 2003. ... GNU Lesser General Public License for more details. ... RECURSIVE SUBROUTINE put_sll ...
    (comp.lang.fortran)
  • Re: Callbacks - Delphi and CVF
    ... | I have a FORTRAN DLL that does the computations and takes about hours ... | want to be able to access the callback functions address from every ... | subroutine in the fortran dll. ... SUBROUTINE ReportProgress ...
    (comp.lang.fortran)