      SUBROUTINE GETXFXX(NF,XSFXPAK,XSFXPAL,NLON,NLAT,
     1                   INCD,IDAY,MDAY,KOUNT,GG,NAMTS)
C
C     * MAY 28, 2003 - M. LAZARE. NEW VERSION WHICH REMOVES "ROW"
C     *                           FIELDS AND INTERNAL PACKING DENSITIES.    
C     *                           ALSO, USES NEW ROUTINE "GETAGBX" INSTEAD 
C     *                           OF "GETAGB". 
C     *                           NOTE THAT NO INTERPOLATION IS DONE AT
C     *                           FIRST STEP (REMOVES CALL TO INTXFX).
C     * MAY  7/98 - R.HARVEY - PREVIOUS VERSION GETXFX.
C
C     * READ IN TRACER SURFACE FLUX FIELD(S).
C     * TIME LABEL IS THE JULIAN DATE OF THE FIRST OF THE MONTH 
C     * (NFDM) FOR WHICH THE SST ARE THE MONTHLY AVERAGE. 
C     * WHEN THE MODEL IS MOVING THROUGH THE YEAR (INCD.NE.0),
C     * THEN NEW FIELDS ARE READ ON EVERY MID MONTH DAY (MMD), 
C     * AND INTERPOLATION WILL BE DONE BETWEEN THE TWO ADJACENT 
C     * MID MONTH DAYS. XSFXPAK IS THE PRECEDENT, XSFXPAL THE FOLLOWING.
C 
      IMPLICIT NONE
      REAL XSFXPAK(1),XSFXPAL(1)
      REAL GG(1)
      INTEGER NFDM(12),MMD(12)
  
      INTEGER NF, NLON, NLAT, INCD, IDAY
      INTEGER MDAY, KOUNT, NAMTS

      INTEGER IMO, IMOT, IYRMOT
      INTEGER JOUR1, JOUR, N
      INTEGER MBUF2, L1, MDAY1, M, L
  
      INTEGER IYEAR,IYMDH,IMDH,MYRSSTI,ISAVDTS
      COMMON /KEEPTIM/ IYEAR,IMDH,MYRSSTI,ISAVDTS
C 
      DATA NFDM/  1, 32, 60, 91,121,152,182,213,244,274,305,335/
      DATA  MMD/ 16, 46, 75,106,136,167,197,228,259,289,320,350/
C----------------------------------------------------------------------
C     * VALUE TO SEARCH FOR IN IBUF(2) IS DEPENDANT ON WHETHER RUN
C     * IS USING STANDARD BOUNDARY FORCING OR MULTI-YEAR CONDITIONS.
C 
C     * IN 32-BIT, THIS ONLY WORKS UNTIL IYEAR=2147!
      IYMDH = 1000000*IYEAR + IMDH
      IMO=(IYMDH-(1000000*IYEAR))/10000
      IF(IMO.NE.12)                          THEN
        IMOT=IMO+1
        IYRMOT=1000000*IYEAR + 10000*IMOT + 100
      ELSE
        IMOT=1
        IYRMOT=(IYEAR+1)*1000000 + 10000*IMOT + 100
      ENDIF
C
      IF(INCD.EQ.0) THEN
C       * 
C       * MODEL IS STATIONARY.
C       * ABORT IF RUNNING AMIP-LIKE EXPERIMENT.
C
        IF(MYRSSTI.NE.0)           CALL XIT('GETXFXX',-1)
        IF(KOUNT.EQ.0) THEN 
C         * 
C         * START-UP TIME. READ-IN XSFX FOR AVERAGE OF MONTH. 
C         * 
C          MDAY=IDAY 
          CALL GETAGBX(XSFXPAK,NAMTS,NF,NLON,NLAT,IDAY,GG) 
          RETURN
        ELSE
C         * 
C         * NOT A NEW INTEGRATION. NO NEW FIELD REQUIRED. 
C         * 
          RETURN
        ENDIF 
      ELSE
C       * 
C       * THE MODEL IS MOVING.
C       * 
        IF(KOUNT.EQ.0) THEN 
C         * 
C         * START-UP TIME. GET XSFX FOR PREVIOUS AND FOLLOWING MID MONTH DAYS.
C         * NOTE THAT FOR AMIP-LIKE RUNS, NO "PREVIOUS" CONDITIONS
C         * EXIST SO THAT START CONDITIONS HELD CONSTANT THROUGH FIRST
C         * HALF-MONTH.
C         * 
          L=0 
          DO 150 N=1,12 
            IF(IDAY.GE.MMD(N)) L=N+1
  150     CONTINUE

          IF(L.EQ.0.OR.L.EQ.13) L=1 
          MDAY=MMD(L) 
          WRITE(6,6020) MDAY
          CALL GETAGBX(XSFXPAK,NAMTS,NF,NLON,NLAT,IYMDH,GG)
          CALL GETAGBX(XSFXPAL,NAMTS,NF,NLON,NLAT,IYMDH,GG)

          RETURN
        ELSE
C         * 
C         * THIS IS IN THE MIDDLE OF A RUN. 
C         * 
          PRINT*,'INSIDE GETXFX -- IDAY, MDAY= ',IDAY,' ',MDAY

          PRINT*,'TIME TO RESET MDAYT.'
            WRITE(6,6010) 
C           * 
C           * TIME TO GET NEW TRACER SURFACE FLUX FIELDS FOR NEXT
C           * MID-MONTH DAY. 
C           * 
            M=0 
            DO 250 N=1,12 
              IF(IDAY.EQ.MMD(N)) M=N+1
  250       CONTINUE

            IF(M.EQ.13) M=1 
            IF(M.EQ.0)                         CALL XIT('GETXFXX',-2) 
            MDAY=MMD(M) 
            JOUR=NFDM(M)
            WRITE(6,6020) MDAY
            IF(MYRSSTI.EQ.0)     THEN
              MBUF2=JOUR
            ELSE
              MBUF2=IYRMOT
            ENDIF
            PRINT*,'BEFORE GETAGBX -- IDAY, MDAY= ',IDAY,' ',MDAY
            CALL GETAGBX(XSFXPAL,NAMTS,NF,NLON,NLAT,MBUF2,GG)
            PRINT*,'AFTER GETAGBX -- IDAY, MDAY= ',IDAY,' ',MDAY
            RETURN

        ENDIF 
      ENDIF 
C---------------------------------------------------------------------
 6010 FORMAT('0    NEW TRACER SURFACE FLUX FIELDS REQUIRED') 
 6020 FORMAT('0    MDAYT RESET TO',I6)
      END 
