[Bug fortran/45710] WRITE of NAMELIST group to internal file contains newline characters

urbanjost at comcast dot net gcc-bugzilla@gcc.gnu.org
Mon Sep 20 09:57:00 GMT 2010



------- Comment #6 from urbanjost at comcast dot net  2010-09-20 09:57 -------
Subject: Re:  WRITE of NAMELIST group to internal file contains newline
characters

That is the confusing part. The output only looks like it is multiple lines 
because a newline is placed between each name=value pair.
The example is using an array; but the array is filled with an @ character 
and line numbers first so when it is printed you can see that
only one line of the array was used by the WRITE.  The definition for 
NAMELIST output says an arbitrary number of spaces and records
can be used, but I don't think it intended newlines to be allowed in the 
output; unless the output is of type STREAM, perhaps.

program oneline
real :: a=1,b=2,c=3,d=4
NAMELIST /NL1/ a,b,c
parameter(ilines=5)
character(len=80) :: out(ilines)

! fill array OUT with @
do i=1,len(out)
   out(:)(i:i)='@'
enddo

! put line number at beginning
do j=1,ilines
   write(out(j)(1:5),'(i3.3,1x)')j
enddo
write(*,*)'BEFORE:'
write(*,'(a)')out

WRITE(out,NL1)
write(*,*)'AFTER:'
write(*,'(a)')out

end program oneline
! BEFORE:
!001 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!002 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!003 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!004 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!005 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
! AFTER:
!&NL1
! A= 1.00000000    ,
! B=  2.0000000    ,
! C=  3.0000000    ,  /
!
!002 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!003 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!004 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
!005 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@



----- Original Message ----- 
From: "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: <urbanjost@comcast.net>
Sent: Monday, September 20, 2010 3:56 AM
Subject: [Bug fortran/45710] WRITE of NAMELIST group to internal file 
contains newline characters


>
>
> ------- Comment #5 from burnus at gcc dot gnu dot org  2010-09-20 
> 07:56 -------
> (In reply to comment #0)
>> In gfortran a WRITE of a NAMELIST group into an internal file appears to 
>> all
>> go into the first record.
> [...]
>> only major complaint with that is that I first guessed that your output
>> into an internal file would be formatted just like it was to stdout.
>>
>> But gfortran output to stdout or to a file writes in a very different 
>> format,
>> putting one keyword=value per line (which I like, but is also not 
>> required by
>> any standard requirement I can find).
>
> If you use a scalar string, there is only a single record - thus gfortran 
> has
> no choice then using only one record. You could instead use a character 
> array,
> e.g.
>
> character(30) :: str(6)
> integer :: a, b, c, d
> namelist /nml/ a,b,c,d
> str = ''
> write(str,nml=nml)
> write(*,'(a)')str
> end
>
> From the F2008 standard:
> "If the file is a scalar character variable, it consists of a single 
> record
> whose length is the same as the length of the scalar character variable. 
> If the
> file is a character array, it is treated as a sequence of character array
> elements. Each array element, if any, is a record of the file."
>
>
> (In reply to comment #4)
>> This issue, line ending for namelist to character arrays, has come up 
>> before.
>> I don't remember the outcome of that previous discussion.  I will 
>> research a
>> little.
>
> Well, in gfortran character arrays seem to do what urbanjost would like to
> have: A new record for each namelist element.
>
>
> -- 
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45710
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
> 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45710



More information about the Gcc-bugs mailing list