26   use fms_mod,           
only: write_version_number
    41 #include<file_version.h>    55   character(len=*), 
parameter :: 
mod_name = 
'coupler_types_mod'    59     character(len=48)       :: name = 
' '    60     real, 
pointer, 
contiguous, 
dimension(:,:,:) :: values => null() 
    63     logical                 :: mean = .true. 
    64     logical                 :: override = .false. 
    65     integer                 :: id_diag = 0
    66     character(len=128)      :: long_name = 
' '    67     character(len=128)      :: units = 
' '    68     integer                 :: id_rest = 0
    69     logical                 :: may_init = .true. 
    75     character(len=48)                 :: name = 
' '    76     integer                           :: num_fields = 0
    78     character(len=128)                :: flux_type = 
' '    79     character(len=128)                :: implementation = 
' '    80     real, 
pointer, 
dimension(:)       :: param => null() 
    81     logical, 
pointer, 
dimension(:)    :: flag => null() 
    82     integer                           :: atm_tr_index = 0
    83     character(len=128)                :: ice_restart_file = 
' '    84     character(len=128)                :: ocean_restart_file = 
' '    87     logical                           :: use_atm_pressure
    88     logical                           :: use_10m_wind_speed
    89     logical                           :: pass_through_ice
    94     integer                                            :: num_bcs = 0
    96     logical    :: set = .false.       
    97     integer    :: isd, isc, iec, ied
    98     integer    :: jsd, jsc, jec, jed
   105     character(len=48)       :: name = 
' '   106     real, 
pointer, 
contiguous, 
dimension(:,:) :: values => null() 
   109     logical                 :: mean = .true. 
   110     logical                 :: override = .false. 
   111     integer                 :: id_diag = 0
   112     character(len=128)      :: long_name = 
' '   113     character(len=128)      :: units = 
' '   114     integer                 :: id_rest = 0
   115     logical                 :: may_init = .true. 
   121     character(len=48)                 :: name = 
' '   122     integer                           :: num_fields = 0
   124     character(len=128)                :: flux_type = 
' '   125     character(len=128)                :: implementation = 
' '   126     real, 
pointer, 
dimension(:)       :: param => null() 
   127     logical, 
pointer, 
dimension(:)    :: flag => null() 
   128     integer                           :: atm_tr_index = 0
   129     character(len=128)                :: ice_restart_file = 
' '   130     character(len=128)                :: ocean_restart_file = 
' '   133     logical                           :: use_atm_pressure
   134     logical                           :: use_10m_wind_speed
   135     logical                           :: pass_through_ice
   140     integer                                            :: num_bcs = 0
   142     logical    :: set = .false.       
   143     integer    :: isd, isc, iec, ied
   144     integer    :: jsd, jsc, jec, jed
   149     character(len=48)           :: name = 
' '   150     real, 
pointer, 
dimension(:) :: values => null() 
   151     logical                     :: mean = .true. 
   152     logical                     :: override = .false. 
   153     integer                     :: id_diag = 0
   154     character(len=128)          :: long_name = 
' '   155     character(len=128)          :: units = 
' '   156     logical                     :: may_init = .true. 
   162     character(len=48)              :: name = 
' '   163     integer                        :: num_fields = 0
   165     character(len=128)             :: flux_type = 
' '   166     character(len=128)             :: implementation = 
' '   167     real, 
pointer, 
dimension(:)    :: param => null() 
   168     logical, 
pointer, 
dimension(:) :: flag => null() 
   169     integer                        :: atm_tr_index = 0
   170     character(len=128)             :: ice_restart_file = 
' '   171     character(len=128)             :: ocean_restart_file = 
' '   172     logical                        :: use_atm_pressure
   173     logical                        :: use_10m_wind_speed
   174     logical                        :: pass_through_ice
   179     integer                                            :: num_bcs = 0
   181     logical    :: set = .false.       
   300     logical, 
save   :: module_is_initialized = .false.
   303     if (module_is_initialized) 
then   308     call write_version_number(trim(
mod_name), version)
   310     module_is_initialized = .true.
   320       & diag_name, axes, time, suffix)
   323     integer, 
intent(in)                     :: is
   324     integer, 
intent(in)                     :: ie
   325     integer, 
intent(in)                     :: js
   326     integer, 
intent(in)                     :: je
   327     character(len=*), 
intent(in)            :: diag_name
   328     integer, 
dimension(:), 
intent(in)       :: axes
   330     character(len=*), 
intent(in), 
optional  :: suffix
   332     character(len=*), 
parameter :: error_header =&
   333         & 
'==>Error from coupler_types_mod (coupler_type_copy_1d_2d):'   334     character(len=400)      :: error_msg
   337     if (var_out%num_bcs > 0) 
then   340       call mpp_error(fatal, trim(error_header) // 
' Number of output fields exceeds zero')
   343     if (var_in%num_bcs >= 0)&
   344         & 
call ct_spawn_1d_2d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), suffix)
   346     if ((var_out%num_bcs > 0) .and. (diag_name .ne. 
' '))&
   355       & diag_name, axes, time, suffix)
   358     integer, 
intent(in)                     :: is
   359     integer, 
intent(in)                     :: ie
   360     integer, 
intent(in)                     :: js
   361     integer, 
intent(in)                     :: je
   362     integer, 
intent(in)                     :: kd
   363     character(len=*), 
intent(in)            :: diag_name
   364     integer, 
dimension(:), 
intent(in)       :: axes
   366     character(len=*), 
intent(in), 
optional  :: suffix
   368     character(len=*), 
parameter :: error_header =&
   369         & 
'==>Error from coupler_types_mod (coupler_type_copy_1d_3d):'   370     character(len=400)      :: error_msg
   373     if (var_out%num_bcs > 0) 
then   376       call mpp_error(fatal, trim(error_header) // 
' Number of output fields exceeds zero')
   379     if (var_in%num_bcs >= 0)&
   380         & 
call ct_spawn_1d_3d(var_in, var_out,  (/ is, is, ie, ie /), (/ js, js, je, je /), (/1, kd/), suffix)
   382     if ((var_out%num_bcs > 0) .and. (diag_name .ne. 
' '))&
   390       & diag_name, axes, time, suffix)
   391     type(coupler_2d_bc_type), 
intent(in)    :: var_in
   392     type(coupler_2d_bc_type), 
intent(inout) :: var_out
   393     integer, 
intent(in)                     :: is
   394     integer, 
intent(in)                     :: ie
   395     integer, 
intent(in)                     :: js
   396     integer, 
intent(in)                     :: je
   397     character(len=*), 
intent(in)            :: diag_name
   398     integer, 
dimension(:), 
intent(in)       :: axes
   399     type(time_type), 
intent(in)             :: time
   400     character(len=*), 
intent(in), 
optional  :: suffix
   402     character(len=*), 
parameter :: error_header =&
   403         & 
'==>Error from coupler_types_mod (coupler_type_copy_2d_2d):'   404     character(len=400)      :: error_msg
   407     if (var_out%num_bcs > 0) 
then   410       call mpp_error(fatal, trim(error_header) // 
' Number of output fields exceeds zero')
   413     if (var_in%num_bcs >= 0)&
   414         & 
call ct_spawn_2d_2d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), suffix)
   416     if ((var_out%num_bcs > 0) .and. (diag_name .ne. 
' '))&
   424       & diag_name, axes, time, suffix)
   425     type(coupler_2d_bc_type), 
intent(in)    :: var_in
   426     type(coupler_3d_bc_type), 
intent(inout) :: var_out
   427     integer, 
intent(in)                     :: is
   428     integer, 
intent(in)                     :: ie
   429     integer, 
intent(in)                     :: js
   430     integer, 
intent(in)                     :: je
   431     integer, 
intent(in)                     :: kd
   432     character(len=*), 
intent(in)            :: diag_name
   433     integer, 
dimension(:), 
intent(in)       :: axes
   434     type(time_type), 
intent(in)             :: time
   435     character(len=*), 
intent(in), 
optional  :: suffix
   437     character(len=*), 
parameter :: error_header =&
   438         & 
'==>Error from coupler_types_mod (coupler_type_copy_2d_3d):'   439     character(len=400)      :: error_msg
   442     if (var_out%num_bcs > 0) 
then   445       call mpp_error(fatal, trim(error_header) // 
' Number of output fields exceeds zero')
   448     if (var_in%num_bcs >= 0)&
   449         & 
call ct_spawn_2d_3d(var_in, var_out,  (/ is, is, ie, ie /), (/ js, js, je, je /), (/1, kd/), suffix)
   451     if ((var_out%num_bcs > 0) .and. (diag_name .ne. 
' '))&
   459       & diag_name, axes, time, suffix)
   460     type(coupler_3d_bc_type), 
intent(in)    :: var_in
   461     type(coupler_2d_bc_type), 
intent(inout) :: var_out
   462     integer, 
intent(in)                     :: is
   463     integer, 
intent(in)                     :: ie
   464     integer, 
intent(in)                     :: js
   465     integer, 
intent(in)                     :: je
   466     character(len=*), 
intent(in)            :: diag_name
   467     integer, 
dimension(:), 
intent(in)       :: axes
   468     type(time_type), 
intent(in)             :: time
   469     character(len=*), 
intent(in), 
optional  :: suffix
   471     character(len=*), 
parameter :: error_header =&
   472         & 
'==>Error from coupler_types_mod (coupler_type_copy_3d_2d):'   473     character(len=400)      :: error_msg
   476     if (var_out%num_bcs > 0) 
then   479       call mpp_error(fatal, trim(error_header) // 
' Number of output fields exceeds zero')
   482     if (var_in%num_bcs >= 0)&
   483         & 
call ct_spawn_3d_2d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), suffix)
   485     if ((var_out%num_bcs > 0) .and. (diag_name .ne. 
' '))&
   493       & diag_name, axes, time, suffix)
   494     type(coupler_3d_bc_type), 
intent(in)    :: var_in
   495     type(coupler_3d_bc_type), 
intent(inout) :: var_out
   496     integer, 
intent(in)                     :: is
   497     integer, 
intent(in)                     :: ie
   498     integer, 
intent(in)                     :: js
   499     integer, 
intent(in)                     :: je
   500     integer, 
intent(in)                     :: kd
   501     character(len=*), 
intent(in)            :: diag_name
   502     integer, 
dimension(:), 
intent(in)       :: axes
   503     type(time_type), 
intent(in)             :: time
   504     character(len=*), 
intent(in), 
optional  :: suffix
   506     character(len=*), 
parameter :: error_header =&
   507         & 
'==>Error from coupler_types_mod (coupler_type_copy_3d_3d):'   508     character(len=400)      :: error_msg
   511     if (var_out%num_bcs > 0) 
then   514       call mpp_error(fatal, trim(error_header) // 
' Number of output fields exceeds zero')
   517     if (var_in%num_bcs >= 0)&
   518         & 
call ct_spawn_3d_3d(var_in, var_out,  (/ is, is, ie, ie /), (/ js, js, je, je /), (/1, kd/), suffix)
   520     if ((var_out%num_bcs > 0) .and. (diag_name .ne. 
' '))&
   534   subroutine ct_spawn_1d_2d(var_in, var, idim, jdim, suffix, as_needed)
   535     type(coupler_1d_bc_type), 
intent(in)    :: var_in
   536     type(coupler_2d_bc_type), 
intent(inout) :: var
   537     integer, 
dimension(4),    
intent(in)    :: idim
   539     integer, 
dimension(4),    
intent(in)    :: jdim
   541     character(len=*), 
optional, 
intent(in)  :: suffix
   542     logical,          
optional, 
intent(in)  :: as_needed
   545     character(len=*), 
parameter :: error_header =&
   546         & 
'==>Error from coupler_types_mod (CT_spawn_1d_2d):'   547     character(len=400)      :: error_msg
   550     if (
present(as_needed)) 
then   552         if ((var%set) .or. (.not.var_in%set)) 
return   557         & 
call mpp_error(fatal, trim(error_header) // 
' The output type has already been initialized.')
   558     if (.not.var_in%set)&
   559         & 
call mpp_error(fatal, trim(error_header) // 
' The parent type has not been initialized.')
   561     var%num_bcs = var_in%num_bcs
   564     if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then   565       write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
   568     if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then   569       write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list  ', jdim
   572     var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
   573     var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
   575     if (var%num_bcs > 0) 
then   576       if (
associated(var%bc)) 
then   577         call mpp_error(fatal, trim(error_header) // 
' var%bc already associated')
   579       allocate ( var%bc(var%num_bcs) )
   580       do n = 1, var%num_bcs
   581         var%bc(n)%name = var_in%bc(n)%name
   582         var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
   583         var%bc(n)%flux_type = var_in%bc(n)%flux_type
   584         var%bc(n)%implementation = var_in%bc(n)%implementation
   585         var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
   586         var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
   587         var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
   588         var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
   589         var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
   590         var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
   591         var%bc(n)%num_fields = var_in%bc(n)%num_fields
   592         if (
associated(var%bc(n)%field)) 
then   593           write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field already associated'   596         allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
   597         do m = 1, var%bc(n)%num_fields
   598           if (
present(suffix)) 
then   599             var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
   601             var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
   603           var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
   604           var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
   605           var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
   606           var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
   607           if (
associated(var%bc(n)%field(m)%values)) 
then   608             write (error_msg, *) trim(error_header),&
   609                 & 
' var%bc(', n, 
')%field(', m, 
')%values already associated'   613           allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed) )
   614           var%bc(n)%field(m)%values(:,:) = 0.0
   629   subroutine ct_spawn_1d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
   630     type(coupler_1d_bc_type), 
intent(in)    :: var_in
   631     type(coupler_3d_bc_type), 
intent(inout) :: var
   632     integer, 
dimension(4),    
intent(in)    :: idim
   634     integer, 
dimension(4),    
intent(in)    :: jdim
   636     integer, 
dimension(2),    
intent(in)    :: kdim
   638     character(len=*), 
optional, 
intent(in)  :: suffix
   639     logical,          
optional, 
intent(in)  :: as_needed
   642     character(len=*), 
parameter :: error_header =&
   643         & 
'==>Error from coupler_types_mod (CT_spawn_1d_3d):'   644     character(len=400)      :: error_msg
   647     if (
present(as_needed)) 
then   649         if ((var%set) .or. (.not.var_in%set)) 
return   654         & 
call mpp_error(fatal, trim(error_header) // 
' The output type has already been initialized.')
   655     if (.not.var_in%set)&
   656         & 
call mpp_error(fatal, trim(error_header) // 
' The parent type has not been initialized.')
   658     var%num_bcs = var_in%num_bcs
   662     if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then   663       write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
   666     if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then   667       write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list  ', jdim
   670     var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
   671     var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
   672     var%ks  = kdim(1) ; var%ke  = kdim(2)
   674     if (var%num_bcs > 0) 
then   675       if (kdim(1) > kdim(2)) 
then   676         write (error_msg, *) trim(error_header), 
' Disordered k-dimension index bound list  ', kdim
   680       if (
associated(var%bc)) 
then   681         call mpp_error(fatal, trim(error_header) // 
' var%bc already associated')
   683       allocate ( var%bc(var%num_bcs) )
   684       do n = 1, var%num_bcs
   685         var%bc(n)%name = var_in%bc(n)%name
   686         var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
   687         var%bc(n)%flux_type = var_in%bc(n)%flux_type
   688         var%bc(n)%implementation = var_in%bc(n)%implementation
   689         var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
   690         var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
   691         var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
   692         var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
   693         var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
   694         var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
   695         var%bc(n)%num_fields = var_in%bc(n)%num_fields
   696         if (
associated(var%bc(n)%field)) 
then   697           write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field already associated'   700         allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
   701         do m = 1, var%bc(n)%num_fields
   702           if (
present(suffix)) 
then   703             var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
   705             var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
   707           var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
   708           var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
   709           var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
   710           var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
   711           if (
associated(var%bc(n)%field(m)%values)) 
then   712             write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field(', m, 
')%values already associated'   716           allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed,var%ks:var%ke) )
   717           var%bc(n)%field(m)%values(:,:,:) = 0.0
   733   subroutine ct_spawn_2d_2d(var_in, var, idim, jdim, suffix, as_needed)
   734     type(coupler_2d_bc_type), 
intent(in)    :: var_in
   735     type(coupler_2d_bc_type), 
intent(inout) :: var
   736     integer, 
dimension(4),    
intent(in)    :: idim
   738     integer, 
dimension(4),    
intent(in)    :: jdim
   740     character(len=*), 
optional, 
intent(in)  :: suffix
   741     logical,          
optional, 
intent(in)  :: as_needed
   744     character(len=*), 
parameter :: error_header =&
   745         & 
'==>Error from coupler_types_mod (CT_spawn_2d_2d):'   746     character(len=400)      :: error_msg
   749     if (
present(as_needed)) 
then   751         if ((var%set) .or. (.not.var_in%set)) 
return   756         & 
call mpp_error(fatal, trim(error_header) // 
' The output type has already been initialized.')
   757     if (.not.var_in%set)&
   758         & 
call mpp_error(fatal, trim(error_header) // 
' The parent type has not been initialized.')
   760     var%num_bcs = var_in%num_bcs
   763     if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then   764       write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
   767     if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then   768       write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list  ', jdim
   771     var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
   772     var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
   774     if (var%num_bcs > 0) 
then   775       if (
associated(var%bc)) 
then   776         call mpp_error(fatal, trim(error_header) // 
' var%bc already associated')
   778       allocate ( var%bc(var%num_bcs) )
   779       do n = 1, var%num_bcs
   780         var%bc(n)%name = var_in%bc(n)%name
   781         var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
   782         var%bc(n)%flux_type = var_in%bc(n)%flux_type
   783         var%bc(n)%implementation = var_in%bc(n)%implementation
   784         var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
   785         var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
   786         var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
   787         var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
   788         var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
   789         var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
   790         var%bc(n)%num_fields = var_in%bc(n)%num_fields
   791         if (
associated(var%bc(n)%field)) 
then   792           write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field already associated'   795         allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
   796         do m = 1, var%bc(n)%num_fields
   797           if (
present(suffix)) 
then   798             var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
   800             var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
   802           var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
   803           var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
   804           var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
   805           var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
   806           if (
associated(var%bc(n)%field(m)%values)) 
then   807             write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field(', m, 
')%values already associated'   811           allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed) )
   812           var%bc(n)%field(m)%values(:,:) = 0.0
   828   subroutine ct_spawn_2d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
   829     type(coupler_2d_bc_type), 
intent(in)    :: var_in
   830     type(coupler_3d_bc_type), 
intent(inout) :: var
   831     integer, 
dimension(4),    
intent(in)    :: idim
   833     integer, 
dimension(4),    
intent(in)    :: jdim
   835     integer, 
dimension(2),    
intent(in)    :: kdim
   837     character(len=*), 
optional, 
intent(in)  :: suffix
   838     logical,          
optional, 
intent(in)  :: as_needed
   841     character(len=*), 
parameter :: error_header =&
   842         & 
'==>Error from coupler_types_mod (CT_spawn_2d_3d):'   843     character(len=400)      :: error_msg
   846     if (
present(as_needed)) 
then   848         if ((var%set) .or. (.not.var_in%set)) 
return   853         & 
call mpp_error(fatal, trim(error_header) // 
' The output type has already been initialized.')
   854     if (.not.var_in%set)&
   855         & 
call mpp_error(fatal, trim(error_header) // 
' The parent type has not been initialized.')
   857     var%num_bcs = var_in%num_bcs
   861     if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then   862       write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
   865     if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then   866       write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list  ', jdim
   869     if (kdim(1) > kdim(2)) 
then   870       write (error_msg, *) trim(error_header), 
' Disordered k-dimension index bound list  ', kdim
   873     var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
   874     var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
   875     var%ks  = kdim(1) ; var%ke = kdim(2)
   877     if (var%num_bcs > 0) 
then   878       if (
associated(var%bc)) 
then   879         call mpp_error(fatal, trim(error_header) // 
' var%bc already associated')
   881       allocate ( var%bc(var%num_bcs) )
   882       do n = 1, var%num_bcs
   883         var%bc(n)%name = var_in%bc(n)%name
   884         var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
   885         var%bc(n)%flux_type = var_in%bc(n)%flux_type
   886         var%bc(n)%implementation = var_in%bc(n)%implementation
   887         var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
   888         var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
   889         var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
   890         var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
   891         var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
   892         var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
   893         var%bc(n)%num_fields = var_in%bc(n)%num_fields
   894         if (
associated(var%bc(n)%field)) 
then   895           write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field already associated'   898         allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
   899         do m = 1, var%bc(n)%num_fields
   900           if (
present(suffix)) 
then   901             var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
   903             var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
   905           var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
   906           var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
   907           var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
   908           var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
   909           if (
associated(var%bc(n)%field(m)%values)) 
then   910             write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field(', m, 
')%values already associated'   914           allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed,var%ks:var%ke) )
   915           var%bc(n)%field(m)%values(:,:,:) = 0.0
   930   subroutine ct_spawn_3d_2d(var_in, var, idim, jdim, suffix, as_needed)
   931     type(coupler_3d_bc_type), 
intent(in)    :: var_in
   932     type(coupler_2d_bc_type), 
intent(inout) :: var
   933     integer, 
dimension(4),    
intent(in)    :: idim
   935     integer, 
dimension(4),    
intent(in)    :: jdim
   937     character(len=*), 
optional, 
intent(in)  :: suffix
   938     logical,          
optional, 
intent(in)  :: as_needed
   941     character(len=*), 
parameter :: error_header =&
   942         & 
'==>Error from coupler_types_mod (CT_spawn_3d_2d):'   943     character(len=400)      :: error_msg
   946     if (
present(as_needed)) 
then   948         if ((var%set) .or. (.not.var_in%set)) 
return   953         & 
call mpp_error(fatal, trim(error_header) // 
' The output type has already been initialized.')
   954     if (.not.var_in%set)&
   955         & 
call mpp_error(fatal, trim(error_header) // 
' The parent type has not been initialized.')
   957     var%num_bcs = var_in%num_bcs
   960     if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then   961       write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
   964     if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then   965       write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list  ', jdim
   968     var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
   969     var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
   971     if (var%num_bcs > 0) 
then   972       if (
associated(var%bc)) 
then   973         call mpp_error(fatal, trim(error_header) // 
' var%bc already associated')
   975       allocate ( var%bc(var%num_bcs) )
   976       do n = 1, var%num_bcs
   977         var%bc(n)%name = var_in%bc(n)%name
   978         var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
   979         var%bc(n)%flux_type = var_in%bc(n)%flux_type
   980         var%bc(n)%implementation = var_in%bc(n)%implementation
   981         var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
   982         var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
   983         var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
   984         var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
   985         var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
   986         var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
   987         var%bc(n)%num_fields = var_in%bc(n)%num_fields
   988         if (
associated(var%bc(n)%field)) 
then   989           write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field already associated'   992         allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
   993         do m = 1, var%bc(n)%num_fields
   994           if (
present(suffix)) 
then   995             var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
   997             var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
   999           var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
  1000           var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
  1001           var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
  1002           var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
  1003           if (
associated(var%bc(n)%field(m)%values)) 
then  1004             write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field(', m, 
')%values already associated'  1008           allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed) )
  1009           var%bc(n)%field(m)%values(:,:) = 0.0
  1025   subroutine ct_spawn_3d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
  1026     type(coupler_3d_bc_type), 
intent(in)    :: var_in
  1027     type(coupler_3d_bc_type), 
intent(inout) :: var
  1028     integer, 
dimension(4),    
intent(in)    :: idim
  1030     integer, 
dimension(4),    
intent(in)    :: jdim
  1032     integer, 
dimension(2),    
intent(in)    :: kdim
  1034     character(len=*), 
optional, 
intent(in)  :: suffix
  1035     logical,          
optional, 
intent(in)  :: as_needed
  1038     character(len=*), 
parameter :: error_header =&
  1039         & 
'==>Error from coupler_types_mod (CT_spawn_3d_3d):'  1040     character(len=400)      :: error_msg
  1043     if (
present(as_needed)) 
then  1045         if ((var%set) .or. (.not.var_in%set)) 
return  1050         & 
call mpp_error(fatal, trim(error_header) // 
' The output type has already been initialized.')
  1051     if (.not.var_in%set)&
  1052         & 
call mpp_error(fatal, trim(error_header) // 
' The parent type has not been initialized.')
  1054     var%num_bcs = var_in%num_bcs
  1057     if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  1058       write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  1061     if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  1062       write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list  ', jdim
  1065     if (kdim(1) > kdim(2)) 
then  1066       write (error_msg, *) trim(error_header), 
' Disordered k-dimension index bound list  ', kdim
  1069     var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
  1070     var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
  1071     var%ks  = kdim(1) ; var%ke  = kdim(2)
  1073     if (var%num_bcs > 0) 
then  1074       if (
associated(var%bc)) 
then  1075         call mpp_error(fatal, trim(error_header) // 
' var%bc already associated')
  1077       allocate ( var%bc(var%num_bcs) )
  1078       do n = 1, var%num_bcs
  1079         var%bc(n)%name = var_in%bc(n)%name
  1080         var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
  1081         var%bc(n)%flux_type = var_in%bc(n)%flux_type
  1082         var%bc(n)%implementation = var_in%bc(n)%implementation
  1083         var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
  1084         var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
  1085         var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
  1086         var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
  1087         var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
  1088         var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
  1089         var%bc(n)%num_fields = var_in%bc(n)%num_fields
  1090         if (
associated(var%bc(n)%field)) 
then  1091           write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field already associated'  1094         allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
  1095         do m = 1, var%bc(n)%num_fields
  1096           if (
present(suffix)) 
then  1097             var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
  1099             var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
  1101           var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
  1102           var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
  1103           var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
  1104           var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
  1105           if (
associated(var%bc(n)%field(m)%values)) 
then  1106             write (error_msg, *) trim(error_header), 
' var%bc(', n, 
')%field(', m, 
')%values already associated'  1111           allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed,var%ks:var%ke) )
  1112           var%bc(n)%field(m)%values(:,:,:) = 0.0
  1131   subroutine ct_copy_data_2d(var_in, var, halo_size, bc_index, field_index,&
  1132       & exclude_flux_type, only_flux_type, pass_through_ice)
  1133     type(coupler_2d_bc_type),   
intent(in)    :: var_in
  1134     type(coupler_2d_bc_type),   
intent(inout) :: var
  1135     integer,          
optional, 
intent(in)    :: halo_size
  1136     integer,          
optional, 
intent(in)    :: bc_index
  1138     integer,          
optional, 
intent(in)    :: field_index
  1140     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1141     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1142     logical,          
optional, 
intent(in)    :: pass_through_ice
  1145     integer :: i, j, m, n, n1, n2, halo, i_off, j_off
  1147     if (
present(bc_index)) 
then  1148       if (bc_index > var_in%num_bcs)&
  1149           & 
call mpp_error(fatal, 
"CT_copy_data_2d: bc_index is present and exceeds var_in%num_bcs.")
  1150       if (
present(field_index)) 
then ; 
if (field_index > var_in%bc(bc_index)%num_fields)&
  1151           & 
call mpp_error(fatal, 
"CT_copy_data_2d: field_index is present and exceeds num_fields for" //&
  1152           & trim(var_in%bc(bc_index)%name) )
  1154     elseif (
present(field_index)) 
then  1155       call mpp_error(fatal, 
"CT_copy_data_2d: bc_index must be present if field_index is present.")
  1159     if (
present(halo_size)) halo = halo_size
  1163     if (
present(bc_index)) 
then  1170       if ((var_in%iec-var_in%isc) /= (var%iec-var%isc))&
  1171           & 
call mpp_error(fatal, 
"CT_copy_data_2d: There is an i-direction computational domain size mismatch.")
  1172       if ((var_in%jec-var_in%jsc) /= (var%jec-var%jsc))&
  1173           & 
call mpp_error(fatal, 
"CT_copy_data_2d: There is a j-direction computational domain size mismatch.")
  1174       if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  1175           & 
call mpp_error(fatal, 
"CT_copy_data_2d: Excessive i-direction halo size for the input structure.")
  1176       if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  1177           & 
call mpp_error(fatal, 
"CT_copy_data_2d: Excessive j-direction halo size for the input structure.")
  1178       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1179           & 
call mpp_error(fatal, 
"CT_copy_data_2d: Excessive i-direction halo size for the output structure.")
  1180       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1181           & 
call mpp_error(fatal, 
"CT_copy_data_2d: Excessive j-direction halo size for the output structure.")
  1183       i_off = var_in%isc - var%isc
  1184       j_off = var_in%jsc - var%jsc
  1189       if (copy_bc .and. 
present(exclude_flux_type))&
  1190           & copy_bc = .not.(trim(var%bc(n)%flux_type) == trim(exclude_flux_type))
  1191       if (copy_bc .and. 
present(only_flux_type))&
  1192           & copy_bc = (trim(var%bc(n)%flux_type) == trim(only_flux_type))
  1193       if (copy_bc .and. 
present(pass_through_ice))&
  1194           & copy_bc = (pass_through_ice .eqv. var%bc(n)%pass_through_ice)
  1195       if (.not.copy_bc) cycle
  1197       do m = 1, var%bc(n)%num_fields
  1198         if (
present(field_index)) 
then  1199           if (m /= field_index) cycle
  1201         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1202           do j=var%jsc-halo,var%jec+halo
  1203             do i=var%isc-halo,var%iec+halo
  1204               var%bc(n)%field(m)%values(i,j) = var_in%bc(n)%field(m)%values(i+i_off,j+j_off)
  1226   subroutine ct_copy_data_3d(var_in, var, halo_size, bc_index, field_index,&
  1227       & exclude_flux_type, only_flux_type, pass_through_ice)
  1228     type(coupler_3d_bc_type),   
intent(in)    :: var_in
  1229     type(coupler_3d_bc_type),   
intent(inout) :: var
  1230     integer,          
optional, 
intent(in)    :: halo_size
  1231     integer,          
optional, 
intent(in)    :: bc_index
  1233     integer,          
optional, 
intent(in)    :: field_index
  1235     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1237     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1239     logical,          
optional, 
intent(in)    :: pass_through_ice
  1242     integer :: i, j, k, m, n, n1, n2, halo, i_off, j_off, k_off
  1244     if (
present(bc_index)) 
then  1245       if (bc_index > var_in%num_bcs) &
  1246           call mpp_error(fatal, 
"CT_copy_data_3d: bc_index is present and exceeds var_in%num_bcs.")
  1247       if (
present(field_index)) 
then ; 
if (field_index > var_in%bc(bc_index)%num_fields)&
  1248           & 
call mpp_error(fatal, 
"CT_copy_data_3d: field_index is present and exceeds num_fields for" //&
  1249           & trim(var_in%bc(bc_index)%name) )
  1251     elseif (
present(field_index)) 
then  1252       call mpp_error(fatal, 
"CT_copy_data_3d: bc_index must be present if field_index is present.")
  1256     if (
present(halo_size)) halo = halo_size
  1260     if (
present(bc_index)) 
then  1267       if ((var_in%iec-var_in%isc) /= (var%iec-var%isc))&
  1268           & 
call mpp_error(fatal, 
"CT_copy_data_3d: There is an i-direction computational domain size mismatch.")
  1269       if ((var_in%jec-var_in%jsc) /= (var%jec-var%jsc))&
  1270           & 
call mpp_error(fatal, 
"CT_copy_data_3d: There is a j-direction computational domain size mismatch.")
  1271       if ((var_in%ke-var_in%ks) /= (var%ke-var%ks))&
  1272           & 
call mpp_error(fatal, 
"CT_copy_data_3d: There is a k-direction computational domain size mismatch.")
  1273       if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  1274           & 
call mpp_error(fatal, 
"CT_copy_data_3d: Excessive i-direction halo size for the input structure.")
  1275       if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  1276           & 
call mpp_error(fatal, 
"CT_copy_data_3d: Excessive j-direction halo size for the input structure.")
  1277       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1278           & 
call mpp_error(fatal, 
"CT_copy_data_3d: Excessive i-direction halo size for the output structure.")
  1279       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1280           & 
call mpp_error(fatal, 
"CT_copy_data_3d: Excessive j-direction halo size for the output structure.")
  1282       i_off = var_in%isc - var%isc
  1283       j_off = var_in%jsc - var%jsc
  1284       k_off = var_in%ks - var%ks
  1289       if (copy_bc .and. 
present(exclude_flux_type))&
  1290           & copy_bc = .not.(trim(var%bc(n)%flux_type) == trim(exclude_flux_type))
  1291       if (copy_bc .and. 
present(only_flux_type))&
  1292           & copy_bc = (trim(var%bc(n)%flux_type) == trim(only_flux_type))
  1293       if (copy_bc .and. 
present(pass_through_ice))&
  1294           & copy_bc = (pass_through_ice .eqv. var%bc(n)%pass_through_ice)
  1295       if (.not.copy_bc) cycle
  1297       do m = 1, var_in%bc(n)%num_fields
  1298         if (
present(field_index)) 
then  1299           if (m /= field_index) cycle
  1301         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1303             do j=var%jsc-halo,var%jec+halo
  1304               do i=var%isc-halo,var%iec+halo
  1305                 var%bc(n)%field(m)%values(i,j,k) = var_in%bc(n)%field(m)%values(i+i_off,j+j_off,k+k_off)
  1328       & exclude_flux_type, only_flux_type, pass_through_ice,&
  1329       & ind3_start, ind3_end)
  1330     type(coupler_2d_bc_type),   
intent(in)    :: var_in
  1331     type(coupler_3d_bc_type),   
intent(inout) :: var
  1332     integer,          
optional, 
intent(in)    :: halo_size
  1333     integer,          
optional, 
intent(in)    :: bc_index
  1335     integer,          
optional, 
intent(in)    :: field_index
  1337     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1338     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1339     logical,          
optional, 
intent(in)    :: pass_through_ice
  1341     integer,          
optional, 
intent(in)    :: ind3_start
  1343     integer,          
optional, 
intent(in)    :: ind3_end
  1347     integer :: i, j, k, m, n, n1, n2, halo, i_off, j_off, ks, ke
  1349     if (
present(bc_index)) 
then  1350       if (bc_index > var_in%num_bcs)&
  1351           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: bc_index is present and exceeds var_in%num_bcs.")
  1352       if (
present(field_index)) 
then ; 
if (field_index > var_in%bc(bc_index)%num_fields)&
  1353           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: field_index is present and exceeds num_fields for" //&
  1354           & trim(var_in%bc(bc_index)%name) )
  1356     elseif (
present(field_index)) 
then  1357       call mpp_error(fatal, 
"CT_copy_data_2d_3d: bc_index must be present if field_index is present.")
  1361     if (
present(halo_size)) halo = halo_size
  1365     if (
present(bc_index)) 
then  1372       if ((var_in%iec-var_in%isc) /= (var%iec-var%isc))&
  1373           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: There is an i-direction computational domain size mismatch.")
  1374       if ((var_in%jec-var_in%jsc) /= (var%jec-var%jsc))&
  1375           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: There is a j-direction computational domain size mismatch.")
  1376       if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  1377           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: Excessive i-direction halo size for the input structure.")
  1378       if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  1379           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: Excessive j-direction halo size for the input structure.")
  1380       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1381           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: Excessive i-direction halo size for the output structure.")
  1382       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1383           & 
call mpp_error(fatal, 
"CT_copy_data_2d_3d: Excessive j-direction halo size for the output structure.")
  1386     i_off = var_in%isc - var%isc
  1387     j_off = var_in%jsc - var%jsc
  1390       if (copy_bc .and. 
present(exclude_flux_type))&
  1391           & copy_bc = .not.(trim(var_in%bc(n)%flux_type) == trim(exclude_flux_type))
  1392       if (copy_bc .and. 
present(only_flux_type))&
  1393           & copy_bc = (trim(var_in%bc(n)%flux_type) == trim(only_flux_type))
  1394       if (copy_bc .and. 
present(pass_through_ice))&
  1395           & copy_bc = (pass_through_ice .eqv. var_in%bc(n)%pass_through_ice)
  1396       if (.not.copy_bc) cycle
  1398       do m = 1, var_in%bc(n)%num_fields
  1399         if (
present(field_index)) 
then  1400           if (m /= field_index) cycle
  1402         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1404           if (
present(ind3_start)) ks = 
max(ks, ind3_start)
  1406           if (
present(ind3_end)) ke = 
max(ke, ind3_end)
  1408             do j=var%jsc-halo,var%jec+halo
  1409               do i=var%isc-halo,var%iec+halo
  1410                 var%bc(n)%field(m)%values(i,j,k) = var_in%bc(n)%field(m)%values(i+i_off,j+j_off)
  1428     type(coupler_2d_bc_type), 
intent(in)    :: var_in
  1429     type(domain2D),           
intent(in)    :: domain_in
  1430     type(coupler_2d_bc_type), 
intent(inout) :: var_out
  1431     type(domain2D),           
intent(in)    :: domain_out
  1432     logical,        
optional, 
intent(in)    :: complete
  1434     real, 
pointer, 
dimension(:,:) :: null_ptr2D => null()
  1435     logical :: do_in, do_out, do_complete
  1436     integer :: m, n, fc, fc_in, fc_out
  1438     do_complete = .true.
  1439     if (
present(complete)) do_complete = complete
  1443     do_out = var_out%set
  1445     fc_in = 0 ; fc_out = 0
  1447       do n = 1, var_in%num_bcs
  1448         do m = 1, var_in%bc(n)%num_fields
  1449           if (
associated(var_in%bc(n)%field(m)%values)) fc_in = fc_in + 1
  1453     if (fc_in == 0) do_in = .false.
  1455       do n = 1, var_out%num_bcs
  1456         do m = 1, var_out%bc(n)%num_fields
  1457           if (
associated(var_out%bc(n)%field(m)%values)) fc_out = fc_out + 1
  1461     if (fc_out == 0) do_out = .false.
  1463     if (do_in .and. do_out) 
then  1464       if (var_in%num_bcs /= var_out%num_bcs) 
call mpp_error(fatal,&
  1465           & 
"Mismatch in num_bcs in CT_copy_data_2d.")
  1466       if (fc_in /= fc_out) 
call mpp_error(fatal,&
  1467           & 
"Mismatch in the total number of fields in CT_redistribute_data_2d.")
  1470     if (.not.(do_in .or. do_out)) 
return  1473     if (do_in .and. do_out) 
then  1474       do n = 1, var_in%num_bcs
  1475         do m = 1, var_in%bc(n)%num_fields
  1476           if ( 
associated(var_in%bc(n)%field(m)%values) .neqv.&
  1477               & 
associated(var_out%bc(n)%field(m)%values) ) &
  1479               & 
"Mismatch in which fields are associated in CT_redistribute_data_2d.")
  1480           if ( 
associated(var_in%bc(n)%field(m)%values) ) 
then  1483                 & domain_out, var_out%bc(n)%field(m)%values,&
  1484                 & complete=(do_complete.and.(fc==fc_in)) )
  1489       do n = 1, var_in%num_bcs
  1490         do m = 1, var_in%bc(n)%num_fields
  1491           if ( 
associated(var_in%bc(n)%field(m)%values) ) 
then  1494                 & domain_out, null_ptr2d,&
  1495                 & complete=(do_complete.and.(fc==fc_in)) )
  1499     elseif (do_out) 
then  1500       do n = 1, var_out%num_bcs
  1501         do m = 1, var_out%bc(n)%num_fields
  1502           if ( 
associated(var_out%bc(n)%field(m)%values) ) 
then  1505                 & domain_out, var_out%bc(n)%field(m)%values,&
  1506                 & complete=(do_complete.and.(fc==fc_out)) )
  1518     type(coupler_3d_bc_type), 
intent(in)    :: var_in
  1519     type(domain2D),           
intent(in)    :: domain_in
  1520     type(coupler_3d_bc_type), 
intent(inout) :: var_out
  1521     type(domain2D),           
intent(in)    :: domain_out
  1522     logical,        
optional, 
intent(in)    :: complete
  1524     real, 
pointer, 
dimension(:,:,:) :: null_ptr3D => null()
  1525     logical :: do_in, do_out, do_complete
  1526     integer :: m, n, fc, fc_in, fc_out
  1528     do_complete = .true.
  1529     if (
present(complete)) do_complete = complete
  1533     do_out = var_out%set
  1538       do n = 1, var_in%num_bcs
  1539         do m = 1, var_in%bc(n)%num_fields
  1540           if (
associated(var_in%bc(n)%field(m)%values)) fc_in = fc_in + 1
  1544     if (fc_in == 0) do_in = .false.
  1546       do n = 1, var_out%num_bcs
  1547         do m = 1, var_out%bc(n)%num_fields
  1548           if (
associated(var_out%bc(n)%field(m)%values)) fc_out = fc_out + 1
  1552     if (fc_out == 0) do_out = .false.
  1554     if (do_in .and. do_out) 
then  1555       if (var_in%num_bcs /= var_out%num_bcs) 
call mpp_error(fatal,&
  1556           & 
"Mismatch in num_bcs in CT_copy_data_3d.")
  1557       if (fc_in /= fc_out) 
call mpp_error(fatal,&
  1558           & 
"Mismatch in the total number of fields in CT_redistribute_data_3d.")
  1561     if (.not.(do_in .or. do_out)) 
return  1564     if (do_in .and. do_out) 
then  1565       do n = 1, var_in%num_bcs
  1566         do m = 1, var_in%bc(n)%num_fields
  1567           if ( 
associated(var_in%bc(n)%field(m)%values) .neqv.&
  1568               & 
associated(var_out%bc(n)%field(m)%values) )&
  1570               & 
"Mismatch in which fields are associated in CT_redistribute_data_3d.")
  1571           if ( 
associated(var_in%bc(n)%field(m)%values) ) 
then  1574                 & domain_out, var_out%bc(n)%field(m)%values,&
  1575                 & complete=(do_complete.and.(fc==fc_in)) )
  1580       do n = 1, var_in%num_bcs
  1581         do m = 1, var_in%bc(n)%num_fields
  1582           if ( 
associated(var_in%bc(n)%field(m)%values) ) 
then  1585                 & domain_out, null_ptr3d,&
  1586                 & complete=(do_complete.and.(fc==fc_in)) )
  1590     elseif (do_out) 
then  1591       do n = 1, var_out%num_bcs
  1592         do m = 1, var_out%bc(n)%num_fields
  1593           if ( 
associated(var_out%bc(n)%field(m)%values) ) 
then  1596                 & domain_out, var_out%bc(n)%field(m)%values,&
  1597                 & complete=(do_complete.and.(fc==fc_out)) )
  1610       & exclude_flux_type, only_flux_type, pass_through_ice)
  1611     type(coupler_2d_bc_type),   
intent(inout) :: var
  1612     real,                       
intent(in)    :: scale
  1613     integer,          
optional, 
intent(in)    :: halo_size
  1615     integer,          
optional, 
intent(in)    :: bc_index
  1617     integer,          
optional, 
intent(in)    :: field_index
  1619     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1621     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1623     logical,          
optional, 
intent(in)    :: pass_through_ice
  1627     integer :: i, j, m, n, n1, n2, halo
  1629     if (
present(bc_index)) 
then  1630       if (bc_index > var%num_bcs)&
  1631           & 
call mpp_error(fatal, 
"CT_rescale_data_2d: bc_index is present and exceeds var%num_bcs.")
  1632       if (
present(field_index)) 
then ; 
if (field_index > var%bc(bc_index)%num_fields)&
  1633           & 
call mpp_error(fatal, 
"CT_rescale_data_2d: field_index is present and exceeds num_fields for" //&
  1634           & trim(var%bc(bc_index)%name) )
  1636     elseif (
present(field_index)) 
then  1637       call mpp_error(fatal, 
"CT_rescale_data_2d: bc_index must be present if field_index is present.")
  1641     if (
present(halo_size)) halo = halo_size
  1645     if (
present(bc_index)) 
then  1652       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1653           & 
call mpp_error(fatal, 
"CT_rescale_data_2d: Excessive i-direction halo size.")
  1654       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1655           & 
call mpp_error(fatal, 
"CT_rescale_data_2d: Excessive j-direction halo size.")
  1660       if (do_bc .and. 
present(exclude_flux_type))&
  1661           & do_bc = .not.(trim(var%bc(n)%flux_type) == trim(exclude_flux_type))
  1662       if (do_bc .and. 
present(only_flux_type))&
  1663           & do_bc = (trim(var%bc(n)%flux_type) == trim(only_flux_type))
  1664       if (do_bc .and. 
present(pass_through_ice))&
  1665           & do_bc = (pass_through_ice .eqv. var%bc(n)%pass_through_ice)
  1666       if (.not.do_bc) cycle
  1668       do m = 1, var%bc(n)%num_fields
  1669         if (
present(field_index)) 
then  1670           if (m /= field_index) cycle
  1672         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1673           if (scale == 0.0) 
then  1674             if (
present(halo_size)) 
then  1675               do j=var%jsc-halo,var%jec+halo
  1676                 do i=var%isc-halo,var%iec+halo
  1677                   var%bc(n)%field(m)%values(i,j) = 0.0
  1681               var%bc(n)%field(m)%values(:,:) = 0.0
  1684             do j=var%jsc-halo,var%jec+halo
  1685               do i=var%isc-halo,var%iec+halo
  1686                 var%bc(n)%field(m)%values(i,j) = scale * var%bc(n)%field(m)%values(i,j)
  1700       & exclude_flux_type, only_flux_type, pass_through_ice)
  1701     type(coupler_3d_bc_type),   
intent(inout) :: var
  1702     real,                       
intent(in)    :: scale
  1703     integer,          
optional, 
intent(in)    :: halo_size
  1705     integer,          
optional, 
intent(in)    :: bc_index
  1707     integer,          
optional, 
intent(in)    :: field_index
  1709     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1711     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1713     logical,          
optional, 
intent(in)    :: pass_through_ice
  1717     integer :: i, j, k, m, n, n1, n2, halo
  1719     if (
present(bc_index)) 
then  1720       if (bc_index > var%num_bcs)&
  1721           & 
call mpp_error(fatal, 
"CT_rescale_data_2d: bc_index is present and exceeds var%num_bcs.")
  1722       if (
present(field_index)) 
then ; 
if (field_index > var%bc(bc_index)%num_fields)&
  1723           & 
call mpp_error(fatal, 
"CT_rescale_data_2d: field_index is present and exceeds num_fields for" //&
  1724           & trim(var%bc(bc_index)%name) )
  1726     elseif (
present(field_index)) 
then  1727       call mpp_error(fatal, 
"CT_rescale_data_2d: bc_index must be present if field_index is present.")
  1731     if (
present(halo_size)) halo = halo_size
  1735     if (
present(bc_index)) 
then  1742       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1743           & 
call mpp_error(fatal, 
"CT_rescale_data_3d: Excessive i-direction halo size.")
  1744       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1745           & 
call mpp_error(fatal, 
"CT_rescale_data_3d: Excessive j-direction halo size.")
  1750       if (do_bc .and. 
present(exclude_flux_type))&
  1751           & do_bc = .not.(trim(var%bc(n)%flux_type) == trim(exclude_flux_type))
  1752       if (do_bc .and. 
present(only_flux_type))&
  1753           & do_bc = (trim(var%bc(n)%flux_type) == trim(only_flux_type))
  1754       if (do_bc .and. 
present(pass_through_ice))&
  1755           & do_bc = (pass_through_ice .eqv. var%bc(n)%pass_through_ice)
  1756       if (.not.do_bc) cycle
  1758       do m = 1, var%bc(n)%num_fields
  1759         if (
present(field_index)) 
then  1760           if (m /= field_index) cycle
  1762         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1763           if (scale == 0.0) 
then  1764             if (
present(halo_size)) 
then  1766                 do j=var%jsc-halo,var%jec+halo
  1767                   do i=var%isc-halo,var%iec+halo
  1768                     var%bc(n)%field(m)%values(i,j,k) = 0.0
  1773               var%bc(n)%field(m)%values(:,:,:) = 0.0
  1777               do j=var%jsc-halo,var%jec+halo
  1778                 do i=var%isc-halo,var%iec+halo
  1779                   var%bc(n)%field(m)%values(i,j,k) = scale * var%bc(n)%field(m)%values(i,j,k)
  1803       & scale_factor, scale_prev, exclude_flux_type, only_flux_type, pass_through_ice)
  1804     type(coupler_2d_bc_type),   
intent(in)    :: var_in
  1805     type(coupler_2d_bc_type),   
intent(inout) :: var
  1806     integer,          
optional, 
intent(in)    :: halo_size
  1807     integer,          
optional, 
intent(in)    :: bc_index
  1809     integer,          
optional, 
intent(in)    :: field_index
  1811     real,             
optional, 
intent(in)    :: scale_factor
  1812     real,             
optional, 
intent(in)    :: scale_prev
  1813     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1815     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1817     logical,          
optional, 
intent(in)    :: pass_through_ice
  1820     real :: scale, sc_prev
  1821     logical :: increment_bc
  1822     integer :: i, j, m, n, n1, n2, halo, i_off, j_off
  1825     if (
present(scale_factor)) scale = scale_factor
  1827     if (
present(scale_prev)) sc_prev = scale_prev
  1829     if (
present(bc_index)) 
then  1830       if (bc_index > var_in%num_bcs)&
  1831           & 
call mpp_error(fatal, 
"CT_increment_data_2d_2d: bc_index is present and exceeds var_in%num_bcs.")
  1832       if (
present(field_index)) 
then  1833         if (field_index > var_in%bc(bc_index)%num_fields)&
  1834             & 
call mpp_error(fatal, 
"CT_increment_data_2d_2d: field_index is present and exceeds num_fields for" //&
  1835             & trim(var_in%bc(bc_index)%name) )
  1837     elseif (
present(field_index)) 
then  1838       call mpp_error(fatal, 
"CT_increment_data_2d_2d: bc_index must be present if field_index is present.")
  1842     if (
present(halo_size)) halo = halo_size
  1846     if (
present(bc_index)) 
then  1853       if ((var_in%iec-var_in%isc) /= (var%iec-var%isc))&
  1854           & 
call mpp_error(fatal, 
"CT_increment_data_2d: There is an i-direction computational domain size mismatch.")
  1855       if ((var_in%jec-var_in%jsc) /= (var%jec-var%jsc))&
  1856           & 
call mpp_error(fatal, 
"CT_increment_data_2d: There is a j-direction computational domain size mismatch.")
  1857       if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  1858           & 
call mpp_error(fatal, 
"CT_increment_data_2d: Excessive i-direction halo size for the input structure.")
  1859       if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  1860           & 
call mpp_error(fatal, 
"CT_increment_data_2d: Excessive j-direction halo size for the input structure.")
  1861       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1862           & 
call mpp_error(fatal, 
"CT_increment_data_2d: Excessive i-direction halo size for the output structure.")
  1863       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1864           & 
call mpp_error(fatal, 
"CT_increment_data_2d: Excessive j-direction halo size for the output structure.")
  1866       i_off = var_in%isc - var%isc
  1867       j_off = var_in%jsc - var%jsc
  1871       increment_bc = .true.
  1872       if (increment_bc .and. 
present(exclude_flux_type))&
  1873           & increment_bc = .not.(trim(var%bc(n)%flux_type) == trim(exclude_flux_type))
  1874       if (increment_bc .and. 
present(only_flux_type))&
  1875           & increment_bc = (trim(var%bc(n)%flux_type) == trim(only_flux_type))
  1876       if (increment_bc .and. 
present(pass_through_ice))&
  1877           & increment_bc = (pass_through_ice .eqv. var%bc(n)%pass_through_ice)
  1878       if (.not.increment_bc) cycle
  1880       do m = 1, var_in%bc(n)%num_fields
  1881         if (
present(field_index)) 
then  1882           if (m /= field_index) cycle 
  1884         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1885           do j=var%jsc-halo,var%jec+halo
  1886             do i=var%isc-halo,var%iec+halo
  1887               var%bc(n)%field(m)%values(i,j) = sc_prev * var%bc(n)%field(m)%values(i,j) +&
  1888                   & scale * var_in%bc(n)%field(m)%values(i+i_off,j+j_off)
  1912       & scale_factor, scale_prev, exclude_flux_type, only_flux_type, pass_through_ice)
  1913     type(coupler_3d_bc_type),   
intent(in)    :: var_in
  1914     type(coupler_3d_bc_type),   
intent(inout) :: var
  1915     integer,          
optional, 
intent(in)    :: halo_size
  1916     integer,          
optional, 
intent(in)    :: bc_index
  1918     integer,          
optional, 
intent(in)    :: field_index
  1920     real,             
optional, 
intent(in)    :: scale_factor
  1921     real,             
optional, 
intent(in)    :: scale_prev
  1922     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  1924     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  1926     logical,          
optional, 
intent(in)    :: pass_through_ice
  1929     real :: scale, sc_prev
  1930     logical :: increment_bc
  1931     integer :: i, j, k, m, n, n1, n2, halo, i_off, j_off, k_off
  1934     if (
present(scale_factor)) scale = scale_factor
  1936     if (
present(scale_prev)) sc_prev = scale_prev
  1938     if (
present(bc_index)) 
then  1939       if (bc_index > var_in%num_bcs)&
  1940           & 
call mpp_error(fatal, 
"CT_increment_data_3d_3d: bc_index is present and exceeds var_in%num_bcs.")
  1941       if (
present(field_index)) 
then ; 
if (field_index > var_in%bc(bc_index)%num_fields)&
  1942           & 
call mpp_error(fatal, 
"CT_increment_data_3d_3d: field_index is present and exceeds num_fields for" //&
  1943           & trim(var_in%bc(bc_index)%name) )
  1945     elseif (
present(field_index)) 
then  1946       call mpp_error(fatal, 
"CT_increment_data_3d_3d: bc_index must be present if field_index is present.")
  1950     if (
present(halo_size)) halo = halo_size
  1954     if (
present(bc_index)) 
then  1961       if ((var_in%iec-var_in%isc) /= (var%iec-var%isc))&
  1962           & 
call mpp_error(fatal, 
"CT_increment_data_3d: There is an i-direction computational domain size mismatch.")
  1963       if ((var_in%jec-var_in%jsc) /= (var%jec-var%jsc))&
  1964           & 
call mpp_error(fatal, 
"CT_increment_data_3d: There is a j-direction computational domain size mismatch.")
  1965       if ((var_in%ke-var_in%ks) /= (var%ke-var%ks))&
  1966           & 
call mpp_error(fatal, 
"CT_increment_data_3d: There is a k-direction computational domain size mismatch.")
  1967       if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  1968           & 
call mpp_error(fatal, 
"CT_increment_data_3d: Excessive i-direction halo size for the input structure.")
  1969       if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  1970           & 
call mpp_error(fatal, 
"CT_increment_data_3d: Excessive j-direction halo size for the input structure.")
  1971       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  1972           & 
call mpp_error(fatal, 
"CT_increment_data_3d: Excessive i-direction halo size for the output structure.")
  1973       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  1974           & 
call mpp_error(fatal, 
"CT_increment_data_3d: Excessive j-direction halo size for the output structure.")
  1976       i_off = var_in%isc - var%isc
  1977       j_off = var_in%jsc - var%jsc
  1978       k_off = var_in%ks - var%ks
  1982       increment_bc = .true.
  1983       if (increment_bc .and. 
present(exclude_flux_type))&
  1984           & increment_bc = .not.(trim(var%bc(n)%flux_type) == trim(exclude_flux_type))
  1985       if (increment_bc .and. 
present(only_flux_type))&
  1986           & increment_bc = (trim(var%bc(n)%flux_type) == trim(only_flux_type))
  1987       if (increment_bc .and. 
present(pass_through_ice))&
  1988           & increment_bc = (pass_through_ice .eqv. var%bc(n)%pass_through_ice)
  1989       if (.not.increment_bc) cycle
  1991       do m = 1, var_in%bc(n)%num_fields
  1992         if (
present(field_index)) 
then  1993           if (m /= field_index) cycle
  1995         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  1997             do j=var%jsc-halo,var%jec+halo
  1998               do i=var%isc-halo,var%iec+halo
  1999                 var%bc(n)%field(m)%values(i,j,k) = sc_prev * var%bc(n)%field(m)%values(i,j,k) +&
  2000                     & scale * var_in%bc(n)%field(m)%values(i+i_off,j+j_off,k+k_off)
  2027       & scale_factor, scale_prev, exclude_flux_type, only_flux_type, pass_through_ice)
  2028     type(coupler_3d_bc_type),   
intent(in)    :: var_in
  2029     real, 
dimension(:,:,:),     
intent(in)    :: weights
  2033     type(coupler_2d_bc_type),   
intent(inout) :: var
  2034     integer,          
optional, 
intent(in)    :: halo_size
  2035     integer,          
optional, 
intent(in)    :: bc_index
  2037     integer,          
optional, 
intent(in)    :: field_index
  2039     real,             
optional, 
intent(in)    :: scale_factor
  2040     real,             
optional, 
intent(in)    :: scale_prev
  2041     character(len=*), 
optional, 
intent(in)    :: exclude_flux_type
  2043     character(len=*), 
optional, 
intent(in)    :: only_flux_type
  2045     logical,          
optional, 
intent(in)    :: pass_through_ice
  2048     real :: scale, sc_prev
  2049     logical :: increment_bc
  2050     integer :: i, j, k, m, n, n1, n2, halo
  2051     integer :: io1, jo1, iow, jow, kow  
  2054     if (
present(scale_factor)) scale = scale_factor
  2056     if (
present(scale_prev)) sc_prev = scale_prev
  2058     if (
present(bc_index)) 
then  2059       if (bc_index > var_in%num_bcs)&
  2060           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: bc_index is present and exceeds var_in%num_bcs.")
  2061       if (
present(field_index)) 
then ; 
if (field_index > var_in%bc(bc_index)%num_fields)&
  2062           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: field_index is present and exceeds num_fields for" //&
  2063           & trim(var_in%bc(bc_index)%name) )
  2065     elseif (
present(field_index)) 
then  2066       call mpp_error(fatal, 
"CT_increment_data_2d_3d: bc_index must be present if field_index is present.")
  2070     if (
present(halo_size)) halo = halo_size
  2074     if (
present(bc_index)) 
then  2081       if ((var_in%iec-var_in%isc) /= (var%iec-var%isc))&
  2082           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: There is an i-direction computational domain size mismatch.")
  2083       if ((var_in%jec-var_in%jsc) /= (var%jec-var%jsc))&
  2084           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: There is a j-direction computational domain size mismatch.")
  2085       if ((1+var_in%ke-var_in%ks) /= 
size(weights,3))&
  2086           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: There is a k-direction size mismatch with the weights array.")
  2087       if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  2088           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: Excessive i-direction halo size for the input structure.")
  2089       if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  2090           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: Excessive j-direction halo size for the input structure.")
  2091       if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  2092           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: Excessive i-direction halo size for the output structure.")
  2093       if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  2094           & 
call mpp_error(fatal, 
"CT_increment_data_2d_3d: Excessive j-direction halo size for the output structure.")
  2096       if ((1+var%iec-var%isc) == 
size(weights,1)) 
then  2098       elseif ((1+var%ied-var%isd) == 
size(weights,1)) 
then  2100       elseif ((1+var_in%ied-var_in%isd) == 
size(weights,1)) 
then  2101         iow = 1 + (var_in%isc - var_in%isd) - var%isc
  2103         call mpp_error(fatal, 
"CT_increment_data_2d_3d: weights array must be the i-size of a computational or data domain.")
  2105       if ((1+var%jec-var%jsc) == 
size(weights,2)) 
then  2107       elseif ((1+var%jed-var%jsd) == 
size(weights,2)) 
then  2109       elseif ((1+var_in%jed-var_in%jsd) == 
size(weights,2)) 
then  2110         jow = 1 + (var_in%jsc - var_in%jsd) - var%jsc
  2112         call mpp_error(fatal, 
"CT_increment_data_2d_3d: weights array must be the j-size of a computational or data domain.")
  2115       io1 = var_in%isc - var%isc
  2116       jo1 = var_in%jsc - var%jsc
  2121       increment_bc = .true.
  2122       if (increment_bc .and. 
present(exclude_flux_type))&
  2123           & increment_bc = .not.(trim(var_in%bc(n)%flux_type) == trim(exclude_flux_type))
  2124       if (increment_bc .and. 
present(only_flux_type))&
  2125           & increment_bc = (trim(var_in%bc(n)%flux_type) == trim(only_flux_type))
  2126       if (increment_bc .and. 
present(pass_through_ice))&
  2127           & increment_bc = (pass_through_ice .eqv. var_in%bc(n)%pass_through_ice)
  2128       if (.not.increment_bc) cycle
  2130       do m = 1, var_in%bc(n)%num_fields
  2131         if (
present(field_index)) 
then  2132           if (m /= field_index) cycle
  2134         if ( 
associated(var%bc(n)%field(m)%values) ) 
then  2135           do k=var_in%ks,var_in%ke
  2136             do j=var%jsc-halo,var%jec+halo
  2137               do i=var%isc-halo,var%iec+halo
  2138                 var%bc(n)%field(m)%values(i,j) = sc_prev * var%bc(n)%field(m)%values(i,j) +&
  2139                     & (scale * weights(i+iow,j+jow,k+kow)) * var_in%bc(n)%field(m)%values(i+io1,j+io1,k)
  2165       & scale_factor, halo_size, idim, jdim)
  2166     type(coupler_2d_bc_type),   
intent(in)    :: var_in
  2167     integer,                    
intent(in)    :: bc_index
  2169     integer,                    
intent(in)    :: field_index
  2171     real, 
dimension(1:,1:),     
intent(out)   :: array_out
  2174     real,             
optional, 
intent(in)    :: scale_factor
  2175     integer,          
optional, 
intent(in)    :: halo_size
  2176     integer, 
dimension(4), 
optional, 
intent(in) :: idim
  2179     integer, 
dimension(4), 
optional, 
intent(in) :: jdim
  2183     character(len=*), 
parameter :: error_header =&
  2184         & 
'==>Error from coupler_types_mod (CT_extract_data_2d):'  2185     character(len=400)      :: error_msg
  2188     integer :: i, j, halo, i_off, j_off
  2190     if (bc_index <= 0) 
then  2191       array_out(:,:) = 0.0
  2196     if (
present(halo_size)) halo = halo_size
  2198     if (
present(scale_factor)) scale = scale_factor
  2200     if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  2201         & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the input structure.")
  2202     if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  2203         & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the input structure.")
  2205     if (bc_index > var_in%num_bcs)&
  2206         & 
call mpp_error(fatal, trim(error_header)//
" bc_index exceeds var_in%num_bcs.")
  2207     if (field_index > var_in%bc(bc_index)%num_fields)&
  2208         & 
call mpp_error(fatal, trim(error_header)//
" field_index exceeds num_fields for" //&
  2209         & trim(var_in%bc(bc_index)%name) )
  2212     if (
present(idim)) 
then  2213       if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  2214         write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  2217       if (
size(array_out,1) /= (1+idim(4)-idim(1))) 
then  2218         write (error_msg, *) trim(error_header), 
' The declared i-dimension size of ',&
  2219             & (1+idim(4)-idim(1)), 
' does not match the actual size of ', 
size(array_out,1)
  2222       if ((var_in%iec-var_in%isc) /= (idim(3)-idim(2)))&
  2223           & 
call mpp_error(fatal, trim(error_header)//
" There is an i-direction computational domain size mismatch.")
  2224       if ((idim(2)-idim(1) < halo) .or. (idim(4)-idim(3) < halo))&
  2225           & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the output array.")
  2226       if (
size(array_out,1) < 2*halo + 1 + var_in%iec - var_in%isc) 
then  2227         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2228             & (1+idim(4)-idim(1)), 
' is too small to match the data of size ',&
  2229             & (2*halo + 1 + var_in%iec - var_in%isc)
  2233       i_off = (1-idim(1)) + (idim(2)-var_in%isc)
  2235       if (
size(array_out,1) < 2*halo + 1 + var_in%iec - var_in%isc) 
then  2236         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2237             & 
size(array_out,1), 
' does not match the data of size ',&
  2238             & (2*halo + 1 + var_in%iec - var_in%isc)
  2241       i_off = 1 - (var_in%isc-halo)
  2245     if (
present(jdim)) 
then  2246       if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  2247         write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list ', jdim
  2250       if (
size(array_out,2) /= (1+jdim(4)-jdim(1))) 
then  2251         write (error_msg, *) trim(error_header), 
' The declared j-dimension size of ',&
  2252             & (1+jdim(4)-jdim(1)), 
' does not match the actual size of ', 
size(array_out,2)
  2255       if ((var_in%jec-var_in%jsc) /= (jdim(3)-jdim(2)))&
  2256           & 
call mpp_error(fatal, trim(error_header)//
" There is an j-direction computational domain size mismatch.")
  2257       if ((jdim(2)-jdim(1) < halo) .or. (jdim(4)-jdim(3) < halo))&
  2258           & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the output array.")
  2259       if (
size(array_out,2) < 2*halo + 1 + var_in%jec - var_in%jsc) 
then  2260         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2261             & (1+jdim(4)-jdim(1)), 
' is too small to match the data of size ',&
  2262             & (2*halo + 1 + var_in%jec - var_in%jsc)
  2266       j_off = (1-jdim(1)) + (jdim(2)-var_in%jsc)
  2268       if (
size(array_out,2) < 2*halo + 1 + var_in%jec - var_in%jsc) 
then  2269         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2270             & 
size(array_out,2), 
' does not match the data of size ',&
  2271             & (2*halo + 1 + var_in%jec - var_in%jsc)
  2274       j_off = 1 - (var_in%jsc-halo)
  2277     do j=var_in%jsc-halo,var_in%jec+halo
  2278       do i=var_in%isc-halo,var_in%iec+halo
  2279         array_out(i+i_off,j+j_off) = scale * var_in%bc(bc_index)%field(field_index)%values(i,j)
  2302       & scale_factor, halo_size, idim, jdim)
  2303     type(coupler_3d_bc_type),   
intent(in)    :: var_in
  2304     integer,                    
intent(in)    :: bc_index
  2306     integer,                    
intent(in)    :: field_index
  2308     integer,                    
intent(in)    :: k_in
  2309     real, 
dimension(1:,1:),     
intent(out)   :: array_out
  2312     real,             
optional, 
intent(in)    :: scale_factor
  2313     integer,          
optional, 
intent(in)    :: halo_size
  2314     integer, 
dimension(4), 
optional, 
intent(in) :: idim
  2317     integer, 
dimension(4), 
optional, 
intent(in) :: jdim
  2320     character(len=*), 
parameter :: error_header =&
  2321         & 
'==>Error from coupler_types_mod (CT_extract_data_3d_2d):'  2322     character(len=400)      :: error_msg
  2325     integer :: i, j, k, halo, i_off, j_off
  2327     if (bc_index <= 0) 
then  2328       array_out(:,:) = 0.0
  2333     if (
present(halo_size)) halo = halo_size
  2335     if (
present(scale_factor)) scale = scale_factor
  2337     if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  2338         & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the input structure.")
  2339     if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  2340         & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the input structure.")
  2342     if (bc_index > var_in%num_bcs)&
  2343         & 
call mpp_error(fatal, trim(error_header)//
" bc_index exceeds var_in%num_bcs.")
  2344     if (field_index > var_in%bc(bc_index)%num_fields)&
  2345         & 
call mpp_error(fatal, trim(error_header)//
" field_index exceeds num_fields for" //&
  2346         & trim(var_in%bc(bc_index)%name) )
  2349     if (
present(idim)) 
then  2350       if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  2351         write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  2354       if (
size(array_out,1) /= (1+idim(4)-idim(1))) 
then  2355         write (error_msg, *) trim(error_header), 
' The declared i-dimension size of ',&
  2356             & (1+idim(4)-idim(1)), 
' does not match the actual size of ', 
size(array_out,1)
  2359       if ((var_in%iec-var_in%isc) /= (idim(3)-idim(2)))&
  2360           & 
call mpp_error(fatal, trim(error_header)//
" There is an i-direction computational domain size mismatch.")
  2361       if ((idim(2)-idim(1) < halo) .or. (idim(4)-idim(3) < halo))&
  2362           & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the output array.")
  2363       if (
size(array_out,1) < 2*halo + 1 + var_in%iec - var_in%isc) 
then  2364         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2365             & (1+idim(4)-idim(1)), 
' is too small to match the data of size ',&
  2366             & (2*halo + 1 + var_in%iec - var_in%isc)
  2370       i_off = (1-idim(1)) + (idim(2)-var_in%isc)
  2372       if (
size(array_out,1) < 2*halo + 1 + var_in%iec - var_in%isc) 
then  2373         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2374             & 
size(array_out,1), 
' does not match the data of size ',&
  2375             & (2*halo + 1 + var_in%iec - var_in%isc)
  2378       i_off = 1 - (var_in%isc-halo)
  2382     if (
present(jdim)) 
then  2383       if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  2384         write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list ', jdim
  2387       if (
size(array_out,2) /= (1+jdim(4)-jdim(1))) 
then  2388         write (error_msg, *) trim(error_header), 
' The declared j-dimension size of ',&
  2389             & (1+jdim(4)-jdim(1)), 
' does not match the actual size of ', 
size(array_out,2)
  2392       if ((var_in%jec-var_in%jsc) /= (jdim(3)-jdim(2)))&
  2393           & 
call mpp_error(fatal, trim(error_header)//
" There is an j-direction computational domain size mismatch.")
  2394       if ((jdim(2)-jdim(1) < halo) .or. (jdim(4)-jdim(3) < halo))&
  2395           & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the output array.")
  2396       if (
size(array_out,2) < 2*halo + 1 + var_in%jec - var_in%jsc) 
then  2397         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2398             & (1+jdim(4)-jdim(1)), 
' is too small to match the data of size ',&
  2399             & (2*halo + 1 + var_in%jec - var_in%jsc)
  2403       j_off = (1-jdim(1)) + (jdim(2)-var_in%jsc)
  2405       if (
size(array_out,2) < 2*halo + 1 + var_in%jec - var_in%jsc) 
then  2406         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2407             & 
size(array_out,2), 
' does not match the data of size ',&
  2408             & (2*halo + 1 + var_in%jec - var_in%jsc)
  2411       j_off = 1 - (var_in%jsc-halo)
  2414     if ((k_in > var_in%ke) .or. (k_in < var_in%ks)) 
then  2415       write (error_msg, *) trim(error_header), 
' The extracted k-index of ', k_in,&
  2416           & 
' is outside of the valid range of ', var_in%ks, 
' to ', var_in%ke
  2420     do j=var_in%jsc-halo,var_in%jec+halo
  2421       do i=var_in%isc-halo,var_in%iec+halo
  2422         array_out(i+i_off,j+j_off) = scale * var_in%bc(bc_index)%field(field_index)%values(i,j,k_in)
  2445       & scale_factor, halo_size, idim, jdim)
  2446     type(coupler_3d_bc_type),   
intent(in)    :: var_in
  2447     integer,                    
intent(in)    :: bc_index
  2449     integer,                    
intent(in)    :: field_index
  2451     real, 
dimension(1:,1:,1:),  
intent(out)   :: array_out
  2454     real,             
optional, 
intent(in)    :: scale_factor
  2455     integer,          
optional, 
intent(in)    :: halo_size
  2456     integer, 
dimension(4), 
optional, 
intent(in) :: idim
  2459     integer, 
dimension(4), 
optional, 
intent(in) :: jdim
  2463     character(len=*), 
parameter :: error_header =&
  2464         & 
'==>Error from coupler_types_mod (CT_extract_data_3d):'  2465     character(len=400) :: error_msg
  2468     integer :: i, j, k, halo, i_off, j_off, k_off
  2470     if (bc_index <= 0) 
then  2471       array_out(:,:,:) = 0.0
  2476     if (
present(halo_size)) halo = halo_size
  2478     if (
present(scale_factor)) scale = scale_factor
  2480     if ((var_in%isc-var_in%isd < halo) .or. (var_in%ied-var_in%iec < halo))&
  2481         & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the input structure.")
  2482     if ((var_in%jsc-var_in%jsd < halo) .or. (var_in%jed-var_in%jec < halo))&
  2483         & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the input structure.")
  2485     if (bc_index > var_in%num_bcs)&
  2486         & 
call mpp_error(fatal, trim(error_header)//
" bc_index exceeds var_in%num_bcs.")
  2487     if (field_index > var_in%bc(bc_index)%num_fields)&
  2488         & 
call mpp_error(fatal, trim(error_header)//
" field_index exceeds num_fields for" //&
  2489         & trim(var_in%bc(bc_index)%name) )
  2492     if (
present(idim)) 
then  2493       if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  2494         write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  2497       if (
size(array_out,1) /= (1+idim(4)-idim(1))) 
then  2498         write (error_msg, *) trim(error_header), 
' The declared i-dimension size of ',&
  2499             & (1+idim(4)-idim(1)), 
' does not match the actual size of ', 
size(array_out,1)
  2502       if ((var_in%iec-var_in%isc) /= (idim(3)-idim(2)))&
  2503           & 
call mpp_error(fatal, trim(error_header)//
" There is an i-direction computational domain size mismatch.")
  2504       if ((idim(2)-idim(1) < halo) .or. (idim(4)-idim(3) < halo))&
  2505           & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the output array.")
  2506       if (
size(array_out,1) < 2*halo + 1 + var_in%iec - var_in%isc) 
then  2507         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2508             & (1+idim(4)-idim(1)), 
' is too small to match the data of size ',&
  2509             & (2*halo + 1 + var_in%iec - var_in%isc)
  2513       i_off = (1-idim(1)) + (idim(2)-var_in%isc)
  2515       if (
size(array_out,1) < 2*halo + 1 + var_in%iec - var_in%isc) 
then  2516         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2517             & 
size(array_out,1), 
' does not match the data of size ',&
  2518             & (2*halo + 1 + var_in%iec - var_in%isc)
  2521       i_off = 1 - (var_in%isc-halo)
  2525     if (
present(jdim)) 
then  2526       if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  2527         write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list ', jdim
  2530       if (
size(array_out,2) /= (1+jdim(4)-jdim(1))) 
then  2531         write (error_msg, *) trim(error_header), 
' The declared j-dimension size of ',&
  2532             & (1+jdim(4)-jdim(1)), 
' does not match the actual size of ', 
size(array_out,2)
  2535       if ((var_in%jec-var_in%jsc) /= (jdim(3)-jdim(2)))&
  2536           & 
call mpp_error(fatal, trim(error_header)//
" There is an j-direction computational domain size mismatch.")
  2537       if ((jdim(2)-jdim(1) < halo) .or. (jdim(4)-jdim(3) < halo))&
  2538           & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the output array.")
  2539       if (
size(array_out,2) < 2*halo + 1 + var_in%jec - var_in%jsc) 
then  2540         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2541             & (1+jdim(4)-jdim(1)), 
' is too small to match the data of size ',&
  2542             & (2*halo + 1 + var_in%jec - var_in%jsc)
  2546       j_off = (1-jdim(1)) + (jdim(2)-var_in%jsc)
  2548       if (
size(array_out,2) < 2*halo + 1 + var_in%jec - var_in%jsc) 
then  2549         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2550             & 
size(array_out,2), 
' does not match the data of size ',&
  2551             & (2*halo + 1 + var_in%jec - var_in%jsc)
  2554       j_off = 1 - (var_in%jsc-halo)
  2557     if (
size(array_out,3) /= 1 + var_in%ke - var_in%ks) 
then  2558       write (error_msg, *) trim(error_header), 
' The target array with k-dimension size ',&
  2559           & 
size(array_out,3), 
' does not match the data of size ',&
  2560           & (1 + var_in%ke - var_in%ks)
  2563     k_off = 1 - var_in%ks
  2565     do k=var_in%ks,var_in%ke
  2566       do j=var_in%jsc-halo,var_in%jec+halo
  2567         do i=var_in%isc-halo,var_in%iec+halo
  2568           array_out(i+i_off,j+j_off,k+k_off) = scale * var_in%bc(bc_index)%field(field_index)%values(i,j,k)
  2591       & scale_factor, halo_size, idim, jdim)
  2592     real, 
dimension(1:,1:),     
intent(in)   :: array_in
  2595     integer,                    
intent(in)    :: bc_index
  2597     integer,                    
intent(in)    :: field_index
  2599     type(coupler_2d_bc_type),   
intent(inout) :: var
  2600     real,             
optional, 
intent(in)    :: scale_factor
  2601     integer,          
optional, 
intent(in)    :: halo_size
  2602     integer, 
dimension(4), 
optional, 
intent(in) :: idim
  2605     integer, 
dimension(4), 
optional, 
intent(in) :: jdim
  2608     character(len=*), 
parameter :: error_header =&
  2609         & 
'==>Error from coupler_types_mod (CT_set_data_2d):'  2610     character(len=400) :: error_msg
  2613     integer :: i, j, halo, i_off, j_off
  2615     if (bc_index <= 0) 
return  2618     if (
present(halo_size)) halo = halo_size
  2620     if (
present(scale_factor)) scale = scale_factor
  2622     if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  2623         & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the input structure.")
  2624     if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  2625         & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the input structure.")
  2627     if (bc_index > var%num_bcs) &
  2628         call mpp_error(fatal, trim(error_header)//
" bc_index exceeds var%num_bcs.")
  2629     if (field_index > var%bc(bc_index)%num_fields)&
  2630         & 
call mpp_error(fatal, trim(error_header)//
" field_index exceeds num_fields for" //&
  2631         & trim(var%bc(bc_index)%name) )
  2634     if (
present(idim)) 
then  2635       if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  2636         write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  2639       if (
size(array_in,1) /= (1+idim(4)-idim(1))) 
then  2640         write (error_msg, *) trim(error_header), 
' The declared i-dimension size of ',&
  2641             & (1+idim(4)-idim(1)), 
' does not match the actual size of ', 
size(array_in,1)
  2644       if ((var%iec-var%isc) /= (idim(3)-idim(2)))&
  2645           & 
call mpp_error(fatal, trim(error_header)//
" There is an i-direction computational domain size mismatch.")
  2646       if ((idim(2)-idim(1) < halo) .or. (idim(4)-idim(3) < halo))&
  2647           & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the output array.")
  2648       if (
size(array_in,1) < 2*halo + 1 + var%iec - var%isc) 
then  2649         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2650             & (1+idim(4)-idim(1)), 
' is too small to match the data of size ',&
  2651             & (2*halo + 1 + var%iec - var%isc)
  2655       i_off = (1-idim(1)) + (idim(2)-var%isc)
  2657       if (
size(array_in,1) < 2*halo + 1 + var%iec - var%isc) 
then  2658         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2659             & 
size(array_in,1), 
' does not match the data of size ',&
  2660             & (2*halo + 1 + var%iec - var%isc)
  2663       i_off = 1 - (var%isc-halo)
  2667     if (
present(jdim)) 
then  2668       if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  2669         write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list ', jdim
  2672       if (
size(array_in,2) /= (1+jdim(4)-jdim(1))) 
then  2673         write (error_msg, *) trim(error_header), 
' The declared j-dimension size of ',&
  2674             & (1+jdim(4)-jdim(1)), 
' does not match the actual size of ', 
size(array_in,2)
  2677       if ((var%jec-var%jsc) /= (jdim(3)-jdim(2)))&
  2678           & 
call mpp_error(fatal, trim(error_header)//
" There is an j-direction computational domain size mismatch.")
  2679       if ((jdim(2)-jdim(1) < halo) .or. (jdim(4)-jdim(3) < halo))&
  2680           & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the output array.")
  2681       if (
size(array_in,2) < 2*halo + 1 + var%jec - var%jsc) 
then  2682         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2683             & (1+jdim(4)-jdim(1)), 
' is too small to match the data of size ',&
  2684             & (2*halo + 1 + var%jec - var%jsc)
  2688       j_off = (1-jdim(1)) + (jdim(2)-var%jsc)
  2690       if (
size(array_in,2) < 2*halo + 1 + var%jec - var%jsc) 
then  2691         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2692             & 
size(array_in,2), 
' does not match the data of size ',&
  2693             & (2*halo + 1 + var%jec - var%jsc)
  2696       j_off = 1 - (var%jsc-halo)
  2699     do j=var%jsc-halo,var%jec+halo
  2700       do i=var%isc-halo,var%iec+halo
  2701         var%bc(bc_index)%field(field_index)%values(i,j) = scale * array_in(i+i_off,j+j_off)
  2725       & scale_factor, halo_size, idim, jdim)
  2726     real, 
dimension(1:,1:),     
intent(in)    :: array_in
  2729     integer,                    
intent(in)    :: bc_index
  2731     integer,                    
intent(in)    :: field_index
  2733     integer,                    
intent(in)    :: k_out
  2734     type(coupler_3d_bc_type),   
intent(inout) :: var
  2735     real,             
optional, 
intent(in)    :: scale_factor
  2736     integer,          
optional, 
intent(in)    :: halo_size
  2737     integer, 
dimension(4), 
optional, 
intent(in) :: idim
  2740     integer, 
dimension(4), 
optional, 
intent(in) :: jdim
  2744     character(len=*), 
parameter :: error_header =&
  2745         & 
'==>Error from coupler_types_mod (CT_set_data_3d_2d):'  2746     character(len=400)      :: error_msg
  2749     integer :: i, j, halo, i_off, j_off
  2751     if (bc_index <= 0) 
return  2754     if (
present(halo_size)) halo = halo_size
  2756     if (
present(scale_factor)) scale = scale_factor
  2758     if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  2759         & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the input structure.")
  2760     if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  2761         & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the input structure.")
  2763     if (bc_index > var%num_bcs)&
  2764         & 
call mpp_error(fatal, trim(error_header)//
" bc_index exceeds var%num_bcs.")
  2765     if (field_index > var%bc(bc_index)%num_fields)&
  2766         & 
call mpp_error(fatal, trim(error_header)//
" field_index exceeds num_fields for" //&
  2767         & trim(var%bc(bc_index)%name) )
  2770     if (
present(idim)) 
then  2771       if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  2772         write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  2775       if (
size(array_in,1) /= (1+idim(4)-idim(1))) 
then  2776         write (error_msg, *) trim(error_header), 
' The declared i-dimension size of ',&
  2777             & (1+idim(4)-idim(1)), 
' does not match the actual size of ', 
size(array_in,1)
  2780       if ((var%iec-var%isc) /= (idim(3)-idim(2)))&
  2781           & 
call mpp_error(fatal, trim(error_header)//
" There is an i-direction computational domain size mismatch.")
  2782       if ((idim(2)-idim(1) < halo) .or. (idim(4)-idim(3) < halo))&
  2783           & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the output array.")
  2784       if (
size(array_in,1) < 2*halo + 1 + var%iec - var%isc) 
then  2785         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2786             & (1+idim(4)-idim(1)), 
' is too small to match the data of size ',&
  2787             & (2*halo + 1 + var%iec - var%isc)
  2791       i_off = (1-idim(1)) + (idim(2)-var%isc)
  2793       if (
size(array_in,1) < 2*halo + 1 + var%iec - var%isc) 
then  2794         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2795             & 
size(array_in,1), 
' does not match the data of size ',&
  2796             & (2*halo + 1 + var%iec - var%isc)
  2799       i_off = 1 - (var%isc-halo)
  2803     if (
present(jdim)) 
then  2804       if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  2805         write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list ', jdim
  2808       if (
size(array_in,2) /= (1+jdim(4)-jdim(1))) 
then  2809         write (error_msg, *) trim(error_header), 
' The declared j-dimension size of ',&
  2810             & (1+jdim(4)-jdim(1)), 
' does not match the actual size of ', 
size(array_in,2)
  2813       if ((var%jec-var%jsc) /= (jdim(3)-jdim(2)))&
  2814           & 
call mpp_error(fatal, trim(error_header)//
" There is an j-direction computational domain size mismatch.")
  2815       if ((jdim(2)-jdim(1) < halo) .or. (jdim(4)-jdim(3) < halo))&
  2816           & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the output array.")
  2817       if (
size(array_in,2) < 2*halo + 1 + var%jec - var%jsc) 
then  2818         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2819             & (1+jdim(4)-jdim(1)), 
' is too small to match the data of size ',&
  2820             & (2*halo + 1 + var%jec - var%jsc)
  2824       j_off = (1-jdim(1)) + (jdim(2)-var%jsc)
  2826       if (
size(array_in,2) < 2*halo + 1 + var%jec - var%jsc) 
then  2827         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2828             & 
size(array_in,2), 
' does not match the data of size ',&
  2829             & (2*halo + 1 + var%jec - var%jsc)
  2832       j_off = 1 - (var%jsc-halo)
  2835     if ((k_out > var%ke) .or. (k_out < var%ks)) 
then  2836       write (error_msg, *) trim(error_header), 
' The k-index of ', k_out,&
  2837           & 
' is outside of the valid range of ', var%ks, 
' to ', var%ke
  2841     do j=var%jsc-halo,var%jec+halo
  2842       do i=var%isc-halo,var%iec+halo
  2843         var%bc(bc_index)%field(field_index)%values(i,j,k_out) = scale * array_in(i+i_off,j+j_off)
  2866       & scale_factor, halo_size, idim, jdim)
  2867     real, 
dimension(1:,1:,1:),  
intent(in)    :: array_in
  2870     integer,                    
intent(in)    :: bc_index
  2872     integer,                    
intent(in)    :: field_index
  2874     type(coupler_3d_bc_type),   
intent(inout) :: var
  2875     real,             
optional, 
intent(in)    :: scale_factor
  2876     integer,          
optional, 
intent(in)    :: halo_size
  2877     integer, 
dimension(4), 
optional, 
intent(in) :: idim
  2880     integer, 
dimension(4), 
optional, 
intent(in) :: jdim
  2884     character(len=*), 
parameter :: error_header =&
  2885         & 
'==>Error from coupler_types_mod (CT_set_data_3d):'  2886     character(len=400) :: error_msg
  2889     integer :: i, j, k, halo, i_off, j_off, k_off
  2891     if (bc_index <= 0) 
return  2894     if (
present(halo_size)) halo = halo_size
  2896     if (
present(scale_factor)) scale = scale_factor
  2898     if ((var%isc-var%isd < halo) .or. (var%ied-var%iec < halo))&
  2899         & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the input structure.")
  2900     if ((var%jsc-var%jsd < halo) .or. (var%jed-var%jec < halo))&
  2901         & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the input structure.")
  2903     if (bc_index > var%num_bcs)&
  2904         & 
call mpp_error(fatal, trim(error_header)//
" bc_index exceeds var%num_bcs.")
  2905     if (field_index > var%bc(bc_index)%num_fields)&
  2906         & 
call mpp_error(fatal, trim(error_header)//
" field_index exceeds num_fields for" //&
  2907         & trim(var%bc(bc_index)%name) )
  2910     if (
present(idim)) 
then  2911       if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) 
then  2912         write (error_msg, *) trim(error_header), 
' Disordered i-dimension index bound list ', idim
  2915       if (
size(array_in,1) /= (1+idim(4)-idim(1))) 
then  2916         write (error_msg, *) trim(error_header), 
' The declared i-dimension size of ',&
  2917             & (1+idim(4)-idim(1)), 
' does not match the actual size of ', 
size(array_in,1)
  2920       if ((var%iec-var%isc) /= (idim(3)-idim(2)))&
  2921           & 
call mpp_error(fatal, trim(error_header)//
" There is an i-direction computational domain size mismatch.")
  2922       if ((idim(2)-idim(1) < halo) .or. (idim(4)-idim(3) < halo))&
  2923           & 
call mpp_error(fatal, trim(error_header)//
" Excessive i-direction halo size for the output array.")
  2924       if (
size(array_in,1) < 2*halo + 1 + var%iec - var%isc) 
then  2925         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2926             & (1+idim(4)-idim(1)), 
' is too small to match the data of size ',&
  2927             & (2*halo + 1 + var%iec - var%isc)
  2931       i_off = (1-idim(1)) + (idim(2)-var%isc)
  2933       if (
size(array_in,1) < 2*halo + 1 + var%iec - var%isc) 
then  2934         write (error_msg, *) trim(error_header), 
' The target array with i-dimension size ',&
  2935             & 
size(array_in,1), 
' does not match the data of size ',&
  2936             & (2*halo + 1 + var%iec - var%isc)
  2939       i_off = 1 - (var%isc-halo)
  2943     if (
present(jdim)) 
then  2944       if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) 
then  2945         write (error_msg, *) trim(error_header), 
' Disordered j-dimension index bound list ', jdim
  2948       if (
size(array_in,2) /= (1+jdim(4)-jdim(1))) 
then  2949         write (error_msg, *) trim(error_header), 
' The declared j-dimension size of ',&
  2950             & (1+jdim(4)-jdim(1)), 
' does not match the actual size of ', 
size(array_in,2)
  2953       if ((var%jec-var%jsc) /= (jdim(3)-jdim(2)))&
  2954           & 
call mpp_error(fatal, trim(error_header)//
" There is an j-direction computational domain size mismatch.")
  2955       if ((jdim(2)-jdim(1) < halo) .or. (jdim(4)-jdim(3) < halo))&
  2956           & 
call mpp_error(fatal, trim(error_header)//
" Excessive j-direction halo size for the output array.")
  2957       if (
size(array_in,2) < 2*halo + 1 + var%jec - var%jsc) 
then  2958         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2959             & (1+jdim(4)-jdim(1)), 
' is too small to match the data of size ',&
  2960             & (2*halo + 1 + var%jec - var%jsc)
  2964       j_off = (1-jdim(1)) + (jdim(2)-var%jsc)
  2966       if (
size(array_in,2) < 2*halo + 1 + var%jec - var%jsc) 
then  2967         write (error_msg, *) trim(error_header), 
' The target array with j-dimension size ',&
  2968             & 
size(array_in,2), 
' does not match the data of size ',&
  2969             & (2*halo + 1 + var%jec - var%jsc)
  2972       j_off = 1 - (var%jsc-halo)
  2975     if (
size(array_in,3) /= 1 + var%ke - var%ks) 
then  2976       write (error_msg, *) trim(error_header), 
' The target array with k-dimension size ',&
  2977           & 
size(array_in,3), 
' does not match the data of size ',&
  2978           & (1 + var%ke - var%ks)
  2984       do j=var%jsc-halo,var%jec+halo
  2985         do i=var%isc-halo,var%iec+halo
  2986           var%bc(bc_index)%field(field_index)%values(i,j,k) = scale * array_in(i+i_off,j+j_off,k+k_off)
  2997     type(coupler_2d_bc_type), 
intent(inout) :: var
  2998     character(len=*),         
intent(in)    :: diag_name
  2999     integer, 
dimension(:),    
intent(in)    :: axes
  3000     type(time_type),          
intent(in)    :: time
  3004     if (diag_name == 
' ') 
return  3006     if (
size(axes) < 2) 
then  3007       call mpp_error(fatal, 
'==>Error from coupler_types_mod' //&
  3008           & 
'(coupler_types_set_diags_3d): axes has less than 2 elements')
  3011     do n = 1, var%num_bcs
  3012       do m = 1, var%bc(n)%num_fields
  3014             & var%bc(n)%field(m)%name, axes(1:2), time,&
  3015             & var%bc(n)%field(m)%long_name, var%bc(n)%field(m)%units)
  3024     type(coupler_3d_bc_type), 
intent(inout) :: var
  3025     character(len=*),         
intent(in)    :: diag_name
  3026     integer, 
dimension(:),    
intent(in)    :: axes
  3027     type(time_type),          
intent(in)    :: time
  3031     if (diag_name == 
' ') 
return  3033     if (
size(axes) < 3) 
then  3034       call mpp_error(fatal, 
'==>Error from coupler_types_mod' //&
  3035           & 
'(coupler_types_set_diags_3d): axes has less than 3 elements')
  3038     do n = 1, var%num_bcs
  3039       do m = 1, var%bc(n)%num_fields
  3041             & var%bc(n)%field(m)%name, axes(1:3), time,&
  3042             & var%bc(n)%field(m)%long_name, var%bc(n)%field(m)%units )
  3050     type(coupler_2d_bc_type), 
intent(in) :: var
  3051     type(time_type),          
intent(in) :: time
  3056     do n = 1, var%num_bcs
  3057       do m = 1, var%bc(n)%num_fields
  3058         if (var%bc(n)%field(m)%id_diag > 0) 
then  3059           used = 
send_data(var%bc(n)%field(m)%id_diag, var%bc(n)%field(m)%values, time)
  3067     type(coupler_3d_bc_type), 
intent(in) :: var
  3068     type(time_type),          
intent(in) :: time
  3073     do n = 1, var%num_bcs
  3074       do m = 1, var%bc(n)%num_fields
  3075         if (var%bc(n)%field(m)%id_diag > 0) 
then  3076           used = 
send_data(var%bc(n)%field(m)%id_diag, var%bc(n)%field(m)%values, time)
  3087     type(coupler_2d_bc_type), 
intent(inout) :: var
  3088     type(restart_file_type),  
dimension(:), 
pointer :: bc_rest_files
  3089     integer,                  
intent(out) :: num_rest_files
  3090     type(domain2D),           
intent(in)  :: mpp_domain
  3091     logical,        
optional, 
intent(in)  :: ocean_restart
  3093     character(len=80), 
dimension(max(1,var%num_bcs)) :: rest_file_names
  3094     character(len=80) :: file_nm
  3099     if (
present(ocean_restart)) ocn_rest = ocean_restart
  3103     do n = 1, var%num_bcs
  3104       if (var%bc(n)%num_fields <= 0) cycle
  3105       file_nm = trim(var%bc(n)%ice_restart_file)
  3106       if (ocn_rest) file_nm = trim(var%bc(n)%ocean_restart_file)
  3107       do f = 1, num_rest_files
  3108         if (trim(file_nm) == trim(rest_file_names(f))) 
exit  3110       if (f>num_rest_files) 
then  3111         num_rest_files = num_rest_files + 1
  3112         rest_file_names(f) = trim(file_nm)
  3116     if (num_rest_files == 0) 
return  3119     allocate(bc_rest_files(num_rest_files))
  3120     do n = 1, var%num_bcs
  3121       if (var%bc(n)%num_fields <= 0) cycle
  3123       file_nm = trim(var%bc(n)%ice_restart_file)
  3124       if (ocn_rest) file_nm = trim(var%bc(n)%ocean_restart_file)
  3125       do f = 1, num_rest_files
  3126         if (trim(file_nm) == trim(rest_file_names(f))) 
exit  3129       var%bc(n)%rest_type => bc_rest_files(f)
  3130       do m = 1, var%bc(n)%num_fields
  3132             & rest_file_names(f), var%bc(n)%field(m)%name, var%bc(n)%field(m)%values,&
  3133             & mpp_domain, mandatory=.not.var%bc(n)%field(m)%may_init )
  3143     type(coupler_2d_bc_type), 
intent(inout) :: var
  3144     character(len=*),         
intent(in)    :: file_name
  3145     type(restart_file_type),  
pointer       :: rest_file
  3146     type(domain2D),           
intent(in)    :: mpp_domain
  3147     character(len=*), 
optional, 
intent(in)  :: varname_prefix
  3152     character(len=128) :: var_name
  3156     if (.not.
associated(rest_file)) 
allocate(rest_file)
  3157     do n = 1, var%num_bcs
  3158       if (var%bc(n)%num_fields <= 0) cycle
  3160       var%bc(n)%rest_type => rest_file
  3161       do m = 1, var%bc(n)%num_fields
  3162         var_name = trim(var%bc(n)%field(m)%name)
  3163         if (
present(varname_prefix)) var_name = trim(varname_prefix)//trim(var_name)
  3165             & file_name, var_name, var%bc(n)%field(m)%values,&
  3166             & mpp_domain, mandatory=.not.var%bc(n)%field(m)%may_init )
  3176     type(coupler_3d_bc_type), 
intent(inout) :: var
  3177     type(restart_file_type),  
dimension(:), 
pointer :: bc_rest_files
  3178     integer,                  
intent(out)   :: num_rest_files
  3179     type(domain2D),           
intent(in)    :: mpp_domain
  3180     logical,        
optional, 
intent(in)    :: ocean_restart
  3182     character(len=80), 
dimension(max(1,var%num_bcs)) :: rest_file_names
  3183     character(len=80) :: file_nm
  3185     integer :: f, n, m, id_restart
  3188     if (
present(ocean_restart)) ocn_rest = ocean_restart
  3192     do n = 1, var%num_bcs
  3193       if (var%bc(n)%num_fields <= 0) cycle
  3194       file_nm = trim(var%bc(n)%ice_restart_file)
  3195       if (ocn_rest) file_nm = trim(var%bc(n)%ocean_restart_file)
  3196       do f = 1, num_rest_files
  3197         if (trim(file_nm) == trim(rest_file_names(f))) 
exit  3199       if (f>num_rest_files) 
then  3200         num_rest_files = num_rest_files + 1
  3201         rest_file_names(f) = trim(file_nm)
  3205     if (num_rest_files == 0) 
return  3208     allocate(bc_rest_files(num_rest_files))
  3209     do n = 1, var%num_bcs
  3210       if (var%bc(n)%num_fields <= 0) cycle
  3211       file_nm = trim(var%bc(n)%ice_restart_file)
  3212       if (ocn_rest) file_nm = trim(var%bc(n)%ocean_restart_file)
  3213       do f = 1, num_rest_files
  3214         if (trim(file_nm) == trim(rest_file_names(f))) 
exit  3217       var%bc(n)%rest_type => bc_rest_files(f)
  3218       do m = 1, var%bc(n)%num_fields
  3220             & rest_file_names(f), var%bc(n)%field(m)%name, var%bc(n)%field(m)%values,&
  3221             & mpp_domain, mandatory=.not.var%bc(n)%field(m)%may_init )
  3230     type(coupler_3d_bc_type), 
intent(inout) :: var
  3231     character(len=*),         
intent(in)  :: file_name
  3232     type(restart_file_type),  
pointer     :: rest_file
  3233     type(domain2D),           
intent(in)  :: mpp_domain
  3234     character(len=*), 
optional, 
intent(in)  :: varname_prefix
  3239     character(len=128) :: var_name
  3243     if (.not.
associated(rest_file)) 
allocate(rest_file)
  3244     do n = 1, var%num_bcs
  3245       if (var%bc(n)%num_fields <= 0) cycle
  3247       var%bc(n)%rest_type => rest_file
  3248       do m = 1, var%bc(n)%num_fields
  3249         var_name = trim(var%bc(n)%field(m)%name)
  3250         if (
present(varname_prefix)) var_name = trim(varname_prefix)//trim(var_name)
  3252             & file_name, var_name, var%bc(n)%field(m)%values,&
  3253             & mpp_domain, mandatory=.not.var%bc(n)%field(m)%may_init )
  3263   subroutine ct_restore_state_2d(var, directory, all_or_nothing, all_required, test_by_field)
  3264     type(coupler_2d_bc_type), 
intent(inout) :: var
  3265     character(len=*), 
optional, 
intent(in)  :: directory
  3267     logical,        
optional, 
intent(in)    :: all_or_nothing
  3270     logical,        
optional, 
intent(in)    :: all_required
  3273     logical,        
optional, 
intent(in)    :: test_by_field
  3276     integer :: n, m, num_fld
  3277     character(len=80) :: unset_varname
  3278     logical :: any_set, all_set, all_var_set, any_var_set, var_set
  3285     do n = 1, var%num_bcs
  3286       any_var_set = .false.
  3287       all_var_set = .true.
  3288       do m = 1, var%bc(n)%num_fields
  3290         if (var%bc(n)%field(m)%id_rest > 0) 
then  3292           if (.not.var_set) 
then  3293             call restore_state(var%bc(n)%rest_type, var%bc(n)%field(m)%id_rest,&
  3294                 & directory=directory, nonfatal_missing_files=.true.)
  3299         if (.not.var_set) unset_varname = trim(var%bc(n)%field(m)%name)
  3300         if (var_set) any_set = .true.
  3301         if (all_set) all_set = var_set
  3302         if (var_set) any_var_set = .true.
  3303         if (all_var_set) all_var_set = var_set
  3306       num_fld = num_fld + var%bc(n)%num_fields
  3307       if ((var%bc(n)%num_fields > 0) .and. 
present(test_by_field)) 
then  3308         if (test_by_field .and. (all_var_set .neqv. any_var_set)) 
call mpp_error(fatal,&
  3309             & 
"CT_restore_state_2d: test_by_field is true, and "//&
  3310             & trim(unset_varname)//
" was not read but some other fields in "//&
  3311             & trim(trim(var%bc(n)%name))//
" were.")
  3315     if ((num_fld > 0) .and. 
present(all_or_nothing)) 
then  3316       if (all_or_nothing .and. (all_set .neqv. any_set)) 
call mpp_error(fatal,&
  3317           & 
"CT_restore_state_2d: all_or_nothing is true, and "//&
  3318           & trim(unset_varname)//
" was not read but some other fields were.")
  3321     if (
present(all_required)) 
then  3322       if (all_required .and. .not.all_set) 
then  3323         call mpp_error(fatal, 
"CT_restore_state_2d: all_required is true, but "//&
  3324             & trim(unset_varname)//
" was not read from its restart file.")
  3333   subroutine ct_restore_state_3d(var, directory, all_or_nothing, all_required, test_by_field)
  3334     type(coupler_3d_bc_type), 
intent(inout) :: var
  3335     character(len=*), 
optional, 
intent(in)  :: directory
  3337     logical,        
optional, 
intent(in)    :: all_or_nothing
  3340     logical,        
optional, 
intent(in)    :: all_required
  3343     logical,        
optional, 
intent(in)    :: test_by_field
  3346     integer :: n, m, num_fld
  3347     character(len=80) :: unset_varname
  3348     logical :: any_set, all_set, all_var_set, any_var_set, var_set
  3355     do n = 1, var%num_bcs
  3356       any_var_set = .false.
  3357       all_var_set = .true.
  3358       do m = 1, var%bc(n)%num_fields
  3360         if (var%bc(n)%field(m)%id_rest > 0) 
then  3362           if (.not.var_set) 
then  3363             call restore_state(var%bc(n)%rest_type, var%bc(n)%field(m)%id_rest,&
  3364                 & directory=directory, nonfatal_missing_files=.true.)
  3369         if (.not.var_set) unset_varname = trim(var%bc(n)%field(m)%name)
  3371         if (var_set) any_set = .true.
  3372         if (all_set) all_set = var_set
  3373         if (var_set) any_var_set = .true.
  3374         if (all_var_set) all_var_set = var_set
  3377       num_fld = num_fld + var%bc(n)%num_fields
  3378       if ((var%bc(n)%num_fields > 0) .and. 
present(test_by_field)) 
then  3379         if (test_by_field .and. (all_var_set .neqv. any_var_set)) 
call mpp_error(fatal,&
  3380             & 
"CT_restore_state_3d: test_by_field is true, and "//&
  3381             & trim(unset_varname)//
" was not read but some other fields in "//&
  3382             & trim(trim(var%bc(n)%name))//
" were.")
  3386     if ((num_fld > 0) .and. 
present(all_or_nothing)) 
then  3387       if (all_or_nothing .and. (all_set .neqv. any_set)) 
call mpp_error(fatal,&
  3388           & 
"CT_restore_state_3d: all_or_nothing is true, and "//&
  3389           & trim(unset_varname)//
" was not read but some other fields were.")
  3392     if (
present(all_required)) 
then  3393       if (all_required .and. .not.all_set) 
then  3394         call mpp_error(fatal, 
"CT_restore_state_3d: all_required is true, but "//&
  3395             & trim(unset_varname)//
" was not read from its restart file.")
  3403     character(len=3),         
intent(in)    :: gridname
  3404     type(coupler_2d_bc_type), 
intent(inout) :: var
  3405     type(time_type),          
intent(in)    :: time
  3409     do n = 1, var%num_bcs
  3410       do m = 1, var%bc(n)%num_fields
  3411         call data_override(gridname, var%bc(n)%field(m)%name, var%bc(n)%field(m)%values, time)
  3418     character(len=3),         
intent(in)    :: gridname
  3419     type(coupler_3d_bc_type), 
intent(inout) :: var
  3420     type(time_type),          
intent(in)    :: time
  3424     do n = 1, var%num_bcs
  3425       do m = 1, var%bc(n)%num_fields
  3426         call data_override(gridname, var%bc(n)%field(m)%name, var%bc(n)%field(m)%values, time)
  3434     type(coupler_2d_bc_type),   
intent(in) :: var
  3435     integer,                    
intent(in) :: outunit
  3436     character(len=*), 
optional, 
intent(in) :: name_lead
  3438     character(len=120) :: var_name
  3441     do n = 1, var%num_bcs
  3442       do m = 1, var%bc(n)%num_fields
  3443         if (
present(name_lead)) 
then  3444           var_name = trim(name_lead)//trim(var%bc(n)%field(m)%name)
  3446           var_name = trim(var%bc(n)%field(m)%name)
  3448         write(outunit, 
'("   CHECKSUM:: ",A40," = ",Z20)') trim(var_name),&
  3449             & 
mpp_chksum(var%bc(n)%field(m)%values(var%isc:var%iec,var%jsc:var%jec) )
  3456     type(coupler_3d_bc_type),   
intent(in) :: var
  3457     integer,                    
intent(in) :: outunit
  3458     character(len=*), 
optional, 
intent(in) :: name_lead
  3460     character(len=120) :: var_name
  3463     do n = 1, var%num_bcs
  3464       do m = 1, var%bc(n)%num_fields
  3465         if (
present(name_lead)) 
then  3466           var_name = trim(name_lead)//trim(var%bc(n)%field(m)%name)
  3468           var_name = trim(var%bc(n)%field(m)%name)
  3470         write(outunit, 
'("   CHECKSUM:: ",A40," = ",Z20)') var_name,&
  3471             & 
mpp_chksum(var%bc(n)%field(m)%values(var%isc:var%iec,var%jsc:var%jec,:) )
  3500     type(coupler_1d_bc_type), 
intent(inout) :: var
  3504     if (var%num_bcs > 0) 
then  3505       do n = 1, var%num_bcs
  3506         do m = 1, var%bc(n)%num_fields
  3507           deallocate ( var%bc(n)%field(m)%values )
  3509         deallocate ( var%bc(n)%field )
  3511       deallocate ( var%bc )
  3520     type(coupler_2d_bc_type), 
intent(inout) :: var
  3524     if (var%num_bcs > 0) 
then  3525       do n = 1, var%num_bcs
  3526         do m = 1, var%bc(n)%num_fields
  3527           deallocate ( var%bc(n)%field(m)%values )
  3529         deallocate ( var%bc(n)%field )
  3531       deallocate ( var%bc )
  3540     type(coupler_3d_bc_type), 
intent(inout) :: var
  3544     if (var%num_bcs > 0) 
then  3545       do n = 1, var%num_bcs
  3546         do m = 1, var%bc(n)%num_fields
  3547           deallocate ( var%bc(n)%field(m)%values )
  3549         deallocate ( var%bc(n)%field )
  3551       deallocate ( var%bc )
 
subroutine ct_increment_data_3d_3d(var_in, var, halo_size, bc_index, field_index, scale_factor, scale_prev, exclude_flux_type, only_flux_type, pass_through_ice)
 
subroutine ct_redistribute_data_2d(var_in, domain_in, var_out, domain_out, complete)
Redistribute the data in all elements of a coupler_2d_bc_type. 
 
subroutine ct_send_data_3d(var, Time)
Write out all diagnostics of elements of a coupler_3d_bc_type. 
 
This is the interface to set diagnostics for the arrays in a coupler_bc_type. 
 
subroutine ct_extract_data_3d_2d(var_in, bc_index, field_index, k_in, array_out, scale_factor, halo_size, idim, jdim)
 
subroutine ct_set_diags_3d(var, diag_name, axes, time)
Register the diagnostics of a coupler_3d_bc_type. 
 
subroutine, public coupler_type_copy_1d_3d(var_in, var_out, is, ie, js, je, kd, diag_name, axes, time, suffix)
Copy fields from one coupler type to another. 1-D to 3-D version for generic coupler_type_copy. 
 
subroutine ct_register_restarts_to_file_2d(var, file_name, rest_file, mpp_domain, varname_prefix)
 
subroutine coupler_type_copy_3d_2d(var_in, var_out, is, ie, js, je, diag_name, axes, time, suffix)
Copy fields from one coupler type to another. 3-D to 2-D version for generic coupler_type_copy. 
 
subroutine ct_destructor_3d(var)
Deallocate all data associated with a coupler_3d_bc_type. 
 
subroutine ct_write_chksums_3d(var, outunit, name_lead)
Write out checksums for the elements of a coupler_3d_bc_type. 
 
This is the interface to rescale the field data in a coupler_bc_type. 
 
integer, public ind_csurf
The index of the ocean surface concentration. 
 
subroutine ct_data_override_3d(gridname, var, Time)
Potentially override the values in a coupler_3d_bc_type. 
 
character(len= *), parameter mod_name
 
subroutine ct_restore_state_3d(var, directory, all_or_nothing, all_required, test_by_field)
Read in fields from restart files into a coupler_3d_bc_type. 
 
subroutine ct_spawn_3d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
Generate one coupler type using another as a template. 3-D to 3-D version for generic CT_spawn...
 
subroutine, public coupler_type_copy_1d_2d(var_in, var_out, is, ie, js, je, diag_name, axes, time, suffix)
Copy fields from one coupler type to another. 1-D to 2-D version for generic coupler_type_copy. 
 
subroutine ct_extract_data_3d(var_in, bc_index, field_index, array_out, scale_factor, halo_size, idim, jdim)
Extract single 3d field from a coupler_3d_bc_type. 
 
logical function ct_initialized_1d(var)
Indicate whether a coupler_1d_bc_type has been initialized. 
 
integer, public ind_deposition
The index for the atmospheric deposition flux. 
 
subroutine ct_copy_data_2d(var_in, var, halo_size, bc_index, field_index, exclude_flux_type, only_flux_type, pass_through_ice)
Copy all elements of coupler_2d_bc_type. 
 
subroutine coupler_type_copy_3d_3d(var_in, var_out, is, ie, js, je, kd, diag_name, axes, time, suffix)
Copy fields from one coupler type to another. 3-D to 3-D version for generic coupler_type_copy. 
 
This is the interface to read in the fields in a coupler_bc_type that have been saved in restart file...
 
This is the interface to copy the field data from one coupler_bc_type to another of the same rank...
 
integer, public ind_alpha
The index of the solubility array for a tracer. 
 
subroutine ct_restore_state_2d(var, directory, all_or_nothing, all_required, test_by_field)
Reads in fields from restart files into a coupler_2d_bc_type. 
 
integer, public ind_kw
The index for the piston velocity. 
 
subroutine ct_data_override_2d(gridname, var, Time)
Potentially override the values in a coupler_2d_bc_type. 
 
This is the interface to increment the field data from one coupler_bc_type with the data from another...
 
subroutine coupler_type_copy_2d_2d(var_in, var_out, is, ie, js, je, diag_name, axes, time, suffix)
Copy fields from one coupler type to another. 2-D to 2-D version for generic coupler_type_copy. 
 
This is the interface to write out checksums for the elements of a coupler_bc_type. 
 
subroutine ct_spawn_1d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
Generate one coupler type using another as a template. 1-D to 3-D version for generic CT_spawn...
 
subroutine, public coupler_types_init
Initialize the coupler types. 
 
integer, public ind_sc_no
The index for the Schmidt number for a tracer flux. 
 
integer, public ind_deltap
The index for ocean-air gas partial pressure change. 
 
This is the interface to deallocate any data associated with a coupler_bc_type. 
 
subroutine ct_spawn_2d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
Generate one coupler type using another as a template. 2-D to 3-D version for generic CT_spawn...
 
subroutine ct_set_diags_2d(var, diag_name, axes, time)
 
subroutine ct_rescale_data_2d(var, scale, halo_size, bc_index, field_index, exclude_flux_type, only_flux_type, pass_through_ice)
Rescales the fields in the fields in the elements of a coupler_2d_bc_type. 
 
This is the interface to set a field in a coupler_bc_type from an array. 
 
subroutine coupler_type_copy_2d_3d(var_in, var_out, is, ie, js, je, kd, diag_name, axes, time, suffix)
Copy fields from one coupler type to another. 2-D to 3-D version for generic coupler_type_copy. 
 
integer, public ind_runoff
The index for a runoff flux. 
 
subroutine ct_rescale_data_3d(var, scale, halo_size, bc_index, field_index, exclude_flux_type, only_flux_type, pass_through_ice)
 
subroutine ct_copy_data_2d_3d(var_in, var, halo_size, bc_index, field_index, exclude_flux_type, only_flux_type, pass_through_ice, ind3_start, ind3_end)
Copy all elements of coupler_2d_bc_type to coupler_3d_bc_type. 
 
logical function ct_initialized_3d(var)
Indicate whether a coupler_3d_bc_type has been initialized. 
 
integer, public ind_psurf
The index of the surface atmospheric pressure. 
 
subroutine ct_copy_data_3d(var_in, var, halo_size, bc_index, field_index, exclude_flux_type, only_flux_type, pass_through_ice)
Copy all elements of coupler_3d_bc_type. 
 
This is the interface to register the fields in a coupler_bc_type to be saved in restart files...
 
subroutine ct_spawn_2d_2d(var_in, var, idim, jdim, suffix, as_needed)
Generate one coupler type using another as a template. 2-D to 2-D version for generic CT_spawn...
 
subroutine ct_set_data_3d(array_in, bc_index, field_index, var, scale_factor, halo_size, idim, jdim)
Set a single 3d field in a coupler_3d_bc_type. 
 
This is the interface to write out diagnostics of the arrays in a coupler_bc_type. 
 
subroutine ct_spawn_3d_2d(var_in, var, idim, jdim, suffix, as_needed)
Generate one coupler type using another as a template. 3-D to 2-D version for generic CT_spawn...
 
subroutine ct_set_data_2d_3d(array_in, bc_index, field_index, k_out, var, scale_factor, halo_size, idim, jdim)
Set one k-level of a single 3d field in a coupler_3d_bc_type. 
 
subroutine ct_register_restarts_to_file_3d(var, file_name, rest_file, mpp_domain, varname_prefix)
Register the fields in a coupler_3d_bc_type to be saved to restart files. 
 
integer, public ind_u10
The index of the 10 m wind speed. 
 
This module contains type declarations for the coupler. 
 
subroutine ct_increment_data_2d_3d(var_in, weights, var, halo_size, bc_index, field_index, scale_factor, scale_prev, exclude_flux_type, only_flux_type, pass_through_ice)
 
subroutine ct_send_data_2d(var, Time)
Write out all diagnostics of elements of a coupler_2d_bc_type. 
 
This is the interface to spawn one coupler_bc_type into another and then register diagnostics associa...
 
integer, public ind_pcair
The index of the atmospheric concentration. 
 
subroutine ct_register_restarts_2d(var, bc_rest_files, num_rest_files, mpp_domain, ocean_restart)
 
subroutine ct_increment_data_2d_2d(var_in, var, halo_size, bc_index, field_index, scale_factor, scale_prev, exclude_flux_type, only_flux_type, pass_through_ice)
 
subroutine ct_register_restarts_3d(var, bc_rest_files, num_rest_files, mpp_domain, ocean_restart)
 
subroutine ct_redistribute_data_3d(var_in, domain_in, var_out, domain_out, complete)
Redistributes the data in all elements of one coupler_2d_bc_type. 
 
subroutine ct_extract_data_2d(var_in, bc_index, field_index, array_out, scale_factor, halo_size, idim, jdim)
Extract a 2d field from a coupler_2d_bc_type. 
 
subroutine ct_destructor_2d(var)
Deallocate all data associated with a coupler_2d_bc_type. 
 
This is the interface to override the values of the arrays in a coupler_bc_type. 
 
This is the interface to redistribute the field data from one coupler_bc_type to another of the same ...
 
This is the interface to spawn one coupler_bc_type into another. 
 
subroutine ct_destructor_1d(var)
Deallocate all data associated with a coupler_1d_bc_type. 
 
logical function ct_initialized_2d(var)
Indicate whether a coupler_2d_bc_type has been initialized. 
 
integer, public ind_flux0
The index for the piston velocity. 
 
subroutine ct_write_chksums_2d(var, outunit, name_lead)
Write out checksums for the elements of a coupler_2d_bc_type. 
 
This function interface indicates whether a coupler_bc_type has been initialized. ...
 
integer, public ind_flux
The index for the tracer flux. 
 
subroutine ct_set_data_2d(array_in, bc_index, field_index, var, scale_factor, halo_size, idim, jdim)
Set single 2d field in coupler_3d_bc_type. 
 
subroutine ct_spawn_1d_2d(var_in, var, idim, jdim, suffix, as_needed)
Generate one coupler type using another as a template. 1-D to 2-D version for generic coupler_type_sp...