Skip to content

Commit

Permalink
move standard deviation to restart loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Courtney Peverley committed Jul 31, 2024
1 parent bfe40be commit 7d240af
Showing 1 changed file with 71 additions and 20 deletions.
91 changes: 71 additions & 20 deletions src/control/cam_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4690,7 +4690,6 @@ subroutine h_define (t, restart)
num_hdims = 2
do i = 1, num_hdims
dimindex(i) = header_info(1)%get_hdimid(i)
nacsdims(i) = header_info(1)%get_hdimid(i)
end do
else if (patch_output) then
! All patches for this variable should be on the same grid
Expand All @@ -4716,30 +4715,29 @@ subroutine h_define (t, restart)
num_hdims = header_info(grd)%num_hdims()
do i = 1, num_hdims
dimindex(i) = header_info(grd)%get_hdimid(i)
nacsdims(i) = header_info(grd)%get_hdimid(i)
end do
end if ! is_satfile

!
! Create variables and atributes for fields written out as columns
!

dimids_tmp = dimindex
! Figure the dimension ID array for this field
! We have defined the horizontal grid dimensions in dimindex
fdims = num_hdims
do j = 1, mdimsize
fdims = fdims + 1
dimids_tmp(fdims) = mdimids(mdims(j))
end do
if(.not. restart) then
! Only add time dimension if this is not a restart history tape
fdims = fdims + 1
dimids_tmp(fdims) = timdim
end if
fname_tmp = strip_suffix(tape(t)%hlist(fld)%field%name)
do i = 1, num_patches
fname_tmp = strip_suffix(tape(t)%hlist(fld)%field%name)
varid => tape(t)%hlist(fld)%varid(i)
dimids_tmp = dimindex
! Figure the dimension ID array for this field
! We have defined the horizontal grid dimensions in dimindex
fdims = num_hdims
do j = 1, mdimsize
fdims = fdims + 1
dimids_tmp(fdims) = mdimids(mdims(j))
end do
if(.not. restart) then
! Only add time dimension if this is not a restart history tape
fdims = fdims + 1
dimids_tmp(fdims) = timdim
end if
if (patch_output) then
! For patch output, we need new dimension IDs and a different name
call tape(t)%patches(i)%get_var_data(fname_tmp, &
Expand Down Expand Up @@ -4832,9 +4830,61 @@ subroutine h_define (t, restart)
tape(t)%hlist(fld)%field%name)
call cam_pio_handle_error(ierr, &
'h_define: cannot define basename for '//trim(fname_tmp))
end if
end if
end do ! Loop over output patches
if (restart) then
end do ! Loop over fields
if (restart) then
do fld = 1, nflds(t)
if(is_satfile(t)) then
num_hdims=0
else if (interpolate) then
! Interpolate can't use normal grid code since we are forcing fields
! to use interpolate decomp
if (.not. allocated(header_info)) then
! Safety check
call endrun('h_define: header_info not allocated')
end if
num_hdims = 2
do i = 1, num_hdims
nacsdims(i) = header_info(1)%get_hdimid(i)
dimindex(i) = header_info(1)%get_hdimid(i)
end do
else if (patch_output) then
! All patches for this variable should be on the same grid
num_hdims = tape(t)%patches(1)%num_hdims(tape(t)%hlist(fld)%field%decomp_type)
else
! Normal grid output
! Find appropriate grid in header_info
if (.not. allocated(header_info)) then
! Safety check
call endrun('h_define: header_info not allocated')
end if
grd = -1
do i = 1, size(header_info)
if (header_info(i)%get_gridid() == tape(t)%hlist(fld)%field%decomp_type) then
grd = i
exit
end if
end do
if (grd < 0) then
write(errormsg, '(a,i0,2a)') 'grid, ',tape(t)%hlist(fld)%field%decomp_type,', not found for ',trim(fname_tmp)
call endrun('H_DEFINE: '//errormsg)
end if
num_hdims = header_info(grd)%num_hdims()
do i = 1, num_hdims
nacsdims(i) = header_info(grd)%get_hdimid(i)
dimindex(i) = header_info(grd)%get_hdimid(i)
end do
end if ! is_satfile

dimids_tmp = dimindex
! Figure the dimension ID array for this field
! We have defined the horizontal grid dimensions in dimindex
fdims = num_hdims
do j = 1, mdimsize
fdims = fdims + 1
dimids_tmp(fdims) = mdimids(mdims(j))
end do
fname_tmp = strip_suffix(tape(t)%hlist(fld)%field%name)
! For restart history files, we need to save accumulation counts
fname_tmp = trim(fname_tmp)//'_nacs'
Expand All @@ -4859,8 +4909,9 @@ subroutine h_define (t, restart)
call cam_pio_def_var(tape(t)%Files(f), trim(fname_tmp), pio_double, &
dimids_tmp(1:fdims), tape(t)%hlist(fld)%sbuf_varid)
endif
end if ! is restart
end do ! Loop over fields

end do ! Loop over fields
end if
!
deallocate(mdimids)
ret = pio_enddef(tape(t)%Files(f))
Expand Down

0 comments on commit 7d240af

Please sign in to comment.