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

      subroutine asqrtc2 1,1
*
***s/r asqrtc2  - Adjoint of sqrtc2.ftn for nanalvar = 4 only.
*
*
*Author  : Luc Fillion - ARMA/EC - 11 Mar 2009.
*Revision:
* 
*
*     -------------------
**    Purpose: Used for XD-Var analysis
*
*Arguments
*     none
*
      IMPLICIT NONE
*
#include "taglam4d.cdk"
#include "comdim.cdk"
#include "comct0.cdk"
#include "comlun.cdk"
#include "comsim.cdk"
#include "comcorr.cdk"
#include "comfftla.cdk"
#include "comsp.cdk"
#include "comcva.cdk"
#include "com1obs.cdk"
*
      integer ji,jj,jrow,jcol,jk,jla,jband,jm,ila
      integer idim,iflag
      integer idum1,idum2,idum3,idum4
      real*8 zmin,zmax
      real*8 zsp(nksdim,2,maxbpop)
      real*8 zsp2(nksdim2,2,maxbpop)
      real*8 zsp3(nksdim2,2,maxbpop)
!
      REAL*8 ONE8,ZERO8
      data ONE8,ZERO8/1.D0,0.D0/
      real*8 zcon
      real*8 zsp1(nla,2)
      real*8 zsprpn(ni+2,nj+2)
*
**
      call normsphalf
      go to 998
!
      do jband = 1, nband
        do jm = 1, mbandsp(jband)
          ila = mila(jm,jband) 
          do jk = 1, nksdim
            zsp2(jk,1,jm) = sp(ila,1,jk)
            zsp2(jk,2,jm) = sp(ila,2,jk)
          enddo
          do jk = 1, nflev
            zsp2(jk+nksdim,1,jm) = sptb(ila,1,jk)
            zsp2(jk+nksdim,2,jm) = sptb(ila,2,jk)
          enddo
        enddo
!
        idim=2*mbandsp(jband)
!
        CALL DGEMM('T','N',NKSDIM,idim,NKSDIM2,ONE8,CORNS(1,1,jband-1,1),NKSDIM2,
     &             ZSP2(1,1,1),NKSDIM2,ZERO8,ZSP(1,1,1),NKSDIM)
!
        do jm = 1, mbandsp(jband)
          ila=mila(jm,jband) 
          do jk = 1, nksdim
            sp(ila,1,jk) = zsp(jk,1,jm)
            sp(ila,2,jk) = zsp(jk,2,jm)
          enddo
        enddo
!
      enddo ! jband
 998  continue
!
      do jband = nband+1, nbandtot
        do jm = 1, mbandsp(jband)
            do jk = 1, nksdim  ! psi,chiu,phiu etc...
            ila=mila(jm,jband) 
            sp(ila,1,jk) = 0.0
            sp(ila,2,jk) = 0.0
          enddo
        enddo
      enddo
!
      return
      end