C******************** START FILE CONSEL.FOR ; GROUP CONCTR *************
C=============================================
C  CONSEL
C   SELECT CONTOUR VALUES FOR CONTOUR PLOTS
C     D. MC CUNE MAY 21 1980
C
C
C   ILOGC: =1==> LINEAR SPACING OF CONTOURS
C          =2==> LOG SPACING OF CONTOURS (IN FCN UNITS)
C
C   CMIN,CMAX--  LOWER,UPPER BND ON CONTOURS
C      IF CMIN OR CMAX .LE. 0, LOG SPACING NOT ALLOWED
C      NMAX:  MAX # CONTOURS
C
C  OUTPUT:
C      ZCNTR  CHOSEN CONTOURS
C      NRET:  # CHOSEN
C
      SUBROUTINE CONSEL(LUNTRM,ILOGC,CMIN,CMAX,NMAX,ZCNTR,NRET)
C
      DIMENSION ZCNTR(NMAX)
C
C  START OF EXECUTABLE CODE
C
      IF(NMAX.GT.2) GO TO 20
        NRET=1
        ZCNTR(1)=0.5*(CMIN+CMAX)
        IF(CMIN.EQ.CMAX) GO TO 190
        GO TO 1000
C
 20   CONTINUE
      GO TO (100,200) ILOGC
C  LINEAR SPACING
 100  CONTINUE
      ITRY=0
C  REVERSE CMIN,CMAX IF NECESSARY
      IF(CMIN.EQ.CMAX) GO TO 190
      IF(CMIN.LT.CMAX) GO TO 110
      ZMIN=CMAX
      CMAX=CMIN
      CMIN=ZMIN
C
 110  CONTINUE
      ZWID=CMAX-CMIN
      ZWPI=ZWID/(NMAX+1)
      Z=ALOG10(ZWPI)
      IWL10=IFIXR(Z)
C
 120  CONTINUE
      ITRY=ITRY+1
      IF(ITRY.EQ.1) ZINTVL=1.0*10.0**IWL10
      IF(ITRY.EQ.2) ZINTVL=2.0*10.0**IWL10
      IF(ITRY.EQ.3) ZINTVL=5.0*10.0**IWL10
      IF(ITRY.LE.3) GO TO 125
      ITRY=0
      IWL10=IWL10+1
      GO TO 120
C
 125  CONTINUE
      IFI0=IFIXR(CMIN/ZINTVL)
      IFI0=IFI0+1
      ZCNTR(1)=IFI0*ZINTVL
      DO 130 INT=2,NMAX
        INTM1=INT-1
        ZNEXT=ZCNTR(INTM1)+ZINTVL
        ZCNTR(INT)=ZNEXT
 130  CONTINUE
      IF(ZCNTR(NMAX).GE.(CMAX-ZINTVL)) GO TO 140
C  TOO MANY INTERVALS
      GO TO 120
C
 140  CONTINUE
      do int=nmax,1,-1
        if(zcntr(int).le.cmax) go to 149
      enddo
      int=1
 149  continue
      nret=int
      GO TO 1000
C
 190  CONTINUE
C  CMIN=CMAX
        NRET=1
        IF(CMIN.EQ.0.0) ZCNTR(1)=1.0E-30
        IF(CMIN.NE.0.0) ZCNTR(1)=0.0
        GO TO 1000
C
C  LOG SPACING
C
 200  CONTINUE
      IF(.NOT.((CMIN.LE.0.0).OR.(CMAX.LE.0.0).OR.
     >          (CMIN.GE.CMAX))) GO TO 210
 205  CONTINUE
      WRITE(LUNTRM,2001)
 2001 FORMAT(
     >  ' % SUB:CONSEL CONTOUR LIMITS NOT SUITABLE FOR LOG-SPACING'/)
      IF(.NOT.((CMIN.LE.0.0).AND.(CMAX.GT.0.0))) GO TO 100
C  STANDARD FIXUP
      WRITE(LUNTRM,20010)
20010 FORMAT(' % SUB:CONSEL STANDARD FIXUP TAKEN')
      CMIN=1.E-4*CMAX
C  PROCEDE
 210  CONTINUE
      Z=ALOG10(CMAX/CMIN)
      IZ=IFIXR(Z)
      IF(IZ.LE.0.0) GO TO 205
C
C  IZ IS A LOWER LIMIT ON THE # OF DECADES RANGED OVER BY CMIN,CMAX
      ZPI=FLOAT(IZ)/(NMAX+1)
      IPI=IFIXR(ZPI)
C
C  IPI= " # OF DECADES PER INTERVAL BETWEEN CONTOURS "
      IPI=IPI-1
C
 225  CONTINUE
      IPI=IPI+1
      IF(IPI.EQ.0) GO TO 250
      IMIN=IFIXR(ALOG10(CMIN))+1
      ZCNTR(1)=10.0**IMIN
      ZMUL=10.0**IPI
      DO 230 INT=2,NMAX
        INTM1=INT-1
        ZNEXT=ZMUL*ZCNTR(INTM1)
        ZCNTR(INT)=ZNEXT
 230  CONTINUE
      ZNEXT=ZNEXT*ZMUL
      IF(ZNEXT.LT.CMAX) GO TO 225
C
 240  CONTINUE
      do int=nmax,1,-1
        if(zcntr(int).le.cmax) go to 249
      enddo
      int=1
 249  continue
      nret=int
      GO TO 1000
C
C  MORE THAN ONE CONTOUR PER DECADE
 250  CONTINUE
      IPDEC=4
C
 255  CONTINUE
      IPDEC=IPDEC-1
      IF(IPDEC.LE.0) GO TO 225
      IEMIN=IFIXR(ALOG10(CMIN))
      ZSCI=1.0
C
 260  CONTINUE
      ZSCI=ZFSCC1(ZSCI,IPDEC)
      ZTES=ZSCI*10.0**IEMIN
      IF((ZSCI.EQ.10.0).OR.(ZTES.GT.CMIN)) GO TO 270
      GO TO 260
C
C  FOUND START POINT
 270  CONTINUE
      ZCNTR(1)=ZTES
      IPNT=1
C
 275  CONTINUE
      IF(ZSCI.NE.10.0) GO TO 278
      ZSCI=1.0
      IEMIN=IEMIN+1
C
 278  CONTINUE
      ZSCI=ZFSCC1(ZSCI,IPDEC)
      ZTES=ZSCI*10.0**IEMIN
      IF(ZTES.GT.CMAX) GO TO 290
      IPNT=IPNT+1
      ZCNTR(IPNT)=ZTES
      IF(IPNT.EQ.NMAX) GO TO 290
      GO TO 275
C
C  CHECK TO SEE IF ENTIRE RANGE IS COVERED
 290  CONTINUE
      IF(IPNT.LT.NMAX) GO TO 295
      ZSCI=ZFSCC1(ZSCI,IPDEC)
      ZTES=ZSCI*10.0**IEMIN
      IF(ZTES.LT.CMAX) GO TO 255
C
 295  CONTINUE
      NRET=IPNT
C
      GO TO 1000
C-----------------------
C  EXIT:
 1000   CONTINUE
      RETURN
C
      	END
C******************** END FILE CONSEL.FOR ; GROUP CONCTR ***************
