- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The things in a namelist group need to be allocated ahead of executing any read or write statements for that namelist group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for these answers. Too bad indeed these small features didn't make it to the standard - they could have been convenient.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The topic has come up in the standards committee, but didn't generate much enthusiasm.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page