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

2010-09-21 Thread urbanjost at comcast dot net


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

Per some discussions today, there were apparently different versions on some 
of the nodes I was using, ranging from 4.3.4 to 4.6.0 (they were all 
supposed to be
identical); so I can't be sure till I get back.

But I installed Cygwin on an MSWindows laptop and upgraded to gfortran 4.6.0 
(per the gfortran -v switch; it comes with gfortran 4.3.4)
and I am getting what you show, which is much better, I looked thru all the 
2009 and 2010 fixes and missed seeing any change like this.

Maybe a few tweeks are in order? Looking at the f2008 draft standard,
 from 10.11.4.3 line 5, taken literally the  should be in column 2 instead 
of 1;
and the records written to in the OUT array should be blank filled to the
end per 9.4 line 2 bullet (d)?  That would be more in line with how 
list-directed
output works (column 1 always being clear) and would prevent garbage from
being in the lines written to if OUT is not initialized to all blanks; so I 
think I'm
reading
(interpreting?) the sections correctly.

From the draft:

  10.11.4.3Namelist output records

1 If two or more successive values for the same namelist group item in
  an output record produced have identical values, the processor has
  the option of producing a repeated constant of the form r *c instead
  of the sequence of identical values.

2 The name of each namelist group object list item is placed in the
  output record followed by an equals and a list of values of the namelist
  group object list item.

3 An ampersand character followed immediately by a namelistgroupname
  will be produced by namelist formatting at the start of the first
  output record to indicate which particular group of data objects is
  being output. A slash is produced by namelist formatting to indicate
  the end of the namelist formatting.

4 A null value is not produced by namelist formatting.

5 Except for new records created by explicit formatting within a defined
  output procedure or by continuation of delimited character sequences,
  each output record begins with a blank character.

   9.4  Internal files

1 Internal files provide a means of transferring and converting data
  from internal storage to internal storage.

2 An internal file is a record file with the following properties.

   (a)· The file is a variable of default, ASCII, or ISO 10646 character
 that is not an array section with a vector subscript.

   (b)· A record of an internal file is a scalar character variable.

   (c)· 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. The ordering of the records of the file is
 the same as the ordering of the array elements in the array (6.5.3.2)
 or the array section (6.5.3.3). Every record of the file has the
 same length, which is the length of an array element in the array.

  (d)· A record of the internal file becomes defined by writing the
 record. If the number of characters written in a record is less
 than the length of the record, the remaining portion of the record
 is filled with blanks. The number of characters to be written shall
 not exceed the length of the record.

  (e)· A record may be read only if the record is defined.

   (f)· A record of an internal file may become defined (or undefined)
 by means other than an output statement.  For example, the character
 variable may become defined by a character assignment statement.

   (g)· An internal file is always positioned at the beginning of the
 first record prior to data transfer, except for child data transfer
 statements (9.6.4.7). This record becomes the current record.

   (h)· The initial value of a connection mode (9.5.2) is the value that
 would be implied by an initial OPEN statement without the
 corresponding keyword.

   (i)· Reading and writing records shall be accomplished only by sequential
 access formatted input/output statements.

   (j)· An internal file shall not be specified as the unit in a file
 connection statement or a file positioning statement.


- Original Message - 
From: jvdelisle at gcc dot gnu dot org gcc-bugzi...@gcc.gnu.org
To: urbanj...@comcast.net
Sent: Monday, September 20, 2010 11:20 PM
Subject: [Bug fortran/45710] WRITE of NAMELIST group to internal file 
contains newline characters




 --- Comment #7 from jvdelisle at gcc dot gnu dot org  2010-09-21 
 03:20 ---
 With current trunk, gfortran 4.6, I get:

 BEFORE:
 001  @@@
 002  @@@
 003

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

2010-09-20 Thread burnus at gcc dot gnu dot org


--- 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



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

2010-09-20 Thread urbanjost at comcast dot net


--- 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.,
! B=  2.000,
! C=  3.000,  /
!
!002 
@@@
!003 
@@@
!004 
@@@
!005 
@@@



- Original Message - 
From: burnus at gcc dot gnu dot org gcc-bugzi...@gcc.gnu.org
To: urbanj...@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



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

2010-09-20 Thread jvdelisle at gcc dot gnu dot org


--- Comment #7 from jvdelisle at gcc dot gnu dot org  2010-09-21 03:20 
---
With current trunk, gfortran 4.6, I get:

 BEFORE:
001  @@@
002  @@@
003  @@@
004  @@@
005  @@@
 AFTER:
NL1 @@@
 A=  1.000,@
 B=  2.000,@
 C=  3.000,@
 /  

I thought I remembered fixing this before. What version of gfortran are you
using? (I snipped off the ends of the lines above to fit the report.)


-- 


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



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

2010-09-18 Thread urbanjost at comcast dot net


--- Comment #2 from urbanjost at comcast dot net  2010-09-18 16:35 ---
Subject: Re:  WRITE of NAMELIST group to internal file contains newline
characters

The irony in that question is that the obscurity of the example is a direct 
result of the unexpected
behavior of write of a NAMELIST into an internal file. The original question 
I was asked was
reduced to a much simpler test case, and the question why does the 
following program start to
fail when the variable E is added to the NAMELIST group?.

PROGRAM NMIF
INTEGER :: A=1,B=2,C=3,D=4,E=5
!NAMELIST /NL1/ A,B,C,D ! works in gfortran
NAMELIST /NL1/ A,B,C,D,E   ! End of record error in gfortran
CHARACTER(LEN=80) :: OUT(10)
OUT=' '
WRITE(OUT,NL1)
WRITE(*,'(A)')OUT
END PROGRAM NMIF

The code then mutated during an e-mail-only conversion,  where
it ended up that filling OUT with an @ character and numbering the lines 
made it much clearer what
was truly an output record and what was not; and just how several people had 
become convinced that
the output from the NAMELIST output was in the form of one variable per 
line.  So what was
required to clarify an issue for a number of people ended up confusing you. 
Also note that every
compiler tried (XL, ifort, g95, gfortran)  had different results, which was 
only clear when OUT was
filled with a non-white-space character and annotated.  Looking back on it I 
see that what we
thought was a trivial example program could confuse someone not privy to the 
discussions that lead
from the above example code to what was entered in bugzilla.

So obscurity lead to obscurity.




- Original Message - 
From: kargl at gcc dot gnu dot org gcc-bugzi...@gcc.gnu.org
To: urbanj...@comcast.net
Sent: Friday, September 17, 2010 5:53 PM
Subject: [Bug fortran/45710] WRITE of NAMELIST group to internal file 
contains newline characters




 --- Comment #1 from kargl at gcc dot gnu dot org  2010-09-17 
 21:53 ---
 Could you format your bug report any more poorly?


 -- 


 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



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

2010-09-18 Thread kargl at gcc dot gnu dot org


--- Comment #3 from kargl at gcc dot gnu dot org  2010-09-18 17:11 ---
(In reply to comment #2)

 So what was
 required to clarify an issue for a number of people ended up confusing you. 
 Also note that every
 compiler tried (XL, ifort, g95, gfortran)  had different results, which was 
 only clear when OUT was
 filled with a non-white-space character and annotated.  Looking back on it I 
 see that what we
 thought was a trivial example program could confuse someone not privy to the 
 discussions that lead
 from the above example code to what was entered in bugzilla.

Please go to http://gcc.gnu.org/buzilla/show_bug.cgi?id=45710

My original comment was directed at how *extremely difficult*
it is to read your
bug report because of the poorly formatted narrative.  Long lines get wrapped
in bugzilla,
which means that the large comment in the posted code is broken
into different lines that
are no longer comments.  So one cannot simply cut-n-paste the original
code into
a program that one can easily compile to demonstrate the problem.  Oh, and
yes, you 
should have included the original simple program
because that program 
is a good candidate for the dejagnu testsuite; whereas the large code
may be
more difficult to add the dg directives and possibly a final scan
pass
of an intermediate file.

For the sarcasm impaired, the above was purposely written
with poor line breaks to hopefully demonstrate the problem.


-- 


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



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

2010-09-18 Thread jvdelisle at gcc dot gnu dot org


--- Comment #4 from jvdelisle at gcc dot gnu dot org  2010-09-18 18:18 
---
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.


-- 

jvdelisle at gcc dot gnu dot org changed:

   What|Removed |Added

 AssignedTo|unassigned at gcc dot gnu   |jvdelisle at gcc dot gnu dot
   |dot org |org
 Status|UNCONFIRMED |ASSIGNED
 Ever Confirmed|0   |1
   Last reconfirmed|-00-00 00:00:00 |2010-09-18 18:18:59
   date||


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



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

2010-09-17 Thread kargl at gcc dot gnu dot org


--- Comment #1 from kargl at gcc dot gnu dot org  2010-09-17 21:53 ---
Could you format your bug report any more poorly?


-- 


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