Re: syntax of reading netCDF4 files with groups

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 04 2013 - 21:09:19 MST

Wenshan,

We have fixed the problem.
The fixes will be in the new release (6.1.1, coming soon).

Thanks,

Wei

huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924

On Jan 4, 2013, at 8:23 PM, Wei Huang wrote:

> Wenshan,
>
> There is a problem with getfilegrpnames, otherwise, the second script below will work.
>
> Mean while, you can use "ncl_filedump X.nc | grep group" to get the group names.
>
> Then use script:
> f = addfile ("X.nc" , "r") ; could also have ccm, grb or hdf suffux
>
> ;(0) snd_LImon_ACCESS1-0_historical_all-ens_GN_monthly_anomaly
> ;(1) snd_LImon_CCSM4_historical_all-ens_GN_monthly_anomaly
> ;(2) snd_LImon_CESM1-CAM5_historical_all-ens_GN_monthly_anomaly
> ;(3) snd_LImon_CESM1-FASTCHEM_historical_all-ens_GN_monthly_anomaly
> ;(4) snd_LImon_CESM1-WACCM_historical_all-ens_GN_monthly_anomaly
> ;(5) snd_LImon_CMCC-CM_historical_all-ens_GN_monthly_anomaly
> ;(6) snd_LImon_CMCC-CMS_historical_all-ens_GN_monthly_anomaly
> ;(7) snd_LImon_CSIRO-Mk3-6-0_historical_all-ens_GN_monthly_anomaly
>
> gn = "snd_LImon_ACCESS1-0_historical_all-ens_GN_monthly_anomaly"
>
> g = f=>$gn$ ; read the group to memory
>
> printVarSummary(g)
>
> vNames = getfilevarnames (g) ; get names of all groups on file
> nvNames = dimsizes (vNames) ; number of vars in the group
>
> print (nvNames) ; print number of variables in group
> print (vNames) ; print variable name in group
>
> do m=0,nvNames-1
> print("===========================================================")
> print("Variable Number: " + m)
> v = g->$vNames(m)$ ; read the variable to memory
> printVarSummary(v)
> delete(v)
> end do
>
> to read variables.
>
> We are working on getfilegrpnames, and hope to fix it soon.
>
> Regards,
>
> Wei
>
>
> huangwei@ucar.edu
> VETS/CISL
> National Center for Atmospheric Research
> P.O. Box 3000 (1850 Table Mesa Dr.)
> Boulder, CO 80307-3000 USA
> (303) 497-8924
>
>
> -------------
> f = addfile ("X.nc" , "r") ; could also have ccm, grb or hdf suffux
>
> ;print(f)
>
> gNames = getfilegrpnames (f) ; get names of all groups on file
> ngNames = dimsizes (gNames) ; number of groups on the file
>
> print (ngNames) ; print number of group names on file
> print (gNames) ; print group names on file
>
> do n=0,ngNames-1 ; loop thru each group
> print("--------------------------------------------------------")
> print("Group Number: " + n)
>
> g = f=>$gNames(n)$ ; read the group to memory
>
> printVarSummary(g)
>
> vNames = getfilevarnames (g) ; get names of all groups on file
> nvNames = dimsizes (vNames) ; number of vars in the group
>
> print (nvNames) ; print number of variables in group
> print (vNames) ; print variable name in group
>
> do m=0,nvNames-1
> print("===========================================================")
> print("Variable Number: " + m)
> v = g->$vNames(m)$ ; read the variable to memory
> printVarSummary(v)
> delete(v)
> end do
>
> ;[SNIP]
>
> delete(g)
> end do
>
>
>
>
> On Jan 4, 2013, at 4:38 PM, Wei Huang wrote:
>
>> Wenshan,
>>
>> I'll check and get back to you.
>>
>> Thanks,
>>
>> Wei
>>
>> huangwei@ucar.edu
>> VETS/CISL
>> National Center for Atmospheric Research
>> P.O. Box 3000 (1850 Table Mesa Dr.)
>> Boulder, CO 80307-3000 USA
>> (303) 497-8924
>>
>>
>>
>>
>>
>>
>> On Jan 4, 2013, at 4:32 PM, Wenshan Wang wrote:
>>
>>> 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 ("X.nc" , "r") ; could also have ccm, grb or hdf suffux
>>> gNames = getfilegrpnames (f) ; get names of all groups on file
>>>
>>> nNames = dimsizes (gNames) ; number of groups on the file
>>>
>>> print (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(v) ; dimension size of the group
>>> rank = dimsizes(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
>>
>> _______________________________________________
>> 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 Fri Jan 4 21:09:34 2013

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