<p><b>mhoffman@lanl.gov</b> 2013-03-08 15:21:26 -0700 (Fri, 08 Mar 2013)</p><p>BRANCH COMMIT - land ice<br>
<br>
Adjustment to my previous commit on how to handle writing output for the initial time level.  This commit fixes things so that the time stamp on the output file (if there is one) always matches the first time level contained in the file.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/land_ice_projects/implement_core/src/core_land_ice/mpas_land_ice_mpas_core.F
===================================================================
--- branches/land_ice_projects/implement_core/src/core_land_ice/mpas_land_ice_mpas_core.F        2013-03-08 22:10:40 UTC (rev 2574)
+++ branches/land_ice_projects/implement_core/src/core_land_ice/mpas_land_ice_mpas_core.F        2013-03-08 22:21:26 UTC (rev 2575)
@@ -305,7 +305,6 @@
       integer, intent(inout) :: output_frame
 
       integer :: itimestep
-      integer :: ioutputfile   ! A counter for how many output files have been generated.
       type (block_type), pointer :: block_ptr
 
       type (MPAS_Time_Type) :: currTime
@@ -316,12 +315,14 @@
       currTime = mpas_get_clock_time(clock, MPAS_NOW, ierr)
       call mpas_get_time(curr_time=currTime, dateTimeString=timeStamp, ierr=ierr)         
 
-      ioutputfile = 1 ! We always start with a file open because framework opens the first output file
 
       if (config_write_output_on_startup) then
          call mpas_timer_start(&quot;write output frame&quot;)
-         call write_output_frame(output_obj, output_frame, ioutputfile, domain)
+         call write_output_frame(output_obj, output_frame, domain)
          call mpas_timer_stop(&quot;write output frame&quot;)
+      elseif (config_frames_per_outfile /= 0) then
+         ! if we are not writing on startup then close the already open file since it will have a confusing time stamp (the time stamp would be the inital time, but the intial time is not present in the file!)
+         call mpas_output_state_finalize(output_obj, domain % dminfo)
       endif
 
       ! During integration, time level 1 stores the model state at the beginning of the
@@ -358,14 +359,12 @@
             call mpas_timer_start(&quot;write output&quot;)
             call mpas_reset_clock_alarm(clock, outputAlarmID, ierr=ierr)
             ! output_frame will always be &gt; 1 here unless it was reset after the maximum number of frames per outfile was reached
-            ! if output_frame == 1 we may need to init a new output file, but only under certain circumstances
-            !    If config_frames_per_outfile is 0 then we never need to do this because there is only one output file for the whole run
-            !    We also don't need to do this on the first file of the simulation because that file is inited by default in framework
-            !    Therefore we need to check if we are on the first file or not (using the counter variable ioutputfile).
-            if ( (output_frame == 1) .and. (config_frames_per_outfile /= 0) .and. (ioutputfile &gt; 1) ) then 
+            ! If output_frame == 1 we may need to init a new output file, but only if config_frames_per_outfile is not 0.
+            ! If config_frames_per_outfile is 0 then we never need to do this because there is only one output file for the whole run
+            if ( (output_frame == 1) .and. (config_frames_per_outfile /= 0) ) then 
                call mpas_output_state_init(output_obj, domain, &quot;OUTPUT&quot;, trim(timeStamp))
             end if
-            call write_output_frame(output_obj, output_frame, ioutputfile, domain)
+            call write_output_frame(output_obj, output_frame, domain)
             call mpas_timer_stop(&quot;write output&quot;)
          end if
 
@@ -386,7 +385,7 @@
    end subroutine mpas_core_run
    
    
-   subroutine write_output_frame(output_obj, output_frame, ioutputfile, domain)
+   subroutine write_output_frame(output_obj, output_frame, domain)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ! Compute diagnostic fields for a domain and write model state to output file
    !
@@ -401,7 +400,6 @@
 
       type (io_output_object), intent(inout) :: output_obj
       integer, intent(inout) :: output_frame
-      integer, intent(inout) :: ioutputfile
       type (domain_type), intent(inout) :: domain
    
       integer :: i, j, k
@@ -424,7 +422,6 @@
             call mpas_output_state_finalize(output_obj, domain % dminfo)
             current_outfile_frames = 0
             output_frame = 1
-            ioutputfile = ioutputfile + 1
          end if
       end if
 

</font>
</pre>