<p><b>duda</b> 2010-10-29 11:06:59 -0600 (Fri, 29 Oct 2010)</p><p>BRANCH COMMIT<br>
<br>
Add changes to re-organize the driver and sub-driver levels of<br>
MPAS, removing all core-specific code, in particular, calls to<br>
test case initialization. Now, the sub-driver implements init(),<br>
run(), and finalize() routines, which make calls to the<br>
init/run/finalize routines implemented by main modules of the<br>
framework and core. These changes will allow us to separate the<br>
initialization step from the model proper, and should also make it<br>
easier to package MPAS as a component in a coupled system in<br>
future.<br>
<br>
<br>
A    src/core_hyd_atmos/module_core.F<br>
D    src/core_hyd_atmos/mpas_interface.F<br>
M    src/core_hyd_atmos/Makefile<br>
A    src/core_sw/module_core.F<br>
D    src/core_sw/mpas_interface.F<br>
M    src/core_sw/Makefile<br>
M    src/driver/mpas.F<br>
M    src/driver/module_subdriver.F<br>
A    src/core_nhyd_atmos/module_core.F<br>
D    src/core_nhyd_atmos/mpas_interface.F<br>
M    src/core_nhyd_atmos/Makefile<br>
A    src/core_ocean/module_core.F<br>
D    src/core_ocean/mpas_interface.F<br>
M    src/core_ocean/Makefile<br>
M    src/framework/module_grid_types.F<br>
A    src/framework/module_framework.F<br>
M    src/framework/Makefile<br>
</p><hr noshade><pre><font color="gray">Modified: branches/atmos_nonhydrostatic/src/core_hyd_atmos/Makefile
===================================================================
--- branches/atmos_nonhydrostatic/src/core_hyd_atmos/Makefile        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_hyd_atmos/Makefile        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,9 +1,9 @@
 .SUFFIXES: .F .o
 
-OBJS = module_test_cases.o \
+OBJS = module_core.o \
+       module_test_cases.o \
        module_time_integration.o \
-       module_advection.o \
-       mpas_interface.o
+       module_advection.o
 
 all: core_hyd
 
@@ -16,7 +16,7 @@
 
 module_advection.o: 
 
-mpas_interface.o: module_advection.o module_test_cases.o module_time_integration.o
+module_core.o: module_advection.o module_test_cases.o module_time_integration.o
 
 clean:
         $(RM) *.o *.mod *.f90 libdycore.a

Copied: branches/atmos_nonhydrostatic/src/core_hyd_atmos/module_core.F (from rev 581, branches/atmos_nonhydrostatic/src/core_hyd_atmos/mpas_interface.F)
===================================================================
--- branches/atmos_nonhydrostatic/src/core_hyd_atmos/module_core.F                                (rev 0)
+++ branches/atmos_nonhydrostatic/src/core_hyd_atmos/module_core.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -0,0 +1,201 @@
+module core
+
+   use framework
+
+   type (io_output_object) :: restart_obj
+   integer :: restart_frame
+
+  
+   contains
+
+
+     subroutine mpas_init(domain)
+
+      use configure
+      use grid_types
+      use test_cases
+
+      implicit none
+
+      type (domain_type), intent(inout) :: domain
+
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block
+
+
+      if (.not. config_do_restart) call setup_hyd_test_case(domain)
+
+      !
+      ! Initialize core
+      !
+      dt = config_dt
+      block =&gt; domain % blocklist
+      do while (associated(block))
+         call mpas_init_block(block, block % mesh, dt)
+         block =&gt; block % next
+      end do
+
+      restart_frame = 1
+
+   end subroutine mpas_init

+
+   subroutine mpas_init_block(block, mesh, dt)
+   
+      use grid_types
+      use advection
+      use time_integration
+      use RBF_interpolation
+      use vector_reconstruction
+   
+      implicit none
+   
+      type (block_type), intent(inout) :: block
+      type (mesh_type), intent(inout) :: mesh
+      real (kind=RKIND), intent(in) :: dt
+   
+   
+      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 % state % time_levs(1) % state, block % diag, mesh)
+   
+      if (.not. config_do_restart) block % state % time_levs(1) % state % xtime % scalar = 0.0
+   
+   end subroutine mpas_init_block
+   
+   
+   subroutine mpas_run(domain, output_obj, output_frame)
+   
+      use grid_types
+      use io_output
+      use timer
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+      integer, intent(inout) :: output_frame
+   
+      integer :: ntimesteps, itimestep
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block_ptr
+   
+      ! Eventually, dt should be domain specific
+      dt = config_dt
+      ntimesteps = config_ntimesteps
+   
+      call write_output_frame(output_obj, output_frame, domain)
+   
+      ! During integration, time level 1 stores the model state at the beginning of the
+      !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
+      do itimestep = 1,ntimesteps
+         write(0,*) 'Doing timestep ', itimestep
+         call timer_start(&quot;time integration&quot;)
+         call mpas_timestep(domain, itimestep, dt)
+         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_state(domain % blocklist % state)
+   
+         if (mod(itimestep, config_output_interval) == 0) then
+            call write_output_frame(output_obj, output_frame, domain)
+         end if
+         if (mod(itimestep, config_restart_interval) == 0 .and. config_restart_interval &gt; 0) then
+            if (restart_frame == 1) call output_state_init(restart_obj, domain, &quot;RESTART&quot;)
+            call output_state_for_domain(restart_obj, domain, restart_frame)
+            restart_frame = restart_frame + 1
+         end if
+      end do
+   
+   end subroutine mpas_run
+   
+   
+   subroutine write_output_frame(output_obj, output_frame, domain)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain and write model state to output file
+   !
+   ! Input/Output: domain - contains model state; diagnostic field are computed
+   !                        before returning
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+      use io_output
+   
+      implicit none
+   
+      integer, intent(inout) :: output_frame
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+   
+      integer :: i, j, k
+      integer :: eoe
+      type (block_type), pointer :: block_ptr
+   
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
+         block_ptr =&gt; block_ptr % next
+      end do
+   
+      call output_state_for_domain(output_obj, domain, output_frame)
+      output_frame = output_frame + 1
+   
+   end subroutine write_output_frame
+   
+   
+   subroutine compute_output_diagnostics(state, grid)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain
+   !
+   ! Input: state - contains model prognostic fields
+   !        grid  - contains grid metadata
+   !
+   ! Output: state - upon returning, diagnostic fields will have be computed
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+   
+      implicit none
+   
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
+   
+      integer :: i, eoe
+      integer :: iEdge, k
+   
+   end subroutine compute_output_diagnostics
+   
+   
+   subroutine mpas_timestep(domain, itimestep, dt)
+   
+      use grid_types
+      use time_integration
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+      integer, intent(in) :: itimestep
+      real (kind=RKIND), intent(in) :: dt
+   
+      call timestep(domain, dt)
+   
+   end subroutine mpas_timestep
+   
+   
+   subroutine mpas_finalize(domain)
+   
+      use grid_types
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+
+      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
+   
+   end subroutine mpas_finalize
+
+end module core

Deleted: branches/atmos_nonhydrostatic/src/core_hyd_atmos/mpas_interface.F
===================================================================
--- branches/atmos_nonhydrostatic/src/core_hyd_atmos/mpas_interface.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_hyd_atmos/mpas_interface.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,88 +0,0 @@
-subroutine mpas_setup_test_case(domain)
-
-   use grid_types
-   use test_cases
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   call setup_hyd_test_case(domain)
-
-end subroutine mpas_setup_test_case
-
-
-subroutine mpas_init_domain(domain)
-! Initialize grid variables that are computed from the netcdf input file.
-
-   use grid_types
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   ! This is currently a stub.
-
-end subroutine mpas_init_domain
-
-
-subroutine mpas_init(block, mesh, dt)
-
-   use grid_types
-   use advection
-   use time_integration
-   use RBF_interpolation
-   use vector_reconstruction
-
-   implicit none
-
-   type (block_type), intent(inout) :: block
-   type (mesh_type), intent(inout) :: mesh
-   real (kind=RKIND), intent(in) :: dt
-
-   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 % state % time_levs(1) % state, block % diag, mesh)
-
-end subroutine mpas_init
-
-
-subroutine mpas_query(key, ivalue)
-
-   implicit none
-
-   character (len=256), intent(in) :: key
-   integer, intent(out) :: ivalue
-
-   if (index(key,'STORAGE_FACTOR') /= 0) then
-      ivalue = 1
-   end if
-
-end subroutine mpas_query
-
-
-subroutine mpas_timestep(domain, itimestep, dt)
-
-   use grid_types
-   use time_integration
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain 
-   integer, intent(in) :: itimestep
-   real (kind=RKIND), intent(in) :: dt
-
-   call timestep(domain, dt)
-
-end subroutine mpas_timestep
-
-
-subroutine mpas_finalize()
-
-   implicit none
-
-end subroutine mpas_finalize

Modified: branches/atmos_nonhydrostatic/src/core_nhyd_atmos/Makefile
===================================================================
--- branches/atmos_nonhydrostatic/src/core_nhyd_atmos/Makefile        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_nhyd_atmos/Makefile        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,9 +1,9 @@
 .SUFFIXES: .F .o
 
-OBJS = module_test_cases.o \
+OBJS = module_core.o \
+       module_test_cases.o \
        module_time_integration.o \
-       module_advection.o \
-       mpas_interface.o
+       module_advection.o
 
 all: core_hyd
 
@@ -16,7 +16,7 @@
 
 module_advection.o: 
 
-mpas_interface.o: module_advection.o module_test_cases.o module_time_integration.o
+module_core.o: module_advection.o module_test_cases.o module_time_integration.o
 
 clean:
         $(RM) *.o *.mod *.f90 libdycore.a

Copied: branches/atmos_nonhydrostatic/src/core_nhyd_atmos/module_core.F (from rev 581, branches/atmos_nonhydrostatic/src/core_nhyd_atmos/mpas_interface.F)
===================================================================
--- branches/atmos_nonhydrostatic/src/core_nhyd_atmos/module_core.F                                (rev 0)
+++ branches/atmos_nonhydrostatic/src/core_nhyd_atmos/module_core.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -0,0 +1,204 @@
+module core
+
+   use framework
+
+   type (io_output_object) :: restart_obj
+   integer :: restart_frame
+
+
+   contains
+
+
+   subroutine mpas_init(domain)
+
+      use configure
+      use grid_types
+      use test_cases
+
+      implicit none
+
+      type (domain_type), intent(inout) :: domain
+
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block
+
+
+      if (.not. config_do_restart) call setup_nhyd_test_case(domain)
+
+      !
+      ! Initialize core
+      !
+      dt = config_dt
+      block =&gt; domain % blocklist
+      do while (associated(block))
+         call mpas_init_block(block, block % mesh, dt)
+         block =&gt; block % next
+      end do
+
+      restart_frame = 1
+
+   end subroutine mpas_init
+
+
+   subroutine mpas_init_block(block, mesh, dt)
+   
+      use grid_types
+   !   use advection
+      use time_integration
+      use configure
+   
+      implicit none
+   
+      type (block_type), intent(inout) :: block
+      type (mesh_type), intent(inout) :: mesh
+      real (kind=RKIND), intent(in) :: dt
+   
+   
+      if (.not. config_do_restart) then
+         call init_coupled_diagnostics( block % state % time_levs(1) % state, block % diag, mesh)
+         call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, block % diag, mesh)
+      end if
+   
+   !
+   ! 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)
+   
+      if (.not. config_do_restart) block % state % time_levs(1) % state % xtime % scalar = 0.0
+   
+   end subroutine mpas_init_block
+   
+   
+   subroutine mpas_run(domain, output_obj, output_frame)
+   
+      use grid_types
+      use io_output
+      use timer
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+      integer, intent(inout) :: output_frame
+   
+      integer :: ntimesteps, itimestep
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block_ptr
+   
+      ! Eventually, dt should be domain specific
+      dt = config_dt
+      ntimesteps = config_ntimesteps
+   
+      call write_output_frame(output_obj, output_frame, domain)
+   
+      ! During integration, time level 1 stores the model state at the beginning of the
+      !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
+      do itimestep = 1,ntimesteps
+         write(0,*) 'Doing timestep ', itimestep
+         call timer_start(&quot;time integration&quot;)
+         call mpas_timestep(domain, itimestep, dt)
+         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_state(domain % blocklist % state)
+   
+         if (mod(itimestep, config_output_interval) == 0) then
+            call write_output_frame(output_obj, output_frame, domain)
+         end if
+         if (mod(itimestep, config_restart_interval) == 0 .and. config_restart_interval &gt; 0) then
+            if (restart_frame == 1) call output_state_init(restart_obj, domain, &quot;RESTART&quot;)
+            call output_state_for_domain(restart_obj, domain, restart_frame)
+            restart_frame = restart_frame + 1
+         end if
+      end do
+   
+   end subroutine mpas_run
+   
+   
+   subroutine write_output_frame(output_obj, output_frame, domain)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain and write model state to output file
+   !
+   ! Input/Output: domain - contains model state; diagnostic field are computed
+   !                        before returning
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+      use io_output
+   
+      implicit none
+   
+      integer, intent(inout) :: output_frame
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+   
+      integer :: i, j, k
+      integer :: eoe
+      type (block_type), pointer :: block_ptr
+   
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
+         block_ptr =&gt; block_ptr % next
+      end do
+   
+      call output_state_for_domain(output_obj, domain, output_frame)
+      output_frame = output_frame + 1
+   
+   end subroutine write_output_frame
+   
+   
+   subroutine compute_output_diagnostics(state, grid)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain
+   !
+   ! Input: state - contains model prognostic fields
+   !        grid  - contains grid metadata
+   !
+   ! Output: state - upon returning, diagnostic fields will have be computed
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+   
+      implicit none
+   
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
+   
+      integer :: i, eoe
+      integer :: iEdge, k
+   
+   end subroutine compute_output_diagnostics
+   
+   
+   subroutine mpas_timestep(domain, itimestep, dt)
+   
+      use grid_types
+      use time_integration
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+      integer, intent(in) :: itimestep
+      real (kind=RKIND), intent(in) :: dt
+   
+      call timestep(domain, dt)
+   
+   end subroutine mpas_timestep
+   
+   
+   subroutine mpas_finalize(domain)
+   
+      use grid_types
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+
+      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
+   
+   end subroutine mpas_finalize
+
+end module core

Deleted: branches/atmos_nonhydrostatic/src/core_nhyd_atmos/mpas_interface.F
===================================================================
--- branches/atmos_nonhydrostatic/src/core_nhyd_atmos/mpas_interface.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_nhyd_atmos/mpas_interface.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,97 +0,0 @@
-subroutine mpas_setup_test_case(domain)
-
-   use grid_types
-   use test_cases
-
-   implicit none
-
-   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
-
-
-subroutine mpas_init_domain(domain)
-! Initialize grid variables that are computed from the netcdf input file.
-
-   use grid_types
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   ! This is currently a stub.
-
-end subroutine mpas_init_domain
-
-
-subroutine mpas_init(block, mesh, dt)
-
-   use grid_types
-!   use advection
-   use time_integration
-   use configure
-
-   implicit none
-
-   type (block_type), intent(inout) :: block
-   type (mesh_type), intent(inout) :: mesh
-   real (kind=RKIND), intent(in) :: dt
-
-   if (.not. config_do_restart) then
-      call init_coupled_diagnostics( block % state % time_levs(1) % state, block % diag, mesh)
-      call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, block % diag, mesh)
-   end if
-
-!
-! 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)
-
-end subroutine mpas_init
-
-
-subroutine mpas_query(key, ivalue)
-
-   implicit none
-
-   character (len=256), intent(in) :: key
-   integer, intent(out) :: ivalue
-
-   if (index(key,'STORAGE_FACTOR') /= 0) then
-      ivalue = 1
-   end if
-
-end subroutine mpas_query
-
-
-subroutine mpas_timestep(domain, itimestep, dt)
-
-   use grid_types
-   use time_integration
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain 
-   integer, intent(in) :: itimestep
-   real (kind=RKIND), intent(in) :: dt
-
-   call timestep(domain, dt)
-
-end subroutine mpas_timestep
-
-
-subroutine mpas_finalize()
-
-   implicit none
-
-end subroutine mpas_finalize

Modified: branches/atmos_nonhydrostatic/src/core_ocean/Makefile
===================================================================
--- branches/atmos_nonhydrostatic/src/core_ocean/Makefile        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_ocean/Makefile        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,10 +1,10 @@
 .SUFFIXES: .F .o
 
-OBJS = module_test_cases.o \
+OBJS = module_core.o \
+       module_test_cases.o \
        module_advection.o \
        module_time_integration.o \
-       module_global_diagnostics.o \
-       mpas_interface.o
+       module_global_diagnostics.o
 
 all: core_hyd
 
@@ -19,7 +19,7 @@
 
 module_global_diagnostics.o: 
 
-mpas_interface.o: module_advection.o module_global_diagnostics.o module_test_cases.o module_time_integration.o
+module_core.o: module_advection.o module_global_diagnostics.o module_test_cases.o module_time_integration.o
 
 clean:
         $(RM) *.o *.mod *.f90 libdycore.a

Copied: branches/atmos_nonhydrostatic/src/core_ocean/module_core.F (from rev 581, branches/atmos_nonhydrostatic/src/core_ocean/mpas_interface.F)
===================================================================
--- branches/atmos_nonhydrostatic/src/core_ocean/module_core.F                                (rev 0)
+++ branches/atmos_nonhydrostatic/src/core_ocean/module_core.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -0,0 +1,225 @@
+module core
+
+   use framework
+
+   type (io_output_object) :: restart_obj
+   integer :: restart_frame
+
+
+   contains
+
+
+   subroutine mpas_init(domain)
+
+      use configure
+      use grid_types
+      use test_cases
+
+      implicit none
+
+      type (domain_type), intent(inout) :: domain
+
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block
+
+
+      if (.not. config_do_restart) call setup_sw_test_case(domain)
+
+      !
+      ! Initialize core
+      !
+      dt = config_dt
+      block =&gt; domain % blocklist
+      do while (associated(block))
+         call mpas_init_block(block, block % mesh, dt)
+         block =&gt; block % next
+      end do
+
+   ! mrp 100316 In order for this to work, we need to pass domain % dminfo as an 
+   ! input arguement into mpas_init.  Ask about that later.  For now, there will be
+   ! no initial statistics write.
+   
+   !   call timer_start(&quot;global diagnostics&quot;)
+   !   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)
+
+      restart_frame = 1
+
+   end subroutine mpas_init
+
+
+   subroutine mpas_init_block(block, mesh, dt)
+   
+      use grid_types
+      use time_integration
+      use RBF_interpolation
+      use vector_reconstruction
+   
+      implicit none
+   
+      type (block_type), intent(inout) :: block
+      type (mesh_type), intent(inout) :: mesh
+      real (kind=RKIND), intent(in) :: dt
+   
+   
+      call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
+   
+      call rbfInterp_initialize(mesh)
+      call init_reconstruct(mesh)
+      call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
+   
+      if (.not. config_do_restart) block % state % time_levs(1) % state % xtime % scalar = 0.0
+   
+   end subroutine mpas_init_block
+   
+   
+   subroutine mpas_run(domain, output_obj, output_frame)
+   
+      use grid_types
+      use io_output
+      use timer
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+      integer, intent(inout) :: output_frame
+   
+      integer :: ntimesteps, itimestep
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block_ptr
+   
+      ! Eventually, dt should be domain specific
+      dt = config_dt
+      ntimesteps = config_ntimesteps
+   
+      call write_output_frame(output_obj, output_frame, domain)
+   
+      ! During integration, time level 1 stores the model state at the beginning of the
+      !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
+      do itimestep = 1,ntimesteps
+         write(0,*) 'Doing timestep ', itimestep
+         call timer_start(&quot;time integration&quot;)
+         call mpas_timestep(domain, itimestep, dt)
+         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_state(domain % blocklist % state)
+   
+         if (mod(itimestep, config_output_interval) == 0) then
+            call write_output_frame(output_obj, output_frame, domain)
+         end if
+         if (mod(itimestep, config_restart_interval) == 0 .and. config_restart_interval &gt; 0) then
+            if (restart_frame == 1) call output_state_init(restart_obj, domain, &quot;RESTART&quot;)
+            call output_state_for_domain(restart_obj, domain, restart_frame)
+            restart_frame = restart_frame + 1
+         end if
+      end do
+
+   end subroutine mpas_run
+   
+   
+   subroutine write_output_frame(output_obj, output_frame, domain)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain and write model state to output file
+   !
+   ! Input/Output: domain - contains model state; diagnostic field are computed
+   !                        before returning
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+      use io_output
+   
+      implicit none
+   
+      integer, intent(inout) :: output_frame
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+   
+      integer :: i, j, k
+      integer :: eoe
+      type (block_type), pointer :: block_ptr
+   
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
+         block_ptr =&gt; block_ptr % next
+      end do
+   
+      call output_state_for_domain(output_obj, domain, output_frame)
+      output_frame = output_frame + 1
+   
+   end subroutine write_output_frame
+   
+   
+   subroutine compute_output_diagnostics(state, grid)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain
+   !
+   ! Input: state - contains model prognostic fields
+   !        grid  - contains grid metadata
+   !
+   ! Output: state - upon returning, diagnostic fields will have be computed
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+   
+      implicit none
+   
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
+   
+      integer :: i, eoe
+      integer :: iEdge, k
+   
+   end subroutine compute_output_diagnostics
+   
+   
+   subroutine mpas_timestep(domain, itimestep, dt)
+   
+      use grid_types
+      use time_integration
+      use timer
+      use global_diagnostics
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+      integer, intent(in) :: itimestep
+      real (kind=RKIND), intent(in) :: dt
+      type (block_type), pointer :: block_ptr
+   
+      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.'
+         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
+   
+   end subroutine mpas_timestep
+   
+   
+   subroutine mpas_finalize(domain)
+   
+      use grid_types
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+
+      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
+   
+   end subroutine mpas_finalize
+
+end module core

Deleted: branches/atmos_nonhydrostatic/src/core_ocean/mpas_interface.F
===================================================================
--- branches/atmos_nonhydrostatic/src/core_ocean/mpas_interface.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_ocean/mpas_interface.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,110 +0,0 @@
-subroutine mpas_setup_test_case(domain)
-
-   use grid_types
-   use test_cases
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   call setup_sw_test_case(domain)
-
-end subroutine mpas_setup_test_case
-
-subroutine mpas_init_domain(domain)
-! Initialize grid variables that are computed from the netcdf input file.
-
-   use grid_types
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   ! This is currently a stub.
-
-end subroutine mpas_init_domain
-
-subroutine mpas_init(block, mesh, dt)
-
-   use grid_types
-   use time_integration
-   use RBF_interpolation
-   use vector_reconstruction
-
-   implicit none
-
-   type (block_type), intent(inout) :: block
-   type (mesh_type), intent(inout) :: mesh
-   real (kind=RKIND), intent(in) :: dt
-
-   call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
-
-   call rbfInterp_initialize(mesh)
-   call init_reconstruct(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 % 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)
-
-end subroutine mpas_init
-
-
-subroutine mpas_query(key, ivalue)
-
-   implicit none
-
-   character (len=256), intent(in) :: key
-   integer, intent(out) :: ivalue
-
-   if (index(key,'STORAGE_FACTOR') /= 0) then
-      ivalue = 2
-   end if
-
-end subroutine mpas_query
-
-
-subroutine mpas_timestep(domain, itimestep, dt)
-
-   use grid_types
-   use time_integration
-   use timer
-   use global_diagnostics
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain 
-   integer, intent(in) :: itimestep
-   real (kind=RKIND), intent(in) :: dt
-   type (block_type), pointer :: block_ptr
-
-   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.'
-      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
-
-end subroutine mpas_timestep
-
-
-subroutine mpas_finalize()
-
-   implicit none
-
-end subroutine mpas_finalize

Modified: branches/atmos_nonhydrostatic/src/core_sw/Makefile
===================================================================
--- branches/atmos_nonhydrostatic/src/core_sw/Makefile        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_sw/Makefile        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,10 +1,10 @@
 .SUFFIXES: .F .o
 
-OBJS =         module_test_cases.o \
+OBJS =         module_core.o \
+        module_test_cases.o \
         module_advection.o \
         module_time_integration.o \
-        module_global_diagnostics.o \
-        mpas_interface.o 
+        module_global_diagnostics.o
 
 all: core_sw
 
@@ -19,7 +19,7 @@
 
 module_global_diagnostics.o:
 
-mpas_interface.o: module_global_diagnostics.o module_test_cases.o module_time_integration.o module_advection.o
+module_core.o: module_global_diagnostics.o module_test_cases.o module_time_integration.o module_advection.o
 
 clean:
         $(RM) *.o *.mod *.f90 libdycore.a

Copied: branches/atmos_nonhydrostatic/src/core_sw/module_core.F (from rev 581, branches/atmos_nonhydrostatic/src/core_sw/mpas_interface.F)
===================================================================
--- branches/atmos_nonhydrostatic/src/core_sw/module_core.F                                (rev 0)
+++ branches/atmos_nonhydrostatic/src/core_sw/module_core.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -0,0 +1,217 @@
+module core
+
+   use framework
+
+   type (io_output_object) :: restart_obj
+   integer :: restart_frame
+
+
+   contains
+
+
+   subroutine mpas_init(domain)
+   
+      use configure
+      use grid_types
+      use test_cases
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain
+   
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block
+
+
+      if (.not. config_do_restart) call setup_sw_test_case(domain)
+
+      !
+      ! Initialize core
+      !
+      dt = config_dt
+      block =&gt; domain % blocklist
+      do while (associated(block))
+         call mpas_init_block(block, block % mesh, dt)
+         block =&gt; block % next
+      end do
+
+      restart_frame = 1
+   
+   end subroutine mpas_init
+   
+   
+   subroutine mpas_init_block(block, mesh, dt)
+   
+      use grid_types
+      use time_integration
+      use RBF_interpolation
+      use vector_reconstruction
+   
+      implicit none
+   
+      type (block_type), intent(inout) :: block
+      type (mesh_type), intent(inout) :: mesh
+      real (kind=RKIND), intent(in) :: dt
+   
+   
+      call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
+   
+      call rbfInterp_initialize(mesh)
+      call init_reconstruct(mesh)
+      call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
+   
+      if (.not. config_do_restart) block % state % time_levs(1) % state % xtime % scalar = 0.0
+   
+   end subroutine mpas_init_block
+   
+   
+   subroutine mpas_run(domain, output_obj, output_frame)
+   
+      use grid_types
+      use io_output
+      use timer
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+      integer, intent(inout) :: output_frame
+   
+      integer :: ntimesteps, itimestep
+      real (kind=RKIND) :: dt
+      type (block_type), pointer :: block_ptr
+   
+      ! Eventually, dt should be domain specific
+      dt = config_dt
+      ntimesteps = config_ntimesteps
+   
+      call write_output_frame(output_obj, output_frame, domain)
+   
+      ! During integration, time level 1 stores the model state at the beginning of the
+      !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
+      do itimestep = 1,ntimesteps
+         write(0,*) 'Doing timestep ', itimestep
+         call timer_start(&quot;time integration&quot;)
+         call mpas_timestep(domain, itimestep, dt)
+         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_state(domain % blocklist % state)
+   
+         if (mod(itimestep, config_output_interval) == 0) then
+            call write_output_frame(output_obj, output_frame, domain)
+         end if
+         if (mod(itimestep, config_restart_interval) == 0 .and. config_restart_interval &gt; 0) then
+            if (restart_frame == 1) call output_state_init(restart_obj, domain, &quot;RESTART&quot;)
+            call output_state_for_domain(restart_obj, domain, restart_frame)
+            restart_frame = restart_frame + 1
+         end if
+      end do
+
+   end subroutine mpas_run
+   
+   
+   subroutine write_output_frame(output_obj, output_frame, domain)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain and write model state to output file
+   !
+   ! Input/Output: domain - contains model state; diagnostic field are computed
+   !                        before returning
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+      use io_output
+   
+      implicit none
+   
+      integer, intent(inout) :: output_frame
+      type (domain_type), intent(inout) :: domain
+      type (io_output_object), intent(inout) :: output_obj
+   
+      integer :: i, j, k
+      integer :: eoe
+      type (block_type), pointer :: block_ptr
+   
+      block_ptr =&gt; domain % blocklist
+      do while (associated(block_ptr))
+         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
+         block_ptr =&gt; block_ptr % next
+      end do
+   
+      call output_state_for_domain(output_obj, domain, output_frame)
+      output_frame = output_frame + 1
+   
+   end subroutine write_output_frame
+   
+   
+   subroutine compute_output_diagnostics(state, grid)
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   ! Compute diagnostic fields for a domain
+   !
+   ! Input: state - contains model prognostic fields
+   !        grid  - contains grid metadata
+   !
+   ! Output: state - upon returning, diagnostic fields will have be computed
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   
+      use grid_types
+   
+      implicit none
+   
+      type (state_type), intent(inout) :: state
+      type (mesh_type), intent(in) :: grid
+   
+      integer :: i, eoe
+      integer :: iEdge, k
+   
+   end subroutine compute_output_diagnostics
+   
+   
+   subroutine mpas_timestep(domain, itimestep, dt)
+   
+      use grid_types
+      use time_integration
+      use timer
+      use global_diagnostics
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+      integer, intent(in) :: itimestep
+      real (kind=RKIND), intent(in) :: dt
+      type (block_type), pointer :: block_ptr
+   
+      call timestep(domain, dt)
+   
+      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
+      end if
+   
+   end subroutine mpas_timestep
+   
+   
+   subroutine mpas_finalize(domain)
+   
+      use grid_types
+   
+      implicit none
+   
+      type (domain_type), intent(inout) :: domain 
+
+      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
+   
+   end subroutine mpas_finalize
+
+end module core

Deleted: branches/atmos_nonhydrostatic/src/core_sw/mpas_interface.F
===================================================================
--- branches/atmos_nonhydrostatic/src/core_sw/mpas_interface.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/core_sw/mpas_interface.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,104 +0,0 @@
-subroutine mpas_setup_test_case(domain)
-
-   use grid_types
-   use test_cases
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   call setup_sw_test_case(domain)
-
-end subroutine mpas_setup_test_case
-
-
-subroutine mpas_init_domain(domain)
-! Initialize grid variables that are computed from the netcdf input file.
-
-   use grid_types
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain
-
-   ! This is currently a stub.
-
-end subroutine mpas_init_domain
-
-
-subroutine mpas_init(block, mesh, dt)
-
-   use grid_types
-   use time_integration
-   use RBF_interpolation
-   use vector_reconstruction
-
-   implicit none
-
-   type (block_type), intent(inout) :: block
-   type (mesh_type), intent(inout) :: mesh
-   real (kind=RKIND), intent(in) :: dt
-
-   call compute_solve_diagnostics(dt, block % state % time_levs(1) % state, mesh)
-
-   call rbfInterp_initialize(mesh)
-   call init_reconstruct(mesh)
-   call reconstruct(block % state % time_levs(1) % state, block % diag, mesh)
-
-end subroutine mpas_init
-
-
-subroutine mpas_query(key, ivalue)
-
-   implicit none
-
-   character (len=256), intent(in) :: key
-   integer, intent(out) :: ivalue
-
-   if (index(key,'STORAGE_FACTOR') /= 0) then
-      ivalue = 2
-   end if
-
-end subroutine mpas_query
-
-
-subroutine mpas_timestep(domain, itimestep, dt)
-
-   use grid_types
-   use time_integration
-   use timer
-   use global_diagnostics
-
-   implicit none
-
-   type (domain_type), intent(inout) :: domain 
-   integer, intent(in) :: itimestep
-   real (kind=RKIND), intent(in) :: dt
-   type (block_type), pointer :: block_ptr
-
-   call timestep(domain, dt)
-
-   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
-   end if
-
-end subroutine mpas_timestep
-
-
-subroutine mpas_finalize()
-
-   implicit none
-
-end subroutine mpas_finalize

Modified: branches/atmos_nonhydrostatic/src/driver/module_subdriver.F
===================================================================
--- branches/atmos_nonhydrostatic/src/driver/module_subdriver.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/driver/module_subdriver.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,150 +1,86 @@
 module subdriver
 
-   use grid_types
-   use io_output
-   use configure
-   use dmpar
-   use timer
+   use framework
+   use core
 
+   type (dm_info), pointer :: dminfo
+   type (domain_type), pointer :: domain
+   type (io_output_object) :: output_obj
    integer :: output_frame
-   integer :: restart_frame
 
-   interface
-      subroutine mpas_init(block, mesh, dt)
-         use grid_types
-         type (block_type), intent(inout) :: block
-         type (mesh_type), intent(inout) :: mesh
-         real (kind=RKIND), intent(in) :: dt
-      end subroutine mpas_init
 
-      subroutine mpas_timestep(domain, itimestep, dt)
-         use grid_types
-         type (domain_type), intent(inout) :: domain
-         integer, intent(in) :: itimestep
-         real (kind=RKIND), intent(in) :: dt
-      end subroutine mpas_timestep
-   end interface
-
-
    contains
 
 
-   subroutine solve(domain)
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   ! Solve 2d shallow water equations over the time range specified in the 
-   !   namelist, writing model state to an output file periodically
-   !
-   ! Input/Output: domain - grid metadata and model state, to be advanced forward 
-   !                       in time
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+   subroutine init()

       implicit none
 
-      type (domain_type), intent(inout) :: domain
-     
-      integer :: ntimesteps, itimestep
       real (kind=RKIND) :: dt
-      type (block_type), pointer :: block_ptr
-      type (io_output_object) :: output_obj
-      type (io_output_object) :: restart_obj
 
+      call timer_start(&quot;total time&quot;)
+      call timer_start(&quot;initialize&quot;)
 
-      ! Eventually, dt should be domain specific
-      dt = config_dt
-      ntimesteps = config_ntimesteps
 
+      !
+      ! Initialize infrastructure
+      !
+      call framework_init(dminfo, domain)
 
-      ! Compute diagnostic fields needed in solve loop, and initialize 
-      !    simulation time to 0 for all blocks
-      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 % state % time_levs(1) % state % xtime % scalar = 0.0
-         block_ptr =&gt; block_ptr % next
-      end do
 
-      ! Before integrating, write out the initial state
-      output_frame = 1
-      restart_frame = 1
-      call output_state_init(output_obj, domain, &quot;OUTPUT&quot;)
-      call write_output_frame(output_obj, domain)
+      call input_state_for_domain(domain)
 
 
-      ! During integration, time level 1 stores the model state at the beginning of the 
-      !   time step, and time level 2 stores the state advanced dt in time by timestep(...)
-      do itimestep = 1,ntimesteps     
-         write(0,*) 'Doing timestep ', itimestep
-         call timer_start(&quot;time integration&quot;)
-         call mpas_timestep(domain, itimestep, dt) 
-         call timer_stop(&quot;time integration&quot;)
+      !
+      ! Initialize core
+      !
+      call mpas_init(domain)
 
-         ! Move time level 2 fields back into time level 1 for next time step
-         call shift_time_levels_state(domain % blocklist % state)
+      call timer_stop(&quot;initialize&quot;)
 
-         if (mod(itimestep, config_output_interval) == 0) then 
-            call write_output_frame(output_obj, domain)
-         end if
-         if (mod(itimestep, config_restart_interval) == 0 .and. config_restart_interval &gt; 0) then 
-            if (restart_frame == 1) call output_state_init(restart_obj, domain, &quot;RESTART&quot;)
-            call output_state_for_domain(restart_obj, domain, restart_frame)
-            restart_frame = restart_frame + 1
-         end if
-      end do
 
-      call output_state_finalize(output_obj, domain % dminfo)
-      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
+      !
+      ! Set up output streams to be written to by the MPAS core
+      !
+      output_frame = 1
+      call output_state_init(output_obj, domain, &quot;OUTPUT&quot;)
 
-   end subroutine solve
+   end subroutine init
 
 
-   subroutine write_output_frame(output_obj, domain)
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   ! Compute diagnostic fields for a domain and write model state to output file
-   !
-   ! Input/Output: domain - contains model state; diagnostic field are computed 
-   !                        before returning
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   subroutine run()
 
       implicit none
 
-      type (domain_type), intent(inout) :: domain
-      type (io_output_object), intent(inout) :: output_obj
+      call mpas_run(domain, output_obj, output_frame)
 
-      integer :: i, j, k
-      integer :: eoe
-      type (block_type), pointer :: block_ptr
+   end subroutine run
 
-      block_ptr =&gt; domain % blocklist
-      do while (associated(block_ptr))
-         call compute_output_diagnostics(block_ptr % state % time_levs(1) % state, block_ptr % mesh)
-         block_ptr =&gt; block_ptr % next
-      end do
 
-      call output_state_for_domain(output_obj, domain, output_frame)
-      output_frame = output_frame + 1
+   subroutine finalize()
+   
+      implicit none
 
-   end subroutine write_output_frame
+      !
+      ! Finalize output streams
+      !
+      call output_state_finalize(output_obj, domain % dminfo)
 
 
-   subroutine compute_output_diagnostics(state, grid)
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-   ! Compute diagnostic fields for a domain
-   !
-   ! Input: state - contains model prognostic fields
-   !        grid  - contains grid metadata
-   ! 
-   ! Output: state - upon returning, diagnostic fields will have be computed
-   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      !
+      ! Finalize core
+      !
+      call mpas_finalize(domain)
 
-      implicit none
+      call timer_stop(&quot;total time&quot;)
+      call timer_write()
 
-      type (state_type), intent(inout) :: state
-      type (mesh_type), intent(in) :: grid
 
-      integer :: i, eoe
-      integer :: iEdge, k
+      !
+      ! Finalize infrastructure
+      !
+      call framework_finalize(dminfo, domain)
 
-   end subroutine compute_output_diagnostics
+   end subroutine finalize
 
-
 end module subdriver

Modified: branches/atmos_nonhydrostatic/src/driver/mpas.F
===================================================================
--- branches/atmos_nonhydrostatic/src/driver/mpas.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/driver/mpas.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -1,51 +1,15 @@
 program mpas
 
-   use grid_types
-   use configure
-   use io_input
-   use dmpar
-   use timer
    use subdriver
 
    implicit none
 
-   interface mpas_setup_test_case
-      subroutine mpas_setup_test_case(domain)
-         use grid_types
-         type (domain_type), intent(inout) :: domain
-      end subroutine mpas_setup_test_case
-   end interface mpas_setup_test_case
+   call init()
 
+   call run() 
 
-   type (dm_info), pointer :: dminfo
-   type (domain_type), pointer :: domain
+   call finalize()
 
-   allocate(dminfo)
-   call dmpar_init(dminfo)
-
-   call read_namelist(dminfo)
-
-   call timer_start(&quot;total time&quot;)
-
-   call timer_start(&quot;initialize&quot;)
-   call allocate_domain(domain, dminfo)
-
-   call input_state_for_domain(domain)
-
-   call mpas_init_domain(domain)
-
-   if (.not. config_do_restart) call mpas_setup_test_case(domain)
-   call timer_stop(&quot;initialize&quot;)
-
-   call solve(domain) 
-
-   call deallocate_domain(domain)
-
-   call timer_stop(&quot;total time&quot;)
-   call timer_write()
-
-   call dmpar_finalize(dminfo)
-
    stop
 
 end program mpas

Modified: branches/atmos_nonhydrostatic/src/framework/Makefile
===================================================================
--- branches/atmos_nonhydrostatic/src/framework/Makefile        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/framework/Makefile        2010-10-29 17:06:59 UTC (rev 586)
@@ -4,7 +4,8 @@
    ZOLTANOBJ = module_zoltan_interface.o
 endif
 
-OBJS = module_timer.o \
+OBJS = module_framework.o \
+       module_timer.o \
        module_configure.o \
        module_constants.o \
        module_grid_types.o \
@@ -22,6 +23,8 @@
 framework: $(OBJS)
         ar -ru libframework.a $(OBJS)
 
+module_framework.o: module_dmpar.o module_io_input.o module_io_output.o module_grid_types.o module_configure.o module_timer.o
+
 module_configure.o: module_dmpar.o
 
 module_grid_types.o: module_dmpar.o

Added: branches/atmos_nonhydrostatic/src/framework/module_framework.F
===================================================================
--- branches/atmos_nonhydrostatic/src/framework/module_framework.F                                (rev 0)
+++ branches/atmos_nonhydrostatic/src/framework/module_framework.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -0,0 +1,44 @@
+module framework
+
+   use dmpar
+   use grid_types
+   use io_input
+   use io_output
+   use configure
+   use timer
+
+
+   contains
+
+   
+   subroutine framework_init(dminfo, domain)
+
+      implicit none
+
+      type (dm_info), pointer :: dminfo
+      type (domain_type), pointer :: domain
+
+      allocate(dminfo)
+      call dmpar_init(dminfo)
+
+      call read_namelist(dminfo)
+
+      call allocate_domain(domain, dminfo)
+
+   end subroutine framework_init
+
+   
+   subroutine framework_finalize(dminfo, domain)
+  
+      implicit none
+
+      type (dm_info), pointer :: dminfo
+      type (domain_type), pointer :: domain
+
+      call deallocate_domain(domain)
+
+      call dmpar_finalize(dminfo)
+
+   end subroutine framework_finalize
+
+end module framework

Modified: branches/atmos_nonhydrostatic/src/framework/module_grid_types.F
===================================================================
--- branches/atmos_nonhydrostatic/src/framework/module_grid_types.F        2010-10-29 16:57:23 UTC (rev 585)
+++ branches/atmos_nonhydrostatic/src/framework/module_grid_types.F        2010-10-29 17:06:59 UTC (rev 586)
@@ -93,7 +93,6 @@
 
    ! Derived type for storing part of a domain; used as a basic unit of work for a process
    type block_type
-      integer :: storageFactor    ! Additional storage used by time integration scheme
 
 #include &quot;block_group_members.inc&quot;
 
@@ -113,17 +112,7 @@
       type (dm_info), pointer :: dminfo
    end type domain_type
 
-   !
-   ! Solver interface routines provided by specific dycore
-   !
-   interface
-      subroutine mpas_query(key, ivalue)
-         character (len=256), intent(in) :: key
-         integer, intent(out) :: ivalue
-      end subroutine mpas_query
-   end interface
 
-
    contains
 
 
@@ -152,14 +141,10 @@
 #include &quot;dim_dummy_decls.inc&quot;
 
       integer :: i
-      character (len=256) :: key
 
       nullify(b % prev)
       nullify(b % next)
 
-      key = 'STORAGE_FACTOR'
-      call mpas_query(key, b % storageFactor)
-
       allocate(b % parinfo)
 
       b % domain =&gt; dom

</font>
</pre>