!-------------------------------------- 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 --------------------------------------
!

      SUBROUTINE READGERR(KULGERR,CDOP) 1,1
#if defined (DOC)
*
***s/r READGERR  - Read the forecast error standard deviation
*     .            and put it in COMGD1
*
*Author  : P. Gauthier *ARMA/AES  September 30, 1993
*
*Revision: J. Halle    *CMDA/AES  Oct 1999
*          - Add ground temperature (TG) to the model state.
*     .
*     -------------------
**    Purpose:
*
*Arguments
*     KULGERR:  logical unit on which the forecast error standard deviation
*     .         has been written (it may be in core)
*     CDOP   :  = 'M' forecast error standard deviation IS PUT IN COMGD1
*     .               to prepare for multiplication
C     .         = 'D; inverse of forecast error standard deviation IS PUT IN COMGD1
*     .               to prepare for division
*
#endif
      IMPLICIT NONE
#include "pardim.cdk"
#include "comdim.cdk"
#include "comspg.cdk"
#include "comgd1.cdk"
#include "compstat.cdk"
#include "comstate.cdk"
      INTEGER KULGERR
      CHARACTER*1 CDOP
C
      INTEGER JK, JLON, JGL
      REAL*8 DLSIGMA
C
C*    1. Transfer the forecast error to GD1
C
 100  CONTINUE
      CALL TRANSFER('ZGD1')
      IF(CDOP.EQ.'M') THEN
         DO  JGL = 1, NJ
            DO JK = 1, NKGDIM
               DLSIGMA = DBLE(RGSIG(JGL,JK))
               DO JLON = 1,NI
                  GD1(JLON,JK,JGL) = DLSIGMA
               END DO
            END DO
         END DO
         IF ( NGEXIST(NGTG) .EQ. 1 ) THEN
            DO  JGL = 1, NJ
               DO JLON = 1,NI
                  DLSIGMA = DBLE(TGSTDBG(JLON,JGL))
                  GTG1(JLON,1,JGL) = DLSIGMA
               END DO
            END DO
         ENDIF
      ELSE IF(CDOP.EQ.'D') THEN
         DO  JGL = 1, NJ
            DO JK = 1, NKGDIM
               DLSIGMA = DBLE(RGSIG(JGL,JK))
               IF(DLSIGMA.EQ.0.)THEN
                  DLSIGMA = 1.D20
               ELSE
                  DLSIGMA = 1.D0/DLSIGMA
               END IF
               DO JLON = 1,NI
                  GD1(JLON,JK,JGL) = DLSIGMA
               END DO
            END DO
         END DO
         IF ( NGEXIST(NGTG) .EQ. 1 ) THEN
            DO  JGL = 1, NJ
               DO JLON = 1,NI
                  DLSIGMA = DBLE(TGSTDBG(JLON,JGL))
                  IF(DLSIGMA.EQ.0.)THEN
                     DLSIGMA = 1.D20
                  ELSE
                     DLSIGMA = 1.D0/DLSIGMA
                  END IF
                  GTG1(JLON,1,JGL) = DLSIGMA
               END DO
            END DO
         ENDIF
      END IF
C
      RETURN
      END