FORTRAN block data seems to not be working

南笙酒味 提交于 2019-12-11 06:36:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!