[ncl-talk] read and write netcdf-4 compressed files
David Brown
dbrown at ucar.edu
Fri Feb 5 14:37:26 MST 2016
Hi Dan,
The problem is a dimension mismatch. I am not sure why it does not get
reported as such, but here is the issue:
Your call to wrf_user_getvar asks for time step 0, granted the only
time step since the Time dimension has only 1 element. But the result
is that the return variable 'bb' is reduced from 4 dimensions (t,
z,y,x) in the file variable to 3 (z,y,x) in the local variable.
Then you are trying to assign this 3d variable to a 4d variable in the
file. This causes the error.
There are two ways to fix it.
1) Substitute -1 for 0 in the 3rd argument to wrf_user_getvar. You
will then get Time as the leftmost dimension of a 4d variable, and the
write can proceed without error.
2) Or leave the wrf_user_getvar call alone. You can write the 3d local
variable into the 4d file variable by subscripting the left hand side
of the assignment:
in->PM2_5_DRY(0,:,:,:) = (/bb/)
We will look into why this is not caught earlier with a more apropos
"dimension mismatch" error to avoid the trip into the NetCDF library
code and the resulting low-level error messages.
-dave
On Thu, Feb 4, 2016 at 8:16 PM, Dan Chen <dchen at ucar.edu> wrote:
> Hi,
>
> My name is Dan Chen working at MMM, NCAR. I'm using ncl to read a variable
> and write into the netcdf-4 compressed file on Yellowstone, but failed.
>
> The script is as blow:
> ========================================
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT//lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
>
> begin
>
> fils = "/glade/scratch/dchen/ncl_netcdf4/analysis.ensmean"
> in = addfile(fils,"w")
> bb = wrf_user_getvar(in,"PM2_5_DRY",0)
> bb = bb*10
> fils->PM2_5_DRY = (/bb/)
>
> end
> ==========================================
>
>
> The error is as below
> =========================
> Copyright (C) 1995-2015 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.3.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> fatal:["NclNetCDF4.c":3073]:NclNetCDF4.c: Error in nc_def_var_chunking in
> file (/glade/scratch/dchen/ncl_netcdf4/analysis.ensmean) for writing, at
> line: 3073
>
> line 3074 of NclNetCDF4.c: NetCDF: Attempt to define var properties, like
> deflate, after enddef.
> ============================
>
>
> If I change the input file to a normal netcdf file without the compression
> option, it works fine. But I do need to process those netcdf-4 compressed
> files. Can you let me know if there is anything I can try?
>
> Many thanks,
> Dan
>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
More information about the ncl-talk
mailing list