13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>variable in a subroutine needs to be kept between successive calls to the subroutine, itshould be given the attribute save:subroutine sub1 (first)implicit nonelogical, intent (in) :: firstinteger, save :: int1[ … ]end program sub1Note that initialisation of a variable in the declaration or in a data statement implicitlygives it the save status. However, it is clearer to explicitly include the save attribute alsoin these cases:integer, save :: int1 = 0One should not give a variable the save attribute if it does not need it, as it may impedeoptimisation by the compiler and it also makes e.g., parallelisation more difficult.Variables in modulesThe lifetime of a variable declared in a module is as long as any routine using thismodule is running. Consider the following example:module mod1implicit noneinteger :: int1end module mod1subroutine sub1 (first)use mod1implicit nonelogical, intent (in) :: firstif (first) thenint1 = 0elseint1 = int1 + 1end ifend subroutine sub1program prog1implicit nonecall sub1 (.true.)call sub1 (.false.)end subroutine prog164

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!