      SUBROUTINE RAYPLT                                                 RAYP001 

C        W(81)=1. PLOTS PROJECTION OF RAYPATH ON VERTICAL PLANE         RAYP002 

C             =2. PLOTS PROJECTION OF RAYPATH ON GROUND                 RAYP003 

      COMMON /PLT/ XL,XR,YB,YT,RESET                                    RAYP004 

      COMMON /CONST/ PI,PIT2,PID2,DUM(5)                                RAYP005 

      COMMON /FLG/ NTYP,NEWWR,NEWWP,PENET,LINES,IHOP,HPUNCH             RAYP006 

      COMMON R(6) /WW/ ID(10),W0,W(400)                                 RAYP007 

      EQUIVALENCE (TH,R(2)),(PH,R(3))                                   RAYP008 

      EQUIVALENCE (EARTHR,W(2)),(PLAT,W(24)),(PLON,W(25)),(PLT,W(81)),  RAYP009 

     1 (FACTR,W(82)),(LLAT,W(83)),(LLON,W(84)),(RLAT,W(85)),(RLON,W(86))RAYP010 

     2,(TIC,W(87)),(HB,W(88))                                           RAYP011 

      REAL LLAT,LLON,LTIC                                               RAYP012 

      LOGICAL NEWWR,NEWWP,PENET                                         RAYP013 

      IF (.NOT.NEWWR) GO TO 5                                           RAYP014 

C                                                                       RAYP015 

C          NEW W ARRAY -- REINITIALIZE                                  RAYP016 

      NEWWR=.FALSE.                                                     RAYP017 

      RESET=1.                                                          RAYP018 

CONVERT COORDINATES OF VERTICAL PLANE FROM GEOGRAPHIC TO GEOMAGNETIC    RAYP019 

      SW=SIN (PLAT)                                                     RAYP020 

      CW=SIN (PID2-PLAT)                                                RAYP021 

      SLM=SIN (LLAT)                                                    RAYP022 

      CLM=SIN (PID2-LLAT)                                               RAYP023 

      SRM=SIN (RLAT)                                                    RAYP024 

      CRM=SIN (PID2-RLAT)                                               RAYP025 

      CDPHI=SIN (PID2-(LLON-PLON))                                      RAYP026 

      PHL=ATAN2(SIN (LLON-PLON)*CLM,CDPHI*SW*CLM-CW*SLM)                RAYP027 

      CTHL=CDPHI*CW*CLM+SW*SLM                                          RAYP028 

      STHL=SIN (ACOS (CTHL))                                            RAYP029 

      CDPHI=SIN (PID2-(RLON-PLON))                                      RAYP030 

      PHR=ATAN2(SIN (RLON-PLON)*CRM,CDPHI*SW*CRM-CW*SRM)                RAYP031 

      CTHR=CDPHI*CW*CRM+SW*SRM                                          RAYP032 

      STHR=SIN (ACOS (CTHR))                                            RAYP033 

      CLR=CTHL*CTHR+STHL*STHR*SIN (PID2-(PHL-PHR))                      RAYP034 

      SLR=SQRT (1.-CLR**2)                                              RAYP035 

      IF (PLT.EQ.2.) GO TO 3                                            RAYP036 

      FACTR=1.                                                          RAYP037 

      R0=EARTHR+HB                                                      RAYP038 

      ALPHA=.5*ACOS (CLR)                                               RAYP039 

      XR=R0*SIN (ALPHA)                                                 RAYP040 

      XL=-XR                                                            RAYP041 

      YB=R0*SIN (PID2-ALPHA)                                            RAYP042 

      YT=YB+2.*XR                                                       RAYP043 

      GO TO 5                                                           RAYP044 

    3 IF (FACTR.EQ.0.) FACTR=1.                                         RAYP045 

      ALPH1=ATAN2(STHR*SIN (PHR-PHL),(CTHR-CTHL*CLR)/STHL)              RAYP046 

      XL=0.                                                             RAYP047 

      XR=EARTHR*ACOS (CLR)                                              RAYP048 

      YT=0.5*XR/FACTR                                                   RAYP049 

      YB=-YT                                                            RAYP050 

C                                                                       RAYP051 

    5 STH=SIN (TH)                                                      RAYP052 

      CTH=SIN (PID2-TH)                                                 RAYP053 

      CR=CTHR*CTH+STHR*STH*SIN (PID2-(PHR-PH))                          RAYP054 

      CL=CTHL*CTH+STHL*STH*SIN (PID2-(PHL-PH))                          RAYP055 

      CEA=ATAN2(CR-CL*CLR,CL*SLR)                                       RAYP056 

      NEW=1                                                             RAYP057 

      IF (IHOP.NE.0) NEW=0                                              RAYP058 

      IF (PLT.EQ.2.) GO TO 10                                           RAYP059 

      CALL PLOT (R(1)*SIN(CEA-ALPHA),R(1)*SIN(PID2-(CEA-ALPHA)),NEW)    RAYP060 

      RETURN                                                            RAYP061 

   10 SL=SQRT (1.-CL**2)                                                RAYP062 

      TMP1=STH*SIN (PH-PHL)                                             RAYP063 

      TMP2=(CTH-CTHL*CL)/STHL                                           RAYP064 

      ALPH2=0.                                                          RAYP065 

      IF (TMP1.NE.0..OR.TMP2.NE.0.) ALPH2=ATAN2(TMP1,TMP2)              RAYP066 

      CALL PLOT (EARTHR*CEA,EARTHR*ASIN(SL*SIN (ALPH1-ALPH2)),NEW)      RAYP067 

      RETURN                                                            RAYP068 

C                                                                       RAYP069 

C          DRAW AXES AND CALL FOR LABELING AND TERMINATION OF THIS PLOT RAYP070 

      ENTRY ENDPLT                                                      RAYP071 

      TICKX=0.01*(YT-YB)                                                RAYP072 

      IF (PLT.EQ.2.) GO TO 25                                           RAYP073 

      R1=EARTHR-TICKX                                                   RAYP074 

      X=XL                                                              RAYP075 

      Y=YB                                                              RAYP076 

      CALL PLOT (X,Y,1)                                                 RAYP077 

      NTIC=2                                                            RAYP078 

      IF (TIC.NE.0.) NTIC=NTIC+2.*ALPHA/TIC                             RAYP079 

      NLINE=MAX0 (1,100/NTIC)                                           RAYP080 

      DO 20 I=1,NTIC                                                    RAYP081 

      ANG=-ALPHA+(I-1)*TIC                                              RAYP082 

      CALL PLOT (R1*SIN (ANG),R1*SIN (PID2-ANG),0)                      RAYP083 

      CALL PLOT (X,Y,0)                                                 RAYP084 

      DO 20 J=1,NLINE                                                   RAYP085 

      ANG=ANG+TIC/NLINE                                                 RAYP086 

      X=EARTHR*SIN (ANG)                                                RAYP087 

      Y=EARTHR*SIN (PID2-ANG)                                           RAYP088 

   20 CALL PLOT (X,Y,0)                                                 RAYP089 

      CALL PLOT (XR,YB,0)                                               RAYP090 

      GO TO 50                                                          RAYP091 

   25 DTIC=TIC*EARTHR                                                   RAYP092 

      LTIC=DTIC/FACTR                                                   RAYP093 

      TICY=XL+0.01*(XR-XL)                                              RAYP094 

      NTIC=YT/LTIC                                                      RAYP095 

      TIC1=-LTIC*NTIC                                                   RAYP096 

      CALL PLOT (XL,YB,1)                                               RAYP097 

      NTIC=2*NTIC+1                                                     RAYP098 

      DO 30 I=1,NTIC                                                    RAYP099 

      Y=TIC1+(I-1)*LTIC                                                 RAYP100 

      CALL PLOT (XL,Y,0)                                                RAYP101 

      CALL PLOT (TICY,Y,0)                                              RAYP102 

   30 CALL PLOT (XL,Y,0)                                                RAYP103 

      CALL PLOT (XL,YT,0)                                               RAYP104 

      CALL PLOT (XL,0.,1)                                               RAYP105 

      NTIC=(XR-XL)/DTIC                                                 RAYP106 

      DO 40 I=1,NTIC                                                    RAYP107 

      X=I*DTIC                                                          RAYP108 

      CALL PLOT (X,0.,0)                                                RAYP109 

      CALL PLOT (X,TICKX,0)                                             RAYP110 

   40 CALL PLOT (X,0.,0)                                                RAYP111 

      CALL PLOT (XR,0.,0)                                               RAYP112 

   50 CALL LABPLT                                                       RAYP113 

      CALL PLTEND                                                       RAYP114 

      RETURN                                                            RAYP115 

         END                                                            RAYP116-

