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

Home » Public Forums » archive » Re: FindFile for more than one filetype
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
Re: FindFile for more than one filetype [message #28571] Fri, 21 December 2001 09:41
James Kuyper Jr. is currently offline  James Kuyper Jr.
Messages: 10
Registered: November 2001
Junior Member
Sue wrote:

> "Richard Tyc" <richt@sbrc.umanitoba.ca> wrote in message news:<9vtjoa$mmt$1@canopus.cc.umanitoba.ca>...
>
>>> for yr = 1981, 2000 do begin
>>>
>>
>> How about something real simple like this to replace AND:
>>

>> filelist = FINDFILE(outpath + string(yr, FORMAT = '(I4.4)')
>> + '*'+ '_average.int', COUNT=filecount)
>> if filecnt NE 1 then break;

Change to:

if filecount NE 1 then break;
totalcnt = filecount

>>
>> filelist = [ filelist, FINDFILE(outpath + string(yr+1, FORMAT = '(I4.4)')
>> + '*'+ '_average.int', COUNT=filecount) ]
>> if filecnt NE 1 then break;

Change to:

if filecount NE 1 then break;
totalcnt = totalcnt + filecount;

>>
>>
>>> endfor
>>
>> Rich
>
> ---------
> I tried this and for some reason the filecount still equals 1, instead
> of 2. Interestingly enough, when I print filelist...I do get two
> files. Any ideas?
> --Sue

With the given changes, filecount will still be 1, but totalcnt will now
have the value of 2, as you expected.
Re: FindFile for more than one filetype [message #28572 is a reply to message #28571] Fri, 21 December 2001 08:09 Go to previous message
sargum_manley is currently offline  sargum_manley
Messages: 2
Registered: December 2001
Junior Member
"Richard Tyc" <richt@sbrc.umanitoba.ca> wrote in message news:<9vtjoa$mmt$1@canopus.cc.umanitoba.ca>...
>> for yr = 1981, 2000 do begin
>>
> How about something real simple like this to replace AND:
>
> filelist = FINDFILE(outpath + string(yr, FORMAT = '(I4.4)')
> + '*'+ '_average.int', COUNT=filecount)
> if filecnt NE 1 then break;
>
> filelist = [ filelist, FINDFILE(outpath + string(yr+1, FORMAT = '(I4.4)')
> + '*'+ '_average.int', COUNT=filecount) ]
> if filecnt NE 1 then break;
>
>> endfor
>
> Rich
---------
I tried this and for some reason the filecount still equals 1, instead
of 2. Interestingly enough, when I print filelist...I do get two
files. Any ideas?
--Sue
Re: FindFile for more than one filetype [message #28575 is a reply to message #28572] Fri, 21 December 2001 01:42 Go to previous message
Martin Downing is currently offline  Martin Downing
Messages: 136
Registered: September 1998
Senior Member
> Sue wrote:
>>
>> filelist = FINDFILE(outpath + string(yr, FORMAT = '(I4.4)')
>> + '*'+ '_average.int', COUNT=filecount)
>> and
>> FINDFILE(outpath + string(yr+1, FORMAT = '(I4.4)')+ '*'
>> + '_average.int', COUNT=filecount)
>>
>> trying to use the "AND" here gives me an error about how strings can
>> not be used in this way or something but I left the code up here so
>> that the concept of what I want to achieve is clear.
>>

Hi Sue,
You were close, but since findfile returns a single string or a sting array
for multiple files, what you want to do is add the two result together into
a composite string array:
ie: composite_result = [result1, result2]

filelist = [FINDFILE(outpath + string(yr, FORMAT = '(I4.4)') +
'*_average.int', COUNT=filecount1), $
FINDFILE(outpath + string(yr+1, FORMAT = '(I4.4)')+
'*_average.int', COUNT=filecount2)]

then test filecount1 and filecount2 seperately for your error checking:

if (filecount1 ne 1) and (filecount2 ne 1) then message, "one or more
files missing" ; or whatever

cheers

Martin

> "Paul van Delst" <paul.vandelst@noaa.gov> wrote in message
news:3C22528E.AFE25B1B@noaa.gov...
> Why not do:
>
> ; -- Get the list of all the files you want
> all_files = FINDFILE( outpath + '*_average.int', COUNT = n_files )
>
> ; -- Set the start year
> start_year = 1981L
>
> ; -- Loop over blocks of two files
> FOR i = 0L, n_files - 2L DO BEGIN
>
> ; -- Indices for the two files you want
> index = [ i, i+1 ]
>
> ; -- Years for the two files you want
> year = LONG( index ) + start_year
>
> ; -- Pluck 'em out
> filelist = all_files[ index ]
>
> ; -- Do stuff with 'em
> ......
>
> ENDFOR
>
> Will this work? The files should be in the correct order since their
prefix is the year number
> - but you might want to do a sort anyway to check before you enter the
loop. You can also
> extract out the year from the file name string if needs be but adding the
index seems to be
> easier.
>
> paulv

Paul,

I agree you should do a sort, but the potential weakness of this method is
that it assumes the file list is both complete and does not contain any
extra files. For instance, if year 1982 was missing, 1981 would be grouped
with 1983. Also , if someone has inserted 1982a_average.int into the
directory then there will similarly be problems.

Martin
Re: FindFile for more than one filetype [message #28578 is a reply to message #28575] Thu, 20 December 2001 13:05 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Sue wrote:
>
> Hello,
>
> I have a folder full of *_average.int files where the * represents
> different years (1981-2000).
>
> I am trying to make it so that my variable, filelist, equals two
> files: (1)1981_average.int and (2)1982_average.int and then the next
> time, filelist equals: (1)1982_average.int and (2)1983_average.int and
> so on. It is also important that I get the filecount to equal 2.
>
> However, I can not figure out how to do it using the FindFile function
> using the IDL language.
>
> This is what I have so far...(of course there is other stuff in btwn)
>
> for yr = 1981, 2000 do begin
>
> filelist = FINDFILE(outpath + string(yr, FORMAT = '(I4.4)')
> + '*'+ '_average.int', COUNT=filecount)
> and
> FINDFILE(outpath + string(yr+1, FORMAT = '(I4.4)')+ '*'
> + '_average.int', COUNT=filecount)
>
> endfor
>
> trying to use the "AND" here gives me an error about how strings can
> not be used in this way or something but I left the code up here so
> that the concept of what I want to achieve is clear.
>
> Thanks.
> Sue

Why not do:

; -- Get the list of all the files you want
all_files = FINDFILE( outpath + '*_average.int', COUNT = n_files )

; -- Set the start year
start_year = 1981L

; -- Loop over blocks of two files
FOR i = 0L, n_files - 2L DO BEGIN

; -- Indices for the two files you want
index = [ i, i+1 ]

; -- Years for the two files you want
year = LONG( index ) + start_year

; -- Pluck 'em out
filelist = all_files[ index ]

; -- Do stuff with 'em
......

ENDFOR

Will this work? The files should be in the correct order since their prefix is the year number
- but you might want to do a sort anyway to check before you enter the loop. You can also
extract out the year from the file name string if needs be but adding the index seems to be
easier.

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
Re: FindFile for more than one filetype [message #28579 is a reply to message #28578] Thu, 20 December 2001 13:03 Go to previous message
Richard Tyc is currently offline  Richard Tyc
Messages: 69
Registered: June 1999
Member
> for yr = 1981, 2000 do begin
>
How about something real simple like this to replace AND:

filelist = FINDFILE(outpath + string(yr, FORMAT = '(I4.4)')
+ '*'+ '_average.int', COUNT=filecount)
if filecnt NE 1 then break;

filelist = [ filelist, FINDFILE(outpath + string(yr+1, FORMAT = '(I4.4)')
+ '*'+ '_average.int', COUNT=filecount) ]
if filecnt NE 1 then break;

> endfor

Rich
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Pointer syntax and IDL 4.0: summary
Next Topic: Wiener filter

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

Current Time: Wed Oct 08 13:40:08 PDT 2025

Total time taken to generate the page: 0.00655 seconds