GrADS

Contents


任意線上におけるデータの抽出(鉛直1層)

鉛直多層にしたい場合はbashを使ってループして取得する。

#!/bin/bash
'reinit'
'cc'
* =================================================
* Set file
* =================================================
CTLFILE="../data/composite_dailyeof.highs.ctl"
OUTFILE=test.txt
* =================================================
* Set cross section
* =================================================
LONMIN=130 ; LONMAX=145
LATMIN=45 ; LATMAX=30
INT=0.5
* =================================================
* Set time and variables (for GRSM)
* =================================================
TIME=1
HOURS=24*1
'open 'CTLFILE
'q dims'
'set t 'TIME
'hgt=hgtsfc'
'uflx=quflxclm'
'vflx=qvflxclm'
'p0=pratesfc*60*60*'HOURS
'w0=pwatclm'
'e0=lhtflsfc/5/1000000*60*60*'HOURS
* =================================================
* Output grid informaiton (do not change bellow)
* =================================================
say result
say 'Information of cross section'
MAXCNT=(LONMAX-LONMIN)/INT+1
say 'LONMIN : 'LONMIN
say 'LONMAX : 'LONMAX
say 'LATMIN : 'LATMIN
say 'LATMAX : 'LATMAX
say 'COUNT : 'MAXCNT
* =================================================
* Prepare water components (do not change bellow)
* =================================================
'div0=hdivg(uflx,vflx)*60*60*'HOURS
ICNT=1
while ICNT <= MAXCNT    >
  LON=LONMIN+(ICNT-1)*INT
  LAT=LATMIN+(LATMAX-LATMIN)*(LON-LONMIN)/(LONMAX-LONMIN)

  CLON=math_format('%7.3f',LON)
  CLAT=math_format('%7.3f',LAT)

  'set lon 'LON
  'set lat 'LAT

  'd div0'
  DIV0=subwrd(result,4)
  CDIV0=math_format('%7.3f',DIV0)
  'd e0'
  E0=subwrd(result,4)
  CE0=math_format('%7.3f',E0)
  'd w0'
  W0=subwrd(result,4)
  CW0=math_format('%7.3f',W0)
  'd p0'
  P0=subwrd(result,4)
  CP0=math_format('%7.3f',P0)
  'd hgt'
  HGT=subwrd(result,4)
  CHGT=math_format('%7.3f',HGT)

  RESULT=CLON" "CLAT" "CW0" "CP0" "CE0" "CDIV0" "CHGT
  say RESULT
  ret = write( OUTFILE, RESULT, append )

  ICNT=ICNT+1
endwhile
                  

shell から grads への橋渡し

tmp ファイルを作成する必要がないので、個人的に好き。

#!/bin/bash
grads -l << EOF
reinit
open flx.ctl
d pwatclm
print test.eps
EOF
                  

BinからNetCDFへの変換

バイナリをGradsで読めるNetCDF形式(CORDS)に変換する方法。

ctl を作成すれば一発変換!

スクリプトを書く必要がない。

$ gradsnc -bl -c
ga-> run lats4d.gs -v -i FCTL -ftype ctl -o FOUT -format coards -q

※注意点

gradsnc でないとダメだった。latsスクリプトがないとおこられる。gradsnc を使えるようにするために、libtermcap.so.2が必要とおこられた→対象法は下記サイトを参照

https://mallappat2011.wordpress.com/2013/09/03/libtermcap-so-2-no-such-file-or-directory-in-ubuntu/


BinをNetCDFへ変換する方法

サンプルスクリプトの通り、opengradsを使うと簡単。

 #!/bin/bash
# ==============================================================
#  Parameter
# ==============================================================
XDEF=1440
YDEF=720
#==============================================================
# GrADS
#==============================================================
YYYY=2008
for MO in 01 02 03 04 05 06 07 08 09 10 11 12 ; do
  FDAT=../dat/${YYYY}${MO}.nc
  FOUT=../out/${YYYY}${MO}.g15
  DAYS=`/home/masatano/bin/day.x $YYYY $MO`
  TMAX=`echo $DAYS | awk '{print $1*8}'`

tmpgs=tmp$$.gs
cat > $tmpgs << EOF
'reinit'
'sdfopen $FDAT'
'set gxout fwrite'
'set undef dfile'
'set fwrite $FOUT'

t=1
while t<=$TMAX
'set x 1 $XDEF'
'set y 1 $YDEF'
'set t 't
'd precipitation'
t=t+1
endwhile

'disable fwrite'
'quit'
EOF

  opengrads -lbc $tmpgs 1>/dev/null

  echo Make $FOUT

done