Skip to content
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

Output downscaled glacier data in cpl glc hist file #441

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions mediator/med_phases_history_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,20 @@ subroutine med_phases_history_write_med(gcomp, rc)
end subroutine med_phases_history_write_med

!===============================================================================
subroutine med_phases_history_write_lnd2glc(gcomp, fldbun, rc)
subroutine med_phases_history_write_lnd2glc(gcomp, fldbun_lnd, rc, fldbun_glc)

! Write yearly average of lnd -> glc fields
! Write yearly average of lnd -> glc fields on both land and glc grids

use med_internalstate_mod, only : complnd
use med_internalstate_mod, only : complnd, compglc
use med_constants_mod , only : SecPerDay => med_constants_SecPerDay
use med_io_mod , only : med_io_write_time, med_io_define_time
use med_io_mod , only : med_io_date2yyyymmdd, med_io_sec2hms, med_io_ymd2date

! input/output variables
type(ESMF_GridComp) , intent(in) :: gcomp
type(ESMF_FieldBundle) , intent(in) :: fldbun
type(ESMF_FieldBundle) , intent(in) :: fldbun_lnd
integer , intent(out) :: rc
type(ESMF_FieldBundle) , intent(in), optional :: fldbun_glc(:)

! local variables
type(file_desc_t) :: io_file
Expand All @@ -546,7 +547,7 @@ subroutine med_phases_history_write_lnd2glc(gcomp, fldbun, rc)
real(r8) :: time_val ! time coordinate output
real(r8) :: time_bnds(2) ! time bounds output
character(len=CL) :: hist_file
integer :: m
integer :: m,n
logical :: isPresent
character(len=*), parameter :: subname='(med_phases_history_write_lnd2glc)'
!---------------------------------------
Expand Down Expand Up @@ -619,9 +620,21 @@ subroutine med_phases_history_write_lnd2glc(gcomp, fldbun, rc)
call med_io_write_time(io_file, time_val, time_bnds, nt=1, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
call med_io_write(io_file, fldbun, whead(m), wdata(m), is_local%wrap%nx(complnd), is_local%wrap%ny(complnd), &

call med_io_write(io_file, fldbun_lnd, whead(m), wdata(m), &
is_local%wrap%nx(complnd), is_local%wrap%ny(complnd), &
nt=1, pre=trim(compname(complnd))//'Imp', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (present(fldbun_glc)) then
do n = 1,size(fldbun_glc)
call med_io_write(io_file, fldbun_glc(n), whead(m), wdata(m), &
is_local%wrap%nx(compglc(n)), is_local%wrap%ny(compglc(n)), &
nt=1, pre=trim(compname(compglc(n)))//'Exp', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end do
end if

end do ! end of loop over m

! Close history file
Expand Down
40 changes: 24 additions & 16 deletions mediator/med_phases_prep_glc_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -632,22 +632,6 @@ subroutine med_phases_prep_glc_avg(gcomp, rc)
end if
end do

! Write auxiliary history file if flag is set and accumulation is being done
if (lndAccum2glc_cnt > 0) then
call NUOPC_CompAttributeGet(gcomp, name="histaux_l2x1yrg", value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) write_histaux_l2x1yrg
else
write_histaux_l2x1yrg = .false.
end if
if (write_histaux_l2x1yrg) then
call med_phases_history_write_lnd2glc(gcomp, FBlndAccum2glc_l, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
end if

if (is_local%wrap%ocn2glc_coupling) then
! Average import from accumulated ocn import data
do n = 1, size(fldnames_fr_ocn)
Expand Down Expand Up @@ -688,15 +672,39 @@ subroutine med_phases_prep_glc_avg(gcomp, rc)
if (chkErr(rc,__LINE__,u_FILE_u)) return
end if

! Determine if auxiliary file will be written
write_histaux_l2x1yrg = .false.
if (lndAccum2glc_cnt > 0) then
call NUOPC_CompAttributeGet(gcomp, name="histaux_l2x1yrg", value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) write_histaux_l2x1yrg
end if
end if

! Write auxiliary history file if flag is set and accumulation is being done
if (is_local%wrap%lnd2glc_coupling) then
! Map accumulated field bundle from land grid (with elevation classes) to glc grid (without elevation classes)
! and set FBExp(compglc(ns)) data
! Zero land accumulator and accumulated field bundles on land grid
call med_phases_prep_glc_map_lnd2glc(gcomp, rc)
if (chkErr(rc,__LINE__,u_FILE_u)) return

if (write_histaux_l2x1yrg) then
call med_phases_history_write_lnd2glc(gcomp, FBlndAccum2glc_l, &
fldbun_glc=is_local%wrap%FBExp(compglc(:)), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

lndAccum2glc_cnt = 0
call fldbun_reset(FBlndAccum2glc_l, value=czero, rc=rc)
if (chkErr(rc,__LINE__,u_FILE_u)) return
else
if (write_histaux_l2x1yrg) then
call med_phases_history_write_lnd2glc(gcomp, FBlndAccum2glc_l, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
end if

if (dbug_flag > 1) then
Expand Down
Loading