!-------------------------------------- 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 --------------------------------------
*S/P SATQ - CALCULE L'HUMIDITE SPECIFIQUE A SATURATION
*

      SUBROUTINE SATQ(QS, T, PS, PSMEAN, NI, NJ, SATUCO),2
#include "impnone.cdk"
      INTEGER NI,NJ
      REAL QS(NI,NJ),T(NI,NJ),PS(NI,NJ),PSMEAN
      LOGICAL SATUCO
*
*Author
*          Michel Roch  (May1987)
*
*Revision
* 001      MJ L'Heureux (Aug 1987) Adaptation to the revised RFE
*          code
* 002      N. Brunet  (May90) Standardization of thermodynamic
*          functions
* 003      N. Brunet  (May91) New version of thermodynamic functions
*          and file of constants
*
*Object
*          to calculate the specific humidity at saturation
*
*Arguments
*
*          - Output -
* QS       specific humidity at saturation
*
*          - Input -
* T        temperature
* PS       LN(surface pressure)
* PSMEAN   mean of PS
* NI       1st dimension
* NJ       2nd dimension
* SATUCO   .TRUE. if water/ice phase for saturation
*          .FALSE. if water phase only for saturation
*
**
*
*
      INTEGER I,J
      REAL PMBR
*
#include "consphy.cdk"
#include "dintern.cdk"
#include "fintern.cdk"
*
      IF(SATUCO)THEN
      DO 10 J=1,NJ
         DO 10 I=1,NI
            PMBR = EXP(PS(I,J)+PSMEAN)
            QS(I,J) = FOQST(T(I,J),PMBR)
10    CONTINUE
      ELSE
      DO 20 J=1,NJ
         DO 20 I=1,NI
            PMBR = EXP(PS(I,J)+PSMEAN)
            QS(I,J) = FOQSA(T(I,J),PMBR)
20    CONTINUE
      END IF
*
      RETURN
      CONTAINS
#include "fintern90.cdk"
      END