Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26733 Discussions

Syntax error. found END-OF-FILE when expecting one of: <LABEL> <END-OF-STATEMENT>

Jon_D_2
New Contributor I
1,648 Views

I am porting Fortran 77 to Fortran 90.   I am getting the following syntax error:

source.i(4): error #5082: Syntax error, found END-OF-FILE when expecting one of: <LABEL> <END-OF-STATEMENT> ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
        end structure
---------------------^
compilation aborted for source.i (code 1)
make: *** [contempt28] Error 1
 

Here is the code in the source.i file:

structure /arg_struct/
            integer length
            character*256 arg
end structure

There are only four lines to the source.i file.  
The rest of the code that pertains to the source.i is in the source.f file shown here:

if (iargc() .ne. arg_count) then
            print *,'usage: contempt28_tu steamtable HPGLfile PGD RXI'
      1      //' RXO HXO HXI axisfile scratchdir'
          call exit (1)
      end if

c
c  Get the arguments from the command line.
c  Note that the use of the argument array is parameterized for
c  easy changes, if not easy reading.
c
      do i=1,arg_count
          call getarg (i, args(i).arg)
          args(i).length = lnblnk (args(i).arg)
      end do

      scratch = args(arg_scratch).arg
      scratch_length = args(arg_scratch).length

c
c  Open the files.  If there's trouble, let the f77 run-time library report
c  the error.
c
      ! Open the steam table file (Use the logical name).  This was   ! jmj
      ! added to allow multiple executions.                           ! jmj
                                                                        ! jmj
      OPEN ( UNIT = 15, FILE =
      1      args(arg_steam).arg(:args(arg_steam).length),
      1      STATUS = 'OLD', READONLY, FORM = 'UNFORMATTED')         ! jmj

      open (50, file=args(arg_hpgl).arg(:args(arg_hpgl).length),
      1      status='unknown')                              !HPGL
      open (51, file=args(arg_pgd).arg(:args(arg_pgd).length),
      1      status='unknown', form='unformatted')!output for plotting program
      open (10, file=args(arg_rxi).arg(:args(arg_rxi).length),
      1      status='old', readonly)                              !DRXE1
      open (11, file=args(arg_rxo).arg(:args(arg_rxo).length),
      1      status='unknown')                              !RXO
      open (7, file=args(arg_hxo).arg(:args(arg_hxo).length),
      1      status='unknown')                              !HXO
      open (3, file=args(arg_hxi).arg(:args(arg_hxi).length),
      1      status='old', readonly)                              !HX1
      open (53, file=args(arg_axis).arg(:args(arg_axis).length),
      1      status='old', dispose='delete')                        !axis


I followed the advice of this website with no luck
https://gcc.gnu.org/onlinedocs/gcc-4.4.1/gfortran/STRUCTURE-and-RECORD.html
Here is the new source.i file based on what I read in the link above.

TYPE arg_struct
            integer length
            character*256 arg
 END TYPE
 

I am still getting the syntax error.
I modified the rest of the source code per the information I read in the link:

if (iargc() .ne. arg_count) then
            print *,'usage: contempt28_tu steamtable HPGLfile PGD RXI'
      1      //' RXO HXO HXI axisfile scratchdir'
          call exit (1)
      end if

c
c  Get the arguments from the command line.
c  Note that the use of the argument array is parameterized for
c  easy changes, if not easy reading.
c
      do i=1,arg_count
          call getarg (i, args(i)%arg)
          args(i)%length = lnblnk (args(i)%arg)
      end do

      scratch = args(arg_scratch)%arg
      scratch_length = args(arg_scratch)%length

c
c  Open the files.  If there's trouble, let the f77 run-time library report
c  the error.
c
        ! Open the steam table file (Use the logical name).  This was   ! jmj
        ! added to allow multiple executions.                           ! jmj
                                                                        ! jmj
      OPEN ( UNIT = 15, FILE =
     1 args(arg_steam)%arg(:args(arg_steam)%length),
     1 STATUS = 'OLD', READONLY, FORM = 'UNFORMATTED')                  ! jmj

      open (50, file=args(arg_hpgl)%arg(:args(arg_hpgl)%length),
     1 status='unknown')                                                !HPGL
      open (51, file=args(arg_pgd)%arg(:args(arg_pgd)%length),
     1 status='unknown', form='unformatted')!output for plotting program
      open (10, file=args(arg_rxi)%arg(:args(arg_rxi)%length),
     1 status='old', readonly)                                          !DRXE1
      open (11, file=args(arg_rxo)%arg(:args(arg_rxo)%length),
     1 status='unknown')                                                !RXO
      open (7, file=args(arg_hxo)%arg(:args(arg_hxo)%length),
     1 status='unknown')                                                !HXO
      open (3, file=args(arg_hxi)%arg(:args(arg_hxi)%length),
     1 status='old', readonly)                                          !HX1
      open (53, file=args(arg_axis)%arg(:args(arg_axis)%length),
     1 status='old', dispose='delete')                                  !axis


Thank you in advance for your time!

0 Kudos
5 Replies
Johannes_Rieke
New Contributor III
1,648 Views

Hi Jon,

In general COMMAND_ARGUMENT_COUNT() replaces iargc(), GET_COMMAND_ARGUMENT replaces getarg and len_trim replaces lnblnk in newer Fortran.

It's hard to reproduce you error. Please supply a minimum working example, that others can compile.

I made some guesses and a working example could look like this (not elegant):

program test
  implicit none
  TYPE arg_struct
    integer            :: length
    character(len=256) :: arg
  END TYPE
  
  integer                       :: i, uio
  integer                       :: arg_scratch, scratch_length
  integer, parameter            :: arg_count=10, arg_steam=1
  type(arg_struct), allocatable :: args(:)
  character(len=256)            :: scratch
 

  !I am still getting the syntax error.
  !I modified the rest of the source code per the information I read in the link:
  
  if (COMMAND_ARGUMENT_COUNT() .ne. arg_count) then
    print *,'usage: contempt28_tu steamtable HPGLfile PGD RXI' &
            //' RXO HXO HXI axisfile scratchdir'
    call exit (1)
  end if

!
!  Get the arguments from the command line.
!  Note that the use of the argument array is parameterized for
!  easy changes, if not easy reading.
!
      allocate(args(arg_count))
      do i=1,arg_count
          call GET_COMMAND_ARGUMENT (number=i, value=args(i)%arg)
          args(i)%length = len_trim(args(i)%arg)
      end do

      arg_scratch = arg_count
      scratch = args(arg_scratch)%arg
      scratch_length = args(arg_scratch)%length

!
!  Open the files.  If there's trouble, let the f77 run-time library report
!  the error.
!
        ! Open the steam table file (Use the logical name).  This was   ! jmj
        ! added to allow multiple executions.                           ! jmj
                                                                        ! jmj
      OPEN ( NEWUNIT = uio, FILE =args(arg_steam)%arg(:args(arg_steam)%length),&
             STATUS = 'OLD', READONLY, FORM = 'UNFORMATTED')                  ! jmj

     
end program

 

Lorri_M_Intel
Employee
1,648 Views

If source.i contains only the four lines shown, then it cannot be compiled on its own.

I expect that originally it was 'included' into source.f, either with the standard Fortran statement

         include "source.i"

or using non-standard, C-like preprocessing as:

#include "source.i"

 

Jon_D_2
New Contributor I
1,648 Views

The "contempt28.i (named as source.i in the example) is an include file that is used by contempt28.f.   The program is a beast, as it uses over 100 other souce codes and additional library files.  I believe someone back in the 90s made a change to this code while it was using the f77 compiler.  I'm running into problem porting this to intel fortran 90 

Sorry I was not very clear presenting the problem.   The include file just has those four lines.  I was surprised when I saw this as well.

Jon_D_2
New Contributor I
1,648 Views

To Lorri and Johannes,

I am going to remove the contempt28.i code into the contempt28.f source and see if that works.  Johannes, thank you so much for putting the code example together.  I think that will be very helpful.  I'll check back with you after I get the code updated.

Lorri,

The statement include 'contempt28_tu.i' is used in the contempt28.f code.   I am linking the code on the build.   Having just SAID that, something clicked.  I would never link an include file on a build, why am I linking this one???   I am converting all f77 makefiles, code, etc... over to  f90.   and I wrote contempt28_tu.i as a link to the .f file.   It just didn't click till now that it was originally done in error.   I think I need to stop rethink what I'm doing.  Thanks Lorri.  

Jon_D_2
New Contributor I
1,648 Views

That corrected the problem.   I am still going to use Johannes example to improve the code.  Thanks both of you!

Reply