      SUBROUTINE GTM(RLATG,RLONG,RLATMP,RLONMP,RLATM,RLONM,DIP,DEC,W,N)      GTM.2
C     ****                                                                   GTM.3
C     ****     TRANSFORMS GEOGRAPHIC COORDINATES TO GEOMAGNETIC,             GTM.4
C     ****     CALCULATES DIP AND DECLINATION.                               GTM.5
C     ****                                                                   GTM.6
C     ****     RLATG(N), RLONG(N) --  N-DIMENSIONAL ARRAYS OF GEOGRAPHIC     GTM.7
C     ****     LATITUDES AND CORRESPONDING LONGITUDES. (RADIANS)             GTM.8
C     ****                                                                   GTM.9
C     ****     RLATMP, RLONMP --  GEOGRAPHIC COORDINATES OF GEOMAGNETIC      GTM.10
C     ****     NORTH POLE. (RADIANS)                                         GTM.11
C     ****                                                                   GTM.12
C     ****     RLATM(N), RLONM(N) --  OUTPUT ARRAYS OF GEOMAGNETIC           GTM.13
C     ****     COORDINATES. (RADIANS)                                        GTM.14
C     ****                                                                   GTM.15
C     ****     DIP(N), DEC(N) -- OUTPUT ARRAYS OF DIP AND DECLINATION.       GTM.16
C     ****                                                                   GTM.17
C     ****     W(N,4) --  WORKING ARRAY.                                     GTM.18
C     ****                                                                   GTM.19
C     ****     N --  NUMBER OF (LAT,LON) POINTS TO BE TRANSFORMED.           GTM.20
C     ****                                                                   GTM.21
C     ****                                                                   GTM.22
      DIMENSION RLATG(N),RLONG(N),RLATM(N),RLONM(N),DIP(N),DEC(N),W(N,4)     GTM.24
      DATA E/1.E-10/                                                         GTM.25
      SINLAM=SIN(RLATMP)                                                    GTM.26
      COSLAM=COS(RLATMP)                                                    GTM.27
      DO I=1,N                                                               GTM.28
       W(I,1)=SIN(RLATG(I))                                                 GTM.29
       W(I,2)=COS(RLATG(I))                                                 GTM.30
       W(I,3)=SIN(RLONG(I)+E-RLONMP)                                        GTM.31
       W(I,4)=COS(RLONG(I)+E-RLONMP)                                        GTM.32
       W(I,4)=SINLAM*W(I,1)+COSLAM*W(I,2)*W(I,4)                             GTM.33
       RLONM(I)=ATAN2(W(I,3)*W(I,2),(W(I,4)*SINLAM-W(I,1))/COSLAM)          GTM.34
       RLATM(I)=ASIN(W(I,4))                                                GTM.35
       DEC(I)=ATAN2(COSLAM*W(I,2)*W(I,3),SINLAM-W(I,1)*W(I,4))              GTM.36
       DIP(I)=ATAN(2.*TAN(RLATM(I)))                                       GTM.37
      ENDDO                                                                  GTM.38
      RETURN                                                                 GTM.39
                                                                             GTM.40
      ENTRY MTG(RLATG,RLONG,RLATMP,RLONMP,RLATM,RLONM,W,N)                   GTM.41
C     ****                                                                   GTM.42
C     ****     INVERSE TRANSFORMATION                                        GTM.43
C     ****                                                                   GTM.44
C     ****     PARAMETERS AS ABOVE EXCEPT INPUT --  RLATM,RLONM              GTM.45
C     ****                                OUTPUT --  RLATG,RLONG             GTM.46
C     ****                                                                   GTM.47
      SINLAM=SIN(RLATMP)                                                    GTM.48
      COSLAM=COS(RLATMP)                                                    GTM.49
      SINLOM=SIN(RLONMP)                                                    GTM.50
      COSLOM=COS(RLONMP)                                                    GTM.51
      DO I=1,N                                                               GTM.52
       W(I,1)=SIN(RLATM(I))                                                 GTM.53
       W(I,2)=COS(RLATM(I))                                                 GTM.54
       W(I,3)=SIN(RLONM(I))                                                 GTM.55
       W(I,4)=COS(RLONM(I))                                                 GTM.56
       RLATG(I)=SINLAM*W(I,1)-COSLAM*W(I,2)*W(I,4)                           GTM.57
       W(I,3)=W(I,3)*W(I,2)                                                  GTM.58
       W(I,4)=-(RLATG(I)*SINLAM-W(I,1))/COSLAM                               GTM.59
       RLATG(I)=ASIN(RLATG(I))                                              GTM.60
       RLONG(I)=ATAN2(SINLOM*W(I,4)+COSLOM*W(I,3),COSLOM*W(I,4)-SINLOM      GTM.61
     A          *W(I,3))                                                     GTM.62
      ENDDO                                                                  GTM.63
                                                                             GTM.64
      RETURN                                                                 GTM.65
      END                                                                    GTM.66
