语句标签字段中的非法字符 - 编译.f扩展名

时间:2017-03-27 06:05:39

标签: annotations fortran intel-fortran

我尝试使用ifort编译 .f 文件。

我遇到以下错误:

/.../ wreqvr.f(2):错误#5149:语句标签字段中的非法字符[h]    该文件是GNU C库的一部分。 ---- ^

从以下建议: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/293662 - >说将.f扩展名更改为.f90。

还有其他解决方案吗? (我不想更改扩展名,因为代码是由git管理的......)

我为旧机器使用了相同的ifort版本,运行良好且无错误。

我不明白为什么会出现这个错误。

我的旧机器与新机器之间的唯一区别是centos版本(旧版本6,新版本7)

gcc版本是否与此错误有关?

我添加了部分代码和错误信息。这里:coord.f文件

/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */


/* This header is separate from features.h so that the compiler can
   include it implicitly at the start of every compilation.  It must
   not itself include <features.h> or any other header that includes
   <features.h> because the implicit include comes before any feature
   test macros that may be defined in a source file before it first
   explicitly includes a system header.  GCC knows the name of this
   header in order to preinclude it.  */

/* We do support the IEC 559 math functionality, real and complex.  */

/* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /
   Unicode 6.0.  */

/* We do not support C11 <threads.h>.  */

      subroutine coord(vx,vy,n,d,x,y)

c  version : 21.07.2000 16:18
c=======================================================================
      implicit none
c*** Calculate the x and y coordinates of a point located on a curve v
c*** at a distance d from the origin of the curve

*  arguments
      integer n
      real*8 vx(n),vy(n),d,x,y

*  variables locales
      integer i
      real*8 dist,distot,eps
      parameter (eps=1.e-06)

*  procedures
      intrinsic sqrt

c========================
c.. n   : number of points in the curve
c.. vx,vy: coordinates of the points in the curve
c.. d   : required distance along the curve
c.. x,y : coordinates of the found point
c.. dist: distance between 2 consecutive points on the curve
c.. distot: total distance covered
c========================

*..Initialisation.

      distot = 0.0

*..Loop over the curve segments

      do i=1, n-1 !{

         dist = sqrt((vx(i+1)-vx(i))**2 + (vy(i+1)-vy(i))**2)
         distot = distot + dist

*..Check whether the distance d is passed

         if (distot .ge. d) then !{
            x = vx(i+1) - ((distot-d)/dist)*(vx(i+1)-vx(i))
            y = vy(i+1) - ((distot-d)/dist)*(vy(i+1)-vy(i))

            return

         end if !}

      end do  !}
c*** Check whether the required distance is equal - within tolerance -
c*** to the total curve length

      if (abs(distot - d) .lt. eps) then !{
         x = vx(n)
         y = vy(n)

         return

      end if !}

*..Error: required distance greater than the total curve length.

      print *, 'coord: required distance greater than the total length'
      print*,'distot=',distot
      print*,'d=',d
      call pltend
      stop  'Check the target specification'

      end

$ ifort coord.f

coord.f(1): error #5149: Illegal character in statement label field  [/]
/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
^
coord.f(1): error #5149: Illegal character in statement label field  [*]
/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
-^
coord.f(1): error #5149: Illegal character in statement label field  [C]
/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
---^
coord.f(1): error #5149: Illegal character in statement label field  [o]
/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
----^
coord.f(1): error #5118: First statement in file must not be continued
/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
-----^
coord.f(2): error #5149: Illegal character in statement label field  [T]
   This file is part of the GNU C Library.
---^
coord.f(2): error #5149: Illegal character in statement label field  [h]
   This file is part of the GNU C Library.
----^
coord.f(4): error #5149: Illegal character in statement label field  [T]
   The GNU C Library is free software; you can redistribute it and/or
---^
coord.f(4): error #5149: Illegal character in statement label field  [h]
   The GNU C Library is free software; you can redistribute it and/or

$ ifort -free coord.f 要么 $ ifort coord.f90

coord.f(1): error #5082: Syntax error, found '/' when expecting one of: <LABEL> <END-OF-STATEMENT> ; BLOCK BLOCKDATA PROGRAM MODULE TYPE BYTE CHARACTER ...
/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
^
coord.f(16): error #5145: Invalid blank/tab
   <http://www.gnu.org/licenses/>.  */
----------------------------------^
coord.f(20): error #5145: Invalid blank/tab
   include it implicitly at the start of every compilation.  It must
-----------------------------------------------------------^
coord.f(29): error #5143: Missing mandatory separating blank
/* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /
--------------------------------^
coord.f(30): error #5145: Invalid blank/tab
   Unicode 6.0.  */
---------------^

2 个答案:

答案 0 :(得分:0)

如果文件是您正在编译的原始文件,则应删除C样式注释。

/*开头,以*/结尾。

这些块不是合法的Fortran。 C预处理器会丢弃它们,但即使您通过ifort -fpp启用预处理,它们也不会被丢弃。只有C预处理器丢弃它们。

有关类似问题,另请参阅How do I compile this Fortran code with new 2017 ifort?

几乎可以肯定,之前有人使用C预处理器创建了这些文件。那是错的。不要将自己的C预处理器用于Fortran源文件。

并且不使用gcc预处理Fortran源,它是一个C预处理器,它以错误的模式使用C预处理器。你可以通过Fortran编译器使用预处理器(gfortran -cppifort -fpp - 小心cpp和fpp略有不同),但不要直接使用C预处理器而不要使用C编译器

答案 1 :(得分:0)

即使已经回答了这个问题,我也遇到了同样的问题。 有助于解决的问题是: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/293662(即使我在linux上)

.f90和ifort而不是f77的组合使用很有帮助。

如果构建系统依赖于设置FC,F77等(以及MPIF77),请确保将它们相应地设置为ifort(和mpiifort)。 如果对于连续任务,不同的子步骤默认使用不同的工具,则通常会遇到问题,因此,请根据您的构建系统明确地控制它们。