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

Home » Public Forums » archive » Re: Looping code for proccessing multiple 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: Looping code for proccessing multiple files [message #78525 is a reply to message #78523] Wed, 30 November 2011 12:44 Go to previous messageGo to previous message
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Nov 30, 12:09 pm, Rick Walton <r.d.wal...@leeds.ac.uk> wrote:
> Hi,
>
> I'm very new to this game but would be grateful for some advice on
> applying a simple process to multiple files.
>
> See below for my code so far.  The problem I am encountering is that
> the routine will not run through the second for loop and attempts to
> repeat the first for loop over and over on the first file that it
> reads.  Funnily enough, at first I accidentally used 'i' in both for
> loops and this enabled both for loops to run but with the second
> expression in the second for loop limited to the second expression in
> the first for loop.
>
> Please can anyone offer any help with this?
>
>  N = N_ELEMENTS(FINDFILE('*Norm.var'))
>          PRINT, 'Number of files: ', N
>
>          myfile_array = FINDFILE('*Norm.var')
>
>          FOR i = 0, N-1 DO BEGIN
>                 mv = readvar(myfile_array(i), /sr)          ;Reads
> input file
>         PRINT, myfile_array(i)
>
>         mv2 = fltarr(31,31,252)                        ;Creates new array
>
>         FOR j=0,251 do begin mv2(*,*,j)=avg(mv(4:35,4:35,j))         ;Takes
> the average of region between co-ordinates 4 and 35 in x and y axes
>
>         savevar, STRSUBST(myfile_array(i), '\\Norm.var', 'Norm Avg C1.var'),
> mv2, /sr
>                                           ;Saves new file (mv2) with
> file name adapted from original file name
>
>         ENDFOR
>           ENDFOR
> END

First of all, as another poster commented already, SAVEVAR should not
be inside the second loop. (I assume READVAR, SAVEVAR and STRSUBST are
user defined functions that do what they should.) Second, why is there
a user defined function AVG for averaging? IDL already contains a
function MEAN to do that.

Apart from that, this code looks like 20-year old IDL code. It will
not even run on IDL 8.0 and newer (or maybe with a compile option for
backwards compability?) due to use of () instead of [] for array
access. () was deprecated already in IDL 5.0 about 15 years ago... The
function FINDFILE was also deprecated in IDL 5.5 about 10 years ago,
but still works. Use FILE_SEARCH instead.

--
Yngvar
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: X window requirement for batch jobs: not just for plotting
Next Topic: 3D view of DEM

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

Current Time: Thu Oct 09 23:19:30 PDT 2025

Total time taken to generate the page: 1.03697 seconds