!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
! version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
#include "phy_macros_f.h"
***S/R MTHTAW2 - CALCULE TW OU THETAW
*
SUBROUTINE MTHTAW2(TW,HU,TX,PX,LNPS,MODP,SWTT, 2,7
$ SWPH,SWTH,TI,NI,NK,N)
*
#include "impnone.cdk"
INTEGER NI, NK, N, MODP
REAL TW(NI,NK), HU(NI,NK), TX(NI,NK)
REAL PX(NK), LNPS(NI,*), TI
REAL TEMP1
LOGICAL SWTT, SWPH, SWTH
*
*Author
* N. Brunet (Jan91)
*
*Revision
* 001 B. Bilodeau (August 1991)- Adaptation to UNIX
* 002 N. Brunet (May 1994) - change to l2ocprv in order to
* obtain results closer to those of tephigram
* 003 N. Brunet (sept 2000) adaptation to new functions
* sgamasp and schal.
*
*Object
* to calculate TW or THETAW (according to the value SWTT)
* from specific humidity, temperature and pressure
*
*Arguments
*
* - Output -
* TW TW or THETAW in Kelvins
*
* - Input -
* HU specific humidity in kg/kg
* TI temperature (K) at which we start calculating
* latent heat of sublimation
* if swph=false, ti is n/a
* ti must be .LE. trpl
*
* TX temperature or virtual temperature in Kelvins
* PX see MODP
* LNPS see MODP
* MODP pressure mode (SI units only):
* =0; pressure level in PX
* =1; sigma level in PX and PS(surface pressure) in LNPS
* =2; sigma level in PX and logarithm of sigma level in
* LNPS
* =3; all points of pressure in LNPS(NI,*) in Pascals
* =4; sigma level in PX and logarithm of sigma level in
* LNPS(in millibars unless using SI units)
* =5; logarithm of pressure level in PX(in millibars unless
* using SI units)
* SWTT .TRUE. to pass TT for argument
* .FALSE. to pass TV for argument
* SWPH .TRUE. to consider water and ice phase
* .FALSE. to consider water phase only
* SWTH .TRUE. to calculate THETAW
* .FALSE. to calculate TW
* NI horizontal dimension
* NK vertical dimension
* N number of treated points
*
*IMPLICITES
#include "consphy.cdk"
*
*MODULES
EXTERNAL INCTPHY, SCHAL, SGAMASP
*
**
*--------------------------------------------------------------------
*
REAL Q1, DQ1, Q0, TH, FT0, DFT0, PRN
REAL DLP, D, QP, DT, DTPR, LATHEAT, HSCP
REAL SCHAL, SGAMASP
INTEGER ITER, I, K, NN, J
************************************************************************
*
* AUTOMATIC ARRAY
*
************************************************************************
*
AUTOMATIC ( PN , REAL , (N) )
*
************************************************************************
*
*
#include "dintern.cdk"
#include "fintern.cdk"
*--------------------------------------------------------------------
#include "initcph.cdk"
*
DO 10 K=1,NK
*
#include "modpr2.cdk"
IF(SWTT)THEN
DO 100 I=1,N
TW(I,K) = TX(I,K)
100 CONTINUE
ELSE
DO 105 I=1,N
TW(I,K) = FOTTV
(TX(I,K),HU(I,K))
105 CONTINUE
END IF
*
*
*
DO 200 I=1,N
*
* ON TROUVE 'TW' EN SOLUTIONNANT PAR METHODE
* DE NEWTON DU 1ER ORDRE AVEC 4 ITERATIONS.
*
Q0 = HU(I,K)
*
DO 300 ITER=1,4
LATHEAT = SCHAL
(TW(I,K), TI, SWPH)
HSCP = LATHEAT / CPD
TEMP1 = PN(I)
IF(SWPH)THEN
Q1 = FOQST
(TW(I,K),TEMP1)
DQ1 = FODQS
(Q1,TW(I,K))
ELSE
Q1 = FOQSA
(TW(I,K),TEMP1)
DQ1 = FODQA
(Q1,TW(I,K))
END IF
FT0 = -HSCP*(Q1 - Q0)
DFT0 = -1.0 -(HSCP*DQ1)
TW(I,K) = TW(I,K) - FT0/DFT0
Q0 = Q0 + FT0/(DFT0*HSCP)
300 CONTINUE
*
IF(SWTH)THEN
*
* ON TROUVE THETAW EN UTILISANT LA PENTE DE L'ADIABATIQUE
* MOUILLEE ET EN FAISANT LES CALCULS PAR TRANCHE DE
* 1000 PA ('DLP') EN PASSANT DE 'PN' A 100000.
*
IF(PN(I).NE.100000.)THEN
DLP = 1000.
D = 100000. - PN(I)
NN = INT(ABS(D/DLP))
IF(D.LT.0.)DLP = -DLP
D = D - FLOAT(NN)*DLP
IF(D.NE.0.)THEN
NN = NN + 1
ELSE
D = DLP
END IF
*
PRN = PN(I)
TH = TW(I,K)
*
DO 400 J=1,NN
* --- calcule dT / dp
dt = sgamasp
(th, prn, swph, ti)
* --- multiplie par delta P --> donne delta T
dtpr = dt * d
* --- mise a jour de la temp et de la pression
th = th + dtpr
PRN = PRN + D
IF(J.EQ.1)D = DLP
400 CONTINUE
*
TW(I,K) = TH
*
END IF
*
END IF
200 CONTINUE
*
10 CONTINUE
*
*
RETURN
CONTAINS
#include "fintern90.cdk"
END