Selecting odd/even numbered files [message #29974] |
Wed, 03 April 2002 04:26  |
Irene Dumkow
Messages: 5 Registered: October 2000
|
Junior Member |
|
|
I have been writing an IDL routine to plot some of our data in a certain
way. The measuring programm saves the data using a given prefix, adding
a number starting from 001 until the user stops the measurement (eq
xxxxx001.ext to xxxxx323.ext). The measuring program can do different
kinds of measurements, but it will save the datafiles all in one
directory. But for the data-plotting, I sometimes only want to select
the odd or even numbers (for a start, the most ideal case would be to
give a starting value and an increment). I have been using
dialog_pickfile() for the fileselection, which is not suited for the
task on hand. I was wondering if somebody has written a routine which
does something like I want (selecting only even numbered or only odd
numbered files) or can give me some ideas, because I am completely
stumped on even how to get started.
Thanks in advance
Irene
|
|
|
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
|
|
|