      SUBROUTINE FXSAT(DLAT,DLONG,DATE,LQ,*)
C     SUBROUTINE FXSAT.  DETERMINE FX AT SATELLITE TO GIVE IDENTICAL
C     SLOPES FOR THE FIRST TWO LAMINATIONS, ASSUMING LINEAR IN LOG(N)
C     LAMINATIONS.
      IMPLICIT REAL*8(A-H,O-Z)
      REAL*4 DLAT,DLONG,DATE,HGT,BN,BE,BV,BT
      LOGICAL LOWN
      COMMON /CALC/ AA(50),BB(50),F(50),HP(50),FH(50),TH(70),DEN(70)
      COMMON /MISC/ DP,FH1,ASUM,BSUM,FA,CPH,X1,X2,GMT1
      COMMON /SWJTCH/ ISAT,LOCSAT,IFXS,NCASES,ICODE(4),N,METHOD,IORD,IP
      DIMENSION FXS(10),DIFF(10),PCNT(10)
      DATA PCNT / .90,.92,.94,.96,.97,.98,.99,.993,.996,.998 /
      SAVE
C     BEGIN BY FINDING MAXIMUM PERMISSIBLE VALUE OF FXS BASED ON A
C     NEARLY VERTICAL PROFILE AT THE SATELLITE. FOR A REGULAR IONOGRAM,
C     FIRST TRY  TEN SELECTED PERCENTAGES OF F(2), AND FIND THE TWO
C     WHICH YIELD CLOSEST AGREEMENT BETWEEN RESULTING FH(2) AND ACTUAL
C     FH(2). SEARCH STOPS BEFORE TEN VALUES HAVE BEEN TRIED IF THESE
C     DIFFERENCES CHANGE SIGN OR BECOME NON-MONOTONIC. NO ITERATIONS ARE
C     DONE IN LAMINATION CALCULATIONS.  FOR LOW DENSITY IONOGRAMS
C     (FHS > .89*F(2)), USE TEN VALUES OF FXS EQUALLY SPACED BETWEEN FHS
C     AND F(2).
      METH=METHOD
      METHOD=1
      IF(F(3).LT.(F(2)+0.001)) GO TO 2000
      FHS=FH1
      L=2
      I=2
      FA=F(2)
      F1MAX=FA-0.0011
      TEST=(FA-FHS)/11.0
      IF(TEST.LT.0.0011) GO TO 1500
      LOWN=.FALSE.
      IF (FHS.GE.(0.89*FA)) LOWN=.TRUE.
      DO 100 M=1,10
      FXS(M)=PCNT(M)*FA
      IF (LOWN) FXS(M)=FHS+M*TEST
      IF(FXS(M).GT.F1MAX) GO TO 800
      FH(2)=FA-1.001*FXS(M)*(FXS(M)-FHS)/FA
      DEN(1)=FXS(M)*(FXS(M)-FHS)*12400.0
      DEN(2)=FA*(FA-FH(2))*12400.0
      CALL XLAM(L,I,DLAT,DLONG,DATE,LQ,2,*2000)
      HGT=TH(1)-(HP(2)*DLOG(X2/X1))/ASUM
      CALL FIELDG(DLAT,DLONG,HGT,DATE,10,LQ,BN,BE,BV,BT)
      DIFF(M)=(BT*2.8000E-05) - FH(2)
      TH(2)=HGT
      K=M
      DA=DABS(DIFF(M))
      IF (M-2) 300,400,500
  300 MA=1
      FC=DA
      GO TO 100
  500 IF(DIFF(M).LT.DIFF(M-1)) GO TO 800
C     FIND THE TWO SMALLEST VALUES OF DA (FC,FB), AND CORRESPONDING
C     VALUES OF M (MA,MB).
      IF (DA.GE.FB .OR. DA.EQ.FC) GO TO 600
  400 IF (DA.LT.FC) GO TO 700
      FB=DA
      MB=M
      GO TO 600
  700 FB=FC
      FC=DA
      MB=MA
      MA=M
  600 IF((DIFF(M)*DIFF(M-1)) .LT. 0.) GO TO 800
  100 CONTINUE
  800 FC=FXS(MA)
      FB=FXS(MB)
      DA=DIFF(MA)
      DB=DIFF(MB)
      NL=K
C     FIND MAXIMUM PERMISSIBLE VALUE OF FXS (=FB) USING FALSE POSITION
C     RULE AND STARTING WITH FXS(MA) AND FXS(MB) FROM THE DO 100 LOOP.
C     SEARCH STOPS BEFORE TEN VALUES HAVE BEEN TRIED IF THE ABSOLUTE
C     VALUE OF THE DIFFERENCE BETWEEN COMPUTED AND ACTUAL FH(2)<.00001.
      DO 900 M=1,10
      FXS(M)=FC-DA*(FB-FC)/(DB-DA)
      IF(FXS(M).GT.F1MAX) FXS(M)=F1MAX
      FH(2)=FA-1.001*FXS(M)*(FXS(M)-FHS)/FA
      DEN(1)=FXS(M)*(FXS(M)-FHS)*12400.0
      DEN(2)=FA*(FA-FH(2))*12400.0
      CALL XLAM(L,I,DLAT,DLONG,DATE,LQ,2,*2000)
      HGT=TH(1)-(HP(2)*DLOG(X2/X1))/ASUM
      CALL FIELDG(DLAT,DLONG,HGT,DATE,10,LQ,BN,BE,BV,BT)
      DIFF(M)=(BT*2.8000E-05) - FH(2)
      TH(2)=HGT
      FB=FXS(M)
      DB=DIFF(M)
      K=M
      IF (DABS(DB).LT. 0.00001) GO TO 1000
  900 CONTINUE
C     COMPUTE FXS=F(1) WHICH GIVES THE SAME SLOPES FOR THE FIRST TWO
C     LAMINATIONS (AA(2)=AA(3)). INITIAL VALUE OF F(1) IS THE AVERAGE OF
C     MAXIMUM (FB) AND MINIMUM (FH(1)) PERMISSIBLE VALUES.  FB IS THE
C     REFERENCE POINT FOR FALSE POSITION RULE USED TO REFINE SUCCESSIVE
C     VALUES OF FXS.  PROCEDURE IS APPLIED TO DEL2=(1-AA(3)/AA(2)) FOR
C     LOW DENSITY IONOGRAMS (DENSITY CORRESPONDING TO FB < 500 EL/CC);
C     OTHERWISE, DEL2=(1-AA(3)/AA(2))**2.  CONVERGENCE IS ACHIEVED WHEN
C     (1.0-AA(3)/AA(2))**2 < .0001. A MAXIMUM OF 15 VALUES OF FXS TRIED.
 1000 F(1)=FB
      DELF=FB-FHS
      LOWN=.FALSE.
      IF((1.24D4*FB*(FB-FH(1))) .LE. 500.) LOWN=.TRUE.
      K=K+NL
      MA=1
      DELA = 1.0
      NL=N
      DO 1100 M=1,15
      FX1=F(1)
      DEN(1)=12400.*FX1*(FX1-FH(1))
      DO 1300 I=2,3
      IBAD=0
      DP=0.0
      FA=F(I)
      FH(I)=FA-DEN(I-1)*8.07258870D-5/FA
      DEN(I)=12400.*FA*(FA-FH(I))
      CALL XLAM(L,I,DLAT,DLONG,DATE,LQ,3,*1700)
      GO TO 1300
 1700 IBAD=1
 1300 CONTINUE
      IF (IBAD .EQ. 0) GO TO 1800
      IF(M.EQ.15) GO TO 200
      IF (M .GT. MA) GO TO 1400
C     RESET REFERENCE.
      MA=MA+1
      F(1)=F(1)-0.001
      GO TO 1100
C     RESTART ON FALSE POSITION METHOD.
 1400 F(1)=FHS+DFLOAT(M)*DELF/16.
      GO TO 1100
 1800 RATIO=AA(3)/AA(2)
      DELA=1.-RATIO
      R=RATIO
      IF(.NOT.LOWN) R=R**2
      IF (M .GT. MA) GO TO 1900
      DEL1=1.-R
      F1=F(1)
      F(1)=0.5*(FH(1)+FB)
      GO TO 1100
 1900 DEL2=1.-R
      F2=F(1)
      IF(DELA**2.LT.0.0001) GO TO 1200
      F(1)=F1-(DEL1*(F2-F1))/(DEL2-DEL1)
 1100 CONTINUE
 1200 WRITE(6,1)FB,K,FX1,RATIO,M
      METHOD=METH
      N=NL
      RETURN
  200 WRITE(6,5)
      GO TO 2100
 1500 WRITE(6,4)
      GO TO 2100
 2000 WRITE(6,3)
 2100 METHOD=METH
      WRITE(6,2)
      RETURN 1
    1 FORMAT(' FXSMAX=',F6.3,' MHZ.',I4,' ITERATIONS (MAX=20).'/
     F     ' COMPUTED FXS=',F6.3,' MHZ  SLOPE2/SLOPE1=',F7.4,I4,
     F     ' ITERATIONS (MAX=15).')
    2 FORMAT(' PROBLEM OCCURRED DURING CALL TO FXSAT SUBROUTINE.  PROCES
     FSING OF THIS IONOGRAM TERMINATED.')
    3 FORMAT(' DATA FOR F=',F6.3,' NOT MONOTONICALLY INCREASING.')
    4 FORMAT(' FH(2) TOO CLOSE TO FHS.')
    5 FORMAT(' CALCULATION OF FXS DID NOT CONVERGE WITH 15 ITERATIONS.')
      END
