<p><b>mpetersen@lanl.gov</b> 2012-01-17 14:44:00 -0700 (Tue, 17 Jan 2012)</p><p>Merged performance branch to ale branch.<br>
</p><hr noshade><pre><font color="gray">
Property changes on: branches/ocean_projects/ale_vert_coord
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/ocean_projects/imp_vert_mix_mrp:754-986
/branches/ocean_projects/split_explicit_mrp:1134-1138
/branches/ocean_projects/split_explicit_timestepping:1044-1097
/branches/ocean_projects/vert_adv_mrp:704-745
/branches/source_renaming:1082-1113
/branches/time_manager:924-962
   + /branches/ocean_projects/imp_vert_mix_mrp:754-986
/branches/ocean_projects/performance:1120-1357
/branches/ocean_projects/split_explicit_mrp:1134-1138
/branches/ocean_projects/split_explicit_timestepping:1044-1097
/branches/ocean_projects/vert_adv_mrp:704-745
/branches/source_renaming:1082-1113
/branches/time_manager:924-962

Modified: branches/ocean_projects/ale_vert_coord/Makefile
===================================================================
--- branches/ocean_projects/ale_vert_coord/Makefile        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/Makefile        2012-01-17 21:44:00 UTC (rev 1384)
@@ -31,7 +31,7 @@
         &quot;CFLAGS = -g&quot; \
         &quot;LDFLAGS = -g -C&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 xlf:
         ( make all \
@@ -43,7 +43,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
  
 ftn:
         ( make all \
@@ -55,7 +55,7 @@
         &quot;CFLAGS = -fast&quot; \
         &quot;LDFLAGS = &quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi:
         ( make all \
@@ -67,7 +67,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-nersc:
         ( make all \
@@ -79,7 +79,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-llnl:
         ( make all \
@@ -91,7 +91,7 @@
         &quot;CFLAGS = -fast&quot; \
         &quot;LDFLAGS = &quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-serial:
         ( make all \
@@ -103,7 +103,7 @@
         &quot;CFLAGS = -O0 -g&quot; \
         &quot;LDFLAGS = -O0 -g -Mbounds -Mchkptr&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 ifort-serial:
         ( make all \
@@ -111,11 +111,11 @@
         &quot;CC = gcc&quot; \
         &quot;SFC = ifort&quot; \
         &quot;SCC = gcc&quot; \
-        &quot;FFLAGS = -real-size 64 -O3 -convert big_endian -FR&quot; \
+        &quot;FFLAGS = -real-size 64 -convert big_endian -FR -O0 -check all&quot; \
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 ifort-papi:
         ( make all \
@@ -127,7 +127,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_PAPI -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; \
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_PAPI -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; \
         &quot;PAPILIBS = -L$(PAPI)/lib -lpapi&quot; )
 
 ifort-papi-serial:
@@ -140,7 +140,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_PAPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; \
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_PAPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; \
         &quot;PAPILIBS = -L$(PAPI)/lib -lpapi&quot; )
 
 ifort:
@@ -153,7 +153,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 gfortran:
         ( make all \
@@ -165,7 +165,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3 -m64&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 gfortran-serial:
         ( make all \
@@ -177,7 +177,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3 -m64&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 g95:
         ( make all \
@@ -189,7 +189,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 g95-serial:
         ( make all \
@@ -201,7 +201,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pathscale-nersc:
         ( make all \
@@ -213,7 +213,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 cray-nersc:
         ( make all \
@@ -225,7 +225,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 intel-nersc:
         ( make all \
@@ -237,7 +237,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 CPPINCLUDES = -I../inc -I$(NETCDF)/include -I$(PAPI)/include
 FCINCLUDES = -I../inc -I$(NETCDF)/include -I$(PAPI)/include

Modified: branches/ocean_projects/ale_vert_coord/namelist.input
===================================================================
--- branches/ocean_projects/ale_vert_coord/namelist.input        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/namelist.input        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1 +1 @@
-link namelist.input.sw
\ No newline at end of file
+link namelist.input.ocean
\ No newline at end of file

Modified: branches/ocean_projects/ale_vert_coord/namelist.input.ocean
===================================================================
--- branches/ocean_projects/ale_vert_coord/namelist.input.ocean        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/namelist.input.ocean        2012-01-17 21:44:00 UTC (rev 1384)
@@ -2,7 +2,7 @@
    config_test_case = 0
    config_time_integration = 'split_explicit'
    config_rk_filter_btr_mode = .false.
-   config_dt = 10.0
+   config_dt = 100.0
    config_start_time = '0000-01-01_00:00:00'
    config_run_duration = '2000_00:00:00'
    config_stats_interval = 1920
@@ -31,9 +31,6 @@
    config_n_btr_cor_iter = 2
    config_u_correction = .true.
    config_filter_btr_mode = .false.
-   config_btr_mom_decay  = .false.
-   config_btr_mom_decay_time =   3600.0
-   config_btr_mom_eddy_visc2 =   0.0
    config_btr_subcycle_loop_factor =  2
    config_SSH_from =  'avg_flux'
    config_new_btr_variables_from = 'btr_avg'


Property changes on: branches/ocean_projects/ale_vert_coord/src
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/ocean_projects/imp_vert_mix_mrp/src:754-986
/branches/ocean_projects/performance/src:1120-1357
/branches/ocean_projects/rayleigh/src:1298-1311
/branches/ocean_projects/split_explicit_mrp/src:1133-1175
/branches/ocean_projects/split_explicit_timestepping/src:1044-1097
/branches/ocean_projects/vert_adv_mrp/src:704-745
/branches/source_renaming/src:1082-1113
/branches/time_manager/src:924-962
/trunk/mpas/src:1224-1336

Modified: branches/ocean_projects/ale_vert_coord/src/Makefile
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/Makefile        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/Makefile        2012-01-17 21:44:00 UTC (rev 1384)
@@ -7,7 +7,7 @@
 
 reg_includes: 
         ( cd registry; make CC=&quot;$(SCC)&quot; )
-        ( cd inc; ../registry/parse ../core_$(CORE)/Registry )
+        ( cd inc; $(CPP) ../core_$(CORE)/Registry | ../registry/parse &gt; Registry.processed)
 
 externals:
         ( cd external; make FC=&quot;$(FC)&quot; SFC=&quot;$(SFC)&quot; CC=&quot;$(CC)&quot; SCC=&quot;$(SCC)&quot; FFLAGS=&quot;$(FFLAGS)&quot; CFLAGS=&quot;$(CFLAGS)&quot; CPP=&quot;$(CPP)&quot; NETCDF=&quot;$(NETCDF)&quot; CORE=&quot;$(CORE)&quot; )
@@ -33,7 +33,7 @@
         ( cd external; make clean )
         ( cd framework; make clean )
         ( cd operators; make clean )
-        ( cd inc; rm -f *.inc )
+        ( cd inc; rm -f *.inc Registry.processed )
         if [ -d core_$(CORE) ] ; then \
            ( cd core_$(CORE); make clean ) \
         fi;

Modified: branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/Registry
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/Registry        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/Registry        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,6 +1,6 @@
-#
-# namelist  type  namelist_record  name  default_value
-#
+%
+% namelist  type  namelist_record  name  default_value
+%
 namelist integer   sw_model config_test_case            5
 namelist character sw_model config_time_integration     SRK3
 namelist real      sw_model config_dt                   172.8
@@ -31,9 +31,9 @@
 namelist logical   restart  config_do_restart           false
 namelist character restart  config_restart_interval     none
 
-#
-# dim  type  name_in_file  name_in_code
-#
+%
+% dim  type  name_in_file  name_in_code
+%
 dim nCells nCells
 dim nEdges nEdges
 dim maxEdges maxEdges
@@ -44,14 +44,14 @@
 dim FIFTEEN 15
 dim TWENTYONE 21
 dim R3 3
-#dim nVertLevels nVertLevels
+%dim nVertLevels nVertLevels
 dim nVertLevels namelist:config_nvertlevels
-#dim nTracers nTracers
+%dim nTracers nTracers
 dim nVertLevelsP1 nVertLevels+1
 
-#
-# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
-#
+%
+% var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
+%
 var persistent text    xtime ( Time ) 2 ro xtime state - -
 
 var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
@@ -102,7 +102,7 @@
 var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
 var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
-# description of the vertical grid structure
+% description of the vertical grid structure
 var persistent real    rdnu ( nVertLevels ) 0 iro rdnu mesh - -
 var persistent real    rdnw ( nVertLevels ) 0 iro rdnw mesh - -
 var persistent real    fnm ( nVertLevels ) 0 iro fnm mesh - -
@@ -111,16 +111,16 @@
 var persistent real    dnu ( nVertLevels ) 0 iro dnu mesh - -
 var persistent real    dnw ( nVertLevels ) 0 iro dnw mesh - -
 
-# Prognostic variables: read from input, saved in restart, and written to output
+% Prognostic variables: read from input, saved in restart, and written to output
 var persistent real    u ( nVertLevels nEdges Time ) 2 iro u state - -
 var persistent real    theta ( nVertLevels nCells Time ) 2 iro theta state - -
 var persistent real    surface_pressure ( nCells Time ) 2 iro surface_pressure state - -
 var persistent real    qv ( nVertLevels nCells Time ) 2 iro qv state scalars moist
 var persistent real    qc ( nVertLevels nCells Time ) 2 iro qc state scalars moist
 var persistent real    qr ( nVertLevels nCells Time ) 2 iro qr state scalars moist
-#var persistent real    tracers ( nTracers nVertLevels nCells Time ) 2 iro state tracers - -
+%var persistent real    tracers ( nTracers nVertLevels nCells Time ) 2 iro state tracers - -
 
-# state variables diagnosed from prognostic state
+% state variables diagnosed from prognostic state
 var persistent real    h ( nVertLevels nCells Time ) 2 ro h state - -
 var persistent real    ww ( nVertLevelsP1 nCells Time ) 2 ro ww state - -
 var persistent real    w ( nVertLevelsP1 nCells Time ) 2 ro w state - -
@@ -128,7 +128,7 @@
 var persistent real    geopotential ( nVertLevelsP1 nCells Time ) 2 ro geopotential state - -
 var persistent real    alpha ( nVertLevels nCells Time ) 2 iro alpha state - -
 
-# Diagnostic fields: only written to output
+% Diagnostic fields: only written to output
 var persistent real    v ( nVertLevels nEdges Time ) 2 o v state - -
 var persistent real    divergence ( nVertLevels nCells Time ) 2 o divergence state - -
 var persistent real    vorticity ( nVertLevels nVertices Time ) 2 o vorticity state - -
@@ -143,7 +143,7 @@
 var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 1 o uReconstructZonal diag - -
 var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 1 o uReconstructMeridional diag - -
 
-# Tendency variables
+% Tendency variables
 var persistent real    tend_h ( nVertLevels nCells Time ) 1 - h tend - -
 var persistent real    tend_u ( nVertLevels nEdges Time ) 1 - u tend - -
 var persistent real    tend_vh ( nVertLevels nEdges Time ) 1 - vh tend - -
@@ -152,7 +152,7 @@
 var persistent real    tend_qc ( nVertLevels nCells Time ) 1 - qc tend scalars moist
 var persistent real    tend_qr ( nVertLevels nCells Time ) 1 - qr tend scalars moist
 
-# Other diagnostic variables: neither read nor written to any files
+% Other diagnostic variables: neither read nor written to any files
 var persistent real    vh ( nVertLevels nEdges Time ) 2 - vh state - -
 var persistent real    circulation ( nVertLevels nVertices Time ) 2 - circulation state - -
 var persistent real    gradPVt ( nVertLevels nEdges Time ) 2 - gradPVt state - -
@@ -174,12 +174,12 @@
 var persistent real    qv_old ( nVertLevels nCells ) 0 - qv_old mesh scalars_old moist_old
 var persistent real    qc_old ( nVertLevels nCells ) 0 - qc_old mesh scalars_old moist_old
 var persistent real    qr_old ( nVertLevels nCells ) 0 - qr_old mesh scalars_old moist_old
-#var persistent real    tracers_old ( nTracers nVertLevels nCells ) 0 - tracers_old mesh - -
+%var persistent real    tracers_old ( nTracers nVertLevels nCells ) 0 - tracers_old mesh - -
 
-# Space needed for advection
+% Space needed for advection
 var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 o deriv_two mesh - -
 var persistent integer advCells ( TWENTYONE nCells ) 0 - advCells mesh - -
 
-# Arrays required for reconstruction of velocity field
+% Arrays required for reconstruction of velocity field
 var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_advection.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_advection.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_advection.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,6 @@
 module atmh_advection
 
+   use mpas_kind_types
    use mpas_grid_types
    use mpas_configure
    use mpas_constants
@@ -116,7 +117,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -335,7 +336,7 @@
    ! Computes the angle between arcs AB and AC, given points A, B, and C
    ! Equation numbers w.r.t. http://mathworld.wolfram.com/SphericalTrigonometry.html
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)
+   real (kind=RKIND) function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)
    
       implicit none
    
@@ -355,9 +356,9 @@
       real (kind=RKIND) :: s                ! Semiperimeter of the triangle
       real (kind=RKIND) :: sin_angle
    
-      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0),-1.0))      ! Eqn. (3)
-      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0),-1.0))      ! Eqn. (2)
-      c = acos(max(min(ax*bx + ay*by + az*bz,1.0),-1.0))      ! Eqn. (1)
+      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (3)
+      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (2)
+      c = acos(max(min(ax*bx + ay*by + az*bz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (1)
    
       ABx = bx - ax
       ABy = by - ay
@@ -373,12 +374,12 @@
    
       s = 0.5*(a + b + c)
 !      sin_angle = sqrt((sin(s-b)*sin(s-c))/(sin(b)*sin(c)))   ! Eqn. (28)
-      sin_angle = sqrt(min(1.,max(0.,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
+      sin_angle = sqrt(min(1.0_RKIND,max(0.0_RKIND,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
    
       if ((Dx*ax + Dy*ay + Dz*az) &gt;= 0.0) then
-         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       else
-         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
    end function sphere_angle
@@ -390,7 +391,7 @@
    ! Computes the angle between vectors AB and AC, given points A, B, and C, and
    !   a vector (u,v,w) normal to the plane.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)
+   real (kind=RKIND) function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)
    
       implicit none
    
@@ -425,9 +426,9 @@
       cos_angle = (ABx*ACx + ABy*ACy + ABz*ACz) / (mAB * mAC)
    
       if ((Dx*u + Dy*v + Dz*w) &gt;= 0.0) then
-         plane_angle =  acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle =  acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       else
-         plane_angle = -acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle = -acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
    end function plane_angle
@@ -440,7 +441,7 @@
    !    B=(bx, by, bz). It is assumed that both A and B lie on the surface of the
    !    same sphere centered at the origin.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function arc_length(ax, ay, az, bx, by, bz)
+   real (kind=RKIND) function arc_length(ax, ay, az, bx, by, bz)
    
       implicit none
    
@@ -575,7 +576,7 @@
 !                                                                       !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
-SUBROUTine MIGS (A,N,X,INDX)
+SUBROUTINE MIGS (A,N,X,INDX)
 !
 ! Subroutine to invert matrix A(N,N) with the inverse stored
 ! in X(N,N) in the output.  Copyright (c) Tao Pang 2001.
@@ -617,7 +618,7 @@
       X(J,I) =  X(J,I)/A(INDX(J),J)
     END DO
   END DO
-END SUBROUTine MIGS
+END SUBROUTINE MIGS
 
 
 SUBROUTINE ELGS (A,N,INDX)
@@ -646,7 +647,7 @@
   DO I = 1, N
     C1= 0.0
     DO J = 1, N
-      C1 = AMAX1(C1,ABS(A(I,J)))
+      C1 = MAX(C1,ABS(A(I,J)))
     END DO
     C(I) = C1
   END DO

Modified: branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_test_cases.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_test_cases.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_test_cases.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -258,7 +258,7 @@
 
          if (config_test_case == 2) then
             r_pert = sphere_distance( grid % latEdge % array (iEdge), grid % lonEdge % array (iEdge), &amp;
-                                      lat_pert, lon_pert, 1.)/(pert_radius)
+                                      lat_pert, lon_pert, 1.0_RKIND)/(pert_radius)
             u_pert = u_perturbation*exp(-r_pert**2)*(lat2-lat1)*a/grid % dvEdge % array(iEdge)
 
          else if (config_test_case == 3) then
@@ -468,7 +468,7 @@
    end subroutine atmh_test_case_1
 
 
-   real function sphere_distance(lat1, lon1, lat2, lon2, radius)
+   real (kind=RKIND) function sphere_distance(lat1, lon1, lat2, lon2, radius)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Compute the great-circle distance between (lat1, lon1) and (lat2, lon2) on a
    !   sphere with given radius.
@@ -487,7 +487,7 @@
    end function sphere_distance
 
 
-   real function AA(theta)
+   real (kind=RKIND) function AA(theta)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! A, used in height field computation for Rossby-Haurwitz wave
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -506,7 +506,7 @@
    end function AA
 
    
-   real function BB(theta)
+   real (kind=RKIND) function BB(theta)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! B, used in height field computation for Rossby-Haurwitz wave
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -524,7 +524,7 @@
    end function BB
 
 
-   real function CC(theta)
+   real (kind=RKIND) function CC(theta)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! C, used in height field computation for Rossby-Haurwitz wave
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Modified: branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_time_integration.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_time_integration.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_hyd_atmos/mpas_atmh_time_integration.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1652,9 +1652,9 @@
     
                   ! add in vertical flux to get max and min estimate
                   s_max_update(iScalar) = s_max_update(iScalar)  &amp;
-                     - rdnw(k) * (max(0.,v_flux(iScalar,iCell,km0)) - min(0.,v_flux(iScalar,iCell,km1)))
+                     - rdnw(k) * (max(0.0_RKIND,v_flux(iScalar,iCell,km0)) - min(0.0_RKIND,v_flux(iScalar,iCell,km1)))
                   s_min_update(iScalar) = s_min_update(iScalar)  &amp;
-                     - rdnw(k) * (min(0.,v_flux(iScalar,iCell,km0)) - max(0.,v_flux(iScalar,iCell,km1)))
+                     - rdnw(k) * (min(0.0_RKIND,v_flux(iScalar,iCell,km0)) - max(0.0_RKIND,v_flux(iScalar,iCell,km1)))
     
                end do
    
@@ -1671,8 +1671,8 @@
                         fdir = -1.0
                      end if
                      flux = -fdir * h_flux(iScalar,iEdge)/grid % areaCell % array(iCell)
-                     s_max_update(iScalar) = s_max_update(iScalar) + max(0.,flux)
-                     s_min_update(iScalar) = s_min_update(iScalar) + min(0.,flux)
+                     s_max_update(iScalar) = s_max_update(iScalar) + max(0.0_RKIND,flux)
+                     s_min_update(iScalar) = s_min_update(iScalar) + min(0.0_RKIND,flux)
   
                   end do
    
@@ -1687,9 +1687,9 @@
                   s_min_update (iScalar) =  s_min_update (iScalar) / h_new (k,iCell)
                   s_upwind = s_update(iScalar,iCell,km0) / h_new(k,iCell)
                   if ( s_max_update(iScalar) &gt; s_max(iScalar) .and. config_monotonic)   &amp;
-                     scale_in (iScalar,iCell,km0) = max(0.,(s_max(iScalar)-s_upwind)/(s_max_update(iScalar)-s_upwind+eps))
+                     scale_in (iScalar,iCell,km0) = max(0.0_RKIND,(s_max(iScalar)-s_upwind)/(s_max_update(iScalar)-s_upwind+eps))
                   if ( s_min_update(iScalar) &lt; s_min(iScalar) )   &amp;
-                     scale_out (iScalar,iCell,km0) = max(0.,(s_upwind-s_min(iScalar))/(s_upwind-s_min_update(iScalar)+eps))
+                     scale_out (iScalar,iCell,km0) = max(0.0_RKIND,(s_upwind-s_min(iScalar))/(s_upwind-s_min_update(iScalar)+eps))
                 end do
   
             end do ! end loop over cells to compute scale factor


Property changes on: branches/ocean_projects/ale_vert_coord/src/core_ocean
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean:1260-1270
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean:754-986
/branches/ocean_projects/performance/src/core_ocean:1120-1357
/branches/ocean_projects/rayleigh/src/core_ocean:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean:1133-1175
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean:704-745
/branches/source_renaming/src/core_ocean:1082-1113
/branches/time_manager/src/core_ocean:924-962
/trunk/mpas/src/core_ocean:1224-1336

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/Makefile
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/Makefile        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/Makefile        2012-01-17 21:44:00 UTC (rev 1384)
@@ -13,6 +13,7 @@
            mpas_ocn_vel_forcing.o \
            mpas_ocn_vel_forcing_windstress.o \
            mpas_ocn_vel_forcing_bottomdrag.o \
+           mpas_ocn_vel_forcing_rayleigh.o \
            mpas_ocn_vel_pressure_grad.o \
            mpas_ocn_tracer_vadv.o \
            mpas_ocn_tracer_vadv_spline.o \
@@ -41,9 +42,9 @@
            mpas_ocn_equation_of_state.o \
            mpas_ocn_equation_of_state_jm.o \
            mpas_ocn_equation_of_state_linear.o \
-       mpas_ocn_global_diagnostics.o
+       mpas_ocn_global_diagnostics.o \
+           mpas_ocn_time_average.o
 
-
 all: core_hyd
 
 core_hyd: $(OBJS)
@@ -59,10 +60,12 @@
 
 mpas_ocn_time_integration_split.o:
 
-mpas_ocn_tendency.o:
+mpas_ocn_tendency.o: mpas_ocn_time_average.o
 
 mpas_ocn_global_diagnostics.o: 
 
+mpas_ocn_time_average.o:
+
 mpas_ocn_thick_hadv.o:
 
 mpas_ocn_thick_vadv.o:
@@ -77,12 +80,14 @@
 
 mpas_ocn_vel_hmix_del4.o:
 
-mpas_ocn_vel_forcing.o: mpas_ocn_vel_forcing_windstress.o mpas_ocn_vel_forcing_bottomdrag.o
+mpas_ocn_vel_forcing.o: mpas_ocn_vel_forcing_windstress.o mpas_ocn_vel_forcing_bottomdrag.o mpas_ocn_vel_forcing_rayleigh.o
 
 mpas_ocn_vel_forcing_windstress.o:
 
-mpas_ocn_velforcing_bottomdrag.o:
+mpas_ocn_vel_forcing_bottomdrag.o:
 
+mpas_ocn_vel_forcing_rayleigh.o:
+
 mpas_ocn_vel_coriolis.o:
 
 mpas_ocn_tracer_hadv.o:  mpas_ocn_tracer_hadv2.o  mpas_ocn_tracer_hadv3.o  mpas_ocn_tracer_hadv4.o
@@ -172,7 +177,8 @@
                                           mpas_ocn_equation_of_state.o \
                                           mpas_ocn_equation_of_state_jm.o \
                                           mpas_ocn_equation_of_state_linear.o \
-                                          mpas_ocn_global_diagnostics.o
+                                          mpas_ocn_global_diagnostics.o \
+                                          mpas_ocn_time_average.o
 
 clean:
         $(RM) *.o *.mod *.f90 libdycore.a

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/Registry
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/Registry        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/Registry        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,6 +1,6 @@
-#
-# namelist  type  namelist_record  name  default_value
-#
+%
+% namelist  type  namelist_record  name  default_value
+%
 namelist integer   sw_model config_test_case           5
 namelist character sw_model config_time_integration    RK4
 namelist logical   sw_model config_rk_filter_btr_mode  false
@@ -10,6 +10,7 @@
 namelist character sw_model config_stop_time           none
 namelist character sw_model config_run_duration        none
 namelist integer   sw_model config_stats_interval      100
+namelist logical   sw_model config_initial_stats       false
 namelist character io       config_input_name          grid.nc
 namelist character io       config_output_name         output.nc
 namelist character io       config_restart_name        restart.nc
@@ -21,16 +22,13 @@
 namelist character grid     config_vert_grid_type      isopycnal
 namelist real      grid     config_rho0                1028
 namelist integer   split_explicit_ts config_n_ts_iter     2
-namelist integer   split_explicit_ts config_n_bcl_iter_beg   4
-namelist integer   split_explicit_ts config_n_bcl_iter_mid   4
-namelist integer   split_explicit_ts config_n_bcl_iter_end   4
-namelist integer   split_explicit_ts config_n_btr_subcycles  10
-namelist integer   split_explicit_ts config_n_btr_cor_iter  1
+namelist integer   split_explicit_ts config_n_bcl_iter_beg   2
+namelist integer   split_explicit_ts config_n_bcl_iter_mid   2
+namelist integer   split_explicit_ts config_n_bcl_iter_end   2
+namelist integer   split_explicit_ts config_n_btr_subcycles  20
+namelist integer   split_explicit_ts config_n_btr_cor_iter  2
 namelist logical   split_explicit_ts config_u_correction true
 namelist logical   split_explicit_ts config_filter_btr_mode false
-namelist logical   split_explicit_ts config_btr_mom_decay         false 
-namelist real      split_explicit_ts config_btr_mom_decay_time    3600.0
-namelist real      split_explicit_ts config_btr_mom_eddy_visc2    0.0
 namelist integer   split_explicit_ts config_btr_subcycle_loop_factor  2
 namelist character split_explicit_ts config_SSH_from  avg_flux
 namelist character split_explicit_ts config_new_btr_variables_from  btr_avg
@@ -38,7 +36,7 @@
 namelist real      split_explicit_ts config_btr_gam2_SSHWt1  1.0
 namelist real      split_explicit_ts config_btr_gam3_uWt2    1.0
 namelist logical   split_explicit_ts config_btr_solve_SSH2   false
-namelist logical   sw_model config_h_ScaleWithMesh     false
+namelist logical   hmix     config_h_ScaleWithMesh     false
 namelist real      hmix     config_h_mom_eddy_visc2     0.0
 namelist real      hmix     config_h_mom_eddy_visc4     0.0
 namelist logical   hmix     config_visc_vorticity_term true
@@ -48,8 +46,8 @@
 namelist real      hmix     config_h_tracer_eddy_diff2  0.0
 namelist real      hmix     config_h_tracer_eddy_diff4  0.0
 namelist real      hmix     config_apvm_upwinding       0.5
-namelist logical   hmix     config_mom_decay            false 
-namelist real      hmix     config_mom_decay_time       3600.0
+namelist logical   hmix     config_rayleigh_friction    false
+namelist real      hmix     config_rayleigh_damping_coeff 0.0
 namelist character vmix     config_vert_visc_type       const
 namelist character vmix     config_vert_diff_type       const
 namelist logical   vmix     config_implicit_vertical_mix  .true.
@@ -78,9 +76,9 @@
 namelist real      restore   config_restoreT_timescale  90.0
 namelist real      restore   config_restoreS_timescale  90.0
 
-#
-# dim  type  name_in_file  name_in_code
-#
+%
+% dim  type  name_in_file  name_in_code
+%
 dim nCells nCells
 dim nEdges nEdges
 dim maxEdges maxEdges
@@ -94,9 +92,9 @@
 dim nVertLevels nVertLevels
 dim nVertLevelsP1 nVertLevels+1
 
-#
-# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
-#
+%
+% var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
+%
 var persistent text    xtime ( Time ) 2 ro xtime state - -
 
 var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
@@ -151,21 +149,21 @@
 var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
 var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
-# Space needed for advection
+% Space needed for advection
 var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 - deriv_two mesh - -
 var persistent integer advCells ( TWENTYONE nCells ) 0 - advCells mesh - -
 
-# !! NOTE: the following arrays are needed to allow the use
-# !! of the module_advection.F w/o alteration
-# Space needed for deformation calculation weights
+% !! NOTE: the following arrays are needed to allow the use
+% !! of the module_advection.F w/o alteration
+% Space needed for deformation calculation weights
 var persistent real    defc_a ( maxEdges nCells ) 0 - defc_a mesh - -
 var persistent real    defc_b ( maxEdges nCells ) 0 - defc_b mesh - -
 var persistent real    kdiff ( nVertLevels nCells Time ) 0 - kdiff mesh - -
 
-# Arrays required for reconstruction of velocity field
+% Arrays required for reconstruction of velocity field
 var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
-# Arrays for z-level version of mpas-ocean
+% Arrays for z-level version of mpas-ocean
 var persistent integer maxLevelCell ( nCells ) 0 iro maxLevelCell mesh - -
 var persistent integer maxLevelEdgeTop ( nEdges ) 0 - maxLevelEdgeTop mesh - -
 var persistent integer maxLevelEdgeBot ( nEdges ) 0 - maxLevelEdgeBot mesh - -
@@ -175,23 +173,26 @@
 var persistent real zMidZLevel ( nVertLevels ) 0 - zMidZLevel mesh - -
 var persistent real zTopZLevel ( nVertLevelsP1 ) 0 - zTopZLevel mesh - -
 
-# Boundary conditions: read from input, saved in restart and written to output
+% Boundary conditions: read from input, saved in restart and written to output
 var persistent integer boundaryEdge ( nVertLevels nEdges ) 0 iro boundaryEdge mesh - -
 var persistent integer boundaryVertex ( nVertLevels nVertices ) 0 iro boundaryVertex mesh - -
 var persistent integer boundaryCell ( nVertLevels nCells ) 0 iro boundaryCell mesh - -
+var persistent integer edgeMask ( nVertLevels nEdges ) 0 o edgeMask mesh - -
+var persistent integer vertexMask ( nVertLevels nVertices ) 0 o vertexMask mesh - -
+var persistent integer cellMask ( nVertLevels nCells ) 0 o cellMask mesh - -
 var persistent real    u_src ( nVertLevels nEdges ) 0 ir u_src mesh - -
 var persistent real    temperatureRestore ( nCells ) 0 ir temperatureRestore mesh - -
 var persistent real    salinityRestore ( nCells ) 0 ir salinityRestore mesh - -
 
-# Prognostic variables: read from input, saved in restart, and written to output
+% Prognostic variables: read from input, saved in restart, and written to output
 var persistent real    u ( nVertLevels nEdges Time ) 2 ir u state - -
-var persistent real    h ( nVertLevels nCells Time ) 2 iro h state - -
+var persistent real    h ( nVertLevels nCells Time ) 2 ir h state - -
 var persistent real    rho ( nVertLevels nCells Time ) 2 iro rho state - -
 var persistent real    temperature ( nVertLevels nCells Time ) 2 iro temperature state tracers dynamics
 var persistent real    salinity ( nVertLevels nCells Time ) 2 iro salinity state tracers dynamics
 var persistent real    tracer1 ( nVertLevels nCells Time ) 2 iro tracer1 state tracers testing
 
-# Tendency variables: neither read nor written to any files
+% Tendency variables: neither read nor written to any files
 var persistent real    tend_u ( nVertLevels nEdges Time ) 1 - u tend - -
 var persistent real    tend_h ( nVertLevels nCells Time ) 1 - h tend - -
 var persistent real    tend_ssh ( nCells Time ) 1 - ssh tend - -
@@ -199,20 +200,20 @@
 var persistent real    tend_salinity ( nVertLevels nCells Time ) 1 - salinity tend tracers dynamics
 var persistent real    tend_tracer1 ( nVertLevels nCells Time ) 1 - tracer1 tend tracers testing
 
-# state variables for Split Explicit timesplitting
+% state variables for Split Explicit timesplitting
 var persistent real   uBtr ( nEdges Time )         2 -  uBtr state - -
 var persistent real   ssh ( nCells Time )          2 o  ssh state - - 
 var persistent real   uBtrSubcycle ( nEdges Time ) 2 -  uBtrSubcycle state - -
 var persistent real   sshSubcycle ( nCells Time )  2 -  sshSubcycle state - - 
-var persistent real   FBtr ( nEdges Time )         1 -  FBtr state - - 
-var persistent real   GBtrForcing ( nEdges Time )  1 -  GBtrForcing state - -
+var persistent real   FBtr ( nEdges Time )         2 -  FBtr state - - 
+var persistent real   GBtrForcing ( nEdges Time )  2 -  GBtrForcing state - -
 var persistent real   uBcl ( nVertLevels nEdges Time )  2 - uBcl state - - 
-var persistent real   circulationBtr ( nVertices Time ) 1 - circulationBtr state - -
-var persistent real   divergenceBtr ( nCells Time ) 1 - divergenceBtr state - -
-var persistent real   vorticityBtr ( nVertices Time ) 1 - vorticityBtr state - -
-var persistent real   u_diffusionBtr ( nEdges Time ) 1 - u_diffusionBtr state - -
+var persistent real   circulationBtr ( nVertices Time ) 2 - circulationBtr state - -
+var persistent real   divergenceBtr ( nCells Time ) 2 - divergenceBtr state - -
+var persistent real   vorticityBtr ( nVertices Time ) 2 - vorticityBtr state - -
+var persistent real   u_diffusionBtr ( nEdges Time ) 2 - u_diffusionBtr state - -
 
-# Diagnostic fields: only written to output
+% Diagnostic fields: only written to output
 var persistent real    zMid ( nVertLevels nCells Time ) 2 io zMid state - -
 var persistent real    v ( nVertLevels nEdges Time ) 2 - v state - -
 var persistent real    divergence ( nVertLevels nCells Time ) 2 o divergence state - -
@@ -236,13 +237,13 @@
 var persistent real    wTop ( nVertLevelsP1 nCells Time ) 2 - wTop state - -
 var persistent real    rhoDisplaced ( nVertLevels nCells Time ) 2 - rhoDisplaced state - -
 
-# Other diagnostic variables: neither read nor written to any files
+% Other diagnostic variables: neither read nor written to any files
 var persistent real    vh ( nVertLevels nEdges Time ) 2 - vh state - -
 var persistent real    circulation ( nVertLevels nVertices Time ) 2 - circulation state - -
 var persistent real    gradPVt ( nVertLevels nEdges Time ) 2 - gradPVt state - -
 var persistent real    gradPVn ( nVertLevels nEdges Time ) 2 - gradPVn state - -
 
-# Globally reduced diagnostic variables: only written to output
+% Globally reduced diagnostic variables: only written to output
 var persistent real    areaCellGlobal ( Time ) 2 o areaCellGlobal state - -
 var persistent real    areaEdgeGlobal ( Time ) 2 o areaEdgeGlobal state - -
 var persistent real    areaTriangleGlobal ( Time ) 2 o areaTriangleGlobal state - -
@@ -251,8 +252,18 @@
 var persistent real    volumeEdgeGlobal ( Time ) 2 o volumeEdgeGlobal state - -
 var persistent real    CFLNumberGlobal ( Time ) 2 o CFLNumberGlobal state - -
 
-# Diagnostics fields, only one time level required
+% Diagnostics fields, only one time level required
 var persistent real    RiTopOfCell ( nVertLevelsP1 nCells Time ) 1 - RiTopOfCell diagnostics - -
 var persistent real    RiTopOfEdge ( nVertLevelsP1 nEdges Time ) 1 - RiTopOfEdge diagnostics - -
 var persistent real    vertViscTopOfEdge ( nVertLevelsP1 nEdges Time ) 1 - vertViscTopOfEdge diagnostics - -
 var persistent real    vertDiffTopOfCell ( nVertLevelsP1 nCells Time ) 1 - vertDiffTopOfCell diagnostics - -
+
+var persistent real    nAccumulate ( Time ) 2 o nAccumulate state - -
+var persistent real    acc_ssh ( nCells Time ) 2 o acc_ssh state - -
+var persistent real    acc_sshVar ( nCells Time ) 2 o acc_sshVar state - -
+var persistent real    acc_uReconstructZonal ( nVertLevels nCells Time ) 2 o acc_uReconstructZonal state - -
+var persistent real    acc_uReconstructMeridional ( nVertLevels nCells Time ) 2 o acc_uReconstructMeridional state - -
+var persistent real    acc_uReconstructZonalVar ( nVertLevels nCells Time ) 2 o acc_uReconstructZonalVar state - -
+var persistent real    acc_uReconstructMeridionalVar ( nVertLevels nCells Time ) 2 o acc_uReconstructMeridionalVar state - -
+var persistent real           acc_u ( nVertLevels nEdges Time ) 2 o acc_u state - -
+var persistent real           acc_uVar ( nVertLevels nEdges Time ) 2 o acc_uVar state - -

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_advection.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_advection.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_advection.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,6 @@
 module ocn_advection
 
+   use mpas_kind_types
    use mpas_grid_types
    use mpas_configure
    use mpas_constants
@@ -8,7 +9,7 @@
    contains
 
 
-   subroutine ocn_initialize_advection_rk( grid )
+   subroutine ocn_initialize_advection_rk( grid )!{{{
                                       
 !
 ! compute the cell coefficients for the polynomial fit.
@@ -117,7 +118,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -381,7 +382,7 @@
 !      end do
 !      stop
 
-   end subroutine ocn_initialize_advection_rk
+   end subroutine ocn_initialize_advection_rk!}}}
 
 
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -390,7 +391,7 @@
    ! Computes the angle between arcs AB and AC, given points A, B, and C
    ! Equation numbers w.r.t. http://mathworld.wolfram.com/SphericalTrigonometry.html
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)
+   real (kind=RKIND) function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)!{{{
    
       implicit none
    
@@ -410,9 +411,9 @@
       real (kind=RKIND) :: s                ! Semiperimeter of the triangle
       real (kind=RKIND) :: sin_angle
    
-      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0),-1.0))      ! Eqn. (3)
-      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0),-1.0))      ! Eqn. (2)
-      c = acos(max(min(ax*bx + ay*by + az*bz,1.0),-1.0))      ! Eqn. (1)
+      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (3)
+      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (2)
+      c = acos(max(min(ax*bx + ay*by + az*bz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (1)
    
       ABx = bx - ax
       ABy = by - ay
@@ -428,15 +429,15 @@
    
       s = 0.5*(a + b + c)
 !      sin_angle = sqrt((sin(s-b)*sin(s-c))/(sin(b)*sin(c)))   ! Eqn. (28)
-      sin_angle = sqrt(min(1.,max(0.,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
+      sin_angle = sqrt(min(1.0_RKIND,max(0.0_RKIND,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
    
       if ((Dx*ax + Dy*ay + Dz*az) &gt;= 0.0) then
-         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       else
-         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
-   end function sphere_angle
+   end function sphere_angle!}}}
    
 
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -445,7 +446,7 @@
    ! Computes the angle between vectors AB and AC, given points A, B, and C, and
    !   a vector (u,v,w) normal to the plane.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)
+   real (kind=RKIND) function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)!{{{
    
       implicit none
    
@@ -480,12 +481,12 @@
       cos_angle = (ABx*ACx + ABy*ACy + ABz*ACz) / (mAB * mAC)
    
       if ((Dx*u + Dy*v + Dz*w) &gt;= 0.0) then
-         plane_angle =  acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle =  acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       else
-         plane_angle = -acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle = -acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
-   end function plane_angle
+   end function plane_angle!}}}
 
 
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -495,7 +496,7 @@
    !    B=(bx, by, bz). It is assumed that both A and B lie on the surface of the
    !    same sphere centered at the origin.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function arc_length(ax, ay, az, bx, by, bz)
+   real (kind=RKIND) function arc_length(ax, ay, az, bx, by, bz)!{{{
    
       implicit none
    
@@ -518,7 +519,7 @@
 !      arc_length = sqrt(r) * 2.0 * asin(c/(2.0*r))
       arc_length = r * 2.0 * asin(c/(2.0*r))
 
-   end function arc_length
+   end function arc_length!}}}
    
    
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -528,7 +529,7 @@
    !   A=(ax, ay, az) to B=(bx, by, bz). It is assumed that A and B lie on the
    !   surface of a sphere centered at the origin.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   subroutine ocn_arc_bisect(ax, ay, az, bx, by, bz, cx, cy, cz)
+   subroutine ocn_arc_bisect(ax, ay, az, bx, by, bz, cx, cy, cz)!{{{
    
       implicit none
    
@@ -553,10 +554,10 @@
          cz = r * cz / d
       end if
    
-   end subroutine ocn_arc_bisect
+   end subroutine ocn_arc_bisect!}}}
 
 
-   subroutine ocn_poly_fit_2(a_in,b_out,weights_in,m,n,ne)
+   subroutine ocn_poly_fit_2(a_in,b_out,weights_in,m,n,ne)!{{{
 
       implicit none
 
@@ -611,7 +612,7 @@
 !
 !     write(6,*) ' '
 
-   end subroutine ocn_poly_fit_2
+   end subroutine ocn_poly_fit_2!}}}
 
 
 ! Updated 10/24/2001.
@@ -630,119 +631,119 @@
 !                                                                       !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
-SUBROUTine ocn_migs (A,N,X,INDX)
+subroutine ocn_migs (a,n,x,indx)!{{{
 !
-! Subroutine to invert matrix A(N,N) with the inverse stored
-! in X(N,N) in the output.  Copyright (c) Tao Pang 2001.
+! subroutine to invert matrix a(n,n) with the inverse stored
+! in x(n,n) in the output.  copyright (c) tao pang 2001.
 !
-  IMPLICIT NONE
-  INTEGER, INTENT (IN) :: N
-  INTEGER :: I,J,K
-  INTEGER, INTENT (OUT), DIMENSION (N) :: INDX
-  REAL (kind=RKIND), INTENT (INOUT), DIMENSION (N,N):: A
-  REAL (kind=RKIND), INTENT (OUT), DIMENSION (N,N):: X
-  REAL (kind=RKIND), DIMENSION (N,N) :: B
+  implicit none
+  integer, intent (in) :: n
+  integer :: i,j,k
+  integer, intent (out), dimension (n) :: indx
+  real (kind=RKIND), intent (inout), dimension (n,n):: a
+  real (kind=RKIND), intent (out), dimension (n,n):: x
+  real (kind=RKIND), dimension (n,n) :: b
 !
-  DO I = 1, N
-    DO J = 1, N
-      B(I,J) = 0.0
-    END DO
-  END DO
-  DO I = 1, N
-    B(I,I) = 1.0
-  END DO
+  do i = 1, n
+    do j = 1, n
+      b(i,j) = 0.0
+    end do
+  end do
+  do i = 1, n
+    b(i,i) = 1.0
+  end do
 !
-  call ocn_elgs (A,N,INDX)
+  call ocn_elgs (a,n,indx)
 !
-  DO I = 1, N-1
-    DO J = I+1, N
-      DO K = 1, N
-        B(INDX(J),K) = B(INDX(J),K)-A(INDX(J),I)*B(INDX(I),K)
-      END DO
-    END DO
-  END DO
+  do i = 1, n-1
+    do j = i+1, n
+      do k = 1, n
+        b(indx(j),k) = b(indx(j),k)-a(indx(j),i)*b(indx(i),k)
+      end do
+    end do
+  end do
 !
-  DO I = 1, N
-    X(N,I) = B(INDX(N),I)/A(INDX(N),N)
-    DO J = N-1, 1, -1
-      X(J,I) = B(INDX(J),I)
-      DO K = J+1, N
-        X(J,I) = X(J,I)-A(INDX(J),K)*X(K,I)
-      END DO
-      X(J,I) =  X(J,I)/A(INDX(J),J)
-    END DO
-  END DO
-END SUBROUTine ocn_migs
+  do i = 1, n
+    x(n,i) = b(indx(n),i)/a(indx(n),n)
+    do j = n-1, 1, -1
+      x(j,i) = b(indx(j),i)
+      do k = j+1, n
+        x(j,i) = x(j,i)-a(indx(j),k)*x(k,i)
+      end do
+      x(j,i) =  x(j,i)/a(indx(j),j)
+    end do
+  end do
+end subroutine ocn_migs!}}}
 
 
-SUBROUTine ocn_elgs (A,N,INDX)
+subroutine ocn_elgs (a,n,indx)!{{{
 !
-! Subroutine to perform the partial-pivoting Gaussian elimination.
-! A(N,N) is the original matrix in the input and transformed matrix
+! subroutine to perform the partial-pivoting gaussian elimination.
+! a(n,n) is the original matrix in the input and transformed matrix
 ! plus the pivoting element ratios below the diagonal in the output.
-! INDX(N) records the pivoting order.  Copyright (c) Tao Pang 2001.
+! indx(n) records the pivoting order.  copyright (c) tao pang 2001.
 !
-  IMPLICIT NONE
-  INTEGER, INTENT (IN) :: N
-  INTEGER :: I,J,K,ITMP
-  INTEGER, INTENT (OUT), DIMENSION (N) :: INDX
-  REAL (kind=RKIND) :: C1,PI,PI1,PJ
-  REAL (kind=RKIND), INTENT (INOUT), DIMENSION (N,N) :: A
-  REAL (kind=RKIND), DIMENSION (N) :: C
+  implicit none
+  integer, intent (in) :: n
+  integer :: i,j,k,itmp
+  integer, intent (out), dimension (n) :: indx
+  real (kind=RKIND) :: c1,pi,pi1,pj
+  real (kind=RKIND), intent (inout), dimension (n,n) :: a
+  real (kind=RKIND), dimension (n) :: c
 !
-! Initialize the index
+! initialize the index
 !
-  DO I = 1, N
-    INDX(I) = I
-  END DO
+  do i = 1, n
+    indx(i) = i
+  end do
 !
-! Find the rescaling factors, one from each row
+! find the rescaling factors, one from each row
 !
-  DO I = 1, N
-    C1= 0.0
-    DO J = 1, N
-      C1 = MAX(C1,ABS(A(I,J)))
-    END DO
-    C(I) = C1
-  END DO
+  do i = 1, n
+    c1= 0.0
+    do j = 1, n
+      c1 = max(c1,abs(a(i,j)))
+    end do
+    c(i) = c1
+  end do
 !
-! Search the pivoting (largest) element from each column
+! search the pivoting (largest) element from each column
 !
-  DO J = 1, N-1
-    PI1 = 0.0
-    DO I = J, N
-      PI = ABS(A(INDX(I),J))/C(INDX(I))
-      IF (PI.GT.PI1) THEN
-        PI1 = PI
-        K   = I
-      ENDIF
-    END DO
+  do j = 1, n-1
+    pi1 = 0.0
+    do i = j, n
+      pi = abs(a(indx(i),j))/c(indx(i))
+      if (pi.gt.pi1) then
+        pi1 = pi
+        k   = i
+      endif
+    end do
 !
-! Interchange the rows via INDX(N) to record pivoting order
+! interchange the rows via indx(n) to record pivoting order
 !
-    ITMP    = INDX(J)
-    INDX(J) = INDX(K)
-    INDX(K) = ITMP
-    DO I = J+1, N
-      PJ  = A(INDX(I),J)/A(INDX(J),J)
+    itmp    = indx(j)
+    indx(j) = indx(k)
+    indx(k) = itmp
+    do i = j+1, n
+      pj  = a(indx(i),j)/a(indx(j),j)
 !
-! Record pivoting ratios below the diagonal
+! record pivoting ratios below the diagonal
 !
-      A(INDX(I),J) = PJ
+      a(indx(i),j) = pj
 !
-! Modify other elements accordingly
+! modify other elements accordingly
 !
-      DO K = J+1, N
-        A(INDX(I),K) = A(INDX(I),K)-PJ*A(INDX(J),K)
-      END DO
-    END DO
-  END DO
+      do k = j+1, n
+        a(indx(i),k) = a(indx(i),k)-pj*a(indx(j),k)
+      end do
+    end do
+  end do
 !
-END SUBROUTine ocn_elgs
+end subroutine ocn_elgs!}}}
 
 !-------------------------------------------------------------
 
-   subroutine ocn_initialize_deformation_weights( grid )
+   subroutine ocn_initialize_deformation_weights( grid )!{{{
                                       
 !
 ! compute the cell coefficients for the deformation calculations
@@ -839,7 +840,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -891,10 +892,10 @@
          do i=2,n-1
             ip1 = i+1
             if (ip1 == n) ip1 = 1
-            thetat(i) = plane_angle( 0.,0.,0.,  &amp;
-                                     xp(i)-xp(i-1), yp(i)-yp(i-1), 0.,  &amp;
-                                     xp(ip1)-xp(i), yp(ip1)-yp(i), 0.,  &amp;
-                                     0., 0., 1.)
+            thetat(i) = plane_angle( 0.0_RKIND, 0.0_RKIND, 0.0_RKIND,  &amp;
+                                     xp(i)-xp(i-1), yp(i)-yp(i-1), 0.0_RKIND,  &amp;
+                                     xp(ip1)-xp(i), yp(ip1)-yp(i), 0.0_RKIND,  &amp;
+                                     0.0_RKIND, 0.0_RKIND, 1.0_RKIND)
             thetat(i) = thetat(i) + thetat(i-1)
          end do
 
@@ -929,6 +930,6 @@
 
       if (debug) write(0,*) ' exiting def weight calc '
 
-   end subroutine ocn_initialize_deformation_weights
+   end subroutine ocn_initialize_deformation_weights!}}}
 
 end module ocn_advection

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
    use ocn_equation_of_state_linear
    use ocn_equation_of_state_jm
 
@@ -45,8 +44,8 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: eosON
-   logical :: linearEos, jmEos
+   integer :: eosON
+   integer :: linearEos, jmEos
 
 
 !***********************************************************************
@@ -97,20 +96,18 @@
 
       err = 0
 
-      if(.not.eosOn) return
+      if(eosOn == 0) return
 
-      call mpas_timer_start(&quot;ocn_equation_of_state_rho&quot;)
-
       tracers =&gt; s % tracers % array
       indexT = s % index_temperature
       indexS = s % index_salinity
 
-      if (linearEos) then
+      if (linearEos == 1) then
          rho =&gt; s % rho % array
 
          call ocn_equation_of_state_linear_rho(grid, indexT, indexS, tracers, rho, err)
 
-      elseif (jmEos) then
+      elseif (jmEos == 1) then
 
          if(k_displaced == 0) then
              rho =&gt; s % rho % array
@@ -122,8 +119,6 @@
 
       endif
 
-      call mpas_timer_stop(&quot;ocn_equation_of_state_rho&quot;)
-
    end subroutine ocn_equation_of_state_rho!}}}
 
 !***********************************************************************
@@ -155,17 +150,17 @@
       integer, intent(out) :: err
 
       err = 0
-      eosON = .false.
-      linearEos = .false.
-      jmEos = .false.
+      eosON = 0
+      linearEos = 0
+      jmEos = 0
 
       if(config_vert_grid_type.ne.'isopycnal') then
-          eosON = .true.
+          eosON = 1
 
           if (config_eos_type.eq.'linear') then
-              linearEos = .true.
+              linearEos = 1
           elseif (config_eos_type.eq.'jm') then
-              jmEos = .true.
+              jmEos = 1
           else
               print *,'Invalid choice for config_eos_type.'
               print *,'  Choices are: linear, jm'

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_jm.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_jm.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_jm.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -103,23 +102,23 @@
 
       integer, dimension(:), pointer :: maxLevelCell
 
-   real (kind=RKIND) :: &amp;
-      TQ,SQ,             &amp;! adjusted T,S
-      BULK_MOD,          &amp;! Bulk modulus
-      RHO_S,             &amp;! density at the surface
-      DRDT0,             &amp;! d(density)/d(temperature), for surface
-      DRDS0,             &amp;! d(density)/d(salinity   ), for surface
-      DKDT,              &amp;! d(bulk modulus)/d(pot. temp.)
-      DKDS,              &amp;! d(bulk modulus)/d(salinity  )
-      SQR,DENOMK,        &amp;! work arrays
-      WORK1, WORK2, WORK3, WORK4, T2, depth
+      real (kind=RKIND) :: &amp;
+         TQ,SQ,             &amp;! adjusted T,S
+         BULK_MOD,          &amp;! Bulk modulus
+         RHO_S,             &amp;! density at the surface
+         DRDT0,             &amp;! d(density)/d(temperature), for surface
+         DRDS0,             &amp;! d(density)/d(salinity   ), for surface
+         DKDT,              &amp;! d(bulk modulus)/d(pot. temp.)
+         DKDS,              &amp;! d(bulk modulus)/d(salinity  )
+         SQR,DENOMK,        &amp;! work arrays
+         WORK1, WORK2, WORK3, WORK4, T2, depth
 
-   real (kind=RKIND) :: &amp; 
-      tmin, tmax,        &amp;! valid temperature range for level k
-      smin, smax          ! valid salinity    range for level k
+      real (kind=RKIND) :: &amp; 
+         tmin, tmax,        &amp;! valid temperature range for level k
+         smin, smax          ! valid salinity    range for level k
 
-   real (kind=RKIND), dimension(:), allocatable :: &amp;
-      p, p2 ! temporary pressure scalars
+      real (kind=RKIND), dimension(:), allocatable :: &amp;
+         p, p2 ! temporary pressure scalars
 
 !-----------------------------------------------------------------------
 !
@@ -127,75 +126,73 @@
 !
 !-----------------------------------------------------------------------
 
-   !*** for density of fresh water (standard UNESCO)
+      !*** for density of fresh water (standard UNESCO)
 
-   real (kind=RKIND), parameter ::              &amp;
-      unt0 =   999.842594,           &amp;
-      unt1 =  6.793952e-2,           &amp;
-      unt2 = -9.095290e-3,           &amp;
-      unt3 =  1.001685e-4,           &amp;
-      unt4 = -1.120083e-6,           &amp;
-      unt5 =  6.536332e-9
+      real (kind=RKIND), parameter ::              &amp;
+         unt0 =   999.842594,           &amp;
+         unt1 =  6.793952e-2,           &amp;
+         unt2 = -9.095290e-3,           &amp;
+         unt3 =  1.001685e-4,           &amp;
+         unt4 = -1.120083e-6,           &amp;
+         unt5 =  6.536332e-9
+   
+      !*** for dependence of surface density on salinity (UNESCO)
 
-   !*** for dependence of surface density on salinity (UNESCO)
-
-   real (kind=RKIND), parameter ::              &amp;
-      uns1t0 =  0.824493 ,           &amp;
-      uns1t1 = -4.0899e-3,           &amp;
-      uns1t2 =  7.6438e-5,           &amp;
-      uns1t3 = -8.2467e-7,           &amp;
-      uns1t4 =  5.3875e-9,           &amp;
-      unsqt0 = -5.72466e-3,          &amp;
-      unsqt1 =  1.0227e-4,           &amp;
-      unsqt2 = -1.6546e-6,           &amp;
-      uns2t0 =  4.8314e-4
-
-   !*** from Table A1 of Jackett and McDougall
-
-   real (kind=RKIND), parameter ::              &amp;
-      bup0s0t0 =  1.965933e+4,       &amp;
-      bup0s0t1 =  1.444304e+2,       &amp;
-      bup0s0t2 = -1.706103   ,       &amp;
-      bup0s0t3 =  9.648704e-3,       &amp;
-      bup0s0t4 = -4.190253e-5
-
-   real (kind=RKIND), parameter ::              &amp;
-      bup0s1t0 =  5.284855e+1,       &amp;
-      bup0s1t1 = -3.101089e-1,       &amp;
-      bup0s1t2 =  6.283263e-3,       &amp;
-      bup0s1t3 = -5.084188e-5
-
-   real (kind=RKIND), parameter ::              &amp;
-      bup0sqt0 =  3.886640e-1,       &amp;
-      bup0sqt1 =  9.085835e-3,       &amp;
-      bup0sqt2 = -4.619924e-4
-
-   real (kind=RKIND), parameter ::              &amp;
-      bup1s0t0 =  3.186519   ,       &amp;
-      bup1s0t1 =  2.212276e-2,       &amp;
-      bup1s0t2 = -2.984642e-4,       &amp;
-      bup1s0t3 =  1.956415e-6 
-
-   real (kind=RKIND), parameter ::              &amp;
-      bup1s1t0 =  6.704388e-3,       &amp;
-      bup1s1t1 = -1.847318e-4,       &amp;
-      bup1s1t2 =  2.059331e-7,       &amp;
-      bup1sqt0 =  1.480266e-4 
-
-   real (kind=RKIND), parameter ::              &amp;
-      bup2s0t0 =  2.102898e-4,       &amp;
-      bup2s0t1 = -1.202016e-5,       &amp;
-      bup2s0t2 =  1.394680e-7,       &amp;
-      bup2s1t0 = -2.040237e-6,       &amp;
-      bup2s1t1 =  6.128773e-8,       &amp;
-      bup2s1t2 =  6.207323e-10
-
-   integer :: k_test, k_ref
-
+      real (kind=RKIND), parameter ::              &amp;
+         uns1t0 =  0.824493 ,           &amp;
+         uns1t1 = -4.0899e-3,           &amp;
+         uns1t2 =  7.6438e-5,           &amp;
+         uns1t3 = -8.2467e-7,           &amp;
+         uns1t4 =  5.3875e-9,           &amp;
+         unsqt0 = -5.72466e-3,          &amp;
+         unsqt1 =  1.0227e-4,           &amp;
+         unsqt2 = -1.6546e-6,           &amp;
+         uns2t0 =  4.8314e-4
+   
+      !*** from Table A1 of Jackett and McDougall
+   
+      real (kind=RKIND), parameter ::              &amp;
+         bup0s0t0 =  1.965933e+4,       &amp;
+         bup0s0t1 =  1.444304e+2,       &amp;
+         bup0s0t2 = -1.706103   ,       &amp;
+         bup0s0t3 =  9.648704e-3,       &amp;
+         bup0s0t4 = -4.190253e-5
+   
+      real (kind=RKIND), parameter ::              &amp;
+         bup0s1t0 =  5.284855e+1,       &amp;
+         bup0s1t1 = -3.101089e-1,       &amp;
+         bup0s1t2 =  6.283263e-3,       &amp;
+         bup0s1t3 = -5.084188e-5
+   
+      real (kind=RKIND), parameter ::              &amp;
+         bup0sqt0 =  3.886640e-1,       &amp;
+         bup0sqt1 =  9.085835e-3,       &amp;
+         bup0sqt2 = -4.619924e-4
+   
+      real (kind=RKIND), parameter ::              &amp;
+         bup1s0t0 =  3.186519   ,       &amp;
+         bup1s0t1 =  2.212276e-2,       &amp;
+         bup1s0t2 = -2.984642e-4,       &amp;
+         bup1s0t3 =  1.956415e-6 
+   
+      real (kind=RKIND), parameter ::              &amp;
+         bup1s1t0 =  6.704388e-3,       &amp;
+         bup1s1t1 = -1.847318e-4,       &amp;
+         bup1s1t2 =  2.059331e-7,       &amp;
+         bup1sqt0 =  1.480266e-4 
+   
+      real (kind=RKIND), parameter ::              &amp;
+         bup2s0t0 =  2.102898e-4,       &amp;
+         bup2s0t1 = -1.202016e-5,       &amp;
+         bup2s0t2 =  1.394680e-7,       &amp;
+         bup2s1t0 = -2.040237e-6,       &amp;
+         bup2s1t1 =  6.128773e-8,       &amp;
+         bup2s1t2 =  6.207323e-10
+   
+      integer :: k_test, k_ref
+   
       err = 0
-
-      call mpas_timer_start(&quot;equation_of_state_jm&quot;)
-
+   
       nCells      = grid % nCells
       maxLevelCell      =&gt; grid % maxLevelCell % array
       nVertLevels = grid % nVertLevels
@@ -224,93 +221,90 @@
             + 0.100766*depth + 2.28405e-7*depth**2
       enddo
 
-   !  If k_displaced=0, in-situ density is returned (no displacement)
-   !  If k_displaced/=0, potential density is returned
+      !  If k_displaced=0, in-situ density is returned (no displacement)
+      !  If k_displaced/=0, potential density is returned
 
-   !  if displacement_type = 'relative', potential density is calculated
-   !     referenced to level k + k_displaced
-   !  if displacement_type = 'absolute', potential density is calculated
-   !     referenced to level k_displaced for all k
-   !  NOTE: k_displaced = 0 or &gt; nVertLevels is incompatible with 'absolute'
-   !     so abort if necessary
+      !  if displacement_type = 'relative', potential density is calculated
+      !     referenced to level k + k_displaced
+      !  if displacement_type = 'absolute', potential density is calculated
+      !     referenced to level k_displaced for all k
+      !  NOTE: k_displaced = 0 or &gt; nVertLevels is incompatible with 'absolute'
+      !     so abort if necessary
 
-   if (displacement_type == 'absolute' .and.   &amp;
-       (k_displaced &lt;= 0 .or. k_displaced &gt; nVertLevels) ) then
-      write(0,*) 'Abort: In equation_of_state_jm', &amp;
-         ' k_displaced must be between 1 and nVertLevels for ', &amp;
-         'displacement_type = absolute'
-      call mpas_dmpar_abort(dminfo)
-   endif
+      if (displacement_type == 'absolute' .and.   &amp;
+         (k_displaced &lt;= 0 .or. k_displaced &gt; nVertLevels) ) then
 
-   if (k_displaced == 0) then
-      do k=1,nVertLevels
-         p(k)   = pRefEOS(k)
-         p2(k)  = p(k)*p(k)
-      enddo
-   else ! k_displaced /= 0
-      do k=1,nVertLevels
-         if (displacement_type == 'relative') then
-            k_test = min(k + k_displaced, nVertLevels)
-            k_ref  = max(k_test, 1)
-         else
-            k_test = min(k_displaced, nVertLevels)
-            k_ref  = max(k_test, 1)
-         endif
-         p(k)   = pRefEOS(k_ref)
-         p2(k)  = p(k)*p(k)
-      enddo
-   endif
+         write(0,*) 'Abort: In equation_of_state_jm', &amp;
+             ' k_displaced must be between 1 and nVertLevels for ', &amp;
+             'displacement_type = absolute'
+         call mpas_dmpar_abort(dminfo)
+      endif
 
-  do iCell=1,nCells
-    do k=1,maxLevelCell(iCell)
+      if (k_displaced == 0) then
+         do k=1,nVertLevels
+            p(k)   = pRefEOS(k)
+            p2(k)  = p(k)*p(k)
+         enddo
+      else ! k_displaced /= 0
+         do k=1,nVertLevels
+            if (displacement_type == 'relative') then
+               k_test = min(k + k_displaced, nVertLevels)
+               k_ref  = max(k_test, 1)
+            else
+               k_test = min(k_displaced, nVertLevels)
+               k_ref  = max(k_test, 1)
+            endif
+            p(k)   = pRefEOS(k_ref)
+            p2(k)  = p(k)*p(k)
+         enddo
+      endif
 
-      SQ  = max(min(tracers(indexS,k,iCell),smax),smin)
-      TQ  = max(min(tracers(indexT,k,iCell),tmax),tmin)
+      do iCell=1,nCells
+         do k=1,maxLevelCell(iCell)
+            SQ  = max(min(tracers(indexS,k,iCell),smax),smin)
+            TQ  = max(min(tracers(indexT,k,iCell),tmax),tmin)
+   
+            SQR = sqrt(SQ)
+            T2  = TQ*TQ
 
-      SQR = sqrt(SQ)
-      T2  = TQ*TQ
+            !***
+            !*** first calculate surface (p=0) values from UNESCO eqns.
+            !***
 
-      !***
-      !*** first calculate surface (p=0) values from UNESCO eqns.
-      !***
+            WORK1 = uns1t0 + uns1t1*TQ + &amp; 
+                   (uns1t2 + uns1t3*TQ + uns1t4*T2)*T2
+            WORK2 = SQR*(unsqt0 + unsqt1*TQ + unsqt2*T2)
 
-      WORK1 = uns1t0 + uns1t1*TQ + &amp; 
-             (uns1t2 + uns1t3*TQ + uns1t4*T2)*T2
-      WORK2 = SQR*(unsqt0 + unsqt1*TQ + unsqt2*T2)
+            RHO_S = unt1*TQ + (unt2 + unt3*TQ + (unt4 + unt5*TQ)*T2)*T2 &amp;
+                            + (uns2t0*SQ + WORK1 + WORK2)*SQ
 
-      RHO_S = unt1*TQ + (unt2 + unt3*TQ + (unt4 + unt5*TQ)*T2)*T2 &amp;
-                      + (uns2t0*SQ + WORK1 + WORK2)*SQ
+            !***
+            !*** now calculate bulk modulus at pressure p from 
+            !*** Jackett and McDougall formula
+            !***
 
-      !***
-      !*** now calculate bulk modulus at pressure p from 
-      !*** Jackett and McDougall formula
-      !***
+            WORK3 = bup0s1t0 + bup0s1t1*TQ +                    &amp;
+                    (bup0s1t2 + bup0s1t3*TQ)*T2 +                &amp;
+                    p(k) *(bup1s1t0 + bup1s1t1*TQ + bup1s1t2*T2) + &amp;
+                    p2(k)*(bup2s1t0 + bup2s1t1*TQ + bup2s1t2*T2)
+            WORK4 = SQR*(bup0sqt0 + bup0sqt1*TQ + bup0sqt2*T2 + &amp;
+                         bup1sqt0*p(k))
+   
+            BULK_MOD  = bup0s0t0 + bup0s0t1*TQ +                    &amp;
+                        (bup0s0t2 + bup0s0t3*TQ + bup0s0t4*T2)*T2 + &amp;
+                        p(k) *(bup1s0t0 + bup1s0t1*TQ +                &amp;
+                        (bup1s0t2 + bup1s0t3*TQ)*T2) +           &amp;
+                        p2(k)*(bup2s0t0 + bup2s0t1*TQ + bup2s0t2*T2) + &amp;
+                        SQ*(WORK3 + WORK4)
+  
+            DENOMK = 1.0/(BULK_MOD - p(k))
+   
+            rho(k,iCell) = (unt0 + RHO_S)*BULK_MOD*DENOMK
 
-      WORK3 = bup0s1t0 + bup0s1t1*TQ +                    &amp;
-             (bup0s1t2 + bup0s1t3*TQ)*T2 +                &amp;
-              p(k) *(bup1s1t0 + bup1s1t1*TQ + bup1s1t2*T2) + &amp;
-              p2(k)*(bup2s1t0 + bup2s1t1*TQ + bup2s1t2*T2)
-      WORK4 = SQR*(bup0sqt0 + bup0sqt1*TQ + bup0sqt2*T2 + &amp;
-                   bup1sqt0*p(k))
+         end do
+      end do
 
-      BULK_MOD  = bup0s0t0 + bup0s0t1*TQ +                    &amp;
-                  (bup0s0t2 + bup0s0t3*TQ + bup0s0t4*T2)*T2 + &amp;
-                  p(k) *(bup1s0t0 + bup1s0t1*TQ +                &amp;
-                     (bup1s0t2 + bup1s0t3*TQ)*T2) +           &amp;
-                  p2(k)*(bup2s0t0 + bup2s0t1*TQ + bup2s0t2*T2) + &amp;
-                  SQ*(WORK3 + WORK4)
-
-      DENOMK = 1.0/(BULK_MOD - p(k))
-
-      rho(k,iCell) = (unt0 + RHO_S)*BULK_MOD*DENOMK
-
-    end do
-  end do
-
-   deallocate(pRefEOS,p,p2)
-
-   call mpas_timer_stop(&quot;equation_of_state_jm&quot;)
-
+      deallocate(pRefEOS,p,p2)
    end subroutine ocn_equation_of_state_jm_rho!}}}
 
 !***********************************************************************

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_linear.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_linear.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_linear.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -87,8 +86,6 @@
       integer :: nCells, iCell, k
       type (dm_info) :: dminfo
 
-      call mpas_timer_start(&quot;ocn_equation_of_state_linear&quot;)
-
       maxLevelCell      =&gt; grid % maxLevelCell % array
       nCells      = grid % nCells
 
@@ -103,8 +100,6 @@
          end do
       end do
 
-      call mpas_timer_stop(&quot;ocn_equation_of_state_linear&quot;)
-
    end subroutine ocn_equation_of_state_linear_rho!}}}
 
 !***********************************************************************

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_global_diagnostics.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_global_diagnostics.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_global_diagnostics.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -4,14 +4,17 @@
    use mpas_configure
    use mpas_constants
    use mpas_dmpar
+   use mpas_timer
 
    implicit none
    save
    public
 
+   type (timer_node), pointer :: diagBlockTimer, diagMPITimer
+
    contains
 
-   subroutine ocn_compute_global_diagnostics(dminfo, state, grid, timeIndex, dt)
+   subroutine ocn_compute_global_diagnostics(domain, timeLevel, timeIndex, dt)!{{{
 
       ! Note: this routine assumes that there is only one block per processor. No looping
       ! is preformed over blocks.
@@ -26,197 +29,300 @@
 
       implicit none
 
-      type (dm_info), intent(in) :: dminfo
-      type (state_type), intent(inout) :: state
-      type (mesh_type), intent(in) :: grid
+      type (domain_type), intent(inout) :: domain !&lt; Input/Output: domain information
       integer, intent(in) :: timeIndex
       real (kind=RKIND), intent(in) :: dt
 
+      type (block_type), pointer :: block
+      type (dm_info), pointer :: dminfo
+      type (state_type), pointer :: state
+      type (mesh_type), pointer :: grid
+
       integer :: nVertLevels, nCellsSolve, nEdgesSolve, nVerticesSolve, nCellsGlobal, nEdgesGlobal, nVerticesGlobal, iTracer
+      integer :: elementIndex, variableIndex, nVariables, nSums, nMaxes, nMins
+      integer :: timeLevel,k,i, num_tracers
+      integer :: fileID
+      integer, parameter :: kMaxVariables = 1024 ! this must be a little more than double the number of variables to be reduced
 
-      real (kind=RKIND) ::  areaCellGlobal, areaEdgeGlobal, areaTriangleGlobal
+      real (kind=RKIND) :: volumeCellGlobal, volumeEdgeGlobal, CFLNumberGlobal, localCFL, localSum, areaCellGlobal, areaEdgeGlobal, areaTriangleGlobal
       real (kind=RKIND), dimension(:), pointer ::  areaCell, dcEdge, dvEdge, areaTriangle, areaEdge
       real (kind=RKIND), dimension(:,:), pointer :: h, u, v, h_edge, circulation, vorticity, ke, pv_edge, pv_vertex, &amp;
          pv_cell, gradPVn, gradPVt, pressure, MontPot, wTop, rho, tracerTemp
       real (kind=RKIND), dimension(:,:,:), pointer :: tracers
+      
+      real (kind=RKIND), dimension(kMaxVariables) :: sums, mins, maxes, averages, verticalSumMins, verticalSumMaxes, reductions
+      real (kind=RKIND), dimension(kMaxVariables) :: sums_tmp, mins_tmp, maxes_tmp, averages_tmp, verticalSumMins_tmp, verticalSumMaxes_tmp
 
-      real (kind=RKIND) :: volumeCellGlobal, volumeEdgeGlobal, CFLNumberGlobal
-      real (kind=RKIND) ::  localCFL, localSum
-      integer :: elementIndex, variableIndex, nVariables, nSums, nMaxes, nMins
-      integer :: timeLevel,k,i, num_tracers
+      block =&gt; domain % blocklist
+      dminfo =&gt; domain % dminfo
 
-      integer, parameter :: kMaxVariables = 1024 ! this must be a little more than double the number of variables to be reduced
+      sums = 0.0
+      mins = 0.0
+      maxes = 0.0
+      averages = 0.0
+      verticalSumMins = 0.0
+      verticalSumMaxes = 0.0
+      reductions = 0.0
 
-      real (kind=RKIND), dimension(kMaxVariables) :: sums, mins, maxes, averages, verticalSumMins, verticalSumMaxes, reductions
+      call mpas_timer_start(&quot;diagnostic block loop&quot;, .false., diagBlockTimer)
+      do while (associated(block))
+         state =&gt; block % state % time_levs(timeLevel) % state
+         grid =&gt; block % mesh
+         
+         num_tracers = state % num_tracers
 
-      integer :: fileID
+         nVertLevels = grid % nVertLevels
+         nCellsSolve = grid % nCellsSolve
+         nEdgesSolve = grid % nEdgesSolve
+         nVerticesSolve = grid % nVerticesSolve
 
-      num_tracers = state % num_tracers
+         areaCell =&gt; grid % areaCell % array
+         dcEdge =&gt; grid % dcEdge % array
+         dvEdge =&gt; grid % dvEdge % array
+         areaTriangle =&gt; grid % areaTriangle % array
+         allocate(areaEdge(1:nEdgesSolve))
+         areaEdge = dcEdge(1:nEdgesSolve)*dvEdge(1:nEdgesSolve)
 
-      nVertLevels = grid % nVertLevels
-      nCellsSolve = grid % nCellsSolve
-      nEdgesSolve = grid % nEdgesSolve
-      nVerticesSolve = grid % nVerticesSolve
+         h =&gt; state % h % array
+         u =&gt; state % u % array
+         rho =&gt; state % rho % array
+         tracers =&gt; state % tracers % array
+         v =&gt; state % v % array
+         wTop =&gt; state % wTop % array
+         h_edge =&gt; state % h_edge % array
+         circulation =&gt; state % circulation % array
+         vorticity =&gt; state % vorticity % array
+         ke =&gt; state % ke % array
+         pv_edge =&gt; state % pv_edge % array
+         pv_vertex =&gt; state % pv_vertex % array
+         pv_cell =&gt; state % pv_cell % array
+         gradPVn =&gt; state % gradPVn % array
+         gradPVt =&gt; state % gradPVt % array
+         MontPot =&gt; state % MontPot % array
+         pressure =&gt; state % pressure % array
 
-      areaCell =&gt; grid % areaCell % array
-      dcEdge =&gt; grid % dcEdge % array
-      dvEdge =&gt; grid % dvEdge % array
-      areaTriangle =&gt; grid % areaTriangle % array
-      allocate(areaEdge(1:nEdgesSolve))
-      areaEdge = dcEdge(1:nEdgesSolve)*dvEdge(1:nEdgesSolve)
+         variableIndex = 0
+         ! h
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+            sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      h =&gt; state % h % array
-      u =&gt; state % u % array
-      rho =&gt; state % rho % array
-      tracers =&gt; state % tracers % array
-      v =&gt; state % v % array
-      wTop =&gt; state % wTop % array
-      h_edge =&gt; state % h_edge % array
-      circulation =&gt; state % circulation % array
-      vorticity =&gt; state % vorticity % array
-      ke =&gt; state % ke % array
-      pv_edge =&gt; state % pv_edge % array
-      pv_vertex =&gt; state % pv_vertex % array
-      pv_cell =&gt; state % pv_cell % array
-      gradPVn =&gt; state % gradPVn % array
-      gradPVt =&gt; state % gradPVt % array
-      MontPot =&gt; state % MontPot % array
-      pressure =&gt; state % pressure % array
+         ! u
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
+            u(:,1:nEdgesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      variableIndex = 0
-      ! h
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-        sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), verticalSumMaxes(variableIndex))
+         ! v
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
+            v(:,1:nEdgesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! u
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
-        u(:,1:nEdgesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! h_edge
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
+            sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! v
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
-        v(:,1:nEdgesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! circulation
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_local_stats(dminfo, nVertLevels, nVerticesSolve, circulation(:,1:nVerticesSolve), &amp;
+            sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), verticalSumMaxes_tmp(variableIndex))
+            sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! h_edge
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
-        sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), verticalSumMaxes(variableIndex))
+         ! vorticity
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nVerticesSolve, areaTriangle(1:nVerticesSolve), &amp;
+            vorticity(:,1:nVerticesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), &amp;
+            verticalSumMins_tmp(variableIndex), verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! circulation
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_local_stats(dminfo, nVertLevels, nVerticesSolve, circulation(:,1:nVerticesSolve), &amp;
-        sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), verticalSumMaxes(variableIndex))
+         ! ke
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+            ke(:,1:nCellsSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! vorticity
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nVerticesSolve, areaTriangle(1:nVerticesSolve), &amp;
-        vorticity(:,1:nVerticesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), &amp;
-        verticalSumMins(variableIndex), verticalSumMaxes(variableIndex))
+         ! pv_edge
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
+            pv_edge(:,1:nEdgesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! ke
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-        ke(:,1:nCellsSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! pv_vertex
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nVerticesSolve, areaTriangle(1:nVerticesSolve), &amp;
+            pv_vertex(:,1:nVerticesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), &amp;
+            verticalSumMins_tmp(variableIndex), verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! pv_edge
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
-        pv_edge(:,1:nEdgesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! pv_cell
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+            pv_cell(:,1:nCellsSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! pv_vertex
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nVerticesSolve, areaTriangle(1:nVerticesSolve), &amp;
-        pv_vertex(:,1:nVerticesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), &amp;
-        verticalSumMins(variableIndex), verticalSumMaxes(variableIndex))
+         ! gradPVn
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
+            gradPVn(:,1:nEdgesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! pv_cell
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-        pv_cell(:,1:nCellsSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! gradPVt
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
+            gradPVt(:,1:nEdgesSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! gradPVn
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
-        gradPVn(:,1:nEdgesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! pressure
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+            pressure(:,1:nCellsSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! gradPVt
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nEdgesSolve, areaEdge(1:nEdgesSolve), h_edge(:,1:nEdgesSolve), &amp;
-        gradPVt(:,1:nEdgesSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! MontPot
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+            MontPot(:,1:nCellsSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! pressure
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-        pressure(:,1:nCellsSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! wTop vertical velocity
+         variableIndex = variableIndex + 1
+         call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels+1, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+            wTop(:,1:nCellsSolve), sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+            verticalSumMaxes_tmp(variableIndex))
+         sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+         mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+         maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+         verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+         verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
 
-      ! MontPot
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-        MontPot(:,1:nCellsSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         ! Tracers
+         allocate(tracerTemp(nVertLevels,nCellsSolve))
+         do iTracer=1,num_tracers
+            variableIndex = variableIndex + 1
+            tracerTemp = Tracers(iTracer,:,1:nCellsSolve)
+            call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
+               tracerTemp, sums_tmp(variableIndex), mins_tmp(variableIndex), maxes_tmp(variableIndex), verticalSumMins_tmp(variableIndex), &amp;
+               verticalSumMaxes_tmp(variableIndex))
+            sums(variableIndex) = sums(variableIndex) + sums_tmp(variableIndex)
+            mins(variableIndex) = min(mins(variableIndex), mins_tmp(variableIndex))
+            maxes(variableIndex) = max(maxes(variableIndex), maxes_tmp(variableIndex))
+            verticalSumMins(variableIndex) = min(verticalSumMins(variableIndex), verticalSumMins_tmp(variableIndex))
+            verticalSumMaxes(variableIndex) = max(verticalSumMaxes(variableIndex), verticalSumMaxes_tmp(variableIndex))
+         enddo
+         deallocate(tracerTemp)
 
-      ! wTop vertical velocity
-      variableIndex = variableIndex + 1
-      call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels+1, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-        wTop(:,1:nCellsSolve), sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-        verticalSumMaxes(variableIndex))
+         nVariables = variableIndex
+         nSums = nVariables
+         nMins = nVariables
+         nMaxes = nVariables
 
-      ! Tracers
-      allocate(tracerTemp(nVertLevels,nCellsSolve))
-      do iTracer=1,num_tracers
-        variableIndex = variableIndex + 1
-        tracerTemp = Tracers(iTracer,:,1:nCellsSolve)
-        call ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nCellsSolve, areaCell(1:nCellsSolve), h(:,1:nCellsSolve), &amp;
-          tracerTemp, sums(variableIndex), mins(variableIndex), maxes(variableIndex), verticalSumMins(variableIndex), &amp;
-          verticalSumMaxes(variableIndex))
-      enddo
-      deallocate(tracerTemp)
+         nSums = nSums + 1
+         sums(nSums) = sums(nSums) + sum(areaCell(1:nCellsSolve))
 
-      nVariables = variableIndex
-      nSums = nVariables
-      nMins = nVariables
-      nMaxes = nVariables
+         nSums = nSums + 1
+         sums(nSums) = sums(nSums) + sum(dcEdge(1:nEdgesSolve)*dvEdge(1:nEdgesSolve))
 
-      nSums = nSums + 1
-      sums(nSums) = sum(areaCell(1:nCellsSolve))
+         nSums = nSums + 1
+         sums(nSums) = sums(nSums) + sum(areaTriangle(1:nVerticesSolve))
 
-      nSums = nSums + 1
-      sums(nSums) = sum(dcEdge(1:nEdgesSolve)*dvEdge(1:nEdgesSolve))
+         nSums = nSums + 1
+         sums(nSums) = sums(nSums) + nCellsSolve
 
-      nSums = nSums + 1
-      sums(nSums) = sum(areaTriangle(1:nVerticesSolve))
+         nSums = nSums + 1
+         sums(nSums) = sums(nSums) + nEdgesSolve
 
-      nSums = nSums + 1
-      sums(nSums) = nCellsSolve
+         nSums = nSums + 1
+         sums(nSums) = sums(nSums) + nVerticesSolve
 
-      nSums = nSums + 1
-      sums(nSums) = nEdgesSolve
+         localCFL = 0.0
+         do elementIndex = 1,nEdgesSolve
+            localCFL = max(localCFL, maxval(dt*u(:,elementIndex)/dcEdge(elementIndex)))
+         end do
+         nMaxes = nMaxes + 1
+         maxes(nMaxes) = localCFL
 
-      nSums = nSums + 1
-      sums(nSums) = nVerticesSolve
+         do i = 1, nVariables
+            mins(nMins+i) = min(mins(nMins+i),verticalSumMins_tmp(i))
+            maxes(nMaxes+i) = max(maxes(nMaxes+i),verticalSumMaxes_tmp(i))
+         end do
 
-      localCFL = 0.0
-      do elementIndex = 1,nEdgesSolve
-         localCFL = max(localCFL, maxval(dt*u(:,elementIndex)/dcEdge(elementIndex)))
+         nMins = nMins + nVariables
+         nMaxes = nMaxes + nVariables
+
+         block =&gt; block % next
       end do
-      nMaxes = nMaxes + 1
-      maxes(nMaxes) = localCFL
+      call mpas_timer_stop(&quot;diagnostic block loop&quot;, diagBlockTimer)
+      call mpas_timer_start(&quot;diagnostics mpi&quot;, .false., diagMPITimer)
 
-      mins(nMins+1:nMins+nVariables) = verticalSumMins(1:nVariables)
-      nMins = nMins + nVariables
-      maxes(nMaxes+1:nMaxes+nVariables) = verticalSumMaxes(1:nVariables)
-      nMaxes = nMaxes + nVariables
-
       ! global reduction of the 5 arrays (packed into 3 to minimize global communication)
       call mpas_dmpar_sum_real_array(dminfo, nSums, sums(1:nSums), reductions(1:nSums))
       sums(1:nVariables) = reductions(1:nVariables)
@@ -306,6 +412,8 @@
         averages(variableIndex) = sums(variableIndex)/volumeCellGlobal
       enddo
 
+      call mpas_timer_stop(&quot;diagnostics mpi&quot;, diagMPITimer)
+
       ! write out the data to files
       if (dminfo % my_proc_id == IO_NODE) then
          fileID = getFreeUnit()
@@ -343,9 +451,9 @@
       state % CFLNumberGlobal % scalar = CFLNumberGlobal
       deallocate(areaEdge)
 
-   end subroutine ocn_compute_global_diagnostics
+   end subroutine ocn_compute_global_diagnostics!}}}
 
-   integer function getFreeUnit()
+   integer function getFreeUnit()!{{{
       implicit none
 
       integer :: index
@@ -361,9 +469,9 @@
             end if
          end if
       end do
-   end function getFreeUnit
+   end function getFreeUnit!}}}
 
-   subroutine ocn_compute_field_local_stats(dminfo, nVertLevels, nElements, field, localSum, localMin, localMax, localVertSumMin, &amp;
+   subroutine ocn_compute_field_local_stats(dminfo, nVertLevels, nElements, field, localSum, localMin, localMax, localVertSumMin, &amp;!{{{
       localVertSumMax)
 
       implicit none
@@ -380,9 +488,9 @@
       localVertSumMin = minval(sum(field,1))
       localVertSumMax = maxval(sum(field,1))
 
-   end subroutine ocn_compute_field_local_stats
+   end subroutine ocn_compute_field_local_stats!}}}
 
-   subroutine ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nElements, areas, field, localSum, localMin, &amp;
+   subroutine ocn_compute_field_area_weighted_local_stats(dminfo, nVertLevels, nElements, areas, field, localSum, localMin, &amp;!{{{
       localMax, localVertSumMin, localVertSumMax)
 
       implicit none
@@ -406,9 +514,9 @@
       localVertSumMin = minval(sum(field,1))
       localVertSumMax = maxval(sum(field,1))
 
-   end subroutine ocn_compute_field_area_weighted_local_stats
+   end subroutine ocn_compute_field_area_weighted_local_stats!}}}
 
-   subroutine ocn_compute_field_thickness_weighted_local_stats(dminfo, nVertLevels, nElements, h, field, &amp;
+   subroutine ocn_compute_field_thickness_weighted_local_stats(dminfo, nVertLevels, nElements, h, field, &amp;!{{{
       localSum, localMin, localMax, localVertSumMin, localVertSumMax)
 
       implicit none
@@ -430,9 +538,9 @@
       localVertSumMin = minval(sum(h*field,1))
       localVertSumMax = maxval(sum(h*field,1))
 
-   end subroutine ocn_compute_field_thickness_weighted_local_stats
+   end subroutine ocn_compute_field_thickness_weighted_local_stats!}}}
 
-   subroutine ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nElements, areas, h, field, &amp;
+   subroutine ocn_compute_field_volume_weighted_local_stats(dminfo, nVertLevels, nElements, areas, h, field, &amp;!{{{
       localSum, localMin, localMax, localVertSumMin, localVertSumMax)
 
       implicit none
@@ -459,11 +567,10 @@
       localVertSumMin = minval(sum(h*field,1))
       localVertSumMax = maxval(sum(h*field,1))
 
-   end subroutine ocn_compute_field_volume_weighted_local_stats
+   end subroutine ocn_compute_field_volume_weighted_local_stats!}}}
 
+   subroutine ocn_compute_global_sum(dminfo, nVertLevels, nElements, field, globalSum)!{{{
 
-   subroutine ocn_compute_global_sum(dminfo, nVertLevels, nElements, field, globalSum)
-
       implicit none
 
       type (dm_info), intent(in) :: dminfo
@@ -476,9 +583,9 @@
       localSum = sum(field)
       call mpas_dmpar_sum_real(dminfo, localSum, globalSum)
 
-   end subroutine ocn_compute_global_sum
+   end subroutine ocn_compute_global_sum!}}}
 
-   subroutine ocn_compute_area_weighted_global_sum(dminfo, nVertLevels, nElements, areas, field, globalSum)
+   subroutine ocn_compute_area_weighted_global_sum(dminfo, nVertLevels, nElements, areas, field, globalSum)!{{{
 
       implicit none
 
@@ -498,9 +605,9 @@
    
       call mpas_dmpar_sum_real(dminfo, localSum, globalSum)
        
-   end subroutine ocn_compute_area_weighted_global_sum
+   end subroutine ocn_compute_area_weighted_global_sum!}}}
 
-   subroutine ocn_compute_volume_weighted_global_sum(dminfo, nVertLevels, nElements, areas, h, field, globalSum)
+   subroutine ocn_compute_volume_weighted_global_sum(dminfo, nVertLevels, nElements, areas, h, field, globalSum)!{{{
 
       implicit none
 
@@ -517,9 +624,9 @@
 
       call ocn_compute_area_weighted_global_sum(dminfo, nVertLevels, nElements, areas, hTimesField, globalSum)
 
-   end subroutine ocn_compute_volume_weighted_global_sum
+   end subroutine ocn_compute_volume_weighted_global_sum!}}}
 
-   subroutine ocn_compute_global_min(dminfo, nVertLevels, nElements, field, globalMin)
+   subroutine ocn_compute_global_min(dminfo, nVertLevels, nElements, field, globalMin)!{{{
 
       implicit none
 
@@ -533,9 +640,9 @@
       localMin = minval(field)
       call mpas_dmpar_min_real(dminfo, localMin, globalMin)
 
-   end subroutine ocn_compute_global_min
+   end subroutine ocn_compute_global_min!}}}
 
-   subroutine ocn_compute_global_max(dminfo, nVertLevels, nElements, field, globalMax)
+   subroutine ocn_compute_global_max(dminfo, nVertLevels, nElements, field, globalMax)!{{{
 
       implicit none
 
@@ -549,9 +656,9 @@
       localMax = maxval(field)
       call mpas_dmpar_max_real(dminfo, localMax, globalMax)
 
-   end subroutine ocn_compute_global_max
+   end subroutine ocn_compute_global_max!}}}
 
-   subroutine ocn_compute_global_vert_sum_horiz_min(dminfo, nVertLevels, nElements, field, globalMin)
+   subroutine ocn_compute_global_vert_sum_horiz_min(dminfo, nVertLevels, nElements, field, globalMin)!{{{
 
       implicit none
 
@@ -565,9 +672,9 @@
       localMin = minval(sum(field,1))
       call mpas_dmpar_min_real(dminfo, localMin, globalMin)
 
-   end subroutine ocn_compute_global_vert_sum_horiz_min
+   end subroutine ocn_compute_global_vert_sum_horiz_min!}}}
 
-   subroutine ocn_compute_global_vert_sum_horiz_max(dminfo, nVertLevels, nElements, field, globalMax)
+   subroutine ocn_compute_global_vert_sum_horiz_max(dminfo, nVertLevels, nElements, field, globalMax)!{{{
 
       implicit none
 
@@ -581,9 +688,9 @@
       localMax = maxval(sum(field,1))
       call mpas_dmpar_max_real(dminfo, localMax, globalMax)
 
-   end subroutine ocn_compute_global_vert_sum_horiz_max
+   end subroutine ocn_compute_global_vert_sum_horiz_max!}}}
 
-   subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_min(dminfo, nVertLevels, nElements, h, field, globalMin)
+   subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_min(dminfo, nVertLevels, nElements, h, field, globalMin)!{{{
 
       implicit none
 
@@ -597,9 +704,9 @@
       localMin = minval(sum(h*field,1))
       call mpas_dmpar_min_real(dminfo, localMin, globalMin)
 
-   end subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_min
+   end subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_min!}}}
 
-   subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_max(dminfo, nVertLevels, nElements, h, field, globalMax)
+   subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_max(dminfo, nVertLevels, nElements, h, field, globalMax)!{{{
 
       implicit none
 
@@ -613,6 +720,6 @@
       localMax = maxval(sum(h*field,1))
       call mpas_dmpar_max_real(dminfo, localMax, globalMax)
 
-   end subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_max
+   end subroutine ocn_compute_global_vert_thickness_weighted_sum_horiz_max!}}}
 
 end module ocn_global_diagnostics

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_mpas_core.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_mpas_core.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_mpas_core.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,12 +1,15 @@
 module mpas_core
 
+   use mpas_configure
    use mpas_framework
    use mpas_timekeeping
    use mpas_dmpar
+   use mpas_timer
+   use mpas_counter
+
+   use ocn_global_diagnostics
    use ocn_test_cases
-
    use ocn_time_integration
-
    use ocn_tendency
 
    use ocn_vel_pressure_grad
@@ -23,6 +26,8 @@
 
    use ocn_vmix
 
+   use ocn_time_average
+
    type (io_output_object) :: restart_obj
 
    integer :: current_outfile_frames
@@ -33,11 +38,13 @@
    integer, parameter :: restartAlarmID = 2
    integer, parameter :: statsAlarmID = 3
 
+   type (timer_node), pointer :: globalDiagTimer, timeIntTimer
+   type (timer_node), pointer :: initDiagSolveTimer
+
    contains
 
    subroutine mpas_core_init(domain, startTimeStamp)!{{{
 
-      use mpas_configure
       use mpas_grid_types
 
       implicit none
@@ -79,29 +86,36 @@
       call ocn_equation_of_state_init(err_tmp)
       err = ior(err, err_tmp)
 
+      call ocn_tendency_init(err_tmp)
+      err = ior(err,err_tmp)
+
+      call mpas_timer_init(domain)
+
+      call mpas_counter_init(domain)
+
       if(err.eq.1) then
           call mpas_dmpar_abort(dminfo)
       endif
 
       if (.not. config_do_restart) call setup_sw_test_case(domain)
 
-      call compute_maxLevel(domain)
+      call ocn_compute_max_level(domain)
 
       if (config_vert_grid_type.eq.'isopycnal') then
          print *, ' Using isopycnal vertical coordinates'
       elseif (config_vert_grid_type.eq.'zlevel') then
          print *, ' Using z-level vertical coordinates'
-         call init_ZLevel(domain)
+         call ocn_init_z_level(domain)
       elseif (config_vert_grid_type.eq.'zstar1') then
          print *, ' Using z-star vertical coordinates,', &amp;
            ' all convergence in top layer'
-         call init_ZLevel(domain)
+         call ocn_init_z_level(domain)
       elseif (config_vert_grid_type.eq.'zstar') then
          print *, ' Using z-star vertical coordinates'
-         call init_ZLevel(domain)
+         call ocn_init_z_level(domain)
       elseif (config_vert_grid_type.eq.'zstarWeights') then
          print *, ' Using z-star vertical coordinates with weights'
-         call init_ZLevel(domain)
+         call ocn_init_z_level(domain)
       else 
          print *, ' Incorrect choice of config_vert_grid_type:',&amp;
            config_vert_grid_type
@@ -120,33 +134,32 @@
       !
       dt = config_dt
 
-      call simulation_clock_init(domain, dt, startTimeStamp)
+      call ocn_simulation_clock_init(domain, dt, startTimeStamp)
 
       block =&gt; domain % blocklist
       do while (associated(block))
          call mpas_init_block(block, block % mesh, dt)
          block % state % time_levs(1) % state % xtime % scalar = startTimeStamp 
          block =&gt; block % next
-
-         !dwj 110919 This allows the restorings to grab the indices for
-         ! temperature and salinity tracers from state.
       end do
 
    ! mrp 100316 In order for this to work, we need to pass domain % dminfo as an 
    ! input arguement into mpas_init.  Ask about that later.  For now, there will be
    ! no initial statistics write.
    
-   !   call mpas_timer_start(&quot;global diagnostics&quot;)
-   !   call ocn_compute_global_diagnostics(domain % dminfo, block % state % time_levs(1) % state, mesh, 0, dt)
-   !   call mpas_timer_stop(&quot;global diagnostics&quot;)
-   !   call mpas_output_state_init(output_obj, domain, &quot;OUTPUT&quot;)
-   !   call write_output_frame(output_obj, domain)
+      if (config_initial_stats) then
+          call mpas_timer_start(&quot;global diagnostics&quot;, .false., globalDiagTimer)
+          call ocn_compute_global_diagnostics(domain, 1 , 0, dt)
+          call mpas_timer_stop(&quot;global diagnostics&quot;, globalDiagTimer)
+!         call mpas_output_state_init(output_obj, domain, &quot;OUTPUT&quot;)
+!         call ocn_write_output_frame(output_obj, output_frame, domain)
+      endif
 
       current_outfile_frames = 0
 
    end subroutine mpas_core_init!}}}
 
-   subroutine simulation_clock_init(domain, dt, startTimeStamp)!{{{
+   subroutine ocn_simulation_clock_init(domain, dt, startTimeStamp)!{{{
 
       implicit none
 
@@ -202,7 +215,7 @@
 
       call mpas_get_time(curr_time=startTime, dateTimeString=startTimeStamp, ierr=ierr)
 
-   end subroutine simulation_clock_init!}}}
+   end subroutine ocn_simulation_clock_init!}}}
 
    subroutine mpas_init_block(block, mesh, dt)!{{{
    
@@ -217,10 +230,13 @@
       real (kind=RKIND), intent(in) :: dt
       integer :: i, iEdge, iCell, k
    
+      call ocn_time_average_init(block % state % time_levs(1) % state)
    
+      call mpas_timer_start(&quot;diagnostic solve&quot;, .false., initDiagSolveTimer)
       call ocn_diagnostic_solve(dt, block % state % time_levs(1) % state, mesh)
+      call mpas_timer_stop(&quot;diagnostic solve&quot;, initDiagSolveTimer)
 
-      call compute_mesh_scaling(mesh)
+      call ocn_compute_mesh_scaling(mesh)
  
       call mpas_rbf_interp_initialize(mesh)
       call mpas_init_reconstruct(mesh)
@@ -308,8 +324,14 @@
       call mpas_get_time(curr_time=currTime, dateTimeString=timeStamp, ierr=ierr)
       write(0,*) 'Initial time ', timeStamp
 
-      call write_output_frame(output_obj, output_frame, domain)
+      call ocn_write_output_frame(output_obj, output_frame, domain)
+      block_ptr =&gt; domain % blocklist
 
+      do while(associated(block_ptr))
+        call ocn_time_average_init(block_ptr % state % time_levs(1) % state)
+        block_ptr =&gt; block_ptr % next
+      end do
+
       ! During integration, time level 1 stores the model state at the beginning of the
       !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
       itimestep = 0
@@ -322,9 +344,9 @@
          call mpas_get_time(curr_time=currTime, dateTimeString=timeStamp, ierr=ierr)
          write(0,*) 'Doing timestep ', timeStamp
 
-         call mpas_timer_start(&quot;time integration&quot;)
+         call mpas_timer_start(&quot;time integration&quot;, .false., timeIntTimer)
          call mpas_timestep(domain, itimestep, dt, timeStamp)
-         call mpas_timer_stop(&quot;time integration&quot;)
+         call mpas_timer_stop(&quot;time integration&quot;, timeIntTimer)
    
          ! Move time level 2 fields back into time level 1 for next time step
          call mpas_shift_time_levels_state(domain % blocklist % state)
@@ -336,7 +358,20 @@
                call mpas_output_state_finalize(output_obj, domain % dminfo)
                call mpas_output_state_init(output_obj, domain, &quot;OUTPUT&quot;, trim(timeStamp))
             end if
-            call write_output_frame(output_obj, output_frame, domain)
+
+            block_ptr =&gt; domain % blocklist
+            do while (associated(block_ptr))
+                call ocn_time_average_normalize(block_ptr % state % time_levs(1) % state)
+                block_ptr =&gt; block_ptr % next
+            end do
+
+            call ocn_write_output_frame(output_obj, output_frame, domain)
+
+            block_ptr =&gt; domain % blocklist
+            do while (associated(block_ptr))
+                call ocn_time_average_init(block_ptr % state % time_levs(1) % state)
+                block_ptr =&gt; block_ptr % next
+            end do
          end if
 
          if (mpas_is_alarm_ringing(clock, restartAlarmID, ierr=ierr)) then
@@ -352,7 +387,7 @@
 
    end subroutine mpas_core_run!}}}
    
-   subroutine write_output_frame(output_obj, output_frame, domain)!{{{
+   subroutine ocn_write_output_frame(output_obj, output_frame, domain)!{{{
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Compute diagnostic fields for a domain and write model state to output file
    !
@@ -375,7 +410,7 @@
    
       block_ptr =&gt; domain % blocklist
       do while (associated(block_ptr))
-         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
+         call ocn_compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
          block_ptr =&gt; block_ptr % next
       end do
    
@@ -391,9 +426,9 @@
          end if
       end if
    
-   end subroutine write_output_frame!}}}
+   end subroutine ocn_write_output_frame!}}}
    
-   subroutine compute_output_diagnostics(state, grid)!{{{
+   subroutine ocn_compute_output_diagnostics(state, grid)!{{{
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Compute diagnostic fields for a domain
    !
@@ -413,13 +448,11 @@
       integer :: i, eoe
       integer :: iEdge, k
    
-   end subroutine compute_output_diagnostics!}}}
+   end subroutine ocn_compute_output_diagnostics!}}}
    
    subroutine mpas_timestep(domain, itimestep, dt, timeStamp)!{{{
    
       use mpas_grid_types
-      use mpas_timer
-      use ocn_global_diagnostics
    
       implicit none
    
@@ -435,17 +468,9 @@
 
       if (config_stats_interval &gt; 0) then
           if (mod(itimestep, config_stats_interval) == 0) then
-              block_ptr =&gt; domain % blocklist
-              if (associated(block_ptr % next)) then
-                  write(0,*) 'Error: computeGlobalDiagnostics assumes ',&amp;
-                     'that there is only one block per processor.'
-              end if
-
-          call mpas_timer_start(&quot;global diagnostics&quot;)
-          call ocn_compute_global_diagnostics(domain % dminfo, &amp;
-             block_ptr % state % time_levs(2) % state, block_ptr % mesh, &amp;
-             itimestep, dt)
-          call mpas_timer_stop(&quot;global diagnostics&quot;)
+             call mpas_timer_start(&quot;global diagnostics&quot;, .false., globalDiagTimer)
+             call ocn_compute_global_diagnostics(domain, 2, itimestep, dt);
+             call mpas_timer_stop(&quot;global diagnostics&quot;, globalDiagTimer)
           end if
       end if
 
@@ -468,7 +493,7 @@
 
    end subroutine mpas_timestep!}}}
 
-subroutine init_ZLevel(domain)!{{{
+subroutine ocn_init_z_level(domain)!{{{
 ! Initialize maxLevel and bouncary grid variables.
 
    use mpas_grid_types
@@ -595,9 +620,9 @@
 
    end do
 
-end subroutine init_ZLevel!}}}
+end subroutine ocn_init_z_level!}}}
 
-subroutine compute_maxLevel(domain)!{{{
+subroutine ocn_compute_max_level(domain)!{{{
 ! Initialize maxLevel and bouncary grid variables.
 
    use mpas_grid_types
@@ -622,7 +647,7 @@
       maxLevelVertexTop, maxLevelVertexBot
    integer, dimension(:,:), pointer :: &amp;
       cellsOnEdge, cellsOnVertex, boundaryEdge, boundaryCell, &amp;
-      boundaryVertex, verticesOnEdge
+      boundaryVertex, verticesOnEdge, edgeMask, cellMask, vertexMask
 
    ! Initialize z-level grid variables from h, read in from input file.
    block =&gt; domain % blocklist
@@ -639,6 +664,9 @@
       boundaryEdge   =&gt; block % mesh % boundaryEdge % array
       boundaryCell   =&gt; block % mesh % boundaryCell % array
       boundaryVertex =&gt; block % mesh % boundaryVertex % array
+      edgeMask =&gt; block % mesh % edgeMask % array
+      cellMask =&gt; block % mesh % cellMask % array
+      vertexMask =&gt; block % mesh % vertexMask % array
 
       nCells      = block % mesh % nCells
       nEdges      = block % mesh % nEdges
@@ -692,22 +720,31 @@
       maxLevelVertexTop(nVertices+1) = 0
 
       ! set boundary edge
-      boundaryEdge=1
+      boundaryEdge(:,1:nEdges+1)=1
+      edgeMask(:,1:nEdges+1)=0
       do iEdge=1,nEdges
          boundaryEdge(1:maxLevelEdgeTop(iEdge),iEdge)=0
+         edgeMask(1:maxLevelEdgeTop(iEdge),iEdge)=1
       end do 
 
       !
       ! Find cells and vertices that have an edge on the boundary
       !
-      boundaryCell(:,:) = 0
+      boundaryCell(:,1:nCells+1) = 0
+      cellMask(:,1:nCells+1) = 1
+      boundaryVertex(:,1:nVertices+1) = 0
+      vertexMask(:,1:nVertices+1) = 1
       do iEdge=1,nEdges
          do k=1,nVertLevels
             if (boundaryEdge(k,iEdge).eq.1) then
                boundaryCell(k,cellsOnEdge(1,iEdge)) = 1
                boundaryCell(k,cellsOnEdge(2,iEdge)) = 1
+               cellMask(k,cellsOnEdge(1,iEdge)) = 0
+               cellMask(k,cellsOnEdge(2,iEdge)) = 0
                boundaryVertex(k,verticesOnEdge(1,iEdge)) = 1
                boundaryVertex(k,verticesOnEdge(2,iEdge)) = 1
+               vertexMask(k,verticesOnEdge(1,iEdge)) = 0
+               vertexMask(k,verticesOnEdge(2,iEdge)) = 0
             endif
          end do
       end do
@@ -718,7 +755,7 @@
    ! Note: We do not update halos on maxLevel* variables.  I want the
    ! outside edge of a halo to be zero on each processor.
 
-end subroutine compute_maxLevel!}}}
+end subroutine ocn_compute_max_level!}}}
    
    subroutine mpas_core_finalize(domain)!{{{
    
@@ -733,7 +770,7 @@
 
    end subroutine mpas_core_finalize!}}}
 
-   subroutine compute_mesh_scaling(mesh)!{{{
+   subroutine ocn_compute_mesh_scaling(mesh)!{{{
 
       use mpas_grid_types
       use mpas_configure
@@ -763,7 +800,7 @@
          end do
       end if
 
-   end subroutine compute_mesh_scaling!}}}
+   end subroutine ocn_compute_mesh_scaling!}}}
 
 end module mpas_core
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_restoring.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_restoring.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_restoring.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -42,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: restoringOn !&lt; Flag to turn on/off resotring
+   integer :: restoringOn !&lt; Flag to turn on/off resotring
 
    real (kind=RKIND) :: temperatureTimeScale, salinityTimeScale !&lt; restoring timescales
 
@@ -111,27 +111,25 @@
       integer :: iCell, nCellsSolve, k
 
       real (kind=RKIND), dimension(:), pointer :: temperatureRestore, salinityRestore
+      real (kind=RKIND) :: invTemp, invSalinity
 
       err = 0
 
-      if(.not.restoringOn) return
+      if(restoringOn == 0) return
 
       nCellsSolve = grid % nCellsSolve
 
       temperatureRestore =&gt; grid % temperatureRestore % array
       salinityRestore =&gt; grid % salinityRestore % array
 
+      invTemp = 1.0 / (temperatureTimeScale * 86400.0)
+      invSalinity = 1.0 / (salinityTimeScale * 86400.0)
+
       k = 1  ! restoring only in top layer
       do iCell=1,nCellsSolve
+        tend(indexT, k, iCell) = tend(indexT, k, iCell) - h(k,iCell)*(tracers(indexT, k, iCell) - temperatureRestore(iCell)) * invTemp
+        tend(indexS, k, iCell) = tend(indexS, k, iCell) - h(k,iCell)*(tracers(indexS, k, iCell) - salinityRestore(iCell)) * invSalinity
 
-        tend(indexT, k, iCell) = tend(indexT, k, iCell)  &amp;
-             - h(k,iCell)*(tracers(indexT, k, iCell) - temperatureRestore(iCell)) &amp;
-             / (temperatureTimeScale * 86400.0)
-
-        tend(indexS, k, iCell) = tend(indexS, k, iCell)  &amp;
-             - h(k,iCell)*(tracers(indexS, k, iCell) - salinityRestore(iCell)) &amp;
-             / (salinityTimeScale * 86400.0)
-
 !       write(6,10) iCell, tracers(indexT, k, iCell), &amp;
 !              temperatureRestore(iCell), tracers(indexT, k, iCell), &amp;
 !             (tracers(indexT, k, iCell) - temperatureRestore(iCell)) &amp;
@@ -162,10 +160,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      restoringOn = .false.
+      restoringOn = 0
 
       if(config_restoreTS) then
-          restoringOn = .true.
+          restoringOn = 1
           temperatureTimeScale = config_restoreT_timescale
           salinityTimeScale = config_restoreS_timescale
       endif

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tendency.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tendency.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tendency.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -38,10 +38,17 @@
    use ocn_equation_of_state
    use ocn_vmix
 
+   use ocn_time_average
+
    implicit none
    private
    save
 
+   type (timer_node), pointer :: diagEOSTimer
+   type (timer_node), pointer :: thickHadvTimer, thickVadvTimer
+   type (timer_node), pointer :: velCorTimer, velVadvTimer, velPgradTimer, velHmixTimer, velForceTimer, velExpVmixTimer
+   type (timer_node), pointer :: tracerHadvTimer, tracerVadvTimer, tracerHmixTimer, tracerExpVmixTimer, tracerRestoringTimer
+
    !--------------------------------------------------------------------
    !
    ! Public parameters
@@ -59,7 +66,8 @@
              ocn_tend_scalar, &amp;
              ocn_diagnostic_solve, &amp;
              ocn_wtop, &amp;
-             ocn_fuperp
+             ocn_fuperp, &amp;
+             ocn_tendency_init
 
    !--------------------------------------------------------------------
    !
@@ -67,7 +75,11 @@
    !
    !--------------------------------------------------------------------
 
+   integer :: hadv2nd, hadv3rd, hadv4th
+   integer :: ke_cell_flag, ke_vertex_flag
+   real (kind=RKIND) ::  coef_3rd_order, fCoef
 
+
 !***********************************************************************
 
 contains
@@ -102,83 +114,18 @@
       type (diagnostics_type), intent(in) :: d
       type (mesh_type), intent(in) :: grid
 
-      integer :: iEdge, iCell, iVertex, k, cell1, cell2, &amp;
-        vertex1, vertex2, eoe, i, j, err
+      real (kind=RKIND), dimension(:,:), pointer :: h_edge, u, wTop, tend_h
 
-! mrp 110512 I just split compute_tend into compute_tend_u and ocn_tend_h.
-!  Most of these variables can be removed, but at a later time.
-      integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve
-      real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, q, &amp;
-        upstream_bias, wTopEdge, rho0Inv, r
-      real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel 
-      real (kind=RKIND), dimension(:,:), pointer :: &amp;
-        weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, pressure, &amp;
-        tend_h, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
-        MontPot, wTop, divergence, vertViscTopOfEdge
-      type (dm_info) :: dminfo
+      integer :: err
 
-      integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge, &amp;
-        maxLevelCell, maxLevelEdgeTop, maxLevelVertexBot
-      integer, dimension(:,:), pointer :: &amp;
-        cellsOnEdge, cellsOnVertex, verticesOnEdge, edgesOnCell, &amp;
-        edgesOnEdge, edgesOnVertex
-      real (kind=RKIND) :: u_diffusion
-      real (kind=RKIND), dimension(:), allocatable:: fluxVertTop,w_dudzTopEdge
-
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_divergence
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_u
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_circulation, delsq_vorticity
-
       call mpas_timer_start(&quot;ocn_tend_h&quot;)
 
-      h           =&gt; s % h % array
       u           =&gt; s % u % array
-      v           =&gt; s % v % array
       wTop        =&gt; s % wTop % array
       h_edge      =&gt; s % h_edge % array
-      circulation =&gt; s % circulation % array
-      vorticity   =&gt; s % vorticity % array
-      divergence  =&gt; s % divergence % array
-      ke          =&gt; s % ke % array
-      ke_edge     =&gt; s % ke_edge % array
-      pv_edge     =&gt; s % pv_edge % array
-      MontPot     =&gt; s % MontPot % array
-      pressure    =&gt; s % pressure % array
-      vertViscTopOfEdge =&gt; d % vertViscTopOfEdge % array
 
-      weightsOnEdge     =&gt; grid % weightsOnEdge % array
-      kiteAreasOnVertex =&gt; grid % kiteAreasOnVertex % array
-      cellsOnEdge       =&gt; grid % cellsOnEdge % array
-      cellsOnVertex     =&gt; grid % cellsOnVertex % array
-      verticesOnEdge    =&gt; grid % verticesOnEdge % array
-      nEdgesOnCell      =&gt; grid % nEdgesOnCell % array
-      edgesOnCell       =&gt; grid % edgesOnCell % array
-      nEdgesOnEdge      =&gt; grid % nEdgesOnEdge % array
-      edgesOnEdge       =&gt; grid % edgesOnEdge % array
-      edgesOnVertex     =&gt; grid % edgesOnVertex % array
-      dcEdge            =&gt; grid % dcEdge % array
-      dvEdge            =&gt; grid % dvEdge % array
-      areaCell          =&gt; grid % areaCell % array
-      areaTriangle      =&gt; grid % areaTriangle % array
-      h_s               =&gt; grid % h_s % array
-      fVertex           =&gt; grid % fVertex % array
-      fEdge             =&gt; grid % fEdge % array
-      zMidZLevel        =&gt; grid % zMidZLevel % array
-      zTopZLevel        =&gt; grid % zTopZLevel % array
-      maxLevelCell      =&gt; grid % maxLevelCell % array
-      maxLevelEdgeTop      =&gt; grid % maxLevelEdgeTop % array
-      maxLevelVertexBot    =&gt; grid % maxLevelVertexBot % array
-
       tend_h      =&gt; tend % h % array
                   
-      nCells      = grid % nCells
-      nEdges      = grid % nEdges
-      nEdgesSolve = grid % nEdgesSolve
-      nVertices   = grid % nVertices
-      nVertLevels = grid % nVertLevels
-
       !
       ! height tendency: start accumulating tendency terms
       !
@@ -192,21 +139,18 @@
       !
       ! for z-level, only compute height tendency for top layer.
 
-      call mpas_timer_start(&quot;ocn_tend_h-horiz adv&quot;)
-
+      call mpas_timer_start(&quot;hadv&quot;, .false., thickHadvTimer)
       call ocn_thick_hadv_tend(grid, u, h_edge, tend_h, err)
+      call mpas_timer_stop(&quot;hadv&quot;, thickHadvTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_h-horiz adv&quot;)
-
       !
       ! height tendency: vertical advection term -d/dz(hw)
       !
       ! Vertical advection computed for top layer of a z grid only.
-      call mpas_timer_start(&quot;ocn_tend_h-vert adv&quot;)
-
+      call mpas_timer_start(&quot;vadv&quot;, .false., thickVadvTimer)
       call ocn_thick_vadv_tend(grid, wtop, tend_h, err)
+      call mpas_timer_stop(&quot;vadv&quot;, thickVadvTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_h-vert adv&quot;)
       call mpas_timer_stop(&quot;ocn_tend_h&quot;)
    
    end subroutine ocn_tend_h!}}}
@@ -241,49 +185,22 @@
       type (diagnostics_type), intent(in) :: d
       type (mesh_type), intent(in) :: grid
 
-! mrp 110512 I just split compute_tend into ocn_tend_u and compute_tend_h.
-!  Some of these variables can be removed, but at a later time.
-      integer :: iEdge, iCell, iVertex, k, cell1, cell2, &amp;
-        vertex1, vertex2, eoe, i, j
-
-      integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve, err
-      real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, q, &amp;
-        upstream_bias, wTopEdge, rho0Inv, r, visc_vorticity_coef
-      real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel, meshScalingDel2, meshScalingDel4
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
-        weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, rho, zMid, pressure, &amp;
+        h_edge, h, u, rho, zMid, pressure, &amp;
         tend_u, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
         MontPot, wTop, divergence, vertViscTopOfEdge
-      type (dm_info) :: dminfo
 
-      integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge, &amp;
-        maxLevelCell, maxLevelEdgeTop, maxLevelVertexBot
-      integer, dimension(:,:), pointer :: &amp;
-        cellsOnEdge, cellsOnVertex, verticesOnEdge, edgesOnCell, &amp;
-        edgesOnEdge, edgesOnVertex
-      real (kind=RKIND) :: u_diffusion
-      real (kind=RKIND), dimension(:), allocatable:: fluxVertTop,w_dudzTopEdge
-
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_divergence
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_u
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_circulation, delsq_vorticity
-
-
       real (kind=RKIND), dimension(:,:), pointer :: u_src
-      real (kind=RKIND), parameter :: rho_ref = 1000.0
 
+      integer :: err
+
       call mpas_timer_start(&quot;ocn_tend_u&quot;)
 
-      h           =&gt; s % h % array
       u           =&gt; s % u % array
-      v           =&gt; s % v % array
       rho         =&gt; s % rho % array
       wTop        =&gt; s % wTop % array
       zMid        =&gt; s % zMid % array
       h_edge      =&gt; s % h_edge % array
-      circulation =&gt; s % circulation % array
       vorticity   =&gt; s % vorticity % array
       divergence  =&gt; s % divergence % array
       ke          =&gt; s % ke % array
@@ -293,43 +210,10 @@
       pressure    =&gt; s % pressure % array
       vertViscTopOfEdge =&gt; d % vertViscTopOfEdge % array
 
-      weightsOnEdge     =&gt; grid % weightsOnEdge % array
-      kiteAreasOnVertex =&gt; grid % kiteAreasOnVertex % array
-      cellsOnEdge       =&gt; grid % cellsOnEdge % array
-      cellsOnVertex     =&gt; grid % cellsOnVertex % array
-      verticesOnEdge    =&gt; grid % verticesOnEdge % array
-      nEdgesOnCell      =&gt; grid % nEdgesOnCell % array
-      edgesOnCell       =&gt; grid % edgesOnCell % array
-      nEdgesOnEdge      =&gt; grid % nEdgesOnEdge % array
-      edgesOnEdge       =&gt; grid % edgesOnEdge % array
-      edgesOnVertex     =&gt; grid % edgesOnVertex % array
-      dcEdge            =&gt; grid % dcEdge % array
-      dvEdge            =&gt; grid % dvEdge % array
-      areaCell          =&gt; grid % areaCell % array
-      areaTriangle      =&gt; grid % areaTriangle % array
-      h_s               =&gt; grid % h_s % array
-! mrp 110516 cleanup fvertex fedge not used in this subroutine
-      fVertex           =&gt; grid % fVertex % array
-      fEdge             =&gt; grid % fEdge % array
-      zMidZLevel        =&gt; grid % zMidZLevel % array
-      zTopZLevel        =&gt; grid % zTopZLevel % array
-      maxLevelCell      =&gt; grid % maxLevelCell % array
-      maxLevelEdgeTop      =&gt; grid % maxLevelEdgeTop % array
-      maxLevelVertexBot    =&gt; grid % maxLevelVertexBot % array
-
       tend_u      =&gt; tend % u % array
                   
-      nCells      = grid % nCells
-      nEdges      = grid % nEdges
-      nEdgesSolve = grid % nEdgesSolve
-      nVertices   = grid % nVertices
-      nVertLevels = grid % nVertLevels
-
       u_src =&gt; grid % u_src % array
 
-      meshScalingDel2 =&gt; grid % meshScalingDel2 % array
-      meshScalingDel4 =&gt; grid % meshScalingDel4 % array
-
       !
       ! velocity tendency: start accumulating tendency terms
       !
@@ -340,66 +224,54 @@
       ! velocity tendency: nonlinear Coriolis term and grad of kinetic energy
       !
 
-      call mpas_timer_start(&quot;ocn_tend_u-coriolis&quot;)
-
+      call mpas_timer_start(&quot;coriolis&quot;, .false., velCorTimer)
       call ocn_vel_coriolis_tend(grid, pv_edge, h_edge, u, ke, tend_u, err)
+      call mpas_timer_stop(&quot;coriolis&quot;, velCorTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_u-coriolis&quot;)
-
       !
       ! velocity tendency: vertical advection term -w du/dz
       !
-      call mpas_timer_start(&quot;ocn_tend_u-vert adv&quot;)
-
+      call mpas_timer_start(&quot;vadv&quot;, .false., velVadvTimer)
       call ocn_vel_vadv_tend(grid, u, h_edge, wtop, tend_u, err)
+      call mpas_timer_stop(&quot;vadv&quot;, velVadvTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_u-vert adv&quot;)
-
       !
       ! velocity tendency: pressure gradient
       !
-      call mpas_timer_start(&quot;ocn_tend_u-pressure grad&quot;)
-
+      call mpas_timer_start(&quot;pressure grad&quot;, .false., velPgradTimer)
       if (config_vert_grid_type.eq.'isopycnal') then
           call ocn_vel_pressure_grad_tend(grid, MontPot,  zMid, rho, tend_u, err)
       else
           call ocn_vel_pressure_grad_tend(grid, pressure, zMid, rho, tend_u, err)
       end if
+      call mpas_timer_stop(&quot;pressure grad&quot;, velPgradTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_u-pressure grad&quot;)
-
       !
       ! velocity tendency: del2 dissipation, </font>
<font color="black">u_2 </font>
<font color="black">abla^2 u
       !   computed as </font>
<font color="black">u( </font>
<font color="black">abla divergence + k \times </font>
<font color="gray">abla vorticity )
       !   strictly only valid for config_h_mom_eddy_visc2 == constant
       !
-      call mpas_timer_start(&quot;ocn_tend_u-horiz mix&quot;)
-
+      call mpas_timer_start(&quot;hmix&quot;, .false., velHmixTimer)
       call ocn_vel_hmix_tend(grid, divergence, vorticity, tend_u, err)
+      call mpas_timer_stop(&quot;hmix&quot;, velHmixTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_u-horiz mix&quot;)
-
       !
       ! velocity tendency: forcing and bottom drag
       !
       ! mrp 101115 note: in order to include flux boundary conditions, we will need to 
       ! know the bottom edge with nonzero velocity and place the drag there.
 
-      call mpas_timer_start(&quot;ocn_tend_u-forcings&quot;)
-
+      call mpas_timer_start(&quot;forcings&quot;, .false., velForceTimer)
       call ocn_vel_forcing_tend(grid, u, u_src, ke_edge, h_edge, tend_u, err)
+      call mpas_timer_stop(&quot;forcings&quot;, velForceTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_u-forcings&quot;)
-
       !
       ! velocity tendency: vertical mixing d/dz( nu_v du/dz))
       !
       if (.not.config_implicit_vertical_mix) then
-          call mpas_timer_start(&quot;ocn_tend_u-explicit vert mix&quot;)
-
+          call mpas_timer_start(&quot;explicit vmix&quot;, .false., velExpVmixTimer)
           call ocn_vel_vmix_tend_explicit(grid, u, h_edge, vertvisctopofedge, tend_u, err)
-
-          call mpas_timer_stop(&quot;ocn_tend_u-explicit vert mix&quot;)
+          call mpas_timer_stop(&quot;explicit vmix&quot;, velExpVmixTimer)
       endif
       call mpas_timer_stop(&quot;ocn_tend_u&quot;)
 
@@ -436,73 +308,24 @@
       type (diagnostics_type), intent(in) :: d
       type (mesh_type), intent(in) :: grid
 
-      integer :: i, k, iCell, iEdge, iTracer, cell1, cell2, upwindCell,&amp;
-        nEdges, nCells, nCellsSolve, nVertLevels, num_tracers, err
-      real (kind=RKIND) :: invAreaCell1, invAreaCell2, tracer_turb_flux
-      real (kind=RKIND) :: flux, tracer_edge, r
-      real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
-        u,h,rho, wTop, h_edge, vertDiffTopOfCell
+        u,h,wTop, h_edge, vertDiffTopOfCell
       real (kind=RKIND), dimension(:,:,:), pointer :: &amp;
         tracers, tend_tr
-      integer, dimension(:,:), pointer :: boundaryEdge
-      type (dm_info) :: dminfo
 
-      integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge, &amp;
-        maxLevelCell, maxLevelEdgeTop, maxLevelVertexBot
-      integer, dimension(:,:), pointer :: cellsOnEdge, boundaryCell
-      real (kind=RKIND), dimension(:), pointer :: zTopZLevel,zMidZLevel, &amp;
-         meshScalingDel2, meshScalingDel4
-      real (kind=RKIND), dimension(:), allocatable:: tracer2ndDer, tracersIn, tracersOut, posZMidZLevel, &amp;
-            posZTopZLevel
-      real (kind=RKIND), dimension(:,:), allocatable:: fluxVertTop, boundaryMask
-      real (kind=RKIND), dimension(:,:,:), allocatable::tr_flux, tr_div, delsq_tracer, tracerTop
+      integer :: err
 
-
-      real (kind=RKIND) :: d2fdx2_cell1, d2fdx2_cell2
-      real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
-      real (kind=RKIND) :: coef_3rd_order, flux3Coef, cSignWTop
-
-      integer :: index_temperature, index_salinity, rrr
-      real (kind=RKIND), dimension(:), pointer :: temperatureRestore, salinityRestore
-
       call mpas_timer_start(&quot;ocn_tend_scalar&quot;)
 
       u           =&gt; s % u % array
       h           =&gt; s % h % array
-      rho         =&gt; s % rho % array
-      boundaryCell=&gt; grid % boundaryCell % array
       wTop        =&gt; s % wTop % array
       tracers     =&gt; s % tracers % array
       h_edge      =&gt; s % h_edge % array
       vertDiffTopOfCell =&gt; d % vertDiffTopOfCell % array
 
       tend_tr     =&gt; tend % tracers % array
-                  
-      areaCell          =&gt; grid % areaCell % array
-      cellsOnEdge       =&gt; grid % cellsOnEdge % array
-      dvEdge            =&gt; grid % dvEdge % array
-      dcEdge            =&gt; grid % dcEdge % array
-      zTopZLevel        =&gt; grid % zTopZLevel % array
-      zMidZLevel        =&gt; grid % zMidZLevel % array
-      boundaryEdge      =&gt; grid % boundaryEdge % array
-      maxLevelCell      =&gt; grid % maxLevelCell % array
-      maxLevelEdgeTop      =&gt; grid % maxLevelEdgeTop % array
-      maxLevelVertexBot    =&gt; grid % maxLevelVertexBot % array
 
-      nEdges      = grid % nEdges
-      nCells      = grid % nCells
-      nCellsSolve = grid % nCellsSolve
-      nVertLevels = grid % nVertLevels
-      num_tracers = s % num_tracers
-
-      meshScalingDel2 =&gt; grid % meshScalingDel2 % array
-      meshScalingDel4 =&gt; grid % meshScalingDel4 % array
-
-
-      deriv_two   =&gt; grid % deriv_two % array
-
       !
       ! initialize tracer tendency (RHS of tracer equation) to zero.
       !
@@ -516,32 +339,26 @@
       ! and then change maxLevelEdgeTop to maxLevelEdgeBot in the following section.
       ! tracer_edge at the boundary will also need to be defined for flux boundaries.
 
-      call mpas_timer_start(&quot;ocn_tend_scalar-horiz adv&quot;)
-
+      call mpas_timer_start(&quot;hadv&quot;, .false., tracerHadvTimer)
       call ocn_tracer_hadv_tend(grid, u, h_edge, tracers, tend_tr, err)
+      call mpas_timer_stop(&quot;hadv&quot;, tracerHadvTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_scalar-horiz adv&quot;)
 
-
       !
       ! tracer tendency: vertical advection term -d/dz( h \phi w)
       !
 
-      call mpas_timer_start(&quot;ocn_tend_scalar-vert adv&quot;)
-
+      call mpas_timer_start(&quot;vadv&quot;, .false., tracerVadvTimer)
       call ocn_tracer_vadv_tend(grid, h, wtop, tracers, tend_tr, err)
+      call mpas_timer_stop(&quot;vadv&quot;, tracerVadvTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_scalar-vert adv&quot;)
-
       !
       ! tracer tendency: del2 horizontal tracer diffusion, div(h \kappa_2 </font>
<font color="gray">abla \phi)
       !
-      call mpas_timer_start(&quot;ocn_tend_scalar-horiz diff&quot;)
-
+      call mpas_timer_start(&quot;hmix&quot;, .false., tracerHmixTimer)
       call ocn_tracer_hmix_tend(grid, h_edge, tracers, tend_tr, err)
+      call mpas_timer_stop(&quot;hmix&quot;, tracerHmixTimer)
 
-      call mpas_timer_stop(&quot;ocn_tend_scalar-horiz diff&quot;)
-
 ! mrp 110516 printing
 !print *, 'tend_tr 1',minval(tend_tr(3,1,1:nCells)),&amp;
 !                   maxval(tend_tr(3,1,1:nCells))
@@ -553,11 +370,11 @@
       ! tracer tendency: vertical diffusion h d/dz( \kappa_v d\phi/dz)
       !
       if (.not.config_implicit_vertical_mix) then
-         call mpas_timer_start(&quot;ocn_tend_scalar-explicit vert diff&quot;)
+         call mpas_timer_start(&quot;explicit vmix&quot;, .false., tracerExpVmixTimer)
 
          call ocn_tracer_vmix_tend_explicit(grid, h, vertdifftopofcell, tracers, tend_tr, err)
 
-         call mpas_timer_stop(&quot;ocn_tend_scalar-explicit vert diff&quot;)
+         call mpas_timer_stop(&quot;explicit vmix&quot;, tracerExpVmixTimer)
       endif
 
 ! mrp 110516 printing
@@ -568,11 +385,11 @@
       !
       ! add restoring to T and S in top model layer
       !
-      call mpas_timer_start(&quot;ocn_tend_scalar-restoring&quot;)
+      call mpas_timer_start(&quot;restoring&quot;, .false., tracerRestoringTimer)
 
       call ocn_restoring_tend(grid, h, s%index_temperature, s%index_salinity, tracers, tend_tr, err)
 
-      call mpas_timer_stop(&quot;ocn_tend_scalar-restoring&quot;)
+      call mpas_timer_stop(&quot;restoring&quot;, tracerRestoringTimer)
 
  10   format(2i8,10e20.10)
       call mpas_timer_stop(&quot;ocn_tend_scalar&quot;)
@@ -608,42 +425,34 @@
       type (mesh_type), intent(in) :: grid
 
 
-      integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, cov
-      real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, rho0Inv
+      integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j
+      integer :: boundaryMask, velMask, nCells, nEdges, nVertices, nVertLevels, vertexDegree, err
 
-      integer :: nCells, nEdges, nVertices, nVertLevels, vertexDegree, fCoef, err
+      integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge, &amp;
+        maxLevelCell, maxLevelEdgeTop, maxLevelEdgeBot, &amp;
+        maxLevelVertexBot
+      integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnVertex, &amp;
+        verticesOnEdge, edgesOnEdge, edgesOnVertex,boundaryCell
 
+      real (kind=RKIND) :: d2fdx2_cell1, d2fdx2_cell2, coef_3rd_order, r_tmp, invAreaCell1, invAreaCell2, invAreaTri1, invAreaTri2, invLength, h_vertex
 
+      real (kind=RKIND), dimension(:), allocatable:: pTop
+
       real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
+        h_s, fVertex, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
         zTopZLevel
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
-        weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, w, pressure,&amp;
+        weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, pressure,&amp;
         circulation, vorticity, ke, ke_edge, MontPot, wTop, zMid, &amp;
         pv_edge, pv_vertex, pv_cell, gradPVn, gradPVt, divergence, &amp;
         rho, temperature, salinity, kev, kevc
-      real (kind=RKIND), dimension(:,:,:), pointer :: tracers
-      real (kind=RKIND), dimension(:), allocatable:: pTop
+      real (kind=RKIND), dimension(:,:,:), pointer :: tracers, deriv_two
       real (kind=RKIND), dimension(:,:), allocatable:: div_u
       character :: c1*6
 
-      integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnVertex, &amp;
-        verticesOnEdge, edgesOnCell, edgesOnEdge, edgesOnVertex, &amp;
-        boundaryEdge, boundaryCell
-      integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge, &amp;
-        maxLevelCell, maxLevelEdgeTop, maxLevelEdgeBot, &amp;
-        maxLevelVertexBot,  maxLevelVertexTop
-      real (kind=RKIND) :: d2fdx2_cell1, d2fdx2_cell2
-      real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
-      real (kind=RKIND) :: coef_3rd_order
-      real (kind=RKIND) :: r, h1, h2
-
-      call mpas_timer_start(&quot;ocn_diagnostic_solve&quot;)
-
       h           =&gt; s % h % array
       u           =&gt; s % u % array
       v           =&gt; s % v % array
-      wTop        =&gt; s % wTop % array
       h_edge      =&gt; s % h_edge % array
       circulation =&gt; s % circulation % array
       vorticity   =&gt; s % vorticity % array
@@ -658,10 +467,10 @@
       gradPVn     =&gt; s % gradPVn % array
       gradPVt     =&gt; s % gradPVt % array
       rho         =&gt; s % rho % array
-      tracers     =&gt; s % tracers % array
       MontPot     =&gt; s % MontPot % array
       pressure    =&gt; s % pressure % array
       zMid        =&gt; s % zMid % array
+      tracers     =&gt; s % tracers % array
 
       weightsOnEdge     =&gt; grid % weightsOnEdge % array
       kiteAreasOnVertex =&gt; grid % kiteAreasOnVertex % array
@@ -669,7 +478,6 @@
       cellsOnVertex     =&gt; grid % cellsOnVertex % array
       verticesOnEdge    =&gt; grid % verticesOnEdge % array
       nEdgesOnCell      =&gt; grid % nEdgesOnCell % array
-      edgesOnCell       =&gt; grid % edgesOnCell % array
       nEdgesOnEdge      =&gt; grid % nEdgesOnEdge % array
       edgesOnEdge       =&gt; grid % edgesOnEdge % array
       edgesOnVertex     =&gt; grid % edgesOnVertex % array
@@ -679,14 +487,12 @@
       areaTriangle      =&gt; grid % areaTriangle % array
       h_s               =&gt; grid % h_s % array
       fVertex           =&gt; grid % fVertex % array
-      fEdge             =&gt; grid % fEdge % array
       zTopZLevel        =&gt; grid % zTopZLevel % array
       deriv_two         =&gt; grid % deriv_two % array
       maxLevelCell      =&gt; grid % maxLevelCell % array
       maxLevelEdgeTop   =&gt; grid % maxLevelEdgeTop % array
       maxLevelEdgeBot   =&gt; grid % maxLevelEdgeBot % array
       maxLevelVertexBot =&gt; grid % maxLevelVertexBot % array
-      maxLevelVertexTop =&gt; grid % maxLevelVertexTop % array
                   
       nCells      = grid % nCells
       nEdges      = grid % nEdges
@@ -694,7 +500,6 @@
       nVertLevels = grid % nVertLevels
       vertexDegree = grid % vertexDegree
 
-      boundaryEdge =&gt; grid % boundaryEdge % array
       boundaryCell =&gt; grid % boundaryCell % array
 
       !
@@ -704,28 +509,25 @@
       ! mrp 101115 note: in order to include flux boundary conditions, we will need to 
       ! assign h_edge for maxLevelEdgeTop:maxLevelEdgeBot in the following section
 
-      call mpas_timer_start(&quot;ocn_diagnostic_solve-hEdge&quot;)
+      ! initialize h_edge to avoid divide by zero and NaN problems.
+      h_edge = -1.0e34
 
-      coef_3rd_order = 0.
-      if (config_thickness_adv_order == 3) coef_3rd_order = 1.0
-      if (config_thickness_adv_order == 3 .and. config_monotonic) coef_3rd_order = 0.25
+!     coef_3rd_order = 0.
+!     if (config_thickness_adv_order == 3) coef_3rd_order = 1.0
+!     if (config_thickness_adv_order == 3 .and. config_monotonic) coef_3rd_order = 0.25
 
-      if (config_thickness_adv_order == 2) then
-          call mpas_timer_start(&quot;ocn_diagnostic_solve-hEdge 2&quot;)
-
-         do iEdge=1,nEdges
+!     if (config_thickness_adv_order == 2) then
+         do iEdge=1,nEdges*hadv2nd
             cell1 = cellsOnEdge(1,iEdge)
             cell2 = cellsOnEdge(2,iEdge)
             do k=1,maxLevelEdgeTop(iEdge)
                h_edge(k,iEdge) = 0.5 * (h(k,cell1) + h(k,cell2))
             end do
          end do
-          call mpas_timer_stop(&quot;ocn_diagnostic_solve-hEdge 2&quot;)
 
-      else if (config_thickness_adv_order == 3) then
-          call mpas_timer_start(&quot;ocn_diagnostic_solve-hEdge 3&quot;)
+!     else if (config_thickness_adv_order == 3) then
 
-         do iEdge=1,nEdges
+         do iEdge=1,nEdges*hadv3rd
             cell1 = cellsOnEdge(1,iEdge)
             cell2 = cellsOnEdge(2,iEdge)
 
@@ -734,48 +536,34 @@
                d2fdx2_cell1 = 0.0
                d2fdx2_cell2 = 0.0
 
-               !-- if not a boundary cell
-               if(boundaryCell(k,cell1).eq.0.and.boundaryCell(k,cell2).eq.0) then
+               boundaryMask = abs(transfer(.not.(boundaryCell(k,cell1) == 0 .and. boundaryCell(k,cell2) == 0), boundaryMask))
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2)
+               d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1) * boundaryMask
+               d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2) * boundaryMask
 
-                  !-- all edges of cell 1
-                  do i=1, grid % nEdgesOnCell % array (cell1)
-                          d2fdx2_cell1 = d2fdx2_cell1 + &amp;
-                          deriv_two(i+1,1,iEdge) * h(k,grid % CellsOnCell % array (i,cell1))
-                  end do
+               !-- all edges of cell 1
+               do i=1, nEdgesOnCell(cell1) * boundaryMask
+                  d2fdx2_cell1 = d2fdx2_cell1 + &amp;
+                  deriv_two(i+1,1,iEdge) * h(k,grid % CellsOnCell % array (i,cell1))
+               end do
 
-                  !-- all edges of cell 2
-                  do i=1, grid % nEdgesOnCell % array (cell2)
-                          d2fdx2_cell2 = d2fdx2_cell2 + &amp;
-                          deriv_two(i+1,2,iEdge) * h(k,grid % CellsOnCell % array (i,cell2))
-                  end do
+               !-- all edges of cell 2
+               do i=1, nEdgesOnCell(cell2) * boundaryMask
+                  d2fdx2_cell2 = d2fdx2_cell2 + &amp;
+                  deriv_two(i+1,2,iEdge) * h(k,grid % CellsOnCell % array (i,cell2))
+               end do
 
-               endif
+               velMask = 2*(abs(transfer(u(k,iEdge) &lt;= 0, velMask))) - 1
 
-               !-- if u &gt; 0:
-               if (u(k,iEdge) &gt; 0) then
-                  h_edge(k,iEdge) =     &amp;
-                       0.5*(h(k,cell1) + h(k,cell2))      &amp;
-                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
-                       -(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12.
-               !-- else u &lt;= 0:
-               else
-                  h_edge(k,iEdge) =     &amp;
-                       0.5*(h(k,cell1) + h(k,cell2))      &amp;
-                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
-                       +(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12.
-               end if
+               h_edge(k,iEdge) = 0.5*(h(k,cell1) + h(k,cell2)) - (dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
+                               + velMask * (dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12.
 
             end do   ! do k
          end do         ! do iEdge
 
-          call mpas_timer_stop(&quot;ocn_diagnostic_solve-hEdge 3&quot;)
-      else  if (config_thickness_adv_order == 4) then
-          call mpas_timer_start(&quot;ocn_diagnostic_solve-hEdge 4&quot;)
+!     else  if (config_thickness_adv_order == 4) then
 
-         do iEdge=1,nEdges
+         do iEdge=1,nEdges*hadv4th
             cell1 = cellsOnEdge(1,iEdge)
             cell2 = cellsOnEdge(2,iEdge)
 
@@ -784,26 +572,23 @@
                d2fdx2_cell1 = 0.0
                d2fdx2_cell2 = 0.0
 
-               !-- if not a boundary cell
-               if(boundaryCell(k,cell1).eq.0.and.boundaryCell(k,cell2).eq.0) then
+               boundaryMask = abs(transfer(.not.(boundaryCell(k,cell1) == 0 .and. boundaryCell(k,cell2) == 0), boundaryMask))
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2)
+               d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1) * boundaryMask
+               d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2) * boundaryMask
 
-                  !-- all edges of cell 1
-                  do i=1, grid % nEdgesOnCell % array (cell1)
-                          d2fdx2_cell1 = d2fdx2_cell1 + &amp;
-                          deriv_two(i+1,1,iEdge) * h(k,grid % CellsOnCell % array (i,cell1))
-                  end do
+               !-- all edges of cell 1
+               do i=1, nEdgesOnCell(cell1) * boundaryMask
+                  d2fdx2_cell1 = d2fdx2_cell1 + &amp;
+                  deriv_two(i+1,1,iEdge) * h(k,grid % CellsOnCell % array (i,cell1))
+               end do
 
-                  !-- all edges of cell 2
-                  do i=1, grid % nEdgesOnCell % array (cell2)
-                          d2fdx2_cell2 = d2fdx2_cell2 + &amp;
-                          deriv_two(i+1,2,iEdge) * h(k,grid % CellsOnCell % array (i,cell2))
-                  end do
+               !-- all edges of cell 2
+               do i=1, nEdgesOnCell(cell2) * boundaryMask
+                  d2fdx2_cell2 = d2fdx2_cell2 + &amp;
+                  deriv_two(i+1,2,iEdge) * h(k,grid % CellsOnCell % array (i,cell2))
+               end do
 
-               endif
-
                h_edge(k,iEdge) =   &amp;
                     0.5*(h(k,cell1) + h(k,cell2))      &amp;
                        -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.
@@ -811,9 +596,7 @@
             end do   ! do k
          end do         ! do iEdge
 
-         call mpas_timer_stop(&quot;ocn_diagnostic_solve-hEdge 4&quot;)
-      endif   ! if(config_thickness_adv_order == 2)
-      call mpas_timer_stop(&quot;ocn_diagnostic_solve-hEdge&quot;)
+!     endif   ! if(config_thickness_adv_order == 2)
 
       !
       ! set the velocity and height at dummy address
@@ -825,81 +608,78 @@
       tracers(s % index_temperature,:,nCells+1) = -1e34
       tracers(s % index_salinity,:,nCells+1) = -1e34
 
-      !
-      ! Compute circulation and relative vorticity at each vertex
-      !
       circulation(:,:) = 0.0
+      vorticity(:,:) = 0.0
+      divergence(:,:) = 0.0
+      ke(:,:) = 0.0
+      v(:,:) = 0.0
       do iEdge=1,nEdges
          vertex1 = verticesOnEdge(1,iEdge)
          vertex2 = verticesOnEdge(2,iEdge)
-         do k=1,maxLevelEdgeBot(iEdge)
-            circulation(k,vertex1) = circulation(k,vertex1) - dcEdge(iEdge) * u(k,iEdge)
-            circulation(k,vertex2) = circulation(k,vertex2) + dcEdge(iEdge) * u(k,iEdge)
-         end do
-      end do
-      do iVertex=1,nVertices
-         do k=1,maxLevelVertexBot(iVertex)
-            vorticity(k,iVertex) = circulation(k,iVertex) / areaTriangle(iVertex)
-         end do
-      end do
 
-      !
-      ! Compute the divergence at each cell center
-      !
-      divergence(:,:) = 0.0
-      do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
-         do k=1,maxLevelEdgeBot(iEdge)
-             divergence(k,cell1) = divergence(k,cell1) + u(k,iEdge)*dvEdge(iEdge)
-             divergence(k,cell2) = divergence(k,cell2) - u(k,iEdge)*dvEdge(iEdge)
-         enddo
-      end do
-      do iCell = 1,nCells
-         r = 1.0 / areaCell(iCell)
-         do k = 1,maxLevelCell(iCell)
-            divergence(k,iCell) = divergence(k,iCell) * r
-         enddo
-      enddo
 
-      !
-      ! Compute kinetic energy in each cell
-      !
-      ke(:,:) = 0.0
-      do iEdge=1,nEdges
-         cell1 = cellsOnEdge(1,iEdge)
-         cell2 = cellsOnEdge(2,iEdge)
+         invAreaTri1 = 1.0 / areaTriangle(vertex1)
+         invAreaTri2 = 1.0 / areaTriangle(vertex2)
+
+         invAreaCell1 = 1.0 / areaCell(cell1)
+         invAreaCell2 = 1.0 / areaCell(cell2)
+
          do k=1,maxLevelEdgeBot(iEdge)
-              ke(k,cell1) = ke(k,cell1) + 0.25 * dcEdge(iEdge) * dvEdge(iEdge) * u(k,iEdge)**2.0
-              ke(k,cell2) = ke(k,cell2) + 0.25 * dcEdge(iEdge) * dvEdge(iEdge) * u(k,iEdge)**2.0
-         enddo
+            ! Compute circulation and relative vorticity at each vertex
+            r_tmp = dcEdge(iEdge) * u(k,iEdge)
+            circulation(k,vertex1) = circulation(k,vertex1) - r_tmp
+            circulation(k,vertex2) = circulation(k,vertex2) + r_tmp
+
+            vorticity(k, vertex1) = vorticity(k, vertex1) - r_tmp * invAreaTri1
+            vorticity(k, vertex2) = vorticity(k, vertex2) + r_tmp * invAreaTri2
+
+            ! Compute the divergence at each cell center
+            r_tmp = dvEdge(iEdge) * u(k, iEdge)
+            divergence(k,cell1) = divergence(k,cell1) + r_tmp * invAreaCell1
+            divergence(k,cell2) = divergence(k,cell2) - r_tmp * invAreaCell2
+
+            ! Compute kinetic energy in each cell
+            r_tmp = r_tmp * dcEdge(iEdge) * u(k,iEdge)
+            ke(k,cell1) = ke(k,cell1) + 0.25 * r_tmp * invAreaCell1
+            ke(k,cell2) = ke(k,cell2) + 0.25 * r_tmp * invAreaCell2
+         end do
+
+         ! Compute v (tangential) velocities
+         do i=1,nEdgesOnEdge(iEdge)
+            eoe = edgesOnEdge(i,iEdge)
+            ! mrp 101115 note: in order to include flux boundary conditions,
+            ! the following loop may need to change to maxLevelEdgeBot
+            do k = 1,maxLevelEdgeTop(iEdge) 
+               v(k,iEdge) = v(k,iEdge) + weightsOnEdge(i,iEdge) * u(k, eoe)
+            end do
+         end do
+
       end do
-      do iCell = 1,nCells
-         do k = 1,maxLevelCell(iCell)
-            ke(k,iCell) = ke(k,iCell) / areaCell(iCell)
-         enddo
-      enddo
 
       !
       ! Compute kinetic energy in each vertex
       !
       kev(:,:) = 0.0; kevc(:,:) = 0.0
-      do iEdge=1,nEdges
+      do iEdge=1,nEdges*ke_vertex_flag
          do k=1,nVertLevels
-            kev(k,verticesOnEdge(1,iEdge)) = kev(k,verticesOnEdge(1,iEdge)) + dcEdge(iEdge) * dvEdge(iEdge) * u(k,iEdge)**2
-            kev(k,verticesOnEdge(2,iEdge)) = kev(k,verticesOnEdge(2,iEdge)) + dcEdge(iEdge) * dvEdge(iEdge) * u(k,iEdge)**2
+            r_tmp = dcEdge(iEdge) * dvEdge(iEdge) * u(k, iEdge)**2
+            kev(k,verticesOnEdge(1,iEdge)) = kev(k,verticesOnEdge(1,iEdge)) + r_tmp
+            kev(k,verticesOnEdge(2,iEdge)) = kev(k,verticesOnEdge(2,iEdge)) + r_tmp
          end do
       end do
-      do iVertex = 1,nVertices
+      do iVertex = 1,nVertices*ke_vertex_flag
          do k=1,nVertLevels
-           kev(k,iVertex) = kev(k,iVertex) / areaTriangle(iVertex) / 4.0
+           kev(k,iVertex) = kev(k,iVertex) / areaTriangle(iVertex) * 0.25
          enddo
       enddo
-      do iVertex = 1, nVertices
+      do iVertex = 1, nVertices*ke_vertex_flag
        do i=1,grid % vertexDegree
          iCell = cellsOnVertex(i,iVertex)
+         invAreaCell1 = 1.0 / areaCell(iCell)
          do k=1,nVertLevels
-           kevc(k,iCell) = kevc(k,iCell) + kiteAreasOnVertex(i, iVertex) * kev(k, iVertex) / areaCell(iCell)
+           kevc(k,iCell) = kevc(k,iCell) + kiteAreasOnVertex(i, iVertex) * kev(k, iVertex) * invAreaCell1
          enddo
        enddo
       enddo
@@ -907,35 +687,17 @@
       !
       ! Compute kinetic energy in each cell by blending ke and kevc
       !
-      if(config_include_KE_vertex) then
-      do iCell=1,nCells
+      do iCell=1,nCells*ke_vertex_flag
          do k=1,nVertLevels
             ke(k,iCell) = 5.0/8.0*ke(k,iCell) + 3.0/8.0*kevc(k,iCell)
          end do
       end do
-      endif
 
       !
-      ! Compute v (tangential) velocities
-      !
-      v(:,:) = 0.0
-      do iEdge = 1,nEdges
-         do i=1,nEdgesOnEdge(iEdge)
-            eoe = edgesOnEdge(i,iEdge)
-            ! mrp 101115 note: in order to include flux boundary conditions,
-            ! the following loop may need to change to maxLevelEdgeBot
-            do k = 1,maxLevelEdgeTop(iEdge) 
-               v(k,iEdge) = v(k,iEdge) + weightsOnEdge(i,iEdge) * u(k, eoe)
-            end do
-         end do
-      end do
-
-      !
       ! Compute ke on cell edges at velocity locations for quadratic bottom drag. 
       !
       ! mrp 101025 efficiency note: we could get rid of ke_edge completely by 
       ! using sqrt(u(k,iEdge)**2 + v(k,iEdge)**2) in its place elsewhere.
-      ke_edge = 0.0  !mrp remove 0 for efficiency
       do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
@@ -948,83 +710,64 @@
       ! Compute height at vertices, pv at vertices, and average pv to edge locations
       !  ( this computes pv_vertex at all vertices bounding real cells and distance-1 ghost cells )
       !
-      if (trim(config_time_integration) == 'RK4') then
-         ! for RK4, PV is really PV = (eta+f)/h
-         fCoef = 1
-      elseif (trim(config_time_integration) == 'split_explicit' &amp;
-          .or.trim(config_time_integration) == 'unsplit_explicit') then
-         ! for split explicit, PV is eta/h because f is added separately to the momentum forcing.
-! mrp temp, new should be:
-         fCoef = 0
-! old, for testing:
-!         fCoef = 1
-      end if
-
       do iVertex = 1,nVertices
+         invAreaTri1 = 1.0 / areaTriangle(iVertex)
          do k=1,maxLevelVertexBot(iVertex)
             h_vertex = 0.0
             do i=1,vertexDegree
                h_vertex = h_vertex + h(k,cellsOnVertex(i,iVertex)) * kiteAreasOnVertex(i,iVertex)
             end do
-            h_vertex = h_vertex / areaTriangle(iVertex)
+            h_vertex = h_vertex * invAreaTri1
 
             pv_vertex(k,iVertex) = (fCoef*fVertex(iVertex) + vorticity(k,iVertex)) / h_vertex
          end do
       end do
 
-      !
-      ! Compute pv at cell centers
-      !    ( this computes pv_cell for all real cells and distance-1 ghost cells )
-      !
       pv_cell(:,:) = 0.0
+      pv_edge(:,:) = 0.0
       do iVertex = 1,nVertices
          do i=1,vertexDegree
             iCell = cellsOnVertex(i,iVertex)
+            iEdge = edgesOnVertex(i,iVertex)
+
+            invAreaCell1 = 1.0 / areaCell(iCell)
+
+            ! Compute pv at cell centers
+            !    ( this computes pv_cell for all real cells and distance-1 ghost cells )
             do k = 1,maxLevelCell(iCell)
-               pv_cell(k,iCell) = pv_cell(k,iCell)  &amp;
-                  + kiteAreasOnVertex(i, iVertex) * pv_vertex(k, iVertex) &amp;
-                    / areaCell(iCell)
+               pv_cell(k,iCell) = pv_cell(k,iCell) + kiteAreasOnVertex(i, iVertex) * pv_vertex(k, iVertex) * invAreaCell1
             enddo
-         enddo
-      enddo
 
-      !
-      ! Compute pv at the edges
-      !   ( this computes pv_edge at all edges bounding real cells )
-      !
-      pv_edge(:,:) = 0.0
-      do iVertex = 1,nVertices
-         do i=1,vertexDegree
-            iEdge = edgesOnVertex(i,iVertex)
+            ! Compute pv at the edges
+            !   ( this computes pv_edge at all edges bounding real cells )
             do k=1,maxLevelEdgeBot(iEdge)
-               pv_edge(k,iEdge) =  pv_edge(k,iEdge) + 0.5 * pv_vertex(k,iVertex)
+               pv_edge(k,iEdge) = pv_edge(k,iEdge) + 0.5 * pv_vertex(k,iVertex)
             enddo
-        end do
-      end do
+         enddo
+      enddo
 
-      !
-      ! Compute gradient of PV in normal direction
-      !   ( this computes gradPVn for all edges bounding real cells )
-      !
-      gradPVn(:,:) = 0.0
+!     gradPVn(:,:) = 0.0
+!     gradPVt(:,:) = 0.0
       do iEdge = 1,nEdges
+         cell1 = cellsOnEdge(1, iEdge)
+         cell2 = cellsOnEdge(2, iEdge)
+         vertex1 = verticesOnedge(1, iEdge)
+         vertex2 = verticesOnedge(2, iEdge)
+
+         invLength = 1.0 / dcEdge(iEdge)
+         ! Compute gradient of PV in normal direction
+         !   ( this computes gradPVn for all edges bounding real cells )
          do k=1,maxLevelEdgeTop(iEdge)
-            gradPVn(k,iEdge) = (  pv_cell(k,cellsOnEdge(2,iEdge)) &amp;
-                                - pv_cell(k,cellsOnEdge(1,iEdge))) &amp;
-                               / dcEdge(iEdge)
+            gradPVn(k,iEdge) = (pv_cell(k,cell2) - pv_cell(k,cell1)) * invLength
          enddo
-      enddo
 
-      !
-      ! Compute gradient of PV in the tangent direction
-      !   ( this computes gradPVt at all edges bounding real cells and distance-1 ghost cells )
-      !
-      do iEdge = 1,nEdges
+         invLength = 1.0 / dvEdge(iEdge)
+         ! Compute gradient of PV in the tangent direction
+         !   ( this computes gradPVt at all edges bounding real cells and distance-1 ghost cells )
          do k = 1,maxLevelEdgeBot(iEdge)
-           gradPVt(k,iEdge) = (  pv_vertex(k,verticesOnEdge(2,iEdge)) &amp;
-                               - pv_vertex(k,verticesOnEdge(1,iEdge))) &amp;
-                                 /dvEdge(iEdge)
+           gradPVt(k,iEdge) = (pv_vertex(k,vertex2) - pv_vertex(k,vertex1)) * invLength
          enddo
+
       enddo
 
       !
@@ -1044,15 +787,18 @@
       ! For an isopycnal model, density should remain constant.
       ! For zlevel, calculate in-situ density
       if (config_vert_grid_type.ne.'isopycnal') then
+         call mpas_timer_start(&quot;equation of state&quot;, .false., diagEOSTimer)
          call ocn_equation_of_state_rho(s, grid, 0, 'relative', err)
       ! mrp 110324 In order to visualize rhoDisplaced, include the following
          call ocn_equation_of_state_rho(s, grid, 1, 'relative', err)
+         call mpas_timer_stop(&quot;equation of state&quot;, diagEOSTimer)
       endif
 
       !
       ! Pressure
       ! This section must be after computing rho
       !
+      ! dwj: 10/25/2011 - Need to explore isopycnal vs zlevel flags
       if (config_vert_grid_type.eq.'isopycnal') then
 
         ! For Isopycnal model.
@@ -1113,8 +859,6 @@
 ! mrp 111206 remove
 !      call ocn_wtop(s,grid)
 
-      call mpas_timer_stop(&quot;ocn_diagnostic_solve&quot;)
-
    end subroutine ocn_diagnostic_solve!}}}
 
 !***********************************************************************
@@ -1164,8 +908,6 @@
         maxLevelCell, maxLevelEdgeTop, maxLevelEdgeBot, &amp;
         maxLevelVertexBot,  maxLevelVertexTop
 
-        call mpas_timer_start(&quot;wTop&quot;)
-
       u           =&gt; s % u % array
       h           =&gt; s % h % array
       wTop        =&gt; s % wTop % array
@@ -1210,6 +952,7 @@
       !
       ! vertical velocity through layer interface
       !
+      !dwj: 10/25/2011 - Need to explore isopycnal vs zlevel flags
       if (config_vert_grid_type.eq.'isopycnal') then
         ! set vertical velocity to zero in isopycnal case
         wTop=0.0  
@@ -1241,6 +984,7 @@
            ! bottom is zero.
            wTop(1,iCell) = 0.0
            wTop(maxLevelCell(iCell)+1,iCell) = 0.0
+
            do k=maxLevelCell(iCell),2,-1
               wTop(k,iCell) = wTop(k+1,iCell) - div_hu(k,iCell) - h_tend_col(k)
            end do
@@ -1302,8 +1046,6 @@
 
       deallocate(div_hu, div_hu_btr, h_tend_col, h_weights)
 
-      call mpas_timer_stop(&quot;wTop&quot;)
-
    end subroutine ocn_wtop!}}}
 
 !***********************************************************************
@@ -1336,88 +1078,35 @@
 
 ! mrp 110512 I just split compute_tend into compute_tend_u and compute_tend_h.
 !  Some of these variables can be removed, but at a later time.
-      integer :: iEdge, iCell, iVertex, k, cell1, cell2, &amp;
-        vertex1, vertex2, eoe, i, j
+      integer :: iEdge, cell1, cell2, eoe, i, j, k
 
-      integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve
-      real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, q, &amp;
-        upstream_bias, wTopEdge, rho0Inv, r
-      real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel 
-      real (kind=RKIND), dimension(:,:), pointer :: &amp;
-        weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, uBcl, v, pressure, &amp;
-        tend_u, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
-        MontPot, wTop, divergence, vertViscTopOfEdge
+      integer :: nEdgesSolve
+      real (kind=RKIND), dimension(:), pointer :: fEdge
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge, u, uBcl
       type (dm_info) :: dminfo
 
-      integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge, &amp;
-        maxLevelCell, maxLevelEdgeTop, maxLevelVertexBot
-      integer, dimension(:,:), pointer :: &amp;
-        cellsOnEdge, cellsOnVertex, verticesOnEdge, edgesOnCell, &amp;
-        edgesOnEdge, edgesOnVertex
-      real (kind=RKIND) :: u_diffusion
-      real (kind=RKIND), dimension(:), allocatable:: fluxVertTop,w_dudzTopEdge
+      integer, dimension(:), pointer :: maxLevelEdgeTop, nEdgesOnEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnEdge
 
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_divergence
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_u
-      real (kind=RKIND), allocatable, dimension(:,:) :: delsq_circulation, delsq_vorticity
-
-
-      real (kind=RKIND), dimension(:,:), pointer :: u_src
-      real (kind=RKIND), parameter :: rho_ref = 1000.0
-
       call mpas_timer_start(&quot;ocn_fuperp&quot;)
 
-      h           =&gt; s % h % array
       u           =&gt; s % u % array
       uBcl        =&gt; s % uBcl % array
-      v           =&gt; s % v % array
-      wTop        =&gt; s % wTop % array
-      h_edge      =&gt; s % h_edge % array
-      circulation =&gt; s % circulation % array
-      vorticity   =&gt; s % vorticity % array
-      divergence  =&gt; s % divergence % array
-      ke          =&gt; s % ke % array
-      ke_edge     =&gt; s % ke_edge % array
-      pv_edge     =&gt; s % pv_edge % array
-      MontPot     =&gt; s % MontPot % array
-      pressure    =&gt; s % pressure % array
-
       weightsOnEdge     =&gt; grid % weightsOnEdge % array
-      kiteAreasOnVertex =&gt; grid % kiteAreasOnVertex % array
+      fEdge             =&gt; grid % fEdge % array
+      maxLevelEdgeTop      =&gt; grid % maxLevelEdgeTop % array
       cellsOnEdge       =&gt; grid % cellsOnEdge % array
-      cellsOnVertex     =&gt; grid % cellsOnVertex % array
-      verticesOnEdge    =&gt; grid % verticesOnEdge % array
-      nEdgesOnCell      =&gt; grid % nEdgesOnCell % array
-      edgesOnCell       =&gt; grid % edgesOnCell % array
       nEdgesOnEdge      =&gt; grid % nEdgesOnEdge % array
       edgesOnEdge       =&gt; grid % edgesOnEdge % array
-      edgesOnVertex     =&gt; grid % edgesOnVertex % array
-      dcEdge            =&gt; grid % dcEdge % array
-      dvEdge            =&gt; grid % dvEdge % array
-      areaCell          =&gt; grid % areaCell % array
-      areaTriangle      =&gt; grid % areaTriangle % array
-      h_s               =&gt; grid % h_s % array
-      fVertex           =&gt; grid % fVertex % array
-      fEdge             =&gt; grid % fEdge % array
-      zMidZLevel        =&gt; grid % zMidZLevel % array
-      zTopZLevel        =&gt; grid % zTopZLevel % array
-      maxLevelCell      =&gt; grid % maxLevelCell % array
-      maxLevelEdgeTop      =&gt; grid % maxLevelEdgeTop % array
-      maxLevelVertexBot    =&gt; grid % maxLevelVertexBot % array
 
-                  
-      nCells      = grid % nCells
-      nEdges      = grid % nEdges
+      fEdge       =&gt; grid % fEdge % array
+
       nEdgesSolve = grid % nEdgesSolve
-      nVertices   = grid % nVertices
-      nVertLevels = grid % nVertLevels
 
       !
       ! Put f*uBcl^{perp} in u as a work variable
       !
-      do iEdge=1,grid % nEdgesSolve
+      do iEdge=1,nEdgesSolve
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
 
@@ -1436,7 +1125,71 @@
    end subroutine ocn_fuperp!}}}
 
 !***********************************************************************
+!
+!  routine ocn_tendency_init
+!
+!&gt; \brief   Initializes flags used within tendency routines.
+!&gt; \author  Doug Jacobsen
+!&gt; \date    4 November 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes flags related to quantities computed within
+!&gt;  other tendency routines.
+!
+!-----------------------------------------------------------------------
 
+    subroutine ocn_tendency_init(err)!{{{
+        integer, intent(out) :: err
+
+        err = 0
+
+        coef_3rd_order = 0.
+
+        if (config_thickness_adv_order == 2) then
+            hadv2nd = 1
+            hadv3rd = 0
+            hadv4th = 0
+        else if (config_thickness_adv_order == 3) then
+            hadv2nd = 0
+            hadv3rd = 1
+            hadv4th = 0
+
+            if(config_monotonic) then
+                coef_3rd_order = 0.25
+            else
+                coef_3rd_order = 1.0
+            endif
+        else if (config_thickness_adv_order == 4) then
+            hadv2nd = 0
+            hadv3rd = 0
+            hadv4th = 1
+        end if
+
+
+        if(config_include_KE_vertex) then
+            ke_vertex_flag = 1
+            ke_cell_flag = 0
+        else
+            ke_vertex_flag = 0
+            ke_cell_flag = 1
+        endif
+
+        if (trim(config_time_integration) == 'RK4') then
+            ! for RK4, PV is really PV = (eta+f)/h
+            fCoef = 1
+        elseif (trim(config_time_integration) == 'split_explicit' &amp;
+          .or.trim(config_time_integration) == 'unsplit_explicit') then
+            ! for split explicit, PV is eta/h because f is added separately to the momentum forcing.
+            ! mrp temp, new should be:
+            fCoef = 0
+            ! old, for testing:
+            !         fCoef = 1
+        end if
+
+    end subroutine ocn_tendency_init!}}}
+
+!***********************************************************************
+
 end module ocn_tendency
 
 !|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_thick_hadv.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_thick_hadv.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_thick_hadv.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -107,7 +107,7 @@
       integer, dimension(:), pointer :: maxLevelEdgeBot, MaxLevelCell
       integer, dimension(:,:), pointer :: cellsOnEdge
 
-      real (kind=RKIND) :: flux
+      real (kind=RKIND) :: flux, invAreaCell1, invAreaCell2
       real (kind=RKIND), dimension(:), pointer :: dvEdge, areaCell
 
       !-----------------------------------------------------------------

Copied: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_average.F (from rev 1357, branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_average.F)
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_average.F                                (rev 0)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_average.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -0,0 +1,129 @@
+module ocn_time_average
+
+    use mpas_grid_types
+
+    implicit none
+    save
+    public
+
+    contains 
+
+    subroutine ocn_time_average_init(state)!{{{
+        type (state_type), intent(inout) :: state
+
+        real, pointer :: nAccumulate
+
+        real (kind=RKIND), dimension(:), pointer :: acc_ssh, acc_sshVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_uReconstructZonal, acc_uReconstructMeridional, acc_uReconstructZonalVar, acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_u, acc_uVar
+
+        nAccumulate =&gt; state % nAccumulate % scalar
+
+        acc_ssh =&gt; state % acc_ssh % array
+        acc_sshVar =&gt; state % acc_sshVar % array
+        acc_uReconstructZonal =&gt; state % acc_uReconstructZonal % array
+        acc_uReconstructMeridional =&gt; state % acc_uReconstructMeridional % array
+        acc_uReconstructZonalVar =&gt; state % acc_uReconstructZonalVar % array
+        acc_uReconstructMeridionalVar =&gt; state % acc_uReconstructMeridionalVar % array
+        acc_u =&gt; state % acc_u % array
+        acc_uVar =&gt; state % acc_uVar % array
+
+        nAccumulate = 0
+
+        acc_ssh = 0.0
+        acc_sshVar = 0.0
+        acc_uReconstructZonal = 0.0
+        acc_uReconstructMeridional = 0.0
+        acc_uReconstructZonalVar = 0.0
+        acc_uReconstructMeridionalVar = 0.0
+        acc_u = 0.0
+        acc_uVar = 0.0
+
+    end subroutine ocn_time_average_init!}}}
+
+    subroutine ocn_time_average_accumulate(state, old_state)!{{{
+        type (state_type), intent(inout) :: state
+        type (state_type), intent(in) :: old_state
+
+        real, pointer :: nAccumulate, old_nAccumulate
+
+        real (kind=RKIND), dimension(:), pointer :: ssh
+        real (kind=RKIND), dimension(:,:), pointer :: uReconstructZonal, uReconstructMeridional, u
+
+        real (kind=RKIND), dimension(:,:), pointer :: acc_u, acc_uVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_uReconstructZonal, acc_uReconstructMeridional, acc_uReconstructZonalVar, acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:), pointer :: acc_ssh, acc_sshVar
+
+        real (kind=RKIND), dimension(:,:), pointer :: old_acc_u, old_acc_uVar
+        real (kind=RKIND), dimension(:,:), pointer :: old_acc_uReconstructZonal, old_acc_uReconstructMeridional, old_acc_uReconstructZonalVar, old_acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:), pointer :: old_acc_ssh, old_acc_sshVar
+
+        old_nAccumulate =&gt; old_state % nAccumulate  % scalar
+        nAccumulate =&gt; state % nAccumulate  % scalar
+
+        ssh =&gt; state % ssh % array
+        uReconstructZonal =&gt; state % uReconstructZonal % array
+        uReconstructMeridional =&gt; state % uReconstructMeridional % array
+        u =&gt; state % u % array
+
+        acc_ssh =&gt; state % acc_ssh % array
+        acc_sshVar =&gt; state % acc_sshVar % array
+        acc_uReconstructZonal =&gt; state % acc_uReconstructZonal % array
+        acc_uReconstructMeridional =&gt; state % acc_uReconstructMeridional % array
+        acc_uReconstructZonalVar =&gt; state % acc_uReconstructZonalVar % array
+        acc_uReconstructMeridionalVar =&gt; state % acc_uReconstructMeridionalVar % array
+        acc_u =&gt; state % acc_u % array
+        acc_uVar =&gt; state % acc_uVar % array
+
+        old_acc_ssh =&gt; old_state % acc_ssh % array
+        old_acc_sshVar =&gt; old_state % acc_sshVar % array
+        old_acc_uReconstructZonal =&gt; old_state % acc_uReconstructZonal % array
+        old_acc_uReconstructMeridional =&gt; old_state % acc_uReconstructMeridional % array
+        old_acc_uReconstructZonalVar =&gt; old_state % acc_uReconstructZonalVar % array
+        old_acc_uReconstructMeridionalVar =&gt; old_state % acc_uReconstructMeridionalVar % array
+        old_acc_u =&gt; old_state % acc_u % array
+        old_acc_uVar =&gt; old_state % acc_uVar % array
+
+        acc_ssh = old_acc_ssh + ssh
+        acc_sshVar = old_acc_sshVar + ssh**2
+        acc_uReconstructZonal = old_acc_uReconstructZonal + uReconstructZonal
+        acc_uReconstructMeridional = old_acc_uReconstructMeridional + uReconstructMeridional
+        acc_uReconstructZonalVar = old_acc_uReconstructZonalVar + uReconstructZonal**2
+        acc_uReconstructMeridionalVar = old_acc_uReconstructMeridionalVar + uReconstructMeridional**2
+        acc_u = old_acc_u + u
+        acc_uVar = old_acc_uVar + u**2
+
+        nAccumulate = old_nAccumulate + 1
+    end subroutine ocn_time_average_accumulate!}}}
+
+    subroutine ocn_time_average_normalize(state)!{{{
+        type (state_type), intent(inout) :: state
+
+        real, pointer :: nAccumulate
+
+        real (kind=RKIND), dimension(:), pointer :: acc_ssh, acc_sshVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_uReconstructZonal, acc_uReconstructMeridional, acc_uReconstructZonalVar, acc_uReconstructMeridionalVar
+        real (kind=RKIND), dimension(:,:), pointer :: acc_u, acc_uVar
+
+        nAccumulate =&gt; state % nAccumulate  % scalar
+
+        acc_ssh =&gt; state % acc_ssh % array
+        acc_sshVar =&gt; state % acc_sshVar % array
+        acc_uReconstructZonal =&gt; state % acc_uReconstructZonal % array
+        acc_uReconstructMeridional =&gt; state % acc_uReconstructMeridional % array
+        acc_uReconstructZonalVar =&gt; state % acc_uReconstructZonalVar % array
+        acc_uReconstructMeridionalVar =&gt; state % acc_uReconstructMeridionalVar % array
+        acc_u =&gt; state % acc_u % array
+        acc_uVar =&gt; state % acc_uVar % array
+
+        acc_ssh = acc_ssh / nAccumulate
+        acc_sshVar = acc_sshVar / nAccumulate
+        acc_uReconstructZonal = acc_uReconstructZonal / nAccumulate
+        acc_uReconstructMeridional = acc_uReconstructMeridional / nAccumulate
+        acc_uReconstructZonalVar = acc_uReconstructZonalVar / nAccumulate
+        acc_uReconstructMeridionalVar = acc_uReconstructMeridionalVar / nAccumulate
+        acc_u = acc_u / nAccumulate
+        acc_uVar = acc_uVar / nAccumulate
+    end subroutine ocn_time_average_normalize!}}}
+
+end module ocn_time_average

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_rk4.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_rk4.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_rk4.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -24,7 +24,8 @@
    use ocn_tendency
 
    use ocn_equation_of_state
-   use ocn_Vmix
+   use ocn_vmix
+   use ocn_time_average
 
    implicit none
    private
@@ -182,7 +183,6 @@
            endif
 
            call ocn_tend_scalar(block % tend, provis, block % diagnostics, block % mesh)
-           call enforce_boundaryEdge(block % tend, block % mesh)
            block =&gt; block % next
         end do
         call mpas_timer_stop(&quot;RK4-tendency computations&quot;)
@@ -299,8 +299,6 @@
 
          if (config_implicit_vertical_mix) then
             call mpas_timer_start(&quot;RK4-implicit vert mix&quot;)
-            allocate(A(nVertLevels),C(nVertLevels),uTemp(nVertLevels), &amp;
-               tracersTemp(num_tracers,nVertLevels))
 
             call ocn_vmix_coefs(block % mesh, block % state % time_levs(2) % state, block % diagnostics, err)
 
@@ -320,31 +318,9 @@
             !
 
             call ocn_tracer_vmix_tend_implicit(block % mesh, dt, vertdifftopofcell, h, tracers, err)
+            call mpas_timer_stop(&quot;RK4-implicit vert mix&quot;)
          end if
 
-         ! mrp 110725 momentum decay term
-         if (config_mom_decay) then
-             call mpas_timer_start(&quot;RK4-momentum decay&quot;)
-
-            !
-            !  Implicit solve for momentum decay
-            !
-            !  Add term to RHS of momentum equation: -1/gamma u
-            !
-            !  This changes the solve to:
-            !  u^{n+1} = u_provis^{n+1}/(1+dt/gamma)
-            !
-            coef = 1.0/(1.0 + dt/config_mom_decay_time)
-            do iEdge=1,block % mesh % nEdges
-               do k=1,maxLevelEdgeTop(iEdge)
-                  u(k,iEdge) = coef*u(k,iEdge) 
-               end do
-            end do
-
-            call mpas_timer_stop(&quot;RK4-momentum decay&quot;)
-         end if
-
-
          if (config_test_case == 1) then    ! For case 1, wind field should be fixed
             block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
          end if
@@ -359,6 +335,8 @@
                           block % state % time_levs(2) % state % uReconstructMeridional % array    &amp;
                          )
 
+         call ocn_time_average_accumulate(block % state % time_levs(2) % state, block % state % time_levs(1) % state)
+
          block =&gt; block % next
       end do
       call mpas_timer_stop(&quot;RK4-cleaup phase&quot;)
@@ -605,51 +583,6 @@
 
    end subroutine filter_btr_mode_u!}}}
 
-   subroutine enforce_boundaryEdge(tend, grid)!{{{
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   ! Enforce any boundary conditions on the normal velocity at each edge
-   !
-   ! Input: grid - grid metadata
-   !
-   ! Output: tend_u set to zero at boundaryEdge == 1 locations
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-
-      implicit none
-
-      type (tend_type), intent(inout) :: tend
-      type (mesh_type), intent(in) :: grid
-
-      integer, dimension(:,:), pointer :: boundaryEdge
-      real (kind=RKIND), dimension(:,:), pointer :: tend_u
-      integer :: nCells, nEdges, nVertices, nVertLevels
-      integer :: iEdge, k
-
-      call mpas_timer_start(&quot;enforce_boundaryEdge&quot;)
-
-      nCells      = grid % nCells
-      nEdges      = grid % nEdges
-      nVertices   = grid % nVertices
-      nVertLevels = grid % nVertLevels
-
-      boundaryEdge         =&gt; grid % boundaryEdge % array
-      tend_u      =&gt; tend % u % array
-
-      if(maxval(boundaryEdge).le.0) return
-
-      do iEdge = 1,nEdges
-        do k = 1,nVertLevels
-
-          if(boundaryEdge(k,iEdge).eq.1) then
-             tend_u(k,iEdge) = 0.0
-          endif
-
-        enddo
-       enddo
-      call mpas_timer_stop(&quot;enforce_boundaryEdge&quot;)
-
-   end subroutine enforce_boundaryEdge!}}}
-
 end module ocn_time_integration_rk4
 
 ! vim: foldmethod=marker

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_split.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_split.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_split.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -27,8 +27,8 @@
 
    use ocn_equation_of_state
    use ocn_vmix
+   use ocn_time_average
 
-
    implicit none
    private
    save
@@ -47,6 +47,10 @@
 
    public :: ocn_time_integrator_split
 
+   type (timer_node), pointer :: timer_main, timer_prep, timer_bcl_vel, timer_btr_vel, timer_diagnostic_update, timer_implicit_vmix, &amp;
+                                 timer_halo_diagnostic, timer_halo_ubtr, timer_halo_ssh, timer_halo_f, timer_halo_h, &amp; 
+                                 timer_halo_tracers, timer_halo_ubcl
+
    contains
 
 !|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -63,16 +67,16 @@
 !
 !-----------------------------------------------------------------------
 
-subroutine ocn_time_integrator_split(domain, dt)!{{{
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   ! Advance model state forward in time by the specified time step using 
-   !   Split_Explicit timestepping scheme
-   !
-   ! Input: domain - current model state in time level 1 (e.g., time_levs(1)state%h(:,:)) 
-   !                 plus grid meta-data
-   ! Output: domain - upon exit, time level 2 (e.g., time_levs(2)%state%h(:,:)) contains 
-   !                  model state advanced forward in time by dt seconds
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    subroutine ocn_time_integrator_split(domain, dt)!{{{
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    ! Advance model state forward in time by the specified time step using 
+    !   Split_Explicit timestepping scheme
+    !
+    ! Input: domain - current model state in time level 1 (e.g., time_levs(1)state%h(:,:)) 
+    !                 plus grid meta-data
+    ! Output: domain - upon exit, time level 2 (e.g., time_levs(2)%state%h(:,:)) contains 
+    !                  model state advanced forward in time by dt seconds
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
       implicit none
 
@@ -81,72 +85,75 @@
 
       type (dm_info) :: dminfo
       integer :: iCell, i,k,j, iEdge, cell1, cell2, split_explicit_step, split, &amp;
-        eoe, oldBtrSubcycleTime, newBtrSubcycleTime, uPerpTime, BtrCorIter, &amp;
-        n_bcl_iter(config_n_ts_iter), &amp;
-        vertex1, vertex2, iVertex
-
+                 eoe, oldBtrSubcycleTime, newBtrSubcycleTime, uPerpTime, BtrCorIter, &amp;
+                 n_bcl_iter(config_n_ts_iter), &amp;
+                 vertex1, vertex2, iVertex, sshSwapFlag
+      
       type (block_type), pointer :: block
       real (kind=RKIND) :: uhSum, hSum, sshEdge, flux, &amp;
-         uPerp, uCorr, tracerTemp, coef, FBtr_coeff, sshCell1, sshCell2
+                 uPerp, uCorr, tracerTemp, coef, FBtr_coeff, sshCell1, sshCell2
       real (kind=RKIND), dimension(:), pointer :: sshNew
 
       integer :: num_tracers, ucorr_coef, err
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
-        u, h, h_edge, ke_edge, vertViscTopOfEdge, vertDiffTopOfCell
+                 u, h, h_edge, ke_edge, vertViscTopOfEdge, vertDiffTopOfCell
       real (kind=RKIND), dimension(:,:,:), pointer :: tracers
       integer, dimension(:), pointer :: &amp; 
-        maxLevelCell, maxLevelEdgeTop
+                 maxLevelCell, maxLevelEdgeTop
       real (kind=RKIND), dimension(:), allocatable:: A,C,uTemp, hNew
       real (kind=RKIND), dimension(:,:), allocatable:: tracersTemp
 
-      call mpas_timer_start(&quot;split_explicit_timestep&quot;)
+      sshSwapFlag = 1
 
+      call mpas_timer_start(&quot;se timestep&quot;, .false., timer_main)
+
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       !
       !  Prep variables before first iteration
       !
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      call mpas_timer_start(&quot;se prep&quot;, .false., timer_prep)
       block =&gt; domain % blocklist
       do while (associated(block))
 
-         do iEdge=1,block % mesh % nEdges
+        do iEdge=1,block % mesh % nEdges
 
-            ! The baroclinic velocity needs be recomputed at the beginning of a 
-            ! timestep because the implicit vertical mixing is conducted on the
-            ! total u.  We keep uBtr from the previous timestep.
-              block % state % time_levs(1) % state % uBcl % array(:,iEdge) &amp;
-            = block % state % time_levs(1) % state % u % array(:,iEdge) &amp;
-            - block % state % time_levs(1) % state % uBtr % array(iEdge)
+          ! The baroclinic velocity needs be recomputed at the beginning of a 
+          ! timestep because the implicit vertical mixing is conducted on the
+          ! total u.  We keep uBtr from the previous timestep.
+          block % state % time_levs(1) % state % uBcl % array(:,iEdge) &amp;
+              = block % state % time_levs(1) % state % u % array(:,iEdge) &amp;
+              - block % state % time_levs(1) % state % uBtr % array(iEdge)
 
-              block % state % time_levs(2) % state % u % array(:,iEdge) &amp;
-            = block % state % time_levs(1) % state % u % array(:,iEdge)
+          block % state % time_levs(2) % state % u % array(:,iEdge) &amp;
+              = block % state % time_levs(1) % state % u % array(:,iEdge)
 
-              block % state % time_levs(2) % state % uBcl % array(:,iEdge) &amp;
-            = block % state % time_levs(1) % state % uBcl % array(:,iEdge)
+          block % state % time_levs(2) % state % uBcl % array(:,iEdge) &amp;
+              = block % state % time_levs(1) % state % uBcl % array(:,iEdge)
 
-         enddo ! iEdge
+        enddo ! iEdge
 
-         ! Initialize * variables that are used compute baroclinic tendencies below.
-           block % state % time_levs(2) % state % ssh % array(:) &amp;
-         = block % state % time_levs(1) % state % ssh % array(:)
+        ! Initialize * variables that are used compute baroclinic tendencies below.
+        block % state % time_levs(2) % state % ssh % array(:) &amp;
+            = block % state % time_levs(1) % state % ssh % array(:)
 
-           block % state % time_levs(2) % state % h_edge % array(:,:) &amp;
-         = block % state % time_levs(1) % state % h_edge % array(:,:)
+        block % state % time_levs(2) % state % h_edge % array(:,:) &amp;
+            = block % state % time_levs(1) % state % h_edge % array(:,:)
 
-         do iCell=1,block % mesh % nCells  ! couple tracers to h
-           ! change to maxLevelCell % array(iCell) ?
-           do k=1,block % mesh % nVertLevels
+        do iCell=1,block % mesh % nCells  ! couple tracers to h
+          ! change to maxLevelCell % array(iCell) ?
+          do k=1,block % mesh % nVertLevels
 
-                block % state % time_levs(2) % state % tracers % array(:,k,iCell) &amp; 
-              = block % state % time_levs(1) % state % tracers % array(:,k,iCell) 
-            end do
+            block % state % time_levs(2) % state % tracers % array(:,k,iCell) &amp; 
+                = block % state % time_levs(1) % state % tracers % array(:,k,iCell) 
+          end do
 
-         end do
+        end do
 
-         block =&gt; block % next
+        block =&gt; block % next
       end do
 
-
+      call mpas_timer_stop(&quot;se prep&quot;, timer_prep)
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       ! BEGIN large iteration loop 
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -155,953 +162,755 @@
       n_bcl_iter(config_n_ts_iter) = config_n_bcl_iter_end
 
       do split_explicit_step = 1, config_n_ts_iter
-! ---  update halos for diagnostic variables
+        ! ---  update halos for diagnostic variables
 
+        call mpas_timer_start(&quot;se halo diag&quot;, .false., timer_halo_diagnostic)
         block =&gt; domain % blocklist
         do while (associated(block))
 
-           call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % pv_edge % array(:,:), &amp;
-                                            block % mesh % nVertLevels, block % mesh % nEdges, &amp;
-                                            block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
+          call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % pv_edge % array(:,:), &amp;
+              block % mesh % nVertLevels, block % mesh % nEdges, &amp;
+              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
 
-           if (config_h_mom_eddy_visc4 &gt; 0.0) then
-              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % divergence % array(:,:), &amp;
-                                               block % mesh % nVertLevels, block % mesh % nCells, &amp;
-                                               block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % vorticity % array(:,:), &amp;
-                                               block % mesh % nVertLevels, block % mesh % nVertices, &amp;
-                                               block % parinfo % verticesToSend, block % parinfo % verticesToRecv)
-           end if
+          if (config_h_mom_eddy_visc4 &gt; 0.0) then
+            call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % divergence % array(:,:), &amp;
+                block % mesh % nVertLevels, block % mesh % nCells, &amp;
+                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
+            call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % vorticity % array(:,:), &amp;
+                block % mesh % nVertLevels, block % mesh % nVertices, &amp;
+                block % parinfo % verticesToSend, block % parinfo % verticesToRecv)
+          end if
 
-           block =&gt; block % next
+          block =&gt; block % next
         end do
+        call mpas_timer_stop(&quot;se halo diag&quot;, timer_halo_diagnostic)
 
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      !
-      !  Stage 1: Baroclinic velocity (3D) prediction, explicit with long timestep
-      !
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !
+        !  Stage 1: Baroclinic velocity (3D) prediction, explicit with long timestep
+        !
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-      ! compute velocity tendencies, T(u*,w*,p*)
+        ! compute velocity tendencies, T(u*,w*,p*)
+        call mpas_timer_start(&quot;se bcl vel&quot;, .false., timer_bcl_vel)
 
-      block =&gt; domain % blocklist
-      do while (associated(block))
-         if (.not.config_implicit_vertical_mix) then
+        block =&gt; domain % blocklist
+        do while (associated(block))
+          if (.not.config_implicit_vertical_mix) then
             call ocn_vmix_coefs(block % mesh, block % state % time_levs(2) % state, block % diagnostics, err)
-         end if
-         call ocn_tend_u(block % tend, block % state % time_levs(2) % state , block % diagnostics, block % mesh)
-         call enforce_boundaryEdge(block % tend, block % mesh)
-         block =&gt; block % next
-      end do
+          end if
+          call ocn_tend_u(block % tend, block % state % time_levs(2) % state , block % diagnostics, block % mesh)
+          block =&gt; block % next
+        end do
 
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      ! BEGIN baroclinic iterations on linear Coriolis term
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      do j=1,n_bcl_iter(split_explicit_step)
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        ! BEGIN baroclinic iterations on linear Coriolis term
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        do j=1,n_bcl_iter(split_explicit_step)
 
-         ! Use this G coefficient to avoid an if statement within the iEdge loop.
-         if     (trim(config_time_integration) == 'unsplit_explicit') then
+          ! Use this G coefficient to avoid an if statement within the iEdge loop.
+          if (trim(config_time_integration) == 'unsplit_explicit') then
             split = 0
-         elseif (trim(config_time_integration) == 'split_explicit') then
+          elseif (trim(config_time_integration) == 'split_explicit') then
             split = 1
-         endif
+          endif
 
-         block =&gt; domain % blocklist
-         do while (associated(block))
-           allocate(uTemp(block % mesh % nVertLevels))
+          block =&gt; domain % blocklist
+          do while (associated(block))
+            allocate(uTemp(block % mesh % nVertLevels))
 
-           ! Put f*uBcl^{perp} in uNew as a work variable
-           call ocn_fuperp(block % state % time_levs(2) % state , block % mesh)
+            ! Put f*uBcl^{perp} in uNew as a work variable
+            call ocn_fuperp(block % state % time_levs(2) % state , block % mesh)
 
-           do iEdge=1,block % mesh % nEdges
+            do iEdge=1,block % mesh % nEdges
               cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
               cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
 
               uTemp = 0.0  ! could put this after with uTemp(maxleveledgetop+1:nvertlevels)=0
               do k=1,block % mesh % maxLevelEdgeTop % array(iEdge)
 
-                 ! uBclNew = uBclOld + dt*(-f*uBclPerp + T(u*,w*,p*) + g*grad(SSH*) )
-                 ! Here uNew is a work variable containing -fEdge(iEdge)*uBclPerp(k,iEdge)
-                 uTemp(k) &amp;
-                 = block % state % time_levs(1) % state % uBcl % array(k,iEdge) &amp;
-                 + dt * (block % tend % u % array (k,iEdge) &amp;
-                      + block % state % time_levs(2) % state % u % array (k,iEdge) &amp;  ! this is f*uBcl^{perp}
-                      + split*gravity &amp;
-                        *(  block % state % time_levs(2) % state % ssh % array(cell2) &amp;
-                          - block % state % time_levs(2) % state % ssh % array(cell1) ) &amp;
+                ! uBclNew = uBclOld + dt*(-f*uBclPerp + T(u*,w*,p*) + g*grad(SSH*) )
+                ! Here uNew is a work variable containing -fEdge(iEdge)*uBclPerp(k,iEdge)
+                uTemp(k) = block % state % time_levs(1) % state % uBcl % array(k,iEdge) &amp;
+                         + dt * (block % tend % u % array (k,iEdge) &amp;
+                         + block % state % time_levs(2) % state % u % array (k,iEdge) &amp;  ! this is f*uBcl^{perp}
+                         + split * gravity * (  block % state % time_levs(2) % state % ssh % array(cell2) &amp;
+                         - block % state % time_levs(2) % state % ssh % array(cell1) ) &amp;
                           /block % mesh % dcEdge % array(iEdge) )
               enddo
 
               ! Compute GBtrForcing, the vertically averaged forcing
-              sshEdge = 0.5*( &amp;
-                  block % state % time_levs(1) % state % ssh % array(cell1) &amp; 
-                + block % state % time_levs(1) % state % ssh % array(cell2) ) 
+              sshEdge = 0.5*( block % state % time_levs(1) % state % ssh % array(cell1) &amp; 
+                      + block % state % time_levs(1) % state % ssh % array(cell2) ) 
 
               uhSum = (sshEdge + block % mesh % hZLevel % array(1)) * uTemp(1)
               hSum  =  sshEdge + block % mesh % hZLevel % array(1)
 
               do k=2,block % mesh % maxLevelEdgeTop % array(iEdge)
-                 uhSum = uhSum + block % mesh % hZLevel % array(k) * uTemp(k)
-                 hSum  =  hSum + block % mesh % hZLevel % array(k)
+                uhSum = uhSum + block % mesh % hZLevel % array(k) * uTemp(k)
+                hSum  =  hSum + block % mesh % hZLevel % array(k)
               enddo
               block % state % time_levs(1) % state % GBtrForcing % array(iEdge) = split*uhSum/hSum/dt
 
 
               do k=1,block % mesh % maxLevelEdgeTop % array(iEdge)
-                 ! These two steps are together here:
-                 !{\bf u}'_{k,n+1} = {\bf u}'_{k,n} - \Delta t {\overline {\bf G}}
-                 !{\bf u}'_{k,n+1/2} = \frac{1}{2}\left({\bf u}^{'}_{k,n} +{\bf u}'_{k,n+1}\right) 
-                 ! so that uBclNew is at time n+1/2
-                block % state % time_levs(2) % state % uBcl % array(k,iEdge) &amp;
-                  = 0.5*( &amp;
-                  block % state % time_levs(1) % state % uBcl % array(k,iEdge) &amp;
-                  + uTemp(k) - dt * block % state % time_levs(1) % state % GBtrForcing % array(iEdge))
+                ! These two steps are together here:
+                !{\bf u}'_{k,n+1} = {\bf u}'_{k,n} - \Delta t {\overline {\bf G}}
+                !{\bf u}'_{k,n+1/2} = \frac{1}{2}\left({\bf u}^{'}_{k,n} +{\bf u}'_{k,n+1}\right) 
+                ! so that uBclNew is at time n+1/2
+                block % state % time_levs(2) % state % uBcl % array(k,iEdge) = 0.5*( &amp;
+                    block % state % time_levs(1) % state % uBcl % array(k,iEdge) &amp;
+                    + uTemp(k) - dt * block % state % time_levs(1) % state % GBtrForcing % array(iEdge))
               enddo
 
-           enddo ! iEdge
+            enddo ! iEdge
 
-           deallocate(uTemp)
+            deallocate(uTemp)
 
-           block =&gt; block % next
-         end do
+            block =&gt; block % next
+          end do
 
-        block =&gt; domain % blocklist
-        do while (associated(block))
-           call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % uBcl % array(:,:), &amp;
-                                            block % mesh % nVertLevels, block % mesh % nEdges, &amp;
-                                            block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
+          call mpas_timer_start(&quot;se halo ubcl&quot;, .false., timer_halo_ubcl)
+          block =&gt; domain % blocklist
+          do while (associated(block))
+            call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % uBcl % array(:,:), &amp;
+                block % mesh % nVertLevels, block % mesh % nEdges, &amp;
+                block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
 
-           block =&gt; block % next
-        end do
+            block =&gt; block % next
+          end do
+          call mpas_timer_stop(&quot;se halo ubcl&quot;, timer_halo_ubcl)
 
-      enddo  ! do j=1,config_n_bcl_iter
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      ! END baroclinic iterations on linear Coriolis term
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        enddo  ! do j=1,config_n_bcl_iter
 
+        call mpas_timer_stop(&quot;se bcl vel&quot;, timer_bcl_vel)
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        ! END baroclinic iterations on linear Coriolis term
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      
 
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      !
-      !  Stage 2: Barotropic velocity (2D) prediction, explicitly subcycled
-      !
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !
+        !  Stage 2: Barotropic velocity (2D) prediction, explicitly subcycled
+        !
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-      oldBtrSubcycleTime = 1
-      newBtrSubcycleTime = 2
+        call mpas_timer_start(&quot;se btr vel&quot;, .false., timer_btr_vel)
 
-      if (trim(config_time_integration) == 'unsplit_explicit') then
+        oldBtrSubcycleTime = 1
+        newBtrSubcycleTime = 2
 
-         block =&gt; domain % blocklist
-         do while (associated(block))
+        if (trim(config_time_integration) == 'unsplit_explicit') then
 
+          block =&gt; domain % blocklist
+          do while (associated(block))
+
             ! For Split_Explicit unsplit, simply set uBtrNew=0, uBtrSubcycle=0, and uNew=uBclNew
             block % state % time_levs(2) % state % uBtr % array(:) = 0.0
 
             block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(:) = 0.0
 
-               block % state % time_levs(2) % state % u    % array(:,:) &amp;
-             = block % state % time_levs(2) % state % uBcl % array(:,:) 
+            block % state % time_levs(2) % state % u % array(:,:)  = block % state % time_levs(2) % state % uBcl % array(:,:) 
 
             block =&gt; block % next
-         end do  ! block
+          end do  ! block
 
-      elseif (trim(config_time_integration) == 'split_explicit') then
+        elseif (trim(config_time_integration) == 'split_explicit') then
 
-         ! Initialize variables for barotropic subcycling
-         block =&gt; domain % blocklist
-         do while (associated(block))
+          ! Initialize variables for barotropic subcycling
+          block =&gt; domain % blocklist
+          do while (associated(block))
 
-        if (config_filter_btr_mode) then
-          block % state % time_levs(1) % state % GBtrForcing % array(:) = 0.0
-        endif
+            if (config_filter_btr_mode) then
+              block % state % time_levs(1) % state % GBtrForcing % array(:) = 0.0
+            endif
 
             do iCell=1,block % mesh % nCells
               ! sshSubcycleOld = sshOld  
-                block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
-              = block % state % time_levs(1) % state % ssh % array(iCell)  
+              block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell)  = block % state % time_levs(1) % state % ssh % array(iCell)  
 
               ! sshNew = sshOld  This is the first for the summation
-                block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-              = block % state % time_levs(1) % state % ssh % array(iCell)  
+              block % state % time_levs(2) % state % ssh % array(iCell) = block % state % time_levs(1) % state % ssh % array(iCell)  
             enddo
 
-           do iEdge=1,block % mesh % nEdges
+            do iEdge=1,block % mesh % nEdges
 
               ! uBtrSubcycleOld = uBtrOld 
-                block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-              = block % state % time_levs(1) % state % uBtr % array(iEdge) 
+              block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) = block % state % time_levs(1) % state % uBtr % array(iEdge) 
 
               ! uBtrNew = BtrOld  This is the first for the summation
-                block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
-              = block % state % time_levs(1) % state % uBtr % array(iEdge) 
+              block % state % time_levs(2) % state % uBtr % array(iEdge)  = block % state % time_levs(1) % state % uBtr % array(iEdge) 
 
               ! FBtr = 0  
               block % state % time_levs(1) % state % FBtr % array(iEdge) = 0.0
             enddo
 
             block =&gt; block % next
-         end do  ! block
+          end do  ! block
 
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      ! BEGIN Barotropic subcycle loop
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-         do j=1,config_n_btr_subcycles*config_btr_subcycle_loop_factor
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          ! BEGIN Barotropic subcycle loop
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          do j=1,config_n_btr_subcycles*config_btr_subcycle_loop_factor
 
-            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-            ! Barotropic subcycle: initial solve for velecity
-            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          if (config_btr_gam1_uWt1&gt;1.0e-12) then  ! only do this part if it is needed in next SSH solve
-            uPerpTime = oldBtrSubcycleTime
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          ! Barotropic subcycle: initial solve for velecity
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+            if (config_btr_gam1_uWt1&gt;1.0e-12) then  ! only do this part if it is needed in next SSH solve
+              uPerpTime = oldBtrSubcycleTime
 
-            block =&gt; domain % blocklist
-            do while (associated(block))
+              block =&gt; domain % blocklist
+              do while (associated(block))
 
-         do iEdge=1,block % mesh % nEdges
+                do iEdge=1,block % mesh % nEdges
 
-               cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-               cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
+                  cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
+                  cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
 
-            ! Compute -f*uPerp
-            uPerp = 0.0
-            do i = 1,block % mesh % nEdgesOnEdge % array(iEdge)
-               eoe = block % mesh % edgesOnEdge % array(i,iEdge)
-               uPerp = uPerp + block % mesh % weightsOnEdge % array(i,iEdge) &amp;
-                  * block % state % time_levs(uPerpTime) % state % uBtrSubcycle % array(eoe) &amp;
-                  * block % mesh % fEdge  % array(eoe)
-            end do
+                  ! Compute -f*uPerp
+                  uPerp = 0.0
+                  do i = 1,block % mesh % nEdgesOnEdge % array(iEdge)
+                    eoe = block % mesh % edgesOnEdge % array(i,iEdge)
+                    uPerp = uPerp + block % mesh % weightsOnEdge % array(i,iEdge) &amp;
+                          * block % state % time_levs(uPerpTime) % state % uBtrSubcycle % array(eoe) &amp;
+                          * block % mesh % fEdge  % array(eoe)
+                  end do
+      
+                  ! uBtrNew = uBtrOld + dt*(-f*uBtroldPerp - g*grad(SSH) + G)
+                  block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
+                     = (block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
+                     + dt / config_n_btr_subcycles * (uPerp - gravity &amp;
+                     * (block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) &amp;
+                     - block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) ) &amp;
+                     / block % mesh % dcEdge % array(iEdge) &amp;
+                     + block % state % time_levs(1) % state % GBtrForcing % array(iEdge))) * block % mesh % edgeMask % array(1, iEdge)
+                end do
 
-          ! mrp 110606 efficiency note: could make this a 1D integer factor instead of an if statement.
-          if (block % mesh % boundaryEdge % array(1,iEdge).eq.1) then
-                block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) = 0.0
-          else
+                block =&gt; block % next
+              end do  ! block
 
-             ! uBtrNew = uBtrOld + dt*(-f*uBtroldPerp - g*grad(SSH) + G)
-                block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-              = block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-              + dt/config_n_btr_subcycles *( &amp;
-                        uPerp &amp;
-                      - gravity &amp;
-                        *(  block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) &amp;
-                          - block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) ) &amp;
-                          /block % mesh % dcEdge % array(iEdge) &amp;
-                      + block % state % time_levs(1) % state % GBtrForcing % array(iEdge) )
+              !   boundary update on uBtrNew
+              call mpas_timer_start(&quot;se halo ubtr&quot;, .false., timer_halo_ubtr)
+              block =&gt; domain % blocklist
+              do while (associated(block))
 
-          endif
+                call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
+                    block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(:), &amp;
+                    block % mesh % nEdges, block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
 
-         end do
+                block =&gt; block % next
+              end do  ! block
+              call mpas_timer_stop(&quot;se halo ubtr&quot;, timer_halo_ubtr)
+            endif ! config_btr_gam1_uWt1&gt;1.0e-12
 
-         !  Implicit solve for barotropic momentum decay
-         if ( config_btr_mom_decay) then
-            !
-            !  Add term to RHS of momentum equation: -1/gamma u
-            !
-            !  This changes the solve to:
-            !  u^{n+1} = u_provis^{n+1}/(1+dt/gamma)
-            !
-            coef = 1.0/(1.0 + dt/config_n_btr_subcycles/config_btr_mom_decay_time)
-            do iEdge=1,block % mesh % nEdges
-                block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-              = block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-              * coef
-            end do
 
-          endif
-
-
-               block =&gt; block % next
-            end do  ! block
-
-
-            !   boundary update on uBtrNew
-            block =&gt; domain % blocklist
-            do while (associated(block))
-
-           call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
-              block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(:), &amp;
-              block % mesh % nEdges, &amp;
-              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-
-               block =&gt; block % next
-            end do  ! block
-
-          endif ! config_btr_gam1_uWt1&gt;1.0e-12
-
-
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             ! Barotropic subcycle: Compute thickness flux and new SSH: PREDICTOR
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             block =&gt; domain % blocklist
             do while (associated(block))
-
-           block % tend % ssh % array(:) = 0.0
-
-           if (config_btr_solve_SSH2) then
-             ! If config_btr_solve_SSH2=.true., then do NOT accumulate FBtr in this SSH predictor 
-             ! section, because it will be accumulated in the SSH corrector section.
-             FBtr_coeff = 0.0
-           else
-             ! otherwise, DO accumulate FBtr in this SSH predictor section
-             FBtr_coeff = 1.0
-           endif
-
-           ! config_btr_gam1_uWt1 sets the forward weighting of velocity in the SSH computation
-           ! config_btr_gam1_uWt1=  1     flux = uBtrNew*H
-           ! config_btr_gam1_uWt1=0.5     flux = 1/2*(uBtrNew+uBtrOld)*H
-           ! config_btr_gam1_uWt1=  0     flux = uBtrOld*H
-           do iEdge=1,block % mesh % nEdges
-              cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-              cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
-
-              sshEdge = 0.5 &amp;
-                 *(  block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) &amp;
-                   + block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) )
-              hSum = sum(block % mesh % hZLevel % array (1:block % mesh % maxLevelEdgeTop % array(iEdge)))
-
-              flux = ((1.0-config_btr_gam1_uWt1) &amp; 
-                        * block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-                       + config_btr_gam1_uWt1 &amp;
-                        * block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)) &amp;
-                    * (sshEdge + hSum)
-
-               block % tend % ssh % array(cell1) = block % tend % ssh % array(cell1) &amp;
-                 - flux * block % mesh % dvEdge % array(iEdge) 
-               block % tend % ssh % array(cell2) = block % tend % ssh % array(cell2) &amp;
-                 + flux * block % mesh % dvEdge % array(iEdge) 
-
-               block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-             = block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-             + FBtr_coeff*flux
-         end do

-         ! SSHnew = SSHold + dt/J*(-div(Flux))
-         do iCell=1,block % mesh % nCells 
-
+      
+              block % tend % ssh % array(:) = 0.0
+      
+              if (config_btr_solve_SSH2) then
+                ! If config_btr_solve_SSH2=.true., then do NOT accumulate FBtr in this SSH predictor 
+                ! section, because it will be accumulated in the SSH corrector section.
+                FBtr_coeff = 0.0
+              else
+                ! otherwise, DO accumulate FBtr in this SSH predictor section
+                FBtr_coeff = 1.0
+              endif
+      
+              ! config_btr_gam1_uWt1 sets the forward weighting of velocity in the SSH computation
+              ! config_btr_gam1_uWt1=  1     flux = uBtrNew*H
+              ! config_btr_gam1_uWt1=0.5     flux = 1/2*(uBtrNew+uBtrOld)*H
+              ! config_btr_gam1_uWt1=  0     flux = uBtrOld*H
+              do iEdge=1,block % mesh % nEdges
+                cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
+                cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
+      
+                sshEdge = 0.5 * (block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) &amp;
+                        + block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) )
+                hSum = sum(block % mesh % hZLevel % array (1:block % mesh % maxLevelEdgeTop % array(iEdge)))
+      
+                flux = ((1.0-config_btr_gam1_uWt1) * block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
+                     + config_btr_gam1_uWt1 * block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)) * (sshEdge + hSum)
+      
+                block % tend % ssh % array(cell1) = block % tend % ssh % array(cell1) - flux * block % mesh % dvEdge % array(iEdge)
+                block % tend % ssh % array(cell2) = block % tend % ssh % array(cell2) + flux * block % mesh % dvEdge % array(iEdge) 
+      
+                block % state % time_levs(1) % state % FBtr % array(iEdge) = block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
+                  + FBtr_coeff*flux
+              end do
+      
+              ! SSHnew = SSHold + dt/J*(-div(Flux))
+              do iCell=1,block % mesh % nCells 
+      
                 block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
-              = block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
-              + dt/config_n_btr_subcycles &amp;
-                * block % tend % ssh % array(iCell) / block % mesh % areaCell % array (iCell)
-
-         end do
-
-               block =&gt; block % next
+                    = block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
+                    + dt/config_n_btr_subcycles * block % tend % ssh % array(iCell) / block % mesh % areaCell % array (iCell)
+      
+              end do
+      
+              block =&gt; block % next
             end do  ! block
-
+      
             !   boundary update on SSHnew
+            call mpas_timer_start(&quot;se halo ssh&quot;, .false., timer_halo_ssh)
             block =&gt; domain % blocklist
             do while (associated(block))
-
-!              block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(:), &amp;
-
-           call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
-              block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(:), &amp;
-              block % mesh % nCells, &amp;
-              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-
-               block =&gt; block % next
+              ! block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(:), &amp;
+      
+              call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
+                  block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(:), &amp;
+                  block % mesh % nCells, block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
+      
+              block =&gt; block % next
             end do  ! block
-
-
-! mrp 110801 begin
-! This whole section, bounded by 'mrp 110801', may be deleted later if it is found
-! that barotropic del2 is not useful.
+            call mpas_timer_stop(&quot;se halo ssh&quot;, timer_halo_ssh)
+      
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-            ! Barotropic subcycle: compute btr_divergence and btr_vorticity for del2(u_btr) 
-            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-            block =&gt; domain % blocklist
-            do while (associated(block))
-      block % state % time_levs(1) % state % u_diffusionBtr % array(:) = 0.0
-      if ( config_btr_mom_eddy_visc2 &gt; 0.0 ) then
-      !
-      ! Compute circulation and relative vorticity at each vertex
-      !
-      block % state % time_levs(1) % state % circulationBtr % array(:) = 0.0
-      do iEdge=1,block % mesh % nEdges
-         vertex1 = block % mesh % verticesOnEdge % array(1,iEdge)
-         vertex2 = block % mesh % verticesOnEdge % array(2,iEdge)
-             block % state % time_levs(1) % state % circulationBtr % array(vertex1) &amp;
-           = block % state % time_levs(1) % state % circulationBtr % array(vertex1) &amp;
-           - block % mesh % dcEdge % array (iEdge) &amp;
-            *block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)
-
-             block % state % time_levs(1) % state % circulationBtr % array(vertex2) &amp;
-           = block % state % time_levs(1) % state % circulationBtr % array(vertex2) &amp;
-           + block % mesh % dcEdge % array (iEdge) &amp;
-            *block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)
-      end do 
-      do iVertex=1,block % mesh % nVertices
-            block % state % time_levs(1) % state % vorticityBtr % array(iVertex) &amp;
-          = block % state % time_levs(1) % state % circulationBtr % array(iVertex) / block % mesh % areaTriangle % array (iVertex)
-      end do
-
-      !
-      ! Compute the divergence at each cell center
-      !
-      block % state % time_levs(1) % state % divergenceBtr % array(:) = 0.0
-      do iEdge=1,block % mesh % nEdges
-         cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-         cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
-             block % state % time_levs(1) % state % divergenceBtr % array (cell1) &amp;
-           = block % state % time_levs(1) % state % divergenceBtr % array (cell1) &amp;
-           + block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-            *block % mesh % dvEdge % array(iEdge)
-
-             block % state % time_levs(1) % state % divergenceBtr % array (cell2) &amp;
-           = block % state % time_levs(1) % state % divergenceBtr % array (cell2) &amp;
-           - block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-            *block % mesh % dvEdge % array(iEdge)
-      end do
-      do iCell = 1,block % mesh % nCells
-         block % state % time_levs(1) % state % divergenceBtr % array(iCell) &amp;
-       = block % state % time_levs(1) % state % divergenceBtr % array(iCell) &amp;
-        /block % mesh % areaCell % array(iCell)
-      enddo
-
-      !
-      ! Compute Btr diffusion
-      !
-         do iEdge=1,block % mesh % nEdgesSolve
-            cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-            cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
-            vertex1 = block % mesh % verticesOnEdge % array(1,iEdge)
-            vertex2 = block % mesh % verticesOnEdge % array(2,iEdge)
-
-               ! Here -( vorticityBtr(vertex2) - vorticityBtr(vertex1) ) / dvEdge % array (iEdge)
-               ! is - </font>
<font color="red">abla vorticity pointing from vertex 2 to vertex 1, or equivalently 
-               !    + k \times </font>
<font color="gray">abla vorticity pointing from cell1 to cell2.
-
-               block % state % time_levs(1) % state % u_diffusionBtr % array(iEdge) = block % mesh % meshScalingDel2 % array (iEdge) * config_btr_mom_eddy_visc2 * &amp;
-                   (( block % state % time_levs(1) % state % divergenceBtr % array(cell2)  - block % state % time_levs(1) % state % divergenceBtr % array(cell1) ) / block % mesh % dcEdge % array (iEdge)  &amp;
-                  -( block % state % time_levs(1) % state % vorticityBtr % array(vertex2) - block % state % time_levs(1) % state % vorticityBtr % array(vertex1) ) / block % mesh % dvEdge % array (iEdge))
-
-         end do
-      end if
-               block =&gt; block % next
-            end do  ! block
-! mrp 110801 end
-
-
-            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             ! Barotropic subcycle: Final solve for velocity.  Iterate for Coriolis term.
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-       do BtrCorIter=1,config_n_btr_cor_iter
-
-          uPerpTime = newBtrSubcycleTime
-
-          block =&gt; domain % blocklist
-          do while (associated(block))
-
-         do iEdge=1,block % mesh % nEdges 
-
-               cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-               cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
-
-            ! Compute -f*uPerp
-            uPerp = 0.0
-            do i = 1,block % mesh % nEdgesOnEdge % array(iEdge)
-               eoe = block % mesh % edgesOnEdge % array(i,iEdge)
-               uPerp = uPerp + block % mesh % weightsOnEdge % array(i,iEdge) &amp;
-                  * block % state % time_levs(uPerpTime) % state % uBtrSubcycle % array(eoe) &amp;
-                  * block % mesh % fEdge  % array(eoe) 
-            end do
-
-          ! mrp 110606 efficiency note: could make this a 1D integer factor instead of an if statement.
-          if (block % mesh % boundaryEdge % array(1,iEdge).eq.1) then
-                block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) = 0.0
-          else
-
-             ! uBtrNew = uBtrOld + dt*(-f*uBtroldPerp - g*grad(SSH) + G)
-
-             sshCell1 = &amp;
-               (1-config_btr_gam2_SSHWt1)*block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) &amp;
-                + config_btr_gam2_SSHWt1 *block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(cell1)
-
-             sshCell2 = &amp;
-               (1-config_btr_gam2_SSHWt1)*block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) &amp;
-                + config_btr_gam2_SSHWt1 *block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(cell2)
-
-                block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp; 
-              = block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp; 
-              + dt/config_n_btr_subcycles *( &amp;
-                        uPerp &amp;
-                      - gravity &amp;
-                        *(  sshCell2 &amp;
-                          - sshCell1 )&amp;
-                          /block % mesh % dcEdge % array(iEdge) &amp;
+            do BtrCorIter=1,config_n_btr_cor_iter
+              uPerpTime = newBtrSubcycleTime
+      
+              block =&gt; domain % blocklist
+              do while (associated(block))
+                do iEdge=1,block % mesh % nEdges 
+                  cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
+                  cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
+      
+                  ! Compute -f*uPerp
+                  uPerp = 0.0
+                  do i = 1,block % mesh % nEdgesOnEdge % array(iEdge)
+                    eoe = block % mesh % edgesOnEdge % array(i,iEdge)
+                    uPerp = uPerp + block % mesh % weightsOnEdge % array(i,iEdge) &amp;
+                          * block % state % time_levs(uPerpTime) % state % uBtrSubcycle % array(eoe) &amp;
+                          * block % mesh % fEdge  % array(eoe) 
+                  end do
+      
+                  sshCell1 = (1-config_btr_gam2_SSHWt1)*block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) &amp;
+                           +    config_btr_gam2_SSHWt1 *block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(cell1)
+    
+                  sshCell2 = (1-config_btr_gam2_SSHWt1)*block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) &amp;
+                           +    config_btr_gam2_SSHWt1 *block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(cell2)
+    
+                  block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp; 
+                      = (block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp; 
+                      + dt/config_n_btr_subcycles *(uPerp - gravity *(sshCell2 - sshCell1) /block % mesh % dcEdge % array(iEdge) &amp;
                       + block % state % time_levs(1) % state % GBtrForcing % array(iEdge) &amp;
-                      + block % state % time_levs(1) % state % u_diffusionBtr % array(iEdge))
-                      ! added del2 diffusion to btr solve
-
-          endif
-
-         end do
-
-            !  Implicit solve for barotropic momentum decay
-         if ( config_btr_mom_decay) then
-            !  Add term to RHS of momentum equation: -1/gamma u
-            !
-            !  This changes the solve to:
-            !  u^{n+1} = u_provis^{n+1}/(1+dt/gamma)
-            !
-            coef = 1.0/(1.0 + dt/config_n_btr_subcycles/config_btr_mom_decay_time)
-            do iEdge=1,block % mesh % nEdges 
-                block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp; 
-              = block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-              * coef
-            end do
-
-         endif
-
-               block =&gt; block % next
-            end do  ! block
-
-
-            !   boundary update on uBtrNew
-            block =&gt; domain % blocklist
-            do while (associated(block))
-
-               call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
-                  block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(:), &amp;
-                  block % mesh % nEdges, &amp;
-                  block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-
-               block =&gt; block % next
-            end do  ! block
-
-       end do !do BtrCorIter=1,config_n_btr_cor_iter
-
+                      + block % state % time_levs(1) % state % u_diffusionBtr % array(iEdge))) * block % mesh % edgeMask % array(1,iEdge)
+                end do
+      
+                block =&gt; block % next
+              end do  ! block
+      
+      
+              !   boundary update on uBtrNew
+              call mpas_timer_start(&quot;se halo ubtr&quot;, .false., timer_halo_ubtr)
+              block =&gt; domain % blocklist
+              do while (associated(block))
+                call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
+                    block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(:), &amp;
+                    block % mesh % nEdges, block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
+      
+                block =&gt; block % next
+              end do  ! block
+              call mpas_timer_stop(&quot;se halo ubtr&quot;, timer_halo_ubtr)
+            end do !do BtrCorIter=1,config_n_btr_cor_iter
+      
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             ! Barotropic subcycle: Compute thickness flux and new SSH: CORRECTOR
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-        if (config_btr_solve_SSH2) then
-
-            block =&gt; domain % blocklist
-            do while (associated(block))
-
-           block % tend % ssh % array(:) = 0.0
-
-           ! config_btr_gam3_uWt2 sets the forward weighting of velocity in the SSH computation
-           ! config_btr_gam3_uWt2=  1     flux = uBtrNew*H
-           ! config_btr_gam3_uWt2=0.5     flux = 1/2*(uBtrNew+uBtrOld)*H
-           ! config_btr_gam3_uWt2=  0     flux = uBtrOld*H
-
-           do iEdge=1,block % mesh % nEdges
-              cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-              cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
-
-              sshEdge = 0.5 &amp;
-                 *(  block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) &amp;
-                   + block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2) )
-              hSum = sum(block % mesh % hZLevel % array (1:block % mesh % maxLevelEdgeTop % array(iEdge)))
-
-              flux = ((1.0-config_btr_gam3_uWt2) &amp; 
-                        * block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
-                       + config_btr_gam3_uWt2 &amp;
-                        * block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)) &amp;
-                    * (sshEdge + hSum)
-
-               block % tend % ssh % array(cell1) = block % tend % ssh % array(cell1) &amp;
-                 - flux * block % mesh % dvEdge % array(iEdge) 
-               block % tend % ssh % array(cell2) = block % tend % ssh % array(cell2) &amp;
-                 + flux * block % mesh % dvEdge % array(iEdge) 
-
-               block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-             = block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-             + flux
-
-
-         end do

-         ! SSHnew = SSHold + dt/J*(-div(Flux))
-         do iCell=1,block % mesh % nCells 
-
-                block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
-              = block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
-              + dt/config_n_btr_subcycles &amp;
-                * block % tend % ssh % array(iCell) / block % mesh % areaCell % array (iCell)
-
-         end do
-
-               block =&gt; block % next
-            end do  ! block
-
-            !   boundary update on SSHnew
-            block =&gt; domain % blocklist
-            do while (associated(block))
-
-           call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
-              block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(:), &amp;
-              block % mesh % nCells, &amp;
-              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-
-               block =&gt; block % next
-            end do  ! block
-
-        endif ! config_btr_solve_SSH2
-
+            if (config_btr_solve_SSH2) then
+      
+              block =&gt; domain % blocklist
+              do while (associated(block))
+                block % tend % ssh % array(:) = 0.0
+      
+                ! config_btr_gam3_uWt2 sets the forward weighting of velocity in the SSH computation
+                ! config_btr_gam3_uWt2=  1     flux = uBtrNew*H
+                ! config_btr_gam3_uWt2=0.5     flux = 1/2*(uBtrNew+uBtrOld)*H
+                ! config_btr_gam3_uWt2=  0     flux = uBtrOld*H
+      
+                do iEdge=1,block % mesh % nEdges
+                  cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
+                  cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
+      
+                  sshEdge = 0.5 * (block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell1) &amp;
+                          + block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(cell2))
+                  hSum = sum(block % mesh % hZLevel % array (1:block % mesh % maxLevelEdgeTop % array(iEdge)))
+      
+                  flux = ((1.0-config_btr_gam3_uWt2) * block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge) &amp;
+                       + config_btr_gam3_uWt2 * block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)) &amp;
+                       * (sshEdge + hSum)
+      
+                  block % tend % ssh % array(cell1) = block % tend % ssh % array(cell1) - flux * block % mesh % dvEdge % array(iEdge) 
+                  block % tend % ssh % array(cell2) = block % tend % ssh % array(cell2) + flux * block % mesh % dvEdge % array(iEdge) 
+      
+                  block % state % time_levs(1) % state % FBtr % array(iEdge) = block % state % time_levs(1) % state % FBtr % array(iEdge) + flux
+                end do
+      
+                ! SSHnew = SSHold + dt/J*(-div(Flux))
+                do iCell=1,block % mesh % nCells 
+                  block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
+                      = block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp; 
+                      + dt/config_n_btr_subcycles * block % tend % ssh % array(iCell) / block % mesh % areaCell % array (iCell)
+                end do
+      
+                block =&gt; block % next
+              end do  ! block
+      
+              !   boundary update on SSHnew
+              call mpas_timer_start(&quot;se halo ssh&quot;, .false., timer_halo_ssh)
+              block =&gt; domain % blocklist
+              do while (associated(block))
+                call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
+                    block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(:), &amp;
+                    block % mesh % nCells, block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
+      
+                block =&gt; block % next
+              end do  ! block
+              call mpas_timer_stop(&quot;se halo ssh&quot;, timer_halo_ssh)
+            endif ! config_btr_solve_SSH2
+      
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             ! Barotropic subcycle: Accumulate running sums, advance timestep pointers
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+      
             block =&gt; domain % blocklist
             do while (associated(block))
-
-         ! Accumulate SSH in running sum over the subcycles.
-         do iCell=1,block % mesh % nCells 
-                block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-              = block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-              + block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(iCell)  
-         end do
-
-            ! uBtrNew = uBtrNew + uBtrSubcycleNEW
-            ! This accumulates the sum.
-            ! If the Barotropic Coriolis iteration is limited to one, this could 
-            ! be merged with the above code.
-         do iEdge=1,block % mesh % nEdges 
-
-                block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
-              = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
-              + block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)  
-
-            end do  ! iEdge
-               block =&gt; block % next
-         end do  ! block
-
+      
+              ! Accumulate SSH in running sum over the subcycles.
+              do iCell=1,block % mesh % nCells 
+                block % state % time_levs(2) % state % ssh % array(iCell) = block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
+                    + block % state % time_levs(newBtrSubcycleTime) % state % sshSubcycle % array(iCell)  
+              end do
+      
+              ! uBtrNew = uBtrNew + uBtrSubcycleNEW
+              ! This accumulates the sum.
+              ! If the Barotropic Coriolis iteration is limited to one, this could 
+              ! be merged with the above code.
+              do iEdge=1,block % mesh % nEdges 
+      
+                block % state % time_levs(2) % state % uBtr % array(iEdge) = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
+                    + block % state % time_levs(newBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)  
+      
+              end do  ! iEdge
+              block =&gt; block % next
+            end do  ! block
+      
             ! advance time pointers
             oldBtrSubcycleTime = mod(oldBtrSubcycleTime,2)+1
             newBtrSubcycleTime = mod(newBtrSubcycleTime,2)+1
+      
+          end do ! j=1,config_n_btr_subcycles
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          ! END Barotropic subcycle loop
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      
 
-         end do ! j=1,config_n_btr_subcycles
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      ! END Barotropic subcycle loop
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        ! Normalize Barotropic subcycle sums: ssh, uBtr, and F
+          block =&gt; domain % blocklist
+          do while (associated(block))
+      
+            do iEdge=1,block % mesh % nEdges
+              block % state % time_levs(1) % state % FBtr % array(iEdge) = block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
+                  / (config_n_btr_subcycles*config_btr_subcycle_loop_factor)
+      
+              block % state % time_levs(2) % state % uBtr % array(iEdge) = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
+                  / (config_n_btr_subcycles*config_btr_subcycle_loop_factor + 1)
+            end do
+      
+            if (config_SSH_from=='avg_of_SSH_subcycles') then
+              do iCell=1,block % mesh % nCells 
+                block % state % time_levs(2) % state % ssh % array(iCell) = block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
+                    / (config_n_btr_subcycles*config_btr_subcycle_loop_factor + 1)
+              end do
+            elseif (config_SSH_from=='avg_flux') then
+              ! see below
+            else
+              write(0,*) 'Abort: Unknown config_SSH_from option: ' //trim(config_SSH_from)
+              call mpas_dmpar_abort(dminfo)
+            endif
+      
+            block =&gt; block % next
+          end do  ! block
+      
+      
+          ! boundary update on F
+          call mpas_timer_start(&quot;se halo F&quot;, .false., timer_halo_f)
+          block =&gt; domain % blocklist
+          do while (associated(block))
+            call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
+                block % state % time_levs(1) % state % FBtr % array(:), &amp;
+                block % mesh % nEdges, block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
+      
+            block =&gt; block % next
+          end do  ! block
+          call mpas_timer_stop(&quot;se halo F&quot;, timer_halo_f)
 
 
-            ! Normalize Barotropic subcycle sums: ssh, uBtr, and F
-            block =&gt; domain % blocklist
-            do while (associated(block))
+          ! Check that you can compute SSH using the total sum or the individual increments
+          ! over the barotropic subcycles.
+          ! efficiency: This next block of code is really a check for debugging, and can 
+          ! be removed later.
+          block =&gt; domain % blocklist
+          do while (associated(block))
 
-         do iEdge=1,block % mesh % nEdges
-               block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-             = block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-             / (config_n_btr_subcycles*config_btr_subcycle_loop_factor)
+            allocate(uTemp(block % mesh % nVertLevels))
 
-                block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
-              = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
-             / (config_n_btr_subcycles*config_btr_subcycle_loop_factor + 1)
-         end do
+            if (config_SSH_from=='avg_flux') then
+              ! Accumulate fluxes in the tend % ssh variable
+              block % tend % ssh % array(:) = 0.0
+              do iEdge=1,block % mesh % nEdges
+                cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
+                cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
 
-        if (config_SSH_from=='avg_of_SSH_subcycles') then
-         do iCell=1,block % mesh % nCells 
-                block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-              = block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-             / (config_n_btr_subcycles*config_btr_subcycle_loop_factor + 1)
-         end do
-        elseif (config_SSH_from=='avg_flux') then
-           ! see below
-        else
-         write(0,*) 'Abort: Unknown config_SSH_from option: '&amp;
-           //trim(config_SSH_from)
-         call mpas_dmpar_abort(dminfo)
-        endif
-
-               block =&gt; block % next
-            end do  ! block
-
-
-            ! boundary update on F
-            block =&gt; domain % blocklist
-            do while (associated(block))
-
-           call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, &amp;
-              block % state % time_levs(1) % state % FBtr % array(:), &amp;
-              block % mesh % nEdges, &amp;
-              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-
-               block =&gt; block % next
-            end do  ! block
-
-
-            ! Check that you can compute SSH using the total sum or the individual increments
-            ! over the barotropic subcycles.
-            ! efficiency: This next block of code is really a check for debugging, and can 
-            ! be removed later.
-            block =&gt; domain % blocklist
-            do while (associated(block))
-
-               allocate(uTemp(block % mesh % nVertLevels))
-
-        if (config_SSH_from=='avg_flux') then
-           ! Accumulate fluxes in the tend % ssh variable
-           block % tend % ssh % array(:) = 0.0
-           do iEdge=1,block % mesh % nEdges
-              cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
-              cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
-
-                 block % tend % ssh % array(cell1) &amp;
-               = block % tend % ssh % array(cell1) &amp;
-               - block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
+                block % tend % ssh % array(cell1) = block % tend % ssh % array(cell1) &amp;
+                    - block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
                     * block % mesh % dvEdge % array(iEdge)
 
 
-                 block % tend % ssh % array(cell2) &amp;
-               = block % tend % ssh % array(cell2) &amp;
-               + block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
+                block % tend % ssh % array(cell2) = block % tend % ssh % array(cell2) &amp;
+                    + block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
                     * block % mesh % dvEdge % array(iEdge)
 
-          end do
+              end do
 
-         do iCell=1,block % mesh % nCells 

-             ! SSHnew = SSHold + dt*(-div(Flux))
-                block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-              = block % state % time_levs(1) % state % ssh % array(iCell) &amp; 
-              + dt &amp;
-                * block % tend % ssh % array(iCell) / block % mesh % areaCell % array (iCell)
-         end do
-       endif
+              do iCell=1,block % mesh % nCells 
 
-         ! Correction velocity    uCorr = (Flux - Sum(h u*))/H
-         ! or, for the full latex version:
-         !u^{corr} = \left( {\overline {\bf F}} 
-         !  - \sum_{k=1}^{N^{edge}} \left(\zeta_{k,n}^{*\;edge}+\Delta z_k\right)  u_k^* \right)
-         !\left/ \sum_{k=1}^{N^{edge}} \left(\zeta_{k,n}^{*\;edge}+\Delta z_k\right)   \right. 
+                ! SSHnew = SSHold + dt*(-div(Flux))
+                block % state % time_levs(2) % state % ssh % array(iCell) = block % state % time_levs(1) % state % ssh % array(iCell) &amp; 
+                    + dt * block % tend % ssh % array(iCell) / block % mesh % areaCell % array (iCell)
+              end do
+            endif
 
-          if (config_u_correction) then
-             ucorr_coef = 1
-          else
-             ucorr_coef = 0
-          endif
+            ! Correction velocity    uCorr = (Flux - Sum(h u*))/H
+            ! or, for the full latex version:
+            !u^{corr} = \left( {\overline {\bf F}} 
+            !  - \sum_{k=1}^{N^{edge}} \left(\zeta_{k,n}^{*\;edge}+\Delta z_k\right)  u_k^* \right)
+            !\left/ \sum_{k=1}^{N^{edge}} \left(\zeta_{k,n}^{*\;edge}+\Delta z_k\right)   \right. 
 
-           do iEdge=1,block % mesh % nEdges
+            if (config_u_correction) then
+              ucorr_coef = 1
+            else
+              ucorr_coef = 0
+            endif
+
+            do iEdge=1,block % mesh % nEdges
               cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
               cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
 
-              sshEdge = 0.5 &amp;
-                 *(  block % state % time_levs(2) % state % ssh % array(cell1) &amp;
-                   + block % state % time_levs(2) % state % ssh % array(cell2) )
+              sshEdge = 0.5 * (block % state % time_levs(2) % state % ssh % array(cell1) &amp;
+                  + block % state % time_levs(2) % state % ssh % array(cell2))
 
-             ! This is u*
-               uTemp(:) &amp;
-             = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
-             + block % state % time_levs(2) % state % uBcl % array(:,iEdge) 
+              ! This is u*
+              uTemp(:) = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
+                  + block % state % time_levs(2) % state % uBcl % array(:,iEdge) 
 
               uhSum = (sshEdge + block % mesh % hZLevel % array(1)) * uTemp(1)
               hSum  =  sshEdge + block % mesh % hZLevel % array(1)
 
               do k=2,block % mesh % maxLevelEdgeTop % array(iEdge)
-                 uhSum = uhSum + block % mesh % hZLevel % array(k) * uTemp(k)
-                 hSum  =  hSum + block % mesh % hZLevel % array(k)
+                uhSum = uhSum + block % mesh % hZLevel % array(k) * uTemp(k)
+                hSum  =  hSum + block % mesh % hZLevel % array(k)
               enddo
 
-            uCorr =   ucorr_coef*(( block % state % time_levs(1) % state % FBtr % array(iEdge) &amp;
-                      - uhSum)/hSum)
+              uCorr =   ucorr_coef*(( block % state % time_levs(1) % state % FBtr % array(iEdge) - uhSum)/hSum)
 
               ! put u^{tr}, the velocity for tracer transport, in uNew
-          ! mrp 060611 not sure if boundary enforcement is needed here.  
-          if (block % mesh % boundaryEdge % array(1,iEdge).eq.1) then
-              block % state % time_levs(2) % state % u % array(:,iEdge) = 0.0
-          else
-            do k=1,block % mesh % maxLevelEdgeTop % array(iEdge)
-              block % state % time_levs(2) % state % u % array(k,iEdge) = uTemp(k) + uCorr
-            enddo
-            do k=block % mesh % maxLevelEdgeTop % array(iEdge)+1,block % mesh % nVertLevels
-              block % state % time_levs(2) % state % u % array(k,iEdge) = 0.0
-            enddo
-          endif
+              ! mrp 060611 not sure if boundary enforcement is needed here.  
+              if (block % mesh % boundaryEdge % array(1,iEdge).eq.1) then
+                block % state % time_levs(2) % state % u % array(:,iEdge) = 0.0
+              else
+                do k=1,block % mesh % maxLevelEdgeTop % array(iEdge)
+                  block % state % time_levs(2) % state % u % array(k,iEdge) = uTemp(k) + uCorr
+                enddo
+                do k=block % mesh % maxLevelEdgeTop % array(iEdge)+1,block % mesh % nVertLevels
+                  block % state % time_levs(2) % state % u % array(k,iEdge) = 0.0
+                enddo
+              endif
 
-         ! Put new sshEdge values in h_edge array, for the OcnTendScalar call below.
-             block % state % time_levs(2) % state % h_edge % array(1,iEdge) &amp;
-           = sshEdge + block % mesh % hZLevel % array(1)
+              ! Put new sshEdge values in h_edge array, for the OcnTendScalar call below.
+              block % state % time_levs(2) % state % h_edge % array(1,iEdge) = sshEdge + block % mesh % hZLevel % array(1)
 
-           do k=2,block % mesh % nVertLevels
-             block % state % time_levs(2) % state % h_edge % array(k,iEdge) &amp;
-           = block % mesh % hZLevel % array(k)
-           enddo
+              do k=2,block % mesh % nVertLevels
+                block % state % time_levs(2) % state % h_edge % array(k,iEdge) = block % mesh % hZLevel % array(k)
+              enddo
+            end do ! iEdge
 
-          end do ! iEdge
+            ! Put new SSH values in h array, for the OcnTendScalar call below.
+            do iCell=1,block % mesh % nCells 
+              block % state % time_levs(2) % state % h % array(1,iCell) = block % state % time_levs(2) % state % ssh % array(iCell) &amp;
+                  + block % mesh % hZLevel % array(1)
 
-         ! Put new SSH values in h array, for the OcnTendScalar call below.
-         do iCell=1,block % mesh % nCells 
-             block % state % time_levs(2) % state % h % array(1,iCell) &amp;
-           = block % state % time_levs(2) % state % ssh % array(iCell) &amp;
-           + block % mesh % hZLevel % array(1)
+              ! mrp 110601 efficiency note: Since h just moves back and forth between pointers,
+              ! this is not necessary once initialized.
+              do k=2,block % mesh % nVertLevels * sshSwapFlag
+                block % state % time_levs(2) % state % h % array(k,iCell)  = block % mesh % hZLevel % array(k)
+              enddo
+            enddo ! iCell
 
-           ! mrp 110601 efficiency note: Since h just moves back and forth between pointers,
-           ! this is not necessary once initialized.
-           do k=2,block % mesh % nVertLevels
-             block % state % time_levs(2) % state % h % array(k,iCell) &amp;
-           = block % mesh % hZLevel % array(k)
-           enddo
-         enddo ! iCell
+            deallocate(uTemp)
 
-           deallocate(uTemp)
+            block =&gt; block % next
+          end do  ! block
+          sshSwapFlag = 0
+        endif ! split_explicit
+        call mpas_timer_stop(&quot;se btr vel&quot;, timer_btr_vel)
 
-               block =&gt; block % next
-            end do  ! block
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !
+        !  Stage 3: Tracer, density, pressure, vertical velocity prediction
+        !
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+        block =&gt; domain % blocklist
+        do while (associated(block))
+          call ocn_wtop(block % state % time_levs(2) % state, block % mesh)
 
-      endif ! split_explicit
+          if (trim(config_time_integration) == 'unsplit_explicit') then
+            call ocn_tend_h(block % tend, block % state % time_levs(2) % state , block % diagnostics, block % mesh)
+          endif
 
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      !
-      !  Stage 3: Tracer, density, pressure, vertical velocity prediction
-      !
-      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          call ocn_tend_scalar(block % tend, block % state % time_levs(2) % state , block % diagnostics, block % mesh)
 
-         block =&gt; domain % blocklist
-         do while (associated(block))
+          block =&gt; block % next
+        end do
 
-           call ocn_wtop(block % state % time_levs(2) % state, block % mesh)
-
-      if (trim(config_time_integration) == 'unsplit_explicit') then
-           call ocn_tend_h(block % tend, block % state % time_levs(2) % state , block % diagnostics, block % mesh)
-      endif
-
-           call ocn_tend_scalar(block % tend, block % state % time_levs(2) % state , block % diagnostics, block % mesh)
-
-           block =&gt; block % next
-         end do
-
         ! update halo for thicknes for unsplit only
         if (trim(config_time_integration) == 'unsplit_explicit') then
-           block =&gt; domain % blocklist
-           do while (associated(block))
-              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % tend % h % array(:,:), &amp;
-                                               block % mesh % nVertLevels, block % mesh % nCells, &amp;
-                                               block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              block =&gt; block % next
-           end do
+          call mpas_timer_start(&quot;se halo h&quot;, .false., timer_halo_h)
+          block =&gt; domain % blocklist
+          do while (associated(block))
+            call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % tend % h % array(:,:), &amp;
+                block % mesh % nVertLevels, block % mesh % nCells, block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
+            block =&gt; block % next
+          end do
+          call mpas_timer_stop(&quot;se halo h&quot;, timer_halo_h)
         endif ! unsplit_explicit
 
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           allocate(hNew(block % mesh % nVertLevels))
+          allocate(hNew(block % mesh % nVertLevels))
 
-        if (trim(config_new_btr_variables_from) == 'last_subcycle') then
-           ! This points to the last barotropic SSH subcycle
-           sshNew =&gt; block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array
-        elseif (trim(config_new_btr_variables_from) == 'btr_avg') then
-           ! This points to the tendency variable SSH*
-           sshNew =&gt; block % state % time_levs(2) % state % ssh % array
-        endif
+          if (trim(config_new_btr_variables_from) == 'last_subcycle') then
+            ! This points to the last barotropic SSH subcycle
+            sshNew =&gt; block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array
+          elseif (trim(config_new_btr_variables_from) == 'btr_avg') then
+            ! This points to the tendency variable SSH*
+            sshNew =&gt; block % state % time_levs(2) % state % ssh % array
+          endif
 
-      if (trim(config_time_integration) == 'unsplit_explicit') then
+          if (trim(config_time_integration) == 'unsplit_explicit') then
 
-         do iCell=1,block % mesh % nCells
-           ! this is h_{n+1}
-             block % state % time_levs(2) % state % h % array(:,iCell) &amp;
-           = block % state % time_levs(1) % state % h % array(:,iCell) &amp;
-           + dt* block % tend % h % array(:,iCell) 
+            do iCell=1,block % mesh % nCells
+              ! this is h_{n+1}
+              block % state % time_levs(2) % state % h % array(:,iCell) &amp;
+                  = block % state % time_levs(1) % state % h % array(:,iCell) &amp;
+                  + dt* block % tend % h % array(:,iCell) 
 
-            ! this is only for the hNew computation below, so there is the correct
-            ! value in the ssh variable for unsplit_explicit case.
-            block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp;
-          = block % state % time_levs(2) % state % h % array(1,iCell) &amp;
-          - block % mesh % hZLevel % array(1)
-           end do ! iCell
+              ! this is only for the hNew computation below, so there is the correct
+              ! value in the ssh variable for unsplit_explicit case.
+              block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) &amp;
+                  = block % state % time_levs(2) % state % h % array(1,iCell) &amp;
+                  - block % mesh % hZLevel % array(1)
+            end do ! iCell
+          endif ! unsplit_explicit
 
-      endif ! unsplit_explicit
-
-           ! Only need T &amp; S for earlier iterations,
-           ! then all the tracers needed the last time through.
-         if (split_explicit_step &lt; config_n_ts_iter) then
-
-           hNew(:) = block % mesh % hZLevel % array(:)
-           do iCell=1,block % mesh % nCells
+          ! Only need T &amp; S for earlier iterations,
+          ! then all the tracers needed the last time through.
+          if (split_explicit_step &lt; config_n_ts_iter) then
+            hNew(:) = block % mesh % hZLevel % array(:)
+            do iCell=1,block % mesh % nCells
               ! sshNew is a pointer, defined above.
               hNew(1) =  sshNew(iCell) + block % mesh % hZLevel % array(1)
               do k=1,block % mesh % maxLevelCell % array(iCell)
-                 do i=1,2
-                ! This is Phi at n+1
-                tracerTemp &amp;
-                = (  block % state % time_levs(1) % state % tracers % array(i,k,iCell) &amp;
-                   * block % state % time_levs(1) % state % h % array(k,iCell) &amp;
-                 + dt * block % tend % tracers % array(i,k,iCell) &amp;
-                  ) / hNew(k)
+                do i=1,2
+                  ! This is Phi at n+1
+                  tracerTemp = (  block % state % time_levs(1) % state % tracers % array(i,k,iCell) &amp;
+                      * block % state % time_levs(1) % state % h % array(k,iCell) &amp;
+                      + dt * block % tend % tracers % array(i,k,iCell)) / hNew(k)
 
-                ! This is Phi at n+1/2
-                   block % state % time_levs(2) % state % tracers % array(i,k,iCell)  &amp;
-                 = 0.5*( &amp;
-                   block % state % time_levs(1) % state % tracers % array(i,k,iCell) &amp;
-                 + tracerTemp )
-                 enddo
+                  ! This is Phi at n+1/2
+                  block % state % time_levs(2) % state % tracers % array(i,k,iCell) = 0.5*( &amp;
+                      block % state % time_levs(1) % state % tracers % array(i,k,iCell) + tracerTemp )
+                enddo
               end do
-           end do ! iCell
+            end do ! iCell
 
 
-          if (trim(config_time_integration) == 'unsplit_explicit') then
+            if (trim(config_time_integration) == 'unsplit_explicit') then
 
-            ! compute h*, which is h at n+1/2 and put into array hNew
-            ! on last iteration, hNew remains at n+1
-           do iCell=1,block % mesh % nCells
-                 block % state % time_levs(2) % state % h % array(1,iCell) &amp;
-                 = 0.5*( &amp;
-                 block % state % time_levs(2) % state % h % array(1,iCell) &amp;
-               + block % state % time_levs(1) % state % h % array(1,iCell) )
+              ! compute h*, which is h at n+1/2 and put into array hNew
+              ! on last iteration, hNew remains at n+1
+              do iCell=1,block % mesh % nCells
+                block % state % time_levs(2) % state % h % array(1,iCell) = 0.5*( &amp;
+                    block % state % time_levs(2) % state % h % array(1,iCell) &amp;
+                    + block % state % time_levs(1) % state % h % array(1,iCell) )
+              end do ! iCell
+            endif ! unsplit_explicit
 
-           end do ! iCell
-          endif ! unsplit_explicit
+            ! compute u*, the velocity for tendency terms.  Put in uNew.
+            ! uBclNew is at time n+1/2 here.
+            ! This overwrites u^{tr}, the tracer transport velocity, which was in uNew.
+            ! The following must occur after  call OcnTendScalar
+            do iEdge=1,block % mesh % nEdges
+              block % state % time_levs(2) % state % u % array(:,iEdge) &amp;
+                  = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
+                  + block % state % time_levs(2) % state % uBcl % array(:,iEdge) 
+            end do ! iEdge
 
-          ! compute u*, the velocity for tendency terms.  Put in uNew.
-          ! uBclNew is at time n+1/2 here.
-          ! This overwrites u^{tr}, the tracer transport velocity, which was in uNew.
-          ! The following must occur after  call OcnTendScalar
-           do iEdge=1,block % mesh % nEdges
-               block % state % time_levs(2) % state % u    % array(:,iEdge) &amp;
-             = block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
-             + block % state % time_levs(2) % state % uBcl % array(:,iEdge) 
-           end do ! iEdge
+          elseif (split_explicit_step == config_n_ts_iter) then
 
-         elseif (split_explicit_step == config_n_ts_iter) then
-
-           hNew(:) = block % mesh % hZLevel % array(:)
-           do iCell=1,block % mesh % nCells
+            hNew(:) = block % mesh % hZLevel % array(:)
+            do iCell=1,block % mesh % nCells
               ! sshNew is a pointer, defined above.
               hNew(1) =  sshNew(iCell) + block % mesh % hZLevel % array(1)
               do k=1,block % mesh % maxLevelCell % array(iCell)
-                 do i=1,block % state % time_levs(1) % state % num_tracers
-                ! This is Phi at n+1
-                   block % state % time_levs(2) % state % tracers % array(i,k,iCell)  &amp;
-                = (  block % state % time_levs(1) % state % tracers % array(i,k,iCell) &amp;
-                   * block % state % time_levs(1) % state % h % array(k,iCell) &amp;
-                 + dt * block % tend % tracers % array(i,k,iCell) &amp;
-                  ) / hNew(k)
+                do i=1,block % state % time_levs(1) % state % num_tracers
+                  ! This is Phi at n+1
+                  block % state % time_levs(2) % state % tracers % array(i,k,iCell)  &amp;
+                      = (block % state % time_levs(1) % state % tracers % array(i,k,iCell) &amp;
+                      * block % state % time_levs(1) % state % h % array(k,iCell) &amp;
+                      + dt * block % tend % tracers % array(i,k,iCell)) / hNew(k)
 
-                 enddo
+                enddo
               end do
-           end do
+            end do
+          endif ! split_explicit_step
+          deallocate(hNew)
 
-         endif ! split_explicit_step
-           deallocate(hNew)
+          block =&gt; block % next
+        end do
 
-         block =&gt; block % next
-       end do
-
         ! Boundary update on tracers.  This is placed here, rather than 
         ! on tend % tracers as in RK4, because I needed to update 
         ! afterwards for the del4 diffusion operator.
+        call mpas_timer_start(&quot;se halo tracers&quot;, .false., timer_halo_tracers)
         block =&gt; domain % blocklist
         do while (associated(block))
-           call mpas_dmpar_exch_halo_field3d_real(domain % dminfo, block % state % time_levs(2) % state % tracers % array(:,:,:), &amp;
-                                            block % tend % num_tracers, block % mesh % nVertLevels, block % mesh % nCells, &amp;
-                                            block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           block =&gt; block % next
+          call mpas_dmpar_exch_halo_field3d_real(domain % dminfo, block % state % time_levs(2) % state % tracers % array(:,:,:), &amp;
+              block % tend % num_tracers, block % mesh % nVertLevels, block % mesh % nCells, block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
+          block =&gt; block % next
         end do
+        call mpas_timer_stop(&quot;se halo tracers&quot;, timer_halo_tracers)
 
 
-         if (split_explicit_step &lt; config_n_ts_iter) then
-            ! mrp 110512  I really only need this to compute h_edge, density, pressure.
-            ! I can par this down later.
-            block =&gt; domain % blocklist
-            do while (associated(block))
+        if (split_explicit_step &lt; config_n_ts_iter) then
+          ! mrp 110512  I really only need this to compute h_edge, density, pressure.
+          ! I can par this down later.
+          block =&gt; domain % blocklist
+          do while (associated(block))
 
-               call ocn_diagnostic_solve(dt, block % state % time_levs(2) % state, block % mesh)
+            call ocn_diagnostic_solve(dt, block % state % time_levs(2) % state, block % mesh)
 
-               block =&gt; block % next
-            end do
-         endif
+            block =&gt; block % next
+          end do
+        endif
 
       end do  ! split_explicit_step = 1, config_n_ts_iter
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -1113,150 +922,113 @@
       !
       block =&gt; domain % blocklist
       do while (associated(block))
-
         if (trim(config_new_btr_variables_from) == 'last_subcycle') then
-         do iEdge=1,block % mesh % nEdges
-               ! uBtrNew = uBtrSubcycleNew  (old here is because counter already flipped)
-               ! This line is not needed if u is resplit at the beginning of the timestep.
-                block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
-              = block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)  
-         enddo ! iEdges
+          do iEdge=1,block % mesh % nEdges
+            ! uBtrNew = uBtrSubcycleNew  (old here is because counter already flipped)
+            ! This line is not needed if u is resplit at the beginning of the timestep.
+            block % state % time_levs(2) % state % uBtr % array(iEdge) &amp; 
+                = block % state % time_levs(oldBtrSubcycleTime) % state % uBtrSubcycle % array(iEdge)  
+          enddo ! iEdges
         elseif (trim(config_new_btr_variables_from) == 'btr_avg') then
-               ! uBtrNew from u*.  this is done above, so u* is already in
-               ! block % state % time_levs(2) % state % uBtr % array(iEdge) 
+          ! uBtrNew from u*.  this is done above, so u* is already in
+          ! block % state % time_levs(2) % state % uBtr % array(iEdge) 
         else
-         write(0,*) 'Abort: Unknown config_new_btr_variables_from: '&amp;
-           //trim(config_time_integration)
-         call mpas_dmpar_abort(dminfo)
-       endif
+          write(0,*) 'Abort: Unknown config_new_btr_variables_from: '//trim(config_time_integration)
+          call mpas_dmpar_abort(dminfo)
+        endif
 
-         ! Recompute final u to go on to next step.
-         ! u_{n+1} = uBtr_{n+1} + uBcl_{n+1} 
-         ! Right now uBclNew is at time n+1/2, so back compute to get uBcl at time n+1
-         !   using uBcl_{n+1/2} = 1/2*(uBcl_n + u_Bcl_{n+1})
-         ! so the following lines are
-         ! u_{n+1} = uBtr_{n+1} + 2*uBcl_{n+1/2} - uBcl_n
-         ! note that uBcl is recomputed at the beginning of the next timestep due to Imp Vert mixing,
-         ! so uBcl does not have to be recomputed here.
+        ! Recompute final u to go on to next step.
+        ! u_{n+1} = uBtr_{n+1} + uBcl_{n+1} 
+        ! Right now uBclNew is at time n+1/2, so back compute to get uBcl at time n+1
+        !   using uBcl_{n+1/2} = 1/2*(uBcl_n + u_Bcl_{n+1})
+        ! so the following lines are
+        ! u_{n+1} = uBtr_{n+1} + 2*uBcl_{n+1/2} - uBcl_n
+        ! note that uBcl is recomputed at the beginning of the next timestep due to Imp Vert mixing,
+        ! so uBcl does not have to be recomputed here.
+      
+        do iEdge=1,block % mesh % nEdges
+          do k=1,block % mesh % maxLevelEdgeTop % array(iEdge)
+            block % state % time_levs(2) % state % u % array(k,iEdge) =  block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
+                + 2*block % state % time_levs(2) % state % uBcl % array(k,iEdge) -  block % state % time_levs(1) % state % uBcl % array(k,iEdge)
+          enddo
+        enddo ! iEdges
 
-         do iEdge=1,block % mesh % nEdges
-            do k=1,block % mesh % maxLevelEdgeTop % array(iEdge)
-
-               block % state % time_levs(2) % state % u % array(k,iEdge) &amp; 
-            =  block % state % time_levs(2) % state % uBtr % array(iEdge) &amp;
-            +2*block % state % time_levs(2) % state % uBcl % array(k,iEdge) &amp;
-            -  block % state % time_levs(1) % state % uBcl % array(k,iEdge)
-            enddo
-            ! mrp 110607 zero out velocity below land edges. efficiency: this may not be required.
-            do k=block % mesh % maxLevelEdgeTop % array(iEdge) + 1, block % mesh % nVertLevels
-               block % state % time_levs(2) % state % u % array(k,iEdge) = 0.0
-            enddo
-
-         enddo ! iEdges
-
         if (trim(config_time_integration) == 'split_explicit') then
+          if (trim(config_new_btr_variables_from) == 'last_subcycle') then
+            do iCell=1,block % mesh % nCells
+              ! SSH for the next step is from the end of the barotropic subcycle.
+              block % state % time_levs(2) % state % ssh % array(iCell) =  block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) 
+            end do ! iCell
+          elseif (trim(config_new_btr_variables_from) == 'btr_avg') then
+            ! sshNew from ssh*.  This is done above, so ssh* is already in
+            ! block % state % time_levs(2) % state % ssh % array(iCell) 
+          endif
 
-        if (trim(config_new_btr_variables_from) == 'last_subcycle') then
-         do iCell=1,block % mesh % nCells
-         ! SSH for the next step is from the end of the barotropic subcycle.
-               block % state % time_levs(2) % state % ssh % array(iCell) &amp; 
-            =  block % state % time_levs(oldBtrSubcycleTime) % state % sshSubcycle % array(iCell) 
-         end do ! iCell
-        elseif (trim(config_new_btr_variables_from) == 'btr_avg') then
-               ! sshNew from ssh*.  This is done above, so ssh* is already in
-               ! block % state % time_levs(2) % state % ssh % array(iCell) 
-        endif
+          do iCell=1,block % mesh % nCells
+            ! Put new SSH values in h array, for the OcnTendScalar call below.
+            block % state % time_levs(2) % state % h % array(1,iCell) = block % state % time_levs(2) % state % ssh % array(iCell) + block % mesh % hZLevel % array(1)
 
-         do iCell=1,block % mesh % nCells
-         ! Put new SSH values in h array, for the OcnTendScalar call below.
-             block % state % time_levs(2) % state % h % array(1,iCell) &amp;
-           = block % state % time_levs(2) % state % ssh % array(iCell) &amp;
-           + block % mesh % hZLevel % array(1)
+            ! mrp 110601 efficiency note: Since h just moves back and forth between pointers,
+            ! this is not necessary once initialized. 
+            do k=2,block % mesh % nVertLevels * sshSwapFlag
+              block % state % time_levs(2) % state % h % array(k,iCell) = block % mesh % hZLevel % array(k)
+            end do
+          end do ! iCell
+          sshSwapFlag = 0
+        end if ! split_explicit
 
-           ! mrp 110601 efficiency note: Since h just moves back and forth between pointers,
-           ! this is not necessary once initialized.
-           do k=2,block % mesh % nVertLevels
-             block % state % time_levs(2) % state % h % array(k,iCell) &amp;
-           = block % mesh % hZLevel % array(k)
-           end do
-         end do ! iCell
-       end if ! split_explicit

-       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-       !
-       !  Implicit vertical mixing, done after timestep is complete
-       !
-       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        !
+        !  Implicit vertical mixing, done after timestep is complete
+        !
+        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-         u           =&gt; block % state % time_levs(2) % state % u % array
-         tracers     =&gt; block % state % time_levs(2) % state % tracers % array
-         h           =&gt; block % state % time_levs(2) % state % h % array
-         h_edge      =&gt; block % state % time_levs(2) % state % h_edge % array
-         ke_edge     =&gt; block % state % time_levs(2) % state % ke_edge % array
-         num_tracers = block % state % time_levs(2) % state % num_tracers
-         vertViscTopOfEdge =&gt; block % diagnostics % vertViscTopOfEdge % array
-         vertDiffTopOfCell =&gt; block % diagnostics % vertDiffTopOfCell % array
-         maxLevelCell    =&gt; block % mesh % maxLevelCell % array
-         maxLevelEdgeTop =&gt; block % mesh % maxLevelEdgeTop % array
+        u           =&gt; block % state % time_levs(2) % state % u % array
+        tracers     =&gt; block % state % time_levs(2) % state % tracers % array
+        h           =&gt; block % state % time_levs(2) % state % h % array
+        h_edge      =&gt; block % state % time_levs(2) % state % h_edge % array
+        ke_edge     =&gt; block % state % time_levs(2) % state % ke_edge % array
+        num_tracers = block % state % time_levs(2) % state % num_tracers
+        vertViscTopOfEdge =&gt; block % diagnostics % vertViscTopOfEdge % array
+        vertDiffTopOfCell =&gt; block % diagnostics % vertDiffTopOfCell % array
+        maxLevelCell    =&gt; block % mesh % maxLevelCell % array
+        maxLevelEdgeTop =&gt; block % mesh % maxLevelEdgeTop % array
 
-         if (config_implicit_vertical_mix) then
-            allocate(A(block % mesh % nVertLevels),C(block % mesh % nVertLevels),uTemp(block % mesh % nVertLevels), &amp;
-               tracersTemp(num_tracers,block % mesh % nVertLevels))
+        if (config_implicit_vertical_mix) then
+          call ocn_vmix_coefs(block % mesh, block % state % time_levs(2) % state, block % diagnostics, err)
 
-            call ocn_vmix_coefs(block % mesh, block % state % time_levs(2) % state, block % diagnostics, err)
+          !
+          !  Implicit vertical solve for momentum
+          !
 
-            !
-            !  Implicit vertical solve for momentum
-            !
+          call ocn_vel_vmix_tend_implicit(block % mesh, dt, ke_edge, vertvisctopofedge, h, h_edge, u, err)
+      
+          !
+          !  Implicit vertical solve for tracers
+          !
+          call ocn_tracer_vmix_tend_implicit(block % mesh, dt, vertdifftopofcell, h, tracers, err)
+        end if
 
-            call ocn_vel_vmix_tend_implicit(block % mesh, dt, ke_edge, vertvisctopofedge, h, h_edge, u, err)
+        if (config_test_case == 1) then    ! For case 1, wind field should be fixed
+          block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
+        end if
 
-            !
-            !  Implicit vertical solve for tracers
-            !
-            call ocn_tracer_vmix_tend_implicit(block % mesh, dt, vertdifftopofcell, h, tracers, err)
-         end if
+        call ocn_diagnostic_solve(dt, block % state % time_levs(2) % state, block % mesh)
 
-         ! mrp 110725 adding momentum decay term
-         if (config_mom_decay) then
+        call mpas_reconstruct(block % mesh, block % state % time_levs(2) % state % u % array,          &amp;
+            block % state % time_levs(2) % state % uReconstructX % array,            &amp;
+            block % state % time_levs(2) % state % uReconstructY % array,            &amp;
+            block % state % time_levs(2) % state % uReconstructZ % array,            &amp;
+            block % state % time_levs(2) % state % uReconstructZonal % array,        &amp;
+            block % state % time_levs(2) % state % uReconstructMeridional % array)
 
-            !
-            !  Implicit solve for momentum decay
-            !
-            !  Add term to RHS of momentum equation: -1/gamma u
-            !
-            !  This changes the solve to:
-            !  u^{n+1} = u_provis^{n+1}/(1+dt/gamma)
-            !
-            coef = 1.0/(1.0 + dt/config_mom_decay_time)
-            do iEdge=1,block % mesh % nEdges
-               do k=1,maxLevelEdgeTop(iEdge)
-                  u(k,iEdge) = coef*u(k,iEdge) 
-               end do
-            end do
+        call ocn_time_average_accumulate(block % state % time_levs(2) % state, block % state % time_levs(1) % state)
 
-         end if
-
-         if (config_test_case == 1) then    ! For case 1, wind field should be fixed
-            block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
-         end if
-
-         call ocn_diagnostic_solve(dt, block % state % time_levs(2) % state, block % mesh)
-
-         call mpas_reconstruct(block % mesh, block % state % time_levs(2) % state % u % array,          &amp;
-                          block % state % time_levs(2) % state % uReconstructX % array,            &amp;
-                          block % state % time_levs(2) % state % uReconstructY % array,            &amp;
-                          block % state % time_levs(2) % state % uReconstructZ % array,            &amp;
-                          block % state % time_levs(2) % state % uReconstructZonal % array,        &amp;
-                          block % state % time_levs(2) % state % uReconstructMeridional % array    &amp;
-                         )
-
-         block =&gt; block % next
+        block =&gt; block % next
       end do
-      call mpas_timer_stop(&quot;split_explicit_timestep&quot;)
+      call mpas_timer_stop(&quot;se timestep&quot;, timer_main)
+    end subroutine ocn_time_integrator_split!}}}
 
-   end subroutine ocn_time_integrator_split!}}}
-
    subroutine filter_btr_mode_tend_u(tend, s, d, grid)!{{{
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Filter and remove barotropic mode from the tendencies
@@ -1357,27 +1129,24 @@
 
       u_src =&gt; grid % u_src % array
 
-           do iEdge=1,grid % nEdges
+      do iEdge=1,grid % nEdges
+        ! I am using hZLevel here.  This assumes that SSH is zero everywhere already,
+        ! which should be the case if the barotropic mode is filtered.
+        ! The more general case is to use sshEdge or h_edge.
+        uhSum = (grid % hZLevel % array(1)) * tend_u(1,iEdge)
+        hSum  =  grid % hZLevel % array(1)
 
-              ! I am using hZLevel here.  This assumes that SSH is zero everywhere already,
-              ! which should be the case if the barotropic mode is filtered.
-              ! The more general case is to use sshEdge or h_edge.
-              uhSum = (grid % hZLevel % array(1)) * tend_u(1,iEdge)
-              hSum  =  grid % hZLevel % array(1)
+        do k=2,grid % maxLevelEdgeTop % array(iEdge)
+          uhSum = uhSum + grid % hZLevel % array(k) * tend_u(k,iEdge)
+          hSum  =  hSum + grid % hZLevel % array(k)
+        enddo
 
-              do k=2,grid % maxLevelEdgeTop % array(iEdge)
-                 uhSum = uhSum + grid % hZLevel % array(k) * tend_u(k,iEdge)
-                 hSum  =  hSum + grid % hZLevel % array(k)
-              enddo
+        vertSum = uhSum/hSum
+        do k=1,grid % maxLevelEdgeTop % array(iEdge)
+          tend_u(k,iEdge) = tend_u(k,iEdge) - vertSum
+        enddo
+      enddo ! iEdge
 
-              vertSum = uhSum/hSum
-
-              do k=1,grid % maxLevelEdgeTop % array(iEdge)
-                 tend_u(k,iEdge) = tend_u(k,iEdge) - vertSum
-              enddo
-
-           enddo ! iEdge
-
       call mpas_timer_stop(&quot;filter_btr_mode_tend_u&quot;)
 
    end subroutine filter_btr_mode_tend_u!}}}
@@ -1477,75 +1246,28 @@
 
       u_src =&gt; grid % u_src % array
 
-           do iEdge=1,grid % nEdges
+      do iEdge=1,grid % nEdges
+        ! I am using hZLevel here.  This assumes that SSH is zero everywhere already,
+        ! which should be the case if the barotropic mode is filtered.
+        ! The more general case is to use sshedge or h_edge.
+        uhSum = (grid % hZLevel % array(1)) * u(1,iEdge)
+        hSum  =  grid % hZLevel % array(1)
 
-              ! I am using hZLevel here.  This assumes that SSH is zero everywhere already,
-              ! which should be the case if the barotropic mode is filtered.
-              ! The more general case is to use sshedge or h_edge.
-              uhSum = (grid % hZLevel % array(1)) * u(1,iEdge)
-              hSum  =  grid % hZLevel % array(1)
+        do k=2,grid % maxLevelEdgeTop % array(iEdge)
+          uhSum = uhSum + grid % hZLevel % array(k) * u(k,iEdge)
+          hSum  =  hSum + grid % hZLevel % array(k)
+        enddo
 
-              do k=2,grid % maxLevelEdgeTop % array(iEdge)
-                 uhSum = uhSum + grid % hZLevel % array(k) * u(k,iEdge)
-                 hSum  =  hSum + grid % hZLevel % array(k)
-              enddo
+        vertSum = uhSum/hSum
+        do k=1,grid % maxLevelEdgeTop % array(iEdge)
+          u(k,iEdge) = u(k,iEdge) - vertSum
+        enddo
+      enddo ! iEdge
 
-              vertSum = uhSum/hSum
-              do k=1,grid % maxLevelEdgeTop % array(iEdge)
-                 u(k,iEdge) = u(k,iEdge) - vertSum
-              enddo
-
-           enddo ! iEdge
-
       call mpas_timer_stop(&quot;filter_btr_mode_u&quot;)
 
    end subroutine filter_btr_mode_u!}}}
 
-   subroutine enforce_boundaryEdge(tend, grid)!{{{
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   ! Enforce any boundary conditions on the normal velocity at each edge
-   !
-   ! Input: grid - grid metadata
-   !
-   ! Output: tend_u set to zero at boundaryEdge == 1 locations
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-
-      implicit none
-
-      type (tend_type), intent(inout) :: tend
-      type (mesh_type), intent(in) :: grid
-
-      integer, dimension(:,:), pointer :: boundaryEdge
-      real (kind=RKIND), dimension(:,:), pointer :: tend_u
-      integer :: nCells, nEdges, nVertices, nVertLevels
-      integer :: iEdge, k
-
-      call mpas_timer_start(&quot;enforce_boundaryEdge&quot;)
-
-      nCells      = grid % nCells
-      nEdges      = grid % nEdges
-      nVertices   = grid % nVertices
-      nVertLevels = grid % nVertLevels
-
-      boundaryEdge         =&gt; grid % boundaryEdge % array
-      tend_u      =&gt; tend % u % array
-
-      if(maxval(boundaryEdge).le.0) return
-
-      do iEdge = 1,nEdges
-        do k = 1,nVertLevels
-
-          if(boundaryEdge(k,iEdge).eq.1) then
-             tend_u(k,iEdge) = 0.0
-          endif
-
-        enddo
-       enddo
-      call mpas_timer_stop(&quot;enforce_boundaryEdge&quot;)
-
-   end subroutine enforce_boundaryEdge!}}}
-
 end module ocn_time_integration_split
 
 ! vim: foldmethod=marker

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,6 +16,7 @@
 
    use mpas_grid_types
    use mpas_configure
+   use mpas_timer
 
    use ocn_tracer_hadv2
    use ocn_tracer_hadv3
@@ -46,7 +47,9 @@
    !
    !--------------------------------------------------------------------
 
+   type (timer_node), pointer :: hadv2Timer, hadv3Timer, hadv4Timer
 
+
 !***********************************************************************
 
 contains
@@ -122,9 +125,15 @@
       !
       !-----------------------------------------------------------------
 
+      call mpas_timer_start(&quot;hadv2&quot;, .false., hadv2Timer);
       call ocn_tracer_hadv2_tend(grid, u, h_edge, tracers, tend, err1)
+      call mpas_timer_stop(&quot;hadv2&quot;, hadv2Timer);
+      call mpas_timer_start(&quot;hadv3&quot;, .false., hadv3Timer);
       call ocn_tracer_hadv3_tend(grid, u, h_edge, tracers, tend, err2)
+      call mpas_timer_stop(&quot;hadv3&quot;, hadv3Timer);
+      call mpas_timer_start(&quot;hadv4&quot;, .false., hadv4Timer);
       call ocn_tracer_hadv4_tend(grid, u, h_edge, tracers, tend, err3)
+      call mpas_timer_stop(&quot;hadv4&quot;, hadv4Timer);
 
       err = ior(err1, ior(err2, err3))
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv2.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv2.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv2.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: hadv2On !&lt; Flag to turn on/off 2nd order hadv
+   integer :: hadv2On !&lt; Flag to turn on/off 2nd order hadv
 
 !***********************************************************************
 
@@ -111,7 +110,7 @@
       integer, dimension(:), pointer :: maxLevelEdgeTop
       integer, dimension(:,:), pointer :: cellsOnEdge
 
-      real (kind=RKIND) :: flux, tracer_edge
+      real (kind=RKIND) :: flux, tracer_edge, invAreaCell1, invAreaCell2, r_tmp
 
       real (kind=RKIND), dimension(:), pointer :: dvEdge, areaCell
 
@@ -125,10 +124,8 @@
 
       err = 0
 
-      if(.not.hadv2On) return
+      if(hadv2On == 0) return
 
-      call mpas_timer_start(&quot;compute_scalar_tend-horiz adv 2&quot;)
-
       nEdges = grid % nEdges
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
@@ -139,17 +136,19 @@
       do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
+
+         invAreaCell1 = 1.0 / areaCell(cell1)
+         invAreaCell2 = 1.0 / areaCell(cell2)
          do k=1,maxLevelEdgeTop(iEdge)
+            r_tmp = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge)
             do iTracer=1,num_tracers
                tracer_edge = 0.5 * (tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))
-               flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge) * tracer_edge
-               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux/areaCell(cell1)
-               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux/areaCell(cell2)
+               flux = r_tmp * tracer_edge
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux * invAreaCell1
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux * invAreaCell2
             end do
          end do
       end do
-
-      call mpas_timer_stop(&quot;compute_scalar_tend-horiz adv 2&quot;)
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_hadv2_tend!}}}
@@ -181,10 +180,10 @@
       integer, intent(out) :: err !&lt; Output: Error flag
 
       err = 0
-      hadv2On = .false.
+      hadv2On = 0
 
       if (config_tracer_adv_order == 2) then
-          hadv2On = .true.
+          hadv2On = 1
       end if
 
    !--------------------------------------------------------------------

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv3.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv3.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv3.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: hadv3On !&lt; Flag to turn on/off 3rd order hadv
+   integer :: hadv3On !&lt; Flag to turn on/off 3rd order hadv
    real (kind=RKIND) :: coef_3rd_order !&lt; Coefficient for 3rd order hadv
 
 !***********************************************************************
@@ -107,13 +106,15 @@
       !
       !-----------------------------------------------------------------
 
-      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, i, k
+      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, i, k, &amp;
+                 boundaryMask, velMask
 
       integer, dimension(:), pointer :: maxLevelEdgeTop, nEdgesOnCell
       integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnCell, &amp;
-                                          boundaryCell
+                                          cellMask, edgeMask
 
-      real (kind=RKIND) :: flux, tracer_edge, d2fdx2_cell1, d2fdx2_cell2
+      real (kind=RKIND) :: flux, tracer_edge, d2fdx2_cell1, d2fdx2_cell2, &amp;
+                           invAreaCell1, invAreaCell2
 
       real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
       real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
@@ -128,13 +129,13 @@
 
       err = 0
 
-      if(.not.hadv3On) return
+      if(hadv3On == 0) return
 
       nEdges = grid % nEdges
       num_tracers = size(tracers, dim=1)
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       nEdgesOnCell =&gt; grid % nEdgesOnCell % array
-      boundaryCell =&gt; grid % boundaryCell % array
+      cellMask =&gt; grid % cellMask % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       cellsOnCell =&gt; grid % cellsOnCell % array
       dvEdge =&gt; grid % dvEdge % array
@@ -142,60 +143,51 @@
       areaCell =&gt; grid % areaCell % array
       deriv_two =&gt; grid % deriv_two % array
 
-      call mpas_timer_start(&quot;compute_scalar_tend-horiz adv 3&quot;)
       do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
 
+         invAreaCell1 = 1.0 / areaCell(cell1)
+         invAreaCell2 = 1.0 / areaCell(cell2)
+
          do k=1,maxLevelEdgeTop(iEdge)
 
             d2fdx2_cell1 = 0.0
             d2fdx2_cell2 = 0.0
 
+            boundaryMask = abs(transfer(cellMask(k,cell1)  == 1 .and. cellMask(k,cell2) == 1,boundaryMask))
+
             do iTracer=1,num_tracers
 
                !-- if not a boundary cell
-               if(boundaryCell(k,cell1).eq.0.and.boundaryCell(k,cell2).eq.0) then
+               d2fdx2_cell1 = deriv_two(1,1,iEdge) * tracers(iTracer,k,cell1) * boundaryMask
+               d2fdx2_cell2 = deriv_two(1,2,iEdge) * tracers(iTracer,k,cell2) * boundaryMask
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * tracers(iTracer,k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * tracers(iTracer,k,cell2)
+               !-- all edges of cell 1
+               do i=1,nEdgesOnCell(cell1) * boundaryMask
+                  d2fdx2_cell1 = d2fdx2_cell1 + &amp;
+                  deriv_two(i+1,1,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell1))
+               end do
 
-                  !-- all edges of cell 1
-                  do i=1,nEdgesOnCell(cell1)
-                     d2fdx2_cell1 = d2fdx2_cell1 + &amp;
-                     deriv_two(i+1,1,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell1))
-                  end do
+               !-- all edges of cell 2
+               do i=1,nEdgesOnCell(cell2) * boundaryMask
+                  d2fdx2_cell2 = d2fdx2_cell2 + &amp;
+                  deriv_two(i+1,2,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell2))
+               end do
 
-                  !-- all edges of cell 2
-                  do i=1,nEdgesOnCell(cell2)
-                     d2fdx2_cell2 = d2fdx2_cell2 + &amp;
-                     deriv_two(i+1,2,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell2))
-                  end do
 
-               endif
+               velMask = 2*(abs(transfer(u(k,iEdge) &lt;= 0, velMask))) - 1
+               flux = dvEdge(iEdge) *  u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
+                    0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
+                    -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
+                    +velMask*(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12. )
 
-               !-- if u &gt; 0:
-               if (u(k,iEdge) &gt; 0) then
-                  flux = dvEdge(iEdge) * u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
-                       0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
-                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
-                       -(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12. )
-               !-- else u &lt;= 0:
-               else
-                  flux = dvEdge(iEdge) *  u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
-                       0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
-                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
-                       +(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12. )
-               end if
-
                !-- update tendency
-               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux/areaCell(cell1)
-               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux/areaCell(cell2)
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux*invAreaCell1
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux*invAreaCell2
             enddo
          end do
       end do
-      call mpas_timer_stop(&quot;compute_scalar_tend-horiz adv 3&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_hadv3_tend!}}}
@@ -227,10 +219,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      hadv3On = .false.
+      hadv3On = 0
 
       if (config_tracer_adv_order == 3) then
-          hadv3On = .true.
+          hadv3On = 1
 
           coef_3rd_order = 1.0
           if (config_monotonic) coef_3rd_order = 0.25

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv4.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv4.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv4.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: hadv4On !&lt; Flag to turning on/off 4th order hadv
+   integer :: hadv4On !&lt; Flag to turning on/off 4th order hadv
 
 !***********************************************************************
 
@@ -106,12 +105,13 @@
       !
       !-----------------------------------------------------------------
 
-      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, i, k
+      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, i, k, &amp;
+                 boundaryMask
 
-      integer, dimension(:), pointer :: maxLevelEdgeTop
-      integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnCell, boundaryCell
+      integer, dimension(:), pointer :: maxLevelEdgeTop, nEdgesOnCell
+      integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnCell, cellMask
 
-      real (kind=RKIND) :: flux, tracer_edge, d2fdx2_cell1, d2fdx2_cell2
+      real (kind=RKIND) :: flux, tracer_edge, d2fdx2_cell1, d2fdx2_cell2, invAreaCell1, invAreaCell2
 
       real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
       real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
@@ -126,12 +126,13 @@
 
       err = 0
 
-      if(.not.hadv4On) return
+      if(hadv4On == 0) return
 
       nEdges = grid % nEdges
       num_tracers = size(tracers, dim=1)
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
-      boundaryCell =&gt; grid % boundaryCell % array
+      nEdgesOnCell = grid % nEdgesOnCell % array
+      cellMask =&gt; grid % cellMask % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       cellsOnCell =&gt; grid % cellsOnCell % array
       dvEdge =&gt; grid % dvEdge % array
@@ -139,51 +140,46 @@
       areaCell =&gt; grid % areaCell % array
       deriv_two =&gt; grid % deriv_two % array
 
-      call mpas_timer_start(&quot;compute_scalar_tend-horiz adv 4&quot;)
-
       do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
 
+         invAreaCell1 = 1.0 / areaCell(cell1)
+         invAreaCell2 = 1.0 / areaCell(cell2)
+
          do k=1,maxLevelEdgeTop(iEdge)
 
             d2fdx2_cell1 = 0.0
             d2fdx2_cell2 = 0.0
 
+            boundaryMask = abs(transfer(cellMask(k,cell1) == 1 .and. cellMask(k, cell2) == 1, boundaryMask))
+
             do iTracer=1,num_tracers
+               d2fdx2_cell1 = deriv_two(1,1,iEdge) * tracers(iTracer,k,cell1) * boundaryMask
+               d2fdx2_cell2 = deriv_two(1,2,iEdge) * tracers(iTracer,k,cell2) * boundaryMask
 
-               !-- if not a boundary cell
-               if(boundaryCell(k,cell1).eq.0.and.boundaryCell(k,cell2).eq.0) then
+               !-- all edges of cell 1
+               do i=1,nEdgesOnCell(cell1) * boundaryMask
+                  d2fdx2_cell1 = d2fdx2_cell1 + &amp;
+                  deriv_two(i+1,1,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell1))
+               end do
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * tracers(iTracer,k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * tracers(iTracer,k,cell2)
+               !-- all edges of cell 2
+               do i=1,nEdgesOnCell(cell2) * boundaryMask
+                   d2fdx2_cell2 = d2fdx2_cell2 + &amp;
+                   deriv_two(i+1,2,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell2))
+               end do
 
-                  !-- all edges of cell 1
-                  do i=1, grid % nEdgesOnCell % array (cell1)
-                     d2fdx2_cell1 = d2fdx2_cell1 + &amp;
-                     deriv_two(i+1,1,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell1))
-                  end do
-
-                  !-- all edges of cell 2
-                  do i=1, grid % nEdgesOnCell % array (cell2)
-                      d2fdx2_cell2 = d2fdx2_cell2 + &amp;
-                      deriv_two(i+1,2,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell2))
-                  end do
-
-               endif
-
                flux = dvEdge(iEdge) *  u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
                     0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
                        -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12. )
 
                !-- update tendency
-               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux/areaCell(cell1)
-               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux/areaCell(cell2)
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux * invAreaCell1
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux * invAreaCell2
             enddo
          end do
       end do
-      call mpas_timer_stop(&quot;compute_scalar_tend-horiz adv 4&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_hadv4_tend!}}}
@@ -215,10 +211,10 @@
       integer, intent(out) :: err !&lt; Output: Error flag
 
       err = 0
-      hadv4On = .false.
+      hadv4On = 0
 
       if (config_tracer_adv_order == 4) then
-          hadv4On = .true.
+          hadv4On = 1
       end if
 
    !--------------------------------------------------------------------

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -18,6 +18,7 @@
 
    use mpas_grid_types
    use mpas_configure
+   use mpas_timer
    use ocn_tracer_hmix_del2
    use ocn_tracer_hmix_del4
 
@@ -46,7 +47,9 @@
    !
    !--------------------------------------------------------------------
 
+   type (timer_node), pointer :: del2Timer, del4Timer
 
+
 !***********************************************************************
 
 contains
@@ -119,8 +122,12 @@
       !
       !-----------------------------------------------------------------
 
+      call mpas_timer_start(&quot;del2&quot;, .false., del2Timer)
       call ocn_tracer_hmix_del2_tend(grid, h_edge, tracers, tend, err1)
+      call mpas_timer_stop(&quot;del2&quot;, del2Timer)
+      call mpas_timer_start(&quot;del4&quot;, .false., del4Timer)
       call ocn_tracer_hmix_del4_tend(grid, h_edge, tracers, tend, err2)
+      call mpas_timer_stop(&quot;del4&quot;, del4Timer)
 
       err = ior(err1, err2)
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del2.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del2.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del2.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -18,7 +18,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -45,7 +44,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: del2On
+   integer :: del2On
 
    real (kind=RKIND) :: eddyDiff2
 
@@ -114,10 +113,10 @@
       integer, dimension(:,:), allocatable :: boundaryMask
 
       integer, dimension(:), pointer :: maxLevelEdgeTop
-      integer, dimension(:,:), pointer :: cellsOnEdge, boundaryEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, edgeMask
 
       real (kind=RKIND) :: invAreaCell1, invAreaCell2
-      real (kind=RKIND) :: tracer_turb_flux, flux
+      real (kind=RKIND) :: tracer_turb_flux, flux, r_tmp
 
       real (kind=RKIND), dimension(:), pointer :: areaCell, dvEdge, dcEdge
       real (kind=RKIND), dimension(:), pointer :: meshScalingDel2
@@ -132,17 +131,15 @@
 
       err = 0
 
-      if (.not.del2On) return
+      if (del2On == 0) return
 
-      call mpas_timer_start(&quot;compute_scalar_tend-horiz diff 2&quot;)
-
       nEdges = grid % nEdges
       nVertLevels = grid % nVertLevels
       num_tracers = size(tracers, dim=1)
 
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
-      boundaryEdge =&gt; grid % boundaryEdge % array
+      edgeMask =&gt; grid % edgeMask % array
       areaCell =&gt; grid % areaCell % array
       dvEdge =&gt; grid % dvEdge % array
       dcEdge =&gt; grid % dcEdge % array
@@ -151,36 +148,28 @@
       !
       ! compute a boundary mask to enforce insulating boundary conditions in the horizontal
       !
-      allocate(boundaryMask(nVertLevels, nEdges+1))
-      boundaryMask = 1.0
-      where(boundaryEdge.eq.1) boundaryMask=0.0
-
       do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
          invAreaCell1 = 1.0/areaCell(cell1)
          invAreaCell2 = 1.0/areaCell(cell2)
 
+         r_tmp = meshScalingDel2(iEdge) * eddyDiff2 * dvEdge(iEdge) / dcEdge(iEdge)
+
          do k=1,maxLevelEdgeTop(iEdge)
            do iTracer=1,num_tracers
               ! \kappa_2 </font>
<font color="red">abla \phi on edge
-              tracer_turb_flux = meshScalingDel2(iEdge) * eddyDiff2 &amp;
-                 *(  tracers(iTracer,k,cell2) &amp;
-                   - tracers(iTracer,k,cell1))/dcEdge(iEdge)
+              tracer_turb_flux = tracers(iTracer,k,cell2) - tracers(iTracer,k,cell1)
 
               ! div(h \kappa_2 </font>
<font color="gray">abla \phi) at cell center
-              flux = dvEdge (iEdge) * h_edge(k,iEdge) &amp;
-                 * tracer_turb_flux * boundaryMask(k, iEdge)
+              flux = h_edge(k,iEdge) * tracer_turb_flux * edgeMask(k, iEdge) * r_tmp
+
               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) + flux * invAreaCell1
               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) - flux * invAreaCell2
            end do
          end do
 
       end do
-
-      deallocate(boundaryMask)
-      call mpas_timer_stop(&quot;compute_scalar_tend-horiz diff 2&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_hmix_del2_tend!}}}
@@ -213,10 +202,10 @@
 
       err = 0
 
-      del2on = .false.
+      del2on = 0
 
       if ( config_h_tracer_eddy_diff2 &gt; 0.0 ) then
-          del2On = .true.
+          del2On = 1
           eddyDiff2 = config_h_tracer_eddy_diff2
       endif
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del4.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del4.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del4.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -18,7 +18,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -45,7 +44,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: Del4On
+   integer :: del4On
 
    real (kind=RKIND) :: eddyDiff4
 
@@ -133,10 +132,8 @@
 
       err = 0
 
-      if (.not.Del4On) return
+      if (del4On == 0) return
 
-      call mpas_timer_start(&quot;compute_scalar_tend-horiz diff 4&quot;)
-
       nEdges = grid % nEdges
       nCells = grid % nCells
       num_tracers = size(tracers, dim=1)
@@ -213,7 +210,6 @@
 
       deallocate(delsq_tracer)
       deallocate(boundaryMask)
-      call mpas_timer_stop(&quot;compute_scalar_tend-horiz diff 4&quot;)
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_hmix_del4_tend!}}}
@@ -245,10 +241,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      Del4on = .false.
+      del4on = 0
 
       if ( config_h_tracer_eddy_diff4 &gt; 0.0 ) then
-          Del4On = .true.
+          del4On = 1
           eddyDiff4 = config_h_tracer_eddy_diff4
       endif
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -45,7 +45,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: vadvOn
+   integer :: vadvOn
 
 
 !***********************************************************************
@@ -123,7 +123,7 @@
 
       err = 0
 
-      if(.not.vadvOn) return
+      if(vadvOn == 0) return
 
       call ocn_tracer_vadv_stencil_tend(grid, h, wTop, tracers, tend, err1)
       call ocn_tracer_vadv_spline_tend(grid, h, wTop, tracers, tend, err2)
@@ -165,10 +165,10 @@
       integer :: err1, err2
 
       err = 0
-      vadvOn = .false.
+      vadvOn = 0
 
       if (config_vert_grid_type.ne.'isopycnal') then
-          vadvOn = .true.
+          vadvOn = 1
           call ocn_tracer_vadv_stencil_init(err1)
           call ocn_tracer_vadv_spline_init(err2)
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,6 +16,7 @@
 
    use mpas_grid_types
    use mpas_configure
+   use mpas_timer
 
    use ocn_tracer_vadv_spline2
    use ocn_tracer_vadv_spline3
@@ -45,7 +46,8 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: splineOn
+   type (timer_node), pointer :: spline2_timer, spline3_timer
+   integer :: splineOn
 
 
 !***********************************************************************
@@ -123,10 +125,14 @@
 
       err = 0
 
-      if(.not.splineOn) return
+      if(splineOn == 0) return
 
+      call mpas_timer_start(&quot;spline 2&quot;, .false., spline2_timer)
       call ocn_tracer_vadv_spline2_tend(grid, h, wTop, tracers, tend, err1)
+      call mpas_timer_stop(&quot;spline 2&quot;, spline2_timer)
+      call mpas_timer_start(&quot;spline 3&quot;, .false., spline3_timer)
       call ocn_tracer_vadv_spline3_tend(grid, h, wTop, tracers, tend, err2)
+      call mpas_timer_stop(&quot;spline 3&quot;, spline3_timer)
 
       err = ior(err1, err2)
 
@@ -166,10 +172,10 @@
 
       err = 0
 
-      splineOn = .false.
+      splineOn = 0
 
       if(config_vert_tracer_adv.eq.'spline') then
-         splineOn = .true.
+         splineOn = 1
 
          call ocn_tracer_vadv_spline2_init(err1)
          call ocn_tracer_vadv_spline3_init(err2)

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: spline2On
+   integer :: spline2On
 
 
 !***********************************************************************
@@ -121,11 +120,9 @@
 
       err = 0
 
-      if(.not.spline2On) return
+      if(spline2On == 0) return
       ! Compute tracerTop using linear interpolation.
 
-      call mpas_timer_start(&quot;compute_scalar_tend-vert adv spline 2&quot;)
-
       nCells = grid % nCells
       nCellsSolve = grid % nCellsSolve
       nVertLevels = grid % nVertLevels
@@ -160,8 +157,6 @@
       end do
 
       deallocate(tracerTop)
-
-      call mpas_timer_stop(&quot;compute_scalar_tend-vert adv spline 2&quot;)
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vadv_spline2_tend!}}}
@@ -194,10 +189,10 @@
 
       err = 0
 
-      spline2On = .false.
+      spline2On = 0
 
       if(config_vert_tracer_adv_order.eq.2) then
-        spline2On = .true.
+        spline2On = 1
       endif
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
    use mpas_spline_interpolation
 
    implicit none
@@ -44,7 +43,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: spline3On
+   integer :: spline3On
 
 
 !***********************************************************************
@@ -126,11 +125,9 @@
 
       err = 0
 
-      if(.not.spline3On) return
+      if(spline3On == 0) return
       ! Compute tracerTop using linear interpolation.
 
-      call mpas_timer_start(&quot;compute_scalar_tend-vert adv spline 3&quot;)
-
       nCells = grid % nCells
       nCellsSolve = grid % nCellsSolve
       nVertLevels = grid % nVertLevels
@@ -191,8 +188,6 @@
       deallocate(tracer2ndDer)
       deallocate(tracersIn,tracersOut, posZMidZLevel, posZTopZLevel)
       deallocate(tracerTop)
-
-      call mpas_timer_stop(&quot;compute_scalar_tend-vert adv spline 3&quot;)
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vadv_spline3_tend!}}}
@@ -225,10 +220,10 @@
 
       err = 0
 
-      spline3On = .false.
+      spline3On = 0
 
       if(config_vert_tracer_adv_order.eq.3) then
-        spline3On = .true.
+        spline3On = 1
       endif
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,6 +16,7 @@
 
    use mpas_grid_types
    use mpas_configure
+   use mpas_timer
 
    use ocn_tracer_vadv_stencil2
    use ocn_tracer_vadv_stencil3
@@ -46,9 +47,11 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: stencilOn
+   type (timer_node), pointer :: stencil2_timer, stencil3_timer, stencil4_timer
 
+   integer :: stencilOn
 
+
 !***********************************************************************
 
 contains
@@ -124,11 +127,17 @@
 
       err = 0
 
-      if(.not. stencilOn) return
+      if(stencilOn == 0) return
 
+      call mpas_timer_start(&quot;stencil 2&quot;, .false., stencil2_timer)
       call ocn_tracer_vadv_stencil2_tend(grid, wTop, tracers, tend, err1)
+      call mpas_timer_stop(&quot;stencil 2&quot;, stencil2_timer)
+      call mpas_timer_start(&quot;stencil 3&quot;, .false., stencil3_timer)
       call ocn_tracer_vadv_stencil3_tend(grid, h, wTop, tracers, tend, err2)
+      call mpas_timer_stop(&quot;stencil 3&quot;, stencil3_timer)
+      call mpas_timer_start(&quot;stencil 4&quot;, .false., stencil4_timer)
       call ocn_tracer_vadv_stencil4_tend(grid, h, wTop, tracers, tend, err3)
+      call mpas_timer_stop(&quot;stencil 4&quot;, stencil4_timer)
 
       err = ior(err1, ior(err2, err3))
 
@@ -168,10 +177,10 @@
 
       err = 0
 
-      stencilOn = .false.
+      stencilOn = 0
 
       if (config_vert_tracer_adv.eq.'stencil') then
-         stencilOn = .true.
+         stencilOn = 1
 
          call ocn_tracer_vadv_stencil2_init(err1)
          call ocn_tracer_vadv_stencil3_init(err2)

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: stencil2On
+   integer :: stencil2On
 
 
 !***********************************************************************
@@ -122,11 +121,8 @@
 
       err = 0
 
-      if(.not. stencil2On) return
+      if(stencil2On == 0) return
 
-
-      call mpas_timer_start(&quot;compute_scalar_tend-vert adv stencil 2&quot;)
-
       nCells = grid % nCells
       nCellsSolve = grid % nCellsSolve
       num_tracers = size(tracers, 1)
@@ -160,8 +156,6 @@
       end do
 
       deallocate(tracerTop)
-      call mpas_timer_stop(&quot;compute_scalar_tend-vert adv stencil 2&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vadv_stencil2_tend!}}}
@@ -195,10 +189,10 @@
       integer :: err1, err2, err3
 
       err = 0
-      stencil2On = .false.
+      stencil2On = 0
 
       if(config_vert_tracer_adv_order.eq.2) then
-          stencil2On = .true.
+          stencil2On = 1
       endif
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: stencil3On
+   integer :: stencil3On
 
 
 !***********************************************************************
@@ -124,7 +123,7 @@
 
       err = 0
 
-      if(.not. stencil3On) return
+      if(stencil3On == 0) return
 
       nCells = grid % nCells
       nCellsSolve = grid % nCellsSolve
@@ -132,8 +131,6 @@
       nVertLevels = grid % nVertLevels
       maxLevelCell =&gt; grid % maxLevelCell % array
 
-      call mpas_timer_start(&quot;compute_scalar_tend-vert adv stencil 3&quot;)
-
       allocate(tracerTop(num_tracers,nVertLevels+1,nCells))
 
       ! Compute tracerTop using 3rd order stencil.  This is the same
@@ -183,8 +180,6 @@
       end do
 
       deallocate(tracerTop)
-      call mpas_timer_stop(&quot;compute_scalar_tend-vert adv stencil 3&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vadv_stencil3_tend!}}}
@@ -216,10 +211,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      stencil3On = .false.
+      stencil3On = 0
 
       if(config_vert_tracer_adv_order.eq.3) then
-          stencil3On = .true.
+          stencil3On = 1
       endif
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: stencil4On
+   integer :: stencil4On
 
 
 !***********************************************************************
@@ -124,10 +123,8 @@
 
       err = 0
 
-      if(.not. Stencil4On) return
+      if(Stencil4On == 0) return
 
-      call mpas_timer_start(&quot;compute_scalar_tend-vert adv stencil 4&quot;)
-
       nCells = grid % nCells
       nCellsSolve = grid % nCellsSolve
       num_tracers = size(tracers, 1)
@@ -178,8 +175,6 @@
       end do
 
       deallocate(tracerTop)
-      call mpas_timer_stop(&quot;compute_scalar_tend-vert adv stencil 4&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vadv_stencil4_tend!}}}
@@ -211,10 +206,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      stencil4On = .false.
+      stencil4On = 0
 
       if(config_vert_tracer_adv_order.eq.4) then
-          stencil4On = .true.
+          stencil4On = 1
       endif
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_coriolis.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_coriolis.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_coriolis.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -106,13 +106,13 @@
       !-----------------------------------------------------------------
 
       integer, dimension(:), pointer :: maxLevelEdgeTop, nEdgesOnEdge
-      integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnEdge, edgeMask
       real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
       real (kind=RKIND), dimension(:), pointer :: dcEdge
 
       integer :: j, k
       integer :: cell1, cell2, nEdgesSolve, iEdge, eoe
-      real (kind=RKIND) :: workpv, q
+      real (kind=RKIND) :: workpv, q, invLength
 
       err = 0
 
@@ -123,12 +123,16 @@
       weightsOnEdge =&gt; grid % weightsOnEdge % array
       dcEdge =&gt; grid % dcEdge % array
 
+      edgeMask =&gt; grid % edgeMask % array
+
       nEdgesSolve = grid % nEdgesSolve
 
       do iEdge=1,grid % nEdgesSolve
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
 
+         invLength = 1.0 / dcEdge(iEdgE)
+
          do k=1,maxLevelEdgeTop(iEdge)
 
             q = 0.0
@@ -138,9 +142,7 @@
                q = q + weightsOnEdge(j,iEdge) * u(k,eoe) * workpv * h_edge(k,eoe) 
             end do
 
-           tend(k,iEdge) = tend(k,iEdge)     &amp;
-                  + q     &amp;
-                  - (   ke(k,cell2) - ke(k,cell1) ) / dcEdge(iEdge)
+           tend(k,iEdge) = tend(k,iEdge) + edgeMask(k, iEdge) * (q - (   ke(k,cell2) - ke(k,cell1) ) * invLength )
 
          end do
       end do

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -19,6 +19,7 @@
 
    use ocn_vel_forcing_windstress
    use ocn_vel_forcing_bottomdrag
+   use ocn_vel_forcing_rayleigh
 
    implicit none
    private
@@ -114,7 +115,7 @@
       !
       !-----------------------------------------------------------------
 
-      integer :: err1, err2
+      integer :: err1, err2, err3
 
       !-----------------------------------------------------------------
       !
@@ -126,8 +127,10 @@
 
       call ocn_vel_forcing_windstress_tend(grid, u_src, h_edge, tend, err1)
       call ocn_vel_forcing_bottomdrag_tend(grid, u, ke_edge, h_edge, tend, err2)
+      call ocn_vel_forcing_rayleigh_tend(grid, u, tend, err3)
 
       err = ior(err1, err2)
+      err = ior(err, err3)
 
    !--------------------------------------------------------------------
 
@@ -161,12 +164,14 @@
 
       integer, intent(out) :: err !&lt; Output: error flag
 
-      integer :: err1, err2
+      integer :: err1, err2, err3
 
       call ocn_vel_forcing_windstress_init(err1)
       call ocn_vel_forcing_bottomdrag_init(err2)
+      call ocn_vel_forcing_rayleigh_init(err3)
 
       err = ior(err1, err2)
+      err = ior(err, err3)
 
    !--------------------------------------------------------------------
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -42,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: bottomDragOn
+   integer :: bottomDragOn
    real (kind=RKIND) :: bottomDragCoef
 
 
@@ -109,6 +109,7 @@
 
       integer :: iEdge, nEdgesSolve, k
       integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: edgeMask
 
       !-----------------------------------------------------------------
       !
@@ -120,35 +121,24 @@
 
       err = 0
 
-      if(.not.bottomDragOn) return
+      if(bottomDragOn == 0) return
 
       nEdgesSolve = grid % nEdgesSolve
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      edgeMask =&gt; grid % edgeMask % array
 
       do iEdge=1,grid % nEdgesSolve
 
-        k = maxLevelEdgeTop(iEdge)
+        k = max(maxLevelEdgeTop(iEdge), 1)
 
-        ! efficiency note: it would be nice to avoid this
-        ! if within a do.  This could be done with
-        ! k =  max(maxLevelEdgeTop(iEdge),1)
-        ! and then tend_u(1,iEdge) is just not used for land cells.
+        ! bottom drag is the same as POP:
+        ! -c |u| u  where c is unitless and 1.0e-3.
+        ! see POP Reference guide, section 3.4.4.
 
-        if (k&gt;0) then
-           ! bottom drag is the same as POP:
-           ! -c |u| u  where c is unitless and 1.0e-3.
-           ! see POP Reference guide, section 3.4.4.
+        tend(k,iEdge) = tend(k,iEdge)-edgeMask(k,iEdge)*(bottomDragCoef*u(k,iEdge)*sqrt(2.0*ke_edge(k,iEdge))/h_edge(k,iEdge))
 
-           tend(k,iEdge) = tend(k,iEdge)  &amp;
-               -bottomDragCoef*u(k,iEdge) &amp;
-               *sqrt(2.0*ke_edge(k,iEdge))/h_edge(k,iEdge)
-
-        endif
-
       enddo
 
-
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_forcing_bottomdrag_tend!}}}
@@ -182,10 +172,10 @@
 
       err = 0
 
-      bottomDragOn = .false.
+      bottomDragOn = 0
 
       if (.not.config_implicit_vertical_mix) then
-          bottomDragOn = .true.
+          bottomDragOn = 1
           bottomDragCoef = config_bottom_drag_coeff
       endif
 

Copied: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F (from rev 1357, branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F)
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F                                (rev 0)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -0,0 +1,182 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  ocn_vel_forcing_rayleigh
+!
+!&gt; \brief MPAS ocean Rayleigh Friction (to be used to smooth &quot;shocks&quot; from cold starts)
+!&gt; \author Todd Ringler
+!&gt; \date   5 January 2012
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains the routine for computing 
+!&gt;  tendencies based on linear Rayleigh friction.
+!
+!-----------------------------------------------------------------------
+
+module ocn_vel_forcing_rayleigh
+
+   use mpas_grid_types
+   use mpas_configure
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: ocn_vel_forcing_rayleigh_tend, &amp;
+             ocn_vel_forcing_rayleigh_init
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+   logical :: rayleighFrictionOn
+   real (kind=RKIND) :: rayleighDampingCoef
+
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  ocn_vel_forcing_rayleigh_tend
+!
+!&gt; \brief   Computes tendency term from Rayleigh friction
+!&gt; \author  Todd Ringler
+!&gt; \date    5 January 2012
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the Rayleigh friction tendency for momentum
+!&gt;  based on current state.
+!
+!-----------------------------------------------------------------------
+
+   subroutine ocn_vel_forcing_rayleigh_tend(grid, u, tend, err)!{{{
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         u    !&lt; Input: velocity 
+
+      type (mesh_type), intent(in) :: &amp;
+         grid          !&lt; Input: grid information
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(inout) :: &amp;
+         tend          !&lt; Input/Output: velocity tendency
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err !&lt; Output: error flag
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: iEdge, nEdgesSolve, k
+      integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: edgeMask
+
+      !-----------------------------------------------------------------
+      !
+      ! call relevant routines for computing tendencies
+      ! note that the user can choose multiple options and the 
+      !   tendencies will be added together
+      !
+      !-----------------------------------------------------------------
+
+      err = 0
+
+      if(.not.rayleighFrictionOn) return
+
+      nEdgesSolve = grid % nEdgesSolve
+      maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      edgeMask =&gt; grid % edgeMask % array
+
+      do iEdge=1,nEdgesSolve
+        do k=1,maxLevelEdgeTop(iEdge)
+
+           tend(k,iEdge) = tend(k,iEdge) - rayleighDampingCoef * u(k,iEdge) * edgeMask(k, iEdge)
+
+        enddo
+      enddo
+
+
+   !--------------------------------------------------------------------
+
+   end subroutine ocn_vel_forcing_rayleigh_tend!}}}
+
+!***********************************************************************
+!
+!  ocn_vel_forcing_rayleigh_init
+!
+!&gt; \brief   Initializes ocean Rayleigh friction
+!&gt; \author  Todd Ringler
+!&gt; \date    5 January 2012
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes quantities related to 
+!&gt;  in the ocean. 
+!
+!-----------------------------------------------------------------------
+
+   subroutine ocn_vel_forcing_rayleigh_init(err)!{{{
+
+   !--------------------------------------------------------------------
+
+      !-----------------------------------------------------------------
+      !
+      ! call individual init routines for each parameterization
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err !&lt; Output: error flag
+
+
+      err = 0
+
+      rayleighDampingCoef = 0.0
+
+      if (config_rayleigh_friction) then
+          rayleighFrictionOn = .true.
+          rayleighDampingCoef = config_rayleigh_damping_coeff
+      endif
+
+   !--------------------------------------------------------------------
+
+   end subroutine ocn_vel_forcing_rayleigh_init!}}}
+
+!***********************************************************************
+
+end module ocn_vel_forcing_rayleigh
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+! vim: foldmethod=marker

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_windstress.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_windstress.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_windstress.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -42,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: windStressOn
+   integer :: windStressOn
    real (kind=RKIND) :: rho_ref
 
 
@@ -106,8 +106,8 @@
 
       integer :: iEdge, nEdgesSolve, k
       integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: edgeMask
 
-
       !-----------------------------------------------------------------
       !
       ! call relevant routines for computing tendencies
@@ -118,25 +118,23 @@
 
       err = 0
 
-      if(.not.windStressOn) return
+      if(windStressOn == 0) return
 
       nEdgesSolve = grid % nEdgesSolve
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      edgeMask =&gt; grid % edgeMask % array
 
       do iEdge=1,nEdgesSolve
 
-        k = maxLevelEdgeTop(iEdge)
-
         ! efficiency note: it would be nice to avoid this
         ! if within a do.  This could be done with
         ! k =  max(maxLevelEdgeTop(iEdge),1)
         ! and then tend_u(1,iEdge) is just not used for land cells.
 
-        if (k&gt;0) then
+        do k = 1,min(maxLevelEdgeTop(iEdge),1)
            ! forcing in top layer only
-           tend(1,iEdge) =  tend(1,iEdge) &amp;
-              + u_src(1,iEdge)/rho_ref/h_edge(1,iEdge)
-        endif
+           tend(k,iEdge) =  tend(k,iEdge) + edgeMask(k, iEdge) * (u_src(k,iEdge)/rho_ref/h_edge(k,iEdge))
+        enddo
 
       enddo
 
@@ -171,13 +169,11 @@
 
       integer, intent(out) :: err !&lt; Output: error flag
 
-
-      windStressOn = .true.
+      windStressOn = 1
       rho_ref = 1000.0
 
       err = 0
 
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_forcing_windstress_init!}}}

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -18,6 +18,7 @@
 
    use mpas_grid_types
    use mpas_configure
+   use mpas_timer
    use ocn_vel_hmix_del2
    use ocn_vel_hmix_del4
 
@@ -46,7 +47,9 @@
    !
    !--------------------------------------------------------------------
 
+   type (timer_node), pointer :: del2Timer, del4Timer
 
+
 !***********************************************************************
 
 contains
@@ -119,8 +122,12 @@
       !
       !-----------------------------------------------------------------
 
+      call mpas_timer_start(&quot;del2&quot;, .false., del2Timer)
       call ocn_vel_hmix_del2_tend(grid, divergence, vorticity, tend, err1)
+      call mpas_timer_stop(&quot;del2&quot;, del2Timer)
+      call mpas_timer_start(&quot;del4&quot;, .false., del4Timer)
       call ocn_vel_hmix_del4_tend(grid, divergence, vorticity, tend, err2)
+      call mpas_timer_stop(&quot;del4&quot;, del4Timer)
 
       err = ior(err1, err2)
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del2.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del2.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del2.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,8 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: &amp;
-      hmixDel2On         !&lt; local flag to determine whether del2 chosen
+   integer ::  hmixDel2On  !&lt; integer flag to determine whether del2 chosen
 
    real (kind=RKIND) :: &amp;
       eddyVisc2,        &amp;!&lt; base eddy diffusivity for Laplacian
@@ -116,9 +114,9 @@
       integer :: iEdge, nEdgesSolve, cell1, cell2, vertex1, vertex2
       integer :: k
       integer, dimension(:), pointer :: maxLevelEdgeTop
-      integer, dimension(:,:), pointer :: cellsOnEdge, verticesOnEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, verticesOnEdge, edgeMask
 
-      real (kind=RKIND) :: u_diffusion
+      real (kind=RKIND) :: u_diffusion, invLength1, invLength2
       real (kind=RKIND), dimension(:), pointer :: meshScalingDel2, &amp;
               dcEdge, dvEdge
 
@@ -130,15 +128,14 @@
 
       err = 0
 
-      if(.not.hmixDel2On) return
+      if(hmixDel2On == 0) return
 
-      call mpas_timer_start(&quot;compute_tend_u-horiz mix-del2&quot;)
-      
       nEdgesSolve = grid % nEdgesSolve
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       verticesOnEdge =&gt; grid % verticesOnEdge % array
       meshScalingDel2 =&gt; grid % meshScalingDel2 % array
+      edgeMask =&gt; grid % edgeMask % array
       dcEdge =&gt; grid % dcEdge % array
       dvEdge =&gt; grid % dvEdge % array
 
@@ -148,25 +145,26 @@
          vertex1 = verticesOnEdge(1,iEdge)
          vertex2 = verticesOnEdge(2,iEdge)
 
+         invLength1 = 1.0 / dcEdge(iEdge)
+         invLength2 = 1.0 / dvEdge(iEdge)
+
          do k=1,maxLevelEdgeTop(iEdge)
 
             ! Here -( vorticity(k,vertex2) - vorticity(k,vertex1) ) / dvEdge(iEdge)
             ! is - </font>
<font color="black">abla vorticity pointing from vertex 2 to vertex 1, or equivalently 
             !    + k \times </font>
<font color="gray">abla vorticity pointing from cell1 to cell2.
 
-            u_diffusion = ( divergence(k,cell2)  - divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
+            u_diffusion = ( divergence(k,cell2)  - divergence(k,cell1) ) * invLength1 &amp;
                           -viscVortCoef &amp;
-                          *( vorticity(k,vertex2) - vorticity(k,vertex1) ) / dvEdge(iEdge)
+                          *( vorticity(k,vertex2) - vorticity(k,vertex1) ) * invLength2
 
             u_diffusion = meshScalingDel2(iEdge) * eddyVisc2 * u_diffusion
 
-            tend(k,iEdge) = tend(k,iEdge) + u_diffusion
+            tend(k,iEdge) = tend(k,iEdge) + edgeMask(k, iEdge) * u_diffusion
 
          end do
       end do
 
-      call mpas_timer_stop(&quot;compute_tend_u-horiz mix-del2&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_hmix_del2_tend!}}}
@@ -198,10 +196,10 @@
 
    err = 0
 
-   hmixDel2On = .false.
+   hmixDel2On = 0
 
    if ( config_h_mom_eddy_visc2 &gt; 0.0 ) then
-      hmixDel2On = .true.
+      hmixDel2On = 1
       eddyVisc2 = config_h_mom_eddy_visc2
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del4.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del4.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del4.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,7 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: &amp;
+   integer :: &amp;
       hmixDel4On       !&lt; local flag to determine whether del4 chosen
 
    real (kind=RKIND) :: &amp;
@@ -114,30 +113,30 @@
       !
       !-----------------------------------------------------------------
 
-      integer :: iEdge, nEdges, cell1, cell2, vertex1, vertex2, k
+      integer :: iEdge, cell1, cell2, vertex1, vertex2, k
       integer :: iCell, iVertex
-      integer :: nVertices, nVertLevels, nCells
+      integer :: nVertices, nVertLevels, nCells, nEdges, nEdgesSolve
 
       integer, dimension(:), pointer :: maxLevelEdgeTop, maxLevelVertexBot, &amp;
             maxLevelCell
-      integer, dimension(:,:), pointer :: cellsOnEdge, verticesOnEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, verticesOnEdge, edgeMask
 
 
-      real (kind=RKIND) :: u_diffusion, r
+      real (kind=RKIND) :: u_diffusion, invAreaCell1, invAreaCell2, invAreaTri1, &amp;
+            invAreaTri2, invDcEdge, invDvEdge, r_tmp, delsq_u
       real (kind=RKIND), dimension(:), pointer :: dcEdge, dvEdge, areaTriangle, &amp;
             meshScalingDel4, areaCell
 
       real (kind=RKIND), dimension(:,:), allocatable :: delsq_divergence, &amp;
-            delsq_u, delsq_circulation, delsq_vorticity
+            delsq_circulation, delsq_vorticity
 
       err = 0
 
-      if(.not.hmixDel4On) return
+      if(hmixDel4On == 0) return
 
-      call mpas_timer_start(&quot;compute_tend-horiz mix-del4&quot;)
-
       nCells = grid % nCells
       nEdges = grid % nEdges
+      nEdgesSolve = grid % nEdgessolve
       nVertices = grid % nVertices
       nVertLevels = grid % nVertLevels
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
@@ -150,102 +149,70 @@
       areaTriangle =&gt; grid % areaTriangle % array
       areaCell =&gt; grid % areaCell % array
       meshScalingDel4 =&gt; grid % meshScalingDel4 % array
+      edgeMask =&gt; grid % edgeMask % array
 
       allocate(delsq_divergence(nVertLevels, nCells+1))
-      allocate(delsq_u(nVertLevels, nEdges+1))
-      allocate(delsq_circulation(nVertLevels, nVertices+1))
       allocate(delsq_vorticity(nVertLevels, nVertices+1))
 
-      delsq_u(:,:) = 0.0
-      delsq_circulation(:,:) = 0.0
       delsq_vorticity(:,:) = 0.0
       delsq_divergence(:,:) = 0.0
 
-      ! Compute </font>
<font color="black">abla^2 u = </font>
<font color="black">abla divergence + k \times </font>
<font color="red">abla vorticity
-      do iEdge=1,grid % nEdges
+      do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
+
          vertex1 = verticesOnEdge(1,iEdge)
          vertex2 = verticesOnEdge(2,iEdge)
 
-         do k=1,maxLevelEdgeTop(iEdge)
+         invAreaTri1 = 1.0 / areaTriangle(vertex1)
+         invAreaTri2 = 1.0 / areaTriangle(vertex2)
 
-            delsq_u(k,iEdge) = &amp; 
-               ( divergence(k,cell2)  - divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
-               -viscVortCoef &amp;
-               *( vorticity(k,vertex2) - vorticity(k,vertex1)) / dvEdge(iEdge)
+         invAreaCell1 = 1.0 / areaCell(cell1)
+         invAreaCell2 = 1.0 / areaCell(cell2)
 
-         end do
-      end do
+         invDcEdge = 1.0 / dcEdge(iEdge)
+         invDvEdge = 1.0 / dvEdge(iEdge)
 
-      ! vorticity using </font>
<font color="red">abla^2 u
-      do iEdge=1,nEdges
-         vertex1 = verticesOnEdge(1,iEdge)
-         vertex2 = verticesOnEdge(2,iEdge)
          do k=1,maxLevelEdgeTop(iEdge)
-            delsq_circulation(k,vertex1) = delsq_circulation(k,vertex1) &amp;
-               - dcEdge(iEdge) * delsq_u(k,iEdge)
-            delsq_circulation(k,vertex2) = delsq_circulation(k,vertex2) &amp;
-               + dcEdge(iEdge) * delsq_u(k,iEdge)
-         end do
-      end do
-      do iVertex=1,nVertices
-         r = 1.0 / areaTriangle(iVertex)
-         do k=1,maxLevelVertexBot(iVertex)
-            delsq_vorticity(k,iVertex) = delsq_circulation(k,iVertex) * r
-         end do
-      end do
+            ! Compute </font>
<font color="black">abla^2 u = </font>
<font color="black">abla divergence + k \times </font>
<font color="red">abla vorticity
+            delsq_u =          ( divergence(k,cell2)  - divergence(k,cell1) ) * invDcEdge  &amp;
+                -viscVortCoef *( vorticity(k,vertex2) - vorticity(k,vertex1)) * invDvEdge 
 
-      ! Divergence using </font>
<font color="red">abla^2 u
-      do iEdge=1,nEdges
-         cell1 = cellsOnEdge(1,iEdge)
-         cell2 = cellsOnEdge(2,iEdge)
-         do k=1,maxLevelEdgeTop(iEdge)
-           delsq_divergence(k,cell1) = delsq_divergence(k,cell1) &amp;
-             + delsq_u(k,iEdge)*dvEdge(iEdge)
-           delsq_divergence(k,cell2) = delsq_divergence(k,cell2) &amp;
-             - delsq_u(k,iEdge)*dvEdge(iEdge)
+            ! vorticity using </font>
<font color="blue">abla^2 u
+            r_tmp = dcEdge(iEdge) * delsq_u
+            delsq_vorticity(k,vertex1) = delsq_vorticity(k,vertex1) - r_tmp * invAreaTri1
+            delsq_vorticity(k,vertex2) = delsq_vorticity(k,vertex2) + r_tmp * invAreaTri2
+
+            ! Divergence using </font>
<font color="red">abla^2 u
+            r_tmp = dvEdge(iEdge) * delsq_u
+            delsq_divergence(k, cell1) = delsq_divergence(k,cell1) + r_tmp * invAreaCell1
+            delsq_divergence(k, cell2) = delsq_divergence(k,cell2) - r_tmp * invAreaCell2
          end do
       end do
-      do iCell = 1,nCells
-         r = 1.0 / areaCell(iCell)
-         do k = 1,maxLevelCell(iCell)
-            delsq_divergence(k,iCell) = delsq_divergence(k,iCell) * r
-         end do
-      end do
 
       ! Compute - \kappa </font>
<font color="black">abla^4 u 
       ! as  </font>
<font color="black">abla div(</font>
<font color="black">abla^2 u) + k \times </font>
<font color="black">abla ( k \cross curl(</font>
<font color="gray">abla^2 u) )
-      do iEdge=1,grid % nEdgesSolve
+      do iEdge=1,nEdgesSolve
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
          vertex1 = verticesOnEdge(1,iEdge)
          vertex2 = verticesOnEdge(2,iEdge)
 
+         invDcEdge = 1.0 / dcEdge(iEdge)
+         invDvEdge = 1.0 / dvEdge(iEdge)
+         r_tmp = meshScalingDel4(iEdge) * eddyVisc4
+
          do k=1,maxLevelEdgeTop(iEdge)
-            delsq_u(k,iEdge) = &amp; 
-               ( divergence(k,cell2)  - divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
-              -( vorticity(k,vertex2) - vorticity(k,vertex1)) / dvEdge(iEdge)
+            u_diffusion = (delsq_divergence(k,cell2) - delsq_divergence(k,cell1)) * invDcEdge  &amp;
+                -viscVortCoef * (delsq_vorticity(k,vertex2) - delsq_vorticity(k,vertex1) ) * invDvEdge
 
-            u_diffusion = (  delsq_divergence(k,cell2) &amp;
-                           - delsq_divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
-                         -viscVortCoef &amp;
-                         *(  delsq_vorticity(k,vertex2) &amp;
-                           - delsq_vorticity(k,vertex1) ) / dvEdge(iEdge)
-
-            u_diffusion = meshScalingDel4(iEdge) * eddyVisc4 * u_diffusion
-
-            tend(k,iEdge) = tend(k,iEdge) - u_diffusion
+            tend(k,iEdge) = tend(k,iEdge) - edgeMask(k, iEdge) * u_diffusion * r_tmp
          end do
       end do
 
       deallocate(delsq_divergence)
-      deallocate(delsq_u)
-      deallocate(delsq_circulation)
       deallocate(delsq_vorticity)
 
-      call mpas_timer_stop(&quot;compute_tend-horiz mix-del4&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_hmix_del4_tend!}}}
@@ -276,10 +243,10 @@
 
    err = 0
 
-   hmixDel4On = .false.
+   hmixDel4On = 0
 
    if ( config_h_mom_eddy_visc4 &gt; 0.0 ) then
-      hmixDel4On = .true.
+      hmixDel4On = 1
       eddyVisc4 = config_h_mom_eddy_visc4
       if (config_visc_vorticity_term) then
          viscVortCoef = config_visc_vorticity_visc4_scale

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_pressure_grad.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_pressure_grad.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_pressure_grad.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -106,9 +106,10 @@
 
       integer :: nEdgesSolve, iEdge, k, cell1, cell2
       integer, dimension(:), pointer :: maxLevelEdgeTop
-      integer, dimension(:,:), pointer :: cellsOnEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, edgeMask
 
       real (kind=RKIND), dimension(:), pointer :: dcEdge
+      real (kind=RKIND) :: invdcEdge
 
       err = 0
 
@@ -116,14 +117,17 @@
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       dcEdge =&gt; grid % dcEdge % array
+      edgeMask =&gt; grid % edgeMask % array
 
       if (config_vert_grid_type.eq.'isopycnal') then
         do iEdge=1,nEdgesSolve
           cell1 = cellsOnEdge(1,iEdge)
           cell2 = cellsOnEdge(2,iEdge)
+          invdcEdge = 1.0 / dcEdge(iEdge)
+
           do k=1,maxLevelEdgeTop(iEdge)
              tend(k,iEdge) = tend(k,iEdge)     &amp;
-               - (pressure(k,cell2) - pressure(k,cell1))/dcEdge(iEdge)
+               - edgeMask(k,iEdge) *(pressure(k,cell2) - pressure(k,cell1))* invdcEdge
            end do
         enddo
       else 
@@ -134,18 +138,22 @@
         do iEdge=1,nEdgesSolve
           cell1 = cellsOnEdge(1,iEdge)
           cell2 = cellsOnEdge(2,iEdge)
+          invdcEdge = 1.0 / dcEdge(iEdge)
 
           do k=1,maxLevelEdgeTop(iEdge)
             tend(k,iEdge) = tend(k,iEdge)     &amp;
-              - rho0Inv*(  pressure(k,cell2) &amp;
-                         - pressure(k,cell1) )/dcEdge(iEdge) &amp;
-              - grho0Inv*  0.5*(rho(k,cell1)+rho(k,cell2)) &amp;
+              - edgeMask(k,iEdge) * rho0Inv*(  pressure(k,cell2) &amp;
+                         - pressure(k,cell1) )* invdcEdge &amp;
+              - edgeMask(k,iEdge) * grho0Inv*  0.5*(rho(k,cell1)+rho(k,cell2)) &amp;
                         *(  zMid(k,cell2) &amp;
-                          - zMid(k,cell1) )/dcEdge(iEdge)
+                          - zMid(k,cell1) )* invdcEdge
                       
           end do
 
-        enddo
+! 120112 mrp Doug's performance branch had:
+!         tend(k,iEdge) = tend(k,iEdge) - edgeMask(k,iEdge) * rho0Inv*(  pressure(k,cell2) - pressure(k,cell1) ) * invdcEdge
+       end do
+
       endif
 
 
@@ -192,6 +200,14 @@
       rho0Inv = 1.0/config_rho0
       grho0Inv = gravity/config_rho0
 
+! 120112 mrp Doug's performance branch had:
+!      if (config_vert_grid_type.eq.'isopycnal') then
+!        rho0Inv = 1.0
+!      elseif (config_vert_grid_type.eq.'zlevel') then
+!        rho0Inv = 1.0/config_rho0
+!      end if
+
+
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_pressure_grad_init!}}}

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_vadv.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_vadv.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_vadv.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -43,7 +43,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: velVadvOn
+   integer :: velVadvOn
 
 
 !***********************************************************************
@@ -107,13 +107,13 @@
       integer :: iEdge, nEdgesSolve, cell1, cell2, k
       integer :: nVertLevels
       integer, dimension(:), pointer :: maxLevelEdgeTop
-      integer, dimension(:,:), pointer :: cellsOnEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, edgeMask
 
-      real :: wTopEdge
-      real, dimension(:), allocatable :: w_dudzTopEdge
-      real, dimension(:), pointer :: zMidZLevel
+      real (kind=RKIND) :: wTopEdge
+      real (kind=RKIND), dimension(:), allocatable :: w_dudzTopEdge
+      real (kind=RKIND), dimension(:), pointer :: zMidZLevel
 
-      if(.not.velVadvOn) return
+      if(velVadvOn == 0) return
 
       err = 0
 
@@ -122,6 +122,7 @@
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       zMidZLevel =&gt; grid % zMidZLevel % array
+      edgeMask =&gt; grid % edgeMask % array
 
       allocate(w_dudzTopEdge(nVertLevels+1))
       w_dudzTopEdge = 0.0
@@ -141,8 +142,7 @@
         ! Average w*du/dz from vertical interface to vertical middle of cell
         do k=1,maxLevelEdgeTop(iEdge)
 
-          tend(k,iEdge) = tend(k,iEdge) &amp;
-             - 0.5 * (w_dudzTopEdge(k) + w_dudzTopEdge(k+1))
+          tend(k,iEdge) = tend(k,iEdge) - edgeMask(k, iEdge) * 0.5 * (w_dudzTopEdge(k) + w_dudzTopEdge(k+1))
         enddo
       enddo
       deallocate(w_dudzTopEdge)
@@ -178,10 +178,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      velVadvOn = .false.
+      velVadvOn = 0
 
       if (config_vert_grid_type.ne.'isopycnal') then
-          velVadvOn = .true.
+          velVadvOn = 1
       end if
 
    !--------------------------------------------------------------------

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -55,7 +55,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: explicitOn, implicitOn
+   integer :: explicitOn, implicitOn
 
 !***********************************************************************
 
@@ -197,10 +197,8 @@
 
       err = 0
 
-      if(implicitOn) return
+      if(implicitOn == 1) return
 
-      call mpas_timer_start(&quot;compute_tend_u-explicit vert mix&quot;)
-
       nEdgessolve = grid % nEdgesSolve
       nVertLevels = grid % nVertLevels
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
@@ -223,9 +221,6 @@
 
       end do
       deallocate(fluxVertTop)
-
-      call mpas_timer_stop(&quot;compute_tend_u-explicit vert mix&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_vmix_tend_explicit!}}}
@@ -303,7 +298,7 @@
 
       err = 0
 
-      if(explicitOn) return
+      if(explicitOn == 1) return
 
       nEdges = grid % nEdges
       nVertLevels = grid % nVertLevels
@@ -346,6 +341,8 @@
         end if
       end do
 
+      deallocate(A,C,uTemp)
+
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_vmix_tend_implicit!}}}
@@ -415,10 +412,8 @@
 
       err = 0
 
-      if(implicitOn) return
+      if(implicitOn == 1) return
 
-      call mpas_timer_start(&quot;compute_scalar_tend-explicit vert diff&quot;)
-
       nCellsSolve = grid % nCellsSolve
       nVertLevels = grid % nVertLevels
       num_tracers = size(tracers, dim=1)
@@ -453,9 +448,6 @@
 !print '(a,50e12.2)', 'tend_tr    ',tend_tr(3,1,1:maxLevelCell(iCell))
       enddo ! iCell loop
       deallocate(fluxVertTop)
-
-      call mpas_timer_stop(&quot;compute_scalar_tend-explicit vert diff&quot;)
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vmix_tend_explicit!}}}
@@ -526,7 +518,7 @@
 
       err = 0
 
-      if(explicitOn) return
+      if(explicitOn == 1) return
 
       nCells = grid % nCells
       nVertLevels = grid % nVertLevels
@@ -557,9 +549,9 @@
          tracers(:,1:maxLevelCell(iCell),iCell) = tracersTemp(:,1:maxLevelCell(iCell))
          tracers(:,maxLevelCell(iCell)+1:nVertLevels,iCell) = -1e34
       end do
+
       deallocate(A,C,tracersTemp)
 
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vmix_tend_implicit!}}}
@@ -596,12 +588,12 @@
 
       err = 0
 
-      explicitOn = .true.
-      implicitOn = .false.
+      explicitOn = 1
+      implicitOn = 0
 
       if(config_implicit_vertical_mix) then
-          explicitOn = .false.
-          implicitOn =.true.
+          explicitOn = 0
+          implicitOn = 1
       end if
 
       call ocn_vmix_coefs_const_init(err1)

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_const.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_const.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_const.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -47,7 +47,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: constViscOn, constDiffOn
+   integer :: constViscOn, constDiffOn
 
    real (kind=RKIND) :: constVisc, constDiff
 
@@ -121,7 +121,7 @@
       !-----------------------------------------------------------------
 
       err = 0
-      if((.not.constViscOn) .and. (.not.constDiffOn)) return
+      if((constViscOn == 0) .and. (constDiffOn == 0)) return
 
       vertViscTopOfEdge =&gt; d % vertViscTopOfEdge % array
       vertDiffTopOfCell =&gt; d % vertDiffTopOfCell % array
@@ -183,7 +183,7 @@
 
       err = 0
 
-      if(.not.constViscOn) return
+      if(constViscOn == 0) return
 
       vertViscTopOfEdge = constVisc
 
@@ -239,7 +239,7 @@
 
       err = 0
 
-      if(.not.constDiffOn) return
+      if(constDiffOn == 0) return
 
       vertDiffTopOfCell = constDiff
 
@@ -279,16 +279,16 @@
 
       err = 0
 
-      constViscOn = .false.
-      constDiffOn = .false.
+      constViscOn = 0
+      constDiffOn = 0
 
       if (config_vert_visc_type.eq.'const') then
-          constViscOn = .true.
+          constViscOn = 1
           constVisc = config_vert_visc
       endif
 
       if (config_vert_diff_type.eq.'const') then
-          constDiffOn = .true.
+          constDiffOn = 1
           constDiff = config_vert_diff
       endif
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_rich.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_rich.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_rich.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -26,6 +26,8 @@
    private
    save
 
+   type (timer_node), pointer :: richEOSTimer
+
    !--------------------------------------------------------------------
    !
    ! Public parameters
@@ -47,7 +49,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: richViscOn, richDiffOn
+   integer :: richViscOn, richDiffOn
 
 !***********************************************************************
 
@@ -122,7 +124,7 @@
       !-----------------------------------------------------------------
 
       err = 0
-      if((.not.richViscOn) .and. (.not.richDiffOn)) return
+      if((richViscOn == 0) .and. (richDiffOn == 0)) return
 
       indexT = s%index_temperature
       indexS = s%index_salinity
@@ -139,8 +141,10 @@
       rhoDisplaced =&gt; s % rhoDisplaced % array
       tracers =&gt; s % tracers % array
 
+      call mpas_timer_start(&quot;eos rich&quot;, .false., richEOSTimer)
       call ocn_equation_of_state_rho(s, grid, 0, 'relative', err)
       call ocn_equation_of_state_rho(s, grid, 1, 'relative', err)
+      call mpas_timer_stop(&quot;eos rich&quot;, richEOSTimer)
 
       call ocn_vmix_get_rich_numbers(grid, indexT, indexS, u, h, h_edge, &amp; 
                                   rho, rhoDisplaced, tracers, RiTopOfEdge, RiTopOfCell, err1)
@@ -212,7 +216,7 @@
 
       err = 0
 
-      if(.not.richViscOn) return
+      if(richViscOn == 0) return
 
       nEdges = grid % nEdges
 
@@ -318,7 +322,7 @@
 
       err = 0
 
-      if(.not.richDiffOn) return
+      if(richDiffOn == 0) return
 
       nCells = grid % nCells
 
@@ -440,7 +444,7 @@
 
       err = 0
 
-      if(.not.richViscOn .and. .not.richDiffOn) return
+      if((richViscOn == 0) .and. (richDiffOn == 0)) return
 
       nVertLevels = grid % nVertLevels
       nCells = grid % nCells
@@ -576,15 +580,15 @@
 
       err = 0
 
-      richViscOn = .false.
-      richDiffOn = .false.
+      richViscOn = 0
+      richDiffOn = 0
 
       if (config_vert_visc_type.eq.'rich') then
-          richViscOn = .true.
+          richViscOn = 1
       endif
 
       if (config_vert_diff_type.eq.'rich') then
-          richDiffOn = .true.
+          richDiffOn = 1
       endif
 
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -44,7 +44,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: tanhViscOn, tanhDiffOn
+   integer :: tanhViscOn, tanhDiffOn
 
 !***********************************************************************
 
@@ -115,7 +115,7 @@
       !-----------------------------------------------------------------
 
       err = 0
-      if((.not.tanhViscOn) .and. (.not.tanhDiffOn)) return
+      if((tanhViscOn == 0) .and. (tanhDiffOn == 0)) return
 
       vertViscTopOfEdge =&gt; d % vertViscTopOfEdge % array
       vertDiffTopOfCell =&gt; d % vertDiffTopOfCell % array
@@ -181,7 +181,7 @@
 
       err = 0
 
-      if(.not.tanhViscOn) return
+      if(tanhViscOn == 0) return
 
       nVertLevels = grid % nVertLevels
       zTopZLevel =&gt; grid % zTopZLevel % array
@@ -250,7 +250,7 @@
 
       err = 0
 
-      if(.not.tanhDiffOn) return
+      if(tanhDiffOn == 0) return
 
       nVertLevels = grid % nVertLevels
       zTopZLevel =&gt; grid % zTopZLevel % array
@@ -297,18 +297,18 @@
 
       err = 0
 
-      tanhViscOn = .false.
-      tanhDiffOn = .false.
+      tanhViscOn = 0
+      tanhDiffOn = 0
 
       if (config_vert_visc_type.eq.'tanh') then
-          tanhViscOn = .true.
+          tanhViscOn = 1
       endif
 
       if (config_vert_diff_type.eq.'tanh') then
-          tanhDiffOn = .true.
+          tanhDiffOn = 1
       endif
 
-      if(tanhViscOn .or. tanhDiffOn) then
+      if((tanhViscOn == 1) .or. (tanhDiffOn == 1)) then
          if (config_vert_grid_type.ne.'zlevel') then
             write(0,*) 'Abort: config_vert_diff_type.eq.tanh may only', &amp;
                        ' use config_vert_grid_type of zlevel at this time'

Modified: branches/ocean_projects/ale_vert_coord/src/core_sw/Registry
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_sw/Registry        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_sw/Registry        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,6 +1,6 @@
-#
-# namelist  type  namelist_record  name  default_value
-#
+%
+% namelist  type  namelist_record  name  default_value
+%
 namelist integer     sw_model  config_test_case             5
 namelist character   sw_model  config_time_integration      RK4
 namelist real        sw_model  config_dt                    172.8
@@ -30,9 +30,9 @@
 namelist logical     restart   config_do_restart            false
 namelist character   restart   config_restart_interval      none
 
-#
-# dim  type  name_in_file  name_in_code
-#
+%
+% dim  type  name_in_file  name_in_code
+%
 dim nCells nCells
 dim nEdges nEdges
 dim maxEdges maxEdges
@@ -46,9 +46,9 @@
 dim nVertLevels nVertLevels
 dim nTracers nTracers
 
-#
-# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
-#
+%
+% var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
+%
 var persistent text    xtime ( Time ) 2 ro xtime state - -
 
 var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
@@ -104,37 +104,37 @@
 var persistent real    fCell ( nCells ) 0 iro fCell mesh - -
 var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
-# Space needed for advection
+% Space needed for advection
 var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 o deriv_two mesh - -
 var persistent integer advCells ( TWENTYONE nCells ) 0 - advCells mesh - -
 
-# !! NOTE: the following arrays are needed to allow the use
-# !! of the module_advection.F w/o alteration
-# Space needed for deformation calculation weights
+% !! NOTE: the following arrays are needed to allow the use
+% !! of the module_advection.F w/o alteration
+% Space needed for deformation calculation weights
 var persistent real    defc_a ( maxEdges nCells ) 0 - defc_a mesh - -
 var persistent real    defc_b ( maxEdges nCells ) 0 - defc_b mesh - -
 var persistent real    kdiff ( nVertLevels nCells Time ) 0 - kdiff mesh - -
 
-# Arrays required for reconstruction of velocity field
+% Arrays required for reconstruction of velocity field
 var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
-# Boundary conditions: read from input, saved in restart and written to output
+% Boundary conditions: read from input, saved in restart and written to output
 var persistent integer boundaryEdge ( nVertLevels nEdges ) 0 iro boundaryEdge mesh - -
 var persistent integer boundaryVertex ( nVertLevels nVertices ) 0 iro boundaryVertex mesh - -
 var persistent integer boundaryCell ( nVertLevels nCells ) 0 iro boundaryCell mesh - -
 var persistent real    u_src ( nVertLevels nEdges ) 0 iro u_src mesh - -
 
-# Prognostic variables: read from input, saved in restart, and written to output
+% Prognostic variables: read from input, saved in restart, and written to output
 var persistent real    u ( nVertLevels nEdges Time ) 2 iro u state - -
 var persistent real    h ( nVertLevels nCells Time ) 2 iro h state - -
 var persistent real    tracers ( nTracers nVertLevels nCells Time ) 2 iro tracers state - -
 
-# Tendency variables
+% Tendency variables
 var persistent real    tend_u ( nVertLevels nEdges Time ) 1 - u tend - -
 var persistent real    tend_h ( nVertLevels nCells Time ) 1 - h tend - -
 var persistent real    tend_tracers ( nTracers nVertLevels nCells Time ) 1 - tracers tend - -
 
-# Diagnostic fields: only written to output
+% Diagnostic fields: only written to output
 var persistent real    v ( nVertLevels nEdges Time ) 2 o v state - -
 var persistent real    divergence ( nVertLevels nCells Time ) 2 o divergence state - -
 var persistent real    vorticity ( nVertLevels nVertices Time ) 2 o vorticity state - -
@@ -150,7 +150,7 @@
 var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 2 o uReconstructZonal state - -
 var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 2 o uReconstructMeridional state - -
 
-# Other diagnostic variables: neither read nor written to any files
+% Other diagnostic variables: neither read nor written to any files
 var persistent real    vh ( nVertLevels nEdges Time ) 2 - vh state - -
 var persistent real    circulation ( nVertLevels nVertices Time ) 2 - circulation state - -
 var persistent real    gradPVt ( nVertLevels nEdges Time ) 2 - gradPVt state - -

Modified: branches/ocean_projects/ale_vert_coord/src/core_sw/mpas_sw_advection.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_sw/mpas_sw_advection.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_sw/mpas_sw_advection.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,6 @@
 module sw_advection
 
+   use mpas_kind_types
    use mpas_grid_types
    use mpas_configure
    use mpas_constants
@@ -117,7 +118,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -390,7 +391,7 @@
    ! Computes the angle between arcs AB and AC, given points A, B, and C
    ! Equation numbers w.r.t. http://mathworld.wolfram.com/SphericalTrigonometry.html
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)
+   real (kind=RKIND) function sphere_angle(ax, ay, az, bx, by, bz, cx, cy, cz)
    
       implicit none
    
@@ -410,9 +411,9 @@
       real (kind=RKIND) :: s                ! Semiperimeter of the triangle
       real (kind=RKIND) :: sin_angle
    
-      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0),-1.0))      ! Eqn. (3)
-      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0),-1.0))      ! Eqn. (2)
-      c = acos(max(min(ax*bx + ay*by + az*bz,1.0),-1.0))      ! Eqn. (1)
+      a = acos(max(min(bx*cx + by*cy + bz*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (3)
+      b = acos(max(min(ax*cx + ay*cy + az*cz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (2)
+      c = acos(max(min(ax*bx + ay*by + az*bz,1.0_RKIND),-1.0_RKIND))      ! Eqn. (1)
    
       ABx = bx - ax
       ABy = by - ay
@@ -428,12 +429,12 @@
    
       s = 0.5*(a + b + c)
 !      sin_angle = sqrt((sin(s-b)*sin(s-c))/(sin(b)*sin(c)))   ! Eqn. (28)
-      sin_angle = sqrt(min(1.,max(0.,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
+      sin_angle = sqrt(min(1.0_RKIND,max(0.0_RKIND,(sin(s-b)*sin(s-c))/(sin(b)*sin(c)))))   ! Eqn. (28)
    
       if ((Dx*ax + Dy*ay + Dz*az) &gt;= 0.0) then
-         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle =  2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       else
-         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0),-1.0))
+         sphere_angle = -2.0 * asin(max(min(sin_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
    end function sphere_angle
@@ -445,7 +446,7 @@
    ! Computes the angle between vectors AB and AC, given points A, B, and C, and
    !   a vector (u,v,w) normal to the plane.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)
+   real (kind=RKIND) function plane_angle(ax, ay, az, bx, by, bz, cx, cy, cz, u, v, w)
    
       implicit none
    
@@ -480,9 +481,9 @@
       cos_angle = (ABx*ACx + ABy*ACy + ABz*ACz) / (mAB * mAC)
    
       if ((Dx*u + Dy*v + Dz*w) &gt;= 0.0) then
-         plane_angle =  acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle =  acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       else
-         plane_angle = -acos(max(min(cos_angle,1.0),-1.0))
+         plane_angle = -acos(max(min(cos_angle,1.0_RKIND),-1.0_RKIND))
       end if
    
    end function plane_angle
@@ -495,7 +496,7 @@
    !    B=(bx, by, bz). It is assumed that both A and B lie on the surface of the
    !    same sphere centered at the origin.
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   real function arc_length(ax, ay, az, bx, by, bz)
+   real (kind=RKIND) function arc_length(ax, ay, az, bx, by, bz)
    
       implicit none
    
@@ -838,7 +839,7 @@
 
             theta_abs(iCell) =  pii/2. - sphere_angle( xc(1), yc(1), zc(1),  &amp;
                                                        xc(2), yc(2), zc(2),  &amp;
-                                                       0.,    0.,    1.      ) 
+                                                       0.0_RKIND, 0.0_RKIND, 1.0_RKIND ) 
 
 ! angles from cell center to neighbor centers (thetav)
 
@@ -890,10 +891,10 @@
          do i=2,n-1
             ip1 = i+1
             if (ip1 == n) ip1 = 1
-            thetat(i) = plane_angle( 0.,0.,0.,  &amp;
-                                     xp(i)-xp(i-1), yp(i)-yp(i-1), 0.,  &amp;
-                                     xp(ip1)-xp(i), yp(ip1)-yp(i), 0.,  &amp;
-                                     0., 0., 1.)
+            thetat(i) = plane_angle( 0.0_RKIND, 0.0_RKIND, 0.0_RKIND,  &amp;
+                                     xp(i)-xp(i-1), yp(i)-yp(i-1), 0.0_RKIND,  &amp;
+                                     xp(ip1)-xp(i), yp(ip1)-yp(i), 0.0_RKIND,  &amp;
+                                     0.0_RKIND, 0.0_RKIND, 1.0_RKIND)
             thetat(i) = thetat(i) + thetat(i-1)
          end do
 

Modified: branches/ocean_projects/ale_vert_coord/src/core_sw/mpas_sw_time_integration.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/core_sw/mpas_sw_time_integration.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/core_sw/mpas_sw_time_integration.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -123,10 +123,10 @@
                                             block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
 
            if (config_h_mom_eddy_visc4 &gt; 0.0) then
-              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % divergence % array(:,:), &amp;
+              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, provis % divergence % array(:,:), &amp;
                                                block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % state % time_levs(2) % state % vorticity % array(:,:), &amp;
+              call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, provis % vorticity % array(:,:), &amp;
                                                block % mesh % nVertLevels, block % mesh % nVertices, &amp;
                                                block % parinfo % verticesToSend, block % parinfo % verticesToRecv)
            end if

Modified: branches/ocean_projects/ale_vert_coord/src/driver/mpas_subdriver.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/driver/mpas_subdriver.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/driver/mpas_subdriver.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -19,15 +19,13 @@
       real (kind=RKIND) :: dt
       character(len=32) :: timeStamp
 
-      call mpas_timer_start(&quot;total time&quot;)
-      call mpas_timer_start(&quot;initialize&quot;)
-
-
       !
       ! Initialize infrastructure
       !
       call mpas_framework_init(dminfo, domain)
 
+      call mpas_timer_start(&quot;total time&quot;)
+      call mpas_timer_start(&quot;initialize&quot;)
 
       call mpas_input_state_for_domain(domain)
 
@@ -68,6 +66,8 @@
    
       implicit none
 
+      call mpas_timer_start(&quot;finalize&quot;)
+
       !
       ! Finalize output streams
       !
@@ -78,11 +78,11 @@
       ! Finalize core
       !
       call mpas_core_finalize(domain)
+      call mpas_timer_stop(&quot;finalize&quot;)
 
       call mpas_timer_stop(&quot;total time&quot;)
       call mpas_timer_write()
 
-
       !
       ! Finalize infrastructure
       !

Modified: branches/ocean_projects/ale_vert_coord/src/framework/Makefile
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/Makefile        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/Makefile        2012-01-17 21:44:00 UTC (rev 1384)
@@ -4,8 +4,10 @@
    ZOLTANOBJ = mpas_zoltan_interface.o
 endif
 
-OBJS = mpas_framework.o \
+OBJS = mpas_kind_types.o \
+       mpas_framework.o \
        mpas_timer.o \
+           mpas_counter.o \
        mpas_timekeeping.o \
        mpas_configure.o \
        mpas_constants.o \
@@ -28,10 +30,18 @@
 
 mpas_configure.o: mpas_dmpar.o
 
+mpas_constants.o: mpas_kind_types.o
+
 mpas_grid_types.o: mpas_dmpar.o
 
-mpas_dmpar.o: mpas_sort.o streams.o
+mpas_dmpar.o: mpas_sort.o streams.o mpas_kind_types.o
 
+mpas_sort.o: mpas_kind_types.o
+
+mpas_timekeeping.o: mpas_kind_types.o
+
+mpas_timer.o: mpas_kind_types.o
+
 mpas_block_decomp.o: mpas_grid_types.o mpas_hash.o mpas_configure.o
 
 mpas_io_input.o: mpas_grid_types.o mpas_dmpar.o mpas_block_decomp.o mpas_sort.o mpas_configure.o mpas_timekeeping.o $(ZOLTANOBJ)

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_constants.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_constants.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_constants.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,7 @@
 module mpas_constants
 
+   use mpas_kind_types
+
    real (kind=RKIND), parameter :: pii     = 3.141592653589793   
    real (kind=RKIND), parameter :: a       = 6371229.0
    real (kind=RKIND), parameter :: omega   = 7.29212e-5

Copied: branches/ocean_projects/ale_vert_coord/src/framework/mpas_counter.F (from rev 1357, branches/ocean_projects/performance/src/framework/mpas_counter.F)
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_counter.F                                (rev 0)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_counter.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -0,0 +1,171 @@
+      module mpas_counter
+
+        use mpas_grid_types
+        use mpas_dmpar
+
+        implicit none
+        save
+
+#ifdef _PAPI
+        include 'f90papi.h'
+#endif
+
+        integer :: event_set
+        integer :: num_counters
+        integer, dimension(:), allocatable :: counters
+        character (len=72), dimension(:), allocatable :: counter_names
+
+        type (dm_info), pointer :: domain_info
+
+        public :: mpas_counter_start, &amp;
+                  mpas_counter_stop, &amp;
+                  mpas_counter_reset, &amp;
+                  mpas_counter_write, &amp;
+                  mpas_counter_init
+
+        contains
+
+        subroutine mpas_counter_start()!{{{
+        integer :: err
+
+#ifdef _PAPI
+          call PAPIF_start(event_set, err)
+
+          if ( err .ne. PAPI_OK ) then
+            print *,'Error in mpas_counter_start'
+            call mpas_dmpar_abort(domain_info)
+          endif
+#endif
+        end subroutine mpas_counter_start!}}}
+
+        subroutine mpas_counter_stop()!{{{
+        integer :: err
+
+#ifdef _PAPI
+          call PAPIF_stop(event_set, counters, err)
+
+          if ( err .ne. PAPI_OK ) then
+            print *,'Error in mpas_counter_stop'
+            call mpas_dmpar_abort(domain_info)
+          endif
+#endif
+        end subroutine mpas_counter_stop!}}}
+
+        subroutine mpas_counter_reset()!{{{
+          integer :: err
+        
+#ifdef _PAPI
+          call PAPIF_reset(event_set, err)
+
+          if ( err .ne. PAPI_OK ) then
+            print *,'Error in mpas_counter_reset'
+            call mpas_dmpar_abort(domain_info)
+          endif
+#endif
+        end subroutine mpas_counter_reset!}}}
+
+        subroutine mpas_counter_write()!{{{
+          integer :: i
+
+          write(*,*) ''
+          write(*,*) ''
+
+          do i = 1, num_counters
+            write(*,'(a15, i15)') counter_names(i), counters(i)
+          end do
+
+        end subroutine mpas_counter_write!}}}
+
+        subroutine mpas_counter_init(domain)!{{{
+          type (domain_type), intent(in), optional :: domain
+
+          integer :: err, event_code, tmp_counters, i
+          integer, dimension(:), allocatable :: event_list
+
+          num_counters = 0
+
+          if( present(domain) ) then
+              domain_info =&gt; domain % dminfo
+          endif
+
+#ifdef _PAPI
+          err = PAPI_VER_CURRENT
+          call PAPIF_library_init(err)
+          if (err .ne. PAPI_VER_CURRENT) then
+              print *, 'Error initializing the PAPI Library', err
+              call mpas_dmpar_abort(domain % dminfo)
+          end if
+
+          ! Setup papi event set and counters
+          event_set = PAPI_NULL
+
+          call PAPIF_create_eventset(event_set, err)
+
+          if ( err .ne. PAPI_OK ) then
+              print *, 'Error in PAPIF_create_eventset', err
+              call mpas_dmpar_abort(domain % dminfo)
+          end if
+
+          ! L1 Total Cache Misses
+          event_code = PAPI_L1_TCM
+
+          call PAPIF_add_event(event_set, event_code, err)
+
+          if ( err == PAPI_OK) then
+              num_counters = num_counters + 1
+          else
+              print *,'Error in add PAPI_L1_TCM', err
+          end if
+
+          ! L2 Total Cache Misses
+          event_code = PAPI_L2_TCM
+
+          call PAPIF_add_event(event_set, event_code, err)
+
+          if ( err == PAPI_OK) then
+              num_counters = num_counters + 1
+          else
+              print *,'Error in add PAPI_L2_TCM', err
+          end if
+
+          ! L3 Total Cache Misses
+          event_code = PAPI_L3_TCM
+
+          call PAPIF_add_event(event_set, event_code, err)
+
+          if ( err == PAPI_OK) then
+              num_counters = num_counters + 1
+          else
+              print *,'Error in add PAPI_L3_TCM', err
+          end if
+
+          ! Mispredicted Branches
+          event_code = PAPI_BR_MSP
+
+          call PAPIF_add_event(event_set, event_code, err)
+
+          if ( err == PAPI_OK) then
+              num_counters = num_counters + 1
+          else
+              print *,'Error in add PAPI_BR_MSP', err
+          end if
+
+
+          allocate(counters(num_counters))
+          allocate(event_list(num_counters))
+          allocate(counter_names(num_counters))
+
+          call PAPIF_list_events(event_set, event_list, num_counters, err)
+
+          do i = 1, num_counters
+            call PAPIF_event_code_to_name(event_list(i), counter_names(i), err)
+          enddo
+
+          deallocate(event_list)
+#endif
+
+        end subroutine mpas_counter_init!}}}
+
+      end module mpas_counter
+
+! vim: foldmethod=marker et ts=2

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_dmpar.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_dmpar.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_dmpar.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,15 +1,16 @@
 module mpas_dmpar
 
+   use mpas_kind_types
    use mpas_sort
 
 #ifdef _MPI
 include 'mpif.h'
    integer, parameter :: MPI_INTEGERKIND = MPI_INTEGER
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+   integer, parameter :: MPI_REALKIND = MPI_REAL
+#else
    integer, parameter :: MPI_REALKIND = MPI_DOUBLE_PRECISION
-#else
-   integer, parameter :: MPI_REALKIND = MPI_REAL
 #endif
 #endif
 
@@ -19,6 +20,7 @@
 
    type dm_info
       integer :: nprocs, my_proc_id, comm, info
+      logical :: using_external_comm
    end type dm_info
 
 
@@ -45,23 +47,30 @@
    contains
 
 
-   subroutine mpas_dmpar_init(dminfo)
+   subroutine mpas_dmpar_init(dminfo, mpi_comm)
 
       implicit none
 
       type (dm_info), intent(inout) :: dminfo
+      integer, intent(in), optional :: mpi_comm     ! Optional: externally-supplied MPI communicator
 
 #ifdef _MPI
       integer :: mpi_rank, mpi_size
       integer :: mpi_ierr
 
+      if (present(mpi_comm)) then
+         dminfo % comm = mpi_comm
+         dminfo % using_external_comm = .true.
+      else
+         call MPI_Init(mpi_ierr)
+         dminfo % comm = MPI_COMM_WORLD
+         dminfo % using_external_comm = .false.
+      end if
+
       ! Find out our rank and the total number of processors
-      call MPI_Init(mpi_ierr)
-      call MPI_Comm_rank(MPI_COMM_WORLD, mpi_rank, mpi_ierr)
-      call MPI_Comm_size(MPI_COMM_WORLD, mpi_size, mpi_ierr)
+      call MPI_Comm_rank(dminfo % comm, mpi_rank, mpi_ierr)
+      call MPI_Comm_size(dminfo % comm, mpi_size, mpi_ierr)
 
-      dminfo % comm = MPI_COMM_WORLD
-
       dminfo % nprocs = mpi_size
       dminfo % my_proc_id = mpi_rank
 
@@ -75,6 +84,7 @@
       dminfo % comm = 0
       dminfo % my_proc_id = IO_NODE
       dminfo % nprocs = 1
+      dminfo % using_external_comm = .false.
 #endif
 
    end subroutine mpas_dmpar_init
@@ -89,7 +99,9 @@
 #ifdef _MPI
       integer :: mpi_ierr
 
-      call MPI_Finalize(mpi_ierr)
+      if (.not. dminfo % using_external_comm) then
+         call MPI_Finalize(mpi_ierr)
+      end if
 #endif
 
    end subroutine mpas_dmpar_finalize

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_io_input.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_io_input.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_io_input.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1226,10 +1226,10 @@
 
 #include &quot;input_field0dreal.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start1, count1, field % scalar)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start1, count1, field % scalar)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start1, count1, field % scalar)
 #endif
  
    end subroutine mpas_io_input_field0d_real
@@ -1261,10 +1261,10 @@
  
 #include &quot;input_field1dreal.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start1, count1, field % array)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start1, count1, field % array)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start1, count1, field % array)
 #endif
  
    end subroutine mpas_io_input_field1d_real
@@ -1290,10 +1290,10 @@
  
 #include &quot;input_field2dreal.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start2, count2, field % array)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start2, count2, field % array)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start2, count2, field % array)
 #endif
 
    end subroutine mpas_io_input_field2d_real
@@ -1321,10 +1321,10 @@
  
 #include &quot;input_field3dreal.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start3, count3, field % array)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start3, count3, field % array)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start3, count3, field % array)
 #endif
 
    end subroutine mpas_io_input_field3d_real
@@ -1348,10 +1348,10 @@
  
 #include &quot;input_field0dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start1, count1, field % scalar)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start1, count1, field % scalar)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start1, count1, field % scalar)
 #endif
 
    end subroutine mpas_io_input_field0d_real_time
@@ -1377,10 +1377,10 @@
  
 #include &quot;input_field1dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start2, count2, field % array)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start2, count2, field % array)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start2, count2, field % array)
 #endif
 
    end subroutine mpas_io_input_field1d_real_time
@@ -1408,10 +1408,10 @@
  
 #include &quot;input_field2dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start3, count3, field % array)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start3, count3, field % array)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start3, count3, field % array)
 #endif
 
    end subroutine mpas_io_input_field2d_real_time
@@ -1441,10 +1441,10 @@
  
 #include &quot;input_field3dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#if SINGLE_PRECISION
+      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start4, count4, field % array)
+#else
       nferr = nf_get_vara_double(input_obj % rd_ncid, varID, start4, count4, field % array)
-#else
-      nferr = nf_get_vara_real(input_obj % rd_ncid, varID, start4, count4, field % array)
 #endif
 
    end subroutine mpas_io_input_field3d_real_time

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_io_output.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_io_output.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_io_output.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -429,10 +429,10 @@
 
 #include &quot;output_field0dreal.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start1, count1, field % scalar)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start1, count1, field % scalar)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start1, count1, field % scalar)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -458,10 +458,10 @@
 
 #include &quot;output_field1dreal.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, VarID, start1, count1, field % array)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, VarID, start1, count1, field % array)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, VarID, start1, count1, field % array)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -489,10 +489,10 @@
 
 #include &quot;output_field2dreal.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start2, count2, field % array)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start2, count2, field % array)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start2, count2, field % array)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -522,10 +522,10 @@
 
 #include &quot;output_field3dreal.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start3, count3, field % array)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start3, count3, field % array)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start3, count3, field % array)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -551,10 +551,10 @@
 
 #include &quot;output_field0dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start1, count1, field % scalar)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start1, count1, field % scalar)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start1, count1, field % scalar)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -582,10 +582,10 @@
 
 #include &quot;output_field1dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start2, count2, field % array)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start2, count2, field % array)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start2, count2, field % array)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -615,10 +615,10 @@
 
 #include &quot;output_field2dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start3, count3, field % array)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start3, count3, field % array)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start3, count3, field % array)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)
@@ -650,10 +650,10 @@
 
 #include &quot;output_field3dreal_time.inc&quot;
 
-#if (RKIND == 8)
+#ifdef SINGLE_PRECISION
+      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start4, count4, field % array)
+#else
       nferr = nf_put_vara_double(output_obj % wr_ncid, varID, start4, count4, field % array)
-#else
-      nferr = nf_put_vara_real(output_obj % wr_ncid, varID, start4, count4, field % array)
 #endif
  
       nferr = nf_sync(output_obj % wr_ncid)

Copied: branches/ocean_projects/ale_vert_coord/src/framework/mpas_kind_types.F (from rev 1357, branches/ocean_projects/performance/src/framework/mpas_kind_types.F)
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_kind_types.F                                (rev 0)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_kind_types.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -0,0 +1,15 @@
+module mpas_kind_types
+
+#ifdef SINGLE_PRECISION
+   integer, parameter :: RKIND  = selected_real_kind(6)
+#else
+   integer, parameter :: RKIND  = selected_real_kind(12)
+#endif
+
+   contains
+
+   subroutine dummy_kinds()
+
+   end subroutine dummy_kinds
+
+end module mpas_kind_types

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_sort.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_sort.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_sort.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,7 @@
 module mpas_sort
 
+   use mpas_kind_types
+
    interface quicksort
       module procedure mpas_quicksort_int
       module procedure mpas_quicksort_real

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_timekeeping.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_timekeeping.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_timekeeping.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,6 @@
 module mpas_timekeeping
 
+   use mpas_kind_types
    use ESMF_BaseMod
    use ESMF_Stubs
    use ESMF_CalendarMod

Modified: branches/ocean_projects/ale_vert_coord/src/framework/mpas_timer.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/framework/mpas_timer.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/framework/mpas_timer.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,8 @@
       module mpas_timer
 
+        use mpas_grid_types
+        use mpas_dmpar
+
         implicit none
         save
 !       private
@@ -8,9 +11,9 @@
         include 'f90papi.h'
 #endif
 
-#ifdef _MPI
-        include 'mpif.h'
-#endif
+!#ifdef _MPI
+!        include 'mpif.h'
+!#endif
 
         type timer_node
           character (len=72) :: timer_name
@@ -18,15 +21,19 @@
           integer :: levels, calls
           real (kind=RKIND) :: start_time, end_time, total_time
           real (kind=RKIND) :: max_time, min_time, avg_time
+          real (kind=RKIND) :: efficiency
           type (timer_node), pointer :: next
         end type timer_node
 
         type (timer_node), pointer :: all_timers
-        integer :: levels
+        integer :: levels, synced
 
+        type (dm_info), pointer :: domain_info
+
         public :: mpas_timer_start, &amp;
                   mpas_timer_stop, &amp;
-                  mpas_timer_write
+                  mpas_timer_write, &amp;
+                  mpas_timer_init
 
         contains
 
@@ -85,6 +92,7 @@
               current%min_time = 100000000.0
               current%avg_time = 0.0
               current%calls = 0
+              current%efficiency = 0.0
             else
               current =&gt; timer_ptr
             endif
@@ -112,6 +120,7 @@
             current%min_time = 100000000.0
             current%avg_time = 0.0
             current%calls = 0
+            current%efficiency = 0.0
           endif
 
           if((timer_added .or. timer_found) .and. (.not.current%running)) then
@@ -230,6 +239,10 @@
 
           total_found = .false.
 
+          if(associated(domain_info) .and. synced == 0) then
+            call mpas_timer_sync()
+          endif
+
           if(present(timer_ptr) .and. (.not.present(total_ptr))) then
             print *,'timer_write :: timer_ptr valid, but total_ptr is not assigned.'
             stop
@@ -251,7 +264,7 @@
               percent = timer_ptr%total_time/total_ptr%total_time
             endif
 
-            write(*,'(i2, 1x, a35, f15.5, i10, 3f15.5, f8.2)') timer_ptr%levels, tname(1:timer_ptr%levels)//timer_ptr%timer_name, timer_ptr%total_time, timer_ptr%calls, timer_ptr%min_time, timer_ptr%max_time, timer_ptr%avg_time, percent
+            write(*,'(i2, 1x, a35, f15.5, i10, 3f15.5, 2f8.2)') timer_ptr%levels, tname(1:timer_ptr%levels)//timer_ptr%timer_name, timer_ptr%total_time, timer_ptr%calls, timer_ptr%min_time, timer_ptr%max_time, timer_ptr%avg_time, percent, timer_ptr%efficiency
             return
           endif
 
@@ -271,7 +284,7 @@
             stop
           end if
 
-          write(*,'(3x, a10, 24x, a15, a10, a13, a15, a15, a15)') 'timer_name', 'total', 'calls', 'min', 'max', 'avg', 'percent'
+          write(*,'(3x, a10, 24x, a15, a10, a13, a15, a15, a12, a12)') 'timer_name', 'total', 'calls', 'min', 'max', 'avg', 'percent', 'efficiency'
           write(*,'(i2, 1x, a35, f15.5, i10, 3f15.5)') total%levels, total%timer_name, total%total_time, total%calls, total%min_time, total%max_time, total%avg_time
 
           current =&gt; all_timers
@@ -290,6 +303,57 @@
 
         end subroutine mpas_timer_write!}}}
 
+        subroutine mpas_timer_init(domain)!{{{
+          type (domain_type), intent(in), optional :: domain
+
+          if( present(domain) ) then
+              domain_info =&gt; domain % dminfo
+          endif
+
+          synced = 0
+
+        end subroutine mpas_timer_init!}}}
+
+        subroutine mpas_timer_sync()!{{{
+          type (timer_node), pointer :: current
+          real (kind=RKIND) :: all_total_time, all_max_time, all_min_time, all_ave_time
+
+          current =&gt; all_timers
+
+          sync_timers: do while(associated(current))
+            all_total_time = 0.0
+            all_ave_time = 0.0
+            all_max_time = 0.0
+            all_min_time = 0.0
+
+            call mpas_dmpar_max_real(domain_info, current % total_time, all_total_time)
+            call mpas_dmpar_sum_real(domain_info, current % total_time, all_ave_time)
+            
+            all_ave_time = all_ave_time / domain_info % nprocs
+
+            current % total_time = all_total_time
+
+#ifdef _MPI
+            current % efficiency = all_ave_time / all_total_time
+#else
+            current % efficiency = 1.0
+#endif
+
+            current % avg_time = current % total_time / current % calls
+
+            call mpas_dmpar_max_real(domain_info, current % max_time, all_max_time)
+            current % max_time = all_max_time
+
+            call mpas_dmpar_min_real(domain_info, current % min_time, all_min_time)
+            current % min_time = all_min_time
+
+            current =&gt; current % next
+          end do sync_timers
+
+          synced = 1
+
+        end subroutine mpas_timer_sync!}}}
+
       end module mpas_timer
 
 ! vim: foldmethod=marker et ts=2

Modified: branches/ocean_projects/ale_vert_coord/src/operators/mpas_spline_interpolation.F
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/operators/mpas_spline_interpolation.F        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/operators/mpas_spline_interpolation.F        2012-01-17 21:44:00 UTC (rev 1384)
@@ -1,5 +1,7 @@
 module mpas_spline_interpolation
 
+  use mpas_kind_types
+
   implicit none
 
   private

Modified: branches/ocean_projects/ale_vert_coord/src/registry/parse.c
===================================================================
--- branches/ocean_projects/ale_vert_coord/src/registry/parse.c        2012-01-17 19:22:35 UTC (rev 1383)
+++ branches/ocean_projects/ale_vert_coord/src/registry/parse.c        2012-01-17 21:44:00 UTC (rev 1384)
@@ -19,23 +19,21 @@
    struct group_list * groups;
 
    if (argc != 2) {
-      fprintf(stderr,&quot;</font>
<font color="black">Usage: %s filename</font>
<font color="black"></font>
<font color="red">&quot;, argv[0]);
-      return 1;
+      fprintf(stderr,&quot;Reading registry file from standard input</font>
<font color="red">&quot;);
+      regfile = stdin;
    }
-
-   if (regfile = fopen(argv[1], &quot;r&quot;)) {
-      nls = NULL;
-      dims = NULL;
-      vars = NULL;
-      if (parse_reg(regfile, &amp;nls, &amp;dims, &amp;vars, &amp;groups)) {
-         return 1;
-      }
-   }   
-   else {
+   else if (!(regfile = fopen(argv[1], &quot;r&quot;))) {
       fprintf(stderr,&quot;</font>
<font color="black">Error: Could not open file %s for reading.</font>
<font color="black"></font>
<font color="gray">&quot;, argv[1]);
       return 1;
    }   
 
+   nls = NULL;
+   dims = NULL;
+   vars = NULL;
+   if (parse_reg(regfile, &amp;nls, &amp;dims, &amp;vars, &amp;groups)) {
+      return 1;
+   }
+
    sort_vars(vars);
    sort_group_vars(groups);
 
@@ -244,6 +242,7 @@
             dimlist_ptr = dimlist_ptr-&gt;next;
          }
       }
+      fprintf(stdout,&quot;</font>
<font color="gray">&quot;);
    } 
 
    nls_ptr = *nls;
@@ -274,18 +273,19 @@
    
    do { c = getc(regfile); } while (((char)c == ' ' || (char)c == '</font>
<font color="red">' || (char)c == '\t') &amp;&amp; c != EOF);
 
-   while ((char)c == '#') {
+   while ((char)c == '%') {
       do { c = getc(regfile); } while ((char)c != '</font>
<font color="black">' &amp;&amp; c != EOF);
       do { c = getc(regfile); } while (((char)c == ' ' || (char)c == '</font>
<font color="red">' || (char)c == '\t') &amp;&amp; c != EOF);
    };
-   while((char)c != ' ' &amp;&amp; (char)c != '</font>
<font color="blue">' &amp;&amp; (char)c != '\t' &amp;&amp; c != EOF &amp;&amp; (char)c != '#') {
+   while((char)c != ' ' &amp;&amp; (char)c != '</font>
<font color="red">' &amp;&amp; (char)c != '\t' &amp;&amp; c != EOF &amp;&amp; (char)c != '%') {
       word[i++] = (char)c; 
       c = (char)getc(regfile);
    } 
    word[i] = '\0';
 
-   if ((char)c == '#') do { c = getc(regfile); } while ((char)c != '</font>
<font color="blue">' &amp;&amp; c != EOF);
+   if ((char)c == '%') do { c = getc(regfile); } while ((char)c != '</font>
<font color="blue">' &amp;&amp; c != EOF);
 
+   fprintf(stdout,&quot;%s &quot;,word);
    return c;
 }
 

</font>
</pre>