Skip to content

Commit

Permalink
ctsm warm_start mods
Browse files Browse the repository at this point in the history
  • Loading branch information
jtruesdal committed Dec 4, 2024
1 parent a389e6d commit 46015e9
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 66 deletions.
81 changes: 51 additions & 30 deletions src/init_interp/initInterp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,13 @@ subroutine findMinDist( dimname, begi, endi, bego, endo, ncidi, ncido, &
write(iulog,*)'calling set_subgrid_info for ',trim(dimname), ' for input'
end if
call set_subgrid_info(beg=begi, end=endi, dimname=dimname, use_glob=.true., &
ncid=ncidi, active=activei, subgrid=subgridi)
ncid=ncidi, active=activei, subgrid=subgridi, allow_scm=.false.)

if (masterproc) then
write(iulog,*)'calling set_subgrid_info for ',trim(dimname), ' for output'
end if
call set_subgrid_info(beg=bego, end=endo, dimname=dimname, use_glob=.false., &
ncid=ncido, active=activeo, subgrid=subgrido)
ncid=ncido, active=activeo, subgrid=subgrido, allow_scm=.true.)

select case (interp_method)
case (interp_method_general)
Expand Down Expand Up @@ -859,7 +859,7 @@ end subroutine findMinDist

!=======================================================================

subroutine set_subgrid_info(beg, end, dimname, use_glob, ncid, active, subgrid)
subroutine set_subgrid_info(beg, end, dimname, use_glob, ncid, active, subgrid, allow_scm)

! --------------------------------------------------------------------
! arguments
Expand All @@ -869,6 +869,7 @@ subroutine set_subgrid_info(beg, end, dimname, use_glob, ncid, active, subgrid)
logical , intent(in) :: use_glob ! if .true., use the 'glob' form of ncd_io
logical , intent(out) :: active(beg:end)
type(subgrid_type) , intent(inout) :: subgrid
logical , intent(in) :: allow_scm ! if .true., allow single column model subset of data
!
! local variables
integer :: n
Expand Down Expand Up @@ -896,32 +897,32 @@ subroutine set_subgrid_info(beg, end, dimname, use_glob, ncid, active, subgrid)
end if

if (dimname == 'pft') then
call read_var_double(ncid=ncid, varname='pfts1d_lon' , data=subgrid%lon , dim1name='pft', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='pfts1d_lat' , data=subgrid%lat , dim1name='pft', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='pfts1d_itypveg', data=subgrid%ptype, dim1name='pft', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='pfts1d_itypcol', data=subgrid%ctype, dim1name='pft', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='pfts1d_ityplun', data=subgrid%ltype, dim1name='pft', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='pfts1d_active' , data=itemp , dim1name='pft', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='pfts1d_lon' , data=subgrid%lon , dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
call read_var_double(ncid=ncid, varname='pfts1d_lat' , data=subgrid%lat , dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='pfts1d_itypveg', data=subgrid%ptype, dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='pfts1d_itypcol', data=subgrid%ctype, dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='pfts1d_ityplun', data=subgrid%ltype, dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='pfts1d_active' , data=itemp , dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
if (associated(subgrid%topoglc)) then
call read_var_double(ncid=ncid, varname='pfts1d_topoglc', data=subgrid%topoglc, dim1name='pft', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='pfts1d_topoglc', data=subgrid%topoglc, dim1name='pft', use_glob=use_glob, allow_scm=allow_scm)
end if
else if (dimname == 'column') then
call read_var_double(ncid=ncid, varname='cols1d_lon' , data=subgrid%lon , dim1name='column', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='cols1d_lat' , data=subgrid%lat , dim1name='column', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='cols1d_ityp' , data=subgrid%ctype, dim1name='column', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='cols1d_ityplun', data=subgrid%ltype, dim1name='column', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='cols1d_active' , data=itemp , dim1name='column', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='cols1d_lon' , data=subgrid%lon , dim1name='column', use_glob=use_glob, allow_scm=allow_scm)
call read_var_double(ncid=ncid, varname='cols1d_lat' , data=subgrid%lat , dim1name='column', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='cols1d_ityp' , data=subgrid%ctype, dim1name='column', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='cols1d_ityplun', data=subgrid%ltype, dim1name='column', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='cols1d_active' , data=itemp , dim1name='column', use_glob=use_glob, allow_scm=allow_scm)
if (associated(subgrid%topoglc)) then
call read_var_double(ncid=ncid, varname='cols1d_topoglc', data=subgrid%topoglc, dim1name='column', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='cols1d_topoglc', data=subgrid%topoglc, dim1name='column', use_glob=use_glob, allow_scm=allow_scm)
end if
else if (dimname == 'landunit') then
call read_var_double(ncid=ncid, varname='land1d_lon' , data=subgrid%lon , dim1name='landunit', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='land1d_lat' , data=subgrid%lat , dim1name='landunit', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='land1d_ityplun', data=subgrid%ltype, dim1name='landunit', use_glob=use_glob)
call read_var_int(ncid=ncid, varname='land1d_active' , data=itemp , dim1name='landunit', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='land1d_lon' , data=subgrid%lon , dim1name='landunit', use_glob=use_glob, allow_scm=allow_scm)
call read_var_double(ncid=ncid, varname='land1d_lat' , data=subgrid%lat , dim1name='landunit', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='land1d_ityplun', data=subgrid%ltype, dim1name='landunit', use_glob=use_glob, allow_scm=allow_scm)
call read_var_int(ncid=ncid, varname='land1d_active' , data=itemp , dim1name='landunit', use_glob=use_glob, allow_scm=allow_scm)
else if (dimname == 'gridcell') then
call read_var_double(ncid=ncid, varname='grid1d_lon' , data=subgrid%lon , dim1name='gridcell', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='grid1d_lat' , data=subgrid%lat , dim1name='gridcell', use_glob=use_glob)
call read_var_double(ncid=ncid, varname='grid1d_lon' , data=subgrid%lon , dim1name='gridcell', use_glob=use_glob, allow_scm=allow_scm)
call read_var_double(ncid=ncid, varname='grid1d_lat' , data=subgrid%lat , dim1name='gridcell', use_glob=use_glob, allow_scm=allow_scm)

! All gridcells in the restart file are active
itemp(beg:end) = 1
Expand All @@ -942,35 +943,55 @@ subroutine set_subgrid_info(beg, end, dimname, use_glob, ncid, active, subgrid)

contains

subroutine read_var_double(ncid, varname, data, dim1name, use_glob)
subroutine read_var_double(ncid, varname, data, dim1name, use_glob, allow_scm)
! Wraps the ncd_io call, providing logic related to whether we're using the 'glob'
! form of ncd_io
type(file_desc_t) , intent(inout) :: ncid
character(len=*) , intent(in) :: varname
real(r8), pointer , intent(inout) :: data(:)
character(len=*) , intent(in) :: dim1name
logical , intent(in) :: use_glob ! if .true., use the 'glob' form of ncd_io
logical , intent(in) :: allow_scm ! if .true., use the 'glob' form of ncd_io

! local
character(16) :: readflag

if (allow_scm) then
readflag='read'
else
readflag='read_noscm'
endif

if (use_glob) then
call ncd_io(ncid=ncid, varname=varname, flag='read', data=data)
call ncd_io(ncid=ncid, varname=varname, flag=trim(readflag), data=data)
else
call ncd_io(ncid=ncid, varname=varname, flag='read', data=data, dim1name=dim1name)
call ncd_io(ncid=ncid, varname=varname, flag=trim(readflag), data=data, dim1name=dim1name)
end if
end subroutine read_var_double

subroutine read_var_int(ncid, varname, data, dim1name, use_glob)
subroutine read_var_int(ncid, varname, data, dim1name, use_glob, allow_scm)
! Wraps the ncd_io call, providing logic related to whether we're using the 'glob'
! form of ncd_io
type(file_desc_t) , intent(inout) :: ncid
character(len=*) , intent(in) :: varname
integer, pointer , intent(inout) :: data(:)
character(len=*) , intent(in) :: dim1name
logical , intent(in) :: use_glob ! if .true., use the 'glob' form of ncd_io
logical , intent(in) :: allow_scm ! if .true., allow scm data slice

! local
character(16) :: readflag

if (allow_scm) then
readflag='read'
else
readflag='read_noscm'
endif

if (use_glob) then
call ncd_io(ncid=ncid, varname=varname, flag='read', data=data)
call ncd_io(ncid=ncid, varname=varname, flag=trim(readflag), data=data)
else
call ncd_io(ncid=ncid, varname=varname, flag='read', data=data, dim1name=dim1name)
call ncd_io(ncid=ncid, varname=varname, flag=trim(readflag), data=data, dim1name=dim1name)
end if
end subroutine read_var_int

Expand Down Expand Up @@ -1038,7 +1059,7 @@ subroutine interp_1d_double (varname, varname_i, dimname, begi, endi, bego, endo
end if

allocate (rbufsli(begi:endi), rbufslo(bego:endo))
call ncd_io(ncid=ncidi, varname=trim(varname_i), flag='read', data=rbufsli)
call ncd_io(ncid=ncidi, varname=trim(varname_i), flag='read_noscm', data=rbufsli)
call ncd_io(ncid=ncido, varname=trim(varname), flag='read', data=rbufslo, &
dim1name=dimname)

Expand Down Expand Up @@ -1080,7 +1101,7 @@ subroutine interp_1d_int (varname, varname_i, dimname, begi, endi, bego, endo, n

allocate (ibufsli(begi:endi), ibufslo(bego:endo))

call ncd_io(ncid=ncidi, varname=trim(varname_i), flag='read', &
call ncd_io(ncid=ncidi, varname=trim(varname_i), flag='read_noscm', &
data=ibufsli)
call ncd_io(ncid=ncido, varname=trim(varname), flag='read', &
data=ibufslo, dim1name=dimname)
Expand Down
2 changes: 1 addition & 1 deletion src/init_interp/initInterpMultilevelContainer.F90
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ subroutine create_snow_interpolators(interp_multilevel_levsno, interp_multilevel

! Read snlsno_source_sgrid
allocate(snlsno_source_sgrid(bounds_source%get_begc() : bounds_source%get_endc()))
call ncd_io(ncid=ncid_source, varname='SNLSNO', flag='read', &
call ncd_io(ncid=ncid_source, varname='SNLSNO', flag='read_noscm', &
data=snlsno_source_sgrid)
snlsno_source_sgrid(:) = abs(snlsno_source_sgrid(:))

Expand Down
8 changes: 4 additions & 4 deletions src/main/histFileMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5068,9 +5068,9 @@ subroutine hist_restart_ncd (bounds, ncid, flag, rdate)
end if

call ncd_io(ncid=ncid_hist(t), flag='read', varname=trim(name), &
dim1name=type1d_out, data=hbuf1d)
dim1name=type1d_out, data=hbuf1d, posNOTonfile=.true.)
call ncd_io(ncid=ncid_hist(t), flag='read', varname=trim(name_acc), &
dim1name=type1d_out, data=nacs1d)
dim1name=type1d_out, data=nacs1d, posNOTonfile=.true.)

hbuf(beg1d_out:end1d_out,1) = hbuf1d(beg1d_out:end1d_out)
nacs(beg1d_out:end1d_out,1) = nacs1d(beg1d_out:end1d_out)
Expand All @@ -5079,9 +5079,9 @@ subroutine hist_restart_ncd (bounds, ncid, flag, rdate)
deallocate(nacs1d)
else
call ncd_io(ncid=ncid_hist(t), flag='read', varname=trim(name), &
dim1name=type1d_out, data=hbuf)
dim1name=type1d_out, data=hbuf, posNOTonfile=.true.)
call ncd_io(ncid=ncid_hist(t), flag='read', varname=trim(name_acc), &
dim1name=type1d_out, data=nacs)
dim1name=type1d_out, data=nacs, posNOTonfile=.true.)
end if
end do

Expand Down
Loading

0 comments on commit 46015e9

Please sign in to comment.