Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29430 Discussions

Allocatable character strings in namelists?

OP1
New Contributor III
757 Views

Assume I have a text file called 'text.txt' which contains:

&A
S = 'Hi!'
/

The following code produces different output depending on which line is commented out for the definition of S. I thought allocatable characters were accepted in namelist groups?

PROGRAM P
IMPLICIT NONE
!CHARACTER(LEN=50) :: S
CHARACTER(LEN=:),ALLOCATABLE :: S
NAMELIST /A/ S
OPEN(UNIT=10,FILE='test.txt')
READ(10,NML=A)
WRITE(*,*) S
END PROGRAM P

 

0 Kudos
4 Replies
IanH
Honored Contributor III
757 Views

The things in a namelist group need to be allocated ahead of executing any read or write statements for that namelist group.
 

0 Kudos
Steven_L_Intel1
Employee
757 Views

Yes, indeed. The standard theoretically could have specified automatic (re)allocation for allocatable, deferred-length character variables in a list-directed or NAMELIST READ, but didn't. 

0 Kudos
OP1
New Contributor III
757 Views

Thanks for these answers. Too bad indeed these small features didn't make it to the standard - they could have been convenient.

0 Kudos
Steven_L_Intel1
Employee
757 Views

The topic has come up in the standards committee, but didn't generate much enthusiasm.

0 Kudos
Reply