https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118793

            Bug ID: 118793
           Summary: request NAMELIST reports of input errors indicate
                    position of error and show line containing error
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: urbanjost at comcast dot net
  Target Milestone: ---

Currently when NAMELIST input errors occur neither the line where the
error occurred or a line and column number where the syntax error was
detected is produced. It would be very helpful if that additional
informaton was provided.

      program main
      implicit none
      character(len=80),save       :: page(5)=[character(len=80) :: &
      '&config                              ', &
      '  param1 = 10                        ', &
      '  param2 === 0.5 ! problematic line  ', &
      '  param3 = "Hello"                   ', &
      '/' ]
      integer                      :: param1 ; namelist /config/ param1
      real                         :: param2 ; namelist /config/ param2
      character(len=256)           :: param3 ; namelist /config/ param3
      character(len=256)           :: iomsg
      integer                      :: iostat, lun, i
        ! file
        
open(newunit=lun,file='_config.nml',status='unknown',action='readwrite')
         write(lun,'(a)')(trim(page(i)),i=1,size(page))
         rewind(lun)
         read(lun,nml=config,iostat=iostat,iomsg=iomsg)
         close(unit=lun,status='delete')
         if(iostat.ne.0) write(*,*)'<ERROR>FILE: '//trim(iomsg)

        ! internal file
         read(page,nml=config,iostat=iostat,iomsg=iomsg)
         if(iostat.ne.0) write(*,*)'<ERROR>INTERNAL: '//trim(iomsg)

        ! scratch file
         open(newunit=lun,status='scratch')
         write(lun,'(a)')(trim(page(i)),i=1,size(page))
         rewind(lun)
         read(lun,nml=config,iostat=iostat,iomsg=iomsg)
         close(unit=lun,status='delete')
         if(iostat.ne.0) write(*,*)'<ERROR>SCRATCH: '//trim(iomsg)

         stop merge(0,1,iostat==0)
      end program main

      > $ gfortran main.f90 && ./a.out
      > <ERROR>FILE: namelist read: misplaced = sign
      > <ERROR>INTERNAL: namelist read: misplaced = sign
      > <ERROR>SCRATCH: namelist read: misplaced = sign

A sampling of other compilers produces the position of the error in the
input

    $ ifx main.f90 && ./a.out
    > <ERROR>FILE: READ: syntax error in NAMELIST input, unit -129, file
/home/user/_config.nml
    > , line 3, position 12

    $ flang-new main.f90 && ./a.out
    > <ERROR>FILE: READ: Bad real input data at column 12 of record 3

Ideally, something like:

    <ERROR>FILE: namelist read: misplaced = sign at line 3, column 12 in file
/home/user/_config.nml
    <ERROR>INTERNAL: namelist read: misplaced = sign at line 3, column 12 in
internal file "page"
    <ERROR>SCRATCH: namelist read: misplaced = sign at line 3, column 12 in
unit -129

and showing the line with the error

      >  param2 === 0.5 ! problematic line
      >           ^
      >           misplaced = sign

would make locating input errors much easier

Reply via email to