Declaration and initialization of local variables in Fortran PURE FUNCTIONs
fortran
Solution
Under modern Fortran initialization implies `SAVE`. From F2008 5.2.3
Explicit initialization of a variable that is not in a common block implies the SAVE attribute, which may be confirmed by explicit specification.
You can use local variables, but just
real t
t = 0
which isn't initialization.
Problem
I have a function that looks like this: ``` PURE FUNCTION simulate(initial_state, time_specification) TYPE(ocean), INTENT(IN) :: initial_state TYPE(simulation_time), INTENT(IN) :: time_specification TYPE(ocean) :: simulate REAL :: t = 0.0 ! etc END FUNCTION simulate ``` gfortran 4.8.1 informs me that ``` REAL :: t = 0.0 1 Error: Initialization of variable at (1) is not allowed in a PURE procedure ``` As I understand it, I should be able to use local variables within pure functions as long as they do not have the SAVE attribute. So what am I doing wrong?