Re: Does this string processing work for you?
- From: "David Frank" <dave_frank@xxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 09:55:36 GMT
"Arjen Markus" <arjen.markus@xxxxxxxxxx> wrote in message
news:1127978370.237919.290330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I strongly disagree with your conclusion that a few of the compliers
> discussed
> here "get it right". For one thing, why do they invariably conclude
> _eight_
> values have been read? Clearly, there are only seven valid values, so
> in an
> ideal world, the value of n should have been 7.
>
No it shud be 8 for same reason that the standard dictates that a do loop
shall exit +1 to its do terminus count when run to completion and lots of
code depends on that behaviour, this just repeats that KNOWN behaviour
> This gets rather tricky when you start using more complex
> read-statements:
>
> read( s, *, err=1 ) v(idvector)
>
> where idvector is a vector of indices
>
> There is no way in this statement that you can figure out how many
> data were read!
>
But your statement doesnt invoke a explicit list do loop, if you want to
index the output, below shows that usage
> Another thing where this goes awry, in my opinion, is the fact that the
> string must end in space+non-digit, rather than simply a non-digit.
>
But of course a (Cstring e.g.) MUST be provided EVERY time, which costs 1
statement to setup
The result is still just 2 statements which is fastest (probably) shortest,
clearest method to process a unknown string record and thus is worth the 1
statement to ALWAYS setup.
! -------------------
program process_string
character(200) :: s = '1,2,3,4,5,6,7'
integer :: v(7), n, indx(7) = [7:1:-1] ! small size(7) used
only to demo indx
s(len_trim(s)+1:) = ' ' // char(0) ! create padded
cstring
read (s,*,err=1) (v(indx(n)),n=1,size(v))
1 write (*,'(999I3)') n, v(1:n-1) ! and voila = 8 7 6 5 4 3 2 1
end program
.
- Follow-Ups:
- Re: Does this string processing work for you?
- From: Dan Nagle
- Re: Does this string processing work for you?
- References:
- Does this string processing work for you?
- From: David Frank
- Re: Does this string processing work for you?
- From: Herman D . Knoble
- Re: Does this string processing work for you?
- From: David Frank
- Re: Does this string processing work for you?
- From: Arjen Markus
- Does this string processing work for you?
- Prev by Date: Re: compilation cascades and new Fortran features
- Next by Date: Re: Intel Fortran license?
- Previous by thread: Re: Does this string processing work for you?
- Next by thread: Re: Does this string processing work for you?
- Index(es):
Relevant Pages
|