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

Home » Public Forums » archive » sorting string arrays - non alphabetic and user defined order
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: sorting string arrays - non alphabetic and user defined order [message #50826 is a reply to message #50654] Tue, 17 October 2006 00:14 Go to previous messageGo to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
Hi,

It seemed much more fun when I thought we were talking about dwarves...

I'm not sure I understnad what you're asking in the new post. It seems
to me that in my code 'namelist' is your NamelistB, and mylist is
NamelistC. NamelistA is superfluous to the problem, isn't it?

Here's a modified code to show what I mean - NamelistA has a couple of
extra entries, but I never use it. Even if they are present in mylist
(NamelistC), they will be ignored when filtered with mylist
(NamelistB). Even a double entry will turn up only once.

namelistA=['Sneezy','Daddy','Groggy','Dopey','Ally','Curry', 'Emmy','Bully','Jockey','Hippy','Itchy','Fluffy']

namelist=['Daddy','Groggy','Ally','Curry','Emmy','Bully','Jo ckey','Hippy','Itchy','Fluffy']
mylist=['Emmy','Fluffy','Itchy','Jockey','Groggy','Groggy',' Sneezy']
n=n_elements(namelist)
m=n_elements(mylist)
a1=rebin(transpose(indgen(m)),n,m)
a2=rebin(indgen(n),n,m)
s=mylist[a1] eq namelist[a2]
result=namelist[where(total(s,2) gt 0)]

IDL> print,result
Groggy Emmy Jockey Itchy Fluffy

'result' will automatically have the right size and be indexed from
zero upwards - you don't need to worry about declaring it beforehand.
Or have I missed what you're asking?

regards,
Greg


metachronist wrote:
> Hi Greg,
>
> Thank you for your quick response, it is much appreciated. Your method
> works fine. I am afraid I left out of couple of questions related to
> the problem.
>
> Is there a way to dynamically allocate arrays ( varying size) ?
> Specifically, this is what I am trying to do.
>
> #1
>
> I have a station database. This "string" array contains details
> pertaining to all the stations (names,locations,code etc.). Let's call
> this NAMELIST 'A'
>
> #2
>
> Now, I made a list of stations I want to look at from the above
> database. Let's call this NAMELIST 'B'
>
> #3
>
> The list of stations provided to me (NAMELIST 'C') may or may not
> contain all the stations in namelist 'B'
>
> #4
>
> I make a 1-1 string match between namelists 'B' and 'C' and extract
> only those stations that are present in B and C, and order C similar to
> B (user defined non-alphabetic)
>
> #5
>
> Problem is: I know the dimensions of the string array 'B' because I get
> to choose the stations I want from the original big database. Now, I
> don't know the dimensions of 'C' because it is variable, it may have
> same dimensions as B or less than B or none at all and the order might
> vary. Since, it can "ALSO" have same dimensions of B (max possible
> dimension), I define
>
> C=strarr(n_elements(B))
>
> But when the dimensions are less than that in B, there are elements
> with 'strlen' equal to zero. For example, C[3] maybe empty and may be
> C[7] and all other elements of the array may be filled.. I want to get
> rid of these trailing/beginning/in between empty (zero length) elements
> (I know this is because of the above declaration)
> and make this array to have dimensions = # of non-zero elements
>
> Is there a way to tackle such situations? I tried to index and
> increment the # of non-zero elements and redeclare the dimensions of C
> to be # of non-zero elements.. But it didn't work.. Meanwhile, I will
> try to modify your code to see if it works for my need.
>
> I appreciate your time and help!
> Thanks much,
> ~rk
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: path to .sav file
Next Topic: Re: Retrieving the title of a widget_base after the fact.

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

Current Time: Fri Oct 10 23:10:39 PDT 2025

Total time taken to generate the page: 0.80139 seconds