comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » extract numbers from string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
extract numbers from string [message #44518] Tue, 21 June 2005 13:59 Go to next message
Tobi is currently offline  Tobi
Messages: 2
Registered: June 2005
Junior Member
i have a data file with a header that has several lines, which i read
with

readf,1,firstline
readf,1,secondline
....

firstline is a string that looks like
xpixels = 1024

i am trying to convert this to a variable called nx which has the value
1024.

is there a clean and easy way to do this?

Thanks!
Re: extract numbers from string [message #44577 is a reply to message #44518] Thu, 23 June 2005 01:30 Go to previous messageGo to next message
enod is currently offline  enod
Messages: 41
Registered: November 2004
Member
Why not use '=' as the seperator?

Tian.
Re: extract numbers from string [message #44582 is a reply to message #44518] Wed, 22 June 2005 05:18 Go to previous messageGo to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Try this: nx=long(strmid(firstline,10,4)). You may have to adjust the
position and length (10 & 4) depending on your range of variables.


"Tobi" <tbeetz@yahoo.com> wrote in message
news:1119387544.336298.199520@f14g2000cwb.googlegroups.com.. .
> i have a data file with a header that has several lines, which i read
> with
>
> readf,1,firstline
> readf,1,secondline
> ....
>
> firstline is a string that looks like
> xpixels = 1024
>
> i am trying to convert this to a variable called nx which has the value
> 1024.
>
> is there a clean and easy way to do this?
>
> Thanks!
>
Re: extract numbers from string [message #44585 is a reply to message #44518] Wed, 22 June 2005 07:27 Go to previous messageGo to next message
Norbert Hahn is currently offline  Norbert Hahn
Messages: 46
Registered: May 2003
Member
"Tobi" <tbeetz@yahoo.com> wrote:

> i have a data file with a header that has several lines, which i read
> with
>
> readf,1,firstline
> readf,1,secondline
> ....
>
> firstline is a string that looks like
> xpixels = 1024
>
> i am trying to convert this to a variable called nx which has the value
> 1024.
>
> is there a clean and easy way to do this?

I would use

reads, firstline, nx, format="(9X,I5)"

The format statment cause reads to skip 9 characters and then expect up to 5
digits for an integer number.

HTH
Norbert
Re: extract numbers from string [message #44586 is a reply to message #44518] Wed, 22 June 2005 05:55 Go to previous messageGo to next message
Ken Mankoff is currently offline  Ken Mankoff
Messages: 158
Registered: February 2000
Senior Member
On Tue, 21 Jun 2005, Tobi wrote:
> i have a data file with a header that has several lines, which i read
> with
>
> readf,1,firstline
> readf,1,secondline
> ....
>
> firstline is a string that looks like
> xpixels = 1024
>
> i am trying to convert this to a variable called nx which has the
> value 1024.
>
> is there a clean and easy way to do this?

success = execute( firstline )
success = execute( secondline )

-k.

--
http://spacebit.dyndns.org/
Re: extract numbers from string [message #44587 is a reply to message #44586] Wed, 22 June 2005 07:10 Go to previous messageGo to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Pretty clever, I guess I am one of the only IDL programmers out here that is
not using the execute function.

Haje

"Ken Mankoff" <mankoff@gmail.com> wrote in message
news:Pine.OSX.4.61.0506220854490.440@gouda.localhost...
>
> On Tue, 21 Jun 2005, Tobi wrote:
>> i have a data file with a header that has several lines, which i read
>> with
>>
>> readf,1,firstline
>> readf,1,secondline
>> ....
>>
>> firstline is a string that looks like
>> xpixels = 1024
>>
>> i am trying to convert this to a variable called nx which has the value
>> 1024.
>>
>> is there a clean and easy way to do this?
>
> success = execute( firstline )
> success = execute( secondline )
>
> -k.
>
> --
> http://spacebit.dyndns.org/
>
Re: extract numbers from string [message #44600 is a reply to message #44587] Tue, 05 July 2005 13:19 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Haje Korth wrote:

> Pretty clever, I guess I am one of the only IDL programmers out here that
> is not using the execute function.
>
> Haje
>

No, I am too :-)

Btw. for this it is not necessary to use execute.
You could do this by SCOPE_VARFETCH and this one runs in vm too.

cheers

Reimar


> "Ken Mankoff" <mankoff@gmail.com> wrote in message
> news:Pine.OSX.4.61.0506220854490.440@gouda.localhost...
>>
>> On Tue, 21 Jun 2005, Tobi wrote:
>>> i have a data file with a header that has several lines, which i read
>>> with
>>>
>>> readf,1,firstline
>>> readf,1,secondline
>>> ....
>>>
>>> firstline is a string that looks like
>>> xpixels = 1024
>>>
>>> i am trying to convert this to a variable called nx which has the value
>>> 1024.
>>>
>>> is there a clean and easy way to do this?
>>
>> success = execute( firstline )
>> success = execute( secondline )
>>
>> -k.
>>
>> --
>> http://spacebit.dyndns.org/
>>

--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Inverse 3D FFT
Next Topic: Re: Inverse 3D FFT

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:12:51 PDT 2025

Total time taken to generate the page: 0.00688 seconds