
      SUBROUTINE GRDINT(AM,AG,IG,JG,WT,LG,LM,IMAXG,JMAXG,IMAXM,JMAXM,
     |  JM)
      implicit none
C     ****
C     ****     TRANSFORM SCALAR FIELD GIVEN ON GEOGRAPHIC GRID TO
C     ****       GEOMAGNETIC GRID USING INDICES AND WEIGHTS GENERATED
C     ****       BY GRDSTM.
C     ****
C     ****     INPUT:
C     ****      AG(LG,1) IS 2-DIM SCALAR FIELD TO BE TRANSFORMED TO
C     ****        GEOMAGNETIC GRID.
C     ****        NB: PERIODIC POINT IS REPEATED SO THAT
C     ****        AG(IMAXG+1,JG) = AG(1,JG)
C     ****        (LM.GE.IMAXG+1)
C     ****      IMAXG, JMAXG  DIMENSIONS OF GEOGRAPHIC GRID
C     ****      IMAXM, JMAXM  DIMENSIONS OF GEOMAGNETIC GRID
C     ****      LG IS FIRST DIMENSION OF AG IN CALLING PROGRAM
C     ****        (LG.GE.IMAXG+1)
C     ****      IG(LM,1) GIVES ROUNDED DOWN GEOGRAPHIC LONGITUDE INDEX
C     ****        FOR EACH GEOMAGNETIC GRID POINT
C     ****      JG(LM,1) GIVES ROUNDED DOWN GEOGRAPHIC LATITUDE INDEX
C     ****        FOR EACH GEOMAGNETIC GRID POINT
C     ****      WT(4,LM,1) WEIGHTS FOR 4 CORNERS OF EACH GEOMAGNETIC
C     ****        GRID ELEMENT
C     ****      LM IS FIRST DIMENSION OF ARRAYS AM, IG, JG, WT IN
C     ****        CALLING PROGRAM
C     ****        (LM.GE.IMAXM)
C     ****      IEM IS FLAG INDICATING TYPE OF TRANSFORMATION
C     ****        IEM = 1 FOR OUPUT FIELDS AT DIP EQUATOR
C     ****        IEM = 0 FOR GLOBAL OUTPUT FIELDS
C     ****      NOTE:  IG, JG, WT ARE PRODUCED BY PREVIOUS CALL TO
C     ****        GRDSTM.
C     ****
C     ****     OUTPUT:
C     ****      AM(LM,1) 2-DIM SCALAR FIELD TRANSFORMED TO GEOMAGNETIC
C     ****        LATITUDE/LONGITUDE GRID
C     ****
!
! Args:
      integer,intent(in) :: lg,lm,imaxg,jmaxg,imaxm,jmaxm,jm
      real,intent(out) :: AM(LM,1)
      real,intent(in) :: AG(LG,1),WT(4,LM,1)
      integer,intent(in) :: IG(LM,1),JG(LM,1)
!
! Local:
      integer :: im
C     ****
C     ****     CARRY OUT INTERPOLATION
C     ****
      DO 1 IM = 1,IMAXM
        AM(IM,1) =
     1    AG(IG(IM,JM),JG(IM,JM))*WT(1,IM,JM)+
     2    AG(IG(IM,JM)+1,JG(IM,JM))*WT(2,IM,JM)+
     3    AG(IG(IM,JM)+1,JG(IM,JM)+1)*WT(3,IM,JM)+
     4    AG(IG(IM,JM),JG(IM,JM)+1)*WT(4,IM,JM)
    1 CONTINUE
      RETURN
      END

