I have the following array:
type bar
integer*4 :: high
integer*4 :: low
end type
type(bar), dimension(2000:2025, 12, 31, 0:23, 0:59) :: data
I have the following questions:
Which value will have by default high/low variables in each derived type variable of the array? I.E., are they initialized to 0 by default? Does this depend on compiler or it is enforced by the standard?
What if derived type and array are defined in a module? Does it change anything?
If I would like to initialize the whole array high/low values to -1? Which would be the simplest way to do it?
If this depends on compiler then I am using gfortran (gcc8).
There is no particular value guaranteed. The values are undefined. Your compiler might promise some particular value, but it is not portable.
It changes nothing at all.
The default component initialization
:
type bar
integer*4 :: high = -1
integer*4 :: low = -1
end type
for all variables of that type.
Or you can initialize the array only.
type(bar), dimension(2000:2025, 12, 31, 0:23, 0:59) :: data = bar(-1, -1)
Note that the usual gotchas apply, the variable is now implicitly save
. But if it is a module variable it does not change anything. If it is a procedure local variable, be careful.
Please note that the *4
for integers is not valid Fortran 90. It is not standard Fortran at all.