Dai, A., and K.E. Trenberth, 2002: Estimates of freshwater discharge from continents: Latitudinal and seasonal variations. J. Hydrometeorol., 3, 660-687.
Dai, A., T. Qian, K. E. Trenberth, and J. D Milliman, 2009: Changes in continental freshwater discharge from 1949-2004. J. Climate, 22, 2773-2791.
::::::::::::::
run.sh
::::::::::::::
#!/bin/bash
# Description:
#
# Author: am
#
# Host: aofd165.bio.mie-u.ac.jp
# Directory: /work1/am/2015.Ibnu.Indian.Ocean/Run-off/Dai
#
# Revision history:
# This file is created by /usr/local/mybin/nbscr.sh at 11:57 on 04-13-2016.
outdir=output
mkdir -vp $outdir
exe=readme-2d-monthly-discharge-timeSeries
echo "Program $exe starts."
echo
${exe}
echo "Done $exe"
echo
ctl=runoff_dai_mon_clim.ctl
echo "Print GrADS CTL file, "$ctl
cat <<EOF >$ctl
DSET ^${outdir}/runoff_Dai2008_monthly_climatology.bin
OPTIONS sequential big_endian
OPTIONS template
UNDEF -999.9
XDEF 360 LINEAR -179.5 1.0
YDEF 180 LINEAR -89.5 1.0
ZDEF 1 LEVELS 1
TDEF 12 LINEAR 00z01Jan1949 1mo
VARS 1
vmonavg 1 99 monthly runoff climatology [1E6 m3/s]
ENDVARS
EOF
echo "Done."
echo
#
# The following lines are samples:
#
# Sample for handling options
# CMDNAME=$0
# Ref. https://sites.google.com/site/infoaofd/Home/computer/unix-linux/script/tips-on-bash-script/hikisuuwoshorisuru
#while getopts t: OPT; do
# case in
# "t" ) flagt="true" ; value_t="" ;;
# * ) echo "Usage nbscr.sh [-t VALUE] [file name]" 1>&2
# esac
#done
#
#value_t=NOT_AVAILABLE
#
#if [ = "foo" ]; then
# type="foo"
#elif [ = "boo" ]; then
# type="boo"
#else
# type=""
#fi
#shift 0
# Sample for checking arguments
#if [ $# -lt 1 ]; then
# echo Error in $0 : No arugment
# echo Usage: $0 arg
# exit 1
#fi
#if [ $# -lt 2 ]; then
# echo Error in $0 : Wrong number of arugments
# echo Usage: $0 arg1 arg2
# exit 1
#fi
# Sample for checking input file
#in=""
#if [ ! -f $in ]; then
# echo Error in $0 : No such file, $in
# exit 1
#fi
# Sample for creating directory
#dir=""
#if [ ! -d $dir ]; then
# mkdir -p ${dir}
# echo Directory, ${dir} created.
#fi
#out=$(basename $in .asc).ps
#echo Input : $in
#echo Output : $out
# Sample of do-while loop
#i=1
#n=3
#while [ $i -le $n ]; do
# i=$(expr $i + 1)
#done
# Sample of for loop
# list_item="a b c"
#for item in list_item
#do
# echo $item
#done
# Sample of if block
#i=3
#if [ $i -le 5 ]; then
#
#else if [ $i -le 2 ]; then
#
#else
#
#fi
::::::::::::::
readme-2d-monthly-discharge-timeSeries.f90
::::::::::::::
!
! The 2-dimentional annual discharge data from 1949-2004 were derived using the
! constructed (i.e., infilled) water year (Oct-Sep) flow from the downstream station
! (adjusted to river mouth using the ratio of flow rates at the river mouth and the
! station simulated by a river routing model forced by runoff fields from Fekete
! et al. 2002. For the largest 200 rivers only) from the 925 rivers, and then scaled
! up to account for contributions from the unmonitored areas (i.e., areas not
! covered by the 925 rivers). See following papers for more details:
! Dai, A., and K.E. Trenberth, 2002: Estimates of freshwater discharge from
! continents: Latitudinal and seasonal variations. J. Hydrometeorol., 3, 660-687.
! Dai, A., T. Qian, K. E. Trenberth, and J. D Milliman, 2009: Changes in continental
! freshwater discharge from 1949-2004. J. Climate, 22, 2773-2791.
! Because the infilling, adjustment to river mouth, and the scaling for
! unmonitored areas are done most reliably for annual flow, the time series
! data were not done for monthly flow. One way to apply the annual flow data
! (which are on a 1deg grid, with zero values for non-coastal boxes), one can
! make use of the long-mean annual cycle (at each 1deg box) from Dai and
! Trenberth (2002), e.g., with the following Fortran codes:
!
! The binary data files were created on a Unix machine and are in big endian
! format.
!
! BINARY mode should be used in downloading the binary files!
!
! Fortran 90 codes to read water year discharge data and add a
! mean annual cycle to it:
!
! Definition of the 1deg grid: the center of box (i,j) is at
! lon = aln1 + (i-1)*di (from -180 to 180), lat = alt1+(j-1)*dj :
parameter(mi=360,mj=180,di=1.,dj=1.,aln1=-179.5,alt1=-89.5)
parameter(iyrb=1949,iyre=2004,nyr=iyre-iyrb+1)
! 1949,2004 ! for water yr 1949(from Oct 1948-Sep 1949) to 2004
integer,parameter::iyyyy1=1949,iyyyy2=2004
real vann(mi,mj) ! water year discharge for each yr from Dai et al.(2008)
real vmonavg(mi,mj,12) ! monthly climatology from Dai and Trenberth(2002)
real vmon(mi,mj,nyr,12) ! constructed monthly discharge
real ratio(mi,mj,12) ! annual cycle ratio
character(len=2000)::file1, file2, ofle1
file1='/work4/data/Runoff.Dai/runoff2ocean-mon-fromStn-1deg-2d.bin'
file2='/work4/data/Runoff.Dai/annual-dis-waterYr1949-2004-2d-scaled-con.bin'
ofle1='output/runoff_Dai2008_monthly_climatology.bin'
! open input data files: These are the data files should be used.
! created on a Unix machine (in big endian format):
print '(A,A)','Open ',trim(file1)
open(1,form='unformatted',file=file1,action="read")
print '(A)','Done.'
print *
print '(A,A)','Open ',trim(file2)
open(2,form='unformatted',file=file2,action="read")
print '(A)','Done.'
print *
! To get the mean annual cycle coeff.:
print '(A)','Gget the mean annual cycle coeff.'
do mon=1,12
read(1)((vmonavg(i,j,mon),i=1,mi),j=1,mj) ! in Sv or E6 m3/s
enddo
print '(A)','Done.'
print *
print '(A)','Get annual cycle ratio.'
do j=1,mj
do i=1,mi
sum=0.
do mon=1,12
sum=sum+vmonavg(i,j,mon)
enddo !mon
if (sum.gt.0.) then
sum=sum/12. ! still in unit of Sv
do mon=1,12
ratio(i,j,mon)=vmonavg(i,j,mon)/sum ! normalized by annual flow rate
enddo
else
do mon=1,12
ratio(i,j,mon)=1. ! no seasonal variations if annual value=0.
enddo
endif
enddo !j
enddo !i
print '(A)','Done.'
print *
! To create the monthly series by adding the mean annual cycle:
print '(A)','Create the monthly series by adding the mean annual cycle.'
! skip the two non-discharge records:
read(2)
read(2)
iy=0
do iyear=iyyyy1,iyyyy2 ! for water yr 1949(from Oct 1948-Sep 1949) to 2004
if(iyear==iyyyy1)then
print '(A,i4)',' ',iyear
print '(A)',' ...'
else if(mod(iyear,10)==0)then
print '(A,i4)',' ',iyear
else if(mod(iyear,10)==1)then
print '(A,A)',' ...'
else if(iyear==iyyyy2)then
print '(A,i4)',' ',iyear
endif
iy=iy+1 ! iy=1 for 1949
read(2)vann ! in Sv. Only coastal boxes have non-zero values.
! get the monthly data for water yr: iyear
do 20 mon=1,12
if (mon.le.9) then
do j=1,mj
do i=1,mi
vmon(i,j,iy,mon)=vann(i,j)*ratio(i,j,mon)
enddo
enddo
else if (iy.gt.1) then ! for the last year
do j=1,mj
do i=1,mi
vmon(i,j,iy1,mon)=vann(i,j)*ratio(i,j,mon) ! flow in Sv for month=mon,
enddo ! year = iyrb+iy1-1
enddo
endif
20 continue
iy1=iy
enddo !iyear
print '(A)','Done.'
print *
print '(A)','Output data for plotting using GrADS.'
print *
print '(A,A)','Open ',trim(ofle1)
open(20,file=ofle1,form="unformatted")
print *
print '(A)','Printing monthly climatology ...'
do mon=1,12
write(20)((vmonavg(i,j,mon),i=1,mi),j=1,mj)
enddo! !mon
close(20)
print '(A)','Done.'
print *
end
::::::::::::::
runoff.dai.run.sh
::::::::::::::
#!/bin/sh
gs=$(basename $0 .run.sh).gs
if [ ! -f $gs ]; then
echo Error in $0 : No such file, $gs
exit 1
fi
# Parameters
indir=.
figdir=../Fig
ctl=runoff_dai_mon_clim.ctl
opt_grads=bcp
out=${figdir}/$(basename $ctl .ctl).eps
grads -${opt_grads} "$gs -indir $indir -ctl $ctl -out $out -q"
exit 0
::::::::::::::
runoff.dai.gs
::::::::::::::
function runoff( args )
*
* Decode options
*
i = 1
while( 1 )
arg = subwrd( args, i )
i = i + 1;
if( arg = '' ); break; endif
while( 1 )
if( arg = '-indir');indir = subwrd(args,i);i=i+1;break;endif
if( arg = '-ctl') ; ctl = subwrd(args,i);i=i+1;break;endif
if( arg = '-out' ); out = subwrd(args,i);i=i+1;break;endif
if( arg = '-q' ); quitopt=yes ;i=i+1;break;endif
say 'Syntax error : arg= 'arg
return
endwhile
endwhile
say
say 'CTL file: 'ctl
say
'open ' indir '/' ctl
'cc'
'set lon 40 100'
'set lat -5 35'
'mul 3 4 1 4'
'set grads off'
'set t '1
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 2 4'
'set grads off'
'set t '2
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 3 4'
'set grads off'
'set t '3
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 1 3'
'set grads off'
'set t '4
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 2 3'
'set grads off'
'set t '5
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 3 3'
'set grads off'
'set t '6
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 1 2'
'set grads off'
'set t '7
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 2 2'
'set grads off'
'set t '8
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 3 2'
'set grads off'
'set t '9
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 1 1'
'set grads off'
'set t '10
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 2 1'
'set grads off'
'set t '11
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'mul 3 4 3 1'
'set grads off'
'set t '12
'set xlint 20'
'set ylint 10'
'color -gxout shaded 0 0.005 0.001 -kind white->lightcyan->springgreen->coral->hotpink'
'd vmonavg'
'xcbar 1 7 0.2 0.3'
say 'Figure file: 'out
'gxprint 'out
if ( quitopt = "yes" ); quit; endif
return