As to “best alternatives”, consider first the predominant uses of DATA
statement in codes that you will not view as “modern fortran”. Such uses will be:
- Data initialization of what are otherwise constants in code, take the value of the mathematical constant \pi for example,
- Data initialization of arrays that have some “heft” and pattern to them which then need to be reused in code.
For the use case #1 above, consider named constant facility in Fortran with the PARAMETER
attribute.
For the second use case, consider the use of such data objects as module entities instead.
Note the standard semantics implicitly imparts the SAVE
attribute to objects in DATA
statements:
- named constants with the
PARAMETER
are both immutable and available in program when a program unit containing its definition becomes active, Thus no issue here. - module entities are also
SAVE
and working with them can be seen as a modern, safer alternative.