      SUBROUTINE HAMLTN                                                 HAML001 

	character*8 modrin,id

C********* CALCULATES HAMILTONS EQUATIONS FOR RAY TRACING               HAML002 

      COMMON /CONST/ PI,PIT2,PID2,DEGS,RAD,K,C,LOGTEN                   HAML003 

      COMMON /RIN/ MODRIN(3),COLL,FIELD,SPACE,KAY2,KAY2I,               HAML004 

     1              H,HI,PHPT,PHPTI,PHPR,PHPRI,PHPTH,PHPTHI,PHPPH,PHPPHIHAML005 

     2, PHPOM,PHPOMI,PHPKR,PHPKRI,PHPKTH,PHPKTI, PHPKPH,PHPKPI          HAML006 

     3 ,KPHPK,KPHPKI,POLAR,POLARI,LPOLAR,LPOLRI                         HAML007 

      COMMON R(20),T,STP,DRDT(20) /WW/ ID(10),W0,W(400)                 HAML008 

      EQUIVALENCE (TH,R(2)),(PH,R(3)),(KR,R(4)),(KTH,R(5)),(KPH,R(6)),  HAML009 

     1 (DTHDT,DRDT(2)),(DPHDT,DRDT(3)),(DKRDT,DRDT(4)),(DKTHDT,DRDT(5)),HAML010 

     2 (DKPHDT,DRDT(6)),(F,W(6))                                        HAML011 

      REAL KR,KTH,KPH,KPHPK,KPHPKI,LPOLAR,LPOLRI,LOGTEN,K,KAY2,KAY2I    HAML012 

      OM=PIT2*1.E6*F                                                    HAML013 

      STH=SIN(TH)                                                       HAML014 

      CTH=SIN(PID2-TH)                                                  HAML015 

      RSTH=R(1)*STH                                                     HAML016 

      RCTH=R(1)*CTH                                                     HAML017 

      CALL RINDEX                                                       HAML018 

      DRDT(1)=-PHPKR/(PHPOM*C)                                           

      DTHDT=-PHPKTH/(PHPOM*R(1)*C)                                      HAML020 

      DPHDT=-PHPKPH/(PHPOM*RSTH*C)                                      HAML021 

      DKRDT=PHPR/(PHPOM*C)+KTH*DTHDT+KPH*STH*DPHDT                      HAML022 

      DKTHDT=(PHPTH/(PHPOM*C)-KTH*DRDT(1)+KPH*RCTH*DPHDT)/R(1)              

      DKPHDT=(PHPPH/(PHPOM*C)-KPH*STH*DRDT(1)-KPH*RCTH*DTHDT)/RSTH          

      NR=6                                                              HAML025 

C********* PHASE PATH                                                   HAML026 

      IF (W(57).EQ.0.) GO TO 10                                         HAML027 

      NR=NR+1                                                           HAML028 

      DRDT(NR)=-     KPHPK/PHPOM/OM                                     HAML029 

C********* ABSORPTION                                                   HAML030 

   10 IF (W(58).EQ.0.) GO TO 15                                         HAML031 

      NR=NR+1                                                           HAML032 

      DRDT(NR)= 10./LOGTEN*KPHPK*KAY2I/(KR*KR+KTH*KTH+KPH*KPH)/PHPOM/C  HAML033 

C********* DOPPLER SHIFT                                                HAML034 

   15 IF (W(59).EQ.0.) GO TO 20                                         HAML035 

      NR=NR+1                                                           HAML036 

      DRDT(NR)=-PHPT/PHPOM/C/PIT2                                       HAML037 

C********* GEOMETRICAL PATH LENGTH                                      HAML038 

   20 IF (W(60).EQ.0.) GO TO 25                                         HAML039 

      NR=NR+1                                                           HAML040 

      DRDT(NR)=-SQRT(PHPKR**2+PHPKTH**2+PHPKPH**2)/PHPOM   /C           HAML041 

C********* OTHER CALCULATIONS                                           HAML042 

   25 CONTINUE                                                          HAML043 

      RETURN                                                            HAML044 

         END                                                            HAML045-

