Odd string/index problem [message #21685] |
Wed, 13 September 2000 00:00  |
wmc
Messages: 117 Registered: February 1995
|
Senior Member |
|
|
Can someone explain this to me:
wmc> a='stoat'
wmc> print,a([0]),'>'
stoat
>
wmc> print,a(0),'>'
stoat>
This irritation surfaced when I tried to do
i=where(strings eq somestring)
print,strings(i)
which needs to be
i=i[0]
print,strings(i)
but why?
-W.
--
William M Connolley | wmc@bas.ac.uk | http://www.nerc-bas.ac.uk/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
|
|
|
Re: Odd string/index problem [message #21763 is a reply to message #21685] |
Thu, 14 September 2000 00:00  |
wmc
Messages: 117 Registered: February 1995
|
Senior Member |
|
|
Martin Schultz <martin.schultz@dkrz.de> wrote:
>> [...] after printing an array, IDL always starts a new line
>> OK, its an array, but is it acceptable that IDL always starts a new line
>> after printing an array? Whats the justification for that?
> a = findgen(10)
> b = findgen(20)
> c = indgen(4)
> print,a,b,c
No, this is cheating, in this case print clearly has to do formatting,
since the items are numeric. In the case of strings, the need to exta
formatting is not clear.
-W.
--
William M Connolley | wmc@bas.ac.uk | http://www.nerc-bas.ac.uk/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
|
|
|
Re: Odd string/index problem [message #21767 is a reply to message #21685] |
Thu, 14 September 2000 00:00  |
Paul van Delst
Messages: 364 Registered: March 1997
|
Senior Member |
|
|
wmc@bas.ac.uk wrote:
>
> marc <m_schellens@hotmail.com> wrote:
>> wmc@bas.ac.uk wrote:
>>> wmc> a='stoat'
>>> wmc> print,a([0]),'>'
>>> stoat
>>>>
>>> wmc> print,a(0),'>'
>>> stoat>
>
>> This is because your i is an array, while i[0] is a scalar.
>> therefore strings(i) is a string array, while strings(i[0]) is a scalar.
>
>> after printing an array, IDL always starts a new line
>
> OK, its an array, but is it acceptable that IDL always starts a new line
> after printing an array? Whats the justification for that?
>
IDL> a = [ 1,2,4,7,11 ]
IDL> b = [ 2.0,3.7,4.0 ]
IDL> c = [ 2,6,4,9,4,2,7 ]
IDL> print, a, b, c, FORMAT = '( 5i5,3f7.3,7i5 )'
1 2 4 7 11 2.000 3.700 4.000 2 6 4 9
4 2 7
IDL> print, a, b, c
1 2 4 7 11
2.00000 3.70000 4.00000
2 6 4 9 4 2 7
Well, I gotta tell you, I prefer the default option.
I print out full arrays more often than single elements (or single
element arrays). If the first example was the default it would be pretty
annoying don't you reckon?
paulv
--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.202, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
|
|
|
Re: Odd string/index problem [message #21770 is a reply to message #21685] |
Thu, 14 September 2000 00:00  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
> after printing an array, IDL always starts a new line
>
> OK, its an array, but is it acceptable that IDL always starts a new line
> after printing an array? Whats the justification for that?
>
I really like this feature! Say you have
a = findgen(10)
b = findgen(20)
c = indgen(4)
print,a,b,c
It would be much harder to distinguish between the arrays if IDL would
not break the line.
Martin
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|
Re: Odd string/index problem [message #21771 is a reply to message #21685] |
Thu, 14 September 2000 00:00  |
wmc
Messages: 117 Registered: February 1995
|
Senior Member |
|
|
marc <m_schellens@hotmail.com> wrote:
> wmc@bas.ac.uk wrote:
>> wmc> a='stoat'
>> wmc> print,a([0]),'>'
>> stoat
>>>
>> wmc> print,a(0),'>'
>> stoat>
> This is because your i is an array, while i[0] is a scalar.
> therefore strings(i) is a string array, while strings(i[0]) is a scalar.
> after printing an array, IDL always starts a new line
OK, its an array, but is it acceptable that IDL always starts a new line
after printing an array? Whats the justification for that?
-W.
--
William M Connolley | wmc@bas.ac.uk | http://www.nerc-bas.ac.uk/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
|
|
|