FORTRAN块数据似乎不工作 [英] FORTRAN block data seems to not be working

查看:153
本文介绍了FORTRAN块数据似乎不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一些遗留代码,这些代码在很大程度上依赖于用 BLOCK DATA 初始化的类似于下面代码的公共块。

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

somearray 在每个字符串中有几个空格,而不是在 BLOCK DATA 中指定的实际值。这可能是什么原因?

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?

注意:代码使用英特尔Fortran编译

Note: the code is compiled with Intel Fortran

推荐答案

通过在任何语句的 END 语句之前添加 SAVE 语句,我找到了解决此问题的方法 BLOCK DATA 如下所示。

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

这篇关于FORTRAN块数据似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆