comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Looping code for proccessing multiple files

Re: Looping code for proccessing multiple files
type: item
description: Just curious, how do you know it doesn't run through the j loop? Also, why is SAVEVAR inside the loop?
creator: edward.s.meinel@aero.
date: 2011-11-30T14:23:06-00:00

Re: Looping code for proccessing multiple files
type: item
description: 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
creator: Yngvar Larsen
date: 2011-11-30T20:44:24-00:00

Re: Looping code for proccessing multiple files
type: item
description: Yngvar Larsen writes: > 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. I thought this was the normal way graduate students learn to program from their advisors. ;-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.idlcoyote.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2011-11-30T20:52:00-00:00