Re: syntax of reading netCDF4 files with groups

From: Wenshan Wang <wenshanw_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 04 2013 - 16:32:34 MST

The version of NCL I am using is: 6.1.0-08Oct2012_1119

I've put my sample file on the ftp:
incoming/snd_LImon_all-model_historical_all-ens_GN_monthly-anomaly.nc

Thank you!

Best,
Wenshan

On Fri, Jan 4, 2013 at 3:15 PM, Wenshan Wang <wenshanw@uci.edu> wrote:

> Dear all,
>
> I am trying to read netCDF4 files with groups, following the example given
> on the page of 'getfilegrpnames'.
> Here it is:
>
> f = *addfile* <http://www.ncl.ucar.edu/Document/Functions/Built-in/addfile.shtml> ("X.nc" , "r") ; could also have ccm, grb or hdf suffux
> gNames = *getfilegrpnames* (f) ; get names of all groups on file
>
> nNames = *dimsizes* <http://www.ncl.ucar.edu/Document/Functions/Built-in/dimsizes.shtml> (gNames) ; number of groups on the file
>
> *print* <http://www.ncl.ucar.edu/Document/Functions/Built-in/print.shtml> (nNames) ; print all group names on file
>
> do n=0,nNames-1 ; loop thru each group
> v = f->$gNames(n)$ ; read the group to memory
>
> dimv = *dimsizes* <http://www.ncl.ucar.edu/Document/Functions/Built-in/dimsizes.shtml>(v) ; dimension size of the group
> rank = *dimsizes* <http://www.ncl.ucar.edu/Document/Functions/Built-in/dimsizes.shtml>(dimv) ; rank [ie: number of dimensions]
>
> [SNIP]
>
> delete (v)
> delete (rank)
> end do
>
>
> However, if I followed the example and use:
>
> v = f->$gNames(n)$
>
> It will result in:
> fatal:["Execute.c":5709]:variable
> (snc_LImon_bcc-csm1-1_historical_all-ens_clm) is not in file (fin)
>
> Instead, if I use:
> gg = fin=>$gn(j)$
> dd = gg->$var(i)$
> It can read what I want, but there is an error message:
> fatal:NclNetCDF4: Could not reopen the file
> (~/data/cmip5/output/4plot/snd_LImon_all-model_historical_all-ens_clm.nc)
> for reading
>
> So, what syntax should I use to read variables in groups?
>
> Thank you very much!
> Happy New Year!
>
> Best,
> Wenshan
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jan 4 16:33:02 2013

This archive was generated by hypermail 2.1.8 : Mon Jan 07 2013 - 08:57:08 MST