CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of MIRHEAPJ from mirheapj.f
CMAX: ----------------------------------------------------
      SUBROUTINE mirheapj_v1(test,iheap,os,ln,i,n)
C  MIN-REAL-HEAP-ADJUST
C  THE COMPLETE BINARY TREE OF LENGTH N WITH MIN HEAPS AT THE ROOTS
C  2*I AND 2*I+1 IS ADJUSTED TO CONTAIN A MIN HEAP AT THE ROOT I.
cmax: Changed argument IHEAP to passed with index
      INTEGER os
      INTEGER ln
      INTEGER iheap(1-os+1:ln+1-os), n, i, j, iheapi
      REAL TEST (N), VALUE
!hpf$ distribute iheap(block)
!hpf$ distribute test(block)
      j = 2 * i
      iheapi = iheap(i)
      value = test(iheapi)
  100 CONTINUE
      IF (j .LE. n) THEN
        IF (j .LT. n) THEN
          IF (test(iheap(j)) .GT. test(iheap(j + 1))) THEN
            j = j + 1
          ENDIF
        ENDIF
        IF (value .GT. test(iheap(j))) THEN
          iheap(j / 2) = iheap(j)
          j = 2 * j
          GOTO 100
        ENDIF
      ENDIF
  200 CONTINUE
      iheap(j / 2) = iheapi
      RETURN
      END
CMAX: ----------------------------------------------------
