Confirming understanding of assignments

Just to confirm my understanding…

data ifirst /0/

would be the equivalent to…

integer ifirst = 0

and not…

integer ifirst

first = 0

Equally…

DATA DTIMEx, DTMINx, DTMAXx /0.0, 0.0, 0.0/

would become

real dtimex = 0.0
real dtminx = 0.0
real dtmax = 0.0

whilst…

DATA ZH / 1.0081451, 4.003874, 12.0038156, 23., 24.32,      &
     &      26.97, 28.06, 32.07, 39.102, 40.08, 55.85, 14.0075257,      &
     &      16., 19.99, 6.941/

is defining an array with 15 elements, each element assigned the given value; so…

real zh = (/ 1.0081451, 4.003874, 12.0038156, 23., 24.32,      &
     &      26.97, 28.06, 32.07, 39.102, 40.08, 55.85, 14.0075257,      &
     &      16., 19.99, 6.941/)

Am I correct here?

Technically your first line is equivalent to the following in that the SAVE attribute is implied with DATA statements:

integer, save :: ifirst = 0

And carry this forward to the rest of your code snippets.

Yes, I excluded the save in my examples because I always get a comment that it is implied anyway. I will be including the save, even if implied, since I agreed with an earlier poster that I should not rely upon implications. :slight_smile:
Thank you.

In my opinion this is a wise decision: it makes the SAVE attribute explicit. (It is also distinguishes the statement from syntactically but not semantically equivalent statements in C or similar languages)

Please note, however, a subtle difference. While the two following lines:

integer, save :: ifirst = 0
integer :: ifirst = 0

do mean exactly the same, the following two:

integer, save :: ifirst = 0, isec
integer :: ifirst = 0, isec

do not. In the first line the save attribute is given both to ifirst and isec. In the second line only ifirst is (implicitly) given save attribute.

2 Likes