      SUBROUTINE GETBNDX(  GTPAK,  GTPAL,  GTPAM,
     1                    SICPAK, SICPAL, SICPAM,
     2                   SICNPAK,SICNPAL,SICNPAM,
     3                   MASKPAK,NLON,NLAT,INCD,IDAY,MDAY,
     4                   KOUNT,NUGC,NUGT,NUSIC,GG)
C
C     * SEP 27/03 - M.LAZARE. INCORPORATES NECESSARY MPI REVISIIONS.
C     * MAY 28/03 - M.LAZARE. ROW/ROL FIELDS REMOVED (NOT USED) AND
C     *                       NPPS,NPPG REMOVED FROM CALL.
C     * APR 30/03 - M.LAZARE. {GETAGB,GETGGB} -> {GETAGBX,GETGGBX}.
C     * JUL 27/00 - M.LAZARE. COSMETIC CHANGE TO OPTIMIZE I/O
C     *                       AFTER INITSP, IFF MYRSSTI=0.
C     * OCT  7/97 - M.LAZARE. COMBINE PREVOUS GETGT6/GETSIC6 INTO
C     *                       ONE ROUTINE WHERE SEA-ICE CONCENTRATION
C     *                       HAS BEEN ADDED AND SEA-ICE FIELDS ARE
C     *                       DEFINED AT MID-MONTH. ALSO, LAND-MASK
C     *                       FIELD USED INSTEAD OF "GCPAK" AND
C     *                       PREVIOUS MID-MONTH FIELDS STORED IN
C     *                       RESPECTIVE "PAM" ARRAYS.
C     *                       SINCE ALL ARE COMBINED IN ONE SUBROUTINE
C     *                       NOW, THE 3 POSSIBLY DISTINCT UNIT NUMBERS
C     *                       ARE PASSED IN AND USED.         
C     * JUN 15/95 - M.LAZARE. PREVIOUS VERSIONS GETGT6/GETSIC6.
C     * OCT 11/87 - M.LAZARE. PREVIOUS VERSION GETGT5.
C
C     * READ IN GROUND TEMPERATURE, SEA-ICE MASS AND SEA-ICE
C     * CONCENTRATION FIELD(S).
C
C     * PREVIOUS MID-MONTH VALUES ARE STORED IN "PAM" ARRAYS.
C
C     * TIME LABEL IS THE JULIAN DATE OF THE FIRST OF THE MONTH 
C     * (NFDM) FOR WHICH THE SST ARE THE MONTHLY AVERAGE. 
C
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. "PAK" IS THE PRECEDENT, "PAL" IS THE TARGET.

      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)                                         

      REAL   GTPAK(*),  GTPAL(*),  GTPAM(*)
      REAL  SICPAK(*), SICPAL(*), SICPAM(*)
      REAL SICNPAK(*),SICNPAL(*),SICNPAM(*)
      REAL MASKPAK(*),GG(*)

      INTEGER NFDM(12),MMD(12)
      INTEGER*4 MYNODE
C
      COMMON /KEEPTIM/ IYEAR,IMDH,MYRSSTI,ISAVDTS
      COMMON /MPINFO/ MYNODE
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     * DETERMINE NEXT MID-MONTH INDICATOR.
C
      IF(MYNODE.EQ.0) WRITE(6,6010) 
C
C     * TIME TO GET NEW BOUNDARY FIELDS FOR NEXT MID-MONTH DAY. 
C
      M=0 
      DO 250 N=1,12 
        IF(IDAY.GE.MMD(N)) M=N+1
  250 CONTINUE
      IF(M.EQ.0 .OR. M.EQ.13) M=1 
      MDAY=MMD(M) 
      JOUR=MMD(M)
      M1=M-1
      IF(M1.EQ.0) M1=12 
      JOUR1=MMD(M1)
      MDAY1=MMD(M1) 
      IF(MYNODE.EQ.0) WRITE(6,6020) MDAY

C     * VALUE TO SEARCH FOR IN IBUF(2) IS DEPENDANT ON WHETHER RUN
C     * IS USING STANDARD BOUNDARY FORCING OR MULTI-YEAR CONDITIONS.
C
      IF(MYRSSTI.EQ.0)                      THEN
        MBUF1=JOUR1
        MBUF2=JOUR
      ELSE 
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
        IYRMO=1000000*IYEAR + 10000*IMO + 100
C
        MBUF1=IYRMO
        MBUF2=IYRMOT
      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('GETBNDX',-2)
        IF(KOUNT.EQ.0) THEN 
C         
C         * START-UP TIME. READ-IN FIELDS FOR AVERAGE OF MONTH. 
C         * INITIALIZE TARGET FIELDS AS WELL, ALTHOUGH NOT USED.
C         
          CALL GETAGBX(  GTPAK,NC4TO8("  GT"), NUGT,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX(  GTPAL,NC4TO8("  GT"), NUGT,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX(  GTPAM,NC4TO8("  GT"), NUGT,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX( SICPAK,NC4TO8(" SIC"),NUSIC,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX( SICPAL,NC4TO8(" SIC"),NUSIC,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX( SICPAM,NC4TO8(" SIC"),NUSIC,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX(SICNPAK,NC4TO8("SICN"), NUGC,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX(SICNPAL,NC4TO8("SICN"), NUGC,NLON,NLAT,IDAY,GG) 
          CALL GETAGBX(SICNPAM,NC4TO8("SICN"), NUGC,NLON,NLAT,IDAY,GG) 

        ELSE
C         
C         * NOT A NEW INTEGRATION. NO NEW FIELDS REQUIRED. 
C         
        ENDIF 

      ELSE
C      
C       * THE MODEL IS MOVING.
C      
        IF(KOUNT.EQ.0) THEN 
C         
C         * START-UP TIME. GET FIELDS FOR PREVIOUS AND TARGET MID-MONTH DAYS.
C         * NOTE THAT FOR MULTI-YEAR SST/ICE RUNS, NO "PREVIOUS" CONDITIONS
C         * EXIST SO THAT START CONDITIONS HELD CONSTANT THROUGH FIRST
C         * HALF-MONTH.
C         
          IF(MYRSSTI.EQ.0)     THEN
C
            CALL GETAGBX(GTPAM,NC4TO8("  GT"),NUGT,NLON,NLAT,JOUR1,GG)
            CALL GETAGBX(GTPAL,NC4TO8("  GT"),NUGT,NLON,NLAT,JOUR ,GG)
            CALL GETAGBX(GTPAK,NC4TO8("  GT"),NUGT,NLON,NLAT,IDAY ,GG)
C
            CALL GETAGBX(SICNPAM,NC4TO8("SICN"),NUGC,NLON,NLAT,JOUR1,GG)
            CALL GETAGBX(SICNPAL,NC4TO8("SICN"),NUGC,NLON,NLAT,JOUR ,GG)
            CALL GETAGBX(SICNPAK,NC4TO8("SICN"),NUGC,NLON,NLAT,IDAY ,GG)
C
            CALL GETAGBX(SICPAM,NC4TO8(" SIC"),NUSIC,NLON,NLAT,JOUR1,GG)
            CALL GETAGBX(SICPAL,NC4TO8(" SIC"),NUSIC,NLON,NLAT,JOUR ,GG)
            CALL GETAGBX(SICPAK,NC4TO8(" SIC"),NUSIC,NLON,NLAT,IDAY ,GG)
          ELSE  
            CALL GETAGBX(  GTPAK,NC4TO8("  GT"), NUGT,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX(  GTPAL,NC4TO8("  GT"), NUGT,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX(  GTPAM,NC4TO8("  GT"), NUGT,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX(SICNPAK,NC4TO8("SICN"), NUGC,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX(SICNPAL,NC4TO8("SICN"), NUGC,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX(SICNPAM,NC4TO8("SICN"), NUGC,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX( SICPAK,NC4TO8(" SIC"),NUSIC,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX( SICPAL,NC4TO8(" SIC"),NUSIC,NLON,NLAT,
     1                   IYMDH,GG)
            CALL GETAGBX( SICPAM,NC4TO8(" SIC"),NUSIC,NLON,NLAT,
     1                   IYMDH,GG)
          ENDIF

        ELSE
C 
C         * THIS IS IN THE MIDDLE OF A RUN. 
C
          IF(MYRSSTI.EQ.0) THEN
C
C           * ALL DATA IS ON ONE FILE, AND READ IN OPTIMAL ORDER
C           * FOR MAXIMUM I/O.
C
            IF(NUGT.NE.NUGC .OR. NUGT.NE.NUSIC .OR. NUGC.NE.NUSIC) THEN
              CALL XIT ('GETBNDX',-3)
            ENDIF
C
            NUAN=NUGC
            REWIND NUAN
C
C           * NOTE THAT THE LOGIC IS MAINTAINED FOR OPTIMAL I/O EVEN
C           * THOUGH THERE IS A REWIND BETWEEN THE TWO SETS IN THE
C           * FOLLOWING. THIS IS BECAUSE CURRENTLY ONLY "GT" UNDERGOES
C           * THE CONSERVATION OF MONTHLY MEANS. IF IN THE FUTURE ALL
C           * 3 FIELDS DID, THE REWINDS COULD BE REMOVED!
C   
            IF(IDAY.EQ.MMD(1) .OR. IDAY.EQ.MMD(12)) THEN
             CALL GETGGBX(SICNPAL,NC4TO8("SICN"),NUAN,NLON,NLAT,
     1                    MBUF2,1,GG)
             CALL GETGGBX( SICPAL,NC4TO8(" SIC"),NUAN,NLON,NLAT,
     1                    MBUF2,1,GG)
             CALL GETGGBX(  GTPAL,NC4TO8("  GT"),NUAN,NLON,NLAT,
     1                    MBUF2,1,GG)
             REWIND NUAN
             CALL GETGGBX(SICNPAM,NC4TO8("SICN"),NUAN,NLON,NLAT,
     1                    MBUF1,1,GG)
             CALL GETGGBX( SICPAM,NC4TO8(" SIC"),NUAN,NLON,NLAT,
     1                    MBUF1,1,GG)
             CALL GETGGBX(  GTPAM,NC4TO8("  GT"),NUAN,NLON,NLAT,
     1                    MBUF1,1,GG)
            ELSE
             CALL GETGGBX(SICNPAM,NC4TO8("SICN"),NUAN,NLON,NLAT,
     1                    MBUF1,1,GG)
             CALL GETGGBX( SICPAM,NC4TO8(" SIC"),NUAN,NLON,NLAT,
     1                    MBUF1,1,GG)
             CALL GETGGBX(  GTPAM,NC4TO8("  GT"),NUAN,NLON,NLAT,
     1                    MBUF1,1,GG)
             REWIND NUAN
             CALL GETGGBX(SICNPAL,NC4TO8("SICN"),NUAN,NLON,NLAT,
     1                    MBUF2,1,GG)
             CALL GETGGBX( SICPAL,NC4TO8(" SIC"),NUAN,NLON,NLAT,
     1                    MBUF2,1,GG)
             CALL GETGGBX(  GTPAL,NC4TO8("  GT"),NUAN,NLON,NLAT,
     1                    MBUF2,1,GG)
            ENDIF

          ELSE 

            CALL GETAGBX(  GTPAL,NC4TO8("  GT"), NUGT,NLON,NLAT,
     1                   MBUF2,GG)
            CALL GETAGBX(SICNPAL,NC4TO8("SICN"), NUGC,NLON,NLAT,
     1                   MBUF2,GG)
            CALL GETAGBX( SICPAL,NC4TO8(" SIC"),NUSIC,NLON,NLAT,
     1                   MBUF2,GG)
            CALL GETAGBX(  GTPAM,NC4TO8("  GT"), NUGT,NLON,NLAT,
     1                   MBUF1,GG)
            CALL GETAGBX(SICNPAM,NC4TO8("SICN"), NUGC,NLON,NLAT,
     1                   MBUF1,GG)
            CALL GETAGBX( SICPAM,NC4TO8(" SIC"),NUSIC,NLON,NLAT,
     1                   MBUF1,GG)
         
          ENDIF

        ENDIF

      ENDIF 
      RETURN
C---------------------------------------------------------------------
 6010 FORMAT('0    NEW BOUNDARY CONDITIONS REQUIRED') 
 6020 FORMAT('0    MDAY RESET TO',I6)
      END
