This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gfortran patch for PR 19071 incorrect output of complex withsingle edit descriptor


we were printing out a complex number like this:

write(74,'(1P,E13.5)'),a

all on one line when it should be printed on two lines.  there is
only one REAL edit descriptor, the format has to be re-scanned to
print the second half of the complex number.


the check was only being done at the start of formatted output,
which works great with scalar variables, but not for complex which
is considered 2 consecutive REAL's in this routine.

moved the check inside the for loop so it is considered after the
first REAL is printed.


No additional failures on i686/linux/gnu.  No change to the NIST
F77 test suite either (darn !!!, i was hoping for a freebie).


The below test suite file fails before and passes after applying this
patch.



--bud


2004-12-23  Bud Davis  <bdavis9659@comcast.net>

	* io/tranfer.c (formatted_transfer): moved check for 
	format reversion inside the processing loop.


! pr 19071
! test case provided by
!   Thomas.Koenig@online.de
!
      program cio
      complex a
      real r1,r2
      a = cmplx(1.0, 2.0)
      open(unit=74,status='scratch')
      write(74,'(1P,E13.5)'),a
      rewind(74)
!  can read the complex in as two reals, one on each line
      read(74,'(E13.5)')r1,r2
      if (r1.ne.1.0 .and. r2.ne.2.0) call abort
      end



Index: gcc/libgfortran/io/transfer.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.22
diff -c -3 -p -r1.22 transfer.c
*** gcc/libgfortran/io/transfer.c	14 Dec 2004 16:34:08 -0000	1.22
--- gcc/libgfortran/io/transfer.c	23 Dec 2004 23:58:52 -0000
*************** formatted_transfer (bt type, void *p, in
*** 425,440 ****
    if (type == BT_COMPLEX)
      type = BT_REAL;
  
-   /* If reversion has occurred and there is another real data item,
-      then we have to move to the next record.  */
- 
-   if (g.reversion_flag && n > 0)
-     {
-       g.reversion_flag = 0;
-       next_record (0);
-     }
    for (;;)
      {
        consume_data_flag = 1 ;
        if (ioparm.library_return != LIBRARY_OK)
  	break;
--- 425,440 ----
    if (type == BT_COMPLEX)
      type = BT_REAL;
  
    for (;;)
      {
+       /* If reversion has occurred and there is another real data
item,
+          then we have to move to the next record.  */
+       if (g.reversion_flag && n > 0)
+         {
+           g.reversion_flag = 0;
+           next_record (0);
+         }
+ 
        consume_data_flag = 1 ;
        if (ioparm.library_return != LIBRARY_OK)
  	break;







Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]