public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/109394] New: list-directed read of character from complex number
@ 2023-04-03 18:13 snavece at hotmail dot com
  2023-04-03 19:06 ` [Bug fortran/109394] " kargl at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: snavece at hotmail dot com @ 2023-04-03 18:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109394

            Bug ID: 109394
           Summary: list-directed read of character from complex number
           Product: gcc
           Version: og11 (devel/omp/gcc-11)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: snavece at hotmail dot com
  Target Milestone: ---

My question is how should a complex number be parsed when using a list-directed
read to a string?  Currently complex numbers are parsed to two tokens in
gfortran. An alternative is to parse complex numbers to one token.  See
examples below.  I recognize that it is a judgment call. I would argue the
second technique makes the handling of complex numbers easier, although it may
raise a number of unintended consequences that I have not considered.
Using the following file, test.f:
      PROGRAM MAIN
C
      IMPLICIT NONE
C
      INTEGER, PARAMETER :: MXTOKS = 10
      INTEGER IERR
C
      CHARACTER * 20 TOKENS(MXTOKS)
      CHARACTER * 132 LINE
C
      LINE = '''A B C'' "A B C" (1.0, 2.0) 1 2 3 1.0 2.0 3.0'
      print *, 'Line: /', TRIM(LINE), '/'
      READ (LINE, *, IOSTAT=IERR) TOKENS
      print *, TOKENS
      print *, 'Ierr:', IERR
      STOP
      END
and the commands in a Cygwin mksh shell:
$ gfortarn -o test.exe test.f
$ ./test.exe
The result is:
 Line: /'A B C' "A B C" (1.0, 2.0) 1 2 3 1.0 2.0 3.0/
 A B C               A B C               (1.0                2.0)              
 1                   2                   3                   1.0               
 2.0                 3.0
 Ierr:           0

An alternate parsing could be:
 'A B C'             "A B C"             (1.0, 2.0)          1                 
 2                   3                   1.0                 2.0               
 3.0
 Ierr:          -1
The IERR = -1 indicating that end of line was encountered before reading 10
tokens.

My environment is mksh in a Cygwin 64 delivery running on Windows 10 Version
12H2 (OS Build 19044.2728)
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/11/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-11.3.0/configure
--srcdir=/mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-11.3.0 --prefix=/usr
--exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc
--docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C
--build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin
--without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib
--with-gcc-major-version-only --enable-shared --enable-shared-libgcc
--enable-static --enable-version-specific-runtime-libs --enable-bootstrap
--enable-__cxa_atexit --with-dwarf2 --with-tune=generic
--enable-languages=c,c++,fortran,lto,objc,obj-c++,jit --enable-graphite
--enable-threads=posix --enable-libatomic --enable-libgomp --enable-libquadmath
--enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers
--with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl
--without-libiconv-prefix --without-libintl-prefix --with-system-zlib
--enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible
--enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (GCC)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/109394] list-directed read of character from complex number
  2023-04-03 18:13 [Bug fortran/109394] New: list-directed read of character from complex number snavece at hotmail dot com
@ 2023-04-03 19:06 ` kargl at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-04-03 19:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109394

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #1 from kargl at gcc dot gnu.org ---
Please see "13.10 List-directed formatting" in the Fortran standard.

For the program you posted, a comma, blank, and semicolon are
value separators.  If you look at each token with 

   do i = 1, mxtoks
      print *, trim(tokens(i))
   end do

you 

 a b c
 a b c
 (1.0
 2.0)
 1
 2
 3
 1.0
 2.0
 3.0

where the comma is the end of the character string "(1.0"

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-03 19:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03 18:13 [Bug fortran/109394] New: list-directed read of character from complex number snavece at hotmail dot com
2023-04-03 19:06 ` [Bug fortran/109394] " kargl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).