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

Home » Public Forums » archive » Dealing with list created by STRSPLIT?
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
Dealing with list created by STRSPLIT? [message #76194] Thu, 19 May 2011 19:44 Go to next message
BLesht is currently offline  BLesht
Messages: 89
Registered: March 2007
Member
I have an array of full-path filenames from which I need to extract
some substrings. The array consists of a large number of strings of
the form

diskname/maindir/subdir1/subdir2/subdir3/filename
diskname/maindir/subidr1/subdir2/subdir3/filename etc.

The lengths of the subdirXs can be different. What I wanted to do was
create some arrays the elements of which would be the subdirXs. I
thought this would be simple now that STRSPLIT allows arrays as
input. I had the array of n filenames in a string array and I used

splitnames = STRSPLIT(filenames, '/', /EXTRACT).

The result 'splitnames' is a list with n elements and each element is
of the form

diskname maindir subdir1 subdir2 subdir3 filename as it should be.
Each element is a string array.

What I can't seem to figure out is how to now extract one of these
terms from the list element. That is, I'd like to end up with arrays
that have the n subdir2s (for example). I've tried using the
LIST::TOARRAY () feature but this fails for some mysterious reason
with the message

IDL> namearray=splitnames.ToArray()
% LIST::TOARRAY: Unable to convert to type STRING: Element 798
% Error occurred at: LIST::TOARRAY
% $MAIN$
% Execution halted at: $MAIN$

Element 798 is no different from any of the elements in the list, by
the way, but this is not the real problem (at least I don't think it
is)

There must be an easy way to do this; I'm not seeing it. Any help
would be much appreciated.
Re: Dealing with list created by STRSPLIT? [message #76235 is a reply to message #76194] Mon, 23 May 2011 14:45 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Torrence writes:

> That didn't work in IDL 8.0.1 or earlier. All of the list elements
> needed to be scalars for ::ToArray to work. In IDL 8.1 we added code
> that handles arrays.

Oh, OK. That explains why I got no errors when I
tried to covert the list to an array. Thanks!

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Dealing with list created by STRSPLIT? [message #76236 is a reply to message #76194] Mon, 23 May 2011 14:39 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On May 23, 3:01 pm, David Fanning <n...@idlcoyote.com> wrote:
> Chris Torrence writes:
>> Okay, in IDL 8.0.1, the List::ToArray() only worked if your List
>> contained scalars. In IDL 8.1 it now works for lists that contain
>> array elements, as long each array has the same number of elements.
>
>> So, once you upgrade to IDL 8.1 you should be fine.
>
> Well, Barry would have been fine had he been able
> to convert the list to an array. Do we know why
> he wasn't able to do that?
>
> Cheers,
>
> David

That didn't work in IDL 8.0.1 or earlier. All of the list elements
needed to be scalars for ::ToArray to work. In IDL 8.1 we added code
that handles arrays.

-Chris
Re: Dealing with list created by STRSPLIT? [message #76239 is a reply to message #76194] Mon, 23 May 2011 14:01 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Torrence writes:

> Okay, in IDL 8.0.1, the List::ToArray() only worked if your List
> contained scalars. In IDL 8.1 it now works for lists that contain
> array elements, as long each array has the same number of elements.
>
> So, once you upgrade to IDL 8.1 you should be fine.

Well, Barry would have been fine had he been able
to convert the list to an array. Do we know why
he wasn't able to do that?

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Dealing with list created by STRSPLIT? [message #76240 is a reply to message #76194] Mon, 23 May 2011 14:00 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On May 23, 5:54 pm, Chris Torrence <gorth...@gmail.com> wrote:
>> On May 20, 2:46 pm, Barry Lesht <ble...@gmail.com> wrote:
>
>>> Thanks, David.  I'll see if Chris replies again and in the meantime
>>> install 8.1.
>
>>> Regards, Barry
>
> Okay, in IDL 8.0.1, the List::ToArray() only worked if your List
> contained scalars. In IDL 8.1 it now works for lists that contain
> array elements, as long each array has the same number of elements.
>
> So, once you upgrade to IDL 8.1 you should be fine.

Yes, I forgot about that, which is a very nice addition.
Re: Dealing with list created by STRSPLIT? [message #76241 is a reply to message #76194] Mon, 23 May 2011 13:54 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
> On May 20, 2:46 pm, Barry Lesht <ble...@gmail.com> wrote:
>
>> Thanks, David.  I'll see if Chris replies again and in the meantime
>> install 8.1.
>
>> Regards, Barry


Okay, in IDL 8.0.1, the List::ToArray() only worked if your List
contained scalars. In IDL 8.1 it now works for lists that contain
array elements, as long each array has the same number of elements.

So, once you upgrade to IDL 8.1 you should be fine.

Cheers,
Chris
Re: Dealing with list created by STRSPLIT? [message #76242 is a reply to message #76194] Mon, 23 May 2011 13:53 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
> I should have said "you can also use the usual array ranges, *, etc."
> for the second and subsequent indices. The first index MUST be a
> scalar.

It seems easy to make a derived class that would do it. Which is the
beauty of having the containers implemented by objects.
Re: Dealing with list created by STRSPLIT? [message #76355 is a reply to message #76241] Tue, 24 May 2011 11:39 Go to previous messageGo to next message
BLesht is currently offline  BLesht
Messages: 89
Registered: March 2007
Member
On May 23, 3:54 pm, Chris Torrence <gorth...@gmail.com> wrote:
>> On May 20, 2:46 pm, Barry Lesht <ble...@gmail.com> wrote:
>
>>> Thanks, David.  I'll see if Chris replies again and in the meantime
>>> install 8.1.
>
>>> Regards, Barry
>
> Okay, in IDL 8.0.1, the List::ToArray() only worked if your List
> contained scalars. In IDL 8.1 it now works for lists that contain
> array elements, as long each array has the same number of elements.
>
> So, once you upgrade to IDL 8.1 you should be fine.
>
> Cheers,
> Chris

Thanks very much, all. I did install 8.1 a few days ago, but got
distracted from this problem by another project. Here is what happens
now (success!).

IDL> help, splitname
SPLITNAME LIST <ID=22 NELEMENTS=804>
IDL> help, splitname[0]
<Expression> STRING = Array[7]
IDL> newarray=splitname.ToArray()
IDL> help, newarray
NEWARRAY STRING = Array[804, 7]

Which is what I was originally hoping for. I really appreciate your
suggestions and help.

Barry
Re: Dealing with list created by STRSPLIT? [message #81009 is a reply to message #76194] Sat, 04 August 2012 01:52 Go to previous messageGo to next message
zhyf87 is currently offline  zhyf87
Messages: 1
Registered: August 2012
Junior Member
在 2011年5月20日星期五UTC+8上午10时44分42秒,Barry Lesht写道:
> I have an array of full-path filenames from which I need to extract
> some substrings. The array consists of a large number of strings of
> the form
>
> diskname/maindir/subdir1/subdir2/subdir3/filename
> diskname/maindir/subidr1/subdir2/subdir3/filename etc.
>
> The lengths of the subdirXs can be different. What I wanted to do was
> create some arrays the elements of which would be the subdirXs. I
> thought this would be simple now that STRSPLIT allows arrays as
> input. I had the array of n filenames in a string array and I used
>
> splitnames = STRSPLIT(filenames, '/', /EXTRACT).
>
> The result 'splitnames' is a list with n elements and each element is
> of the form
>
> diskname maindir subdir1 subdir2 subdir3 filename as it should be.
> Each element is a string array.
>
> What I can't seem to figure out is how to now extract one of these
> terms from the list element. That is, I'd like to end up with arrays
> that have the n subdir2s (for example). I've tried using the
> LIST::TOARRAY () feature but this fails for some mysterious reason
> with the message
>
> IDL> namearray=splitnames.ToArray()
> % LIST::TOARRAY: Unable to convert to type STRING: Element 798
> % Error occurred at: LIST::TOARRAY
> % $MAIN$
> % Execution halted at: $MAIN$
>
> Element 798 is no different from any of the elements in the list, by
> the way, but this is not the real problem (at least I don't think it
> is)
>
> There must be an easy way to do this; I'm not seeing it. Any help
> would be much appreciated.

same problem here with 8.0
first indice must be a scalar while exacting elements, and LIST.ToArray doesn't work. for loop solves this :)
Re: Dealing with list created by STRSPLIT? [message #92852 is a reply to message #76355] Sun, 13 March 2016 14:43 Go to previous message
Adam Erickson is currently offline  Adam Erickson
Messages: 8
Registered: July 2015
Junior Member
On Tuesday, May 24, 2011 at 8:39:30 PM UTC+2, Barry Lesht wrote:
> On May 23, 3:54 pm, Chris Torrence <gorth...@gmail.com> wrote:
>>> On May 20, 2:46 pm, Barry Lesht <ble...@gmail.com> wrote:
>>
>>>> Thanks, David.  I'll see if Chris replies again and in the meantime
>>>> install 8.1.
>>
>>>> Regards, Barry
>>
>> Okay, in IDL 8.0.1, the List::ToArray() only worked if your List
>> contained scalars. In IDL 8.1 it now works for lists that contain
>> array elements, as long each array has the same number of elements.
>>
>> So, once you upgrade to IDL 8.1 you should be fine.
>>
>> Cheers,
>> Chris
>
> Thanks very much, all. I did install 8.1 a few days ago, but got
> distracted from this problem by another project. Here is what happens
> now (success!).
>
> IDL> help, splitname
> SPLITNAME LIST <ID=22 NELEMENTS=804>
> IDL> help, splitname[0]
> <Expression> STRING = Array[7]
> IDL> newarray=splitname.ToArray()
> IDL> help, newarray
> NEWARRAY STRING = Array[804, 7]
>
> Which is what I was originally hoping for. I really appreciate your
> suggestions and help.
>
> Barry

Yes, thank you for this! I hope the issue has been addressed. Efficient indexing is a very important feature to have.

Adam
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: solving non linear equation
Next Topic: FINDGEN function - Question

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

Current Time: Wed Oct 08 09:09:06 PDT 2025

Total time taken to generate the page: 0.00675 seconds