Re: Does this string processing work for you?
David Frank wrote:
"Arjen Markus" <arjen.markus@xxxxxxxxxx> wrote in message
news:1127994635.662422.247740@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
But what happens with a loop like:
read( s, *, err=1 ) ( v(i) ,i=7,100,3 )
(By the way the final value of "i" with the Intel Fortran compiler
on Linux is 103)
Regards,
Arjen
The task is to find a EASY way to process unknown #items from file record
strings.
And that's a fine task. It can be done in a variety of ways
using standard conforming code. The problem is that you
want the standard to be modified to force a particular
way of processing a particular error. That's hard to do.
Putting in lines like "if a string ends in 'blankchar(0)'
and is being read by an implied do loop, the loop index is
incremented by one" is just too special cased to work. As
others have said, there are lots of ways to write implied
dos, and as I said earlier, there are lots of ways to make
mistakes. The standard needs to do something predictable
for every case.
If Fortran did adopt some rule about returning an index,
what would you like to happen for
read( s, *, err=1 ) ( v(i) ,i=1,5 ), (x(j), j=1,5)
what values would you like for i and j if the error
happens in the first 5 values? How do you determine
whether it did or not?
*** Hendrickson
Your bum-fuzzling artifice above is not pertinent to this task, but if you
HAVE to spread the items into the receiving array
below can do your 7,100,3 spreading
! -------------------
program process_string
character(200) :: s = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17'
integer :: v(100), n
s(len_trim(s)+1:) = ' ' // char(0)
read (s,*,err=1) (v(7+(n-1)*3),n=1,size(v))
1 write (*,'(999I3)') n, v(1:n-1)
end program
18 0 0 0 0 0 0 1 0 0 2 0 0 3 0 0 4 0
.