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

Home » Public Forums » archive » Re: Selecting odd/even numbered files
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: Selecting odd/even numbered files [message #29971] Wed, 03 April 2002 07:19 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Irene Dumkow (irene.dumkow@uni-essen.de) writes:

> 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.

Here is a little program that should do what you want it to
do:

************************************************************ **
FUNCTION PickSomeFiles, Filter=filter, EVEN=even, ODD=odd, Count=count

IF N_Elements(filter) EQ 0 THEN filter="*.ext"

files = FindFile(filter, Count=count)
slen = StrLen(files)

IF Keyword_Set(even) THEN BEGIN
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
index = Where(numbers MOD 2 EQ 0, count)
IF count GT 0 THEN RETURN, files[index] ELSE RETURN, ""
ENDIF

IF Keyword_Set(odd) THEN BEGIN
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
index = Where(numbers MOD 2 EQ 1, count)
IF count GT 0 THEN RETURN, files[index] ELSE RETURN, ""
ENDIF

RETURN, files
END
************************************************************ ***

You would call it like this. It assumes that all the files
in the directory will be named as you have described above,
with 8 characters in the first part of the file (last three
characters are digits), and a three character extension. The
program will have to be modified if that is not the case.

IDL> filenames = PickSomeFiles(Filter='*.txt', Count=count)
IDL> IF count GT 0 THEN Print, filenames
david001.txt david002.txt david003.txt david004.txt

To select even numbered files, set the EVEN keyword. To select
odd numbered files, set the ODD keyword.

Here is what my test session looked like:

IDL> print, picksomefiles(filter='*.txt',count=c) & print, c
david001.txt david002.txt david003.txt david004.txt
4
IDL> print, picksomefiles(/even)
david002.txt david004.txt

IDL> print, picksomefiles(/odd)
david001.txt david003.txt

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
[Message index]
 
Read Message
Read Message
Previous Topic: Re: analyze reader and writer in IDL?
Next Topic: Selecting odd/even numbered files

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

Current Time: Wed Oct 08 08:49:52 PDT 2025

Total time taken to generate the page: 0.00653 seconds