Re: Loops in filenames? [message #20086] |
Wed, 17 May 2000 00:00 |
Paul van Delst
Messages: 364 Registered: March 1997
|
Senior Member |
|
|
Bernard Puc wrote:
>
> Simon de Vet wrote:
>>
>> I have a number of text files, 'surfout.01', 'surfout.02' ...
>> 'surfout.12'.
>>
>> I can load any one of them into a 3-d array (model, longitude,
>> latitude). However, since each represents a different month, I would
>> like to put them all together into a 4-d array of (month, model,
>> longitude, latitude).
>>
>> The ackward method would be to just load each one in with its own little
>> code, changing the number each time. I know that there must be a better
>> way.
>>
>> Is it possible to load the files with a loop? I don't know where in the
>> help to look for such info, nor even where to start experimenting.
>
> ;To read a set of files
> filename = 'surfout.'
> EXT = ['01','02','03','04','05','06','07','08','09','10','11','12' ]
> for i = 0, 11 do begin
> openr,lun,/get_lun,filename+EXT[i]
> ;Read in values
> free_lun,lun
> endfor
Apologies for pickiness but wouldn't one prefer:
filename = 'surfout.'
for i = 0, 11 do begin
openr,lun,/get_lun,filename+STRING(i+1,FORMAT='(i2.2)')
;Read in values
free_lun,lun
endfor
?
It's a slow day....can you tell?
--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.202, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
|
|
|
Re: Loops in filenames? [message #20087 is a reply to message #20086] |
Wed, 17 May 2000 00:00  |
Steve Cox
Messages: 3 Registered: November 1999
|
Junior Member |
|
|
In article <3922D26B.FCBD39AF@mathstat.dal.ca>,
Simon de Vet <simon@mathstat.dal.ca> wrote:
> I'm a little embarrassed to admit that after puzzling over this all
> morning, I solved the problem about 10 minutes after posting my plea.
>
> The technique I'm using is nearly identical to that of David and
Bernard.
>
> Why is it that this ALWAYS happens? Must be another Zen thing...
It's not just the perverse humor of the universe that makes
this happen though. There's also the fact that coming up
with a concise way to describe one's problem clearly to others
is a giant first step toward solving it oneself anyway.
-Steve Cox
Sent via Deja.com http://www.deja.com/
Before you buy.
|
|
|
Re: Loops in filenames? [message #20088 is a reply to message #20086] |
Wed, 17 May 2000 00:00  |
Simon de Vet
Messages: 36 Registered: May 2000
|
Member |
|
|
Simon de Vet wrote:
> Is it possible to load the files with a loop? I don't know where in the
> help to look for such info, nor even where to start experimenting.
I'm a little embarrassed to admit that after puzzling over this all
morning, I solved the problem about 10 minutes after posting my plea.
The technique I'm using is nearly identical to that of David and Bernard.
Why is it that this ALWAYS happens? Must be another Zen thing...
Simon
|
|
|
Re: Loops in filenames? [message #20089 is a reply to message #20086] |
Wed, 17 May 2000 00:00  |
Bernard Puc
Messages: 65 Registered: January 1998
|
Member |
|
|
Simon de Vet wrote:
>
> I have a number of text files, 'surfout.01', 'surfout.02' ...
> 'surfout.12'.
>
> I can load any one of them into a 3-d array (model, longitude,
> latitude). However, since each represents a different month, I would
> like to put them all together into a 4-d array of (month, model,
> longitude, latitude).
>
> The ackward method would be to just load each one in with its own little
> code, changing the number each time. I know that there must be a better
> way.
>
> Is it possible to load the files with a loop? I don't know where in the
> help to look for such info, nor even where to start experimenting.
;To read a set of files
filename = 'surfout.'
EXT = ['01','02','03','04','05','06','07','08','09','10','11','12' ]
for i = 0, 11 do begin
openr,lun,/get_lun,filename+EXT[i]
;Read in values
free_lun,lun
endfor
--
Bernard Puc AETC, INC.
bpuc@va.aetc.com 1225 Jefferson Davis Highway #800
(703) 413-0500 Arlington, VA 22202
|
|
|
Re: Loops in filenames? [message #20090 is a reply to message #20086] |
Wed, 17 May 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Simon de Vet (simon@mathstat.dal.ca) writes:
> I have a number of text files, 'surfout.01', 'surfout.02' ...
> 'surfout.12'.
>
> I can load any one of them into a 3-d array (model, longitude,
> latitude). However, since each represents a different month, I would
> like to put them all together into a 4-d array of (month, model,
> longitude, latitude).
>
> The ackward method would be to just load each one in with its own little
> code, changing the number each time. I know that there must be a better
> way.
>
> Is it possible to load the files with a loop? I don't know where in the
> help to look for such info, nor even where to start experimenting.
I should think something like this might work:
files = Findfiles('surfout.*', Count=numFiles)
files = files[Sort(files)]
FOR j=0,numFiles-1 DO BEGIN
OpenR, lun, files[j], /Get_Lun
etc.
etc.
Free_Lun, lun
ENDFOR
Be sure to check the file names before you use
this code. Findfiles returns names in a strange order
sometimes. It seems almost random to me. You might
have to experiment with a better way to sort the
names if the order is important to you.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|