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

Home » Public Forums » archive » STRMID question
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
STRMID question [message #26279] Mon, 20 August 2001 10:13 Go to next message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Hello,

I have a "question" about the output of STRMID. Consider the following:

Given an input string array:

IDL> s='_'+strtrim(10L^lindgen(10),2)+'.'
IDL> print, s
_1. _10. _100. _1000. _10000. _100000. _1000000. _10000000. _100000000. _1000000000.

I search for the "_" and "." characters (I do a reverse search as there may be other "_"
or "." in the string before the last set):

IDL> delim1 = STRPOS( s, '_', /REVERSE_SEARCH ) + 1
IDL> delim2 = STRPOS( s, '.', /REVERSE_SEARCH ) - 1

So now I want to extract out the substrings from the string array delimited by delim1 and
delim2:

IDL> help, STRMID( s, delim1, delim2-delim1+1 )
<Expression> STRING = Array[10, 10]

How come I get a 2-D array output? I can sort of see how that _could_ happen since delim1
and delim2 are both vectors so the output:

IDL> print, STRMID( s, delim1, delim2-delim1+1 )
1 1. 1. 1. 1. 1. 1. 1. 1. 1.
1 10 10. 10. 10. 10. 10. 10. 10. 10.
1 10 100 100. 100. 100. 100. 100. 100. 100.
1 10 100 1000 1000. 1000. 1000. 1000. 1000. 1000.
1 10 100 1000 10000 10000. 10000. 10000. 10000. 10000.
1 10 100 1000 10000 100000 100000. 100000. 100000. 100000.
1 10 100 1000 10000 100000 1000000 1000000. 1000000. 1000000.
1 10 100 1000 10000 100000 1000000 10000000 10000000. 10000000.
1 10 100 1000 10000 100000 1000000 10000000 100000000 100000000.
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000

sort of makes sense, but does it make sense to anyone that it _should_ happen?? It's not a
big deal since I can do a

IDL> si=STRMID( s, delim1, delim2-delim1+1 )
IDL> i=indgen(10)
IDL> print, si[i,i]
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000

to extract the diagonal, but the original result sorta threw me and I haven't yet
recovered <whimper>.

paulv

--
Paul van Delst A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
Fax:(301)763-8545 And drinking largely sobers us again.
Alexander Pope.
Re: STRMID question [message #26360 is a reply to message #26279] Tue, 21 August 2001 08:37 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Hi Paul,

I don't know diddle about how strings are handled except that switching
between strings and bytes (where IDL really handles strings) is
definitely an eye-glazer.

Check out the following; the number of columns of the output array is
matched to the string element with the most number of characters, in
your example the last element. So, to me, the question is, how come IDL
doesn't put back these strings into a simpler vector when using the
higher-order string processing commands (like strmid)?


Ben



IDL> s='_'+strtrim(10L^lindgen(10),2)+'.'
IDL> print, s
_1. _10. _100. _1000. _10000. _100000. _1000000. _10000000. _100000000. _1000000000.
IDL> print, byte(s)
95 49 46 0 0 0 0 0 0 0 0 0
95 49 48 46 0 0 0 0 0 0 0 0
95 49 48 48 46 0 0 0 0 0 0 0
95 49 48 48 48 46 0 0 0 0 0 0
95 49 48 48 48 48 46 0 0 0 0 0
95 49 48 48 48 48 48 46 0 0 0 0
95 49 48 48 48 48 48 48 46 0 0 0
95 49 48 48 48 48 48 48 48 46 0 0
95 49 48 48 48 48 48 48 48 48 46 0
95 49 48 48 48 48 48 48 48 48 48 46
IDL> help, s, byte(s)
S STRING = Array[10]
<Expression> BYTE = Array[12, 10]
IDL> for i = 0, 9 do help,s[i], byte(s[i])
<Expression> STRING = '_1.'
<Expression> BYTE = Array[3]
<Expression> STRING = '_10.'
<Expression> BYTE = Array[4]
<Expression> STRING = '_100.'
<Expression> BYTE = Array[5]
<Expression> STRING = '_1000.'
<Expression> BYTE = Array[6]
<Expression> STRING = '_10000.'
<Expression> BYTE = Array[7]
<Expression> STRING = '_100000.'
<Expression> BYTE = Array[8]
<Expression> STRING = '_1000000.'
<Expression> BYTE = Array[9]
<Expression> STRING = '_10000000.'
<Expression> BYTE = Array[10]
<Expression> STRING = '_100000000.'
<Expression> BYTE = Array[11]
<Expression> STRING = '_1000000000.'
<Expression> BYTE = Array[12]




Paul van Delst wrote:
>
> Hello,
>
> I have a "question" about the output of STRMID. Consider the following:
>
> Given an input string array:
>
> IDL> s='_'+strtrim(10L^lindgen(10),2)+'.'
> IDL> print, s
> _1. _10. _100. _1000. _10000. _100000. _1000000. _10000000. _100000000. _1000000000.
>
> I search for the "_" and "." characters (I do a reverse search as there may be other "_"
> or "." in the string before the last set):
>
> IDL> delim1 = STRPOS( s, '_', /REVERSE_SEARCH ) + 1
> IDL> delim2 = STRPOS( s, '.', /REVERSE_SEARCH ) - 1
>
> So now I want to extract out the substrings from the string array delimited by delim1 and
> delim2:
>
> IDL> help, STRMID( s, delim1, delim2-delim1+1 )
> <Expression> STRING = Array[10, 10]
>
> How come I get a 2-D array output? I can sort of see how that _could_ happen since delim1
> and delim2 are both vectors so the output:
>
> IDL> print, STRMID( s, delim1, delim2-delim1+1 )
> 1 1. 1. 1. 1. 1. 1. 1. 1. 1.
> 1 10 10. 10. 10. 10. 10. 10. 10. 10.
> 1 10 100 100. 100. 100. 100. 100. 100. 100.
> 1 10 100 1000 1000. 1000. 1000. 1000. 1000. 1000.
> 1 10 100 1000 10000 10000. 10000. 10000. 10000. 10000.
> 1 10 100 1000 10000 100000 100000. 100000. 100000. 100000.
> 1 10 100 1000 10000 100000 1000000 1000000. 1000000. 1000000.
> 1 10 100 1000 10000 100000 1000000 10000000 10000000. 10000000.
> 1 10 100 1000 10000 100000 1000000 10000000 100000000 100000000.
> 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
>
> sort of makes sense, but does it make sense to anyone that it _should_ happen?? It's not a
> big deal since I can do a
>
> IDL> si=STRMID( s, delim1, delim2-delim1+1 )
> IDL> i=indgen(10)
> IDL> print, si[i,i]
> 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
>
> to extract the diagonal, but the original result sorta threw me and I haven't yet
> recovered <whimper>.
>
> paulv
>
> --
> Paul van Delst A little learning is a dangerous thing;
> CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
> Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
> Fax:(301)763-8545 And drinking largely sobers us again.
> Alexander Pope.

--
Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd.
W. Boothbay Harbor, ME 04575
btupper@bigelow.org
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: GET_SCREEN_SIZE in Windows
Next Topic: Re: problems with VELOVECT

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

Current Time: Wed Oct 08 15:49:02 PDT 2025

Total time taken to generate the page: 0.00587 seconds