-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix QC test, fix bug in history time axis, fix history output averaging for timestep output #624
Changes from 9 commits
441f693
15763d8
b3364a6
96d5851
7b5c2b4
c5794b4
eaa3c3a
e31ce7e
83068c7
3fd897e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1758,6 +1758,7 @@ subroutine accum_hist (dt) | |
nstrm ! nstreams (1 if writing initial condition) | ||
|
||
real (kind=dbl_kind) :: & | ||
timedbl , & ! temporary dbl for time bounds | ||
ravgct , & ! 1/avgct | ||
ravgctz ! 1/avgct | ||
|
||
|
@@ -1814,7 +1815,7 @@ subroutine accum_hist (dt) | |
n4Dfcum = n4Dscum + num_avail_hist_fields_4Df ! should equal num_avail_hist_fields_tot | ||
|
||
do ns = 1,nstreams | ||
if (.not. hist_avg .or. histfreq(ns) == '1') then ! write snapshots | ||
if (.not. hist_avg) then ! write snapshots | ||
do n = 1,n2D | ||
if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) & | ||
a2D(:,:,n,:) = c0 | ||
|
@@ -1862,11 +1863,10 @@ subroutine accum_hist (dt) | |
avgct(ns) = c1 | ||
else ! write averages over time histfreq | ||
avgct(ns) = avgct(ns) + c1 | ||
! if (avgct(ns) == c1) time_beg(ns) = (time-dt)/int(secday) | ||
if (avgct(ns) == c1) then | ||
time_beg(ns) = (timesecs-dt)/int(secday) | ||
time_beg(ns) = real(time_beg(ns),kind=real_kind) | ||
endif | ||
endif | ||
if (avgct(ns) == c1) then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this just initializes timedbl and time_beg at the beginning of the averaging interval? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct. and timedbl is just a temporary local to make going from double to single a little cleaner. time_beg is now initialized whenever hist_avg is on because we should assume it might be written to the history file when hist_avg is on, even for histfreq='1' and histfreq_n=1. This moves away from treating histfreq='1' and histfreq_n=1 as special cases which allows for averaging across timesteps (histfreq='1') and allows a user to cleanly set hist_avg to true even if histfreq_n=1. |
||
timedbl = (timesecs-dt)/(secday) | ||
time_beg(ns) = real(timedbl,kind=real_kind) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could do without time_beg(ns) = real((timesecs-dt)/(secday), kind=real_kind) Is there any reason that I'm missing why we need a separate variable ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We absolutely could implement what you propose. |
||
endif | ||
enddo | ||
|
||
|
@@ -3966,8 +3966,8 @@ subroutine accum_hist (dt) | |
enddo ! iblk | ||
!$OMP END PARALLEL DO | ||
|
||
time_end(ns) = timesecs/int(secday) | ||
time_end(ns) = real(time_end(ns),kind=real_kind) | ||
timedbl = timesecs/secday | ||
time_end(ns) = real(timedbl,kind=real_kind) | ||
|
||
!--------------------------------------------------------------- | ||
! write file | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -672,64 +672,67 @@ subroutine construct_filename(ncfile,suffix,ns) | |
iday = mday | ||
isec = msec - dt | ||
|
||
if (write_ic) isec = msec | ||
! construct filename | ||
if (write_ic) then | ||
isec = msec | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
incond_file(1:lenstr(incond_file)),'.',iyear,'-', & | ||
imonth,'-',iday,'-',isec,'.',suffix | ||
imonth,'-',iday,'-',isec,'.',trim(suffix) | ||
else | ||
|
||
if (hist_avg .and. histfreq(ns) /= '1') then | ||
if (histfreq(ns) == 'h'.or.histfreq(ns) == 'H') then | ||
! do nothing | ||
elseif (new_year) then | ||
iyear = iyear - 1 | ||
imonth = 12 | ||
iday = daymo(imonth) | ||
elseif (new_month) then | ||
imonth = mmonth - 1 | ||
iday = daymo(imonth) | ||
elseif (new_day) then | ||
iday = iday - 1 | ||
endif | ||
endif | ||
|
||
cstream = '' | ||
if (hist_avg) then | ||
if (histfreq(ns) == '1' .or. histfreq(ns) == 'h'.or.histfreq(ns) == 'H') then | ||
! do nothing | ||
elseif (new_year) then | ||
iyear = iyear - 1 | ||
imonth = 12 | ||
iday = daymo(imonth) | ||
elseif (new_month) then | ||
imonth = mmonth - 1 | ||
iday = daymo(imonth) | ||
elseif (new_day) then | ||
iday = iday - 1 | ||
endif | ||
endif | ||
Comment on lines
+683
to
+696
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I looked at this code in the context of #551, I did not readily understand why we have to do those substractions here, and why we do not have to do any if histfreq = 1 or h... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all part of a rather complex interaction between dates and history frequencies with a certain amount of assumption built-in. Basically, if you are doing annual, monthly, or daily averages, the history will be written on the "new_flag". At that point, you're in the next year, month, or day. So you subtract "1" so when you construct the filename, the name is associated with the year, month, or day being averaged. Of course, all this comes unglued if the histfreq_n is not 1 in terms of the filename. The instantaneous stuff and histfreq='1' just writes out a file with the current date in it because there isn't a general way to create a meaningful filename. Most of what I did tried to preserve what's there and expand how it works. There are many things that could be further improved. |
||
|
||
cstream = '' | ||
!echmod ! this was implemented for CESM but it breaks post-processing software | ||
!echmod ! of other groups (including RASM which uses CESMCOUPLED) | ||
!echmod if (ns > 1) write(cstream,'(i1.1)') ns-1 | ||
Comment on lines
+698
to
701
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these lines (setting an empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about removing the cstream but they aren't hurting anyone and I wasn't sure whether maybe some coupled system was using them, so I left them in. We could/should think about removing it, but we'd want to ask outside users whether they are using it. |
||
|
||
if (histfreq(ns) == '1') then ! instantaneous, write every dt | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', & | ||
iyear,'-',imonth,'-',iday,'-',msec,'.',suffix | ||
|
||
elseif (hist_avg) then ! write averaged data | ||
|
||
if (histfreq(ns) == 'd'.or.histfreq(ns) == 'D') then ! daily | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream), & | ||
'.',iyear,'-',imonth,'-',iday,'.',suffix | ||
elseif (histfreq(ns) == 'h'.or.histfreq(ns) == 'H') then ! hourly | ||
write(ncfile,'(a,a,i2.2,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'_', & | ||
histfreq_n(ns),'h.',iyear,'-',imonth,'-',iday,'-',msec,'.',suffix | ||
elseif (histfreq(ns) == 'm'.or.histfreq(ns) == 'M') then ! monthly | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'.', & | ||
iyear,'-',imonth,'.',suffix | ||
elseif (histfreq(ns) == 'y'.or.histfreq(ns) == 'Y') then ! yearly | ||
write(ncfile,'(a,a,i4.4,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'.', & | ||
iyear,'.',suffix | ||
endif | ||
if (hist_avg) then ! write averaged data | ||
if (histfreq(ns) == '1' .and. histfreq_n(ns) == 1) then ! timestep | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', & | ||
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix) | ||
Comment on lines
+704
to
+707
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand why we need a separate else ! instantaneous line at the end of the subroutine ? I guess the idea is that someone might have hist_avg = true and histfreq =1 and histfreq_n = 1, and in this case we ignore hist_avg (since there is nothing to average) and write instantaneous output instead ? I'm wondering if it might be more useful to catch that early in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With multiple history streams and a single hist_avg variable, we do not want to change hist_avg to false if one of the streams has histfreq='1' and histfreq_n=1. A future goal would be to make hist_avg an array as Dave suggested then we have more options. |
||
elseif (histfreq(ns) == '1' .and. histfreq_n(ns) > 1) then ! timestep | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'.', & | ||
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix) | ||
elseif (histfreq(ns) == 'h'.or.histfreq(ns) == 'H') then ! hourly | ||
write(ncfile,'(a,a,i2.2,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'_', & | ||
histfreq_n(ns),'h.',iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix) | ||
elseif (histfreq(ns) == 'd'.or.histfreq(ns) == 'D') then ! daily | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'.', & | ||
iyear,'-',imonth,'-',iday,'.',trim(suffix) | ||
elseif (histfreq(ns) == 'm'.or.histfreq(ns) == 'M') then ! monthly | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'.', & | ||
iyear,'-',imonth,'.',trim(suffix) | ||
elseif (histfreq(ns) == 'y'.or.histfreq(ns) == 'Y') then ! yearly | ||
write(ncfile,'(a,a,i4.4,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'.', & | ||
iyear,'.',trim(suffix) | ||
endif | ||
|
||
else ! instantaneous | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file))//trim(cstream),'_inst.', & | ||
iyear,'-',imonth,'-',iday,'-',msec,'.',trim(suffix) | ||
endif | ||
|
||
else ! instantaneous with histfreq > dt | ||
write(ncfile,'(a,a,i4.4,a,i2.2,a,i2.2,a,i5.5,a,a)') & | ||
history_file(1:lenstr(history_file)),'_inst.', & | ||
iyear,'-',imonth,'-',iday,'-',msec,'.',suffix | ||
endif | ||
endif | ||
|
||
end subroutine construct_filename | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, I would like hist_avg to be an array of size nstreams. Then we can control the instantaneous versus average on a stream by stream basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, I will make sure that's part of an issue.