<p><b>duda</b> 2010-10-13 14:25:17 -0600 (Wed, 13 Oct 2010)</p><p>BRANCH COMMIT<br>
<br>
Bring atmos_physics branch up-to-date with respect to atmos_nonhydrostatic branch.<br>
<br>
<br>
A    namelist.input.nhyd_atmos_squall<br>
M    graphics/matlab/MapDataToDx.m<br>
M    graphics/matlab/MapGridToDx.m<br>
A    graphics/ncl/cells_hex.ncl<br>
A    graphics/ncl/cells_nhyd_sphere.ncl<br>
A    graphics/ncl/cells_nhyd_sph1.ncl<br>
A    graphics/ncl/xz_plane.ncl<br>
M    namelist.input.hyd_atmos<br>
M    namelist.input.sw<br>
M    src/core_hyd_atmos/mpas_interface.F<br>
M    src/core_hyd_atmos/module_advection.F<br>
M    src/core_hyd_atmos/module_test_cases.F<br>
M    src/core_hyd_atmos/Registry<br>
M    src/core_hyd_atmos/module_time_integration.F<br>
M    src/core_sw/module_global_diagnostics.F<br>
M    src/core_sw/mpas_interface.F<br>
M    src/core_sw/module_test_cases.F<br>
M    src/core_sw/Registry<br>
M    src/core_sw/module_time_integration.F<br>
M    src/registry/registry_types.h<br>
M    src/registry/gen_inc.c<br>
M    src/registry/gen_inc.h<br>
M    src/registry/parse.c<br>
M    src/core_physics/module_driver_microphysics.F<br>
M    src/core_physics/module_physics_driver.F<br>
M    src/core_physics/module_physics_init.F<br>
M    src/core_physics/module_physics_interface_hyd.F<br>
M    src/core_physics/module_physics_sfclayer.F<br>
M    src/core_physics/module_physics_manager.F<br>
M    src/core_physics/module_physics_todynamics.F<br>
M    src/core_physics/module_pbl.F<br>
M    src/core_physics/module_driver_convection_deep.F<br>
M    src/core_physics/module_physics_control.F<br>
M    src/core_physics/module_physics_interface_nhyd.F<br>
M    src/driver/module_subdriver.F<br>
M    src/core_nhyd_atmos/mpas_interface.F<br>
M    src/core_nhyd_atmos/module_advection.F<br>
M    src/core_nhyd_atmos/module_test_cases.F<br>
M    src/core_nhyd_atmos/Registry<br>
M    src/core_nhyd_atmos/module_time_integration.F<br>
M    src/core_ocean/module_global_diagnostics.F<br>
M    src/core_ocean/mpas_interface.F<br>
M    src/core_ocean/module_test_cases.F<br>
M    src/core_ocean/Registry<br>
M    src/core_ocean/module_time_integration.F<br>
M    src/framework/module_io_input.F<br>
M    src/framework/module_io_output.F<br>
M    src/framework/module_grid_types.F<br>
M    src/operators/module_RBF_interpolation.F<br>
M    src/operators/module_vector_reconstruction.F<br>
M    Makefile<br>
M    namelist.input.ocean<br>
A    namelist.input.nhyd_atmos_mtn_wave<br>
A    namelist.input.nhyd_atmos_jw<br>
A    namelist.input.nhyd_atmos<br>
</p><hr noshade><pre><font color="gray">Modified: branches/atmos_physics/Makefile
===================================================================
--- branches/atmos_physics/Makefile        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/Makefile        2010-10-13 20:25:17 UTC (rev 549)
@@ -1,18 +1,10 @@
 #MODEL_FORMULATION = -DNCAR_FORMULATION
 MODEL_FORMULATION = -DLANL_FORMULATION
 
-ifeq ($(CORE),hyd_atmos)
-EXPAND_LEVELS = -DEXPAND_LEVELS=26
-endif
-
-ifeq ($(CORE),nhyd_atmos)
-EXPAND_LEVELS = -DEXPAND_LEVELS=26
-endif
-
 FILE_OFFSET = -DOFFSET64BIT
 
-PHYSICS = -DDO_PHYSICS
-#PHYSICS  = 
+#PHYSICS = -DDO_PHYSICS
+PHYSICS  = 
 
 #########################
 # Section for Zoltan TPL
@@ -41,7 +33,7 @@
         &quot;CFLAGS = -g&quot; \
         &quot;LDFLAGS = -g -C&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
  
 ftn:
         ( make all \
@@ -53,7 +45,7 @@
         &quot;CFLAGS = -fast&quot; \
         &quot;LDFLAGS = &quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi:
         ( make all \
@@ -65,7 +57,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-llnl:
         ( make all \
@@ -77,7 +69,7 @@
         &quot;CFLAGS = -fast&quot; \
         &quot;LDFLAGS = &quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-serial:
         ( make all \
@@ -89,7 +81,7 @@
         &quot;CFLAGS = -O0 -g&quot; \
         &quot;LDFLAGS = -O0 -g -Mbounds -Mchkptr&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 ifort:
         ( make all \
@@ -101,7 +93,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(PHYSICS) -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(PHYSICS) -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 gfortran:
         ( make all \
@@ -113,7 +105,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3 -m64&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(PHYSICS) -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(PHYSICS) -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 g95:
         ( make all \
@@ -125,7 +117,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 g95-serial:
         ( make all \
@@ -137,7 +129,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE $(PHYSICS) $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 
 CPPINCLUDES = -I../inc -I$(NETCDF)/include

Modified: branches/atmos_physics/graphics/matlab/MapDataToDx.m
===================================================================
--- branches/atmos_physics/graphics/matlab/MapDataToDx.m        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/graphics/matlab/MapDataToDx.m        2010-10-13 20:25:17 UTC (rev 549)
@@ -6,53 +6,46 @@
 
 eps = 1.0e-12
 
-ncid = netcdf.open('../output.nc','nc_nowrite')
+ncid = netcdf.open('output.nc','nc_nowrite')
 
-doThickness = 1;
-doKE = 1;
-doVorticity = 1;
+doThickness = 0;
+doKE = 0;
+doVorticity = 0;
 doVelocity = 1;
 
+%%%%%
+%  CHECK THAT THE DIMENSION ORDER (AND NUMBER) AGREES WITH OUR OUTPUT.NC
+%%%%%
+
+[TimeName, TimeLength] = netcdf.inqDim(ncid,0);
 [nCellsName, nCellsLength] = netcdf.inqDim(ncid,1);
 [nEdgesName, nEdgesLength] = netcdf.inqDim(ncid,2);
 [nVerticesName, nVerticesLength] = netcdf.inqDim(ncid,5);
-[nVertLevelsName, nVertLevelsLength] = netcdf.inqDim(ncid,8);
-[nTracersName, nTracersLength] = netcdf.inqDim(ncid,9);
-[TimeName, TimeLength] = netcdf.inqDim(ncid,0);
+[nVertLevelsName, nVertLevelsLength] = netcdf.inqDim(ncid,9);
+[nTracersName, nTracersLength] = netcdf.inqDim(ncid,10);
 
+TimeLength
+nCellsLength
+nEdgesLength
+nVerticesLength
+nVertLevelsLength
+nTracersLength
+
+
+if (doThickness == 1)
+    
 thicknessID = netcdf.inqVarID(ncid,'h');
 work =  netcdf.getVar(ncid,thicknessID);
 [thicknessName,xtype,dimids,natts] = netcdf.inqVar(ncid,thicknessID);
 thickness=work;
 
-keID = netcdf.inqVarID(ncid,'ke');
-work =  netcdf.getVar(ncid,keID);
-[keName,xtype,dimids,natts] = netcdf.inqVar(ncid,keID);
-ke=work;
-
-vorticityID = netcdf.inqVarID(ncid,'vorticity');
-work =  netcdf.getVar(ncid,vorticityID);
-[vorticityName,xtype,dimids,natts] = netcdf.inqVar(ncid,vorticityID);
-vorticity=work;
-
-uID = netcdf.inqVarID(ncid,'u');
-work =  netcdf.getVar(ncid,uID);
-[uName,xtype,dimids,natts] = netcdf.inqVar(ncid,uID);
-u=work;
-
-vID = netcdf.inqVarID(ncid,'v');
-work =  netcdf.getVar(ncid,vID);
-[vName,xtype,dimids,natts] = netcdf.inqVar(ncid,vID);
-v=work;
-
-
-if (doThickness == 1)
-system('rm -f ../dx/h.*.*.data')
+system('rm -f ./dx/h.*.*.data')
 for iLevel=1:nVertLevelsLength
 for iTime=0:TimeLength-1
-    stringTime = int2str(iTime)
-    stringVert = int2str(iLevel)
-    FileName = strcat('../dx/', thicknessName, '.', ...
+    iTime
+    stringTime = int2str(iTime);
+    stringVert = int2str(iLevel);
+    FileName = strcat('./dx/', thicknessName, '.', ...
         stringVert, '.', stringTime, '.', 'data')
     for iCell=1:nCellsLength
       data = thickness(iLevel,iCell,iTime+1);
@@ -65,12 +58,18 @@
 end
 
 if (doKE == 1)
-system('rm -f ../dx/ke.*.*.data')
+
+keID = netcdf.inqVarID(ncid,'ke');
+work =  netcdf.getVar(ncid,keID);
+[keName,xtype,dimids,natts] = netcdf.inqVar(ncid,keID);
+ke=work;
+
+system('rm -f ./dx/ke.*.*.data')
 for iLevel=1:nVertLevelsLength
 for iTime=0:TimeLength-1
-    stringTime = int2str(iTime)
-    stringVert = int2str(iLevel)
-    FileName = strcat('../dx/', keName, '.', ...
+    stringTime = int2str(iTime);
+    stringVert = int2str(iLevel);
+    FileName = strcat('./dx/', keName, '.', ...
         stringVert, '.', stringTime, '.', 'data')
     for iCell=1:nCellsLength
       data = ke(iLevel,iCell,iTime+1);
@@ -83,12 +82,18 @@
 end
 
 if (doVorticity == 1)
-system('rm -f ../dx/vorticity.*.*.data')
+    
+vorticityID = netcdf.inqVarID(ncid,'vorticity');
+work =  netcdf.getVar(ncid,vorticityID);
+[vorticityName,xtype,dimids,natts] = netcdf.inqVar(ncid,vorticityID);
+vorticity=work;
+
+system('rm -f ./dx/vorticity.*.*.data')
 for iLevel=1:nVertLevelsLength
 for iTime=0:TimeLength-1
-    stringTime = int2str(iTime)
-    stringVert = int2str(iLevel)
-    FileName = strcat('../dx/', vorticityName, '.', ...
+    stringTime = int2str(iTime);
+    stringVert = int2str(iLevel);
+    FileName = strcat('./dx/', vorticityName, '.', ...
         stringVert, '.', stringTime, '.', 'data')
     for iVertex=1:nVerticesLength
       data = vorticity(iLevel,iVertex,iTime+1);
@@ -101,39 +106,40 @@
 end
 
 if (doVelocity == 1)
-system('rm -f ../dx/u.*.*.data')
-for iLevel=1:nVertLevelsLength
-for iTime=0:TimeLength-1
-    stringTime = int2str(iTime)
-    stringVert = int2str(iLevel)
-    FileName = strcat('../dx/', uName, '.', ...
-        stringVert, '.', stringTime, '.', 'data')
-    for iEdge=1:nEdgesLength
-      data = u(iLevel,iEdge,iTime+1);
-      if abs(data) &lt; eps, data=0;, end;
-      dlmwrite(FileName, data, ...
-         'precision', '%18.10e', '-append')
-    end
-end
-end
-end
 
-if (doVelocity == 1)
-system('rm -f ../dx/v.*.*.data')
+uID = netcdf.inqVarID(ncid,'uReconstructX');
+work =  netcdf.getVar(ncid,uID);
+[uName,xtype,dimids,natts] = netcdf.inqVar(ncid,uID);
+u=work;
+
+vID = netcdf.inqVarID(ncid,'uReconstructY');
+work =  netcdf.getVar(ncid,vID);
+[vName,xtype,dimids,natts] = netcdf.inqVar(ncid,vID);
+v=work;
+
+wID = netcdf.inqVarID(ncid,'uReconstructZ');
+work =  netcdf.getVar(ncid,wID);
+[wName,xtype,dimids,natts] = netcdf.inqVar(ncid,wID);
+w=work;
+
+system('rm -f ./dx/velocity.*.*.data')
 for iLevel=1:nVertLevelsLength
 for iTime=0:TimeLength-1
-    stringTime = int2str(iTime)
-    stringVert = int2str(iLevel)
-    FileName = strcat('../dx/', vName, '.', ...
+    stringTime = int2str(iTime);
+    stringVert = int2str(iLevel);
+    FileName = strcat('./dx/', 'velocity', '.', ...
         stringVert, '.', stringTime, '.', 'data')
-    for iEdge=1:nEdgesLength
-      data = v(iLevel,iEdge,iTime+1);
-      if abs(data) &lt; eps, data=0;, end;
-      dlmwrite(FileName, data, ...
+    for iCell=1:nCellsLength
+      r(1) = u(iLevel,iCell,iTime+1);
+      r(2) = v(iLevel,iCell,iTime+1);
+      r(3) = w(iLevel,iCell,iTime+1);
+      dlmwrite(FileName, r(1), ...
          'precision', '%18.10e', '-append')
+     dlmwrite(FileName, r(2), ...
+         'precision', '%18.10e', '-append')
+     dlmwrite(FileName, r(3), ...
+         'precision', '%18.10e', '-append')
     end
 end
 end
-end
-
-
+end
\ No newline at end of file

Modified: branches/atmos_physics/graphics/matlab/MapGridToDx.m
===================================================================
--- branches/atmos_physics/graphics/matlab/MapGridToDx.m        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/graphics/matlab/MapGridToDx.m        2010-10-13 20:25:17 UTC (rev 549)
@@ -6,18 +6,18 @@
 clear all
 
 % begin periodic parameters
-doPeriodic = 1
-dc = 1000.0
-nx = 200
-ny = 200
+doPeriodic = 0;
+dc = 1000.0;
+nx = 200;
+ny = 200;
 % end periodic parameters
 
 doWrite = 1
-doVor = 0
-doTri = 0
-doEdge = 1
+doVor = 1
+doTri = 1
+doVector = 1
 
-ncid = netcdf.open('../grid.nc','nc_nowrite');
+ncid = netcdf.open('grid.nc','nc_nowrite');
 
 if (doVor == 1)
     
@@ -47,19 +47,19 @@
     nCells=work(1)
 
     if (doWrite == 1)
-    system('rm -f ../dx/vor.position.data');
-    system('rm -f ../dx/vor.edge.data');
-    system('rm -f ../dx/vor.loop.data');
-    system('rm -f ../dx/vor.face.data');
-    system('rm -f ../dx/vor.area.data');
+    system('rm -f ./dx/vor.position.data');
+    system('rm -f ./dx/vor.edge.data');
+    system('rm -f ./dx/vor.loop.data');
+    system('rm -f ./dx/vor.face.data');
+    system('rm -f ./dx/vor.area.data');
 
     iloop=0;
     iedge=0;
     for i=1:nCells
-     dlmwrite('../dx/vor.face.data', i-1, '-append');
-     dlmwrite('../dx/vor.area.data', areaCell(i), ...
+     dlmwrite('./dx/vor.face.data', i-1, '-append');
+     dlmwrite('./dx/vor.area.data', areaCell(i), ...
         'precision', '%18.10e', '-append');
-       dlmwrite('../dx/vor.loop.data', iloop, ...
+       dlmwrite('./dx/vor.loop.data', iloop, ...
         'precision', '%10i', '-append');
        edge(1:nEdgesOnCell(i)) = iedge;
      
@@ -85,11 +85,11 @@
      end;
      
      for j=1:nEdgesOnCell(i)
-         dlmwrite('../dx/vor.position.data', x(:,j), 'delimiter', '\t', ...
+         dlmwrite('./dx/vor.position.data', x(:,j), 'delimiter', '\t', ...
              'precision', '%18.10e', '-append');
          edge(j) = iedge + j - 1;
        end;
-       dlmwrite('../dx/vor.edge.data', edge(1:nEdgesOnCell(i)), ...
+       dlmwrite('./dx/vor.edge.data', edge(1:nEdgesOnCell(i)), ...
         'delimiter', '\t', 'precision', '%10i', '-append')
        iloop = iloop + nEdgesOnCell(i);
       iedge = iedge + nEdgesOnCell(i);
@@ -126,19 +126,19 @@
     nVertices = work(:,2)
 
     if (doWrite == 1)
-    system('rm -f ../dx/tri.position.data');
-    system('rm -f ../dx/tri.edge.data');
-    system('rm -f ../dx/tri.loop.data');
-    system('rm -f ../dx/tri.face.data');
-    system('rm -f ../dx/tri.area.data');
+    system('rm -f ./dx/tri.position.data');
+    system('rm -f ./dx/tri.edge.data');
+    system('rm -f ./dx/tri.loop.data');
+    system('rm -f ./dx/tri.face.data');
+    system('rm -f ./dx/tri.area.data');
     
     iloop=0;
     iedge=0;
     for i=1:nVertices
-     dlmwrite('../dx/tri.face.data', i-1, '-append');
-     dlmwrite('../dx/tri.area.data', areaTriangle(i), ...
+     dlmwrite('./dx/tri.face.data', i-1, '-append');
+     dlmwrite('./dx/tri.area.data', areaTriangle(i), ...
         'precision', '%18.10e', '-append');
-     dlmwrite('../dx/tri.loop.data', iloop, ...
+     dlmwrite('./dx/tri.loop.data', iloop, ...
         'precision', '%10i', '-append');
      edge(1:3) = iedge;
      for j=1:nCellsOnVertex
@@ -163,11 +163,11 @@
      end;
      
      for j=1:nCellsOnVertex;
-         dlmwrite('../dx/tri.position.data', x(:,j), 'delimiter', '\t', ...
+         dlmwrite('./dx/tri.position.data', x(:,j), 'delimiter', '\t', ...
              'precision', '%18.10e', '-append')
          edge(j) = iedge + j - 1;
      end;
-     dlmwrite('../dx/tri.edge.data', edge(1:3), ...
+     dlmwrite('./dx/tri.edge.data', edge(1:3), ...
          'delimiter', '\t', 'precision', '%10i', '-append')
      iloop = iloop + 3;
      iedge = iedge + 3;
@@ -177,26 +177,17 @@
 
 end;
 
-if (doEdge == 1)
+if (doVector == 1)
     
     if (doWrite == 1)
-        system('rm -f ../dx/edge.position.data');
-        system('rm -f ../dx/normal.data');
-        system('rm -f ../dx/tangent.data');
+        system('rm -f ./dx/vector.position.data');
+        system('rm -f ./dx/vector.data');
     end;
     
-    [nEdgesName, nEdgesLength] = netcdf.inqDim(ncid,1);
-    xE_id = netcdf.inqVarID(ncid,'xEdge');
-    yE_id = netcdf.inqVarID(ncid,'yEdge');
-    zE_id = netcdf.inqVarID(ncid,'zEdge');
-    nCellsOnEdge = 2;
-    nEdges = nEdgesLength;
-    cellsOnEdge_id = netcdf.inqVarID(ncid, 'cellsOnEdge');
-
-    xE=netcdf.getVar(ncid, xE_id);
-    yE=netcdf.getVar(ncid, yE_id);
-    zE=netcdf.getVar(ncid, zE_id);
-    cellsOnEdge=netcdf.getVar(ncid, cellsOnEdge_id);
+    nEdgesOnCell_id = netcdf.inqVarID(ncid,'nEdgesOnCell');
+    nEdgesOnCell=netcdf.getVar(ncid, nEdgesOnCell_id);
+    work=size(nEdgesOnCell(:,1));
+    nCells=work(1)
     
     xC_id = netcdf.inqVarID(ncid,'xCell');
     yC_id = netcdf.inqVarID(ncid,'yCell');
@@ -206,53 +197,45 @@
     yC=netcdf.getVar(ncid, yC_id);
     zC=netcdf.getVar(ncid, zC_id);
     
-    for i=1:nEdges
-      
-        j1 = cellsOnEdge(1,i);
-        j2 = cellsOnEdge(2,i);
-        iCell1 = min(j1,j2);
-        iCell2 = max(j1,j2);
+    xP = 0.0;
+    yP = 0.0;
+    zP = 1.0;
+    
+    for i=1:nCells
         
-        x(1) = xC(iCell2)-xC(iCell1);
-        x(2) = yC(iCell2)-yC(iCell1);
-        x(3) = zC(iCell2)-zC(iCell1);
+        a(1) = xC(i); 
+        a(2) = yC(i);
+        a(3) = zC(i);
         
-        normal = x ./ sqrt(x(1)^2 + x(2)^2 + x(3)^2);
+        b(1) = xP;
+        b(2) = yP;
+        b(3) = zP;
         
-        x(1) = xE(i); x(2) = yE(i); x(3) = zE(i);
-        tangent(1) = x(2).*normal(3) - x(3).*normal(2);
-        tangent(2) = x(3).*normal(1) - x(1).*normal(3);
-        tangent(3) = x(1).*normal(2) - x(2).*normal(1);
+        c(1) = a(2)*b(3) - a(3)*b(2);
+        c(2) = a(3)*b(1) - a(1)*b(3);
+        c(3) = a(1)*b(2) - a(2)*b(1);
+
     
-    
         if (doWrite == 1)
         
-            dlmwrite('../dx/edge.position.data', xE(i), ...
+            dlmwrite('./dx/vector.position.data', xC(i), ...
              'precision', '%18.10e', '-append')
        
-            dlmwrite('../dx/edge.position.data', yE(i), ...
+            dlmwrite('./dx/vector.position.data', yC(i), ...
              'precision', '%18.10e', '-append')
        
-            dlmwrite('../dx/edge.position.data', zE(i), ...
+            dlmwrite('./dx/vector.position.data', zC(i), ...
              'precision', '%18.10e', '-append')
-       
-            dlmwrite('../dx/normal.data', normal(1), ...
+         
+            dlmwrite('./dx/vector.data', c(1), ...
              'precision', '%18.10e', '-append')
        
-            dlmwrite('../dx/normal.data', normal(2), ...
+            dlmwrite('./dx/vector.data', c(2), ...
              'precision', '%18.10e', '-append')
        
-            dlmwrite('../dx/normal.data', normal(3), ...
+            dlmwrite('./dx/vector.data', c(3), ...
              'precision', '%18.10e', '-append')
        
-            dlmwrite('../dx/tangent.data', tangent(1), ...
-             'precision', '%18.10e', '-append')
-       
-            dlmwrite('../dx/tangent.data', tangent(2), ...
-             'precision', '%18.10e', '-append')
-       
-            dlmwrite('../dx/tangent.data', tangent(3), ...
-             'precision', '%18.10e', '-append')
     
     end;
     

Added: branches/atmos_physics/graphics/ncl/cells_hex.ncl
===================================================================
--- branches/atmos_physics/graphics/ncl/cells_hex.ncl                                (rev 0)
+++ branches/atmos_physics/graphics/ncl/cells_hex.ncl        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,171 @@
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl&quot;
+
+begin
+
+  plotfield = &quot;w&quot;
+  level = 5
+  winds = True
+  nrows = 100
+  ncols = 100
+  maxedges = 6
+
+  wks = gsn_open_wks(&quot;pdf&quot;,&quot;cells&quot;)
+  gsn_define_colormap(wks,&quot;wh-bl-gr-ye-re&quot;)
+
+  f = addfile(&quot;output.nc&quot;,&quot;r&quot;)
+
+  xCell   = f-&gt;xCell(:)
+  yCell   = f-&gt;yCell(:)
+  zCell   = f-&gt;zCell(:)
+  xEdge   = f-&gt;xEdge(:)
+  yEdge   = f-&gt;yEdge(:)
+  zEdge   = f-&gt;zEdge(:)
+  xVertex = f-&gt;xVertex(:)
+  yVertex = f-&gt;yVertex(:)
+  zVertex = f-&gt;zVertex(:)
+  verticesOnCell = f-&gt;verticesOnCell(:,:)
+  edgesOnCell = f-&gt;edgesOnCell(:,:)
+  edgesOnEdge = f-&gt;edgesOnEdge(:,:)
+  verticesOnEdge = f-&gt;verticesOnEdge(:,:)
+  cellsOnEdge = f-&gt;cellsOnEdge(:,:)
+  cellsOnVertex = f-&gt;cellsOnVertex(:,:)
+  edgesOnVertex = f-&gt;edgesOnVertex(:,:)
+
+  res                      = True
+
+  t = stringtointeger(getenv(&quot;T&quot;))
+
+  xpoly = new((/maxedges/), &quot;double&quot;)
+  ypoly = new((/maxedges/), &quot;double&quot;)
+
+  xcb = new((/4/), &quot;float&quot;)
+  ycb = new((/4/), &quot;float&quot;)
+
+  pres = True
+  pres@gsnFrame = False
+  pres@xyLineColor = &quot;Background&quot;
+  plot = gsn_xy(wks,xCell,yCell,pres)
+
+  if (plotfield .eq. &quot;tracer&quot;) then
+     fld   = f-&gt;tracers(t,:,0,0)
+     minfld = min(fld)
+     maxfld = max(fld)
+  end if
+  if (plotfield .eq. &quot;w&quot;) then
+     fld   = f-&gt;w(t,:,level)
+     minfld = min(fld)
+     maxfld = max(fld)
+  end if
+  if (plotfield .eq. &quot;t&quot;) then
+     fld   = f-&gt;theta(t,:,level)
+     minfld = min(fld)
+     maxfld = max(fld)
+  end if
+  if (plotfield .eq. &quot;qr&quot;) then
+     fld   = f-&gt;qr(t,:,level)
+     minfld = min(fld)
+     maxfld = max(fld)
+  end if
+  if (plotfield .eq. &quot;ke&quot;) then
+     fld   = f-&gt;ke(t,:,0)
+     minfld = min(fld)
+     maxfld = max(fld)
+  end if
+  if (plotfield .eq. &quot;vorticity&quot;) then
+     fld   = f-&gt;vorticity(t,:,0)
+     minfld = min(fld)
+     maxfld = max(fld)
+  end if
+  scalefac = 198.0/(maxfld - minfld)
+
+  if (plotfield .eq. &quot;vorticity&quot;) then
+     do iRow=1,nrows-2
+     do iCol=1,ncols-2
+     iCell = iRow*ncols+iCol
+     do iVertex=2*iCell,2*iCell+1
+     do i=0,2
+        xpoly(i) = xCell(cellsOnVertex(iVertex,i)-1)
+        ypoly(i) = yCell(cellsOnVertex(iVertex,i)-1)
+        res@gsFillColor = doubletointeger((fld(iVertex)-minfld)*scalefac)+2
+     end do
+     gsn_polygon(wks,plot,xpoly,ypoly,res);
+     end do
+     end do
+     end do
+  end if
+
+  if (plotfield .eq. &quot;h&quot; .or. plotfield .eq. &quot;ke&quot; .or. plotfield .eq. &quot;t&quot; .or. plotfield .eq. &quot;w&quot; .or. plotfield .eq. &quot;qr&quot;) then
+     do iRow=1,nrows-2
+     do iCol=0,ncols-2
+     iCell = iRow*ncols+iCol
+     do i=0,5
+        xpoly(i) = xVertex(verticesOnCell(iCell,i)-1)
+        ypoly(i) = yVertex(verticesOnCell(iCell,i)-1)
+        res@gsFillColor = doubletointeger((fld(iCell)-minfld)*scalefac)+2
+     end do
+     gsn_polygon(wks,plot,xpoly,ypoly,res);
+     end do
+     end do
+  end if
+
+  if (winds) then
+     u   = 2.*f-&gt;u(t,:,level)
+     v   = 2.*f-&gt;v(t,:,level)
+     alpha = f-&gt;angleEdge(:)
+     esizes = dimsizes(u)
+     u_earth = new(dimsizes(u),float)
+     v_earth = new(dimsizes(u),float)
+     xwind = new(dimsizes(u),float)
+     ywind = new(dimsizes(u),float)
+     do i=0,esizes(0)-1
+        u_earth(i) = doubletofloat(u(i)*cos(alpha(i)) - v(i)*sin(alpha(i)))
+        v_earth(i) = doubletofloat(u(i)*sin(alpha(i)) + v(i)*cos(alpha(i)))
+        xwind(i) = doubletofloat(xEdge(i))
+        ywind(i) = doubletofloat(yEdge(i))
+     end do
+   
+     wmsetp(&quot;VCH&quot;,0.0010)
+     wmsetp(&quot;VRN&quot;,0.010)
+     wmsetp(&quot;VRS&quot;,100.0)
+     wmsetp(&quot;VCW&quot;,0.10)
+
+     wmvect(wks, xwind, ywind, u_earth, v_earth)
+  end if
+
+  ;
+  ; Draw label bar
+  ;
+  tres = True
+  tres@txAngleF = 90.0
+  tres@txFontHeightF = 0.015
+  do i=2,200
+     xcb(0) = 0.1 + i*0.8/198
+     ycb(0) = 0.1
+
+     xcb(1) = 0.1 + (i+1)*0.8/198
+     ycb(1) = 0.1
+
+     xcb(2) = 0.1 + (i+1)*0.8/198
+     ycb(2) = 0.15
+
+     xcb(3) = 0.1 + i*0.8/198
+     ycb(3) = 0.15
+
+     res@gsFillColor = i
+
+     gsn_polygon_ndc(wks,xcb,ycb,res);
+
+     j = (i-2) % 20
+     if ((j .eq. 0) .or. (i .eq. 200)) then
+        ff = minfld + (i-2) / scalefac
+        label = sprintf(&quot;%7.3g&quot;, ff)
+        gsn_text_ndc(wks, label, xcb(0), 0.05, tres)
+     end if
+
+  end do
+
+  frame(wks)
+
+end
+

Added: branches/atmos_physics/graphics/ncl/cells_nhyd_sph1.ncl
===================================================================
--- branches/atmos_physics/graphics/ncl/cells_nhyd_sph1.ncl                                (rev 0)
+++ branches/atmos_physics/graphics/ncl/cells_nhyd_sph1.ncl        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,207 @@
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;
+
+begin
+
+  ;
+  ; Which field to plot
+  ;
+  plotfield = &quot;h&quot;
+;  plotfield = &quot;ke&quot;
+;  plotfield = &quot;vorticity&quot;
+
+  ;
+  ; Whether to plot wind vectors
+  ;
+;  winds    = True
+  winds    = False
+
+  ;
+  ; Whether to do color-filled plot (filled=True) or
+  ;   to plot contours of height field (filled=False)
+  ;
+  filled   = True
+;  filled   = False
+
+  ;
+  ; The (lat,lon) the plot is to be centered over
+  ;
+  cenLat   = 90.0
+  cenLon   = 180.0
+
+  ;
+  ; Projection to use for plot
+  ;
+  projection = &quot;Orthographic&quot;
+;  projection = &quot;CylindricalEquidistant&quot;
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+  r2d = 57.2957795             ; radians to degrees
+
+  maxedges = 7 
+
+; wks_type = &quot;pdf&quot;
+; wks_type@wkOrientation = &quot;landscape&quot;
+; wks = gsn_open_wks(wks_type,&quot;cells&quot;)
+
+ wks = gsn_open_wks(&quot;pdf&quot;,&quot;cells&quot;)
+;  wks = gsn_open_wks(&quot;x11&quot;,&quot;cells&quot;)
+  gsn_define_colormap(wks,&quot;gui_default&quot;)
+
+  f = addfile(&quot;output.nc&quot;,&quot;r&quot;)
+
+  lonCell   = f-&gt;lonCell(:) * r2d
+  latCell   = f-&gt;latCell(:) * r2d
+  lonVertex = f-&gt;lonVertex(:) * r2d
+  latVertex = f-&gt;latVertex(:) * r2d
+  lonEdge = f-&gt;lonEdge(:) * r2d
+  latEdge = f-&gt;latEdge(:) * r2d
+  verticesOnCell = f-&gt;verticesOnCell(:,:)
+  alpha = f-&gt;angleEdge(:)
+
+  res                      = True
+  res@gsnMaximize          = True
+  res@gsnSpreadColors      = True
+
+  if (plotfield .eq. &quot;h&quot; .or. plotfield .eq. &quot;ke&quot;) then
+     res@sfXArray             = lonCell
+     res@sfYArray             = latCell
+  end if
+  if (plotfield .eq. &quot;vorticity&quot;) then
+     res@sfXArray             = lonVertex
+     res@sfYArray             = latVertex
+  end if
+
+  res@cnFillMode           = &quot;AreaFill&quot;
+
+  if (filled) then
+     res@cnFillOn             = True
+;     res@cnLinesOn            = False
+;     res@cnRasterModeOn       = True
+;     res@cnLinesOn            = False
+     res@cnLinesOn            = True
+     res@cnLineLabelsOn       = False
+  else
+     res@cnFillOn             = False
+     res@cnLinesOn            = True
+     res@cnLineLabelsOn       = True
+  end if
+
+;  res@cnLevelSelectionMode  = 2
+;  res@cnLevels              = (/950.,960.,970.,980.,990.,1000.,1010.,1020./)
+  res@cnLevelSelectionMode  = 3
+  res@cnLevelSpacingF      =  2.
+  res@cnMinLevelValF       = 940.
+  res@cnMaxLevelValF       = 1020.
+  res@cnInfoLabelOn        = True
+
+  res@lbLabelAutoStride    = True
+  res@lbBoxLinesOn         = False
+
+  res@mpProjection      = projection
+  res@mpDataBaseVersion = &quot;MediumRes&quot;
+  res@mpCenterLatF      = cenLat
+  res@mpCenterLonF      = cenLon
+  res@mpGridAndLimbOn   = True
+;  res@mpGridAndLimbDrawOrder = &quot;PreDraw&quot;
+  res@mpGridLineColor   = &quot;Background&quot;
+  res@mpOutlineOn       = False
+  res@mpFillOn          = False
+  res@mpPerimOn         = False
+  res@gsnFrame          = False
+
+
+  t = stringtointeger(getenv(&quot;T&quot;))
+  if (plotfield .eq. &quot;h&quot;) then
+;     h   = f-&gt;h(t,:,0)
+;     hs  = f-&gt;h_s(:)
+;     fld = h + hs
+;      h = f-&gt;ww(t,:,5)
+;     h = (f-&gt;surface_pressure(t,:) + 219.4)/100.
+;     h = f-&gt;geopotential(t,:,18)
+;     h = f-&gt;theta(t,:,25)-f-&gt;theta(0,:,25)
+;     h = f-&gt;theta(t,:,0)-f-&gt;theta_base(:,0)
+;     h = f-&gt;surface_pressure(t,:)/100.
+;     h = (f-&gt;surface_pressure(t,:)-f-&gt;surface_pressure(0,:))/100.
+;     h = f-&gt;pressure(t,:,0)/100.
+;     fld = h
+
+      cf1 = 2.
+      cf2 = -1.5
+      cf3 = .5
+
+;      cf1 = 1.
+;      cf2 = 0.
+;      cf3 = 0.
+
+      pfirst = f-&gt;pressure(t,:,0)+f-&gt;pressure_base(:,0)
+      psecond = f-&gt;pressure(t,:,1)+f-&gt;pressure_base(:,1)
+      pthird = f-&gt;pressure(t,:,2)+f-&gt;pressure_base(:,2)
+;      fld = (cf1*pfirst + cf2*psecond + cf3*pthird)/100.
+
+      rhofirst = f-&gt;rho(t,:,0)
+      rhosecond = f-&gt;rho(t,:,1)
+      qvfirst = f-&gt;qv(t,:,0)
+      qvsecond = f-&gt;qv(t,:,1)
+      rdzw = f-&gt;rdzw
+
+      gravity = 9.80616
+      fld = (pfirst + (0.5*gravity/rdzw(0))*(1.25*rhofirst*(1.+qvfirst) - 0.25*rhosecond*(1.+qvsecond)))/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)))
+
+
+;      fld = f-&gt;pressure(t,:,25)+f-&gt;pressure_base(:,25)
+
+;       fld = f-&gt;kdiff(t,:,0)
+
+;      zg = f-&gt;zgrid
+;      csizes = dimsizes(pfirst)
+;      fld = pfirst
+;      do i=0,csizes(0)-1
+;        zoff = (zg(i,1)-zg(i,0))/(zg(i,2)-zg(i,0))
+;        fld(i) = ((1.+zoff)*pfirst(i) + -zoff*psecond(i))/100.
+;      end do
+;
+  end if
+  if (plotfield .eq. &quot;ke&quot;) then
+     fld = f-&gt;ke(t,:,18)
+  end if
+  if (plotfield .eq. &quot;vorticity&quot;) then
+     fld = f-&gt;vorticity(t,:,1)
+  end if
+  res@cnLineDashPattern = 0
+  map = gsn_csm_contour_map(wks,fld,res)
+
+  if (winds) then
+     u   = f-&gt;u(t,:,25) - f-&gt;u(0,:,25)
+     v   = f-&gt;v(t,:,25) - f-&gt;v(0,:,25)
+     esizes = dimsizes(u)
+     u_earth = new(dimsizes(u),float)
+     v_earth = new(dimsizes(u),float)
+     lat_edge = new(dimsizes(u),float)
+     lon_edge = new(dimsizes(u),float)
+     do i=0,esizes(0)-1
+        u_earth(i) = doubletofloat(u(i)*cos(alpha(i)) - v(i)*sin(alpha(i)))
+        v_earth(i) = doubletofloat(u(i)*sin(alpha(i)) + v(i)*cos(alpha(i)))
+        lat_edge(i) = doubletofloat(latEdge(i))
+        lon_edge(i) = doubletofloat(lonEdge(i))
+     end do
+
+     wmsetp(&quot;VCH&quot;,0.0010)
+     wmsetp(&quot;VRN&quot;,0.010)
+     wmsetp(&quot;VRS&quot;,100.0)
+     wmsetp(&quot;VCW&quot;,0.10)
+
+     wmvectmap(wks, lat_edge, lon_edge, u_earth, v_earth)
+  end if
+
+  frame(wks)
+
+end
+

Added: branches/atmos_physics/graphics/ncl/cells_nhyd_sphere.ncl
===================================================================
--- branches/atmos_physics/graphics/ncl/cells_nhyd_sphere.ncl                                (rev 0)
+++ branches/atmos_physics/graphics/ncl/cells_nhyd_sphere.ncl        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,215 @@
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;
+
+begin
+
+  ;
+  ; Which field to plot
+  ;
+  plotfield = &quot;h&quot;
+;  plotfield = &quot;ke&quot;
+;  plotfield = &quot;vorticity&quot;
+
+  ;
+  ; Whether to plot wind vectors
+  ;
+;  winds    = True
+  winds    = False
+
+  ;
+  ; Whether to do color-filled plot (filled=True) or
+  ;   to plot contours of height field (filled=False)
+  ;
+  filled   = True
+;  filled   = False
+
+  ;
+  ; The (lat,lon) the plot is to be centered over
+  ;
+  cenLat   = 90.0
+  cenLon   = 180.0
+
+  ;
+  ; Projection to use for plot
+  ;
+  projection = &quot;Orthographic&quot;
+;  projection = &quot;CylindricalEquidistant&quot;
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+  r2d = 57.2957795             ; radians to degrees
+
+  maxedges = 7 
+
+; wks_type = &quot;pdf&quot;
+; wks_type@wkOrientation = &quot;landscape&quot;
+; wks = gsn_open_wks(wks_type,&quot;cells&quot;)
+
+ wks = gsn_open_wks(&quot;pdf&quot;,&quot;cells&quot;)
+;  wks = gsn_open_wks(&quot;x11&quot;,&quot;cells&quot;)
+  gsn_define_colormap(wks,&quot;gui_default&quot;)
+
+  f = addfile(&quot;output.nc&quot;,&quot;r&quot;)
+
+  lonCell   = f-&gt;lonCell(:) * r2d
+  latCell   = f-&gt;latCell(:) * r2d
+  lonVertex = f-&gt;lonVertex(:) * r2d
+  latVertex = f-&gt;latVertex(:) * r2d
+  lonEdge = f-&gt;lonEdge(:) * r2d
+  latEdge = f-&gt;latEdge(:) * r2d
+  verticesOnCell = f-&gt;verticesOnCell(:,:)
+  alpha = f-&gt;angleEdge(:)
+
+  res                      = True
+  res@gsnMaximize          = True
+  res@gsnSpreadColors      = True
+
+  if (plotfield .eq. &quot;h&quot; .or. plotfield .eq. &quot;ke&quot;) then
+     res@sfXArray             = lonCell
+     res@sfYArray             = latCell
+  end if
+  if (plotfield .eq. &quot;vorticity&quot;) then
+     res@sfXArray             = lonVertex
+     res@sfYArray             = latVertex
+  end if
+
+  res@cnFillMode           = &quot;AreaFill&quot;
+
+  if (filled) then
+     res@cnFillOn             = True
+;     res@cnLinesOn            = False
+;     res@cnRasterModeOn       = True
+     res@cnLinesOn            = True
+     res@cnLineLabelsOn       = False
+  else
+     res@cnFillOn             = False
+     res@cnLinesOn            = True
+     res@cnLineLabelsOn       = True
+  end if
+
+;  res@cnLevelSpacingF      =  10.0
+  res@cnInfoLabelOn        = True
+
+  res@lbLabelAutoStride    = True
+  res@lbBoxLinesOn         = False
+
+  res@mpProjection      = projection
+  res@mpDataBaseVersion = &quot;MediumRes&quot;
+  res@mpCenterLatF      = cenLat
+  res@mpCenterLonF      = cenLon
+
+  res@mpMinLatF = 0.
+  res@mpMaxLatF = 90.
+
+  res@mpGridAndLimbOn   = True
+;  res@mpGridAndLimbDrawOrder = &quot;PreDraw&quot;
+  res@mpGridLineColor   = &quot;Background&quot;
+  res@mpOutlineOn       = False
+  res@mpFillOn          = False
+  res@mpPerimOn         = False
+  res@gsnFrame          = False
+
+  res@cnLevelSelectionMode  = 2
+ res@cnLevels              = (/950.,960.,970.,980.,990.,1000.,1010.,1020./)
+; res@cnLevels              = (/962.,966.,970.,974.,978.,982.,986.,990.,994.,998.,1002.,1006.,1010.,1014./)
+; res@cnLevels              = (/952.,956.,960.,964.,968.,972.,976.,980.,984.,988.,992.,996.,1000.,1004.,1008.,1012.,1016.,1020./)
+
+;  res@cnMinLevelValF=
+;  res@cnMaxLevelValF=
+;  res@cnLevelSpacingF=
+
+
+  t = stringtointeger(getenv(&quot;T&quot;))
+  if (plotfield .eq. &quot;h&quot;) then
+;     h   = f-&gt;h(t,:,0)
+;     hs  = f-&gt;h_s(:)
+;     fld = h + hs
+;      h = f-&gt;ww(t,:,5)
+;     h = (f-&gt;surface_pressure(t,:) + 219.4)/100.
+;     h = f-&gt;geopotential(t,:,18)
+;     h = f-&gt;theta(t,:,25)-f-&gt;theta(0,:,25)
+;     h = f-&gt;theta(t,:,0)-f-&gt;theta_base(:,0)
+;     h = f-&gt;surface_pressure(t,:)/100.
+;     h = (f-&gt;surface_pressure(t,:)-f-&gt;surface_pressure(0,:))/100.
+;     h = f-&gt;pressure(t,:,0)/100.
+;     fld = h
+
+      cf1 = 2.
+      cf2 = -1.5
+      cf3 = .5
+
+;      cf1 = 1.
+;      cf2 = 0.
+;      cf3 = 0.
+
+      pfirst = f-&gt;pressure(t,:,0)+f-&gt;pressure_base(:,0)
+      psecond = f-&gt;pressure(t,:,1)+f-&gt;pressure_base(:,1)
+      pthird = f-&gt;pressure(t,:,2)+f-&gt;pressure_base(:,2)
+      fld = (cf1*pfirst + cf2*psecond + cf3*pthird)/100.
+
+      rhofirst = f-&gt;rho(t,:,0)
+      rhosecond = f-&gt;rho(t,:,1)
+      qvfirst = f-&gt;qv(t,:,0)
+      qvsecond = f-&gt;qv(t,:,1)
+      rdzw = f-&gt;rdzw
+
+      gravity = 9.80616
+      fld = (pfirst + (0.5*gravity/rdzw(0))*(1.25*rhofirst*(1.+qvfirst) - 0.25*rhosecond*(1.+qvsecond)))/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)))
+
+
+;      fld = f-&gt;pressure(t,:,25)+f-&gt;pressure_base(:,25)
+
+;      zg = f-&gt;zgrid
+;      csizes = dimsizes(pfirst)
+;      fld = pfirst
+;      do i=0,csizes(0)-1
+;        zoff = (zg(i,1)-zg(i,0))/(zg(i,2)-zg(i,0))
+;        fld(i) = ((1.+zoff)*pfirst(i) + -zoff*psecond(i))/100.
+;      end do
+;
+
+;   fld = f-&gt;theta(t,:,0)
+
+  end if
+  if (plotfield .eq. &quot;ke&quot;) then
+     fld = f-&gt;ke(t,:,18)
+  end if
+  if (plotfield .eq. &quot;vorticity&quot;) then
+     fld = f-&gt;vorticity(t,:,2)
+  end if
+  res@cnLineDashPattern = 0
+  map = gsn_csm_contour_map(wks,fld,res)
+
+  if (winds) then
+     u   = f-&gt;u(t,:,25) - f-&gt;u(0,:,25)
+     v   = f-&gt;v(t,:,25) - f-&gt;v(0,:,25)
+     esizes = dimsizes(u)
+     u_earth = new(dimsizes(u),float)
+     v_earth = new(dimsizes(u),float)
+     lat_edge = new(dimsizes(u),float)
+     lon_edge = new(dimsizes(u),float)
+     do i=0,esizes(0)-1
+        u_earth(i) = doubletofloat(u(i)*cos(alpha(i)) - v(i)*sin(alpha(i)))
+        v_earth(i) = doubletofloat(u(i)*sin(alpha(i)) + v(i)*cos(alpha(i)))
+        lat_edge(i) = doubletofloat(latEdge(i))
+        lon_edge(i) = doubletofloat(lonEdge(i))
+     end do
+
+     wmsetp(&quot;VCH&quot;,0.0010)
+     wmsetp(&quot;VRN&quot;,0.010)
+     wmsetp(&quot;VRS&quot;,100.0)
+     wmsetp(&quot;VCW&quot;,0.10)
+
+     wmvectmap(wks, lat_edge, lon_edge, u_earth, v_earth)
+  end if
+
+  frame(wks)
+
+end
+

Added: branches/atmos_physics/graphics/ncl/xz_plane.ncl
===================================================================
--- branches/atmos_physics/graphics/ncl/xz_plane.ncl                                (rev 0)
+++ branches/atmos_physics/graphics/ncl/xz_plane.ncl        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,161 @@
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;
+load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl&quot;
+
+begin
+  r2d = 57.2957795             ; radians to degrees
+  pi  = 3.14159265
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  ; Set the field to be plotted in the section labeled SET FIELD HERE
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+  ;
+  ; Whether to plot horizontal wind vectors
+  ;
+  horiz_winds    = True
+;  horiz_winds    = False
+
+  ;
+  ; Whether to do color-filled plot (filled=True) or
+  ;   to plot contours of height field (filled=False)
+  ;
+;  filled   = True
+  filled   = False
+
+  ;
+  ; The number of rows and columns in the data set
+  ;
+  nrows = 4
+  ncols = 200
+
+  ;
+  ; The row number (between 1 and nrows) to plot
+  ;
+  irow = 1
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+  wks = gsn_open_wks(&quot;pdf&quot;,&quot;xsec&quot;)
+  gsn_define_colormap(wks,&quot;gui_default&quot;)
+
+  f = addfile(&quot;output.nc&quot;,&quot;r&quot;)
+
+  lonCell   = f-&gt;lonCell(:) * r2d
+  latCell   = f-&gt;latCell(:) * r2d
+  xCell     = f-&gt;xCell(:)
+  yCell     = f-&gt;yCell(:)
+  zCell     = f-&gt;zCell(:)
+  lonVertex = f-&gt;lonVertex(:) * r2d
+  latVertex = f-&gt;latVertex(:) * r2d
+  xVertex = f-&gt;xVertex(:)
+  yVertex = f-&gt;yVertex(:)
+  zVertex = f-&gt;zVertex(:)
+  lonEdge = f-&gt;lonEdge(:) * r2d
+  latEdge = f-&gt;latEdge(:) * r2d
+  xEdge = f-&gt;xEdge(:)
+  yEdge = f-&gt;yEdge(:)
+  zEdge = f-&gt;zEdge(:)
+  verticesOnCell = f-&gt;verticesOnCell(:,:)
+  edgesOnCell = f-&gt;edgesOnCell(:,:)
+  nCellsOnCell = f-&gt;nEdgesOnCell(:)
+  cellsOnCell = f-&gt;cellsOnCell(:,:)
+  alpha = f-&gt;angleEdge(:)
+
+  dims = dimsizes(latCell)
+  nCells = dims(0)
+
+  nsec = ncols
+
+  xsec_id = new((/nsec/),integer)
+  xsec_edge_id = new((/nsec+1/),integer)
+
+  do i=0,nsec-1
+     xsec_id(i) = i + ncols * (irow-1)
+     xsec_edge_id(i) = 3 * (xsec_id(i))
+  end do
+  xsec_edge_id(nsec) = xsec_edge_id(nsec-1) + 3
+
+  res                      = True
+  res@gsnMaximize          = True
+  res@gsnSpreadColors      = True
+
+  res@cnFillMode           = &quot;AreaFill&quot;
+
+  if (filled) then
+     res@cnFillOn             = True
+     res@cnLinesOn            = False
+     res@cnLineLabelsOn       = False
+  else
+     res@cnFillOn             = False
+     res@cnLinesOn            = True
+     res@cnLineLabelsOn       = True
+  end if
+
+;  res@cnLevelSpacingF      =  50.0
+  res@cnInfoLabelOn        = True
+
+  res@lbLabelAutoStride    = True
+  res@lbBoxLinesOn         = False
+
+  res@gsnFrame          = False
+
+
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  ;; BEGIN SET FIELD HERE
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  t = stringtointeger(getenv(&quot;T&quot;))
+
+  fld = f-&gt;tx(t,:,:)
+  ldims = dimsizes(fld)
+  nVertLevels = ldims(1)
+
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+  ;; END SET FIELD HERE
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+  res@cnLineDashPattern = 0
+
+  ; Extract field from along cross section into plotting array
+  arr = new((/nVertLevels,nsec/),float) 
+  do i=0,nsec-1
+     do j=0,nVertLevels-1
+        arr(j,i) = doubletofloat(fld(xsec_id(i),j))
+     end do
+  end do
+  
+  map = gsn_csm_contour(wks,arr,res)
+
+  if (horiz_winds) then
+     u   = f-&gt;u(t,:,:)
+     v   = f-&gt;v(t,:,:)
+     esizes = dimsizes(u)
+     u_earth = new((/nVertLevels,nsec/),float)
+     v_earth = new((/nVertLevels,nsec/),float)
+     x_edge = new((/nVertLevels,nsec/),float)
+     y_edge = new((/nVertLevels,nsec/),float)
+     do i=0,nsec-1
+     do j=0,nVertLevels-1
+        u_earth(j,i) = doubletofloat(u(xsec_edge_id(i),j)*cos(alpha(xsec_edge_id(i))) - v(xsec_edge_id(i),j)*sin(alpha(xsec_edge_id(i))))
+        v_earth(j,i) = doubletofloat(u(xsec_edge_id(i),j)*sin(alpha(xsec_edge_id(i))) + v(xsec_edge_id(i),j)*cos(alpha(xsec_edge_id(i))))
+        x_edge(j,i) = i
+        y_edge(j,i) = j
+     end do
+     end do
+
+     wmsetp(&quot;VCH&quot;,0.0010)
+     wmsetp(&quot;VRN&quot;,0.010)
+     wmsetp(&quot;VRS&quot;,100.0)
+     wmsetp(&quot;VCW&quot;,0.10)
+
+     wmvect(wks, x_edge, y_edge, u_earth, v_earth)
+  end if
+
+  frame(wks)
+
+end
+

Modified: branches/atmos_physics/namelist.input.hyd_atmos
===================================================================
--- branches/atmos_physics/namelist.input.hyd_atmos        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/namelist.input.hyd_atmos        2010-10-13 20:25:17 UTC (rev 549)
@@ -16,6 +16,10 @@
    config_mp_physics = 0
 /
 
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
 &amp;io
    config_input_name = 'grid.nc'
    config_output_name = 'output.nc'
@@ -27,8 +31,8 @@
    config_do_restart = .false.
    config_restart_time = 1036800.0
 /
+
 &amp;physics
    config_n_physics = 01
    config_n_microp  = 20
 /
-

Added: branches/atmos_physics/namelist.input.nhyd_atmos
===================================================================
--- branches/atmos_physics/namelist.input.nhyd_atmos                                (rev 0)
+++ branches/atmos_physics/namelist.input.nhyd_atmos        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,39 @@
+&amp;nhyd_model
+   config_test_case = 2
+   config_time_integration = 'SRK3'
+   config_dt = 1800
+   config_ntimesteps = 480
+   config_output_interval = 48
+   config_number_of_sub_steps = 6
+   config_h_mom_eddy_visc2 = 0000.
+   config_h_mom_eddy_visc4 = 0.
+   config_v_mom_eddy_visc2 = 00.0
+   config_h_theta_eddy_visc2 = 0000.
+   config_h_theta_eddy_visc4 = 00.
+   config_v_theta_eddy_visc2 = 00.0
+   config_theta_adv_order = 2
+   config_scalar_adv_order = 2
+   config_positive_definite = .false.
+   config_monotonic = .false.
+   config_epssm = 0.1
+   config_smdiv = 0.1
+/
+
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
+&amp;io
+   config_input_name = 'grid.nc'
+   config_output_name = 'output.nc'
+   config_restart_name = 'restart.nc'
+/
+
+&amp;restart
+   config_restart_interval = 3000
+   config_do_restart = .false.
+   config_restart_time = 1036800.0
+/
+
+&amp;physics
+/

Added: branches/atmos_physics/namelist.input.nhyd_atmos_jw
===================================================================
--- branches/atmos_physics/namelist.input.nhyd_atmos_jw                                (rev 0)
+++ branches/atmos_physics/namelist.input.nhyd_atmos_jw        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,47 @@
+&amp;nhyd_model
+   config_test_case = 2
+   config_time_integration = 'SRK3'
+   config_dt = 450
+   config_ntimesteps = 1920
+   config_output_interval = 192
+   config_number_of_sub_steps = 6
+   config_h_mom_eddy_visc2 = 0.0e+04
+   config_h_mom_eddy_visc4 = 0.
+   config_v_mom_eddy_visc2 = 00.0
+   config_h_theta_eddy_visc2 = 0.0e+04
+   config_h_theta_eddy_visc4 = 00.
+   config_v_theta_eddy_visc2 = 00.0
+   config_horiz_mixing       = '2d_smagorinsky'
+   config_len_disp           = 60000.
+   config_u_vadv_order = 3
+   config_w_vadv_order = 3
+   config_theta_vadv_order = 3
+   config_scalar_vadv_order = 3
+   config_theta_adv_order = 3
+   config_scalar_adv_order = 3
+   config_scalar_advection = .false.
+   config_positive_definite = .false.
+   config_coef_3rd_order = 1.0
+   config_monotonic = .false.
+   config_epssm = 0.1
+   config_smdiv = 0.1
+/
+
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
+&amp;io
+   config_input_name = 'grid.nc'
+   config_output_name = 'output.nc'
+   config_restart_name = 'restart.nc'
+/
+
+&amp;restart
+   config_restart_interval = 3000
+   config_do_restart = .false.
+   config_restart_time = 1036800.0
+/
+
+&amp;physics
+/

Added: branches/atmos_physics/namelist.input.nhyd_atmos_mtn_wave
===================================================================
--- branches/atmos_physics/namelist.input.nhyd_atmos_mtn_wave                                (rev 0)
+++ branches/atmos_physics/namelist.input.nhyd_atmos_mtn_wave        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,42 @@
+&amp;nhyd_model
+   config_test_case = 6
+   config_time_integration = 'SRK3'
+   config_dt = 6.
+   config_ntimesteps = 3000
+   config_output_interval = 100
+   config_number_of_sub_steps = 6
+   config_h_mom_eddy_visc2 = 10.
+   config_h_mom_eddy_visc4 = 0.
+   config_v_mom_eddy_visc2 = 10.
+   config_h_theta_eddy_visc2 = 10.
+   config_h_theta_eddy_visc4 = 0.
+   config_v_theta_eddy_visc2 = 10.
+   config_theta_adv_order = 3
+   config_w_adv_order = 3
+   config_scalar_advection = .false.
+   config_positive_definite = .false.
+   config_monotonic = .false.
+   config_mix_full = .false.
+   config_horiz_mixing = '2d_fixed'
+   config_coef_3rd_order = 0.25
+   config_epssm = 0.2
+/
+
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
+&amp;io
+   config_input_name = 'grid.nc'
+   config_output_name = 'output.nc'
+   config_restart_name = 'restart.nc'
+/
+
+&amp;restart
+   config_restart_interval = 3000
+   config_do_restart = .false.
+   config_restart_time = 1036800.0
+/
+
+&amp;physics
+/

Added: branches/atmos_physics/namelist.input.nhyd_atmos_squall
===================================================================
--- branches/atmos_physics/namelist.input.nhyd_atmos_squall                                (rev 0)
+++ branches/atmos_physics/namelist.input.nhyd_atmos_squall        2010-10-13 20:25:17 UTC (rev 549)
@@ -0,0 +1,37 @@
+&amp;nhyd_model
+   config_test_case = 4
+   config_time_integration = 'SRK3'
+   config_dt = 6.
+   config_ntimesteps = 600
+   config_output_interval = 100
+   config_number_of_sub_steps = 6
+   config_h_mom_eddy_visc2 = 500.
+   config_h_mom_eddy_visc4 = 0.
+   config_v_mom_eddy_visc2 = 500.0
+   config_h_theta_eddy_visc2 = 500.
+   config_h_theta_eddy_visc4 = 00.
+   config_v_theta_eddy_visc2 = 500.0
+   config_theta_adv_order = 2
+   config_scalar_adv_order = 2
+   config_positive_definite = .false.
+   config_monotonic = .false.
+/
+
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
+&amp;io
+   config_input_name = 'grid.nc'
+   config_output_name = 'output.nc'
+   config_restart_name = 'restart.nc'
+/
+
+&amp;restart
+   config_restart_interval = 3000
+   config_do_restart = .false.
+   config_restart_time = 1036800.0
+/
+
+&amp;physics
+/

Modified: branches/atmos_physics/namelist.input.ocean
===================================================================
--- branches/atmos_physics/namelist.input.ocean        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/namelist.input.ocean        2010-10-13 20:25:17 UTC (rev 549)
@@ -1,11 +1,10 @@
 &amp;sw_model
    config_test_case = 0
    config_time_integration = 'RK4'
-   config_dt = 60.0
-   config_ntimesteps = 1440000 
-   config_output_interval = 14400 
-   config_stats_interval = 1440 
-   config_visc  = 1.0e5
+   config_dt = 90.0
+   config_ntimesteps = 1920000
+   config_output_interval = 19200
+   config_stats_interval = 1920
 /
 
 &amp;io
@@ -17,29 +16,32 @@
 &amp;restart
    config_restart_interval = 115200
    config_do_restart = .false.
-   config_restart_time = 1036800.0
+   config_restart_time = 31104000
 /
 
 &amp;grid
-   config_vert_grid_type = 'zlevel'
-   config_rho0 = 1028
+   config_vert_grid_type = 'isopycnal'
+   config_rho0 = 1015
 /
 &amp;hmix
-   config_hor_diffusion  = 1.0e4
+   config_h_mom_eddy_visc2 = 0.0
+   config_h_mom_eddy_visc4 = 5.0e8
+   config_h_tracer_eddy_diff2 = 10.0
+   config_h_tracer_eddy_diff4 = 0.0
 /
 &amp;vmix
-   config_vert_visc_type  = 'tanh'
-   config_vert_diff_type  = 'tanh'
+   config_vert_visc_type  = 'const'
+   config_vert_diff_type  = 'const'
    config_vmixTanhViscMax = 2.5e-1
    config_vmixTanhViscMin = 1.0e-4
    config_vmixTanhDiffMax = 2.5e-2
    config_vmixTanhDiffMin = 1.0e-5
    config_vmixTanhZMid    = -100
    config_vmixTanhZWidth  = 100
-   config_vert_viscosity  = 2.5e-4
-   config_vert_diffusion  = 2.5e-5 
+   config_vert_viscosity  = 1.0e-4
+   config_vert_diffusion  = 1.0e-4
 /
 &amp;advection
-   config_hor_tracer_adv = 'upwind'
-   config_vert_tracer_adv = 'upwind'
+   config_hor_tracer_adv = 'centered'
+   config_vert_tracer_adv = 'centered'
 /

Modified: branches/atmos_physics/namelist.input.sw
===================================================================
--- branches/atmos_physics/namelist.input.sw        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/namelist.input.sw        2010-10-13 20:25:17 UTC (rev 549)
@@ -4,6 +4,7 @@
    config_dt = 172.8
    config_ntimesteps = 7500
    config_output_interval = 500
+   config_stats_interval = 0
    config_visc  = 0.0
 /
 

Modified: branches/atmos_physics/src/core_hyd_atmos/Registry
===================================================================
--- branches/atmos_physics/src/core_hyd_atmos/Registry        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_hyd_atmos/Registry        2010-10-13 20:25:17 UTC (rev 549)
@@ -18,6 +18,7 @@
 namelist logical   sw_model config_positive_definite    false
 namelist logical   sw_model config_monotonic            true
 namelist integer   sw_model config_mp_physics           0
+namelist integer   dimensions config_nvertlevels        26
 namelist character io       config_input_name           grid.nc
 namelist character io       config_output_name          output.nc
 namelist character io       config_restart_name         restart.nc
@@ -38,144 +39,159 @@
 dim FIFTEEN 15
 dim TWENTYONE 21
 dim R3 3
-dim nVertLevels nVertLevels
+#dim nVertLevels nVertLevels
+dim nVertLevels namelist:config_nvertlevels
 #dim nTracers nTracers
 dim nVertLevelsP1 nVertLevels+1
 
 #
-# var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
+# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
 #
-var real    xtime ( Time ) ro xtime - -
+var persistent real    xtime ( Time ) 2 ro xtime state - -
 
-var real    latCell ( nCells ) iro latCell - -
-var real    lonCell ( nCells ) iro lonCell - -
-var real    xCell ( nCells ) iro xCell - -
-var real    yCell ( nCells ) iro yCell - -
-var real    zCell ( nCells ) iro zCell - -
-var integer indexToCellID ( nCells ) iro indexToCellID - -
+var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
+var persistent real    lonCell ( nCells ) 0 iro lonCell mesh - -
+var persistent real    xCell ( nCells ) 0 iro xCell mesh - -
+var persistent real    yCell ( nCells ) 0 iro yCell mesh - -
+var persistent real    zCell ( nCells ) 0 iro zCell mesh - -
+var persistent integer indexToCellID ( nCells ) 0 iro indexToCellID mesh - -
 
-var real    latEdge ( nEdges ) iro latEdge - -
-var real    lonEdge ( nEdges ) iro lonEdge - -
-var real    xEdge ( nEdges ) iro xEdge - -
-var real    yEdge ( nEdges ) iro yEdge - -
-var real    zEdge ( nEdges ) iro zEdge - -
-var integer indexToEdgeID ( nEdges ) iro indexToEdgeID - -
+var persistent real    latEdge ( nEdges ) 0 iro latEdge mesh - -
+var persistent real    lonEdge ( nEdges ) 0 iro lonEdge mesh - -
+var persistent real    xEdge ( nEdges ) 0 iro xEdge mesh - -
+var persistent real    yEdge ( nEdges ) 0 iro yEdge mesh - -
+var persistent real    zEdge ( nEdges ) 0 iro zEdge mesh - -
+var persistent integer indexToEdgeID ( nEdges ) 0 iro indexToEdgeID mesh - -
 
-var real    latVertex ( nVertices ) iro latVertex - -
-var real    lonVertex ( nVertices ) iro lonVertex - -
-var real    xVertex ( nVertices ) iro xVertex - -
-var real    yVertex ( nVertices ) iro yVertex - -
-var real    zVertex ( nVertices ) iro zVertex - -
-var integer indexToVertexID ( nVertices ) iro indexToVertexID - -
+var persistent real    latVertex ( nVertices ) 0 iro latVertex mesh - -
+var persistent real    lonVertex ( nVertices ) 0 iro lonVertex mesh - -
+var persistent real    xVertex ( nVertices ) 0 iro xVertex mesh - -
+var persistent real    yVertex ( nVertices ) 0 iro yVertex mesh - -
+var persistent real    zVertex ( nVertices ) 0 iro zVertex mesh - -
+var persistent integer indexToVertexID ( nVertices ) 0 iro indexToVertexID mesh - -
 
-var integer cellsOnEdge ( TWO nEdges ) iro cellsOnEdge - -
-var integer nEdgesOnCell ( nCells ) iro nEdgesOnCell - -
-var integer nEdgesOnEdge ( nEdges ) iro nEdgesOnEdge - -
-var integer edgesOnCell ( maxEdges nCells ) iro edgesOnCell - -
-var integer edgesOnEdge ( maxEdges2 nEdges ) iro edgesOnEdge - -
+var persistent integer cellsOnEdge ( TWO nEdges ) 0 iro cellsOnEdge mesh - -
+var persistent integer nEdgesOnCell ( nCells ) 0 iro nEdgesOnCell mesh - -
+var persistent integer nEdgesOnEdge ( nEdges ) 0 iro nEdgesOnEdge mesh - -
+var persistent integer edgesOnCell ( maxEdges nCells ) 0 iro edgesOnCell mesh - -
+var persistent integer edgesOnEdge ( maxEdges2 nEdges ) 0 iro edgesOnEdge mesh - -
 
-var real    weightsOnEdge ( maxEdges2 nEdges ) iro weightsOnEdge - -
-var real    dvEdge ( nEdges ) iro dvEdge - -
-var real    dcEdge ( nEdges ) iro dcEdge - -
-var real    angleEdge ( nEdges ) iro angleEdge - -
-var real    areaCell ( nCells ) iro areaCell - -
-var real    areaTriangle ( nVertices ) iro areaTriangle - -
+var persistent real    weightsOnEdge ( maxEdges2 nEdges ) 0 iro weightsOnEdge mesh - -
+var persistent real    dvEdge ( nEdges ) 0 iro dvEdge mesh - -
+var persistent real    dcEdge ( nEdges ) 0 iro dcEdge mesh - -
+var persistent real    angleEdge ( nEdges ) 0 iro angleEdge mesh - -
+var persistent real    areaCell ( nCells ) 0 iro areaCell mesh - -
+var persistent real    areaTriangle ( nVertices ) 0 iro areaTriangle mesh - -
 
-var real    edgeNormalVectors ( R3 nEdges ) o edgeNormalVectors - -
-var real    localVerticalUnitVectors ( R3 nCells ) o localVerticalUnitVectors - -
-var real    cellTangentPlane ( R3 TWO nEdges ) o cellTangentPlane - -
+var persistent real    edgeNormalVectors ( R3 nEdges ) 0 o edgeNormalVectors mesh - -
+var persistent real    localVerticalUnitVectors ( R3 nCells ) 0 o localVerticalUnitVectors mesh - -
+var persistent real    cellTangentPlane ( R3 TWO nEdges ) 0 o cellTangentPlane mesh - -
 
-var integer cellsOnCell ( maxEdges nCells ) iro cellsOnCell - -
-var integer verticesOnCell ( maxEdges nCells ) iro verticesOnCell - -
-var integer verticesOnEdge ( TWO nEdges ) iro verticesOnEdge - -
-var integer edgesOnVertex ( vertexDegree nVertices ) iro edgesOnVertex - -
-var integer cellsOnVertex ( vertexDegree nVertices ) iro cellsOnVertex - -
-var real    kiteAreasOnVertex ( vertexDegree nVertices ) iro kiteAreasOnVertex - -
-var real    fEdge ( nEdges ) iro fEdge - -
-var real    fVertex ( nVertices ) iro fVertex - -
-var real    h_s ( nCells ) iro h_s - -
+var persistent integer cellsOnCell ( maxEdges nCells ) 0 iro cellsOnCell mesh - -
+var persistent integer verticesOnCell ( maxEdges nCells ) 0 iro verticesOnCell mesh - -
+var persistent integer verticesOnEdge ( TWO nEdges ) 0 iro verticesOnEdge mesh - -
+var persistent integer edgesOnVertex ( vertexDegree nVertices ) 0 iro edgesOnVertex mesh - -
+var persistent integer cellsOnVertex ( vertexDegree nVertices ) 0 iro cellsOnVertex mesh - -
+var persistent real    kiteAreasOnVertex ( vertexDegree nVertices ) 0 iro kiteAreasOnVertex mesh - -
+var persistent real    fEdge ( nEdges ) 0 iro fEdge mesh - -
+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
-var real    rdnu ( nVertLevels ) iro rdnu - -
-var real    rdnw ( nVertLevels ) iro rdnw - -
-var real    fnm ( nVertLevels ) iro fnm - -
-var real    fnp ( nVertLevels ) iro fnp - -
-var real    dbn ( nVertLevels ) iro dbn - -
-var real    dnu ( nVertLevels ) iro dnu - -
-var real    dnw ( nVertLevels ) iro dnw - -
+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 - -
+var persistent real    fnp ( nVertLevels ) 0 iro fnp mesh - -
+var persistent real    dbn ( nVertLevels ) 0 iro dbn mesh - -
+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
-var real    u ( nVertLevels nEdges Time ) iro u - -
-var real    theta ( nVertLevels nCells Time ) iro theta - -
-var real    surface_pressure ( nCells Time ) iro surface_pressure - -
-var real    qv ( nVertLevels nCells Time ) iro qv scalars moist
-var real    qc ( nVertLevels nCells Time ) iro qc scalars moist
-var real    qr ( nVertLevels nCells Time ) iro qr scalars moist
-var real    qi ( nVertLevels nCells Time ) iro qi scalars moist
-var real    qs ( nVertLevels nCells Time ) iro qs scalars moist
-var real    qg ( nVertLevels nCells Time ) iro qg scalars moist
-var real    qnr ( nVertLevels nCells Time ) iro qnr scalars number
-var real    qni ( nVertLevels nCells Time ) iro qni scalars number
-var real    h_diabatic ( nVertLevels nCells Time ) ro h_diabatic - -
-#var real    tracers ( nTracers nVertLevels nCells Time ) iro tracers - -
+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    qi ( nVertLevels nCells Time ) 2 iro qi state scalars moist
+var persistent real    qs ( nVertLevels nCells Time ) 2 iro qs state scalars moist
+var persistent real    qg ( nVertLevels nCells Time ) 2 iro qg state scalars moist
+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
+var persistent real    h_diabatic ( nVertLevels nCells Time ) 2 ro h_diabatic state - -
+#var persistent real    tracers ( nTracers nVertLevels nCells Time ) 2 iro tracers state - -
 
 # state variables diagnosed from prognostic state
-var real    h ( nVertLevels nCells Time ) ro h - -
-var real    ww ( nVertLevelsP1 nCells Time ) ro ww - -
-var real    w ( nVertLevelsP1 nCells Time ) ro w - -
-var real    pressure ( nVertLevelsP1 nCells Time ) ro pressure - -
-var real    geopotential ( nVertLevelsP1 nCells Time ) ro geopotential - -
-var real    alpha ( nVertLevels nCells Time ) iro alpha - -
+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 - -
+var persistent real    pressure ( nVertLevelsP1 nCells Time ) 2 ro pressure state - -
+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
-var real    v ( nVertLevels nEdges Time ) o v - -
-var real    divergence ( nVertLevels nCells Time ) o divergence - -
-var real    vorticity ( nVertLevels nVertices Time ) o vorticity - -
-var real    pv_edge ( nVertLevels nEdges Time ) o pv_edge - -
-var real    h_edge ( nVertLevels nEdges Time ) o h_edge - -
-var real    ke ( nVertLevels nCells Time ) o ke - -
-var real    pv_vertex ( nVertLevels nVertices Time ) o pv_vertex - -
-var real    pv_cell ( nVertLevels nCells Time ) o pv_cell - -
-var real    uReconstructX ( nVertLevels nCells Time ) o uReconstructX - -
-var real    uReconstructY ( nVertLevels nCells Time ) o uReconstructY - -
-var real    uReconstructZ ( nVertLevels nCells Time ) o uReconstructZ - -
-var real    uReconstructZonal ( nVertLevels nCells Time ) o uReconstructZonal - -
-var real    uReconstructMeridional ( nVertLevels nCells Time ) o uReconstructMeridional - -
+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 - -
+var persistent real    pv_edge ( nVertLevels nEdges Time ) 2 o pv_edge state - -
+var persistent real    h_edge ( nVertLevels nEdges Time ) 2 o h_edge state - -
+var persistent real    ke ( nVertLevels nCells Time ) 2 o ke state - -
+var persistent real    pv_vertex ( nVertLevels nVertices Time ) 2 o pv_vertex state - -
+var persistent real    pv_cell ( nVertLevels nCells Time ) 2 o pv_cell state - -
+var persistent real    uReconstructX ( nVertLevels nCells Time ) 1 o uReconstructX diag - -
+var persistent real    uReconstructY ( nVertLevels nCells Time ) 1 o uReconstructY diag - -
+var persistent real    uReconstructZ ( nVertLevels nCells Time ) 1 o uReconstructZ diag - -
+var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 1 o uReconstructZonal diag - -
+var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 1 o uReconstructMeridional diag - -
 
+# 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 - -
+var persistent real    tend_theta ( nVertLevels nCells Time ) 1 - theta tend - -
+var persistent real    tend_qv ( nVertLevels nCells Time ) 1 - qv tend scalars moist
+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
+var persistent real    tend_qi ( nVertLevels nCells Time ) 1 - qi tend scalars moist
+var persistent real    tend_qs ( nVertLevels nCells Time ) 1 - qs tend scalars moist
+var persistent real    tend_qg ( nVertLevels nCells Time ) 1 - qg tend scalars moist
+var persistent real    tend_qnr ( nVertLevels nCells Time ) 1 - qnr tend scalars number
+var persistent real    tend_qni ( nVertLevels nCells Time ) 1 - qni tend scalars number
+
 # Other diagnostic variables: neither read nor written to any files
-var real    vh ( nVertLevels nEdges Time ) - vh - -
-var real    circulation ( nVertLevels nVertices Time ) - circulation - -
-var real    gradPVt ( nVertLevels nEdges Time ) - gradPVt - -
-var real    gradPVn ( nVertLevels nEdges Time ) - gradPVn - -
+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 - -
 
-var real    uhAvg ( nVertLevels nEdges ) - uhAvg - -
-var real    wwAvg ( nVertLevelsP1 nCells ) - wwAvg - -
-var real    qtot ( nVertLevels nCells ) - qtot - -
-var real    cqu  ( nVertLevels nEdges ) - cqu - -
-var real    dpsdt ( nCells ) - dpsdt - -
+var persistent real    uhAvg ( nVertLevels nEdges ) 0 - uhAvg mesh - -
+var persistent real    wwAvg ( nVertLevelsP1 nCells ) 0 - wwAvg mesh - -
+var persistent real    qtot ( nVertLevels nCells ) 0 - qtot mesh - -
+var persistent real    cqu  ( nVertLevels nEdges ) 0 - cqu mesh - -
+var persistent real    dpsdt ( nCells ) 0 - dpsdt mesh - -
 
-var real    u_old ( nVertLevels nEdges ) - u_old - -
-var real    ww_old ( nVertLevelsP1 nCells ) - ww_old - -
-var real    theta_old ( nVertLevels nCells ) - theta_old - -
-var real    h_edge_old ( nVertLevels nEdges ) - h_edge_old - -
-var real    h_old ( nVertLevels nCells ) - h_old - -
-var real    pressure_old ( nVertLevelsP1 nCells ) - pressure_old - -
-var real    qv_old ( nVertLevels nCells ) - qv_old scalars_old moist_old
-var real    qc_old ( nVertLevels nCells ) - qc_old scalars_old moist_old
-var real    qr_old ( nVertLevels nCells ) - qr_old scalars_old moist_old
-var real    qi_old ( nVertLevels nCells ) - qi_old scalars_old moist_old
-var real    qs_old ( nVertLevels nCells ) - qs_old scalars_old moist_old
-var real    qg_old ( nVertLevels nCells ) - qg_old scalars_old moist_old
-var real    qnr_old ( nVertLevels nCells Time ) - qnr_old scalars_old number_old
-var real    qni_old ( nVertLevels nCells Time ) - qni_old scalars_old number_old
-#var real    tracers_old ( nTracers nVertLevels nCells ) - tracers_old - -
+var persistent real    u_old ( nVertLevels nEdges ) 0 - u_old mesh - -
+var persistent real    ww_old ( nVertLevelsP1 nCells ) 0 - ww_old mesh - -
+var persistent real    theta_old ( nVertLevels nCells ) 0 - theta_old mesh - -
+var persistent real    h_edge_old ( nVertLevels nEdges ) 0 - h_edge_old mesh - -
+var persistent real    h_old ( nVertLevels nCells ) 0 - h_old mesh - -
+var persistent real    pressure_old ( nVertLevelsP1 nCells ) 0 - pressure_old mesh - -
+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    qi_old ( nVertLevels nCells ) 0 - qi_old mesh scalars_old moist_old
+var persistent real    qs_old ( nVertLevels nCells ) 0 - qs_old mesh scalars_old moist_old
+var persistent real    qg_old ( nVertLevels nCells ) 0 - qg_old mesh scalars_old moist_old
+var persistent real    qnr_old ( nVertLevels nCells ) 0 - qnr_old mesh scalars_old number_old
+var persistent real    qni_old ( nVertLevels nCells ) 0 - qni_old mesh scalars_old number_old
+#var persistent real    tracers_old ( nTracers nVertLevels nCells ) 0 - tracers_old mesh - -
 
 # Space needed for advection
-var real    deriv_two ( FIFTEEN TWO nEdges ) o deriv_two - -
-var integer advCells ( TWENTYONE nCells ) - advCells - -
+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
-var real    coeffs_reconstruct ( R3 maxEdges nCells ) - coeffs_reconstruct - -
+var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
 #==================================================================================================
 # DECLARATIONS OF ALL PHYSICS VARIABLES (will need to be moved to a Physics Registry shared by the
@@ -207,12 +223,12 @@
 # qi_col    : vertically-integrated cloud ice mixing ratio                                  (kg/m2)
 # qs_col    &quot; vertically-integrated snow mixing ratio                                       (kg/m2)
 
-var real    qv_col     ( nCells Time             )  o  qv_col     - -
-var real    qc_col     ( nCells Time             )  o  qc_col     - -
-var real    qr_col     ( nCells Time             )  o  qr_col     - -
-var real    qi_col     ( nCells Time             )  o  qi_col     - -
-var real    qs_col     ( nCells Time             )  o  qs_col     - -
-var real    qg_col     ( nCells Time             )  o  qg_col     - -
+var persistent real    qv_col     ( nCells Time             ) 2  o  qv_col     state - -
+var persistent real    qc_col     ( nCells Time             ) 2  o  qc_col     state - -
+var persistent real    qr_col     ( nCells Time             ) 2  o  qr_col     state - -
+var persistent real    qi_col     ( nCells Time             ) 2  o  qi_col     state - -
+var persistent real    qs_col     ( nCells Time             ) 2  o  qs_col     state - -
+var persistent real    qg_col     ( nCells Time             ) 2  o  qg_col     state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF CLOUD MICROPHYSICS:
@@ -226,13 +242,13 @@
 # graupelncv: time-step grid-scale precipitation of graupel                                    (mm)
 # sr        : time-step ratio of frozen versus total grid-scale precipitation                   (-)
 
-var real    rainnc     ( nCells Time             )  ro rainnc     - -
-var real    rainncv    ( nCells Time             )  ro rainncv    - -
-var real    snownc     ( nCells Time             )  ro snownc     - -
-var real    snowncv    ( nCells Time             )  ro snowncv    - -
-var real    graupelnc  ( nCells Time             )  ro graupelnc  - -
-var real    graupelncv ( nCells Time             )  ro graupelncv - -
-var real    sr         ( nCells Time             )   o sr         - -
+var persistent real    rainnc     ( nCells Time             ) 2  ro rainnc     state - -
+var persistent real    rainncv    ( nCells Time             ) 2  ro rainncv    state - -
+var persistent real    snownc     ( nCells Time             ) 2  ro snownc     state - -
+var persistent real    snowncv    ( nCells Time             ) 2  ro snowncv    state - -
+var persistent real    graupelnc  ( nCells Time             ) 2  ro graupelnc  state - -
+var persistent real    graupelncv ( nCells Time             ) 2  ro graupelncv state - -
+var persistent real    sr         ( nCells Time             ) 2   o sr         state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF CONVECTION:
@@ -251,22 +267,22 @@
 # rqscuten  : tendency of snow mixing ratio due to cumulus convection                   (kg/kg s-1)
 # wavg      : average vertical velocity (KF scheme only)                                    (m s-1)
 
-var real    nca      ( nCells Time             )  ro  nca         - -
-var real    cubot    ( nCells Time             )  ro  cubot       - -
-var real    cutop    ( nCells Time             )  ro  cutop       - -
+var persistent real    nca      ( nCells Time             ) 2  ro  nca         state - -
+var persistent real    cubot    ( nCells Time             ) 2  ro  cubot       state - -
+var persistent real    cutop    ( nCells Time             ) 2  ro  cutop       state - -
 
 # PRECIPITATION:
-var real    rainc    ( nCells Time             )  ro rainc        - -
-var real    raincv   ( nCells Time             )  ro raincv       - -
+var persistent real    rainc    ( nCells Time             ) 2  ro rainc        state - -
+var persistent real    raincv   ( nCells Time             ) 2  ro raincv       state - -
 
 #    TENDENCIES:
-var real    rthcuten ( nVertLevels nCells Time )  ro rthcuten     - -
-var real    rqvcuten ( nVertLevels nCells Time )  ro rqvcuten     - -
-var real    rqccuten ( nVertLevels nCells Time )  ro rqccuten     - -
-var real    rqrcuten ( nVertLevels nCells Time )  ro rqrcuten     - -
-var real    rqicuten ( nVertLevels nCells Time )  ro rqicuten     - -
-var real    rqscuten ( nVertLevels nCells Time )  ro rqscuten     - -
-var real    w0avg    ( nVertLevels nCells Time )  ro w0avg        - -
+var persistent real    rthcuten ( nVertLevels nCells Time ) 2  ro rthcuten     state - -
+var persistent real    rqvcuten ( nVertLevels nCells Time ) 2  ro rqvcuten     state - -
+var persistent real    rqccuten ( nVertLevels nCells Time ) 2  ro rqccuten     state - -
+var persistent real    rqrcuten ( nVertLevels nCells Time ) 2  ro rqrcuten     state - -
+var persistent real    rqicuten ( nVertLevels nCells Time ) 2  ro rqicuten     state - -
+var persistent real    rqscuten ( nVertLevels nCells Time ) 2  ro rqscuten     state - -
+var persistent real    w0avg    ( nVertLevels nCells Time ) 2  ro w0avg        state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF PLANETARY BOUNDARY LAYER PROCESSES:
@@ -278,12 +294,12 @@
 # rqiblten  : tendency of cloud ice mixing ratio due to pbl processes                   (kg/kg s-1)
 
 #    TENDENCIES:
-var real    rublten  ( nVertLevels nCells Time )  ro rublten      - -
-var real    rvblten  ( nVertLevels nCells Time )  ro rvblten      - -
-var real    rthblten ( nVertLevels nCells Time )  ro rthblten     - -
-var real    rqvblten ( nVertLevels nCells Time )  ro rqvblten     - -
-var real    rqcblten ( nVertLevels nCells Time )  ro rqcblten     - -
-var real    rqiblten ( nVertLevels nCells Time )  ro rqiblten     - -
+var persistent real    rublten  ( nVertLevels nCells Time ) 2  ro rublten      state - -
+var persistent real    rvblten  ( nVertLevels nCells Time ) 2  ro rvblten      state - -
+var persistent real    rthblten ( nVertLevels nCells Time ) 2  ro rthblten     state - -
+var persistent real    rqvblten ( nVertLevels nCells Time ) 2  ro rqvblten     state - -
+var persistent real    rqcblten ( nVertLevels nCells Time ) 2  ro rqcblten     state - -
+var persistent real    rqiblten ( nVertLevels nCells Time ) 2  ro rqiblten     state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF SURFACE LAYER PROCESSES:
@@ -311,26 +327,26 @@
 # xland    :land mask (1 for land; 2 for water)                                                 [-]
 # znt      :time-varying roughness length                                                       [m]
 
-var real    flhc     ( nCells Time             )  r  flhc         - -
-var real    flqc     ( nCells Time             )  r  flqc         - -
-var real    hfx      ( nCells Time             )  r  hfx          - -
-var real    lh       ( nCells Time             )  r  lh           - -
-var real    mavail   ( nCells Time             )  r  mavail       - -
-var real    mol      ( nCells Time             )  r  mol          - -
-var real    pblh     ( nCells Time             )  r  pblh         - -
-var real    q2       ( nCells Time             )  r  q2           - -
-var real    qfx      ( nCells Time             )  r  qfx          - -
-var real    qsfc     ( nCells Time             )  r  qsfc         - -
-var real    regime   ( nCells Time             )  r  regime       - -
-var real    rmol     ( nCells Time             )  r  rmol         - -
-var real    t2       ( nCells Time             )  r  t2           - -
-var real    tsk      ( nCells Time             )  r  tsk          - -
-var real    th2      ( nCells Time             )  r  th2          - -
-var real    u10      ( nCells Time             )  r  u10          - -
-var real    ust      ( nCells Time             )  r  ust          - -
-var real    ustm     ( nCells Time             )  r  ustm         - -
-var real    v10      ( nCells Time             )  r  v10          - -
-var real    xland    ( nCells Time             )  r  xland        - -
-var real    znt      ( nCells Time             )  r  znt          - -
+var persistent real    flhc     ( nCells Time             ) 2  r  flhc         state - -
+var persistent real    flqc     ( nCells Time             ) 2  r  flqc         state - -
+var persistent real    hfx      ( nCells Time             ) 2  r  hfx          state - -
+var persistent real    lh       ( nCells Time             ) 2  r  lh           state - -
+var persistent real    mavail   ( nCells Time             ) 2  r  mavail       state - -
+var persistent real    mol      ( nCells Time             ) 2  r  mol          state - -
+var persistent real    pblh     ( nCells Time             ) 2  r  pblh         state - -
+var persistent real    q2       ( nCells Time             ) 2  r  q2           state - -
+var persistent real    qfx      ( nCells Time             ) 2  r  qfx          state - -
+var persistent real    qsfc     ( nCells Time             ) 2  r  qsfc         state - -
+var persistent real    regime   ( nCells Time             ) 2  r  regime       state - -
+var persistent real    rmol     ( nCells Time             ) 2  r  rmol         state - -
+var persistent real    t2       ( nCells Time             ) 2  r  t2           state - -
+var persistent real    tsk      ( nCells Time             ) 2  r  tsk          state - -
+var persistent real    th2      ( nCells Time             ) 2  r  th2          state - -
+var persistent real    u10      ( nCells Time             ) 2  r  u10          state - -
+var persistent real    ust      ( nCells Time             ) 2  r  ust          state - -
+var persistent real    ustm     ( nCells Time             ) 2  r  ustm         state - -
+var persistent real    v10      ( nCells Time             ) 2  r  v10          state - -
+var persistent real    xland    ( nCells Time             ) 2  r  xland        state - -
+var persistent real    znt      ( nCells Time             ) 2  r  znt          state - -
 
 #==================================================================================================

Modified: branches/atmos_physics/src/core_hyd_atmos/module_advection.F
===================================================================
--- branches/atmos_physics/src/core_hyd_atmos/module_advection.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_hyd_atmos/module_advection.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -17,7 +17,7 @@
 !
       implicit none
 
-      type (grid_meta), intent(in) :: grid
+      type (mesh_type), intent(in) :: grid
 
       real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
       integer, dimension(:,:), pointer :: advCells

Modified: branches/atmos_physics/src/core_hyd_atmos/module_test_cases.F
===================================================================
--- branches/atmos_physics/src/core_hyd_atmos/module_test_cases.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_hyd_atmos/module_test_cases.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -35,9 +35,9 @@
          if (config_test_case == 3) write(0,*) ' normal-mode perturbation included '
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call hyd_test_case_1(block_ptr % mesh, block_ptr % time_levs(1) % state, config_test_case)
+            call hyd_test_case_1(block_ptr % mesh, block_ptr % state % time_levs(1) % state, config_test_case)
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -59,8 +59,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
       integer, intent(in) :: test_case
 
       real (kind=RKIND), parameter :: u0 = 35.0
@@ -78,7 +78,7 @@
       real (kind=RKIND), dimension(:,:), pointer :: pressure, theta, alpha, geopotential, h
       real (kind=RKIND), dimension(:,:,:), pointer :: scalars
 
-      integer :: iCell, iEdge, vtx1, vtx2, ivtx, k, nz, nz1
+      integer :: iCell, iEdge, vtx1, vtx2, ivtx, k, nz, nz1, index_qv
       real (kind=RKIND) :: u, v, flux, fluxk, lat1, lat2, eta_v, r_pert, u_pert, lat_pert, lon_pert, r
 
       real (kind=RKIND) :: ptop, p0, phi
@@ -129,6 +129,8 @@
       grid % areaCell % array = grid % areaCell % array * a**2.0
       grid % areaTriangle % array = grid % areaTriangle % array * a**2.0
       grid % kiteAreasOnVertex % array = grid % kiteAreasOnVertex % array * a**2.0
+
+      index_qv = state % index_qv
       
       nz1 = grid % nVertLevels
       nz = nz1 + 1

Modified: branches/atmos_physics/src/core_hyd_atmos/module_time_integration.F
===================================================================
--- branches/atmos_physics/src/core_hyd_atmos/module_time_integration.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_hyd_atmos/module_time_integration.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -42,7 +42,7 @@
 
       block =&gt; domain % blocklist
       do while (associated(block))
-         block % time_levs(2) % state % xtime % scalar = block % time_levs(1) % state % xtime % scalar + dt
+         block % state % time_levs(2) % state % xtime % scalar = block % state % time_levs(1) % state % xtime % scalar + dt
          block =&gt; block % next
       end do
 
@@ -71,7 +71,6 @@
       integer :: iCell, k
       type (block_type), pointer :: block
 
-      integer, parameter :: TEND   = 1
       integer :: rk_step, number_of_sub_steps
       integer :: iScalar
 
@@ -107,7 +106,7 @@
 
       block =&gt; domain % blocklist
       do while (associated(block))
-         call copy_state( block % time_levs(1) % state, block % time_levs(2) % state )
+         call copy_state( block % state % time_levs(2) % state, block % state % time_levs(1) % state )
          block =&gt; block % next
       end do
 
@@ -128,26 +127,26 @@
            call dmpar_exch_halo_field2dReal(domain % dminfo, block % mesh % cqu % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                             block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % h % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % h % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pressure % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % pressure % array(:,:), &amp;
                                             block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % geopotential % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % geopotential % array(:,:), &amp;
                                             block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % alpha % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % alpha % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pv_edge % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(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 dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % divergence % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(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 dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % vorticity % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(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
@@ -158,20 +157,20 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call compute_dyn_tend( block % intermediate_step(TEND), block % time_levs(2) % state, block % mesh )
+           call compute_dyn_tend( block % tend, block % state % time_levs(2) % state, block % mesh )
            block =&gt; block % next
         end do
-        
+
         if(debug) write(0,*) ' returned from dyn_tend '
 
 !#ifdef DO_PHYSICS
 !       if (debug) write(0,*) ' add physics tendencies '
 !       block =&gt; domain % blocklist
 !       do while (associated(block))
-!          call physics_addtend( block % intermediate_step(TEND), block % time_levs(2) % state, &amp;
-!                                block % time_levs(2) % state % h % array, block % mesh )
-!          call dmpar_exch_halo_field3dReal(domain % dminfo, block % intermediate_step(TEND) % scalars % array(:,:,:), &amp;
-!                                           num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+!          call physics_addtend( block % tend, block % state % time_levs(2) % state, &amp;
+!                                block % state % time_levs(2) % state % h % array, block % mesh )
+!          call dmpar_exch_halo_field3dReal(domain % dminfo, block % tend % scalars % array(:,:,:), &amp;
+!                                           block % state % time_levs(2) % state % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
 !                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
 !          block =&gt; block % next
 !       end do
@@ -183,12 +182,12 @@
         !
         block =&gt; domain % blocklist
         do while (associated(block))
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % u % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % u % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                             block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % theta % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % theta % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nCells, &amp;
-                                            block % parinfo % cellsToSend, block % parinfo % cellsToRecv)                                 
+                                            block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
            block =&gt; block % next
         end do
 
@@ -202,9 +201,9 @@
            !    from the previous RK step are needed to compute new scalar tendencies in advance_scalars. 
            !    A cleaner way of preserving scalars should be added in future.
            !
-           block % mesh % scalars_old % array(:,:,:) = block % time_levs(2) % state % scalars % array(:,:,:)
-           call copy_state( block % time_levs(1) % state, block % time_levs(2) % state )
-           block % time_levs(2) % state % scalars % array(:,:,:) = block % mesh % scalars_old % array(:,:,:)
+           block % mesh % scalars_old % array(:,:,:) = block % state % time_levs(2) % state % scalars % array(:,:,:)
+           call copy_state( block % state % time_levs(2) % state, block % state % time_levs(1) % state )
+           block % state % time_levs(2) % state % scalars % array(:,:,:) = block % mesh % scalars_old % array(:,:,:)
            block =&gt; block % next
         end do
 
@@ -216,8 +215,8 @@
       
            block =&gt; domain % blocklist
            do while (associated(block))
-              call advance_dynamics( block % intermediate_step(TEND), block % time_levs(2) % state,  &amp;
-                                     block % mesh,small_step, number_sub_steps(rk_step),             &amp;
+              call advance_dynamics( block % tend, block % state % time_levs(2) % state,  &amp;
+                                     block % mesh, small_step, number_sub_steps(rk_step),             &amp;
                                      rk_sub_timestep(rk_step), rk_step )
               block =&gt; block % next
            end do
@@ -230,10 +229,10 @@
            !
            block =&gt; domain % blocklist
            do while (associated(block))
-!!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % u % array(:,:), &amp;
+!!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % u % array(:,:), &amp;
 !!                                               block % mesh % nVertLevels, block % mesh % nEdges, &amp;
 !!                                               block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % h_edge % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % h_edge % array(:,:), &amp;
                                                block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                                block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
 !!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % mesh % uhAvg % array(:,:), &amp;
@@ -242,34 +241,34 @@
 !!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % mesh % wwAvg % array(:,:), &amp;
 !!                                               block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
 !!                                               block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % theta % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % theta % array(:,:), &amp;
                                                block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-!!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % h % array(:,:), &amp;
+!!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % h % array(:,:), &amp;
 !!                                               block % mesh % nVertLevels, block % mesh % nCells, &amp;
 !!                                               block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-!!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % h % array(:,:), &amp;
+!!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % h % array(:,:), &amp;
 !!                                               block % mesh % nVertLevels, block % mesh % nCells, &amp;
 !!                                               block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
               call dmpar_exch_halo_field1dReal(domain % dminfo, block % mesh % dpsdt % array(:), &amp;
                                                block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call dmpar_exch_halo_field1dReal(domain % dminfo, block % time_levs(2) % state % surface_pressure % array(:), &amp;
+              call dmpar_exch_halo_field1dReal(domain % dminfo, block % state % time_levs(2) % state % surface_pressure % array(:), &amp;
                                                block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % alpha % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % alpha % array(:,:), &amp;
                                                block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % ww % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % ww % array(:,:), &amp;
                                                block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pressure % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % pressure % array(:,:), &amp;
                                                block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
 !!              call dmpar_exch_halo_field2dReal(domain % dminfo, block % mesh % pressure_old % array(:,:), &amp;
 !!                                               block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
 !!                                               block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-              call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % geopotential % array(:,:), &amp;
+              call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % geopotential % array(:,:), &amp;
                                                block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                                block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
               block =&gt; block % next
@@ -279,6 +278,7 @@
 
         if(debug) write(0,*) ' advance scalars '
 
+
         ! ---  advance scalars with time integrated mass fluxes
 
         block =&gt; domain % blocklist
@@ -289,28 +289,25 @@
            !       so we keep the advance_scalars routine as well
            !
            if (rk_step &lt; 3 .or. (.not. config_monotonic .and. .not. config_positive_definite)) then
-
-              call advance_scalars( block % intermediate_step(TEND),                            &amp;
-                                    block % time_levs(1) % state, block % time_levs(2) % state, &amp;
+              call advance_scalars( block % tend,                                                               &amp;
+                                    block % state % time_levs(1) % state, block % state % time_levs(2) % state, &amp;
                                     block % mesh, rk_timestep(rk_step) )
            else
-
-              call advance_scalars_mono( block % intermediate_step(TEND),                            &amp;
-                                         block % time_levs(1) % state, block % time_levs(2) % state, &amp;
-                                         block % mesh, rk_timestep(rk_step), rk_step, 3, &amp;
+              call advance_scalars_mono( block % tend,                                                               &amp;
+                                         block % state % time_levs(1) % state, block % state % time_levs(2) % state, &amp;
+                                         block % mesh, rk_timestep(rk_step), rk_step, 3,                             &amp;
                                          domain % dminfo, block % parinfo % cellsToSend, block % parinfo % cellsToRecv )
            end if
-
            block =&gt; block % next
         end do
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call dmpar_exch_halo_field3dReal(domain % dminfo, block % intermediate_step(TEND) % scalars % array(:,:,:), &amp;
-                                            num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+           call dmpar_exch_halo_field3dReal(domain % dminfo, block % tend % scalars % array(:,:,:), &amp;
+                                            block % tend % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field3dReal(domain % dminfo, block % time_levs(2) % state % scalars % array(:,:,:), &amp;
-                                            num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+           call dmpar_exch_halo_field3dReal(domain % dminfo, block % state % time_levs(2) % state % scalars % array(:,:,:), &amp;
+                                            block % tend % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
            block =&gt; block % next
         end do
@@ -322,9 +319,9 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call compute_solver_constants( block % time_levs(2) % state, block % mesh )
-           call compute_state_diagnostics( block % time_levs(2) % state, block % mesh )
-           call compute_solve_diagnostics( dt, block % time_levs(2) % state, block % mesh )
+           call compute_solver_constants( block % state % time_levs(2) % state, block % mesh )
+           call compute_state_diagnostics( block % state % time_levs(2) % state, block % mesh )
+           call compute_solve_diagnostics( dt, block % state % time_levs(2) % state, block % mesh )
            block =&gt; block % next
         end do
 
@@ -343,8 +340,8 @@
       !
       block =&gt; domain % blocklist
       do while (associated(block))
-         call reconstruct(block % time_levs(2) % state, block % mesh)
-         call compute_w(block % time_levs(2) % state, block % time_levs(1) % state, block % mesh, dt)
+         call reconstruct(block % state % time_levs(2) % state, block % diag, block % mesh)
+         call compute_w(block % state % time_levs(2) % state, block % state % time_levs(1) % state, block % mesh, dt)
          block =&gt; block % next
       end do
 
@@ -354,22 +351,21 @@
          domain_mass = 0.
          scalar_mass = 0.
          block =&gt; domain % blocklist
-         scalar_min = block % time_levs(2) % state % scalars % array (2,1,1)
-         scalar_max = block % time_levs(2) % state % scalars % array (2,1,1)
+         scalar_min = block % state % time_levs(2) % state % scalars % array (2,1,1)
+         scalar_max = block % state % time_levs(2) % state % scalars % array (2,1,1)
          do while(associated(block))
            do iCell = 1, block % mesh % nCellsSolve
-             domain_mass = domain_mass + block % time_levs(2) % state % surface_pressure % array (iCell) * &amp;
+             domain_mass = domain_mass + block % state % time_levs(2) % state % surface_pressure % array (iCell) * &amp;
                                          block % mesh % areaCell % array (iCell) &amp;
-                                       - block % time_levs(2) % state % pressure % array (block % mesh % nVertLevels + 1, 1) * &amp;
+                                       - block % state % time_levs(2) % state % pressure % array (block % mesh % nVertLevels + 1, 1) * &amp;
                                          block % mesh % areaCell % array (iCell)
-
              do k=1, block % mesh % nVertLevelsSolve
-               scalar_mass = scalar_mass - block % time_levs(2) % state % scalars % array (2,k,iCell) * &amp;
-                                           block % time_levs(2) % state % h % array (k,iCell) * &amp;
+               scalar_mass = scalar_mass - block % state % time_levs(2) % state % scalars % array (2,k,iCell) * &amp;
+                                           block % state % time_levs(2) % state % h % array (k,iCell) * &amp;
                                            block % mesh % dnw % array (k) * &amp;
                                            block % mesh % areaCell % array (iCell)
-               scalar_min = min(scalar_min,block % time_levs(2) % state % scalars % array (2,k,iCell))
-               scalar_max = max(scalar_max,block % time_levs(2) % state % scalars % array (2,k,iCell))
+               scalar_min = min(scalar_min,block % state % time_levs(2) % state % scalars % array (2,k,iCell))
+               scalar_max = max(scalar_max,block % state % time_levs(2) % state % scalars % array (2,k,iCell))
              end do
            end do
            block =&gt; block % next
@@ -390,15 +386,15 @@
 
          !call microphysics schemes:
          if(config_microp_scheme .ne. 'off') &amp;
-            call microphysics_driver ( block % time_levs(2) % state, block % mesh, itimestep )
+            call microphysics_driver ( block % state % time_levs(2) % state, block % mesh, itimestep )
 
-            do iScalar = 1, num_scalars
+            do iScalar = 1, block % state % time_levs(2) % state % num_scalars
                scalar_min = 0.
                scalar_max = 0.
                do iCell = 1, block % mesh % nCellsSolve
                do k = 1, block % mesh % nVertLevels
-                  scalar_min = min(scalar_min, block % time_levs(2) % state % scalars % array(iScalar,k,iCell))
-                  scalar_max = max(scalar_max, block % time_levs(2) % state % scalars % array(iScalar,k,iCell))
+                  scalar_min = min(scalar_min, block % state % time_levs(2) % state % scalars % array(iScalar,k,iCell))
+                  scalar_max = max(scalar_max, block % state % time_levs(2) % state % scalars % array(iScalar,k,iCell))
                enddo
                enddo
                write(0,*) ' min, max scalar ',iScalar, scalar_min, scalar_max
@@ -426,8 +422,8 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(inout) :: grid
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(inout) :: grid
 
       integer :: iEdge, iCell, k, cell1, cell2, iq
 
@@ -440,11 +436,11 @@
       grid % qtot % array = 0.
       grid % cqu % array = 1.
 
-      if (num_scalars &gt; 0) then
+      if (s % num_scalars &gt; 0) then
 
         do iCell = 1, nCells
           do k = 1, nVertLevels
-            do iq = moist_start, moist_end
+            do iq = s % moist_start, s % moist_end
               grid % qtot % array(k,iCell) = grid % qtot % array(k,iCell) + s % scalars % array (iq, k, iCell)
             end do
           end do
@@ -478,8 +474,8 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: s
-      type (grid_meta), intent(inout) :: grid
+      type (state_type), intent(inout) :: s
+      type (mesh_type), intent(inout) :: grid
 
       real (kind=RKIND), dimension(:,:,:), pointer :: scalar
       real (kind=RKIND), dimension(:,:), pointer :: h, pressure, qtot, alpha, geopotential, theta
@@ -569,9 +565,9 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(in) :: grid
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j
       real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, q, upstream_bias
@@ -608,7 +604,6 @@
       pv_edge      =&gt; s % pv_edge % array
       geopotential =&gt; s % geopotential % array
       theta        =&gt; s % theta % array
-      h_diabatic   =&gt; s % h_diabatic % array
 
       weightsOnEdge     =&gt; grid % weightsOnEdge % array
       cellsOnEdge       =&gt; grid % cellsOnEdge % array  
@@ -625,6 +620,7 @@
       vh          =&gt; tend % vh % array
       tend_u      =&gt; tend % u % array
       tend_theta  =&gt; tend % theta % array
+      h_diabatic  =&gt; s % h_diabatic % array
 
       ww          =&gt; s % ww % array
       rdnu        =&gt; grid % rdnu % array
@@ -865,6 +861,8 @@
 !----------- rhs for theta
 
       tend_theta(:,:) = 0.
+
+
       !
       !  horizontal mixing for theta - we could combine this with advection directly (i.e. as a turbulent flux),
       !  but here we can also code in hyperdiffusion if we wish (2nd order at present)
@@ -1070,9 +1068,9 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: tend
-      type (grid_state), intent(inout) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(in) :: tend
+      type (state_type), intent(inout) :: s
+      type (mesh_type), intent(in) :: grid
       real (kind=RKIND), intent(in) :: dt
       integer, intent(in) :: small_step, number_small_steps, rk_step
 
@@ -1335,13 +1333,13 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: tend
-      type (grid_state), intent(in) :: s_old
-      type (grid_state), intent(out) :: s_new
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(in) :: tend
+      type (state_type), intent(in) :: s_old
+      type (state_type), intent(inout) :: s_new
+      type (mesh_type), intent(in) :: grid
       real (kind=RKIND) :: dt
 
-      integer :: i, iCell, iEdge, k, iScalar, cell1, cell2
+      integer :: i, iCell, iEdge, k, iScalar, cell1, cell2, num_scalars
       real (kind=RKIND) :: flux, scalar_edge, d2fdx2_cell1, d2fdx2_cell2
 
       real (kind=RKIND), dimension(:,:,:), pointer :: scalar_old, scalar_new, scalar_tend
@@ -1350,12 +1348,14 @@
       real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
       integer, dimension(:,:), pointer :: cellsOnEdge
 
-      real (kind=RKIND), dimension( num_scalars, grid % nVertLevels + 1 ) :: wdtn
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nVertLevels + 1 ) :: wdtn
       integer :: nVertLevels
 
       real (kind=RKIND), dimension(:), pointer :: fnm, fnp, rdnw
       real (kind=RKIND) :: coef_3rd_order
 
+      num_scalars = s_old % num_scalars
+
       coef_3rd_order = 0.
       if (config_scalar_adv_order == 3) coef_3rd_order = 1.0
       if (config_scalar_adv_order == 3 .and. config_monotonic) coef_3rd_order = 0.25
@@ -1380,6 +1380,7 @@
       nVertLevels = grid % nVertLevels
 
       scalar_tend = 0.  !  testing purposes - we have no sources or sinks
+
       !
       ! Runge Kutta integration, so we compute fluxes from scalar_new values, update starts form scalar_old
       !
@@ -1521,16 +1522,16 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: tend
-      type (grid_state), intent(in) :: s_old
-      type (grid_state), intent(out) :: s_new
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(in) :: tend
+      type (state_type), intent(in) :: s_old
+      type (state_type), intent(inout) :: s_new
+      type (mesh_type), intent(in) :: grid
       integer, intent(in) :: rk_step, rk_order
       real (kind=RKIND), intent(in) :: dt
       type (dm_info), intent(in) :: dminfo
       type (exchange_list), pointer :: cellsToSend, cellsToRecv
 
-      integer :: i, iCell, iEdge, k, iScalar, cell_upwind, cell1, cell2
+      integer :: i, iCell, iEdge, k, iScalar, cell_upwind, cell1, cell2, num_scalars
       real (kind=RKIND) :: flux, scalar_edge, d2fdx2_cell1, d2fdx2_cell2
       real (kind=RKIND) :: fdir, flux_upwind, h_flux_upwind, s_upwind
 
@@ -1540,10 +1541,10 @@
       real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
       integer, dimension(:,:), pointer :: cellsOnEdge
 
-      real (kind=RKIND), dimension( num_scalars, grid % nEdges+1) :: h_flux
-      real (kind=RKIND), dimension( num_scalars, grid % nCells+1, 2 ) :: v_flux, v_flux_upwind, s_update
-      real (kind=RKIND), dimension( num_scalars, grid % nCells+1, 2 ) :: scale_out, scale_in
-      real (kind=RKIND), dimension( num_scalars ) :: s_max, s_min, s_max_update, s_min_update
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nEdges+1) :: h_flux
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nCells+1, 2 ) :: v_flux, v_flux_upwind, s_update
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nCells+1, 2 ) :: scale_out, scale_in
+      real (kind=RKIND), dimension( s_old % num_scalars ) :: s_max, s_min, s_max_update, s_min_update
 
       integer :: nVertLevels, km0, km1, ktmp, kcp1, kcm1
 
@@ -1551,6 +1552,8 @@
       real (kind=RKIND), parameter :: eps=1.e-20
       real (kind=RKIND) :: coef_3rd_order
 
+      num_scalars = s_old % num_scalars
+
       scalar_old  =&gt; s_old % scalars % array
       scalar_new  =&gt; s_new % scalars % array
       deriv_two   =&gt; grid % deriv_two % array
@@ -1853,8 +1856,8 @@
       implicit none
 
       real (kind=RKIND), intent(in) :: dt
-      type (grid_state), intent(inout) :: s
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: s
+      type (mesh_type), intent(in) :: grid
 
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, cov
@@ -2104,9 +2107,9 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: s_new
-      type (grid_state), intent(in) :: s_old
-      type (grid_meta), intent(inout) :: grid
+      type (state_type), intent(inout) :: s_new
+      type (state_type), intent(in) :: s_old
+      type (mesh_type), intent(inout) :: grid
 
       real (kind=RKIND), intent(in) :: dt
 

Modified: branches/atmos_physics/src/core_hyd_atmos/mpas_interface.F
===================================================================
--- branches/atmos_physics/src/core_hyd_atmos/mpas_interface.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_hyd_atmos/mpas_interface.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -28,16 +28,16 @@
    implicit none
 
    type (block_type), intent(inout) :: block
-   type (grid_meta), intent(inout) :: mesh
+   type (mesh_type), intent(inout) :: mesh
    real (kind=RKIND), intent(in) :: dt
 
-   call compute_solver_constants(block % time_levs(1) % state, mesh)
-   call compute_state_diagnostics(block % time_levs(1) % state, mesh)
-   call compute_solve_diagnostics(dt, block % time_levs(1) % state, mesh)
+   call compute_solver_constants(block % state % time_levs(1) % state, mesh)
+   call compute_state_diagnostics(block % state % time_levs(1) % state, mesh)
+   call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
    call initialize_advection_rk(mesh)
    call rbfInterp_initialize(mesh)
    call init_reconstruct(mesh)
-   call reconstruct(block % time_levs(1) % state, mesh)
+   call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
 
 #ifdef DO_PHYSICS
    !check that all the physics options are correctly defined and that at least one physics
@@ -46,9 +46,9 @@
 
    !proceed with initialization of physics parameterization if moist_physics is set to true:
    if(moist_physics) then
-      call physics_registry_init(config_do_restart, mesh, block % time_levs(1) % state)
+      call physics_registry_init(config_do_restart, mesh, block % state % time_levs(1) % state)
       call physics_wrf_interface(mesh)
-      call physics_init(mesh, block % time_levs(1) % state)
+      call physics_init(mesh, block % state % time_levs(1) % state)
    endif
 #endif   
 

Modified: branches/atmos_physics/src/core_nhyd_atmos/Registry
===================================================================
--- branches/atmos_physics/src/core_nhyd_atmos/Registry        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_nhyd_atmos/Registry        2010-10-13 20:25:17 UTC (rev 549)
@@ -30,7 +30,7 @@
 namelist integer   nhyd_model config_mp_physics           0.
 namelist real      nhyd_model config_epssm                0.1
 namelist real      nhyd_model config_smdiv                0.1
-
+namelist integer   dimensions config_nvertlevels        26
 namelist character io       config_input_name           grid.nc
 namelist character io       config_output_name          output.nc
 namelist character io       config_restart_name         restart.nc
@@ -52,201 +52,206 @@
 dim FIFTEEN 15
 dim TWENTYONE 21
 dim R3 3
-dim nVertLevels nVertLevels
+dim nVertLevels namelist:config_nvertlevels
 dim nVertLevelsP1 nVertLevels+1
 
 #
 # var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
 #
-var real    xtime ( Time ) ro xtime - -
+var persistent real    xtime ( Time ) 2 ro xtime state - -
 
 #  horizontal grid structure
 
-var real    latCell ( nCells ) iro latCell - -
-var real    lonCell ( nCells ) iro lonCell - -
-var real    xCell ( nCells ) iro xCell - -
-var real    yCell ( nCells ) iro yCell - -
-var real    zCell ( nCells ) iro zCell - -
-var integer indexToCellID ( nCells ) iro indexToCellID - -
+var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
+var persistent real    lonCell ( nCells ) 0 iro lonCell mesh - -
+var persistent real    xCell ( nCells ) 0 iro xCell mesh - -
+var persistent real    yCell ( nCells ) 0 iro yCell mesh - -
+var persistent real    zCell ( nCells ) 0 iro zCell mesh - -
+var persistent integer indexToCellID ( nCells ) 0 iro indexToCellID mesh - -
 
-var real    latEdge ( nEdges ) iro latEdge - -
-var real    lonEdge ( nEdges ) iro lonEdge - -
-var real    xEdge ( nEdges ) iro xEdge - -
-var real    yEdge ( nEdges ) iro yEdge - -
-var real    zEdge ( nEdges ) iro zEdge - -
-var integer indexToEdgeID ( nEdges ) iro indexToEdgeID - -
+var persistent real    latEdge ( nEdges ) 0 iro latEdge mesh - -
+var persistent real    lonEdge ( nEdges ) 0 iro lonEdge mesh - -
+var persistent real    xEdge ( nEdges ) 0 iro xEdge mesh - -
+var persistent real    yEdge ( nEdges ) 0 iro yEdge mesh - -
+var persistent real    zEdge ( nEdges ) 0 iro zEdge mesh - -
+var persistent integer indexToEdgeID ( nEdges ) 0 iro indexToEdgeID mesh - -
 
-var real    latVertex ( nVertices ) iro latVertex - -
-var real    lonVertex ( nVertices ) iro lonVertex - -
-var real    xVertex ( nVertices ) iro xVertex - -
-var real    yVertex ( nVertices ) iro yVertex - -
-var real    zVertex ( nVertices ) iro zVertex - -
-var integer indexToVertexID ( nVertices ) iro indexToVertexID - -
+var persistent real    latVertex ( nVertices ) 0 iro latVertex mesh - -
+var persistent real    lonVertex ( nVertices ) 0 iro lonVertex mesh - -
+var persistent real    xVertex ( nVertices ) 0 iro xVertex mesh - -
+var persistent real    yVertex ( nVertices ) 0 iro yVertex mesh - -
+var persistent real    zVertex ( nVertices ) 0 iro zVertex mesh - -
+var persistent integer indexToVertexID ( nVertices ) 0 iro indexToVertexID mesh - -
 
-var integer cellsOnEdge ( TWO nEdges ) iro cellsOnEdge - -
-var integer nEdgesOnCell ( nCells ) iro nEdgesOnCell - -
-var integer nEdgesOnEdge ( nEdges ) iro nEdgesOnEdge - -
-var integer edgesOnCell ( maxEdges nCells ) iro edgesOnCell - -
-var integer edgesOnEdge ( maxEdges2 nEdges ) iro edgesOnEdge - -
+var persistent integer cellsOnEdge ( TWO nEdges ) 0 iro cellsOnEdge mesh - -
+var persistent integer nEdgesOnCell ( nCells ) 0 iro nEdgesOnCell mesh - -
+var persistent integer nEdgesOnEdge ( nEdges ) 0 iro nEdgesOnEdge mesh - -
+var persistent integer edgesOnCell ( maxEdges nCells ) 0 iro edgesOnCell mesh - -
+var persistent integer edgesOnEdge ( maxEdges2 nEdges ) 0 iro edgesOnEdge mesh - -
 
-var real    weightsOnEdge ( maxEdges2 nEdges ) iro weightsOnEdge - -
-var real    dvEdge ( nEdges ) iro dvEdge - -
-var real    dcEdge ( nEdges ) iro dcEdge - -
-var real    angleEdge ( nEdges ) iro angleEdge - -
-var real    areaCell ( nCells ) iro areaCell - -
-var real    areaTriangle ( nVertices ) iro areaTriangle - -
+var persistent real    weightsOnEdge ( maxEdges2 nEdges ) 0 iro weightsOnEdge mesh - -
+var persistent real    dvEdge ( nEdges ) 0 iro dvEdge mesh - -
+var persistent real    dcEdge ( nEdges ) 0 iro dcEdge mesh - -
+var persistent real    angleEdge ( nEdges ) 0 iro angleEdge mesh - -
+var persistent real    areaCell ( nCells ) 0 iro areaCell mesh - -
+var persistent real    areaTriangle ( nVertices ) 0 iro areaTriangle mesh - -
 
-var real    edgeNormalVectors ( R3 nEdges ) o edgeNormalVectors - -
-var real    localVerticalUnitVectors ( R3 nCells ) o localVerticalUnitVectors - -
-var real    cellTangentPlane ( R3 TWO nEdges ) o cellTangentPlane - -
+var persistent real    edgeNormalVectors ( R3 nEdges ) 0 o edgeNormalVectors mesh - -
+var persistent real    localVerticalUnitVectors ( R3 nCells ) 0 o localVerticalUnitVectors mesh - -
+var persistent real    cellTangentPlane ( R3 TWO nEdges ) 0 o cellTangentPlane mesh - -
 
-var integer cellsOnCell ( maxEdges nCells ) iro cellsOnCell - -
-var integer verticesOnCell ( maxEdges nCells ) iro verticesOnCell - -
-var integer verticesOnEdge ( TWO nEdges ) iro verticesOnEdge - -
-var integer edgesOnVertex ( vertexDegree nVertices ) iro edgesOnVertex - -
-var integer cellsOnVertex ( vertexDegree nVertices ) iro cellsOnVertex - -
-var real    kiteAreasOnVertex ( vertexDegree nVertices ) iro kiteAreasOnVertex - -
-var real    fEdge ( nEdges ) iro fEdge - -
-var real    fVertex ( nVertices ) iro fVertex - -
-var real    h_s ( nCells ) iro h_s - -
+var persistent integer cellsOnCell ( maxEdges nCells ) 0 iro cellsOnCell mesh - -
+var persistent integer verticesOnCell ( maxEdges nCells ) 0 iro verticesOnCell mesh - -
+var persistent integer verticesOnEdge ( TWO nEdges ) 0 iro verticesOnEdge mesh - -
+var persistent integer edgesOnVertex ( vertexDegree nVertices ) 0 iro edgesOnVertex mesh - -
+var persistent integer cellsOnVertex ( vertexDegree nVertices ) 0 iro cellsOnVertex mesh - -
+var persistent real    kiteAreasOnVertex ( vertexDegree nVertices ) 0 iro kiteAreasOnVertex mesh - -
+var persistent real    fEdge ( nEdges ) 0 iro fEdge mesh - -
+var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
+var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
 # some solver scalar coefficients
 
 # coefficients for vertical extrapolation to the surface
-var real    cf1 ( ) iro cf1 - -
-var real    cf2 ( ) iro cf2 - -
-var real    cf3 ( ) iro cf3 - -
+var persistent real    cf1 ( ) 0 iro cf1 mesh - -
+var persistent real    cf2 ( ) 0 iro cf2 mesh - -
+var persistent real    cf3 ( ) 0 iro cf3 mesh - -
 
 # description of the vertical grid structure
 
-var real    hx ( nVertLevelsP1 nCells ) iro hx - -
-var real    zgrid ( nVertLevelsP1 nCells ) iro zgrid - -
-var real    rdzw ( nVertLevels ) iro rdzw - -
-var real    dzu ( nVertLevels ) iro dzu - -
-var real    rdzu ( nVertLevels ) iro rdzu - -
-var real    fzm ( nVertLevels ) iro fzm - -
-var real    fzp ( nVertLevels ) iro fzp - -
-var real    zx ( nVertLevelsP1 nEdges ) iro zx - -
-var real    zz ( nVertLevelsP1 nCells ) iro zz - -
-var real    zf ( nVertLevelsP1 TWO nEdges ) iro zf - -
-var real    zf3 ( nVertLevelsP1 TWO nEdges ) iro zf3 - -
-var real    zb ( nVertLevelsP1 TWO nEdges ) iro zb - -
-var real    zb3 ( nVertLevelsP1 TWO nEdges ) iro zb3 - -
+var persistent real    hx ( nVertLevelsP1 nCells ) 0 iro hx mesh - -
+var persistent real    zgrid ( nVertLevelsP1 nCells ) 0 iro zgrid mesh - -
+var persistent real    rdzw ( nVertLevels ) 0 iro rdzw mesh - -
+var persistent real    dzu ( nVertLevels ) 0 iro dzu mesh - -
+var persistent real    rdzu ( nVertLevels ) 0 iro rdzu mesh - -
+var persistent real    fzm ( nVertLevels ) 0 iro fzm mesh - -
+var persistent real    fzp ( nVertLevels ) 0 iro fzp mesh - -
+var persistent real    zx ( nVertLevelsP1 nEdges ) 0 iro zx mesh - -
+var persistent real    zz ( nVertLevelsP1 nCells ) 0 iro zz mesh - -
+var persistent real    zf ( nVertLevelsP1 TWO nEdges ) 0 iro zf mesh - -
+var persistent real    zf3 ( nVertLevelsP1 TWO nEdges ) 0 iro zf3 mesh - -
+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...
 
-var real    cofrz ( nVertLevels ) - cofrz - -
-var real    cofwr ( nVertLevels nCells ) - cofwr - -
-var real    cofwz ( nVertLevels nCells ) - cofwz - -
-var real    coftz ( nVertLevelsP1 nCells ) - coftz - -
-var real    cofwt ( nVertLevels nCells ) - cofwt - -
-var real    a_tri ( nVertLevels nCells ) - a_tri - -
-var real    alpha_tri ( nVertLevels nCells ) - alpha_tri - -
-var real    gamma_tri ( nVertLevels nCells ) - gamma_tri - -
+var persistent real    cofrz ( nVertLevels ) 0 - cofrz mesh - -
+var persistent real    cofwr ( nVertLevels nCells ) 0 - cofwr mesh - -
+var persistent real    cofwz ( nVertLevels nCells ) 0 - cofwz mesh - -
+var persistent real    coftz ( nVertLevelsP1 nCells ) 0 - coftz mesh - -
+var persistent real    cofwt ( nVertLevels nCells ) 0 - cofwt mesh - -
+var persistent real    a_tri ( nVertLevels nCells ) 0 - a_tri mesh - -
+var persistent real    alpha_tri ( nVertLevels nCells ) 0 - alpha_tri mesh - -
+var persistent real    gamma_tri ( nVertLevels nCells ) 0 - gamma_tri mesh - -
 
 #  W-Rayleigh-damping coefficient
 
-var real    dss ( nVertLevels nCells ) ir dss - -
+var persistent real    dss ( nVertLevels nCells ) 0 ir dss mesh - -
 
 # Prognostic variables: read from input, saved in restart, and written to output
-var real    u ( nVertLevels nEdges Time ) iro u - -
-var real    w ( nVertLevelsP1 nCells Time ) iro w - -
-var real    rho ( nVertLevels nCells Time ) iro rho - -
-var real    rho_p ( nVertLevels nCells Time ) iro rho_p - -
-var real    theta ( nVertLevels nCells Time ) iro theta - -
-var real    rh ( nVertLevels nCells Time ) iro rh - -
-var real    qv ( nVertLevels nCells Time ) iro qv scalars moist
-var real    qc ( nVertLevels nCells Time ) iro qc scalars moist
-var real    qr ( nVertLevels nCells Time ) iro qr scalars moist
-var real    qi ( nVertLevels nCells Time ) iro qi scalars moist
-var real    qs ( nVertLevels nCells Time ) iro qs scalars moist
-var real    qg ( nVertLevels nCells Time ) iro qg scalars moist
-var real    qnr ( nVertLevels nCells Time ) iro qnr scalars number
-var real    qni ( nVertLevels nCells Time ) iro qni scalars number
+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 ( nVertLevels nCells Time ) 2 iro rho state - -
+var persistent real    rho_p ( nVertLevels nCells Time ) 2 iro rho_p state - -
+var persistent real    theta ( nVertLevels nCells Time ) 2 iro theta state - -
+var persistent real    rh ( nVertLevels nCells Time ) 2 iro rh 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    qi ( nVertLevels nCells Time ) 2 iro qi state scalars moist
+var persistent real    qs ( nVertLevels nCells Time ) 2 iro qs state scalars moist
+var persistent real    qg ( nVertLevels nCells Time ) 2 iro qg state scalars moist
+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
 
-#var real    tracers ( nTracers nVertLevels nCells Time ) iro tracers - -
+# Tendency variables
+var persistent real    tend_u ( nVertLevels nEdges Time ) 1 - u tend - -
+var persistent real    tend_w ( nVertLevelsP1 nCells Time ) 1 - w tend - -
+var persistent real    tend_rho ( nVertLevels nCells Time ) 1 - rho tend - -
+var persistent real    tend_theta ( nVertLevels nCells Time ) 1 - theta tend - -
+var persistent real    tend_qv ( nVertLevels nCells Time ) 1 - qv tend scalars moist
+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
 
 # state variables diagnosed from prognostic state
-# var real    ww ( nVertLevelsP1 nCells Time ) ro ww - -
-var real    pressure ( nVertLevels nCells Time ) ro pressure - -
-# var real    pp ( nVertLevelsP1 nCells Time ) - pp - -
+var persistent real    pressure ( nVertLevels nCells Time ) 2 ro pressure state - -
 
-var real    u_init ( nVertLevels ) iro u_init - -
-var real    t_init ( nVertLevels nCells ) iro t_init - -
-var real    qv_init ( nVertLevels ) iro qv_init - -
+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
-var real    v ( nVertLevels nEdges Time ) o v - -
-var real    divergence ( nVertLevels nCells Time ) o divergence - -
-var real    vorticity ( nVertLevels nVertices Time ) o vorticity - -
-var real    pv_edge ( nVertLevels nEdges Time ) o pv_edge - -
-var real    rho_edge ( nVertLevels nEdges Time ) o rho_edge - -
-var real    ke ( nVertLevels nCells Time ) o ke - -
-var real    pv_vertex ( nVertLevels nVertices Time ) o pv_vertex - -
-var real    pv_cell ( nVertLevels nCells Time ) o pv_cell - -
-var real    uReconstructX ( nVertLevels nCells Time ) o uReconstructX - -
-var real    uReconstructY ( nVertLevels nCells Time ) o uReconstructY - -
-var real    uReconstructZ ( nVertLevels nCells Time ) o uReconstructZ - -
-var real    uReconstructZonal ( nVertLevels nCells Time ) o uReconstructZonal - -
-var real    uReconstructMeridional ( nVertLevels nCells Time ) o uReconstructMeridional - -
+var persistent real    v ( nVertLevels nEdges Time ) 1 o v diag - -
+var persistent real    divergence ( nVertLevels nCells Time ) 1 o divergence diag - -
+var persistent real    vorticity ( nVertLevels nVertices Time ) 1 o vorticity diag - -
+var persistent real    pv_edge ( nVertLevels nEdges Time ) 1 o pv_edge diag - -
+var persistent real    rho_edge ( nVertLevels nEdges Time ) 1 o rho_edge diag - -
+var persistent real    ke ( nVertLevels nCells Time ) 1 o ke diag - -
+var persistent real    pv_vertex ( nVertLevels nVertices Time ) 1 o pv_vertex diag - -
+var persistent real    pv_cell ( nVertLevels nCells Time ) 1 o pv_cell diag - -
+var persistent real    uReconstructX ( nVertLevels nCells Time ) 1 o uReconstructX diag - -
+var persistent real    uReconstructY ( nVertLevels nCells Time ) 1 o uReconstructY diag - -
+var persistent real    uReconstructZ ( nVertLevels nCells Time ) 1 o uReconstructZ diag - -
+var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 1 o uReconstructZonal diag - -
+var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 1 o uReconstructMeridional diag - -
 
 # Other diagnostic variables: neither read nor written to any files
-var real    rv ( nVertLevels nEdges Time ) - rv - -
-var real    circulation ( nVertLevels nVertices Time ) - circulation - -
-var real    gradPVt ( nVertLevels nEdges Time ) - gradPVt - -
-var real    gradPVn ( nVertLevels nEdges Time ) - gradPVn - -
-var real    h_divergence ( nVertLevels nCells ) o h_divergence - -
+var persistent real    rv ( nVertLevels nEdges Time ) 1 - rv diag - -
+var persistent real    circulation ( nVertLevels nVertices Time ) 1 - circulation diag - -
+var persistent real    gradPVt ( nVertLevels nEdges Time ) 1 - gradPVt diag - -
+var persistent real    gradPVn ( nVertLevels nEdges Time ) 1 - gradPVn diag - -
+var persistent real    h_divergence ( nVertLevels nCells ) 0 o h_divergence mesh - -
 
-var real    exner ( nVertLevels nCells ) - exner - -
-var real    exner_base ( nVertLevels nCells ) or exner_base - -
-var real    rtheta_base ( nVertLevels nCells ) or rtheta_base - -
-var real    pressure_base ( nVertLevels nCells ) or pressure_base - -
-var real    rho_base ( nVertLevels nCells ) or rho_base - -
-var real    theta_base ( nVertLevels nCells ) or theta_base - -
+var persistent real    exner ( nVertLevels nCells ) 0 - exner mesh - -
+var persistent real    exner_base ( nVertLevels nCells ) 0 or exner_base mesh - -
+var persistent real    rtheta_base ( nVertLevels nCells ) 0 or rtheta_base mesh - -
+var persistent real    pressure_base ( nVertLevels nCells ) 0 or pressure_base mesh - -
+var persistent real    rho_base ( nVertLevels nCells ) 0 or rho_base mesh - -
+var persistent real    theta_base ( nVertLevels nCells ) 0 or theta_base mesh - -
 
 
-var real    ruAvg ( nVertLevels nEdges ) - ruAvg - -
-var real    wwAvg ( nVertLevelsP1 nCells ) - wwAvg - -
-var real    qtot ( nVertLevels nCells ) - qtot - -
-var real    cqu  ( nVertLevels nEdges ) - cqu - -
-var real    cqw  ( nVertLevels nCells ) - cqw - -
-var real    rt_diabatic_tend  ( nVertLevels nCells ) - rt_diabatic_tend - -
+var persistent real    ruAvg ( nVertLevels nEdges ) 0 - ruAvg mesh - -
+var persistent real    wwAvg ( nVertLevelsP1 nCells ) 0 - wwAvg mesh - -
+var persistent real    qtot ( nVertLevels nCells ) 0 - qtot mesh - -
+var persistent real    cqu  ( nVertLevels nEdges ) 0 - cqu mesh - -
+var persistent real    cqw  ( nVertLevels nCells ) 0 - cqw mesh - -
+var persistent real    rt_diabatic_tend  ( nVertLevels nCells ) 0 - rt_diabatic_tend mesh - -
 
 #  coupled variables needed by the solver, but not output...
 
-var real    ru ( nVertLevels nEdges ) - ru - -
-var real    ru_p ( nVertLevels nEdges ) - ru_p - -
-var real    ru_save ( nVertLevels nEdges ) - ru_save - -
+var persistent real    ru ( nVertLevels nEdges ) 0 - ru mesh - -
+var persistent real    ru_p ( nVertLevels nEdges ) 0 - ru_p mesh - -
+var persistent real    ru_save ( nVertLevels nEdges ) 0 - ru_save mesh - -
 
 
-var real    rw ( nVertLevelsP1 nCells ) - rw - -
-var real    rw_p ( nVertLevelsP1 nCells ) - rw_p - -
-var real    rw_save ( nVertLevelsP1 nCells ) - rw_save - -
+var persistent real    rw ( nVertLevelsP1 nCells ) 0 - rw mesh - -
+var persistent real    rw_p ( nVertLevelsP1 nCells ) 0 - rw_p mesh - -
+var persistent real    rw_save ( nVertLevelsP1 nCells ) 0 - rw_save mesh - -
 
-var real    rtheta_p ( nVertLevels nCells ) - rtheta_p - -
-var real    rtheta_pp ( nVertLevels nCells ) - rtheta_pp - -
-var real    rtheta_p_save ( nVertLevels nCells ) - rtheta_p_save - -
-var real    rtheta_pp_old ( nVertLevels nCells ) - rtheta_pp_old - -
+var persistent real    rtheta_p ( nVertLevels nCells ) 0 - rtheta_p mesh - -
+var persistent real    rtheta_pp ( nVertLevels nCells ) 0 - rtheta_pp mesh - -
+var persistent real    rtheta_p_save ( nVertLevels nCells ) 0 - rtheta_p_save mesh - -
+var persistent real    rtheta_pp_old ( nVertLevels nCells ) 0 - rtheta_pp_old mesh - -
 
-var real    rho_pp ( nVertLevels nCells ) - rho_pp - -
-var real    rho_p_save ( nVertLevels nCells ) - rho_p_save - -
+var persistent real    rho_pp ( nVertLevels nCells ) 0 - rho_pp mesh - -
+var persistent real    rho_p_save ( nVertLevels nCells ) 0 - rho_p_save mesh - -
 
-var real    qv_old ( nVertLevels nCells ) - rqv scalars_old moist_old
-var real    qc_old ( nVertLevels nCells ) - rqc scalars_old moist_old
-var real    qr_old ( nVertLevels nCells ) - rqr scalars_old moist_old
+var persistent real    qv_old ( nVertLevels nCells ) 0 - rqv mesh scalars_old moist_old
+var persistent real    qc_old ( nVertLevels nCells ) 0 - rqc mesh scalars_old moist_old
+var persistent real    qr_old ( nVertLevels nCells ) 0 - rqr mesh scalars_old moist_old
 
 # Space needed for advection
-var real    deriv_two ( FIFTEEN TWO nEdges ) o deriv_two - -
-var integer advCells ( TWENTYONE nCells ) - advCells - -
+var persistent real    deriv_two ( FIFTEEN TWO nEdges ) 0 o deriv_two mesh - -
+var persistent integer advCells ( TWENTYONE nCells ) 0 - advCells mesh - -
 
 # Space needed for deformation calculation weights
-var real    defc_a ( maxEdges nCells ) - defc_a - -
-var real    defc_b ( maxEdges nCells ) - defc_b - -
-var real    kdiff ( nVertLevels nCells Time ) - kdiff - -
+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 ) 2 - kdiff diag - -
 
 # Arrays required for reconstruction of velocity field
-var real    coeffs_reconstruct ( R3 maxEdges nCells ) - coeffs_reconstruct - -
+var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
 #==================================================================================================
 # DECLARATIONS OF ALL PHYSICS VARIABLES (will need to be moved to a Physics Registry shared by the
@@ -278,12 +283,12 @@
 # qi_col    : vertically-integrated cloud ice mixing ratio                                  (kg/m2)
 # qs_col    &quot; vertically-integrated snow mixing ratio                                       (kg/m2)
 
-var real    qv_col     ( nCells Time             )  o  qv_col     - -
-var real    qc_col     ( nCells Time             )  o  qc_col     - -
-var real    qr_col     ( nCells Time             )  o  qr_col     - -
-var real    qi_col     ( nCells Time             )  o  qi_col     - -
-var real    qs_col     ( nCells Time             )  o  qs_col     - -
-var real    qg_col     ( nCells Time             )  o  qg_col     - -
+var persistent real    qv_col     ( nCells Time             ) 2  o  qv_col     state - -
+var persistent real    qc_col     ( nCells Time             ) 2  o  qc_col     state - -
+var persistent real    qr_col     ( nCells Time             ) 2  o  qr_col     state - -
+var persistent real    qi_col     ( nCells Time             ) 2  o  qi_col     state - -
+var persistent real    qs_col     ( nCells Time             ) 2  o  qs_col     state - -
+var persistent real    qg_col     ( nCells Time             ) 2  o  qg_col     state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF CLOUD MICROPHYSICS:
@@ -297,13 +302,13 @@
 # graupelncv: time-step grid-scale precipitation of graupel                                    (mm)
 # sr        : time-step ratio of frozen versus total grid-scale precipitation                   (-)
 
-var real    rainnc     ( nCells Time             )  ro rainnc     - -
-var real    rainncv    ( nCells Time             )  ro rainncv    - -
-var real    snownc     ( nCells Time             )  ro snownc     - -
-var real    snowncv    ( nCells Time             )  ro snowncv    - -
-var real    graupelnc  ( nCells Time             )  ro graupelnc  - -
-var real    graupelncv ( nCells Time             )  ro graupelncv - -
-var real    sr         ( nCells Time             )   o sr         - -
+var persistent real    rainnc     ( nCells Time             ) 2  ro rainnc     state - -
+var persistent real    rainncv    ( nCells Time             ) 2  ro rainncv    state - -
+var persistent real    snownc     ( nCells Time             ) 2  ro snownc     state - -
+var persistent real    snowncv    ( nCells Time             ) 2  ro snowncv    state - -
+var persistent real    graupelnc  ( nCells Time             ) 2  ro graupelnc  state - -
+var persistent real    graupelncv ( nCells Time             ) 2  ro graupelncv state - -
+var persistent real    sr         ( nCells Time             ) 2   o sr         state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF CONVECTION:
@@ -322,22 +327,22 @@
 # rqscuten  : tendency of snow mixing ratio due to cumulus convection                   (kg/kg s-1)
 # wavg      : average vertical velocity (KF scheme only)                                    (m s-1)
 
-var real    nca      ( nCells Time             )  ro  nca         - -
-var real    cubot    ( nCells Time             )  ro  cubot       - -
-var real    cutop    ( nCells Time             )  ro  cutop       - -
+var persistent real    nca      ( nCells Time             ) 2  ro  nca         state - -
+var persistent real    cubot    ( nCells Time             ) 2  ro  cubot       state - -
+var persistent real    cutop    ( nCells Time             ) 2  ro  cutop       state - -
 
 # PRECIPITATION:
-var real    rainc    ( nCells Time             )  ro rainc        - -
-var real    raincv   ( nCells Time             )  ro raincv       - -
+var persistent real    rainc    ( nCells Time             ) 2  ro rainc        state - -
+var persistent real    raincv   ( nCells Time             ) 2  ro raincv       state - -
 
 #    TENDENCIES:
-var real    rthcuten ( nVertLevels nCells Time )  ro rthcuten     - -
-var real    rqvcuten ( nVertLevels nCells Time )  ro rqvcuten     - -
-var real    rqccuten ( nVertLevels nCells Time )  ro rqccuten     - -
-var real    rqrcuten ( nVertLevels nCells Time )  ro rqrcuten     - -
-var real    rqicuten ( nVertLevels nCells Time )  ro rqicuten     - -
-var real    rqscuten ( nVertLevels nCells Time )  ro rqscuten     - -
-var real    w0avg    ( nVertLevels nCells Time )  ro w0avg        - -
+var persistent real    rthcuten ( nVertLevels nCells Time ) 2  ro rthcuten     state - -
+var persistent real    rqvcuten ( nVertLevels nCells Time ) 2  ro rqvcuten     state - -
+var persistent real    rqccuten ( nVertLevels nCells Time ) 2  ro rqccuten     state - -
+var persistent real    rqrcuten ( nVertLevels nCells Time ) 2  ro rqrcuten     state - -
+var persistent real    rqicuten ( nVertLevels nCells Time ) 2  ro rqicuten     state - -
+var persistent real    rqscuten ( nVertLevels nCells Time ) 2  ro rqscuten     state - -
+var persistent real    w0avg    ( nVertLevels nCells Time ) 2  ro w0avg        state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF PLANETARY BOUNDARY LAYER PROCESSES:
@@ -349,12 +354,12 @@
 # rqiblten  : tendency of cloud ice mixing ratio due to pbl processes                   (kg/kg s-1)
 
 #    TENDENCIES:
-var real    rublten  ( nVertLevels nCells Time )  ro rublten      - -
-var real    rvblten  ( nVertLevels nCells Time )  ro rvblten      - -
-var real    rthblten ( nVertLevels nCells Time )  ro rthblten     - -
-var real    rqvblten ( nVertLevels nCells Time )  ro rqvblten     - -
-var real    rqcblten ( nVertLevels nCells Time )  ro rqcblten     - -
-var real    rqiblten ( nVertLevels nCells Time )  ro rqiblten     - -
+var persistent real    rublten  ( nVertLevels nCells Time ) 2  ro rublten      state - -
+var persistent real    rvblten  ( nVertLevels nCells Time ) 2  ro rvblten      state - -
+var persistent real    rthblten ( nVertLevels nCells Time ) 2  ro rthblten     state - -
+var persistent real    rqvblten ( nVertLevels nCells Time ) 2  ro rqvblten     state - -
+var persistent real    rqcblten ( nVertLevels nCells Time ) 2  ro rqcblten     state - -
+var persistent real    rqiblten ( nVertLevels nCells Time ) 2  ro rqiblten     state - -
 
 #--------------------------------------------------------------------------------------------------
 #... PARAMETERIZATION OF SURFACE LAYER PROCESSES:
@@ -382,26 +387,26 @@
 # xland    :land mask (1 for land; 2 for water)                                                 [-]
 # znt      :time-varying roughness length                                                       [m]
 
-var real    flhc     ( nCells Time             )  r  flhc         - -
-var real    flqc     ( nCells Time             )  r  flqc         - -
-var real    hfx      ( nCells Time             )  r  hfx          - -
-var real    lh       ( nCells Time             )  r  lh           - -
-var real    mavail   ( nCells Time             )  r  mavail       - -
-var real    mol      ( nCells Time             )  r  mol          - -
-var real    pblh     ( nCells Time             )  r  pblh         - -
-var real    q2       ( nCells Time             )  r  q2           - -
-var real    qfx      ( nCells Time             )  r  qfx          - -
-var real    qsfc     ( nCells Time             )  r  qsfc         - -
-var real    regime   ( nCells Time             )  r  regime       - -
-var real    rmol     ( nCells Time             )  r  rmol         - -
-var real    t2       ( nCells Time             )  r  t2           - -
-var real    tsk      ( nCells Time             )  r  tsk          - -
-var real    th2      ( nCells Time             )  r  th2          - -
-var real    u10      ( nCells Time             )  r  u10          - -
-var real    ust      ( nCells Time             )  r  ust          - -
-var real    ustm     ( nCells Time             )  r  ustm         - -
-var real    v10      ( nCells Time             )  r  v10          - -
-var real    xland    ( nCells Time             )  r  xland        - -
-var real    znt      ( nCells Time             )  r  znt          - -
+var persistent real    flhc     ( nCells Time             ) 2  r  flhc         state - -
+var persistent real    flqc     ( nCells Time             ) 2  r  flqc         state - -
+var persistent real    hfx      ( nCells Time             ) 2  r  hfx          state - -
+var persistent real    lh       ( nCells Time             ) 2  r  lh           state - -
+var persistent real    mavail   ( nCells Time             ) 2  r  mavail       state - -
+var persistent real    mol      ( nCells Time             ) 2  r  mol          state - -
+var persistent real    pblh     ( nCells Time             ) 2  r  pblh         state - -
+var persistent real    q2       ( nCells Time             ) 2  r  q2           state - -
+var persistent real    qfx      ( nCells Time             ) 2  r  qfx          state - -
+var persistent real    qsfc     ( nCells Time             ) 2  r  qsfc         state - -
+var persistent real    regime   ( nCells Time             ) 2  r  regime       state - -
+var persistent real    rmol     ( nCells Time             ) 2  r  rmol         state - -
+var persistent real    t2       ( nCells Time             ) 2  r  t2           state - -
+var persistent real    tsk      ( nCells Time             ) 2  r  tsk          state - -
+var persistent real    th2      ( nCells Time             ) 2  r  th2          state - -
+var persistent real    u10      ( nCells Time             ) 2  r  u10          state - -
+var persistent real    ust      ( nCells Time             ) 2  r  ust          state - -
+var persistent real    ustm     ( nCells Time             ) 2  r  ustm         state - -
+var persistent real    v10      ( nCells Time             ) 2  r  v10          state - -
+var persistent real    xland    ( nCells Time             ) 2  r  xland        state - -
+var persistent real    znt      ( nCells Time             ) 2  r  znt          state - -
 
 #==================================================================================================

Modified: branches/atmos_physics/src/core_nhyd_atmos/module_advection.F
===================================================================
--- branches/atmos_physics/src/core_nhyd_atmos/module_advection.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_nhyd_atmos/module_advection.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -17,7 +17,7 @@
 !
       implicit none
 
-      type (grid_meta), intent(in) :: grid
+      type (mesh_type), intent(in) :: grid
 
       real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
       integer, dimension(:,:), pointer :: advCells
@@ -750,7 +750,7 @@
 !
       implicit none
 
-      type (grid_meta), intent(in) :: grid
+      type (mesh_type), intent(in) :: grid
 
       real (kind=RKIND), dimension(:,:), pointer :: defc_a, defc_b
       integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnCell

Modified: branches/atmos_physics/src/core_nhyd_atmos/module_test_cases.F
===================================================================
--- branches/atmos_physics/src/core_nhyd_atmos/module_test_cases.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_nhyd_atmos/module_test_cases.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -38,10 +38,10 @@
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
             write(0,*) ' calling test case setup '
-            call nhyd_test_case_jw(block_ptr % mesh, block_ptr % time_levs(1) % state, config_test_case)
+            call nhyd_test_case_jw(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag, config_test_case)
             write(0,*) ' returned from test case setup '
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -55,10 +55,10 @@
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
             write(0,*) ' calling test case setup '
-            call nhyd_test_case_squall_line(domain % dminfo, block_ptr % mesh, block_ptr % time_levs(1) % state, config_test_case)
+            call nhyd_test_case_squall_line(domain % dminfo, block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag, config_test_case)
             write(0,*) ' returned from test case setup '
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -70,10 +70,10 @@
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
             write(0,*) ' calling test case setup '
-            call nhyd_test_case_mtn_wave(block_ptr % mesh, block_ptr % time_levs(1) % state, config_test_case)
+            call nhyd_test_case_mtn_wave(block_ptr % mesh, block_ptr % state % time_levs(1) % state, block_ptr % diag, config_test_case)
             write(0,*) ' returned from test case setup '
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -90,15 +90,16 @@
 
 !----------------------------------------------------------------------------------------------------------
 
-   subroutine nhyd_test_case_jw(grid, state, test_case)
+   subroutine nhyd_test_case_jw(grid, state, diag, test_case)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Setup baroclinic wave test case from Jablonowski and Williamson 2008 (QJRMS)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
+      type (diag_type), intent(inout) :: diag
       integer, intent(in) :: test_case
 
       real (kind=RKIND), parameter :: u0 = 35.0
@@ -122,6 +123,8 @@
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, itrp, cell1, cell2, nCellsSolve
 
+      integer :: index_qv
+
       !This is temporary variable here. It just need when calculate tangential velocity v.
       integer :: eoe, j
       integer, dimension(:), pointer :: nEdgesOnEdge 
@@ -225,6 +228,8 @@
       call initialize_advection_rk(grid) 
       call initialize_deformation_weights(grid) 
 
+      index_qv = state % index_qv
+
       rh(:,:) = 0.
       scalars(:,:,:) = 0.
 
@@ -774,13 +779,13 @@
       !
       ! Compute mass fluxes tangential to each edge (i.e., through the faces of dual grid cells)
       !
-      state % v % array(:,:) = 0.0
+      diag % v % array(:,:) = 0.0
       do iEdge = 1, grid%nEdges
          do i=1,nEdgesOnEdge(iEdge)
             eoe = edgesOnEdge(i,iEdge)
             if (eoe &gt; 0) then
                do k = 1, grid%nVertLevels
-                 state % v % array(k,iEdge) = state % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
+                 diag % v % array(k,iEdge) = diag % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
               end do
             end if
          end do
@@ -795,7 +800,6 @@
 
         write(0,*) ' i, psurf, lat ',i,psurf,grid%latCell%array(i)*180./3.1415828
       enddo
-!      stop
 
    end subroutine nhyd_test_case_jw
 
@@ -851,7 +855,7 @@
 
 !----------------------------------------------------------------------------------------------------------
 
-   subroutine nhyd_test_case_squall_line(dminfo, grid, state, test_case)
+   subroutine nhyd_test_case_squall_line(dminfo, grid, state, diag, test_case)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Setup squall line and supercell test case
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -859,8 +863,9 @@
       implicit none
 
       type (dm_info), intent(in) :: dminfo
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
+      type (diag_type), intent(inout) :: diag
       integer, intent(in) :: test_case
 
       real (kind=RKIND), dimension(:), pointer :: rdzw, dzu, rdzu, fzm, fzp
@@ -875,6 +880,7 @@
       real, dimension(:,:), pointer :: weightsOnEdge
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, cell1, cell2, nCellsSolve
+      integer :: index_qv
 
       real (kind=RKIND), dimension(grid % nVertLevels + 1 ) :: znu, znw, znwc, znwv
       real (kind=RKIND), dimension(grid % nVertLevels + 1 ) :: znuc, znuv
@@ -954,6 +960,8 @@
 
       scalars =&gt; state % scalars % array
 
+      index_qv = state % index_qv
+
       scalars(:,:,:) = 0.
 
       call initialize_advection_rk(grid) 
@@ -1214,7 +1222,7 @@
       write(0,*) ' base state sounding '
       write(0,*) ' k,     pb,     rb,     tb,     rtb,     t,     rr,      p,    qvb'
       do k=1,grid%nVertLevels
-         write (0,'i2,8(2x,f19.15)') k,pb(k,1),rb(k,1),tb(k,1),rtb(k,1),t(k,1),rr(k,1),p(k,1),qvb(k)
+         write (0,'(i2,8(2x,f19.15))') k,pb(k,1),rb(k,1),tb(k,1),rtb(k,1),t(k,1),rr(k,1),p(k,1),qvb(k)
       end do
 
 !
@@ -1352,13 +1360,13 @@
       !
       ! Compute mass fluxes tangential to each edge (i.e., through the faces of dual grid cells)
       !
-      state % v % array(:,:) = 0.0
+      diag % v % array(:,:) = 0.0
       do iEdge = 1, grid%nEdges
          do i=1,nEdgesOnEdge(iEdge)
             eoe = edgesOnEdge(i,iEdge)
             if (eoe &gt; 0) then
                do k = 1, grid%nVertLevels
-                 state % v % array(k,iEdge) = state % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
+                 diag % v % array(k,iEdge) = diag % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
               end do
             end if
          end do
@@ -1375,15 +1383,16 @@
 !----------------------------------------------------------------------------------------------------------
 
 
-   subroutine nhyd_test_case_mtn_wave(grid, state, test_case)
+   subroutine nhyd_test_case_mtn_wave(grid, state, diag, test_case)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Setup baroclinic wave test case from Jablonowski and Williamson 2008 (QJRMS)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
+      type (diag_type), intent(inout) :: diag
       integer, intent(in) :: test_case
 
       real (kind=RKIND), parameter :: t0=288., hm=250.
@@ -1401,6 +1410,7 @@
       real, dimension(:,:), pointer :: weightsOnEdge
 
       integer :: iCell, iCell1, iCell2 , iEdge, vtx1, vtx2, ivtx, i, k, nz, nz1, itr, itrp, cell1, cell2, nCellsSolve
+      integer :: index_qv
 
       real (kind=RKIND) :: ptop, pitop, ptopb, p0, flux, d2fdx2_cell1, d2fdx2_cell2
 
@@ -1493,6 +1503,8 @@
 
       scalars =&gt; state % scalars % array
 
+      index_qv = state % index_qv
+
       scalars(:,:,:) = 0.
 
       call initialize_advection_rk(grid) 
@@ -1759,7 +1771,7 @@
        write(0,*) ' ***** base state sounding ***** '
        write(0,*) 'k       pb        p         rb         rtb         rr          tb          t'
        do k=1,grid%nVertLevels
-          write(0,'i2,7(2x,f14.9)') k,pb(k,1),p(k,1),rb(k,1),rtb(k,1),rr(k,1),tb(k,1),t(k,1)
+          write(0,'(i2,7(2x,f14.9))') k,pb(k,1),p(k,1),rb(k,1),rtb(k,1),rr(k,1),tb(k,1),t(k,1)
        end do
  
        scalars(index_qv,:,:) = 0.
@@ -1817,7 +1829,7 @@
       write(0,*) ' *** sounding for the simulation ***'
       write(0,*) '    z       theta       pres         qv       rho_m        u        rr'
       do k=1,nz1
-         write(6,'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;
@@ -1943,13 +1955,13 @@
       !
       ! Compute mass fluxes tangential to each edge (i.e., through the faces of dual grid cells)
       !
-      state % v % array(:,:) = 0.0
+      diag % v % array(:,:) = 0.0
       do iEdge = 1, grid%nEdges
          do i=1,nEdgesOnEdge(iEdge)
             eoe = edgesOnEdge(i,iEdge)
             if (eoe &gt; 0) then
                do k = 1, grid%nVertLevels
-                 state % v % array(k,iEdge) = state % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
+                 diag % v % array(k,iEdge) = diag % v %array(k,iEdge) + weightsOnEdge(i,iEdge) * state % u % array(k, eoe)
               end do
             end if
          end do

Modified: branches/atmos_physics/src/core_nhyd_atmos/module_time_integration.F
===================================================================
--- branches/atmos_physics/src/core_nhyd_atmos/module_time_integration.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_nhyd_atmos/module_time_integration.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -42,7 +42,7 @@
 
       block =&gt; domain % blocklist
       do while (associated(block))
-         block % time_levs(2) % state % xtime % scalar = block % time_levs(1) % state % xtime % scalar + dt
+         block % state % time_levs(2) % state % xtime % scalar = block % state % time_levs(1) % state % xtime % scalar + dt
          block =&gt; block % next
       end do
 
@@ -71,7 +71,6 @@
       integer :: iCell, k, iEdge
       type (block_type), pointer :: block
 
-      integer, parameter :: TEND   = 1
       integer :: rk_step, number_of_sub_steps
       integer :: iScalar
 
@@ -84,6 +83,7 @@
 !      logical, parameter :: do_microphysics = .true.
       logical, parameter :: do_microphysics = .false.
 
+      integer :: index_qc
       real (kind=RKIND) :: domain_mass, scalar_mass, scalar_min, scalar_max
       real (kind=RKIND) :: global_domain_mass, global_scalar_mass, global_scalar_min, global_scalar_max
 
@@ -109,27 +109,27 @@
       block =&gt; domain % blocklist
       do while (associated(block))
 ! theta
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(1) % state % theta % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(1) % state % theta % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
 ! scalars
-         call dmpar_exch_halo_field3dReal(domain % dminfo, block % time_levs(1) % state % scalars % array(:,:,:), &amp;
-                                          num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+         call dmpar_exch_halo_field3dReal(domain % dminfo, block % state % time_levs(1) % state % scalars % array(:,:,:), &amp;
+                                          block % state % time_levs(1) % state % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
 ! pressure
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(1) % state % pressure % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(1) % state % pressure % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
 ! vorticity
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(1) % state % vorticity % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % vorticity % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nVertices, &amp;
                                           block % parinfo % verticesToSend, block % parinfo % verticesToRecv)
 ! divergence
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(1) % state % divergence % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % divergence % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
 ! pv_edge
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(1) % state % pv_edge % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % pv_edge % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                           block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
 ! rtheta_p
@@ -147,7 +147,7 @@
       do while (associated(block))
          ! We are setting values in the halo here, so no communications are needed.
          ! Alternatively, we could just set owned cells and edge values and communicate after this block loop.
-         call rk_integration_setup( block % time_levs(2) % state, block % time_levs(1) % state, block % mesh )
+         call rk_integration_setup( block % state % time_levs(2) % state, block % state % time_levs(1) % state, block % mesh )
          block =&gt; block % next
       end do
 
@@ -164,7 +164,7 @@
            ! The coefficients are set for owned cells (cqw) and for all edges of owned cells, 
            ! thus no communications should be needed after this call.  
            ! We could consider combining this and the next block loop.
-           call compute_moist_coefficients( block % time_levs(2) % state, block % mesh )
+           call compute_moist_coefficients( block % state % time_levs(2) % state, block % mesh )
            block =&gt; block % next
         end do
 
@@ -172,7 +172,7 @@
         if (debug) write(0,*) ' compute_dyn_tend '
         block =&gt; domain % blocklist
         do while (associated(block))
-           call compute_dyn_tend( block % intermediate_step(TEND), block % time_levs(2) % state, block % mesh )
+           call compute_dyn_tend( block % tend, block % state % time_levs(2) % state, block % diag, block % mesh )
            block =&gt; block % next
         end do
         if (debug) write(0,*) ' finished compute_dyn_tend '
@@ -182,8 +182,8 @@
 !       if (debug) write(0,*) ' add physics tendencies '
 !       block =&gt; domain % blocklist
 !       do while (associated(block))
-!          call physics_addtend( block % intermediate_step(TEND), block % time_levs(2) % state, &amp;
-!                                block % time_levs(2) % state % rho % array(:,:), block % mesh )
+!          call physics_addtend( block % tend, block % state % time_levs(2) % state, &amp;
+!                                block % state % time_levs(2) % state % rho % array(:,:), block % mesh )
 !          block =&gt; block % next
 !       end do
 !       if (debug) write(0,*) ' finished add physics tendencies '
@@ -195,16 +195,16 @@
 !***********************************
          block =&gt; domain % blocklist
          do while (associated(block))
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % u % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % u % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % theta % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % theta % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % rho % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % rho % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % w % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % w % array(:,:), &amp;
                                              block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
             block =&gt; block % next
@@ -212,9 +212,9 @@
 
         block =&gt; domain % blocklist
           do while (associated(block))
-            call set_smlstep_pert_variables( block % time_levs(1) % state, block % time_levs(2) % state,  &amp;
-                                             block % intermediate_step(TEND), block % mesh               )
-            call compute_vert_imp_coefs( block % time_levs(2) % state, block % mesh, rk_sub_timestep(rk_step) )
+            call set_smlstep_pert_variables( block % state % time_levs(1) % state, block % state % time_levs(2) % state,  &amp;
+                                             block % tend, block % mesh               )
+            call compute_vert_imp_coefs( block % state % time_levs(2) % state, block % mesh, rk_sub_timestep(rk_step) )
             block =&gt; block % next
         end do
 
@@ -224,7 +224,7 @@
       
            block =&gt; domain % blocklist
            do while (associated(block))
-              call advance_acoustic_step( block % time_levs(2) % state,  block % intermediate_step(TEND),  &amp;
+              call advance_acoustic_step( block % state % time_levs(2) % state,  block % tend,  &amp;
                                           block % mesh, rk_sub_timestep(rk_step)                          )
               block =&gt; block % next
            end do
@@ -259,10 +259,10 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call recover_large_step_variables( block % time_levs(2) % state,             &amp;
+           call recover_large_step_variables( block % state % time_levs(2) % state,     &amp;
                                               block % mesh, rk_timestep(rk_step),       &amp;
                                               number_sub_steps(rk_step), rk_step  )
-
+          
            block =&gt; block % next
         end do
 
@@ -279,12 +279,14 @@
            !       so we keep the advance_scalars routine as well
            !
            if (rk_step &lt; 3 .or. (.not. config_monotonic .and. .not. config_positive_definite)) then
-              call advance_scalars( block % intermediate_step(TEND),                            &amp;
-                                    block % time_levs(1) % state, block % time_levs(2) % state, &amp;
+              call advance_scalars( block % tend,                            &amp;
+                                    block % state % time_levs(1) % state, block % state % time_levs(2) % state, &amp;
+                                    block % diag, &amp;
                                     block % mesh, rk_timestep(rk_step) )
            else
-              call advance_scalars_mono( block % intermediate_step(TEND),                            &amp;
-                                         block % time_levs(1) % state, block % time_levs(2) % state, &amp;
+              call advance_scalars_mono( block % tend,                            &amp;
+                                         block % state % time_levs(1) % state, block % state % time_levs(2) % state, &amp;
+                                         block % diag, &amp;
                                          block % mesh, rk_timestep(rk_step), rk_step, 3,             &amp;
                                          domain % dminfo, block % parinfo % cellsToSend, block % parinfo % cellsToRecv )
            end if
@@ -294,11 +296,11 @@
          block =&gt; domain % blocklist
          do while (associated(block))
 ! For now, we do scalar halo updates later on...
-!            call dmpar_exch_halo_field3dReal(domain % dminfo, block % intermediate_step(TEND) % scalars % array(:,:,:), &amp;
-!                                             num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+!            call dmpar_exch_halo_field3dReal(domain % dminfo, block % tend % scalars % array(:,:,:), &amp;
+!                                             block % tend % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
 !                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-!            call dmpar_exch_halo_field3dReal(domain % dminfo, block % time_levs(2) % state % scalars % array(:,:,:), &amp;
-!                                             num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+!            call dmpar_exch_halo_field3dReal(domain % dminfo, block % state % time_levs(2) % state % scalars % array(:,:,:), &amp;
+!                                             block % state % time_levs(2) % state % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
 !                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
             block =&gt; block % next
          end do
@@ -311,7 +313,7 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call compute_solve_diagnostics( dt, block % time_levs(2) % state, block % mesh )
+           call compute_solve_diagnostics( dt, block % state % time_levs(2) % state, block % diag, block % mesh )
            block =&gt; block % next
         end do
 
@@ -324,50 +326,50 @@
          do while (associated(block))
 
 ! NB: if any of these cause differences, better to uncomment the version after qd_kessler?
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % u % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % u % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % theta % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % theta % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pressure % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % pressure % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % rho % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % rho % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % rho_p % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % rho_p % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % w % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % w % array(:,:), &amp;
                                              block % mesh % nVertLevels+1, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % vorticity % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % vorticity % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nVertices, &amp;
                                              block % parinfo % verticesToSend, block % parinfo % verticesToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pv_vertex % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % pv_vertex % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nVertices, &amp;
                                              block % parinfo % verticesToSend, block % parinfo % verticesToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pv_cell % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % pv_cell % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % divergence % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % divergence % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % ke % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % ke % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % v % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % v % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pv_edge % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % pv_edge % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-            call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % rho_edge % array(:,:), &amp;
+            call dmpar_exch_halo_field2dReal(domain % dminfo, block % diag % rho_edge % array(:,:), &amp;
                                              block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                              block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-            call dmpar_exch_halo_field3dReal(domain % dminfo, block % time_levs(2) % state % scalars % array(:,:,:), &amp;
-                                             num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+            call dmpar_exch_halo_field3dReal(domain % dminfo, block % state % time_levs(2) % state % scalars % array(:,:,:), &amp;
+                                             block % state % time_levs(2) % state % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                              block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
             block =&gt; block % next
          end do
@@ -377,7 +379,7 @@
 !...  compute full velocity vectors at cell centers:
       block =&gt; domain % blocklist
         do while (associated(block))
-           call reconstruct(block % time_levs(2) % state, block % mesh)
+           call reconstruct(block % state % time_levs(2) % state, block % diag, block % mesh)
            block =&gt; block % next
         end do
 
@@ -387,12 +389,12 @@
       do while(associated(block))
 
          !simply set to zero negative mixing ratios of different water species (for now):
-         where ( block % time_levs(2) % state % scalars % array(:,:,:) .lt. 0.) &amp;
-            block % time_levs(2) % state % scalars % array(:,:,:) = 0.
+         where ( block % state % time_levs(2) % state % scalars % array(:,:,:) .lt. 0.) &amp;
+            block % state % time_levs(2) % state % scalars % array(:,:,:) = 0.
 
          !call microphysics schemes:
          if(config_microp_scheme .ne. 'off') &amp;
-            call microphysics_driver ( block % time_levs(2) % state, block % mesh, itimestep )
+            call microphysics_driver ( block % state % time_levs(2) % state, block % mesh, itimestep )
 
          block =&gt; block % next
       end do
@@ -401,7 +403,7 @@
 !     if(do_microphysics) then
 !     block =&gt; domain % blocklist
 !       do while (associated(block))
-!          call qd_kessler( block % time_levs(1) % state, block % time_levs(2) % state, block % mesh, dt )
+!          call qd_kessler( block % state % time_levs(1) % state, block % state % time_levs(2) % state, block % mesh, dt )
 !          block =&gt; block % next
 !       end do
 !     end if
@@ -414,17 +416,17 @@
          call dmpar_exch_halo_field2dReal(domain % dminfo, block % mesh % exner % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % theta % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % theta % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-         call dmpar_exch_halo_field2dReal(domain % dminfo, block % time_levs(2) % state % pressure % array(:,:), &amp;
+         call dmpar_exch_halo_field2dReal(domain % dminfo, block % state % time_levs(2) % state % pressure % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
          call dmpar_exch_halo_field2dReal(domain % dminfo, block % mesh % rt_diabatic_tend % array(:,:), &amp;
                                           block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-         call dmpar_exch_halo_field3dReal(domain % dminfo, block % time_levs(2) % state % scalars % array(:,:,:), &amp;
-                                          num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+         call dmpar_exch_halo_field3dReal(domain % dminfo, block % state % time_levs(2) % state % scalars % array(:,:,:), &amp;
+                                          block % state % time_levs(2) % state % num_scalars, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                           block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
          block =&gt; block % next
       end do
@@ -436,8 +438,8 @@
              scalar_max = 0.
              do iCell = 1, block % mesh % nCellsSolve
              do k = 1, block % mesh % nVertLevels
-               scalar_min = min(scalar_min, block % time_levs(2) % state % w % array(k,iCell))
-               scalar_max = max(scalar_max, block % time_levs(2) % state % w % array(k,iCell))
+               scalar_min = min(scalar_min, block % state % time_levs(2) % state % w % array(k,iCell))
+               scalar_max = max(scalar_max, block % state % time_levs(2) % state % w % array(k,iCell))
              enddo
              enddo
              write(0,*) ' min, max w ',scalar_min, scalar_max
@@ -446,23 +448,23 @@
              scalar_max = 0.
              do iEdge = 1, block % mesh % nEdgesSolve
              do k = 1, block % mesh % nVertLevels
-               scalar_min = min(scalar_min, block % time_levs(2) % state % u % array(k,iEdge))
-               scalar_max = max(scalar_max, block % time_levs(2) % state % u % array(k,iEdge))
+               scalar_min = min(scalar_min, block % state % time_levs(2) % state % u % array(k,iEdge))
+               scalar_max = max(scalar_max, block % state % time_levs(2) % state % u % array(k,iEdge))
              enddo
              enddo
              write(0,*) ' min, max u ',scalar_min, scalar_max
 
-             do iScalar = 1, num_scalars
+             do iScalar = 1, block % state % time_levs(2) % state % num_scalars
                 scalar_min = 0.
                 scalar_max = 0.
                 do iCell = 1, block % mesh % nCellsSolve
                 do k = 1, block % mesh % nVertLevels
-                   scalar_min = min(scalar_min, block % time_levs(2) % state % scalars % array(iScalar,k,iCell))
-                   scalar_max = max(scalar_max, block % time_levs(2) % state % scalars % array(iScalar,k,iCell))
+                  scalar_min = min(scalar_min, block % state % time_levs(2) % state % scalars % array(iScalar,k,iCell))
+                  scalar_max = max(scalar_max, block % state % time_levs(2) % state % scalars % array(iScalar,k,iCell))
                 enddo
                 enddo
                 write(0,*) ' min, max scalar ',iScalar, scalar_min, scalar_max
-             enddo
+             end do
              block =&gt; block % next
 
           end do
@@ -476,8 +478,8 @@
    subroutine rk_integration_setup( s_old, s_new, grid )
 
      implicit none
-     type (grid_state) :: s_new, s_old
-     type (grid_meta) :: grid
+     type (state_type) :: s_new, s_old
+     type (mesh_type) :: grid
      integer :: iCell, k
 
      grid % ru_save % array = grid % ru % array
@@ -491,17 +493,8 @@
      s_old % rho_p % array = s_new % rho_p % array
      s_old % rho % array = s_new % rho % array
      s_old % pressure % array = s_new % pressure % array
-
      s_old % scalars % array = s_new % scalars % array
 
-     s_old % rho_edge % array = s_new % rho_edge % array
-     s_old % v % array = s_new % v % array
-     s_old % circulation % array = s_new % circulation % array
-     s_old % vorticity % array = s_new % vorticity % array
-     s_old % divergence % array = s_new % divergence % array
-     s_old % ke % array = s_new % ke % array
-     s_old % pv_edge % array = s_new % pv_edge % array
-
    end subroutine rk_integration_setup
 
 !-----
@@ -509,8 +502,8 @@
    subroutine compute_moist_coefficients( state, grid )
 
      implicit none
-     type (grid_state) :: state
-     type (grid_meta) :: grid
+     type (state_type) :: state
+     type (mesh_type) :: grid
 
       integer :: iEdge, iCell, k, cell1, cell2, iq
       integer :: nCells, nEdges, nVertLevels, nCellsSolve
@@ -524,7 +517,7 @@
         do iCell = 1, nCellsSolve
           do k = 2, nVertLevels
             qtot = 0.
-            do iq = moist_start, moist_end
+            do iq = state % moist_start, state % moist_end
               qtot = qtot + 0.5 * (state % scalars % array (iq, k, iCell) + state % scalars % array (iq, k-1, iCell))
             end do
             grid % cqw % array(k,iCell) = 1./(1.+qtot)
@@ -537,7 +530,7 @@
           if (cell1 &lt;= nCellsSolve .or. cell2 &lt;= nCellsSolve) then
             do k = 1, nVertLevels
               qtot = 0.
-              do iq = moist_start, moist_end
+              do iq = state % moist_start, state % moist_end
                  qtot = qtot + 0.5 * ( state % scalars % array (iq, k, cell1) + state % scalars % array (iq, k, cell2) )
               end do
               grid % cqu % array(k,iEdge) = 1./( 1. + qtot)
@@ -561,8 +554,8 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(inout) :: grid
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(inout) :: grid
       real (kind=RKIND), intent(in) :: dts
 
       integer :: i, k, iq
@@ -631,7 +624,7 @@
         do k=1,nVertLevels
 
           qtot = 0.
-          do iq = moist_start, moist_end
+          do iq = s % moist_start, s % moist_end
             qtot = qtot + s % scalars % array (iq, k, i)
           end do
 
@@ -666,15 +659,16 @@
 
       end do ! loop over cells
 
-      end subroutine compute_vert_imp_coefs
+   end subroutine compute_vert_imp_coefs
 
 !------------------------
 
-      subroutine set_smlstep_pert_variables( s_old, s_new, tend, grid )
+   subroutine set_smlstep_pert_variables( s_old, s_new, tend, grid )
 
       implicit none
-      type (grid_state) :: s_new, s_old, tend
-      type (grid_meta) :: grid
+      type (state_type) :: s_new, s_old
+      type (tend_type) :: tend
+      type (mesh_type) :: grid
       integer :: iCell, iEdge, k, cell1, cell2
       integer, dimension(:,:), pointer :: cellsOnEdge
       real, dimension(:,:,:), pointer :: zf, zf3
@@ -728,16 +722,17 @@
       grid % ruAvg % array = 0.
       grid % wwAvg % array = 0.
 
-      end subroutine set_smlstep_pert_variables
+   end subroutine set_smlstep_pert_variables
 
 !-------------------------------
 
-      subroutine advance_acoustic_step( s, tend, grid, dts )
+   subroutine advance_acoustic_step( s, tend, grid, dts )
 
       implicit none
 
-      type (grid_state) :: s, tend
-      type (grid_meta) :: grid
+      type (state_type) :: s
+      type (tend_type) :: tend
+      type (mesh_type) :: grid
       real (kind=RKIND), intent(in) :: dts
 
       real (kind=RKIND), dimension(:,:), pointer :: rho, theta, ru_p, rw_p, rtheta_pp,    &amp;
@@ -949,8 +944,8 @@
       subroutine recover_large_step_variables( s, grid, dt, ns, rk_step )
 
       implicit none
-      type (grid_state) :: s
-      type (grid_meta) :: grid
+      type (state_type) :: s
+      type (mesh_type) :: grid
       integer, intent(in) :: ns, rk_step
       real (kind=RKIND), intent(in) :: dt
 
@@ -1153,7 +1148,7 @@
 
 !---------------------------------------------------------------------------------------
 
-   subroutine advance_scalars( tend, s_old, s_new, grid, dt)
+   subroutine advance_scalars( tend, s_old, s_new, diag, grid, dt)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
    !
    ! Input: s - current model state
@@ -1164,10 +1159,11 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: tend
-      type (grid_state), intent(in) :: s_old
-      type (grid_state), intent(out) :: s_new
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(in) :: tend
+      type (state_type), intent(in) :: s_old
+      type (state_type), intent(inout) :: s_new
+      type (diag_type), intent(in) :: diag
+      type (mesh_type), intent(in) :: grid
       real (kind=RKIND) :: dt
 
       integer :: i, iCell, iEdge, k, iScalar, cell1, cell2
@@ -1179,7 +1175,7 @@
       real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell, qv_init
       integer, dimension(:,:), pointer :: cellsOnEdge
 
-      real (kind=RKIND), dimension( num_scalars, grid % nVertLevels + 1 ) :: wdtn
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nVertLevels + 1 ) :: wdtn
       integer :: nVertLevels
 
       real (kind=RKIND), dimension(:), pointer :: fnm, fnp, rdnw
@@ -1205,7 +1201,7 @@
 
       scalar_old  =&gt; s_old % scalars % array
       scalar_new  =&gt; s_new % scalars % array
-      kdiff       =&gt; s_new % kdiff % array
+      kdiff       =&gt; diag % kdiff % array
       deriv_two   =&gt; grid % deriv_two % array
 !****      uhAvg       =&gt; grid % uhAvg % array
       uhAvg       =&gt; grid % ruAvg % array
@@ -1231,7 +1227,7 @@
 
       h_theta_eddy_visc2 = config_h_theta_eddy_visc2
       v_theta_eddy_visc2 = config_v_theta_eddy_visc2
-      rho_edge     =&gt; s_new % rho_edge % array
+      rho_edge     =&gt; diag % rho_edge % array
       rho          =&gt; s_new % rho % array
       qv_init      =&gt; grid % qv_init % array
       zgrid        =&gt; grid % zgrid % array
@@ -1251,7 +1247,7 @@
             cell2 = cellsOnEdge(2,iEdge)
             if (cell1 &gt; 0 .and. cell2 &gt; 0) then
                do k=1,grid % nVertLevels
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      scalar_edge = 0.5 * (scalar_new(iScalar,k,cell1) + scalar_new(iScalar,k,cell2))
                      flux = uhAvg(k,iEdge) * dvEdge(iEdge)  * scalar_edge
                      scalar_tend(iScalar,k,cell1) = scalar_tend(iScalar,k,cell1) - flux/areaCell(cell1)
@@ -1270,7 +1266,7 @@
   
                do k=1,grid % nVertLevels
    
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      d2fdx2_cell1 = deriv_two(1,1,iEdge) * scalar_new(iScalar,k,cell1)
                      d2fdx2_cell2 = deriv_two(1,2,iEdge) * scalar_new(iScalar,k,cell2)
                      do i=1, grid % nEdgesOnCell % array (cell1)
@@ -1313,7 +1309,7 @@
 
                do k=1,grid % nVertLevels
    
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      d2fdx2_cell1 = deriv_two(1,1,iEdge) * scalar_new(iScalar,k,cell1)
                      d2fdx2_cell2 = deriv_two(1,2,iEdge) * scalar_new(iScalar,k,cell2)
                      do i=1, grid % nEdgesOnCell % array (cell1)
@@ -1350,7 +1346,7 @@
             if (cell1 &gt; 0 .and. cell2 &gt; 0) then
 
                do k=1,grid % nVertLevels
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                     scalar_turb_flux = h_theta_eddy_visc2*prandtl*  &amp;
                                         (scalar_new(iScalar,k,cell2) - scalar_new(iScalar,k,cell1))/dcEdge(iEdge)
                     flux = dvEdge (iEdge) * rho_edge(k,iEdge) * scalar_turb_flux
@@ -1370,7 +1366,7 @@
             if (cell1 &gt; 0 .and. cell2 &gt; 0) then
 
                do k=1,grid % nVertLevels
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                     scalar_turb_flux = 0.5*(kdiff(k,cell1)+kdiff(k,cell2))*prandtl*  &amp;
                                         (scalar_new(iScalar,k,cell2) - scalar_new(iScalar,k,cell1))/dcEdge(iEdge)
                     flux = dvEdge (iEdge) * rho_edge(k,iEdge) * scalar_turb_flux
@@ -1399,7 +1395,7 @@
                z0 = 0.5*(z2+z3)
                zp = 0.5*(z3+z4)
 
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                  scalar_tend(iScalar,k,iCell) = scalar_tend(iScalar,k,iCell) + v_theta_eddy_visc2*prandtl*rho(k,iCell)*(&amp;
                                         (scalar_new(iScalar,k+1,iCell)-scalar_new(iScalar,k  ,iCell))/(zp-z0)                 &amp;
                                        -(scalar_new(iScalar,k  ,iCell)-scalar_new(iScalar,k-1,iCell))/(z0-zm) )/(0.5*(zp-zm))
@@ -1407,7 +1403,7 @@
              end do
 
              if ( .not. config_mix_full) then
-             iScalar = index_qv
+             iScalar = s_new % index_qv
                do k=2,nVertLevels-1
                 z1 = zgrid(k-1,iCell)
                 z2 = zgrid(k  ,iCell)
@@ -1437,18 +1433,18 @@
          wdtn(:,1) = 0.
          if (config_scalar_vadv_order == 2) then
            do k = 2, nVertLevels
-              do iScalar=1,num_scalars
+              do iScalar=1,s_old % num_scalars
                 wdtn(iScalar,k) = wwAvg(k,iCell)*(fnm(k)*scalar_new(iScalar,k,iCell)+fnp(k)*scalar_new(iScalar,k-1,iCell))
               end do
            end do
          else 
            k = 2
-           do iScalar=1,num_scalars
+           do iScalar=1,s_old % num_scalars
              wdtn(iScalar,k) = wwAvg(k,iCell)*(fnm(k)*scalar_new(iScalar,k,iCell)+fnp(k)*scalar_new(iScalar,k-1,iCell))
            enddo
            if ( config_scalar_vadv_order == 3 ) then
              do k=3,nVertLevels-1
-             do iScalar=1,num_scalars
+             do iScalar=1,s_old % num_scalars
                wdtn(iScalar,k) = flux3( scalar_new(iScalar,k-2,iCell),scalar_new(iScalar,k-1,iCell),  &amp;
                                         scalar_new(iScalar,k  ,iCell),scalar_new(iScalar,k+1,iCell),  &amp;
                                         wwAvg(k,iCell), coef_3rd_order )
@@ -1456,14 +1452,14 @@
              end do
            else if ( config_scalar_vadv_order == 4 ) then
              do k=3,nVertLevels-1
-             do iScalar=1,num_scalars
+             do iScalar=1,s_old % num_scalars
                wdtn(iScalar,k) = flux4( scalar_new(iScalar,k-2,iCell),scalar_new(iScalar,k-1,iCell),  &amp;
                                         scalar_new(iScalar,k  ,iCell),scalar_new(iScalar,k+1,iCell), wwAvg(k,iCell) )
              end do
              end do
            end if
            k = nVertLevels
-           do iScalar=1,num_scalars
+           do iScalar=1,s_old % num_scalars
              wdtn(iScalar,k) = wwAvg(k,iCell)*(fnm(k)*scalar_new(iScalar,k,iCell)+fnp(k)*scalar_new(iScalar,k-1,iCell))
            enddo
 
@@ -1471,7 +1467,7 @@
          wdtn(:,nVertLevels+1) = 0.
 
          do k=1,grid % nVertLevelsSolve
-            do iScalar=1,num_scalars
+            do iScalar=1,s_old % num_scalars
               scalar_new(iScalar,k,iCell) = (   scalar_old(iScalar,k,iCell)*h_old(k,iCell) &amp;
                     + dt*( scalar_tend(iScalar,k,iCell) -rdnw(k)*(wdtn(iScalar,k+1)-wdtn(iScalar,k)) ) )/h_new(k,iCell)
                                                                                         
@@ -1482,7 +1478,7 @@
    end subroutine advance_scalars
 
 
-   subroutine advance_scalars_mono( tend, s_old, s_new, grid, dt, rk_step, rk_order, dminfo, cellsToSend, cellsToRecv)
+   subroutine advance_scalars_mono( tend, s_old, s_new, diag, grid, dt, rk_step, rk_order, dminfo, cellsToSend, cellsToRecv)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
    !
    ! Input: s - current model state
@@ -1493,10 +1489,11 @@
 
       implicit none
 
-      type (grid_state), intent(in) :: tend
-      type (grid_state), intent(in) :: s_old
-      type (grid_state), intent(out) :: s_new
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(in) :: tend
+      type (state_type), intent(in) :: s_old
+      type (state_type), intent(inout) :: s_new
+      type (diag_type), intent(in) :: diag
+      type (mesh_type), intent(in) :: grid
       integer, intent(in) :: rk_step, rk_order
       real (kind=RKIND), intent(in) :: dt
       type (dm_info), intent(in) :: dminfo
@@ -1512,10 +1509,10 @@
       real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
       integer, dimension(:,:), pointer :: cellsOnEdge
 
-      real (kind=RKIND), dimension( num_scalars, grid % nEdges+1) :: h_flux
-      real (kind=RKIND), dimension( num_scalars, grid % nCells+1, 2 ) :: v_flux, v_flux_upwind, s_update
-      real (kind=RKIND), dimension( num_scalars, grid % nCells+1, 2 ) :: scale_out, scale_in
-      real (kind=RKIND), dimension( num_scalars ) :: s_max, s_min, s_max_update, s_min_update
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nEdges+1) :: h_flux
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nCells+1, 2 ) :: v_flux, v_flux_upwind, s_update
+      real (kind=RKIND), dimension( s_old % num_scalars, grid % nCells+1, 2 ) :: scale_out, scale_in
+      real (kind=RKIND), dimension( s_old % num_scalars ) :: s_max, s_min, s_max_update, s_min_update
 
       integer :: nVertLevels, km0, km1, ktmp, kcp1, kcm1
 
@@ -1590,18 +1587,18 @@
             if (k &lt; grid % nVertLevels) then
 
                if ((config_scalar_vadv_order == 2) .or. (k==1) .or. (k==grid % nVertLevels)) then
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      v_flux(iScalar,iCell,km0) = dt * wwAvg(k+1,iCell) *   &amp;
                           (fnm(k+1) * scalar_new(iScalar,k+1,iCell) + fnp(k+1) * scalar_new(iScalar,k,iCell))
                   end do
                else if (config_scalar_vadv_order == 3) then
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      v_flux(iScalar,iCell,km0) = dt * flux3( scalar_new(iScalar,k-1,iCell),scalar_new(iScalar,k  ,iCell),  &amp;
                                                              scalar_new(iScalar,k+1,iCell),scalar_new(iScalar,k+2,iCell),  &amp;
                                                              wwAvg(k+1,iCell), coef_3rd_order )
                   end do
                else if (config_scalar_vadv_order == 4) then
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      v_flux(iScalar,iCell,km0) = dt * flux4( scalar_new(iScalar,k-1,iCell),scalar_new(iScalar,k  ,iCell),  &amp;
                                                              scalar_new(iScalar,k+1,iCell),scalar_new(iScalar,k+2,iCell), wwAvg(k+1,iCell) )
                   end do
@@ -1610,7 +1607,7 @@
                cell_upwind = k
                if (wwAvg(k+1,iCell) &gt;= 0) cell_upwind = k+1
 
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   v_flux_upwind(iScalar,iCell,km0) = dt * wwAvg(k+1,iCell) * scalar_old(iScalar,cell_upwind,iCell)
                   v_flux(iScalar,iCell,km0) = v_flux(iScalar,iCell,km0) - v_flux_upwind(iScalar,iCell,km0)
 !                  v_flux(iScalar,iCell,km0) = 0.  ! use only upwind - for testing
@@ -1620,7 +1617,7 @@
 
 
             else
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   v_flux(iScalar,iCell,km0) = 0.
                   v_flux_upwind(iScalar,iCell,km0) = 0.
                   s_update(iScalar,iCell,km0) = scalar_old(iScalar,k,iCell) * h_old(k,iCell)  &amp;
@@ -1640,7 +1637,7 @@
                if (cell1 &gt; 0 .and. cell2 &gt; 0) then
                   cell_upwind = cell2
                   if (uhAvg(k,iEdge) &gt;= 0) cell_upwind = cell1
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      scalar_edge = 0.5 * (scalar_new(iScalar,k,cell1) + scalar_new(iScalar,k,cell2))
                      h_flux(iScalar,iEdge) = dt * uhAvg(k,iEdge) * dvEdge(iEdge) * scalar_edge
                      h_flux_upwind = dt * uhAvg(k,iEdge) * dvEdge(iEdge) * scalar_old(iScalar,k,cell_upwind)
@@ -1660,7 +1657,7 @@
                if (cell1 &gt; 0 .and. cell2 &gt; 0) then
                   cell_upwind = cell2
                   if (uhAvg(k,iEdge) &gt;= 0) cell_upwind = cell1
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
   
                      d2fdx2_cell1 = deriv_two(1,1,iEdge) * scalar_new(iScalar,k,cell1)
                      d2fdx2_cell2 = deriv_two(1,2,iEdge) * scalar_new(iScalar,k,cell2)
@@ -1708,7 +1705,7 @@
 
             do iCell=1,grid % nCells
   
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
    
                   s_max(iScalar) = max(scalar_old(iScalar,k,iCell), scalar_old(iScalar,kcp1,iCell), scalar_old(iScalar,kcm1,iCell))
                   s_min(iScalar) = min(scalar_old(iScalar,k,iCell), scalar_old(iScalar,kcp1,iCell), scalar_old(iScalar,kcm1,iCell))
@@ -1725,7 +1722,7 @@
    
                do i = 1, grid % nEdgesOnCell % array(iCell)  ! go around the edges of each cell
                   if (grid % cellsOnCell % array(i,iCell) &gt; 0) then
-                     do iScalar=1,num_scalars
+                     do iScalar=1,s_old % num_scalars
     
                         s_max(iScalar)  = max(scalar_old(iScalar,k,grid % cellsOnCell % array(i,iCell)), s_max(iScalar))
                         s_min(iScalar)  = min(scalar_old(iScalar,k,grid % cellsOnCell % array(i,iCell)), s_min(iScalar))
@@ -1747,7 +1744,7 @@
    
                if( config_positive_definite ) s_min(:) = 0.
    
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   scale_out (iScalar,iCell,km0) = 1.
                   scale_in (iScalar,iCell,km0) = 1.
                   s_max_update (iScalar) =  s_max_update (iScalar) / h_new (k,iCell)
@@ -1763,16 +1760,16 @@
 
 
             call dmpar_exch_halo_field2dReal(dminfo, scale_out(:,:,1), &amp;
-                                             num_scalars, grid % nCells, &amp;
+                                             s_old % num_scalars, grid % nCells, &amp;
                                              cellsToSend, cellsToRecv)
             call dmpar_exch_halo_field2dReal(dminfo, scale_out(:,:,2), &amp;
-                                             num_scalars, grid % nCells, &amp;
+                                             s_old % num_scalars, grid % nCells, &amp;
                                              cellsToSend, cellsToRecv)
             call dmpar_exch_halo_field2dReal(dminfo, scale_in(:,:,1), &amp;
-                                             num_scalars, grid % nCells, &amp;
+                                             s_old % num_scalars, grid % nCells, &amp;
                                              cellsToSend, cellsToRecv)
             call dmpar_exch_halo_field2dReal(dminfo, scale_in(:,:,2), &amp;
-                                             num_scalars, grid % nCells, &amp;
+                                             s_old % num_scalars, grid % nCells, &amp;
                                              cellsToSend, cellsToRecv)
 
        ! rescale the horizontal fluxes
@@ -1781,7 +1778,7 @@
                cell1 = grid % cellsOnEdge % array(1,iEdge)
                cell2 = grid % cellsOnEdge % array(2,iEdge)
                if (cell1 &gt; 0 .and. cell2 &gt; 0) then
-                  do iScalar=1,num_scalars
+                  do iScalar=1,s_old % num_scalars
                      flux = h_flux(iScalar,iEdge)
                      if (flux &gt; 0) then
                         flux = flux * min(scale_out(iScalar,cell1,km0), scale_in(iScalar,cell2,km0))
@@ -1796,7 +1793,7 @@
        ! rescale the vertical flux
  
             do iCell=1,grid % nCells
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   flux =  v_flux(iScalar,iCell,km1)
                   if (flux &gt; 0) then
                      flux = flux * min(scale_out(iScalar,iCell,km0), scale_in(iScalar,iCell,km1))
@@ -1816,7 +1813,7 @@
 
          do iCell=1,grid % nCells
             !  add in upper vertical flux that was just renormalized
-            do iScalar=1,num_scalars
+            do iScalar=1,s_old % num_scalars
                s_update(iScalar,iCell,km0) = s_update(iScalar,iCell,km0) + rdnw(k) * v_flux(iScalar,iCell,km1)
                if (k &gt; 1) s_update(iScalar,iCell,km1) = s_update(iScalar,iCell,km1) - rdnw(k-1)*v_flux(iScalar,iCell,km1)
             end do
@@ -1826,7 +1823,7 @@
             cell1 = cellsOnEdge(1,iEdge)
             cell2 = cellsOnEdge(2,iEdge)
             if (cell1 &gt; 0 .and. cell2 &gt; 0) then
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   s_update(iScalar,cell1,km0) = s_update(iScalar,cell1,km0) - &amp;
                       h_flux(iScalar,iEdge) / grid % areaCell % array(cell1)
                   s_update(iScalar,cell2,km0) = s_update(iScalar,cell2,km0) + &amp;
@@ -1838,13 +1835,13 @@
          ! decouple from mass
          if (k &gt; 1) then
             do iCell=1,grid % nCells
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   s_update(iScalar,iCell,km1) = s_update(iScalar,iCell,km1) / h_new(k-1,iCell)
                end do
             end do
  
             do iCell=1,grid % nCells
-               do iScalar=1,num_scalars
+               do iScalar=1,s_old % num_scalars
                   scalar_new(iScalar,k-1,iCell) = s_update(iScalar,iCell,km1) 
                end do
             end do
@@ -1857,7 +1854,7 @@
       end do
 
       do iCell=1,grid % nCells
-         do iScalar=1,num_scalars
+         do iScalar=1,s_old % num_scalars
             scalar_new(iScalar,grid % nVertLevels,iCell) = s_update(iScalar,iCell,km1) / h_new(grid%nVertLevels,iCell)
          end do
       end do
@@ -1866,7 +1863,7 @@
 
 !----
 
-   subroutine compute_dyn_tend(tend, s, grid)
+   subroutine compute_dyn_tend(tend, s, diag, grid)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
    ! Compute height and normal wind tendencies, as well as diagnostic variables
    !
@@ -1880,9 +1877,10 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (state_type), intent(in) :: s
+      type (diag_type), intent(in) :: diag
+      type (mesh_type), intent(in) :: grid
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, iq
       real (kind=RKIND) :: flux, vorticity_abs, rho_vertex, workpv, q, upstream_bias
@@ -1940,21 +1938,21 @@
       coef_3rd_order = config_coef_3rd_order
 
       rho          =&gt; s % rho % array
-      rho_edge     =&gt; s % rho_edge % array
+      rho_edge     =&gt; diag % rho_edge % array
       rb           =&gt; grid % rho_base % array
       rr           =&gt; s % rho_p % array
       u            =&gt; s % u % array
-      v            =&gt; s % v % array
-      kdiff        =&gt; s % kdiff % array
+      v            =&gt; diag % v % array
+      kdiff        =&gt; diag % kdiff % array
       ru           =&gt; grid % ru % array
       w            =&gt; s % w % array
       rw           =&gt; grid % rw % array
       theta        =&gt; s % theta % array
-      circulation  =&gt; s % circulation % array
-      divergence   =&gt; s % divergence % array
-      vorticity    =&gt; s % vorticity % array
-      ke           =&gt; s % ke % array
-      pv_edge      =&gt; s % pv_edge % array
+      circulation  =&gt; diag % circulation % array
+      divergence   =&gt; diag % divergence % array
+      vorticity    =&gt; diag % vorticity % array
+      ke           =&gt; diag % ke % array
+      pv_edge      =&gt; diag % pv_edge % array
       pp           =&gt; s % pressure % array
       pressure_b   =&gt; grid % pressure_base % array
       h_divergence =&gt; grid % h_divergence % array
@@ -2044,7 +2042,7 @@
            h_divergence(k,iCell) = divergence_ru(k,iCell)
            tend_rho(k,iCell) = -divergence_ru(k,iCell)-rdzw(k)*(rw(k+1,iCell)-rw(k,iCell))
 
-           do iq = moist_start, moist_end
+           do iq = s % moist_start, s % moist_end
               qtot(k,iCell) = qtot(k,iCell) + s % scalars % array (iq, k, iCell)
            end do
 
@@ -2977,7 +2975,7 @@
 
 !-------
 
-   subroutine compute_solve_diagnostics(dt, s, grid)
+   subroutine compute_solve_diagnostics(dt, s, diag, grid)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
    ! Compute diagnostic fields used in the tendency computations
    !
@@ -2989,8 +2987,9 @@
       implicit none
 
       real (kind=RKIND), intent(in) :: dt
-      type (grid_state), intent(inout) :: s
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: s
+      type (diag_type), intent(inout) :: diag
+      type (mesh_type), intent(in) :: grid
 
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, cov
@@ -3005,23 +3004,20 @@
       integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge
 
 
-!      h           =&gt; s % h % array
       h           =&gt; s % rho % array
       u           =&gt; s % u % array
-      v           =&gt; s % v % array
-      vh          =&gt; s % rv % array
-      h_edge      =&gt; s % rho_edge % array
-!      tend_h      =&gt; s % h % array
-!      tend_u      =&gt; s % u % array
-      circulation =&gt; s % circulation % array
-      vorticity   =&gt; s % vorticity % array
-      divergence  =&gt; s % divergence % array
-      ke          =&gt; s % ke % array
-      pv_edge     =&gt; s % pv_edge % array
-      pv_vertex   =&gt; s % pv_vertex % array
-      pv_cell     =&gt; s % pv_cell % array
-      gradPVn     =&gt; s % gradPVn % array
-      gradPVt     =&gt; s % gradPVt % array
+      v           =&gt; diag % v % array
+      vh          =&gt; diag % rv % array
+      h_edge      =&gt; diag % rho_edge % array
+      circulation =&gt; diag % circulation % array
+      vorticity   =&gt; diag % vorticity % array
+      divergence  =&gt; diag % divergence % array
+      ke          =&gt; diag % ke % array
+      pv_edge     =&gt; diag % pv_edge % array
+      pv_vertex   =&gt; diag % pv_vertex % array
+      pv_cell     =&gt; diag % pv_cell % array
+      gradPVn     =&gt; diag % gradPVn % array
+      gradPVt     =&gt; diag % gradPVt % array
 
       weightsOnEdge     =&gt; grid % weightsOnEdge % array
       kiteAreasOnVertex =&gt; grid % kiteAreasOnVertex % array
@@ -3257,8 +3253,8 @@
 
    implicit none
    
-   type (grid_state), intent(inout) :: state
-   type (grid_meta), intent(inout) :: grid
+   type (state_type), intent(inout) :: state
+   type (mesh_type), intent(inout) :: grid
 
    integer :: k,iEdge,i,iCell1,iCell2
 
@@ -3276,71 +3272,71 @@
 
    subroutine qd_kessler( state_old, state_new, grid, dt )
 
-   implicit none
+      implicit none
+      
+      type (state_type), intent(inout) :: state_old, state_new
+      type (mesh_type), intent(inout) :: grid
+      real (kind=RKIND), intent(in) :: dt
    
-   type (grid_state), intent(inout) :: state_old, state_new
-   type (grid_meta), intent(inout) :: grid
-   real (kind=RKIND), intent(in) :: dt
+      real (kind=RKIND), dimension( grid % nVertLevels ) :: t, rho, p, dzu, qv, qc, qr, qc1, qr1
+   
+      integer :: k,iEdge,i,iCell,nz1
+      real (kind=RKIND) :: p0,rcv
+   
+   
+      write(0,*) ' in qd_kessler '
+   
+      p0 = 1.e+05
+      rcv = rgas/(cp-rgas)
+      nz1 = grid % nVertLevels
+   
+      do iCell = 1, grid % nCellsSolve
+   
+        do k = 1, grid % nVertLevels
+   
+          grid % rt_diabatic_tend % array(k,iCell) = state_new % theta % array(k,iCell)
+   
+          t(k) = state_new % theta % 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 % array(k,iCell)
+          p(k) = grid % 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))
+          dzu(k) = grid % dzu % array(k)
+   
+        end do
+   
+        call kessler( t,qv,qc,qc1,qr,qr1,rho,p,dt,dzu,nz1, 1)
+   
+        do k = 1, grid % nVertLevels
+   
+          state_new % theta % array(k,iCell) = t(k)*(1.+1.61*qv(k))
+          grid % rt_diabatic_tend % array(k,iCell) = state_new % rho % array(k,iCell) *  &amp;
+                     (state_new % theta % array(k,iCell) - grid % rt_diabatic_tend % array(k,iCell))/dt
+          grid % rtheta_p % array(k,iCell) = state_new % rho % array(k,iCell) * state_new % theta % array(k,iCell)  &amp;
+                                         - grid % rtheta_base % array(k,iCell) 
+          state_new % scalars % array(state_new % index_qv,k,iCell) = qv(k)
+          state_new % scalars % array(state_new % index_qc,k,iCell) = qc(k)
+          state_new % scalars % array(state_new % index_qr,k,iCell) = qr(k)
+   
+          grid % exner % array(k,iCell) =                                       &amp;
+                                 ( grid % zz % array(k,iCell)*(rgas/p0) * ( &amp;
+                                     grid % rtheta_p % array(k,iCell)       &amp;
+                                   + grid % rtheta_base % array(k,iCell) ) )**rcv
+   
+          state_new % pressure % array(k,iCell) =                                               &amp;
+               grid % zz % array(k,iCell) * rgas * (                                        &amp;
+                 grid % exner % array(k,iCell)*grid % rtheta_p % array(k,iCell)             &amp;
+                                   +grid % rtheta_base % array(k,iCell) *                   &amp;
+                        (grid % exner % array(k,iCell) - grid % exner_base % array(k,iCell)) )
+        end do
+   
+      end do
+   
+      write(0,*) ' exiting qd_kessler '
 
-   real (kind=RKIND), dimension( grid % nVertLevels ) :: t, rho, p, dzu, qv, qc, qr, qc1, qr1
-
-   integer :: k,iEdge,i,iCell,nz1
-   real (kind=RKIND) :: p0,rcv
-
-
-   write(0,*) ' in qd_kessler '
-
-   p0 = 1.e+05
-   rcv = rgas/(cp-rgas)
-   nz1 = grid % nVertLevels
-
-   do iCell = 1, grid % nCellsSolve
-
-     do k = 1, grid % nVertLevels
-
-       grid % rt_diabatic_tend % array(k,iCell) = state_new % theta % array(k,iCell)
-
-       t(k) = state_new % theta % array(k,iCell)/(1. + 1.61*state_new % scalars % array(index_qv,k,iCell))
-       rho(k) = grid % zz % array(k,iCell)*state_new % rho % array(k,iCell)
-       p(k) = grid % exner % array(k,iCell)
-       qv(k) = max(0.,state_new % scalars % array(index_qv,k,iCell))
-       qc(k) = max(0.,state_new % scalars % array(index_qc,k,iCell))
-       qr(k) = max(0.,state_new % scalars % array(index_qr,k,iCell))
-       qc1(k) = max(0.,state_old % scalars % array(index_qc,k,iCell))
-       qr1(k) = max(0.,state_old % scalars % array(index_qr,k,iCell))
-       dzu(k) = grid % dzu % array(k)
-
-     end do
-
-     call kessler( t,qv,qc,qc1,qr,qr1,rho,p,dt,dzu,nz1, 1)
-
-     do k = 1, grid % nVertLevels
-
-       state_new % theta % array(k,iCell) = t(k)*(1.+1.61*qv(k))
-       grid % rt_diabatic_tend % array(k,iCell) = &amp;
-                  (state_new % theta % array(k,iCell) - grid % rt_diabatic_tend % array(k,iCell))/dt
-       grid % rtheta_p % array(k,iCell) = state_new % rho % array(k,iCell) * state_new % theta % array(k,iCell)  &amp;
-                                      - grid % rtheta_base % array(k,iCell) 
-       state_new % scalars % array(index_qv,k,iCell) = qv(k)
-       state_new % scalars % array(index_qc,k,iCell) = qc(k)
-       state_new % scalars % array(index_qr,k,iCell) = qr(k)
-
-       grid % exner % array(k,iCell) =                                       &amp;
-                              ( grid % zz % array(k,iCell)*(rgas/p0) * ( &amp;
-                                  grid % rtheta_p % array(k,iCell)       &amp;
-                                + grid % rtheta_base % array(k,iCell) ) )**rcv
-
-       state_new % pressure % array(k,iCell) =                                               &amp;
-            grid % zz % array(k,iCell) * rgas * (                                        &amp;
-              grid % exner % array(k,iCell)*grid % rtheta_p % array(k,iCell)             &amp;
-                                +grid % rtheta_base % array(k,iCell) *                   &amp;
-                     (grid % exner % array(k,iCell) - grid % exner_base % array(k,iCell)) )
-     end do
-
-   end do
-
-   write(0,*) ' exiting qd_kessler '
-
    end subroutine qd_kessler
 
 !-----------------------------------------------------------------------

Modified: branches/atmos_physics/src/core_nhyd_atmos/mpas_interface.F
===================================================================
--- branches/atmos_physics/src/core_nhyd_atmos/mpas_interface.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_nhyd_atmos/mpas_interface.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -7,6 +7,12 @@
 
    type (domain_type), intent(inout) :: domain
 
+!
+! Note: initialize_advection_rk() and initialize_deformation_weights()
+!       are called from within setup_nhyd_test_case(); after initialization
+!       is migrated to a separate program/processing step, we can uncomment
+!       calls to these routines in in mpas_init() if necessary
+!
    call setup_nhyd_test_case(domain)
 
 end subroutine mpas_setup_test_case
@@ -15,7 +21,7 @@
 subroutine mpas_init(block, mesh, dt)
 
    use grid_types
-   use advection
+!   use advection
    use time_integration
    use vector_reconstruction
 #ifdef DO_PHYSICS
@@ -27,19 +33,23 @@
    implicit none
 
    type (block_type), intent(inout) :: block
-   type (grid_meta), intent(inout) :: mesh
+   type (mesh_type), intent(inout) :: mesh
    real (kind=RKIND), intent(in) :: dt
 
-!   call compute_solver_constants(block % time_levs(1) % state, mesh)
-!   call compute_state_diagnostics(block % time_levs(1) % state, mesh) 
-   call init_coupled_diagnostics( block % time_levs(1) % state, mesh)
-   call compute_solve_diagnostics(dt, block % time_levs(1) % state, mesh)  ! ok for nonhydrostatic model
-   call initialize_advection_rk(mesh)
+   call init_coupled_diagnostics( block % state % time_levs(1) % state, mesh)
+   call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, block % diag, mesh)
+
    call rbfInterp_initialize(mesh)
    call init_reconstruct(mesh)
-   call reconstruct(block % time_levs(1) % state, mesh)
-   call initialize_deformation_weights(mesh)
+   call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
 
+!
+! Note: The following initialization calls have been moved to mpas_setup_test_case()
+!       since values computed by these routines are needed to produce initial fields
+!
+!   call initialize_advection_rk(mesh)
+!   call initialize_deformation_weights(mesh)
+
 #ifdef DO_PHYSICS
    !check that all the physics options are correctly defined and that at least one physics
    !parameterization is called (using the logical moist_physics):
@@ -48,9 +58,9 @@
    !proceed with initialization of physics parameterization if moist_physics is set to true:
    if(moist_physics) then
 !initialization of all physics variables in registry:
-      call physics_registry_init(config_do_restart, mesh, block % time_levs(1) % state)
+      call physics_registry_init(config_do_restart, mesh, block % state % time_levs(1) % state)
       call physics_wrf_interface(mesh)
-      call physics_init(mesh, block % time_levs(1) % state)
+      call physics_init(mesh, block % state % time_levs(1) % state)
    endif
 #endif
 

Modified: branches/atmos_physics/src/core_ocean/Registry
===================================================================
--- branches/atmos_physics/src/core_ocean/Registry        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_ocean/Registry        2010-10-13 20:25:17 UTC (rev 549)
@@ -7,7 +7,6 @@
 namelist integer   sw_model config_ntimesteps        7500
 namelist integer   sw_model config_output_interval   500
 namelist integer   sw_model config_stats_interval    100
-namelist real      sw_model config_visc              0.0
 namelist character io       config_input_name        grid.nc
 namelist character io       config_output_name       output.nc
 namelist character io       config_restart_name      restart.nc
@@ -16,7 +15,10 @@
 namelist real      restart  config_restart_time      172800.0
 namelist character grid     config_vert_grid_type    isopycnal
 namelist real      grid     config_rho0              1028
-namelist real      hmix     config_hor_diffusion     2000.0
+namelist real      hmix     config_h_mom_eddy_visc2     0.0
+namelist real      hmix     config_h_mom_eddy_visc4     0.0
+namelist real      hmix     config_h_tracer_eddy_diff2  0.0
+namelist real      hmix     config_h_tracer_eddy_diff4  0.0
 namelist character vmix     config_vert_visc_type    const
 namelist character vmix     config_vert_diff_type    const
 namelist real      vmix     config_vert_viscosity    2.5e-4
@@ -30,7 +32,6 @@
 namelist character advection  config_hor_tracer_adv  'centered'
 namelist character advection  config_vert_tracer_adv 'centered'
 
-
 #
 # dim  type  name_in_file  name_in_code
 #
@@ -46,122 +47,131 @@
 dim nVertLevelsP1 nVertLevels+1
 
 #
-# var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
+# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
 #
-var real    xtime ( Time ) ro xtime - -
+var persistent real    xtime ( Time ) 2 ro xtime state - -
 
-var real    latCell ( nCells ) iro latCell - -
-var real    lonCell ( nCells ) iro lonCell - -
-var real    xCell ( nCells ) iro xCell - -
-var real    yCell ( nCells ) iro yCell - -
-var real    zCell ( nCells ) iro zCell - -
-var integer indexToCellID ( nCells ) iro indexToCellID - -
+var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
+var persistent real    lonCell ( nCells ) 0 iro lonCell mesh - -
+var persistent real    xCell ( nCells ) 0 iro xCell mesh - -
+var persistent real    yCell ( nCells ) 0 iro yCell mesh - -
+var persistent real    zCell ( nCells ) 0 iro zCell mesh - -
+var persistent integer indexToCellID ( nCells ) 0 iro indexToCellID mesh - -
 
-var real    latEdge ( nEdges ) iro latEdge - -
-var real    lonEdge ( nEdges ) iro lonEdge - -
-var real    xEdge ( nEdges ) iro xEdge - -
-var real    yEdge ( nEdges ) iro yEdge - -
-var real    zEdge ( nEdges ) iro zEdge - -
-var integer indexToEdgeID ( nEdges ) iro indexToEdgeID - -
+var persistent real    latEdge ( nEdges ) 0 iro latEdge mesh - -
+var persistent real    lonEdge ( nEdges ) 0 iro lonEdge mesh - -
+var persistent real    xEdge ( nEdges ) 0 iro xEdge mesh - -
+var persistent real    yEdge ( nEdges ) 0 iro yEdge mesh - -
+var persistent real    zEdge ( nEdges ) 0 iro zEdge mesh - -
+var persistent integer indexToEdgeID ( nEdges ) 0 iro indexToEdgeID mesh - -
 
-var real    latVertex ( nVertices ) iro latVertex - -
-var real    lonVertex ( nVertices ) iro lonVertex - -
-var real    xVertex ( nVertices ) iro xVertex - -
-var real    yVertex ( nVertices ) iro yVertex - -
-var real    zVertex ( nVertices ) iro zVertex - -
-var integer indexToVertexID ( nVertices ) iro indexToVertexID - -
+var persistent real    latVertex ( nVertices ) 0 iro latVertex mesh - -
+var persistent real    lonVertex ( nVertices ) 0 iro lonVertex mesh - -
+var persistent real    xVertex ( nVertices ) 0 iro xVertex mesh - -
+var persistent real    yVertex ( nVertices ) 0 iro yVertex mesh - -
+var persistent real    zVertex ( nVertices ) 0 iro zVertex mesh - -
+var persistent integer indexToVertexID ( nVertices ) 0 iro indexToVertexID mesh - -
 
-var integer cellsOnEdge ( TWO nEdges ) iro cellsOnEdge - -
-var integer nEdgesOnCell ( nCells ) iro nEdgesOnCell - -
-var integer nEdgesOnEdge ( nEdges ) iro nEdgesOnEdge - -
-var integer edgesOnCell ( maxEdges nCells ) iro edgesOnCell - -
-var integer edgesOnEdge ( maxEdges2 nEdges ) iro edgesOnEdge - -
+var persistent integer cellsOnEdge ( TWO nEdges ) 0 iro cellsOnEdge mesh - -
+var persistent integer nEdgesOnCell ( nCells ) 0 iro nEdgesOnCell mesh - -
+var persistent integer nEdgesOnEdge ( nEdges ) 0 iro nEdgesOnEdge mesh - -
+var persistent integer edgesOnCell ( maxEdges nCells ) 0 iro edgesOnCell mesh - -
+var persistent integer edgesOnEdge ( maxEdges2 nEdges ) 0 iro edgesOnEdge mesh - -
 
-var real    weightsOnEdge ( maxEdges2 nEdges ) iro weightsOnEdge - -
-var real    dvEdge ( nEdges ) iro dvEdge - -
-var real    dcEdge ( nEdges ) iro dcEdge - -
-var real    angleEdge ( nEdges ) iro angleEdge - -
-var real    areaCell ( nCells ) iro areaCell - -
-var real    areaTriangle ( nVertices ) iro areaTriangle - -
+var persistent real    weightsOnEdge ( maxEdges2 nEdges ) 0 iro weightsOnEdge mesh - -
+var persistent real    dvEdge ( nEdges ) 0 iro dvEdge mesh - -
+var persistent real    dcEdge ( nEdges ) 0 iro dcEdge mesh - -
+var persistent real    angleEdge ( nEdges ) 0 iro angleEdge mesh - -
+var persistent real    areaCell ( nCells ) 0 iro areaCell mesh - -
+var persistent real    areaTriangle ( nVertices ) 0 iro areaTriangle mesh - -
 
-var real    edgeNormalVectors ( R3 nEdges ) o edgeNormalVectors - -
-var real    localVerticalUnitVectors ( R3 nCells ) o localVerticalUnitVectors - -
-var real    cellTangentPlane ( R3 TWO nEdges ) o cellTangentPlane - -
+var persistent real    edgeNormalVectors ( R3 nEdges ) 0 o edgeNormalVectors mesh - -
+var persistent real    localVerticalUnitVectors ( R3 nCells ) 0 o localVerticalUnitVectors mesh - -
+var persistent real    cellTangentPlane ( R3 TWO nEdges ) 0 o cellTangentPlane mesh - -
 
-var integer cellsOnCell ( maxEdges nCells ) iro cellsOnCell - -
-var integer verticesOnCell ( maxEdges nCells ) iro verticesOnCell - -
-var integer verticesOnEdge ( TWO nEdges ) iro verticesOnEdge - -
-var integer edgesOnVertex ( vertexDegree nVertices ) iro edgesOnVertex - -
-var integer cellsOnVertex ( vertexDegree nVertices ) iro cellsOnVertex - -
-var real    kiteAreasOnVertex ( vertexDegree nVertices ) iro kiteAreasOnVertex - -
-var real    fEdge ( nEdges ) iro fEdge - -
-var real    fVertex ( nVertices ) iro fVertex - -
-var real    h_s ( nCells ) iro h_s - -
+var persistent integer cellsOnCell ( maxEdges nCells ) 0 iro cellsOnCell mesh - -
+var persistent integer verticesOnCell ( maxEdges nCells ) 0 iro verticesOnCell mesh - -
+var persistent integer verticesOnEdge ( TWO nEdges ) 0 iro verticesOnEdge mesh - -
+var persistent integer edgesOnVertex ( vertexDegree nVertices ) 0 iro edgesOnVertex mesh - -
+var persistent integer cellsOnVertex ( vertexDegree nVertices ) 0 iro cellsOnVertex mesh - -
+var persistent real    kiteAreasOnVertex ( vertexDegree nVertices ) 0 iro kiteAreasOnVertex mesh - -
+var persistent real    fEdge ( nEdges ) 0 iro fEdge mesh - -
+var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
+var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
 # Arrays required for reconstruction of velocity field
-var real    coeffs_reconstruct ( R3 maxEdges nCells ) - coeffs_reconstruct - -
+var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
 # Arrays for z-level version of mpas-ocean
-var integer maxLevelsCell ( nCells ) iro kmaxCell - -
-var integer maxLevelsEdge ( nEdges ) iro kmaxEdge - -
-var real hZLevel ( nVertLevels ) iro hZLevel - -
-var real zMidZLevel ( nVertLevels ) iro zMidZLevel - -
-var real zTopZLevel ( nVertLevelsP1 ) iro zTopZLevel - -
+var persistent integer maxLevelsCell ( nCells ) 0 iro kmaxCell mesh - -
+var persistent integer maxLevelsEdge ( nEdges ) 0 iro kmaxEdge mesh - -
+var persistent real hZLevel ( nVertLevels ) 0 iro hZLevel mesh - -
+var persistent real zMidZLevel ( nVertLevels ) 0 iro zMidZLevel mesh - -
+var persistent real zTopZLevel ( nVertLevelsP1 ) 0 iro zTopZLevel mesh - -
 
 # Boundary conditions: read from input, saved in restart and written to output
-var integer boundaryEdge ( nVertLevels nEdges ) iro boundaryEdge - -
-var integer boundaryVertex ( nVertLevels nVertices ) iro boundaryVertex - -
-var real    u_src ( nVertLevels nEdges ) iro u_src - -
+var persistent integer boundaryEdge ( nVertLevels nEdges ) 0 iro boundaryEdge mesh - -
+var persistent integer boundaryVertex ( nVertLevels nVertices ) 0 iro boundaryVertex 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
-var real    u ( nVertLevels nEdges Time ) iro u - -
-var real    h ( nVertLevels nCells Time ) iro h - -
-var real    rho ( nVertLevels nCells Time ) iro rho - -
-var real    temperature ( nVertLevels nCells Time ) iro temperature tracers dynamics
-var real    salinity ( nVertLevels nCells Time ) iro salinity tracers dynamics
-var real    tracer1 ( nVertLevels nCells Time ) iro tracer1 tracers testing
-var real    tracer2 ( nVertLevels nCells Time ) iro tracer2 tracers testing
+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    rho ( nVertLevels nCells Time ) 2 iro rho state - -
+var persistent real    temperature ( nVertLevels nCells Time ) 2 iro temperature state tracers dynamics
+var persistent real    salinity ( nVertLevels nCells Time ) 2 iro salinity state tracers dynamics
+var persistent real    tracer1 ( nVertLevels nCells Time ) 2 iro tracer1 state tracers testing
+var persistent real    tracer2 ( nVertLevels nCells Time ) 2 iro tracer2 state tracers testing
 
+# 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_temperature ( nVertLevels nCells Time ) 1 - temperature tend tracers dynamics
+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
+var persistent real    tend_tracer2 ( nVertLevels nCells Time ) 1 - tracer2 tend tracers testing
+
 # Diagnostic fields: only written to output
-var real    v ( nVertLevels nEdges Time ) o v - -
-var real    divergence ( nVertLevels nCells Time ) o divergence - -
-var real    vorticity ( nVertLevels nVertices Time ) o vorticity - -
-var real    pv_edge ( nVertLevels nEdges Time ) o pv_edge - -
-var real    h_edge ( nVertLevels nEdges Time ) o h_edge - -
-var real    ke ( nVertLevels nCells Time ) o ke - -
-var real    ke_edge ( nVertLevels nEdges Time ) o ke_edge - -
-var real    pv_vertex ( nVertLevels nVertices Time ) o pv_vertex - -
-var real    pv_cell ( nVertLevels nCells Time ) o pv_cell - -
-var real    uReconstructX ( nVertLevels nCells Time ) o uReconstructX - -
-var real    uReconstructY ( nVertLevels nCells Time ) o uReconstructY - -
-var real    uReconstructZ ( nVertLevels nCells Time ) o uReconstructZ - -
-var real    uReconstructZonal ( nVertLevels nCells Time ) o uReconstructZonal - -
-var real    uReconstructMeridional ( nVertLevels nCells Time ) o uReconstructMeridional - -
-var real    zMid ( nVertLevels nCells Time ) o zMid - -
-var real    zTop ( nVertLevelsP1 nCells Time ) o zTop - -
-var real    zMidEdge ( nVertLevels nEdges Time ) o zMidEdge - -
-var real    zTopEdge ( nVertLevelsP1 nEdges Time ) o zTopEdge - -
-var real    p ( nVertLevels nCells Time ) o p - -
-var real    pTop ( nVertLevelsP1 nCells Time ) o pTop - -
-var real    pZLevel ( nVertLevels nCells Time ) o pZLevel - -
-var real    MontPot ( nVertLevels nCells Time ) o MontPot - -
-var real    wTop ( nVertLevelsP1 nCells Time ) o wTop - -
-var real    ssh ( nCells Time ) o ssh - -
+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 - -
+var persistent real    pv_edge ( nVertLevels nEdges Time ) 2 o pv_edge state - -
+var persistent real    h_edge ( nVertLevels nEdges Time ) 2 o h_edge state - -
+var persistent real    h_vertex ( nVertLevels nVertices Time ) 2 o h_vertex state - -
+var persistent real    ke ( nVertLevels nCells Time ) 2 o ke state - -
+var persistent real    ke_edge ( nVertLevels nEdges Time ) 2 o ke_edge state - -
+var persistent real    pv_vertex ( nVertLevels nVertices Time ) 2 o pv_vertex state - -
+var persistent real    pv_cell ( nVertLevels nCells Time ) 2 o pv_cell state - -
+var persistent real    uReconstructX ( nVertLevels nCells Time ) 1 o uReconstructX diag - -
+var persistent real    uReconstructY ( nVertLevels nCells Time ) 1 o uReconstructY diag - -
+var persistent real    uReconstructZ ( nVertLevels nCells Time ) 1 o uReconstructZ diag - -
+var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 1 o uReconstructZonal diag - -
+var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 1 o uReconstructMeridional diag - -
+var persistent real    zMid ( nVertLevels nCells Time ) 2 o zMid state - -
+var persistent real    zTop ( nVertLevelsP1 nCells Time ) 2 o zTop state - -
+var persistent real    zMidEdge ( nVertLevels nEdges Time ) 2 o zMidEdge state - -
+var persistent real    zTopEdge ( nVertLevelsP1 nEdges Time ) 2 o zTopEdge state - -
+var persistent real    p ( nVertLevels nCells Time ) 2 o p state - -
+var persistent real    pTop ( nVertLevelsP1 nCells Time ) 2 o pTop state - -
+var persistent real    pZLevel ( nVertLevels nCells Time ) 2 o pZLevel state - -
+var persistent real    MontPot ( nVertLevels nCells Time ) 2 o MontPot state - -
+var persistent real    wTop ( nVertLevelsP1 nCells Time ) 2 o wTop state - -
+var persistent real    ssh ( nCells Time ) 2 o ssh state - -
 
 # Other diagnostic variables: neither read nor written to any files
-var real    vh ( nVertLevels nEdges Time ) - vh - -
-var real    circulation ( nVertLevels nVertices Time ) - circulation - -
-var real    gradPVt ( nVertLevels nEdges Time ) - gradPVt - -
-var real    gradPVn ( nVertLevels nEdges Time ) - gradPVn - -
+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 - -
 
 # xsad 10-02-05:
 # Globally reduced diagnostic variables: only written to output
-var real    areaCellGlobal ( Time ) o areaCellGlobal - -
-var real    areaEdgeGlobal ( Time ) o areaEdgeGlobal - -
-var real    areaTriangleGlobal ( Time ) o areaTriangleGlobal - -
+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 - -
 
-var real    volumeCellGlobal ( Time ) o volumeCellGlobal - -
-var real    volumeEdgeGlobal ( Time ) o volumeEdgeGlobal - -
-var real    CFLNumberGlobal ( Time ) o CFLNumberGlobal - -
+var persistent real    volumeCellGlobal ( Time ) 2 o volumeCellGlobal state - -
+var persistent real    volumeEdgeGlobal ( Time ) 2 o volumeEdgeGlobal state - -
+var persistent real    CFLNumberGlobal ( Time ) 2 o CFLNumberGlobal state - -
 # xsad 10-02-05 end
 

Modified: branches/atmos_physics/src/core_ocean/module_global_diagnostics.F
===================================================================
--- branches/atmos_physics/src/core_ocean/module_global_diagnostics.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_ocean/module_global_diagnostics.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -27,8 +27,8 @@
       implicit none
 
       type (dm_info), intent(in) :: dminfo
-      type (grid_state), intent(inout) :: state
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
       integer, intent(in) :: timeIndex
       real (kind=RKIND), intent(in) :: dt
 
@@ -43,7 +43,7 @@
       real (kind=RKIND) :: volumeCellGlobal, volumeEdgeGlobal, CFLNumberGlobal
       real (kind=RKIND) ::  localCFL, localSum
       integer :: elementIndex, variableIndex, nVariables, nSums, nMaxes, nMins
-      integer :: timeLevel,k,i
+      integer :: timeLevel,k,i, num_tracers
 
       integer, parameter :: kMaxVariables = 1024 ! this must be a little more than double the number of variables to be reduced
 
@@ -51,6 +51,8 @@
 
       integer :: fileID
 
+      num_tracers = state % num_tracers
+
       nVertLevels = grid % nVertLevels
       nCellsSolve = grid % nCellsSolve
       nEdgesSolve = grid % nEdgesSolve

Modified: branches/atmos_physics/src/core_ocean/module_test_cases.F
===================================================================
--- branches/atmos_physics/src/core_ocean/module_test_cases.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_ocean/module_test_cases.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -28,10 +28,10 @@
       ! mrp 100507: for diagnostic output
       integer :: iTracer
       real (kind=RKIND), dimension(:), pointer :: xCell,yCell, &amp;
-         hZLevel, zMidZLevel, zTopZLevel 
+         hZLevel, zMidZLevel, zTopZLevel, latCell,LonCell
       real (kind=RKIND), dimension(:,:), pointer :: h, u, u_src, rho
       real (kind=RKIND), dimension(:,:,:), pointer :: tracers
-      real (kind=RKIND) :: delta_rho
+      real (kind=RKIND) :: delta_rho, pi, latCenter, lonCenter, dist
       integer :: nCells, nEdges, nVertices, nVertLevels
       ! mrp 100507 end: for diagnostic output
 
@@ -44,7 +44,7 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_1(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_1(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -54,7 +54,7 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_2(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_2(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -64,7 +64,7 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_5(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_5(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -74,7 +74,7 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_6(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_6(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             block_ptr =&gt; block_ptr % next
          end do
 
@@ -89,8 +89,8 @@
       do while (associated(block_ptr))
 
         do i=2,nTimeLevs
-           call copy_state(block_ptr % time_levs(1) % state, &amp;
-                           block_ptr % time_levs(i) % state)
+           call copy_state(block_ptr % state % time_levs(i) % state, &amp;
+                           block_ptr % state % time_levs(1) % state)
         end do
 
         block_ptr =&gt; block_ptr % next
@@ -99,13 +99,15 @@
       ! Initialize z-level grid variables from h, read in from input file.
       block_ptr =&gt; domain % blocklist
       do while (associated(block_ptr))
-         h          =&gt; block_ptr % time_levs(1) % state % h % array
-         u          =&gt; block_ptr % time_levs(1) % state % u % array
-         rho        =&gt; block_ptr % time_levs(1) % state % rho % array
-         tracers    =&gt; block_ptr % time_levs(1) % state % tracers % array
+         h          =&gt; block_ptr % state % time_levs(1) % state % h % array
+         u          =&gt; block_ptr % state % time_levs(1) % state % u % array
+         rho        =&gt; block_ptr % state % time_levs(1) % state % rho % array
+         tracers    =&gt; block_ptr % state % time_levs(1) % state % tracers % array
          u_src      =&gt; block_ptr % mesh % u_src % array
          xCell      =&gt; block_ptr % mesh % xCell % array
          yCell      =&gt; block_ptr % mesh % yCell % array
+         latCell      =&gt; block_ptr % mesh % latCell % array
+         lonCell      =&gt; block_ptr % mesh % lonCell % array
 
          hZLevel    =&gt; block_ptr % mesh % hZLevel % array
          zMidZLevel =&gt; block_ptr % mesh % zMidZLevel % array
@@ -116,6 +118,13 @@
          nVertices   = block_ptr % mesh % nVertices
          nVertLevels = block_ptr % mesh % nVertLevels
 
+         pi=3.1415
+         ! Tracer blob in Central Pacific, away from boundaries:
+         !latCenter=pi/16;  lonCenter=9./8.*pi
+
+         ! Tracer blob in Central Pacific, near boundaries:
+         latCenter=pi*2./16;  lonCenter=13./16.*pi
+
          if (config_vert_grid_type.eq.'zlevel') then
            ! These should eventually be in an input file.  For now
            ! I just read them in from h(:,1).
@@ -138,22 +147,30 @@
            ! Set tracers, if not done in grid.nc file
            !tracers = 0.0
            do iCell = 1,nCells
+             dist = sqrt( (latCell(iCell)-latCenter)**2 + (lonCell(iCell)-lonCenter)**2)
              do iLevel = 1,nVertLevels
               ! for 20 layer test
-              ! tracers(index_temperature,iLevel,iCell) = 5.0  ! temperature
-              ! tracers(index_salinity,iLevel,iCell) = 1.4 + iLevel*0.6  ! salinity
+              ! tracers(block_ptr % state % time_levs(1) % state % index_temperature,iLevel,iCell) = 5.0  ! temperature
+              ! tracers(block_ptr % state % time_levs(1) % state % index_salinity,iLevel,iCell) = 1.4 + iLevel*0.6  ! salinity
 
               ! for x3, 25 layer test
-              tracers(index_temperature,iLevel,iCell) = 10.0  ! temperature
-              tracers(index_salinity,iLevel,iCell) = 1.4 + iLevel*0.6  ! salinity
+              !tracers(block_ptr % state % time_levs(1) % state % index_temperature,iLevel,iCell) = 10.0  ! temperature
+              !tracers(block_ptr % state % time_levs(1) % state % index_salinity,iLevel,iCell) = 1.4 + iLevel*0.6  ! salinity
 
-               tracers(index_tracer1,iLevel,iCell) = 1.0
-               tracers(index_tracer2,iLevel,iCell) = &amp;
-                 (yCell(iCell)/4000.e3 + xCell(iCell)/2500.e3 )/2.0
+              ! tracers(block_ptr % state % time_levs(1) % state % index_tracer1,iLevel,iCell) = 1.0
+              ! tracers(block_ptr % state % time_levs(1) % state % index_tracer2,iLevel,iCell) = &amp;
+              !    (yCell(iCell)/4000.e3 + xCell(iCell)/2500.e3 )/2.0
 
+              ! Tracer blob 
+              !if (dist.lt.pi/16) then
+              !  tracers(block_ptr % state % time_levs(1) % state % index_tracer1,iLevel,iCell) = 1.0
+              !!else  
+              !  tracers(block_ptr % state % time_levs(1) % state % index_tracer1,iLevel,iCell) = 0.0
+              !endif
+
               rho(iLevel,iCell) = 1000.0*(  1.0 &amp;
-                 - 2.5e-4*tracers(index_temperature,iLevel,iCell) &amp;
-                 + 7.6e-4*tracers(index_salinity,iLevel,iCell))
+                 - 2.5e-4*tracers(block_ptr % state % time_levs(1) % state % index_temperature,iLevel,iCell) &amp;
+                 + 7.6e-4*tracers(block_ptr % state % time_levs(1) % state % index_salinity,iLevel,iCell))
 
              enddo
            enddo
@@ -177,7 +194,7 @@
          enddo
 
          print '(10a)', 'itracer ilevel  min tracer  max tracer'
-         do iTracer=1,num_tracers
+         do iTracer=1,block_ptr % state % time_levs(1) % state % num_tracers
          do iLevel = 1,nVertLevels
             print '(2i5,20es12.4)', iTracer,ilevel, &amp;
               minval(tracers(itracer,iLevel,1:nCells)), maxval(tracers(itracer,iLevel,1:nCells))
@@ -202,8 +219,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: u0 = 2.0 * pii * a / (12.0 * 86400.0)
       real (kind=RKIND), parameter :: h0 = 1000.0
@@ -278,8 +295,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: u0 = 2.0 * pii * a / (12.0 * 86400.0)
       real (kind=RKIND), parameter :: gh0 = 29400.0
@@ -369,8 +386,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: u0 = 20.
       real (kind=RKIND), parameter :: gh0 = 5960.0*gravity
@@ -491,8 +508,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: h0 = 8000.0
       real (kind=RKIND), parameter :: w = 7.848e-6

Modified: branches/atmos_physics/src/core_ocean/module_time_integration.F
===================================================================
--- branches/atmos_physics/src/core_ocean/module_time_integration.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_ocean/module_time_integration.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -37,10 +37,10 @@
 
       block =&gt; domain % blocklist
       do while (associated(block))
-         block % time_levs(2) % state % xtime % scalar &amp;
-           = block % time_levs(1) % state % xtime % scalar + dt
+         block % state % time_levs(2) % state % xtime % scalar &amp;
+           = block % state % time_levs(1) % state % xtime % scalar + dt
 
-         if (isNaN(sum(block % time_levs(2) % state % u % array))) then
+         if (isNaN(sum(block % state % time_levs(2) % state % u % array))) then
             write(0,*) 'Abort: NaN detected'
             call dmpar_abort(dminfo)
          endif
@@ -69,13 +69,16 @@
 
       integer :: iCell, k, i
       type (block_type), pointer :: block
+      type (state_type) :: provis
 
-      integer, parameter :: PROVIS = 1
-      integer, parameter :: TEND   = 2
       integer :: rk_step
 
       real (kind=RKIND), dimension(4) :: rk_weights, rk_substep_weights
 
+      block =&gt; domain % blocklist
+      call allocate_state(provis, &amp;
+                          block % mesh % nCells, block % mesh % nEdges, block % mesh % maxEdges, block % mesh % maxEdges2, &amp;
+                          block % mesh % nVertices, block % mesh % vertexDegree, block % mesh % nVertLevels )
 
       !
       ! Initialize time_levs(2) with state at current time
@@ -86,16 +89,16 @@
       block =&gt; domain % blocklist
       do while (associated(block))
 
-         block % time_levs(2) % state % u % array(:,:) = block % time_levs(1) % state % u % array(:,:)
-         block % time_levs(2) % state % h % array(:,:) = block % time_levs(1) % state % h % array(:,:)
+         block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
+         block % state % time_levs(2) % state % h % array(:,:) = block % state % time_levs(1) % state % h % array(:,:)
          do iCell=1,block % mesh % nCells  ! couple tracers to h
            do k=1,block % mesh % nVertLevels
-             block % time_levs(2) % state % tracers % array(:,k,iCell) = block % time_levs(1) % state % tracers % array(:,k,iCell) &amp;
-                                                                       * block % time_levs(1) % state % h % array(k,iCell)
+             block % state % time_levs(2) % state % tracers % array(:,k,iCell) = block % state % time_levs(1) % state % tracers % array(:,k,iCell) &amp;
+                                                                       * block % state % time_levs(1) % state % h % array(k,iCell)
             end do
          end do
 
-         call copy_state(block % time_levs(1) % state, block % intermediate_step(PROVIS))
+         call copy_state(provis, block % state % time_levs(1) % state)
 
          block =&gt; block % next
       end do
@@ -119,9 +122,19 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(PROVIS) % pv_edge % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, provis % 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 dmpar_exch_halo_field2dReal(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 dmpar_exch_halo_field2dReal(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
         end do
 
@@ -129,9 +142,9 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call compute_tend(block % intermediate_step(TEND), block % intermediate_step(PROVIS), block % mesh)
-           call compute_scalar_tend(block % intermediate_step(TEND), block % intermediate_step(PROVIS), block % mesh)
-           call enforce_boundaryEdge(block % intermediate_step(TEND), block % mesh)
+           call compute_tend(block % tend, provis, block % mesh)
+           call compute_scalar_tend(block % tend, provis, block % mesh)
+           call enforce_boundaryEdge(block % tend, block % mesh)
            block =&gt; block % next
         end do
 
@@ -139,14 +152,14 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % u % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % u % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                             block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % h % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % h % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field3dReal(domain % dminfo, block % intermediate_step(TEND) % tracers % array(:,:,:), &amp;
-                                            num_tracers, block % mesh % nVertLevels, block % mesh % nCells, &amp;
+           call dmpar_exch_halo_field3dReal(domain % dminfo, block % tend % tracers % array(:,:,:), &amp;
+                                            block % tend % num_tracers, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
            block =&gt; block % next
         end do
@@ -157,24 +170,24 @@
            block =&gt; domain % blocklist
            do while (associated(block))
 
-              block % intermediate_step(PROVIS) % u % array(:,:)       = block % time_levs(1) % state % u % array(:,:)  &amp;
-                                         + rk_substep_weights(rk_step) * block % intermediate_step(TEND) % u % array(:,:)
-              block % intermediate_step(PROVIS) % h % array(:,:)       = block % time_levs(1) % state % h % array(:,:)  &amp;
-                                         + rk_substep_weights(rk_step) * block % intermediate_step(TEND) % h % array(:,:)
+              provis % u % array(:,:)       = block % state % time_levs(1) % state % u % array(:,:)  &amp;
+                                         + rk_substep_weights(rk_step) * block % tend % u % array(:,:)
+              provis % h % array(:,:)       = block % state % time_levs(1) % state % h % array(:,:)  &amp;
+                                         + rk_substep_weights(rk_step) * block % tend % h % array(:,:)
               do iCell=1,block % mesh % nCells
                  do k=1,block % mesh % nVertLevels
-                    block % intermediate_step(PROVIS) % tracers % array(:,k,iCell) = ( &amp;
-                                                                      block % time_levs(1) % state % h % array(k,iCell) * &amp;
-                                                                      block % time_levs(1) % state % tracers % array(:,k,iCell)  &amp;
-                                      + rk_substep_weights(rk_step) * block % intermediate_step(TEND) % tracers % array(:,k,iCell) &amp;
-                                                                     ) / block % intermediate_step(PROVIS) % h % array(k,iCell)
+                    provis % tracers % array(:,k,iCell) = ( &amp;
+                                                                      block % state % time_levs(1) % state % h % array(k,iCell) * &amp;
+                                                                      block % state % time_levs(1) % state % tracers % array(:,k,iCell)  &amp;
+                                      + rk_substep_weights(rk_step) * block % tend % tracers % array(:,k,iCell) &amp;
+                                                                     ) / provis % h % array(k,iCell)
                  end do
 
               end do
               if (config_test_case == 1) then    ! For case 1, wind field should be fixed
-                 block % intermediate_step(PROVIS) % u % array(:,:) = block % time_levs(1) % state % u % array(:,:)
+                 provis % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
               end if
-              call compute_solve_diagnostics(dt, block % intermediate_step(PROVIS), block % mesh)
+              call compute_solve_diagnostics(dt, provis, block % mesh)
               block =&gt; block % next
            end do
         end if
@@ -185,16 +198,16 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           block % time_levs(2) % state % u % array(:,:) = block % time_levs(2) % state % u % array(:,:) &amp;
-                                   + rk_weights(rk_step) * block % intermediate_step(TEND) % u % array(:,:) 
-           block % time_levs(2) % state % h % array(:,:) = block % time_levs(2) % state % h % array(:,:) &amp;
-                                   + rk_weights(rk_step) * block % intermediate_step(TEND) % h % array(:,:) 
+           block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(2) % state % u % array(:,:) &amp;
+                                   + rk_weights(rk_step) * block % tend % u % array(:,:) 
+           block % state % time_levs(2) % state % h % array(:,:) = block % state % time_levs(2) % state % h % array(:,:) &amp;
+                                   + rk_weights(rk_step) * block % tend % h % array(:,:) 
 
            do iCell=1,block % mesh % nCells
               do k=1,block % mesh % nVertLevels
-                 block % time_levs(2) % state % tracers % array(:,k,iCell) =  &amp;
-                                                                       block % time_levs(2) % state % tracers % array(:,k,iCell) &amp;
-                                               + rk_weights(rk_step) * block % intermediate_step(TEND) % tracers % array(:,k,iCell)
+                 block % state % time_levs(2) % state % tracers % array(:,k,iCell) =  &amp;
+                                                                       block % state % time_levs(2) % state % tracers % array(:,k,iCell) &amp;
+                                               + rk_weights(rk_step) * block % tend % tracers % array(:,k,iCell)
               end do
            end do
 
@@ -213,23 +226,25 @@
       do while (associated(block))
          do iCell=1,block % mesh % nCells
             do k=1,block % mesh % nVertLevels
-               block % time_levs(2) % state % tracers % array(:,k,iCell) = &amp;
-                                                                     block % time_levs(2) % state % tracers % array(:,k,iCell)  &amp;
-                                                                   / block % time_levs(2) % state % h % array(k,iCell)
+               block % state % time_levs(2) % state % tracers % array(:,k,iCell) = &amp;
+                                                                     block % state % time_levs(2) % state % tracers % array(:,k,iCell)  &amp;
+                                                                   / block % state % time_levs(2) % state % h % array(k,iCell)
             end do
          end do
 
          if (config_test_case == 1) then    ! For case 1, wind field should be fixed
-            block % time_levs(2) % state % u % array(:,:) = block % time_levs(1) % state % u % array(:,:)
+            block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
          end if
 
-         call compute_solve_diagnostics(dt, block % time_levs(2) % state, block % mesh)
+         call compute_solve_diagnostics(dt, block % state % time_levs(2) % state, block % mesh)
 
-         call reconstruct(block % time_levs(2) % state, block % mesh)
+         call reconstruct(block % state % time_levs(2) % state, block % diag, block % mesh)
 
          block =&gt; block % next
       end do
 
+      call deallocate_state(provis)
+
    end subroutine rk4
 
 
@@ -245,15 +260,16 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(in) :: grid
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j
 
       integer :: nCells, nEdges, nVertices, nVertLevels
+      real (kind=RKIND) :: h_mom_eddy_visc2, h_mom_eddy_visc4
       real (kind=RKIND) :: flux, vorticity_abs, h_vertex, workpv, q, &amp;
-        upstream_bias, wTopEdge, rho0Inv
+        upstream_bias, wTopEdge, rho0Inv, r
       real (kind=RKIND), dimension(:), pointer :: &amp;
         h_s, fVertex, fEdge, dvEdge, dcEdge, areaCell, areaTriangle, &amp;
         zMidZLevel, zTopZLevel 
@@ -270,6 +286,11 @@
       real (kind=RKIND) :: u_diffusion
       real (kind=RKIND), dimension(:), allocatable:: fluxVertTop,w_dudzTopEdge, vertViscTop
 
+      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
 
@@ -319,6 +340,9 @@
 
       u_src =&gt; grid % u_src % array
 
+      h_mom_eddy_visc2 = config_h_mom_eddy_visc2
+      h_mom_eddy_visc4 = config_h_mom_eddy_visc4
+
       !
       ! height tendency: horizontal advection term -</font>
<font color="gray">abla\cdot ( hu)
       !
@@ -370,12 +394,16 @@
       endif ! coordinate type
 
       !
+      ! velocity tendency: start accumulating tendency terms
+      !
+      tend_u(:,:) = 0.0
+
+      !
       ! velocity tendency: vertical advection term -w du/dz
       !
       allocate(w_dudzTopEdge(nVertLevels+1))
       w_dudzTopEdge(1) = 0.0
       w_dudzTopEdge(nVertLevels+1) = 0.0
-      tend_u(:,:) = 0.0
       if (config_vert_grid_type.eq.'zlevel') then
        do iEdge=1,grid % nEdgesSolve
          cell1 = cellsOnEdge(1,iEdge)
@@ -424,23 +452,138 @@
       endif
 
       !
-      ! velocity tendency: -q(h u^\perp) - </font>
<font color="red">abla K 
-      !                +</font>
<font color="black">u_h(</font>
<font color="black">abla \delta + {\bf k}\times </font>
<font color="blue">abla \xi)
+      ! velocity tendency: del2 dissipation, </font>
<font color="black">u_2 </font>
<font color="blue">abla^2 u
+      !   computed as </font>
<font color="black">u( </font>
<font color="black">abla divergence + k \times </font>
<font color="red">abla vorticity )
+      !   strictly only valid for h_mom_eddy_visc2 == constant
       !
-      ! Compute diffusion, computed as </font>
<font color="black">abla divergence - k \times </font>
<font color="red">abla vorticity
-      !                    only valid for visc == constant
-       do iEdge=1,grid % nEdgesSolve
+      if ( h_mom_eddy_visc2 &gt; 0.0 ) then
+         do iEdge=1,grid % nEdgesSolve
+            cell1 = cellsOnEdge(1,iEdge)
+            cell2 = cellsOnEdge(2,iEdge)
+            vertex1 = verticesOnEdge(1,iEdge)
+            vertex2 = verticesOnEdge(2,iEdge)
+
+            do k=1,nVertLevels
+
+               ! Here -( vorticity(k,vertex2) - vorticity(k,vertex1) ) / dvEdge(iEdge)
+               ! is - </font>
<font color="blue">abla vorticity pointing from vertex 2 to vertex 1, or equivalently 
+               !    + k \times </font>
<font color="blue">abla vorticity pointing from cell1 to cell2.
+
+               u_diffusion = ( divergence(k,cell2)  - divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
+                            -( vorticity(k,vertex2) - vorticity(k,vertex1) ) / dvEdge(iEdge)
+               u_diffusion = h_mom_eddy_visc2 * u_diffusion
+
+               tend_u(k,iEdge) = tend_u(k,iEdge) + u_diffusion
+
+            end do
+         end do
+      end if
+
+      !
+      ! velocity tendency: del4 dissipation, -</font>
<font color="black">u_4 </font>
<font color="blue">abla^4 u
+      !   computed as </font>
<font color="black">abla^2 u = </font>
<font color="black">abla divergence + k \times </font>
<font color="blue">abla vorticity
+      !   applied recursively.
+      !   strictly only valid for h_mom_eddy_visc4 == constant
+      !
+      if ( h_mom_eddy_visc4 &gt; 0.0 ) then
+
+         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
+
+         ! Compute </font>
<font color="black">abla^2 u = </font>
<font color="black">abla divergence + k \times </font>
<font color="blue">abla vorticity
+         do iEdge=1,grid % nEdges
+            cell1 = cellsOnEdge(1,iEdge)
+            cell2 = cellsOnEdge(2,iEdge)
+            vertex1 = verticesOnEdge(1,iEdge)
+            vertex2 = verticesOnEdge(2,iEdge)
+
+            do k=1,nVertLevels
+
+               u_diffusion = ( divergence(k,cell2)  - divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
+                            -( vorticity(k,vertex2) - vorticity(k,vertex1)) / dvEdge(iEdge)

+               delsq_u(k,iEdge) = delsq_u(k,iEdge) + u_diffusion
+
+            end do
+         end do
+
+         ! vorticity using </font>
<font color="blue">abla^2 u
+         delsq_circulation(:,:) = 0.0
+         do iEdge=1,nEdges
+            vertex1 = verticesOnEdge(1,iEdge)
+            vertex2 = verticesOnEdge(2,iEdge)
+            do k=1,nVertLevels
+               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,nVertLevels
+               delsq_vorticity(k,iVertex) = delsq_circulation(k,iVertex) * r
+            end do
+         end do
+
+         ! Divergence using </font>
<font color="blue">abla^2 u
+         delsq_divergence(:,:) = 0.0
+         do iEdge=1,nEdges
+            cell1 = cellsOnEdge(1,iEdge)
+            cell2 = cellsOnEdge(2,iEdge)
+            do k=1,nVertLevels
+              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)
+            end do
+         end do
+         do iCell = 1,nCells
+            r = 1.0 / areaCell(iCell)
+            do k = 1,nVertLevels
+               delsq_divergence(k,iCell) = delsq_divergence(k,iCell) * r
+            end do
+         end do
+
+         ! Compute - \kappa </font>
<font color="blue">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
+            cell1 = cellsOnEdge(1,iEdge)
+            cell2 = cellsOnEdge(2,iEdge)
+            vertex1 = verticesOnEdge(1,iEdge)
+            vertex2 = verticesOnEdge(2,iEdge)
+
+            do k=1,nVertLevels
+
+               u_diffusion = (  delsq_divergence(k,cell2) &amp;
+                              - delsq_divergence(k,cell1) ) / dcEdge(iEdge)  &amp;
+                            -(  delsq_vorticity(k,vertex2) &amp;
+                              - delsq_vorticity(k,vertex1) ) / dvEdge(iEdge)

+               tend_u(k,iEdge) = tend_u(k,iEdge) - h_mom_eddy_visc4 * u_diffusion
+            end do
+         end do
+
+         deallocate(delsq_divergence)
+         deallocate(delsq_u)
+         deallocate(delsq_circulation)
+         deallocate(delsq_vorticity)
+
+      end if
+
+      !
+      ! velocity tendency: nonlinear Coriolis term and grad of kinetic energy
+      !
+      do iEdge=1,grid % nEdgesSolve
          cell1 = cellsOnEdge(1,iEdge)
          cell2 = cellsOnEdge(2,iEdge)
-         vertex1 = verticesOnEdge(1,iEdge)
-         vertex2 = verticesOnEdge(2,iEdge)
 
          do k=1,nVertLevels
 
-            u_diffusion =   ( divergence(k,cell2)  -  divergence(k,cell1) ) / dcEdge(iEdge) &amp;
-                           -(vorticity(k,vertex2)  - vorticity(k,vertex1) ) / dvEdge(iEdge)
-            u_diffusion = config_visc * u_diffusion
-
             q = 0.0
             do j = 1,nEdgesOnEdge(iEdge)
                eoe = edgesOnEdge(j,iEdge)
@@ -449,7 +592,6 @@
             end do
             tend_u(k,iEdge) = tend_u(k,iEdge)     &amp;
                    + q     &amp;
-                   + u_diffusion &amp;
                    - (   ke(k,cell2) - ke(k,cell1) ) / dcEdge(iEdge)
 
          end do
@@ -471,13 +613,6 @@
            - 1.0e-3*u(nVertLevels,iEdge) &amp;
              *sqrt(2.0*ke_edge(nVertLevels,iEdge))
 
-         ! mrp 100603 The following method is more straight forward, 
-         ! that the above method of computing ke_edge, but I have
-         ! not verified that v is working correctly yet.
-         !tend_u(nVertLevels,iEdge) = tend_u(nVertLevels,iEdge)  &amp;
-         !  - 1.0e-3*u(nVertLevels,iEdge) &amp;
-         !    *sqrt(u(nVertLevels,iEdge)**2 + v(nVertLevels,iEdge)**2)
-
          ! old bottom drag, just linear friction
          ! du/dt = u/tau where tau=100 days.
          !tend_u(nVertLevels,iEdge) = tend_u(nVertLevels,iEdge)  &amp;
@@ -540,12 +675,13 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(in) :: grid
 
       integer :: iCell, iEdge, k, iTracer, cell1, cell2, upwindCell,&amp;
         nEdges, nCells, nVertLevels
+      real (kind=RKIND) :: h_tracer_eddy_diff2, h_tracer_eddy_diff4, invAreaCell1, invAreaCell2, tracer_turb_flux
       real (kind=RKIND) :: flux, tracer_edge, r
       real (kind=RKIND) :: dist
       real (kind=RKIND), dimension(:), pointer :: &amp;
@@ -554,14 +690,15 @@
         u,h,wTop, h_edge, zMid, zTop
       real (kind=RKIND), dimension(:,:,:), pointer :: &amp;
         tracers, tend_tr
+      integer, dimension(:,:), pointer :: boundaryEdge
       type (dm_info) :: dminfo
 
       integer, dimension(:), pointer :: nEdgesOnCell, nEdgesOnEdge
       integer, dimension(:,:), pointer :: cellsOnEdge
       real (kind=RKIND), dimension(:), pointer :: &amp;
         zTopZLevel 
-      real (kind=RKIND), dimension(:,:), allocatable:: fluxVertTop, tracerTop
-      real (kind=RKIND), dimension(:,:,:), allocatable::tr_flux, tr_div
+      real (kind=RKIND), dimension(:,:), allocatable:: fluxVertTop, tracerTop, boundaryMask
+      real (kind=RKIND), dimension(:,:,:), allocatable::tr_flux, tr_div, delsq_tracer
 
       real (kind=RKIND), dimension(:), allocatable:: vertDiffTop
 
@@ -580,11 +717,16 @@
       dvEdge            =&gt; grid % dvEdge % array
       dcEdge            =&gt; grid % dcEdge % array
       zTopZLevel        =&gt; grid % zTopZLevel % array
+      boundaryEdge      =&gt; grid % boundaryEdge % array
 
       nEdges      = grid % nEdges
       nCells      = grid % nCells
       nVertLevels = grid % nVertLevels
 
+
+      h_tracer_eddy_diff2 = config_h_tracer_eddy_diff2
+      h_tracer_eddy_diff4 = config_h_tracer_eddy_diff4
+
       !
       ! tracer tendency: horizontal advection term -div( h \phi u)
       !
@@ -596,7 +738,7 @@
          cell2 = cellsOnEdge(2,iEdge)
          if (cell1 &lt;= nCells .and. cell2 &lt;= nCells) then
             do k=1,nVertLevels
-               do iTracer=1,num_tracers
+               do iTracer=1,s % num_tracers
                   tracer_edge = 0.5 * (  tracers(iTracer,k,cell1) &amp;
                                        + tracers(iTracer,k,cell2))
                   flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge) &amp;
@@ -620,7 +762,7 @@
                else
                  upwindCell = cell2
                endif
-               do iTracer=1,num_tracers
+               do iTracer=1,s % num_tracers
                   flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge) &amp;
                          * tracers(iTracer,k,upwindCell)
                   tend_tr(iTracer,k,cell1) = tend_tr(iTracer,k,cell1) - flux
@@ -633,7 +775,7 @@
       endif
       do iCell=1,grid % nCellsSolve
          do k=1,grid % nVertLevelsSolve
-            do iTracer=1,num_tracers
+            do iTracer=1,s % num_tracers
                tend_tr(iTracer,k,iCell) = tend_tr(iTracer,k,iCell) / areaCell(iCell)
             end do
          end do
@@ -642,14 +784,14 @@
       !
       ! tracer tendency: vertical advection term -d/dz( h \phi w)
       !
-      allocate(tracerTop(num_tracers,nVertLevels+1))
+      allocate(tracerTop(s % num_tracers,nVertLevels+1))
       tracerTop(:,1)=0.0
       tracerTop(:,nVertLevels+1)=0.0
       do iCell=1,grid % nCellsSolve 
 
          if (config_vert_tracer_adv.eq.'centered') then
            do k=2,nVertLevels
-             do iTracer=1,num_tracers
+             do iTracer=1,s % num_tracers
                tracerTop(iTracer,k) = ( tracers(iTracer,k-1,iCell) &amp;
                                        +tracers(iTracer,k  ,iCell))/2.0
              end do
@@ -662,7 +804,7 @@
              else
                upwindCell = k-1
              endif
-             do iTracer=1,num_tracers
+             do iTracer=1,s % num_tracers
                tracerTop(iTracer,k) = tracers(iTracer,upwindCell,iCell)
              end do
            end do
@@ -670,7 +812,7 @@
          endif
 
          do k=1,nVertLevels  
-            do iTracer=1,num_tracers
+            do iTracer=1,s % num_tracers
                tend_tr(iTracer,k,iCell) = tend_tr(iTracer,k,iCell) &amp;
                   - (   wTop(k  ,iCell)*tracerTop(iTracer,k  ) &amp;
                       - wTop(k+1,iCell)*tracerTop(iTracer,k+1))
@@ -681,61 +823,118 @@
       deallocate(tracerTop)
 
       !
-      ! tracer tendency: horizontal tracer diffusion 
-      !   div(h \kappa_h </font>
<font color="blue">abla\phi )
+      ! tracer tendency: del2 horizontal tracer diffusion, div(h \kappa_2 </font>
<font color="red">abla \phi)
       !
-      ! first compute \kappa_h </font>
<font color="red">abla\phi at horizontal edges.
-      allocate(tr_flux(num_tracers,nVertLevels,nEdges))
-      tr_flux(:,:,:) = 0.0
-      do iEdge=1,nEdges
-        cell1 = cellsOnEdge(1,iEdge)
-        cell2 = cellsOnEdge(2,iEdge)
-        if (cell1 &lt;= nCells .and. cell2 &lt;= nCells) then
-          do k=1,nVertLevels
-            do iTracer=1,num_tracers
-              tr_flux(iTracer,k,iEdge) =  h_edge(k,iEdge)*config_hor_diffusion *    &amp;
-                 (Tracers(iTracer,k,cell2) - Tracers(iTracer,k,cell1))/dcEdge(iEdge)
+      if ( h_tracer_eddy_diff2 &gt; 0.0 ) then
+
+         !
+         ! 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,grid % nEdges
+            cell1 = grid % cellsOnEdge % array(1,iEdge)
+            cell2 = grid % cellsOnEdge % array(2,iEdge)
+            invAreaCell1 = 1.0/areaCell(cell1)
+            invAreaCell2 = 1.0/areaCell(cell2)
+
+            do k=1,grid % nVertLevels
+              do iTracer=1,s % num_tracers
+                 ! \kappa_2 </font>
<font color="blue">abla \phi on edge
+                 tracer_turb_flux = h_tracer_eddy_diff2 &amp;
+                    *(  tracers(iTracer,k,cell2) &amp;
+                      - tracers(iTracer,k,cell1))/dcEdge(iEdge)
+
+                 ! div(h \kappa_2 </font>
<font color="blue">abla \phi) at cell center
+                 flux = dvEdge (iEdge) * h_edge(k,iEdge) &amp;
+                    * tracer_turb_flux * boundaryMask(k, iEdge)
+                 tend_tr(iTracer,k,cell1) = tend_tr(iTracer,k,cell1) + flux * invAreaCell1
+                 tend_tr(iTracer,k,cell2) = tend_tr(iTracer,k,cell2) - flux * invAreaCell2
+              end do
+            end do
+
+         end do
+
+        deallocate(boundaryMask)
+
+      end if
+
+      !
+      ! tracer tendency: del4 horizontal tracer diffusion, &amp;
+      !    div(h \kappa_4 </font>
<font color="black">abla [div(h </font>
<font color="blue">abla \phi)])
+      !
+      if ( h_tracer_eddy_diff4 &gt; 0.0 ) then
+
+         !
+         ! 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
+
+         allocate(delsq_tracer(s % num_tracers,nVertLevels, nCells+1))
+
+         delsq_tracer(:,:,:) = 0.
+
+         ! first del2: div(h </font>
<font color="blue">abla \phi) at cell center
+         do iEdge=1,grid % nEdges
+            cell1 = grid % cellsOnEdge % array(1,iEdge)
+            cell2 = grid % cellsOnEdge % array(2,iEdge)
+
+            do k=1,grid % nVertLevels
+              do iTracer=1,s % 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)
+              end do
+            end do
+
+         end do
+
+         do iCell = 1, nCells
+            r = 1.0 / areaCell(iCell)
+            do k=1,nVertLevels
+            do iTracer=1,s % 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="red">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)
+
+            do k=1,grid % nVertLevels
+            do iTracer=1,s % num_tracers
+               tracer_turb_flux = h_tracer_eddy_diff4 &amp;
+                  *(  delsq_tracer(iTracer,k,cell2)  &amp;
+                    - delsq_tracer(iTracer,k,cell1))/dcEdge(iEdge)
+               flux = dvEdge (iEdge) * tracer_turb_flux
+
+               tend_tr(iTracer,k,cell1) = tend_tr(iTracer,k,cell1) &amp; 
+                  - flux * invAreaCell1 * boundaryMask(k,iEdge)
+               tend_tr(iTracer,k,cell2) = tend_tr(iTracer,k,cell2) &amp;
+                  + flux * invAreaCell2 * boundaryMask(k,iEdge)
+
+            end do
             enddo
-          enddo
-        endif
-      enddo
 
-      ! Compute the divergence, div(h \kappa_h </font>
<font color="red">abla\phi) at cell centers
-      allocate(tr_div(num_tracers,nVertLevels,nCells))
-      tr_div(:,:,:) = 0.0
-      do iEdge=1,nEdges
-         cell1 = cellsOnEdge(1,iEdge)
-         cell2 = cellsOnEdge(2,iEdge)
-         if (cell1 &lt;= nCells) then
-           do k=1,nVertLevels
-             do iTracer=1,num_tracers
-               tr_div(iTracer,k,cell1) = tr_div(iTracer,k,cell1) &amp;
-                + tr_flux(iTracer,k,iEdge)*dvEdge(iEdge)
-             enddo
-           enddo
-         endif
-         if (cell2 &lt;= nCells) then
-           do k=1,nVertLevels
-             do iTracer=1,num_tracers
-               tr_div(iTracer,k,cell2) = tr_div(iTracer,k,cell2) &amp;
-                 - tr_flux(iTracer,k,iEdge)*dvEdge(iEdge)
-             enddo
-           enddo
-         end if
-      end do
+         end do
 
-      ! add div(h \kappa_h </font>
<font color="gray">abla\phi ) to tracer tendency
-      do iCell = 1,nCells
-        r = 1.0 / areaCell(iCell)
-        do k = 1,nVertLevels
-           do iTracer=1,num_tracers
-              tend_tr(iTracer,k,iCell) = tend_tr(iTracer,k,iCell) &amp;
-                + tr_div(iTracer,k,iCell)*r
-           enddo
-        enddo
-      enddo
-      deallocate(tr_flux, tr_div)
+         deallocate(delsq_tracer)
 
+      end if
+
       !
       ! tracer tendency: vertical diffusion h d/dz( \kappa_v d\phi/dz)
       !
@@ -760,12 +959,12 @@
         call dmpar_abort(dminfo)
       endif
 
-      allocate(fluxVertTop(num_tracers,nVertLevels+1))
+      allocate(fluxVertTop(s % num_tracers,nVertLevels+1))
       fluxVertTop(:,1) = 0.0
       fluxVertTop(:,nVertLevels+1) = 0.0
       do iCell=1,grid % nCellsSolve 
          do k=2,nVertLevels
-           do iTracer=1,num_tracers
+           do iTracer=1,s % num_tracers
              ! compute \kappa_v d\phi/dz
              fluxVertTop(iTracer,k) = vertDiffTop(k) &amp;
                 * (tracers(iTracer,k-1,iCell) - tracers(iTracer,k,iCell) )&amp;
@@ -775,7 +974,7 @@
 
          do k=1,nVertLevels
            dist = zTop(k,iCell) - zTop(k+1,iCell)
-           do iTracer=1,num_tracers
+           do iTracer=1,s % num_tracers
              tend_tr(iTracer,k,iCell) = tend_tr(iTracer,k,iCell) &amp;
                + h(k,iCell)*(fluxVertTop(iTracer,k) - fluxVertTop(iTracer,k+1))/dist
            enddo
@@ -788,7 +987,7 @@
           ! print some diagnostics - for debugging
 !         print *, 'after vertical mixing',&amp;
 ! 'iTracer,k, minval(tend_tr(itracer,k,:)), maxval(tend_tr(itracer,k,:))'
-!         do iTracer=1,num_tracers
+!         do iTracer=1,s % num_tracers
 !         do k = 1,nVertLevels
 !            print '(2i5,20es12.4)', iTracer,k, &amp;
 !              minval(tend_tr(itracer,k,:)), maxval(tend_tr(itracer,k,:))
@@ -811,8 +1010,8 @@
       implicit none
 
       real (kind=RKIND), intent(in) :: dt
-      type (grid_state), intent(inout) :: s
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: s
+      type (mesh_type), intent(in) :: grid
 
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, cov
@@ -1128,8 +1327,8 @@
           do k=1,nVertLevels
             ! Linear equation of state, for the time being
             rho(k,iCell) = 1000.0*(  1.0 &amp;
-               - 2.5e-4*tracers(index_temperature,k,iCell) &amp;
-               + 7.6e-4*tracers(index_salinity,k,iCell))
+               - 2.5e-4*tracers(s % index_temperature,k,iCell) &amp;
+               + 7.6e-4*tracers(s % index_salinity,k,iCell))
           end do
         end do
       endif
@@ -1194,8 +1393,9 @@
          pZLevel(1,iCell) = rho(1,iCell)*gravity &amp;
             * (h(1,iCell)-0.5*hZLevel(1)) 
          do k=2,nVertLevels
-            delta_p = rho(k,iCell)*gravity*hZLevel(k)
-            pZLevel(k,iCell) = pZLevel(k-1,iCell) + 0.5*delta_p
+            pZLevel(k,iCell) = pZLevel(k-1,iCell)  &amp;
+              + 0.5*gravity*(  rho(k-1,iCell)*hZLevel(k-1) &amp;
+                             + rho(k  ,iCell)*hZLevel(k  ))
          end do
 
       end do
@@ -1263,8 +1463,8 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (mesh_type), intent(in) :: grid
 
       integer, dimension(:,:), pointer :: boundaryEdge
       real (kind=RKIND), dimension(:,:), pointer :: tend_u

Modified: branches/atmos_physics/src/core_ocean/mpas_interface.F
===================================================================
--- branches/atmos_physics/src/core_ocean/mpas_interface.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_ocean/mpas_interface.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -22,21 +22,21 @@
    implicit none
 
    type (block_type), intent(inout) :: block
-   type (grid_meta), intent(inout) :: mesh
+   type (mesh_type), intent(inout) :: mesh
    real (kind=RKIND), intent(in) :: dt
 
-   call compute_solve_diagnostics(dt, block % time_levs(1) % state, mesh)
+   call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
 
    call rbfInterp_initialize(mesh)
    call init_reconstruct(mesh)
-   call reconstruct(block % time_levs(1) % state, mesh)
+   call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
 
 ! 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 timer_start(&quot;global diagnostics&quot;)
-!   call computeGlobalDiagnostics(domain % dminfo, block % time_levs(1) % state, mesh, 0, dt)
+!   call computeGlobalDiagnostics(domain % dminfo, block % state % time_levs(1) % state, mesh, 0, dt)
 !   call timer_stop(&quot;global diagnostics&quot;)
 !   call output_state_init(output_obj, domain, &quot;OUTPUT&quot;)
 !   call write_output_frame(output_obj, domain)
@@ -83,7 +83,7 @@
 
       call timer_start(&quot;global diagnostics&quot;)
       call computeGlobalDiagnostics(domain % dminfo, &amp;
-         block_ptr % time_levs(2) % state, block_ptr % mesh, &amp;
+         block_ptr % state % time_levs(2) % state, block_ptr % mesh, &amp;
          itimestep, dt)
       call timer_stop(&quot;global diagnostics&quot;)
    end if

Modified: branches/atmos_physics/src/core_physics/module_driver_convection_deep.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_driver_convection_deep.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_driver_convection_deep.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -129,9 +129,11 @@
  end subroutine convection_deep_deallocate
 
 !=============================================================================================
- subroutine convection_deep_init
+ subroutine convection_deep_init(s)
 !=============================================================================================
 
+ type (state_type), intent(in) :: s
+
 !local variables and arrays:
 !---------------------------
  logical:: allowed_to_read
@@ -146,9 +148,9 @@
        write(0,*) '--- begin kain-fritsch initialization:'
 
        allowed_to_read = .false.
-       p_first_scalar  = moist_start + 1
-       p_qi = index_qi
-       p_qs = index_qs
+       p_first_scalar  = s % moist_start + 1
+       p_qi = s % index_qi
+       p_qs = s % index_qs
 
        f_qv = .false.
        f_qc = .false.
@@ -181,8 +183,8 @@
 !input and output arguments:
 !---------------------------
  integer,intent(in):: itimestep
- type(grid_meta),intent(in):: mesh
- type(grid_state),intent(inout):: state
+ type(mesh_type),intent(in):: mesh
+ type(state_type),intent(inout):: state
 
 !local variables and arrays:
 !---------------------------
@@ -297,7 +299,7 @@
  subroutine convection_from_MPAS(state)
 !=============================================================================================
 !input arguments:
- type(grid_state),intent(in):: state
+ type(state_type),intent(in):: state
 
 !---------------------------------------------------------------------------------------------
 
@@ -351,7 +353,7 @@
  subroutine convection_to_MPAS(state)
 !=============================================================================================
 !inout arguments:
- type(grid_state),intent(inout):: state
+ type(state_type),intent(inout):: state
 
 !---------------------------------------------------------------------------------------------
 

Modified: branches/atmos_physics/src/core_physics/module_driver_microphysics.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_driver_microphysics.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_driver_microphysics.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -121,12 +121,12 @@
 
 !input arguments:
 !----------------
- type(grid_meta),intent(in):: grid
+ type(mesh_type),intent(in):: grid
  integer,intent(in):: itimestep
     
 !inout arguments:
 !----------------
- type(grid_state),intent(inout):: state
+ type(state_type),intent(inout):: state
 
 !local variables and arrays:
 !---------------------------
@@ -242,10 +242,10 @@
 !=============================================================================================
 
 !input variables:
- type(grid_meta) ,intent(in):: grid
+ type(mesh_type) ,intent(in):: grid
 
 !output variables:
- type(grid_state),intent(out):: state
+ type(state_type),intent(out):: state
 
 !local variables:
  integer:: i,icell,j
@@ -297,7 +297,7 @@
 !=============================================================================================
 
 !output variables:
- type(grid_state),intent(inout):: state
+ type(state_type),intent(inout):: state
 
 !local variables:
  integer:: i,j

Modified: branches/atmos_physics/src/core_physics/module_pbl.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_pbl.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_pbl.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -51,8 +51,8 @@
 !input and output arguments:
 !---------------------------
  integer,intent(in):: itimestep
- type(grid_meta),intent(in):: grid
- type(grid_state),intent(out):: vars
+ type(mesh_type),intent(in):: grid
+ type(state_type),intent(out):: vars
 
 !--------------------------------------------------------------------------------------------- 
  write(0,*) '--- enter pbl driver:'

Modified: branches/atmos_physics/src/core_physics/module_physics_control.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_control.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_control.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -138,8 +138,8 @@
 !input and output arguments:
 !---------------------------
 logical,intent(in):: config_do_restart
- type(grid_meta),intent(in):: grid
- type(grid_state),intent(inout):: s
+ type(mesh_type),intent(in):: grid
+ type(state_type),intent(inout):: s
 
 !local variables:
  integer:: k,icell

Modified: branches/atmos_physics/src/core_physics/module_physics_driver.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_driver.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_driver.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -49,29 +49,29 @@
  do while(associated(block))
 
     !compute relative humidity:
-    !call compute_relhum(block%mesh,block%time_levs(1)%state)
+    !call compute_relhum(block%mesh,block%state%time_levs(1)%state)
 
     !physics prep step:
 #ifdef non_hydrostatic_core
-    call MPAS_to_physics(block%mesh,block%time_levs(1)%state)
+    call MPAS_to_physics(block%mesh,block%state%time_levs(1)%state,block%diag)
 #elif hydrostatic_core
-    call MPAS_to_physics(block%time_levs(1)%state)
+    call MPAS_to_physics(block%state%time_levs(1)%state,block%diag)
 #endif
 
     !call to convection:
     if(config_conv_deep_scheme .ne. 'off') &amp;
-       call convection_deep_driver(itimestep,block%mesh,block%time_levs(1)%state)
+       call convection_deep_driver(itimestep,block%mesh,block%state%time_levs(1)%state)
 
     !call to pbl schemes:
 !   if(config_pbl_scheme .ne. 'off') &amp;
-!      call pbl_driver(itimestep,block%mesh,block%time_levs(1)%state)
+!      call pbl_driver(itimestep,block%mesh,block%state%time_levs(1)%state)
 
     !add all physics tendencies:
     !call physics_add_tendencies
 
     !move physics time_levs(1) to time_levs(2):
 #ifdef non_hydrostatic_core
-     call nhyd_copy_state_physics(block%time_levs(1)%state,block%time_levs(2)%state)
+     call nhyd_copy_state_physics(block%state%time_levs(1)%state,block%state%time_levs(2)%state)
 #endif
 
     block =&gt; block % next

Modified: branches/atmos_physics/src/core_physics/module_physics_init.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_init.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_init.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -22,14 +22,14 @@
 
 !input and output arguments:
 !---------------------------
- type(grid_meta),intent(in):: mesh
- type(grid_state),intent(inout):: s
+ type(mesh_type),intent(in):: mesh
+ type(state_type),intent(inout):: s
 
 !=============================================================================================
 
 !initialization of parameterized deep convective processes:
  if(config_conv_deep_scheme .ne. 'off') then
-    call convection_deep_init
+    call convection_deep_init(s)
  endif
 
 !initialization of cloud microphysics processes:

Modified: branches/atmos_physics/src/core_physics/module_physics_interface_hyd.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_interface_hyd.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_interface_hyd.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -20,11 +20,12 @@
  contains
 
 !=============================================================================================
- subroutine MPAS_to_physics(state)
+ subroutine MPAS_to_physics(state,diag)
 !=============================================================================================
 
 !input variables:
- type(grid_state),intent(in):: state
+ type(state_type),intent(in):: state
+ type(diag_type),intent(in):: diag
  
 !local variables:
  real(kind=RKIND):: tm
@@ -33,13 +34,13 @@
 
 !initialization:
  w =&gt; state % w % array
- u =&gt; state % uReconstructZonal % array
- v =&gt; state % uReconstructMeridional % array
+ u =&gt; diag % uReconstructZonal % array
+ v =&gt; diag % uReconstructMeridional % array
 
  geopotential =&gt; state % geopotential % array
  pressure     =&gt; state % pressure % array
  theta        =&gt; state % theta % array
- qv           =&gt; state % scalars % array(index_qv,:,:)
+ qv           =&gt; state % scalars % array(state%index_qv,:,:)
 
  do j = jts, jte
  do k = kts, kte
@@ -76,7 +77,7 @@
 !=============================================================================================
 
 !input variables:
- type(grid_state),intent(in):: state
+ type(state_type),intent(in):: state
 
 !---------------------------------------------------------------------------------------------
 
@@ -99,12 +100,12 @@
     pi_p(i,k,j) = (pres_p(i,k,j)/p0)**(R_d/cp)
     t_p(i,k,j)  = th_p(i,k,j)*pi_p(i,k,j)
 
-!   qv_p(i,k,j) = max(0.,state % scalars % array(index_qv,k,i))
-!   qc_p(i,k,j) = max(0.,state % scalars % array(index_qc,k,i))
-!   qr_p(i,k,j) = max(0.,state % scalars % array(index_qr,k,i))
-    qv_p(i,k,j) = state % scalars % array(index_qv,k,i)
-    qc_p(i,k,j) = state % scalars % array(index_qc,k,i)
-    qr_p(i,k,j) = state % scalars % array(index_qr,k,i)
+!   qv_p(i,k,j) = max(0.,state % scalars % array(state%index_qv,k,i))
+!   qc_p(i,k,j) = max(0.,state % scalars % array(state%index_qc,k,i))
+!   qr_p(i,k,j) = max(0.,state % scalars % array(state%index_qr,k,i))
+    qv_p(i,k,j) = state % scalars % array(state%index_qv,k,i)
+    qc_p(i,k,j) = state % scalars % array(state%index_qc,k,i)
+    qr_p(i,k,j) = state % scalars % array(state%index_qr,k,i)
  enddo
  enddo
  enddo
@@ -118,18 +119,18 @@
        do k = kts, kte
        do i = its, ite
           !mass mixing ratios:
-!         qi_p(i,k,j) = max(0.,state % scalars % array(index_qi,k,i))
-!         qs_p(i,k,j) = max(0.,state % scalars % array(index_qs,k,i))
-!         qg_p(i,k,j) = max(0.,state % scalars % array(index_qg,k,i))
-          qi_p(i,k,j) = state % scalars % array(index_qi,k,i)
-          qs_p(i,k,j) = state % scalars % array(index_qs,k,i)
-          qg_p(i,k,j) = state % scalars % array(index_qg,k,i)
+!         qi_p(i,k,j) = max(0.,state % scalars % array(state%index_qi,k,i))
+!         qs_p(i,k,j) = max(0.,state % scalars % array(state%index_qs,k,i))
+!         qg_p(i,k,j) = max(0.,state % scalars % array(state%index_qg,k,i))
+          qi_p(i,k,j) = state % scalars % array(state%index_qi,k,i)
+          qs_p(i,k,j) = state % scalars % array(state%index_qs,k,i)
+          qg_p(i,k,j) = state % scalars % array(state%index_qg,k,i)
 
           !number concentrations:
-!         qnr_p(i,k,j) = max(0., state % scalars % array(index_qnr,k,i))
-!         qni_p(i,k,j) = max(0., state % scalars % array(index_qni,k,i))
-          qnr_p(i,k,j) = state % scalars % array(index_qnr,k,i)
-          qni_p(i,k,j) = state % scalars % array(index_qni,k,i)
+!         qnr_p(i,k,j) = max(0., state % scalars % array(state%index_qnr,k,i))
+!         qni_p(i,k,j) = max(0., state % scalars % array(state%index_qni,k,i))
+          qnr_p(i,k,j) = state % scalars % array(state%index_qnr,k,i)
+          qni_p(i,k,j) = state % scalars % array(state%index_qni,k,i)
        enddo
        enddo
        enddo
@@ -150,7 +151,7 @@
 !=============================================================================================
 
 !output variables:
- type(grid_state),intent(out):: state
+ type(state_type),intent(out):: state
 
 !---------------------------------------------------------------------------------------------
 
@@ -165,9 +166,9 @@
  do i = its, ite
     t_p(i,k,j) = th_p(i,k,j) * pi_p(i,k,j)
     state % theta   % array(k,i) = th_p(i,k,j)
-    state % scalars % array(index_qv,k,i)  = qv_p(i,k,j)
-    state % scalars % array(index_qc,k,i)  = qc_p(i,k,j)
-    state % scalars % array(index_qr,k,i)  = qr_p(i,k,j)
+    state % scalars % array(state%index_qv,k,i)  = qv_p(i,k,j)
+    state % scalars % array(state%index_qc,k,i)  = qc_p(i,k,j)
+    state % scalars % array(state%index_qr,k,i)  = qr_p(i,k,j)
 
     state % h_diabatic % array(k,i) = (state % theta % array(k,i) &amp;
                               -  state % h_diabatic % array(k,i)) / dt_dyn
@@ -184,13 +185,13 @@
        do k = kts, kte
        do i = its, ite
           !mass mixing ratios:
-          state % scalars % array(index_qi,k,i)  = qi_p(i,k,j)
-          state % scalars % array(index_qs,k,i)  = qs_p(i,k,j)
-          state % scalars % array(index_qg,k,i)  = qg_p(i,k,j)
+          state % scalars % array(state%index_qi,k,i)  = qi_p(i,k,j)
+          state % scalars % array(state%index_qs,k,i)  = qs_p(i,k,j)
+          state % scalars % array(state%index_qg,k,i)  = qg_p(i,k,j)
 
           !number concentrations:
-          state % scalars % array(index_qnr,k,i) = qnr_p(i,k,j)
-          state % scalars % array(index_qni,k,i) = qni_p(i,k,j)
+          state % scalars % array(state%index_qnr,k,i) = qnr_p(i,k,j)
+          state % scalars % array(state%index_qni,k,i) = qni_p(i,k,j)
        enddo
        enddo
        enddo

Modified: branches/atmos_physics/src/core_physics/module_physics_interface_nhyd.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_interface_nhyd.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_interface_nhyd.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -22,9 +22,9 @@
 !=============================================================================================
 
 !input variables:
- type(grid_state),intent(in):: src
+ type(state_type),intent(in):: src
 !inout variables:
- type(grid_state),intent(inout):: dest
+ type(state_type),intent(inout):: dest
 
 !---------------------------------------------------------------------------------------------
 
@@ -85,12 +85,13 @@
  end subroutine nhyd_copy_state_physics
 
 !=============================================================================================
- subroutine MPAS_to_physics(grid,vars)
+ subroutine MPAS_to_physics(grid,vars,diag)
 !=============================================================================================
 
 !input variables:
- type(grid_meta) ,intent(in):: grid
- type(grid_state),intent(in):: vars
+ type(mesh_type) ,intent(in):: grid
+ type(state_type),intent(in):: vars
+ type(diag_type) ,intent(in):: diag
 
 !local variables:
  integer:: i,k,j
@@ -115,11 +116,11 @@
  rho        =&gt; vars % rho % array
  theta      =&gt; vars % theta % array
  pressure   =&gt; vars % pressure % array
- qv         =&gt; vars % scalars % array(index_qv,:,:)
+ qv         =&gt; vars % scalars % array(vars%index_qv,:,:)
 
  w          =&gt; vars % w % array
- u          =&gt; vars % uReconstructZonal % array
- v          =&gt; vars % uReconstructMeridional % array
+ u          =&gt; diag % uReconstructZonal % array
+ v          =&gt; diag % uReconstructMeridional % array
 
 !copy sounding variables from the geodesic grid to the wrf-physics grid:
  do j = jts, jtf
@@ -139,7 +140,7 @@
 
     dz_p(i,k,j) = zgrid(k+1,i)-zgrid(k,i)
 
-    qv_p(i,k,j) = max(0.,vars % scalars % array(index_qv,k,i))
+    qv_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qv,k,i))
 
  enddo
  enddo
@@ -156,8 +157,8 @@
 !=============================================================================================
 
 !input variables:
- type(grid_meta) ,intent(in):: grid
- type(grid_state),intent(in):: vars
+ type(mesh_type) ,intent(in):: grid
+ type(state_type),intent(in):: vars
 
 !local variables:
  integer:: i,k,j
@@ -190,7 +191,7 @@
  rh         =&gt; vars % rh % array
  pressure   =&gt; vars % pressure % array
 
- qv =&gt; vars % scalars % array(index_qv,:,:)
+ qv =&gt; vars % scalars % array(vars%index_qv,:,:)
 
 !copy sounding variables from the geodesic grid to the wrf-physics grid:
  do j = jts, jtf
@@ -205,9 +206,9 @@
     z_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)
 
-    qv_p(i,k,j) = max(0.,vars % scalars % array(index_qv,k,i))
-    qc_p(i,k,j) = max(0.,vars % scalars % array(index_qc,k,i))
-    qr_p(i,k,j) = max(0.,vars % scalars % array(index_qr,k,i))
+    qv_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qv,k,i))
+    qc_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qc,k,i))
+    qr_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qr,k,i))
  enddo
  enddo
  enddo
@@ -231,13 +232,13 @@
        do i = its, itf
 
           !mass mixing ratios:
-          qi_p(i,k,j) = max(0.,vars % scalars % array(index_qi,k,i))
-          qs_p(i,k,j) = max(0.,vars % scalars % array(index_qs,k,i))
-          qg_p(i,k,j) = max(0.,vars % scalars % array(index_qg,k,i))
+          qi_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qi,k,i))
+          qs_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qs,k,i))
+          qg_p(i,k,j) = max(0.,vars % scalars % array(vars%index_qg,k,i))
 
           !number concentrations:
-          qnr_p(i,k,j) = max(0., vars % scalars % array(index_qnr,k,i))
-          qni_p(i,k,j) = max(0., vars % scalars % array(index_qni,k,i))
+          qnr_p(i,k,j) = max(0., vars % scalars % array(vars%index_qnr,k,i))
+          qni_p(i,k,j) = max(0., vars % scalars % array(vars%index_qni,k,i))
 
        enddo
        enddo
@@ -314,10 +315,10 @@
 
 !input variables:
  integer,intent(in):: itimestep
- type(grid_meta),intent(in):: grid
+ type(mesh_type),intent(in):: grid
 
 !output variables:
- type(grid_state),intent(out):: vars
+ type(state_type),intent(out):: vars
 
  real(kind=RKIND):: min_theta,min_thp,min_tp
  real(kind=RKIND):: max_theta,max_thp,max_tp
@@ -373,9 +374,9 @@
                   + (exner(k,i)-exner_b(k,i))*rtheta_b(k,i))
 
     !mass mixing ratios:
-    vars % scalars % array(index_qv,k,i) = qv_p(i,k,j)
-    vars % scalars % array(index_qc,k,i) = qc_p(i,k,j)
-    vars % scalars % array(index_qr,k,i) = qr_p(i,k,j)
+    vars % scalars % array(vars%index_qv,k,i) = qv_p(i,k,j)
+    vars % scalars % array(vars%index_qc,k,i) = qc_p(i,k,j)
+    vars % scalars % array(vars%index_qr,k,i) = qr_p(i,k,j)
 
  enddo
  enddo
@@ -392,13 +393,13 @@
        do i = its, itf
 
           !mass mixing ratios:
-          vars % scalars % array(index_qi,k,i) = qi_p(i,k,j)
-          vars % scalars % array(index_qs,k,i) = qs_p(i,k,j)
-          vars % scalars % array(index_qg,k,i) = qg_p(i,k,j)
+          vars % scalars % array(vars%index_qi,k,i) = qi_p(i,k,j)
+          vars % scalars % array(vars%index_qs,k,i) = qs_p(i,k,j)
+          vars % scalars % array(vars%index_qg,k,i) = qg_p(i,k,j)
 
           !number concentrations:
-          vars % scalars % array(index_qnr,k,i) = qnr_p(i,k,j)
-          vars % scalars % array(index_qni,k,i) = qni_p(i,k,j)
+          vars % scalars % array(vars%index_qnr,k,i) = qnr_p(i,k,j)
+          vars % scalars % array(vars%index_qni,k,i) = qni_p(i,k,j)
 
        enddo
        enddo
@@ -432,36 +433,36 @@
  min_tp    = minval(t_p(:,:,:))
  write(0,*) ' max_tp     =  ',max_tp   ,'  min_tp  = ',min_tp
 
- max_qv = maxval(vars%scalars%array(index_qv,:,:))
- min_qv = minval(vars%scalars%array(index_qv,:,:))
+ max_qv = maxval(vars%scalars%array(vars%index_qv,:,:))
+ min_qv = minval(vars%scalars%array(vars%index_qv,:,:))
  write(0,*) ' max_qv  =  ',max_qv,'  min_qv  = ',min_qv
 
- max_qc = maxval(vars%scalars%array(index_qc,:,:))
- min_qc = minval(vars%scalars%array(index_qc,:,:))
+ max_qc = maxval(vars%scalars%array(vars%index_qc,:,:))
+ min_qc = minval(vars%scalars%array(vars%index_qc,:,:))
  write(0,*) ' max_qc  =  ',max_qc,'  min_qc  = ',min_qc
 
- max_qr = maxval(vars%scalars%array(index_qr,:,:))
- min_qr = minval(vars%scalars%array(index_qr,:,:))
+ max_qr = maxval(vars%scalars%array(vars%index_qr,:,:))
+ min_qr = minval(vars%scalars%array(vars%index_qr,:,:))
  write(0,*) ' max_qr  =  ',max_qr,'  min_qr  = ',min_qr
 
- max_qi = maxval(vars%scalars%array(index_qi,:,:))
- min_qi = minval(vars%scalars%array(index_qi,:,:))
+ max_qi = maxval(vars%scalars%array(vars%index_qi,:,:))
+ min_qi = minval(vars%scalars%array(vars%index_qi,:,:))
  write(0,*) ' max_qi  =  ',max_qi,'  min_qi  = ',min_qi
 
- max_qs = maxval(vars%scalars%array(index_qs,:,:))
- min_qs = minval(vars%scalars%array(index_qs,:,:))
+ max_qs = maxval(vars%scalars%array(vars%index_qs,:,:))
+ min_qs = minval(vars%scalars%array(vars%index_qs,:,:))
  write(0,*) ' max_qs  =  ',max_qs,'  min_qs  = ',min_qs
 
- max_qg = maxval(vars%scalars%array(index_qg,:,:))
- min_qg = minval(vars%scalars%array(index_qg,:,:))
+ max_qg = maxval(vars%scalars%array(vars%index_qg,:,:))
+ min_qg = minval(vars%scalars%array(vars%index_qg,:,:))
  write(0,*) ' max_qg  =  ',max_qg,'  min_qg  = ',min_qg
 
- max_qnr = maxval(vars%scalars%array(index_qnr,:,:))
- min_qnr = minval(vars%scalars%array(index_qnr,:,:))
+ max_qnr = maxval(vars%scalars%array(vars%index_qnr,:,:))
+ min_qnr = minval(vars%scalars%array(vars%index_qnr,:,:))
  write(0,*) ' max_qnr = ',max_qnr,'  min_qnr = ',min_qnr
 
- max_qni = maxval(vars%scalars%array(index_qni,:,:))
- min_qni = minval(vars%scalars%array(index_qni,:,:))
+ max_qni = maxval(vars%scalars%array(vars%index_qni,:,:))
+ min_qni = minval(vars%scalars%array(vars%index_qni,:,:))
  write(0,*) ' max_qni = ',max_qni,'  min_qni = ',min_qni
 
 !formats:
@@ -473,8 +474,8 @@
  subroutine compute_relhum(grid,vars)
 !--------------------------------------------------------------------------------------------------
    
- type(grid_state),intent(in) :: vars
- type(grid_meta),intent(in)  :: grid
+ type(state_type),intent(in) :: vars
+ type(mesh_type),intent(in)  :: grid
 
  real,dimension(:,:),pointer :: theta,pressure  
  real,dimension(:,:),pointer :: pressure_b,exner
@@ -489,7 +490,7 @@
  theta    =&gt; vars % theta % array
  pressure =&gt; vars % pressure % array
  rh       =&gt; vars % rh  % array
- qv       =&gt; vars % scalars % array(index_qv,:,:)
+ qv       =&gt; vars % scalars % array(vars%index_qv,:,:)
 
  do iCell = 1, grid % nCells
     do k = 1, grid % nVertLevels

Modified: branches/atmos_physics/src/core_physics/module_physics_manager.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_manager.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_manager.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -41,7 +41,7 @@
 
 !input arguments:
 !----------------
- type(grid_meta),intent(in):: mesh
+ type(mesh_type),intent(in):: mesh
 
 !=============================================================================================
  write(0,*)

Modified: branches/atmos_physics/src/core_physics/module_physics_sfclayer.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_sfclayer.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_sfclayer.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -87,7 +87,7 @@
 !=============================================================================================
 
 !input arguments:
- type(grid_state),intent(in):: s
+ type(state_type),intent(in):: s
 
 !---------------------------------------------------------------------------------------------
 

Modified: branches/atmos_physics/src/core_physics/module_physics_todynamics.F
===================================================================
--- branches/atmos_physics/src/core_physics/module_physics_todynamics.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_physics/module_physics_todynamics.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -15,14 +15,14 @@
 
 !input variables:
 !----------------
- type(grid_meta),intent(in):: grid
- type(grid_state),intent(in):: vars
+ type(mesh_type),intent(in):: grid
+ type(state_type),intent(in):: vars
 
  real(kind=RKIND),intent(in),dimension(grid%nVertLevels,grid%nCells):: mass
  
 !inout variables:
 !----------------
- type(grid_state),intent(inout):: tend
+ type(tend_type),intent(inout):: tend
 
 !local variables:
 !----------------
@@ -57,18 +57,18 @@
     do i = 1, nCellsSolve
     do k = 1, nVertLevels
        tend_theta(k,i)=tend_theta(k,i)+rthcuten(k,i)*mass(k,i)
-       tend_scalars(index_qv,k,i)=tend_scalars(index_qv,k,i)+rqvcuten(k,i)*mass(k,i)
-       tend_scalars(index_qc,k,i)=tend_scalars(index_qc,k,i)+rqccuten(k,i)*mass(k,i)
-       tend_scalars(index_qr,k,i)=tend_scalars(index_qr,k,i)+rqrcuten(k,i)*mass(k,i)
-       tend_scalars(index_qi,k,i)=tend_scalars(index_qi,k,i)+rqicuten(k,i)*mass(k,i)
-       tend_scalars(index_qs,k,i)=tend_scalars(index_qs,k,i)+rqscuten(k,i)*mass(k,i)    
+       tend_scalars(vars%index_qv,k,i)=tend_scalars(vars%index_qv,k,i)+rqvcuten(k,i)*mass(k,i)
+       tend_scalars(vars%index_qc,k,i)=tend_scalars(vars%index_qc,k,i)+rqccuten(k,i)*mass(k,i)
+       tend_scalars(vars%index_qr,k,i)=tend_scalars(vars%index_qr,k,i)+rqrcuten(k,i)*mass(k,i)
+       tend_scalars(vars%index_qi,k,i)=tend_scalars(vars%index_qi,k,i)+rqicuten(k,i)*mass(k,i)
+       tend_scalars(vars%index_qs,k,i)=tend_scalars(vars%index_qs,k,i)+rqscuten(k,i)*mass(k,i)    
 !      write(0,201) i,k,tend_theta(k,i),            &amp;
-!                       tend_scalars(index_qv,k,i), &amp;
-!                       tend_scalars(index_qc,k,i), &amp;
-!                       tend_scalars(index_qr,k,i), &amp;
-!                       tend_scalars(index_qi,k,i), &amp;
-!                       tend_scalars(index_qs,k,i), &amp;
-!                       tend_scalars(index_qg,k,i)
+!                       tend_scalars(vars%index_qv,k,i), &amp;
+!                       tend_scalars(vars%index_qc,k,i), &amp;
+!                       tend_scalars(vars%index_qr,k,i), &amp;
+!                       tend_scalars(vars%index_qi,k,i), &amp;
+!                       tend_scalars(vars%index_qs,k,i), &amp;
+!                       tend_scalars(vars%index_qg,k,i)
     enddo
     enddo
 

Modified: branches/atmos_physics/src/core_sw/Registry
===================================================================
--- branches/atmos_physics/src/core_sw/Registry        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_sw/Registry        2010-10-13 20:25:17 UTC (rev 549)
@@ -30,90 +30,95 @@
 dim nTracers nTracers
 
 #
-# var  type  name_in_file  ( dims )  iro-  name_in_code super-array array_class
+# var persistence type  name_in_file  ( dims )  time_levs iro-  name_in_code struct super-array array_class
 #
-var real    xtime ( Time ) ro xtime - -
+var persistent real    xtime ( Time ) 2 ro xtime state - -
 
-var real    latCell ( nCells ) iro latCell - -
-var real    lonCell ( nCells ) iro lonCell - -
-var real    xCell ( nCells ) iro xCell - -
-var real    yCell ( nCells ) iro yCell - -
-var real    zCell ( nCells ) iro zCell - -
-var integer indexToCellID ( nCells ) iro indexToCellID - -
+var persistent real    latCell ( nCells ) 0 iro latCell mesh - -
+var persistent real    lonCell ( nCells ) 0 iro lonCell mesh - -
+var persistent real    xCell ( nCells ) 0 iro xCell mesh - -
+var persistent real    yCell ( nCells ) 0 iro yCell mesh - -
+var persistent real    zCell ( nCells ) 0 iro zCell mesh - -
+var persistent integer indexToCellID ( nCells ) 0 iro indexToCellID mesh - -
 
-var real    latEdge ( nEdges ) iro latEdge - -
-var real    lonEdge ( nEdges ) iro lonEdge - -
-var real    xEdge ( nEdges ) iro xEdge - -
-var real    yEdge ( nEdges ) iro yEdge - -
-var real    zEdge ( nEdges ) iro zEdge - -
-var integer indexToEdgeID ( nEdges ) iro indexToEdgeID - -
+var persistent real    latEdge ( nEdges ) 0 iro latEdge mesh - -
+var persistent real    lonEdge ( nEdges ) 0 iro lonEdge mesh - -
+var persistent real    xEdge ( nEdges ) 0 iro xEdge mesh - -
+var persistent real    yEdge ( nEdges ) 0 iro yEdge mesh - -
+var persistent real    zEdge ( nEdges ) 0 iro zEdge mesh - -
+var persistent integer indexToEdgeID ( nEdges ) 0 iro indexToEdgeID mesh - -
 
-var real    latVertex ( nVertices ) iro latVertex - -
-var real    lonVertex ( nVertices ) iro lonVertex - -
-var real    xVertex ( nVertices ) iro xVertex - -
-var real    yVertex ( nVertices ) iro yVertex - -
-var real    zVertex ( nVertices ) iro zVertex - -
-var integer indexToVertexID ( nVertices ) iro indexToVertexID - -
+var persistent real    latVertex ( nVertices ) 0 iro latVertex mesh - -
+var persistent real    lonVertex ( nVertices ) 0 iro lonVertex mesh - -
+var persistent real    xVertex ( nVertices ) 0 iro xVertex mesh - -
+var persistent real    yVertex ( nVertices ) 0 iro yVertex mesh - -
+var persistent real    zVertex ( nVertices ) 0 iro zVertex mesh - -
+var persistent integer indexToVertexID ( nVertices ) 0 iro indexToVertexID mesh - -
 
-var integer cellsOnEdge ( TWO nEdges ) iro cellsOnEdge - -
-var integer nEdgesOnCell ( nCells ) iro nEdgesOnCell - -
-var integer nEdgesOnEdge ( nEdges ) iro nEdgesOnEdge - -
-var integer edgesOnCell ( maxEdges nCells ) iro edgesOnCell - -
-var integer edgesOnEdge ( maxEdges2 nEdges ) iro edgesOnEdge - -
+var persistent integer cellsOnEdge ( TWO nEdges ) 0 iro cellsOnEdge mesh - -
+var persistent integer nEdgesOnCell ( nCells ) 0 iro nEdgesOnCell mesh - -
+var persistent integer nEdgesOnEdge ( nEdges ) 0 iro nEdgesOnEdge mesh - -
+var persistent integer edgesOnCell ( maxEdges nCells ) 0 iro edgesOnCell mesh - -
+var persistent integer edgesOnEdge ( maxEdges2 nEdges ) 0 iro edgesOnEdge mesh - -
 
-var real    weightsOnEdge ( maxEdges2 nEdges ) iro weightsOnEdge - -
-var real    dvEdge ( nEdges ) iro dvEdge - -
-var real    dcEdge ( nEdges ) iro dcEdge - -
-var real    angleEdge ( nEdges ) iro angleEdge - -
-var real    areaCell ( nCells ) iro areaCell - -
-var real    areaTriangle ( nVertices ) iro areaTriangle - -
+var persistent real    weightsOnEdge ( maxEdges2 nEdges ) 0 iro weightsOnEdge mesh - -
+var persistent real    dvEdge ( nEdges ) 0 iro dvEdge mesh - -
+var persistent real    dcEdge ( nEdges ) 0 iro dcEdge mesh - -
+var persistent real    angleEdge ( nEdges ) 0 iro angleEdge mesh - -
+var persistent real    areaCell ( nCells ) 0 iro areaCell mesh - -
+var persistent real    areaTriangle ( nVertices ) 0 iro areaTriangle mesh - -
 
-var real    edgeNormalVectors ( R3 nEdges ) o edgeNormalVectors - -
-var real    localVerticalUnitVectors ( R3 nCells ) o localVerticalUnitVectors - -
-var real    cellTangentPlane ( R3 TWO nEdges ) o cellTangentPlane - -
+var persistent real    edgeNormalVectors ( R3 nEdges ) 0 o edgeNormalVectors mesh - -
+var persistent real    localVerticalUnitVectors ( R3 nCells ) 0 o localVerticalUnitVectors mesh - -
+var persistent real    cellTangentPlane ( R3 TWO nEdges ) 0 o cellTangentPlane mesh - -
 
-var integer cellsOnCell ( maxEdges nCells ) iro cellsOnCell - -
-var integer verticesOnCell ( maxEdges nCells ) iro verticesOnCell - -
-var integer verticesOnEdge ( TWO nEdges ) iro verticesOnEdge - -
-var integer edgesOnVertex ( vertexDegree nVertices ) iro edgesOnVertex - -
-var integer cellsOnVertex ( vertexDegree nVertices ) iro cellsOnVertex - -
-var real    kiteAreasOnVertex ( vertexDegree nVertices ) iro kiteAreasOnVertex - -
-var real    fEdge ( nEdges ) iro fEdge - -
-var real    fVertex ( nVertices ) iro fVertex - -
-var real    fCell ( nCells ) iro fCell - -
-var real    h_s ( nCells ) iro h_s - -
+var persistent integer cellsOnCell ( maxEdges nCells ) 0 iro cellsOnCell mesh - -
+var persistent integer verticesOnCell ( maxEdges nCells ) 0 iro verticesOnCell mesh - -
+var persistent integer verticesOnEdge ( TWO nEdges ) 0 iro verticesOnEdge mesh - -
+var persistent integer edgesOnVertex ( vertexDegree nVertices ) 0 iro edgesOnVertex mesh - -
+var persistent integer cellsOnVertex ( vertexDegree nVertices ) 0 iro cellsOnVertex mesh - -
+var persistent real    kiteAreasOnVertex ( vertexDegree nVertices ) 0 iro kiteAreasOnVertex mesh - -
+var persistent real    fEdge ( nEdges ) 0 iro fEdge mesh - -
+var persistent real    fVertex ( nVertices ) 0 iro fVertex mesh - -
+var persistent real    fCell ( nCells ) 0 iro fCell mesh - -
+var persistent real    h_s ( nCells ) 0 iro h_s mesh - -
 
 # Arrays required for reconstruction of velocity field
-var real    coeffs_reconstruct ( R3 maxEdges nCells ) - coeffs_reconstruct - -
+var persistent real    coeffs_reconstruct ( R3 maxEdges nCells ) 0 - coeffs_reconstruct mesh - -
 
 # Boundary conditions: read from input, saved in restart and written to output
-var integer boundaryEdge ( nVertLevels nEdges ) iro boundaryEdge - -
-var integer boundaryVertex ( nVertLevels nVertices ) iro boundaryVertex - -
+var persistent integer boundaryEdge ( nVertLevels nEdges ) 0 iro boundaryEdge mesh - -
+var persistent integer boundaryVertex ( nVertLevels nVertices ) 0 iro boundaryVertex mesh - -
 
 # Prognostic variables: read from input, saved in restart, and written to output
-var real    u ( nVertLevels nEdges Time ) iro u - -
-var real    h ( nVertLevels nCells Time ) iro h - -
-var real    tracers ( nTracers nVertLevels nCells Time ) iro tracers - -
+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
+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
-var real    v ( nVertLevels nEdges Time ) o v - -
-var real    divergence ( nVertLevels nCells Time ) o divergence - -
-var real    vorticity ( nVertLevels nVertices Time ) o vorticity - -
-var real    vorticity_cell ( nVertLevels nCells Time ) o vorticity_cell - -
-var real    pv_edge ( nVertLevels nEdges Time ) o pv_edge - -
-var real    h_edge ( nVertLevels nEdges Time ) o h_edge - -
-var real    ke ( nVertLevels nCells Time ) o ke - -
-var real    pv_vertex ( nVertLevels nVertices Time ) o pv_vertex - -
-var real    pv_cell ( nVertLevels nCells Time ) o pv_cell - -
-var real    uReconstructX ( nVertLevels nCells Time ) o uReconstructX - -
-var real    uReconstructY ( nVertLevels nCells Time ) o uReconstructY - -
-var real    uReconstructZ ( nVertLevels nCells Time ) o uReconstructZ - -
-var real    uReconstructZonal ( nVertLevels nCells Time ) o uReconstructZonal - -
-var real    uReconstructMeridional ( nVertLevels nCells Time ) o uReconstructMeridional - -
+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 - -
+var persistent real    vorticity_cell ( nVertLevels nCells Time ) 2 o vorticity_cell state - -
+var persistent real    pv_edge ( nVertLevels nEdges Time ) 2 o pv_edge state - -
+var persistent real    h_edge ( nVertLevels nEdges Time ) 2 o h_edge state - -
+var persistent real    ke ( nVertLevels nCells Time ) 2 o ke state - -
+var persistent real    pv_vertex ( nVertLevels nVertices Time ) 2 o pv_vertex state - -
+var persistent real    pv_cell ( nVertLevels nCells Time ) 2 o pv_cell state - -
+var persistent real    uReconstructX ( nVertLevels nCells Time ) 1 o uReconstructX diag - -
+var persistent real    uReconstructY ( nVertLevels nCells Time ) 1 o uReconstructY diag - -
+var persistent real    uReconstructZ ( nVertLevels nCells Time ) 1 o uReconstructZ diag - -
+var persistent real    uReconstructZonal ( nVertLevels nCells Time ) 1 o uReconstructZonal diag - -
+var persistent real    uReconstructMeridional ( nVertLevels nCells Time ) 1 o uReconstructMeridional diag - -
 
 # Other diagnostic variables: neither read nor written to any files
-var real    vh ( nVertLevels nEdges Time ) - vh - -
-var real    circulation ( nVertLevels nVertices Time ) - circulation - -
-var real    gradPVt ( nVertLevels nEdges Time ) - gradPVt - -
-var real    gradPVn ( nVertLevels nEdges Time ) - gradPVn - -
-var real        h_vertex ( nVertLevels nVertices Time ) - h_vertex - -
+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 - -
+var persistent real        h_vertex ( nVertLevels nVertices Time ) 2 - h_vertex state - -

Modified: branches/atmos_physics/src/core_sw/module_global_diagnostics.F
===================================================================
--- branches/atmos_physics/src/core_sw/module_global_diagnostics.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_sw/module_global_diagnostics.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -28,7 +28,7 @@
       ! 1. Define the array to integrate, and the variable for the value above.
       ! 2. Allocate the array with the correct dimensions.
       ! 3. Fill the array with the data to be integrated.
-      !     eg. G_h = Sum(h dA)/Sum(dA), See below for array filling
+      !     eg. GlobalFluidThickness = Sum(h dA)/Sum(dA), See below for array filling
       ! 4. Call Function to compute Global Stat that you want.
       ! 5. Finish computing the global stat/integral
       ! 6. Write out your global stat to the file
@@ -37,8 +37,8 @@
       implicit none
 
       type (dm_info), intent(in) :: dminfo
-      type (grid_state), intent(inout) :: state
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
       integer, intent(in) :: timeIndex
       real (kind=RKIND), intent(in) :: dt
 
@@ -46,26 +46,36 @@
       integer :: nCells
 
       ! Step 1
-      ! 1. Define the array to integrate, and the variable for the value above.
-      real (kind=RKIND) ::  areaCellGlobal, areaEdgeGlobal, areaTriangleGlobal
-      real (kind=RKIND), dimension(:), pointer ::  areaCell, dcEdge, dvEdge, areaTriangle, areaEdge, h_s
-      real (kind=RKIND), dimension(:,:), pointer :: h, u, v, h_edge, pv_edge, pv_vertex, pv_cell, h_vertex
+      ! 1. Define the array to integrate, and the variable for the value to be stored in after the integration
+      real (kind=RKIND), dimension(:), pointer ::  areaCell, dcEdge, dvEdge, areaTriangle, h_s, fCell, fEdge
+      real (kind=RKIND), dimension(:,:), pointer :: h, u, v, h_edge, pv_edge, pv_vertex, pv_cell, h_vertex, weightsOnEdge
 
-      real (kind=RKIND), dimension(:), allocatable :: eres, h_ref
-      real (kind=RKIND), dimension(:,:), allocatable :: pe_vertex, u2, h2, hb, pv_temp, pve_bot, h_top, h_bot, cor_energy, sshr, ke_sink, pe_sink
       real (kind=RKIND), dimension(:,:,:), pointer :: tracers
 
-      real (kind=RKIND) ::  global_temp, gh, gpv, gpe, ge, ger, e_cor, sshr_val, h_ref_val, ke_sink_val, pe_sink_val, ke
+      real (kind=RKIND), dimension(:), allocatable :: volumeWeightedPotentialEnergyReservoir, averageThickness
+      real (kind=RKIND), dimension(:), allocatable :: potentialEnstrophyReservior, areaEdge, h_s_edge
+
+      real (kind=RKIND), dimension(:,:), allocatable :: cellVolume, cellArea, volumeWeightedPotentialVorticity
+      real (kind=RKIND), dimension(:,:), allocatable :: volumeWeightedPotentialEnstrophy, vertexVolume, volumeWeightedKineticEnergy 
+      real (kind=RKIND), dimension(:,:), allocatable :: volumeWeightedPotentialEnergy, volumeWeightedPotentialEnergyTopography 
+      real (kind=RKIND), dimension(:,:), allocatable :: keTend_CoriolisForce, keTend_PressureGradient 
+      real (kind=RKIND), dimension(:,:), allocatable ::peTend_DivThickness, refAreaWeightedSurfaceHeight, refAreaWeightedSurfaceHeight_edge
+
+      real (kind=RKIND) :: sumCellVolume, sumCellArea, sumVertexVolume, sumrefAreaWeightedSurfaceHeight
+
+      real (kind=RKIND) :: globalFluidThickness, globalPotentialVorticity, globalPotentialEnstrophy, globalEnergy 
+      real (kind=RKIND) :: globalCoriolisEnergyTendency, globalKEPETendency, globalPotentialEnstrophyReservoir 
+      real (kind=RKIND) :: globalKineticEnergy, globalPotentialEnergy, globalPotentialEnergyReservoir
+      real (kind=RKIND) :: globalKineticEnergyTendency, globalPotentialEnergyTendency
+      real (kind=RKIND) ::  global_temp, workpv, q
       real (kind=RKIND) :: volumeCellGlobal, volumeEdgeGlobal, CFLNumberGlobal
+
       integer :: elementIndex, variableIndex, nVariables, nSums, nMaxes, nMins
-      integer :: timeLevel,k,i
+      integer :: timeLevel, eoe, iLevel, iCell, iEdge, iVertex
+      integer :: fileID, iCell1, iCell2, j
 
-      integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnCell
-
-      integer, parameter :: kMaxVariables = 1024 ! this must be a little more than double the number of variables to be reduced
-      real (kind=RKIND), dimension(kMaxVariables) :: sums, mins, maxes, averages, verticalSumMins, verticalSumMaxes, reductions
-
-      integer :: fileID, iCell1, iCell2, iEdge
+      integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnCell, edgesOnEdge
+      integer, dimension(:), pointer :: nEdgesOnEdge
       
       cellsOnEdge =&gt; grid % cellsOnEdge % array
       edgesOnCell =&gt; grid % edgesOnCell % array
@@ -81,8 +91,14 @@
       dcEdge =&gt; grid % dcEdge % array
       dvEdge =&gt; grid % dvEdge % array
       areaTriangle =&gt; grid % areaTriangle % array
+      fCell =&gt; grid % fCell % array
+      fEdge =&gt; grid % fEdge % array
+      edgesOnEdge       =&gt; grid % edgesOnEdge % array
+      nEdgesOnEdge      =&gt; grid % nEdgesOnEdge % array
+
       allocate(areaEdge(1:nEdgesSolve))
       areaEdge = dcEdge(1:nEdgesSolve)*dvEdge(1:nEdgesSolve)
+      weightsOnEdge     =&gt; grid % weightsOnEdge % array
 
       h =&gt; state % h % array
       u =&gt; state % u % array
@@ -96,114 +112,171 @@
 
       ! Step 2
       ! 2. Allocate the array with the correct dimensions.
-      allocate(h_top(nVertLevels,nCellsSolve))
-      allocate(h_bot(nVertLevels,nCellsSolve))
-      allocate(h2(nVertLevels,nCellsSolve))
-      allocate(hb(nVertLevels,nCellsSolve))
-      allocate(sshr(nVertLevels,nCellsSolve))
+      allocate(cellVolume(nVertLevels,nCellsSolve))
+      allocate(cellArea(nVertLevels,nCellsSolve))
+      allocate(refAreaWeightedSurfaceHeight(nVertLevels,nCellsSolve))
+      allocate(refAreaWeightedSurfaceHeight_edge(nVertLevels,nEdgesSolve))
+      allocate(volumeWeightedPotentialVorticity(nVertLevels,nVerticesSolve))
+      allocate(volumeWeightedPotentialEnstrophy(nVertLevels,nVerticesSolve))
+      allocate(potentialEnstrophyReservior(nCellsSolve))
+      allocate(vertexVolume(nVertLevels,nVerticesSolve))
+      allocate(volumeWeightedKineticEnergy(nVertLevels,nEdgesSolve))
+      allocate(volumeWeightedPotentialEnergy(nVertLevels,nCellsSolve))
+      allocate(volumeWeightedPotentialEnergyTopography(nVertLevels,nCellsSolve))
+      allocate(volumeWeightedPotentialEnergyReservoir(nCellsSolve))
+      allocate(keTend_CoriolisForce(nVertLevels,nEdgesSolve))
+      allocate(keTend_PressureGradient(nVertLevels,nEdgesSolve))
+      allocate(peTend_DivThickness(nVertLevels,nCells))
 
-      allocate(h_ref(nCellsSolve))
+      allocate(averageThickness(nCellsSolve))
 
-      allocate(pv_temp(nVertLevels,nVerticesSolve))
-      allocate(pe_vertex(nVertLevels,nVerticesSolve))
-      allocate(pve_bot(nVertLevels,nVerticesSolve))
+      allocate(h_s_edge(nEdgesSOlve))
 
-      allocate(u2(nVertLevels,nEdgesSolve))
-      allocate(cor_energy(nVertLevels,nEdgesSolve))
 
-      allocate(ke_sink(nVertLevels,nEdgesSolve))
-      allocate(pe_sink(nVertLevels,nCells))
+      cellVolume = 0
+      refAreaWeightedSurfaceHeight = 0
+      refAreaWeightedSurfaceHeight_edge = 0
+      vertexVolume = 0
+      cellArea = 0
+      averageThickness = 0
+      volumeWeightedPotentialVorticity = 0
+      volumeWeightedPotentialEnstrophy = 0
+      volumeWeightedKineticEnergy = 0
+      volumeWeightedPotentialEnergy = 0
+      volumeWeightedPotentialEnergyTopography = 0
+      volumeWeightedPotentialEnergyReservoir = 0
+      keTend_PressureGradient = 0
+      peTend_DivThickness = 0
+      keTend_CoriolisForce = 0
+      h_s_edge = 0
 
-      allocate(eres(nCellsSolve))
-
-      pe_sink = 0
-
       ! Build Arrays for Global Integrals
       ! Step 3
       ! 3. Fill the array with the data to be integrated.
-      !     eg. G_h = Sum(h dA)/Sum(dA), See below for array filling
-      do i = 1,nVertLevels
-        ! G_h Top = Sum(h dA)
-        h_top(i,:) = h(i,1:nCellsSolve)*areaCell(1:nCellsSolve)
-        ! G_h Bot = Sum(dA)
-        h_bot(i,:) = areaCell(1:nCellsSolve)
-        pv_temp(i,:) = pv_vertex(i,1:nVerticesSolve)*h_vertex(i,1:nVerticesSolve)*areaTriangle(1:nVerticesSolve) 
-        pe_vertex(i,:) = pv_vertex(i,1:nVerticesSolve)*pv_vertex(i,1:nVerticesSolve)*h_vertex(i,1:nVerticesSolve)*areaTriangle(1:nVerticesSolve)
-        pve_bot(i,:) = h_vertex(i,1:nVerticesSolve)*areaTriangle(1:nVerticesSolve)
-        u2(i,:) = u(i,1:nEdgesSolve)*u(i,1:nEdgesSolve)*h_edge(i,1:nEdgesSolve)*areaEdge(1:nEdgesSolve)*0.5
-        h2(i,:) = gravity*h(i,1:nCellsSolve)*h(i,1:nCellsSolve)*areaCell(1:nCellsSolve)*0.5
-        hb(i,:) = gravity*h(i,1:nCellsSolve)*h_s(1:nCellsSolve)*areaCell(1:nCellsSolve)
-        cor_energy(i,:) = h_edge(i,1:nEdgesSolve)*u(i,1:nEdgesSolve)*pv_edge(i,1:nEdgesSolve)*areaEdge(1:nEdgesSolve)
-        sshr(i,:) = areaCell(1:nCellsSolve)*(h(i,1:nCellsSolve)+h_s(1:nCellsSolve))
+      !     eg. GlobalFluidThickness = Sum(h dA)/Sum(dA), See below for array filling
+      do iLevel = 1,nVertLevels
+        ! eg. GlobalFluidThickness top (Sum( h dA)) = Sum(cellVolume)
+        cellVolume(iLevel,:) = h(iLevel,1:nCellsSolve)*areaCell(1:nCellsSolve)
+        ! eg. GlobalFluidThickness bot (Sum(dA)) = Sum(cellArea)
+        cellArea(iLevel,:) = areaCell(1:nCellsSolve)
+        volumeWeightedPotentialVorticity(iLevel,:) = pv_vertex(iLevel,1:nVerticesSolve) &amp;
+                *h_vertex(iLevel,1:nVerticesSolve)*areaTriangle(1:nVerticesSolve) 
+        volumeWeightedPotentialEnstrophy(iLevel,:) = pv_vertex(iLevel,1:nVerticesSolve) &amp; 
+                *pv_vertex(iLevel,1:nVerticesSolve)*h_vertex(iLevel,1:nVerticesSolve)*areaTriangle(1:nVerticesSolve)
+        vertexVolume(iLevel,:) = h_vertex(iLevel,1:nVerticesSolve)*areaTriangle(1:nVerticesSolve)
+        volumeWeightedKineticEnergy(iLevel,:) = u(iLevel,1:nEdgesSolve)*u(iLevel,1:nEdgesSolve) &amp;
+                *h_edge(iLevel,1:nEdgesSolve)*areaEdge(1:nEdgesSolve)*0.5
+        volumeWeightedPotentialEnergy(iLevel,:) = gravity*h(iLevel,1:nCellsSolve)*h(iLevel,1:nCellsSolve)*areaCell(1:nCellsSolve)*0.5
+        volumeWeightedPotentialEnergyTopography(iLevel,:) = gravity*h(iLevel,1:nCellsSolve)*h_s(1:nCellsSolve)*areaCell(1:nCellsSolve)
+        refAreaWeightedSurfaceHeight(iLevel,:) = areaCell(1:nCellsSolve)*(h(iLevel,1:nCellsSolve)+h_s(1:nCellsSolve))
 
-        do k = 1,nEdgesSolve
-            iCell1 = cellsOnEdge(k,1)
-            iCell2 = cellsOnEdge(k,2)
-            ke_sink(i,k) = areaEdge(k)*h_edge(i,k)*u(i,k)*gravity*(h(i,iCell2)+h_s(iCell2) - h(i,iCell1)-h_s(iCell1))/dcEdge(k)
-            pe_sink(i,iCell1) = pe_sink(i,iCell1) + h_edge(i,k)*u(i,k)*dvEdge(k)
-            pe_sink(i,iCell2) = pe_sink(i,iCell2) - h_edge(i,k)*u(i,k)*dvEdge(k)
+        do iEdge = 1,nEdgesSolve
+            q = 0.0
+            do j = 1,nEdgesOnEdge(iEdge)
+               eoe = edgesOnEdge(j,iEdge)
+               workpv = 0.5 * (pv_edge(iLevel,iEdge) + pv_edge(iLevel,eoe))
+               q = q + weightsOnEdge(j,iEdge) * u(iLevel,eoe) * workpv * h_edge(iLevel,eoe) 
+            end do
+            keTend_CoriolisForce(iLevel,iEdge) = h_edge(iLevel,iEdge) * u(iLevel,iEdge) * q * areaEdge(iEdge)
+
+            iCell1 = cellsOnEdge(iEdge,1)
+            iCell2 = cellsOnEdge(iEdge,2)
+
+            refAreaWeightedSurfaceHeight_edge(iLevel,iEdge) = areaEdge(iEdge)*(h_edge(iLevel,iEdge) + 0.5*(h_s(iCell1) + h_s(iCell2)))
+
+            keTend_PressureGradient(iLevel,iEdge) = areaEdge(iEdge)*h_edge(iLevel,iEdge)*u(iLevel,iEdge) &amp;
+                        *gravity*(h(iLevel,iCell2)+h_s(iCell2) - h(iLevel,iCell1)-h_s(iCell1))/dcEdge(iEdge)
+            peTend_DivThickness(iLevel,iCell1) = peTend_DivThickness(iLevel,iCell1) &amp;
+                        + h_edge(iLevel,iEdge)*u(iLevel,iEdge)*dvEdge(iEdge)
+            peTend_DivThickness(iLevel,iCell2) = peTend_DivThickness(iLevel,iCell2) &amp;
+                        - h_edge(iLevel,iEdge)*u(iLevel,iEdge)*dvEdge(iEdge)
         end do
-        pe_sink(i,:) = pe_sink(i,1:nCellsSolve)*gravity*(h(i,1:nCellsSolve)+h_s(1:nCellsSolve))
+
+        peTend_DivThickness(iLevel,:) = peTend_DivThickness(iLevel,1:nCells)*gravity &amp;
+                   *(h(iLevel,1:nCells)+h_s(1:nCells))
       end do
 
+      do iEdge = 1,nEdgesSolve
+          iCell1 = cellsOnEdge(iEdge,1)
+          iCell2 = cellsOnEdge(iEdge,2)
+          
+          h_s_edge(iEdge) = 0.5*(h_s(iCell1) + h_s(iCell2))
+      end do
+
       ! Step 4
       ! 4. Call Function to compute Global Stat that you want.
-      ! KE and PE Sink Terms
-      call computeGlobalSum(dminfo, nVertLevels, nEdgesSolve, ke_sink, ke_sink_val)
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, pe_sink, pe_sink_val)
+      ! Computing Kinetic and Potential Energy Tendency Terms
+      call computeGlobalSum(dminfo, nVertLevels, nEdgesSolve, keTend_PressureGradient, globalKineticEnergyTendency)
+      call computeGlobalSum(dminfo, nVertLevels, nCells, peTend_DivThickness, globalPotentialEnergyTendency)
 
-      call computeGlobalSum(dminfo, 1, nCellsSolve, h_ref, h_ref_val)
+      ! Computing top and bottom of global mass integral
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, cellVolume, sumCellVolume)
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, cellArea, sumCellArea)
 
-      ! Global Area Average of h
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, h_top, gh)
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, h_bot, global_temp)
+      globalKineticEnergyTendency = globalKineticEnergyTendency / sumCellVolume
+      globalPotentialEnergyTendency = globalPotentialEnergyTendency / sumCellVolume
 
       ! Step 5
       ! 5. Finish computing the global stat/integral
-      gh = gh/global_temp
+      globalFluidThickness = sumCellVolume/sumCellArea
 
-      ! Mean SSH for PE Res
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, sshr, sshr_val)
+      ! Compute Average Sea Surface Height for Potential Energy and Enstrophy
+      ! Reservoir computations
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, refAreaWeightedSurfaceHeight, sumrefAreaWeightedSurfaceHeight)
 
-      h_ref(:) = (sshr_val/global_temp)-h_s(1:nCellsSolve)
+      averageThickness(:) = (sumrefAreaWeightedSurfaceHeight/sumCellArea)-h_s(1:nCellsSolve)
 
+      ! Compute Volume Weighted Averages of Potential Vorticity and Potential Enstrophy
+      call computeGlobalSum(dminfo, nVertLevels, nVerticesSolve, volumeWeightedPotentialVorticity, globalPotentialVorticity)
+      call computeGlobalSum(dminfo, nVertLevels, nVerticesSolve, volumeWeightedPotentialEnstrophy, globalPotentialEnstrophy)
+      call computeGlobalSum(dminfo, nVertLevels, nVerticesSolve, vertexVolume, sumVertexVolume)
 
-      ! Gloabl Area-Thickness Average of pv and pe
-      call computeGlobalSum(dminfo, nVertLevels, nVerticesSolve, pv_temp, gpv)
-      call computeGlobalSum(dminfo, nVertLevels, nVerticesSolve, pe_vertex, gpe)
-      call computeGlobalSum(dminfo, nVertLevels, nVerticesSolve, pve_bot, global_temp)
+      globalPotentialVorticity = globalPotentialVorticity/sumVertexVolume
+      globalPotentialEnstrophy = globalPotentialEnstrophy/sumVertexVolume
 
-      gpv = gpv/global_temp
-      gpe = gpe/global_temp
+      ! Compte Potential Enstrophy Reservior
+      potentialEnstrophyReservior(:) = areaCell(:)*fCell(:)*fCell(:)/averageThickness
+      call computeGlobalSum(dminfo, 1, nCellsSolve, potentialEnstrophyReservior, globalPotentialEnstrophyReservoir)
+      globalPotentialEnstrophyReservoir = globalPotentialEnstrophyReservoir/sumCellVolume
 
-      ! Global Integral of Total Energy with subtracting reference res
-      call computeGlobalSum(dminfo, nVertLevels, nEdgesSolve, u2, ke)
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, h2, global_temp)
-      ge = ke + global_temp
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, hb, global_temp)
-      ge = ge + global_temp
+      globalPotentialEnstrophy = globalPotentialEnstrophy - globalPotentialEnstrophyReservoir
 
-      eres(1:nCellsSolve) = areaCell(1:nCellsSolve)*h_ref*h_ref*gravity*0.5
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, eres, global_temp)
-      ger = global_temp
-      eres(1:nCellsSolve) = areaCell(1:nCellsSolve)*h_ref*h_s(1:nCellsSolve)*gravity
-      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, eres, global_temp)
-      ger = ger + global_temp
-      ge = ge - ger
+      ! Compute Kinetic and Potential Energy terms to be combined into total energy
+      call computeGlobalSum(dminfo, nVertLevels, nEdgesSolve, volumeWeightedKineticEnergy, globalKineticEnergy)
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, volumeWeightedPotentialEnergy, globalPotentialEnergy)
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, volumeWeightedPotentialEnergyTopography, global_temp)
 
-      ! Global Integral of spurious Coriolis energy for Time to KE doubling
-      call computeGlobalSum(dminfo, nVertLevels, nEdgesSolve, cor_energy, e_cor)
+      globalKineticEnergy = globalKineticEnergy/sumCellVolume
+      globalPotentialEnergy = (globalPotentialEnergy + global_temp)/sumCellVolume
 
+      ! Compute Potential energy reservoir to be subtracted from potential energy term
+      volumeWeightedPotentialEnergyReservoir(1:nCellsSolve) = areaCell(1:nCellsSolve)*averageThickness*averageThickness*gravity*0.5
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, volumeWeightedPotentialEnergyReservoir, globalPotentialEnergyReservoir)
+      volumeWeightedPotentialEnergyReservoir(1:nCellsSolve) = areaCell(1:nCellsSolve)*averageThickness*h_s(1:nCellsSolve)*gravity
+      call computeGlobalSum(dminfo, nVertLevels, nCellsSolve, volumeWeightedPotentialEnergyReservoir, global_temp)
+
+      globalPotentialEnergyReservoir = (globalPotentialEnergyReservoir + global_temp)/sumCellVolume
+
+      globalPotentialEnergy = globalPotentialEnergy - globalPotentialEnergyReservoir
+      globalEnergy = globalKineticEnergy + globalPotentialEnergy
+
+      ! Compute Coriolis energy tendency term
+      call computeGlobalSum(dminfo, nVertLevels, nEdgesSolve, keTend_CoriolisForce, globalCoriolisEnergyTendency)
+      globalCoriolisEnergyTendency = globalCoriolisEnergyTendency/sumCellVolume
+
       ! Step 6
       ! 6. Write out your global stat to the file
       if (dminfo % my_proc_id == IO_NODE) then
          fileID = getFreeUnit()
+
          if (timeIndex/config_stats_interval == 1) then
              open(fileID, file='GlobalIntegrals.txt',STATUS='unknown')
          else
-             open(fileID, file='GlobalIntegrals.txt',ACCESS='append')
+             open(fileID, file='GlobalIntegrals.txt',POSITION='append')
          endif 
-         write(fileID,'(100es24.16)') gh, gpv, gpe, ge, e_cor, abs(ke/e_cor), ke_sink_val+pe_sink_val,abs(ke/(ke_sink_val+pe_sink_val))
+         write(fileID,'(1i, 100es24.16)') timeIndex, timeIndex*dt, globalFluidThickness, globalPotentialVorticity, globalPotentialEnstrophy, &amp;
+                        globalEnergy, globalCoriolisEnergyTendency, globalKineticEnergyTendency+globalPotentialEnergyTendency, &amp;
+                        globalKineticEnergy, globalPotentialEnergy
          close(fileID)
       end if
 

Modified: branches/atmos_physics/src/core_sw/module_test_cases.F
===================================================================
--- branches/atmos_physics/src/core_sw/module_test_cases.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_sw/module_test_cases.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -33,9 +33,9 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_1(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_1(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -47,9 +47,9 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_2(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_2(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -61,9 +61,9 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_5(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_5(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -75,9 +75,9 @@
 
          block_ptr =&gt; domain % blocklist
          do while (associated(block_ptr))
-            call sw_test_case_6(block_ptr % mesh, block_ptr % time_levs(1) % state)
+            call sw_test_case_6(block_ptr % mesh, block_ptr % state % time_levs(1) % state)
             do i=2,nTimeLevs
-               call copy_state(block_ptr % time_levs(1) % state, block_ptr % time_levs(i) % state)
+               call copy_state(block_ptr % state % time_levs(i) % state, block_ptr % state % time_levs(1) % state)
             end do
 
             block_ptr =&gt; block_ptr % next
@@ -102,8 +102,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: u0 = 2.0 * pii * a / (12.0 * 86400.0)
       real (kind=RKIND), parameter :: h0 = 1000.0
@@ -148,9 +148,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -164,9 +161,6 @@
          else
             state % h % array(1,iCell) = 0.0
          end if
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_1
@@ -184,8 +178,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: u0 = 2.0 * pii * a / (12.0 * 86400.0)
       real (kind=RKIND), parameter :: gh0 = 29400.0
@@ -230,9 +224,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -262,9 +253,6 @@
                                              )**2.0 &amp;
                                       ) / &amp;
                                       gravity
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_2
@@ -281,8 +269,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: u0 = 20.
       real (kind=RKIND), parameter :: gh0 = 5960.0*gravity
@@ -330,9 +318,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -389,9 +374,6 @@
                                       ) / &amp;
                                       gravity
          state % h % array(1,iCell) = state % h % array(1,iCell) - grid % h_s % array(iCell)
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_5
@@ -408,8 +390,8 @@
 
       implicit none
 
-      type (grid_meta), intent(inout) :: grid
-      type (grid_state), intent(inout) :: state
+      type (mesh_type), intent(inout) :: grid
+      type (state_type), intent(inout) :: state
 
       real (kind=RKIND), parameter :: h0 = 8000.0
       real (kind=RKIND), parameter :: w = 7.848e-6
@@ -453,9 +435,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -467,9 +446,6 @@
                                                       a*a*BB(grid%latCell%array(iCell)) * cos(R*grid%lonCell%array(iCell)) + &amp;
                                                       a*a*CC(grid%latCell%array(iCell)) * cos(2.0*R*grid%lonCell%array(iCell)) &amp;
                                       ) / gravity
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_6

Modified: branches/atmos_physics/src/core_sw/module_time_integration.F
===================================================================
--- branches/atmos_physics/src/core_sw/module_time_integration.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_sw/module_time_integration.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -37,7 +37,7 @@
 
       block =&gt; domain % blocklist
       do while (associated(block))
-         block % time_levs(2) % state % xtime % scalar = block % time_levs(1) % state % xtime % scalar + dt
+         block % state % time_levs(2) % state % xtime % scalar = block % state % time_levs(1) % state % xtime % scalar + dt
          block =&gt; block % next
       end do
 
@@ -62,13 +62,17 @@
 
       integer :: iCell, k
       type (block_type), pointer :: block
+      type (state_type) :: provis
 
-      integer, parameter :: PROVIS = 1
-      integer, parameter :: TEND   = 2
       integer :: rk_step
 
       real (kind=RKIND), dimension(4) :: rk_weights, rk_substep_weights
 
+      block =&gt; domain % blocklist
+      call allocate_state(provis, &amp;
+                          block % mesh % nCells, block % mesh % nEdges, block % mesh % maxEdges, block % mesh % maxEdges2, &amp;
+                          block % mesh % nVertices, block % mesh % vertexDegree, block % mesh % nVertLevels, &amp;
+                          block % mesh % nTracers)
 
       !
       ! Initialize time_levs(2) with state at current time
@@ -79,16 +83,16 @@
       block =&gt; domain % blocklist
       do while (associated(block))
 
-         block % time_levs(2) % state % u % array(:,:) = block % time_levs(1) % state % u % array(:,:)
-         block % time_levs(2) % state % h % array(:,:) = block % time_levs(1) % state % h % array(:,:)
+         block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
+         block % state % time_levs(2) % state % h % array(:,:) = block % state % time_levs(1) % state % h % array(:,:)
          do iCell=1,block % mesh % nCells  ! couple tracers to h
            do k=1,block % mesh % nVertLevels
-             block % time_levs(2) % state % tracers % array(:,k,iCell) = block % time_levs(1) % state % tracers % array(:,k,iCell) &amp;
-                                                                       * block % time_levs(1) % state % h % array(k,iCell)
+             block % state % time_levs(2) % state % tracers % array(:,k,iCell) = block % state % time_levs(1) % state % tracers % array(:,k,iCell) &amp;
+                                                                       * block % state % time_levs(1) % state % h % array(k,iCell)
             end do
          end do
 
-         call copy_state(block % time_levs(1) % state, block % intermediate_step(PROVIS))
+         call copy_state(provis, block % state % time_levs(1) % state)
 
          block =&gt; block % next
       end do
@@ -113,7 +117,7 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(PROVIS) % pv_edge % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, provis % pv_edge % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                             block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
            block =&gt; block % next
@@ -123,9 +127,9 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call compute_tend(block % intermediate_step(TEND), block % intermediate_step(PROVIS), block % mesh)
-           call compute_scalar_tend(block % intermediate_step(TEND), block % intermediate_step(PROVIS), block % mesh)
-           call enforce_boundaryEdge(block % intermediate_step(TEND), block % mesh)
+           call compute_tend(block % tend, provis, block % mesh)
+           call compute_scalar_tend(block % tend, provis, block % mesh)
+           call enforce_boundaryEdge(block % tend, block % mesh)
            block =&gt; block % next
         end do
 
@@ -133,13 +137,13 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % u % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % u % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nEdges, &amp;
                                             block % parinfo % edgesToSend, block % parinfo % edgesToRecv)
-           call dmpar_exch_halo_field2dReal(domain % dminfo, block % intermediate_step(TEND) % h % array(:,:), &amp;
+           call dmpar_exch_halo_field2dReal(domain % dminfo, block % tend % h % array(:,:), &amp;
                                             block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
-           call dmpar_exch_halo_field3dReal(domain % dminfo, block % intermediate_step(TEND) % tracers % array(:,:,:), &amp;
+           call dmpar_exch_halo_field3dReal(domain % dminfo, block % tend % tracers % array(:,:,:), &amp;
                                             block % mesh % nTracers, block % mesh % nVertLevels, block % mesh % nCells, &amp;
                                             block % parinfo % cellsToSend, block % parinfo % cellsToRecv)
            block =&gt; block % next
@@ -150,23 +154,23 @@
         if (rk_step &lt; 4) then
            block =&gt; domain % blocklist
            do while (associated(block))
-              block % intermediate_step(PROVIS) % u % array(:,:)       = block % time_levs(1) % state % u % array(:,:)  &amp;
-                                         + rk_substep_weights(rk_step) * block % intermediate_step(TEND) % u % array(:,:)
-              block % intermediate_step(PROVIS) % h % array(:,:)       = block % time_levs(1) % state % h % array(:,:)  &amp;
-                                         + rk_substep_weights(rk_step) * block % intermediate_step(TEND) % h % array(:,:)
+              provis % u % array(:,:)       = block % state % time_levs(1) % state % u % array(:,:)  &amp;
+                                            + rk_substep_weights(rk_step) * block % tend % u % array(:,:)
+              provis % h % array(:,:)       = block % state % time_levs(1) % state % h % array(:,:)  &amp;
+                                            + rk_substep_weights(rk_step) * block % tend % h % array(:,:)
               do iCell=1,block % mesh % nCells
                  do k=1,block % mesh % nVertLevels
-                    block % intermediate_step(PROVIS) % tracers % array(:,k,iCell) = ( &amp;
-                                                                      block % time_levs(1) % state % h % array(k,iCell) * &amp;
-                                                                      block % time_levs(1) % state % tracers % array(:,k,iCell)  &amp;
-                                      + rk_substep_weights(rk_step) * block % intermediate_step(TEND) % tracers % array(:,k,iCell) &amp;
-                                                                     ) / block % intermediate_step(PROVIS) % h % array(k,iCell)
+                    provis % tracers % array(:,k,iCell) = ( &amp;
+                                                           block % state % time_levs(1) % state % h % array(k,iCell) * &amp;
+                                                           block % state % time_levs(1) % state % tracers % array(:,k,iCell)  &amp;
+                                      + rk_substep_weights(rk_step) * block % tend % tracers % array(:,k,iCell) &amp;
+                                                          ) / provis % h % array(k,iCell)
                  end do
               end do
               if (config_test_case == 1) then    ! For case 1, wind field should be fixed
-                 block % intermediate_step(PROVIS) % u % array(:,:) = block % time_levs(1) % state % u % array(:,:)
+                 provis % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
               end if
-              call compute_solve_diagnostics(dt, block % intermediate_step(PROVIS), block % mesh)
+              call compute_solve_diagnostics(dt, provis, block % mesh)
               block =&gt; block % next
            end do
         end if
@@ -175,15 +179,15 @@
 
         block =&gt; domain % blocklist
         do while (associated(block))
-           block % time_levs(2) % state % u % array(:,:) = block % time_levs(2) % state % u % array(:,:) &amp;
-                                   + rk_weights(rk_step) * block % intermediate_step(TEND) % u % array(:,:) 
-           block % time_levs(2) % state % h % array(:,:) = block % time_levs(2) % state % h % array(:,:) &amp;
-                                   + rk_weights(rk_step) * block % intermediate_step(TEND) % h % array(:,:) 
+           block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(2) % state % u % array(:,:) &amp;
+                                   + rk_weights(rk_step) * block % tend % u % array(:,:) 
+           block % state % time_levs(2) % state % h % array(:,:) = block % state % time_levs(2) % state % h % array(:,:) &amp;
+                                   + rk_weights(rk_step) * block % tend % h % array(:,:) 
            do iCell=1,block % mesh % nCells
               do k=1,block % mesh % nVertLevels
-                 block % time_levs(2) % state % tracers % array(:,k,iCell) =  &amp;
-                                                                       block % time_levs(2) % state % tracers % array(:,k,iCell) &amp;
-                                               + rk_weights(rk_step) * block % intermediate_step(TEND) % tracers % array(:,k,iCell)
+                 block % state % time_levs(2) % state % tracers % array(:,k,iCell) =  &amp;
+                                                                       block % state % time_levs(2) % state % tracers % array(:,k,iCell) &amp;
+                                               + rk_weights(rk_step) * block % tend % tracers % array(:,k,iCell)
               end do
            end do
            block =&gt; block % next
@@ -202,23 +206,25 @@
       do while (associated(block))
          do iCell=1,block % mesh % nCells
             do k=1,block % mesh % nVertLevels
-               block % time_levs(2) % state % tracers % array(:,k,iCell) = &amp;
-                                                                     block % time_levs(2) % state % tracers % array(:,k,iCell)  &amp;
-                                                                   / block % time_levs(2) % state % h % array(k,iCell)
+               block % state % time_levs(2) % state % tracers % array(:,k,iCell) = &amp;
+                                                                     block % state % time_levs(2) % state % tracers % array(:,k,iCell)  &amp;
+                                                                   / block % state % time_levs(2) % state % h % array(k,iCell)
             end do
          end do
 
          if (config_test_case == 1) then    ! For case 1, wind field should be fixed
-            block % time_levs(2) % state % u % array(:,:) = block % time_levs(1) % state % u % array(:,:)
+            block % state % time_levs(2) % state % u % array(:,:) = block % state % time_levs(1) % state % u % array(:,:)
          end if
 
-         call compute_solve_diagnostics(dt, block % time_levs(2) % state, block % mesh)
+         call compute_solve_diagnostics(dt, block % state % time_levs(2) % state, block % mesh)
 
-         call reconstruct(block % time_levs(2) % state, block % mesh)
+         call reconstruct(block % state % time_levs(2) % state, block % diag, block % mesh)
 
          block =&gt; block % next
       end do
 
+      call deallocate_state(provis)
+
    end subroutine rk4
 
 
@@ -234,9 +240,9 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(in) :: grid
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j
       real (kind=RKIND) :: flux, vorticity_abs, workpv, q, upstream_bias
@@ -394,9 +400,9 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_state), intent(in) :: s
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (state_type), intent(in) :: s
+      type (mesh_type), intent(in) :: grid
 
       integer :: iCell, iEdge, k, iTracer, cell1, cell2
       real (kind=RKIND) :: flux, tracer_edge
@@ -440,8 +446,8 @@
       implicit none
 
       real (kind=RKIND), intent(in) :: dt
-      type (grid_state), intent(inout) :: s
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: s
+      type (mesh_type), intent(in) :: grid
 
 
       integer :: iEdge, iCell, iVertex, k, cell1, cell2, vertex1, vertex2, eoe, i, j, cov
@@ -753,8 +759,8 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: tend
-      type (grid_meta), intent(in) :: grid
+      type (tend_type), intent(inout) :: tend
+      type (mesh_type), intent(in) :: grid
 
       integer, dimension(:,:), pointer :: boundaryEdge
       real (kind=RKIND), dimension(:,:), pointer :: tend_u

Modified: branches/atmos_physics/src/core_sw/mpas_interface.F
===================================================================
--- branches/atmos_physics/src/core_sw/mpas_interface.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/core_sw/mpas_interface.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -22,14 +22,14 @@
    implicit none
 
    type (block_type), intent(inout) :: block
-   type (grid_meta), intent(inout) :: mesh
+   type (mesh_type), intent(inout) :: mesh
    real (kind=RKIND), intent(in) :: dt
 
-   call compute_solve_diagnostics(dt, block % time_levs(1) % state, mesh)
+   call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
 
    call rbfInterp_initialize(mesh)
    call init_reconstruct(mesh)
-   call reconstruct(block % time_levs(1) % state, mesh)
+   call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
 
 end subroutine mpas_init
 
@@ -64,18 +64,20 @@
 
    call timestep(domain, dt)
 
-   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.'
+   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 timer_start(&quot;global_diagnostics&quot;)
+           call computeGlobalDiagnostics(domain % dminfo, &amp;
+                    block_ptr % state % time_levs(2) % state, block_ptr % mesh, &amp;
+                    itimestep, dt)
+           call timer_stop(&quot;global_diagnostics&quot;)
        end if
-
-       call timer_start(&quot;global_diagnostics&quot;)
-       call computeGlobalDiagnostics(domain % dminfo, &amp;
-                block_ptr % time_levs(2) % state, block_ptr % mesh, &amp;
-                itimestep, dt)
-       call timer_stop(&quot;global_diagnostics&quot;)
    end if
 
 end subroutine mpas_timestep

Modified: branches/atmos_physics/src/driver/module_subdriver.F
===================================================================
--- branches/atmos_physics/src/driver/module_subdriver.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/driver/module_subdriver.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -13,7 +13,7 @@
       subroutine mpas_init(block, mesh, dt)
          use grid_types
          type (block_type), intent(inout) :: block
-         type (grid_meta), intent(inout) :: mesh
+         type (mesh_type), intent(inout) :: mesh
          real (kind=RKIND), intent(in) :: dt
       end subroutine mpas_init
 
@@ -59,7 +59,7 @@
       block_ptr =&gt; domain % blocklist
       do while (associated(block_ptr))
          call mpas_init(block_ptr, block_ptr % mesh, dt)
-         if (.not. config_do_restart) block_ptr % time_levs(1) % state % xtime % scalar = 0.0
+         if (.not. config_do_restart) block_ptr % state % time_levs(1) % state % xtime % scalar = 0.0
          block_ptr =&gt; block_ptr % next
       end do
 
@@ -79,7 +79,7 @@
          call timer_stop(&quot;time integration&quot;)
 
          ! Move time level 2 fields back into time level 1 for next time step
-         call shift_time_levels(domain)
+         call shift_time_levels_state(domain % blocklist % state)
 
          if (mod(itimestep, config_output_interval) == 0) then 
             call write_output_frame(output_obj, domain)
@@ -116,7 +116,7 @@
 
       block_ptr =&gt; domain % blocklist
       do while (associated(block_ptr))
-         call compute_output_diagnostics(block_ptr % time_levs(1) % state, block_ptr % mesh)
+         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
          block_ptr =&gt; block_ptr % next
       end do
 
@@ -138,8 +138,8 @@
 
       implicit none
 
-      type (grid_state), intent(inout) :: state
-      type (grid_meta), intent(in) :: grid
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
 
       integer :: i, eoe
       integer :: iEdge, k

Modified: branches/atmos_physics/src/framework/module_grid_types.F
===================================================================
--- branches/atmos_physics/src/framework/module_grid_types.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/framework/module_grid_types.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -4,8 +4,7 @@
 
    integer, parameter :: nTimeLevs = 2
 
-#include &quot;super_array_indices.inc&quot;
-  
+
    ! Derived type describing info for doing I/O specific to a field
    type io_info
       character (len=1024) :: fieldName
@@ -66,7 +65,7 @@
 
 
    ! Derived type for storing grid meta-data
-   type grid_meta
+   type mesh_type
 
 #include &quot;field_dimensions.inc&quot;
 
@@ -75,21 +74,12 @@
 
 #include &quot;time_invariant_fields.inc&quot;
 
-   end type grid_meta
+   end type mesh_type
 
 
-   ! Derived type for storing model state
-   type grid_state
+#include &quot;variable_groups.inc&quot;
 
-#include &quot;time_varying_fields.inc&quot;
 
-   end type grid_state
-
-   type grid_state_ptr
-      type (grid_state), pointer :: state
-   end type grid_state_ptr
-
-
    ! Type for storing (possibly architecture specific) information concerning to parallelism
    type parallel_info
       type (exchange_list), pointer :: cellsToSend            ! List of types describing which cells to send to other blocks
@@ -105,11 +95,8 @@
    type block_type
       integer :: storageFactor    ! Additional storage used by time integration scheme
 
-      type (grid_meta), pointer :: mesh
-      type (grid_state_ptr), pointer, dimension(:) :: time_levs
+#include &quot;block_group_members.inc&quot;
 
-      type (grid_state), allocatable, dimension(:) :: intermediate_step
-
       type (domain_type), pointer :: domain
 
       type (parallel_info), pointer :: parinfo
@@ -170,60 +157,21 @@
       nullify(b % prev)
       nullify(b % next)
 
-      allocate(b % time_levs(nTimeLevs))
-
-      allocate(b % mesh)
-      call allocate_grid_meta(b % mesh, &amp;
-#include &quot;dim_dummy_args.inc&quot;
-                             )
-  
-      do i=1,nTimeLevs
-         allocate(b % time_levs(i) % state)
-         call allocate_grid_state(b % time_levs(i) % state, b)
-      end do
-
       key = 'STORAGE_FACTOR'
       call mpas_query(key, b % storageFactor)
 
-      ! Allocate storage for intermediate steps used by time integration scheme
-      allocate(b % intermediate_step(b % storageFactor))
-      do i=1,b % storageFactor
-         call allocate_grid_state(b % intermediate_step(i), b)
-      end do
-
       allocate(b % parinfo)
 
       b % domain =&gt; dom
 
+#include &quot;block_allocs.inc&quot;
+
    end subroutine allocate_block
 
 
-   subroutine allocate_grid_meta(g, &amp;
-#include &quot;dim_dummy_args.inc&quot;
-                                )
+#include &quot;group_alloc_routines.inc&quot;
 
-      implicit none
 
-      type (grid_meta), intent(inout) :: g
-#include &quot;dim_dummy_decls.inc&quot;
-
-#include &quot;grid_meta_allocs.inc&quot;
-
-   end subroutine allocate_grid_meta
-
-
-   subroutine allocate_grid_state(s, b)
-
-      implicit none
-
-      type (grid_state), intent(inout) :: s
-      type (block_type), pointer :: b
-
-#include &quot;grid_state_allocs.inc&quot;
-
-   end subroutine allocate_grid_state
-
-
    subroutine deallocate_domain(dom)
 
       implicit none
@@ -251,78 +199,19 @@
 
       integer :: i
 
-      call deallocate_grid_meta(b % mesh)
-      deallocate(b % mesh)
-      do i=1,nTimeLevs
-         call deallocate_grid_state(b % time_levs(i) % state)
-         deallocate(b % time_levs(i) % state)
-      end do
-      deallocate(b % time_levs)
-      do i=1,b % storageFactor
-         call deallocate_grid_state(b % intermediate_step(i))
-      end do
-      deallocate(b % intermediate_step)
       deallocate(b % parinfo)
 
+#include &quot;block_deallocs.inc&quot;
+
    end subroutine deallocate_block
 
 
-   subroutine deallocate_grid_meta(g)
+#include &quot;group_dealloc_routines.inc&quot;
 
-      implicit none
 
-      type (grid_meta), intent(inout) :: g
+#include &quot;group_copy_routines.inc&quot;
 
-#include &quot;grid_meta_deallocs.inc&quot;
 
-   end subroutine deallocate_grid_meta
+#include &quot;group_shift_level_routines.inc&quot;
 
-
-   subroutine deallocate_grid_state(s)
-
-      implicit none
-
-      type (grid_state), intent(inout) :: s
-
-#include &quot;grid_state_deallocs.inc&quot;
-
-   end subroutine deallocate_grid_state
-
-
-   subroutine copy_state(src, dest)
-
-      implicit none
-
-      type (grid_state), intent(in) :: src
-      type (grid_state), intent(inout) :: dest
-
-#include &quot;copy_state.inc&quot;
-  
-   end subroutine copy_state
-
-
-   subroutine shift_time_levels(domain)
-
-      implicit none
-
-      type (domain_type), intent(inout) :: domain
-
-      integer :: i
-      type (block_type), pointer :: block_ptr
-      type (grid_state), pointer :: sptr
-
-      block_ptr =&gt; domain % blocklist
-      do while (associated(block_ptr))
-
-         sptr =&gt; block_ptr % time_levs(1) % state
-         do i=1,nTimeLevs-1
-            block_ptr % time_levs(i) % state =&gt; block_ptr % time_levs(i+1) % state
-         end do
-         block_ptr % time_levs(nTimeLevs) % state =&gt; sptr
-
-         block_ptr =&gt; block_ptr % next
-      end do
-
-   end subroutine shift_time_levels
-
 end module grid_types

Modified: branches/atmos_physics/src/framework/module_io_input.F
===================================================================
--- branches/atmos_physics/src/framework/module_io_input.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/framework/module_io_input.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -1094,13 +1094,6 @@
  
 #include &quot;netcdf_read_ids.inc&quot;
 
-#ifdef EXPAND_LEVELS
-      if (.not. config_do_restart) then
-         input_obj % rdLocalnVertLevels = EXPAND_LEVELS
-         write(0,*) 'Expanding nVertLevels to ',input_obj % rdLocalnVertLevels,' by duplicating the first level.'
-      end if
-#endif
-
    end subroutine io_input_init
 
   

Modified: branches/atmos_physics/src/framework/module_io_output.F
===================================================================
--- branches/atmos_physics/src/framework/module_io_output.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/framework/module_io_output.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -338,7 +338,7 @@
  
       type (io_output_object), intent(inout) :: output_obj
       type (dm_info), intent(in) :: dminfo
-      type (grid_meta), intent(in) :: mesh
+      type (mesh_type), intent(in) :: mesh
 #include &quot;dim_dummy_decls.inc&quot;
  
       integer :: nferr

Modified: branches/atmos_physics/src/operators/module_RBF_interpolation.F
===================================================================
--- branches/atmos_physics/src/operators/module_RBF_interpolation.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/operators/module_RBF_interpolation.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -112,7 +112,7 @@
 
     implicit none
 
-    type (grid_meta), intent(inout) :: grid 
+    type (mesh_type), intent(inout) :: grid 
 
     integer :: nCells, nEdges
     integer, dimension(:,:), pointer :: cellsOnEdge, edgesOnCell

Modified: branches/atmos_physics/src/operators/module_vector_reconstruction.F
===================================================================
--- branches/atmos_physics/src/operators/module_vector_reconstruction.F        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/operators/module_vector_reconstruction.F        2010-10-13 20:25:17 UTC (rev 549)
@@ -23,7 +23,7 @@
 
     implicit none
 
-    type (grid_meta), intent(inout) :: grid 
+    type (mesh_type), intent(inout) :: grid 
 
     ! temporary arrays needed in the (to be constructed) init procedure
     integer :: nCellsSolve
@@ -112,7 +112,7 @@
 
   end subroutine init_reconstruct
 
-  subroutine reconstruct(state, grid)
+  subroutine reconstruct(state, diag, grid)
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! Purpose: reconstruct vector field at cell centers based on radial basis functions
   !
@@ -123,8 +123,9 @@
 
     implicit none
 
-    type (grid_state), intent(inout) :: state 
-    type (grid_meta), intent(in) :: grid
+    type (state_type), intent(in) :: state 
+    type (diag_type), intent(inout) :: diag 
+    type (mesh_type), intent(in) :: grid
 
     !   temporary arrays needed in the compute procedure
     integer :: nCellsSolve
@@ -151,14 +152,14 @@
     nEdgesOnCell=&gt; grid % nEdgesOnCell % array
     nCellsSolve = grid % nCellsSolve
     u =&gt; state % u % array
-    uReconstructX =&gt; state % uReconstructX % array
-    uReconstructY =&gt; state % uReconstructY % array
-    uReconstructZ =&gt; state % uReconstructZ % array
+    uReconstructX =&gt; diag % uReconstructX % array
+    uReconstructY =&gt; diag % uReconstructY % array
+    uReconstructZ =&gt; diag % uReconstructZ % array
 
     latCell       =&gt; grid % latCell % array
     lonCell       =&gt; grid % lonCell % array
-    uReconstructZonal =&gt; state % uReconstructZonal % array
-    uReconstructMeridional =&gt; state % uReconstructMeridional % array
+    uReconstructZonal =&gt; diag % uReconstructZonal % array
+    uReconstructMeridional =&gt; diag % uReconstructMeridional % array
     on_a_sphere = grid % on_a_sphere
 
     ! init the intent(out)

Modified: branches/atmos_physics/src/registry/gen_inc.c
===================================================================
--- branches/atmos_physics/src/registry/gen_inc.c        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/registry/gen_inc.c        2010-10-13 20:25:17 UTC (rev 549)
@@ -150,12 +150,15 @@
 }
 
 
-void gen_field_defs(struct variable * vars, struct dimension * dims)
+void gen_field_defs(struct group_list * groups, struct variable * vars, struct dimension * dims)
 {
    struct variable * var_ptr;
    struct variable * var_ptr2;
+   struct variable_list * var_list_ptr;
+   struct variable_list * var_list_ptr2;
    struct dimension * dim_ptr;
    struct dimension_list * dimlist_ptr;
+   struct group_list * group_ptr;
    FILE * fd;
    char super_array[1024];
    char array_class[1024];
@@ -163,59 +166,7 @@
    int class_start, class_end;
    int vtype;
 
-   /*
-    * Generate indices for super arrays
-    */
-   fd = fopen(&quot;super_array_indices.inc&quot;, &quot;w&quot;);
-   var_ptr = vars;
-   memcpy(super_array, var_ptr-&gt;super_array, 1024);
-   i = 1;
-   while (var_ptr) {
-      if (strncmp(super_array, var_ptr-&gt;super_array, 1024) != 0) {
-         memcpy(super_array, var_ptr-&gt;super_array, 1024);
-         i = 1;
-       }
-      if (strncmp(var_ptr-&gt;array_class, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: index_%s = %i</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code, i++);
-      var_ptr = var_ptr-&gt;next;
-   }
-   var_ptr = vars;
-   memcpy(super_array, var_ptr-&gt;super_array, 1024);
-   memcpy(array_class, var_ptr-&gt;array_class, 1024);
-   class_start = 1;
-   class_end = 1;
-   i = 1;
-   while (var_ptr) {
-      if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-         if (strncmp(super_array, var_ptr-&gt;super_array, 1024) != 0) {
-            if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="red">&quot;, array_class, class_end);
-            if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="red">&quot;, super_array, i);
-            class_start = 1;
-            class_end = 1;
-            i = 1;
-            memcpy(super_array, var_ptr-&gt;super_array, 1024);
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="red">&quot;, array_class, class_start);
-         }
-         else if (strncmp(array_class, var_ptr-&gt;array_class, 1024) != 0) {
-            fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="red">&quot;, array_class, class_end);
-            class_start = class_end+1;
-            class_end = class_start;
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="red">&quot;, array_class, class_start);
-            i++;
-         }
-         else {
-            class_end++;
-            i++;
-         }
-      }
-      var_ptr = var_ptr-&gt;next;
-   }
-   if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="red">&quot;, array_class, class_end);
-   if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="gray">&quot;, super_array, i);
-   fclose(fd);
 
-
    /*
     *  Generate declarations of dimensions
     */
@@ -311,101 +262,295 @@
 
 
    /*
-    *  Generate declarations of time-invariant fields
+    *  Generate declarations of mesh group
     */
    fd = fopen(&quot;time_invariant_fields.inc&quot;, &quot;w&quot;);
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 0) {
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            memcpy(super_array, var_ptr-&gt;super_array, 1024);
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
+   group_ptr = groups;
+   while (group_ptr) {
+
+      if (!strncmp(group_ptr-&gt;name, &quot;mesh&quot;, 1024)) {
+
+         var_list_ptr = group_ptr-&gt;vlist;
+         memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+         i = 1;
+         while (var_list_ptr) {
+            if (strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) != 0) {
+               memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+               i = 1;
+             }
+            if (strncmp(var_list_ptr-&gt;var-&gt;array_class, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: index_%s = %i</font>
<font color="blue">&quot;, var_list_ptr-&gt;var-&gt;name_in_code, i++);
+            var_list_ptr = var_list_ptr-&gt;next;
+         }
+
+         var_list_ptr = group_ptr-&gt;vlist;
+         memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+         memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
+         class_start = 1;
+         class_end = 1;
+         i = 1;
+         while (var_list_ptr) {
+            if (strncmp(var_list_ptr-&gt;var-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+               if (strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) != 0) {
+                  if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+                  if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="blue">&quot;, super_array, i);
+                  class_start = 1;
+                  class_end = 1;
+                  i = 1;
+                  memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+                  memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
+                  fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="blue">&quot;, array_class, class_start);
+               }
+               else if (strncmp(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024) != 0) {
+                  fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+                  class_start = class_end+1;
+                  class_end = class_start;
+                  memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
+                  fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="red">&quot;, array_class, class_start);
+                  i++;
+               }
+               else {
+                  class_end++;
+                  i++;
+               }
             }
-            if (vtype == INTEGER)  fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="red">&quot;, (var_ptr2-&gt;ndims)+1, var_ptr2-&gt;super_array);
-            if (vtype == REAL)     fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="red">&quot;, (var_ptr2-&gt;ndims)+1, var_ptr2-&gt;super_array);
+            var_list_ptr = var_list_ptr-&gt;next;
          }
-         else {
-            if (var_ptr-&gt;vtype == INTEGER)  fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="red">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-            if (var_ptr-&gt;vtype == REAL)     fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="red">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-            var_ptr = var_ptr-&gt;next;
+         if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+         if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="blue">&quot;, super_array, i);
+
+         var_list_ptr = group_ptr-&gt;vlist;
+         while (var_list_ptr) {
+            var_ptr = var_list_ptr-&gt;var;
+            if (!strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024)) {
+              if (var_ptr-&gt;vtype == INTEGER) fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
+              if (var_ptr-&gt;vtype == REAL)    fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
+            }
+            else {
+              if (var_ptr-&gt;vtype == INTEGER) fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims+1, var_ptr-&gt;super_array);
+              if (var_ptr-&gt;vtype == REAL)    fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="red">&quot;, var_ptr-&gt;ndims+1, var_ptr-&gt;super_array);
+              while (var_list_ptr-&gt;next &amp;&amp; !strncmp(var_list_ptr-&gt;next-&gt;var-&gt;super_array, var_list_ptr-&gt;var-&gt;super_array, 1024)) var_list_ptr = var_list_ptr-&gt;next;
+            }
+            var_list_ptr = var_list_ptr-&gt;next;
          }
+         break;
       }
-      else
-         var_ptr = var_ptr-&gt;next;
+      group_ptr = group_ptr-&gt;next;
    }
 
    fclose(fd);
 
 
    /*
-    *  Generate declarations of time-invariant fields
+    *  Generate declarations of non-mesh groups
     */
-   fd = fopen(&quot;time_varying_fields.inc&quot;, &quot;w&quot;);
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 1) {
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            memcpy(super_array, var_ptr-&gt;super_array, 1024);
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
+   fd = fopen(&quot;variable_groups.inc&quot;, &quot;w&quot;);
+
+   group_ptr = groups;
+   while (group_ptr) {
+      if (strncmp(group_ptr-&gt;name, &quot;mesh&quot;, 1024)) {
+         fortprintf(fd, &quot;   type %s_type</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+
+         var_list_ptr = group_ptr-&gt;vlist;
+         memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+         i = 1;
+         while (var_list_ptr) {
+            if (strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) != 0) {
+               memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+               i = 1;
+             }
+            if (strncmp(var_list_ptr-&gt;var-&gt;array_class, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: index_%s = %i</font>
<font color="blue">&quot;, var_list_ptr-&gt;var-&gt;name_in_code, i++);
+            var_list_ptr = var_list_ptr-&gt;next;
+         }
+
+         var_list_ptr = group_ptr-&gt;vlist;
+         sprintf(super_array, &quot;-&quot;);
+         sprintf(array_class, &quot;-&quot;);
+         class_start = 1;
+         class_end = 1;
+         i = 1;
+
+         while (var_list_ptr) {
+
+            /* Is the current variable in a super array? */
+            if (strncmp(var_list_ptr-&gt;var-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+
+               /* Have we hit the beginning of a new super array? */
+               if (strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) != 0) {
+                  /* Finish off the previous super array? */
+                  if (strncmp(super_array, &quot;-&quot;, 1024) != 0) {
+                     fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+                     fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="blue">&quot;, super_array, i);
+                  }
+                  class_start = 1;
+                  class_end = 1;
+                  i = 1;
+                  memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
+                  memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
+                  fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="blue">&quot;, array_class, class_start);
+               }
+               /* Or have we hit the beginning of a new array class? */
+               else if (strncmp(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024) != 0) {
+                  fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+                  class_start = class_end+1;
+                  class_end = class_start;
+                  memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
+                  fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="red">&quot;, array_class, class_start);
+                  i++;
+               }
+               else {
+                  class_end++;
+                  i++;
+               }
+
             }
-            if (vtype == INTEGER)  fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="red">&quot;, (var_ptr2-&gt;ndims)+1, var_ptr2-&gt;super_array);
-            if (vtype == REAL)     fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="red">&quot;, (var_ptr2-&gt;ndims)+1, var_ptr2-&gt;super_array);
+            var_list_ptr = var_list_ptr-&gt;next;
+
          }
-         else {
-            if (var_ptr-&gt;vtype == INTEGER)  fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="red">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-            if (var_ptr-&gt;vtype == REAL)     fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="red">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-            var_ptr = var_ptr-&gt;next;
+         if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+         if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="blue">&quot;, super_array, i);
+
+         var_list_ptr = group_ptr-&gt;vlist;
+         while (var_list_ptr) {
+            var_ptr = var_list_ptr-&gt;var;
+            if (!strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024)) {
+              if (var_ptr-&gt;vtype == INTEGER) fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
+              if (var_ptr-&gt;vtype == REAL)    fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
+            }
+            else {
+              if (var_ptr-&gt;vtype == INTEGER) fortprintf(fd, &quot;      type (field%idInteger), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims+1, var_ptr-&gt;super_array);
+              if (var_ptr-&gt;vtype == REAL)    fortprintf(fd, &quot;      type (field%idReal), pointer :: %s</font>
<font color="blue">&quot;, var_ptr-&gt;ndims+1, var_ptr-&gt;super_array);
+              while (var_list_ptr-&gt;next &amp;&amp; !strncmp(var_list_ptr-&gt;next-&gt;var-&gt;super_array, var_list_ptr-&gt;var-&gt;super_array, 1024)) var_list_ptr = var_list_ptr-&gt;next;
+            }
+            var_list_ptr = var_list_ptr-&gt;next;
          }
+   
+         fortprintf(fd, &quot;   end type %s_type</font>
<font color="black"></font>
<font color="black"></font>
<font color="blue">&quot;, group_ptr-&gt;name);
+   
+         if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1) {
+            fortprintf(fd, &quot;   type %s_pointer_type</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+            fortprintf(fd, &quot;      type (%s_type), pointer :: %s </font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+            fortprintf(fd, &quot;   end type %s_pointer_type</font>
<font color="black"></font>
<font color="black"></font>
<font color="blue">&quot;, group_ptr-&gt;name);
+   
+            fortprintf(fd, &quot;   type %s_multilevel_type</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+            fortprintf(fd, &quot;      integer :: nTimeLevels</font>
<font color="blue">&quot;);
+            fortprintf(fd, &quot;      type (%s_pointer_type), dimension(:), pointer :: time_levs</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+            fortprintf(fd, &quot;   end type %s_multilevel_type</font>
<font color="black"></font>
<font color="black"></font>
<font color="red">&quot;, group_ptr-&gt;name);
+         }
+   
       }
-      else
-         var_ptr = var_ptr-&gt;next;
+      group_ptr = group_ptr-&gt;next;
    }
 
    fclose(fd);
 
-
    /*
-    *  Generate grid metadata allocations
+    *  Generate instantiations of variable groups in block_type
     */
-   fd = fopen(&quot;grid_meta_allocs.inc&quot;, &quot;w&quot;);
+   fd = fopen(&quot;block_group_members.inc&quot;, &quot;w&quot;);
 
-   dim_ptr = dims;
-   while (dim_ptr) {
-      if (dim_ptr-&gt;constant_value &lt; 0 &amp;&amp; !dim_ptr-&gt;namelist_defined &amp;&amp; !is_derived_dim(dim_ptr-&gt;name_in_code)) fortprintf(fd, &quot;      g %% %s = %s</font>
<font color="red">&quot;, dim_ptr-&gt;name_in_code, dim_ptr-&gt;name_in_code);
-      if (dim_ptr-&gt;constant_value &lt; 0 &amp;&amp; dim_ptr-&gt;namelist_defined &amp;&amp; !is_derived_dim(dim_ptr-&gt;name_in_code)) fortprintf(fd, &quot;      g %% %s = %s</font>
<font color="red">&quot;, dim_ptr-&gt;name_in_file, dim_ptr-&gt;name_in_file);
-      dim_ptr = dim_ptr-&gt;next;
+   group_ptr = groups;
+   while (group_ptr) {
+      if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1)
+         fortprintf(fd, &quot;      type (%s_multilevel_type), pointer :: %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      else
+         fortprintf(fd, &quot;      type (%s_type), pointer :: %s</font>
<font color="red">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      group_ptr = group_ptr-&gt;next;
    }
-   fortprintf(fd, &quot;</font>
<font color="red">&quot;);
 
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 0) {
+   fclose(fd);
+
+
+   /* To be included in allocate_block */
+   fd = fopen(&quot;block_allocs.inc&quot;, &quot;w&quot;);
+   group_ptr = groups;
+   while (group_ptr) {
+      fortprintf(fd, &quot;      allocate(b %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1) {
+         fortprintf(fd, &quot;      b %% %s %% nTimeLevels = %i</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs);
+         fortprintf(fd, &quot;      allocate(b %% %s %% time_levs(%i))</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs);
+         fortprintf(fd, &quot;      do i=1,b %% %s %% nTimeLevels</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+         fortprintf(fd, &quot;         allocate(b %% %s %% time_levs(i) %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;         call allocate_%s(b %% %s %% time_levs(i) %% %s, &amp;</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;#include \&quot;dim_dummy_args.inc\&quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;                         )</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      end do</font>
<font color="black"></font>
<font color="blue">&quot;);
+      }
+      else {
+         fortprintf(fd, &quot;      call allocate_%s(b %% %s, &amp;</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;#include \&quot;dim_dummy_args.inc\&quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;                      )</font>
<font color="black"></font>
<font color="blue">&quot;);
+      }
+      group_ptr = group_ptr-&gt;next;
+   }
+   fclose(fd);
+
+   
+   /* To be included in deallocate_block */
+   fd = fopen(&quot;block_deallocs.inc&quot;, &quot;w&quot;);
+   group_ptr = groups;
+   while (group_ptr) {
+      if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1) {
+         fortprintf(fd, &quot;      do i=1,b %% %s %% nTimeLevels</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+         fortprintf(fd, &quot;         call deallocate_%s(b %% %s %% time_levs(i) %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;         deallocate(b %% %s %% time_levs(i) %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;      end do</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      deallocate(b %% %s %% time_levs)</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      }
+      else {
+         fortprintf(fd, &quot;      call deallocate_%s(b %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      }
+      fortprintf(fd, &quot;      deallocate(b %% %s)</font>
<font color="black"></font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      group_ptr = group_ptr-&gt;next;
+   }
+   fclose(fd);
+
+   /* Definitions of allocate subroutines */
+   fd = fopen(&quot;group_alloc_routines.inc&quot;, &quot;w&quot;);
+   group_ptr = groups;
+   while (group_ptr) {
+      fortprintf(fd, &quot;   subroutine allocate_%s(%s, &amp;</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      fortprintf(fd, &quot;#include \&quot;dim_dummy_args.inc\&quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;                         )</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      implicit none</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      type (%s_type), intent(inout) :: %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      fortprintf(fd, &quot;#include \&quot;dim_dummy_decls.inc\&quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+
+      if (!strncmp(group_ptr-&gt;name, &quot;mesh&quot;, 1024)) {
+         dim_ptr = dims;
+         while (dim_ptr) {
+            if (dim_ptr-&gt;constant_value &lt; 0 &amp;&amp; !dim_ptr-&gt;namelist_defined &amp;&amp; !is_derived_dim(dim_ptr-&gt;name_in_code)) fortprintf(fd, &quot;      %s %% %s = %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, dim_ptr-&gt;name_in_code, dim_ptr-&gt;name_in_code);
+            if (dim_ptr-&gt;constant_value &lt; 0 &amp;&amp; dim_ptr-&gt;namelist_defined &amp;&amp; !is_derived_dim(dim_ptr-&gt;name_in_code)) fortprintf(fd, &quot;      %s %% %s = %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, dim_ptr-&gt;name_in_file, dim_ptr-&gt;name_in_file);
+            dim_ptr = dim_ptr-&gt;next;
+         }
+         fortprintf(fd, &quot;</font>
<font color="red">&quot;);
+      }
+
+
+      var_list_ptr = group_ptr-&gt;vlist;
+      while (var_list_ptr) {
+         var_ptr = var_list_ptr-&gt;var;
          if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
             memcpy(super_array, var_ptr-&gt;super_array, 1024);
             memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
             i = 0;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
+            while (var_list_ptr &amp;&amp; strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) == 0) {
                i++;
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
+               var_list_ptr2 = var_list_ptr;
+               var_list_ptr = var_list_ptr-&gt;next;
             }
-            fortprintf(fd, &quot;      allocate(g %% %s)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      allocate(g %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      allocate(g %% %s %% array(%i, &quot;, var_ptr2-&gt;super_array, i);
+            var_ptr2 = var_list_ptr2-&gt;var;
+            fortprintf(fd, &quot;      allocate(%s %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
+            fortprintf(fd, &quot;      allocate(%s %% %s %% ioinfo)</font>
<font color="gray">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
+            fortprintf(fd, &quot;      allocate(%s %% %s %% array(%i, &quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array, i);
             dimlist_ptr = var_ptr2-&gt;dimlist;
             if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
                 !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
                 !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-               fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
             else
                if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
@@ -414,41 +559,43 @@
                if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
                    !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
                    !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-                  fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
                   if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
                dimlist_ptr = dimlist_ptr-&gt;next;
             }
             fortprintf(fd, &quot;))</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;      g %% %s %% array = 0</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array ); /* initialize field to zero */
+            fortprintf(fd, &quot;      %s %% %s %% array = 0</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array ); /* initialize field to zero */
 
             if (var_ptr2-&gt;iostreams &amp; INPUT0) 
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% input = .true.</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% input = .true.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
             else
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% input = .false.</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% input = .false.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
 
             if (var_ptr2-&gt;iostreams &amp; RESTART0) 
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% restart = .true.</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% restart = .true.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
             else
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% restart = .false.</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% restart = .false.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
 
             if (var_ptr2-&gt;iostreams &amp; OUTPUT0) 
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% output = .true.</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% output = .true.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
             else
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% output = .false.</font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% output = .false.</font>
<font color="black">&quot;, group_ptr-&gt;name, var_ptr2-&gt;super_array);
             fortprintf(fd, &quot;</font>
<font color="red">&quot;);
          }
          else {
-            fortprintf(fd, &quot;      allocate(g %% %s)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      allocate(g %% %s %% ioinfo)</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+            fortprintf(fd, &quot;      allocate(%s %% %s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
+            fortprintf(fd, &quot;      allocate(%s %% %s %% ioinfo)</font>
<font color="gray">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             if (var_ptr-&gt;ndims &gt; 0) {
-               fortprintf(fd, &quot;      allocate(g %% %s %% array(&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      allocate(%s %% %s %% array(&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
                dimlist_ptr = var_ptr-&gt;dimlist;
                if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
                    !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
                    !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-                  fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
                   if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
@@ -457,313 +604,112 @@
                   if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
                       !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
                       !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-                     fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else
                      if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                      else fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
                   dimlist_ptr = dimlist_ptr-&gt;next;
                }
                fortprintf(fd, &quot;))</font>
<font color="red">&quot;);
-               fortprintf(fd, &quot;      g %% %s %% array = 0</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code ); /* initialize field to zero */
+               fortprintf(fd, &quot;      %s %% %s %% array = 0</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code ); /* initialize field to zero */
 
             }
             if (var_ptr-&gt;iostreams &amp; INPUT0) 
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% input = .true.</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% input = .true.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             else
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% input = .false.</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% input = .false.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
 
             if (var_ptr-&gt;iostreams &amp; RESTART0) 
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% restart = .true.</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% restart = .true.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             else
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% restart = .false.</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% restart = .false.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
 
             if (var_ptr-&gt;iostreams &amp; OUTPUT0) 
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% output = .true.</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% output = .true.</font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             else
-               fortprintf(fd, &quot;      g %% %s %% ioinfo %% output = .false.</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      %s %% %s %% ioinfo %% output = .false.</font>
<font color="black">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             fortprintf(fd, &quot;</font>
<font color="red">&quot;);
 
-            var_ptr = var_ptr-&gt;next;
+            var_list_ptr = var_list_ptr-&gt;next;
          }
       }
-      else
-         var_ptr = var_ptr-&gt;next;
-   }
 
+      fortprintf(fd, &quot;   end subroutine allocate_%s</font>
<font color="black"></font>
<font color="black"></font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      group_ptr = group_ptr-&gt;next;
+   }
    fclose(fd);
+   
+   /* Definitions of deallocate subroutines */
+   fd = fopen(&quot;group_dealloc_routines.inc&quot;, &quot;w&quot;);
+   group_ptr = groups;
+   while (group_ptr) {
+      fortprintf(fd, &quot;   subroutine deallocate_%s(%s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      implicit none</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      type (%s_type), intent(inout) :: %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+      fortprintf(fd, &quot;</font>
<font color="red">&quot;);
 
-
-   /*
-    *  Generate grid metadata deallocations
-    */
-   fd = fopen(&quot;grid_meta_deallocs.inc&quot;, &quot;w&quot;);
-
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 0) {
+      var_list_ptr = group_ptr-&gt;vlist;
+      while (var_list_ptr) {
+         var_ptr = var_list_ptr-&gt;var;
          if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
             memcpy(super_array, var_ptr-&gt;super_array, 1024);
             memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
             i = 0;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
+            while (var_list_ptr &amp;&amp; strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) == 0) {
                i++;
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
+               var_list_ptr2 = var_list_ptr;
+               var_list_ptr = var_list_ptr-&gt;next;
             }
-            fortprintf(fd, &quot;      deallocate(g %% %s %% array)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      deallocate(g %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      deallocate(g %% %s)</font>
<font color="black"></font>
<font color="blue">&quot;, var_ptr2-&gt;super_array);
+            fortprintf(fd, &quot;      deallocate(%s %% %s %% array)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_list_ptr2-&gt;var-&gt;super_array);
+            fortprintf(fd, &quot;      deallocate(%s %% %s %% ioinfo)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_list_ptr2-&gt;var-&gt;super_array);
+            fortprintf(fd, &quot;      deallocate(%s %% %s)</font>
<font color="black"></font>
<font color="red">&quot;, group_ptr-&gt;name, var_list_ptr2-&gt;var-&gt;super_array);
          }
          else {
             if (var_ptr-&gt;ndims &gt; 0) {
-               fortprintf(fd, &quot;      deallocate(g %% %s %% array)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-               fortprintf(fd, &quot;      deallocate(g %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-               fortprintf(fd, &quot;      deallocate(g %% %s)</font>
<font color="black"></font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      deallocate(%s %% %s %% array)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      deallocate(%s %% %s %% ioinfo)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      deallocate(%s %% %s)</font>
<font color="black"></font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             }
             else {
-               fortprintf(fd, &quot;      deallocate(g %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-               fortprintf(fd, &quot;      deallocate(g %% %s)</font>
<font color="black"></font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      deallocate(%s %% %s %% ioinfo)</font>
<font color="blue">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
+               fortprintf(fd, &quot;      deallocate(%s %% %s)</font>
<font color="black"></font>
<font color="red">&quot;, group_ptr-&gt;name, var_ptr-&gt;name_in_code);
             }
-            var_ptr = var_ptr-&gt;next;
+            var_list_ptr = var_list_ptr-&gt;next;
          }
       }
-      else
-         var_ptr = var_ptr-&gt;next;
-   }
 
-   fclose(fd);
-
-
-   /*
-    *  Generate grid state allocations
-    */
-   fd = fopen(&quot;grid_state_allocs.inc&quot;, &quot;w&quot;);
-
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 1 &amp;&amp; var_ptr-&gt;ndims &gt; 0) {
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            memcpy(super_array, var_ptr-&gt;super_array, 1024);
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
-            i = 0;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
-               i++;
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
-            }
-            fortprintf(fd, &quot;      allocate(s %% %s)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      allocate(s %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      allocate(s %% %s %% array(%i, &quot;, var_ptr2-&gt;super_array, i);
-            dimlist_ptr = var_ptr2-&gt;dimlist;
-            if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
-                !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
-                !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-               fortprintf(fd, &quot;b %% mesh %% %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-            else
-               if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-               else fortprintf(fd, &quot;b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-            dimlist_ptr = dimlist_ptr-&gt;next;
-            while (dimlist_ptr) {
-               if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
-                   !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
-                   !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-                  fortprintf(fd, &quot;, b %% mesh %% %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               else
-                  if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-                  else fortprintf(fd, &quot;, b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               dimlist_ptr = dimlist_ptr-&gt;next;
-            }
-            fortprintf(fd, &quot;))</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;      s %% %s %% block =&gt; b</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-   
-            if (var_ptr2-&gt;iostreams &amp; INPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .true.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .false.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-   
-            if (var_ptr2-&gt;iostreams &amp; RESTART0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .true.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .false.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-   
-            if (var_ptr2-&gt;iostreams &amp; OUTPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .true.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .false.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;</font>
<font color="red">&quot;);
-         }
-         else {
-            fortprintf(fd, &quot;      allocate(s %% %s)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      allocate(s %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      allocate(s %% %s %% array(&quot;, var_ptr-&gt;name_in_code);
-            dimlist_ptr = var_ptr-&gt;dimlist;
-            if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0) {
-               if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
-                   !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
-                   !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-                  fortprintf(fd, &quot;b %% mesh %% %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               else
-                  if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-                  else fortprintf(fd, &quot;b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-            }
-            else {
-               fortprintf(fd, &quot;%i&quot;, dimlist_ptr-&gt;dim-&gt;constant_value);
-            }
-            dimlist_ptr = dimlist_ptr-&gt;next;
-            while (dimlist_ptr) {
-               if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0) {
-                  if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
-                      !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
-                      !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
-                     fortprintf(fd, &quot;, b %% mesh %% %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else
-                     if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-                     else fortprintf(fd, &quot;, b %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               }
-               else {
-                  fortprintf(fd, &quot;, %i&quot;, dimlist_ptr-&gt;dim-&gt;constant_value);
-               }
-               dimlist_ptr = dimlist_ptr-&gt;next;
-            }
-            fortprintf(fd, &quot;))</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;      s %% %s %% block =&gt; b</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-   
-            if (var_ptr-&gt;iostreams &amp; INPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .true.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .false.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-   
-            if (var_ptr-&gt;iostreams &amp; RESTART0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .true.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .false.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-   
-            if (var_ptr-&gt;iostreams &amp; OUTPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .true.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .false.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;</font>
<font color="red">&quot;);
-            var_ptr = var_ptr-&gt;next;
-         }
-      }
-      else if (var_ptr-&gt;timedim == 1) {
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            memcpy(super_array, var_ptr-&gt;super_array, 1024);
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
-            i = 0;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
-               i++;
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
-            }
-            fortprintf(fd, &quot;      allocate(s %% %s)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      allocate(s %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      allocate(s %% %s %% array(%i)&quot;, var_ptr-&gt;name_in_code, i);
-            fortprintf(fd, &quot;      s %% %s %% block =&gt; b</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-   
-            if (var_ptr2-&gt;iostreams &amp; INPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .true.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .false.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-   
-            if (var_ptr2-&gt;iostreams &amp; RESTART0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .true.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .false.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-   
-            if (var_ptr2-&gt;iostreams &amp; OUTPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .true.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .false.</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;</font>
<font color="red">&quot;);
-         }
-         else {
-            fortprintf(fd, &quot;      allocate(s %% %s)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      allocate(s %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      s %% %s %% block =&gt; b</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-   
-            if (var_ptr-&gt;iostreams &amp; INPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .true.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% input = .false.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-   
-            if (var_ptr-&gt;iostreams &amp; RESTART0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .true.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% restart = .false.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-   
-            if (var_ptr-&gt;iostreams &amp; OUTPUT0) 
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .true.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;      s %% %s %% ioinfo %% output = .false.</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;</font>
<font color="red">&quot;);
-            var_ptr = var_ptr-&gt;next;
-         }
-      } 
-      else
-         var_ptr = var_ptr-&gt;next;
+      fortprintf(fd, &quot;   end subroutine deallocate_%s</font>
<font color="black"></font>
<font color="black"></font>
<font color="red">&quot;, group_ptr-&gt;name);
+      group_ptr = group_ptr-&gt;next;
    }
-
    fclose(fd);
 
-
-   /*
-    *  Generate grid state deallocations
-    */
-   fd = fopen(&quot;grid_state_deallocs.inc&quot;, &quot;w&quot;);
-
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 1) {
+   /* Definitions of copy subroutines */
+   fd = fopen(&quot;group_copy_routines.inc&quot;, &quot;w&quot;);
+   group_ptr = groups;
+   while (group_ptr) {
+      fortprintf(fd, &quot;   subroutine copy_%s(dest, src)</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      implicit none</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      type (%s_type), intent(in) :: src</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      fortprintf(fd, &quot;      type (%s_type), intent(inout) :: dest</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      fortprintf(fd, &quot;</font>
<font color="red">&quot;);
+      var_list_ptr = group_ptr-&gt;vlist;
+      while (var_list_ptr) {
+         var_ptr = var_list_ptr-&gt;var;
          if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
             memcpy(super_array, var_ptr-&gt;super_array, 1024);
             memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
             i = 0;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
+            while (var_list_ptr &amp;&amp; strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) == 0) {
                i++;
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
+               var_list_ptr2 = var_list_ptr;
+               var_list_ptr = var_list_ptr-&gt;next;
             }
-            fortprintf(fd, &quot;      deallocate(s %% %s %% array)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      deallocate(s %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-            fortprintf(fd, &quot;      deallocate(s %% %s)</font>
<font color="black"></font>
<font color="red">&quot;, var_ptr2-&gt;super_array);
-         }
-         else {
-            if (var_ptr-&gt;ndims &gt; 0) fortprintf(fd, &quot;      deallocate(s %% %s %% array)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      deallocate(s %% %s %% ioinfo)</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;      deallocate(s %% %s)</font>
<font color="black"></font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            var_ptr = var_ptr-&gt;next;
-         }
-      }
-      else
-         var_ptr = var_ptr-&gt;next;
-   }
-
-   fclose(fd);
-
-
-   /*
-    *  Generate copies of state arrays
-    */
-   fd = fopen(&quot;copy_state.inc&quot;, &quot;w&quot;);
-
-   var_ptr = vars;
-   while (var_ptr) {
-      if (var_ptr-&gt;timedim == 1) {
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            memcpy(super_array, var_ptr-&gt;super_array, 1024);
-            memcpy(array_class, var_ptr-&gt;array_class, 1024);
-            vtype = var_ptr-&gt;vtype;
-            i = 0;
-            while (var_ptr &amp;&amp; strncmp(super_array, var_ptr-&gt;super_array, 1024) == 0) {
-               i++;
-               var_ptr2 = var_ptr;
-               var_ptr = var_ptr-&gt;next;
-            }
+            var_ptr2 = var_list_ptr2-&gt;var;
             if (var_ptr2-&gt;ndims &gt; 0) 
                fortprintf(fd, &quot;      dest %% %s %% array = src %% %s %% array</font>
<font color="gray">&quot;, var_ptr2-&gt;super_array, var_ptr2-&gt;super_array);
             else
@@ -774,30 +720,59 @@
                fortprintf(fd, &quot;      dest %% %s %% array = src %% %s %% array</font>
<font color="black">&quot;, var_ptr-&gt;name_in_code, var_ptr-&gt;name_in_code);
             else
                fortprintf(fd, &quot;      dest %% %s %% scalar = src %% %s %% scalar</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code, var_ptr-&gt;name_in_code);
-            var_ptr = var_ptr-&gt;next;
+            var_list_ptr = var_list_ptr-&gt;next;
          }
       }
-      else
-         var_ptr = var_ptr-&gt;next;
+      fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;   end subroutine copy_%s</font>
<font color="black"></font>
<font color="black"></font>
<font color="blue">&quot;, group_ptr-&gt;name);
+      group_ptr = group_ptr-&gt;next;
    }
+   fclose(fd);
 
+   /* Definitions of shift_time_level subroutines */
+   fd = fopen(&quot;group_shift_level_routines.inc&quot;, &quot;w&quot;);
+   group_ptr = groups;
+   while (group_ptr) {
+      if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1) {
+         fortprintf(fd, &quot;   subroutine shift_time_levels_%s(%s)</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      implicit none</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      type (%s_multilevel_type), intent(inout) :: %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      integer :: i</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      type (%s_type), pointer :: sptr</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+         fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      sptr =&gt; %s %% time_levs(1) %% %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;      do i=1,%s %% nTimeLevels-1</font>
<font color="blue">&quot;, group_ptr-&gt;name);
+         fortprintf(fd, &quot;         %s %% time_levs(i) %% %s =&gt; %s %% time_levs(i+1) %% %s</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;      end do</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;      %s %% time_levs(%s %% nTimeLevels) %% %s =&gt; sptr</font>
<font color="blue">&quot;, group_ptr-&gt;name, group_ptr-&gt;name, group_ptr-&gt;name);
+         fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;   end subroutine shift_time_levels_%s</font>
<font color="black"></font>
<font color="black"></font>
<font color="gray">&quot;, group_ptr-&gt;name);
+      }
+      group_ptr = group_ptr-&gt;next;
+   }
    fclose(fd);

 }
 
 
-void gen_reads(struct variable * vars, struct dimension * dims)
+void gen_reads(struct group_list * groups, struct variable * vars, struct dimension * dims)
 {
    struct variable * var_ptr;
+   struct variable_list * var_list_ptr;
    struct dimension * dim_ptr;
    struct dimension_list * dimlist_ptr, * lastdim;
+   struct group_list * group_ptr;
    struct dtable * dictionary;
    FILE * fd;
    char vtype[5];
    char fname[32];
+   char struct_deref[1024];
    char * cp1, * cp2;
    int i, j;
    int ivtype;
-   int has_vert_dim, vert_dim;
 
 
    /*
@@ -835,124 +810,64 @@
     */
    fd = fopen(&quot;io_input_fields.inc&quot;, &quot;w&quot;);
 
-   var_ptr = vars;
-   while (var_ptr) {
-      i = 1;
-      dimlist_ptr = var_ptr-&gt;dimlist;
-      if (var_ptr-&gt;vtype == INTEGER) sprintf(vtype, &quot;int&quot;); 
-      else if (var_ptr-&gt;vtype == REAL) sprintf(vtype, &quot;real&quot;); 
+   group_ptr = groups;
+   while (group_ptr) {
+      var_list_ptr = group_ptr-&gt;vlist;
+      while (var_list_ptr) {
+         var_ptr = var_list_ptr-&gt;var;
 
-      if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-         if (var_ptr-&gt;timedim) {
-            fortprintf(fd, &quot;      if ((block %% time_levs(1) %% state %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-            fortprintf(fd, &quot;          (block %% time_levs(1) %% state %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-         }
-         else {
-            fortprintf(fd, &quot;      if ((block %% mesh %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-            fortprintf(fd, &quot;          (block %% mesh %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-         }
-      }
-      else {
-         if (var_ptr-&gt;timedim) {
-            fortprintf(fd, &quot;      if ((block %% time_levs(1) %% state %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;          (block %% time_levs(1) %% state %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-         }
-         else {
-            fortprintf(fd, &quot;      if ((block %% mesh %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;          (block %% mesh %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-         }
-      }
-      vert_dim = 0;
-      while (dimlist_ptr) {
-            if (i &lt; var_ptr-&gt;ndims) {
-               has_vert_dim = !strcmp( &quot;nVertLevels&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i);
-               if (has_vert_dim) {
-                  vert_dim = i;
-                  fortprintf(fd, &quot;#ifdef EXPAND_LEVELS</font>
<font color="red">&quot;);
-                  fortprintf(fd, &quot;      if (.not. config_do_restart) then</font>
<font color="red">&quot;);
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = 1</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i);
-                  fortprintf(fd, &quot;      else</font>
<font color="red">&quot;);
-                  fortprintf(fd, &quot;#endif</font>
<font color="red">&quot;);
-               }
-               if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = block %% mesh %% %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = block %% mesh %% %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
-               else
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               if (has_vert_dim) {
-                  fortprintf(fd, &quot;#ifdef EXPAND_LEVELS</font>
<font color="red">&quot;);
-                  fortprintf(fd, &quot;      end if</font>
<font color="red">&quot;);
-                  fortprintf(fd, &quot;#endif</font>
<font color="red">&quot;);
-               }
-            }
-            else {
-               if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
-                  split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, cp1);
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount%s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, cp1, cp2);
-                  free(cp1);
-                  free(cp2);
-               }
-               else {
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
-               }
-            }
-         dimlist_ptr = dimlist_ptr-&gt;next;
-         i++;
-      }
+         if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1)
+            snprintf(struct_deref, 1024, &quot;block %% %s %% time_levs(1) %% %s&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         else
+            snprintf(struct_deref, 1024, &quot;block %% %s&quot;, group_ptr-&gt;name);
 
-      if (var_ptr-&gt;ndims &gt; 0) {
-         fortprintf(fd, &quot;      allocate(%s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
          i = 1;
          dimlist_ptr = var_ptr-&gt;dimlist;
+         if (var_ptr-&gt;vtype == INTEGER) sprintf(vtype, &quot;int&quot;); 
+         else if (var_ptr-&gt;vtype == REAL) sprintf(vtype, &quot;real&quot;); 
    
-         if (i &lt; var_ptr-&gt;ndims) {
-            if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               else fortprintf(fd, &quot;block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-            else
-               fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+            fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;super_array);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, struct_deref, var_ptr-&gt;super_array);
          }
          else {
-            if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
-               split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-               fortprintf(fd, &quot;read%sCount%s&quot;, cp1, cp2);
-               free(cp1);
-               free(cp2);
-            }
-            else
-               fortprintf(fd, &quot;read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+            fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;name_in_code);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, struct_deref, var_ptr-&gt;name_in_code);
          }
-    
-         dimlist_ptr = dimlist_ptr-&gt;next;
-         i++;
          while (dimlist_ptr) {
-            if (i &lt; var_ptr-&gt;ndims) {
-               if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-               else
-                  fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-            }
-            else {
-               if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
-                  split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-                  fortprintf(fd, &quot;, read%sCount%s&quot;, cp1, cp2);
-                  free(cp1);
-                  free(cp2);
+               if (i &lt; var_ptr-&gt;ndims) {
+                  fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i);
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = block %% mesh %% %s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = block %% mesh %% %s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
                }
-               else
-                  fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
-            }
+               else {
+                  if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
+                     split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+                     fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, cp1);
+                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount%s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, cp1, cp2);
+                     free(cp1);
+                     free(cp2);
+                  }
+                  else {
+                     if (dimlist_ptr-&gt;dim-&gt;namelist_defined) {
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+                     }
+                     else {
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     }
+                  }
+               }
             dimlist_ptr = dimlist_ptr-&gt;next;
             i++;
          }
-         fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="gray">&quot;);
-
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            fortprintf(fd, &quot;      allocate(super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
+   
+         if (var_ptr-&gt;ndims &gt; 0) {
+            fortprintf(fd, &quot;      allocate(%s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
             i = 1;
             dimlist_ptr = var_ptr-&gt;dimlist;
       
@@ -963,166 +878,193 @@
                else
                   fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
             }
+            else {
+               if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
+                  split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+                  fortprintf(fd, &quot;read%sCount%s&quot;, cp1, cp2);
+                  free(cp1);
+                  free(cp2);
+               }
+               else
+                  if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+                  else fortprintf(fd, &quot;read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+            }
+       
             dimlist_ptr = dimlist_ptr-&gt;next;
             i++;
             while (dimlist_ptr) {
-               if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-               else
-                  fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               if (i &lt; var_ptr-&gt;ndims) {
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               }
+               else {
+                  if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
+                     split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+                     fortprintf(fd, &quot;, read%sCount%s&quot;, cp1, cp2);
+                     free(cp1);
+                     free(cp2);
+                  }
+                  else
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     else fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+               }
                dimlist_ptr = dimlist_ptr-&gt;next;
                i++;
             }
             fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="red">&quot;);
-         }
-      }
-
-      fortprintf(fd, &quot;      %s%id %% ioinfo %% fieldName = \'%s\'</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_file);
-      if (var_ptr-&gt;timedim)
-         fortprintf(fd, &quot;      call io_input_field_time(input_obj, %s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-      else
-         fortprintf(fd, &quot;      call io_input_field(input_obj, %s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-
-      if (vert_dim &gt; 0) {
-         fortprintf(fd, &quot;#ifdef EXPAND_LEVELS</font>
<font color="red">&quot;);
-         fortprintf(fd, &quot;      if (.not. config_do_restart) then</font>
<font color="red">&quot;);
-         fortprintf(fd, &quot;         do k=2,EXPAND_LEVELS</font>
<font color="red">&quot;);
-         fortprintf(fd, &quot;            %s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
-         for (i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-            if (i &gt; 1) fortprintf(fd, &quot;,&quot;);
-            fortprintf(fd, &quot;%s&quot;, i == vert_dim ? &quot;k&quot; : &quot;:&quot;);
-         }
-         fortprintf(fd, &quot;) = %s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
-         for (i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-            if (i &gt; 1) fortprintf(fd, &quot;,&quot;);
-            fortprintf(fd, &quot;%s&quot;, i == vert_dim ? &quot;1&quot; : &quot;:&quot;);
-         }
-         fortprintf(fd, &quot;)</font>
<font color="red">&quot;);
-         fortprintf(fd, &quot;         end do</font>
<font color="red">&quot;);
-         fortprintf(fd, &quot;      end if</font>
<font color="red">&quot;);
-         fortprintf(fd, &quot;#endif</font>
<font color="red">&quot;);
-      }
-
-      if (var_ptr-&gt;ndims &gt; 0) {
-         fortprintf(fd, &quot;      call dmpar_alltoall_field(dminfo, &amp;</font>
<font color="red">&quot;);
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            if (var_ptr-&gt;timedim) 
-               fortprintf(fd, &quot;                                %s%id %% array, super_%s%id, &amp;</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, vtype, var_ptr-&gt;ndims);
-            else
-               fortprintf(fd, &quot;                                %s%id %% array, super_%s%id, &amp;</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, vtype, var_ptr-&gt;ndims);
-         }
-         else {
-            if (var_ptr-&gt;timedim) 
-               fortprintf(fd, &quot;                                %s%id %% array, block %% time_levs(1) %% state %% %s %% array, &amp;</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-            else
-               fortprintf(fd, &quot;                                %s%id %% array, block %% mesh %% %s %% array, &amp;</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-         }
    
-         i = 1;
-         dimlist_ptr = var_ptr-&gt;dimlist;
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+               fortprintf(fd, &quot;      allocate(super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
+               i = 1;
+               dimlist_ptr = var_ptr-&gt;dimlist;
          
-         if (i &lt; var_ptr-&gt;ndims)
-            if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;                                block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               else fortprintf(fd, &quot;                                block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-            else
-               fortprintf(fd, &quot;                                %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-         else {
-            lastdim = dimlist_ptr;
-            if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
-               split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-               fortprintf(fd, &quot;                                read%sCount%s&quot;, cp1, cp2);
-               free(cp1);
-               free(cp2);
+               if (i &lt; var_ptr-&gt;ndims) {
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+               }
+               dimlist_ptr = dimlist_ptr-&gt;next;
+               i++;
+               while (dimlist_ptr) {
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+
+                  dimlist_ptr = dimlist_ptr-&gt;next;
+                  i++;
+               }
+               fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="red">&quot;);
             }
-            else
-               fortprintf(fd, &quot;                                read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
          }
-    
-         dimlist_ptr = dimlist_ptr-&gt;next;
-         i++;
-         while (dimlist_ptr) {
+   
+         fortprintf(fd, &quot;      %s%id %% ioinfo %% fieldName = \'%s\'</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_file);
+         if (var_ptr-&gt;timedim)
+            fortprintf(fd, &quot;      call io_input_field_time(input_obj, %s%id)</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims);
+         else
+            fortprintf(fd, &quot;      call io_input_field(input_obj, %s%id)</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims);
+   
+         if (var_ptr-&gt;ndims &gt; 0) {
+            fortprintf(fd, &quot;      call dmpar_alltoall_field(dminfo, &amp;</font>
<font color="blue">&quot;);
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
+               fortprintf(fd, &quot;                                %s%id %% array, super_%s%id, &amp;</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, vtype, var_ptr-&gt;ndims);
+            else
+               fortprintf(fd, &quot;                                %s%id %% array, %s %% %s %% array, &amp;</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, struct_deref, var_ptr-&gt;name_in_code);
+      
+            i = 1;
+            dimlist_ptr = var_ptr-&gt;dimlist;
+            
             if (i &lt; var_ptr-&gt;ndims)
                if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;                                block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;                                block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
-                  fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  fortprintf(fd, &quot;                                %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
             else {
                lastdim = dimlist_ptr;
                if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
                   split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-                  fortprintf(fd, &quot;, read%sCount%s&quot;, cp1, cp2);
+                  fortprintf(fd, &quot;                                read%sCount%s&quot;, cp1, cp2);
                   free(cp1);
                   free(cp2);
                }
                else
-                  fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;                                read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                  else fortprintf(fd, &quot;                                read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
             }
+       
             dimlist_ptr = dimlist_ptr-&gt;next;
             i++;
-         }
-         fortprintf(fd, &quot;, block %% mesh %% %s, &amp;</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_code);
-   
-         if (is_derived_dim(lastdim-&gt;dim-&gt;name_in_code)) {
-            fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
-         }
-         else
-            fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
-
-
-         /* Copy from super_ array to field */
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            i = 1;
-            dimlist_ptr = var_ptr-&gt;dimlist;
-            while (i &lt;= var_ptr-&gt;ndims) {
-               if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      do i%i=1,block %% mesh %% %s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;      do i%i=1,block %% mesh %% %s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
-               else
-                  fortprintf(fd, &quot;      do i%i=1,%s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-   
-               i++;
+            while (dimlist_ptr) {
+               if (i &lt; var_ptr-&gt;ndims)
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else {
+                  lastdim = dimlist_ptr;
+                  if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
+                     split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+                     fortprintf(fd, &quot;, read%sCount%s&quot;, cp1, cp2);
+                     free(cp1);
+                     free(cp2);
+                  }
+                  else
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     else fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+               }
                dimlist_ptr = dimlist_ptr-&gt;next;
+               i++;
             }
-   
-            if (var_ptr-&gt;timedim) 
-               fortprintf(fd, &quot;         block %% time_levs(1) %% state %% %s %% array(index_%s,&quot;, var_ptr-&gt;super_array, var_ptr-&gt;name_in_code);
+            if (!lastdim-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code);
+            else fortprintf(fd, &quot;, block %% mesh %% %s, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_file);
+      
+            if (is_derived_dim(lastdim-&gt;dim-&gt;name_in_code)) 
+               fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
             else
-               fortprintf(fd, &quot;         block %% mesh %% %s %% array(index_%s,&quot;, var_ptr-&gt;super_array, var_ptr-&gt;name_in_code);
-            for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-               fortprintf(fd, &quot;i%i&quot;,i);
-               if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;,&quot;);
-            }
-            fortprintf(fd, &quot;) = super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
-            for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-               fortprintf(fd, &quot;i%i&quot;,i);
-               if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;,&quot;);
-            }
-            fortprintf(fd, &quot;)</font>
<font color="blue">&quot;);
+               if (lastdim-&gt;dim-&gt;namelist_defined) 
+                  fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
+               else
+                  fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
    
-            i = 1;
-            while (i &lt;= var_ptr-&gt;ndims) {
-               fortprintf(fd, &quot;      end do</font>
<font color="red">&quot;);
-               i++;
+   
+            /* Copy from super_ array to field */
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+               i = 1;
+               dimlist_ptr = var_ptr-&gt;dimlist;
+               while (i &lt;= var_ptr-&gt;ndims) {
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      do i%i=1,block %% mesh %% %s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;      do i%i=1,block %% mesh %% %s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     fortprintf(fd, &quot;      do i%i=1,%s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+      
+                  i++;
+                  dimlist_ptr = dimlist_ptr-&gt;next;
+               }
+      
+               fortprintf(fd, &quot;         %s %% %s %% array(%s %% index_%s,&quot;, struct_deref, var_ptr-&gt;super_array, struct_deref, var_ptr-&gt;name_in_code);
+
+               for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
+                  fortprintf(fd, &quot;i%i&quot;,i);
+                  if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;,&quot;);
+               }
+               fortprintf(fd, &quot;) = super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
+               for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
+                  fortprintf(fd, &quot;i%i&quot;,i);
+                  if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;,&quot;);
+               }
+               fortprintf(fd, &quot;)</font>
<font color="blue">&quot;);
+      
+               i = 1;
+               while (i &lt;= var_ptr-&gt;ndims) {
+                  fortprintf(fd, &quot;      end do</font>
<font color="blue">&quot;);
+                  i++;
+               }
             }
+   
+            fortprintf(fd, &quot;      deallocate(%s%id %% array)</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims);
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
+               fortprintf(fd, &quot;      deallocate(super_%s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
          }
-
-         fortprintf(fd, &quot;      deallocate(%s%id %% array)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
-            fortprintf(fd, &quot;      deallocate(super_%s%id)</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims);
+         else {
+            fortprintf(fd, &quot;      %s %% %s %% scalar = %s%id %% scalar</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;name_in_code, vtype, var_ptr-&gt;ndims);
+         }
+        
+         fortprintf(fd, &quot;      end if</font>
<font color="black"></font>
<font color="red">&quot;);
+   
+         var_list_ptr = var_list_ptr-&gt;next;
       }
-      else {
-         if (var_ptr-&gt;timedim) 
-            fortprintf(fd, &quot;      block %% time_levs(1) %% state %% %s %% scalar = %s%id %% scalar</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code, vtype, var_ptr-&gt;ndims);
-         else
-            fortprintf(fd, &quot;      block %% mesh %% %s %% scalar = %s%id %% scalar</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code, vtype, var_ptr-&gt;ndims);
-      }
-     
-      fortprintf(fd, &quot;      end if</font>
<font color="black"></font>
<font color="gray">&quot;);
-
-      var_ptr = var_ptr-&gt;next;
+      group_ptr = group_ptr-&gt;next;
    }
 
    fclose(fd);
@@ -1262,16 +1204,19 @@
 }
 
 
-void gen_writes(struct variable * vars, struct dimension * dims, struct namelist * namelists)
+void gen_writes(struct group_list * groups, struct variable * vars, struct dimension * dims, struct namelist * namelists)
 {
    struct variable * var_ptr;
+   struct variable_list * var_list_ptr;
    struct dimension * dim_ptr;
    struct dimension_list * dimlist_ptr, * lastdim;
+   struct group_list * group_ptr;
    struct dtable * dictionary;
    struct namelist * nl;
    FILE * fd;
    char vtype[5];
    char fname[32];
+   char struct_deref[1024];
    char * cp1, * cp2;
    int i, j;
    int ivtype;
@@ -1418,226 +1363,224 @@
     */
    fd = fopen(&quot;io_output_fields.inc&quot;, &quot;w&quot;);
 
-   var_ptr = vars;
-   while (var_ptr) {
-      i = 1;
-      dimlist_ptr = var_ptr-&gt;dimlist;
-      if (var_ptr-&gt;vtype == INTEGER) sprintf(vtype, &quot;int&quot;); 
-      else if (var_ptr-&gt;vtype == REAL) sprintf(vtype, &quot;real&quot;); 
+   group_ptr = groups;
+   while (group_ptr) {
+      var_list_ptr = group_ptr-&gt;vlist;
+      while (var_list_ptr) {
+         var_ptr = var_list_ptr-&gt;var;
 
-      if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-         if (var_ptr-&gt;timedim) {
-            fortprintf(fd, &quot;      if ((domain %% blocklist %% time_levs(1) %% state %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-            fortprintf(fd, &quot;          (domain %% blocklist %% time_levs(1) %% state %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART)) then</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-         }
-         else {
-            fortprintf(fd, &quot;      if ((domain %% blocklist %% mesh %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-            fortprintf(fd, &quot;          (domain %% blocklist %% mesh %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART)) then</font>
<font color="red">&quot;, var_ptr-&gt;super_array);
-         }
-      }
-      else {
-         if (var_ptr-&gt;timedim) {
-            fortprintf(fd, &quot;      if ((domain %% blocklist %% time_levs(1) %% state %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;          (domain %% blocklist %% time_levs(1) %% state %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART)) then</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-         }
-         else {
-            fortprintf(fd, &quot;      if ((domain %% blocklist %% mesh %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-            fortprintf(fd, &quot;          (domain %% blocklist %% mesh %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART)) then</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code);
-         }
-      }
-
-      if (var_ptr-&gt;ndims &gt; 0) {
-         while (dimlist_ptr) {
-               if (i &lt; var_ptr-&gt;ndims) {
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i);
-                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = domain %% blocklist %% mesh %% %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                     else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = domain %% blocklist %% mesh %% %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
-                  else
-                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               }
-               else {
-                  fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i);
-                  if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
-                     split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = n%sGlobal%s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, cp1, cp2);
-                     free(cp1);
-                     free(cp2);
-                  }
-                  else
-                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %sGlobal</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               }
-            dimlist_ptr = dimlist_ptr-&gt;next;
-            i++;
-         }
-   
-         fortprintf(fd, &quot;      allocate(%s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
+         if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1)
+            snprintf(struct_deref, 1024, &quot;domain %% blocklist %% %s %% time_levs(1) %% %s&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         else
+            snprintf(struct_deref, 1024, &quot;domain %% blocklist %% %s&quot;, group_ptr-&gt;name);
+         
          i = 1;
          dimlist_ptr = var_ptr-&gt;dimlist;
+         if (var_ptr-&gt;vtype == INTEGER) sprintf(vtype, &quot;int&quot;); 
+         else if (var_ptr-&gt;vtype == REAL) sprintf(vtype, &quot;real&quot;); 
    
-         if (i &lt; var_ptr-&gt;ndims)
-            if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               else fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-            else
-               fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+            fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;super_array);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART)) then</font>
<font color="red">&quot;, struct_deref, var_ptr-&gt;super_array);
+         }
          else {
-            if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
-               split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-               fortprintf(fd, &quot;n%sGlobal%s&quot;, cp1, cp2);
-               free(cp1);
-               free(cp2);
-            }
-            else
-               fortprintf(fd, &quot;%sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-            lastdim = dimlist_ptr;
+            fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;name_in_code);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART)) then</font>
<font color="red">&quot;, struct_deref, var_ptr-&gt;name_in_code);
          }
-         dimlist_ptr = dimlist_ptr-&gt;next;
-         i++;
-         while (dimlist_ptr) {
+   
+         if (var_ptr-&gt;ndims &gt; 0) {
+            while (dimlist_ptr) {
+                  if (i &lt; var_ptr-&gt;ndims) {
+                     fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i);
+                     if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                        if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = domain %% blocklist %% mesh %% %s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                        else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = domain %% blocklist %% mesh %% %s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                     else
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  }
+                  else {
+                     fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i);
+                     if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
+                        split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = n%sGlobal%s</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, cp1, cp2);
+                        free(cp1);
+                        free(cp2);
+                     }
+                     else
+                        if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %sGlobal</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                        else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %sGlobal</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  }
+               dimlist_ptr = dimlist_ptr-&gt;next;
+               i++;
+            }
+      
+            fortprintf(fd, &quot;      allocate(%s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
+            i = 1;
+            dimlist_ptr = var_ptr-&gt;dimlist;
+      
             if (i &lt; var_ptr-&gt;ndims)
                if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
-                  fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
             else {
                if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
                   split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-                  fortprintf(fd, &quot;, n%sGlobal%s&quot;, cp1, cp2);
+                  fortprintf(fd, &quot;n%sGlobal%s&quot;, cp1, cp2);
                   free(cp1);
                   free(cp2);
                }
                else
-                  fortprintf(fd, &quot;, %sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;%sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                lastdim = dimlist_ptr;
             }
             dimlist_ptr = dimlist_ptr-&gt;next;
             i++;
-         }
-         fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="red">&quot;);
-
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
-            if (var_ptr-&gt;ndims &gt; 0) {
-               fortprintf(fd, &quot;      allocate(super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
+            while (dimlist_ptr) {
+               if (i &lt; var_ptr-&gt;ndims)
+                  if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else {
+                  if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
+                     split_derived_dim_string(dimlist_ptr-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+                     fortprintf(fd, &quot;, n%sGlobal%s&quot;, cp1, cp2);
+                     free(cp1);
+                     free(cp2);
+                  }
+                  else
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, %sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  lastdim = dimlist_ptr;
+               }
+               dimlist_ptr = dimlist_ptr-&gt;next;
+               i++;
+            }
+            fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="blue">&quot;);
+   
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+               if (var_ptr-&gt;ndims &gt; 0) {
+                  fortprintf(fd, &quot;      allocate(super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
+                  i = 1;
+                  dimlist_ptr = var_ptr-&gt;dimlist;
+                  while (dimlist_ptr) {
+                     if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+                        if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                        else fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                     else
+                        fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+      
+                     if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;, &quot;);
+         
+                     dimlist_ptr = dimlist_ptr-&gt;next;
+                     i++;
+                  }
+                  fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="red">&quot;);
+               }
+   
+               /* Copy from field to super_ array */
                i = 1;
                dimlist_ptr = var_ptr-&gt;dimlist;
-               while (dimlist_ptr) {
+               while (i &lt;= var_ptr-&gt;ndims) {
                   if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                     else fortprintf(fd, &quot;domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      do i%i=1,domain %% blocklist %% mesh %% %s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;      do i%i=1,domain %% blocklist %% mesh %% %s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else
-                     fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     fortprintf(fd, &quot;      do i%i=1,%s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
    
-                  if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;, &quot;);
-      
+                  i++;
                   dimlist_ptr = dimlist_ptr-&gt;next;
+               }
+   
+               fortprintf(fd, &quot;         super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
+               for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
+                  fortprintf(fd, &quot;i%i&quot;,i);
+                  if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;,&quot;);
+               }
+               fortprintf(fd, &quot;) = %s %% %s %% array(&quot;, struct_deref, var_ptr-&gt;super_array);
+               fortprintf(fd, &quot;%s %% index_%s&quot;, struct_deref, var_ptr-&gt;name_in_code);
+               for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
+                  fortprintf(fd, &quot;,i%i&quot;,i);
+               }
+               fortprintf(fd, &quot;)</font>
<font color="blue">&quot;);
+   
+               i = 1;
+               while (i &lt;= var_ptr-&gt;ndims) {
+                  fortprintf(fd, &quot;      end do</font>
<font color="red">&quot;);
                   i++;
                }
-               fortprintf(fd, &quot;))</font>
<font color="black"></font>
<font color="red">&quot;);
             }
-
-            /* Copy from field to super_ array */
+   
+            fortprintf(fd, &quot;      %s%id %% ioinfo %% fieldName = \'%s\'</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_file);
+            fortprintf(fd, &quot;      call dmpar_alltoall_field(domain %% dminfo, &amp;</font>
<font color="blue">&quot;);
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
+               fortprintf(fd, &quot;                                super_%s%id, %s%id %% array, &amp;</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, vtype, var_ptr-&gt;ndims);
+            else
+               fortprintf(fd, &quot;                                %s %% %s %% array, %s%id %% array, &amp;</font>
<font color="red">&quot;, struct_deref, var_ptr-&gt;name_in_code, vtype, var_ptr-&gt;ndims);
+      
             i = 1;
             dimlist_ptr = var_ptr-&gt;dimlist;
-            while (i &lt;= var_ptr-&gt;ndims) {
+            
+            if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
+               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;                                domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else fortprintf(fd, &quot;                                domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+            else
+               fortprintf(fd, &quot;                                %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+       
+            dimlist_ptr = dimlist_ptr-&gt;next;
+            i++;
+            while (dimlist_ptr) {
                if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      do i%i=1,domain %% blocklist %% mesh %% %s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  else fortprintf(fd, &quot;      do i%i=1,domain %% blocklist %% mesh %% %s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
-                  fortprintf(fd, &quot;      do i%i=1,%s</font>
<font color="red">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-
-               i++;
+                  fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+      
                dimlist_ptr = dimlist_ptr-&gt;next;
-            }
-
-            fortprintf(fd, &quot;         super_%s%id(&quot;, vtype, var_ptr-&gt;ndims);
-            for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-               fortprintf(fd, &quot;i%i&quot;,i);
-               if (i &lt; var_ptr-&gt;ndims) fortprintf(fd, &quot;,&quot;);
-            }
-            if (var_ptr-&gt;timedim) 
-               fortprintf(fd, &quot;) = domain %% blocklist %% time_levs(1) %% state %% %s %% array(&quot;, var_ptr-&gt;super_array);
-            else
-               fortprintf(fd, &quot;) = domain %% blocklist %% mesh %% %s %% array(&quot;, var_ptr-&gt;super_array);
-            fortprintf(fd, &quot;index_%s&quot;, var_ptr-&gt;name_in_code);
-            for(i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-               fortprintf(fd, &quot;,i%i&quot;,i);
-            }
-            fortprintf(fd, &quot;)</font>
<font color="red">&quot;);
-
-            i = 1;
-            while (i &lt;= var_ptr-&gt;ndims) {
-               fortprintf(fd, &quot;      end do</font>
<font color="blue">&quot;);
                i++;
+            }     
+      
+            if (is_derived_dim(lastdim-&gt;dim-&gt;name_in_code)) {
+               split_derived_dim_string(lastdim-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
+               fortprintf(fd, &quot;, n%sGlobal%s, &amp;</font>
<font color="blue">&quot;, cp1, cp2);
+               fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
+               free(cp1);
+               free(cp2);
             }
+            else {
+               if (!lastdim-&gt;dim-&gt;namelist_defined) {
+                  fortprintf(fd, &quot;, %sGlobal, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code);
+                  fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
+               }
+               else {
+                  fortprintf(fd, &quot;, %sGlobal, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_file);
+                  fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
+               }
+            }
          }
-
-         fortprintf(fd, &quot;      %s%id %% ioinfo %% fieldName = \'%s\'</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_file);
-         fortprintf(fd, &quot;      call dmpar_alltoall_field(domain %% dminfo, &amp;</font>
<font color="red">&quot;);
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
-            fortprintf(fd, &quot;                                super_%s%id, %s%id %% array, &amp;</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, vtype, var_ptr-&gt;ndims);
          else {
-            if (var_ptr-&gt;timedim) 
-               fortprintf(fd, &quot;                                domain %% blocklist %% time_levs(1) %% state %% %s %% array, %s%id %% array, &amp;</font>
<font color="red">&quot;, var_ptr-&gt;name_in_code, vtype, var_ptr-&gt;ndims);
-            else
-               fortprintf(fd, &quot;                                domain %% blocklist %% mesh %% %s %% array, %s%id %% array, &amp;</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_code, vtype, var_ptr-&gt;ndims);
+            fortprintf(fd, &quot;      %s%id %% ioinfo %% fieldName = \'%s\'</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_file);
+            fortprintf(fd, &quot;      %s%id %% scalar = %s %% %s %% scalar</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, struct_deref, var_ptr-&gt;name_in_code);
          }
    
-         i = 1;
-         dimlist_ptr = var_ptr-&gt;dimlist;
-         
-         if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-            if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;                                domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-            else fortprintf(fd, &quot;                                domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+         if (var_ptr-&gt;timedim)
+            fortprintf(fd, &quot;      if (domain %% dminfo %% my_proc_id == IO_NODE) call io_output_field_time(output_obj, %s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
          else
-            fortprintf(fd, &quot;                                %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-    
-         dimlist_ptr = dimlist_ptr-&gt;next;
-         i++;
-         while (dimlist_ptr) {
-            if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
-               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-               else fortprintf(fd, &quot;, domain %% blocklist %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
-            else
-               fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
-   
-            dimlist_ptr = dimlist_ptr-&gt;next;
-            i++;
-         }     
-   
-         if (is_derived_dim(lastdim-&gt;dim-&gt;name_in_code)) {
-            split_derived_dim_string(lastdim-&gt;dim-&gt;name_in_code, &amp;cp1, &amp;cp2);
-            fortprintf(fd, &quot;, n%sGlobal%s, &amp;</font>
<font color="red">&quot;, cp1, cp2);
-            fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
-            free(cp1);
-            free(cp2);
+            fortprintf(fd, &quot;      if (domain %% dminfo %% my_proc_id == IO_NODE) call io_output_field(output_obj, %s%id)</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims);
+         if (var_ptr-&gt;ndims &gt; 0) {
+            fortprintf(fd, &quot;      deallocate(%s%id %% array)</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims);
+            if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
+               fortprintf(fd, &quot;      deallocate(super_%s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
          }
-         else {
-            fortprintf(fd, &quot;, %sGlobal, &amp;</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_code);
-            fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
-         }
+         fortprintf(fd, &quot;      end if</font>
<font color="black"></font>
<font color="red">&quot;);
+   
+         var_list_ptr = var_list_ptr-&gt;next;
       }
-      else {
-         fortprintf(fd, &quot;      %s%id %% ioinfo %% fieldName = \'%s\'</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_file);
-         if (var_ptr-&gt;timedim) 
-            fortprintf(fd, &quot;      %s%id %% scalar = domain %% blocklist %% time_levs(1) %% state %% %s %% scalar</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-         else
-            fortprintf(fd, &quot;      %s%id %% scalar = domain %% blocklist %% mesh %% %s %% scalar</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, var_ptr-&gt;name_in_code);
-      }
-
-      if (var_ptr-&gt;timedim)
-         fortprintf(fd, &quot;      if (domain %% dminfo %% my_proc_id == IO_NODE) call io_output_field_time(output_obj, %s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-      else
-         fortprintf(fd, &quot;      if (domain %% dminfo %% my_proc_id == IO_NODE) call io_output_field(output_obj, %s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-      if (var_ptr-&gt;ndims &gt; 0) {
-         fortprintf(fd, &quot;      deallocate(%s%id %% array)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
-            fortprintf(fd, &quot;      deallocate(super_%s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
-      }
-      fortprintf(fd, &quot;      end if</font>
<font color="black"></font>
<font color="gray">&quot;);
-
-      var_ptr = var_ptr-&gt;next;
+      group_ptr = group_ptr-&gt;next;
    }
 
    fclose(fd);
@@ -1680,7 +1623,7 @@
 
    
    /*
-    *  Generate code to write 0d, 1d, 2d, 3d real time-varying fields
+    *  Generate code to write 0d, 1d, 2d, 3d time-varying fields
     */
    for(j=0; j&lt;2; j++) {
       for(i=0; i&lt;=3; i++) {

Modified: branches/atmos_physics/src/registry/gen_inc.h
===================================================================
--- branches/atmos_physics/src/registry/gen_inc.h        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/registry/gen_inc.h        2010-10-13 20:25:17 UTC (rev 549)
@@ -1,4 +1,4 @@
 void gen_namelists(struct namelist *);
-void gen_field_defs(struct variable *, struct dimension *);
-void gen_reads(struct variable *, struct dimension *);
-void gen_writes(struct variable *, struct dimension *, struct namelist *);
+void gen_field_defs(struct group_list * groups, struct variable *, struct dimension *);
+void gen_reads(struct group_list * groups, struct variable *, struct dimension *);
+void gen_writes(struct group_list * groups, struct variable *, struct dimension *, struct namelist *);

Modified: branches/atmos_physics/src/registry/parse.c
===================================================================
--- branches/atmos_physics/src/registry/parse.c        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/registry/parse.c        2010-10-13 20:25:17 UTC (rev 549)
@@ -4,10 +4,11 @@
 #include &quot;registry_types.h&quot;
 #include &quot;gen_inc.h&quot;
 
-int parse_reg(FILE *, struct namelist **, struct dimension **, struct variable **);
+int parse_reg(FILE *, struct namelist **, struct dimension **, struct variable **, struct group_list **);
 int getword(FILE *, char *);
 int is_integer_constant(char *);
 void sort_vars(struct variable *);
+void sort_group_vars(struct group_list *);
 
 int main(int argc, char ** argv)
 {
@@ -15,6 +16,7 @@
    struct namelist * nls;
    struct dimension * dims;
    struct variable * vars;
+   struct group_list * groups;
 
    if (argc != 2) {
       fprintf(stderr,&quot;</font>
<font color="black">Usage: %s filename</font>
<font color="black"></font>
<font color="gray">&quot;, argv[0]);
@@ -25,7 +27,7 @@
       nls = NULL;
       dims = NULL;
       vars = NULL;
-      if (parse_reg(regfile, &amp;nls, &amp;dims, &amp;vars)) {
+      if (parse_reg(regfile, &amp;nls, &amp;dims, &amp;vars, &amp;groups)) {
          return 1;
       }
    }   
@@ -35,17 +37,18 @@
    }   
 
    sort_vars(vars);
+   sort_group_vars(groups);
 
    gen_namelists(nls);
-   gen_field_defs(vars, dims);
-   gen_reads(vars, dims);
-   gen_writes(vars, dims, nls);
+   gen_field_defs(groups, vars, dims);
+   gen_reads(groups, vars, dims);
+   gen_writes(groups, vars, dims, nls);
 
    return 0;
 }
 
 
-int parse_reg(FILE * regfile, struct namelist ** nls, struct dimension ** dims, struct variable ** vars)
+int parse_reg(FILE * regfile, struct namelist ** nls, struct dimension ** dims, struct variable ** vars, struct group_list ** groups)
 {
    char word[1024];
    struct namelist * nls_ptr;
@@ -54,13 +57,17 @@
    struct variable * var_ptr;
    struct dimension_list * dimlist_ptr;
    struct dimension * dimlist_cursor;
+   struct group_list * grouplist_ptr;
+   struct variable_list * vlist_cursor;
 
    NEW_NAMELIST(nls_ptr)
    NEW_DIMENSION(dim_ptr)
    NEW_VARIABLE(var_ptr)
+   NEW_GROUP_LIST(grouplist_ptr);
    *nls = nls_ptr;
    *dims = dim_ptr;
    *vars = var_ptr;
+   *groups = grouplist_ptr;
 
    while(getword(regfile, word) != EOF) {
       if (strncmp(word, &quot;namelist&quot;, 1024) == 0) {
@@ -130,7 +137,16 @@
          var_ptr-&gt;timedim = 0;
          var_ptr-&gt;iostreams = 0;
 
+         /* 
+          * persistence 
+          */
          getword(regfile, word); 
+         if (strncmp(word, &quot;persistent&quot;, 1024) == 0) 
+            var_ptr-&gt;persistence = PERSISTENT;
+         else if (strncmp(word, &quot;scratch&quot;, 1024) == 0) 
+            var_ptr-&gt;persistence = SCRATCH;
+
+         getword(regfile, word); 
          if (strncmp(word, &quot;real&quot;, 1024) == 0) 
             var_ptr-&gt;vtype = REAL;
          else if (strncmp(word, &quot;integer&quot;, 1024) == 0) 
@@ -168,14 +184,50 @@
             getword(regfile, word); 
          }
 
-         /* Read I/O info */
+         /* 
+          * time_dim 
+          */
          getword(regfile, word);
+         var_ptr-&gt;ntime_levs = atoi(word);
+
+         /* 
+          * I/O info 
+          */
+         getword(regfile, word);
          if (strchr(word, (int)'i')) var_ptr-&gt;iostreams |= INPUT0;
          if (strchr(word, (int)'r')) var_ptr-&gt;iostreams |= RESTART0;
          if (strchr(word, (int)'o')) var_ptr-&gt;iostreams |= OUTPUT0;
 
          getword(regfile, var_ptr-&gt;name_in_code); 
 
+         /* 
+          * struct 
+          */
+         getword(regfile, var_ptr-&gt;struct_group); 
+         grouplist_ptr = *groups;
+         grouplist_ptr = grouplist_ptr-&gt;next;
+         while (grouplist_ptr &amp;&amp; strncmp(var_ptr-&gt;struct_group, grouplist_ptr-&gt;name, 1024)) {
+            grouplist_ptr = grouplist_ptr-&gt;next;
+         }
+         if (!grouplist_ptr) {
+            grouplist_ptr = *groups;
+            while(grouplist_ptr-&gt;next) grouplist_ptr = grouplist_ptr-&gt;next;
+            NEW_GROUP_LIST(grouplist_ptr-&gt;next);
+            grouplist_ptr = grouplist_ptr-&gt;next;
+            memcpy(grouplist_ptr-&gt;name, var_ptr-&gt;struct_group, (size_t)1024);
+            NEW_VARIABLE_LIST(grouplist_ptr-&gt;vlist);
+            grouplist_ptr-&gt;vlist-&gt;var = var_ptr;
+         }
+         else {
+            vlist_cursor = grouplist_ptr-&gt;vlist;
+            while (vlist_cursor-&gt;next) vlist_cursor = vlist_cursor-&gt;next;
+            NEW_VARIABLE_LIST(vlist_cursor-&gt;next);
+            vlist_cursor-&gt;next-&gt;prev = vlist_cursor;
+            vlist_cursor = vlist_cursor-&gt;next;
+            vlist_cursor-&gt;var = var_ptr;
+         }
+
+
          getword(regfile, var_ptr-&gt;super_array);
          getword(regfile, var_ptr-&gt;array_class);
 
@@ -203,6 +255,10 @@
    if ((*vars)-&gt;next) *vars = (*vars)-&gt;next;
    if (var_ptr) free(var_ptr);
 
+   grouplist_ptr = *groups;
+   if ((*groups)-&gt;next) *groups = (*groups)-&gt;next;
+   if (grouplist_ptr) free(grouplist_ptr);
+
    return 0;
 }
 
@@ -252,7 +308,7 @@
 
    var_ptr = vars;
 
-/*
+/* Attempt at sorting first on super-array, then on class in the same loop
    while (var_ptr) {
       memcpy(super_array, var_ptr-&gt;super_array, 1024);
       memcpy(array_class, var_ptr-&gt;array_class, 1024);
@@ -321,3 +377,68 @@
       var_ptr = var_ptr-&gt;next;
    }
 }
+
+
+void sort_group_vars(struct group_list * groups)
+{
+   struct variable_list * var_list;
+   struct variable_list * var_ptr;
+   struct variable_list * var_ptr2;
+   struct variable_list * var_ptr2_prev;
+   struct group_list * group_ptr;
+   char super_array[1024];
+   char array_class[1024];
+
+   group_ptr = groups;
+
+   while (group_ptr) {
+
+      var_ptr = group_ptr-&gt;vlist;
+   
+      while (var_ptr) {
+         memcpy(super_array, var_ptr-&gt;var-&gt;super_array, 1024);
+         var_ptr2_prev = var_ptr;
+         var_ptr2 = var_ptr-&gt;next;
+         if (var_ptr2 &amp;&amp; strncmp(super_array, var_ptr2-&gt;var-&gt;super_array, 1024) != 0) {
+            while (var_ptr2) {
+               if (strncmp(super_array, var_ptr2-&gt;var-&gt;super_array, 1024) == 0) {
+                  var_ptr2_prev-&gt;next = var_ptr2-&gt;next;
+                  var_ptr2-&gt;next = var_ptr-&gt;next;
+                  var_ptr-&gt;next = var_ptr2;
+                  var_ptr2 = var_ptr2_prev-&gt;next;
+               }
+               else {
+                  var_ptr2_prev = var_ptr2_prev-&gt;next;
+                  var_ptr2 = var_ptr2-&gt;next;
+               }
+            }
+         } 
+         var_ptr = var_ptr-&gt;next;
+      }
+   
+      var_ptr = group_ptr-&gt;vlist;
+   
+      while (var_ptr) {
+         memcpy(array_class, var_ptr-&gt;var-&gt;array_class, 1024);
+         var_ptr2_prev = var_ptr;
+         var_ptr2 = var_ptr-&gt;next;
+         if (var_ptr2 &amp;&amp; strncmp(array_class, var_ptr2-&gt;var-&gt;array_class, 1024) != 0) {
+            while (var_ptr2) {
+               if (strncmp(array_class, var_ptr2-&gt;var-&gt;array_class, 1024) == 0) {
+                  var_ptr2_prev-&gt;next = var_ptr2-&gt;next;
+                  var_ptr2-&gt;next = var_ptr-&gt;next;
+                  var_ptr-&gt;next = var_ptr2;
+                  var_ptr2 = var_ptr2_prev-&gt;next;
+               }
+               else {
+                  var_ptr2_prev = var_ptr2_prev-&gt;next;
+                  var_ptr2 = var_ptr2-&gt;next;
+               }
+            }
+         } 
+         var_ptr = var_ptr-&gt;next;
+      }
+
+      group_ptr = group_ptr-&gt;next;
+   }
+}

Modified: branches/atmos_physics/src/registry/registry_types.h
===================================================================
--- branches/atmos_physics/src/registry/registry_types.h        2010-10-13 18:01:28 UTC (rev 548)
+++ branches/atmos_physics/src/registry/registry_types.h        2010-10-13 20:25:17 UTC (rev 549)
@@ -3,6 +3,9 @@
 #define LOGICAL 2
 #define CHARACTER 3
 
+#define PERSISTENT 0
+#define SCRATCH    1
+
 #define INPUT0    0x00000001
 #define RESTART0  0x00000002
 #define OUTPUT0   0x00000004
@@ -11,6 +14,8 @@
 #define NEW_DIMENSION(X) X = (struct dimension *)malloc(sizeof(struct dimension)); X-&gt;next = NULL;
 #define NEW_DIMENSION_LIST(X) X = (struct dimension_list *)malloc(sizeof(struct dimension_list)); X-&gt;dim = NULL; X-&gt;prev = NULL; X-&gt;next = NULL;
 #define NEW_VARIABLE(X) X = (struct variable *)malloc(sizeof(struct variable)); X-&gt;dimlist = NULL; X-&gt;next = NULL;
+#define NEW_VARIABLE_LIST(X) X = (struct variable_list *)malloc(sizeof(struct variable_list)); X-&gt;var = NULL; X-&gt;prev = NULL; X-&gt;next = NULL;
+#define NEW_GROUP_LIST(X) X = (struct group_list *)malloc(sizeof(struct group_list)); X-&gt;vlist = NULL; X-&gt;next = NULL;
 
 union default_val {
    int ival;
@@ -41,14 +46,29 @@
    struct dimension_list * next;
 };
 
+struct variable_list {
+   struct variable * var;
+   struct variable_list * prev;
+   struct variable_list * next;
+};
+
+struct group_list {
+   char name[1024];
+   struct variable_list * vlist; 
+   struct group_list * next; 
+};
+
 struct variable {
    char name_in_file[1024];
    char name_in_code[1024];
+   char struct_group[1024];
    char super_array[1024];
    char array_class[1024];
+   int persistence;
    int vtype;
    int ndims;
    int timedim;
+   int ntime_levs;
    int iostreams;
    struct dimension_list * dimlist;
    struct variable * next;

</font>
</pre>