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 
Return to the default flat view Create a new topic Submit Reply
Re: Why doesn't this work? [message #7808 is a reply to message #7806] Mon, 13 January 1997 00:00 Go to previous messageGo 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
-----------------------------------------------------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
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 19:04:53 PDT 2025

Total time taken to generate the page: 0.00453 seconds