在具有多个 netCDF 文件的目录上同时执行 shell 和 cdo 操作

Simultaneous shell and cdo operations on a directory with multiple netCDF files

我有一个目录,我们称它为Simulation,目录中有许多文件夹,每个文件夹中都有一些 NetCDF 文件。

Simulation [Directory]:
       ----ACCESS [Folder]:
                  ------ Rootzone_ACCESS_rcp26_xyz.nc
                  ------ Rootzone_ACCESS_rcp45_xyz.nc
                  ------ Rootzone_ACCESS_rcp85_xyz.nc
       ----CCSM4 [Folder]:
                  ------ Rootzone_CCSM4_rcp45_xyz.nc
                  ------ Rootzone_CCSM4_rcp85_xyz.nc
       ----- [Other folders with NetCDF files]

我想对所有文件夹中的每个文件执行2次操作。操作定义如下。

#lets say test.nc is the each individual file
ncatted -O -a units,lon,c,c,"degrees_east" -a units,lat,a,c,"degrees_north" test.nc
# and I want to add '0.25res' at the end of each re-gridded file
cdo remapnn,r1440x720 test.nc test_0.25res.nc

最后,我想将所有重新网格化的文件存储在同一个“Simulation”目录中的不同文件夹(我们称该文件夹为 Regridded_0.25)。最终结果应如下所示。

Simulation [Directory]:
       ----ACCESS [Folder]:
                  ------ Rootzone_ACCESS_rcp26_xyz.nc
                  ------ Rootzone_ACCESS_rcp45_xyz.nc
                  ------ Rootzone_ACCESS_rcp85_xyz.nc
       ----CCSM4 [Folder]:
                  ------ Rootzone_CCSM4_rcp45_xyz.nc
                  ------ Rootzone_CCSM4_rcp85_xyz.nc
       ----- [Other folders with NetCDF files]

       -----Regridded_0.25 [Folder]:
                  ------ Rootzone_ACCESS_rcp26_xyz_0.25res.nc
                  ------ Rootzone_ACCESS_rcp45_xyz_0.25res.nc
                  ------ Rootzone_ACCESS_rcp85_xyz_0.25res.nc
                  ------ Rootzone_CCSM4_rcp45_xyz_0.25res.nc
                  ------ Rootzone_CCSM4_rcp85_xyz_0.25res.nc
                  ------ [Other NetCDF files]

有人可以帮我创建一个可以执行以下操作的 shell script 吗?我在shell中对大数据操作相当缺乏经验,但这会大大减少时间。非常感谢。

我终于在一次 shell 操作中做到了。

#!/bin/sh
for i in $(ls -R ./*/*.nc) ; do 
        #path=$i
        file=$(basename -s .nc $i)
        #echo $file
        ncatted -O -a units,lon,c,c,"degrees_east" -a units,lat,a,c,"degrees_north" ${i}
        cdo remapnn,r1440x720 ${i} ./Regridded/${file}_0.25res.nc; 
done