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

Home » Public Forums » archive » Re: Working with lists
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: Working with lists [message #84393] Mon, 03 June 2013 21:23 Go to next message
SonicKenking is currently offline  SonicKenking
Messages: 51
Registered: October 2010
Member
On Tuesday, June 4, 2013 7:09:06 AM UTC+10, fgg wrote:
> Different error, but still doesn't work here. Btw, I'm running IDL 8.0.1 on Windows 7.
>
>
>
> str = replicate('1000 1000.1515 400 40', 10)
>
> str = strsplit(str, /extract)
>
> array = float(str.ToArray())
>
>
>
> % LIST::TOARRAY: Unable to convert to type STRING: Element 7
>
> % Error occurred at: LIST::TOARRAY
>
> % $MAIN$
>
> % Execution halted at: $MAIN$
>
>
>
>
>
>
>
>> How about this:
>
>>
>
>>
>
>>
>
>> IDL> str = strsplit(str, /extract)
>
>>
>
>> IDL> str = replicate('1000 1000.1515 400 40', 10)
>
>>
>
>> IDL> str = strsplit(str, /extract)
>
>>
>
>> IDL> array = float(str.ToArray() )
>
>>
>
>> IDL> help, array
>
>>
>
>> ARRAY FLOAT = Array[10, 4]
>
>>
>
>> IDL> print, array[*,0]
>
>>
>
>> 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00
>
>>
>
>>
>
>>
>
>> Cheers,
>
>>
>
>> Helder

The error is probably due to your version of IDL.
Anyway, here is a solution without 8.0 features:

s = '1000 1000.1515 400 40'
array = rebin(float(strsplit(s, /extract)), 4, 10)
Re: Working with lists [message #84394 is a reply to message #84393] Mon, 03 June 2013 21:18 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Monday, June 3, 2013 1:39:46 PM UTC-4, fgg wrote:
> I have a string array that looks like this (with the exception that the numbers actually vary from element to element):
>
> str = replicate('1000 1000.1515 400 40', 10)
>
> Is there a simple way to extract these numbers to a 4 by 10 array without using loops? I've tried the following, but it doesn't work:
>
> str = strsplit(str, /extract)
> array = str.ToArray(type='float')

Umm, is there any reason that this doesn't work?
ff = fltarr(4,10)
reads, str, ff

I don't use ToArray(), so I don't really understand how it works. Maybe it's getting confused, but plain READS does not get confused.

Craig
Re: Working with lists [message #84404 is a reply to message #84394] Mon, 03 June 2013 14:09 Go to previous messageGo to next message
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
Different error, but still doesn't work here. Btw, I'm running IDL 8.0.1 on Windows 7.

str = replicate('1000 1000.1515 400 40', 10)
str = strsplit(str, /extract)
array = float(str.ToArray())

% LIST::TOARRAY: Unable to convert to type STRING: Element 7
% Error occurred at: LIST::TOARRAY
% $MAIN$
% Execution halted at: $MAIN$



> How about this:
>
>
>
> IDL> str = strsplit(str, /extract)
>
> IDL> str = replicate('1000 1000.1515 400 40', 10)
>
> IDL> str = strsplit(str, /extract)
>
> IDL> array = float(str.ToArray() )
>
> IDL> help, array
>
> ARRAY FLOAT = Array[10, 4]
>
> IDL> print, array[*,0]
>
> 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00
>
>
>
> Cheers,
>
> Helder
Re: Working with lists [message #84407 is a reply to message #84404] Mon, 03 June 2013 12:21 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, June 3, 2013 7:39:46 PM UTC+2, fgg wrote:
> Hello,
>
>
>
> I have a string array that looks like this (with the exception that the numbers actually vary from element to element):
>
>
>
> str = replicate('1000 1000.1515 400 40', 10)
>
>
>
> Is there a simple way to extract these numbers to a 4 by 10 array without using loops? I've tried the following, but it doesn't work:
>
>
>
> str = strsplit(str, /extract)
>
> array = str.ToArray(type='float')
>
>
>
> % LIST::TOARRAY: Unable to convert to type FLOAT: Element 7
>
> % Error occurred at: LIST::TOARRAY
>
> % $MAIN$
>
> % Execution halted at: $MAIN$
>
>
>
> What's the problem with this?
>
>
>
> Thanks!

How about this:

IDL> str = strsplit(str, /extract)
IDL> str = replicate('1000 1000.1515 400 40', 10)
IDL> str = strsplit(str, /extract)
IDL> array = float(str.ToArray() )
IDL> help, array
ARRAY FLOAT = Array[10, 4]
IDL> print, array[*,0]
1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00 1000.00

Cheers,
Helder
Re: Working with lists [message #84752 is a reply to message #84394] Fri, 07 June 2013 10:33 Go to previous messageGo to next message
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
strsplit returns a list in this case, and if I do what you suggested below I get:

% READS: Object reference expression not allowed in this context: STR.


> Umm, is there any reason that this doesn't work?
>
> ff = fltarr(4,10)
>
> reads, str, ff
>
>
>
> I don't use ToArray(), so I don't really understand how it works. Maybe it's getting confused, but plain READS does not get confused.
>
>
>
> Craig
Re: Working with lists [message #84753 is a reply to message #84393] Fri, 07 June 2013 10:40 Go to previous message
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
Yes, this works for a single line '1000 1000.1515 400 40', but my dataset is actually composed by a bunch of lines like this, where the numbers actually vary. So you have something like replicate('1000 1000.1515 400 40', 10), but where the lines are not really replicates.

Thanks!

>
> The error is probably due to your version of IDL.
>
> Anyway, here is a solution without 8.0 features:
>
>
>
> s = '1000 1000.1515 400 40'
>
> array = rebin(float(strsplit(s, /extract)), 4, 10)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: points on a plot
Next Topic: Subscript by -1 HARD to Track Down

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

Current Time: Wed Oct 08 09:15:29 PDT 2025

Total time taken to generate the page: 0.00288 seconds