2017-08-10 262 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只會遇到麻煩,否則它應該可以正常工作。它確實在全局屬性字段歷史記錄中添加了命令本身,儘管如果不希望的話可以將其關閉。 –