!-------------------------------------- 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 RESIDUALS 1,7
#if defined (DOC)
*
***s/r RESIDUALS  - RESIDUALS
*
*
*Author  : P. Koclas *CMC/CMDA  Nov 1998
*
*Revision: J. Halle  *CMC/CMDA  Jan 2000
*          add processing of TOVS radiances
*        - P. KOclas *CMC/CMDA  Sept 200
*                   -CHANGES FOR V06 version
*        - J. Halle  *CMDA/AES  dec 2000
*                   -adapt to TOVS level 1b.
*          JM Belanger CMDA/SMC  Jan 2001
*                   . 32 bits conversion (add call to cprob8to4)
*         P. KOCLAS Sept 2001
*                   . eliminate unnecessary call to suprep
*                   . ad call to sigmaop ( this enables output of fge in post file)
*         S. Pellerin *ARMA/SMC nov. 2001
*                   . reordering of declaration dependencies (for Linux compilation)
*         L. Fillion ARMA/EC 6 Jul 09 - Call to sigmaop3d.ftn
*
*    -------------------
**    Purpose: TRANSFER resduals O-A to O-P for all observations.
*
*Arguments
*    -NONE-
#endif
      IMPLICIT NONE
*implicits
#include "comlun.cdk"
#include "comdim.cdk"
#include "comdimo.cdk"
#include "cparbrp.cdk"
#include "comoabdy.cdk"
#include "comoahdr.cdk"
#include "comoba.cdk"
#include "comcva.cdk"
#include "comgrd_param.cdk"
*
C
      INTEGER J,JDATA
*---------------------------------------------------------------------
      WRITE(NULOUT,FMT=9000)
 9000 FORMAT(//,3(" *****************"),/
     S     ," residuals: BEGIN RESIDUAL CALCULATION",/
     S     ,3(" *****************"),/)
C
C*    1. Preliminary initializations
C     .  ---------------------------
C
 100  CONTINUE
C
C     .   3.4.3 Convert CMA ---> BURP file and write it
C
C
c     CALL SUPREP
      DO JDATA=1,NDATA
         ROBDATA(NCMOMF,JDATA) =  PPMIS
      ENDDO
!
      if(grd_typ.eq.'GU') then
        CALL SIGMAOP
      else
        call sigmaop3d
      endif
C
C     Transfer REAL*8 part of CMA to REAL*4
C     (follows observation operators computations).

      call cprob8to4
C
      CALL VINT3DFD(NCMOMA)
C
      DO JDATA=1,NDATA
         ROBDATA(NCMOMF,JDATA) =  ROBDATA(NCMOMA,JDATA)
      ENDDO
      DO j =1,1
         CALL PRNTHDR(j,NULOUT)
         CALL PRNTBDY(j,NULOUT)
      END DO
c     CALL SUPREP
      CALL  FILBRPPOST
      RETURN
      END