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

Home » Public Forums » archive » Re: Extracting strings from an array
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
Re: Extracting strings from an array [message #38220] Fri, 27 February 2004 23:30 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
jcdmesq@hotmail.com (Lin) writes:


> Hi folks, I need some help!! I'm not familiar to IDL.
>
> I have an array and I must extract some elements from it. The elements
> I need to extract are always after a name. As an example I have the
> array:
>
> x1024 y1024 lat-22.500000 lon-49.500000 range10.000000
>
> The elements I need to extract are 1024, 1024, -22.5, -49.5 and
> 10.0000. They are always after x, y, lat, lon and range.
>
> How can I do to extract them?? I need some like: "get nn after xx"...

Probably the best tool for the job is Perl. Text processing is its
forte.

IDL does have regular expression matching, which may be enough for
you. I've never used it myself (I just go right to the Perl).

Beyond that, you can do things like use STRPOS to locate the strings
of interest. Then you add an offset to pull out the value you need.

Example:
ip = strpos('lat', strdata) ;; Locate 'lat'
if ip GE 0 then lat = float(strmid(strdata,ip+3)) ; Pull out float after 'lat'

This can be tricky if your keyword names are substrings of each other
though.

A *really* subversive thing to do, which is thus the obvious technique
for me to try myself, is to replace 'lat' with 'lat:', and so on, wrap
the whole string in curly braces, and then EXECUTE() it into a
structure. That will need some error trapping though.

Hope those suggestions helped!
Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Extracting strings from an array [message #38314 is a reply to message #38220] Sun, 29 February 2004 08:38 Go to previous message
jcdmesq is currently offline  jcdmesq
Messages: 2
Registered: February 2004
Junior Member
Dear Craig,

These two lines solved my problem, I can extract all the values I want
from the string!
Thanks a lot,
Lin
Sao Paulo/Brazil


Craig Markwardt <craigmnet@REMOVEcow.physics.wisc.edu> wrote in message news:<onllmnpso5.fsf@cow.physics.wisc.edu>...
> jcdmesq@hotmail.com (Lin) writes:
>
>
>> Hi folks, I need some help!! I'm not familiar to IDL.
>>
>> I have an array and I must extract some elements from it. The elements
>> I need to extract are always after a name. As an example I have the
>> array:
>>
>> x1024 y1024 lat-22.500000 lon-49.500000 range10.000000
>>
>> The elements I need to extract are 1024, 1024, -22.5, -49.5 and
>> 10.0000. They are always after x, y, lat, lon and range.
>>
>> How can I do to extract them?? I need some like: "get nn after xx"...
>
> Probably the best tool for the job is Perl. Text processing is its
> forte.
>
> IDL does have regular expression matching, which may be enough for
> you. I've never used it myself (I just go right to the Perl).
>
> Beyond that, you can do things like use STRPOS to locate the strings
> of interest. Then you add an offset to pull out the value you need.
>
> Example:
> ip = strpos('lat', strdata) ;; Locate 'lat'
> if ip GE 0 then lat = float(strmid(strdata,ip+3)) ; Pull out float after 'lat'
>
> This can be tricky if your keyword names are substrings of each other
> though.
>
> A *really* subversive thing to do, which is thus the obvious technique
> for me to try myself, is to replace 'lat' with 'lat:', and so on, wrap
> the whole string in curly braces, and then EXECUTE() it into a
> structure. That will need some error trapping though.
>
> Hope those suggestions helped!
> Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: math_doit split window
Next Topic: Re: JULDAY-CALDAT problem

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

Current Time: Wed Oct 08 19:51:10 PDT 2025

Total time taken to generate the page: 0.00353 seconds