问题
I am working on some legacy code that relies heavily on common blocks which are initialized with BLOCK DATA
similar to the code below.
BLOCK DATA filename
PARAMETER (size=100)
CHARACTER*8 somearray(size)
COMMON /block1/ somearray
DATA(somearray(i), i=100)/
*'string1', 'string2', ... , 'string100'/
END
At some point in the program a subroutine uses this common block as shown in the code below.
SUBROUTINE SUB(array)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
CHARACTER*8 array(*), somearray(100)
COMMON /block1/ somearray
DO 100 I=1, iterations
array(I)=somearray(I)
...
100 CONTINUE
END
Here somearray
has a couple of spaces in each string instead of the actual values specified in the BLOCK DATA
. What could be the cause of this?
Note: the code is compiled with Intel Fortran
回答1:
I found a solution to this issue by adding a SAVE
statement before the END
statement of any BLOCK DATA
as seen below.
BLOCK DATA filename
PARAMETER (size=100)
CHARACTER*8 somearray(size)
COMMON /block1/ somearray
DATA(somearray(i), i=100)/
*'string1', 'string2', ... , 'string100'/
SAVE
END
来源:https://stackoverflow.com/questions/38142569/fortran-block-data-seems-to-not-be-working