使用DATA语句初始化数组时的fortran语法

时间:2014-10-05 06:44:11

标签: fortran

我遇到了以下无法使用gfortran编译的Fortran代码:

  CHARACTER(LEN=20) :: filename(max_xoms,2)
  DATA(filename = RESHAPE(SOURCE=(/'XobsXOM0.txt','XobsXOM1.txt','XobsXOM2.txt','XobsXOM3.txt','XobsXOM4.txt',  &
                                   'XobsXOM5.txt','XobsXOM6.txt','XobsXOM7.txt','XobsXOM8.txt','XobsXOM9.txt',  &
                                   'XobsXOS0.txt','XobsXOS1.txt','XobsXOS2.txt','XobsXOS3.txt','XobsXOS4.txt',  &
                                   'XobsXOS5.txt','XobsXOS6.txt','XobsXOS7.txt','XobsXOS8.txt','XobsXOS9.txt'/),  &
                                   SHAPE=(/max_xoms,2/)))

代码附带的makefile使用ifort。我将编译器更改为gfortran,并在编译上述内容时收到错误消息:

gfortran  -c -fbacktrace -ffree-line-length-none -Wall hype_indata.f90
hype_indata.f90:48.16:

  DATA(filename = RESHAPE(SOURCE=(/'XobsXOM0.txt','XobsXOM1.txt','XobsXOM2.txt'
                1
Error: Syntax error in DATA statement at (1)

我已尝试在=删除1,但这并不能解决问题。

任何人都可以解释我该如何解决这个问题?

由于

BTW,gfortran --version返回:

GNU Fortran (tdm64-2) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.

1 个答案:

答案 0 :(得分:1)

如果max_omsparameter(即常数,可能是一个),您可以这样做:

CHARACTER(LEN=20) :: filename(max_xoms,2) = RESHAPE(SOURCE=(/'XobsXOM0.txt','XobsXOM1.txt','XobsXOM2.txt','XobsXOM3.txt','XobsXOM4.txt',  &
                                   'XobsXOM5.txt','XobsXOM6.txt','XobsXOM7.txt','XobsXOM8.txt','XobsXOM9.txt',  &
                                   'XobsXOS0.txt','XobsXOS1.txt','XobsXOS2.txt','XobsXOS3.txt','XobsXOS4.txt',  &
                                   'XobsXOS5.txt','XobsXOS6.txt','XobsXOS7.txt','XobsXOS8.txt','XobsXOS9.txt'/),  &
                                   SHAPE=(/max_xoms,2/))

否则移动

filename = RESHAPE(SOURCE=(/'XobsXOM0.txt','XobsXOM1.txt','XobsXOM2.txt','XobsXOM3.txt','XobsXOM4.txt',  &
                                   'XobsXOM5.txt','XobsXOM6.txt','XobsXOM7.txt','XobsXOM8.txt','XobsXOM9.txt',  &
                                   'XobsXOS0.txt','XobsXOS1.txt','XobsXOS2.txt','XobsXOS3.txt','XobsXOS4.txt',  &
                                   'XobsXOS5.txt','XobsXOS6.txt','XobsXOS7.txt','XobsXOS8.txt','XobsXOS9.txt'/),  &
                                   SHAPE=(/max_xoms,2/))

到第一个可执行语句的位置。

通常,请避免使用Fortran 90及更高版本中的DATA