<p><b>croesch@ucar.edu</b> 2011-09-27 17:37:40 -0600 (Tue, 27 Sep 2011)</p><p>BRANCH COMMIT<br>
<br>
Write/read each restart frame to/from an individual file labeled with the restart date/time<br>
Add new restrictions and checks that restart time is consistent with the start time specified in the namelist<br>
Modify surface update logic to ensure the most recent, non-future surface data is retrieved relative to the current time<br>
<br>
<br>
M    src/core_nhyd_atmos/module_mpas_core.F<br>
M    src/framework/module_io_input.F<br>
M    src/framework/module_io_output.F<br>
</p><hr noshade><pre><font color="gray">Modified: branches/atmos_physics/src/core_nhyd_atmos/module_mpas_core.F
===================================================================
--- branches/atmos_physics/src/core_nhyd_atmos/module_mpas_core.F        2011-09-27 23:32:52 UTC (rev 1036)
+++ branches/atmos_physics/src/core_nhyd_atmos/module_mpas_core.F        2011-09-27 23:37:40 UTC (rev 1037)
@@ -4,7 +4,6 @@
 
    type (io_output_object) :: restart_obj
    type (io_input_object) :: sfc_update_obj
-   integer :: restart_frame
    integer :: current_outfile_frames
    
    type (MPAS_Clock_type) :: clock
@@ -52,7 +51,6 @@
          block =&gt; block % next
       end do
 
-      restart_frame = 1
       current_outfile_frames = 0
 
       if (config_sfc_update_interval /= &quot;none&quot;) then
@@ -63,7 +61,7 @@
          call io_input_init(sfc_update_obj, domain % dminfo)
 
          !     
-         ! We need to decide which time slice to read from the surface file
+         ! We need to decide which time slice to read from the surface file - read the most recent time slice that falls before or on the start time
          !
          sfc_update_obj % time = 1
 
@@ -87,7 +85,7 @@
             do i=1,sfc_update_obj % rdLocalTime
                call MPAS_setTime(curr_time=sliceTime, dateTimeString=xtime % array(i))
                timeDiff = abs(sliceTime - startTime)
-               if (timeDiff &lt; minTimeDiff) then
+               if (sliceTime &lt;= startTime .and. timeDiff &lt; minTimeDiff) then
                   minTimeDiff = timeDiff
                   sfc_update_obj % time = i
                end if
@@ -325,9 +323,11 @@
 
          if (MPAS_isAlarmRinging(clock, restartAlarmID, ierr=ierr)) then
             call MPAS_resetClockAlarm(clock, restartAlarmID, ierr=ierr)
-            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
+
+            ! Write one restart time per file
+            call output_state_init(restart_obj, domain, &quot;RESTART&quot;, trim(timeStamp))
+            call output_state_for_domain(restart_obj, domain, 1)
+            call output_state_finalize(restart_obj, domain % dminfo)
          end if
 
       end do
@@ -470,8 +470,6 @@
       type (domain_type), intent(inout) :: domain 
       integer :: ierr
 
-      if (restart_frame &gt; 1) call output_state_finalize(restart_obj, domain % dminfo)
-
       if (config_sfc_update_interval /= &quot;none&quot;) call io_input_finalize(sfc_update_obj, domain % dminfo)
 
       call MPAS_destroyClock(clock, ierr)

Modified: branches/atmos_physics/src/framework/module_io_input.F
===================================================================
--- branches/atmos_physics/src/framework/module_io_input.F        2011-09-27 23:32:52 UTC (rev 1036)
+++ branches/atmos_physics/src/framework/module_io_input.F        2011-09-27 23:37:40 UTC (rev 1037)
@@ -128,9 +128,17 @@
       type (MPAS_TimeInterval_type) :: timeDiff
       type (MPAS_TimeInterval_type) :: minTimeDiff
       character(len=32) :: timeStamp
+      character(len=1024) :: filename
 
       if (config_do_restart) then
-         input_obj % filename = trim(config_restart_name)
+
+         ! this get followed by set is to ensure that the time is in standard format
+         call MPAS_setTime(curr_time=startTime, dateTimeString=config_start_time)
+         call MPAS_getTime(curr_time=startTime, dateTimeString=timeStamp)
+
+         call insert_string_suffix(trim(config_restart_name), timeStamp, filename)
+
+         input_obj % filename = trim(filename)
          input_obj % stream = STREAM_RESTART
       else
          input_obj % filename = trim(config_input_name)
@@ -772,6 +780,12 @@
                end if
             end do
 
+            ! require restart time to exactly match start time (this error should never be reached as we have by this point opened the restart file with a name containing the startTime)
+            if(sliceTime /= startTime) then
+               write(0,*) &quot;Error: restart file &quot;, filename, &quot; did not contain time &quot;, config_start_time
+               call dmpar_abort(domain % dminfo)
+            end if

             timeStamp = xtime % array(input_obj % time)
 
             deallocate(xtime % ioinfo)
@@ -1003,7 +1017,29 @@
 #endif
    end subroutine input_state_for_domain
 
+   !CR:TODO: an identical subroutine is found in module_io_output - merge
+   subroutine insert_string_suffix(stream, suffix, filename)
 
+      implicit none
+
+      character (len=*), intent(in) :: stream
+      character (len=*), intent(in) :: suffix
+      character (len=*), intent(out) :: filename
+      integer :: length, i
+
+      filename = trim(stream) // '.' // trim(suffix)
+
+      length = len_trim(stream)
+      do i=length-1,1,-1
+         if(stream(i:i) == '.') then
+            filename = trim(stream(:i)) // trim(suffix) // trim(stream(i:))
+            exit
+         end if
+      end do
+
+   end subroutine  insert_string_suffix
+
+
    subroutine read_and_distribute_fields(dminfo, input_obj, block, &amp;
                                      readCellsStart, readCellsCount, &amp;
                                      readEdgesStart, readEdgesCount, &amp;

Modified: branches/atmos_physics/src/framework/module_io_output.F
===================================================================
--- branches/atmos_physics/src/framework/module_io_output.F        2011-09-27 23:32:52 UTC (rev 1036)
+++ branches/atmos_physics/src/framework/module_io_output.F        2011-09-27 23:37:40 UTC (rev 1037)
@@ -94,7 +94,12 @@
          output_obj % filename = trim(tempfilename)
          output_obj % stream = OUTPUT
       else if (trim(stream) == 'RESTART') then
-         output_obj % filename = trim(config_restart_name)
+         if(present(outputSuffix)) then
+            call insert_string_suffix(config_restart_name, outputSuffix, tempfilename)
+         else
+            tempfilename = config_restart_name
+         end if
+         output_obj % filename = trim(tempfilename)
          output_obj % stream = RESTART
       else if (trim(stream) == 'SFC') then
          ! Keep filename as whatever was set by the user

</font>
</pre>