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

Home » Public Forums » archive » Re: Why doesn't this work?
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: Why doesn't this work? [message #7789] Tue, 14 January 1997 00:00
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
Tim Abbott wrote:
>
> Can anyone tell me why this doesn't work?
>
> I need to extract the four numbers from the string "[123:456,246:135]"
>
> Here is the code segment I'm trying to use:
> IDL> str = "[123:456,246:135]"
> IDL> reads,str,x1,x2,x3,x4,format='(4(1X,I0))'
> % Unable to apply format code I to input: "]".
> % Execution halted at: $MAIN$
> IDL> print,x1,x2,x3
> 123.000 246.000 0.00000
> IDL> print,x1,x2,x3,x4
> % PRINT: Variable is undefined: X4.
> % Execution halted at: $MAIN$
>

Tim -

I've mailed you a copy of my routine GET_TOKEN.PRO that
allows you to read byte, int, long, float, double and string
values from a string, as tokens. The routine maintains a string
pointer for subsequent calls.

You can parse the above string using:

IDL> str = "[123:456,246:135]"
IDL> pos=0
IDL> s1 = get_token( str, pos, sep='[:,]', /increment)
IDL> s2 = get_token( str, pos, sep='[:,]', /increment)
IDL> s3 = get_token( str, pos, sep='[:,]', /increment)
IDL> s4 = get_token( str, pos, sep='[:,]', /increment)
IDL> help, s1,s2,s3,s4
S1 STRING = '123'
S2 STRING = '456'
S3 STRING = '246'
S4 STRING = '135'

If anyone else is interested, send me an email and I'll send
you a copy.

Dave
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2200
La Jolla, CA 92037
[ UCSD Mail Code 0949 ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
Re: Why doesn't this work? [message #7806 is a reply to message #7789] Mon, 13 January 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Tim Abbott writes:

> Can anyone tell me why this doesn't work?
>
> I need to extract the four numbers from the string "[123:456,246:135]"
>
> Here is the code segment I'm trying to use:
> IDL> str = "[123:456,246:135]"
> IDL> reads,str,x1,x2,x3,x4,format='(4(1X,I0))'
> % Unable to apply format code I to input: "]".
> % Execution halted at: $MAIN$
> IDL> print,x1,x2,x3
> 123.000 246.000 0.00000
> IDL> print,x1,x2,x3,x4
> % PRINT: Variable is undefined: X4.
> % Execution halted at: $MAIN$
>
> Any ideas?

The main reason this doesn't work, I think, is that the READS
procedure and the I0 format require more carefully formatted
input than they are getting here. In particular, they really
don't know how to handle the colons.

You can get this example to work if you perform a little
bit of "processing" on the string to turn the colons into
commas.

I suggest something like this:

comma = 44B
colon = 58B
str = "[123:456,246:135]"
array = BYTE(str)
colonLocations = WHERE(array EQ colon, count)
IF count GT 0 THEN array(colonLocations) = comma
str = STRING(array)
READS, str, x1, x2, x3, x4, FORMAT='(4(1X,I0))'
PRINT, x1, x2, x3, x4

Yours,

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
2642 Bradbury Court, Fort Collins, CO 80521
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
-----------------------------------------------------------
Re: Why doesn't this work? [message #7808 is a reply to message #7806] Mon, 13 January 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Tim Abbott writes:

> Can anyone tell me why this doesn't work?
>
> I need to extract the four numbers from the string "[123:456,246:135]"
>
> Here is the code segment I'm trying to use:
> IDL> str = "[123:456,246:135]"
> IDL> reads,str,x1,x2,x3,x4,format='(4(1X,I0))'
> % Unable to apply format code I to input: "]".
> % Execution halted at: $MAIN$
> IDL> print,x1,x2,x3
> 123.000 246.000 0.00000
> IDL> print,x1,x2,x3,x4
> % PRINT: Variable is undefined: X4.
> % Execution halted at: $MAIN$
>
> Any ideas?

The main reason this doesn't work, I think, is that the READS
procedure and the I0 format require more carefully formatted
input than they are getting here. In particular, they really
don't know how to handle the colons.

You can get this example to work if you perform a little
bit of "processing" on the string to turn the colons into
commas.

I suggest something like this:

comma = 44B
colon = 58B
str = "[123:456,246:135]"
array = BYTE(str)
colonLocations = WHERE(array EQ colon, count)
IF count GT 0 THEN array(colonLocations) = comma
str = STRING(array)
READS, str, x1, x2, x3, x4, FORMAT='(4(1X,I0))'
PRINT, x1, x2, x3, x4

Yours,

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
2642 Bradbury Court, Fort Collins, CO 80521
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
-----------------------------------------------------------
Re: Why doesn't this work? [message #7833 is a reply to message #7806] Thu, 09 January 1997 00:00 Go to previous message
Tim Abbott is currently offline  Tim Abbott
Messages: 4
Registered: January 1997
Junior Member
Oops, as Joe Gurman points out, if all the numbers are 3 digits long
the fix is to use format='(4(1X,I3))'. Unfortunately, the numbers
will not always be 3 digits long...


Tim Abbott wrote:
>
> Can anyone tell me why this doesn't work?
>
> I need to extract the four numbers from the string "[123:456,246:135]"
>
> Here is the code segment I'm trying to use:
> IDL> str = "[123:456,246:135]"
> IDL> reads,str,x1,x2,x3,x4,format='(4(1X,I0))'
> % Unable to apply format code I to input: "]".
> % Execution halted at: $MAIN$
> IDL> print,x1,x2,x3
> 123.000 246.000 0.00000
> IDL> print,x1,x2,x3,x4
> % PRINT: Variable is undefined: X4.
> % Execution halted at: $MAIN$
>
> Any ideas?
>
> --
> Timothy M. C. Abbott
> http://www.cfht.hawaii.edu/~tmca/tmca.html

--
Timothy M. C. Abbott
http://www.cfht.hawaii.edu/~tmca/tmca.html
Re: Why doesn't this work? [message #7834 is a reply to message #7833] Thu, 09 January 1997 00:00 Go to previous message
joseph.b.gurman is currently offline  joseph.b.gurman
Messages: 15
Registered: October 1995
Junior Member
In article <32D58AF7.51A8@cfht.hawaii.edu>, Tim Abbott
<tmca@cfht.hawaii.edu> wrote:

> Can anyone tell me why this doesn't work?
>
> I need to extract the four numbers from the string "[123:456,246:135]"
>
> Here is the code segment I'm trying to use:
> IDL> str = "[123:456,246:135]"
> IDL> reads,str,x1,x2,x3,x4,format='(4(1X,I0))'
^^
> % Unable to apply format code I to input: "]".
> % Execution halted at: $MAIN$
> IDL> print,x1,x2,x3
> 123.000 246.000 0.00000
> IDL> print,x1,x2,x3,x4
> % PRINT: Variable is undefined: X4.
> % Execution halted at: $MAIN$

Tim -

It looks like it's trying to read the final "]" because you're using
I0 --- do you need to do that, or do you know that all your integer
strings will be three characters long? If so, of course, you could just
use:

IDL> reads, str , x1, x2, x3, x4, format = '(4(1X, I3))'

which gives:

IDL> print, x1, x2, x3, x4
123.000 456.000 246.000 135.000

Sorry if I'm missing the point; I thought it might have to do with the
lack of oxygen at the telescope....

Joe Gurman

--
J.B. Gurman / Solar Physics Branch/ NASA Goddard Space Flight Center/
Greenbelt MD 20771 USA / joseph.b.gurman@gsfc.nasa.gov
| Federal employees are still prohibited from holding opinions while at |
| work. Therefore, any opinions expressed herein are somebody else's. |
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: polar stereographic contour plot.
Next Topic: Q: Selection of specific plot regions

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

Current Time: Wed Oct 08 13:31:25 PDT 2025

Total time taken to generate the page: 0.00925 seconds