CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of MIXANL from mixanl.f
CMAX: ----------------------------------------------------
      SUBROUTINE mixanl(fcerr,rh,rmix,pmand,psfc,cov,aquan,asdae,im,jnp,
     &    mlev,mmix,nobs,data,bq)
      
      INTEGER MaxObservPoints
      PARAMETER (MaxObservPoints = 150000)
C  DRIVER FOR THE MIXING RATIO ANALYSIS
C  ANALYSIS IS DONE IN UNITS OF G/KG TO AVOID INDETERMINATE RESULTS IN
C  THE MATRIX EQUATION SOLVER.
c
c     Maximal observation points
c
c
c
      DIMENSION aquan (im * jnp, mlev)
      DIMENSION asdae (im * jnp, mlev)
      INTEGER bq (MaxObservPoints)
      EXTERNAL cov
      REAL data (MaxObservPoints * 10)
      LOGICAL onestage
      REAL fill
      INTEGER IMJM
      INTEGER K
      INTEGER LEV
      INTEGER LEV1
      INTEGER MaxData
      INTEGER NHMS
      INTEGER NYMD
      DIMENSION fcerr (im * jnp, mlev)
      REAL psfc (im * jnp)
      REAL pmand (mlev)
      LOGICAL repack
      DIMENSION rh (im * jnp, mlev)
      DIMENSION rmix (im * jnp, mlev)
      CHARACTER * 60 message
      COMMON / DATAPTRS / IKX, ILAT, ILON, IPRES, ITYPE, IMIX, IFCER
      COMMON / scan / maxobs, rscan, onestage, MaxData
      COMMON / sparam / lsolve, ns, nr, nv, nh (13104), nq, kq (3), volc
     &entre_x (13104), ngv, volcentre_y (13104), glatup (13104), glonup 
     &(13104)
!hpf$ distribute aquan(block,block)
!hpf$ distribute asdae(block,block)
!hpf$ distribute bq(block)
!hpf$ distribute data(block)
!hpf$ distribute fcerr(block,block)
!hpf$ distribute glatup(block)
!hpf$ distribute glonup(block)
!hpf$ distribute kq(block)
!hpf$ distribute nh(block)
!hpf$ distribute pmand(block)
!hpf$ distribute psfc(block)
!hpf$ distribute rh(block,block)
!hpf$ distribute rmix(block,block)
!hpf$ distribute volcentre_x(block)
!hpf$ distribute volcentre_y(block)
      DATA fill / 1.e10 /
      CALL getconi('NYMD    ',nymd)
      CALL getconi('NHMS    ',nhms)
      WRITE( 6,900 ) nymd,nhms
      imjm = im * jnp
      lev1 = mlev - 5
      kq(1) = 1
      IF (nobs .EQ. 0) THEN
        message = 'MIXANL: No observations!'
        CALL flash(2,message,1)
      ENDIF
C  INTERPOLATE FORECAST ERROR TO DATA POINTS
      ifcer = imix + nobs
      CALL vterpv_v1(data,ilat,maxobservpoints * 10,data,ilon,
     &    maxobservpoints * 10,data,ipres,maxobservpoints * 10,data,
     &    ifcer,maxobservpoints * 10,nobs,fcerr)
C  SETUP WORK SPACE
      DO 7002 lev = lev1 , mlev
        DO 7000 k = 1 , imjm
          aquan(k,lev) = 0.0
          asdae(k,lev) = fcerr(k,lev)
  100     CONTINUE
 7000   CONTINUE
        CONTINUE
 7002 CONTINUE
C  FORM AND SOLVE COVARIANCE MATRICES
c     CALL ZEITBEG ('M SOLVE0')
      CALL solvedrv(lev1,mlev,fcerr,cov,aquan,asdae,data,nobs)
c     CALL ZEITEND
C  ADD INCREMENT TO FIRST GUESS FIELD AND FIX ANY NEGATIVE HUMIDITIES
      DO 7006 lev = lev1 , mlev
        DO 7004 k = 1 , imjm
          IF (rmix(k,lev) .NE. fill) THEN
            rmix(k,lev) = rmix(k,lev) + aquan(k,lev)
          ENDIF
          IF (rmix(k,lev) .LT. 0.001) THEN
            rmix(k,lev) = 0.001
          ENDIF
          fcerr(k,lev) = asdae(k,lev)
  300     CONTINUE
 7004   CONTINUE
        CONTINUE
 7006 CONTINUE
      RETURN
900   FORMAT ('0MIXANL: START MOISTURE ANALYSIS FOR NYMD/NHMS',2I8/)
      END
