I have a netCDF file FORCING.nc
which contains a variable time
with attribute value units: hours since 2007-12-28 22:00:00
. In python code, it is as following:
from netCDF4 import Dataset
Dataset('FORCING.nc')["time"]
and the output is:
Out[3]:
<class 'netCDF4._netCDF4.Variable'>
float32 time(time)
units: hours since 2007-12-28 22:00:00
unlimited dimensions:
current shape = (13,)
filling on, default _FillValue of 9.969209968386869e 36 used
And I want to change the attribute of units
from hours since 2007-12-28 22:00:00
to hours since 1996-01-01 22:00:00
. And 1996-01-01 22:00:00
comes from a variable $start_date
in bash script.
So I want to use something like:
ncatted -a units,time,o,c,'hours since '$start_date FORCING.nc
which gives the argument 'hours since ' $start_date
to then catted command, indeed it is 'hours since 1996-01-01 22:00:00'
. But I got the error message like:
ncatted: ERROR file start_date not found. It does not exist on the local filesystem, nor does it match remote filename patterns (e.g., http://foo or foo.bar.edu:file).
ncatted: HINT file-not-found errors usually arise from filename typos, incorrect paths, missing files, or capricious gods. Please verify spelling and location of requested file. If the file resides on a High Performance Storage System (HPSS) accessible via the 'hsi' command, then add the --hpss option and re-try command.
I guess it is because there is space between "hours since 2007-12-28" and "22:00:00". If I use ncatted -a units,time,o,c,'hours since 2007-12-28 22:00:00' FORCING.nc
, it works fine. But how can I use $start_date
? because start_date
varies each time I run the code...
Thanks!
CodePudding user response:
You're close! Try
ncatted -a units,time,o,c,'hours since '"$start_date" FORCING.nc
Shell quoting rules. Can't live with 'em, can't live without 'em.