Search code examples
annotationsfortranintel-fortran

Illegal character in statement label field - when compiling .f extension


I tried to compile .f files using ifort.

I got following errors:

/.../wreqvr.f(2): error #5149: Illegal character in statement label field [h] This file is part of the GNU C Library. ----^

From the following suggestion: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/293662 -> says that changing the extension .f to .f90 works.

Is there any other solution? (I don't want to change the extension because the code is managed by git...)

I used the same ifort version for my old machine which works well without error.

I don't understand why this error comes out.

The only difference between my old machine and new machine is the centos version (old 6, new 7)

Does the gcc version matter regarding this error?


I added part of the code and error msg. here: coord.f file

/* 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 or $ 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.  */
---------------^

Solution

  • If the files are the original files you are compiling then you should delete the C style comments.

    They begin with /* and end with */.

    These blocks are not legal Fortran. C preprocessor discards them, but even if you enable pre-processing by ifort -fpp they will not be discarded. Only the C pre-processor discards them.

    See also How do I compile this Fortran code with new 2017 ifort? for a similar problem.

    It is almost certain that someone created those files by using the C preprocessor before. And that is wrong. Don't use the C preprocessor on its own for Fortran source files.

    And don't use gcc to preprocess Fortran sources, it is a C preprocessor and it uses the C preprocessor in a wrong mode. You can use the preprocessor through Fortran compilers (gfortran -cpp or ifort -fpp - be careful cpp and fpp slightly differ), but don't use the C preprocessor directly and don't use C compilers.