      subroutine ggm2(long,lati,mlong,mlat)
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.
      integer art
      real*8 mlong,mlat,long,lati,faktor
c      common/const/faktor
      faktor=3.141592653589793d0/180.d0
c     if(long.lt.0.d0) long=long+360.d0
      art=0
      zpi=faktor*360.
      cbg=11.4*faktor
      ci=cos(cbg)
      si=sin(cbg)
      if(art.eq.0) goto 10
      cbm=cos(mlat*faktor)
      sbm=sin(mlat*faktor)
      clm=cos(mlong*faktor)
      slm=sin(mlong*faktor)
      sbg=sbm*ci-cbm*clm*si
        if(abs(sbg).gt.1.) sbg=sign(1.,sbg)
      lati=asin(sbg)
      cbg=cos(lati)
      slg=(cbm*slm)/cbg
      clg=(sbm*si+cbm*clm*ci)/cbg
        if(abs(clg).gt.1.) clg=sign(1.,clg)
      long=acos(clg)
      if(slg.lt.0.0) long=zpi-long
      lati=lati/faktor
      long=long/faktor
      long=long-69.8
      if(long.lt.0.0) long=long+360.0
      return
10    ylg=long+69.8
      cbg=cos(lati*faktor)
      sbg=sin(lati*faktor)
      clg=cos(ylg*faktor)
      slg=sin(ylg*faktor)
      sbm=sbg*ci+cbg*clg*si
        if(abs(sbm).gt.1.) sbm=sign(1.,sbm)
      mlat=asin(sbm)
      cbm=cos(mlat)
      slm=(cbg*slg)/cbm
      clm=(-sbg*si+cbg*clg*ci)/cbm
        if(abs(clm).gt.1.) clm=sign(1.,clm)
      mlong=acos(clm)
      if(slm.lt..0) mlong=zpi-mlong
      mlat=mlat/faktor
      mlong=mlong/faktor
      return
      end

