Re: FindFile for more than one filetype [message #28575 is a reply to message #28572] |
Fri, 21 December 2001 01:42   |
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
|
|
|