Sourish,
It turns out this is merely a usage problem. Your original ncap2 command
is missing an output file name, where one is required in this scenario.
Ncap2 is not allowed to add a new variable to the input file, if the format
is netcdf4. Please see the third paragraph in ncap2 documentation on line.
I was misled by inaccurate error messages from your older version of
ncap2. Sorry about the extra noise about alternate causes. It is ironic
that the latest ncap2 version 4.7.9 on my system gives a perfect diagnosis:
> ncap2 -L 6 -4 -h -A -sncap2 -L 6 -4 -h -A -s
'co2_flux_natural=3Dbio_flux_opt+fire_flux_imp+ocn_flux_opt' guineapig.nc
ncap2: ERROR No output file specified with netCDF4 input file. When no
output file is specified, ncap2 tries to write directly to the input file
but this can only work with netCDF3 not netCDF4 input files. Please specify
an output file distinct from the input file and re-try.
I think you can close the NCO bug report.
--Dave
On Mon, Mar 25, 2019 at 2:48 PM Sourish Basu <Sourish.Basu@xxxxxxxxxxxx>
wrote:
> Charlie,
>
> I've narrowed down the exact problem. It seems that ncap2 can append to
> an uncompressed file, or write a compressed variable to a new file, but
> cannot append to a file with compressed variables. I've filed a bug
> report with details at https://sourceforge.net/p/nco/bugs/111/.
>
> -Sourish
>
> On 3/25/19 8:31 AM, Charlie Zender wrote:
> > Souresh,
> >
> > See http://nco.sf.net#help for NCO issues.
> >
> > FWIW, this command works fine for me with your file:
> >
> > ncap2 -L 6 -4 -h -A -s
> > 'co2_flux_natural=bio_flux_opt+fire_flux_imp+ocn_flux_opt'
> > guineapig.nc foo.nc
> >
> > The -A is superfluous, and perhaps you omitted the output filename.
> > If not, please move this thread to the site above.
> >
> > Charlie
>