Created
February 9, 2023 08:35
-
-
Save mehori/51c335ef683bc8b6959eeea140ea77b8 to your computer and use it in GitHub Desktop.
大量の図をbashスクリプトで作図するときのテンプレート
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# draw a figure | |
function draw_figure(){ | |
local ifile=$1 # local にしておくと、うっかり同じ変数名を | |
local mon=$2 # 使ってしまったときも安心 | |
local ofile=$3 | |
echo "draw: $ifile, $ofile, $mon" | |
cat > tmp.ncl << EOF # ここからEOFまでをtmp.nclというファイルに入れる | |
begin | |
f = addfile=("${ifile}","r") # ここで ifile で指定したファイルを開いている | |
u = f->v(${mon},:,:) # mon で指定した時間を切り出し | |
wks = gsn_open_wks("pdf","figure.${mon}") # 出力ファイルの名前も mon をいれて定義 | |
plot = gsn_contour(wks,u,False) | |
end | |
EOF | |
ncl tmp.ncl # ncl を起動 | |
rm tmp.ncl # tmp.ncl を削除 | |
} | |
# main | |
for m in `seq 1 12`; do # 1から12のループ | |
draw_figure inputdata.nc $m fig-monthly # 出力は fig-monthly.1.pdf...みたいになる | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment