      SUBROUTINE PSETUP(UNIT,NAME1,NAME2,LV1,LV2) 
C
C     * JAN 14/93 - E.CHAN.   CONVERT CODED LEVELS INTO ALTERNATE, 
C                             MONOTONICALLY INCREASING CODE.
C     * JUL 26/92 - M.LAZARE. REPLACEMENT OF UNFORMATTED READ BY CALL
C     *                       TO FBUFFIN.  
C     * M. LAZARE  -- AUG 13/90. REMOVE HARD-COAT ON IDAT, SINCE PASSED.
C     * F. ZWIERS  -- JAN 14/85 
C 
C     * SET UP COMMON/PREC/ FOR PUTREC TO USE 
C 
C     * DETERMINE THE NUMBER OF RECORDS IN A SET AT LEVELS IN THE 
C     * RANGE LV1 TO LV2 INCLUSIVE OR THE NUMBER OF RECORDS IN A
C     * SET FOR A PARTICULAR VARIABLE AT LEVELS IN THE RANGE LV1
C     * TO LV2 AND STORE IN NSET. 
C     * 
C     * UNIT = INPUT UNIT NUMBER
C     * NAME1 = NAME OF FIRST VARIABLE OR 4H ALL
C     * NAME2 = NAME OF SECOND VARIABLE.
C     * LV1,LV2 = THE RANGE OF LEVELS 
C     * NSET = NUMBER OF RECORDS PER TIME STEP WITH LV1<=IBUF(4)<=LV2 
C     *        FOR VARIABLE SPECIFIED IN 'NAME'.
C     * 
C 
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      INTEGER T,UNIT,TOLD(2),TSTEP(2),NSET(2),ISET(2) 
      LOGICAL FIRST(2),SECOND(2)
C     DATA NALL/4H ALL/ 
      COMMON /ICOM/IBUF(8),IDAT(1)
      COMMON /PREC/TOLD,TSTEP,NSET,ISET,FIRST,SECOND
C 
C-----------------------------------------------------------------------------
C 
      NALL=NC4TO8(" ALL")
      REWIND UNIT 
C     READ(UNIT,END=1000) IBUF
      CALL FBUFFIN(UNIT,IBUF,-8,K,LEN)
      IF(K.GE.0) GO TO 1000  
      T=IBUF(2) 
      REWIND UNIT 
      NSET(1)=0 
      NSET(2)=0 
C
C     * CONVERT CODED LEVELS INTO CODE THAT IS MONOTONICALLY INCREASING.
C
      CALL LVACODE(LEV1,LV1,1)
      CALL LVACODE(LEV2,LV2,1)
C
  100 CONTINUE
C        READ(UNIT,END=1000) IBUF 
         CALL FBUFFIN(UNIT,IBUF,-8,K,LEN)
         IF(K.GE.0) GO TO 1000  
         IF(IBUF(2).EQ.T)THEN 
            CALL LVACODE(LEVEL,IBUF(4),1) 
            IF(LEVEL.GE.LEV1 .AND. LEVEL.LE.LEV2)THEN 
               IF(NAME1.EQ.NALL .OR. IBUF(3).EQ.NAME1)
     1                               NSET(1)=NSET(1)+1
               IF(IBUF(3).EQ.NAME2) NSET(2)=NSET(2)+1 
            ENDIF 
         ELSE 
            GOTO 1000 
         ENDIF
         GOTO 100 
C 
C-----------------------------------------------------------------------------
C 
 1000 CONTINUE
      DO 1100 I=1,2 
         ISET(I)=0
         FIRST(I)=.TRUE. 
 1100 CONTINUE
      REWIND UNIT 
      RETURN
      END 
