From: Richard Maine on
David Kinniburgh <davidgkinniburgh(a)yahoo.co.uk> wrote:

> > s = 'This,is a,comma-delimited,string,with a,space'
>
> yes, I see that. I was thinking of something like
>
> s = '10 This "quoted string" that'
>
> with space delimiters.

Yeah. Doing the quoted string alone, including embedded blanks, is
trivial and my routine directly handles that case. Handling a quoted
string with possible embedded blanks, but also allowing blank
delimitters is something my routine doesn't directly do in a single
call. I agree it would be a nice addition. Turns out that I don't
regularly have need for that, and it would have added a bit of extra
complexity, so I didn't bother. Not that it is necessarily a lot of
added complexity - just enough that it wasn't worth the tradeoff for me.
You'd probably need an extra optional argument to indicate wanting that
kind of treatment (because I wouldn't necessarily want it in every
case); I didn't actually sit down and work out in detail how I'd do it.
Other people's tradeoffs might, of course, be different.

I didn't necessarily post this subroutine with the idea that it would be
perfect for everyone (though it might do fine for some), but rather to
illustrate a general kind of utility routine that I think it convenient
to have. Modify to individual taste/need.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: robin on
"Bart Vandewoestyne" <MyFirstName.MyLastName(a)telenet.be> wrote in message news:eK1zm.40266$UJ3.19997(a)newsfe13.ams2...
|I have config files with lines that look as follows:
|
| on 0.2 0.2 0.02 0.02 0.01 0.01 pulse 5.0e8 100e3
|
| The number of spaces between items is arbitrary, and the number
| formatting is also arbitrarily chosen by the user. The number of
| numbers after 'pulse' can vary.
|
| I read this as:
|
| character(len=100) :: pointsource_string
| ...
| read(unit=my_unit, fmt="(A)", iostat=ios) pointsource_string
|
| But now I want to split pointsource_string in two, namely so that
| the two resulting strings are:
|
| on 0.2 0.2 0.02 0.02 0.01 0.01 pulse
|
| and
|
| 5.0e8 100e3
|
|
| I have looked into my Fortran 95/2003 explained handbook,
| searching for a way to skip 7 'whitespace areas'... but i could
| not come up with an elegant method to split the string at the
| point where I want to split.
|
| Any suggestions on how to do this?

You can read the entire line as you suggested.
If all lines commence with the word "on", you can effectively ignore it,
beginning aby search from position 3..
If lines commence with other words, you can search for the first blank.
Then search for a letter. That will take you to the second word.
From there, search for a blank.
That will take you to the end of the second word.
From there, you can split the line into two components.
If you need to remove leading blanks from the second part,
the function ADJUSTL will do that.

There are functions for searching: SCAN and VERIFY.


From: Arno on
> You can read the entire line as you suggested.
> If all lines commence with the word "on", you can effectively ignore it,
> beginning aby search from position 3..
> If lines commence with other words, you can search for the first blank.
> Then search for a letter.  That will take you to the second word.

checking for letters can be done with IACHAR

Arno
From: robin on
<analyst41(a)hotmail.com> wrote in message news:c3b4a774-5a3e-4b22-9df5-9434c8b74577(a)s6g2000vbp.googlegroups.com...

>How about this?

> character cscr*100,onvar*2,pulsevar*5
> dimension var1(6),var2(1000)
> cscr = 'on 0.2 0.2 0.02 0.02 0.01 0.01 pulse 5.0e8 100e3'
> var2=-1

> read (cscr,*,end=100,err=100) onvar,(var1(j),j=1,6),pulsevar,(var2(j),j=1,1000)
>
> 100 continue

> print *,trim(onvar),var1,trim(pulsevar),var2(1:5)

> stop
> end

>output:

>on 0.200000003 0.200000003 1.99999996E-02 1.99999996E-02
>9.99999978E-03 9.999999
>78E-03 pulse 500000000. 100000.000 -1.00000000 -1.00000000 -1.00000000
>Program Completed
>Press Enter to Continue.

>initialize var2 to soemthing that will not occr in the input.

>This is a bit dumb, but I don't know how to capture the value of j
>when EOF,ERR or EOR occurs in the second implied do-loop. But the
>first occrrence of -1 will tell you when input data stops.

The value of j is undefined when termination of the READ occurs.


From: GaryScott on
On Oct 7, 10:26 am, Bart Vandewoestyne
<MyFirstName.MyLastN...(a)telenet.be> wrote:
> On 2009-10-07, dpb <n...(a)non.net> wrote:
>
>
>
> >> Any suggestions on how to do this?
>
> > idx = index(ps_string, 'pulse', back=.true.) + len('pulse')+1
> > left_str = ps_string(1:idx-1)
> > rite_str = ps_string(idx:len_trim(ps_string)
>
> Sorry... i forgot to mention that the text 'pulse' can also be
> something else and with a different length... so the above trick
> doesn't work for me.
>
I didn't quite understand why you could not simply add a second

if (idx .eq. 0) then
idx = index(ps_string, 'somehthingelse', back=.true.) +len
('somethingelse')+1
....

i.e. if you don't find a 'pulse' then keep checking for the alternate
key words...
> Regards,
> Bart
>
> --
>         "Share what you know.  Learn what you don't."