Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

User-defined list-directed input

43 views
Skip to first unread message

Thomas Koenig

unread,
Apr 23, 2022, 4:23:22 PM4/23/22
to
I'm not quite sure how user-defined I/O and list-directed input
go together.

For example, can I just write

module x
implicit none
type foo
real :: r
end type foo
interface read(formatted)
module procedure read_formatted
end interface read(formatted)
contains
subroutine read_formatted (dtv, unit, iotype, vlist, iostat, iomsg)
class (foo), intent(inout) :: dtv
integer, intent(in) :: unit
character (len=*), intent(in) :: iotype
integer, intent(in) :: vlist(:)
integer, intent(out) :: iostat
character (len=*), intent(inout) :: iomsg
read (unit,*,iostat=iostat,iomsg=iomsg) dtv%r
end subroutine read_formatted
end module x

program main
use x
implicit none
type(foo) :: a, b
read (*,*) a, b
print *,a,b
end program main

feed "2*1" to this program, and expect it to work and print
some semblance of " 1.000000 1.000000"? There seems to be nothing
prohibiting this in the standard.

Or assume that I want to read a string of arbitrary length (to read
in the numbers in the example above) using list-directed I/O, for
later conversion with internal I/O, reallocating as I go along in
case the user types 1.000000000000000000000000000000000000000e000.
I cannot use the usual method of using ADVANCE="NO", because that
is ignored in a child I/O statement.

I also did not find a good explanation of these finer points
anywhere.

FortranFan

unread,
Apr 23, 2022, 6:11:09 PM4/23/22
to
On Saturday, April 23, 2022 at 4:23:22 PM UTC-4, Thomas Koenig wrote:

> ..
> feed "2*1" to this program, and expect it to work and print
> some semblance of " 1.000000 1.000000"? There seems to be nothing
> prohibiting this in the standard.

Nor supporting it in the standard. You may want to inquire at the J3 mailing list about the r*c form of list-directed input and defined IO is supposed to work with it.

You will know feeding "1,1" to that program will work and print your expected output.

>
> Or assume that I want to read a string of arbitrary length (to read
> in the numbers in the example above) using list-directed I/O, for
> later conversion with internal I/O, reallocating as I go along in
> case the user types 1.000000000000000000000000000000000000000e000.
> I cannot use the usual method of using ADVANCE="NO", because that
> is ignored in a child I/O statement.

Not sure what the question is here but child data transfer is effectively nonadvancing and the child data transfer can take advantage of it in asuitable fashion to read in the characters in some sequence, perhaps even one by one, until the delimiter(s) for list-directed input signal the end of transfer and then do the needed conversion.

>
> I also did not find a good explanation of these finer points
> anywhere.

Again ask for any clarification at the J3 mailing list.
0 new messages