/work1/am/2015.Ibnu.Indian.Ocean/ECCO.dr080g/Ave.Monthly.UVWTS
::::::::::::::
pl.ave.mon.all.run.sh
::::::::::::::
#!/bin/bash
exe=pl.ave.mon.run.sh
if [ ! -f $exe ]; then
echo
echo Error in $0 : No such file, $exe
echo
exit 1
fi
yyyys=1993
yyyye=2014
#ydlist="\
#n10day_01_09 \
#"
#ydlist="\
#n10day_28_37 \
#"
ydlist="\
n10day_01_09 \
n10day_10_18 \
n10day_19_27 \
n10day_28_37 \
"
varlist="T S U V W"
vlev_plot=1
for var in $varlist; do
yyyy=$yyyys
while [ $yyyy -le $yyyye ]; do
for yearday in $ydlist; do
$exe ${var} $yyyy $yearday $vlev_plot
done # yearday
yyyy=$(expr $yyyy + 1)
done # yyyy
done # var
exit 0
::::::::::::::
pl.ave.mon.run.sh
::::::::::::::
#!/bin/sh
export LANC=C
exe=./runncl.sh
ncl=pl.ave.mon.ncl
if [ ! -f $ncl ]; then
echo
echo Error in $0 : No such file, $ncl
echo
exit 1
fi
# Default value
dataset=dr080g
yyyy=1993
yearday=n10day_01_09
varname="T"
vlev_plot=1
# Read arguments
varname=$1
yyyy=$2
yearday=$3
vlev_plot=$4
indir=/work4/data/ECCO.dr080g/${dataset}_${yyyy}/${yearday}
if [ ! -d $indir ]; then
echo
echo Error in $0 : No such directory, $indir
echo
exit 1
fi
figdir=${HOME}/2015.Ibnu.Indian.Ocean/Fig/$(basename $(pwd))/\
$(basename $0 .sh)/${yyyy}
if [ ! -d $figdir ]; then
mkdir -vp $figdir
fi
$exe $ncl ${indir} ${varname} ${yyyy} ${yearday} ${vlev_plot} ${figdir}
echo
echo Done $(basename $0).
echo
::::::::::::::
runncl.sh
::::::::::::::
#!/bin/bash
#
# Universal wrapper script for ncl.
# Pass arguments from the command line to environment variables
#
# version 0.1, Thierry Corti, C2SM ETH Zurich
#
E_BADARGS=65
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` script.ncl argument1 argument2 etc."
exit $E_BADARGS
fi
# save number of arguments to environment variable NCL_N_ARG
export NCL_N_ARGS=$#
# save command line arguments to environment variable NCL_ARG_#
for ((index=1; index<=$#; index++))
do
eval export NCL_ARG_$index=\$$index
done
# run ncl
ncl $1
::::::::::::::
pl.ave.mon.ncl
::::::::::::::
;
; Monthly Average of dr080 dataset
;
; Refer to http://dx.doi.org/10.1002/2014JC010336 for details on dr080
;
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
begin
wallClock1 = systemfunc("date") ; retrieve wall clock time
;
; Read command line arguments
;
scname = getenv("NCL_ARG_1")
indir = getenv("NCL_ARG_2")
varname= getenv("NCL_ARG_3")
yyyy = getenv("NCL_ARG_4")
yearday= getenv("NCL_ARG_5")
vlev = getenv("NCL_ARG_6")
figdir = getenv("NCL_ARG_7")
nt=3
if (yearday .eq. "n10day_01_09") then
datainfo="_08_08.00001_02160"
end if
if (yearday .eq. "n10day_10_18") then
datainfo="_08_08.02160_04320"
end if
if (yearday .eq. "n10day_19_27") then
datainfo="_08_08.04320_06480"
end if
if (yearday .eq. "n10day_28_37") then
datainfo="_08_08.06480_08880"
end if
;
; Input file name
;
infle=indir + "/" + varname + "ave" + datainfo + "_240.cdf"
print("Input: " + infle)
;
; Output file name
;
ofle=indir + "/" + varname + "mon" + datainfo + "_720.cdf"
;
; Read input data
;
f=addfile(infle,"r")
if (varname .eq. "U" )then
var=f->Uave(:,:,:,:)
end if
if (varname .eq. "V" )then
var=f->Vave(:,:,:,:)
end if
if (varname .eq. "W" )then
var=f->Wave(:,:,:,:)
end if
if (varname .eq. "T" )then
var=f->Tave(:,:,:,:)
end if
if (varname .eq. "S" )then
var=f->Save(:,:,:,:)
end if
lat =f->lat
lat_v=f->lat_v
lon =f->lon
lon_u=f->lon_u
depth=f->depth
time=f->time(:)
timem=new( (/nt/), float)
timem!0=time!0
timem@units=time@units
do n=0,2
nn=n*3
timem(n)=time(nn)+25.0*24.0
;
; timem is defined as time at an end of each 30-day averaging interval of
; budget term (gt*.cdf).
;
end do
;print(timem)
;exit
julian0=greg2jul(1970,01,01,00)
julim0m=julian0 + timem/24.0
greg0m=jul2greg(julim0m)
;print(greg0m)
;
; Set up monthly mean variables
;
dim=dimsizes(var)
varm=new( (/nt,dim(1),dim(2),dim(3)/), typeof(var), var@missing_value)
varm@_FillValue = var@missing_value
varm!0="timem"
varm!1="depth"
if (varname .eq. "U") then
varm!2="lat"
varm!3="lon_u"
end if
if (varname .eq. "V") then
varm!2="lat_v"
varm!3="lon"
end if
if (varname .eq. "T" .or. varname .eq. "S" .or. varname .eq. "W") then
varm!2="lat"
varm!3="lon"
end if
;
; Monthly mean
;
do n=0,2
varm(n,:,:,:)=0.0
mx=3
if (yearday .eq. "n10day_28_37" .and. n .eq. 2) then
mx=4
end if
do m=0,mx-1
l= n*3 + m
varm(n,:,:,:)=varm(n,:,:,:) + var(l,:,:,:)
end do
if (yearday .eq. "n10day_28_37" .and. n .eq. 2)then
varm(n,:,:,:)=varm(n,:,:,:)/4.0
else
varm(n,:,:,:)=varm(n,:,:,:)/3.0
end if
;
; var3d=var(1,:,:,:)
; varm3d=varm(n,:,:,:)
; if (any(var3d .eq. var@missing_value)) then
; var1d = ndtooned (var3d) ; convert to 1D array
; varm1d = ndtooned (varm3d)
; idx = ind(var1D.eq.var@missing_value) ; all indices var1D = missing_value
; varm1d(idx) = varm@_FillValue ; set all array syntax
; varm3d = onedtond(varm1D, dimsizes(varm)) ; return to the original array
; delete (var1d) ; var1D no longer needed
; delete (varm1d)
; delete (idx)
; end if
; varm(n,:,:,:)=varm3d(:,:,:)
end do
;
; Output netCDF files
;
system("/bin/rm -f " + ofle)
fout =addfile (ofle, "c")
setfileoption(fout,"DefineMode",True)
setfileoption(fout,"MissingToFillValue",True)
fAtt = True ; assign file attributes
fAtt@title = "dr080g"
fAtt@source_file = infle
fAtt@Conventions = "None"
fAtt@history= "Converted from MITGCM output on 07/24/2015\n"
fAtt@creation_date = systemfunc ("export LANG=C; date")
fileattdef( fout, fAtt ) ; copy file attributes
ntim = dimsizes(timem) ; get dimension sizes
klev = dimsizes(depth)
nlat = dimsizes(lat)
nlat_v= dimsizes(lat_v)
nlon = dimsizes(lon)
nlon_u= dimsizes(lon_u)
nvar = dimsizes(varm)
dimNames = (/"timem", "lat", "lat_v", "lon", "lon_u", "depth"/)
dimSizes = (/ -1 , nlat, nlat_v, nlon, nlon_u, klev /)
dimUnlim = (/ True , False, False, False, False, False /)
filedimdef(fout,dimNames,dimSizes,dimUnlim)
filevardef(fout, "lat" ,typeof(lat), getvardims(lat))
filevardef(fout, "lat_v" ,typeof(lat_v),getvardims(lat_v))
filevardef(fout, "lon" ,typeof(lon), getvardims(lon))
filevardef(fout, "lon_u" ,typeof(lon_u),getvardims(lon_u))
filevardef(fout, "depth" ,typeof(depth),getvardims(depth) )
filevardef(fout, "timem" ,typeof(time), "timem")
filevardef(fout, "varm" ,typeof(varm),getvardims(varm))
;
;
filevarattdef(fout,"lat" ,lat)
filevarattdef(fout,"lat_v" ,lat_v)
filevarattdef(fout,"lon" ,lon)
filevarattdef(fout,"lon_u" ,lon_u)
filevarattdef(fout,"depth" ,depth)
filevarattdef(fout,"timem" ,time)
filevarattdef(fout,"varm" ,var)
;
fout->lat =(/lat/)
fout->lat_v=(/lat_v/)
fout->lon = (/lon/)
fout->lon_u= (/lon_u/)
fout->depth=(/depth/)
fout->timem =(/timem/)
fout->varm = (/varm/)
;
; Plot figure (optional)
;
;Set depth
klev=stringtointeger(vlev)
z=floattointeger(depth(klev-1))
julian0=greg2jul(1970,01,01,00)
;
; float time(time) ;
; time:units = "hours since 1970-01-01 00:00:0.0" ;
;
datefnm=new( (/3/),string)
dateprt=new( (/3/),string)
do n=0,2
;
; Set date
;
nn1=3*n
nn2=3*n + 2
if (yearday .eq. "n10day_28_37" .and. n .eq. 2) then
nn2=9
end if
julim0=julian0 + time(nn1)/24.0 -5.0
julim1=julian0 + time(nn2)/24.0 +5.0
greg0=jul2greg(julim0)
greg1=jul2greg(julim1)
date0=greg0(0)+sprinti("%0.2i",greg0(1))+sprinti("%0.2i",greg0(2))
date1=greg1(0)+sprinti("%0.2i",greg1(1))+sprinti("%0.2i",greg1(2))
datefnm(n)=date0 + "-" + date1
dateprt0=greg0(0) + "/" +sprinti("%0.2i",greg0(1)) + "/" +sprinti("%0.2i",greg0(2))
dateprt1=greg1(0) + "/" +sprinti("%0.2i",greg1(1)) + "/" +sprinti("%0.2i",greg1(2))
dateprt(n)=dateprt0 + "-" + dateprt1
;
; Set output file name
;
filetype="png" ;"ps"
figfle=figdir + "/" + "ECCO.dr080_" + varname + "mon" + \
sprinti("%0.5i",z) + "m." + datefnm(n) + "." + filetype
wks = gsn_open_wks(filetype,figfle)
varm2d := varm(n,klev,:,:)
;delete(varm2d!0)
;delete(varm2d!1)
varm2d!0="lat"
varm2d!1="lon"
if (varname .eq. "T" .or. varname .eq. "S" .or. varname .eq. "W" ) then
varm2d&lat=var&lat
varm2d&lon=var&lon
end if
if (varname .eq. "U" ) then
varm2d&lat=var&lat
varm2d&lon=var&lon_u
end if
if (varname .eq. "V" ) then
varm2d&lat=var&lat_v
varm2d&lon=var&lon
end if
;
; Set NCL resources
;
res = True
res@gsnDraw = False ; don't draw
res@gsnFrame = False ; don't advance frame
;Figure size
res@vpHeightF = 0.35
res@vpWidthF = 0.55
res@vpXF = 0.2
;Map
res@mpFillOn = True
;Contour
res@cnFillOn = True ; turn on color fill
res@cnLineColor = "white"
res@lbOrientation = "vertical"
res@cnLevelSelectionMode = "ManualLevels" ; manually set the contour levels with the following 3 resources
res@gsnContourLineThicknessesScale=1.5
;Choose subregion
res@mpMinLatF =-20
res@mpMaxLatF = 20
res@mpMinLonF = 40
res@mpMaxLonF =110
res@mpDataBaseVersion = "Ncarg4_1" ; use GMT coastline
if (varname .eq. "T" ) then
cnmin=22
cnmax=32
cnint=1
end if
if (varname .eq. "S" ) then
cnmin=30
cnmax=38
cnint=1
end if
if (varname .eq. "U" .or. varname .eq. "V" ) then
cnmin=-1
cnmax= 1
cnint=0.2
end if
if (varname .eq. "W" ) then
cnmin=-1.0e-4
cnmax= 1.0e-4
cnint= 2.0e-5
end if
res1=res
res1@vpYF = 0.9
res1@cnMinLevelValF = cnmin ; set min contour level
res1@cnMaxLevelValF = cnmax ; set max contour level
res1@cnLevelSpacingF = cnint ; set contour spacing
res1@gsnLeftString = dateprt(n) ; add the gsn titles
res1@gsnCenterString = varname
res1@gsnRightString = z + " m"
plotA = gsn_csm_contour_map(wks,varm2d(:,:),res1) ; Draw a contour plot.
plot1 = plotA ; now assign plotA to array
draw(plot1)
delete(res1)
txres = True ; text mods desired
txres@txFontHeightF = 0.015 ; font smaller. default big
txres@txBackgroundFillColor = "white"
txres@txFontColor="black"
gsn_text_ndc(wks,dateprt(n),0.635,0.585,txres)
;
; Header and footer
;
drawNDCGrid(wks)
txres = True ; text mods desired
txres@txFontHeightF = 0.01 ; font smaller. default big
gsn_text_ndc(wks,figdir,0.5,0.99,txres)
text=systemfunc("export LANG=C; date")
gsn_text_ndc(wks,text,0.2,0.010,txres)
text=systemfunc("pwd")+"/"+scname
gsn_text_ndc(wks,text,0.5,0.03,txres)
frame(wks)
print("Figure : " + figfle)
end do ;n
print("")
print("Output: "+ ofle)
print("")
end