Re: Selecting odd/even numbered files [message #30057 is a reply to message #29974] |
Wed, 03 April 2002 12:06  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Wayne Landsman (landsman@mpb.gsfc.nasa.gov) writes:
> A minor footnote to the little program: In IDL V5.3 or later, the 5 lines
>
> numbers = IntArr(N_Elements(files))
> FOR j=0,N_Elements(files)-1 DO BEGIN
> stringpart = StrMid(files[j], 5, 3)
> numbers[j] = Fix(stringpart)
> ENDFOR
>
> can be replaced by the single vectorized line:
>
> numbers = fix(strmid(files,5,3))
Humm. That is what I wrote originally, but I kept getting
the wrong thing. I had already wasted too much time
on this, so I didn't follow up to see *why* it didn't
work. I was expecting an array of 4 elements, and the
numbers kept coming out as 4x4 arrays. :-(
Of course, now I substitute this in my code and it
works perfectly. :-(
I think what I was doing in my original code (before
I cleaned it up to send to the newsgroup, and yes I
*know* I could have cleaned it up even more) was trying
to make it even more general. I had something like this:
slen = StrLen(files)
IF Keyword_Set(even) THEN BEGIN
numbers = fix(strmid(files,slen-5,3))
index = Where(numbers MOD 2 EQ 0, count)
IF count GT 0 THEN RETURN, files[index] ELSE RETURN, ""
ENDIF
where I was trying to use the slen array to select a different
length for each possible filename (assuming they weren't
all the same length, but that they all had 3 character
extensions). In that case, the numbers variable kept
coming out as a 4x4 element array, rather than the expected
4-element array.
So, although these things have been made *slightly*
more vectorizable (is that a word?), they are not
totally there yet.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|