!-------------------------------------- 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 rdptotla_simul 1,1
#if defined (DOC)
*
***s/r rdptotla_simul  - Write the balance operators: Ptot and Ekman for LAM intercomparisons.
*
*Author:    Luc Fillion - ARMA/EC - 3 Sep. 2008.
*Revision:
*
*Arguments: NONE
*
#endif
      IMPLICIT NONE
*implicits
*
#include "pardim.cdk"
#include "comdim.cdk"
#include "comlun.cdk"
#include "comcorr.cdk"
#include "comgem.cdk"
#include "comcva.cdk"
*
*     Local variables
*
      character*1 cltypvar
      character*2 clnomvar
      character*8 cletiket
      INTEGER ini,inj,ink,IERR, IPAK,jk,jk1,jk2,jj
      INTEGER FNOM, FSTOUV, FSTFRM, FCLOS, VFSTECR
      INTEGER IP1,IP2,IP3, IDATYP, IDATEO
      INTEGER vfstlir
      real   zptop4, zpref4,zrcoef4
      real*8 zps,zlev(nflev)
      real*8 zptot(nflev+1,nflev,120)
C
      EXTERNAL FNOM, FSTOUV, FSTFRM, FCLOS, VFSTECR
      INTEGER IM,JM,KM
!
!!
      if(lunitptot) then
        write(nulout,*) ' '
        write(nulout,*) '-----------------------------------------'
        write(nulout,*) 'rdptotla_simul: UNIT MATRIX USED FOR PTOT'
        write(nulout,*) '-----------------------------------------'
        write(nulout,*) ' '
        ptot(:,:,:) = 0.0
        do jj = 1,nj
          do jk1=1,nflev
            ptot(jk1,jk1,jj) = 1.0
          enddo
        enddo
      else
        IPAK = -32
        IDATYP = 5
!
        cletiket = 'P_TO_TGE'
!
        ini = nflev + 1
        inj = nflev
        ink = 120
        ip1 = -1
        ip2 = -1
        ip3 = -1
        idateo = -1
        cltypvar = 'X'
        clnomvar = 'ZZ'
!
        ierr = vfstlir(zptot,nulbgst,ini,inj,ink,idateo,     ! N-->S
     &                 cletiket,ip1,ip2,ip3,cltypvar,clnomvar)
!
        do jj = 1,nj
          DO JK1 = 1,NFLEV+1
            DO JK2 = 1,NFLEV
              if(jj.eq.1) then
                write(nulout,*) 'rdptotla_simul:  Read: jk1,jk2,zptot(jk1,jk2,1)=',
     &           jk1,jk2,zptot(jk1,jk2,1)
              endif
              ptot(jk1,jk2,jj) = zptot(jk1,jk2,1)
            enddo
          enddo
        enddo
      endif
C
      RETURN
      END