Re: syntax of reading netCDF4 files with groups

From: Wenshan Wang <wenshanw_at_nyahnyahspammersnyahnyah>
Date: Sat Jan 05 2013 - 13:11:47 MST

Dear Dr. Huang and friends,

I found that if I only read one group from one file. It will be OK using
Dr. Huang's scripts.
But if I tried to read the second group of the file. The message
"fatal:NclNetCDF4: Could not reopen the file
(~/data/cmip5/output/4plot/snd_LImon_all-model_historical_all-ens_GN_monthly-anomaly.nc)
for reading" will show again.

NCL version: 6.1.0;
Sample file has been uploaded to the ftp:
incoming/snd_LImon_all-model_historical_all-ens_GN_monthly-anomaly.nc

The script I used is as follow:
dir = "~/data/cmip5/output/4plot/"
fn = "snd_LImon_all-model_historical_all-ens_GN_monthly-anomaly.nc"
fin = addfile(dir+fn,"r")

gn1 = "snd_LImon_CCSM4_historical_all-ens_GN_monthly_anomaly"
gg1 = fin=>$gn1$
dd1 = gg1->snd
printVarSummary(dd1)
printMinMax(dd1,True)
print(dd1)

gn2 = "snd_LImon_CSIRO-Mk3-6-0_historical_all-ens_GN_monthly_anomaly"
gg2 = fin=>$gn2$
dd2 = gg2->snd
printVarSummary(dd2)
printMinMax(dd2,True)
print(dd2)

================================================================
Moreover, it seems the content of variable is not the same as that ncdump
gives me.
Much smaller.
I used 'ncdump -v snd
snd_LImon_all-model_historical_all-ens_GN_monthly-anomaly.nc'.

================================================================
When i use 'ncl_filedump -v snd
snd_LImon_all-model_historical_all-ens_GN_monthly-anomaly.nc', it will be
"Segmentation fault (core dumped)".

Thank you!

Best,
Wenshan

On Fri, Jan 4, 2013 at 8:09 PM, Wei Huang <huangwei@ucar.edu> wrote:

> 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* <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
>
>
> _______________________________________________
> 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 Sat Jan 5 13:12:18 2013

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