      SUBROUTINE INTERP(*)
C     SUBROUTINE INTERP. INTERPOLATE THE N(H) DATA OBTAINED FROM THE
C     SCALED X TRACE TO DETERMINE HEIGHTS AT FIXED DENSITIES AND
C     DENSITIES AT FIXED HEIGHTS. WRITE OUT INTERPOLATED RESULTS.
      IMPLICIT REAL*8(A-H,O-Z)
      REAL*4 DLAT,DLONG,DATE
      COMMON /CALC/ AA(50),BB(50),F(50),HP(50),FH(50),TH(70),DEN(70)
      COMMON /SWJTCH/ ISAT,LOCSAT,IFXS,NCASES,ICODE(4),N,METHOD,IORD,IP
      COMMON /PL/ TH1(70),ED1(70),TH2(70),ED2(70),M,M1
      COMMON /OCALC/ FO(50),HPO(50)
      COMMON /IO/ IYR,IDY,ITI,LMT,TITLE(40),DIP,FHS
      DIMENSION                 DENREF(56),D(2),Z(2)
      SAVE
      DATA THINT/50.0/
      DATA DENREF / 1.0E2,2.0E2,2.5E2,3.0E2,4.0E2,5.0E2,6.0E2,7.0E2,
     D              8.0E2,9.0E2,1.0E3,1.25E3,1.5E3,2.0E3,2.5E3,3.0E3,
     D              4.0E3,5.0E3,6.0E3,7.0E3,8.0E3,9.0E3,1.0E4,1.2E4,
     D              1.4E4,1.6E4,1.8E4,2.0E4,2.3E4,2.7E4,3.0E4,3.5E4,
     D              4.0E4,5.0E4,6.0E4,7.0E4,8.0E4,9.0E4,1.0E5,1.25E5,
     D              1.5E5,2.0E5,2.5E5,3.0E5,3.5E5,4.0E5,4.5E5,5.0E5,
     D              6.0E5,7.0E5,8.0E5,9.0E5,1.0E6,1.25E6,1.5E6,2.0E6 /
C     WRITE OUT RESULTS FROM SCALED POINTS.
      WRITE(6,1)
      WRITE(6,2) (TH(I),DEN(I),I=1,N)
C     DENSITIES AT FIXED HEIGHTS OBTAINED FROM LAMINATION CONTAINING
C     DESIRED HEIGHT AND FROM EQUATION OF LAMINATION
      PT=3500.0
 1400 IF (PT .LT. TH(1)) GO TO 1500
      PT=PT-THINT
      IF (PT) 1600,1600,1400
 1500 ED1(1)=DEN(1)
      TH1(1)=TH(1)
      D2LN=DLOG(DEN(1))
      PT1=TH(1)
      K=2
      DO 1700 I=2,N
      D1LN=D2LN
      D2LN=DLOG(DEN(I))
      PT2=TH(I)
 1800 IF(PT2.GE.PT1) GO TO 1600
      IF(PT2.GT.PT) GO TO 1900
      IF (PT2 .LT. PT) GO TO 2000
      PT=PT-THINT
      IF (PT .LE. 0.0) GO TO 1600
 2000 TH1(K)=PT
      IF (METHOD .EQ. 2 .AND. (BB(I)**2) .GT. 0.01) GO TO 2100
      ED1(K)=D2LN+(PT-PT2)*(D1LN-D2LN)/(PT1-PT2)
      GO TO 2200
 2100 ED1(K)=D1LN-(AA(I)+DSQRT(AA(I)**2-4.*BB(I)*(PT1-PT)))/(2.*BB(I))
 2200 K=K+1
      PT=PT-THINT
      IF (PT) 1600,1600,1800
 1900 PT1=PT2
 1700 CONTINUE
      TH1(K)=TH(N)
      ED1(K)=DEN(N)
      M=K-1
      DO 800 I=2,M
  800 ED1(I)=DEXP(ED1(I))
C     WRITE OUT INTERPOLATED RESULTS.
      WRITE(6,3)
      WRITE(6,2) (TH1(I),ED1(I),I=1,K)
C     HEIGHTS AT FIXED DENSITIES OBTAINED FROM LAMINATION CONTAINING
C     DESIRED DENSITY AND FROM EQUATION OF LAMINATION.
      N=N-1
      M1=1
      K=1
      DO 200 L=1,N
      K=K-1
      DO 300 I=1,2
      D(I)=DEN(L+I-1)
  300 Z(I)=TH(L+I-1)
      D1LN=DLOG(D(1))
  400 K=K+1
      D1=DENREF(K)
      DO 500 I=1,2
      ED2(M1)=D1
      IF (D1-D(I)) 600,700,500
  700 TH2(M1)=Z(I)
      M1=M1+1
      IF(I.EQ.1) GO TO 400
  500 CONTINUE
      GO TO 200
  600 IF(I.EQ.1) GO TO 400
      V=DLOG(D1)-D1LN
      TH2(M1)=Z(1)+V*(AA(L+1)+BB(L+1)*V)
      M1=M1+1
      IF(K.GE.56) GO TO 900
      GO TO 400
  200 CONTINUE
  900 M1=M1-1
      N = N+ 1
C     WRITE OUT INTERPOLATED RESULTS.
      WRITE (6,4)
      WRITE(6,2) (TH2(I),ED2(I),I=1,M1)
      IF(IORD.EQ.0) RETURN
      WRITE(6,8)
      WRITE(6,9) (FO(I),HPO(I),I=1,N)
      RETURN
 1600 WRITE (6,7)
      RETURN 1
      ENTRY INREF
      WRITE (6,5)
      WRITE (6,6) (DENREF(K),K=1,56)
      RETURN
    1 FORMAT(' ALTITUDES(KM) AND DENSITIES(EL/CC) CORRESPONDING TO SCALE
     FD H''(F) DATA')
    2 FORMAT(1H ,3X,4('ALT.',3X,'DENSITY',5X)/4(2X,0PF6.1,1X,1PE10.3))
    3 FORMAT(' ALTITUDES AND DENSITIES AT SELECTED HEIGHTS')
    4 FORMAT(' ALTITUDES AND DENSITIES AT SELECTED DENSITIES')
    5 FORMAT(1x,'REFERENCE DENSITIES FOR INTERPOLATION')
    6 FORMAT(2X,1P8E10.2)
    7 FORMAT(1x,'ERROR IN DATA. FIXED-HEIGHT INTERPOLATION NOT POSSIBLE
     F.'/1H ,'FURTHER PROCESSING OF THIS IONOGRAM TERMINATED.')
    8 FORMAT(' CALCULATED ORDINARY TRACE'/' ',5(3X,'F',6X,'HP',2X))
    9 FORMAT(5(1X,F6.3,1X,F6.1))
      END
