












      subroutine get_bry
      


      use Agrif_Util
      interface
        subroutine Sub_Loop_get_bry(padd_E,Mm,padd_X,Lm,may_day_flag,tda
     &ys,mynode,tbry_north_dt,vbry_north_dt,ubry_north_dt,vbarbry_north_
     &dt,ubarbry_north_dt,zetabry_north_dt,tbry_south_dt,vbry_south_dt,u
     &bry_south_dt,vbarbry_south_dt,ubarbry_south_dt,zetabry_south_dt,tb
     &ry_east_dt,vbry_east_dt,ubry_east_dt,vbarbry_east_dt,ubarbry_east_
     &dt,zetabry_east_dt,tbry_west_dt,vbry_west_dt,ubry_west_dt,vbarbry_
     &west_dt,ubarbry_west_dt,zetabry_west_dt,dt,time,bry_time,itbry,bry
     &_rec,bry_ncycle,bry_cycle,ntbry,tbry_north_id,vbry_north_id,ubry_n
     &orth_id,vbarbry_north_id,ubarbry_north_id,zetabry_north_id,tbry_so
     &uth_id,vbry_south_id,ubry_south_id,vbarbry_south_id,ubarbry_south_
     &id,zetabry_south_id,tbry_east_id,vbry_east_id,ubry_east_id,vbarbry
     &_east_id,ubarbry_east_id,zetabry_east_id,tbry_west_id,vbry_west_id
     &,ubry_west_id,vbarbry_west_id,ubarbry_west_id,zetabry_west_id,bry_
     &time_id,bry_id,iic,bry_file)
          implicit none
      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxWSPD = indxSST+3
      integer(4), parameter :: indxTAIR = indxSST+4
      integer(4), parameter :: indxRHUM = indxSST+5
      integer(4), parameter :: indxRADLW = indxSST+6
      integer(4), parameter :: indxRADSW = indxSST+7
      integer(4), parameter :: indxPRATE = indxSST+8
      integer(4), parameter :: indxUWND = indxSST+9
      integer(4), parameter :: indxVWND = indxSST+10
      integer(4), parameter :: indxPATM = indxSST+11
      integer(4), parameter :: indxShflx_rlw = indxSST+12
      integer(4), parameter :: indxShflx_lat = indxSST+13
      integer(4), parameter :: indxShflx_sen = indxSST+14
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      integer(4), parameter :: nf_byte = 1
      integer(4), parameter :: nf_int1 = nf_byte
      integer(4), parameter :: nf_char = 2
      integer(4), parameter :: nf_short = 3
      integer(4), parameter :: nf_int2 = nf_short
      integer(4), parameter :: nf_int = 4
      integer(4), parameter :: nf_float = 5
      integer(4), parameter :: nf_real = nf_float
      integer(4), parameter :: nf_double = 6
      integer(4), parameter :: nf_ubyte = 7
      integer(4), parameter :: nf_ushort = 8
      integer(4), parameter :: nf_uint = 9
      integer(4), parameter :: nf_int64 = 10
      integer(4), parameter :: nf_uint64 = 11
      integer(4), parameter :: nf_fill_byte = -127
      integer(4), parameter :: nf_fill_int1 = nf_fill_byte
      integer(4), parameter :: nf_fill_char = 0
      integer(4), parameter :: nf_fill_short = -32767
      integer(4), parameter :: nf_fill_int2 = nf_fill_short
      integer(4), parameter :: nf_fill_int = -2147483647
      real, parameter :: nf_fill_float = 9.9692099683868690D+36
      real, parameter :: nf_fill_real = nf_fill_float
      real(8), parameter :: nf_fill_double = 9.9692099683868690D+36
      integer(4), parameter :: nf_nowrite = 0
      integer(4), parameter :: nf_write = 1
      integer(4), parameter :: nf_clobber = 0
      integer(4), parameter :: nf_noclobber = 4
      integer(4), parameter :: nf_fill = 0
      integer(4), parameter :: nf_nofill = 256
      integer(4), parameter :: nf_lock = 1024
      integer(4), parameter :: nf_share = 2048
      integer(4), parameter :: nf_64bit_offset = 512
      integer(4), parameter :: nf_64bit_data = 32
      integer(4), parameter :: nf_cdf5 = nf_64bit_data
      integer(4), parameter :: nf_sizehint_default = 0
      integer(4), parameter :: nf_align_chunk = -1
      integer(4), parameter :: nf_format_classic = 1
      integer(4), parameter :: nf_format_64bit = 2
      integer(4), parameter :: nf_format_64bit_offset = nf_format_64bit
      integer(4), parameter :: nf_format_64bit_data = 5
      integer(4), parameter :: nf_format_cdf5 = nf_format_64bit_data
      integer(4), parameter :: nf_diskless = 8
      integer(4), parameter :: nf_mmap = 16
      integer(4), parameter :: nf_unlimited = 0
      integer(4), parameter :: nf_global = 0
      integer(4), parameter :: nf_max_dims = 1024
      integer(4), parameter :: nf_max_attrs = 8192
      integer(4), parameter :: nf_max_vars = 8192
      integer(4), parameter :: nf_max_name = 256
      integer(4), parameter :: nf_max_var_dims = nf_max_dims
      integer(4), parameter :: nf_noerr = 0
      integer(4), parameter :: nf_ebadid = -33
      integer(4), parameter :: nf_eexist = -35
      integer(4), parameter :: nf_einval = -36
      integer(4), parameter :: nf_eperm = -37
      integer(4), parameter :: nf_enotindefine = -38
      integer(4), parameter :: nf_eindefine = -39
      integer(4), parameter :: nf_einvalcoords = -40
      integer(4), parameter :: nf_emaxdims = -41
      integer(4), parameter :: nf_enameinuse = -42
      integer(4), parameter :: nf_enotatt = -43
      integer(4), parameter :: nf_emaxatts = -44
      integer(4), parameter :: nf_ebadtype = -45
      integer(4), parameter :: nf_ebaddim = -46
      integer(4), parameter :: nf_eunlimpos = -47
      integer(4), parameter :: nf_emaxvars = -48
      integer(4), parameter :: nf_enotvar = -49
      integer(4), parameter :: nf_eglobal = -50
      integer(4), parameter :: nf_enotnc = -51
      integer(4), parameter :: nf_ests = -52
      integer(4), parameter :: nf_emaxname = -53
      integer(4), parameter :: nf_eunlimit = -54
      integer(4), parameter :: nf_enorecvars = -55
      integer(4), parameter :: nf_echar = -56
      integer(4), parameter :: nf_eedge = -57
      integer(4), parameter :: nf_estride = -58
      integer(4), parameter :: nf_ebadname = -59
      integer(4), parameter :: nf_erange = -60
      integer(4), parameter :: nf_enomem = -61
      integer(4), parameter :: nf_evarsize = -62
      integer(4), parameter :: nf_edimsize = -63
      integer(4), parameter :: nf_etrunc = -64
      integer(4), parameter :: nf_fatal = 1
      integer(4), parameter :: nf_verbose = 2
      integer(4), parameter :: nf_string = 12
      integer(4), parameter :: nf_vlen = 13
      integer(4), parameter :: nf_opaque = 14
      integer(4), parameter :: nf_enum = 15
      integer(4), parameter :: nf_compound = 16
      integer(4), parameter :: nf_fill_ubyte = 255
      integer(4), parameter :: nf_fill_ushort = 65535
      integer(4), parameter :: nf_format_netcdf4 = 3
      integer(4), parameter :: nf_format_netcdf4_classic = 4
      integer(4), parameter :: nf_netcdf4 = 4096
      integer(4), parameter :: nf_classic_model = 256
      integer(4), parameter :: nf_chunk_seq = 0
      integer(4), parameter :: nf_chunk_sub = 1
      integer(4), parameter :: nf_chunk_sizes = 2
      integer(4), parameter :: nf_endian_native = 0
      integer(4), parameter :: nf_endian_little = 1
      integer(4), parameter :: nf_endian_big = 2
      integer(4), parameter :: nf_chunked = 0
      integer(4), parameter :: nf_contiguous = 1
      integer(4), parameter :: nf_nochecksum = 0
      integer(4), parameter :: nf_fletcher32 = 1
      integer(4), parameter :: nf_noshuffle = 0
      integer(4), parameter :: nf_shuffle = 1
      integer(4), parameter :: nf_szip_ec_option_mask = 4
      integer(4), parameter :: nf_szip_nn_option_mask = 32
      integer(4), parameter :: nf_mpiio = 8192
      integer(4), parameter :: nf_mpiposix = 16384
      integer(4), parameter :: nf_pnetcdf = 32768
      integer(4), parameter :: nf_independent = 0
      integer(4), parameter :: nf_collective = 1
      integer(4), parameter :: nf_ehdferr = -101
      integer(4), parameter :: nf_ecantread = -102
      integer(4), parameter :: nf_ecantwrite = -103
      integer(4), parameter :: nf_ecantcreate = -104
      integer(4), parameter :: nf_efilemeta = -105
      integer(4), parameter :: nf_edimmeta = -106
      integer(4), parameter :: nf_eattmeta = -107
      integer(4), parameter :: nf_evarmeta = -108
      integer(4), parameter :: nf_enocompound = -109
      integer(4), parameter :: nf_eattexists = -110
      integer(4), parameter :: nf_enotnc4 = -111
      integer(4), parameter :: nf_estrictnc3 = -112
      integer(4), parameter :: nf_enotnc3 = -113
      integer(4), parameter :: nf_enopar = -114
      integer(4), parameter :: nf_eparinit = -115
      integer(4), parameter :: nf_ebadgrpid = -116
      integer(4), parameter :: nf_ebadtypid = -117
      integer(4), parameter :: nf_etypdefined = -118
      integer(4), parameter :: nf_ebadfield = -119
      integer(4), parameter :: nf_ebadclass = -120
      integer(4), parameter :: nf_emaptype = -121
      integer(4), parameter :: nf_elatefill = -122
      integer(4), parameter :: nf_elatedef = -123
      integer(4), parameter :: nf_edimscale = -124
      integer(4), parameter :: nf_enogrp = -125
      integer(4), parameter :: ncbyte = 1
      integer(4), parameter :: ncchar = 2
      integer(4), parameter :: ncshort = 3
      integer(4), parameter :: nclong = 4
      integer(4), parameter :: ncfloat = 5
      integer(4), parameter :: ncdouble = 6
      integer(4), parameter :: ncrdwr = 1
      integer(4), parameter :: nccreat = 2
      integer(4), parameter :: ncexcl = 4
      integer(4), parameter :: ncindef = 8
      integer(4), parameter :: ncnsync = 16
      integer(4), parameter :: nchsync = 32
      integer(4), parameter :: ncndirty = 64
      integer(4), parameter :: nchdirty = 128
      integer(4), parameter :: ncfill = 0
      integer(4), parameter :: ncnofill = 256
      integer(4), parameter :: nclink = 32768
      integer(4), parameter :: ncnowrit = 0
      integer(4), parameter :: ncwrite = ncrdwr
      integer(4), parameter :: ncclob = nf_clobber
      integer(4), parameter :: ncnoclob = nf_noclobber
      integer(4), parameter :: ncunlim = 0
      integer(4), parameter :: ncglobal = 0
      integer(4), parameter :: maxncop = 64
      integer(4), parameter :: maxncdim = 1024
      integer(4), parameter :: maxncatt = 8192
      integer(4), parameter :: maxncvar = 8192
      integer(4), parameter :: maxncnam = 256
      integer(4), parameter :: maxvdims = maxncdim
      integer(4), parameter :: ncnoerr = nf_noerr
      integer(4), parameter :: ncebadid = nf_ebadid
      integer(4), parameter :: ncenfile = -31
      integer(4), parameter :: nceexist = nf_eexist
      integer(4), parameter :: nceinval = nf_einval
      integer(4), parameter :: nceperm = nf_eperm
      integer(4), parameter :: ncenotin = nf_enotindefine
      integer(4), parameter :: nceindef = nf_eindefine
      integer(4), parameter :: ncecoord = nf_einvalcoords
      integer(4), parameter :: ncemaxds = nf_emaxdims
      integer(4), parameter :: ncename = nf_enameinuse
      integer(4), parameter :: ncenoatt = nf_enotatt
      integer(4), parameter :: ncemaxat = nf_emaxatts
      integer(4), parameter :: ncebadty = nf_ebadtype
      integer(4), parameter :: ncebadd = nf_ebaddim
      integer(4), parameter :: nceunlim = nf_eunlimpos
      integer(4), parameter :: ncemaxvs = nf_emaxvars
      integer(4), parameter :: ncenotvr = nf_enotvar
      integer(4), parameter :: nceglob = nf_eglobal
      integer(4), parameter :: ncenotnc = nf_enotnc
      integer(4), parameter :: ncests = nf_ests
      integer(4), parameter :: ncentool = nf_emaxname
      integer(4), parameter :: ncfoobar = 32
      integer(4), parameter :: ncsyserr = -31
      integer(4), parameter :: ncfatal = 1
      integer(4), parameter :: ncverbos = 2
      integer(4), parameter :: filbyte = -127
      integer(4), parameter :: filchar = 0
      integer(4), parameter :: filshort = -32767
      integer(4), parameter :: fillong = -2147483647
      real, parameter :: filfloat = 9.9692099683868690D+36
      real(8), parameter :: fildoub = 9.9692099683868690D+36
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: may_day_flag
      real :: tdays
      integer(4) :: mynode
      real :: dt
      real :: time
      integer(4) :: itbry
      integer(4) :: bry_rec
      integer(4) :: bry_ncycle
      real :: bry_cycle
      integer(4) :: ntbry
      integer(4) :: vbry_north_id
      integer(4) :: ubry_north_id
      integer(4) :: vbarbry_north_id
      integer(4) :: ubarbry_north_id
      integer(4) :: zetabry_north_id
      integer(4) :: vbry_south_id
      integer(4) :: ubry_south_id
      integer(4) :: vbarbry_south_id
      integer(4) :: ubarbry_south_id
      integer(4) :: zetabry_south_id
      integer(4) :: vbry_east_id
      integer(4) :: ubry_east_id
      integer(4) :: vbarbry_east_id
      integer(4) :: ubarbry_east_id
      integer(4) :: zetabry_east_id
      integer(4) :: vbry_west_id
      integer(4) :: ubry_west_id
      integer(4) :: vbarbry_west_id
      integer(4) :: ubarbry_west_id
      integer(4) :: zetabry_west_id
      integer(4) :: bry_time_id
      integer(4) :: bry_id
      integer(4) :: iic
      character(180) :: bry_file
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_south_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_west_dt
      real, dimension(1:2) :: bry_time
      integer(4), dimension(1:NT) :: tbry_north_id
      integer(4), dimension(1:NT) :: tbry_south_id
      integer(4), dimension(1:NT) :: tbry_east_id
      integer(4), dimension(1:NT) :: tbry_west_id
        end subroutine Sub_Loop_get_bry

      end interface
      

        call Sub_Loop_get_bry( Agrif_tabvars_i(14)%iarray0, Agrif_tabvar
     &s_i(4)%iarray0, Agrif_tabvars_i(13)%iarray0, Agrif_tabvars_i(2)%ia
     &rray0, Agrif_tabvars_i(167)%iarray0, Agrif_tabvars_r(8)%array0, Ag
     &rif_tabvars_i(176)%iarray0, Agrif_tabvars(162)%array4, Agrif_tabva
     &rs(164)%array3, Agrif_tabvars(166)%array3, Agrif_tabvars(168)%arra
     &y2, Agrif_tabvars(170)%array2, Agrif_tabvars(172)%array2, Agrif_ta
     &bvars(174)%array4, Agrif_tabvars(176)%array3, Agrif_tabvars(178)%a
     &rray3, Agrif_tabvars(180)%array2, Agrif_tabvars(182)%array2, Agrif
     &_tabvars(184)%array2, Agrif_tabvars(186)%array4, Agrif_tabvars(188
     &)%array3, Agrif_tabvars(190)%array3, Agrif_tabvars(192)%array2, Ag
     &rif_tabvars(194)%array2, Agrif_tabvars(196)%array2, Agrif_tabvars(
     &198)%array4, Agrif_tabvars(200)%array3, Agrif_tabvars(202)%array3,
     & Agrif_tabvars(204)%array2, Agrif_tabvars(206)%array2, Agrif_tabva
     &rs(208)%array2, Agrif_tabvars_r(3)%array0, Agrif_tabvars_r(5)%arra
     &y0, Agrif_tabvars(210)%array1, Agrif_tabvars_i(271)%iarray0, Agrif
     &_tabvars_i(272)%iarray0, Agrif_tabvars_i(273)%iarray0, Agrif_tabva
     &rs_r(72)%array0, Agrif_tabvars_i(270)%iarray0, Agrif_tabvars_i(246
     &)%iarray1, Agrif_tabvars_i(247)%iarray0, Agrif_tabvars_i(248)%iarr
     &ay0, Agrif_tabvars_i(249)%iarray0, Agrif_tabvars_i(250)%iarray0, A
     &grif_tabvars_i(251)%iarray0, Agrif_tabvars_i(252)%iarray1, Agrif_t
     &abvars_i(253)%iarray0, Agrif_tabvars_i(254)%iarray0, Agrif_tabvars
     &_i(255)%iarray0, Agrif_tabvars_i(256)%iarray0, Agrif_tabvars_i(257
     &)%iarray0, Agrif_tabvars_i(258)%iarray1, Agrif_tabvars_i(259)%iarr
     &ay0, Agrif_tabvars_i(260)%iarray0, Agrif_tabvars_i(261)%iarray0, A
     &grif_tabvars_i(262)%iarray0, Agrif_tabvars_i(263)%iarray0, Agrif_t
     &abvars_i(264)%iarray1, Agrif_tabvars_i(265)%iarray0, Agrif_tabvars
     &_i(266)%iarray0, Agrif_tabvars_i(267)%iarray0, Agrif_tabvars_i(268
     &)%iarray0, Agrif_tabvars_i(269)%iarray0, Agrif_tabvars_i(274)%iarr
     &ay0, Agrif_tabvars_i(275)%iarray0, Agrif_tabvars_i(147)%iarray0, A
     &grif_tabvars_c(17)%carray0)

      end


      subroutine Sub_Loop_get_bry(padd_E,Mm,padd_X,Lm,may_day_flag,tdays
     &,mynode,tbry_north_dt,vbry_north_dt,ubry_north_dt,vbarbry_north_dt
     &,ubarbry_north_dt,zetabry_north_dt,tbry_south_dt,vbry_south_dt,ubr
     &y_south_dt,vbarbry_south_dt,ubarbry_south_dt,zetabry_south_dt,tbry
     &_east_dt,vbry_east_dt,ubry_east_dt,vbarbry_east_dt,ubarbry_east_dt
     &,zetabry_east_dt,tbry_west_dt,vbry_west_dt,ubry_west_dt,vbarbry_we
     &st_dt,ubarbry_west_dt,zetabry_west_dt,dt,time,bry_time,itbry,bry_r
     &ec,bry_ncycle,bry_cycle,ntbry,tbry_north_id,vbry_north_id,ubry_nor
     &th_id,vbarbry_north_id,ubarbry_north_id,zetabry_north_id,tbry_sout
     &h_id,vbry_south_id,ubry_south_id,vbarbry_south_id,ubarbry_south_id
     &,zetabry_south_id,tbry_east_id,vbry_east_id,ubry_east_id,vbarbry_e
     &ast_id,ubarbry_east_id,zetabry_east_id,tbry_west_id,vbry_west_id,u
     &bry_west_id,vbarbry_west_id,ubarbry_west_id,zetabry_west_id,bry_ti
     &me_id,bry_id,iic,bry_file)

      use Agrif_Types, only : Agrif_tabvars

      implicit none

      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4), parameter :: filetype_his = 1
      integer(4), parameter :: filetype_avg = 2
      integer(4), parameter :: filetype_dia = 3
      integer(4), parameter :: filetype_dia_avg = 4
      integer(4), parameter :: filetype_diaM = 5
      integer(4), parameter :: filetype_diaM_avg = 6
      integer(4), parameter :: filetype_diags_vrt = 7
      integer(4), parameter :: filetype_diags_vrt_avg = 8
      integer(4), parameter :: filetype_diags_ek = 9
      integer(4), parameter :: filetype_diags_ek_avg = 10
      integer(4), parameter :: filetype_diags_pv = 11
      integer(4), parameter :: filetype_diags_pv_avg = 12
      integer(4), parameter :: filetype_diags_eddy_avg = 17
      integer(4), parameter :: filetype_surf = 13
      integer(4), parameter :: filetype_surf_avg = 14
      integer(4), parameter :: filetype_diabio = 15
      integer(4), parameter :: filetype_diabio_avg = 16
      integer(4), parameter :: indxTime = 1
      integer(4), parameter :: indxZ = 2
      integer(4), parameter :: indxUb = 3
      integer(4), parameter :: indxVb = 4
      integer(4), parameter :: indxU = 6
      integer(4), parameter :: indxV = 7
      integer(4), parameter :: indxT = indxV+1
      integer(4), parameter :: indxS = indxV+ntrc_temp+1
      integer(4), parameter :: indxBSD = indxV+ntrc_temp+ntrc_salt+ntrc_
     &pas+ntrc_bio+1
      integer(4), parameter :: indxBSS = 101
      integer(4), parameter :: indxO = indxV+ntrc_temp+ntrc_salt+ntrc_pa
     &s+ntrc_bio+ntrc_sed+ntrc_substot+ntrc_diats+ntrc_diauv+ntrc_diavrt
     &+ntrc_diaek+ntrc_diapv+ntrc_diaeddy+ntrc_surf+ntrc_diabio+1
      integer(4), parameter :: indxW = indxO+1
      integer(4), parameter :: indxR = indxO+2
      integer(4), parameter :: indxVisc = indxO+3
      integer(4), parameter :: indxDiff = indxO+4
      integer(4), parameter :: indxAkv = indxO+5
      integer(4), parameter :: indxAkt = indxO+6
      integer(4), parameter :: indxAks = indxAkv+ntrc_temp+4
      integer(4), parameter :: indxHbl = indxAkv+ntrc_temp+5
      integer(4), parameter :: indxHbbl = indxAkv+ntrc_temp+6
      integer(4), parameter :: indxSSH = indxAkv+ntrc_temp+12
      integer(4), parameter :: indxbvf = indxSSH+1
      integer(4), parameter :: indxSUSTR = indxSSH+2
      integer(4), parameter :: indxSVSTR = indxSSH+3
      integer(4), parameter :: indxTime2 = indxSSH+4
      integer(4), parameter :: indxShflx = indxSUSTR+5
      integer(4), parameter :: indxSwflx = indxShflx+1
      integer(4), parameter :: indxShflx_rsw = indxShflx+2
      integer(4), parameter :: indxSST = indxShflx_rsw+1
      integer(4), parameter :: indxdQdSST = indxShflx_rsw+2
      integer(4), parameter :: indxWSPD = indxSST+3
      integer(4), parameter :: indxTAIR = indxSST+4
      integer(4), parameter :: indxRHUM = indxSST+5
      integer(4), parameter :: indxRADLW = indxSST+6
      integer(4), parameter :: indxRADSW = indxSST+7
      integer(4), parameter :: indxPRATE = indxSST+8
      integer(4), parameter :: indxUWND = indxSST+9
      integer(4), parameter :: indxVWND = indxSST+10
      integer(4), parameter :: indxPATM = indxSST+11
      integer(4), parameter :: indxShflx_rlw = indxSST+12
      integer(4), parameter :: indxShflx_lat = indxSST+13
      integer(4), parameter :: indxShflx_sen = indxSST+14
      integer(4), parameter :: indxWstr = indxSUSTR+23
      integer(4), parameter :: indxUWstr = indxSUSTR+24
      integer(4), parameter :: indxVWstr = indxSUSTR+25
      integer(4), parameter :: indxBostr = indxSUSTR+26
      integer(4), parameter :: indxBustr = indxSUSTR+27
      integer(4), parameter :: indxBvstr = indxBustr+1
      integer(4), parameter :: indxWWA = indxSUSTR+42
      integer(4), parameter :: indxWWD = indxWWA+1
      integer(4), parameter :: indxWWP = indxWWA+2
      integer(4), parameter :: r2dvar = 0
      integer(4), parameter :: u2dvar = 1
      integer(4), parameter :: v2dvar = 2
      integer(4), parameter :: p2dvar = 3
      integer(4), parameter :: r3dvar = 4
      integer(4), parameter :: u3dvar = 5
      integer(4), parameter :: v3dvar = 6
      integer(4), parameter :: p3dvar = 7
      integer(4), parameter :: w3dvar = 8
      integer(4), parameter :: pw3dvar = 11
      integer(4), parameter :: b3dvar = 12
      integer(4), parameter :: nf_byte = 1
      integer(4), parameter :: nf_int1 = nf_byte
      integer(4), parameter :: nf_char = 2
      integer(4), parameter :: nf_short = 3
      integer(4), parameter :: nf_int2 = nf_short
      integer(4), parameter :: nf_int = 4
      integer(4), parameter :: nf_float = 5
      integer(4), parameter :: nf_real = nf_float
      integer(4), parameter :: nf_double = 6
      integer(4), parameter :: nf_ubyte = 7
      integer(4), parameter :: nf_ushort = 8
      integer(4), parameter :: nf_uint = 9
      integer(4), parameter :: nf_int64 = 10
      integer(4), parameter :: nf_uint64 = 11
      integer(4), parameter :: nf_fill_byte = -127
      integer(4), parameter :: nf_fill_int1 = nf_fill_byte
      integer(4), parameter :: nf_fill_char = 0
      integer(4), parameter :: nf_fill_short = -32767
      integer(4), parameter :: nf_fill_int2 = nf_fill_short
      integer(4), parameter :: nf_fill_int = -2147483647
      real, parameter :: nf_fill_float = 9.9692099683868690D+36
      real, parameter :: nf_fill_real = nf_fill_float
      real(8), parameter :: nf_fill_double = 9.9692099683868690D+36
      integer(4), parameter :: nf_nowrite = 0
      integer(4), parameter :: nf_write = 1
      integer(4), parameter :: nf_clobber = 0
      integer(4), parameter :: nf_noclobber = 4
      integer(4), parameter :: nf_fill = 0
      integer(4), parameter :: nf_nofill = 256
      integer(4), parameter :: nf_lock = 1024
      integer(4), parameter :: nf_share = 2048
      integer(4), parameter :: nf_64bit_offset = 512
      integer(4), parameter :: nf_64bit_data = 32
      integer(4), parameter :: nf_cdf5 = nf_64bit_data
      integer(4), parameter :: nf_sizehint_default = 0
      integer(4), parameter :: nf_align_chunk = -1
      integer(4), parameter :: nf_format_classic = 1
      integer(4), parameter :: nf_format_64bit = 2
      integer(4), parameter :: nf_format_64bit_offset = nf_format_64bit
      integer(4), parameter :: nf_format_64bit_data = 5
      integer(4), parameter :: nf_format_cdf5 = nf_format_64bit_data
      integer(4), parameter :: nf_diskless = 8
      integer(4), parameter :: nf_mmap = 16
      integer(4), parameter :: nf_unlimited = 0
      integer(4), parameter :: nf_global = 0
      integer(4), parameter :: nf_max_dims = 1024
      integer(4), parameter :: nf_max_attrs = 8192
      integer(4), parameter :: nf_max_vars = 8192
      integer(4), parameter :: nf_max_name = 256
      integer(4), parameter :: nf_max_var_dims = nf_max_dims
      integer(4), parameter :: nf_noerr = 0
      integer(4), parameter :: nf_ebadid = -33
      integer(4), parameter :: nf_eexist = -35
      integer(4), parameter :: nf_einval = -36
      integer(4), parameter :: nf_eperm = -37
      integer(4), parameter :: nf_enotindefine = -38
      integer(4), parameter :: nf_eindefine = -39
      integer(4), parameter :: nf_einvalcoords = -40
      integer(4), parameter :: nf_emaxdims = -41
      integer(4), parameter :: nf_enameinuse = -42
      integer(4), parameter :: nf_enotatt = -43
      integer(4), parameter :: nf_emaxatts = -44
      integer(4), parameter :: nf_ebadtype = -45
      integer(4), parameter :: nf_ebaddim = -46
      integer(4), parameter :: nf_eunlimpos = -47
      integer(4), parameter :: nf_emaxvars = -48
      integer(4), parameter :: nf_enotvar = -49
      integer(4), parameter :: nf_eglobal = -50
      integer(4), parameter :: nf_enotnc = -51
      integer(4), parameter :: nf_ests = -52
      integer(4), parameter :: nf_emaxname = -53
      integer(4), parameter :: nf_eunlimit = -54
      integer(4), parameter :: nf_enorecvars = -55
      integer(4), parameter :: nf_echar = -56
      integer(4), parameter :: nf_eedge = -57
      integer(4), parameter :: nf_estride = -58
      integer(4), parameter :: nf_ebadname = -59
      integer(4), parameter :: nf_erange = -60
      integer(4), parameter :: nf_enomem = -61
      integer(4), parameter :: nf_evarsize = -62
      integer(4), parameter :: nf_edimsize = -63
      integer(4), parameter :: nf_etrunc = -64
      integer(4), parameter :: nf_fatal = 1
      integer(4), parameter :: nf_verbose = 2
      integer(4), parameter :: nf_string = 12
      integer(4), parameter :: nf_vlen = 13
      integer(4), parameter :: nf_opaque = 14
      integer(4), parameter :: nf_enum = 15
      integer(4), parameter :: nf_compound = 16
      integer(4), parameter :: nf_fill_ubyte = 255
      integer(4), parameter :: nf_fill_ushort = 65535
      integer(4), parameter :: nf_format_netcdf4 = 3
      integer(4), parameter :: nf_format_netcdf4_classic = 4
      integer(4), parameter :: nf_netcdf4 = 4096
      integer(4), parameter :: nf_classic_model = 256
      integer(4), parameter :: nf_chunk_seq = 0
      integer(4), parameter :: nf_chunk_sub = 1
      integer(4), parameter :: nf_chunk_sizes = 2
      integer(4), parameter :: nf_endian_native = 0
      integer(4), parameter :: nf_endian_little = 1
      integer(4), parameter :: nf_endian_big = 2
      integer(4), parameter :: nf_chunked = 0
      integer(4), parameter :: nf_contiguous = 1
      integer(4), parameter :: nf_nochecksum = 0
      integer(4), parameter :: nf_fletcher32 = 1
      integer(4), parameter :: nf_noshuffle = 0
      integer(4), parameter :: nf_shuffle = 1
      integer(4), parameter :: nf_szip_ec_option_mask = 4
      integer(4), parameter :: nf_szip_nn_option_mask = 32
      integer(4), parameter :: nf_mpiio = 8192
      integer(4), parameter :: nf_mpiposix = 16384
      integer(4), parameter :: nf_pnetcdf = 32768
      integer(4), parameter :: nf_independent = 0
      integer(4), parameter :: nf_collective = 1
      integer(4), parameter :: nf_ehdferr = -101
      integer(4), parameter :: nf_ecantread = -102
      integer(4), parameter :: nf_ecantwrite = -103
      integer(4), parameter :: nf_ecantcreate = -104
      integer(4), parameter :: nf_efilemeta = -105
      integer(4), parameter :: nf_edimmeta = -106
      integer(4), parameter :: nf_eattmeta = -107
      integer(4), parameter :: nf_evarmeta = -108
      integer(4), parameter :: nf_enocompound = -109
      integer(4), parameter :: nf_eattexists = -110
      integer(4), parameter :: nf_enotnc4 = -111
      integer(4), parameter :: nf_estrictnc3 = -112
      integer(4), parameter :: nf_enotnc3 = -113
      integer(4), parameter :: nf_enopar = -114
      integer(4), parameter :: nf_eparinit = -115
      integer(4), parameter :: nf_ebadgrpid = -116
      integer(4), parameter :: nf_ebadtypid = -117
      integer(4), parameter :: nf_etypdefined = -118
      integer(4), parameter :: nf_ebadfield = -119
      integer(4), parameter :: nf_ebadclass = -120
      integer(4), parameter :: nf_emaptype = -121
      integer(4), parameter :: nf_elatefill = -122
      integer(4), parameter :: nf_elatedef = -123
      integer(4), parameter :: nf_edimscale = -124
      integer(4), parameter :: nf_enogrp = -125
      integer(4), parameter :: ncbyte = 1
      integer(4), parameter :: ncchar = 2
      integer(4), parameter :: ncshort = 3
      integer(4), parameter :: nclong = 4
      integer(4), parameter :: ncfloat = 5
      integer(4), parameter :: ncdouble = 6
      integer(4), parameter :: ncrdwr = 1
      integer(4), parameter :: nccreat = 2
      integer(4), parameter :: ncexcl = 4
      integer(4), parameter :: ncindef = 8
      integer(4), parameter :: ncnsync = 16
      integer(4), parameter :: nchsync = 32
      integer(4), parameter :: ncndirty = 64
      integer(4), parameter :: nchdirty = 128
      integer(4), parameter :: ncfill = 0
      integer(4), parameter :: ncnofill = 256
      integer(4), parameter :: nclink = 32768
      integer(4), parameter :: ncnowrit = 0
      integer(4), parameter :: ncwrite = ncrdwr
      integer(4), parameter :: ncclob = nf_clobber
      integer(4), parameter :: ncnoclob = nf_noclobber
      integer(4), parameter :: ncunlim = 0
      integer(4), parameter :: ncglobal = 0
      integer(4), parameter :: maxncop = 64
      integer(4), parameter :: maxncdim = 1024
      integer(4), parameter :: maxncatt = 8192
      integer(4), parameter :: maxncvar = 8192
      integer(4), parameter :: maxncnam = 256
      integer(4), parameter :: maxvdims = maxncdim
      integer(4), parameter :: ncnoerr = nf_noerr
      integer(4), parameter :: ncebadid = nf_ebadid
      integer(4), parameter :: ncenfile = -31
      integer(4), parameter :: nceexist = nf_eexist
      integer(4), parameter :: nceinval = nf_einval
      integer(4), parameter :: nceperm = nf_eperm
      integer(4), parameter :: ncenotin = nf_enotindefine
      integer(4), parameter :: nceindef = nf_eindefine
      integer(4), parameter :: ncecoord = nf_einvalcoords
      integer(4), parameter :: ncemaxds = nf_emaxdims
      integer(4), parameter :: ncename = nf_enameinuse
      integer(4), parameter :: ncenoatt = nf_enotatt
      integer(4), parameter :: ncemaxat = nf_emaxatts
      integer(4), parameter :: ncebadty = nf_ebadtype
      integer(4), parameter :: ncebadd = nf_ebaddim
      integer(4), parameter :: nceunlim = nf_eunlimpos
      integer(4), parameter :: ncemaxvs = nf_emaxvars
      integer(4), parameter :: ncenotvr = nf_enotvar
      integer(4), parameter :: nceglob = nf_eglobal
      integer(4), parameter :: ncenotnc = nf_enotnc
      integer(4), parameter :: ncests = nf_ests
      integer(4), parameter :: ncentool = nf_emaxname
      integer(4), parameter :: ncfoobar = 32
      integer(4), parameter :: ncsyserr = -31
      integer(4), parameter :: ncfatal = 1
      integer(4), parameter :: ncverbos = 2
      integer(4), parameter :: filbyte = -127
      integer(4), parameter :: filchar = 0
      integer(4), parameter :: filshort = -32767
      integer(4), parameter :: fillong = -2147483647
      real, parameter :: filfloat = 9.9692099683868690D+36
      real(8), parameter :: fildoub = 9.9692099683868690D+36
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: may_day_flag
      real :: tdays
      integer(4) :: mynode
      real :: dt
      real :: time
      integer(4) :: itbry
      integer(4) :: bry_rec
      integer(4) :: bry_ncycle
      real :: bry_cycle
      integer(4) :: ntbry
      integer(4) :: vbry_north_id
      integer(4) :: ubry_north_id
      integer(4) :: vbarbry_north_id
      integer(4) :: ubarbry_north_id
      integer(4) :: zetabry_north_id
      integer(4) :: vbry_south_id
      integer(4) :: ubry_south_id
      integer(4) :: vbarbry_south_id
      integer(4) :: ubarbry_south_id
      integer(4) :: zetabry_south_id
      integer(4) :: vbry_east_id
      integer(4) :: ubry_east_id
      integer(4) :: vbarbry_east_id
      integer(4) :: ubarbry_east_id
      integer(4) :: zetabry_east_id
      integer(4) :: vbry_west_id
      integer(4) :: ubry_west_id
      integer(4) :: vbarbry_west_id
      integer(4) :: ubarbry_west_id
      integer(4) :: zetabry_west_id
      integer(4) :: bry_time_id
      integer(4) :: bry_id
      integer(4) :: iic
      character(180) :: bry_file
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_south_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_west_dt
      real, dimension(1:2) :: bry_time
      integer(4), dimension(1:NT) :: tbry_north_id
      integer(4), dimension(1:NT) :: tbry_south_id
      integer(4), dimension(1:NT) :: tbry_east_id
      integer(4), dimension(1:NT) :: tbry_west_id
                   

                                            
                             
                                            

                                                             
                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                                          
                                             
                          

                        

                                          
                        

                                                        
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

                                                                  
                                                                       
                                                                 
                                 
                                
                                                                       
                                                                 
                                                                 
                                                                 
                                                        
                                                                       
                                                                 
                                                                 
            
                                              
                                                   
                     
                              
                               
                                 
                                                  
                                                                       
                                                                 
                                                                 
                        
                      
                           
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                    
                           
                                      
                             
                                                 
                                                                       
                                                                 
                     
                                                      
                                                                       
                                                                 
              
                                          
                                                                       
                                                                 
       
                                                           
      real(8) :: Cu_Nbq_X
      real(8) :: Cu_Nbq_Y
      real(8) :: Cu_Nbq_Z
                                             
                                                                       
                                                                 
              
                                                  
                                                                       
                                                                 
              
                                  
                                           
                                                  
                                                                   
                                                               
                                                      
                                                                       
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                        
                                
                                                                       
                                                                 
                                                        

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                          
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                   

                                 
      integer(4) :: iloop
      integer(4) :: indextemp
                                                
                                                         

                             
                                  

                      
                               

                      
                                         

                                 
                                                                       
                                                                 
                              

                                                                       
                                                                 
                                                                 
    
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                 

                        
                                             

                        
                                             

                         
                                              

                        
                                              

                        
                                   

                                     
                                                          

                          
                                     

                                         
                                       

                          
                                                                  

                                    
                                                                     

                                                                       
                                                                 
                                            
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
      

                                                          
                                                                       
                                                                 
                                        

                         
                                       

                          
                                        

                          
                                        

                          
                                        

                                     
                                                                

                                                                
      integer(4) :: indxWEB
      integer(4) :: indxWED
      integer(4) :: indxWER
                                                                       
                                                                 
                                                          

                                                                       
                                                                 
                                                                 
            
                                                                       
                                                                 
                                                                 
       

                                           
                                                       
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
    
                                                                       
                                                                 
                                                                 
                    
                         
                       
                        
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                               
                         
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                      
                         
                                                                       
                                                                 
 
                                                          
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                    
                                   
                                                                 
                                                                       
                                                                 
                                                                 
                                                                 
                               
                                                                  
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
     
                                   
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
               
                        
                        
                        
                         
                        
                       
                         
                        
                          
                         
                          
                        
                         
                          
                             

                                   

                             

                              

                                    

                            

                              

                                    

                               

                              

                               

                             

                               

                                

                                       
                                       
                                       
                                        
                                       
                                      
                                      
                                     
                                       
                                     

                                             

                                  

                                        

                                              

                                           

                                                        

                                              

                                                         

                           
                         
                           
                             
                        
                          
                        
                         
                                
                              
                        
                                    
                               
                                  
                                
                                       
                                     
                               
                            
                        
                                

                              

                                

                                  

                             

                                 

                                

                                 

                                       

                                    

                                         

                                         

                                     

                                       

                                     

                                                          

                                          

                                                       

                                 

                              

                             
                                  

                          
                               

                            
                             
                            
                            
                                
                                    

                                     

                                    

                                   

                                               

                         
                          
                          
                          
                         
                                
                             
                                
                            
                              
                           
                            
                            
                           
                             
                            
                           
                           
                          
                        
                            
                            
                              
                         
                         
                           
                            
                          
                          
                            
                            
                          
                              

                                 

                                 

                                 

                                

                                       

                                    

                                       

                                   

                                     

                                  

                                   

                                   

                                  

                                    

                                   

                                  

                                  

                                 

                               

                                   

                                   

                                     

                                

                                

                                  

                                   

                                 

                                 

                                   

                                   

                                 

                          
                           
                              

                                

                                    
      character(80) :: nf_inq_libvers
      external       nf_inq_libvers
                                 
      character(80) :: nf_strerror
      external       nf_strerror
                                 
      logical :: nf_issyserr
      external       nf_issyserr
                                       
      integer(4) :: nf_inq_base_pe
      external        nf_inq_base_pe
                                       
      integer(4) :: nf_set_base_pe
      external        nf_set_base_pe
                                  
      integer(4) :: nf_create
      external        nf_create
                                   
      integer(4) :: nf__create
      external        nf__create
                                      
      integer(4) :: nf__create_mp
      external        nf__create_mp
                                
      integer(4) :: nf_open
      external        nf_open
                                 
      integer(4) :: nf__open
      external        nf__open
                                    
      integer(4) :: nf__open_mp
      external        nf__open_mp
                                    
      integer(4) :: nf_set_fill
      external        nf_set_fill
                                              
      integer(4) :: nf_set_default_format
      external        nf_set_default_format
                                 
      integer(4) :: nf_redef
      external        nf_redef
                                  
      integer(4) :: nf_enddef
      external        nf_enddef
                                   
      integer(4) :: nf__enddef
      external        nf__enddef
                                
      integer(4) :: nf_sync
      external        nf_sync
                                 
      integer(4) :: nf_abort
      external        nf_abort
                                 
      integer(4) :: nf_close
      external        nf_close
                                  
      integer(4) :: nf_delete
      external        nf_delete
                               
      integer(4) :: nf_inq
      external        nf_inq
                            
      integer(4) :: nf_inq_path
      external nf_inq_path
                                     
      integer(4) :: nf_inq_ndims
      external        nf_inq_ndims
                                     
      integer(4) :: nf_inq_nvars
      external        nf_inq_nvars
                                     
      integer(4) :: nf_inq_natts
      external        nf_inq_natts
                                        
      integer(4) :: nf_inq_unlimdim
      external        nf_inq_unlimdim
                                      
      integer(4) :: nf_inq_format
      external        nf_inq_format
                                   
      integer(4) :: nf_def_dim
      external        nf_def_dim
                                     
      integer(4) :: nf_inq_dimid
      external        nf_inq_dimid
                                   
      integer(4) :: nf_inq_dim
      external        nf_inq_dim
                                       
      integer(4) :: nf_inq_dimname
      external        nf_inq_dimname
                                      
      integer(4) :: nf_inq_dimlen
      external        nf_inq_dimlen
                                      
      integer(4) :: nf_rename_dim
      external        nf_rename_dim
                                   
      integer(4) :: nf_inq_att
      external        nf_inq_att
                                     
      integer(4) :: nf_inq_attid
      external        nf_inq_attid
                                       
      integer(4) :: nf_inq_atttype
      external        nf_inq_atttype
                                      
      integer(4) :: nf_inq_attlen
      external        nf_inq_attlen
                                       
      integer(4) :: nf_inq_attname
      external        nf_inq_attname
                                    
      integer(4) :: nf_copy_att
      external        nf_copy_att
                                      
      integer(4) :: nf_rename_att
      external        nf_rename_att
                                   
      integer(4) :: nf_del_att
      external        nf_del_att
                                        
      integer(4) :: nf_put_att_text
      external        nf_put_att_text
                                        
      integer(4) :: nf_get_att_text
      external        nf_get_att_text
                                        
      integer(4) :: nf_put_att_int1
      external        nf_put_att_int1
                                        
      integer(4) :: nf_get_att_int1
      external        nf_get_att_int1
                                        
      integer(4) :: nf_put_att_int2
      external        nf_put_att_int2
                                        
      integer(4) :: nf_get_att_int2
      external        nf_get_att_int2
                                       
      integer(4) :: nf_put_att_int
      external        nf_put_att_int
                                       
      integer(4) :: nf_get_att_int
      external        nf_get_att_int
                                         
      integer(4) :: nf_put_att_int64
      external        nf_put_att_int64
                                         
      integer(4) :: nf_get_att_int64
      external        nf_get_att_int64
                                        
      integer(4) :: nf_put_att_real
      external        nf_put_att_real
                                        
      integer(4) :: nf_get_att_real
      external        nf_get_att_real
                                          
      integer(4) :: nf_put_att_double
      external        nf_put_att_double
                                          
      integer(4) :: nf_get_att_double
      external        nf_get_att_double
                                   
      integer(4) :: nf_def_var
      external        nf_def_var
                                   
      integer(4) :: nf_inq_var
      external        nf_inq_var
                                     
      integer(4) :: nf_inq_varid
      external        nf_inq_varid
                                       
      integer(4) :: nf_inq_varname
      external        nf_inq_varname
                                       
      integer(4) :: nf_inq_vartype
      external        nf_inq_vartype
                                        
      integer(4) :: nf_inq_varndims
      external        nf_inq_varndims
                                        
      integer(4) :: nf_inq_vardimid
      external        nf_inq_vardimid
                                        
      integer(4) :: nf_inq_varnatts
      external        nf_inq_varnatts
                                      
      integer(4) :: nf_rename_var
      external        nf_rename_var
                                    
      integer(4) :: nf_copy_var
      external        nf_copy_var
                                        
      integer(4) :: nf_put_var_text
      external        nf_put_var_text
                                        
      integer(4) :: nf_get_var_text
      external        nf_get_var_text
                                        
      integer(4) :: nf_put_var_int1
      external        nf_put_var_int1
                                        
      integer(4) :: nf_get_var_int1
      external        nf_get_var_int1
                                        
      integer(4) :: nf_put_var_int2
      external        nf_put_var_int2
                                        
      integer(4) :: nf_get_var_int2
      external        nf_get_var_int2
                                       
      integer(4) :: nf_put_var_int
      external        nf_put_var_int
                                       
      integer(4) :: nf_get_var_int
      external        nf_get_var_int
                                        
      integer(4) :: nf_put_var_real
      external        nf_put_var_real
                                        
      integer(4) :: nf_get_var_real
      external        nf_get_var_real
                                          
      integer(4) :: nf_put_var_double
      external        nf_put_var_double
                                          
      integer(4) :: nf_get_var_double
      external        nf_get_var_double
                                         
      integer(4) :: nf_put_var1_text
      external        nf_put_var1_text
                                         
      integer(4) :: nf_get_var1_text
      external        nf_get_var1_text
                                         
      integer(4) :: nf_put_var1_int1
      external        nf_put_var1_int1
                                         
      integer(4) :: nf_get_var1_int1
      external        nf_get_var1_int1
                                         
      integer(4) :: nf_put_var1_int2
      external        nf_put_var1_int2
                                         
      integer(4) :: nf_get_var1_int2
      external        nf_get_var1_int2
                                        
      integer(4) :: nf_put_var1_int
      external        nf_put_var1_int
                                        
      integer(4) :: nf_get_var1_int
      external        nf_get_var1_int
                                         
      integer(4) :: nf_put_var1_real
      external        nf_put_var1_real
                                         
      integer(4) :: nf_get_var1_real
      external        nf_get_var1_real
                                           
      integer(4) :: nf_put_var1_double
      external        nf_put_var1_double
                                           
      integer(4) :: nf_get_var1_double
      external        nf_get_var1_double
                                         
      integer(4) :: nf_put_vara_text
      external        nf_put_vara_text
                                         
      integer(4) :: nf_get_vara_text
      external        nf_get_vara_text
                                         
      integer(4) :: nf_put_vara_int1
      external        nf_put_vara_int1
                                         
      integer(4) :: nf_get_vara_int1
      external        nf_get_vara_int1
                                         
      integer(4) :: nf_put_vara_int2
      external        nf_put_vara_int2
                                         
      integer(4) :: nf_get_vara_int2
      external        nf_get_vara_int2
                                        
      integer(4) :: nf_put_vara_int
      external        nf_put_vara_int
                                        
      integer(4) :: nf_get_vara_int
      external        nf_get_vara_int
                                         
      integer(4) :: nf_put_vara_real
      external        nf_put_vara_real
                                         
      integer(4) :: nf_get_vara_real
      external        nf_get_vara_real
                                           
      integer(4) :: nf_put_vara_double
      external        nf_put_vara_double
                                           
      integer(4) :: nf_get_vara_double
      external        nf_get_vara_double
                                         
      integer(4) :: nf_put_vars_text
      external        nf_put_vars_text
                                         
      integer(4) :: nf_get_vars_text
      external        nf_get_vars_text
                                         
      integer(4) :: nf_put_vars_int1
      external        nf_put_vars_int1
                                         
      integer(4) :: nf_get_vars_int1
      external        nf_get_vars_int1
                                         
      integer(4) :: nf_put_vars_int2
      external        nf_put_vars_int2
                                         
      integer(4) :: nf_get_vars_int2
      external        nf_get_vars_int2
                                        
      integer(4) :: nf_put_vars_int
      external        nf_put_vars_int
                                        
      integer(4) :: nf_get_vars_int
      external        nf_get_vars_int
                                         
      integer(4) :: nf_put_vars_real
      external        nf_put_vars_real
                                         
      integer(4) :: nf_get_vars_real
      external        nf_get_vars_real
                                           
      integer(4) :: nf_put_vars_double
      external        nf_put_vars_double
                                           
      integer(4) :: nf_get_vars_double
      external        nf_get_vars_double
                                         
      integer(4) :: nf_put_varm_text
      external        nf_put_varm_text
                                         
      integer(4) :: nf_get_varm_text
      external        nf_get_varm_text
                                         
      integer(4) :: nf_put_varm_int1
      external        nf_put_varm_int1
                                         
      integer(4) :: nf_get_varm_int1
      external        nf_get_varm_int1
                                         
      integer(4) :: nf_put_varm_int2
      external        nf_put_varm_int2
                                         
      integer(4) :: nf_get_varm_int2
      external        nf_get_varm_int2
                                        
      integer(4) :: nf_put_varm_int
      external        nf_put_varm_int
                                        
      integer(4) :: nf_get_varm_int
      external        nf_get_varm_int
                                         
      integer(4) :: nf_put_varm_real
      external        nf_put_varm_real
                                         
      integer(4) :: nf_get_varm_real
      external        nf_get_varm_real
                                           
      integer(4) :: nf_put_varm_double
      external        nf_put_varm_double
                                           
      integer(4) :: nf_get_varm_double
      external        nf_get_varm_double
                                  
      integer(4) :: nf_put_var1_int64
      external nf_put_var1_int64
                                  
      integer(4) :: nf_put_vara_int64
      external nf_put_vara_int64
                                  
      integer(4) :: nf_put_vars_int64
      external nf_put_vars_int64
                                  
      integer(4) :: nf_put_varm_int64
      external nf_put_varm_int64
                                 
      integer(4) :: nf_put_var_int64
      external nf_put_var_int64
                                  
      integer(4) :: nf_get_var1_int64
      external nf_get_var1_int64
                                  
      integer(4) :: nf_get_vara_int64
      external nf_get_vara_int64
                                  
      integer(4) :: nf_get_vars_int64
      external nf_get_vars_int64
                                  
      integer(4) :: nf_get_varm_int64
      external nf_get_varm_int64
                                 
      integer(4) :: nf_get_var_int64
      external nf_get_var_int64
                          
                        
                          
                        
                            
                                

                              

                                

                              

                                  

                                        
                                         
                                     

                                        

                                  
                                       

                                          
                                               

                           
                                   

                                 
                                        

                             
                                  

                             
                                  

                               
                                    

                                 
                                      

                                 
                                      

                              
                                   

                           
                                

                              
                                   

                              
                                   

                              
                                   

                             
                                  

                           
                                

                                       
                                            

                                       
                                             

                         
                                 

                            
                                     

                           
                                    

                               
                                    

                              
                                   

                           
                                   

                             
                                     

                              
                                      

                               
                                       

                             
                                     

                            
                                    

                            
                                    

                            
                                    

                               
                                       

                              
                                      

                           
                                   

                              
                                      

                           
                                   

                          
                                  

                            
                                    

                             
                                     

                             
                                     

                               
                                       

                             
                                     

                             
                                     

                            
                                    

                             
                                     

                            
                                    

                             
                                     

                          
                                  

                              
      integer(4) :: nf_create_par
      external nf_create_par
                            
      integer(4) :: nf_open_par
      external nf_open_par
                                  
      integer(4) :: nf_var_par_access
      external nf_var_par_access
                            
      integer(4) :: nf_inq_ncid
      external nf_inq_ncid
                            
      integer(4) :: nf_inq_grps
      external nf_inq_grps
                               
      integer(4) :: nf_inq_grpname
      external nf_inq_grpname
                                    
      integer(4) :: nf_inq_grpname_full
      external nf_inq_grpname_full
                                   
      integer(4) :: nf_inq_grpname_len
      external nf_inq_grpname_len
                                  
      integer(4) :: nf_inq_grp_parent
      external nf_inq_grp_parent
                                
      integer(4) :: nf_inq_grp_ncid
      external nf_inq_grp_ncid
                                     
      integer(4) :: nf_inq_grp_full_ncid
      external nf_inq_grp_full_ncid
                              
      integer(4) :: nf_inq_varids
      external nf_inq_varids
                              
      integer(4) :: nf_inq_dimids
      external nf_inq_dimids
                           
      integer(4) :: nf_def_grp
      external nf_def_grp
                              
      integer(4) :: nf_rename_grp
      external nf_rename_grp
                                   
      integer(4) :: nf_def_var_deflate
      external nf_def_var_deflate
                                   
      integer(4) :: nf_inq_var_deflate
      external nf_inq_var_deflate
                                      
      integer(4) :: nf_def_var_fletcher32
      external nf_def_var_fletcher32
                                      
      integer(4) :: nf_inq_var_fletcher32
      external nf_inq_var_fletcher32
                                    
      integer(4) :: nf_def_var_chunking
      external nf_def_var_chunking
                                    
      integer(4) :: nf_inq_var_chunking
      external nf_inq_var_chunking
                                
      integer(4) :: nf_def_var_fill
      external nf_def_var_fill
                                
      integer(4) :: nf_inq_var_fill
      external nf_inq_var_fill
                                  
      integer(4) :: nf_def_var_endian
      external nf_def_var_endian
                                  
      integer(4) :: nf_inq_var_endian
      external nf_inq_var_endian
                                  
      integer(4) :: nf_def_var_filter
      external nf_def_var_filter
                                  
      integer(4) :: nf_inq_var_filter
      external nf_inq_var_filter
                               
      integer(4) :: nf_inq_typeids
      external nf_inq_typeids
                              
      integer(4) :: nf_inq_typeid
      external nf_inq_typeid
                            
      integer(4) :: nf_inq_type
      external nf_inq_type
                                 
      integer(4) :: nf_inq_user_type
      external nf_inq_user_type
                                
      integer(4) :: nf_def_compound
      external nf_def_compound
                                   
      integer(4) :: nf_insert_compound
      external nf_insert_compound
                                         
      integer(4) :: nf_insert_array_compound
      external nf_insert_array_compound
                                
      integer(4) :: nf_inq_compound
      external nf_inq_compound
                                     
      integer(4) :: nf_inq_compound_name
      external nf_inq_compound_name
                                     
      integer(4) :: nf_inq_compound_size
      external nf_inq_compound_size
                                        
      integer(4) :: nf_inq_compound_nfields
      external nf_inq_compound_nfields
                                      
      integer(4) :: nf_inq_compound_field
      external nf_inq_compound_field
                                          
      integer(4) :: nf_inq_compound_fieldname
      external nf_inq_compound_fieldname
                                           
      integer(4) :: nf_inq_compound_fieldindex
      external nf_inq_compound_fieldindex
                                            
      integer(4) :: nf_inq_compound_fieldoffset
      external nf_inq_compound_fieldoffset
                                          
      integer(4) :: nf_inq_compound_fieldtype
      external nf_inq_compound_fieldtype
                                           
      integer(4) :: nf_inq_compound_fieldndims
      external nf_inq_compound_fieldndims
                                               
      integer(4) :: nf_inq_compound_fielddim_sizes
      external nf_inq_compound_fielddim_sizes
                            
      integer(4) :: nf_def_vlen
      external nf_def_vlen
                            
      integer(4) :: nf_inq_vlen
      external nf_inq_vlen
                             
      integer(4) :: nf_free_vlen
      external nf_free_vlen
                            
      integer(4) :: nf_def_enum
      external nf_def_enum
                               
      integer(4) :: nf_insert_enum
      external nf_insert_enum
                            
      integer(4) :: nf_inq_enum
      external nf_inq_enum
                                   
      integer(4) :: nf_inq_enum_member
      external nf_inq_enum_member
                                  
      integer(4) :: nf_inq_enum_ident
      external nf_inq_enum_ident
                              
      integer(4) :: nf_def_opaque
      external nf_def_opaque
                              
      integer(4) :: nf_inq_opaque
      external nf_inq_opaque
                           
      integer(4) :: nf_put_att
      external nf_put_att
                           
      integer(4) :: nf_get_att
      external nf_get_att
                           
      integer(4) :: nf_put_var
      external nf_put_var
                            
      integer(4) :: nf_put_var1
      external nf_put_var1
                            
      integer(4) :: nf_put_vara
      external nf_put_vara
                            
      integer(4) :: nf_put_vars
      external nf_put_vars
                           
      integer(4) :: nf_get_var
      external nf_get_var
                            
      integer(4) :: nf_get_var1
      external nf_get_var1
                            
      integer(4) :: nf_get_vara
      external nf_get_vara
                            
      integer(4) :: nf_get_vars
      external nf_get_vars
                                    
      integer(4) :: nf_get_vlen_element
      external nf_get_vlen_element
                                    
      integer(4) :: nf_put_vlen_element
      external nf_put_vlen_element
                                   
      integer(4) :: nf_set_chunk_cache
      external nf_set_chunk_cache
                                   
      integer(4) :: nf_get_chunk_cache
      external nf_get_chunk_cache
                                       
      integer(4) :: nf_set_var_chunk_cache
      external nf_set_var_chunk_cache
                                       
      integer(4) :: nf_get_var_chunk_cache
      external nf_get_var_chunk_cache
                      
      integer(4) :: nccre
                      
      integer(4) :: ncopn
                       
      integer(4) :: ncddef
                      
      integer(4) :: ncdid
                       
      integer(4) :: ncvdef
                      
      integer(4) :: ncvid
                       
      integer(4) :: nctlen
                       
      integer(4) :: ncsfil
      external nccre
      external ncopn
      external ncddef
      external ncdid
      external ncvdef
      external ncvid
      external nctlen
      external ncsfil
                       
                        
                       
                        
                        
                        
                         
                         
                       
                         
                        
                       
                         
                         
                       
                         
                        
                         
                         
                         
                         
                         
                        
                         
                         
                         
                         
                        
                         
                         
                         
                         
                        
                         
                         
                         
                        
                       
                         
                         
                         
                        
                         
                         
                         
                        
                         
                         
                       
                       
                        
                       
                        
                         
                           

                           

                            

                           

                            

                             

                           

                            

                           

                            

                             

                             

                              

                               

                           

                               

                               

                             

                                 

                                    

                                        

                        
                            

                              

                             

                                

                                

                                

                               

                                    

                                   

                                     

                               

                                     

                                     

                                   

                                            

                                        

                                           

                                       

                                        

                                      

                                       

                                       

                                     

                                        

                                       

                                      

                                     

                                     

                                 

                                        

                              

                               

                            

                             

                        
                        
                         
                        
                    
                              
                                

                             

                                   

                                       

                                                   

                                                  

                                 
      integer(4) :: nf_set_log_level
      external nf_set_log_level
                           
                                    
                       
                                             
                                                                       
                                                                 
         
                     
                                          
                                                                       
                                                                       
                                                                 
                                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                   
                                                  
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                  
                                                  
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
               
      real :: cff
                                                        
      integer(4) :: lstr
      integer(4) :: lvar
      integer(4) :: lenstr
      integer(4) :: ierr
      integer(4) :: ierr_all
      integer(4) :: itrc
                                                
      integer(4) :: nf_read_bry_EW
      integer(4) :: nf_read_bry_NS
      ierr=nf_noerr
      lstr=lenstr(bry_file)
      if (iic.eq.0 ) then
        if (bry_id.eq.-1) then
          ierr=nf_open (bry_file(1:lstr), nf_nowrite, bry_id)
          if (ierr.ne.nf_noerr) write(stdout,'(/1x,4A/)') 'ERROR ',
     &               'in get_all_bry: can not open netCDF file ''',
     &                                   bry_file(1:lstr),   '''.'
        endif
        if (ierr.eq.nf_noerr) then
          ierr_all=0
          ierr=nf_inq_varid (bry_id, 'bry_time',  bry_time_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'bry_time'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'zeta_west', zetabry_west_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'zeta_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'ubar_west', ubarbry_west_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'ubar_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'vbar_west', vbarbry_west_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'vbar_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'u_west', ubry_west_id)
          if (ierr.ne.nf_noerr)  write(stdout,1) 'u_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'v_west', vbry_west_id)
          if (ierr.ne.nf_noerr)  write(stdout,1) 'v_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'temp_west',
     &         tbry_west_id(itemp))
          if (ierr.ne.nf_noerr) write(stdout,1) 'temp_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'salt_west',
     &         tbry_west_id(isalt))
          if (ierr.ne.nf_noerr) write(stdout,1) 'salt_west'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'zeta_east', zetabry_east_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'zeta_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'ubar_east', ubarbry_east_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'ubar_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'vbar_east', vbarbry_east_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'vbar_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'u_east',   ubry_east_id)
          if (ierr.ne.nf_noerr)  write(stdout,1)   'u_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'v_east',   vbry_east_id)
          if (ierr.ne.nf_noerr)  write(stdout,1)   'v_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'temp_east',
     &         tbry_east_id(itemp))
          if (ierr.ne.nf_noerr) write(stdout,1) 'temp_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'salt_east',
     &         tbry_east_id(isalt))
          if (ierr.ne.nf_noerr) write(stdout,1) 'salt_east'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'zeta_south', zetabry_south_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'zeta_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'ubar_south', ubarbry_south_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'ubar_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'vbar_south', vbarbry_south_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'vbar_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'u_south',  ubry_south_id)
          if (ierr.ne.nf_noerr) write(stdout,1)    'u_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'v_south',  vbry_south_id)
          if (ierr.ne.nf_noerr) write(stdout,1)    'v_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'temp_south',
     &         tbry_south_id(itemp))
          if (ierr.ne.nf_noerr) write(stdout,1) 'temp_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'salt_south',
     &         tbry_south_id(isalt))
          if (ierr.ne.nf_noerr) write(stdout,1) 'salt_south'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'zeta_north', zetabry_north_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'zeta_north'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'ubar_north', ubarbry_north_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'ubar_north'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'vbar_north', vbarbry_north_id)
          if (ierr.ne.nf_noerr) write(stdout,1) 'vbar_north'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'u_north',  ubry_north_id)
          if (ierr.ne.nf_noerr) write(stdout,1)    'u_north'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id,    'v_north',  vbry_north_id)
          if (ierr.ne.nf_noerr)   write(stdout,1)  'v_north'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'temp_north',
     &         tbry_north_id(itemp))
          if (ierr.ne.nf_noerr) write(stdout,1) 'temp_north'
          ierr_all=ierr_all+ierr
          ierr=nf_inq_varid (bry_id, 'salt_north',
     &         tbry_north_id(isalt))
          if (ierr.ne.nf_noerr) write(stdout,1) 'salt_north'
          ierr_all=ierr_all+ierr
          ierr=ierr_all
          if (ierr.eq.nf_noerr) then
            call set_cycle (bry_id, bry_time_id, ntbry,
     &           bry_cycle, bry_ncycle, bry_rec)
            itbry=1
            bry_time(1)=-1.D+20
            bry_time(2)=-1.D+20
          else
            write(stdout,'(8x,4A)') 'ERROR(s) occur while examining',
     &          ' content of netCDF file ''', bry_file(1:lstr), '''.'
          endif
        endif
      endif
  1   format(' ERROR in get_all_bry: cannot find variable ''',A,'''')
      do while (bry_time(itbry).lt.time+.5D0*dt .and. ierr.eq.nf_noerr)
        call advance_cycle (bry_cycle,ntbry,bry_ncycle,bry_rec)
        if (ierr.eq.nf_noerr) then
          ierr=nf_get_var1_double (bry_id, bry_time_id, bry_rec, cff)
          if (ierr.eq.nf_noerr) then
            itbry=min(3-itbry,ntbry)
            bry_time(itbry)=cff*day2sec + bry_cycle*bry_ncycle
            ierr_all=0
            ierr=nf_read_bry_EW (zetabry_west_dt(-1,itbry
     &          ), bry_id,zetabry_west_id, bry_rec, r2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'zeta_west'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (ubarbry_west_dt(-1,itbry
     &          ), bry_id,ubarbry_west_id, bry_rec, u2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'ubar_west'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (vbarbry_west_dt(-1,itbry
     &          ), bry_id,vbarbry_west_id, bry_rec, v2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'vbar_west'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (ubry_west_dt(-1,1,itbry)
     &          , bry_id,ubry_west_id,  bry_rec,  u3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'u_west'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (vbry_west_dt(-1,1,itbry)
     &          , bry_id,vbry_west_id,  bry_rec,  v3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'v_west'
            ierr_all=ierr_all+ierr
            do itrc=1,1+ntrc_salt
              ierr=nf_read_bry_EW (tbry_west_dt(-1,1
     &            ,itbry,itrc),bry_id,tbry_west_id(itrc),  bry_rec,
     &            r3dvar)
              if (ierr.ne.nf_noerr)  write(stdout,2)  'trc_west'
              ierr_all=ierr_all+ierr
            enddo
            ierr=nf_read_bry_EW (zetabry_east_dt(-1,itbry
     &          ), bry_id,zetabry_east_id, bry_rec, r2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'zeta_east'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (ubarbry_east_dt(-1,itbry
     &          ), bry_id,ubarbry_east_id, bry_rec, u2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'ubar_east'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (vbarbry_east_dt(-1,itbry
     &          ), bry_id,vbarbry_east_id, bry_rec, v2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'vbar_east'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (ubry_east_dt(-1,1,itbry)
     &          , bry_id,ubry_east_id,  bry_rec,  u3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'u_east'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_EW (vbry_east_dt(-1,1,itbry)
     &          , bry_id,vbry_east_id,  bry_rec,  v3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'v_east'
            ierr_all=ierr_all+ierr
            do itrc=1,1+ntrc_salt
              ierr=nf_read_bry_EW (tbry_east_dt(-1,1
     &            ,itbry,itrc),bry_id,tbry_east_id(itrc),  bry_rec,
     &            r3dvar)
              if (ierr.ne.nf_noerr)  write(stdout,2)  'trc_east'
              ierr_all=ierr_all+ierr
            enddo
            ierr=nf_read_bry_NS (zetabry_south_dt(-1,itbry
     &          ), bry_id,zetabry_south_id, bry_rec,  r2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'zeta_south'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (ubarbry_south_dt(-1,itbry
     &          ), bry_id,ubarbry_south_id, bry_rec, u2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'ubar_south'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (vbarbry_south_dt(-1,itbry
     &          ), bry_id,vbarbry_south_id, bry_rec, v2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'vbar_south'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (ubry_south_dt(-1,1,itbry)
     &          , bry_id,ubry_south_id,  bry_rec,  u3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'u_south'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (vbry_south_dt(-1,1,itbry)
     &          , bry_id,vbry_south_id,  bry_rec,  v3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'v_south'
            ierr_all=ierr_all+ierr
            do itrc=1,1+ntrc_salt
              ierr=nf_read_bry_NS (tbry_south_dt(-1,1
     &            ,itbry,itrc),bry_id,tbry_south_id(itrc),  bry_rec,
     &            r3dvar)
              if (ierr.ne.nf_noerr) write(stdout,2) 'trc_south'
              ierr_all=ierr_all+ierr
            enddo
            ierr=nf_read_bry_NS (zetabry_north_dt(-1,itbry
     &          ), bry_id,zetabry_north_id, bry_rec, r2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'zeta_north'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (ubarbry_north_dt(-1,itbry
     &          ), bry_id,ubarbry_north_id, bry_rec, u2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'ubar_north'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (vbarbry_north_dt(-1,itbry
     &          ), bry_id,vbarbry_north_id, bry_rec, v2dvar)
            if (ierr.ne.nf_noerr) write(stdout,2) 'vbar_north'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (ubry_north_dt(-1,1,itbry)
     &          , bry_id,ubry_north_id,  bry_rec,  u3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'u_north'
            ierr_all=ierr_all+ierr
            ierr=nf_read_bry_NS (vbry_north_dt(-1,1,itbry)
     &          , bry_id,vbry_north_id,  bry_rec,  v3dvar)
            if (ierr.ne.nf_noerr)  write(stdout,2)  'v_north'
            ierr_all=ierr_all+ierr
            do itrc=1,1+ntrc_salt
              ierr=nf_read_bry_NS (tbry_north_dt(-1,1
     &            ,itbry,itrc),bry_id,tbry_north_id(itrc),  bry_rec,
     &            r3dvar)
              if (ierr.ne.nf_noerr)  write(stdout,2)  'trc_north'
              ierr_all=ierr_all+ierr
            enddo
            ierr=ierr_all
            if (ierr.eq.0) then
              if (mynode.eq.0) write(stdout,'(6x,A,9x,A,1x,F10.4,1x,
     &                                                             I4)')
     &       'GET_BRY    -- Read all boundary data',
     &                                 'for time =', cff
     &                                             , mynode
            else
              if (mynode.eq.0) write(stdout,'(1x,2A,I4/8x,3A)')
     &           'ERROR(s) occur while trying to read record ',
     &            bry_rec,  'in file ''',bry_file(1:lstr),'''.'
            endif
          else
            if (mynode.eq.0) write(stdout,2) 'bry_time'
          endif
        else
         if (mynode.eq.0) write(stdout,
     &    '(/1x,A,I4,1x,A,I4/7x,4A/7x,2(A,G12.4)/)')
     &    'ERROR in get_bry_all: requested time record ',  bry_rec,
     &    'exceeds the last record', ntbry,  'available in netCDF ',
     &    'file ''',   bry_file(1:lstr),  '''',  'tdays = ', tdays,
     &    '  but the last available  bry_time =',
     &                                   bry_time(itbry)*sec2day
        endif
      enddo
  2   format(' ERROR in get_bry: cannot read variable ''',A,'''')
      if (ierr.ne.nf_noerr) may_day_flag=2
      return
       
      

      end subroutine Sub_Loop_get_bry

      subroutine set_bry (tile)      


      use Agrif_Util
      interface
        subroutine Sub_Loop_set_bry(tile,Mmmpi,Lmmpi)
          implicit none
      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      integer(4) :: Mmmpi
      integer(4) :: Lmmpi
      integer(4) :: tile
        end subroutine Sub_Loop_set_bry

      end interface
      integer(4) :: tile
      

        call Sub_Loop_set_bry(tile, Agrif_tabvars_i(8)%iarray0, Agrif_ta
     &bvars_i(7)%iarray0)

      end


      subroutine Sub_Loop_set_bry(tile,Mmmpi,Lmmpi)

      use Agrif_Types, only : Agrif_tabvars

      implicit none

      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      integer(4) :: Mmmpi
      integer(4) :: Lmmpi
      integer(4) :: tile

                   

                     
                                            
                             
                                            

                                                             
                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                                          
                                             
                          

                        

                                          
                        

                                                        
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

                                                            
      integer(4) :: chunk_size_X
      integer(4) :: margin_X
      integer(4) :: chunk_size_E
      integer(4) :: margin_E
                                             
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      integer(4) :: i_X
      integer(4) :: j_E
      chunk_size_X=(Lmmpi+NSUB_X-1)/NSUB_X
      margin_X=(NSUB_X*chunk_size_X-Lmmpi)/2
      chunk_size_E=(Mmmpi+NSUB_E-1)/NSUB_E
      margin_E=(NSUB_E*chunk_size_E-Mmmpi)/2
      j_E=tile/NSUB_X
      i_X=tile-j_E*NSUB_X
      Istr=1+i_X*chunk_size_X-margin_X
      Iend=Istr+chunk_size_X-1
      Istr=max(Istr,1)
      Iend=min(Iend,Lmmpi)
      Jstr=1+j_E*chunk_size_E-margin_E
      Jend=Jstr+chunk_size_E-1
      Jstr=max(Jstr,1)
      Jend=min(Jend,Mmmpi)
      call set_bry_tile (Istr,Iend,Jstr,Jend)
      return
       
      

      end subroutine Sub_Loop_set_bry

      subroutine set_bry_tile (Istr,Iend,Jstr,Jend)      


      use Agrif_Util
      interface
        subroutine Sub_Loop_set_bry_tile(Istr,Iend,Jstr,Jend,padd_E,Mm,p
     &add_X,Lm,may_day_flag,tdays,mynode,tbry_north_dt,tbry_north,vbry_n
     &orth_dt,vbry_north,ubry_north_dt,ubry_north,vbarbry_north_dt,vbarb
     &ry_north,ubarbry_north_dt,ubarbry_north,zetabry_north_dt,zetabry_n
     &orth,tbry_south_dt,tbry_south,vbry_south_dt,vbry_south,ubry_south_
     &dt,ubry_south,vbarbry_south_dt,vbarbry_south,ubarbry_south_dt,ubar
     &bry_south,zetabry_south_dt,zetabry_south,tbry_east_dt,tbry_east,vb
     &ry_east_dt,vbry_east,ubry_east_dt,ubry_east,vbarbry_east_dt,vbarbr
     &y_east,ubarbry_east_dt,ubarbry_east,zetabry_east_dt,zetabry_east,t
     &bry_west_dt,tbry_west,vbry_west_dt,vbry_west,ubry_west_dt,ubry_wes
     &t,vbarbry_west_dt,vbarbry_west,ubarbry_west_dt,ubarbry_west,zetabr
     &y_west_dt,zetabry_west,synchro_flag,bry_time,dt,time,itbry,NORTH_I
     &NTER,Mmmpi,SOUTH_INTER,EAST_INTER,Lmmpi,WEST_INTER)
          implicit none
      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: may_day_flag
      real :: tdays
      integer(4) :: mynode
      logical :: synchro_flag
      real :: dt
      real :: time
      integer(4) :: itbry
      logical :: NORTH_INTER
      integer(4) :: Mmmpi
      logical :: SOUTH_INTER
      logical :: EAST_INTER
      integer(4) :: Lmmpi
      logical :: WEST_INTER
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:NT) :: tbry_north
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: vbry_north
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: ubry_north
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_north_dt
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_north
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_north_dt
      real, dimension(-1:Lm+2+padd_X) :: ubarbry_north
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_north_dt
      real, dimension(-1:Lm+2+padd_X) :: zetabry_north
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:NT) :: tbry_south
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: vbry_south
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: ubry_south
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_south_dt
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_south
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_south_dt
      real, dimension(-1:Lm+2+padd_X) :: ubarbry_south
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_south_dt
      real, dimension(-1:Lm+2+padd_X) :: zetabry_south
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:NT) :: tbry_east
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: vbry_east
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: ubry_east
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_east_dt
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_east
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_east_dt
      real, dimension(-1:Mm+2+padd_E) :: ubarbry_east
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_east_dt
      real, dimension(-1:Mm+2+padd_E) :: zetabry_east
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:NT) :: tbry_west
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: vbry_west
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: ubry_west
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_west_dt
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_west
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_west_dt
      real, dimension(-1:Mm+2+padd_E) :: ubarbry_west
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_west_dt
      real, dimension(-1:Mm+2+padd_E) :: zetabry_west
      real, dimension(1:2) :: bry_time
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
        end subroutine Sub_Loop_set_bry_tile

      end interface
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend
      

        call Sub_Loop_set_bry_tile(Istr,Iend,Jstr,Jend, Agrif_tabvars_i(
     &14)%iarray0, Agrif_tabvars_i(4)%iarray0, Agrif_tabvars_i(13)%iarra
     &y0, Agrif_tabvars_i(2)%iarray0, Agrif_tabvars_i(167)%iarray0, Agri
     &f_tabvars_r(8)%array0, Agrif_tabvars_i(176)%iarray0, Agrif_tabvars
     &(162)%array4, Agrif_tabvars(163)%array3, Agrif_tabvars(164)%array3
     &, Agrif_tabvars(165)%array2, Agrif_tabvars(166)%array3, Agrif_tabv
     &ars(167)%array2, Agrif_tabvars(168)%array2, Agrif_tabvars(169)%arr
     &ay1, Agrif_tabvars(170)%array2, Agrif_tabvars(171)%array1, Agrif_t
     &abvars(172)%array2, Agrif_tabvars(173)%array1, Agrif_tabvars(174)%
     &array4, Agrif_tabvars(175)%array3, Agrif_tabvars(176)%array3, Agri
     &f_tabvars(177)%array2, Agrif_tabvars(178)%array3, Agrif_tabvars(17
     &9)%array2, Agrif_tabvars(180)%array2, Agrif_tabvars(181)%array1, A
     &grif_tabvars(182)%array2, Agrif_tabvars(183)%array1, Agrif_tabvars
     &(184)%array2, Agrif_tabvars(185)%array1, Agrif_tabvars(186)%array4
     &, Agrif_tabvars(187)%array3, Agrif_tabvars(188)%array3, Agrif_tabv
     &ars(189)%array2, Agrif_tabvars(190)%array3, Agrif_tabvars(191)%arr
     &ay2, Agrif_tabvars(192)%array2, Agrif_tabvars(193)%array1, Agrif_t
     &abvars(194)%array2, Agrif_tabvars(195)%array1, Agrif_tabvars(196)%
     &array2, Agrif_tabvars(197)%array1, Agrif_tabvars(198)%array4, Agri
     &f_tabvars(199)%array3, Agrif_tabvars(200)%array3, Agrif_tabvars(20
     &1)%array2, Agrif_tabvars(202)%array3, Agrif_tabvars(203)%array2, A
     &grif_tabvars(204)%array2, Agrif_tabvars(205)%array1, Agrif_tabvars
     &(206)%array2, Agrif_tabvars(207)%array1, Agrif_tabvars(208)%array2
     &, Agrif_tabvars(209)%array1, Agrif_tabvars_l(6)%larray0, Agrif_tab
     &vars(210)%array1, Agrif_tabvars_r(3)%array0, Agrif_tabvars_r(5)%ar
     &ray0, Agrif_tabvars_i(271)%iarray0, Agrif_tabvars_l(13)%larray0, A
     &grif_tabvars_i(8)%iarray0, Agrif_tabvars_l(14)%larray0, Agrif_tabv
     &ars_l(11)%larray0, Agrif_tabvars_i(7)%iarray0, Agrif_tabvars_l(12)
     &%larray0)

      end


      subroutine Sub_Loop_set_bry_tile(Istr,Iend,Jstr,Jend,padd_E,Mm,pad
     &d_X,Lm,may_day_flag,tdays,mynode,tbry_north_dt,tbry_north,vbry_nor
     &th_dt,vbry_north,ubry_north_dt,ubry_north,vbarbry_north_dt,vbarbry
     &_north,ubarbry_north_dt,ubarbry_north,zetabry_north_dt,zetabry_nor
     &th,tbry_south_dt,tbry_south,vbry_south_dt,vbry_south,ubry_south_dt
     &,ubry_south,vbarbry_south_dt,vbarbry_south,ubarbry_south_dt,ubarbr
     &y_south,zetabry_south_dt,zetabry_south,tbry_east_dt,tbry_east,vbry
     &_east_dt,vbry_east,ubry_east_dt,ubry_east,vbarbry_east_dt,vbarbry_
     &east,ubarbry_east_dt,ubarbry_east,zetabry_east_dt,zetabry_east,tbr
     &y_west_dt,tbry_west,vbry_west_dt,vbry_west,ubry_west_dt,ubry_west,
     &vbarbry_west_dt,vbarbry_west,ubarbry_west_dt,ubarbry_west,zetabry_
     &west_dt,zetabry_west,synchro_flag,bry_time,dt,time,itbry,NORTH_INT
     &ER,Mmmpi,SOUTH_INTER,EAST_INTER,Lmmpi,WEST_INTER)

      use Agrif_Types, only : Agrif_tabvars

      implicit none

      integer(4), parameter :: LLm0 = 41
      integer(4), parameter :: MMm0 = 42
      integer(4), parameter :: N = 32
      integer(4), parameter :: NP_XI = 1
      integer(4), parameter :: NP_ETA = 4
      integer(4), parameter :: NNODES = NP_XI*NP_ETA
      integer(4), parameter :: NPP = 1
      integer(4), parameter :: NSUB_X = 1
      integer(4), parameter :: NSUB_E = 1
      integer(4), parameter :: NWEIGHT = 1000
      integer(4), parameter :: stdout = 6
      integer(4), parameter :: Np = N+1
      integer(4), parameter :: NSA = 28
      real, parameter :: Vtransform = 2
      integer(4), parameter :: itemp = 1
      integer(4), parameter :: ntrc_temp = 1
      integer(4), parameter :: ntrc_salt = 1
      integer(4), parameter :: ntrc_pas = 0
      integer(4), parameter :: ntrc_bio = 0
      integer(4), parameter :: ntrc_subs = 0
      integer(4), parameter :: ntrc_substot = 0
      integer(4), parameter :: ntrc_sed = 0
      integer(4), parameter :: NTA = itemp+ntrc_salt
      integer(4), parameter :: NT = itemp+ntrc_salt+ntrc_pas+ntrc_bio+nt
     &rc_sed
      integer(4), parameter :: NTot = NT
      integer(4), parameter :: isalt = itemp+1
      integer(4), parameter :: ntrc_diabio = 0
      integer(4), parameter :: ntrc_diats = 0
      integer(4), parameter :: ntrc_diauv = 0
      integer(4), parameter :: ntrc_diavrt = 0
      integer(4), parameter :: ntrc_diaek = 0
      integer(4), parameter :: ntrc_diapv = 0
      integer(4), parameter :: ntrc_diaeddy = 0
      integer(4), parameter :: ntrc_surf = 0
      real, parameter :: pi = 3.14159265358979323846D0
      real, parameter :: deg2rad = pi/180.D0
      real, parameter :: rad2deg = 180.D0/pi
      real, parameter :: Eradius = 6371315.0D0
      real, parameter :: Erotation = 7.292115090D-5
      real, parameter :: day2sec = 86400.D0
      real, parameter :: sec2day = 1.D0/86400.D0
      real, parameter :: year2day = 365.25D0
      real, parameter :: day2year = 1.D0/365.25D0
      real, parameter :: jul_off = 2440000.D0
      real, parameter :: g = 9.81D0
      real, parameter :: Cp = 3985.0D0
      real, parameter :: vonKar = 0.41D0
      real, parameter :: spval = -999.0D0
      logical, parameter :: mask_val = .true.
      integer(4) :: padd_E
      integer(4) :: Mm
      integer(4) :: padd_X
      integer(4) :: Lm
      integer(4) :: may_day_flag
      real :: tdays
      integer(4) :: mynode
      logical :: synchro_flag
      real :: dt
      real :: time
      integer(4) :: itbry
      logical :: NORTH_INTER
      integer(4) :: Mmmpi
      logical :: SOUTH_INTER
      logical :: EAST_INTER
      integer(4) :: Lmmpi
      logical :: WEST_INTER
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:NT) :: tbry_north
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: vbry_north
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_north_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: ubry_north
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_north_dt
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_north
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_north_dt
      real, dimension(-1:Lm+2+padd_X) :: ubarbry_north
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_north_dt
      real, dimension(-1:Lm+2+padd_X) :: zetabry_north
      real, dimension(-1:Lm+2+padd_X,1:N,1:2,1:NT) :: tbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N,1:NT) :: tbry_south
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: vbry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: vbry_south
      real, dimension(-1:Lm+2+padd_X,1:N,1:2) :: ubry_south_dt
      real, dimension(-1:Lm+2+padd_X,1:N) :: ubry_south
      real, dimension(-1:Lm+2+padd_X,1:2) :: vbarbry_south_dt
      real, dimension(-1:Lm+2+padd_X) :: vbarbry_south
      real, dimension(-1:Lm+2+padd_X,1:2) :: ubarbry_south_dt
      real, dimension(-1:Lm+2+padd_X) :: ubarbry_south
      real, dimension(-1:Lm+2+padd_X,1:2) :: zetabry_south_dt
      real, dimension(-1:Lm+2+padd_X) :: zetabry_south
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:NT) :: tbry_east
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: vbry_east
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_east_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: ubry_east
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_east_dt
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_east
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_east_dt
      real, dimension(-1:Mm+2+padd_E) :: ubarbry_east
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_east_dt
      real, dimension(-1:Mm+2+padd_E) :: zetabry_east
      real, dimension(-1:Mm+2+padd_E,1:N,1:2,1:NT) :: tbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N,1:NT) :: tbry_west
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: vbry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: vbry_west
      real, dimension(-1:Mm+2+padd_E,1:N,1:2) :: ubry_west_dt
      real, dimension(-1:Mm+2+padd_E,1:N) :: ubry_west
      real, dimension(-1:Mm+2+padd_E,1:2) :: vbarbry_west_dt
      real, dimension(-1:Mm+2+padd_E) :: vbarbry_west
      real, dimension(-1:Mm+2+padd_E,1:2) :: ubarbry_west_dt
      real, dimension(-1:Mm+2+padd_E) :: ubarbry_west
      real, dimension(-1:Mm+2+padd_E,1:2) :: zetabry_west_dt
      real, dimension(-1:Mm+2+padd_E) :: zetabry_west
      real, dimension(1:2) :: bry_time
      integer(4) :: Istr
      integer(4) :: Iend
      integer(4) :: Jstr
      integer(4) :: Jend

                   

                                                          
      integer(4) :: i
      integer(4) :: j
      integer(4) :: k
      integer(4) :: it1
      integer(4) :: it2
      integer(4) :: itrc
                          
      real :: cff
      real :: cff1
      real :: cff2
                                            
                             
                                            

                                                             
                                                            
                                           
                                                               
                                    
                                      
                                                          

                       

                                    

                        
                              

                                          
                                             
                          

                        

                                          
                        

                                                        
                      
                              

                                       
                                                                     
                                          
                         

                             

                             

                            

                            

                                             

                            

                                     

                                                               

                         

                                                      
                                                      
                                                                  
                               

                               

                              

                              

                               

                              

                              

                                

                             

                                            
                                               
                                            
                                               
                                                                 
                                                 
                                 
                                               
                                               
                                               
                                               
                                               
                                               
                                             
                                             
                                             
                                             
                                             
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                               
                                              
                                                  
                                                  
                                                  
                                                  
                                                 
                                                 
                                               
                                               
                                                      
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                           
                                                           
                                                           
                                    
                                                
                                                
                                                
                                                
                                                 
                           
                           
                           
                           
                             
                                              
                          
                                                                  
                                                                       
                                                                 
                                 
                                
                                                                       
                                                                 
                                                                 
                                                                 
                                                        
                                                                       
                                                                 
                                                                 
            
                                              
                                                   
                     
                              
                               
                                 
                                                  
                                                                       
                                                                 
                                                                 
                        
                      
                           
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                                 
                                                    
                           
                                      
                             
                                                 
                                                                       
                                                                 
                     
                                                      
                                                                       
                                                                 
              
                                          
                                                                       
                                                                 
       
                                                           
      real(8) :: Cu_Nbq_X
      real(8) :: Cu_Nbq_Y
      real(8) :: Cu_Nbq_Z
                                             
                                                                       
                                                                 
              
                                                  
                                                                       
                                                                 
              
                                  
                                           
                                                  
                                                                   
                                                               
                                                      
                                                                       
                                                                 
                      
                                                                       
                                                                 
                                                                 
                                                                 
                                                                 
                                                        
                                
                                                                       
                                                                 
                                                        

                                                                       
                                                                 
                  
                                                                       
                                                                 
                                                                 
                                                                 
                  

                          

              
                             

                  
                               

                 
                                

                       
                                   

                           
                                    
                       
                                             
                                                                       
                                                                 
         
                     
                                          
                                                                       
                                                                       
                                                                 
                                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                
                                            
                                                 
                                                             
                                           
                                                    
                                 
                                      
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                 
                                              
                                                   
                                                                
                                             
                                                       
                                  
                                        
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                   
                                                  
                                                                       
                                                                 
              
                                                           
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                                
                                                                       
                                                                 
                                                                 
                              
                                                                       
                                                                 
                              
                                                                       
                                                                 
                  
                                                  
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                                                       
                                                                 
                
                                                              
                                                                       
                                                                 
                                                                 
                                      
                                                                       
                                                                 
                                                      
                                                                       
                                                                 
                                                                 
                                  
                                                                       
                                                                 
                                    
                                                                       
                                                                 
                    
                                                     
                                        
      integer(4) :: IstrR
      integer(4) :: IendR
      integer(4) :: JstrR
      integer(4) :: JendR
      if (Istr.eq.1) then
        if (WEST_INTER) then
          IstrR=Istr-2
        else
          IstrR=Istr-1
        endif
      else
        IstrR=Istr
      endif
      if (Iend.eq.Lmmpi) then
        if (EAST_INTER) then
          IendR=Iend+2
        else
          IendR=Iend+1
        endif
      else
        IendR=Iend
      endif
      if (Jstr.eq.1) then
        if (SOUTH_INTER) then
          JstrR=Jstr-2
        else
          JstrR=Jstr-1
        endif
      else
        JstrR=Jstr
      endif
      if (Jend.eq.Mmmpi) then
        if (NORTH_INTER) then
          JendR=Jend+2
        else
          JendR=Jend+1
        endif
      else
        JendR=Jend
      endif
      it1=3-itbry
      it2=itbry
      cff=time+0.5D0*dt
      cff1=bry_time(it2)-cff
      cff2=cff-bry_time(it1)
      if (Istr+Jstr.eq.2 .and. cff1.lt.dt) synchro_flag=.true.
      if (cff1.ge.0.D0 .and. cff2.ge.0.D0) then
        cff=1.D0/(cff1+cff2)
        cff1=cff1*cff
        cff2=cff2*cff
        if (.not.WEST_INTER) then
          do j=JstrR,JendR
            zetabry_west(j)=cff1*zetabry_west_dt(j,it1)
     &                     +cff2*zetabry_west_dt(j,it2)
          enddo
          do j=JstrR,JendR
            ubarbry_west(j)=cff1*ubarbry_west_dt(j,it1)
     &                     +cff2*ubarbry_west_dt(j,it2)
            vbarbry_west(j)=cff1*vbarbry_west_dt(j,it1)
     &                     +cff2*vbarbry_west_dt(j,it2)
          enddo
          do k=1,N
            do j=JstrR,JendR
              ubry_west(j,k)=cff1*ubry_west_dt(j,k,it1)
     &                      +cff2*ubry_west_dt(j,k,it2)
              vbry_west(j,k)=cff1*vbry_west_dt(j,k,it1)
     &                      +cff2*vbry_west_dt(j,k,it2)
            enddo
          enddo
          do itrc=1,1+ntrc_salt
            do k=1,N
              do j=JstrR,JendR
                tbry_west(j,k,itrc)=cff1*tbry_west_dt(j,k,it1,itrc)
     &                             +cff2*tbry_west_dt(j,k,it2,itrc)
              enddo
            enddo
          enddo
        endif
        if (.not.EAST_INTER) then
          do j=JstrR,JendR
            zetabry_east(j)=cff1*zetabry_east_dt(j,it1)
     &                     +cff2*zetabry_east_dt(j,it2)
          enddo
          do j=JstrR,JendR
            ubarbry_east(j)=cff1*ubarbry_east_dt(j,it1)
     &                     +cff2*ubarbry_east_dt(j,it2)
            vbarbry_east(j)=cff1*vbarbry_east_dt(j,it1)
     &                     +cff2*vbarbry_east_dt(j,it2)
          enddo
          do k=1,N
            do j=JstrR,JendR
              ubry_east(j,k)=cff1*ubry_east_dt(j,k,it1)
     &                      +cff2*ubry_east_dt(j,k,it2)
              vbry_east(j,k)=cff1*vbry_east_dt(j,k,it1)
     &                      +cff2*vbry_east_dt(j,k,it2)
            enddo
          enddo
          do itrc=1,1+ntrc_salt
            do k=1,N
              do j=JstrR,JendR
                tbry_east(j,k,itrc)=cff1*tbry_east_dt(j,k,it1,itrc)
     &                             +cff2*tbry_east_dt(j,k,it2,itrc)
              enddo
            enddo
          enddo
        endif
        if (.not.SOUTH_INTER) then
          do i=IstrR,IendR
            zetabry_south(i)=cff1*zetabry_south_dt(i,it1)
     &                      +cff2*zetabry_south_dt(i,it2)
          enddo
          do i=IstrR,IendR
            ubarbry_south(i)=cff1*ubarbry_south_dt(i,it1)
     &                      +cff2*ubarbry_south_dt(i,it2)
            vbarbry_south(i)=cff1*vbarbry_south_dt(i,it1)
     &                      +cff2*vbarbry_south_dt(i,it2)
          enddo
          do k=1,N
            do i=IstrR,IendR
              ubry_south(i,k)=cff1*ubry_south_dt(i,k,it1)
     &                       +cff2*ubry_south_dt(i,k,it2)
              vbry_south(i,k)=cff1*vbry_south_dt(i,k,it1)
     &                       +cff2*vbry_south_dt(i,k,it2)
            enddo
          enddo
          do itrc=1,1+ntrc_salt
            do k=1,N
              do i=IstrR,IendR
                tbry_south(i,k,itrc)=cff1*tbry_south_dt(i,k,it1,itrc)
     &                              +cff2*tbry_south_dt(i,k,it2,itrc)
              enddo
            enddo
          enddo
        endif
        if (.not.NORTH_INTER) then
          do i=IstrR,IendR
            zetabry_north(i)=cff1*zetabry_north_dt(i,it1)
     &                      +cff2*zetabry_north_dt(i,it2)
          enddo
          do i=IstrR,IendR
            ubarbry_north(i)=cff1*ubarbry_north_dt(i,it1)
     &                      +cff2*ubarbry_north_dt(i,it2)
            vbarbry_north(i)=cff1*vbarbry_north_dt(i,it1)
     &                      +cff2*vbarbry_north_dt(i,it2)
          enddo
          do k=1,N
            do i=IstrR,IendR
              ubry_north(i,k)=cff1*ubry_north_dt(i,k,it1)
     &                       +cff2*ubry_north_dt(i,k,it2)
              vbry_north(i,k)=cff1*vbry_north_dt(i,k,it1)
     &                       +cff2*vbry_north_dt(i,k,it2)
            enddo
          enddo
          do itrc=1,1+ntrc_salt
            do k=1,N
              do i=IstrR,IendR
                tbry_north(i,k,itrc)=cff1*tbry_north_dt(i,k,it1,itrc)
     &                              +cff2*tbry_north_dt(i,k,it2,itrc)
              enddo
            enddo
          enddo
        endif
      elseif (Istr+Jstr.eq.2) then
        if (mynode.eq.0) write(stdout,'(/2(1x,A)/3(1x,A,F16.10)/)')
     &   'SET_BRY_ALL_TILE - current model time is out of bounds of',
     &   '''bry_time''.',     'BRY_TSTART=',   bry_time(it1)*sec2day,
     &   'TDAYS=',  tdays,    'BRY_TEND=',     bry_time(it2)*sec2day
        may_day_flag=2
      endif
      return
       
      

      end subroutine Sub_Loop_set_bry_tile

