!-------------------------------------- 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 PRSCAL(KDIM,PX,PY,DDSC) 4
#if defined (DOC)
*
***s/r PRSCAL: inner product in canonical space
*
*
*Author  : P. Gauthier *ARMA/AES  January 27, 1993
*Revision:
*       JM Belanger CMDA/SMC  Apr 2001
*                   . 32 bits conversion (eliminate use of DBLE)
*       M Buehner *ARMA/SMC April 2002
*                   . Added Hessian Eigenvector preconditioning
*                     (optimized by M. Valin)
*    -------------------
**    Purpose: evaluation of the inner product used in the
*     .        minimization
*
*Arguments
*     i : KDIM     : dimension of the vectors
*     i : PX, PY   : vector for which <PX,PY> is being calculated
*     o : DDSC     : result of the inner product
*
* Implicit argument:
*     SCALP(KDIM)contained in COMCVA
*
#endif
      IMPLICIT NONE
*implicits
#include "comdim.cdk"
#include "comcva.cdk"
#include "comanl.cdk"
*
      INTEGER KDIM, J, RR, IERR
      REAL*8 PX(KDIM), PY(KDIM)
      REAL*8 DDSC,TEMPO
      REAL*8 ZPY(KDIM)
C
      IF(NPRECON.ge.1) THEN
c SCALP NOT INCLUDED WITH PRECON!!!
        DDSC = 0.
c CALCULATE PX^T*(I + G1*G1^T)*PY
        DO J = 1, KDIM
          ZPY(J)= PY(J)
        ENDDO
c
        DO RR = 1, NPRECON
          TEMPO=0.0
          DO J = 1, KDIM
            TEMPO = TEMPO + RRNK1(J,RR)*PY(J)
          ENDDO
          DO J = 1, KDIM
            ZPY(J)= ZPY(J) + RRNK1(J,RR)*TEMPO
          ENDDO
        ENDDO
c
        DO J = 1, KDIM
           DDSC = DDSC + PX(J)*ZPY(J)
        ENDDO
c
      ELSE
        DDSC = 0.
        DO 101 J = 1, KDIM
           DDSC = DDSC + SCALP(J)*PX(J)*PY(J)
 101    CONTINUE
      ENDIF
c
      RETURN
      END