!**************************************************/ program f90_BTS !**************************************************/ implicit none integer,parameter::NDmax=1000 integer,parameter::NYE=14 integer,parameter::NBTS=10000 real(8)::data_org(1:NDmax) real(8)::pyear(1:NYE) real(8)::qq(1:NYE) real(8)::qbts(1:NBTS,1:NYE) real(8)::dataw(1:NBTS) integer::nd !Number of data real(8),allocatable::datax(:) !Observed data real(8),allocatable::datab(:) !data for bootstrap integer,allocatable::idata(:) ! real(8)::p,qave,work integer::i,j,k,nnn,mmm,kl,ku integer::imethod character(len=50)::fnameR,fnameW,fnameH character(len=200)::strcom character(len=1000)::linebuf character(len=50)::dummy integer::io pyear(1)=2.0D0 pyear(2)=5.0D0 pyear(3)=10.0D0 pyear(4)=20.0D0 pyear(5)=30.0D0 pyear(6)=50.0D0 pyear(7)=100.0D0 pyear(8)=200.0D0 pyear(9)=300.0D0 pyear(10)=500.0D0 pyear(11)=1000.0D0 pyear(12)=2000.0D0 pyear(13)=3000.0D0 pyear(14)=5000.0D0 !Reading input file and output file from command line call getarg(1,dummy) !Method of analysis call getarg(2,fnameR) !Input data file call getarg(3,fnameW) !Output data file call getarg(4,fnameH) !Histogram data file read(dummy,*) imethod !convert character 'dummy' to integer 'imethod' ! imethod ! 1 Gumbel Gumbel distribution ! 2 GEV Generalized Extreme Value distribution ! 3 Weibull (Goda) Weibull distribution (L-moments by GODA) ! 4 Weibull (LSM) Weibull distribution (least square method) ! 5 Weibull (MLM) Weibull distribution (Maximum Likelihood method) ! 6 SQRT-ET SQRT exponential-type distribution of maximum ! 7 LP3 Log Pearson type III distribution ! 8 LN3 (Iwai) Logarithmic Normal distribution with 3 variables (quantile) ! 9 LN3 (Moment) Logarithmic Normal distribution with 3 variables (moment) ! 10 LN3 (Trial) Logarithmic Normal distribution with 3 variables (trial) ! 11 Exponential Exponential distribution ! 12 GPD Generalized Pareto distribution !========================*/ ! Data input */ !========================*/ open(11,file=fnameR,status='old') read(11,'(a)') strcom do i=1,NDmax read(11,*,iostat=io) data_org(i) if(io/=0)exit end do close(11) nd=i-1 allocate(datax(1:nd)) allocate(datab(1:nd)) allocate(idata(1:nd)) do i=1,nd datax(i)=data_org(i) end do !=============================*/ ! Calculation on BTS method */ !=============================*/ ! Result: Quantile qbts(1:NBTS,1:NYE) do nnn=1,NBTS call IRAND(nd,idata) do i=1,nd datab(i)=datax(idata(i)) end do call CAL_QQ(imethod,nd,datab,pyear,qq,NYE) do mmm=1,NYE qbts(nnn,mmm)=qq(mmm) end do end do !=============================*/ ! Output of result */ !=============================*/ if(imethod==1) strcom="Gumbel bootstrap" if(imethod==2) strcom="GEV bootstrap" if(imethod==3) strcom="Weibull (Goda) bootstrap" if(imethod==4) strcom="Weibull (LSM) bootstrap" if(imethod==5) strcom="Weibull (MLM) bootstrap" if(imethod==6) strcom="SQRT-ET bootstrap" if(imethod==7) strcom="LP3 bootstrap" if(imethod==8) strcom="LN3 (Iwai) bootstrap" if(imethod==9) strcom="LN3 (Moment) bootstrap" if(imethod==10)strcom="LN3 (Trial) bootstrap" if(imethod==11)strcom="Exponential bootstrap" if(imethod==12)strcom="GPD bootstrap" ! Calculation using original data call CAL_QQ(imethod,nd,datax,pyear,qq,NYE) open(12,file=fnameW,status='replace') write(12,'(a)') trim(strcom) write(12,'(a)') 'Year,Prob.,Qorg,Qprd,Q95,Q05' do mmm=1,NYE do i=1,NBTS dataw(i)=qbts(i,mmm) end do call SSORT(NBTS,dataw) do i=1,NBTS qbts(i,mmm)=dataw(i) end do qave=0.0D0 do i=1,NBTS qave=qave+qbts(i,mmm) end do qave=qave/dble(NBTS) kl=int(0.025*dble(NBTS)) ku=NBTS-kl p=1.0D0-1.0D0/pyear(mmm) write(linebuf,'(f7.0,",",e10.5,4(",",f7.1))') & pyear(mmm),p,qq(mmm),qave,qbts(ku,mmm),qbts(kl,mmm) call del_spaces(linebuf) write (12,'(a)') trim(linebuf) end do close(12) !=============================*/ ! Output for Histogram */ !=============================*/ mmm=NYE dummy=' (5000year)' if(imethod==1) strcom="Gumbel bootstrap" if(imethod==2) strcom="GEV bootstrap" if(imethod==3) strcom="Weibull (Goda) bootstrap" if(imethod==4) strcom="Weibull (LSM) bootstrap" if(imethod==5) strcom="Weibull (MLM) bootstrap" if(imethod==6) strcom="SQRT-ET bootstrap" if(imethod==7) strcom="LP3 bootstrap" if(imethod==8) strcom="LN3 (Iwai) bootstrap" if(imethod==9) strcom="LN3 (Moment) bootstrap" if(imethod==10)strcom="LN3 (Trial) bootstrap" if(imethod==11)strcom="Exponential bootstrap" if(imethod==12)strcom="GPD bootstrap" strcom=trim(adjustl(strcom))//trim(adjustl(dummy)) open(12,file=fnameH,status='replace') write(12,'(a)') trim(strcom) do i=1,NBTS write(linebuf,'(f7.1)') qbts(i,mmm) call del_spaces(linebuf) write (12,'(a)') trim(linebuf) end do close(12) contains !---------------------------------------------------------------------------*/ subroutine CAL_QQ(imethod,nd,datat,pyear,qq,NYE) !Gumbel integer,intent(in)::imethod,nd,NYE real(8),intent(in)::pyear(1:NYE) real(8),intent(inout)::datat(1:nd) real(8),intent(out)::qq(1:NYE) integer::i real(8)::datay(1:nd),alpha,p real(8)::a_gum,c_gum real(8)::k_gev,a_gev,c_gev real(8)::k_wgo,a_wgo,c_wgo real(8)::k_wls,a_wls,c_wls,k_wml,a_wml,c_wml real(8)::a_sqr,b_sqr real(8)::a_lp3,b_lp3,c_lp3 real(8)::a_lnq,m_lnq,s_lnq real(8)::a_lnm,m_lnm,s_lnm real(8)::a_lnt,m_lnt,s_lnt real(8)::a_exp,c_exp real(8)::k_gpd,a_gpd,c_gpd call SSORT(nd,datat) alpha=0.4D0 do i=1,nd datay(i)=(dble(i)-alpha)/(dble(nd+1)-2.0D0*alpha) end do select case(imethod) case(1) call GUM_COEF(nd,datat,a_gum,c_gum) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_GUM(p,a_gum,c_gum) end do case(2) call GEV_COEF(nd,datat,k_gev,a_gev,c_gev) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_GEV(p,k_gev,a_gev,c_gev) end do case(3) call WGO_COEF(nd,datat,k_wgo,a_wgo,c_wgo) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_WEI(p,k_wgo,a_wgo,c_wgo) end do case(4) call WML_COEF(nd,datat,datay,k_wls,a_wls,c_wls,k_wml,a_wml,c_wml,0) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_WEI(p,k_wls,a_wls,c_wls) end do case(5) call WML_COEF(nd,datat,datay,k_wls,a_wls,c_wls,k_wml,a_wml,c_wml,1) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_WEI(p,k_wml,a_wml,c_wml) end do case(6) call SQR_COEF(nd,datat,a_sqr,b_sqr) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_SQR(p,a_sqr,b_sqr,datat(nd)) end do case(7) call LP3_COEF(nd,datat,a_lp3,b_lp3,c_lp3) do i=1,NYE p=1.0D0-1.0D0/pyear(i) if(b_lp3<1.0D4)then qq(i)=XP_LP3(p,a_lp3,b_lp3,c_lp3) else qq(i)=XP_LP3_SP(nd,datax,p) end if end do case(8) call LNQ_COEF(nd,datat,a_lnq,m_lnq,s_lnq) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_LN3(p,a_lnq,m_lnq,s_lnq) end do case(9) call LNM_COEF(nd,datat,a_lnm,m_lnm,s_lnm) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_LN3(p,a_lnm,m_lnm,s_lnm) end do case(10) call LNT_COEF(nd,datat,datay,a_lnt,m_lnt,s_lnt) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_LN3(p,a_lnt,m_lnt,s_lnt) end do case(11) call EXP_COEF(nd,datat,a_exp,c_exp) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_EXP(p,a_exp,c_exp) end do case(12) call GPD_COEF(nd,datat,k_gpd,a_gpd,c_gpd) do i=1,NYE p=1.0D0-1.0D0/pyear(i) qq(i)=XP_GPD(p,k_gpd,a_gpd,c_gpd) end do end select end subroutine CAL_QQ !---------------------------------------------------------------------------*/ subroutine IRAND(nd,idata) integer,intent(in)::nd integer,intent(out)::idata(1:nd) integer::i real(8)::a,b,x,r a=1.0 b=dble(nd) do i=1,nd call random_number(x) r=a+(b-a)*x idata(i)=int(r+0.5) end do end subroutine IRAND !---------------------------------------------------------------------------*/ subroutine SSORT(nd,datat) integer,intent(in)::nd real(8),intent(inout)::datat(:) integer::i,kh,kv real(8)::temp kv=1 do kv=3*kv+1 if(ndtemp) datat(kh)=datat(kh-kv) kh=kh-kv if(kh0 */ bb=0.0D0 do i=1,nd bb=bb+sqrt(datat(i)) end do bb=(2.0D0*dble(nd)/bb)*(2.0D0*dble(nd)/bb)+0.001D0 ! Bisection method */ b1=bb b2=b1+0.5D0 bb=0.5D0*(b1+b2) f1=FSQR(nd,datat,b1,a1,a2) f2=FSQR(nd,datat,b2,a1,a2) ff=FSQR(nd,datat,bb,a1,a2) do while(0.001