Re: NetCDF addfile question

From: Nick Guy <nick.guy_at_nyahnyahspammersnyahnyah>
Date: Fri Nov 09 2012 - 16:39:30 MST

Hi Ping,

I'm no expert, but here is what I think I've figured out:
If you have a list of files (e.g. NetCDF) you can read a variable that exists in all those files such as below:

ListofFiles=systemfunc("ls /directory/path/containing/files/*")

fAll=addfiles(ListofFiles,"r")

Now you can set the list to concatenate into a one long array:
ListSetType(fAll,"cat")

Now read a named variable of that file:
AllData=fAll[:]->variable

Then you might use something like 'qsort' to change the order to increasing values:
qsort(AllData)

This should return the data sorted. It looks like it will only work for 1D variables, and does not return the indices. Maybe someone else has a more robust suggestion?

Nick Guy
nick.guy@noaa.gov

On Nov 9, 2012, at 3:22 PM, Ping Yang wrote:

> Dear NCL,
>
> I found this topic very interesting.
>
> Here I have questions, if I want to spatially stitch multiple files into one file, how can I do it? Can I create an array for one variable that take all this variable values and informations in difference files? Are there some functions to do this in NCL?
>
> Looking forward to hearing from you.
>
> Best,
>
> Ping
>
> On Fri, Nov 9, 2012 at 3:59 PM, David Brown <dbrown@ucar.edu> wrote:
> Hi Nick,
>
> It is true that you cannot get the global file attributes from the list variable that contains the aggregation of all the files. That is at least in part because the global attributes for each file will not necessarily have the same values, even if they form a logical sequence of files. Also until recently 'list' type variables did not support attributes. However, you do not have to open a particular file in a separate 'addfile' call to get the global attributes for any individual file. Rather than
>
> AttsAll=getvaratts(fAll)
>
> just use:
>
> AttsAll=getvaratts(fAll[0])
>
> Hope this helps.
> -dave
>
> On Nov 7, 2012, at 12:30 PM, Nick Guy wrote:
>
> > Hello,
> > I created NetCDF files recently and used the addfiles function to read a list. I was having trouble reading in the global attributes until I discovered that I had to only read one file at a time via addfile to be able to properly read global attributes. So just a general question: Anyone know why are the attributes not allowed to be read in the same way as variables for the different functions?
> >
> > I've pasted the snippet of code below that I help demonstrates what I am getting at.
> > ;=========================================
> > sondeList=systemfunc("ls "+fdir+"D20111122_*.nc")
> >
> > ; Read all NetCDF files
> > fAll=addfiles(sondeList,"r")
> >
> > file0=addfile(sondeList(0),"r")
> >
> > ListSetType(fAll,"join")
> >
> > AttsAll=getvaratts(fAll) ;; THIS RETURNS ONLY ONE MISSING FIELD
> > print(AttsAll)
> >
> > Atts0=getvaratts(file0) ;; THIS RETURNS THE GLOBAL ATTRIBUTES
> > print(Atts0)
> >
> > I was having trouble reading in the global attributes
> > ========================================
> > All the best,
> >
> > Nick Guy
> > nick.guy@noaa.gov
> >
> >
> >
> >
> > _______________________________________________
> > 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
>
>
>
> --
> Ping Yang, Ph.D.
> CUNY Environmental Crossroads Initiative
> Marshak Science Building - Suite 925
> The City College of New York - CUNY
> 160 Convent Avenue, New York NY 10031
> Phone: 212-650-5769
> Fax: 212-650-7064
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 9 16:39:43 2012

This archive was generated by hypermail 2.1.8 : Tue Nov 13 2012 - 14:27:24 MST