Self study guide: Fortran 95 - University of Cambridge
Self study guide: Fortran 95 - University of Cambridge
Self study guide: Fortran 95 - University of Cambridge
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
subroutine setval(x, y)<br />
! set y to value <strong>of</strong> x<br />
real, intent(in) :: x<br />
real, intent(out) :: y<br />
y = x<br />
end subroutine setval<br />
• Modify the setval example above to use this subroutine.<br />
• Deliberately introduce an error and within the subroutine attempt to change<br />
the value <strong>of</strong> the first argument; try compiling the program and see what happens.<br />
Local variables which are declared within a routine will in general not retain their<br />
values between successive calls to the routine. It is possible to preserve values after<br />
one return into the next call <strong>of</strong> the routine by specifying the save attribute in the<br />
declaration <strong>of</strong> that variable, e.g.<br />
real, save :: local<br />
This <strong>of</strong> course cannot be used for the arguments <strong>of</strong> the routine.<br />
37