2
votes

Here's test code:

program testcase
    implicit none

    integer :: ios, lu
    type derived
        integer :: a
    end type derived
    type (derived) :: d

    namelist /test/ d

    lu = 3
    open (lu, file = 'test.dat', status='old', iostat=ios)
    read (lu, nml = test, iostat=ios)
    if (ios /= 0) then
        write (*, *) 'error!'
    else
        write (*, *) 'good!', d % a
    endif
end program testcase

This program reads an input file test.dat which contains a namelist for test whose type is a derived type derived.

When I try next content for test.dat it works fine(it prints good! 7):

&test
    d%a = 7
/

However, with next content, I get an error:

&test
    d % a = 7
/

Equal sign must follow namelist object name d

What's different is the whitespaces around % sign for component access in derived type.

I've tested with GNU Fortran(gfortran) 5.3.0. I also heard from my colleague that same problem occurred with latest Intel Fortran compiler. He also insisted that the old version of Intel Fortran compiler worked fine with both cases.

Is this behavior is normal? That is, does the standard forbid whitespaces around % in namelist input file, while whitespaces around % are allowed in source code?

Or, is this a bug of compiler or implementation of standard library?

1
I can confirm that gfortran v4.4.7 gives an error if there are spaces around the % character, whereas intel fortran compiler (v12.1.3 and v16.0.3) correctly read the namelist. - chw21
I've caught the error message, it's code 5010, and message is "Equal sign must follow namelist object name d" - chw21
@chw21 Thank you. Your information helped me find some pages which state this case. - xylosper

1 Answers

1
votes

Finally, I found some references which mention this problem.

From http://technion.ac.il/doc/intel/compiler_f/main_for/lref_for/source_files/pghnminp.htm ,

&group-name object = value [, object = value] .../

...

object

Is the name (or subobject designator) of an entity defined in the NAMELIST declaration of the group name. The object name must not contain embedded blanks except within the parentheses of a subscript or substring specifier. Each object must be contained in a single record.

Another one from http://docs.cray.com/books/S-3693-51/html-S-3693-51/i5lylchri.html ,

2.13.1.1. Names in Name-value Pairs

...

  • A name in an input record must not contain embedded blanks. A name in the name-value pair can be preceded or followed by one or more blanks.

So, apparently, it seems that whitespaces in name are never allowed.