CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of SATHGT from sathgt.f
CMAX: ----------------------------------------------------
      SUBROUTINE sathgt_v1(kx,os,ln,lat,os100,ln100,lon,os101,ln101,z,
     &    os102,ln102,pref,nobs,zmod,z1000)
C  COMPUTE SATELLITE HEIGHTS FROM THICKNESSES USING FIRST GUESS HEIGHT
C  FIELD AND UPDATED HEIGHT AT 1000 MB.
cmax: Changed argument KX to passed with index
      INTEGER os
      INTEGER ln
cmax: Changed argument LAT to passed with index
      INTEGER os100
      INTEGER ln100
cmax: Changed argument LON to passed with index
      INTEGER os101
      INTEGER ln101
cmax: Changed argument Z to passed with index
      INTEGER os102
      INTEGER ln102
      INTEGER NOBS
      REAL DZOBS (10000)
      REAL DZ1000 (13104)
      INTEGER I
      INTEGER IBATCH
      INTEGER II
      INTEGER IREF
      REAL kx(1-os+1:ln+1-os)
      REAL lat(1-os100+1:ln100+1-os100)
      INTEGER LBATCH
      INTEGER LLAST
      REAL lon(1-os101+1:ln101+1-os101)
      INTEGER N
      INTEGER NBATCH
      DIMENSION PREF (NOBS)
      DIMENSION z(1-os102+1:ln102+1-os102)
      DIMENSION ZMOD (im, jnp, mlev)
      REAL ZREF
      DIMENSION Z1000 (im, jnp)
      CHARACTER * 60 message
C  ANALYSIS CONTROL PARAMETERS
      LOGICAL STRAT, SLP, FDCOS, FEXP, SAVEAE, SIGDAT
      COMMON / CONTRL / im, jnp, NB, NDALT, NHMS, NLAY, NLAYM1, NLAYP1, 
     &NYMD, STRAT, IDIMEN, SLP, FDCOS, FEXP, SAVEAE, SIGDAT, MAXREP
      COMMON / pmh / pmand (18)
C VERTICAL INDICES
      COMMON / MLAY / mlev, MLEVM1, MMIX, MMIXM1, LS, LSM1
!hpf$ distribute dz1000(block)
!hpf$ distribute dzobs(block)
!hpf$ distribute kx(block)
!hpf$ distribute lat(block)
!hpf$ distribute lon(block)
!hpf$ distribute pmand(block)
!hpf$ distribute pref(block)
!hpf$ distribute z(block)
!hpf$ distribute z1000(block,block)
!hpf$ distribute zmod(block,block,block)
      DATA FILL / 1.e15 /
      message(1:60) = ' '
C COMPUTE DELZ AT THE GRIDPOINTS
      loop_count = 0
      DO 7002 i = 1 , im
        DO 7000 j = 1 , jnp
          loop_count = loop_count + 1
          dz1000(loop_count) = z1000(i,j) - zmod(i,j,mlev)
  101     CONTINUE
 7000   CONTINUE
        CONTINUE
 7002 CONTINUE
C  DO THE HEIGHT COMPUTATION IN BATCHES
      lbatch = 10000
      nbatch = nobs / lbatch
      IF (mod(nobs,lbatch) .NE. 0) THEN
        nbatch = nbatch + 1
        llast = mod(nobs,lbatch)
      ELSE
        llast = lbatch
      ENDIF
      IF (nbatch .EQ. 0) THEN
        message = ' SATHGT: Zero batch size detected. '
        CALL flash(5,message,1)
      ENDIF
      DO 7006 n = 1 , nbatch
        ibatch = lbatch * (n - 1) + 1
        IF (n .EQ. nbatch) THEN
          lbatch = llast
        ENDIF
C INTERPOLATE DZ TO OBS LOCATIONS IN THE BATCH.
        CALL terpv_v2(lat,ibatch - (1 - os100),ln100,lon,ibatch - (1 - 
     &      os101),ln101,dzobs,1,10000,lbatch,dz1000)
C  COMPUTE HEIGHTS FOR SATELLITE OBSERVATIONS IN THE BATCH
        ii = ibatch - 1
C  CHECK THAT REFERANCE PRESSURE IS ONE OF THE VALID MANDATORY LEVELS
        DO i = 1 , lbatch
          ii = ii + 1
          IF ((kx(ii) .GT. 30.0) .AND. (kx(ii) .LE. 86.0) .AND. (z(ii) 
     &          .LT. 1.0E+10)) THEN
            iref = iplev(pref(ii))
            IF ((iref .LE. mlev) .AND. (abs(pref(ii) - pmand(iref)) 
     &            .LT. 0.001)) THEN
              CALL terp(im,jnp,lat(ii),lon(ii),zmod(1,1,iref),zref)
              z(ii) = z(ii) + zref + dzobs(i)
            ELSE
              z(ii) = fill
            ENDIF
          ENDIF
        ENDDO
        CONTINUE
 7006 CONTINUE
      RETURN
      END
CMAX: ----------------------------------------------------
