!================================================================
! $B0l<!85J|<MBPN.J?9UBg5$7W;;(B; $B:BI8@_Dj(B
!
! 97/03/17 $B>.9b@5;L(B
!================================================================
MODULE cod_module
USE para_module
IMPLICIT NONE
PUBLIC :: set_mprs,set_dprs,set_mtau,set_dtau

	CONTAINS
!----------------------------------------------------------------
SUBROUTINE set_mprs(Ts,slp,p)	! $B<>=aBg5$$N05NO:BI8(B

	REAL,INTENT(in)			:: Ts	! $BCOI=5$29(B
	REAL,INTENT(out) 		:: slp	! $BA4COI=5$05(B
	REAL,DIMENSION(zdim),INTENT(out):: p	! $BA405NO(B
	INTEGER				:: i

	slp = Ps + pv00*EXP(-ql/(R*Ts))

	DO i=1,zdim
	   p(i) = slp/(zdim-1)*(zdim-i)
	END DO
	
END SUBROUTINE set_mprs
!----------------------------------------------------------------
SUBROUTINE set_dprs(slp,p)	! $B4%AgBg5$$N05NO:BI8(B

	REAL,INTENT(out)		:: slp	! $BA4COI=5$05(B
	REAL,DIMENSION(zdim),INTENT(out):: p	! $BA405NO(B
	INTEGER				:: i

	slp = Ps

	DO i=1,zdim
	   p(i) = slp/(zdim-1)*(zdim-i)
	END DO
	
END SUBROUTINE set_dprs
!----------------------------------------------------------------
SUBROUTINE set_mtau(p,xv,tau)	! $B<>=aBg5$$N8w3XE*8|$5$N7W;;(B

!	INTEGER,INTENT(in)		:: dim	! $BG[Ns<!85(B
	REAL,DIMENSION(:),INTENT(in)	:: p	! $B05NO(B
	REAL,DIMENSION(:),INTENT(in)	:: xv	! $B?e>x5$%b%kJ,N((B
	REAL,DIMENSION(:),INTENT(out)	:: tau	! $B8w3XE*?<$5(B
	REAL,DIMENSION(:),ALLOCATABLE	:: xd	! $B4%AgBg5$%b%kJ,N((B
	REAL,DIMENSION(:),ALLOCATABLE	:: Mm	! $BJ?6QJ,;RNL(B

	ALLOCATE(xd(SIZE(p)))
	ALLOCATE(Mm(SIZE(p)))

	xd  = 1.- xv
	Mm  = Mr*xd + Mv*xv
	tau = (kaiv*Mv*xv + kaid*Mr*xd)*p/(ga*Mm)

	DEALLOCATE(xd,Mm)

END SUBROUTINE set_mtau
!----------------------------------------------------------------
SUBROUTINE set_dtau(p,tau)	! $B4%AgBg5$$N8w3XE*8|$5$N7W;;(B

!	INTEGER,INTENT(in)		:: dim	! $BG[Ns<!85(B
	REAL,DIMENSION(:),INTENT(in)	:: p	! $B05NO(B
	REAL,DIMENSION(:),INTENT(out)	:: tau	! $B8w3XE*?<$5(B

	tau   = kaid*p/ga
	
END SUBROUTINE set_dtau
!----------------------------------------------------------------
SUBROUTINE set_xv(i,pxv,xv)	! $B?e>x5$%b%kJ,N($N7W;;(B

	INTEGER,INTENT(in)		:: i	! $B7w3&LL9bEYHV9f(B
	REAL,DIMENSION(zdim),INTENT(in)	:: pxv	! $B?e>x5$%b%kJ,N((B($B2>CM(B)
	REAL,DIMENSION(zdim),INTENT(out):: xv	! $B?e>x5$%b%kJ,N((B

	xv(1:i)      = pxv(1:i)
	IF ( i /= zdim ) THEN
	  xv(i+1:zdim) = pxv(i)
	END IF

END SUBROUTINE set_xv
!----------------------------------------------------------------
END MODULE cod_module







