NCO:用包含空白的新字符串更改变量的属性值 space

NCO: change the attribute value of variable with a new string containing blank space

我有一个 netCDF 文件 FORCING.nc,其中包含一个属性值为 units: hours since 2007-12-28 22:00:00 的变量 time。在python代码中,如下:

from netCDF4 import Dataset
Dataset('FORCING.nc')["time"]

输出为:

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

我想将 units 的属性从 hours since 2007-12-28 22:00:00 更改为 hours since 1996-01-01 22:00:001996-01-01 22:00:00 来自 bash 脚本中的变量 $start_date

所以我想使用类似的东西:

ncatted -a units,time,o,c,'hours since '$start_date FORCING.nc

将参数 'hours since '+$start_date 提供给 catted 命令,实际上它是 'hours since 1996-01-01 22:00:00' 。但我收到如下错误消息:

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.

我猜这是因为“自 2007 年 12 月 28 日以来的小时数”和“22:00:00”之间有 space。如果我使用 ncatted -a units,time,o,c,'hours since 2007-12-28 22:00:00' FORCING.nc,它工作正常。但是如何使用 $start_date 呢?因为 start_date 每次我 运行 代码都不同...

谢谢!

你很接近!尝试

ncatted -a units,time,o,c,'hours since '"$start_date" FORCING.nc

Shell 引用规则。不能和他们一起生活,不能没有他们。