From: Bart Vandewoestyne on
On 2009-10-07, The Star King <jfb(a)npl.co.uk> wrote:
>
> I suggest
>
> character(30) :: data(10)
> integer i
>
> read (pointsource_string,*) (data(i),i=1,10)

Hmm... will this also work if the number of numbers after 'pulse' is
variable?

Regards,
Bart

--
"Share what you know. Learn what you don't."
From: Bart Vandewoestyne on
On 2009-10-07, Richard Maine <nospam(a)see.signature> wrote:
>
> There isn't anything "magic". Just search for non-whitspace and then
> search for whitespace. Loop the appropriate number of times. See the
> index, scan, and verify intrinsics.

OK. Thanks for the suggestion/input. So i think i need a
subroutine that allows me to do stuff like the following:

call split(inputstring, 7, outputstring1, outputstring2)

Using this call, i would be splitting inputstring at the 7th
whitespace-area between non-whitespace characters/words. The
first part would end up in outputstring1, while the second
part would end up in outputstring 2.

Hmpf... looks like i'll have to do some 'annoying' programming
here... :-( Unless somebody really sees a clever, short and
elegant solution?

Regards,
Bart

--
"Share what you know. Learn what you don't."
From: The Star King on
On Oct 7, 5:18 pm, Bart Vandewoestyne
<MyFirstName.MyLastN...(a)telenet.be> wrote:
> On 2009-10-07, Richard Maine <nos...(a)see.signature> wrote:
>
>
>
> > There isn't anything "magic". Just search for non-whitspace and then
> > search for whitespace. Loop the appropriate number of times. See the
> > index, scan, and verify intrinsics.
>
> OK.  Thanks for the suggestion/input.  So i think i need a
> subroutine that allows me to do stuff like the following:
>
>   call split(inputstring, 7, outputstring1, outputstring2)
>
> Using this call, i would be splitting inputstring at the 7th
> whitespace-area between non-whitespace characters/words.  The
> first part would end up in outputstring1, while the second
> part would end up in outputstring 2.
>
> Hmpf... looks like i'll have to do some 'annoying' programming
> here... :-(  Unless somebody really sees a clever, short and
> elegant solution?
>
> Regards,
> Bart
>
> --
>         "Share what you know.  Learn what you don't."

How about something like this (note I have "proved it correct not
tried it" etc :-)

i=1
do
grabbed=grab(pointsource_string,data(i))
if (grabbed.eq.0) exit
i=i+1
enddo

function grab(string,res)

integer grab
character(*) string
character(len(string)) res

string=adjustl(string)
do i=1,len(string)-1
if (string(i:i).eq.' '.and.string(i+1:i+1).ne.' ') then
res=string(:i)
string=string(i+1:)
grab=1
return
endif

grab=0

end
From: The Star King on
On Oct 7, 5:35 pm, The Star King <j...(a)npl.co.uk> wrote:
> On Oct 7, 5:18 pm, Bart Vandewoestyne
>
>
>
>
>
> <MyFirstName.MyLastN...(a)telenet.be> wrote:
> > On 2009-10-07, Richard Maine <nos...(a)see.signature> wrote:
>
> > > There isn't anything "magic". Just search for non-whitspace and then
> > > search for whitespace. Loop the appropriate number of times. See the
> > > index, scan, and verify intrinsics.
>
> > OK.  Thanks for the suggestion/input.  So i think i need a
> > subroutine that allows me to do stuff like the following:
>
> >   call split(inputstring, 7, outputstring1, outputstring2)
>
> > Using this call, i would be splitting inputstring at the 7th
> > whitespace-area between non-whitespace characters/words.  The
> > first part would end up in outputstring1, while the second
> > part would end up in outputstring 2.
>
> > Hmpf... looks like i'll have to do some 'annoying' programming
> > here... :-(  Unless somebody really sees a clever, short and
> > elegant solution?
>
> > Regards,
> > Bart
>
> > --
> >         "Share what you know.  Learn what you don't."
>
> How about something like this (note I have "proved it correct not
> tried it" etc :-)
>
> i=1
> do
>   grabbed=grab(pointsource_string,data(i))
>   if (grabbed.eq.0) exit
>   i=i+1
> enddo
>
> function grab(string,res)
>
> integer grab
> character(*) string
> character(len(string)) res
>
> string=adjustl(string)
> do i=1,len(string)-1
> if (string(i:i).eq.' '.and.string(i+1:i+1).ne.' ') then
>   res=string(:i)
>   string=string(i+1:)
>   grab=1
>   return
> endif
>
> grab=0
>
> end- Hide quoted text -
>
> - Show quoted text -

Forgot the enddo!

function grab(string,res)

integer grab
character(*) string
character(len(string)) res

string=adjustl(string)
do i=1,len(string)-1
if (string(i:i).eq.' '.and.string(i+1:i+1).ne.' ') then
res=string(:i)
string=string(i+1:)
grab=1
return
endif
enddo

grab=0


end function grab
From: Richard Maine on
The Star King <jfb(a)npl.co.uk> wrote:

> > i=1
> > do
> > grabbed=grab(pointsource_string,data(i))
> > if (grabbed.eq.0) exit
> > i=i+1
> > enddo
> >
....
> Forgot the enddo!
>
> function grab(string,res)
>
> integer grab
> character(*) string
> character(len(string)) res
>
> string=adjustl(string)
> do i=1,len(string)-1
> if (string(i:i).eq.' '.and.string(i+1:i+1).ne.' ') then
> res=string(:i)
> string=string(i+1:)
> grab=1
> return
> endif
> enddo
>
> grab=0
>
>
> end function grab

Not a style I favor in that it not only relies heavily on function side
efects, but one of those side effects is to modify the "input" string.
I'll not try to claim it is objectively bad style - just different from
what I'd use. Looks a lot like C written with Fortran syntax (complete
with using integer vaues 0 and 1 in place of logicals). But different
stroke, etc.

Somewhat more substantial is that this looks prone to exceeding array
bounds (for the array data) without checking. (speaking of C-like :-). I
am particularly careful about things like that when they can be
triggered by oddities in input data because it is easy for that to slip
by testing and show up only "in the field." If you have a fixed-size
array that you are storing results in, then one might as well use that
information, as in

do i = 1 , size(data)
grabbed=grab(pointsource_string,data(i))
if (grabbed.eq.0) exit
end do
if (i>size(data)) call error_halt('Some message')

Or do whatever else you want for the error condition (including the
possibility of ignoring it if that seems appropriate, for example if
extra junk at the end of the string is ok).

But most important, if this is supposed to be a general utility routine,
is that it fails in a simple case. Always look for boundary conditions.
In the particular case of the OP's sample, it wouldn't come up because
the OP said he was looking to split after 7 fields I think it was. But
if this is supposed to be a general utility routine, one might expect it
to work for boundary cases such as 1 field. If the input string consists
of a single field with no blanks, this function doesn't return that
field. I'd consider that a bug.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain