Re: Loop over files variables in list

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 23 2011 - 12:30:20 MST

Just to add a bit to this discussion for anyone interested, there is an as yet undocumented function in NCL 6.0.0 and later called "ListCount" that will give you the number of elements in any list type variable directly. This allows the loop in Dennis' code to be written as

do nf = 0, ListCount(f) -1
  x = f[n]->WIND
end do

 -dave

On Nov 23, 2011, at 7:37 AM, Dennis Shea wrote:

> ;=================================================;
> ; Read all file names in directory
> ;=================================================;
> diri = "./" ; input directory
> fili = systemfunc("cd "+diri+" ; ls foo*nc")
> print(fili) ; all file names
> nfili = dimsizes(fili)
> ;=================================================;
> ; Establish list of all possible files; *no* reading is done
> ; 'f' is a variable of type 'list'; index via [...]
> ;=================================================;
> f = addfiles(diri+fili, "r")
>
> do nf=0,nfili-1
> x = f[n]->WIND
>
> end do
>
> ######
>
> alternatively, do a standard loop
>
> do nf=0,nfili-1
> f = addfile(diri+fili(nf), "r")
> x = f->WIND
>
> end do
>
>
> On 11/23/11 3:01 AM, Davis, Neil wrote:
>> I am trying to write a routine which needs to loop over a file list
>> created by addfiles. Running the command dimsizes on the list returns a
>> value of 1 no matter how many elements are in the list. I see when I use
>> printVarSummary that there is a variable output as Total Items which
>> gives the correct number of items in the list.
>>
>> Is there any NCL function which would allow me to obtain that value or
>> provide another method to loop over the files in the list.
>>
>> Thank you,
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Nov 23 12:30:26 2011

This archive was generated by hypermail 2.1.8 : Wed Nov 23 2011 - 16:46:19 MST