      SUBROUTINE READPAR
C-----------------------------------------------------------------------
C Read file names and parameters.  Angles converted to radians here.
C-----------------------------------------------------------------------
C
      IMPLICIT UNDEFINED (A-Z)
C
      INCLUDE     'PARAMETR.INC'
      INCLUDE     'ELLIPSE.INC'
C
      REAL*8      DUMMY
      INTEGER*4   MODE, J, IPLOT
      CHARACTER*3 AGE

C
      WRITE (OUTC,501) ' Control parameters (end with /)'
      WRITE (OUTC,501) ' e.g. PLOT_DEV '                   
      MODE=2
      CALL KEYIN(PARS,VALS,NPARS,ENDMRK,MODE,INC,OUTC)
C
      WRITE (OUTC,501) VERSN   
      RAMAX  = VALS(1)
      DECMAX = VALS(2)
      DOTS   = VALS(4).EQ.0D0
      LINEWD = VALS(5)
      NFONT  = VALS(6)
C      WRITE (PLOT_DEV, '(A)') (VALS(J),J=7,10) ! VALS 11-18 NOT USED
      PLOT_DEV='/LJL'
      PLOT   = .TRUE.
      CALL STR$UPCASE(PLOT_DEV,PLOT_DEV)
C
      WRITE (DATAFILE, '(12A8)') (VALS(J),J=19,30)
      WRITE (OUTFILE,  '(12A8)') (VALS(J),J=31,42)
C      DATAFILE = 'ALPEQU.DAT'
C      OUTFILE = 'TEST.OUT'
      WRITE(6,*) ' OUTFILE = ' , OUTFILE
C
      AGE = 'NEW'
    9 IF (OUTFILE.NE.' ') THEN
            OPEN (UNIT=PR, FILE=OUTFILE, STATUS=AGE,
     1           FORM='FORMATTED',IOSTAT=IER)
      ELSE
            OPEN (UNIT=PR, FILE='ELLIPSE.OUT', STATUS=AGE,
     1           FORM='FORMATTED',IOSTAT=IER)
      END IF

      IF ( IER .NE. 0 ) THEN
          WRITE(OUTC,*) ' FILE EXISTS: '//OUTFILE
          WRITE(OUTC,*) ' OVERWRITE IT ? '
          READ (INC,*) ANSWER
          IF ( ANSWER.EQ.'Y' .OR. ANSWER.EQ.'y' ) THEN
              AGE = 'OLD'
              GO TO 9
          ELSE
              GO TO 11
          END IF
      END IF

   11 CONTINUE 

      DEL_COUNT   =  0

      IF (VALS(43).NE.-1000.) A_APP    = VALS(43)
      IF (VALS(44).NE.-1000.) B_APP    = VALS(44)
      IF (VALS(45).NE.-1000.) E_APP    = VALS(45)
      IF (VALS(46).NE.-1000.) A_ANGLE  = VALS(46) * RPDEG
      IF (VALS(47).NE.-1000.) CRA      = VALS(47)
      IF (VALS(48).NE.-1000.) CDEC     = VALS(48)

C      WRITE(OUTC,'(1X,A,6(F8.3,1X))')
C     1 'READPAR: VALS(43) TO (48):',VALS(43),VALS(44),VALS(45),
C     2      VALS(46),VALS(47),VALS(48)

      IF (VALS(43).NE.-1000..AND.
     1    VALS(44).NE.-1000..AND.
     2    B_APP.GT.A_APP)         THEN   ! IF B > A, SWAP AXES

        DUMMY     =  A_APP
        A_APP     =  B_APP
        B_APP     =  DUMMY
        DUMMY     =  VALS(43)
        VALS(43)  =  VALS(44)
        VALS(44)  =  DUMMY
        A_ANGLE   =  A_ANGLE + 90.

      END IF

      IF (VALS(43).NE.-1000..AND.VALS(44).NE.-1000.) THEN
          E_APP   =  SQRT(A_APP**2 - B_APP**2) / A_APP
      END IF

      STATE       = 'N'

      IF (VALS(47).NE.-1000..AND.
     2    VALS(48).NE.-1000.)    STATE = 'C'

      IF (VALS(43).NE.-1000..AND.
     1    VALS(46).NE.-1000..AND.
     2    VALS(47).NE.-1000..AND.
     3    VALS(48).NE.-1000.)    STATE = 'AC'

      IF (VALS(44).NE.-1000..AND.
     1    VALS(46).NE.-1000..AND.
     2    VALS(47).NE.-1000..AND.
     3    VALS(48).NE.-1000.)    STATE = 'BC'

      IF (VALS(43).NE.-1000..AND.
     1    VALS(44).NE.-1000..AND.
     2    VALS(46).NE.-1000..AND.
     3    VALS(47).NE.-1000..AND.
     4    VALS(48).NE.-1000.)    STATE = 'ABC'

      IF (VALS(43).NE.-1000..AND.
     1    VALS(45).NE.-1000..AND.
     2    VALS(46).NE.-1000..AND.
     3    VALS(47).NE.-1000..AND.
     4    VALS(48).NE.-1000.)    STATE = 'ACE'

      IF (VALS(43).NE.-1000..AND.
     1    VALS(45).NE.-1000..AND.
     2    VALS(46).NE.-1000..AND.
     3    VALS(47).NE.-1000..AND.
     4    VALS(48).NE.-1000.)    STATE = 'BCE'

C     --------------------------------------------------------------
      IF (VALS(45).NE.-1000.) THEN
        IF      (STATE.EQ.'ACE')  THEN   ! CALC. B_APP

          B_APP   = A_APP * SQRT(1. - E_APP**2)
          STATE   = 'ABC'

        ELSE IF (STATE.EQ.'BCE')  THEN   ! CALC. A_APP

          A_APP   = B_APP / SQRT(1. - E_APP**2)
          STATE   = 'ABC'

        END IF

      END IF

C     --------------------------------------------------------------
      IF (STATE.EQ.'AC'.OR.STATE.EQ.'ABC') THEN
C              SET MAJOR AXIS
        ARA(1)  =  CRA  + A_APP * SIN(A_ANGLE)
        ADEC(1) =  CDEC + A_APP * COS(A_ANGLE)
        ARA(2)  =  2.*CRA  - ARA(1)
        ADEC(2) =  2.*CDEC - ADEC(1)
      END IF

C     --------------------------------------------------------------
      IF (STATE.EQ.'BC'.OR.STATE.EQ.'ABC') THEN
C              SET MINOR AXIS
        BRA(1)  =  CRA  - B_APP * COS(A_ANGLE)
        BDEC(1) =  CDEC + B_APP * SIN(A_ANGLE)
        BRA(2)  =  2.*CRA  - BRA(1)
        BDEC(2) =  2.*CDEC - BDEC(1)
      END IF

C     --------------------------------------------------------------

      IF (VALS(49).NE.-1000.) EPOCH    = VALS(49)
      IF (VALS(50).NE.-1000.) INCLIN   = VALS(50) * RPDEG
      IF (VALS(51).NE.-1000.) ARG_PERI = VALS(51) * RPDEG
      IF (VALS(52).NE.-1000.) ASC_NODE = VALS(52) * RPDEG
      IF (VALS(53).NE.-1000.) A_TRUE   = VALS(53)
      IF (VALS(54).NE.-1000.) E_TRUE   = VALS(54)
      IF (VALS(55).NE.-1000.) PERIOD   = VALS(55)

      IF ( VALS(49).NE.-1000. .AND. 
     1     VALS(50).NE.-1000. .AND. 
     2     VALS(51).NE.-1000. .AND. 
     3     VALS(52).NE.-1000. .AND. 
     4     VALS(53).NE.-1000. .AND. 
     5     VALS(54).NE.-1000. .AND. 
     6     VALS(55).NE.-1000.       ) TRUFIT = .TRUE.

      WRITE(6,501) DATAFILE
      WRITE(6,501) OUTFILE
      WRITE(6,501) PLOT_DEV
      WRITE(6,501) PLOTFILE

C SET DISPLAY DEFAULTS
      DISP_ORB  = .TRUE.      ! DISPLAY MODEL ORBIT
      DISP_CALC = .TRUE.      ! DISPLAY CALC. POS. AT OBS. TIMES
      DISP_ERR  = .TRUE.      ! DISPLAY ERROR BARS
      DISP_CURV = .FALSE.     ! DISPL. ORB. NOT AS CURVE, BUT AS PTS

      SYM_DAT   = 17          ! DISPLAY DATA WITH BULLETS
      SYM_MOD   = 21          ! DISPLAY MODEL WITH SMALL CIRCLES
      SYM_ORB   = 1           ! DISPLAY ORBIT WITH DOTS 
      AXIS      = 0           ! DISPLAY BOX W/ COORDS, BUT NO ZERO LINES

      ERRLINWD  = LINEWD      ! LINEWIDTH FOR ERROR BARS
      ERRLINTY  = 1           ! LINE TYPE FOR ERROR BARS
      O_CLINWD  = LINEWD      ! LINEWIDTH AND TYPE FOR CONNECTING CALC.
      O_CLINTY  = 1           ! POINTS WITH OBSERVED POINTS
      ORBLINWD  = LINEWD      ! LINEWIDTH FOR ORBIT CURVE
      ORBLINTY  = 1           ! LINE TYPE FOR ORBIT CURVE
                              ! LINEWD IS SET FROM KEYIN


      RETURN

  900 WRITE(OUTC,501) ' Some kind of plot problem with PGBEGIN'
      RETURN
C---------------------------------------------------------------
C FORMAT STATEMENTS
  501 FORMAT(1X, A)
C---------------------------------------------------------------
      END

