title: pack/compress netcdf data ("add offset" and "scale factor") with CDO, NCO or similar
body: <p>I have heavy netCDF files with floating 64-bits precision. I would like to pack using specific values for the <code>add_offset</code> and <code>scale_factor</code> parameters (so then I could transform to short I16 precision). I have found information for unpacking with CDO operators but not for packing.</p>
  <p>Any help? Thank you in advance!</p>
  <p>Edit:</p>
  <pre><code>diego@LAcompu:~/new$ ncks -m in.nc
  netcdf in {
    dimensions:
      bnds = 2 ;
      lat = 202 ;
      lon = 62 ;
      time = UNLIMITED ; // (15777 currently)
  
    variables:
      float lat(lat) ;
        lat:standard_name = &quot;latitude&quot; ;
        lat:long_name = &quot;latitude&quot; ;
        lat:units = &quot;degrees_north&quot; ;
        lat:axis = &quot;Y&quot; ;
  
      float lon(lon) ;
        lon:standard_name = &quot;longitude&quot; ;
        lon:long_name = &quot;longitude&quot; ;
        lon:units = &quot;degrees_east&quot; ;
        lon:axis = &quot;X&quot; ;
  
      double t2m(time,lat,lon) ;
        t2m:long_name = &quot;2 metre temperature&quot; ;
        t2m:units = &quot;Celsius&quot; ;
        t2m:_FillValue = -32767. ;
        t2m:missing_value = -32767. ;
  
      double time(time) ;
        time:standard_name = &quot;time&quot; ;
        time:long_name = &quot;time&quot; ;
        time:bounds = &quot;time_bnds&quot; ;
        time:units = &quot;hours since 1900-01-01 00:00:00.0&quot; ;
        time:calendar = &quot;gregorian&quot; ;
        time:axis = &quot;T&quot; ;
  
      double time_bnds(time,bnds) ;
  } // group /
  diego@LAcompu:~/new$ ncap2 -v -O -s 't2m=pack_short(t2m,0.00166667,0.0);' in.nc out.nc
  ncap2: WARNING pack_short(): Function has been called with more than one argument
  diego@LAcompu:~/new$ ncks -m out.nc
  netcdf out {
    dimensions:
      lat = 202 ;
      lon = 62 ;
      time = UNLIMITED ; // (15777 currently)
  
    variables:
      float lat(lat) ;
        lat:standard_name = &quot;latitude&quot; ;
        lat:long_name = &quot;latitude&quot; ;
        lat:units = &quot;degrees_north&quot; ;
        lat:axis = &quot;Y&quot; ;
  
      float lon(lon) ;
        lon:standard_name = &quot;longitude&quot; ;
        lon:long_name = &quot;longitude&quot; ;
        lon:units = &quot;degrees_east&quot; ;
        lon:axis = &quot;X&quot; ;
  
      short t2m(time,lat,lon) ;
        t2m:scale_factor = -0.000784701646794361 ;
        t2m:add_offset = -1.01787074416207 ;
        t2m:_FillValue = -32767s ;
        t2m:long_name = &quot;2 metre temperature&quot; ;
        t2m:missing_value = -32767. ;
        t2m:units = &quot;Celsius&quot; ;
  
      double time(time) ;
        time:standard_name = &quot;time&quot; ;
        time:long_name = &quot;time&quot; ;
        time:bounds = &quot;time_bnds&quot; ;
        time:units = &quot;hours since 1900-01-01 00:00:00.0&quot; ;
        time:calendar = &quot;gregorian&quot; ;
        time:axis = &quot;T&quot; ;
  } // group /
  </code></pre>