2017-08-10 258 views
0

我有一个每日netcdf文件(20060101),时间维度有144个步骤,因此文件中有10分钟时间步骤。现在我想用nco每10分钟创建一个netcdf文件。所以最后它应该创建144个文件。nco每天将netcdf文件剪切为10分钟文件

我已经发现他们使用

ncks -d time,min,max,stride infile.nc outfile.nc

类似的问题,但我不知道怎么写创建这些文件144码。 有人可以帮助我吗? 感谢您的帮助!

+0

你有什么试过,它在哪里失败?你熟悉循环吗? 在向我们展示您的尝试之后,您更可能获得帮助,而不是要求其他人为您编写代码。 – N1B4

回答

1

找到解决方案:

start=1131580800 # first time step in seconds 
for f in *_test.nc; do #$files 
    echo 'Processing' $f 
    for i in {0..17}; do 
    time=$(expr $start + 600 \* $i)     # calculates the next time step --> 600s correspond to 10 minute steps I wanted to have 
    time_new=$(date -d @$time '+_%H%M')    # extracting the time variable from my file and convert it to use them in the file names 
    outfile=$(echo $f|sed "s/_level2/$time_new/g") 
    ncks -d time,$i,$i $f $outfile     # split my original file to 10 min steps 
    done 
done 
1

我没有测试过,但我认为你可以在CDO与一行做到这一点:

cdo splitsel,1 input.nc output 

的“1”是指1将文件分割每个输出文件的时间步长,我想这就是你要求的。

+0

是的,这是正确的,但有时cdo改变元数据,这就是为什么我正在寻找另一种方式来做到这一点。 –

+1

如果字段不在“标准”lat-lon类型的网格上,CDO只会遇到麻烦,否则它应该可以正常工作。它确实在全局属性字段历史记录中添加了命令本身,尽管如果不希望的话可以将其关闭。 –