Re: looping over a series of separate files

From: Kyle Griffin <ksgriffin2_at_nyahnyahspammersnyahnyah>
Date: Mon Jan 27 2014 - 10:52:03 MST

Hi Ioana,

In general, you will always be able to add an array of files via the
addfiles command:

http://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml

I've put together a couple of lines below that should get you started in
the correct direction (although I haven't tested it).

model_num = ispan(1,5,1)
file_path = "amoc_Cont"+model_num+".nc"
f = addfiles(filepath,"r")

At this point, f will be an array of size 5 with each file name at f[0],
f[1], etc. Note the use of brackets [..] and NOT parenthesis (..) in your
variable created by addfiles.

Kyle

----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
Room 1421
1225 W Dayton St, Madison, WI 53706
Email: ksgriffin2@wisc.edu

On Mon, Jan 27, 2014 at 11:41 AM, Ioana Colfescu <colfescu@cola.iges.org>wrote:

> Hi,
>
> I want to apply a series commands to every series of files ( X series of
> files in total),that are in different directories and nothing to do with
> each other.
>
> Using NCL and shell script is like :
> foreach model ( 1 2 3 4 5 )
> cat << EOR > tmp.ncl
> begin
> f=addfile("amoc_Cont${model}.nc","r")
> moc5=f1->AMOC
> ....
> end
> EOR
> ncl tmp.ncl
> end
>
> But in this I keep the files/data separate and I use cshell too.
> My question is, if I want to do this just inside NCL and have all data
> together (and not just write by hand f1=addgfile1,f2=addfile2 etc)
> what's the syntax/way to do it in NCL ?.
> More exactly how do I create a loop that is something like
>
> do i=1,6
> f(i)=addfile("amoc_Cont(i).nc","r")
> ...
> end
>
> The syntax I tried didn't work.
>
> Thanks,
> Ioana
>
> _______________________________________________
> 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 Mon Jan 27 10:52:33 2014

This archive was generated by hypermail 2.1.8 : Fri Feb 07 2014 - 16:39:11 MST