<p><b>qchen3@fsu.edu</b> 2012-02-02 12:34:14 -0700 (Thu, 02 Feb 2012)</p><p>BRANCH COMMIT<br>
<br>
Merging changes from trunk to branch, in preparation for committing back to trunk.<br>
</p><hr noshade><pre><font color="gray">
Property changes on: branches/ocean_projects/gmvar
___________________________________________________________________
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/cam_mpas_nh:1260-1270
/branches/ocean_projects/ale_vert_coord:1225-1383
/branches/ocean_projects/ale_vert_coord_new:1387-1428
/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
/trunk/mpas:1213-1453

Modified: branches/ocean_projects/gmvar/Makefile
===================================================================
--- branches/ocean_projects/gmvar/Makefile        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/Makefile        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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 \
@@ -115,7 +115,7 @@
         &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/gmvar/namelist.input.ocean
===================================================================
--- branches/ocean_projects/gmvar/namelist.input.ocean        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/namelist.input.ocean        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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'
@@ -51,8 +48,6 @@
    config_visc_vorticity_term = .false.
    config_h_tracer_eddy_diff2 = 0.0
    config_h_tracer_eddy_diff4 = 0.0
-   config_mom_decay      = .false.
-   config_mom_decay_time = 3600.0
 /
 &amp;vmix
    config_vert_visc_type  = 'const'


Property changes on: branches/ocean_projects/gmvar/src
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src:1260-1270
/branches/ocean_projects/ale_vert_coord/src:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src:754-986
/branches/ocean_projects/rayleigh/src:1298-1311
/branches/ocean_projects/split_explicit_mrp/src:1134-1138
/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:1213-1453

Modified: branches/ocean_projects/gmvar/src/Makefile
===================================================================
--- branches/ocean_projects/gmvar/src/Makefile        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/Makefile        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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;

Copied: branches/ocean_projects/gmvar/src/core_atmos_physics/checkout_data_files.sh (from rev 1453, trunk/mpas/src/core_atmos_physics/checkout_data_files.sh)
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/checkout_data_files.sh                                (rev 0)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/checkout_data_files.sh        2012-02-02 19:34:14 UTC (rev 1454)
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+svn co https://svn-mpas-model.cgd.ucar.edu/data/physics_wrf/files physics_wrf/files

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_camrad_init.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_camrad_init.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_camrad_init.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -327,36 +327,6 @@
  DM_BCAST_MACRO(ln_ah2ow)
  DM_BCAST_MACRO(ln_eh2ow)
 
-!101 format(i4,7(1x,e19.12))
-!write(0,*) 'ah2onw'
-!do i_te = 1,21
-!   write(0,101) i_te,(ah2onw(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-!write(0,*) 'eh2onw'
-!do i_te = 1,21
-!   write(0,101) i_te,(eh2onw(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-!write(0,*) 'ah2ow'
-!do i_te = 1,21
-!   write(0,101) i_te,(ah2ow(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-!write(0,*) 'cn_ah2ow'
-!do i_te = 1,21
-!   write(0,101) i_te,(cn_ah2ow(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-!write(0,*) 'cn_eh2ow'
-!do i_te = 1,21
-!   write(0,101) i_te,(cn_eh2ow(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-!write(0,*) 'ln_ah2ow'
-!do i_te = 1,21
-!   write(0,101) i_te,(ln_ah2ow(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-!write(0,*) 'ln_eh2ow'
-!do i_te = 1,21
-!   write(0,101) i_te,(ln_eh2ow(1,1,1,i_te,i_rh),i_rh=1,n_rh)
-!enddo
-
  if(dminfo % my_proc_id == IO_NODE) close(cam_abs_unit)
 
 ! Set up table of H2O saturation vapor pressures for use in calculation effective path RH.  
@@ -612,14 +582,15 @@
  DM_BCAST_MACRO(kcb)
  DM_BCAST_MACRO(wcb)
  DM_BCAST_MACRO(gcb)
- DM_BCAST_MACRO(kvolc)
- DM_BCAST_MACRO(wvolc)
  DM_BCAST_MACRO(kdst)
  DM_BCAST_MACRO(wdst)
  DM_BCAST_MACRO(gdst)
  DM_BCAST_MACRO(kbg)
  DM_BCAST_MACRO(wbg)
  DM_BCAST_MACRO(gbg)
+ DM_BCAST_MACRO(kvolc)
+ DM_BCAST_MACRO(wvolc)
+ DM_BCAST_MACRO(gvolc)
 
  if(dminfo % my_proc_id == IO_NODE) close(cam_aer_unit)
 
@@ -676,7 +647,7 @@
     enddo
  enddo
 
-!write(0,*) '--- end subroutine aer_optics_initialize:'
+ write(0,*) '--- end subroutine aer_optics_initialize:'
 
  end subroutine aer_optics_initialize
 

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_date_time.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_date_time.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_date_time.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,10 +1,11 @@
 !=============================================================================================
  module mpas_atmphys_date_time
 
+ use mpas_kind_types
+
  implicit none
  private
- public:: get_current_date,       &amp;
-          get_julgmt,             &amp;
+ public:: get_julgmt,             &amp;
           monthly_interp_to_date, &amp;
           monthly_min_max
 
@@ -13,17 +14,6 @@
  contains
 
 !=============================================================================================
- subroutine get_current_date
-!=============================================================================================
-
-!temporary subroutine to provide the date at which the forecast begins.right now, that date is
-!hard-wired. This will change when the time manager is in place.
-
- current_date = '2010-10-23_00'
-
- end subroutine get_current_date
-
-!=============================================================================================
  subroutine get_julgmt(date_str,julyr,julday,gmt)
 !=============================================================================================
 
@@ -108,7 +98,7 @@
 
  write(0,*)
  write(0,*) '--- enter subroutine monthly_interp_to_date:'
- write(0,*) '--- current_date =',date_str
+ write(0,*) '--- current_date  = ',date_str
 
  write(day15,fmt='(I2.2)') 15
  do l = 1 , 12
@@ -141,8 +131,8 @@
              month2 = month1 + 1
           endif
           if(n == 1) then
-             write(0,*) '--- month1=',month1
-             write(0,*) '--- month2=',month2
+             write(0,*) '--- month1 =',month1
+             write(0,*) '--- month2 =',month2
           endif
           field_out(n) = ( field_in(month2,n) * (target_date - middle(l))    &amp;
                        +   field_in(month1,n) * (middle(l+1) - target_date)) &amp;

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -71,7 +71,7 @@
 
     !call to short wave radiation scheme:
     if(l_radtsw) then
-       call allocate_radiation_sw
+       call allocate_radiation_sw(xtime_s)
        call driver_radiation_sw(itimestep,block%mesh,block%state%time_levs(1)%state,  &amp;
                                block%diag_physics,block%sfc_input,block%tend_physics, &amp;
                                xtime_s)
@@ -79,7 +79,7 @@
 
     !call to long wave radiation scheme:
     if(l_radtlw) then
-       call allocate_radiation_lw
+       call allocate_radiation_lw(xtime_s)
        call driver_radiation_lw(itimestep,block%mesh,block%state%time_levs(1)%state,  &amp;
                                block%diag_physics,block%sfc_input,block%tend_physics, &amp;
                                xtime_s)
@@ -89,7 +89,7 @@
     if(config_radt_sw_scheme.ne.'off' .or. config_radt_lw_scheme.ne.'off') &amp;
        call deallocate_cloudiness
     if(config_radt_sw_scheme.ne.'off') call deallocate_radiation_sw
-    if(config_radt_lw_scheme.ne.'off') call deallocate_radiation_lw
+    if(config_radt_lw_scheme.ne.'off') call deallocate_radiation_lw(xtime_s)
 
     !call to surface-layer scheme:
     if(config_sfclayer_scheme .ne. 'off') then

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_lsm.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_lsm.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_lsm.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -18,10 +18,10 @@
           deallocate_lsm, &amp;
           driver_lsm
  
- logical,parameter:: rdxmaxalb = .true.  !use snow albedo from geogrid;false use table values
- logical,parameter:: myj       = .false. !true if using Mellor-Yamada PBL scheme.
- logical,parameter:: frpcpn    = .false.
- logical,parameter:: rdlai2d   = .false.
+ logical,parameter:: rdmaxalb = .false. !use snow albedo from geogrid;false use table values
+ logical,parameter:: myj      = .false. !true if using Mellor-Yamada PBL scheme.
+ logical,parameter:: frpcpn   = .false.
+ logical,parameter:: rdlai2d  = .false.
 
 !urban physics: since MPAS does not plan to run the urban physics option, the two options
 !below are defined locally:

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_radiation_lw.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_radiation_lw.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_radiation_lw.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,5 +1,6 @@
 !=============================================================================================
  module mpas_atmphys_driver_radiation_lw
+ use mpas_configure, only: config_do_restart
  use mpas_grid_types
  use mpas_timer
 
@@ -26,12 +27,17 @@
  contains
 
 !=============================================================================================
- subroutine allocate_radiation_lw
+ subroutine allocate_radiation_lw(xtime_s)
 !=============================================================================================
 
- if(.not.allocated(f_ice)        ) allocate(f_ice(ims:ime,kms:kme,jms:jme)                )
- if(.not.allocated(f_rain)       ) allocate(f_rain(ims:ime,kms:kme,jms:jme)               )
+!input arguments:
+ real(kind=RKIND),intent(in):: xtime_s
 
+!---------------------------------------------------------------------------------------------
+
+ if(.not.allocated(f_ice)        ) allocate(f_ice(ims:ime,kms:kme,jms:jme)        )
+ if(.not.allocated(f_rain)       ) allocate(f_rain(ims:ime,kms:kme,jms:jme)       )
+
  if(.not.allocated(sfc_emiss_p)  ) allocate(sfc_emiss_p(ims:ime,jms:jme)          )
  if(.not.allocated(snow_p)       ) allocate(snow_p(ims:ime,jms:jme)               )
  if(.not.allocated(tsk_p)        ) allocate(tsk_p(ims:ime,jms:jme)                )
@@ -93,12 +99,21 @@
        if(.not.allocated(aerosolcp_p)  ) &amp;
           allocate(aerosolcp_p(ims:ime,1:num_aerlevels,jms:jme,num_aerosols) )
 
-       if(.not.allocated(emstot_p) ) allocate(emstot_p(ims:ime,kms:kme,jms:jme) )
-       if(.not.allocated(abstot_p) ) &amp;
-          allocate(abstot_p(ims:ime,kms:kme,cam_abs_dim2,jms:jme) )
-       if(.not.allocated(absnxt_p) ) &amp;
-          allocate(absnxt_p(ims:ime,kms:kme,cam_abs_dim1,jms:jme) )
+       !allocate these arrays on the first time step, only:
+       if(xtime_s .lt. 1.e-12) then
 
+          write(0,*) 
+          write(0,*) '--- end subroutine allocate_radiation_lw:'
+          write(0,*) '--- allocate emstot_p,abstot_p,absnxt_p'
+
+          if(.not.allocated(emstot_p) ) allocate(emstot_p(ims:ime,kms:kme,jms:jme) )
+          if(.not.allocated(abstot_p) ) &amp;
+             allocate(abstot_p(ims:ime,kms:kme,cam_abs_dim2,jms:jme) )
+          if(.not.allocated(absnxt_p) ) &amp;
+             allocate(absnxt_p(ims:ime,kms:kme,cam_abs_dim1,jms:jme) )
+
+       endif
+
     case default
 
  end select radiation_lw_select
@@ -106,9 +121,14 @@
  end subroutine allocate_radiation_lw
 
 !=============================================================================================
- subroutine deallocate_radiation_lw
+ subroutine deallocate_radiation_lw(xtime_s)
 !=============================================================================================
 
+!input arguments:
+ real(kind=RKIND),intent(in):: xtime_s
+
+!---------------------------------------------------------------------------------------------
+
  if(allocated(f_ice)        ) deallocate(f_ice        )
  if(allocated(f_rain)       ) deallocate(f_rain       )
  if(allocated(sfc_emiss_p)  ) deallocate(sfc_emiss_p  )
@@ -169,10 +189,6 @@
        if(allocated(aerosolcn_p)  ) deallocate(aerosolcn_p  )
        if(allocated(aerosolcp_p)  ) deallocate(aerosolcp_p  )
 
-       if(allocated(abstot_p)     ) deallocate(abstot_p     )
-       if(allocated(absnxt_p)     ) deallocate(absnxt_p     )
-       if(allocated(emstot_p)     ) deallocate(emstot_p     )
-
     case default
 
  end select radiation_lw_select
@@ -180,7 +196,7 @@
  end subroutine deallocate_radiation_lw
 
 !=============================================================================================
- subroutine radiation_lw_from_MPAS(mesh,state,diag_physics,sfc_input)
+ subroutine radiation_lw_from_MPAS(mesh,state,diag_physics,sfc_input,xtime_s)
 !=============================================================================================
 
 !input arguments:
@@ -189,6 +205,8 @@
  type(sfc_input_type)   ,intent(in):: sfc_input
  type(diag_physics_type),intent(in):: diag_physics
 
+ real(kind=RKIND),intent(in):: xtime_s
+
 !---------------------------------------------------------------------------------------------
 
  do j = jts,jte
@@ -283,42 +301,34 @@
        enddo
        enddo
 
-       call mpas_timer_start(&quot;CAM lw: read arrays for infrared absorption&quot;)
-       !infrared absorption:
-       do j = jts,jte
-       do n = 1,cam_abs_dim1
-       do k = kts,kte
-       do i = its,ite
-          absnxt_p(i,k,n,j) = diag_physics % absnxt % array(k,n,i)
-       enddo
-       enddo
-       enddo
-       do n = 1,cam_abs_dim2
-       do k = kts,kte+1
-       do i = its,ite
-          abstot_p(i,k,n,j) = diag_physics % abstot % array(k,n,i)
-       enddo
-       enddo
-       enddo
-       do k = kts,kte+1
-       do i = its,ite
-          emstot_p(i,k,j) = diag_physics % emstot % array(k,i)
-       enddo
-       enddo
-       enddo
-       call mpas_timer_stop(&quot;CAM lw: read arrays for infrared absorption&quot;)
-!      write(0,*) '--- end radiation_lw_from_MPAS: doabsems=',doabsems
-!      do k = kts,kte+1
-!         write(0,102) k,(maxval(abstot_p(its:ite,k,n,jts:jte)),n=1,10)
-!      enddo
-!      write(0,*)
-!      do k = kts,kte
-!         write(0,102) k,(maxval(absnxt_p(its:ite,k,n,jts:jte)),n=1,cam_abs_dim1)
-!      enddo
-!      write(0,*)
-!      do k = kts,kte+1
-!         write(0,102) k,maxval(emstot_p(its:ite,k,jts:jte))
-!      enddo
+       call mpas_timer_start(&quot;CAM lw: fill arrays for infrared absorption&quot;)
+       if(xtime_s .lt. 1.e-12) then
+          write(0,*)
+          write(0,*) '--- radiation_lw_from_MPAS:'
+          write(0,*) '--- initialize emstot_p,abstot_p,absnxt_p'
+          !infrared absorption:
+          do j = jts,jte
+          do n = 1,cam_abs_dim1
+          do k = kts,kte
+          do i = its,ite
+             absnxt_p(i,k,n,j) = 0.
+          enddo
+          enddo
+          enddo
+          do n = 1,cam_abs_dim2
+          do k = kts,kte+1
+          do i = its,ite
+             abstot_p(i,k,n,j) = 0.
+          enddo
+          enddo
+          enddo
+          do k = kts,kte+1
+          do i = its,ite
+             emstot_p(i,k,j) = 0.
+          enddo
+          enddo
+          enddo
+       endif
 
        call mpas_timer_start(&quot;CAM lw: ozone and aerosols&quot;)
        !ozone mixing ratio:
@@ -367,13 +377,15 @@
  end subroutine radiation_lw_from_MPAS
 
 !=============================================================================================
- subroutine radiation_lw_to_MPAS(diag_physics,tend_physics)
+ subroutine radiation_lw_to_MPAS(diag_physics,tend_physics,xtime_s)
 !=============================================================================================
 
 !input arguments:
  type(diag_physics_type),intent(inout):: diag_physics
  type(tend_physics_type),intent(inout):: tend_physics
 
+ real(kind=RKIND),intent(in):: xtime_s
+
 !---------------------------------------------------------------------------------------------
 
  do j = jts,jte
@@ -407,48 +419,6 @@
  enddo
  enddo
 
- radiation_lw_select: select case (trim(radt_lw_scheme))
-
-    case(&quot;cam_lw&quot;)
-       !infrared absorption:
-       do j = jts,jte
-       do n = 1,cam_abs_dim1
-       do k = kts,kte
-       do i = its,ite
-          diag_physics % absnxt % array(k,n,i) = absnxt_p(i,k,n,j)
-       enddo
-       enddo
-       enddo
-       do n = 1,cam_abs_dim2
-       do k = kts,kte+1
-       do i = its,ite
-          diag_physics % abstot % array(k,n,i) = abstot_p(i,k,n,j)
-       enddo
-       enddo
-       enddo
-       do k = kts,kte+1
-       do i = its,ite
-          diag_physics % emstot % array(k,i) = emstot_p(i,k,j)
-       enddo
-       enddo
-       enddo
-!      write(0,*) '--- end radiation_lw_to_MPAS: doabsems=',doabsems
-!      do k = kts,kte+1
-!         write(0,102) k,(maxval(abstot_p(its:ite,k,n,jts:jte)),n=1,10)
-!      enddo
-!      write(0,*)
-!      do k = kts,kte
-!        write(0,102) k,(maxval(absnxt_p(its:ite,k,n,jts:jte)),n=1,cam_abs_dim1)
-!      enddo
-!      write(0,*)
-!      do k = kts,kte+1
-!         write(0,102) k,maxval(emstot_p(its:ite,k,jts:jte))
-!      enddo
-
-    case default
-
- end select radiation_lw_select
-
 !format:
  101 format(i3,2i6,12(1x,e15.8))
  102 format(i6,12(1x,e15.8))
@@ -517,7 +487,7 @@
  101 format(i8,12(1x,e15.8))
 
 !copy all MPAS arrays to rectangular grid:
- call radiation_lw_from_MPAS(mesh,state,diag_physics,sfc_input)
+ call radiation_lw_from_MPAS(mesh,state,diag_physics,sfc_input,xtime_s)
 
 !call to longwave radiation scheme:
  radiation_lw_select: select case (trim(radt_lw_scheme))
@@ -560,6 +530,8 @@
        radt = dt_radtlw/60.
 
        call mpas_timer_start(&quot;camrad&quot;)
+       write(0,*) '--- enter subroutine camrad_lw: doabsems=',doabsems
+       call mpas_timer_start(&quot;camrad&quot;)
        call camrad( dolw = .true. , dosw = .false. ,                                         &amp;
                 rthratenlw    = rthratenlw_p  , rthratensw    = rthratensw_p  ,              &amp;
                 swupt         = swupt_p       , swuptc        = swuptc_p      ,              &amp;
@@ -579,7 +551,7 @@
                 xlat          = xlat_p        , xlong         = xlon_p        ,              &amp;
                 t_phy         = t_p           , pi_phy        = pi_p          ,              &amp;
                 p_phy         = pres_p        , p8w           = pres2_p       ,              &amp;
-                z             = z_p           , dz8w          = dz_p          ,              &amp;            
+                z             = zmid_p        , dz8w          = dz_p          ,              &amp;            
                 rho_phy       = rho_p         , qv3d          = qv_p          ,              &amp; 
                 qc3d          = qc_p          , qr3d          = qr_p          ,              &amp;
                 qi3d          = qi_p          , qs3d          = qs_p          ,              &amp;
@@ -609,28 +581,27 @@
                 its = its , ite = ite , jts = jts , jte = jte , kts = kts , kte = kte        &amp;
                   )
        call mpas_timer_stop(&quot;camrad&quot;)
-       write(0,*) '--- end subroutince camrad lw: doabsems=',doabsems
        write(0,*) 'max lwupb      =',maxval(lwupb_p(its:ite,jms:jme))
-       write(0,*) 'min lwupb      =',minval(lwupb_p(its:ite,jms:jme))
        write(0,*) 'max lwupbc     =',maxval(lwupbc_p(its:ite,jms:jme))
-       write(0,*) 'min lwupbc     =',minval(lwupbc_p(its:ite,jms:jme))
        write(0,*) 'max lwupt      =',maxval(lwupt_p(its:ite,jms:jme))
-       write(0,*) 'min lwupt      =',minval(lwupt_p(its:ite,jms:jme))
        write(0,*) 'max lwuptc     =',maxval(lwuptc_p(its:ite,jms:jme))
-       write(0,*) 'min lwuptc     =',minval(lwuptc_p(its:ite,jms:jme))
        write(0,*) 'max rthratenlw =',maxval(rthratenlw_p(its:ite,kts:kte,jms:jme))
        write(0,*) 'min rthratenlw =',minval(rthratenlw_p(its:ite,kts:kte,jms:jme))
+       write(0,*) '--- end subroutine camrad lw: doabsems=',doabsems
 
     case default
 
  end select radiation_lw_select
 
 !copy all arrays back to MPAS geodesic grid:
- call radiation_lw_to_MPAS(diag_physics,tend_physics)
+ call radiation_lw_to_MPAS(diag_physics,tend_physics,xtime_s)
 
- write(0,*) '--- end subroutine driver_radiation_lw:'
+ write(0,*) '--- end subroutine driver_radiation_lw'
  call mpas_timer_stop(&quot;radiation_lw&quot;)
 
+!formats:
+ 200 format(i3,i3,8(1x,e15.8))
+
  end subroutine driver_radiation_lw
 
 !=============================================================================================

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_radiation_sw.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_radiation_sw.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_driver_radiation_sw.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -27,12 +27,17 @@
  contains
 
 !=============================================================================================
- subroutine allocate_radiation_sw
+ subroutine allocate_radiation_sw(xtime_s)
 !=============================================================================================
 
- if(.not.allocated(f_ice)        ) allocate(f_ice(ims:ime,kms:kme,jms:jme)                )
- if(.not.allocated(f_rain)       ) allocate(f_rain(ims:ime,kms:kme,jms:jme)               )
+!input arguments:
+ real(kind=RKIND),intent(in):: xtime_s
 
+!---------------------------------------------------------------------------------------------
+
+ if(.not.allocated(f_ice)        ) allocate(f_ice(ims:ime,kms:kme,jms:jme)        )
+ if(.not.allocated(f_rain)       ) allocate(f_rain(ims:ime,kms:kme,jms:jme)       )
+
  if(.not.allocated(xlat_p)       ) allocate(xlat_p(ims:ime,jms:jme)               )
  if(.not.allocated(xlon_p)       ) allocate(xlon_p(ims:ime,jms:jme)               )
 
@@ -65,9 +70,6 @@
        if(.not.allocated(swupflxc_p)   ) allocate(swupflxc_p(ims:ime,kms:kme+1,jms:jme) )
 
     case(&quot;cam_sw&quot;)
-       if(.not.allocated(xlat_p)       ) allocate(xlat_p(ims:ime,jms:jme)               )
-       if(.not.allocated(xlon_p)       ) allocate(xlon_p(ims:ime,jms:jme)               )
-
        if(.not.allocated(glw_p)        ) allocate(glw_p(ims:ime,jms:jme)                )
        if(.not.allocated(lwcf_p)       ) allocate(lwcf_p(ims:ime,jms:jme)               )
        if(.not.allocated(lwdnb_p)      ) allocate(lwdnb_p(ims:ime,jms:jme)              )
@@ -98,12 +100,17 @@
        if(.not.allocated(aerosolcp_p)  ) &amp;
           allocate(aerosolcp_p(ims:ime,1:num_aerlevels,jms:jme,num_aerosols) )
 
-       if(.not.allocated(emstot_p) ) allocate(emstot_p(ims:ime,kms:kme,jms:jme) )
-       if(.not.allocated(abstot_p) ) &amp;
-          allocate(abstot_p(ims:ime,kms:kme,cam_abs_dim2,jms:jme) )
-       if(.not.allocated(absnxt_p) ) &amp;
-          allocate(absnxt_p(ims:ime,kms:kme,cam_abs_dim1,jms:jme) )
+       !allocate these arrays on the first time step, only:
+       if(xtime_s .lt. 1.e-12) then
 
+          if(.not.allocated(emstot_p) ) allocate(emstot_p(ims:ime,kms:kme,jms:jme) )
+          if(.not.allocated(abstot_p) ) &amp;
+             allocate(abstot_p(ims:ime,kms:kme,cam_abs_dim2,jms:jme) )
+          if(.not.allocated(absnxt_p) ) &amp;
+             allocate(absnxt_p(ims:ime,kms:kme,cam_abs_dim1,jms:jme) )
+
+       endif
+
     case default
 
  end select radiation_sw_select
@@ -176,10 +183,6 @@
        if(allocated(aerosolcn_p)  ) deallocate(aerosolcn_p  )
        if(allocated(aerosolcp_p)  ) deallocate(aerosolcp_p  )
 
-       if(allocated(abstot_p)     ) deallocate(abstot_p     )
-       if(allocated(absnxt_p)     ) deallocate(absnxt_p     )
-       if(allocated(emstot_p)     ) deallocate(emstot_p     )
-
     case default
 
  end select radiation_sw_select
@@ -187,7 +190,7 @@
  end subroutine deallocate_radiation_sw
 
 !=============================================================================================
- subroutine radiation_sw_from_MPAS(mesh,state,diag_physics,sfc_input)
+ subroutine radiation_sw_from_MPAS(mesh,state,diag_physics,sfc_input,xtime_s)
 !=============================================================================================
 
 !input arguments:
@@ -196,6 +199,8 @@
  type(diag_physics_type),intent(inout):: diag_physics
  type(sfc_input_type)   ,intent(inout):: sfc_input
 
+ real(kind=RKIND),intent(in):: xtime_s
+
 !---------------------------------------------------------------------------------------------
 
  do j = jts,jte
@@ -265,7 +270,6 @@
        enddo
 
     case(&quot;cam_sw&quot;)
-
        do j = jts,jte
        do i = its,ite
           sfc_emiss_p(i,j) = diag_physics % sfc_emiss % array(i)
@@ -292,39 +296,29 @@
        enddo
        enddo
        !infrared absorption:
-       do j = jts,jte
-       do n = 1,cam_abs_dim1
-       do k = kts,kte
-       do i = its,ite
-          absnxt_p(i,k,n,j) = diag_physics % absnxt % array(k,n,i)
-       enddo
-       enddo
-       enddo
-       do n = 1,cam_abs_dim2
-       do k = kts,kte+1
-       do i = its,ite
-          abstot_p(i,k,n,j) = diag_physics % abstot % array(k,n,i)
-       enddo
-       enddo
-       enddo
-       do k = kts,kte+1
-       do i = its,ite
-          emstot_p(i,k,j) = diag_physics % emstot % array(k,i)
-       enddo
-       enddo
-       enddo
-!      write(0,*) '--- end radiation_sw_from_MPAS: doabsems=',doabsems
-!      do k = kts,kte+1
-!         write(0,102) k,(maxval(abstot_p(its:ite,k,n,jts:jte)),n=1,10)
-!      enddo
-!      write(0,*)
-!      do k = kts,kte
-!         write(0,102) k,(maxval(absnxt_p(its:ite,k,n,jts:jte)),n=1,cam_abs_dim1)
-!      enddo
-!      write(0,*)
-!      do k = kts,kte+1
-!         write(0,102) k,maxval(emstot_p(its:ite,k,jts:jte))
-!      enddo
+       if(xtime_s .lt. 1.e-12) then
+          do j = jts,jte
+          do n = 1,cam_abs_dim1
+          do k = kts,kte
+          do i = its,ite
+             absnxt_p(i,k,n,j) = 0.
+          enddo
+          enddo
+          enddo
+          do n = 1,cam_abs_dim2
+          do k = kts,kte+1
+          do i = its,ite
+             abstot_p(i,k,n,j) = 0.
+          enddo
+          enddo
+          enddo
+          do k = kts,kte+1
+          do i = its,ite
+             emstot_p(i,k,j) = 0.
+          enddo
+          enddo
+          enddo
+       endif
        !ozone mixing ratio:
        do k = 1, num_oznlevels
           pin_p(k) = mesh % pin % array(k,1)
@@ -412,35 +406,6 @@
 
  enddo
 
- radiation_sw_select: select case (trim(radt_sw_scheme))
-    case(&quot;cam_sw&quot;)
-       !infrared absorption:
-       do j = jts,jte
-       do n = 1,cam_abs_dim1
-       do k = kts,kte
-       do i = its,ite
-          diag_physics % absnxt % array(k,n,i) = absnxt_p(i,k,n,j)
-       enddo
-       enddo
-       enddo
-       do n = 1,cam_abs_dim2
-       do k = kts,kte+1
-       do i = its,ite
-          diag_physics % abstot % array(k,n,i) = abstot_p(i,k,n,j)
-       enddo
-       enddo
-       enddo
-       do k = kts,kte+1
-       do i = its,ite
-          diag_physics % emstot % array(k,i) = emstot_p(i,k,j)
-       enddo
-       enddo
-       enddo
-
-    case default
-
- end select radiation_sw_select
-
  end subroutine radiation_sw_to_MPAS
 
 !=============================================================================================
@@ -456,7 +421,7 @@
 
 !---------------------------------------------------------------------------------------------
  write(0,*)
- write(0,*) '--- begin radiation_sw initialization:'
+ write(0,*) '--- enter radiation_sw initialization:'
 
 !call to shortwave radiation scheme:
  radiation_sw_select: select case (trim(radt_sw_scheme))
@@ -475,7 +440,7 @@
 
  end select radiation_sw_select
 
- write(0,*) '--- end radiation_sw initialization:'
+ write(0,*) '--- end radiation_sw initialization'
 
  end subroutine init_radiation_sw
 
@@ -517,7 +482,7 @@
   xtime_m = xtime_s/60.
 
 !copy all MPAS arrays to rectangular grid:
- call radiation_sw_from_MPAS(mesh,state,diag_physics,sfc_input)
+ call radiation_sw_from_MPAS(mesh,state,diag_physics,sfc_input,xtime_s)
 
 !... calculates solar declination:
 !call radconst(declin,solcon,julday,degrad,dpd)
@@ -531,6 +496,7 @@
  radiation_sw_select: select case (trim(radt_sw_scheme))
 
     case (&quot;rrtmg_sw&quot;)
+
        write(0,*) '--- enter subroutine rrtmg_swrad:'
        call rrtmg_swrad( &amp;
                 rthratensw = rthratensw_p , swupt     = swupt_p    , swuptc    = swuptc_p  , &amp;
@@ -562,6 +528,8 @@
        write(0,*) '--- exit subroutine rrtmg_swrad'
 
     case (&quot;cam_sw&quot;)
+
+       write(0,*) '--- enter subroutine camrad_sw:'
        call camrad( dolw = .false. , dosw = .true. ,                                         &amp;
                 rthratenlw    = rthratenlw_p  , rthratensw    = rthratensw_p  ,              &amp;
                 swupt         = swupt_p       , swuptc        = swuptc_p      ,              &amp;
@@ -581,7 +549,7 @@
                 xlat          = xlat_p        , xlong         = xlon_p        ,              &amp;
                 t_phy         = t_p           , pi_phy        = pi_p          ,              &amp;
                 p_phy         = pres_p        , p8w           = pres2_p       ,              &amp;
-                z             = z_p           , dz8w          = dz_p          ,              &amp;            
+                z             = zmid_p        , dz8w          = dz_p          ,              &amp;            
                 rho_phy       = rho_p         , qv3d          = qv_p          ,              &amp; 
                 qc3d          = qc_p          , qr3d          = qr_p          ,              &amp;
                 qi3d          = qi_p          , qs3d          = qs_p          ,              &amp;
@@ -610,19 +578,14 @@
                 ims = ims , ime = ime , jms = jms , jme = jme , kms = kms , kme = kme ,      &amp;
                 its = its , ite = ite , jts = jts , jte = jte , kts = kts , kte = kte        &amp;
                   )
-
-       write(0,*) '--- end subroutine camrad sw'
        write(0,*) 'doabsems =',doabsems
        write(0,*) 'max swupb      =',maxval(swupb_p(its:ite,jms:jme))
-       write(0,*) 'min swupb      =',minval(swupb_p(its:ite,jms:jme))
        write(0,*) 'max swupbc     =',maxval(swupbc_p(its:ite,jms:jme))
-       write(0,*) 'min swupbc     =',minval(swupbc_p(its:ite,jms:jme))
        write(0,*) 'max swupt      =',maxval(swupt_p(its:ite,jms:jme))
-       write(0,*) 'min swupt      =',minval(swupt_p(its:ite,jms:jme))
        write(0,*) 'max swuptc     =',maxval(swuptc_p(its:ite,jms:jme))
-       write(0,*) 'min swuptc     =',minval(swuptc_p(its:ite,jms:jme))
        write(0,*) 'max rthratensw =',maxval(rthratensw_p(its:ite,kts:kte,jms:jme))
        write(0,*) 'min rthratensw =',minval(rthratensw_p(its:ite,kts:kte,jms:jme))
+       write(0,*) '--- end subroutine camrad sw'
 
     case default
 
@@ -631,8 +594,11 @@
 !copy all arrays back to MPAS geodesic grid:
  call radiation_sw_to_MPAS(diag_physics,tend_physics)
 
- write(0,*) '--- end subroutine driver_radiation_sw:'
+ write(0,*) '--- end subroutine driver_radiation_sw'
 
+!formats:
+ 200 format(i3,i6,8(1x,e15.8))
+
  end subroutine driver_radiation_sw
 
 !=============================================================================================

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_init.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_init.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_init.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -73,8 +73,7 @@
 
 !initialization of global surface properties. set here for now, but may be moved when time
 !manager is implemented:
- if(.not. config_do_restart) &amp;
-    call landuse_init_forMPAS(dminfo,julday,mesh,diag_physics,sfc_input)
+ call landuse_init_forMPAS(dminfo,julday,mesh,diag_physics,sfc_input)
 
 !initialization of parameterized deep convective processes:
  if(config_conv_deep_scheme .ne. 'off') &amp;

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_initialize_real.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_initialize_real.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_initialize_real.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,5 +1,6 @@
 !=============================================================================================
  module mpas_atmphys_initialize_real
+ use mpas_kind_types
  use mpas_configure, only: config_met_prefix,  &amp;
                            config_frac_seaice, &amp;
                            config_input_sst,   &amp;
@@ -82,12 +83,12 @@
              
        if(field % iproj == PROJ_LATLON) then
           call map_set(PROJ_LATLON, proj, &amp;
-                       latinc = real(field % deltalat), &amp;
-                       loninc = real(field % deltalon), &amp;
-                       knowni = 1.0, &amp;
-                       knownj = 1.0, &amp;
-                       lat1 = real(field % startlat), &amp;
-                       lon1 = real(field % startlon))
+                       latinc = real(field % deltalat,RKIND), &amp;
+                       loninc = real(field % deltalon,RKIND), &amp;
+                       knowni = 1.0_RKIND, &amp;
+                       knownj = 1.0_RKIND, &amp;
+                       lat1 = real(field % startlat,RKIND), &amp;
+                       lon1 = real(field % startlon,RKIND))
        end if
    
        !Interpolate field to each MPAS grid cell:
@@ -110,10 +111,10 @@
 
           if(index(field % field,'SST') /= 0) then
              fg % sst % array(iCell) = interp_sequence(x,y,1,slab_r8,1,field%nx, &amp;
-                                              1,field%ny,1,1,-1.e30,interp_list,1)
+                                              1,field%ny,1,1,-1.e30_RKIND,interp_list,1)
           elseif(index(field % field,'SEAICE') /= 0) then
              fg % xice % array(iCell) = interp_sequence(x,y,1,slab_r8,1,field%nx, &amp;
-                                              1,field%ny,1,1,-1.e30,interp_list,1)
+                                              1,field%ny,1,1,-1.e30_RKIND,interp_list,1)
           endif          
        end do
 
@@ -425,8 +426,8 @@
  nCells        = mesh % nCells
  nSoilLevels   = mesh % nSoilLevels
  nFGSoilLevels = mesh % nFGSoilLevels
- write(0,*) 'nSoilLevels  =',nSoilLevels
- write(0,*) 'nFGSoilLevels=',nFGSoilLevels
+ write(0,*) 'nSoilLevels   =',nSoilLevels
+ write(0,*) 'nFGSoilLevels =',nFGSoilLevels
 
  landmask =&gt; mesh % landmask % array
 
@@ -606,7 +607,7 @@
  endif
 
 !make sure that all the cells flagged as sea-ice cells are defined as ocean cells:
-!num_seaice_changes = 0
+ num_seaice_changes = 0
  do iCell = 1, nCellsSolve
     if((landmask(iCell).eq.1 .and. xice(iCell).gt.0.) .or. xice(iCell).gt.200.) then
        num_seaice_changes = num_seaice_changes + 1

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_interface_nhyd.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_interface_nhyd.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_interface_nhyd.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -23,15 +23,18 @@
  subroutine allocate_forall_physics
 !=============================================================================================
 
- if(.not.allocated(psfc_p))  allocate(psfc_p(ims:ime,jms:jme)           )
- if(.not.allocated(ptop_p))  allocate(ptop_p(ims:ime,jms:jme)           )
+ if(.not.allocated(psfc_p) )   allocate(psfc_p(ims:ime,jms:jme)         )
+ if(.not.allocated(ptop_p) )   allocate(ptop_p(ims:ime,jms:jme)         )
 
  if(.not.allocated(u_p)    )  allocate(u_p(ims:ime,kms:kme,jms:jme)     )
  if(.not.allocated(v_p)    )  allocate(v_p(ims:ime,kms:kme,jms:jme)     )
+ if(.not.allocated(fzm_p)  )   allocate(fzm_p(ims:ime,kms:kme,jms:jme)  )
+ if(.not.allocated(fzp_p)  )   allocate(fzp_p(ims:ime,kms:kme,jms:jme)  )
  if(.not.allocated(zz_p)   )  allocate(zz_p(ims:ime,kms:kme,jms:jme)    )
  if(.not.allocated(pres_p) )  allocate(pres_p(ims:ime,kms:kme,jms:jme)  )
  if(.not.allocated(pi_p)   )  allocate(pi_p(ims:ime,kms:kme,jms:jme)    )
  if(.not.allocated(z_p)    )  allocate(z_p(ims:ime,kms:kme,jms:jme)     )
+ if(.not.allocated(zmid_p) )  allocate(zmid_p(ims:ime,kms:kme,jms:jme)  )
  if(.not.allocated(dz_p)   )  allocate(dz_p(ims:ime,kms:kme,jms:jme)    )
  if(.not.allocated(t_p)    )  allocate(t_p(ims:ime,kms:kme,jms:jme)     )
  if(.not.allocated(th_p)   )  allocate(th_p(ims:ime,kms:kme,jms:jme)    )
@@ -42,44 +45,7 @@
  if(.not.allocated(w_p)    )  allocate(w_p(ims:ime,kms:kme,jms:jme)     )
  if(.not.allocated(pres2_p))  allocate(pres2_p(ims:ime,kms:kme,jms:jme) )
  if(.not.allocated(t2_p)   )  allocate(t2_p(ims:ime,kms:kme,jms:jme)    )
-
- if(.not.allocated(pres_hyd_p) ) allocate(pres_hyd_p(ims:ime,kms:kme,jms:jme)  )
- if(.not.allocated(pres2_hyd_p)) allocate(pres2_hyd_p(ims:ime,kms:kme,jms:jme) )
  
- do j = jms,jme
- do i = ims,ime
-    psfc_p(i,j)   = 0.
-    ptop_p(i,j)   = 0.
- enddo
- enddo
-
- do j = jms,jme
- do k = kms,kme
- do i = ims,ime
-    u_p(i,k,j)     = 0.
-    v_p(i,k,j)     = 0.
-    w_p(i,k,j)     = 0.
-    pres_p(i,k,j)  = 0.
-    pi_p(i,k,j)    = 0.
-    z_p(i,k,j)     = 0.
-    dz_p(i,k,j)    = 0.
-    t_p(i,k,j)     = 0.
-    th_p(i,k,j)    = 0.
-    al_p(i,k,j)    = 0.
-    rho_p(i,k,j)   = 0.
-    rh_p(i,k,j)    = 0.
-
-    w_p(i,k,j)     = 0.
-    pres2_p(i,k,j) = 0.
-    t2_p(i,k,j)    = 0.
-
-    pres_hyd_p(i,k,j)  = 0.
-    pres2_hyd_p(i,k,j) = 0.
- enddo
- enddo
- enddo
-
-!allocate moist species (to be revisited!):
  if(.not.allocated(qv_p)   ) allocate(qv_p(ims:ime,kms:kme,jms:jme)     )
  if(.not.allocated(qc_p)   ) allocate(qc_p(ims:ime,kms:kme,jms:jme)     )
  if(.not.allocated(qr_p)   ) allocate(qr_p(ims:ime,kms:kme,jms:jme)     )
@@ -93,16 +59,18 @@
  subroutine deallocate_forall_physics
 !=============================================================================================
 
-!de-allocation of all physics arrays:
  if(allocated(psfc_p)  ) deallocate(psfc_p  )
  if(allocated(ptop_p)  ) deallocate(ptop_p  )
 
  if(allocated(u_p)     ) deallocate(u_p     )
  if(allocated(v_p)     ) deallocate(v_p     )
+ if(allocated(fzm_p)   ) deallocate(fzm_p   )
+ if(allocated(fzp_p)   ) deallocate(fzp_p   )
  if(allocated(zz_p)    ) deallocate(zz_p    )
  if(allocated(pres_p)  ) deallocate(pres_p  )
  if(allocated(pi_p)    ) deallocate(pi_p    )
  if(allocated(z_p)     ) deallocate(z_p     )
+ if(allocated(zmid_p)  ) deallocate(zmid_p  )
  if(allocated(dz_p)    ) deallocate(dz_p    )
  if(allocated(t_p)     ) deallocate(t_p     )
  if(allocated(th_p)    ) deallocate(th_p    )
@@ -114,9 +82,6 @@
  if(allocated(pres2_p) ) deallocate(pres2_p )
  if(allocated(t2_p)    ) deallocate(t2_p    )
 
- if(allocated(pres_hyd_p) ) deallocate(pres_hyd_p  )
- if(allocated(pres2_hyd_p)) deallocate(pres2_hyd_p )

  if(allocated(qv_p)    ) deallocate(qv_p    )
  if(allocated(qc_p)    ) deallocate(qc_p    )
  if(allocated(qr_p)    ) deallocate(qr_p    )
@@ -141,12 +106,13 @@
 
  real(kind=RKIND),dimension(:),pointer:: latCell,lonCell
  real(kind=RKIND),dimension(:),pointer  :: fzm,fzp,rdzw
+ real(kind=RKIND),dimension(:),pointer  :: sfc_pressure
  real(kind=RKIND),dimension(:,:),pointer:: zgrid
  real(kind=RKIND),dimension(:,:),pointer:: zz,exner,pressure_b,rtheta_p,rtheta_b
  real(kind=RKIND),dimension(:,:),pointer:: rho_zz,theta_m,qv,pressure_p,u,v,w
  real(kind=RKIND),dimension(:,:),pointer:: qvs,rh
 
- integer:: ip,iEdg
+ real(kind=RKIND):: rho1,rho2,tem1,tem2
 
 !---------------------------------------------------------------------------------------------
 
@@ -164,25 +130,50 @@
  latCell   =&gt; mesh % latCell % array
  lonCell   =&gt; mesh % lonCell % array
 
- fzm        =&gt; mesh % fzm % array
- fzp        =&gt; mesh % fzp % array
- rdzw       =&gt; mesh % rdzw % array
- zgrid      =&gt; mesh % zgrid % array
- zz         =&gt; mesh % zz % array
- exner      =&gt; diag % exner % array
- pressure_b =&gt; diag % pressure_base % array
- pressure_p =&gt; diag % pressure_p % array
- rtheta_p   =&gt; diag % rtheta_p % array
- rtheta_b   =&gt; diag % rtheta_base % array
+ fzm          =&gt; mesh % fzm % array
+ fzp          =&gt; mesh % fzp % array
+ rdzw         =&gt; mesh % rdzw % array
+ zgrid        =&gt; mesh % zgrid % array
+ zz           =&gt; mesh % zz % array
+ sfc_pressure =&gt; diag % surface_pressure % array
+ exner        =&gt; diag % exner % array
+ pressure_b   =&gt; diag % pressure_base % array
+ pressure_p   =&gt; diag % pressure_p % array
+ rtheta_p     =&gt; diag % rtheta_p % array
+ rtheta_b     =&gt; diag % rtheta_base % array
 
- rho_zz     =&gt; state % rho_zz % array
- theta_m    =&gt; state % theta_m % array
- qv         =&gt; state % scalars % array(state%index_qv,:,:)
+ rho_zz  =&gt; state % rho_zz % array
+ theta_m =&gt; state % theta_m % array
+ qv      =&gt; state % scalars % array(state%index_qv,:,:)
 
- w          =&gt; state % w % array
- u          =&gt; diag  % uReconstructZonal % array
- v          =&gt; diag  % uReconstructMeridional % array
+ w =&gt; state % w % array
+ u =&gt; diag  % uReconstructZonal % array
+ v =&gt; diag  % uReconstructMeridional % array
 
+!ldf (2012-01-06): updates the surface pressure as is done in subroutine microphysics_to_MPAS.
+!do j = jts,jte
+!do i = its,ite
+!   sfc_pressure(i) = 0.5*g*(zgrid(2,i)-zgrid(1,i)) &amp;
+!                   * (1.25 * rho_zz(1,i) * zz(1,i) * (1. + qv(1,i))  &amp;
+!                   -  0.25 * rho_zz(2,i) * zz(2,i) * (1. + qv(1,i)))
+!   sfc_pressure(i) = sfc_pressure(i) + pressure_p(1,i) + pressure_b(1,i)
+!enddo
+!enddo
+!ldf end.
+!ldf (2012-01-09): updates the surface pressure using zgrid.
+ do j = jts,jte
+ do i = its,ite
+    tem1 = zgrid(2,i)-zgrid(1,i)
+    tem2 = zgrid(3,i)-zgrid(2,i)
+    rho1 = rho_zz(1,i) * zz(1,i) * (1. + qv(1,i))
+    rho2 = rho_zz(2,i) * zz(2,i) * (1. + qv(2,i))
+    sfc_pressure(i) = 0.5*g*(zgrid(2,i)-zgrid(1,i)) &amp;
+                    * (rho1 + 0.5*(rho2-rho1)*tem1/(tem1+tem2))
+    sfc_pressure(i) = sfc_pressure(i) + pressure_p(1,i) + pressure_b(1,i)
+ enddo
+ enddo
+!ldf end.
+
 !copy sounding variables from the geodesic grid to the rectangular grid:
  do j = jts, jte
  do i = its, ite
@@ -215,11 +206,18 @@
     pi_p(i,k,j)   = exner(k,i)
     pres_p(i,k,j) = pressure_p(k,i) + pressure_b(k,i)
 
-    dz_p(i,k,j) = zgrid(k+1,i)-zgrid(k,i)
+    zmid_p(i,k,j) = 0.5*(zgrid(k+1,i)+zgrid(k,i))
+    dz_p(i,k,j)   = zgrid(k+1,i)-zgrid(k,i)
 
-    !arrays located at w points:
+ enddo
+ enddo
+ enddo
+
+ do j = jts, jte
+ do k = kts,kte+1
+ do i = its,ite
     w_p(i,k,j) = w(k,i)
-   
+    z_p(i,k,j) = zgrid(k,i)
  enddo
  enddo
  enddo
@@ -247,11 +245,23 @@
  enddo
 
 !interpolation of pressure and temperature from theta points to w points:
+!do j = jts,jte
+!do k = kts+1,kte
+!do i = its,ite
+!   t2_p(i,k,j)    = fzm(k)*t_p(i,k,j) + fzp(k)*t_p(i,k-1,j)
+!   pres2_p(i,k,j) = fzm(k)*pres_p(i,k,j) + fzp(k)*pres_p(i,k-1,j)
+!enddo
+!enddo
+!enddo
+!ldf(2011-01-10):
  do j = jts,jte
  do k = kts+1,kte
  do i = its,ite
-    t2_p(i,k,j)    = fzm(k)*t_p(i,k,j) + fzp(k)*t_p(i,k-1,j)
-    pres2_p(i,k,j) = fzm(k)*pres_p(i,k,j) + fzp(k)*pres_p(i,k-1,j)
+    tem1 = 1./(zgrid(k+1,i)-zgrid(k-1,i))
+    fzm_p(i,k,j) = (zgrid(k,i)-zgrid(k-1,i)) * tem1
+    fzp_p(i,k,j) = (zgrid(k+1,i)-zgrid(k,i)) * tem1
+    t2_p(i,k,j)    = fzm_p(i,k,j)*t_p(i,k,j) + fzp_p(i,k,j)*t_p(i,k-1,j)
+    pres2_p(i,k,j) = fzm_p(i,k,j)*pres_p(i,k,j) + fzp_p(i,k,j)*pres_p(i,k-1,j)
  enddo
  enddo
  enddo
@@ -311,17 +321,6 @@
  enddo
  enddo
 
-!calculation of the hydrostatic pressure at w points:
- do j = jts,jte
- do i = its,ite
-    pres2_hyd_p(i,1,j) = psfc_p(i,j)
-    do k = kts+1,kte+1
-       pres2_hyd_p(i,k,j) = pres2_hyd_p(i,k-1,j) &amp;
-                          - rho_p(i,k-1,j)*(1+qv_p(i,k-1,j))*g*dz_p(i,k-1,j)
-    enddo
- enddo
- enddo
-
 !formats: 
  201 format(3i8,10(1x,e15.8))
  202 format(2i6,10(1x,e15.8))
@@ -480,6 +479,13 @@
  real(kind=RKIND),dimension(:,:),pointer:: rho_zz,theta_m,pressure_p
  real(kind=RKIND),dimension(:,:),pointer:: rt_diabatic_tend
 
+!ldf(2011-11-12): surface pressure.
+ real(kind=RKIND):: rho1,rho2,tem1,tem2
+ real(kind=RKIND),dimension(:),pointer:: rdzw
+ real(kind=RKIND),dimension(:),pointer:: sfc_pressure
+ real(kind=RKIND),dimension(:,:),pointer:: zgrid
+!ldf end.
+
 !---------------------------------------------------------------------------------------------
 
  write(0,*)
@@ -487,6 +493,7 @@
 
 !initialization:
  zz         =&gt; mesh % zz % array
+ zgrid      =&gt; mesh % zgrid % array
  exner      =&gt; diag % exner % array
  exner_b    =&gt; diag % exner_base % array
  pressure_b =&gt; diag % pressure_base % array
@@ -499,6 +506,11 @@
 
  rt_diabatic_tend =&gt; tend % rt_diabatic_tend % array
 
+!ldf (2011-11-12): update surface pressure.
+ rdzw =&gt; mesh % rdzw % array
+ sfc_pressure =&gt; diag % surface_pressure % array
+!ldf end.
+
 !variables common to all cloud microphysics schemes:
 
  do j = jts, jte
@@ -529,7 +541,30 @@
  enddo
  enddo
  enddo

+
+!updates the surface pressure.
+!do j = jts,jte
+!do i = its,ite
+!   sfc_pressure(i) = 0.5*g*(zgrid(2,i)-zgrid(1,i)) &amp;
+!                   * (1.25 * rho_zz(1,i) * zz(1,i) * (1. + qv_p(i,1,j))  &amp;
+!                   -  0.25 * rho_zz(2,i) * zz(2,i) * (1. + qv_p(i,2,j)))
+!   sfc_pressure(i) = sfc_pressure(i) + pressure_p(1,i) + pressure_b(1,i)
+!enddo
+!enddo
+!ldf (2012-01-09):
+ do j = jts,jte
+ do i = its,ite
+    tem1 = zgrid(2,i)-zgrid(1,i)
+    tem2 = zgrid(3,i)-zgrid(2,i)
+    rho1 = rho_zz(1,i) * zz(1,i) * (1. + qv_p(i,1,j))
+    rho2 = rho_zz(2,i) * zz(2,i) * (1. + qv_P(i,2,j))
+    sfc_pressure(i) = 0.5*g*(zgrid(2,i)-zgrid(1,i)) &amp;
+                    * (rho1 + 0.5*(rho2-rho1)*tem1/(tem1+tem2))
+    sfc_pressure(i) = sfc_pressure(i) + pressure_p(1,i) + pressure_b(1,i)
+ enddo
+ enddo
+!ldf end.
+
 !variables specific to different cloud microphysics schemes:
 
  microp_select_init: select case(microp_scheme)

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_landuse.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_landuse.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_landuse.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -6,7 +6,8 @@
  module mpas_atmphys_landuse
  use mpas_configure,only: input_landuse_data, &amp;
                           config_sfc_albedo,  &amp;
-                          config_frac_seaice
+                          config_frac_seaice, &amp;
+                          config_do_restart
  use mpas_dmpar
  use mpas_grid_types
 
@@ -184,6 +185,11 @@
  DM_BCAST_MACRO(scfx)
  write(0,*) '--- isice   =',isice
  write(0,*) '--- iswater =',iswater
+ if(config_do_restart) then
+    write(0,*) '--- config_do_restart =', config_do_restart
+    write(0,*) '--- skip the end of landuse_init_forMPAS'
+    return
+ endif
 
 !defines the surface properties over the entire domain:
  do iCell = 1, nCells

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_lsm_noahinit.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_lsm_noahinit.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_lsm_noahinit.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -9,7 +9,7 @@
  use mpas_configure, only: restart =&gt; config_do_restart,  &amp;
                            mminlu  =&gt; input_landuse_data, &amp;
                            mminsl  =&gt; input_soil_data   , &amp;
-                           input_sfc_albedo =&gt; config_sfc_albedo
+                           input_sfc_albedo =&gt; config_sfc_snowalbedo
  use mpas_dmpar
  use mpas_grid_types
 

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_todynamics.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_todynamics.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_todynamics.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -3,7 +3,7 @@
  use mpas_configure
  use mpas_grid_types
 
- use mpas_atmphys_constants, only: R_d,R_v
+ use mpas_atmphys_constants, only: R_d,R_v,degrad
 
  implicit none
  private
@@ -34,9 +34,9 @@
 
 !local variables:
 !----------------
- integer:: i,k,nCells,nCellsSolve,nEdges,nEdgesSolve,nVertLevels
+ integer:: i,iCell,k,n,nCells,nCellsSolve,nEdges,nEdgesSolve,nVertLevels
 
- real(kind=RKIND),dimension(:,:),pointer:: theta,theta_m,qv
+ real(kind=RKIND),dimension(:,:),pointer:: theta_m,qv
  real(kind=RKIND),dimension(:,:),pointer:: rthblten,rqvblten,rqcblten, &amp;
                                            rqiblten,rublten,rvblten
  real(kind=RKIND),dimension(:,:),pointer:: rthcuten,rqvcuten,rqccuten, &amp;
@@ -49,6 +49,10 @@
  real(kind=RKIND):: tem
  real(kind=RKIND),dimension(:,:),allocatable:: rublten_Edge
 
+!ldf (2011-12-16):
+ real(kind=RKIND),dimension(:,:),allocatable:: theta,tend_th
+!ldf end.
+
 !=============================================================================================
 !write(0,*)
 !write(0,*) '--- enter subroutine physics_add_tend:'
@@ -59,7 +63,7 @@
  nEdgesSolve = mesh % nEdgesSolve
  nVertLevels = mesh % nVertLevels
 
- theta   =&gt; diag % theta % array
+!theta   =&gt; diag % theta % array
  theta_m =&gt; state % theta_m % array
  qv      =&gt; state % scalars % array(state%index_qv,:,:)
 
@@ -84,6 +88,11 @@
  tend_theta   =&gt; tend % theta_m % array
  tend_scalars =&gt; tend % scalars % array
 
+!initialize the tendency for the potential temperature and all scalars due to PBL, convection,
+!and longwave and shortwave radiation:
+ allocate(theta(nVertLevels,nCellsSolve)  )
+ allocate(tend_th(nVertLevels,nCellsSolve))
+ tend_th      = 0.
  tend_scalars = 0.
 
 !add coupled tendencies due to PBL processes:
@@ -96,24 +105,25 @@
        tend_u(k,i)=tend_u(k,i)+rublten_Edge(k,i)*mass_edge(k,i)
     enddo
     enddo
-
     deallocate(rublten_Edge)
 
     do i = 1, nCellsSolve
     do k = 1, nVertLevels
-       tend_theta(k,i)=tend_theta(k,i)+rthblten(k,i)*mass(k,i)
+       tend_th(k,i) = tend_th(k,i)+rthblten(k,i)*mass(k,i)
        tend_scalars(tend%index_qv,k,i)=tend_scalars(tend%index_qv,k,i)+rqvblten(k,i)*mass(k,i)
        tend_scalars(tend%index_qc,k,i)=tend_scalars(tend%index_qc,k,i)+rqcblten(k,i)*mass(k,i)
        tend_scalars(tend%index_qi,k,i)=tend_scalars(tend%index_qi,k,i)+rqiblten(k,i)*mass(k,i)
     enddo
     enddo
  endif
+ write(0,*) 'max rthblten = ',maxval(rthblten(:,1:nCellsSolve))
+ write(0,*) 'min rthblten = ',minval(rthblten(:,1:nCellsSolve))
 
 !add coupled tendencies due to convection:
  if(config_conv_deep_scheme .ne. 'off') then
     do i = 1, nCellsSolve
     do k = 1, nVertLevels
-       tend_theta(k,i)=tend_theta(k,i)+rthcuten(k,i)*mass(k,i)
+       tend_th(k,i)=tend_th(k,i)+rthcuten(k,i)*mass(k,i)
        tend_scalars(tend%index_qv,k,i)=tend_scalars(tend%index_qv,k,i)+rqvcuten(k,i)*mass(k,i)
        tend_scalars(tend%index_qc,k,i)=tend_scalars(tend%index_qc,k,i)+rqccuten(k,i)*mass(k,i)
        tend_scalars(tend%index_qr,k,i)=tend_scalars(tend%index_qr,k,i)+rqrcuten(k,i)*mass(k,i)
@@ -122,64 +132,55 @@
     enddo
     enddo
  endif
+ write(0,*) 'max rthcuten = ',maxval(rthcuten(:,1:nCellsSolve))
+ write(0,*) 'min rthcuten = ',minval(rthcuten(:,1:nCellsSolve))
 
 !add coupled tendencies due to longwave radiation:
  if(config_radt_lw_scheme .ne. 'off') then
     do i = 1, nCellsSolve
     do k = 1, nVertLevels
-       tend_theta(k,i)=tend_theta(k,i)+rthratenlw(k,i)*mass(k,i)
+       tend_th(k,i)=tend_th(k,i)+rthratenlw(k,i)*mass(k,i)
     enddo
     enddo
  endif
+ write(0,*) 'max rthratenlw = ',maxval(rthratenlw(:,1:nCellsSolve))
+ write(0,*) 'min rthratenlw = ',minval(rthratenlw(:,1:nCellsSolve))
     
 !add coupled tendencies due to shortwave radiation:
  if(config_radt_sw_scheme .ne. 'off') then
     do i = 1, nCellsSolve
     do k = 1, nVertLevels
-       tend_theta(k,i)=tend_theta(k,i)+rthratensw(k,i)*mass(k,i)
+       tend_th(k,i)=tend_th(k,i)+rthratensw(k,i)*mass(k,i)
     enddo
     enddo
  endif
+ write(0,*) 'max rthratensw = ',maxval(rthratensw(:,1:nCellsSolve))
+ write(0,*) 'min rthratensw = ',minval(rthratensw(:,1:nCellsSolve))
 
 !if non-hydrostatic core, convert the tendency for the potential temperature to a
 !tendency for the modified potential temperature:
 #ifdef non_hydrostatic_core
     do i = 1, nCellsSolve
     do k = 1, nVertLevels
-
        theta(k,i) = theta_m(k,i) / (1. + R_v/R_d * qv(k,i))
-       tend_theta(k,i) = (1. + R_v/R_d * qv(k,i)) * tend_theta(k,i) &amp;
+       tend_th(k,i) = (1. + R_v/R_d * qv(k,i)) * tend_th(k,i) &amp;
                        + R_v/R_d * theta(k,i) * tend_scalars(tend%index_qv,k,i)
+       tend_theta(k,i) = tend_theta(k,i) + tend_th(k,i)
     enddo
-    enddo 
+    enddo
+#elif hydrostatic_core
+    do i = 1, nCellsSolve
+    do k = 1, nVertLevels
+       tend_theta(k,i) = tend_theta(k,i) + tend_th(k,i)
+    enddo
+    enddo
 #endif
+ deallocate(theta)
+ deallocate(tend_th)
 
-!write(0,*) 'max PBL tendencies:'
-!write(0,*) 'max rthblten=',maxval(rthblten(:,:))
-!write(0,*) 'max rqvblten=',maxval(rqvblten(:,:))
-!write(0,*) 'max rqcblten=',maxval(rqcblten(:,:))
-!write(0,*) 'max rqiblten=',maxval(rqiblten(:,:))
-!write(0,*) 'max rublten =',maxval(rublten(:,:))
-!write(0,*) 'max rvblten =',maxval(rvblten(:,:))
-!write(0,*)
-!write(0,*) 'max CU tendencies:'
-!write(0,*) 'max rthcuten=',maxval(rthcuten(:,:))
-!write(0,*) 'max rqvcuten=',maxval(rqvcuten(:,:))
-!write(0,*) 'max rqccuten=',maxval(rqccuten(:,:))
-!write(0,*) 'max rqrcuten=',maxval(rqrcuten(:,:))
-!write(0,*) 'max rqicuten=',maxval(rqicuten(:,:))
-!write(0,*) 'max rqscuten=',maxval(rqscuten(:,:))
-!write(0,*)
-!write(0,*) 'max tend_scalars:'
-!write(0,*) 'max tend qv=',maxval(tend_scalars(tend%index_qv,:,:))
-!write(0,*) 'max tend qc=',maxval(tend_scalars(tend%index_qc,:,:))
-!write(0,*) 'max tend qr=',maxval(tend_scalars(tend%index_qr,:,:))
-!write(0,*) 'max tend qi=',maxval(tend_scalars(tend%index_qi,:,:))
-!write(0,*) 'max tend qs=',maxval(tend_scalars(tend%index_qs,:,:))
-!write(0,*)
-
 !formats:
- 201 format(2i6,8(1x,e15.8))
+ 201 format(2i6,10(1x,e15.8))
+ 202 format(3i6,10(1x,e15.8))
 
  end subroutine  physics_addtend
 

Modified: branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_vars.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_vars.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_atmos_physics/mpas_atmphys_vars.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,5 +1,7 @@
 !=============================================================================================
  module mpas_atmphys_vars
+
+ use mpas_kind_types
  
  implicit none
  public
@@ -32,7 +34,7 @@
  integer,public:: its,ite,jts,jte,kts,kte
  integer,public:: n_microp
 
- integer,public:: num_months          !number of months                                     [-]
+ integer,public:: num_months          !number of months                                    [-]
 
  real(kind=RKIND),public:: dt_dyn     !time-step for dynamics
  real(kind=RKIND),public:: dt_microp  !time-step for cloud microphysics parameterization.
@@ -42,15 +44,19 @@
  real(kind=RKIND),public:: xice_threshold
 
  real(kind=RKIND),dimension(:,:),allocatable:: &amp;
-    area_p             !grid cell area                                                     [m2]
+    area_p             !grid cell area                                                    [m2]
 
 !... arrays related to surface:
  real(kind=RKIND),dimension(:,:),allocatable:: &amp;
     psfc_p,           &amp;!surface pressure                                                  [Pa]
     ptop_p             !model-top pressure                                                [Pa]
 
+ real(kind=RKIND),dimension(:,:,:),allocatable:: &amp;
+    fzm_p,            &amp;!weight for interpolation to w points                               [-]
+    fzp_p              !weight for interpolation to w points                               [-]
+
+ real(kind=RKIND),dimension(:,:,:),allocatable:: &amp;
 !... arrays related to u- and v-velocities interpolated to theta points:
- real(kind=RKIND),dimension(:,:,:),allocatable:: &amp;
     u_p,              &amp;!u-velocity interpolated to theta points                          [m/s]
     v_p                !v-velocity interpolated to theta points                          [m/s]
     
@@ -60,6 +66,7 @@
     pres_p,           &amp;!pressure                                                          [Pa]
     pi_p,             &amp;!(p_phy/p0)**(r_d/cp)                                               [-]
     z_p,              &amp;!height of layer                                                    [m]
+    zmid_p,           &amp;!height of middle of layer                                          [m]
     dz_p,             &amp;!layer thickness                                                    [m]
     t_p,              &amp;!temperature                                                        [K]
     th_p,             &amp;!potential temperature                                              [K]
@@ -68,10 +75,6 @@
     rh_p               !relative humidity                                                  [-]
 
  real(kind=RKIND),dimension(:,:,:),allocatable:: &amp;
-    pres_hyd_p,       &amp;!hydrostatic pressure at theta points                              [Pa]
-    pres2_hyd_p        !hydrostatic pressure at w points                                  [Pa]
-
- real(kind=RKIND),dimension(:,:,:),allocatable:: &amp;
     qv_p,             &amp;!water vapor mixing ratio                                       [kg/kg]
     qc_p,             &amp;!cloud water mixing ratio                                       [kg/kg]
     qr_p,             &amp;!rain mixing ratio                                              [kg/kg]
@@ -323,6 +326,7 @@
 
  integer,public:: &amp;
     num_soils          !number of soil layers                                              [-]
+    
  integer,dimension(:,:),allocatable:: &amp;
     isltyp_p,         &amp;!dominant soil type category                                        [-]
     ivgtyp_p           !dominant vegetation category                                       [-]

Modified: branches/ocean_projects/gmvar/src/core_hyd_atmos/Registry
===================================================================
--- branches/ocean_projects/gmvar/src/core_hyd_atmos/Registry        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_hyd_atmos/Registry        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/core_hyd_atmos/mpas_atmh_advection.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_hyd_atmos/mpas_atmh_advection.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_hyd_atmos/mpas_atmh_advection.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/core_hyd_atmos/mpas_atmh_test_cases.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_hyd_atmos/mpas_atmh_test_cases.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_hyd_atmos/mpas_atmh_test_cases.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/core_hyd_atmos/mpas_atmh_time_integration.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_hyd_atmos/mpas_atmh_time_integration.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_hyd_atmos/mpas_atmh_time_integration.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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

Modified: branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/Registry
===================================================================
--- branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/Registry        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/Registry        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,6 +1,6 @@
-#
-# namelist  type  namelist_record  name  default_value
-#
+%
+% namelist  type  namelist_record  name  default_value
+%
 namelist integer   nhyd_model config_test_case            5
 namelist integer   nhyd_model config_calendar_type        MPAS_GREGORIAN
 namelist character nhyd_model config_start_time           none
@@ -11,6 +11,7 @@
 namelist integer   dimensions config_nsoillevels          4
 namelist integer   dimensions config_nfglevels            27
 namelist integer   dimensions config_nfgsoillevels        4
+namelist integer   dimensions config_months               12
 namelist character data_sources config_geog_data_path     /data3/mp/wrfhelp/WPS_GEOG/
 namelist character data_sources config_met_prefix         FILE
 namelist character data_sources config_sst_prefix         FILE
@@ -35,9 +36,9 @@
 namelist real      restart    config_restart_time         172800.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
@@ -54,14 +55,14 @@
 dim nFGLevels namelist:config_nfglevels
 dim nFGSoilLevels namelist:config_nfgsoillevels
 dim nVertLevelsP1 nVertLevels+1
-dim nMonths 12
+dim nMonths namelist:config_months
 
-#
-# var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
-#
+%
+% var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
+%
 var persistent text    xtime ( Time ) 2 so xtime state - -
 
-#  horizontal grid structure
+%  horizontal grid structure
 
 var persistent real    latCell ( nCells ) 0 io latCell mesh - -
 var persistent real    lonCell ( nCells ) 0 io lonCell mesh - -
@@ -110,16 +111,16 @@
 var persistent real    fEdge ( nEdges ) 0 io fEdge mesh - -
 var persistent real    fVertex ( nVertices ) 0 io fVertex mesh - -
  
-var persistent real    densityFunction ( nCells ) 0 iro densityFunction mesh - -
+var persistent real    meshDensity ( nCells ) 0 iro meshDensity mesh - -
 
-# some solver scalar coefficients
+% some solver scalar coefficients
 
-# coefficients for vertical extrapolation to the surface
+% coefficients for vertical extrapolation to the surface
 var persistent real    cf1 ( ) 0 io cf1 mesh - -
 var persistent real    cf2 ( ) 0 io cf2 mesh - -
 var persistent real    cf3 ( ) 0 io cf3 mesh - -
 
-# static terrestrial fields
+% static terrestrial fields
 var persistent real    ter         ( nCells ) 0 io ter      mesh - -
 var persistent integer landmask    ( nCells ) 0 io landmask mesh - -
 var persistent integer ivgtyp      ( nCells ) 0 io lu_index mesh - -
@@ -132,7 +133,7 @@
 var persistent real    shdmax      ( nCells ) 0 io shdmax mesh - -
 var persistent real    albedo12m   ( nMonths nCells ) 0 io albedo12m mesh - -
 
-# description of the vertical grid structure
+% description of the vertical grid structure
 
 var persistent real    hx ( nVertLevelsP1 nCells ) 0 io hx mesh - -
 var persistent real    zgrid ( nVertLevelsP1 nCells ) 0 io zgrid mesh - -
@@ -148,11 +149,11 @@
 var persistent real    zb ( nVertLevelsP1 TWO nEdges ) 0 io zb mesh - -
 var persistent real    zb3 ( nVertLevelsP1 TWO nEdges ) 0 io zb3 mesh - -
 
-#  W-Rayleigh-damping coefficient
+%  W-Rayleigh-damping coefficient
 
 var persistent real    dss ( nVertLevels nCells ) 0 io dss mesh - -
 
-# Horizontally interpolated from first-guess data
+% Horizontally interpolated from first-guess data
 var persistent real    u_fg ( nFGLevels nEdges Time ) 1 - u fg - -
 var persistent real    v_fg ( nFGLevels nEdges Time ) 1 - v fg - -
 var persistent real    t_fg ( nFGLevels nCells Time ) 1 - t fg - -
@@ -163,21 +164,22 @@
 var persistent real    psfc_fg ( nCells Time ) 1 - psfc fg - -
 var persistent real    pmsl_fg ( nCells Time ) 1 - pmsl fg - -
 
-# Horizontally interpolated from first-guess data
+% Horizontally interpolated from first-guess data
 var persistent real    dz_fg  ( nFGSoilLevels nCells Time ) 1 io dz_fg  fg - -
 var persistent real    dzs_fg ( nFGSoilLevels nCells Time ) 1 io dzs_fg fg - -
 var persistent real    zs_fg  ( nFGSoilLevels nCells Time ) 1 io zs_fg  fg - -
 var persistent real    st_fg  ( nFGSoilLevels nCells Time ) 1 io st_fg  fg - -
 var persistent real    sm_fg  ( nFGSoilLevels nCells Time ) 1 io sm_fg  fg - -
 
-# Horizontally interpolated from first-guess data
-#    and should be read in by model
+% Horizontally interpolated from first-guess data
+%    and should be read in by model
 var persistent real    dz ( nSoilLevels nCells Time ) 1 io dz fg - -
 var persistent real    dzs ( nSoilLevels nCells Time ) 1 io dzs fg - -
 var persistent real    zs ( nSoilLevels nCells Time ) 1 io zs fg - -
 var persistent real    sh2o ( nSoilLevels nCells Time ) 1 io sh2o fg - -
 var persistent real    smois ( nSoilLevels nCells Time ) 1 io smois fg - -
 var persistent real    tslb ( nSoilLevels nCells Time ) 1 io tslb fg - -
+var persistent real    smcrel ( nSoilLevels nCells Time ) 1 io smcrel fg - -
 var persistent real    tmn ( nCells Time ) 1 io tmn fg - -
 var persistent real    skintemp ( nCells Time ) 1 io skintemp fg - -
 var persistent real    sst ( nCells Time ) 1 iso sst fg - -
@@ -191,7 +193,7 @@
 var persistent real    sfc_albbck ( nCells Time ) 1 io sfc_albbck fg - -
 var persistent real    xland ( nCells Time ) 1 io xland fg - - 
 
-# 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 o u state - -
 var persistent real    w ( nVertLevelsP1 nCells Time ) 2 o w state - -
 var persistent real    rho_zz ( nVertLevels nCells Time ) 2 o rho_zz state - -
@@ -200,14 +202,14 @@
 var persistent real    qc ( nVertLevels nCells Time ) 2 o qc state scalars moist
 var persistent real    qr ( nVertLevels nCells Time ) 2 o qr state scalars moist
 
-# state variables diagnosed from prognostic state
+% state variables diagnosed from prognostic state
 var persistent real    pressure_p ( nVertLevels nCells Time ) 1 - pressure_p diag - -
 
 var persistent real    u_init ( nVertLevels ) 0 io u_init mesh - -
 var persistent real    t_init ( nVertLevels nCells ) 0 io t_init mesh - -
 var persistent real    qv_init ( nVertLevels ) 0 io qv_init mesh - -
 
-# Diagnostic fields: only written to output
+% Diagnostic fields: only written to output
 var persistent real    rho ( nVertLevels nCells Time ) 1 o rho diag - -
 var persistent real    theta ( nVertLevels nCells Time ) 1 o theta diag - -
 var persistent real    v ( nVertLevels nEdges Time ) 1 o v diag - -
@@ -227,22 +229,22 @@
 
 var persistent real    cqw  ( nVertLevels nCells Time ) 1 - cqw diag - -
 
-var persistent real    surface_pressure    ( nCells Time    ) 1  o surface_pressure    diag - -
+var persistent real    surface_pressure    ( nCells Time    ) 1  io surface_pressure    diag - -
 
-#  coupled variables needed by the solver, but not output...
+%  coupled variables needed by the solver, but not output...
 var persistent real    ru ( nVertLevels nEdges Time ) 1 - ru diag - -
 var persistent real    rw ( nVertLevelsP1 nCells Time ) 1 - rw diag - -
 var persistent real    rtheta_p ( nVertLevels nCells Time ) 1 - rtheta_p diag - -
 var persistent real    rho_p ( nVertLevels nCells Time ) 1 - rho_p diag - -
 
-# Space needed for advection
+% Space needed for advection
 var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 io deriv_two mesh - -
 var persistent integer advCells ( TWENTYONE nCells ) 0 io advCells mesh - -
 
-# Space needed for deformation calculation weights
+% Space needed for deformation calculation weights
 var persistent real    defc_a ( maxEdges nCells ) 0 io defc_a mesh - -
 var persistent real    defc_b ( maxEdges nCells ) 0 io defc_b mesh - -
 
-# Arrays required for reconstruction of velocity field
+% Arrays required for reconstruction of velocity field
 var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 io coeffs_reconstruct mesh - -
 

Modified: branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_hinterp.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_hinterp.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_hinterp.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -545,10 +545,10 @@
       ify = floor(yy)
       icy = ceiling(yy)
 
-      fxfy = max(0., 1.0 - sqrt((xx-real(ifx))**2+(yy-real(ify))**2))
-      fxcy = max(0., 1.0 - sqrt((xx-real(ifx))**2+(yy-real(icy))**2))
-      cxfy = max(0., 1.0 - sqrt((xx-real(icx))**2+(yy-real(ify))**2))
-      cxcy = max(0., 1.0 - sqrt((xx-real(icx))**2+(yy-real(icy))**2))
+      fxfy = max(0.0_RKIND, 1.0 - sqrt((xx-real(ifx))**2+(yy-real(ify))**2))
+      fxcy = max(0.0_RKIND, 1.0 - sqrt((xx-real(ifx))**2+(yy-real(icy))**2))
+      cxfy = max(0.0_RKIND, 1.0 - sqrt((xx-real(icx))**2+(yy-real(ify))**2))
+      cxcy = max(0.0_RKIND, 1.0 - sqrt((xx-real(icx))**2+(yy-real(icy))**2))
 
       ! First, make sure that the point is contained in the source array
       if (ifx &lt; start_x .or. icx &gt; end_x .or. &amp;
@@ -744,13 +744,13 @@
                if (array(ifx+3-i, ify+3-j, izz) == msgval .or. mask_array(ifx+3-i, ify+3-j) == maskval) then
                   weights(i,j) = 0.0
                else
-                  weights(i,j) = max(0., 2.0 - sqrt((xx-real(ifx+3-i))**2+(yy-real(ify+3-j))**2))
+                  weights(i,j) = max(0.0_RKIND, 2.0 - sqrt((xx-real(ifx+3-i))**2+(yy-real(ify+3-j))**2))
                end if
             else
                if (array(ifx+3-i, ify+3-j, izz) == msgval) then
                   weights(i,j) = 0.0
                else
-                  weights(i,j) = max(0., 2.0 - sqrt((xx-real(ifx+3-i))**2+(yy-real(ify+3-j))**2))
+                  weights(i,j) = max(0.0_RKIND, 2.0 - sqrt((xx-real(ifx+3-i))**2+(yy-real(ify+3-j))**2))
                end if
             end if
     

Modified: branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_llxy.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_llxy.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_llxy.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -130,6 +130,8 @@
 !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+   USE MPAS_KIND_TYPES
+
    INTEGER, PARAMETER :: HH=4, VV=5
 
    REAL (KIND=RKIND), PARAMETER :: PI = 3.141592653589793
@@ -1154,10 +1156,10 @@
       ! intersects the Earth's surface at each of the distinctly different
       ! latitudes
       IF (ABS(truelat1-truelat2) .GT. 0.1) THEN
-         cone = ALOG10(COS(truelat1*rad_per_deg)) - &amp;
-                ALOG10(COS(truelat2*rad_per_deg))
-         cone = cone /(ALOG10(TAN((45.0 - ABS(truelat1)/2.0) * rad_per_deg)) - &amp;
-                ALOG10(TAN((45.0 - ABS(truelat2)/2.0) * rad_per_deg)))        
+         cone = LOG10(COS(truelat1*rad_per_deg)) - &amp;
+                LOG10(COS(truelat2*rad_per_deg))
+         cone = cone /(LOG10(TAN((45.0 - ABS(truelat1)/2.0) * rad_per_deg)) - &amp;
+                LOG10(TAN((45.0 - ABS(truelat2)/2.0) * rad_per_deg)))        
       ELSE
          cone = SIN(ABS(truelat1)*rad_per_deg )  
       ENDIF
@@ -1220,9 +1222,9 @@
          ! Longitude
          lon = proj%stdlon + deg_per_rad * ATAN2(proj%hemi*xx,yy)/proj%cone
 # if ( defined (G95) &amp;&amp; ( DA_CORE == 1 ) )
-         lon = DMOD(lon+360., 360.)
+         lon = DMOD(lon+360., 360.0_RKIND)
 # else
-         lon = AMOD(lon+360., 360.)
+         lon = MOD(lon+360., 360.0_RKIND)
 # endif
    
          ! Latitude.  Latitude determined by solving an equation adapted 
@@ -1323,7 +1325,7 @@
   
       proj%rsw = 0.
       IF (proj%lat1 .NE. 0.) THEN
-         proj%rsw = (ALOG(TAN(0.5*((proj%lat1+90.)*rad_per_deg))))/proj%dlon
+         proj%rsw = (LOG(TAN(0.5*((proj%lat1+90.)*rad_per_deg))))/proj%dlon
       ENDIF
 
       RETURN
@@ -1347,7 +1349,7 @@
       IF (deltalon .LT. -180.) deltalon = deltalon + 360.
       IF (deltalon .GT. 180.) deltalon = deltalon - 360.
       i = proj%knowni + (deltalon/(proj%dlon*deg_per_rad))
-      j = proj%knownj + (ALOG(TAN(0.5*((lat + 90.) * rad_per_deg)))) / &amp;
+      j = proj%knownj + (LOG(TAN(0.5*((lat + 90.) * rad_per_deg)))) / &amp;
              proj%dlon - proj%rsw
   
       RETURN
@@ -1531,7 +1533,7 @@
 
       ! Try to determine whether this domain has global coverage
       if (abs(proj%lat1 - proj%latinc/2. + 90.) &lt; 0.001 .and. &amp;
-          abs(mod(proj%lon1 - proj%loninc/2. - proj%stdlon,360.)) &lt; 0.001) then
+          abs(mod(proj%lon1 - proj%loninc/2. - proj%stdlon,360.0_RKIND)) &lt; 0.001) then
          global_domain = .true.
       else
          global_domain = .false.

Modified: branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_queue.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_queue.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_queue.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -7,6 +7,9 @@
 
 module init_atm_queue
 
+   use mpas_kind_types
+
+
    type q_data         ! The user-defined datatype to store in the queue
       real (kind=RKIND) :: lat, lon
       integer :: x, y

Modified: branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_test_cases.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_test_cases.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_init_nhyd_atmos/mpas_init_atm_test_cases.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -5,12 +5,16 @@
    use mpas_constants
    use mpas_dmpar
    use atm_advection
-   use mpas_sort
-   use mpas_timekeeping
-
    use mpas_atmphys_initialize_real
+   use mpas_RBF_interpolation
+   use mpas_vector_reconstruction
 
+   ! Added only clause to keep xlf90 from getting confused from the overloaded abs intrinsic in mpas_timekeeping
+   use mpas_timekeeping !, only: MPAS_Time_type, MPAS_TimeInterval_type, MPAS_Clock_type, &amp;
+                        !        mpas_set_time, mpas_set_timeInterval, mpas_get_time, operator(+), add_t_ti
+   
 
+
    contains
 
 
@@ -30,17 +34,9 @@
       integer :: i
       type (block_type), pointer :: block_ptr
 
-      if (config_test_case == 0) then
-         write(0,*) ' Using initial conditions from input file'
-         block_ptr =&gt; domain % blocklist
-         do while (associated(block_ptr))
-            do i=2,nTimeLevs
-               call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
-            end do
-            block_ptr =&gt; block_ptr % next
-         end do
 
-      else if ((config_test_case == 1) .or. (config_test_case == 2) .or. (config_test_case == 3)) then
+      if ((config_test_case == 1) .or. (config_test_case == 2) .or. (config_test_case == 3)) then
+
          write(0,*) ' Jablonowski and Williamson baroclinic wave test case '
          if (config_test_case == 1) write(0,*) ' no initial perturbation '
          if (config_test_case == 2) write(0,*) ' initial perturbation included '
@@ -49,11 +45,8 @@
          do while (associated(block_ptr))
             write(0,*) ' calling test case setup '
             call init_atm_test_case_jw(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag, config_test_case)
+            call decouple_variables(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag)
             write(0,*) ' returned from test case setup '
-            do i=2,nTimeLevs
-               call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
-            end do
-
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -66,11 +59,8 @@
          do while (associated(block_ptr))
             write(0,*) ' calling test case setup '
             call init_atm_test_case_squall_line(domain % dminfo, block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag, config_test_case)
+            call decouple_variables(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag)
             write(0,*) ' returned from test case setup '
-            do i=2,nTimeLevs
-               call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
-            end do
-
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -81,11 +71,8 @@
          do while (associated(block_ptr))
             write(0,*) ' calling test case setup '
             call init_atm_test_case_mtn_wave(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag, config_test_case)
+            call decouple_variables(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag)
             write(0,*) ' returned from test case setup '
-            do i=2,nTimeLevs
-               call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
-            end do
-
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -98,11 +85,6 @@
                                     block_ptr % diag, config_test_case, block_ptr % parinfo)
             if(config_physics_init) &amp;
                call physics_initialize_real(block_ptr % mesh, block_ptr % fg)
-
-            do i=2,nTimeLevs
-               call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
-            end do
-
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -113,20 +95,35 @@
          do while (associated(block_ptr))
             call init_atm_test_case_sst(domain, domain % dminfo, block_ptr % mesh, block_ptr % fg, block_ptr % state % time_levs(1) % state, &amp;
                                     block_ptr % diag, config_test_case, block_ptr % parinfo)
-            do i=2,nTimeLevs
-               call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
-            end do
-
             block_ptr =&gt; block_ptr % next
          end do
 
       else
 
+         write(0,*) ' Only test cases 1, 2, 3, 4, 5, 6, 7, and 8 are currently supported for nonhydrostatic core '
+         stop
 
-         write(0,*) ' Only test case 1, 2, 3, 4, 5, 6, and 7 are currently supported for nonhydrostatic core '
-         stop
       end if
 
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         do i=2,nTimeLevs
+            call mpas_copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
+         end do
+         block_ptr =&gt; block_ptr % next
+      end do
+
+      !initialization of surface input variables technically not needed to run our current set of
+      !idealized test cases:
+      if (config_test_case &lt; 7)  then
+         block_ptr =&gt; domain % blocklist
+         do while (associated(block_ptr))
+            call physics_idealized_init(block_ptr % mesh, block_ptr % fg)
+            block_ptr =&gt; block_ptr % next
+         end do
+      endif
+
+
    end subroutine init_atm_setup_test_case
 
 !----------------------------------------------------------------------------------------------------------
@@ -141,6 +138,7 @@
       type (mesh_type), intent(inout) :: grid
       type (state_type), intent(inout) :: state
       type (diag_type), intent(inout) :: diag
+      !type (diag_physics_type), intent(inout) :: diag_physics
       integer, intent(in) :: test_case
 
       real (kind=RKIND), parameter :: u0 = 35.0
@@ -150,15 +148,22 @@
       real (kind=RKIND), parameter :: u_perturbation = 1., pert_radius = 0.1, latitude_pert = 40., longitude_pert = 20.
       real (kind=RKIND), parameter :: theta_c = pii/4.0
       real (kind=RKIND), parameter :: lambda_c = 3.0*pii/2.0
-      real (kind=RKIND), parameter :: rh_max = 0.4       ! Maximum relative humidity
       real (kind=RKIND), parameter :: k_x = 9.           ! Normal mode wave number
 
       real (kind=RKIND), dimension(:), pointer :: rdzw, dzu, rdzu, fzm, fzp
+      real (kind=RKIND), dimension(:), pointer :: surface_pressure
       real (kind=RKIND), dimension(:,:), pointer :: zgrid, zx, zz, hx
       real (kind=RKIND), dimension(:,:), pointer :: pressure, ppb, pb, rho_zz, rb, rr, tb, rtb, p, pp, dss, t, rt
       real (kind=RKIND), dimension(:,:,:), pointer :: zf, zf3, zb, zb3
-      real (kind=RKIND), dimension(:,:,:), pointer :: scalars
       real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
+      
+!.. initialization of moisture:
+      integer:: index_qv
+      real (kind=RKIND),parameter :: rh_max = 0.40 ! Maximum relative humidity
+!      real (kind=RKIND),parameter :: rh_max = 0.70 ! Maximum relative humidity
+      real (kind=RKIND),dimension(grid % nVertLevels, grid % nCells) :: qsat, relhum
+      real (kind=RKIND),dimension(:,:,:),pointer:: scalars
+!.. end initialization of moisture.
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, itrp, cell1, cell2, nCellsSolve
 
@@ -166,8 +171,8 @@
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
       integer, dimension(:,:), pointer :: edgesOnEdge, CellsOnEdge
-      real, dimension(:), pointer :: dvEdge, AreaCell 
-      real, dimension(:,:), pointer :: weightsOnEdge
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, AreaCell 
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
 
       real (kind=RKIND) :: u, v, flux, fluxk, lat1, lat2, eta_v, r_pert, u_pert, lat_pert, lon_pert, r
 
@@ -176,8 +181,7 @@
 
       real (kind=RKIND) :: r_earth, etavs, ztemp, zd, zt, dz, gam, delt, str
 
-      real (kind=RKIND), dimension(grid % nVertLevels, grid % nCells) :: rel_hum, temperature, qv
-      real (kind=RKIND) :: ptmp, es, qvs, xnutr, znut, ptemp
+      real (kind=RKIND) :: es, qvs, xnutr, znut, ptemp 
       integer :: iter
 
       real (kind=RKIND), dimension(grid % nVertLevels + 1 ) :: hyai, hybi, znu, znw, znwc, znwv, hyam, hybm
@@ -185,20 +189,23 @@
 
       real (kind=RKIND), dimension(grid % nVertLevels + 1 ) :: sh, zw, ah
       real (kind=RKIND), dimension(grid % nVertLevels ) :: zu, dzw, rdzwp, rdzwm
-      real (kind=RKIND), dimension(grid % nVertLevels ) :: eta, etav, teta, ppi, tt
+      real (kind=RKIND), dimension(grid % nVertLevels ) :: eta, etav, teta, ppi, tt, temperature_1d
 
       real (kind=RKIND) :: d1, d2, d3, cf1, cf2, cf3, cof1, cof2, psurf
 
       !  storage for (lat,z) arrays for zonal velocity calculation
 
-      integer, parameter :: nlat=361
-      real (kind=RKIND), dimension(grid % nVertLevels + 1) :: zz_1d, zgrid_1d, hx_1d
+      logical, parameter :: rebalance = .true.
+      integer, parameter :: nlat=721
       real (kind=RKIND), dimension(grid % nVertLevels) :: flux_zonal
-      real (kind=RKIND), dimension(nlat, grid % nVertLevels) :: u_2d, etavs_2d
+      real (kind=RKIND), dimension(grid % nVertLevels + 1, nlat) :: zgrid_2d
+      real (kind=RKIND), dimension(grid % nVertLevels, nlat) :: u_2d, pp_2d, rho_2d, qv_2d, etavs_2d, zz_2d
+      real (kind=RKIND), dimension(grid % nVertLevels, nlat-1) :: zx_2d 
       real (kind=RKIND), dimension(nlat) :: lat_2d
-      real (kind=RKIND) :: dlat
+      real (kind=RKIND) :: dlat, hx_1d
       real (kind=RKIND) :: z_edge, z_edge3, d2fdx2_cell1, d2fdx2_cell2
 
+      logical, parameter :: moisture = .true.
       !
       ! Scale all distances and areas from a unit sphere to one with radius a
       !
@@ -259,13 +266,25 @@
       t =&gt; state % theta_m % array      
       rt =&gt; diag % rtheta_p % array
 
+      surface_pressure =&gt; diag % surface_pressure % array
+
+!.. initialization of moisture:
       scalars =&gt; state % scalars % array
+      !qsat    =&gt; diag_physics % qsat % array
+      !relhum  =&gt; diag_physics % relhum % array
+      scalars(:,:,:) = 0.0
+      qsat(:,:)      = 0.0
+      relhum(:,:)    = 0.0
+      qv_2d(:,:)     = 0.0
+!.. end initialization of moisture.
 
-      scalars(:,:,:) = 0.
+      surface_pressure(:) = 0.0
 
       call atm_initialize_advection_rk(grid) 
       call atm_initialize_deformation_weights(grid) 
 
+      index_qv = state % index_qv
+
       xnutr = 0.
       zd = 12000.
       znut = eta_t
@@ -293,7 +312,7 @@
 
       !     Metrics for hybrid coordinate and vertical stretching
 
-      str = 1.5
+      str = 1.8
       zt = 45000.
       dz = zt/float(nz1)
 
@@ -323,7 +342,7 @@
  
             ah(k) = 1.-cos(.5*pii*(k-1)*dz/zt)**6
 !            ah(k) = 0.
-            write(0,*) ' k, sh, zw, ah ',k,sh(k),zw(k),ah(k)                        
+            write(0,*) ' k, sh, zw, ah ',k,sh(k),zw(k),ah(k)
       end do
       do k=1,nz1
          dzw (k) = zw(k+1)-zw(k)
@@ -388,47 +407,43 @@
         end do
       enddo
 
-      do k=1,nz1
-        write(0,*) ' k, zgrid(k,1),hx(k,1) ',k,zgrid(k,1),hx(k,1)
-      enddo
+      !do k=1,nz1
+      !  write(0,*) ' k, zgrid(k,1),hx(k,1) ',k,zgrid(k,1),hx(k,1)
+      !enddo
 
-      do k=1,nz1
-        write(0,*) ' k, zx(k,1) ',k,zx(k,1)
-      enddo
+      !do k=1,nz1
+      !  write(0,*) ' k, zx(k,1) ',k,zx(k,1)
+      !enddo
 
       write(0,*) ' grid metrics setup complete '
 
-!**************  section for 2d (lat,z) calc for zonal velocity
+!**************  section for 2d (z,lat) calc for zonal velocity
 
       dlat = 0.5*pii/float(nlat-1)
       do i = 1,nlat
 
         lat_2d(i) = float(i-1)*dlat
-!        write(0,*) ' zonal setup, latitude = ',lat_2d(i)*180./pii
+        phi = lat_2d(i)
+        hx_1d    = u0/gravity*cos(etavs)**1.5                           &amp;
+                   *((-2.*sin(phi)**6                                   &amp;
+                         *(cos(phi)**2+1./3.)+10./63.)                  &amp;
+                         *(u0)*cos(etavs)**1.5                          &amp;
+                    +(1.6*cos(phi)**3                                   &amp;
+                         *(sin(phi)**2+2./3.)-pii/4.)*r_earth*omega_e)
 
-        do k=1,nz
-          phi = lat_2d(i)
-          hx_1d(k) = u0/gravity*cos(etavs)**1.5                            &amp;
-                      *((-2.*sin(phi)**6                                   &amp;
-                            *(cos(phi)**2+1./3.)+10./63.)                  &amp;
-                            *(u0)*cos(etavs)**1.5                          &amp;
-                       +(1.6*cos(phi)**3                                   &amp;
-                            *(sin(phi)**2+2./3.)-pii/4.)*r_earth*omega_e)
-        enddo
-
         do k=1,nz        
-          zgrid_1d(k) = (1.-ah(k))*(sh(k)*(zt-hx_1d(k))+hx_1d(k))  &amp;
+          zgrid_2d(k,i) = (1.-ah(k))*(sh(k)*(zt-hx_1d)+hx_1d)  &amp;
                          + ah(k) * sh(k)* zt        
         end do
         do k=1,nz1
-          zz_1d (k) = (zw(k+1)-zw(k))/(zgrid_1d(k+1)-zgrid_1d(k))
+          zz_2d (k,i) = (zw(k+1)-zw(k))/(zgrid_2d(k+1,i)-zgrid_2d(k,i))
         end do
 
         do k=1,nz1
-          ztemp    = .5*(zgrid_1d(k+1)+zgrid_1d(k))
+          ztemp    = .5*(zgrid_2d(k+1,i)+zgrid_2d(k,i))
           ppb(k,i) = p0*exp(-gravity*ztemp/(rgas*t0b)) 
           pb (k,i) = (ppb(k,i)/p0)**(rgas/cp)
-          rb (k,i) = ppb(k,i)/(rgas*t0b*zz_1d(k))
+          rb (k,i) = ppb(k,i)/(rgas*t0b*zz_2d(k,i))
           tb (k,i) = t0b/pb(k,i)
           rtb(k,i) = rb(k,i)*tb(k,i)
           p  (k,i) = pb(k,i)
@@ -448,40 +463,43 @@
               teta(k) = t0*eta(k)**(rgas*dtdz/gravity) + delta_t*(znut-eta(k))**5
             end if
           end do
-          ! phi = grid % latCell % array (i)
+
           phi = lat_2d (i)
           do k=1,nz1
-            tt(k) = 0.
-            tt(k) = teta(k)+.75*eta(k)*pii*u0/rgas*sin(etav(k))      &amp;
+            temperature_1d(k) = teta(k)+.75*eta(k)*pii*u0/rgas*sin(etav(k))      &amp;
                             *sqrt(cos(etav(k)))*                   &amp;
                               ((-2.*sin(phi)**6                    &amp;
                                    *(cos(phi)**2+1./3.)+10./63.)   &amp;
                                    *2.*u0*cos(etav(k))**1.5        &amp;
                               +(1.6*cos(phi)**3                    &amp;
-                                *(sin(phi)**2+2./3.)-pii/4.)*r_earth*omega_e)
+                                *(sin(phi)**2+2./3.)-pii/4.)*r_earth*omega_e)/(1.+0.61*qv_2d(k,i))
 
 
-            ztemp   = .5*(zgrid_1d(k)+zgrid_1d(k+1))
+            ztemp   = .5*(zgrid_2d(k,i)+zgrid_2d(k+1,i))
             ptemp   = ppb(k,i) + pp(k,i)
-            qv(k,i) = 0.
 
+            !get moisture 
+            if (moisture) then
+              qv_2d(k,i) = env_qv( ztemp, temperature_1d(k), ptemp, rh_max )
+            end if
+
+            tt(k) = temperature_1d(k)*(1.+1.61*qv_2d(k,i))
           end do
-                
+
           do itrp = 1,25
             do k=1,nz1                                
-              rr(k,i)  = (pp(k,i)/(rgas*zz_1d(k))  &amp;
-                          -rb(k,i)*(tt(k)-t0b))/tt(k)
+              rr(k,i)  = (pp(k,i)/(rgas*zz_2d(k,i)) - rb(k,i)*(tt(k)-t0b))/tt(k)
             end do
 
-            ppi(1) = p0-.5*dzw(1)*gravity                         &amp;
-                          *(1.25*(rr(1,i)+rb(1,i))*(1.+qv(1,i))   &amp;
-                            -.25*(rr(2,i)+rb(2,i))*(1.+qv(2,i)))
+            ppi(1) = p0-.5*dzw(1)*gravity                            &amp;
+                          *(1.25*(rr(1,i)+rb(1,i))*(1.+qv_2d(1,i))   &amp;
+                            -.25*(rr(2,i)+rb(2,i))*(1.+qv_2d(2,i)))
 
             ppi(1) = ppi(1)-ppb(1,i)
             do k=1,nz1-1
-              ppi(k+1) = ppi(k)-.5*dzu(k+1)*gravity*                     &amp;
-                            (rr(k  ,i)+(rr(k  ,i)+rb(k  ,i))*qv(k  ,i)   &amp;
-                            +rr(k+1,i)+(rr(k+1,i)+rb(k+1,i))*qv(k+1,i))
+              ppi(k+1) = ppi(k)-.5*dzu(k+1)*gravity*                        &amp;
+                            (rr(k  ,i)+(rr(k  ,i)+rb(k  ,i))*qv_2d(k  ,i)   &amp;
+                            +rr(k+1,i)+(rr(k+1,i)+rb(k+1,i))*qv_2d(k+1,i))
             end do
 
             do k=1,nz1
@@ -493,21 +511,28 @@
         end do  ! end outer iteration loop itr
 
         do k=1,nz1
-          etavs_2d(i,k) = (0.5*(ppb(k,i)+ppb(k,i)+pp(k,i)+pp(k,i))/p0 - 0.252)*pii/2.
-!          u_2d(i,k) = u0*(sin(2.*lat_2d(i))**2) *(cos(etavs_2d(i,k))**1.5)
-          u_2d(i,k) = u0*(sin(2.*lat_2d(i))**2) *(cos(etavs_2d(i,k))**1.5)*(rb(k,i)+rr(k,i))
+          rho_2d(k,i) = rr(k,i)+rb(k,i)
+          pp_2d(k,i) = pp(k,i)
+          etavs_2d(k,i) = ((ppb(k,i)+pp(k,i))/p0 - 0.252)*pii/2.
+          u_2d(k,i) = u0*(sin(2.*lat_2d(i))**2) *(cos(etavs_2d(k,i))**1.5)
         end do
 
       end do  ! end loop over latitudes for 2D zonal wind field calc
 
-!      do i=1,nlat
-!        do k=1,nz1
-!          u_2d(i,k) = u_2d(i,k) - u0*(sin(2.*lat_2d(i))**2) *(cos(etavs_2d(nlat/2,k))**1.5)
-!        end do
-!      end do
-!
-!      write(22,*) nz1,nlat,u_2d
+      !SHP-balance:: in case of rebalacing for geostrophic wind component
+      if (rebalance) then
 
+        do i=1,nlat-1
+          do k=1,nz1
+            zx_2d(k,i) = (zgrid_2d(k,i+1)-zgrid_2d(k,i))/(dlat*r_earth)
+          end do
+        end do
+
+        call init_atm_recompute_geostrophic_wind(u_2d,rho_2d,pp_2d,qv_2d,lat_2d,zz_2d,zx_2d,     &amp;
+                                        cf1,cf2,cf3,fzm,fzp,rdzw,nz1,nlat,dlat)
+
+      end if
+
 !******************************************************************      
 
 !
@@ -516,7 +541,6 @@
 !     reference sounding based on dry isothermal atmosphere
 !
       do i=1, grid % nCells
-        !write(0,*) ' thermodynamic setup, cell ',i
         do k=1,nz1
           ztemp    = .5*(zgrid(k+1,i)+zgrid(k,i))
           ppb(k,i) = p0*exp(-gravity*ztemp/(rgas*t0b)) 
@@ -529,12 +553,17 @@
           rr (k,i) = 0.
         end do
 
-        if(i == 1) then
-          do k=1,nz1
-            write(0,*) ' k, ppb, pb, rb, tb (k,1) ',k,ppb(k,1),pb(k,1),rb(k,1)*zz(k,1),tb(k,1)
-          enddo
-        end if
-!
+!       if(i == 1) then
+!         do k=1,nz1
+!           write(0,*) ' k, ppb, pb, rb, tb (k,1) ',k,ppb(k,1),pb(k,1),rb(k,1)*zz(k,1),tb(k,1)
+!         enddo
+!       end if
+
+      200 format(4i6,8(1x,e15.8))
+      201 format(3i6,8(1x,e15.8))
+      202 format(2i6,10(1x,e15.8))
+      203 format(i6,10(1x,e15.8))
+
 !     iterations to converge temperature as a function of pressure
 !
         do itr = 1,10
@@ -550,42 +579,60 @@
           end do
           phi = grid % latCell % array (i)
           do k=1,nz1
-            tt(k) = 0.
-            tt(k) = teta(k)+.75*eta(k)*pii*u0/rgas*sin(etav(k))      &amp;
+            temperature_1d(k) = teta(k)+.75*eta(k)*pii*u0/rgas*sin(etav(k))      &amp;
                             *sqrt(cos(etav(k)))*                   &amp;
                               ((-2.*sin(phi)**6                    &amp;
                                    *(cos(phi)**2+1./3.)+10./63.)   &amp;
                                    *2.*u0*cos(etav(k))**1.5        &amp;
                               +(1.6*cos(phi)**3                    &amp;
-                                *(sin(phi)**2+2./3.)-pii/4.)*r_earth*omega_e)
+                                *(sin(phi)**2+2./3.)-pii/4.)*r_earth*omega_e)/(1.+0.61*scalars(index_qv,k,i))
 
-
-            !write(0,*) ' k, tt(k) ',k,tt(k)
             ztemp   = .5*(zgrid(k,i)+zgrid(k+1,i))
             ptemp   = ppb(k,i) + pp(k,i)
-!            qv(k,i) = env_qv( ztemp, tt(k), ptemp, 0 )
-            qv(k,i) = 0.
 
+            !get moisture 
+            if (moisture) then

+                !scalars(index_qv,k,i) = env_qv( ztemp, temperature_1d(k), ptemp, rh_max )
+
+               if(ptemp &lt; 50000.) then
+                  relhum(k,i) = 0.0
+               elseif(ptemp &gt; p0) then
+                  relhum(k,i) = 1.0
+               else
+                  relhum(k,i) = (1.-((p0-ptemp)/50000.)**1.25)
+               endif
+               relhum(k,i) = min(rh_max,relhum(k,i))
+
+               !.. calculation of water vapor mixing ratio:
+               if (temperature_1d(k) &gt; 273.15) then
+                   es  = 1000.*0.6112*exp(17.67*(temperature_1d(k)-273.15)/(temperature_1d(k)-29.65))
+               else
+                   es  = 1000.*0.6112*exp(21.8745584*(temperature_1d(k)-273.15)/(temperature_1d(k)-7.66))
+               end if
+               qsat(k,i) = (287.04/461.6)*es/(ptemp-es)
+               if(relhum(k,i) .eq. 0.0) qsat(k,i) = 0.0
+               scalars(index_qv,k,i) = relhum(k,i)*qsat(k,i)
+            end if
+
+            tt(k) = temperature_1d(k)*(1.+1.61*scalars(index_qv,k,i))
+
           end do
-!          do k=2,nz1
-!            cqw(k,i) = 1./(1.+.5*(qv(k,i)+qv(k-1,i)))
-!          end do
                 
           do itrp = 1,25
             do k=1,nz1                                
-              rr(k,i)  = (pp(k,i)/(rgas*zz(k,i))  &amp;
-                          -rb(k,i)*(tt(k)-t0b))/tt(k)
+              rr(k,i)  = (pp(k,i)/(rgas*zz(k,i)) - rb(k,i)*(tt(k)-t0b))/tt(k)
             end do
 
             ppi(1) = p0-.5*dzw(1)*gravity                         &amp;
-                          *(1.25*(rr(1,i)+rb(1,i))*(1.+qv(1,i))   &amp;
-                            -.25*(rr(2,i)+rb(2,i))*(1.+qv(2,i)))
+                          *(1.25*(rr(1,i)+rb(1,i))*(1.+scalars(index_qv,1,i))   &amp;
+                            -.25*(rr(2,i)+rb(2,i))*(1.+scalars(index_qv,2,i)))
 
             ppi(1) = ppi(1)-ppb(1,i)
             do k=1,nz1-1
               ppi(k+1) = ppi(k)-.5*dzu(k+1)*gravity*                     &amp;
-                            (rr(k  ,i)+(rr(k  ,i)+rb(k  ,i))*qv(k  ,i)   &amp;
-                            +rr(k+1,i)+(rr(k+1,i)+rb(k+1,i))*qv(k+1,i))
+                            (rr(k  ,i)+(rr(k  ,i)+rb(k  ,i))*scalars(index_qv,k  ,i)   &amp;
+                            +rr(k+1,i)+(rr(k+1,i)+rb(k+1,i))*scalars(index_qv,k+1,i))
             end do
 
             do k=1,nz1
@@ -603,14 +650,25 @@
           rho_zz (k,i) = rb(k,i) + rr(k,i)
         end do
 
-        if(i == 1) then
-          do k=1,nz1
-            write(0,*) ' k, p, t, rt ',k,p(k,1),t(k,1),rt(k,1)
-          enddo
-        end if
+        !calculation of surface pressure:
+        surface_pressure(i) = 0.5*dzw(1)*gravity                                    &amp;
+                        * (1.25*(rr(1,i) + rb(1,i)) * (1. + scalars(index_qv,1,i))  &amp;
+                        -  0.25*(rr(2,i) + rb(2,i)) * (1. + scalars(index_qv,2,i)))
+        surface_pressure(i) = surface_pressure(i) + pp(1,i) + ppb(1,i)
 
       end do  ! end loop over cells
 
+      !write(0,*)
+      !write(0,*) '--- initialization of water vapor:'
+      !do iCell = 1, grid % nCells
+      !   if(iCell == 1 .or. iCell == grid % nCells) then
+      !      do k = nz1, 1, -1
+      !         write(0,202) iCell,k,t(k,iCell),relhum(k,iCell),qsat(k,iCell),scalars(index_qv,k,iCell)
+      !      enddo
+      !      write(0,*)
+      !   endif
+      !enddo
+
       lat_pert = latitude_pert*pii/180.
       lon_pert = longitude_pert*pii/180.
 
@@ -626,7 +684,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
@@ -637,34 +695,30 @@
             u_pert = 0.0
          end if
 
-         call init_atm_calc_flux_zonal(u_2d,etavs_2d,lat_2d,flux_zonal,lat1,lat2,grid % dvEdge % array(iEdge),a,u0,nz1,nlat)
+         if (rebalance) then
 
-         do k=1,grid % nVertLevels
-!!           etavs = (0.5*(ppb(k,iCell1)+ppb(k,iCell2)+pp(k,iCell1)+pp(k,iCell2))/p0 - 0.252)*pii/2.
-!           etavs = (0.5*(ppb(k,1)+ppb(k,1)+pp(k,1)+pp(k,1))/p0 - 0.252)*pii/2.
-           etavs = (0.5*(ppb(k,440)+ppb(k,440)+pp(k,440)+pp(k,440))/p0 - 0.252)*pii/2.  ! 10262 mesh
-!           etavs = (0.5*(ppb(k,505)+ppb(k,505)+pp(k,505)+pp(k,505))/p0 - 0.252)*pii/2.  ! 40962 mesh
-  
-!           fluxk = u0*flux*(cos(etavs)**1.5)
+           call init_atm_calc_flux_zonal(u_2d,etavs_2d,lat_2d,flux_zonal,lat1,lat2,grid % dvEdge % array(iEdge),a,u0,nz1,nlat)
+           do k=1,grid % nVertLevels
+             fluxk = u0*flux_zonal(k)/(0.5*(rb(k,iCell1)+rb(k,iCell2)+rr(k,iCell1)+rr(k,iCell2)))
+             state % u % array(k,iEdge) = fluxk + u_pert
+           end do
 
-            fluxk = u0*flux_zonal(k)/(0.5*(rb(k,iCell1)+rb(k,iCell2)+rr(k,iCell1)+rr(k,iCell2)))
+         else 
 
-!           if(k.eq.18) then
-!              write(21,*) ' iEdge, u1, u2 ',iEdge,fluxk,u0*flux_zonal(k)
-!           end if
-!!           fluxk = u0*flux*(cos(znuv(k))**(1.5))
-!!           fluxk = u0 * cos(grid % angleEdge % array(iEdge)) * (sin(lat1+lat2)**2) *(cos(etavs)**1.5)
-           state % u % array(k,iEdge) = fluxk + u_pert
-         end do
+           do k=1,grid % nVertLevels
+             etavs = (0.5*(ppb(k,iCell1)+ppb(k,iCell2)+pp(k,iCell1)+pp(k,iCell2))/p0 - 0.252)*pii/2.
+             fluxk = u0*flux*(cos(etavs)**1.5)
+             state % u % array(k,iEdge) = fluxk + u_pert
+           end do
 
-         cell1 = grid % CellsOnEdge % array(1,i)
-         cell2 = grid % CellsOnEdge % array(2,i)
-         if(cell1 &lt;= nCellsSolve .or. cell2 &lt;= nCellsSolve) then
-           do k=1,nz1
-             diag % ru % array (k,iEdge)  = 0.5*(rho_zz(k,cell1)+rho_zz(k,cell2))*state % u % array (k,iEdge)
-           end do
          end if
 
+         cell1 = grid % CellsOnEdge % array(1,iEdge)
+         cell2 = grid % CellsOnEdge % array(2,iEdge)
+         do k=1,nz1
+            diag % ru % array (k,iEdge)  = 0.5*(rho_zz(k,cell1)+rho_zz(k,cell2))*state % u % array (k,iEdge)
+         end do
+
       !
       ! Generate rotated Coriolis field
       !
@@ -692,55 +746,49 @@
       do iEdge = 1,grid % nEdges
          cell1 = CellsOnEdge(1,iEdge)
          cell2 = CellsOnEdge(2,iEdge)
-         if (cell1 &lt;= nCellsSolve .or. cell2 &lt;= nCellsSolve ) then
 
-            do k = 1, grid%nVertLevels
+         do k = 1, grid%nVertLevels
 
-               if (config_theta_adv_order == 2) then
+            if (config_theta_adv_order == 2) then
 
-                  z_edge = (zgrid(k,cell1)+zgrid(k,cell2))/2.
+               z_edge = (zgrid(k,cell1)+zgrid(k,cell2))/2.
 
-               else if (config_theta_adv_order == 3 .or. config_theta_adv_order ==4) then !theta_adv_order == 3 or 4 
+            else if (config_theta_adv_order == 3 .or. config_theta_adv_order ==4) then !theta_adv_order == 3 or 4 
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * zgrid(k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * zgrid(k,cell2)
-                  do i=1, grid % nEdgesOnCell % array (cell1)
-                     if ( grid % CellsOnCell % array (i,cell1) &gt; 0)       &amp;
-                     d2fdx2_cell1 = d2fdx2_cell1 + deriv_two(i+1,1,iEdge) * zgrid(k,grid % CellsOnCell % array (i,cell1))
-                  end do
-                  do i=1, grid % nEdgesOnCell % array (cell2)
-                     if ( grid % CellsOnCell % array (i,cell2) &gt; 0)       &amp;
-                     d2fdx2_cell2 = d2fdx2_cell2 + deriv_two(i+1,2,iEdge) * zgrid(k,grid % CellsOnCell % array (i,cell2))
-                  end do
+               d2fdx2_cell1 = deriv_two(1,1,iEdge) * zgrid(k,cell1)
+               d2fdx2_cell2 = deriv_two(1,2,iEdge) * zgrid(k,cell2)
+               do i=1, grid % nEdgesOnCell % array (cell1)
+                  d2fdx2_cell1 = d2fdx2_cell1 + deriv_two(i+1,1,iEdge) * zgrid(k,grid % CellsOnCell % array (i,cell1))
+                  d2fdx2_cell2 = d2fdx2_cell2 + deriv_two(i+1,2,iEdge) * zgrid(k,grid % CellsOnCell % array (i,cell2))
+               end do
 
-                  z_edge =  0.5*(zgrid(k,cell1) + zgrid(k,cell2))         &amp;
-                                - (grid % dcEdge % array(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.
+               z_edge =  0.5*(zgrid(k,cell1) + zgrid(k,cell2))         &amp;
+                             - (grid % dcEdge % array(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.
 
-                  if (config_theta_adv_order == 3) then
-                     z_edge3 =  - (grid % dcEdge % array(iEdge) **2) * (d2fdx2_cell1 - d2fdx2_cell2) / 12.
-                  else
-                     z_edge3 = 0.
-                  end if
-
+               if (config_theta_adv_order == 3) then
+                  z_edge3 =  - (grid % dcEdge % array(iEdge) **2) * (d2fdx2_cell1 - d2fdx2_cell2) / 12.
+               else
+                  z_edge3 = 0.
                end if
 
-                  zb(k,1,iEdge) = (z_edge-zgrid(k,cell1))*dvEdge(iEdge)/AreaCell(cell1)
-                  zb(k,2,iEdge) = (z_edge-zgrid(k,cell2))*dvEdge(iEdge)/AreaCell(cell2)
-                  zb3(k,1,iEdge)=  z_edge3*dvEdge(iEdge)/AreaCell(cell1)
-                  zb3(k,2,iEdge)=  z_edge3*dvEdge(iEdge)/AreaCell(cell2)
+            end if
 
-                  if (k /= 1) then
-                     zf(k,1,iEdge) = ( fzm(k)*zz(k,cell1)+fzp(k)*zz(k-1,cell1))*zb(k,1,iEdge)
-                     zf(k,2,iEdge) = ( fzm(k)*zz(k,cell2)+fzp(k)*zz(k-1,cell2))*zb(k,2,iEdge)
-                     zf3(k,1,iEdge)= ( fzm(k)*zz(k,cell1)+fzp(k)*zz(k-1,cell1))*zb3(k,1,iEdge)
-                     zf3(k,2,iEdge)= ( fzm(k)*zz(k,cell2)+fzp(k)*zz(k-1,cell2))*zb3(k,2,iEdge)
-                  end if
+               zb(k,1,iEdge) = (z_edge-zgrid(k,cell1))*dvEdge(iEdge)/AreaCell(cell1)
+               zb(k,2,iEdge) = (z_edge-zgrid(k,cell2))*dvEdge(iEdge)/AreaCell(cell2)
+               zb3(k,1,iEdge)=  z_edge3*dvEdge(iEdge)/AreaCell(cell1)
+               zb3(k,2,iEdge)=  z_edge3*dvEdge(iEdge)/AreaCell(cell2)
 
-            end do
+               if (k /= 1) then
+                  zf(k,1,iEdge) = ( fzm(k)*zz(k,cell1)+fzp(k)*zz(k-1,cell1))*zb(k,1,iEdge)
+                  zf(k,2,iEdge) = ( fzm(k)*zz(k,cell2)+fzp(k)*zz(k-1,cell2))*zb(k,2,iEdge)
+                  zf3(k,1,iEdge)= ( fzm(k)*zz(k,cell1)+fzp(k)*zz(k-1,cell1))*zb3(k,1,iEdge)
+                  zf3(k,2,iEdge)= ( fzm(k)*zz(k,cell2)+fzp(k)*zz(k-1,cell2))*zb3(k,2,iEdge)
+               end if
 
-         end if
-       end do
+         end do
 
+      end do
+
       ! for including terrain
       diag % rw % array = 0.
       state % w % array = 0.
@@ -749,7 +797,6 @@
          cell1 = CellsOnEdge(1,iEdge)
          cell2 = CellsOnEdge(2,iEdge)
 
-         if (cell1 &lt;= nCellsSolve .or. cell2 &lt;= nCellsSolve ) then
          do k = 2, grid%nVertLevels
             flux =  (fzm(k)*diag % ru % array(k,iEdge)+fzp(k)*diag % ru % array(k-1,iEdge))
             diag % rw % array(k,cell2) = diag % rw % array(k,cell2) + zf(k,2,iEdge)*flux
@@ -757,13 +804,12 @@
 
             if (config_theta_adv_order ==3) then 
                diag % rw % array(k,cell2) = diag % rw % array(k,cell2)    &amp;
-                                            - sign(1.,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
+                                            - sign(1.0_RKIND,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
                diag % rw % array(k,cell1) = diag % rw % array(k,cell1)    &amp;
-                                            + sign(1.,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
+                                            + sign(1.0_RKIND,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
             end if
 
          end do
-         end if
 
       end do
 
@@ -783,11 +829,9 @@
       do iEdge = 1, grid%nEdges
          do i=1,nEdgesOnEdge(iEdge)
             eoe = edgesOnEdge(i,iEdge)
-            if (eoe &gt; 0) then
-               do k = 1, grid%nVertLevels
-                 diag % v % array(k,iEdge) = diag % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
-              end do
-            end if
+            do k = 1, grid%nVertLevels
+               diag % v % array(k,iEdge) = diag % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
+           end do
          end do
       end do
 
@@ -795,8 +839,8 @@
         psurf = (cf1*(ppb(1,i)+pp(1,i)) + cf2*(ppb(2,i)+pp(2,i)) + cf3*(ppb(3,i)+pp(3,i)))/100.
 
             psurf = (ppb(1,i)+pp(1,i)) + .5*dzw(1)*gravity        &amp;
-                          *(1.25*(rr(1,i)+rb(1,i))*(1.+qv(1,i))   &amp;
-                            -.25*(rr(2,i)+rb(2,i))*(1.+qv(2,i)))
+                          *(1.25*(rr(1,i)+rb(1,i))*(1.+scalars(index_qv,1,i))   &amp;
+                            -.25*(rr(2,i)+rb(2,i))*(1.+scalars(index_qv,2,i)))
 
         write(0,*) ' i, psurf, lat ',i,psurf,grid%latCell%array(i)*180./3.1415828
       enddo
@@ -805,7 +849,7 @@
       do iCell=1,grid%nCells
          do k=1,grid%nVertLevels
             diag % rho % array(k,iCell) = state % rho_zz % array(k,iCell) * zz(k,iCell)
-            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(state % index_qv,k,iCell))
+            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(index_qv,k,iCell))
          end do
       end do
 
@@ -815,7 +859,7 @@
 
    implicit none
    integer, intent(in) :: nz1,nlat
-   real (kind=RKIND), dimension(nlat,nz1), intent(in) :: u_2d,etavs_2d
+   real (kind=RKIND), dimension(nz1,nlat), intent(in) :: u_2d,etavs_2d
    real (kind=RKIND), dimension(nlat), intent(in) :: lat_2d
    real (kind=RKIND), dimension(nz1), intent(out) :: flux_zonal
    real (kind=RKIND), intent(in) :: lat1_in, lat2_in, dvEdge, a, u0
@@ -845,7 +889,7 @@
      w2 = 0.5*(db-da)**2
 
      do k=1,nz1
-       flux_zonal(k) = flux_zonal(k) + w1*u_2d(i,k) + w2*u_2d(i+1,k)
+       flux_zonal(k) = flux_zonal(k) + w1*u_2d(k,i) + w2*u_2d(k,i+1)
      end do
 
      end if
@@ -855,12 +899,105 @@
 !  renormalize for setting cell-face fluxes
 
    do k=1,nz1
-     flux_zonal(k) = sign(1.,lat2_in-lat1_in)*flux_zonal(k)*dlat*a/dvEdge/u0
+     flux_zonal(k) = sign(1.0_RKIND,lat2_in-lat1_in)*flux_zonal(k)*dlat*a/dvEdge/u0
    end do
      
    end subroutine init_atm_calc_flux_zonal
 
+   !SHP-balance
+   subroutine init_atm_recompute_geostrophic_wind(u_2d,rho_2d,pp_2d,qv_2d,lat_2d,zz_2d,zx_2d,     &amp;
+                                         cf1,cf2,cf3,fzm,fzp,rdzw,nz1,nlat,dlat)
 
+   implicit none
+   integer, intent(in) :: nz1,nlat
+   real (kind=RKIND), dimension(nz1,nlat), intent(inout) :: u_2d
+   real (kind=RKIND), dimension(nz1,nlat), intent(in) :: rho_2d, pp_2d, qv_2d, zz_2d
+   real (kind=RKIND), dimension(nz1,nlat-1), intent(in) :: zx_2d
+   real (kind=RKIND), dimension(nlat), intent(in) :: lat_2d
+   real (kind=RKIND), dimension(nz1), intent(in) :: fzm, fzp, rdzw
+   real (kind=RKIND), intent(in) :: cf1, cf2, cf3, dlat
+
+   !local variable
+   real (kind=RKIND), dimension(nz1,nlat-1) :: pgrad, ru, u
+   real (kind=RKIND), dimension(nlat-1) :: f
+   real (kind=RKIND), dimension(nz1+1)  :: dpzx
+
+   real (kind=RKIND), parameter :: omega_e = 7.29212e-05
+   real (kind=RKIND) :: rdx, qtot, r_earth, phi
+   integer :: k,i, itr
+
+   r_earth  = a
+   rdx = 1./(dlat*r_earth)
+
+   do i=1,nlat-1
+     do k=1,nz1
+       pgrad(k,i) = rdx*(pp_2d(k,i+1)/zz_2d(k,i+1)-pp_2d(k,i)/zz_2d(k,i))
+     end do
+
+     dpzx(:) = 0.
+
+     k=1
+     dpzx(k) = .5*zx_2d(k,i)*(cf1*(pp_2d(k  ,i+1)+pp_2d(k  ,i))        &amp;
+                             +cf2*(pp_2d(k+1,i+1)+pp_2d(k+1,i))        &amp;
+                             +cf3*(pp_2d(k+2,i+1)+pp_2d(k+2,i)))
+     do k=2,nz1
+        dpzx(k) = .5*zx_2d(k,i)*(fzm(k)*(pp_2d(k  ,i+1)+pp_2d(k  ,i))   &amp;
+                                +fzp(k)*(pp_2d(k-1,i+1)+pp_2d(k-1,i)))
+     end do
+
+     do k=1,nz1
+        pgrad(k,i) = pgrad(k,i) - rdzw(k)*(dpzx(k+1)-dpzx(k))
+     end do
+   end do
+
+
+   !initial value of v and rv -&gt; that is from analytic sln. 
+   do i=1,nlat-1
+      do k=1,nz1
+         u(k,i) = .5*(u_2d(k,i)+u_2d(k,i+1))
+         ru(k,i) = u(k,i)*(rho_2d(k,i)+rho_2d(k,i+1))*.5
+      end do
+   end do
+
+   write(0,*) &quot;MAX U wind before REBALANCING ----&gt;&quot;, maxval(abs(u))
+
+   !re-calculate geostrophic wind using iteration 
+   do itr=1,50
+   do i=1,nlat-1
+      phi = (lat_2d(i)+lat_2d(i+1))/2.
+      f(i) = 2.*omega_e*sin(phi)
+      do k=1,nz1
+         if (f(i).eq.0.) then
+           ru(k,i) = 0.
+         else
+           qtot = .5*(qv_2d(k,i)+qv_2d(k,i+1))
+           ru(k,i) = - ( 1./(1.+qtot)*pgrad(k,i) + tan(phi)/r_earth*u(k,i)*ru(k,i) )/f(i)
+         end if
+           u(k,i) = ru(k,i)*2./(rho_2d(k,i)+rho_2d(k,i+1))
+      end do
+   end do
+   end do
+
+   write(0,*) &quot;MAX U wind after REBALANCING ----&gt;&quot;, maxval(abs(u))
+
+   !update 2d ru
+   do i=2,nlat-1
+     do k=1,nz1
+       u_2d(k,i) = (ru(k,i-1)+ru(k,i))*.5
+     end do
+   end do
+
+   i=1
+   do k=1,nz1
+      u_2d(k,i) = (3.*u_2d(k,i+1)-u_2d(k,i+2))*.5
+   end do
+   i=nlat
+   do k=1,nz1
+      u_2d(k,i) = (3.*u_2d(k,i-1)-u_2d(k,i-2))*.5
+   end do
+
+
+   end subroutine init_atm_recompute_geostrophic_wind
 !----------------------------------------------------------------------------------------------------------
 
    subroutine init_atm_test_case_squall_line(dminfo, grid, state, diag, test_case)
@@ -885,7 +1022,7 @@
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
       integer, dimension(:,:), pointer :: edgesOnEdge
-      real, dimension(:,:), pointer :: weightsOnEdge
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, cell1, cell2, nCellsSolve
       integer :: index_qv
@@ -1174,7 +1311,7 @@
       call mpas_dmpar_bcast_real(dminfo, pibtop)
 
       ptopb = p0*pibtop**(1./rcp)
-      write(0,*) 'ptopb = ',.01*ptopb
+      write(6,*) 'ptopb = ',.01*ptopb
 
       do i=1, grid % nCells
          pb(nz1,i) = pibtop+.5*dzw(nz1)*gravity*(1.+qvb(nz1))/(cp*tb(nz1,i)*zz(nz1,i))
@@ -1189,6 +1326,7 @@
             rb (k,i) = pb(k,i)**(1./rcv)/((rgas/p0)*tb(k,i)*zz(k,i))
             rtb(k,i) = rb(k,i)*tb(k,i)
             rr (k,i) = p (k,i)**(1./rcv)/((rgas/p0)*t (k,i)*zz(k,i))-rb(k,i)
+            ppb(k,i) = p0*(zz(k,i)*rgas*rtb(k,i)/p0)**(cp/cv)
          end do
       end do
 
@@ -1200,7 +1338,7 @@
             temp     = p(k,i)*thi(k,i)
             pres     = p0*p(k,i)**(1./rcp)
             qvs      = 380.*exp(17.27*(temp-273.)/(temp-36.))/pres
-            scalars(index_qv,k,i) = amin1(0.014,rh(k,i)*qvs)
+            scalars(index_qv,k,i) = min(0.014_RKIND,rh(k,i)*qvs)
          end do
       end do
 
@@ -1283,7 +1421,7 @@
         ptop = p0*pitop**(1./rcp)
         write(0,*) 'ptop  = ',.01*ptop, .01*ptopb
 
-        call mpas_dmpar_bcast_real(dminfo, pitop)
+        call mpas_dmpar_bcast_real(dminfo, ptop)
 
         do i = 1, grid % nCells
 
@@ -1301,7 +1439,7 @@
           end do
           if (itr==1.and.i==1) then
           do k=1,nz1
-          print *, &quot;pp-check&quot;, pp(k,i) 
+          write(0,*) &quot;pp-check&quot;, pp(k,i) 
           end do
           end if
           do k=1,nz1
@@ -1389,7 +1527,7 @@
       do iCell=1,grid%nCells
          do k=1,grid%nVertLevels
             diag % rho % array(k,iCell) = state % rho_zz % array(k,iCell) * zz(k,iCell)
-            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(state % index_qv,k,iCell))
+            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(index_qv,k,iCell))
          end do
       end do
 
@@ -1422,8 +1560,8 @@
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
       integer, dimension(:,:), pointer :: edgesOnEdge, CellsOnEdge
-      real, dimension(:), pointer :: dvEdge, AreaCell, xCell, yCell 
-      real, dimension(:,:), pointer :: weightsOnEdge
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, AreaCell, xCell, yCell 
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, itrp, cell1, cell2, nCellsSolve
       integer :: index_qv
@@ -1433,7 +1571,7 @@
       real (kind=RKIND) :: ztemp, zd, zt, dz, str
 
       real (kind=RKIND), dimension(grid % nVertLevels, grid % nCells) :: rh
-      real (kind=RKIND) :: ptmp, es, qvs, xnutr, ptemp
+      real (kind=RKIND) :: es, qvs, xnutr, ptemp
       integer :: iter
 
       real (kind=RKIND), dimension(grid % nVertLevels + 1 ) :: zc, zw, ah
@@ -1649,7 +1787,7 @@
 ! smoothing grid for the upper level &gt;&gt; but not propoer for parallel programing 
       dzmin=.7
       do k=2,nz1
-         sm = .25*min((zc(k)-zc(k-1))/dz,1.)
+         sm = .25*min((zc(k)-zc(k-1))/dz,1.0_RKIND)
          do i=1,grid % nCells
             hx(k,i) = hx(k-1,i)
          end do
@@ -1674,7 +1812,7 @@
             end if
 
          end do !end of iteration for smoothing
-99       print *,&quot;PASS-SHP&quot;
+99       write(0,*) &quot;PASS-SHP&quot;
       end do
 
       do iCell=1,grid % nCells
@@ -1826,7 +1964,7 @@
               temp   = p(k,i)*t(k,i)
               pres   = p0*p(k,i)**(1./rcp)
               qvs    = 380.*exp(17.27*(temp-273.)/(temp-36.))/pres
-              scalars(index_qv,k,i) = amin1(0.014,rh(k,i)*qvs)
+              scalars(index_qv,k,i) = min(0.014_RKIND,rh(k,i)*qvs)
            end do
                          
            do k=1,nz1
@@ -1845,7 +1983,7 @@
       write(0,*) ' *** sounding for the simulation ***'
       write(0,*) '    z       theta       pres         qv       rho_m        u        rr'
       do k=1,nz1
-         write(0,'(8(f14.9,2x))') .5*(zgrid(k,1)+zgrid(k+1,1))/1000.,   &amp;
+         write(6,'(8(f14.9,2x))') .5*(zgrid(k,1)+zgrid(k+1,1))/1000.,   &amp;
                        t(k,1)/(1.+1.61*scalars(index_qv,k,1)),        &amp;
                        .01*p0*p(k,1)**(1./rcp),                       &amp;
                        1000.*scalars(index_qv,k,1),                   &amp;
@@ -1949,9 +2087,9 @@
 
             if (config_theta_adv_order ==3) then
                diag % rw % array(k,cell2) = diag % rw % array(k,cell2)    &amp;
-                                            - sign(1.,ru(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
+                                            - sign(1.0_RKIND,ru(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
                diag % rw % array(k,cell1) = diag % rw % array(k,cell1)    &amp;
-                                            + sign(1.,ru(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
+                                            + sign(1.0_RKIND,ru(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
             end if
 
          end do
@@ -1999,7 +2137,7 @@
       do iCell=1,grid%nCells
          do k=1,grid%nVertLevels
             diag % rho % array(k,iCell) = state % rho_zz % array(k,iCell) * zz(k,iCell)
-            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(state % index_qv,k,iCell))
+            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(index_qv,k,iCell))
          end do
       end do
 
@@ -2069,7 +2207,7 @@
       real (kind=RKIND), dimension(:,:), pointer :: sorted_arr
 
       real(kind=RKIND), dimension(:), pointer :: hs, hs1
-      real(kind=RKIND) :: hm, zh, dzmin, dzmina, dzminf, sm
+      real(kind=RKIND) :: hm, zh, dzmin, dzmina, dzmina_global, dzminf, sm
       integer :: nsmterrain, kz, sfc_k
       logical :: hybrid, smooth
 
@@ -2520,12 +2658,12 @@
       grid % soiltemp % array(:) = 0.0
 
       call map_set(PROJ_LATLON, proj, &amp;
-                   latinc = 1.0, &amp;
-                   loninc = 1.0, &amp;
-                   knowni = 1.0, &amp;
-                   knownj = 1.0, &amp;
-                   lat1 = -89.5, &amp;
-                   lon1 = -179.5)
+                   latinc = 1.0_RKIND, &amp;
+                   loninc = 1.0_RKIND, &amp;
+                   knowni = 1.0_RKIND, &amp;
+                   knownj = 1.0_RKIND, &amp;
+                   lat1 = -89.5_RKIND, &amp;
+                   lon1 = -179.5_RKIND)
 
       write(fname,'(a,i5.5,a1,i5.5,a1,i5.5,a1,i5.5)') trim(config_geog_data_path)//'soiltemp_1deg/',1,'-',180,'.',1,'-',180
 write(0,*) trim(fname)
@@ -2568,8 +2706,8 @@
             end if
 if (y &lt; 1.0) y = 1.0
 if (y &gt; 179.0) y = 179.0
-!            grid % soiltemp % array(iCell) = interp_sequence(x, y, 1, soiltemp_1deg, 1, 360, 1, 180, 1, 1, -1.e30, interp_list, 1)
-            grid % soiltemp % array(iCell) = interp_sequence(x, y, 1, soiltemp_1deg, 1, 360, 1, 180, 1, 1, 0., interp_list, 1)
+!            grid % soiltemp % array(iCell) = interp_sequence(x, y, 1, soiltemp_1deg, 1, 360, 1, 180, 1, 1, -1.e30_RKIND, interp_list, 1)
+            grid % soiltemp % array(iCell) = interp_sequence(x, y, 1, soiltemp_1deg, 1, 360, 1, 180, 1, 1, 0.0_RKIND, interp_list, 1)
          else
             grid % soiltemp % array(iCell) = 0.0
          end if
@@ -2595,12 +2733,12 @@
       grid % snoalb % array(:) = 0.0
 
       call map_set(PROJ_LATLON, proj, &amp;
-                   latinc = 1.0, &amp;
-                   loninc = 1.0, &amp;
-                   knowni = 1.0, &amp;
-                   knownj = 1.0, &amp;
-                   lat1 = -89.5, &amp;
-                   lon1 = -179.5)
+                   latinc = 1.0_RKIND, &amp;
+                   loninc = 1.0_RKIND, &amp;
+                   knowni = 1.0_RKIND, &amp;
+                   knownj = 1.0_RKIND, &amp;
+                   lat1 = -89.5_RKIND, &amp;
+                   lon1 = -179.5_RKIND)
 
       write(fname,'(a,i5.5,a1,i5.5,a1,i5.5,a1,i5.5)') trim(config_geog_data_path)//'maxsnowalb/',1,'-',180,'.',1,'-',180
 write(0,*) trim(fname)
@@ -2643,8 +2781,8 @@
             end if
 if (y &lt; 1.0) y = 1.0
 if (y &gt; 179.0) y = 179.0
-!            grid % snoalb % array(iCell) = interp_sequence(x, y, 1, maxsnowalb, 1, 360, 1, 180, 1, 1, -1.e30, interp_list, 1)
-            grid % snoalb % array(iCell) = interp_sequence(x, y, 1, maxsnowalb, 1, 360, 1, 180, 1, 1, 0., interp_list, 1)
+!            grid % snoalb % array(iCell) = interp_sequence(x, y, 1, maxsnowalb, 1, 360, 1, 180, 1, 1, -1.e30_RKIND, interp_list, 1)
+            grid % snoalb % array(iCell) = interp_sequence(x, y, 1, maxsnowalb, 1, 360, 1, 180, 1, 1, 0.0_RKIND, interp_list, 1)
          else
             grid % snoalb % array(iCell) = 0.0
          end if
@@ -2673,12 +2811,12 @@
       grid % greenfrac % array(:,:) = 0.0
 
       call map_set(PROJ_LATLON, proj, &amp;
-                   latinc = 0.144, &amp;
-                   loninc = 0.144, &amp;
-                   knowni = 1.0, &amp;
-                   knownj = 1.0, &amp;
-                   lat1 = -89.928, &amp;
-                   lon1 = -179.928)
+                   latinc = 0.144_RKIND, &amp;
+                   loninc = 0.144_RKIND, &amp;
+                   knowni = 1.0_RKIND, &amp;
+                   knownj = 1.0_RKIND, &amp;
+                   lat1 = -89.928_RKIND, &amp;
+                   lon1 = -179.928_RKIND)
 
       write(fname,'(a,i5.5,a1,i5.5,a1,i5.5,a1,i5.5)') trim(config_geog_data_path)//'greenfrac/',1,'-',1250,'.',1,'-',1250
 write(0,*) trim(fname)
@@ -2715,7 +2853,7 @@
 if (y &lt; 1.0) y = 1.0
 if (y &gt; 1249.0) y = 1249.0
             do k=1,12
-               grid % greenfrac % array(k,iCell) = interp_sequence(x, y, k, vegfra, 1, 2500, 1, 1250, 1, 12, -1.e30, interp_list, 1)
+               grid % greenfrac % array(k,iCell) = interp_sequence(x, y, k, vegfra, 1, 2500, 1, 1250, 1, 12, -1.e30_RKIND, interp_list, 1)
             end do
          else
             grid % greenfrac % array(:,iCell) = 0.0
@@ -2744,12 +2882,12 @@
       grid % albedo12m % array(:,:) = 0.0
 
       call map_set(PROJ_LATLON, proj, &amp;
-                   latinc = 0.144, &amp;
-                   loninc = 0.144, &amp;
-                   knowni = 1.0, &amp;
-                   knownj = 1.0, &amp;
-                   lat1 = -89.928, &amp;
-                   lon1 = -179.928)
+                   latinc = 0.144_RKIND, &amp;
+                   loninc = 0.144_RKIND, &amp;
+                   knowni = 1.0_RKIND, &amp;
+                   knownj = 1.0_RKIND, &amp;
+                   lat1 = -89.928_RKIND, &amp;
+                   lon1 = -179.928_RKIND)
 
       write(fname,'(a,i5.5,a1,i5.5,a1,i5.5,a1,i5.5)') trim(config_geog_data_path)//'albedo_ncep/',1,'-',1250,'.',1,'-',1250
 write(0,*) trim(fname)
@@ -2786,7 +2924,7 @@
 if (y &lt; 1.0) y = 1.0
 if (y &gt; 1249.0) y = 1249.0
             do k=1,12
-               grid % albedo12m % array(k,iCell) = interp_sequence(x, y, k, vegfra, 1, 2500, 1, 1250, 1, 12, 0.0, interp_list, 1)
+               grid % albedo12m % array(k,iCell) = interp_sequence(x, y, k, vegfra, 1, 2500, 1, 1250, 1, 12, 0.0_RKIND, interp_list, 1)
             end do
          else
             grid % albedo12m % array(:,iCell) = 8.0
@@ -2822,12 +2960,12 @@
           
             if (field % iproj == PROJ_LATLON) then
                call map_set(PROJ_LATLON, proj, &amp;
-                            latinc = real(field % deltalat), &amp;
-                            loninc = real(field % deltalon), &amp;
-                            knowni = 1.0, &amp;
-                            knownj = 1.0, &amp;
-                            lat1 = real(field % startlat), &amp;
-                            lon1 = real(field % startlon))
+                            latinc = real(field % deltalat,RKIND), &amp;
+                            loninc = real(field % deltalon,RKIND), &amp;
+                            knowni = 1.0_RKIND, &amp;
+                            knownj = 1.0_RKIND, &amp;
+                            lat1 = real(field % startlat,RKIND), &amp;
+                            lon1 = real(field % startlon,RKIND))
             end if
 
 
@@ -2848,9 +2986,9 @@
                   call latlon_to_ij(proj, lat, lon, x, y)
                end if
                if (ndims == 1) then
-                  destField1d(i) = interp_sequence(x, y, 1, field % slab, 1, field % nx, 1, field % ny, 1, 1, -1.e30, interp_list, 1)
+                  destField1d(i) = interp_sequence(x, y, 1, field % slab, 1, field % nx, 1, field % ny, 1, 1, -1.e30_RKIND, interp_list, 1)
                else if (ndims == 2) then
-                  destField2d(k,i) = interp_sequence(x, y, 1, field % slab, 1, field % nx, 1, field % ny, 1, 1, -1.e30, interp_list, 1)
+                  destField2d(k,i) = interp_sequence(x, y, 1, field % slab, 1, field % nx, 1, field % ny, 1, 1, -1.e30_RKIND, interp_list, 1)
                end if
             end do
          end if
@@ -3014,9 +3152,9 @@
             hx(k,:) = hx(k-1,:)
             dzminf = zw(k)-zw(k-1)
 
-!            dzmin = max(.5,1.-.5*zw(k)/hm)
+!            dzmin = max(0.5_RKIND,1.-.5*zw(k)/hm)
 
-            sm = .05*min(.5*zw(k)/hm,1.)
+            sm = .05*min(0.5_RKIND*zw(k)/hm,1.0_RKIND)
           
             do i=1,50
                do iCell=1,grid %nCells
@@ -3045,10 +3183,11 @@
 
              !  dzmina = minval(hs(:)-hx(k-1,:))
                dzmina = minval(zw(k)+ah(k)*hs(:)-zw(k-1)-ah(k-1)*hx(k-1,:))
+               call mpas_dmpar_min_real(dminfo, dzmina, dzmina_global)
              !  write(0,*) ' k,i, dzmina, dzmin, zw(k)-zw(k-1) ', k,i, dzmina, dzmin, zw(k)-zw(k-1)
-               if (dzmina &gt;= dzmin*(zw(k)-zw(k-1))) then
+               if (dzmina_global &gt;= dzmin*(zw(k)-zw(k-1))) then
                   hx(k,:)=hs(:)
-                  dzminf = dzmina
+                  dzminf = dzmina_global
                else
                   exit
                end if
@@ -3169,6 +3308,13 @@
 
       if (config_met_interp) then
 
+      !ldf (2011-11-19): added initialization of the sea-surface temperature, seaice fraction, and
+      !seaice flag:
+       fg % sst % array    = 0.
+       fg % xice % array   = 0.
+       fg % seaice % array = 0.
+      !ldf end.
+
       !
       ! First, try to locate the LANDSEA field for use as an interpolation mask
       !
@@ -3289,18 +3435,18 @@
           
             if (field % iproj == PROJ_LATLON) then
                call map_set(PROJ_LATLON, proj, &amp;
-                            latinc = real(field % deltalat), &amp;
-                            loninc = real(field % deltalon), &amp;
-                            knowni = 1.0, &amp;
-                            knownj = 1.0, &amp;
-                            lat1 = real(field % startlat), &amp;
-                            lon1 = real(field % startlon))
+                            latinc = real(field % deltalat,RKIND), &amp;
+                            loninc = real(field % deltalon,RKIND), &amp;
+                            knowni = 1.0_RKIND, &amp;
+                            knownj = 1.0_RKIND, &amp;
+                            lat1 = real(field % startlat,RKIND), &amp;
+                            lon1 = real(field % startlon,RKIND))
             else if (field % iproj == PROJ_GAUSS) then
                call map_set(PROJ_GAUSS, proj, &amp;
                             nlat = nint(field % deltalat), &amp;
-                            loninc = real(field % deltalon), &amp;
-                            lat1 = real(field % startlat), &amp;
-                            lon1 = real(field % startlon))
+                            loninc = real(field % deltalon,RKIND), &amp;
+                            lat1 = real(field % startlat,RKIND), &amp;
+                            lon1 = real(field % startlon,RKIND))
 !                            nxmax = nint(360.0 / field % deltalon), &amp;
             end if
 
@@ -3686,7 +3832,8 @@
       ! Set SST based on SKINTEMP field if it wasn't found in input data
       if (minval(fg % sst % array) == 0.0 .and. maxval(fg % sst % array) == 0.0) then
          write(0,*) 'Setting SST from SKINTEMP'
-         where (grid % landmask % array == 0) fg % sst % array = fg % skintemp % array
+         !where (grid % landmask % array == 0) fg % sst % array = fg % skintemp % array
+         fg % sst % array = fg % skintemp % array
       end if
 
       ! Set SNOWC (snow-cover flag) based on SNOW
@@ -3736,13 +3883,13 @@
           
                if (field % iproj == PROJ_PS) then
                   call map_set(PROJ_PS, proj, &amp;
-                               dx = real(field % dx * 1000.0), &amp;
-                               truelat1 = real(field % truelat1), &amp;
-                               stdlon = real(field % xlonc), &amp;
-                               knowni = real(field % nx / 2.0), &amp;
-                               knownj = real(field % ny / 2.0), &amp;
-                               lat1 = real(field % startlat), &amp;
-                               lon1 = real(field % startlon))
+                               dx = real(field % dx * 1000.0,RKIND), &amp;
+                               truelat1 = real(field % truelat1,RKIND), &amp;
+                               stdlon = real(field % xlonc,RKIND), &amp;
+                               knowni = real(field % nx / 2.0,RKIND), &amp;
+                               knownj = real(field % ny / 2.0,RKIND), &amp;
+                               lat1 = real(field % startlat,RKIND), &amp;
+                               lon1 = real(field % startlon,RKIND))
                end if
 
                if (index(field % field, 'SEAICE') /= 0) then
@@ -3948,6 +4095,20 @@
 
 
       !
+      ! Reconstruct zonal and meridional winds for diagnostic puposes:
+      !
+      call mpas_rbf_interp_initialize(grid)
+      call mpas_init_reconstruct(grid)
+      call mpas_reconstruct(grid, state % u % array,                        &amp;
+                            diag % uReconstructX % array,                   &amp;
+                            diag % uReconstructY % array,                   &amp;
+                            diag % uReconstructZ % array,                   &amp;
+                            diag % uReconstructZonal % array,               &amp;
+                            diag % uReconstructMeridional % array           &amp;
+                           )
+   
+
+      !
       ! Adjust surface pressure for difference in topography
       !
       do sfc_k=1,config_nfglevels
@@ -4083,9 +4244,9 @@
 
             if (config_theta_adv_order ==3) then 
                diag % rw % array(k,cell2) = diag % rw % array(k,cell2)    &amp;
-                                            - sign(1.,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
+                                            - sign(1.0_RKIND,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
                diag % rw % array(k,cell1) = diag % rw % array(k,cell1)    &amp;
-                                            + sign(1.,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
+                                            + sign(1.0_RKIND,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
             end if
 
          end do
@@ -4106,7 +4267,8 @@
       end if    ! config_met_interp
 
      
-      ! Calculate surface pressure
+      ! Calculate surface pressure (This is an ad-hoc calculation. The actual surface pressure is actually re-calculated at
+      !the top of the subroutine MPAS_to_physics in ../core_atmos_physics/mpas_atmphys_interface_nhyd.F
       do iCell=1,grid%nCells
          diag % surface_pressure % array(iCell) = 0.5*gravity/rdzw(1)                                              &amp;
                                                 * (1.25* rho_zz(1,iCell) * (1. + scalars(state % index_qv, 1, iCell))  &amp;
@@ -4214,18 +4376,18 @@
              
                if (field % iproj == PROJ_LATLON) then
                   call map_set(PROJ_LATLON, proj, &amp;
-                               latinc = real(field % deltalat), &amp;
-                               loninc = real(field % deltalon), &amp;
-                               knowni = 1.0, &amp;
-                               knownj = 1.0, &amp;
-                               lat1 = real(field % startlat), &amp;
-                               lon1 = real(field % startlon))
+                               latinc = real(field % deltalat,RKIND), &amp;
+                               loninc = real(field % deltalon,RKIND), &amp;
+                               knowni = 1.0_RKIND, &amp;
+                               knownj = 1.0_RKIND, &amp;
+                               lat1 = real(field % startlat,RKIND), &amp;
+                               lon1 = real(field % startlon,RKIND))
                else if (field % iproj == PROJ_GAUSS) then
                   call map_set(PROJ_GAUSS, proj, &amp;
                                nlat = nint(field % deltalat), &amp;
-                               loninc = real(field % deltalon), &amp;
-                               lat1 = real(field % startlat), &amp;
-                               lon1 = real(field % startlon))
+                               loninc = real(field % deltalon,RKIND), &amp;
+                               lat1 = real(field % startlat,RKIND), &amp;
+                               lon1 = real(field % startlon,RKIND))
 !                               nxmax = nint(360.0 / field % deltalon), &amp;
                end if
    
@@ -4246,7 +4408,7 @@
                      lon = lon - 360.0
                      call latlon_to_ij(proj, lat, lon, x, y)
                   end if
-                  fg % sst % array(iCell) = interp_sequence(x, y, 1, slab_r8, 1, field % nx, 1, field % ny, 1, 1, -1.e30, interp_list, 1)
+                  fg % sst % array(iCell) = interp_sequence(x, y, 1, slab_r8, 1, field % nx, 1, field % ny, 1, 1, -1.e30_RKIND, interp_list, 1)
                end do
 
                deallocate(slab_r8)
@@ -4271,18 +4433,18 @@
              
                if (field % iproj == PROJ_LATLON) then
                   call map_set(PROJ_LATLON, proj, &amp;
-                               latinc = real(field % deltalat), &amp;
-                               loninc = real(field % deltalon), &amp;
-                               knowni = 1.0, &amp;
-                               knownj = 1.0, &amp;
-                               lat1 = real(field % startlat), &amp;
-                               lon1 = real(field % startlon))
+                               latinc = real(field % deltalat,RKIND), &amp;
+                               loninc = real(field % deltalon,RKIND), &amp;
+                               knowni = 1.0_RKIND, &amp;
+                               knownj = 1.0_RKIND, &amp;
+                               lat1 = real(field % startlat,RKIND), &amp;
+                               lon1 = real(field % startlon,RKIND))
                else if (field % iproj == PROJ_GAUSS) then
                   call map_set(PROJ_GAUSS, proj, &amp;
                                nlat = nint(field % deltalat), &amp;
-                               loninc = real(field % deltalon), &amp;
-                               lat1 = real(field % startlat), &amp;
-                               lon1 = real(field % startlon))
+                               loninc = real(field % deltalon,RKIND), &amp;
+                               lat1 = real(field % startlat,RKIND), &amp;
+                               lon1 = real(field % startlon,RKIND))
 !                               nxmax = nint(360.0 / field % deltalon), &amp;
                end if
    
@@ -4303,7 +4465,7 @@
                      lon = lon - 360.0
                      call latlon_to_ij(proj, lat, lon, x, y)
                   end if
-                  fg % xice % array(iCell) = interp_sequence(x, y, 1, slab_r8, 1, field % nx, 1, field % ny, 1, 1, -1.e30, interp_list, 1)
+                  fg % xice % array(iCell) = interp_sequence(x, y, 1, slab_r8, 1, field % nx, 1, field % ny, 1, 1, -1.e30_RKIND, interp_list, 1)
 
                end do
 
@@ -4388,26 +4550,8 @@
    end function four_pt
 #endif
 
+!----------------------------------------------------------------------------------------------------------
 
-   real 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.
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-      implicit none
-
-      real (kind=RKIND), intent(in) :: lat1, lon1, lat2, lon2, radius
-
-      real (kind=RKIND) :: arg1
-
-      arg1 = sqrt( sin(0.5*(lat2-lat1))**2 +  &amp;
-                   cos(lat1)*cos(lat2)*sin(0.5*(lon2-lon1))**2 )
-      sphere_distance = 2.*radius*asin(arg1)
-
-   end function sphere_distance
-
-
    integer function nearest_cell(target_lat, target_lon, &amp;
                                  start_cell, &amp;
                                  nCells, maxEdges, nEdgesOnCell, cellsOnCell, latCell, lonCell)
@@ -4432,12 +4576,12 @@
 
       do while (nearest_cell /= current_cell)
          current_cell = nearest_cell
-         current_distance = sphere_distance(latCell(current_cell), lonCell(current_cell), target_lat, target_lon, 1.0)
+         current_distance = sphere_distance(latCell(current_cell), lonCell(current_cell), target_lat, target_lon, 1.0_RKIND)
          nearest_cell = current_cell
          nearest_distance = current_distance
          do i = 1, nEdgesOnCell(current_cell)
             iCell = cellsOnCell(i,current_cell)
-            d = sphere_distance(latCell(iCell), lonCell(iCell), target_lat, target_lon, 1.0)
+            d = sphere_distance(latCell(iCell), lonCell(iCell), target_lat, target_lon, 1.0_RKIND)
             if (d &lt; nearest_distance) then
                nearest_cell = iCell
                nearest_distance = d
@@ -4475,13 +4619,13 @@
 
       do while (nearest_edge /= current_edge)
          current_edge = nearest_edge
-         current_distance = sphere_distance(latEdge(current_edge), lonEdge(current_edge), target_lat, target_lon, 1.0)
+         current_distance = sphere_distance(latEdge(current_edge), lonEdge(current_edge), target_lat, target_lon, 1.0_RKIND)
          nearest_edge = current_edge
          nearest_distance = current_distance
          cell1 = cellsOnEdge(1,current_edge)
          cell2 = cellsOnEdge(2,current_edge)
-         cell1_dist = sphere_distance(latCell(cell1), lonCell(cell1), target_lat, target_lon, 1.0)
-         cell2_dist = sphere_distance(latCell(cell2), lonCell(cell2), target_lat, target_lon, 1.0)
+         cell1_dist = sphere_distance(latCell(cell1), lonCell(cell1), target_lat, target_lon, 1.0_RKIND)
+         cell2_dist = sphere_distance(latCell(cell2), lonCell(cell2), target_lat, target_lon, 1.0_RKIND)
          if (cell1_dist &lt; cell2_dist) then
             iCell = cell1
          else
@@ -4489,7 +4633,7 @@
          end if
          do i = 1, nEdgesOnCell(iCell)
             iEdge = edgesOnCell(i,iCell)
-            d = sphere_distance(latEdge(iEdge), lonEdge(iEdge), target_lat, target_lon, 1.0)
+            d = sphere_distance(latEdge(iEdge), lonEdge(iEdge), target_lat, target_lon, 1.0_RKIND)
             if (d &lt; nearest_distance) then
                nearest_edge = iEdge
                nearest_distance = d
@@ -4500,7 +4644,7 @@
    end function nearest_edge
 
 
-   real function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val)
+   real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val)
 
       implicit none
 
@@ -4602,4 +4746,179 @@
 
    end subroutine init_atm_check_read_error
 
+
+!----------------------------------------------------------------------------------------------------------
+
+   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.
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+      implicit none
+
+      real (kind=RKIND), intent(in) :: lat1, lon1, lat2, lon2, radius
+
+      real (kind=RKIND) :: arg1
+
+      arg1 = sqrt( sin(0.5*(lat2-lat1))**2 +  &amp;
+                   cos(lat1)*cos(lat2)*sin(0.5*(lon2-lon1))**2 )
+      sphere_distance = 2.*radius*asin(arg1)
+
+   end function sphere_distance
+
+!--------------------------------------------------------------------
+
+   real (kind=RKIND) function env_qv( z, temperature, pressure, rh_max )
+
+      implicit none
+      real (kind=RKIND) :: z, temperature, pressure, ztr, es, qvs, p0, rh_max
+
+      p0 = 100000.
+
+!      ztr = 5000.
+!
+!      if(z .gt. ztr) then
+!         env_qv = 0.
+!      else
+!         if(z.lt.2000.) then
+!            env_qv = .5
+!         else
+!            env_qv = .5*(1.-(z-2000.)/(ztr-2000.))
+!         end if
+!      end if
+
+       if (pressure .lt. 50000. ) then
+           env_qv = 0.0
+       else
+           env_qv = (1.-((p0-pressure)/50000.)**1.25)
+       end if
+
+       env_qv = min(rh_max,env_qv)
+
+! env_qv is the relative humidity, turn it into mixing ratio
+       if (temperature .gt. 273.15) then
+           es  = 1000.*0.6112*exp(17.67*(temperature-273.15)/(temperature-29.65))
+       else
+           es  = 1000.*0.6112*exp(21.8745584*(temperature-273.16)/(temperature-7.66))
+       end if
+       qvs = (287.04/461.6)*es/(pressure-es)
+
+       ! qvs =  380.*exp(17.27*(temperature-273.)/(temperature-36.))/pressure
+
+        env_qv = env_qv*qvs
+
+   end function env_qv
+
+
+   subroutine physics_idealized_init(mesh, fg)
+   
+      implicit none
+      
+      !input and output arguments:
+      type(mesh_type),intent(inout):: mesh
+      type (fg_type), intent(inout) :: fg
+      
+      !local variables:
+      integer:: iCell,iMonth,iSoil
+      
+      !---------------------------------------------------------------------------------------------
+      
+      !initialization of surface input variables that are not needed if we run the current set of
+      !idealized test cases:
+      
+      
+      do iCell = 1, mesh % nCells
+      
+         !terrain,soil type, and vegetation:
+         mesh % ter      % array(iCell) = 0.
+         fg % xice       % array(iCell) = 0.
+         mesh % landmask % array(iCell) = 0
+         mesh % lu_index  % array(iCell) = 0
+         mesh % soilcat_top % array(iCell) = 0
+         mesh % shdmin   % array(iCell) = 0.
+         mesh % shdmax   % array(iCell) = 0.
+         fg % vegfra   % array(iCell) = 0.
+         fg % sfc_albbck % array(iCell) = 0.
+         fg % xland % array(iCell) = 0.
+         fg % seaice % array(iCell) = 0.
+      
+         !snow coverage:
+         fg % snow     % array(iCell) = 0.
+         fg % snowc    % array(iCell) = 0.
+         mesh % snoalb % array(iCell) = 0.08
+         fg % snowh % array(iCell) = 0.
+      
+         !surface and sea-surface temperatures:
+         fg % skintemp % array(iCell) = 288.0
+         fg % sst      % array(iCell) = 288.0
+      
+         !soil layers:
+         fg % tmn % array(iCell) = 288.0
+         do iSoil = 1, mesh % nSoilLevels
+            fg % tslb % array(iSoil,iCell)   = 288.0
+            fg % smcrel % array(iSoil,iCell) =   0.0
+            fg % sh2o   % array(iSoil,iCell) =   0.0
+            fg % smois  % array(iSoil,iCell) =   0.0
+            fg % dzs    % array(iSoil,iCell) =   0.0
+         enddo
+      
+         !monthly climatological surface albedo and greeness fraction:
+         do iMonth = 1, mesh % nMonths
+            mesh % albedo12m % array(iMonth,iCell) = 0.08
+            mesh % greenfrac % array(iMonth,iCell) = 0.
+         enddo
+      
+      enddo
+   
+   end subroutine physics_idealized_init
+   
+   
+   subroutine decouple_variables(grid, state, diag)
+
+      implicit none
+
+      type (mesh_type), intent(in) :: grid
+      type (state_type), intent(inout) :: state
+      type (diag_type), intent(inout) :: diag
+
+      integer :: iCell, iEdge, k
+
+      integer, dimension(:,:), pointer :: cellsOnEdge
+      real (kind=RKIND), dimension(:), pointer :: fzm, fzp, rdzw
+      real (kind=RKIND), dimension(:,:), pointer :: zz, pp, ppb
+      real (kind=RKIND), dimension(:,:,:), pointer :: scalars
+
+      cellsOnEdge =&gt; grid % CellsOnEdge % array
+      fzp =&gt; grid % fzm % array
+      fzp =&gt; grid % fzp % array
+      rdzw =&gt; grid % rdzw % array
+      zz =&gt; grid % zz % array
+
+      pp  =&gt; diag % pressure_p % array
+      ppb =&gt; diag % pressure_base % array
+
+      scalars =&gt; state % scalars % array

+     
+      ! Compute surface pressure
+      do iCell=1,grid%nCells
+         diag % surface_pressure % array(iCell) = 0.5*gravity/rdzw(1)                                        &amp;
+                                                * (1.25* state % rho_zz % array(1,iCell) * (1. + scalars(state % index_qv, 1, iCell))  &amp;
+                                                -  0.25* state % rho_zz % array(2,iCell) * (1. + scalars(state % index_qv, 2, iCell)))
+         diag % surface_pressure % array(iCell) = diag % surface_pressure % array(iCell) + pp(1,iCell) + ppb(1,iCell)
+      end do
+
+
+      ! Compute rho and theta from rho_zz and theta_m
+      do iCell=1,grid%nCells
+         do k=1,grid%nVertLevels
+            diag % rho % array(k,iCell) = state % rho_zz % array(k,iCell) * zz(k,iCell)
+            diag % theta % array(k,iCell) = state % theta_m % array(k,iCell) / (1.0 + 1.61 * scalars(state % index_qv,k,iCell))
+         end do
+      end do
+
+   end subroutine decouple_variables
+
+
 end module init_atm_test_cases

Modified: branches/ocean_projects/gmvar/src/core_nhyd_atmos/Registry
===================================================================
--- branches/ocean_projects/gmvar/src/core_nhyd_atmos/Registry        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_nhyd_atmos/Registry        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,6 +1,6 @@
-#
-# namelist  type  namelist_record  name  default_value
-#
+%
+% namelist  type  namelist_record  name  default_value
+%
 namelist integer   nhyd_model config_test_case            5
 namelist character nhyd_model config_time_integration     SRK3
 namelist real      nhyd_model config_dt                   172.8
@@ -50,9 +50,9 @@
 namelist logical   restart    config_do_DAcycling         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
@@ -67,12 +67,12 @@
 dim nVertLevels namelist:config_nvertlevels
 dim nVertLevelsP1 nVertLevels+1
 
-#
-# var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
-#
+%
+% var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
+%
 var persistent text    xtime ( Time ) 2 iro xtime state - -
 
-#  horizontal grid structure
+%  horizontal grid structure
 
 var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
 var persistent real    lonCell ( nCells ) 0 iro lonCell mesh - -
@@ -121,13 +121,13 @@
 var persistent real    fEdge ( nEdges ) 0 iro fEdge mesh - -
 var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
 
-var persistent real    densityFunction ( nCells ) 0 iro meshDensity mesh - -
+var persistent real    meshDensity ( nCells ) 0 iro meshDensity mesh - -
 var persistent real    meshScalingDel2 ( nEdges ) 0 ro meshScalingDel2 mesh - -
 var persistent real    meshScalingDel4 ( nEdges ) 0 ro meshScalingDel4 mesh - -
 
-# some solver scalar coefficients
+% some solver scalar coefficients
 
-# coefficients for vertical extrapolation to the surface
+% coefficients for vertical extrapolation to the surface
 var persistent real    cf1 ( ) 0 iro cf1 mesh - -
 var persistent real    cf2 ( ) 0 iro cf2 mesh - -
 var persistent real    cf3 ( ) 0 iro cf3 mesh - -
@@ -135,7 +135,7 @@
 var persistent real    cpr ( THREE nEdges ) 0 ro cpr mesh - -
 var persistent real    cpl ( THREE nEdges ) 0 ro cpl mesh - -
 
-# description of the vertical grid structure
+% description of the vertical grid structure
 
 var persistent real    hx ( nVertLevelsP1 nCells ) 0 iro hx mesh - -
 var persistent real    zgrid ( nVertLevelsP1 nCells ) 0 iro zgrid mesh - -
@@ -151,8 +151,8 @@
 var persistent real    zb ( nVertLevelsP1 TWO nEdges ) 0 iro zb mesh - -
 var persistent real    zb3 ( nVertLevelsP1 TWO nEdges ) 0 iro zb3 mesh - -
 
-# coefficients for the vertical tridiagonal solve
-# Note:  these could be local but...
+% coefficients for the vertical tridiagonal solve
+% Note:  these could be local but...
 
 var persistent real    cofrz ( nVertLevels Time ) 1 - cofrz diag - -
 var persistent real    cofwr ( nVertLevels nCells Time ) 1 - cofwr diag - -
@@ -163,11 +163,11 @@
 var persistent real    alpha_tri ( nVertLevels nCells Time ) 1 - alpha_tri diag - -
 var persistent real    gamma_tri ( nVertLevels nCells Time ) 1 - gamma_tri diag - -
 
-#  W-Rayleigh-damping coefficient
+%  W-Rayleigh-damping coefficient
 
 var persistent real    dss ( nVertLevels nCells ) 0 iro dss 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    w ( nVertLevelsP1 nCells Time ) 2 iro w state - -
 var persistent real    rho_zz ( nVertLevels nCells Time ) 2 r rho_zz state - -
@@ -181,7 +181,7 @@
 var persistent real    qnr ( nVertLevels nCells Time ) 2 iro qnr state scalars number
 var persistent real    qni ( nVertLevels nCells Time ) 2 iro qni state scalars number
 
-# Tendency variables
+% Tendency variables
 var persistent real    tend_u ( nVertLevels nEdges Time ) 1 o u tend - -
 var persistent real    tend_w ( nVertLevelsP1 nCells Time ) 1 o w tend - -
 var persistent real    tend_rho ( nVertLevels nCells Time ) 1 o rho_zz tend - -
@@ -200,17 +200,17 @@
 var persistent real    euler_tend_w ( nVertLevelsP1 nCells Time ) 1 - w_euler tend - -
 var persistent real    euler_tend_theta ( nVertLevels nCells Time ) 1 - theta_euler tend - -
 
-# state variables diagnosed from prognostic state
+% state variables diagnosed from prognostic state
 var persistent real    pressure_p ( nVertLevels nCells Time ) 1 ro pressure_p diag - -
 
 var persistent real    u_init ( nVertLevels ) 0 iro u_init mesh - -
 var persistent real    t_init ( nVertLevels nCells ) 0 iro t_init mesh - -
 var persistent real    qv_init ( nVertLevels ) 0 iro qv_init mesh - -
 
-# Diagnostic fields: only written to output
-# NOTE: added the &quot;r&quot; option to rho,theta,uReconstructZonal,and uReconstructMeridional for use of the
-# non-hydrostatic dynamical core in a data assimilation framework. NOTE that the &quot;r&quot; option is not
-# needed for those 4 variables to get bit for bit restart capabilities, otherwise. 
+% Diagnostic fields: only written to output
+% NOTE: added the &quot;r&quot; option to rho,theta,uReconstructZonal,and uReconstructMeridional for use of the
+% non-hydrostatic dynamical core in a data assimilation framework. NOTE that the &quot;r&quot; option is not
+% needed for those 4 variables to get bit for bit restart capabilities, otherwise. 
 var persistent real    rho ( nVertLevels nCells Time ) 1 iro rho diag - -
 var persistent real    theta ( nVertLevels nCells Time ) 1 iro theta diag - -
 var persistent real    rh ( nVertLevels nCells Time ) 1 iro rh diag - -
@@ -228,7 +228,7 @@
 var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 1 ro uReconstructZonal diag - -
 var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 1 ro uReconstructMeridional diag - -
 
-# Other diagnostic variables: neither read nor written to any files
+% Other diagnostic variables: neither read nor written to any files
 var persistent real    rv ( nVertLevels nEdges Time ) 1 r rv diag - -
 var persistent real    circulation ( nVertLevels nVertices Time ) 1 r circulation diag - -
 var persistent real    gradPVt ( nVertLevels nEdges Time ) 1 - gradPVt diag - -
@@ -248,7 +248,7 @@
 var persistent real    cqu  ( nVertLevels nEdges Time ) 1 - cqu diag - -
 var persistent real    cqw  ( nVertLevels nCells Time ) 1 - cqw diag - -
 
-#  coupled variables needed by the solver, but not output...
+%  coupled variables needed by the solver, but not output...
 
 var persistent real    ru ( nVertLevels nEdges Time ) 1 r ru diag - -
 var persistent real    ru_p ( nVertLevels nEdges Time ) 1 r ru_p diag - -
@@ -268,7 +268,7 @@
 var persistent real    rho_pp ( nVertLevels nCells Time ) 1 - rho_pp diag - -
 var persistent real    rho_p_save ( nVertLevels nCells Time ) 1 - rho_p_save diag - -
 
-# Space needed for advection
+% Space needed for advection
 var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 ir deriv_two mesh - -
 var persistent integer advCells ( TWENTYONE nCells ) 0 ir advCells mesh - -
 var persistent real    adv_coefs ( FIFTEEN nEdges ) 0 - adv_coefs mesh - -
@@ -277,43 +277,43 @@
 var persistent integer nAdvCellsForEdge ( nEdges ) 0 - nAdvCellsForEdge mesh - -
 
 
-# Space needed for deformation calculation weights
+% Space needed for deformation calculation weights
 var persistent real    defc_a ( maxEdges nCells ) 0 iro defc_a mesh - -
 var persistent real    defc_b ( maxEdges nCells ) 0 iro defc_b mesh - -
-var persistent real    kdiff ( nVertLevels nCells Time ) 2 - kdiff diag - -
+var persistent real    kdiff ( nVertLevels nCells Time ) 1 - kdiff diag - -
 
-# Arrays required for reconstruction of velocity field
+% Arrays required for reconstruction of velocity field
 var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 iro coeffs_reconstruct mesh - -
 
-# ADDED DECLARATIONS MADE BY LDF:
+% ADDED DECLARATIONS MADE BY LDF:
 var persistent real    surface_pressure    ( nCells Time    ) 1 iro surface_pressure    diag - -
 var persistent real    surface_temperature ( nCells Time    ) 1   o surface_temperature diag - -
 
-#==================================================================================================
-# DECLARATIONS OF ALL PHYSICS VARIABLES (will need to be moved to a Physics Registry shared by the
-# hydrostatic and non-hydrostatic dynamical cores):
-#==================================================================================================
+%==================================================================================================
+% DECLARATIONS OF ALL PHYSICS VARIABLES (will need to be moved to a Physics Registry shared by the
+% hydrostatic and non-hydrostatic dynamical cores):
+%==================================================================================================
 
-#... NAMELIST VARIABLES ADDED FOR INITIALIZATION OF SURFACE CHARACTERISTICS:
+%... NAMELIST VARIABLES ADDED FOR INITIALIZATION OF SURFACE CHARACTERISTICS:
 namelist character physics  input_landuse_data          USGS
 namelist character physics  input_soil_data             STAS
 namelist integer   physics  input_soil_temperature_lag   140
 namelist integer   physics  num_soil_layers                4
 namelist integer   physics  months                        12
 
-#... NAMELIST VARIABLE NEEDED FOR THE TIME MANAGER:
+%... NAMELIST VARIABLE NEEDED FOR THE TIME MANAGER:
 dim nMonths namelist:months
 
-#... DIMENSION NEEDED FOR NUMBER OF SOIL LAYERS:
+%... DIMENSION NEEDED FOR NUMBER OF SOIL LAYERS:
 dim nSoilLevels namelist:num_soil_layers
 
-#... DIMENSION NEEDED FOR UPDATING THE DEEP SOIL TEMPERATURE:
+%... DIMENSION NEEDED FOR UPDATING THE DEEP SOIL TEMPERATURE:
 dim nLags namelist:input_soil_temperature_lag 
 
-#... DIMENSION NEEDED FOR OZONE AND AEROSOLS CONCENTRATIONS IN THE CAM LONGWAVE AND SHORTWAVE
-#... RADIATION PARAMETERIZATIONS.
-# noznlev : number of CAM radiation input ozone levels.
-# naerlev : number of CAM radiation input aerosol levels.
+%... DIMENSION NEEDED FOR OZONE AND AEROSOLS CONCENTRATIONS IN THE CAM LONGWAVE AND SHORTWAVE
+%... RADIATION PARAMETERIZATIONS.
+% noznlev : number of CAM radiation input ozone levels.
+% naerlev : number of CAM radiation input aerosol levels.
 
 namelist integer   physics  noznlev                       59
 namelist integer   physics  naerlev                       29
@@ -322,13 +322,14 @@
 dim nAerLevels     namelist:naerlev
 dim cam_dim1       namelist:cam_dim1
 
-#... DIMENSION NEEDED FOR LONGWAVE AND SHORTWAVE RADIATION FLUXES TO INCLUDE AN ADDITIONAL LAYER
-#... BETWEEN THE TOP OF THE MODEL AND THE TOP OF THE ATMOSPHERE
+%... DIMENSION NEEDED FOR LONGWAVE AND SHORTWAVE RADIATION FLUXES TO INCLUDE AN ADDITIONAL LAYER
+%... BETWEEN THE TOP OF THE MODEL AND THE TOP OF THE ATMOSPHERE
 dim nVertLevelsP2 nVertLevels+2
 
-#... NAMELIST VARIABLES ADDED FOR PHYSICS CONFIGURATION:
+%... NAMELIST VARIABLES ADDED FOR PHYSICS CONFIGURATION:
 namelist logical   physics  config_frac_seaice          false
 namelist logical   physics  config_sfc_albedo           false
+namelist logical   physics  config_sfc_snowalbedo       false
 namelist logical   physics  config_sst_update           false
 namelist logical   physics  config_sstdiurn_update      false
 namelist logical   physics  config_deepsoiltemp_update  false
@@ -363,16 +364,16 @@
 var persistent real    east       ( R3 nCells               ) 0  r   east          mesh         - -
 var persistent real    north      ( R3 nCells               ) 0  r   north         mesh         - -
 
-#--------------------------------------------------------------------------------------------------
-#... ARRAYS AND VARIABLES FOR UPDATING THE DEEP SOIL TEMPERATURE:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... ARRAYS AND VARIABLES FOR UPDATING THE DEEP SOIL TEMPERATURE:
+%--------------------------------------------------------------------------------------------------
 
-# nsteps_accum: number of accumulated time-step in a day.
-# ndays_accum : number of accumulated days in a year.
-# tlag        : daily mean surface temperature of prior days                                    [K]
-# tday_accum  : accumulated daily surface temperature for current day                           [K]
-# tyear_mean  : annual mean surface temperature                                                 [K]
-# tyear_accum : accumulated yearly surface temperature for current year                         [K]
+% nsteps_accum: number of accumulated time-step in a day.
+% ndays_accum : number of accumulated days in a year.
+% tlag        : daily mean surface temperature of prior days                                    [K]
+% tday_accum  : accumulated daily surface temperature for current day                           [K]
+% tyear_mean  : annual mean surface temperature                                                 [K]
+% tyear_accum : accumulated yearly surface temperature for current year                         [K]
 
 var persistent integer nsteps_accum ( nCells Time           ) 1  r  nsteps_accum   diag_physics - -
 var persistent integer ndays_accum  ( nCells Time           ) 1  r  ndays_accum    diag_physics - -
@@ -382,17 +383,17 @@
 var persistent real    tyear_mean   ( nCells Time           ) 1  r  tyear_mean     diag_physics - -
 var persistent real    tyear_accum  ( nCells Time           ) 1  r  tyear_accum    diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF CLOUD MICROPHYSICS:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF CLOUD MICROPHYSICS:
+%--------------------------------------------------------------------------------------------------
 
-# rainnc    : accumulated total time-step grid-scale precipitation                             (mm)
-# rainncv   : time-step total grid-scale precipitation                                         (mm)
-# snownc    : accumulated grid-scale precipitation of snow                                     (mm)
-# snowncv   : time-step grid-scale precipitation of snow                                       (mm)
-# graupelnc : accumulated grid-scale precipitation of graupel                                  (mm)
-# graupelncv: time-step grid-scale precipitation of graupel                                    (mm)
-# sr        : time-step ratio of frozen versus total grid-scale precipitation                   (-)
+% rainnc    : accumulated total time-step grid-scale precipitation                             (mm)
+% rainncv   : time-step total grid-scale precipitation                                         (mm)
+% snownc    : accumulated grid-scale precipitation of snow                                     (mm)
+% snowncv   : time-step grid-scale precipitation of snow                                       (mm)
+% graupelnc : accumulated grid-scale precipitation of graupel                                  (mm)
+% graupelncv: time-step grid-scale precipitation of graupel                                    (mm)
+% sr        : time-step ratio of frozen versus total grid-scale precipitation                   (-)
 
 var persistent real    sr         ( nCells Time             ) 1  ro sr             diag_physics - -
 var persistent real    rainncv    ( nCells Time             ) 1  ro rainncv        diag_physics - -
@@ -406,21 +407,21 @@
 var persistent real    qsat       ( nVertLevels nCells Time ) 1  o  qsat           diag_physics - -
 var persistent real    relhum     ( nVertLevels nCells Time ) 1  o  relhum         diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF CONVECTION:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF CONVECTION:
+%--------------------------------------------------------------------------------------------------
 
-# cubot     : lowest level of convection                                                        (-)
-# cutop     : highest level of convection                                                       (-)
-# cuprec    : convective precipitation rate                                                  (mm/s)
-# rainc     : accumulated time-step convective precipitation                                   (mm)
-# raincv    : time-step convective precipitation                                               (mm)
-# rthcuten  : tendency of potential temperature due to cumulus convection                   (K s-1)
-# rqvcuten  : tendency of water vapor mixing ratio due to cumulus convection            (kg/kg s-1)
-# rqccuten  : tendency of cloud water mixing ratio due to cumulus convection            (kg/kg s-1)
-# rqrcuten  : tendency of rain mixing ratio due to cumulus convection                   (kg/kg s-1)
-# rqicuten  : tendency of cloud ice mixing ratio due to cumulus convection              (kg/kg s-1)
-# rqscuten  : tendency of snow mixing ratio due to cumulus convection                   (kg/kg s-1)
+% cubot     : lowest level of convection                                                        (-)
+% cutop     : highest level of convection                                                       (-)
+% cuprec    : convective precipitation rate                                                  (mm/s)
+% rainc     : accumulated time-step convective precipitation                                   (mm)
+% raincv    : time-step convective precipitation                                               (mm)
+% rthcuten  : tendency of potential temperature due to cumulus convection                   (K s-1)
+% rqvcuten  : tendency of water vapor mixing ratio due to cumulus convection            (kg/kg s-1)
+% rqccuten  : tendency of cloud water mixing ratio due to cumulus convection            (kg/kg s-1)
+% rqrcuten  : tendency of rain mixing ratio due to cumulus convection                   (kg/kg s-1)
+% rqicuten  : tendency of cloud ice mixing ratio due to cumulus convection              (kg/kg s-1)
+% rqscuten  : tendency of snow mixing ratio due to cumulus convection                   (kg/kg s-1)
 
 var persistent real    cubot    ( nCells Time              ) 1  ro cubot           diag_physics - -
 var persistent real    cutop    ( nCells Time              ) 1  ro cutop           diag_physics - -
@@ -435,32 +436,32 @@
 var persistent real    rqicuten ( nVertLevels nCells Time  ) 1  ro rqicuten        tend_physics - -
 var persistent real    rqscuten ( nVertLevels nCells Time  ) 1  ro rqscuten        tend_physics - -
 
-#... KAIN_FRITSCH ONLY:
-# nca       : relaxation time for KF parameterization of convection                             (s)
-# wavg0     : average vertical velocity (KF scheme only)                                    (m s-1)
+%... KAIN_FRITSCH ONLY:
+% nca       : relaxation time for KF parameterization of convection                             (s)
+% wavg0     : average vertical velocity (KF scheme only)                                    (m s-1)
 
 var persistent real    nca      ( nCells Time              ) 1  ro nca             diag_physics - -
 var persistent real    w0avg    ( nVertLevels nCells Time  ) 1  ro w0avg           diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF PLANETARY BOUNDARY LAYER PROCESSES:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF PLANETARY BOUNDARY LAYER PROCESSES:
+%--------------------------------------------------------------------------------------------------
 
-# kpbl      : index of PBL top                                                                  (-)
-# hpbl      : PBL height                                                                        (m)
-# exch_h    : exchange coefficient                                                              (-)
-# rublten   : tendency of zonal wind due to pbl processes                                   (m s-1)
-# rvblten   : tendency of meridional wind due to pbl processes                              (m s-1)
-# rthblten  : tendency of potential temperature due to pbl processes                        (K s-1)
-# rqvblten  : tendency of water vapor mixing ratio due to pbl processes                 (kg/kg s-1)
-# rqcblten  : tendency of cloud water mixing ratio due to pbl processes                 (kg/kg s-1)
-# rqiblten  : tendency of cloud ice mixing ratio due to pbl processes                   (kg/kg s-1)
+% kpbl      : index of PBL top                                                                  (-)
+% hpbl      : PBL height                                                                        (m)
+% exch_h    : exchange coefficient                                                              (-)
+% rublten   : tendency of zonal wind due to pbl processes                                   (m s-1)
+% rvblten   : tendency of meridional wind due to pbl processes                              (m s-1)
+% rthblten  : tendency of potential temperature due to pbl processes                        (K s-1)
+% rqvblten  : tendency of water vapor mixing ratio due to pbl processes                 (kg/kg s-1)
+% rqcblten  : tendency of cloud water mixing ratio due to pbl processes                 (kg/kg s-1)
+% rqiblten  : tendency of cloud ice mixing ratio due to pbl processes                   (kg/kg s-1)
 
 var persistent integer kpbl     ( nCells Time               ) 1  ro kpbl           diag_physics - - 
 var persistent real    hpbl     ( nCells Time               ) 1  ro hpbl           diag_physics - - 
 var persistent real    exch_h   ( nVertLevels nCells Time   ) 1   o exch_h         diag_physics - -
 
-#    TENDENCIES:
+%    TENDENCIES:
 var persistent real    rublten  ( nVertLevels nCells Time   ) 1  ro rublten        tend_physics - -
 var persistent real    rvblten  ( nVertLevels nCells Time   ) 1  ro rvblten        tend_physics - -
 var persistent real    rthblten ( nVertLevels nCells Time   ) 1  ro rthblten       tend_physics - -
@@ -468,44 +469,44 @@
 var persistent real    rqcblten ( nVertLevels nCells Time   ) 1  ro rqcblten       tend_physics - -
 var persistent real    rqiblten ( nVertLevels nCells Time   ) 1  ro rqiblten       tend_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF SURFACE LAYER PROCESSES:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF SURFACE LAYER PROCESSES:
+%--------------------------------------------------------------------------------------------------
 
-# br        :bulk richardson number                                                             [-]
-# cd        :drag coefficient at 10m                                                            [-]
-# cda       :drag coefficient at lowest model level                                             [-]
-# chs       :???
-# chs2      :???
-# cqs2      :???
-# ck        :enthalpy exchange coefficient at 10 m                                              [-]
-# cka       :enthalpy exchange coefficient at lowest model level                                [-]
-# cpm       :???
-# flhc      :exchange coefficient for heat                                                      [-]
-# flqc      :exchange coefficient for moisture                                                  [-]
-# gz1oz0    :log of z1 over z0                                                                  [-]
-# hfx       :upward heat flux at the surface                                               [W/m2/s]
-# lh        :latent heat flux at the surface                                                 [W/m2]
-# mavail    :surface moisture availability                                                      [-]
-# mol       :T* in similarity theory                                                            [K]
-# psih      :similarity theory for heat                                                         [-]
-# psim      :similarity theory for momentum                                                     [-]
-# qfx       :upward moisture flux at the surface                                          [kg/m2/s]
-# qgh       :???
-# qsfc      :specific humidity at lower boundary                                            [kg/kg]
-# regime    :flag indicating PBL regime (stable_p,unstable_p,etc...)                            [-]
-# rmol      :1 / Monin Ob length                                                                [-]
-# ust       :u* in similarity theory                                                          [m/s]
-# ustm      :u* in similarity theory without vconv                                            [m/s]
-# zol       :z/L height over Monin-Obukhov length                                               [-]
-# znt       :time-varying roughness length                                                      [m]
-# wspd      :wind speed                                                                       [m/s]
-# DIAGNOSTICS:
-# q2        :specific humidity at 2m                                                        [kg/kg]
-# u10       :u at 10 m                                                                        [m/s]
-# v10       :v at 10 m                                                                        [m/s]
-# t2m       :temperature at 2m                                                                  [K]
-# th2m      :potential temperature at 2m                                                        [K]
+% br        :bulk richardson number                                                             [-]
+% cd        :drag coefficient at 10m                                                            [-]
+% cda       :drag coefficient at lowest model level                                             [-]
+% chs       :???
+% chs2      :???
+% cqs2      :???
+% ck        :enthalpy exchange coefficient at 10 m                                              [-]
+% cka       :enthalpy exchange coefficient at lowest model level                                [-]
+% cpm       :???
+% flhc      :exchange coefficient for heat                                                      [-]
+% flqc      :exchange coefficient for moisture                                                  [-]
+% gz1oz0    :log of z1 over z0                                                                  [-]
+% hfx       :upward heat flux at the surface                                               [W/m2/s]
+% lh        :latent heat flux at the surface                                                 [W/m2]
+% mavail    :surface moisture availability                                                      [-]
+% mol       :T* in similarity theory                                                            [K]
+% psih      :similarity theory for heat                                                         [-]
+% psim      :similarity theory for momentum                                                     [-]
+% qfx       :upward moisture flux at the surface                                          [kg/m2/s]
+% qgh       :???
+% qsfc      :specific humidity at lower boundary                                            [kg/kg]
+% regime    :flag indicating PBL regime (stable_p,unstable_p,etc...)                            [-]
+% rmol      :1 / Monin Ob length                                                                [-]
+% ust       :u* in similarity theory                                                          [m/s]
+% ustm      :u* in similarity theory without vconv                                            [m/s]
+% zol       :z/L height over Monin-Obukhov length                                               [-]
+% znt       :time-varying roughness length                                                      [m]
+% wspd      :wind speed                                                                       [m/s]
+% DIAGNOSTICS:
+% q2        :specific humidity at 2m                                                        [kg/kg]
+% u10       :u at 10 m                                                                        [m/s]
+% v10       :v at 10 m                                                                        [m/s]
+% t2m       :temperature at 2m                                                                  [K]
+% th2m      :potential temperature at 2m                                                        [K]
 
 var persistent real    hfx      ( nCells Time               ) 1  ro hfx            diag_physics - -
 var persistent real    mavail   ( nCells Time               ) 1  ro mavail         diag_physics - -
@@ -536,34 +537,34 @@
 var persistent real    regime   ( nCells Time               ) 1  ro regime         diag_physics - -
 var persistent real    rmol     ( nCells Time               ) 1  ro rmol           diag_physics - -
 var persistent real    wspd     ( nCells Time               ) 1  ro wspd           diag_physics - -
-# DIAGNOSTICS:
+% DIAGNOSTICS:
 var persistent real    u10      ( nCells Time               ) 1  ro u10            diag_physics - -
 var persistent real    v10      ( nCells Time               ) 1  ro v10            diag_physics - -
 var persistent real    q2       ( nCells Time               ) 1  ro q2             diag_physics - -
 var persistent real    t2m      ( nCells Time               ) 1  ro t2m            diag_physics - -
 var persistent real    th2m     ( nCells Time               ) 1  ro th2m           diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF SHORTWAVE RADIATION:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF SHORTWAVE RADIATION:
+%--------------------------------------------------------------------------------------------------
 
-# coszr     :cosine of the solar zenith angle                                                   [-]
+% coszr     :cosine of the solar zenith angle                                                   [-]
 
-# gsw       :net shortwave flux at surface                                                  [W m-2]
-# swcf      :shortwave cloud forcing at top-of-atmosphere                                   [W m-2]
-# swdnb     :all-sky downwelling shortwave flux at bottom-of-atmosphere                     [J m-2]
-# swdnbc    :clear-sky downwelling shortwave flux at bottom-of-atmosphere                   [J m-2]
-# swdnt     :all-sky downwelling shortwave flux at top-of-atmosphere                        [J m-2]
-# swdntc    :clear-sky downwelling shortwave flux at top-of-atmosphere                      [J m-2] 
-# swupb     :all-sky upwelling shortwave flux at bottom-of-atmosphere                       [J m-2]
-# swupbc    :clear-sky upwelling shortwave flux at bottom-of-atmosphere                     [J m-2]
-# swupt     :all-sky upwelling shortwave flux at top-of-atmosphere                          [J m-2]
-# swuptc    :clear-sky upwelling shortwave flux at top-of-atmosphere                        [J m-2]
-# swdnflx   :
-# swdnflxc  :
-# swupflx   :
-# swupflxc  :
-# rthratensw:uncoupled theta tendency due to shortwave radiation                            [K s-1]
+% gsw       :net shortwave flux at surface                                                  [W m-2]
+% swcf      :shortwave cloud forcing at top-of-atmosphere                                   [W m-2]
+% swdnb     :all-sky downwelling shortwave flux at bottom-of-atmosphere                     [J m-2]
+% swdnbc    :clear-sky downwelling shortwave flux at bottom-of-atmosphere                   [J m-2]
+% swdnt     :all-sky downwelling shortwave flux at top-of-atmosphere                        [J m-2]
+% swdntc    :clear-sky downwelling shortwave flux at top-of-atmosphere                      [J m-2] 
+% swupb     :all-sky upwelling shortwave flux at bottom-of-atmosphere                       [J m-2]
+% swupbc    :clear-sky upwelling shortwave flux at bottom-of-atmosphere                     [J m-2]
+% swupt     :all-sky upwelling shortwave flux at top-of-atmosphere                          [J m-2]
+% swuptc    :clear-sky upwelling shortwave flux at top-of-atmosphere                        [J m-2]
+% swdnflx   :
+% swdnflxc  :
+% swupflx   :
+% swupflxc  :
+% rthratensw:uncoupled theta tendency due to shortwave radiation                            [K s-1]
 
 var persistent real    coszr      ( nCells Time               ) 1   o coszr        diag_physics - -
 var persistent real    swcf       ( nCells Time               ) 1   o swcf         diag_physics - -
@@ -579,37 +580,37 @@
 
 var persistent real    rthratensw ( nVertLevels nCells Time   ) 1  ro rthratensw   tend_physics - -
 
-#... RRTMG SW ONLY:
+%... RRTMG SW ONLY:
 var persistent real    swdnflx    ( nVertLevelsP2 nCells Time ) 1   o swdnflx      diag_physics - -
 var persistent real    swdnflxc   ( nVertLevelsP2 nCells Time ) 1   o swdnflxc     diag_physics - -
 var persistent real    swupflx    ( nVertLevelsP2 nCells Time ) 1   o swupflx      diag_physics - -
 var persistent real    swupflxc   ( nVertLevelsP2 nCells Time ) 1   o swupflxc     diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF LONGWAVE RADIATION:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF LONGWAVE RADIATION:
+%--------------------------------------------------------------------------------------------------
 
-# note: glw is the same diagnostic as lwdnb and is used in the land-surface scheme for the calcula-
-#       tion of the surface budget. glw is always an output argument to the subroutine rrtmg_lwrad.
-#       in contrast,lwdnb is an optional ouput argument to the subroutine rrtmg_lwrad depending on
-#       the presence of lwupt (or not).
+% note: glw is the same diagnostic as lwdnb and is used in the land-surface scheme for the calcula-
+%       tion of the surface budget. glw is always an output argument to the subroutine rrtmg_lwrad.
+%       in contrast,lwdnb is an optional ouput argument to the subroutine rrtmg_lwrad depending on
+%       the presence of lwupt (or not).
 
-# glw       :all-sky downwelling longwave flux at bottom-of-atmosphere                      [W m-2]
-# lwcf      :longwave cloud forcing at top-of-atmosphere                                    [W m-2]
-# lwdnb     :all-sky downwelling longwave flux at bottom-of-atmosphere                      [W m-2]
-# lwdnbc    :clear-sky downwelling longwave flux at bottom-of-atmosphere                    [W m-2]
-# lwdnt     :all-sky downwelling longwave flux at top-of-atmosphere                         [W m-2]
-# lwdntc    :clear-sky downwelling longwave flux at top-of-atmosphere                       [W m-2]
-# lwupb     :all-sky upwelling longwave flux at bottom-of-atmosphere                        [W m-2]
-# lwupbc    :clear-sky upwelling longwave flux at bottom-of-atmosphere                      [W m-2]
-# lwupt     :all-sky upwelling longwave flux at top-of-atmosphere                           [W m-2]
-# lwuptc    :clear-sky upwelling longwave flux at top-of-atmosphere                         [W m-2]
-# lwdnflx   :
-# lwdnflxc  :
-# lwupflx   :
-# lwupflxc  :
-# olrtoa    :outgoing longwave radiation at top-of-the-atmosphere                           [W m-2]
-# rthratenlw:uncoupled theta tendency due to longwave radiation                             [K s-1]
+% glw       :all-sky downwelling longwave flux at bottom-of-atmosphere                      [W m-2]
+% lwcf      :longwave cloud forcing at top-of-atmosphere                                    [W m-2]
+% lwdnb     :all-sky downwelling longwave flux at bottom-of-atmosphere                      [W m-2]
+% lwdnbc    :clear-sky downwelling longwave flux at bottom-of-atmosphere                    [W m-2]
+% lwdnt     :all-sky downwelling longwave flux at top-of-atmosphere                         [W m-2]
+% lwdntc    :clear-sky downwelling longwave flux at top-of-atmosphere                       [W m-2]
+% lwupb     :all-sky upwelling longwave flux at bottom-of-atmosphere                        [W m-2]
+% lwupbc    :clear-sky upwelling longwave flux at bottom-of-atmosphere                      [W m-2]
+% lwupt     :all-sky upwelling longwave flux at top-of-atmosphere                           [W m-2]
+% lwuptc    :clear-sky upwelling longwave flux at top-of-atmosphere                         [W m-2]
+% lwdnflx   :
+% lwdnflxc  :
+% lwupflx   :
+% lwupflxc  :
+% olrtoa    :outgoing longwave radiation at top-of-the-atmosphere                           [W m-2]
+% rthratenlw:uncoupled theta tendency due to longwave radiation                             [K s-1]
 
 var persistent real    lwcf       ( nCells Time               ) 1   o lwcf         diag_physics - -
 var persistent real    lwdnb      ( nCells Time               ) 1   o lwdnb        diag_physics - -
@@ -625,30 +626,30 @@
 
 var persistent real    rthratenlw ( nVertLevels nCells Time   ) 1  ro rthratenlw   tend_physics - -
 
-#... RRTMG LW ONLY:
-#var persistent real   lwdnflx    ( nVertLevelsP2 nCells Time ) 1   o lwdnflx      diag_physics - -
-#var persistent real   lwdnflxc   ( nVertLevelsP2 nCells Time ) 1   o lwdnflxc     diag_physics - -
-#var persistent real   lwupflx    ( nVertLevelsP2 nCells Time ) 1   o lwupflx      diag_physics - -
-#var persistent real   lwupflxc   ( nVertLevelsP2 nCells Time ) 1   o lwupflxc     diag_physics - -
+%... RRTMG LW ONLY:
+%var persistent real   lwdnflx    ( nVertLevelsP2 nCells Time ) 1   o lwdnflx      diag_physics - -
+%var persistent real   lwdnflxc   ( nVertLevelsP2 nCells Time ) 1   o lwdnflxc     diag_physics - -
+%var persistent real   lwupflx    ( nVertLevelsP2 nCells Time ) 1   o lwupflx      diag_physics - -
+%var persistent real   lwupflxc   ( nVertLevelsP2 nCells Time ) 1   o lwupflxc     diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... ADDITIONAL &quot;RADIATION&quot; ARRAYS NEEDED ONLY IN THE &quot;CAM&quot; LW AND SW RADIATION CODES:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... ADDITIONAL &quot;RADIATION&quot; ARRAYS NEEDED ONLY IN THE &quot;CAM&quot; LW AND SW RADIATION CODES:
+%--------------------------------------------------------------------------------------------------
 
-#INFRARED ABSORPTION:
+%INFRARED ABSORPTION:
 var persistent real absnxt  ( nVertLevels   cam_dim1      nCells Time ) 1 - absnxt diag_physics - -
 var persistent real abstot  ( nVertLevelsP1 nVertLevelsP1 nCells Time ) 1 - abstot diag_physics - -
 var persistent real emstot  ( nVertLevelsP1 nCells Time               ) 1 - emstot diag_physics - -
 
-# OZONE:
+% OZONE:
 var persistent real    pin      ( nOznLevels nCells         ) 0 -  pin       mesh  - -
 var persistent real    ozmixm   ( nMonths nOznLevels nCells ) 0 -  ozmixm    mesh  - -
 
-# AEROSOLS:
+% AEROSOLS:
 var persistent real    m_hybi   ( nAerLevels nCells         ) 0 -  m_hybi    mesh  - -  
 
 var persistent real    m_ps     ( nCells Time               ) 2 -  m_ps      state - -
-#var persistent real   dummy    ( nAerLevels nCells Time    ) 2 -  dummy     state aerosols aer_cam
+%var persistent real   dummy    ( nAerLevels nCells Time    ) 2 -  dummy     state aerosols aer_cam
 var persistent real    sul      ( nAerLevels nCells Time    ) 2 -  sul       state aerosols aer_cam
 var persistent real    sslt     ( nAerLevels nCells Time    ) 2 -  sslt      state aerosols aer_cam
 var persistent real    dust1    ( nAerLevels nCells Time    ) 2 -  dust1     state aerosols aer_cam
@@ -662,43 +663,43 @@
 var persistent real    bg       ( nAerLevels nCells Time    ) 2 -  bg        state aerosols aer_cam
 var persistent real    volc     ( nAerLevels nCells Time    ) 2 -  volc      state aerosols aer_cam
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMERIZATION OF CLOUDINESS:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMERIZATION OF CLOUDINESS:
+%--------------------------------------------------------------------------------------------------
 
-# cldfrac   :cloud fraction                                                                     [-]
+% cldfrac   :cloud fraction                                                                     [-]
 
 var persistent real    cldfrac    ( nVertLevels nCells Time ) 1   o cldfrac        diag_physics - -
 
-#--------------------------------------------------------------------------------------------------
-#... PARAMETERIZATION OF LAND-SURFACE SCHEME:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... PARAMETERIZATION OF LAND-SURFACE SCHEME:
+%--------------------------------------------------------------------------------------------------
 
-# acsnom         :accumulated melted snow                                                  [kg m-2]
-# acsnow         :accumulated snow                                                         [kg m-2]
-# canwat         :canopy water                                                             [kg m-2]
-# chklowq        :surface saturation flag                                                       [-]
-# grdflx         :ground heat flux                                                          [W m-2]
-# lai            :leaf area index                                                               [-]
-# noahres        :residual of the noah land-surface scheme energy budget                    [W m-2]
-# potevp         :potential evaporation                                                     [W m-2]
-# qz0            :specific humidity at znt                                                [kg kg-1]
-# rib            :??
-# sfc_albedo     :surface albedo                                                                [-]
-# sfc_embck      :background emissivity                                                         [-]
-# sfc_emiss      :surface emissivity                                                            [-]
-# sfcrunoff      :surface runoff                                                            [m s-1]
-# smstav         :moisture availability                                                         [-]
-# smstot         :total moisture                                                           [m3 m-3]
-# snopcx         :snow phase change heat flux                                               [W m-2]
-# snotime        :??
-# sstsk          : skin sea-surface temperature                                                [K]
-# sstsk_diur     : skin sea-surface temperature difference                                     [K]
-# thc            :thermal inertia                                              [Cal cm-1 K-1 s-0.5]
-# udrunoff       :sub-surface runoff                                                        [m s-1]
-# xicem          :ice mask from previous time-step                                              [-]
-# z0             :background roughness length                                                   [m]
-# zs             :depth of centers of soil layers                                               [m]
+% acsnom         :accumulated melted snow                                                  [kg m-2]
+% acsnow         :accumulated snow                                                         [kg m-2]
+% canwat         :canopy water                                                             [kg m-2]
+% chklowq        :surface saturation flag                                                       [-]
+% grdflx         :ground heat flux                                                          [W m-2]
+% lai            :leaf area index                                                               [-]
+% noahres        :residual of the noah land-surface scheme energy budget                    [W m-2]
+% potevp         :potential evaporation                                                     [W m-2]
+% qz0            :specific humidity at znt                                                [kg kg-1]
+% rib            :??
+% sfc_albedo     :surface albedo                                                                [-]
+% sfc_embck      :background emissivity                                                         [-]
+% sfc_emiss      :surface emissivity                                                            [-]
+% sfcrunoff      :surface runoff                                                            [m s-1]
+% smstav         :moisture availability                                                         [-]
+% smstot         :total moisture                                                           [m3 m-3]
+% snopcx         :snow phase change heat flux                                               [W m-2]
+% snotime        :??
+% sstsk          : skin sea-surface temperature                                                [K]
+% sstsk_diur     : skin sea-surface temperature difference                                     [K]
+% thc            :thermal inertia                                              [Cal cm-1 K-1 s-0.5]
+% udrunoff       :sub-surface runoff                                                        [m s-1]
+% xicem          :ice mask from previous time-step                                              [-]
+% z0             :background roughness length                                                   [m]
+% zs             :depth of centers of soil layers                                               [m]
 
 var persistent real    acsnom     ( nCells Time             ) 1  ro acsnom         diag_physics - -
 var persistent real    acsnow     ( nCells Time             ) 1  ro acsnow         diag_physics - -
@@ -726,36 +727,36 @@
 var persistent real    z0         ( nCells Time             ) 1  ro z0             diag_physics - -   
 var persistent real    zs         ( nCells Time             ) 1  ro zs             diag_physics - -   
 
-#--------------------------------------------------------------------------------------------------
-#... SURFACE CHARACTERISTICS THAT NEED TO BE READ FROM GRID.NC:
-#--------------------------------------------------------------------------------------------------
+%--------------------------------------------------------------------------------------------------
+%... SURFACE CHARACTERISTICS THAT NEED TO BE READ FROM GRID.NC:
+%--------------------------------------------------------------------------------------------------
 
-# albedo12m      :monthly climatological albedo                                                 [-]
-# greenfrac      :monthly climatological greeness fraction                                      [-]                             
-# isltyp         :dominant soil category                                                        [-]
-# ivgtyp         :dominant vegetation category                                                  [-]
-# landmask       :=0 for ocean;=1 for land                                                      [-]
-# sfc_albbck     :background albedo                                                             [-]
-# shdmin         :minimum areal fractional coverage of annual green vegetation                  [-]
-# shdmax         :maximum areal fractional coverage of annual green vegetation                  [-]
-# skintemp       :skin temperature                                                              [K]
-# snoalb         :annual max snow albedo                                                        [-]
-# snow           :snow water equivalent                                                    [kg m-2]
-# sst            :sea-surface temperature                                                       [K]
-# snowc          :flag indicating snow coverage (1 for snow cover)                              [-]
-# snowh          :physical snow depth                                                           [m]
-# ter            :terrain height                                                                [-]
-# tmn            :soil temperature at lower boundary                                            [K]
-# vegfra         :vegetation fraction                                                           [-]
-# seaice         :sea-ice mask (=1 when xice is greater than 0; =0 otherwise)                   [-]
-# xice           :fractional sea-ice coverage                                                   [-]
-# xland          :land mask    (1 for land; 2 for water)                                        [-]
+% albedo12m      :monthly climatological albedo                                                 [-]
+% greenfrac      :monthly climatological greeness fraction                                      [-]                             
+% isltyp         :dominant soil category                                                        [-]
+% ivgtyp         :dominant vegetation category                                                  [-]
+% landmask       :=0 for ocean;=1 for land                                                      [-]
+% sfc_albbck     :background albedo                                                             [-]
+% shdmin         :minimum areal fractional coverage of annual green vegetation                  [-]
+% shdmax         :maximum areal fractional coverage of annual green vegetation                  [-]
+% skintemp       :skin temperature                                                              [K]
+% snoalb         :annual max snow albedo                                                        [-]
+% snow           :snow water equivalent                                                    [kg m-2]
+% sst            :sea-surface temperature                                                       [K]
+% snowc          :flag indicating snow coverage (1 for snow cover)                              [-]
+% snowh          :physical snow depth                                                           [m]
+% ter            :terrain height                                                                [-]
+% tmn            :soil temperature at lower boundary                                            [K]
+% vegfra         :vegetation fraction                                                           [-]
+% seaice         :sea-ice mask (=1 when xice is greater than 0; =0 otherwise)                   [-]
+% xice           :fractional sea-ice coverage                                                   [-]
+% xland          :land mask    (1 for land; 2 for water)                                        [-]
 
-# dzs            :thickness of soil layers                                                      [m]
-# smcrel         :soil moisture threshold below which transpiration begins to stress            [-]
-# sh2o           :soil liquid water                                                        [m3 m-3]
-# smois          :soil moisture                                                            [m3 m-3]
-# tslb           :soil temperature                                                              [K]
+% dzs            :thickness of soil layers                                                      [m]
+% smcrel         :soil moisture threshold below which transpiration begins to stress            [-]
+% sh2o           :soil liquid water                                                        [m3 m-3]
+% smois          :soil moisture                                                            [m3 m-3]
+% tslb           :soil temperature                                                              [K]
 
 var persistent integer isltyp     ( nCells                   ) 0 iro isltyp        sfc_input    - -
 var persistent integer ivgtyp     ( nCells                   ) 0 iro ivgtyp        sfc_input    - -
@@ -785,4 +786,4 @@
 var persistent real    smois      ( nSoilLevels nCells Time  ) 1 iro smois         sfc_input    - -
 var persistent real    tslb       ( nSoilLevels nCells Time  ) 1 iro tslb          sfc_input    - -
 
-#==================================================================================================
+%==================================================================================================

Modified: branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_advection.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_advection.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_advection.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,5 +1,6 @@
 module atm_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
    
@@ -701,7 +702,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
@@ -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/gmvar/src/core_nhyd_atmos/mpas_atm_test_cases.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_test_cases.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_test_cases.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -5,7 +5,9 @@
    use mpas_constants
    use mpas_dmpar
    use atm_advection
+#ifdef DO_PHYSICS
    use mpas_atmphys_control
+#endif
 
 
    contains
@@ -94,6 +96,8 @@
          stop
       end if
 
+
+#ifdef DO_PHYSICS
       !initialization of surface input variables technically not needed to run our current set of
       !idealized test cases:
       if (config_test_case &gt; 0)  then
@@ -105,6 +109,7 @@
          end do
 
       endif
+#endif
 
    end subroutine atm_setup_test_case
 
@@ -153,8 +158,8 @@
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
       integer, dimension(:,:), pointer :: edgesOnEdge, CellsOnEdge
-      real, dimension(:), pointer :: dvEdge, AreaCell 
-      real, dimension(:,:), pointer :: weightsOnEdge
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, AreaCell 
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
 
       real (kind=RKIND) :: u, v, flux, fluxk, lat1, lat2, eta_v, r_pert, u_pert, lat_pert, lon_pert, r
 
@@ -666,7 +671,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
@@ -786,9 +791,9 @@
 
             if (config_theta_adv_order ==3) then 
                diag % rw % array(k,cell2) = diag % rw % array(k,cell2)    &amp;
-                                            - sign(1.,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
+                                            - sign(1.0_RKIND,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
                diag % rw % array(k,cell1) = diag % rw % array(k,cell1)    &amp;
-                                            + sign(1.,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
+                                            + sign(1.0_RKIND,diag % ru % array(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
             end if
 
          end do
@@ -881,7 +886,7 @@
 !  renormalize for setting cell-face fluxes
 
    do k=1,nz1
-     flux_zonal(k) = sign(1.,lat2_in-lat1_in)*flux_zonal(k)*dlat*a/dvEdge/u0
+     flux_zonal(k) = sign(1.0_RKIND,lat2_in-lat1_in)*flux_zonal(k)*dlat*a/dvEdge/u0
    end do
      
    end subroutine atm_calc_flux_zonal
@@ -1004,7 +1009,7 @@
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
       integer, dimension(:,:), pointer :: edgesOnEdge
-      real, dimension(:,:), pointer :: weightsOnEdge
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, cell1, cell2, nCellsSolve
       integer :: index_qv
@@ -1320,7 +1325,7 @@
             temp     = p(k,i)*thi(k,i)
             pres     = p0*p(k,i)**(1./rcp)
             qvs      = 380.*exp(17.27*(temp-273.)/(temp-36.))/pres
-            scalars(index_qv,k,i) = amin1(0.014,rh(k,i)*qvs)
+            scalars(index_qv,k,i) = min(0.014_RKIND,rh(k,i)*qvs)
          end do
       end do
 
@@ -1542,8 +1547,8 @@
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
       integer, dimension(:,:), pointer :: edgesOnEdge, CellsOnEdge
-      real, dimension(:), pointer :: dvEdge, AreaCell, xCell, yCell 
-      real, dimension(:,:), pointer :: weightsOnEdge
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, AreaCell, xCell, yCell 
+      real (kind=RKIND), dimension(:,:), pointer :: weightsOnEdge
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, itrp, cell1, cell2, nCellsSolve
       integer :: index_qv
@@ -1769,7 +1774,7 @@
 ! smoothing grid for the upper level &gt;&gt; but not propoer for parallel programing 
       dzmin=.7
       do k=2,nz1
-         sm = .25*min((zc(k)-zc(k-1))/dz,1.)
+         sm = .25*min((zc(k)-zc(k-1))/dz,1.0_RKIND)
          do i=1,grid % nCells
             hx(k,i) = hx(k-1,i)
          end do
@@ -1946,7 +1951,7 @@
               temp   = p(k,i)*t(k,i)
               pres   = p0*p(k,i)**(1./rcp)
               qvs    = 380.*exp(17.27*(temp-273.)/(temp-36.))/pres
-              scalars(index_qv,k,i) = amin1(0.014,rh(k,i)*qvs)
+              scalars(index_qv,k,i) = min(0.014_RKIND,rh(k,i)*qvs)
            end do
                          
            do k=1,nz1
@@ -2069,9 +2074,9 @@
 
             if (config_theta_adv_order ==3) then
                diag % rw % array(k,cell2) = diag % rw % array(k,cell2)    &amp;
-                                            - sign(1.,ru(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
+                                            - sign(1.0_RKIND,ru(k,iEdge))*config_coef_3rd_order*zf3(k,2,iEdge)*flux
                diag % rw % array(k,cell1) = diag % rw % array(k,cell1)    &amp;
-                                            + sign(1.,ru(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
+                                            + sign(1.0_RKIND,ru(k,iEdge))*config_coef_3rd_order*zf3(k,1,iEdge)*flux
             end if
 
          end do
@@ -2128,7 +2133,7 @@
 
 !----------------------------------------------------------------------------------------------------------
 
-   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.
@@ -2147,10 +2152,10 @@
    end function sphere_distance
 
 !--------------------------------------------------------------------
-   real function env_qv( z, temperature, pressure, rh_max )
+   real (kind=RKIND) function env_qv( z, temperature, pressure, rh_max )
 
       implicit none
-      real z, temperature, pressure, ztr, es, qvs, p0, rh_max
+      real (kind=RKIND) :: z, temperature, pressure, ztr, es, qvs, p0, rh_max
 
       p0 = 100000.
 

Modified: branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_time_integration.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_time_integration.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_nhyd_atmos/mpas_atm_time_integration.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -145,10 +145,6 @@
          call mpas_dmpar_exch_halo_field2d_real(domain % dminfo, block % diag % rtheta_p % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-!surface_pressure
-         call mpas_dmpar_exch_halo_field1d_real(domain % dminfo, block % diag % surface_pressure % array(:), &amp;
-                                          block % mesh % nCells, &amp;
-                                          block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
          block =&gt; block % next
       end do
 
@@ -192,7 +188,7 @@
         block =&gt; domain % blocklist
         do while (associated(block))
            call physics_addtend( domain % dminfo , block % parinfo % cellsToSend, block % parinfo % cellsToRecv, &amp;
-                        block % mesh , block % state % time_levs(2) % state, block % diag, block % tend, &amp;
+                        block % mesh , block % state % time_levs(1) % state, block % diag, block % tend, &amp;
                         block % tend_physics , block % state % time_levs(2) % state % rho_zz % array(:,:), &amp;
                         block % diag % rho_edge % array(:,:) )
            block =&gt; block % next
@@ -680,7 +676,7 @@
       type (mesh_type) :: grid
       integer :: iCell, iEdge, k, cell1, cell2
       integer, dimension(:,:), pointer :: cellsOnEdge
-      real, dimension(:,:,:), pointer :: zf, zf3
+      real (kind=RKIND), dimension(:,:,:), pointer :: zf, zf3
       real (kind=RKIND), dimension(:), pointer :: fzm, fzp, dvEdge, areaCell
       real (kind=RKIND) :: flux
 
@@ -718,9 +714,9 @@
             tend % w % array(k,cell1) = tend % w % array(k,cell1) - zf(k,1,iEdge)*flux
 !3rd order stencil
             if (config_theta_adv_order == 3) then
-               tend % w % array(k,cell2) = tend % w % array(k,cell2) + sign(1.,tend % u % array(k,iEdge))  &amp;
+               tend % w % array(k,cell2) = tend % w % array(k,cell2) + sign(1.0_RKIND,tend % u % array(k,iEdge))  &amp;
                                                                *config_coef_3rd_order*zf3(k,2,iEdge)*flux
-               tend % w % array(k,cell1) = tend % w % array(k,cell1) - sign(1.,tend % u % array(k,iEdge))  &amp;
+               tend % w % array(k,cell1) = tend % w % array(k,cell1) - sign(1.0_RKIND,tend % u % array(k,iEdge))  &amp;
                                                                *config_coef_3rd_order*zf3(k,1,iEdge)*flux
             end if
                
@@ -869,7 +865,7 @@
 
                do k=2,nVertLevels
 
-                  kr = min(nVertLevels,k+ nint(.5-sign(.5,zx(k,iEdge)+zx(k+1,iEdge))))
+                  kr = min(nVertLevels,k+ nint(.5-sign(0.5_RKIND,zx(k,iEdge)+zx(k+1,iEdge))))
                   kl = min(nVertLevels,2*k+1-kr)
                   pr = zz(k,cell2)*rtheta_pp_old(k ,cell2)+.5*(zgrid(k   ,cell1) +zgrid(k +1,cell1)   &amp;
                                                               -zgrid(k   ,cell2) -zgrid(k +1,cell2))  &amp;
@@ -1010,7 +1006,7 @@
                                                     rho_pp, rho_zz, rho_base, ruAvg, ru_save, ru_p, u, ru, &amp;
                                                     exner, exner_base, rtheta_base, pressure_p,         &amp;
                                                     zz, theta_m, pressure_b, qvapor
-      real (kind=RKIND), dimension(:), pointer :: fzm, fzp, dvEdge, AreaCell, rdzw, surface_pressure
+      real (kind=RKIND), dimension(:), pointer :: fzm, fzp, dvEdge, AreaCell
       real (kind=RKIND), dimension(:,:,:), pointer :: zb, zb3 
       integer, dimension(:,:), pointer :: cellsOnEdge
 
@@ -1053,9 +1049,7 @@
 
        pressure_p =&gt; diag % pressure_p % array
        pressure_b =&gt; diag % pressure_base % array
-       surface_pressure =&gt; diag % surface_pressure % array
 
-       rdzw =&gt; grid % rdzw % array
        zz =&gt; grid % zz % array
        zb =&gt; grid % zb % array
        zb3 =&gt; grid % zb3 % array
@@ -1130,13 +1124,6 @@
                                                           * (exner(k,iCell)-exner_base(k,iCell)))
           end do
 
-         !calculation of the surface pressure:
-         surface_pressure(iCell) = 0.5*gravity/rdzw(1)                                              &amp;
-                       * (1.25* rho_zz(1,iCell) * (1. + qvapor(1,iCell))  &amp;
-                       -  0.25* rho_zz(2,iCell) * (1. + qvapor(2,iCell)))
-         surface_pressure(iCell) = surface_pressure(iCell) + pressure_p(1,iCell) + pressure_b(1,iCell)
-
-
       end do
 
       ! recover time-averaged ruAvg on all edges of owned cells (for upcoming scalar transport).  
@@ -1167,16 +1154,16 @@
 
           !SHP-mtn
           flux = cf1*ru(1,iEdge) + cf2*ru(2,iEdge) + cf3*ru(3,iEdge)
-          w(1,cell2) = w(1,cell2) - (zb(1,2,iEdge) + sign(1.,flux)*coef_3rd_order*zb3(1,2,iEdge))  &amp;
+          w(1,cell2) = w(1,cell2) - (zb(1,2,iEdge) + sign(1.0_RKIND,flux)*coef_3rd_order*zb3(1,2,iEdge))  &amp;
                                  *flux/(cf1*rho_zz(1,cell2)+cf2*rho_zz(2,cell2)+cf3*rho_zz(3,cell2))
-          w(1,cell1) = w(1,cell1) + (zb(1,1,iEdge) + sign(1.,flux)*coef_3rd_order*zb3(1,1,iEdge))  &amp;
+          w(1,cell1) = w(1,cell1) + (zb(1,1,iEdge) + sign(1.0_RKIND,flux)*coef_3rd_order*zb3(1,1,iEdge))  &amp;
                                  *flux/(cf1*rho_zz(1,cell1)+cf2*rho_zz(2,cell1)+cf3*rho_zz(3,cell1))
 
           do k = 2, nVertLevels
             flux = (fzm(k)*ru(k,iEdge)+fzp(k)*ru(k-1,iEdge))
-            w(k,cell2) = w(k,cell2) - (zb(k,2,iEdge)+sign(1.,flux)*coef_3rd_order*zb3(k,2,iEdge)) &amp;
+            w(k,cell2) = w(k,cell2) - (zb(k,2,iEdge)+sign(1.0_RKIND,flux)*coef_3rd_order*zb3(k,2,iEdge)) &amp;
                                  *flux/(fzm(k)*rho_zz(k,cell2)+fzp(k)*rho_zz(k-1,cell2))
-            w(k,cell1) = w(k,cell1) + (zb(k,1,iEdge)+sign(1.,flux)*coef_3rd_order*zb3(k,1,iEdge)) &amp;
+            w(k,cell1) = w(k,cell1) + (zb(k,1,iEdge)+sign(1.0_RKIND,flux)*coef_3rd_order*zb3(k,1,iEdge)) &amp;
                                  *flux/(fzm(k)*rho_zz(k,cell1)+fzp(k)*rho_zz(k-1,cell1))
           enddo
 
@@ -1298,7 +1285,7 @@
                do i=1,nAdvCellsForEdge(iEdge)
                  iCell = advCellsForEdge(i,iEdge)
                  do k=1,grid % nVertLevels
-                   scalar_weight = adv_coefs(i,iEdge) + coef_3rd_order*sign(1.,uhAvg(k,iEdge))*adv_coefs_3rd(i,iEdge)
+                   scalar_weight = adv_coefs(i,iEdge) + coef_3rd_order*sign(1.0_RKIND,uhAvg(k,iEdge))*adv_coefs_3rd(i,iEdge)
                    do iScalar=1,s_old % num_scalars
                      flux_arr(iScalar,k) = flux_arr(iScalar,k) + scalar_weight* scalar_new(iScalar,k,iCell)
                    end do
@@ -1633,7 +1620,7 @@
                do i=1,nAdvCellsForEdge(iEdge)
                  iCell = advCellsForEdge(i,iEdge)
                  do k=1,grid % nVertLevels
-                   scalar_weight = uhAvg(k,iEdge)*(adv_coefs(i,iEdge) + coef_3rd_order*sign(1.,uhAvg(k,iEdge))*adv_coefs_3rd(i,iEdge))
+                   scalar_weight = uhAvg(k,iEdge)*(adv_coefs(i,iEdge) + coef_3rd_order*sign(1.0_RKIND,uhAvg(k,iEdge))*adv_coefs_3rd(i,iEdge))
                    flux_arr(k,iEdge) = flux_arr(k,iEdge) + scalar_weight* scalar_new(k,iCell)
                  end do
                end do
@@ -1651,7 +1638,7 @@
 
             do k = 2, nVertLevels
               scalar_new(k,iCell) = scalar_old(k,iCell)*h_old(k,iCell)
-              flux_upwind = dt*(max(0.,wwAvg(k,iCell))*scalar_old(k-1,iCell) + min(0.,wwAvg(k,iCell))*scalar_old(k,iCell))
+              flux_upwind = dt*(max(0.0_RKIND,wwAvg(k,iCell))*scalar_old(k-1,iCell) + min(0.0_RKIND,wwAvg(k,iCell))*scalar_old(k,iCell))
               scalar_new(k-1,iCell) = scalar_new(k-1,iCell) - flux_upwind*rdnw(k-1)
               scalar_new(k  ,iCell) = scalar_new(k  ,iCell) + flux_upwind*rdnw(k)
               wdtn(k,iCell) = dt*wdtn(k,iCell) - flux_upwind
@@ -1661,8 +1648,8 @@
 ! contributions to the update:  first the vertical flux component, then the horizontal
 
             do k=1,nVertLevels
-              scale_in (k,iCell) = - rdnw(k)*(min(0.,wdtn(k+1,iCell))-max(0.,wdtn(k,iCell)))
-              scale_out(k,iCell) = - rdnw(k)*(max(0.,wdtn(k+1,iCell))-min(0.,wdtn(k,iCell)))
+              scale_in (k,iCell) = - rdnw(k)*(min(0.0_RKIND,wdtn(k+1,iCell))-max(0.0_RKIND,wdtn(k,iCell)))
+              scale_out(k,iCell) = - rdnw(k)*(max(0.0_RKIND,wdtn(k+1,iCell))-min(0.0_RKIND,wdtn(k,iCell)))
             end do
 
           end do
@@ -1677,15 +1664,15 @@
              if (cell1 &lt;= grid%nCellsSolve .or. cell2 &lt;= grid%nCellsSolve) then  ! only for owned cells
                do k=1,grid % nVertLevels
                  flux_upwind = grid % dvEdge % array(iEdge) * dt *   &amp;
-                        (max(0.,uhAvg(k,iEdge))*scalar_old(k,cell1) + min(0.,uhAvg(k,iEdge))*scalar_old(k,cell2))
+                        (max(0.0_RKIND,uhAvg(k,iEdge))*scalar_old(k,cell1) + min(0.0_RKIND,uhAvg(k,iEdge))*scalar_old(k,cell2))
                  flux_arr(k,iEdge) = dt*flux_arr(k,iEdge) - flux_upwind
                  scalar_new(k,cell1) = scalar_new(k,cell1) - flux_upwind / areaCell(cell1)
                  scalar_new(k,cell2) = scalar_new(k,cell2) + flux_upwind / areaCell(cell2)
 
-                 scale_out(k,cell1) = scale_out(k,cell1) - max(0.,flux_arr(k,iEdge)) / areaCell(cell1)
-                 scale_in (k,cell1) = scale_in (k,cell1) - min(0.,flux_arr(k,iEdge)) / areaCell(cell1)
-                 scale_out(k,cell2) = scale_out(k,cell2) + min(0.,flux_arr(k,iEdge)) / areaCell(cell2)
-                 scale_in (k,cell2) = scale_in (k,cell2) + max(0.,flux_arr(k,iEdge)) / areaCell(cell2)
+                 scale_out(k,cell1) = scale_out(k,cell1) - max(0.0_RKIND,flux_arr(k,iEdge)) / areaCell(cell1)
+                 scale_in (k,cell1) = scale_in (k,cell1) - min(0.0_RKIND,flux_arr(k,iEdge)) / areaCell(cell1)
+                 scale_out(k,cell2) = scale_out(k,cell2) + min(0.0_RKIND,flux_arr(k,iEdge)) / areaCell(cell2)
+                 scale_in (k,cell2) = scale_in (k,cell2) + max(0.0_RKIND,flux_arr(k,iEdge)) / areaCell(cell2)
 
                end do
              end if
@@ -1700,10 +1687,10 @@
                s_upwind = scalar_new(k,iCell)/h_new(k,iCell)
            
                scale_factor = (s_max(k,iCell)-s_upwind)/(s_max_update-s_upwind+eps)
-               scale_in(k,iCell) = min( 1.0, max( 0.0, scale_factor) )
+               scale_in(k,iCell) = min( 1.0_RKIND, max( 0.0_RKIND, scale_factor) )
 
                scale_factor = (s_upwind-s_min(k,iCell))/(s_upwind-s_min_update+eps)
-               scale_out(k,iCell) = min( 1.0, max( 0.0, scale_factor) )
+               scale_out(k,iCell) = min( 1.0_RKIND, max( 0.0_RKIND, scale_factor) )
 
             end do
           end do
@@ -1729,8 +1716,8 @@
                if (cell1 &lt;= grid%nCellsSolve .or. cell2 &lt;= grid%nCellsSolve) then
                   do k = 1, nVertLevels
                      flux = flux_arr(k,iEdge)
-                     flux = max(0.,flux) * min(scale_out(k,cell1), scale_in(k,cell2)) &amp;
-                          + min(0.,flux) * min(scale_in(k,cell1), scale_out(k,cell2))
+                     flux = max(0.0_RKIND,flux) * min(scale_out(k,cell1), scale_in(k,cell2)) &amp;
+                          + min(0.0_RKIND,flux) * min(scale_in(k,cell1), scale_out(k,cell2))
                      flux_arr(k,iEdge) = flux
                   end do
                end if
@@ -1741,8 +1728,8 @@
             do iCell=1,grid % nCells
                do k = 2, nVertLevels
                   flux =  wdtn(k,iCell)
-                  flux = max(0.,flux) * min(scale_out(k-1,iCell), scale_in(k  ,iCell)) &amp;
-                       + min(0.,flux) * min(scale_out(k  ,iCell), scale_in(k-1,iCell))
+                  flux = max(0.0_RKIND,flux) * min(scale_out(k-1,iCell), scale_in(k  ,iCell)) &amp;
+                       + min(0.0_RKIND,flux) * min(scale_out(k  ,iCell), scale_in(k-1,iCell))
                   wdtn(k,iCell) = flux
                end do
             end do
@@ -1790,7 +1777,7 @@
 
           do iCell = 1, grid%nCells
           do k=1, grid%nVertLevels
-            scalar_new_in(iScalar,k,iCell) = max(0.,scalar_new(k,iCell))
+            scalar_new_in(iScalar,k,iCell) = max(0.0_RKIND,scalar_new(k,iCell))
           end do
           end do
 
@@ -1872,7 +1859,8 @@
       real (kind=RKIND) :: r_earth
       real (kind=RKIND), dimension(:,:), pointer :: ur_cell, vr_cell
 
-      real (kind=RKIND), parameter :: c_s = 0.25
+      real (kind=RKIND), parameter :: c_s = 0.125
+!     real (kind=RKIND), parameter :: c_s = 0.25
       real (kind=RKIND), dimension( grid % nVertLevels ) :: d_diag, d_off_diag, flux_arr
       real (kind=RKIND), dimension(:,:), pointer :: defc_a, defc_b
       logical :: delsq_horiz_mixing, newpx
@@ -2072,7 +2060,7 @@
             k = 2
             wduz(k) =  0.5*( rw(k,cell1)+rw(k,cell2) )*(fzm(k)*u(k,iEdge)+fzp(k)*u(k-1,iEdge))  
             do k=3,nVertLevels-1
-               wduz(k) = flux3( u(k-2,iEdge),u(k-1,iEdge),u(k,iEdge),u(k+1,iEdge),0.5*(rw(k,cell1)+rw(k,cell2)), 1. )
+               wduz(k) = flux3( u(k-2,iEdge),u(k-1,iEdge),u(k,iEdge),u(k+1,iEdge),0.5*(rw(k,cell1)+rw(k,cell2)), 1.0_RKIND )
             end do
             k = nVertLevels
             wduz(k) =  0.5*( rw(k,cell1)+rw(k,cell2) )*(fzm(k)*u(k,iEdge)+fzp(k)*u(k-1,iEdge))  
@@ -2368,7 +2356,7 @@
                do i=1,nAdvCellsForEdge(iEdge)
                  iCell = advCellsForEdge(i,iEdge)
                  do k=2,grid % nVertLevels
-                   scalar_weight = adv_coefs(i,iEdge) + coef_3rd_order*sign(1.,ru_edge_w(k))*adv_coefs_3rd(i,iEdge)
+                   scalar_weight = adv_coefs(i,iEdge) + coef_3rd_order*sign(1.0_RKIND,ru_edge_w(k))*adv_coefs_3rd(i,iEdge)
                    flux_arr(k) = flux_arr(k) + scalar_weight* w(k,iCell)
                  end do
                end do
@@ -2582,7 +2570,7 @@
             k = 2
             wdwz(k) =  0.25*(rw(k,icell)+rw(k-1,iCell))*(w(k,iCell)+w(k-1,iCell))
             do k=3,nVertLevels-1
-               wdwz(k) = flux3( w(k-2,iCell),w(k-1,iCell),w(k,iCell),w(k+1,iCell),0.5*(rw(k,iCell)+rw(k-1,iCell)), 1. )
+               wdwz(k) = flux3( w(k-2,iCell),w(k-1,iCell),w(k,iCell),w(k+1,iCell),0.5*(rw(k,iCell)+rw(k-1,iCell)), 1.0_RKIND )
             end do
             k = nVertLevels
             wdwz(k) =  0.25*(rw(k,icell)+rw(k-1,iCell))*(w(k,iCell)+w(k-1,iCell))
@@ -2678,7 +2666,7 @@
                do i=1,nAdvCellsForEdge(iEdge)
                  iCell = advCellsForEdge(i,iEdge)
                  do k=1,grid % nVertLevels
-                   scalar_weight = adv_coefs(i,iEdge) + coef_3rd_order*sign(1.,ru(k,iEdge))*adv_coefs_3rd(i,iEdge)
+                   scalar_weight = adv_coefs(i,iEdge) + coef_3rd_order*sign(1.0_RKIND,ru(k,iEdge))*adv_coefs_3rd(i,iEdge)
                    flux_arr(k) = flux_arr(k) + scalar_weight* theta_m(k,iCell)
                  end do
                end do
@@ -3324,10 +3312,10 @@
                           * (grid % fzp % array(k) * grid % zz % array(k-1,cell1) + grid % fzm % array(k) * grid % zz % array(k,cell1))
 !3rd order! stencil
             if (config_theta_adv_order ==3) then
-               diag % rw % array(k,cell2) = diag % rw % array(k,cell2) + sign(1.,flux)*config_coef_3rd_order    &amp;
+               diag % rw % array(k,cell2) = diag % rw % array(k,cell2) + sign(1.0_RKIND,flux)*config_coef_3rd_order    &amp;
                                         * grid % zb3 % array(k,2,iEdge)*flux                                    &amp;
                           * (grid % fzp % array(k) * grid % zz % array(k-1,cell2) + grid % fzm % array(k) * grid % zz % array(k,cell2))
-               diag % rw % array(k,cell1) = diag % rw % array(k,cell1) - sign(1.,flux)*config_coef_3rd_order    &amp;
+               diag % rw % array(k,cell1) = diag % rw % array(k,cell1) - sign(1.0_RKIND,flux)*config_coef_3rd_order    &amp;
                                         * grid % zb3 % array(k,1,iEdge)*flux                                    &amp;
                           * (grid % fzp % array(k) * grid % zz % array(k-1,cell1) + grid % fzm % array(k) * grid % zz % array(k,cell1))
             end if
@@ -3405,11 +3393,11 @@
           t(k) = state_new % theta_m % array(k,iCell)/(1. + 1.61*state_new % scalars % array(state_new % index_qv,k,iCell))
           rho(k) = grid % zz % array(k,iCell)*state_new % rho_zz % array(k,iCell)
           p(k) = diag % exner % array(k,iCell)
-          qv(k) = max(0.,state_new % scalars % array(state_new % index_qv,k,iCell))
-          qc(k) = max(0.,state_new % scalars % array(state_new % index_qc,k,iCell))
-          qr(k) = max(0.,state_new % scalars % array(state_new % index_qr,k,iCell))
-          qc1(k) = max(0.,state_old % scalars % array(state_old % index_qc,k,iCell))
-          qr1(k) = max(0.,state_old % scalars % array(state_old % index_qr,k,iCell))
+          qv(k) = max(0.0_RKIND,state_new % scalars % array(state_new % index_qv,k,iCell))
+          qc(k) = max(0.0_RKIND,state_new % scalars % array(state_new % index_qc,k,iCell))
+          qr(k) = max(0.0_RKIND,state_new % scalars % array(state_new % index_qr,k,iCell))
+          qc1(k) = max(0.0_RKIND,state_old % scalars % array(state_old % index_qc,k,iCell))
+          qr1(k) = max(0.0_RKIND,state_old % scalars % array(state_old % index_qr,k,iCell))
           dzu(k) = grid % dzu % array(k)
    
         end do
@@ -3486,8 +3474,8 @@
       do i=1,nx
          do k=1,nz1
             qrprod(k) = qc1t(k,i)                                  &amp;
-                      -(qc1t(k,i)-dt*amax1(ackess*(qc1(k,i)-.001), &amp;
-                           0.))/(1.+dt*ckess*qr1(k,i)**.875)       
+                      -(qc1t(k,i)-dt*max(ackess*(qc1(k,i)-.001), &amp;
+                           0.0_RKIND))/(1.+dt*ckess*qr1(k,i)**.875)       
                            velqr(k)  = (qr1(k,i)*r(k))**1.1364*rhalf(k)
             qvs(k)    = pc(k)*exp(f2x*(pk(k)*t1t(k,i)-273.)  &amp;
                                   /(pk(k)*t1t(k,i)- 36.))
@@ -3505,23 +3493,23 @@
          artemp       = 36340.*(.5*(velqr(2)+velqr(1))+veld-velu)
          artot        = artot+dt*artemp
          do k=1,nz1
-            qc1t(k,i) = amax1(qc1t(k,i)-qrprod(k),0.)
-            qr1t(k,i) = amax1(qr1t(k,i)+qrprod(k),0.)
+            qc1t(k,i) = max(qc1t(k,i)-qrprod(k),0.0_RKIND)
+            qr1t(k,i) = max(qr1t(k,i)+qrprod(k),0.0_RKIND)
             prod(k)   = (qv1t(k,i)-qvs(k))/(1.+qvs(k)*f5  &amp;
                                 /(pk(k)*t1t(k,i)-36.)**2)
          end do
          do k=1,nz1
-            ern(k)    = amin1(dt*(((1.6+124.9*(r(k)*qr1t(k,i))**.2046)  &amp;
+            ern(k)    = min(dt*(((1.6+124.9*(r(k)*qr1t(k,i))**.2046)  &amp;
                          *(r(k)*qr1t(k,i))**.525)/(2.55e6*pc(k)         &amp;
                          /(3.8 *qvs(k))+5.4e5))*(dim(qvs(k),qv1t(k,i))  &amp;
                          /(r(k)*qvs(k))),                               &amp;
-                          amax1(-prod(k)-qc1t(k,i),0.),qr1t(k,i))
+                          max(-prod(k)-qc1t(k,i),0.0_RKIND),qr1t(k,i))
          end do
          do k=1,nz1
-            buoycy(k) = f0(k)*(amax1(prod(k),-qc1t(k,i))-ern(k))
-                                qv1t(k,i) = amax1(qv1t(k,i)    &amp;
-                         -amax1(prod(k),-qc1t(k,i))+ern(k),0.)
-            qc1t(k,i) = qc1t(k,i)+amax1(prod(k),-qc1t(k,i))
+            buoycy(k) = f0(k)*(max(prod(k),-qc1t(k,i))-ern(k))
+                                qv1t(k,i) = max(qv1t(k,i)    &amp;
+                         -max(prod(k),-qc1t(k,i))+ern(k),0.0_RKIND)
+            qc1t(k,i) = qc1t(k,i)+max(prod(k),-qc1t(k,i))
             qr1t(k,i) = qr1t(k,i)-ern(k)
             t1t (k,i) = t1t (k,i)+buoycy(k)
          end do


Property changes on: branches/ocean_projects/gmvar/src/core_ocean
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean:754-986
/branches/ocean_projects/rayleigh/src/core_ocean:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean:1134-1138
/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:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/Makefile
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/Makefile        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/Makefile        2012-02-02 19:34:14 UTC (rev 1454)
@@ -14,6 +14,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 \
@@ -42,9 +43,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)
@@ -60,10 +61,12 @@
 
 mpas_ocn_time_integration_split.o:
 
-mpas_ocn_tendency.o: mpas_ocn_gm.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:
@@ -80,12 +83,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
@@ -176,7 +181,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/gmvar/src/core_ocean/Registry
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/Registry        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/Registry        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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
@@ -50,8 +48,8 @@
 namelist real      hmix     config_apvm_upwinding       0.0
 namelist real      hmix     config_h_kappa              0.0
 namelist real      hmix     config_h_kappa_q            0.0
-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.
@@ -80,9 +78,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
@@ -96,9 +94,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 - -
@@ -153,21 +151,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 - -
@@ -176,19 +174,19 @@
 var persistent real hZLevel ( nVertLevels ) 0 iro hZLevel mesh - -
 var persistent real zMidZLevel ( nVertLevels ) 0 - zMidZLevel mesh - -
 var persistent real zTopZLevel ( nVertLevelsP1 ) 0 - zTopZLevel mesh - -
-var persistent real hMeanTopZLevel ( nVertLevels ) 0 - hMeanTopZLevel mesh - -
-var persistent real hRatioZLevelK ( nVertLevels ) 0 - hRatioZLevelK mesh - -
-var persistent real hRatioZLevelKm1 ( nVertLevels ) 0 - hRatioZLevelKm1 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    rho ( nVertLevels nCells Time ) 2 iro rho state - -
@@ -196,7 +194,7 @@
 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 - -
@@ -204,20 +202,21 @@
 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    uTransport ( nVertLevels nEdges Time ) 2 o uTransport state - -
 var persistent real    uBolusGM ( nVertLevels nEdges Time ) 2 o uBolusGM state - -
@@ -251,13 +250,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 - -
@@ -266,8 +265,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 - -


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/Registry
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/Registry:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/Registry:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/Registry:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/Registry:754-986
/branches/ocean_projects/performance/src/core_ocean/Registry:1120-1372
/branches/ocean_projects/rayleigh/src/core_ocean/Registry:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/Registry:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/Registry:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/Registry:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/Registry:704-745
/branches/source_renaming/src/core_ocean/Registry:1082-1113
/branches/time_manager/src/core_ocean/Registry:924-962
/trunk/mpas/src/core_ocean/Registry:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_advection.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_advection.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_advection.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_advection.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_advection.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_advection.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_advection.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_advection.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_advection.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_advection.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_advection.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_advection.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_advection.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_advection.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_advection.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_advection.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_advection.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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
 
@@ -99,8 +98,6 @@
 
       if(.not.eosOn) 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
@@ -122,8 +119,6 @@
 
       endif
 
-      call mpas_timer_stop(&quot;ocn_equation_of_state_rho&quot;)
-
    end subroutine ocn_equation_of_state_rho!}}}
 
 !***********************************************************************
@@ -159,7 +154,7 @@
       linearEos = .false.
       jmEos = .false.
 
-      if(config_vert_grid_type.eq.'zlevel') then
+      if(config_vert_grid_type.ne.'isopycnal') then
           eosON = .true.
 
           if (config_eos_type.eq.'linear') then


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_equation_of_state.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_equation_of_state.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_equation_of_state.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_equation_of_state.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_equation_of_state.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_equation_of_state.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_equation_of_state.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_equation_of_state.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_equation_of_state.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_equation_of_state.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_equation_of_state.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_equation_of_state.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_jm.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_jm.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_jm.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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!}}}
 
 !***********************************************************************


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_jm.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_equation_of_state_jm.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_equation_of_state_jm.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_equation_of_state_jm.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_equation_of_state_jm.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_linear.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_linear.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_linear.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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!}}}
 
 !***********************************************************************


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_equation_of_state_linear.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_equation_of_state_linear.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_equation_of_state_linear.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_equation_of_state_linear.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_equation_of_state_linear.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_global_diagnostics.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_global_diagnostics.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_global_diagnostics.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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()
@@ -322,7 +430,7 @@
             write (fileID,'(100es24.14)') averages(1:nVariables)
          close (fileID)
          open(fileID,file='stats_time.txt',ACCESS='append')
-            write (fileID,'(i5,10x,a,100es24.14)') timeIndex, &amp;
+            write (fileID,'(i10,10x,a,100es24.14)') timeIndex, &amp;
                state % xtime % scalar, dt, &amp;
                CFLNumberGlobal
          close (fileID)
@@ -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


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_global_diagnostics.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_global_diagnostics.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_global_diagnostics.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_global_diagnostics.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_global_diagnostics.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_global_diagnostics.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_global_diagnostics.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_global_diagnostics.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_global_diagnostics.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_global_diagnostics.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_global_diagnostics.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_global_diagnostics.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_global_diagnostics.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_global_diagnostics.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_mpas_core.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_mpas_core.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_mpas_core.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,12 +1,14 @@
 module mpas_core
 
+   use mpas_configure
    use mpas_framework
    use mpas_timekeeping
    use mpas_dmpar
+   use mpas_timer
+
+   use ocn_global_diagnostics
    use ocn_test_cases
-
    use ocn_time_integration
-
    use ocn_tendency
 
    use ocn_vel_pressure_grad
@@ -23,6 +25,8 @@
 
    use ocn_vmix
 
+   use ocn_time_average
+
    type (io_output_object) :: restart_obj
 
    integer :: current_outfile_frames
@@ -33,11 +37,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,25 +85,34 @@
       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)
+
       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 coordinates'
-      elseif (config_vert_grid_type.eq.'zlevel') then
-         print *, ' Using z-level coordinates'
-         call init_ZLevel(domain)
-      else 
-         print *, ' Incorrect choice of config_vert_grid_type:',&amp;
-           config_vert_grid_type
+      print *, ' Vertical grid type is: ',config_vert_grid_type
+
+      if (config_vert_grid_type.ne.'isopycnal'.and. &amp;
+          config_vert_grid_type.ne.'zlevel'.and. &amp;
+          config_vert_grid_type.ne.'zstar1'.and. &amp;
+          config_vert_grid_type.ne.'zstar'.and. &amp;
+          config_vert_grid_type.ne.'zstarWeights') then
+         print *, ' Incorrect choice of config_vert_grid_type.'
          call mpas_dmpar_abort(dminfo)
       endif
 
+      if (config_vert_grid_type.ne.'isopycnal') then
+         call ocn_init_z_level(domain)
+      endif
+
       if (trim(config_new_btr_variables_from) == 'btr_avg' &amp;
            .and.trim(config_time_integration) == 'unsplit_explicit') then
          print *, ' unsplit_explicit option must use',&amp;
@@ -110,33 +125,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
 
@@ -192,7 +206,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)!{{{
    
@@ -207,10 +221,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)
@@ -226,6 +243,8 @@
       ! The reconstructed velocity on land will have values not exactly
       ! -1e34 due to the interpolation of reconstruction.
 
+      block % mesh % areaCell % array(block % mesh % nCells+1) = -1.0e34
+
       do iEdge=1,block % mesh % nEdges
          ! mrp 101115 note: in order to include flux boundary conditions, the following
          ! line will need to change.  Right now, set boundary edges between land and 
@@ -248,7 +267,7 @@
 !              :block % mesh % nVertLevels,iCell) =  -1e34
 
 ! mrp 110516, added just to test for conservation of tracers
-!         block % state % time_levs(1) % state % tracers % array(block % state % time_levs(1) % state % index_tracer1,:,iCell) = 1.0
+         block % state % time_levs(1) % state % tracers % array(block % state % time_levs(1) % state % index_tracer1,:,iCell) = 1.0
 
       end do
 
@@ -298,8 +317,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
@@ -312,9 +337,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)
@@ -326,7 +351,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
@@ -342,7 +380,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
    !
@@ -365,7 +403,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
    
@@ -381,9 +419,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
    !
@@ -403,13 +441,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
    
@@ -425,17 +461,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
 
@@ -458,7 +486,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
@@ -472,10 +500,9 @@
    type (block_type), pointer :: block
 
    integer :: iTracer, cell, cell1, cell2
-   real (kind=RKIND) :: uhSum, hSum, sshEdge
+   real (kind=RKIND) :: uhSum, hSum, hEdge1
    real (kind=RKIND), dimension(:), pointer :: &amp;
-      hZLevel, zMidZLevel, zTopZLevel, &amp;
-      hMeanTopZLevel, hRatioZLevelK, hRatioZLevelKm1
+      hZLevel, zTopZLevel, zMidZLevel
    real (kind=RKIND), dimension(:,:), pointer :: h
    integer :: nVertLevels
 
@@ -485,41 +512,25 @@
 
       h          =&gt; block % state % time_levs(1) % state % h % array
       hZLevel    =&gt; block % mesh % hZLevel % array
+      zTopZLevel =&gt; block % mesh % zTopZLevel % array
       zMidZLevel =&gt; block % mesh % zMidZLevel % array
-      zTopZLevel =&gt; block % mesh % zTopZLevel % array
       nVertLevels = block % mesh % nVertLevels
-      hMeanTopZLevel    =&gt; block % mesh % hMeanTopZLevel % array
-      hRatioZLevelK    =&gt; block % mesh % hRatioZLevelK % array
-      hRatioZLevelKm1    =&gt; block % mesh % hRatioZLevelKm1 % array
 
-      ! These should eventually be in an input file.  For now
-      ! I just read them in from h(:,1).
-      ! Upon restart, the correct hZLevel should be in restart.nc
-      if (.not. config_do_restart) hZLevel = h(:,1)
+      ! hZLevel should be in the grid.nc or restart.nc file.
 
-      ! hZLevel should be in the grid.nc and restart.nc file, 
-      ! and h for k=1 must be specified there as well.

+      ! zTopZLevel is used for the z-coordinate of the bottom of
+      ! the water column.  This is used to compute zMid from bottom
+      ! up at each timestep.
+
+      ! zMidZLevel is used in the EOS computation to compute pressure.
       zTopZLevel(1) = 0.0
       do k = 1,nVertLevels
          zMidZLevel(k) = zTopZLevel(k)-0.5*hZLevel(k)
          zTopZLevel(k+1) = zTopZLevel(k)-  hZLevel(k)
       end do
 
-      hMeanTopZLevel(1) = 0.0
-      hRatioZLevelK(1) = 0.0
-      hRatioZLevelKm1(1) = 0.0
-      do k = 2,nVertLevels
-         hMeanTopZLevel(k) = 0.5*(hZLevel(k-1) + hZLevel(k))
-         hRatioZLevelK(k) = 0.5*hZLevel(k)/hMeanTopZLevel(k)
-         hRatioZLevelKm1(k) = 0.5*hZLevel(k-1)/hMeanTopZLevel(k)
-      end do
-
-      ! mrp 110601 For now, h is the variable saved in the restart file
-      ! I am computing SSH here.  In the future, could make smaller 
-      ! restart files for z-Level runs by saving SSH only.
+      ! Compute ssh from h at level 1.
       do iCell=1,block % mesh % nCells
-
           block % state % time_levs(1) % state % ssh % array(iCell) &amp; 
         = block % state % time_levs(1) % state % h % array(1,iCell) &amp; 
         - block % mesh % hZLevel % array(1)
@@ -548,21 +559,30 @@
                cell1 = block % mesh % cellsOnEdge % array(1,iEdge)
                cell2 = block % mesh % cellsOnEdge % array(2,iEdge)
 
-               sshEdge = 0.5*( &amp;
-                   block % state % time_levs(1) % state % ssh % array(cell1) &amp; 
-                 + block % state % time_levs(1) % state % ssh % array(cell2) ) 
-
                ! uBtr = sum(u)/sum(h) on each column
-               uhSum = (sshEdge + block % mesh % hZLevel % array(1)) &amp;
-                  * block % state % time_levs(1) % state % u % array(1,iEdge)
-               hSum = sshEdge + block % mesh % hZLevel % array(1)
+                  ! ocn_diagnostic_solve has not yet been called, so compute hEdge 
+                  ! just for this edge.
 
+               ! I took out k=1 so that hSum always has a nonzero value, to avoid
+               ! nans in uBtr.
+               hEdge1 = 0.5*( &amp;
+                   block % state % time_levs(1) % state % h % array(1,cell1) &amp; 
+                 + block % state % time_levs(1) % state % h % array(1,cell2) ) 
+
+               uhSum = hEdge1*block % state % time_levs(1) % state % u % array(1,iEdge)
+               hSum = hEdge1
+
                do k=2,block % mesh % maxLevelEdgeTop % array(iEdge)
+                  ! ocn_diagnostic_solve has not yet been called, so compute hEdge 
+                  ! just for this edge.
+                  hEdge1 = 0.5*( &amp;
+                      block % state % time_levs(1) % state % h % array(k,cell1) &amp; 
+                    + block % state % time_levs(1) % state % h % array(k,cell2) ) 
+
                   uhSum = uhSum &amp;
-                     + block % mesh % hZLevel % array(k) &amp;
-                      *block % state % time_levs(1) % state % u % array(k,iEdge)
-                  hSum = hSum &amp;
-                     + block % mesh % hZLevel % array(k)
+                     + hEdge1*block % state % time_levs(1) % state % u % array(k,iEdge)
+                  hSum = hSum + hEdge1
+
                enddo
                block % state % time_levs(1) % state % uBtr % array(iEdge) = uhSum/hsum
 
@@ -590,39 +610,13 @@
 
          endif
 
-!print *, '11 u ',minval(domain % blocklist % state % time_levs(1) % state % u % array(:,1:domain % blocklist % mesh % nEdgesSolve)), &amp;
-!                maxval(domain % blocklist % state % time_levs(1) % state % u % array(:,1:domain % blocklist % mesh % nEdgesSolve))
-!print *, '11 uBtr ',minval(domain % blocklist % state % time_levs(1) % state % uBtr % array(1:domain % blocklist % mesh % nEdgesSolve)), &amp;
-!                    maxval(domain % blocklist % state % time_levs(1) % state % uBtr % array(1:domain % blocklist % mesh % nEdgesSolve))
-!print *, '11 uBcl ',minval(domain % blocklist % state % time_levs(1) % state % uBcl % array(:,1:domain % blocklist % mesh % nEdgesSolve)), &amp;
-!                    maxval(domain % blocklist % state % time_levs(1) % state % uBcl % array(:,1:domain % blocklist % mesh % nEdgesSolve))
-
-
-! mrp temp testing - is uBcl vert sum zero?
-!            do iEdge=1,block % mesh % nEdges
-!              uhSum = (sshEdge + block % mesh % hZLevel % array(1)) * block % state % time_levs(1) % state % uBcl % array(1,iEdge)
-!              hSum  =  sshEdge + block % mesh % hZLevel % array(1)
-
-!              do k=2,block % mesh % maxLevelEdgeTop % array(iEdge)
-!                 uhSum = uhSum + block % mesh % hZLevel % array(k) *  block % state % time_levs(1) % state % uBcl % array(k,iEdge)
-!                 hSum  =  hSum + block % mesh % hZLevel % array(k)
-!              enddo
-!              block % state % time_levs(1) % state % FBtr % array(iEdge) = uhSum/hSum
-
-!           enddo ! iEdge
-
-!print *, 'uBcl vert sum IC',minval(block % state % time_levs(1) % state % FBtr % array(1:block % mesh % nEdgesSolve)), &amp;
-!                            maxval(block % state % time_levs(1) % state % FBtr % array(1:block % mesh % nEdgesSolve))
-
-! mrp temp testing - is uBcl vert sum zero? end
-
       block =&gt; block % next
 
    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
@@ -647,7 +641,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
@@ -664,6 +658,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
@@ -717,22 +714,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
@@ -743,7 +749,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)!{{{
    
@@ -758,7 +764,7 @@
 
    end subroutine mpas_core_finalize!}}}
 
-   subroutine compute_mesh_scaling(mesh)!{{{
+   subroutine ocn_compute_mesh_scaling(mesh)!{{{
 
       use mpas_grid_types
       use mpas_configure
@@ -788,7 +794,7 @@
          end do
       end if
 
-   end subroutine compute_mesh_scaling!}}}
+   end subroutine ocn_compute_mesh_scaling!}}}
 
 end module mpas_core
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_mpas_core.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_mpas_core.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_mpas_core.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_mpas_core.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_mpas_core.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_mpas_core.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_mpas_core.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_mpas_core.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_mpas_core.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_mpas_core.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_mpas_core.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_mpas_core.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_mpas_core.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_mpas_core.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_restoring.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_restoring.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_restoring.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -111,6 +111,7 @@
       integer :: iCell, nCellsSolve, k
 
       real (kind=RKIND), dimension(:), pointer :: temperatureRestore, salinityRestore
+      real (kind=RKIND) :: invTemp, invSalinity
 
       err = 0
 
@@ -121,17 +122,14 @@
       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;


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_restoring.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_restoring.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_restoring.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_restoring.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_restoring.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_restoring.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_restoring.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_restoring.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_restoring.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_restoring.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_restoring.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_restoring.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_restoring.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_restoring.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tendency.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tendency.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tendency.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -39,10 +39,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
@@ -60,7 +67,8 @@
              ocn_tend_scalar, &amp;
              ocn_diagnostic_solve, &amp;
              ocn_wtop, &amp;
-             ocn_fuperp
+             ocn_fuperp, &amp;
+             ocn_tendency_init
 
    !--------------------------------------------------------------------
    !
@@ -68,7 +76,11 @@
    !
    !--------------------------------------------------------------------
 
+   integer :: hadv2nd, hadv3rd, hadv4th
+   integer :: ke_cell_flag, ke_vertex_flag
+   real (kind=RKIND) ::  coef_3rd_order, fCoef
 
+
 !***********************************************************************
 
 contains
@@ -103,84 +115,19 @@
       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, uTransport
 
-! 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, uTransport
-      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
       uTransport  =&gt; s % uTransport % 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
       !
@@ -194,21 +141,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, uTransport, 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!}}}
@@ -243,47 +187,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, 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 +212,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 +226,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 ocn_vel_vadv_tend(grid, u, wtop, tend_u, err)
-
-      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, tend_u, err)
-      elseif (config_vert_grid_type.eq.'zlevel') then
-          call ocn_vel_pressure_grad_tend(grid, pressure, tend_u, err)
+          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,75 +310,25 @@
       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, uTransport, 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;
-         hRatioZLevelK, hRatioZLevelKm1, 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
       uTransport           =&gt; s % uTransport % array
       h           =&gt; s % h % 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
-      hRatioZLevelK    =&gt; grid % hRatioZLevelK % array
-      hRatioZLevelKm1    =&gt; grid % hRatioZLevelKm1 % 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.
       !
@@ -518,32 +342,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, uTransport, 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 ocn_tracer_vadv_tend(grid, wtop, tracers, tend_tr, err)
-
-      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))
@@ -555,11 +373,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
@@ -570,11 +388,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;)
@@ -610,44 +428,36 @@
       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;
-        hZLevel
+        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;
-        circulation, vorticity, ke, ke_edge, MontPot, wTop, &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, uBolusGM, uTransport
-      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
       uTransport  =&gt; s % uTransport % array
       uBolusGM      =&gt; s % uBolusGM % 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
@@ -662,9 +472,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
@@ -672,7 +483,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
@@ -682,14 +492,12 @@
       areaTriangle      =&gt; grid % areaTriangle % array
       h_s               =&gt; grid % h_s % array
       fVertex           =&gt; grid % fVertex % array
-      fEdge             =&gt; grid % fEdge % array
-      hZLevel           =&gt; grid % hZLevel % 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
@@ -697,7 +505,6 @@
       nVertLevels = grid % nVertLevels
       vertexDegree = grid % vertexDegree
 
-      boundaryEdge =&gt; grid % boundaryEdge % array
       boundaryCell =&gt; grid % boundaryCell % array
 
 
@@ -708,205 +515,165 @@
       ! mrp 101115 note: in order to include flux boundary conditions, we will need to 
       ! assign h_edge for maxLevelEdgeTop:maxLevelEdgeBot in the following section
 
-      ! mrp 110516 efficiency note: For z-level, only do this on level 1.  h_edge for all
-      ! lower levels is defined by hZlevel.
+      ! initialize h_edge to avoid divide by zero and NaN problems.
+      h_edge = -1.0e34
 
-      call mpas_timer_start(&quot;ocn_diagnostic_solve-hEdge&quot;)
-
-      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
-            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
+      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
-          call mpas_timer_stop(&quot;ocn_diagnostic_solve-hEdge 2&quot;)
+      end do
 
-      else if (config_thickness_adv_order == 3) then
-          call mpas_timer_start(&quot;ocn_diagnostic_solve-hEdge 3&quot;)
+      do iEdge=1,nEdges*hadv3rd
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,iEdge)
 
-         do iEdge=1,nEdges
-            cell1 = cellsOnEdge(1,iEdge)
-            cell2 = cellsOnEdge(2,iEdge)
+         do k=1,maxLevelEdgeTop(iEdge)
 
-            do k=1,maxLevelEdgeTop(iEdge)
+            d2fdx2_cell1 = 0.0
+            d2fdx2_cell2 = 0.0
 
-               d2fdx2_cell1 = 0.0
-               d2fdx2_cell2 = 0.0
+            boundaryMask = abs(transfer(.not.(boundaryCell(k,cell1) == 0 .and. boundaryCell(k,cell2) == 0), boundaryMask))
 
-               !-- 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) * h(k,cell1) * boundaryMask
+            d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2) * boundaryMask
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2)
+            !-- 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 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 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
 
-                  !-- 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
+            velMask = 2*(abs(transfer(u(k,iEdge) &lt;= 0, velMask))) - 1
 
-               endif
+            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.
 
-               !-- 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
+         end do   ! do k
+      end do         ! do iEdge
 
-            end do   ! do k
-         end do         ! do iEdge
+      do iEdge=1,nEdges*hadv4th
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,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;)
+         do k=1,maxLevelEdgeTop(iEdge)
 
-         do iEdge=1,nEdges
-            cell1 = cellsOnEdge(1,iEdge)
-            cell2 = cellsOnEdge(2,iEdge)
+            d2fdx2_cell1 = 0.0
+            d2fdx2_cell2 = 0.0
 
-            do k=1,maxLevelEdgeTop(iEdge)
+            boundaryMask = abs(transfer(.not.(boundaryCell(k,cell1) == 0 .and. boundaryCell(k,cell2) == 0), boundaryMask))
 
-               d2fdx2_cell1 = 0.0
-               d2fdx2_cell2 = 0.0
+            d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1) * boundaryMask
+            d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(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) * h(k,grid % CellsOnCell % array (i,cell1))
+            end do
 
-                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * h(k,cell1)
-                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * h(k,cell2)
+            !-- 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
 
-                  !-- 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
+            h_edge(k,iEdge) =   &amp;
+                 0.5*(h(k,cell1) + h(k,cell2))      &amp;
+                    -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.
 
-                  !-- 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
+         end do   ! do k
+      end do         ! do iEdge
 
-               endif
-
-               h_edge(k,iEdge) =   &amp;
-                    0.5*(h(k,cell1) + h(k,cell2))      &amp;
-                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.
-
-            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;)
-
       !
       ! set the velocity and height at dummy address
       !    used -1e34 so error clearly occurs if these values are used.
       !
-!mrp 110516 change to zero, change back later:
       u(:,nEdges+1) = -1e34
       h(:,nCells+1) = -1e34
       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
@@ -914,35 +681,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)
@@ -955,83 +704,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
 
       !
@@ -1050,16 +780,19 @@
       !
       ! For an isopycnal model, density should remain constant.
       ! For zlevel, calculate in-situ density
-      if (config_vert_grid_type.eq.'zlevel') then
+      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.
@@ -1087,41 +820,47 @@
         end do
         deallocate(pTop)
 
-      elseif (config_vert_grid_type.eq.'zlevel') then
+      else
 
-        ! For z-level model.
-        ! Compute pressure at middle of each level.  
-        ! At k=1, where p is pressure at a depth of hZLevel(1)/2, not
-        ! pressure at middle of layer including SSH.
-
         do iCell=1,nCells
-           ! compute pressure for z-level coordinates
+           ! pressure for generalized coordinates
            ! assume atmospheric pressure at the surface is zero for now.
-
            pressure(1,iCell) = rho(1,iCell)*gravity &amp;
-              * (h(1,iCell)-0.5*hZLevel(1)) 
+              * 0.5*h(1,iCell)
 
            do k=2,maxLevelCell(iCell)
               pressure(k,iCell) = pressure(k-1,iCell)  &amp;
-                + 0.5*gravity*(  rho(k-1,iCell)*hZLevel(k-1) &amp;
-                               + rho(k  ,iCell)*hZLevel(k  ))
+                + 0.5*gravity*(  rho(k-1,iCell)*h(k-1,iCell) &amp;
+                               + rho(k  ,iCell)*h(k  ,iCell))
            end do
 
+           ! Compute zMid, the z-coordinate of the middle of the layer.
+           ! This is used for the rho g grad z momentum term.
+           k = maxLevelCell(iCell)
+           zMid(k:nVertLevels,iCell) = zTopZLevel(k+1) + 0.5*h(k,iCell)
+
+           do k=maxLevelCell(iCell)-1, 1, -1
+              zMid(k,iCell) = zMid(k+1,iCell)  &amp;
+                + 0.5*(  h(k+1,iCell) &amp;
+                       + h(k  ,iCell))
+           end do
+
         end do
 
       endif
 
-      call ocn_wtop(s,grid)
+! mrp 111206 remove
+!      call ocn_wtop(s,grid)
 
+      ! Applications of any bolus-like parametrizations should be made after the next line.
       uTransport(:,:) = u(:,:)
-      ! Apply the GM closure as a bolus velocity 
+
+      ! Apply the GM closure as a bolus velocity
       if(config_h_kappa .GE. epsilon(0D0)) then
          call ocn_gm_compute_uBolus(s,grid)
          uTransport(:,:) = uTransport(:,:) + uBolusGM(:,:)
       end if
 
-      call mpas_timer_stop(&quot;ocn_diagnostic_solve&quot;)
-
    end subroutine ocn_diagnostic_solve!}}}
 
 !***********************************************************************
@@ -1153,16 +892,16 @@
 
       ! mrp 110512 could clean this out, remove pointers?
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, cov
-      real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, rho0Inv
+      real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, rho0Inv, hSum
 
       integer :: nCells, nEdges, nVertices, nVertLevels, vertexDegree
 
 
       real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        hZLevel
-      real (kind=RKIND), dimension(:,:), pointer :: u,wTop
-      real (kind=RKIND), dimension(:,:), allocatable:: div_u
+        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle
+      real (kind=RKIND), dimension(:,:), pointer :: u,h,wTop, h_edge
+      real (kind=RKIND), dimension(:,:), allocatable:: div_hu
+      real (kind=RKIND), dimension(:), allocatable:: div_hu_btr, h_tend_col, h_weights
 
       integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnVertex, &amp;
         verticesOnEdge, edgesOnCell, edgesOnEdge, edgesOnVertex, &amp;
@@ -1171,14 +910,13 @@
         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
+      h_edge      =&gt; s % h_edge % array
 
       areaCell          =&gt; grid % areaCell % array
       cellsOnEdge       =&gt; grid % cellsOnEdge % array
-      hZLevel           =&gt; grid % hZLevel % array
       maxLevelCell      =&gt; grid % maxLevelCell % array
       maxLevelEdgeBot   =&gt; grid % maxLevelEdgeBot % array
       dvEdge            =&gt; grid % dvEdge % array
@@ -1187,46 +925,128 @@
       nEdges      = grid % nEdges
       nVertLevels = grid % nVertLevels
 
+      allocate(div_hu(nVertLevels,nCells+1), div_hu_btr(nCells+1), &amp;
+          h_tend_col(nVertLevels), h_weights(nVertLevels))
+
       !
+      ! Compute div(h^{edge} u) for each cell
+      ! See Ringler et al. (2010) jcp paper, eqn 19, 21, and fig. 3.
+      !
+      div_hu(:,:) = 0.0
+      do iEdge=1,nEdges
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,iEdge)
+         do k=1,maxLevelEdgeBot(iEdge)
+            flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge) 
+            div_hu(k,cell1) = div_hu(k,cell1) + flux
+            div_hu(k,cell2) = div_hu(k,cell2) - flux
+         end do 
+      end do 
+
+      do iCell=1,nCells
+         div_hu_btr(iCell) = 0.0
+         do k=1,maxLevelCell(iCell)
+            div_hu(k,iCell) = div_hu(k,iCell) / areaCell(iCell)
+            div_hu_btr(iCell) = div_hu_btr(iCell) + div_hu(k,iCell)
+         end do
+      end do
+
+      !
       ! 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  
 
       elseif (config_vert_grid_type.eq.'zlevel') then
 
-        !
-        ! Compute div(u) for each cell
-        ! See Ringler et al. (2010) jcp paper, eqn 19, 21, and fig. 3.
-        !
-        allocate(div_u(nVertLevels,nCells+1))
-        div_u(:,:) = 0.0
-        do iEdge=1,nEdges
-           cell1 = cellsOnEdge(1,iEdge)
-           cell2 = cellsOnEdge(2,iEdge)
-           do k=2,maxLevelEdgeBot(iEdge)
-              flux = u(k,iEdge) * dvEdge(iEdge) 
-              div_u(k,cell1) = div_u(k,cell1) + flux
-              div_u(k,cell2) = div_u(k,cell2) - flux
-           end do 
-        end do 
+        do iCell=1,nCells
+           ! Vertical velocity through layer interface at top and 
+           ! 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)
+           end do
+        end do
 
+      elseif (config_vert_grid_type.eq.'zstar1') then
+
+        ! This is a testing setting.  The computation is similar to zstar,
+        ! but the weights are all in the top layer, so is a bit-for-bit 
+        ! match with zlevel.
+
         do iCell=1,nCells
+
+           h_tend_col = 0.0
+           h_tend_col(1) = - div_hu_btr(iCell)
+
            ! Vertical velocity through layer interface at top and 
            ! 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) &amp;
-                 - div_u(k,iCell)/areaCell(iCell)*hZLevel(k)
+              wTop(k,iCell) = wTop(k+1,iCell) - div_hu(k,iCell) - h_tend_col(k)
            end do
         end do
-        deallocate(div_u)
 
+      elseif (config_vert_grid_type.eq.'zstar') then
+
+        ! Distribute the change in total column height due to the external
+        ! mode, div_hu_btr, among all the layers.  Distribute in proportion
+        ! to the layer thickness.
+
+        do iCell=1,nCells
+
+           hSum = 0.0
+           do k=1,maxLevelCell(iCell)
+              h_tend_col(k) = - h(k,iCell)*div_hu_btr(iCell)
+              hSum = hSum + h(k,iCell)
+           end do
+           h_tend_col = h_tend_col / hSum
+
+           ! Vertical velocity through layer interface at top and 
+           ! 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
+        end do
+
+      elseif (config_vert_grid_type.eq.'zstarWeights') then
+
+        ! This is a test with other weights, not meant to be permanent.
+
+        h_weights = 0.0
+        h_weights(1:5) = 1.0
+        do k=1,10
+           h_weights(5+k) = 1.0-k*0.1
+        end do
+
+        do iCell=1,nCells
+
+           hSum = 0.0
+           do k=1,maxLevelCell(iCell)
+              h_tend_col(k) = - h_weights(k)*h(k,iCell)*div_hu_btr(iCell)
+              hSum = hSum + h_weights(k)*h(k,iCell)
+           end do
+           h_tend_col = h_tend_col / hSum
+
+           ! Vertical velocity through layer interface at top and 
+           ! 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
+        end do
+
       endif
 
-      call mpas_timer_stop(&quot;wTop&quot;)
+      deallocate(div_hu, div_hu_btr, h_tend_col, h_weights)
 
    end subroutine ocn_wtop!}}}
 
@@ -1260,88 +1080,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)
 
@@ -1361,7 +1128,71 @@
 
 
 !***********************************************************************
+!
+!  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
 
 !|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tendency.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tendency.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tendency.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tendency.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tendency.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tendency.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tendency.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tendency.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tendency.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tendency.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tendency.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tendency.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tendency.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tendency.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_hadv.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_hadv.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_hadv.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -104,10 +104,10 @@
       integer :: iEdge, nEdges, cell1, cell2, nVertLevels, k
       integer :: iCell, nCells
 
-      integer, dimension(:), pointer :: maxLevelEdgeTop
+      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
 
       !-----------------------------------------------------------------
@@ -124,46 +124,27 @@
       nCells = grid % nCells
       nVertLevels = grid % nVertLevels
 
-      maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      maxLevelCell      =&gt; grid % maxLevelCell % array
+      maxLevelEdgeBot   =&gt; grid % maxLevelEdgeBot % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       dvEdge =&gt; grid % dvEdge % array
       areaCell =&gt; grid % areaCell % array
 
-      if (config_vert_grid_type.eq.'isopycnal') then

-         do iEdge=1,nEdges
-            cell1 = cellsOnEdge(1,iEdge)
-            cell2 = cellsOnEdge(2,iEdge)
-            do k=1,nVertLevels
-               flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge)
-               tend(k,cell1) = tend(k,cell1) - flux
-               tend(k,cell2) = tend(k,cell2) + flux
-            end do
+      do iEdge=1,nEdges
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,iEdge)
+         do k=1,maxLevelEdgeBot(iEdge)
+            flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge)
+            tend(k,cell1) = tend(k,cell1) - flux 
+            tend(k,cell2) = tend(k,cell2) + flux 
          end do
-         do iCell=1,nCells
-            do k=1,nVertLevels
-               tend(k,iCell) = tend(k,iCell) / areaCell(iCell)
-            end do
+      end do
+      do iCell=1,nCells
+         do k=1,maxLevelCell(iCell)
+            tend(k,iCell) = tend(k,iCell) / areaCell(iCell)
          end do
+      end do
 
-      elseif (config_vert_grid_type.eq.'zlevel') then
-
-         do iEdge=1,nEdges
-            cell1 = cellsOnEdge(1,iEdge)
-            cell2 = cellsOnEdge(2,iEdge)
-            do k=1,min(1,maxLevelEdgeTop(iEdge))
-               flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge)
-               tend(k,cell1) = tend(k,cell1) - flux
-               tend(k,cell2) = tend(k,cell2) + flux
-            end do
-         end do
-         do iCell=1,nCells
-           tend(1,iCell) = tend(1,iCell) / areaCell(iCell)
-         end do
-
-      endif ! config_vert_grid_type
-
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_thick_hadv_tend!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_hadv.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_thick_hadv.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_thick_hadv.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_thick_hadv.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_thick_hadv.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_thick_hadv.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_thick_hadv.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_thick_hadv.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_thick_hadv.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_thick_hadv.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_thick_hadv.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_thick_hadv.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_thick_hadv.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_thick_hadv.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_vadv.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_vadv.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_vadv.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -98,7 +98,8 @@
       !
       !-----------------------------------------------------------------
 
-      integer :: iCell, nCells
+      integer :: iCell, nCells, nVertLevels, k
+      integer, dimension(:), pointer :: MaxLevelCell
 
       !-----------------------------------------------------------------
       !
@@ -110,15 +111,17 @@
 
       err = 0
 
+      maxLevelCell      =&gt; grid % maxLevelCell % array
+
       nCells = grid % nCells
+      nVertLevels = grid % nVertLevels
 
-      if (config_vert_grid_type.eq.'zlevel') then
-        do iCell=1,nCells
-           tend(1,iCell) =   tend(1,iCell) + wTop(2,iCell)
-        end do
-      endif ! coordinate type
+      do iCell=1,nCells
+         do k=1,maxLevelCell(iCell)
+            tend(k,iCell) = tend(k,iCell) + wTop(k+1,iCell) - wTop(k,iCell)
+         end do
+      end do
 
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_thick_vadv_tend!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_thick_vadv.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_thick_vadv.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_thick_vadv.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_thick_vadv.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_thick_vadv.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_thick_vadv.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_thick_vadv.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_thick_vadv.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_thick_vadv.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_thick_vadv.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_thick_vadv.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_thick_vadv.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_thick_vadv.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_thick_vadv.F:1213-1453

Copied: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_average.F (from rev 1453, trunk/mpas/src/core_ocean/mpas_ocn_time_average.F)
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_average.F                                (rev 0)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_average.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_time_integration.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_time_integration.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_time_integration.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_time_integration.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_time_integration.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_time_integration.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_time_integration.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_time_integration.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_time_integration.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_time_integration.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_time_integration.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_rk4.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_rk4.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_rk4.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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
@@ -165,6 +166,10 @@
         call mpas_timer_start(&quot;RK4-tendency computations&quot;)
         block =&gt; domain % blocklist
         do while (associated(block))
+
+           ! mrp 111206 put ocn_wtop call at top for ALE
+           call ocn_wtop(provis, block % mesh)
+
            if (.not.config_implicit_vertical_mix) then
               call ocn_vmix_coefs(block % mesh, provis, block % diagnostics, err)
            end if
@@ -178,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;)
@@ -295,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)
 
@@ -316,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
@@ -355,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;)
@@ -388,8 +370,8 @@
       integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve
       real (kind=RKIND) :: vertSum, uhSum, hSum, sshEdge
       real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel, meshScalingDel2, meshScalingDel4
+        h_s, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
+        meshScalingDel2, meshScalingDel4
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
         weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, pressure, &amp;
         tend_u, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
@@ -444,11 +426,6 @@
       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
@@ -465,15 +442,12 @@
 
            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)
+              uhSum = (h_edge(1,iEdge)) * tend_u(1,iEdge)
+              hSum  =  h_edge(1,iEdge)
 
               do k=2,grid % maxLevelEdgeTop % array(iEdge)
-                 uhSum = uhSum + grid % hZLevel % array(k) * tend_u(k,iEdge)
-                 hSum  =  hSum + grid % hZLevel % array(k)
+                 uhSum = uhSum + h_edge(k,iEdge) * tend_u(k,iEdge)
+                 hSum  =  hSum + h_edge(k,iEdge)
               enddo
 
               vertSum = uhSum/hSum
@@ -511,8 +485,8 @@
       integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve
       real (kind=RKIND) :: vertSum, uhSum, hSum, sshEdge
       real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel, meshScalingDel2, meshScalingDel4
+        h_s, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
+        meshScalingDel2, meshScalingDel4
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
         weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, pressure, &amp;
         tend_u, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
@@ -566,11 +540,6 @@
       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
@@ -585,15 +554,12 @@
 
            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)
+              uhSum = (h_edge(1,iEdge)) * u(1,iEdge)
+              hSum  =  h_edge(1,iEdge)
 
               do k=2,grid % maxLevelEdgeTop % array(iEdge)
-                 uhSum = uhSum + grid % hZLevel % array(k) * u(k,iEdge)
-                 hSum  =  hSum + grid % hZLevel % array(k)
+                 uhSum = uhSum + h_edge(k,iEdge) * u(k,iEdge)
+                 hSum  =  hSum + h_edge(k,iEdge)
               enddo
 
               vertSum = uhSum/hSum
@@ -607,51 +573,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


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_rk4.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_time_integration_rk4.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_rk4.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_time_integration_rk4.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_time_integration_rk4.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_rk4.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_time_integration_rk4.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_time_integration_rk4.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_time_integration_rk4.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_time_integration_rk4.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_time_integration_rk4.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_time_integration_rk4.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_time_integration_rk4.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_time_integration_rk4.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_split.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_split.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_split.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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,760 @@
       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
+                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;
+                     + block % state % time_levs(2) % state % uBcl % array(k,iEdge) 
+                end do
+                do k=block % mesh % maxLevelEdgeTop % array(iEdge)+1,block % mesh % nVertLevels
+                   block % state % time_levs(2) % state % u % array(k,iEdge) = 0.0
+                end do
+            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 +927,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
+        call ocn_diagnostic_solve(dt, block % state % time_levs(2) % state, block % mesh)
 
-            !
-            !  Implicit vertical solve for tracers
-            !
-            call ocn_tracer_vmix_tend_implicit(block % mesh, dt, vertdifftopofcell, h, tracers, err)
-         end if
+        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)
 
-         ! mrp 110725 adding momentum decay term
-         if (config_mom_decay) then
+        call ocn_time_average_accumulate(block % state % time_levs(2) % state, block % state % time_levs(1) % state)
 
-            !
-            !  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
 
-         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
@@ -1282,8 +1059,8 @@
       integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve
       real (kind=RKIND) :: vertSum, uhSum, hSum, sshEdge
       real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel, meshScalingDel2, meshScalingDel4
+        h_s, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
+        meshScalingDel2, meshScalingDel4
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
         weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, pressure, &amp;
         tend_u, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
@@ -1338,11 +1115,6 @@
       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
@@ -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!}}}
@@ -1405,8 +1174,8 @@
       integer :: nCells, nEdges, nVertices, nVertLevels, nEdgesSolve
       real (kind=RKIND) :: vertSum, uhSum, hSum, sshEdge
       real (kind=RKIND), dimension(:), pointer :: &amp;
-        h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
-        zMidZLevel, zTopZLevel, meshScalingDel2, meshScalingDel4
+        h_s, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
+        meshScalingDel2, meshScalingDel4
       real (kind=RKIND), dimension(:,:), pointer :: &amp;
         weightsOnEdge, kiteAreasOnVertex, h_edge, h, u, v, pressure, &amp;
         tend_u, circulation, vorticity, ke, ke_edge, pv_edge, &amp;
@@ -1460,11 +1229,6 @@
       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
@@ -1477,75 +1241,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


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_time_integration_split.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_time_integration_split.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_time_integration_split.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_time_integration_split.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_time_integration_split.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_time_integration_split.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_time_integration_split.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_time_integration_split.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_time_integration_split.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_time_integration_split.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_time_integration_split.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_time_integration_split.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_time_integration_split.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_time_integration_split.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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))
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hadv.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hadv.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hadv.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hadv.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hadv.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hadv.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hadv.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hadv.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hadv.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hadv.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hadv.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hadv.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv2.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv2.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv2.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -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
 
@@ -127,8 +126,6 @@
 
       if(.not.hadv2On) 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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv2.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hadv2.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv2.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hadv2.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hadv2.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hadv2.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hadv2.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hadv2.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hadv2.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hadv2.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hadv2.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hadv2.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hadv2.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hadv2.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv3.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv3.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv3.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -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
@@ -134,7 +135,7 @@
       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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv3.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hadv3.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv3.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hadv3.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hadv3.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hadv3.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hadv3.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hadv3.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hadv3.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hadv3.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hadv3.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hadv3.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hadv3.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hadv3.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv4.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv4.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv4.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -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
@@ -131,7 +131,8 @@
       nEdges = grid % nEdges
       num_tracers = size(tracers, dim=1)
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
-      boundaryCell =&gt; grid % boundaryCell % array
+      nEdgesOnCell =&gt; 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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hadv4.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hadv4.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hadv4.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hadv4.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hadv4.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hadv4.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hadv4.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hadv4.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hadv4.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hadv4.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hadv4.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hadv4.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hadv4.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hadv4.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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)
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hmix.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hmix.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hmix.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hmix.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hmix.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hmix.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hmix.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hmix.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hmix.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hmix.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hmix.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hmix.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del2.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del2.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del2.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -18,7 +18,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -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
@@ -134,15 +133,13 @@
 
       if (.not.del2On) 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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del2.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hmix_del2.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del4.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del4.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del4.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -18,7 +18,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -45,7 +44,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: Del4On
+   logical :: del4On
 
    real (kind=RKIND) :: eddyDiff4
 
@@ -111,12 +110,10 @@
       integer :: iEdge, nEdges, num_tracers, nVertLevels, nCells
       integer :: iTracer, k, iCell, cell1, cell2
 
-      integer, dimension(:,:), allocatable :: boundaryMask
-
       integer, dimension(:), pointer :: maxLevelEdgeTop, maxLevelCell
-      integer, dimension(:,:), pointer :: boundaryEdge, cellsOnEdge
+      integer, dimension(:,:), pointer :: edgeMask, cellsOnEdge
 
-      real (kind=RKIND) :: invAreaCell1, invAreaCell2, r, tracer_turb_flux, flux
+      real (kind=RKIND) :: invAreaCell1, invAreaCell2, tracer_turb_flux, flux, invdcEdge, r_tmp1, r_tmp2
 
       real (kind=RKIND), dimension(:,:,:), allocatable :: delsq_tracer
 
@@ -133,10 +130,8 @@
 
       err = 0
 
-      if (.not.Del4On) return
+      if (.not.del4On) 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)
@@ -144,7 +139,6 @@
 
       maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
       maxLevelCell =&gt; grid % maxLevelCell % array
-      boundaryEdge =&gt; grid % boundaryEdge % array
       cellsOnEdge =&gt; grid % cellsOnEdge % array
 
       dcEdge =&gt; grid % dcEdge % array
@@ -152,68 +146,61 @@
       areaCell =&gt; grid % areaCell % array
       meshScalingDel4 =&gt; grid % meshScalingDel4 % array
 
-      allocate(boundaryMask(nVertLevels, nEdges+1))
-      boundaryMask = 1.0
-      where(boundaryEdge.eq.1) boundaryMask=0.0
+      edgeMask =&gt; grid % edgeMask % array
 
       allocate(delsq_tracer(num_tracers,nVertLevels, nCells+1))
 
-      delsq_tracer(:,:,:) = 0.
+      delsq_tracer(:,:,:) = 0.0
 
       ! first del2: div(h </font>
<font color="red">abla \phi) at cell center
       do iEdge=1,nEdges
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
 
+         invdcEdge = 1.0 / dcEdge(iEdge)
+
+         invAreaCell1 = 1.0 / areaCell(cell1)
+         invAreaCell2 = 1.0 / areaCell(cell2)
+
          do k=1,maxLevelEdgeTop(iEdge)
-           do iTracer=1,num_tracers
-              delsq_tracer(iTracer,k,cell1) = delsq_tracer(iTracer,k,cell1) &amp;
-                 + dvEdge(iEdge)*h_edge(k,iEdge) &amp;
-                   *(tracers(iTracer,k,cell2) - tracers(iTracer,k,cell1)) &amp;
-                   /dcEdge(iEdge) * boundaryMask(k,iEdge)
-              delsq_tracer(iTracer,k,cell2) = delsq_tracer(iTracer,k,cell2) &amp;
-                 - dvEdge(iEdge)*h_edge(k,iEdge) &amp;
-                 *(tracers(iTracer,k,cell2) - tracers(iTracer,k,cell1)) &amp;
-                 /dcEdge(iEdge) * boundaryMask(k,iEdge)
+           do iTracer=1,num_tracers * edgeMask(k, iEdge)
+
+              r_tmp1 = dvEdge(iEdge) * h_edge(k,iEdge) * invdcEdge
+
+              r_tmp2 = r_tmp1 * tracers(iTracer,k,cell2)
+              r_tmp1 = r_tmp1 * tracers(iTracer,k,cell1)
+
+              delsq_tracer(iTracer,k,cell1) = delsq_tracer(iTracer,k,cell1) + (r_tmp2 - r_tmp1) * invAreaCell1
+              delsq_tracer(iTracer,k,cell2) = delsq_tracer(iTracer,k,cell2) - (r_tmp2 - r_tmp1) * invAreaCell2
            end do
          end do
       end do
 
-      do iCell = 1,nCells
-         r = 1.0 / areaCell(iCell)
-         do k=1,maxLevelCell(iCell)
-            do iTracer=1,num_tracers
-               delsq_tracer(iTracer,k,iCell) = delsq_tracer(iTracer,k,iCell) * r
-            end do
-         end do
-      end do
-
       ! second del2: div(h </font>
<font color="gray">abla [delsq_tracer]) at cell center
       do iEdge=1,grid % nEdges
          cell1 = grid % cellsOnEdge % array(1,iEdge)
          cell2 = grid % cellsOnEdge % array(2,iEdge)
+
          invAreaCell1 = 1.0 / areaCell(cell1)
          invAreaCell2 = 1.0 / areaCell(cell2)
 
+         invdcEdge = 1.0 / dcEdge(iEdge)
+
          do k=1,maxLevelEdgeTop(iEdge)
-            do iTracer=1,num_tracers
+            do iTracer=1,num_tracers * edgeMask(k,iEdge)
                tracer_turb_flux = meshScalingDel4(iEdge) * eddyDiff4 &amp;
-                  *(  delsq_tracer(iTracer,k,cell2)  &amp;
-                    - delsq_tracer(iTracer,k,cell1))/dcEdge(iEdge)
+                  * (delsq_tracer(iTracer,k,cell2) - delsq_tracer(iTracer,k,cell1)) &amp;
+                  * invdcEdge
+
                flux = dvEdge (iEdge) * tracer_turb_flux
 
-               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) &amp; 
-                  - flux * invAreaCell1 * boundaryMask(k,iEdge)
-               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) &amp;
-                  + flux * invAreaCell2 * boundaryMask(k,iEdge)
-
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux * invAreaCell1
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux * invAreaCell2
             enddo
          enddo
       end do
 
       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 +232,10 @@
       integer, intent(out) :: err !&lt; Output: error flag
 
       err = 0
-      Del4on = .false.
+      del4on = .false.
 
       if ( config_h_tracer_eddy_diff4 &gt; 0.0 ) then
-          Del4On = .true.
+          del4On = .true.
           eddyDiff4 = config_h_tracer_eddy_diff4
       endif
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_hmix_del4.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_hmix_del4.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -70,7 +70,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -79,6 +79,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -124,8 +125,8 @@
 
       if(.not.vadvOn) return
 
-      call ocn_tracer_vadv_stencil_tend(grid, wTop, tracers, tend, err1)
-      call ocn_tracer_vadv_spline_tend(grid, wTop, tracers, tend, err2)
+      call ocn_tracer_vadv_stencil_tend(grid, h, wTop, tracers, tend, err1)
+      call ocn_tracer_vadv_spline_tend(grid, h, wTop, tracers, tend, err2)
 
       err = ior(err1, err2)
 
@@ -166,7 +167,7 @@
       err = 0
       vadvOn = .false.
 
-      if (config_vert_grid_type.eq.'zlevel') then
+      if (config_vert_grid_type.ne.'isopycnal') then
           vadvOn = .true.
           call ocn_tracer_vadv_stencil_init(err1)
           call ocn_tracer_vadv_spline_init(err2)


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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,6 +46,7 @@
    !
    !--------------------------------------------------------------------
 
+   type (timer_node), pointer :: spline2_timer, spline3_timer
    logical :: splineOn
 
 
@@ -70,7 +72,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_spline_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_spline_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -79,6 +81,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -124,9 +127,14 @@
 
       if(.not.splineOn) return
 
-      call ocn_tracer_vadv_spline2_tend(grid, wTop, tracers, tend, err1)
-      call ocn_tracer_vadv_spline3_tend(grid, wTop, tracers, tend, err2)
+      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)
 
    !--------------------------------------------------------------------


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_spline.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -64,7 +63,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_spline2_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_spline2_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -73,6 +72,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -108,8 +108,6 @@
 
       integer, dimension(:), pointer :: maxLevelCell
 
-      real (kind=RKIND), dimension(:), pointer :: hRatioZLevelK, hRatioZLevelKm1
-
       real (kind=RKIND), dimension(:,:,:), allocatable :: tracerTop
 
       !-----------------------------------------------------------------
@@ -125,28 +123,24 @@
       if(.not.spline2On) 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
       num_tracers = size(tracers, 1)
       maxLevelCell =&gt; grid % maxLevelCell % array
 
-      hRatioZLevelK =&gt; grid % hRatioZLevelK % array
-      hRatioZLevelKm1 =&gt; grid % hRatioZLevelKm1 % array
-
       allocate(tracerTop(num_tracers,nVertLevels+1,nCells))
 
       do iCell=1,nCellsSolve 
          tracerTop(:,1,iCell) = tracers(:,1,iCell) 
          do k=2,maxLevelCell(iCell)
             do iTracer=1,num_tracers
-               ! Note hRatio on the k side is multiplied by tracer at k-1
-               ! and hRatio on the Km1 (k-1) side is mult. by tracer at k.
+               ! Note h on the k side is multiplied by tracer at k-1
+               ! and h on the Km1 (k-1) side is mult. by tracer at k.
                tracerTop(iTracer,k,iCell) = &amp;
-                    hRatioZLevelK(k)  *tracers(iTracer,k-1,iCell) &amp;
-                  + hRatioZLevelKm1(k)*tracers(iTracer,k  ,iCell)
+                  (  h(k  ,iCell)*tracers(iTracer,k-1,iCell) &amp;
+                   + h(k-1,iCell)*tracers(iTracer,k  ,iCell) ) &amp;
+                  / (h(k-1,iCell) + h(k,iCell))   
             end do
          end do
          tracerTop(:,maxLevelCell(iCell)+1,iCell) = tracers(:,maxLevelCell(iCell),iCell)
@@ -163,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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_spline2.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
    use mpas_spline_interpolation
 
    implicit none
@@ -65,7 +64,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_spline3_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_spline3_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -74,6 +73,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -109,11 +109,8 @@
 
       integer, dimension(:), pointer :: maxLevelCell
 
-      real (kind=RKIND), dimension(:), pointer :: hRatioZLevelK, &amp;
-            hRatioZLevelKm1, zTopZLevel, zMidZLevel
-
       real (kind=RKIND), dimension(:), allocatable :: tracer2ndDer,  &amp;
-            tracersIn, tracersOut, posZMidZLevel, posZTopZLevel
+            tracersIn, tracersOut, depthTop, depthMid
       real (kind=RKIND), dimension(:,:,:), allocatable :: tracerTop
 
       !-----------------------------------------------------------------
@@ -129,34 +126,30 @@
       if(.not.spline3On) 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
       num_tracers = size(tracers, 1)
       maxLevelCell =&gt; grid % maxLevelCell % array
 
-      hRatioZLevelK =&gt; grid % hRatioZLevelK % array
-      hRatioZLevelKm1 =&gt; grid % hRatioZLevelKm1 % array
-      zMidZLevel =&gt; grid % zMidZLevel % array
-      zTopZLevel =&gt; grid % zTopZLevel % array
-
       allocate(tracerTop(num_tracers,nVertLevels+1,nCells))
 
       ! Compute tracerTop using cubic spline interpolation.
 
       allocate(tracer2ndDer(nVertLevels))
       allocate(tracersIn(nVertLevels),tracersOut(nVertLevels), &amp;
-            posZMidZLevel(nVertLevels), posZTopZLevel(nVertLevels-1))
+            depthMid(nVertLevels), depthTop(nVertLevels+1))
 
-      ! For the ocean, zlevel coordinates are negative and decreasing, 
-      ! but spline functions assume increasing, so flip to positive.
+      do iCell=1,nCellsSolve 
 
-      posZMidZLevel = -zMidZLevel(1:nVertLevels)
-      posZTopZLevel = -zTopZLevel(2:nVertLevels)
+         ! Here depth considers SSH to be depth=0.  We don't need to 
+         ! have true z-coordinate depths because it is just for interpolation.
+         depthTop(1) = 0.0
+         do k=1,maxLevelCell(iCell)
+            depthMid(k  ) = depthTop(k) + 0.5*h(k,iCell)
+            depthTop(k+1) = depthTop(k) +     h(k,iCell)
+         enddo
 
-      do iCell=1,nCellsSolve 
          ! mrp 110201 efficiency note: push tracer loop down
          ! into spline subroutines to improve efficiency
          do iTracer=1,num_tracers
@@ -165,12 +158,12 @@
             ! subroutine call.  
             tracersIn(1:maxLevelCell(iCell))=tracers(iTracer,1:maxLevelCell(iCell),iCell)
 
-            call mpas_cubic_spline_coefficients(posZMidZLevel, &amp;
+            call mpas_cubic_spline_coefficients(depthMid, &amp;
                tracersIn, maxLevelCell(iCell), tracer2ndDer)
 
             call mpas_interpolate_cubic_spline( &amp;
-               posZMidZLevel, tracersIn, tracer2ndDer, maxLevelCell(iCell), &amp;
-               posZTopZLevel, tracersOut, maxLevelCell(iCell)-1 )
+               depthMid, tracersIn, tracer2ndDer, maxLevelCell(iCell), &amp;
+               depthTop(2:maxLevelCell(iCell)), tracersOut, maxLevelCell(iCell)-1 )
 
             tracerTop(itracer,1,iCell) = tracers(iTracer,1,iCell)
             tracerTop(iTracer,2:maxLevelCell(iCell),iCell) = tracersOut(1:maxLevelCell(iCell)-1)
@@ -189,10 +182,8 @@
       end do
 
       deallocate(tracer2ndDer)
-      deallocate(tracersIn,tracersOut, posZMidZLevel, posZTopZLevel)
+      deallocate(tracersIn,tracersOut, depthMid, depthTop)
       deallocate(tracerTop)
-
-      call mpas_timer_stop(&quot;compute_scalar_tend-vert adv spline 3&quot;)
    !--------------------------------------------------------------------
 
    end subroutine ocn_tracer_vadv_spline3_tend!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_spline3.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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,6 +47,8 @@
    !
    !--------------------------------------------------------------------
 
+   type (timer_node), pointer :: stencil2_timer, stencil3_timer, stencil4_timer
+
    logical :: stencilOn
 
 
@@ -71,7 +74,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_stencil_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_stencil_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -80,6 +83,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -125,9 +129,15 @@
 
       if(.not. stencilOn) return
 
+      call mpas_timer_start(&quot;stencil 2&quot;, .false., stencil2_timer)
       call ocn_tracer_vadv_stencil2_tend(grid, wTop, tracers, tend, err1)
-      call ocn_tracer_vadv_stencil3_tend(grid, wTop, tracers, tend, err2)
-      call ocn_tracer_vadv_stencil4_tend(grid, wTop, tracers, tend, err3)
+      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))
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_stencil.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -122,11 +121,8 @@
 
       err = 0
 
-      if(.not. stencil2On) return
+      if(.not.stencil2On) 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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_stencil2.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -64,7 +63,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_stencil3_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_stencil3_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -73,6 +72,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -110,7 +110,6 @@
       integer, dimension(:), pointer :: maxLevelCell
 
       real (kind=RKIND) :: cSignWTop, flux3Coef
-      real (kind=RKIND), dimension(:), pointer :: hRatioZLevelK, hRatioZLevelKm1
       real (kind=RKIND), dimension(:,:,:), allocatable :: tracerTop
 
 
@@ -124,18 +123,14 @@
 
       err = 0
 
-      if(.not. stencil3On) return
+      if(.not.stencil3On) return
 
       nCells = grid % nCells
       nCellsSolve = grid % nCellsSolve
       num_tracers = size(tracers, 1)
       nVertLevels = grid % nVertLevels
       maxLevelCell =&gt; grid % maxLevelCell % array
-      hRatioZLevelK =&gt; grid % hRatioZLevelK % array
-      hRatioZLevelKm1 =&gt; grid % hRatioZLevelKm1 % 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
@@ -148,9 +143,10 @@
          tracerTop(:,1,iCell) = tracers(:,1,iCell)
          k=2
          do iTracer=1,num_tracers
-           tracerTop(iTracer,k,iCell) = &amp;
-                hRatioZLevelK(k)  *tracers(iTracer,k-1,iCell) &amp;
-              + hRatioZLevelKm1(k)*tracers(iTracer,k  ,iCell)
+            tracerTop(iTracer,k,iCell) = &amp;
+               (  h(k,iCell)*tracers(iTracer,k-1,iCell) &amp;
+                + h(k-1,iCell)*tracers(iTracer,k  ,iCell) ) &amp;
+               / (h(k-1,iCell) + h(k,iCell))   
          end do
          do k=3,maxLevelCell(iCell)-1
             cSignWTop = sign(flux3Coef,wTop(k,iCell))
@@ -165,9 +161,10 @@
          end do
          k=maxLevelCell(iCell)
             do iTracer=1,num_tracers
-              tracerTop(iTracer,k,iCell) = &amp;
-                   hRatioZLevelK(k)  *tracers(iTracer,k-1,iCell) &amp;
-                 + hRatioZLevelKm1(k)*tracers(iTracer,k  ,iCell)
+            tracerTop(iTracer,k,iCell) = &amp;
+               (  h(k,iCell)*tracers(iTracer,k-1,iCell) &amp;
+                + h(k-1,iCell)*tracers(iTracer,k  ,iCell) ) &amp;
+               / (h(k-1,iCell) + h(k,iCell))   
             end do
         tracerTop(:,maxLevelCell(iCell)+1,iCell) = tracers(:,maxLevelCell(iCell),iCell)
       end do
@@ -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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_stencil3.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -64,7 +63,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_tracer_vadv_stencil4_tend(grid, wTop, tracers, tend, err)!{{{
+   subroutine ocn_tracer_vadv_stencil4_tend(grid, h, wTop, tracers, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -73,6 +72,7 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h, &amp;    !&lt; Input: layer thickness
          wTop    !&lt; Input: vertical tracer in top layer
 
       real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
@@ -110,7 +110,6 @@
       integer, dimension(:), pointer :: maxLevelCell
 
       real (kind=RKIND) :: cSingWTop, flux3Coef
-      real (kind=RKIND), dimension(:), pointer :: hRatioZLevelK, hRatioZLevelKm1
       real (kind=RKIND), dimension(:,:,:), allocatable :: tracerTop
 
 
@@ -124,17 +123,13 @@
 
       err = 0
 
-      if(.not. Stencil4On) return
+      if(.not.Stencil4On) 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)
       nVertLevels = grid % nVertLevels
       maxLevelCell =&gt; grid % maxLevelCell % array
-      hRatioZLevelK =&gt; grid % hRatioZLevelK % array
-      hRatioZLevelKm1 =&gt; grid % hRatioZLevelKm1 % array
 
       allocate(tracerTop(num_tracers,nVertLevels+1,nCells))
 
@@ -144,9 +139,10 @@
          tracerTop(:,1,iCell) = tracers(:,1,iCell)
          k=2
             do iTracer=1,num_tracers
-              tracerTop(iTracer,k,iCell) = &amp;
-                   hRatioZLevelK(k)  *tracers(iTracer,k-1,iCell) &amp;
-                 + hRatioZLevelKm1(k)*tracers(iTracer,k  ,iCell)
+               tracerTop(iTracer,k,iCell) = &amp;
+                  (  h(k  ,iCell)*tracers(iTracer,k-1,iCell) &amp;
+                   + h(k-1,iCell)*tracers(iTracer,k  ,iCell) ) &amp;
+                  / (h(k-1,iCell) + h(k,iCell))   
             end do
          do k=3,maxLevelCell(iCell)-1
             do iTracer=1,num_tracers
@@ -160,9 +156,10 @@
          end do
          k=maxLevelCell(iCell)
             do iTracer=1,num_tracers
-              tracerTop(iTracer,k,iCell) = &amp;
-                   hRatioZLevelK(k)  *tracers(iTracer,k-1,iCell) &amp;
-                 + hRatioZLevelKm1(k)*tracers(iTracer,k  ,iCell)
+               tracerTop(iTracer,k,iCell) = &amp;
+                  (  h(k  ,iCell)*tracers(iTracer,k-1,iCell) &amp;
+                   + h(k-1,iCell)*tracers(iTracer,k  ,iCell) ) &amp;
+                  / (h(k-1,iCell) + h(k,iCell))   
             end do
         tracerTop(:,maxLevelCell(iCell)+1,iCell) = tracers(:,maxLevelCell(iCell),iCell)
       end do
@@ -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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_tracer_vadv_stencil4.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_coriolis.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_coriolis.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_coriolis.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_coriolis.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_coriolis.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_coriolis.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_coriolis.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_coriolis.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_coriolis.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_coriolis.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_coriolis.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_coriolis.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_coriolis.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_coriolis.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_coriolis.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_coriolis.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_coriolis.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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)
 
    !--------------------------------------------------------------------
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_forcing.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_forcing.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_forcing.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_forcing.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_forcing.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_forcing.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_forcing.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_forcing.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_forcing.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_forcing.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_forcing.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -109,6 +109,7 @@
 
       integer :: iEdge, nEdgesSolve, k
       integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: edgeMask
 
       !-----------------------------------------------------------------
       !
@@ -124,27 +125,18 @@
 
       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
 
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_forcing_bottomdrag.F:1213-1453

Copied: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F (from rev 1453, trunk/mpas/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F)
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F                                (rev 0)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_rayleigh.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -0,0 +1,180 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  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
+
+      !-----------------------------------------------------------------
+      !
+      ! 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
+
+      do iEdge=1,nEdgesSolve
+        do k=1,maxLevelEdgeTop(iEdge)
+
+           tend(k,iEdge) = tend(k,iEdge) - rayleighDampingCoef * u(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/gmvar/src/core_ocean/mpas_ocn_vel_forcing_windstress.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_windstress.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_windstress.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -106,8 +106,8 @@
 
       integer :: iEdge, nEdgesSolve, k
       integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: edgeMask
 
-
       !-----------------------------------------------------------------
       !
       ! call relevant routines for computing tendencies
@@ -122,21 +122,19 @@
 
       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.
       rho_ref = 1000.0
 
       err = 0
 
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_forcing_windstress_init!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_forcing_windstress.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_forcing_windstress.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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)
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_hmix.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_hmix.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_hmix.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_hmix.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_hmix.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_hmix.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_hmix.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_hmix.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_hmix.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_hmix.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_hmix.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_hmix.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del2.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del2.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del2.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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
+   logical ::  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
 
@@ -132,13 +130,12 @@
 
       if(.not.hmixDel2On) 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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del2.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_hmix_del2.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_hmix_del2.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_hmix_del2.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_hmix_del2.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del4.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del4.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del4.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -16,7 +16,6 @@
 
    use mpas_grid_types
    use mpas_configure
-   use mpas_timer
 
    implicit none
    private
@@ -43,8 +42,7 @@
    !
    !--------------------------------------------------------------------
 
-   logical :: &amp;
-      hmixDel4On       !&lt; local flag to determine whether del4 chosen
+   logical :: hmixDel4On       !&lt; local flag to determine whether del4 chosen
 
    real (kind=RKIND) :: &amp;
       eddyVisc4,        &amp;!&lt; base eddy diffusivity for biharmonic
@@ -114,30 +112,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
 
-      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 +148,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!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_hmix_del4.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_hmix_del4.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_hmix_del4.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_hmix_del4.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_hmix_del4.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_pressure_grad.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_pressure_grad.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_pressure_grad.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -17,6 +17,7 @@
 
    use mpas_grid_types
    use mpas_configure
+   use mpas_constants
 
    implicit none
    private
@@ -43,7 +44,7 @@
    !
    !--------------------------------------------------------------------
 
-   real (kind=RKIND) :: rho0Inv
+   real (kind=RKIND) :: rho0Inv, grho0Inv
 
 
 !***********************************************************************
@@ -64,7 +65,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_vel_pressure_grad_tend(grid, pressure, tend, err)!{{{
+   subroutine ocn_vel_pressure_grad_tend(grid, pressure, zMid, rho, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -73,7 +74,9 @@
       !-----------------------------------------------------------------
 
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
-         pressure !&lt; Input: Pressure field or Mongomery potential
+         pressure, &amp; !&lt; Input: Pressure field or Mongomery potential
+         zMid, &amp;     !&lt; Input: z-coordinate at mid-depth of layer
+         rho         !&lt; Input: density
 
       type (mesh_type), intent(in) :: &amp;
          grid          !&lt; Input: grid information
@@ -103,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
 
@@ -113,31 +117,35 @@
       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)
-          do k=1,maxLevelEdgeTop(iEdge)
-             tend(k,iEdge) = tend(k,iEdge)     &amp;
-               - (pressure(k,cell2) - pressure(k,cell1))/dcEdge(iEdge)
-           end do
-        enddo
-      elseif (config_vert_grid_type.eq.'zlevel') then
-        do iEdge=1,nEdgesSolve
-          cell1 = cellsOnEdge(1,iEdge)
-          cell2 = cellsOnEdge(2,iEdge)
-          do k=1,maxLevelEdgeTop(iEdge)
+      ! pressure for generalized coordinates
+      ! -1/rho_0 (grad p_k + rho g grad z_k^{mid})
 
+      ! For pure isopycnal coordinates, we are still using 
+      ! grad(M), the gradient of Montgomery Potential, because
+      ! we have set rho0Inv=1 and grho0Inv=0 in the init routine,
+      ! and pressure is passed in as MontPot.
+
+      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)
-          end do
+              - 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) )* invdcEdge
+                      
+         end do
 
-        enddo
-      endif
+      end do
 
 
+
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_pressure_grad_tend!}}}
@@ -180,10 +188,14 @@
 
       if (config_vert_grid_type.eq.'isopycnal') then
         rho0Inv = 1.0
-      elseif (config_vert_grid_type.eq.'zlevel') then
+        grho0Inv = 0.0
+      else 
         rho0Inv = 1.0/config_rho0
+        grho0Inv = gravity/config_rho0
       end if
 
+
+
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_pressure_grad_init!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_pressure_grad.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_pressure_grad.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_pressure_grad.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_pressure_grad.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_pressure_grad.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_vadv.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_vadv.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_vadv.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -64,7 +64,7 @@
 !
 !-----------------------------------------------------------------------
 
-   subroutine ocn_vel_vadv_tend(grid, u, wTop, tend, err)!{{{
+   subroutine ocn_vel_vadv_tend(grid, u, h_edge, wTop, tend, err)!{{{
 
       !-----------------------------------------------------------------
       !
@@ -75,6 +75,7 @@
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
          u     !&lt; Input: Horizontal velocity
       real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h_edge,&amp;!&lt; Input: thickness at edge
          wTop  !&lt; Input: Vertical velocity on top layer
 
       type (mesh_type), intent(in) :: &amp;
@@ -106,11 +107,10 @@
       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
 
       if(.not.velVadvOn) return
 
@@ -120,7 +120,7 @@
       nEdgesSolve = grid % nEdgesSolve
       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
@@ -134,14 +134,13 @@
 
           ! compute dudz at vertical interface with first order derivative.
           w_dudzTopEdge(k) = wTopEdge * (u(k-1,iEdge)-u(k,iEdge)) &amp;
-                       / (zMidZLevel(k-1) - zMidZLevel(k))
+                       / (0.5*(h_edge(k-1,iEdge) + h_edge(k,iEdge)))
         end do
         w_dudzTopEdge(maxLevelEdgeTop(iEdge)+1) = 0.0
         ! 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)
@@ -179,7 +178,7 @@
       err = 0
       velVadvOn = .false.
 
-      if (config_vert_grid_type.eq.'zlevel') then
+      if (config_vert_grid_type.ne.'isopycnal') then
           velVadvOn = .true.
       end if
 


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vel_vadv.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vel_vadv.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vel_vadv.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vel_vadv.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vel_vadv.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vel_vadv.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vel_vadv.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vel_vadv.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vel_vadv.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vel_vadv.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vel_vadv.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vel_vadv.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vel_vadv.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vel_vadv.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -199,8 +199,6 @@
 
       if(implicitOn) 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!}}}
@@ -319,7 +314,6 @@
          ! mrp 110315 efficiency note: for z-level, could precompute
          ! -2.0*dt/(h(k)_h(k+1))/h(k) in setup
          ! h_edge is computed in compute_solve_diag, and is not available yet.
-         ! This could be removed if hZLevel used instead.
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
          do k=1,maxLevelEdgeTop(iEdge)
@@ -347,6 +341,8 @@
         end if
       end do
 
+      deallocate(A,C,uTemp)
+
    !--------------------------------------------------------------------
 
    end subroutine ocn_vel_vmix_tend_implicit!}}}
@@ -418,8 +414,6 @@
 
       if(implicitOn) 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)
@@ -454,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!}}}
@@ -558,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!}}}
@@ -602,7 +593,7 @@
 
       if(config_implicit_vertical_mix) then
           explicitOn = .false.
-          implicitOn =.true.
+          implicitOn = .true.
       end if
 
       call ocn_vmix_coefs_const_init(err1)


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vmix.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vmix.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vmix.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vmix.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vmix.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vmix.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vmix.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vmix.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vmix.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vmix.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vmix.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vmix.F:1213-1453


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_const.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vmix_coefs_const.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vmix_coefs_const.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vmix_coefs_const.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vmix_coefs_const.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_rich.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_rich.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_rich.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -26,6 +26,8 @@
    private
    save
 
+   type (timer_node), pointer :: richEOSTimer
+
    !--------------------------------------------------------------------
    !
    ! Public parameters
@@ -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)
@@ -440,7 +444,7 @@
 
       err = 0
 
-      if(.not.richViscOn .and. .not.richDiffOn) return
+      if((.not.richViscOn) .and. (.not.richDiffOn)) return
 
       nVertLevels = grid % nVertLevels
       nCells = grid % nCells
@@ -455,8 +459,8 @@
       areaCell =&gt; grid % areaCell % array
 
       allocate( &amp;
-         drhoTopOfCell(nVertLevels+1,nCells+1), drhoTopOfEdge(nVertLevels+1,nEdges+1), &amp;
-         du2TopOfCell(nVertLevels+1,nCells+1), du2TopOfEdge(nVertLevels+1,nEdges+1))
+         drhoTopOfCell(nVertLevels+1,nCells+1), drhoTopOfEdge(nVertLevels+1,nEdges), &amp;
+         du2TopOfCell(nVertLevels+1,nCells+1), du2TopOfEdge(nVertLevels+1,nEdges))
 
       ! compute density of parcel displaced to next deeper z-level,
       ! in state % rhoDisplaced


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_rich.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vmix_coefs_rich.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -186,6 +186,9 @@
       nVertLevels = grid % nVertLevels
       zTopZLevel =&gt; grid % zTopZLevel % array
 
+      ! zTopZLevel is used here for simplicity.  Using zMid and h, which 
+      ! vary in time, would give the exact location of the top, but it
+      ! would only change the diffusion value very slightly.
       do k=1,nVertLevels+1
           vertViscTopOfEdge(k,:) = -(config_max_visc_tanh-config_min_visc_tanh)/2.0 &amp;
             *tanh(-(zTopZLevel(k)-config_ZMid_tanh) &amp;
@@ -255,6 +258,9 @@
       nVertLevels = grid % nVertLevels
       zTopZLevel =&gt; grid % zTopZLevel % array
 
+      ! zTopZLevel is used here for simplicity.  Using zMid and h, which 
+      ! vary in time, would give the exact location of the top, but it
+      ! would only change the diffusion value very slightly.
       do k=1,nVertLevels+1
          vertDiffTopOfCell(k,:) = -(config_max_diff_tanh-config_min_diff_tanh)/2.0 &amp;
             *tanh(-(zTopZLevel(k)-config_ZMid_tanh) &amp;
@@ -308,14 +314,6 @@
           tanhDiffOn = .true.
       endif
 
-      if(tanhViscOn .or. tanhDiffOn) 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'
-            err = 1
-         endif
-      endif
-
    !--------------------------------------------------------------------
 
    end subroutine ocn_vmix_coefs_tanh_init!}}}


Property changes on: branches/ocean_projects/gmvar/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/cam_mpas_nh/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1260-1270
/branches/ocean_projects/ale_vert_coord/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1225-1383
/branches/ocean_projects/ale_vert_coord_new/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1387-1428
/branches/ocean_projects/imp_vert_mix_mrp/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:754-986
/branches/ocean_projects/performance/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1120-1371
/branches/ocean_projects/rayleigh/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1298-1311
/branches/ocean_projects/split_explicit_mrp/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1134-1138
/branches/ocean_projects/split_explicit_timestepping/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1044-1097
/branches/ocean_projects/time_averaging/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1271-1305
/branches/ocean_projects/vert_adv_mrp/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:704-745
/branches/source_renaming/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1082-1113
/branches/time_manager/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:924-962
/trunk/mpas/src/core_ocean/mpas_ocn_vmix_coefs_tanh.F:1213-1453

Modified: branches/ocean_projects/gmvar/src/core_sw/Registry
===================================================================
--- branches/ocean_projects/gmvar/src/core_sw/Registry        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_sw/Registry        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/core_sw/mpas_sw_advection.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_sw/mpas_sw_advection.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_sw/mpas_sw_advection.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/core_sw/mpas_sw_time_integration.F
===================================================================
--- branches/ocean_projects/gmvar/src/core_sw/mpas_sw_time_integration.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/core_sw/mpas_sw_time_integration.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/driver/mpas_subdriver.F
===================================================================
--- branches/ocean_projects/gmvar/src/driver/mpas_subdriver.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/driver/mpas_subdriver.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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)
 

Modified: branches/ocean_projects/gmvar/src/framework/Makefile
===================================================================
--- branches/ocean_projects/gmvar/src/framework/Makefile        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/Makefile        2012-02-02 19:34:14 UTC (rev 1454)
@@ -4,7 +4,8 @@
    ZOLTANOBJ = mpas_zoltan_interface.o
 endif
 
-OBJS = mpas_framework.o \
+OBJS = mpas_kind_types.o \
+       mpas_framework.o \
        mpas_timer.o \
        mpas_timekeeping.o \
        mpas_configure.o \
@@ -28,10 +29,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/gmvar/src/framework/mpas_constants.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_constants.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_constants.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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

Modified: branches/ocean_projects/gmvar/src/framework/mpas_dmpar.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_dmpar.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_dmpar.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/framework/mpas_io_input.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_io_input.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_io_input.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/framework/mpas_io_output.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_io_output.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_io_output.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/framework/mpas_kind_types.F (from rev 1453, trunk/mpas/src/framework/mpas_kind_types.F)
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_kind_types.F                                (rev 0)
+++ branches/ocean_projects/gmvar/src/framework/mpas_kind_types.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/framework/mpas_sort.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_sort.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_sort.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/framework/mpas_timekeeping.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_timekeeping.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_timekeeping.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,5 +1,6 @@
 module mpas_timekeeping
 
+   use mpas_kind_types
    use ESMF_BaseMod
    use ESMF_Stubs
    use ESMF_CalendarMod

Modified: branches/ocean_projects/gmvar/src/framework/mpas_timer.F
===================================================================
--- branches/ocean_projects/gmvar/src/framework/mpas_timer.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/framework/mpas_timer.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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/gmvar/src/operators/mpas_spline_interpolation.F
===================================================================
--- branches/ocean_projects/gmvar/src/operators/mpas_spline_interpolation.F        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/operators/mpas_spline_interpolation.F        2012-02-02 19:34:14 UTC (rev 1454)
@@ -1,5 +1,7 @@
 module mpas_spline_interpolation
 
+  use mpas_kind_types
+
   implicit none
 
   private

Modified: branches/ocean_projects/gmvar/src/registry/parse.c
===================================================================
--- branches/ocean_projects/gmvar/src/registry/parse.c        2012-02-02 18:17:51 UTC (rev 1453)
+++ branches/ocean_projects/gmvar/src/registry/parse.c        2012-02-02 19:34:14 UTC (rev 1454)
@@ -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>