[ncl-talk] netcdf file compression

Douglas Lowe Douglas.Lowe at manchester.ac.uk
Thu Sep 6 10:40:13 MDT 2018


Hi Dave,

Thanks for the suggestion. It didn’t help with adding this before opening the file to write, but it made me look again at the documentation,
as well as some of the warning messages NCL was giving me, and I realised that setting these file options only works when creating 
a file (they can’t be changed after a file has been created). So I’ve now switched to this code, and when I reopen the file for writing again 
later it works as intended.

setfileoption("nc","format","netcdf4")
setfileoption("nc","CompressionLevel",4)
file_chem   = addfile(filename+".nc", “c”)

cheers,
Doug



> On 4 Sep 2018, at 19:48, Dave Allured - NOAA Affiliate <dave.allured at noaa.gov> wrote:
> 
> Doug,
> 
> When creating a new netcdf-4 file, the "format" option must be globally selected *before* the addfile command.  This is documented on the setfileoption doc page under "format", but it is obscure.  Try rearranging your script like this:
> 
>     setfileoption ("nc","Format","NetCDF4")
>     file_chem = addfile (filename+”.nc", "w")
>     setfileoption (file_chem,"CompressionLevel",4)
> 
> Example 5 at the bottom of the same page also talks about this.
> 
> --Dave
> 
> 
> On Tue, Sep 4, 2018 at 8:11 AM, Douglas Lowe <Douglas.Lowe at manchester.ac.uk> wrote:
> Dear all,
> 
> I’m trying to use the file compression option listed on this manual page:
> https://www.ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml
> 
> This is my code:
> file_chem   = addfile(filename+”.nc", "w")
> setfileoption(file_chem,"Format","NetCDF4")
> setfileoption(file_chem,"CompressionLevel",4)
> 
> However, I am not finding that there’s any extra compression of the data compared to
> using the default compression level - and if I compress the file myself using nccopy
> I find I can greatly compress the file (5Mb down to 50kb).
> 
> Have I missed any extra code that I should be adding (my variable processing / writing
> code is the same as I’d use for netcdf3 files) to make this compression work?
> 
> thanks,
> Doug
> _______________________________________________
> 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