data initialization

Hi,

I was living under the misapprehension that a variable could be initialized at declaration time as follows:

INTEGER :: N = 17

It appears that this is done only the first time that the subroutine, where this variable belongs to, is called. Can I switch this behaviour to a mode where the initialization of the local variable is done every single time that I call the respective subroutine?

Thanks!

Arjan

Hi Arjan,

A variable which is intialized in a type statement has the SAVE attribute automatically applied. Hence, the variable’s value will be persistant between calls. Instead, you’ll need to explicitly initialize N’s value in the body of the routine.

INTEGER :: N
N =10

Hope this helps!
Mat

I already tried the explicit assignment instead of the initialization in the declaration line. It worked for the new problem. And guess what? I re-checked my modules for this trick and now the bitmap-problem is solved!

Have a nice weekend over there!

Arjan

I’m glad to hear it. You have a nice weekend as well!

  • Mat