I have the following piece of code in my subroutine:
character x*256 ,y*80
common /foo/ x ,y(999)
Well, I did not actually write this. So I don't understant the dimensions here. Is y
an 999 element wide array of 80 character long strings?
If so, how can I define this properly in Fortran 90, without the common block?
I will first say that the code you have is "proper" Fortran 90, but I agree with wanting to move away from common blocks.
There is, essentially, nothing specific to the character nature of the declaration. Whenever
is used there are two parts to the declaration of A, as well as the common association: the type and the dimension. Ignoring the association, declaration of the dimension in the
common
statement is allowed and the above is likeThis is in turn the same as
Coming to the specific example, the type is a character of length 80. Your non-common declaration would simply be
Indeed, then,
y
is a rank-1 array of size 999 of length-80 characters.y(10)
is a scalar length-80 character (the 10th element of the arrayy
).x(10)
isn't correct syntax, as the(10)
is array indexing, andx
is a scalar. For substrings a different indexing is required.x(10:10)
is the 10th character of the character variablex
;y(10)(10:10)
is the 10th character of the 10th element of the character arrayy
.