Skip to content

Commit

Permalink
Merge pull request #7 from kdraeder/revert-5-cpl_hist_zeros
Browse files Browse the repository at this point in the history
Revert "Cpl hist zeros"
  • Loading branch information
kdraeder authored Dec 17, 2018
2 parents f0a58df + e7067c3 commit 2a7a98a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 55 deletions.
5 changes: 2 additions & 3 deletions src/drivers/mct/main/cime_comp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3765,15 +3765,14 @@ subroutine cime_run()
if (do_hist_a2x24hr) then
do eai = 1,num_inst_atm
inst_suffix = component_get_suffix(atm(eai))
write_hist_alarm = t24hr_alarm .or. stop_alarm
if (trim(hist_a2x24hr_flds) == 'all') then
call seq_hist_writeaux(infodata, EClock_d, atm(eai), flow='c2x', &
aname='a2x1d',dname='doma',inst_suffix=trim(inst_suffix), &
nx=atm_nx, ny=atm_ny, nt=1, write_now=write_hist_alarm)
nx=atm_nx, ny=atm_ny, nt=1, write_now=t24hr_alarm)
else
call seq_hist_writeaux(infodata, EClock_d, atm(eai), flow='c2x', &
aname='a2x1d',dname='doma',inst_suffix=trim(inst_suffix), &
nx=atm_nx, ny=atm_ny, nt=1, write_now=write_hist_alarm, flds=hist_a2x24hr_flds)
nx=atm_nx, ny=atm_ny, nt=1, write_now=t24hr_alarm, flds=hist_a2x24hr_flds)
endif
enddo
endif
Expand Down
64 changes: 12 additions & 52 deletions src/drivers/mct/main/seq_hist_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,6 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_
integer(IN) :: curr_tod ! Current time-of-day (s)
integer(IN) :: start_ymd ! Starting date YYYYMMDD
integer(IN) :: start_tod ! Starting time-of-day (s)
integer(IN) :: stop_ymd ! Stopping date YYYYMMDD
integer(IN) :: stop_tod ! Stopping time-of-day (s)

real(r8) :: curr_time ! Time interval since reference time
real(r8) :: prev_time ! Time interval since reference time
real(r8) :: avg_time ! Average time for time average
Expand All @@ -1042,22 +1039,19 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_
integer(IN) :: found = -10
logical :: useavg
logical :: use_double ! if true, use double-precision
logical :: use_stop_date ! use the stop date instead of current for runs < 24 hours.
logical :: lwrite_now
logical :: whead, wdata ! for writing restart/history cdf files
real(r8) :: tbnds(2)
character(len=16) :: date_str

! This routine keeps track of information about ALL the aux hist files,
! of which there can be maxout. See the save attribute.
integer(IN), parameter :: maxout = 20 ! number of history files this can handle
integer(IN) , save :: ntout = 0 ! counter of the hist files?
character(CS) , save :: tname(maxout) = 'x1y2z3' ! switch-name to compare against the aname passed in
integer(IN) , save :: ncnt(maxout) = -10 ! number of times written to each hist file so far
character(CL) , save :: hist_file(maxout) ! local paths to history filenames
integer(IN), parameter :: maxout = 20
integer(IN) , save :: ntout = 0
character(CS) , save :: tname(maxout) = 'x1y2z3'
integer(IN) , save :: ncnt(maxout) = -10
character(CL) , save :: hist_file(maxout) ! local path to history filename
type(mct_aVect) , save :: avavg(maxout) ! av accumulator if needed
integer(IN) , save :: avcnt(maxout) = 0 ! accumulator counter
logical , save :: fwrite(maxout) = .true. ! first write of each file
logical , save :: fwrite(maxout) = .true. ! first write
real(r8) , save :: tbnds1(maxout) ! first time_bnds
real(r8) , save :: tbnds2(maxout) ! second time_bnds

Expand Down Expand Up @@ -1086,38 +1080,15 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_
lwrite_now = write_now
endif

! Get the forecast end date+time to make the right file names for the history files.
call seq_timemgr_EClockGetData( EClock_d, &
curr_ymd=curr_ymd, &
curr_tod=curr_tod, &
start_ymd=start_ymd, &
start_tod=start_tod, &
curr_time=curr_time, &
prev_time=prev_time, &
stop_ymd=stop_ymd, &
stop_tod=stop_tod, &
calendar=calendar)

use_stop_date = (stop_ymd - curr_ymd) == 0 .or. &
((stop_ymd - curr_ymd) == 1 .and. stop_tod == 0)
! Having the right number of samples results in correct data being written to each file.
! Ignores 3, (4,) 12 hour forecasts. All of my fixes ignore 1 hour forecasts (WACCMX).
! Ignores other flows; l2x, x2a, ...
! Something like this may belong in the calling routine.
if (use_stop_date) then
if ( aname == 'a2x1h' .or. aname == 'a2x1hi') then
samples_per_file = 6
else if (aname == 'a2x3h' .or. aname == 'a2x3h_prec') then
samples_per_file = 2
else if (aname == 'a2x1d' .or. aname == 'r2x' ) then
samples_per_file = 1
endif
else
samples_per_file = nt
endif
write(logunit, *) 'seq_hist_writeaux stop_{ymd,tod}, use_stop_date, samples = ', &
stop_ymd, stop_tod, use_stop_date, samples_per_file

first_call = .true.
do n = 1, ntout
if (trim(tname(n)) == trim(aname)) then
Expand All @@ -1143,7 +1114,7 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_
if (first_call) then
ntout = ntout + 1
if (ntout > maxout) then
write(logunit, *) 'seq_hist_writeaux maxout exceeded', ntout, maxout
write(logunit, *) 'write_history_writeaux maxout exceeded', ntout, maxout
call shr_sys_abort()
endif
tname(ntout) = trim(aname)
Expand All @@ -1160,6 +1131,8 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_

if (iamin_CPLID) then !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

samples_per_file = nt

if (useavg) then
if (lwrite_now) then
avcnt(found) = avcnt(found) + 1
Expand All @@ -1186,25 +1159,12 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_
if (ncnt(found) == 1) then
fk1 = 1
call seq_infodata_GetData( infodata, case_name=case_name)

! If the stop time is in the same day as the current time,
! use stop time in the history file name.
if (use_stop_date) then
call shr_cal_date2ymd(stop_ymd, yy, mm, dd)
else
call shr_cal_date2ymd(curr_ymd, yy, mm, dd)
endif
call shr_cal_date2ymd(curr_ymd, yy, mm, dd)

if (present(yr_offset)) then
yy = yy + yr_offset
end if

if (use_stop_date) then
call shr_cal_ymdtod2string(date_str, yy, mm, dd, stop_tod)
else
call shr_cal_ymdtod2string(date_str, yy, mm, dd, 0)
endif

call shr_cal_ymdtod2string(date_str, yy, mm, dd, curr_tod)
write(hist_file(found), "(8a)") &
trim(case_name),'.cpl',trim(inst_suffix),'.h',trim(aname),'.',trim(date_str), '.nc'
else
Expand Down Expand Up @@ -1310,7 +1270,7 @@ subroutine seq_hist_writeaux(infodata, EClock_d, comp, flow, aname, dname, inst_

enddo ! fk=1,2

if (ncnt(found) == samples_per_file) then
if (ncnt(found) == nt) then
call seq_io_close(hist_file(found), file_ind=found)
end if
if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
Expand Down

0 comments on commit 2a7a98a

Please sign in to comment.