      SUBROUTINE GGM(ART,LONG,LATI,MLONG,MLAT)
c	taken from the IRI s/r IRINHSUBS.FOR
c
c-----	last modified 4-jun-87
c******* gives wrong sign for geog lat of geom pole ***************
c
C CALCULATES GEOMAGNETIC LONGITUDE (MLONG) AND LATITUDE (MLAT)
C FROM GEOGRAFIC LONGITUDE (LONG) AND LATITUDE (LATI) FOR ART=0
C AND REVERSE FOR ART=1. ALL ANGLES IN DEGREE.
C LATITUDE:-90 TO 90. LONGITUDE:0 TO 360 EAST.
	implicit real*8 (a-h,o-z)
      INTEGER ART
      REAL MLONG,MLAT,LONG,LATI
cccccc      COMMON/CONST/FAKTOR
	pi = 4.d0 * datan(1.d0)
	faktor = pi/180.d0
      ZPI=FAKTOR*360.d0
      CBG=11.4d0*FAKTOR
      CI=dCOS(CBG)
      SI=dSIN(CBG)
      IF(ART.EQ.0.d0) GOTO 10
      CBM=dCOS(MLAT*FAKTOR)
      SBM=dSIN(MLAT*FAKTOR)
      CLM=dCOS(MLONG*FAKTOR)
      SLM=dSIN(MLONG*FAKTOR)
      SBG=SBM*CI-CBM*CLM*SI
      LATI=dASIN(SBG)
      CBG=dCOS(LATI)
      SLG=(CBM*SLM)/CBG
      CLG=(SBM*SI+CBM*CLM*CI)/CBG
        IF(CLG.GT.1.d0) CLG=1.d0
      LONG=dACOS(CLG)
      IF(SLG.LT.0.0d0) LONG=ZPI-dACOS(CLG)
      LATI=LATI/FAKTOR
      LONG=LONG/FAKTOR
      LONG=LONG-69.8d0
      IF(LONG.LT.0.0d0) LONG=LONG+360.0d0
	if(long.gt.360.d0) long = long - 360.d0
      RETURN
10    YLG=LONG+69.8d0
      CBG=dCOS(LATI*FAKTOR)
      SBG=dSIN(LATI*FAKTOR)
      CLG=dCOS(YLG*FAKTOR)
      SLG=dSIN(YLG*FAKTOR)
      SBM=SBG*CI+CBG*CLG*SI
	if(dabs(sbm).gt.1.d0) sbm = dsign(1.0d0,sbm)
      MLAT=dASIN(SBM)
      CBM=dCOS(MLAT)
      SLM=(CBG*SLG)/CBM
      CLM=(-SBG*SI+CBG*CLG*CI)/CBM
        IF(CLM.GT.1.d0) CLM=1.d0
      MLONG=dACOS(CLM)
      IF(SLM.LT.0.d0) MLONG=ZPI-dACOS(CLM)
      MLAT=MLAT/FAKTOR
      MLONG=MLONG/FAKTOR
	if(mlong.lt.0.0d0 ) mlong = mlong + 360.d0
	if(mlong.gt.360.d0) mlong = mlong - 360.d0
      RETURN
      END
