我的任务是从一个文件夹中获取多个相似的NetCDF(.nc
)文件,并在10个变量中堆叠一个a
变量。
我用过:
a <- list.files(path=ncpath, pattern = "nc$", full.names = TRUE)
这使我得到所有具有.nc
扩展名的文件。
如何进行第二项任务?
我希望从文件夹中的这些文件数量中获取此变量a
并将其堆叠。
如果只希望将输出输出到netcdf文件中,则可以考虑在Linux的命令行中使用cdo执行此任务?
files=$(ls *.nc) # you might want to be more selective with your wildcard
# this loop selects the variable from each file and puts into file with the var name at the end
for file in $files ; do
cdo selvar,varname $file ${file%???}_varname.nc
done
# now merge into one file:
cdo merge *_varname.nc merged_file.nc
您显然需要用所选变量的名称替换varname。