Skip to content

Commit

Permalink
Addressing more initial review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Katetc committed Jan 30, 2024
1 parent a019b23 commit 544e33c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cime_config/testdefs/testmods_dirs/cam/silhs/user_nl_cam
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fincl1 = 'U:A','PS:A','T:A','V:A','OMEGA:A','Z3:A','PRECT:A',
'rtp2_dp2', 'rtp2_cl', 'rtp2_pd', 'rtp2_sf', 'rtp2_forcing', 'rtp2_mc', 'thlp2_bt', 'thlp2_ma', 'thlp2_ta', 'thlp2_tp', 'thlp2_dp1', 'thlp2_dp2', 'thlp2_cl',
'thlp2_pd', 'thlp2_sf', 'thlp2_forcing', 'thlp2_mc', 'rtpthlp_bt', 'rtpthlp_ma', 'rtpthlp_ta', 'rtpthlp_tp1', 'rtpthlp_tp2', 'rtpthlp_dp1', 'rtpthlp_dp2',
'rtpthlp_cl', 'rtpthlp_sf', 'rtpthlp_forcing', 'rtpthlp_mc', 'wpthlp_enter_mfl', 'wpthlp_exit_mfl', 'wprtp_enter_mfl', 'wprtp_exit_mfl', 'wpthlp_mfl_min',
'wpthlp_mfl_max', 'wprtp_mfl_min', 'wprtp_mfl_max', 'shear_sqd',
'wpthlp_mfl_max', 'wprtp_mfl_min', 'wprtp_mfl_max', 'shear_sqd', 'Ri_zm'
fincl2 = 'CLDTOT', 'CLDST','CDNUMC','CLDLIQ','CLDICE','FLUT',
'LWCF','SWCF','PRECT'
clubb_history = .true.
Expand Down Expand Up @@ -77,4 +77,4 @@ clubb_vars_zm= 'wp2', 'rtp2', 'thlp2', 'rtpthlp', 'wprtp', 'wpthlp', 'wp4', 'up2
'rtp2_dp2', 'rtp2_cl', 'rtp2_pd', 'rtp2_sf', 'rtp2_forcing', 'rtp2_mc', 'thlp2_bt', 'thlp2_ma', 'thlp2_ta', 'thlp2_tp', 'thlp2_dp1', 'thlp2_dp2', 'thlp2_cl',
'thlp2_pd', 'thlp2_sf', 'thlp2_forcing', 'thlp2_mc', 'rtpthlp_bt', 'rtpthlp_ma', 'rtpthlp_ta', 'rtpthlp_tp1', 'rtpthlp_tp2', 'rtpthlp_dp1', 'rtpthlp_dp2',
'rtpthlp_cl', 'rtpthlp_sf', 'rtpthlp_forcing', 'rtpthlp_mc', 'wpthlp_enter_mfl', 'wpthlp_exit_mfl', 'wprtp_enter_mfl', 'wprtp_exit_mfl', 'wpthlp_mfl_min',
'wpthlp_mfl_max', 'wprtp_mfl_min', 'wprtp_mfl_max', 'shear_sqd'
'wpthlp_mfl_max', 'wprtp_mfl_min', 'wprtp_mfl_max', 'shear_sqd', 'Ri_zm'
69 changes: 48 additions & 21 deletions src/physics/cam/clubb_intr.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ subroutine clubb_ini_cam(pbuf2d)
logical, parameter :: l_input_fields = .false. ! Always false for CAM-CLUBB.
logical, parameter :: l_update_pressure = .false. ! Always false for CAM-CLUBB.

integer :: nlev
integer :: nlev, ierr=0

real(r8) :: &
C1, C1b, C1c, C2rt, C2thl, C2rtthl, &
Expand Down Expand Up @@ -1465,7 +1465,8 @@ subroutine clubb_ini_cam(pbuf2d)
allocate( &
pdf_params_chnk(begchunk:endchunk), &
pdf_params_zm_chnk(begchunk:endchunk), &
pdf_implicit_coefs_terms_chnk(begchunk:endchunk) )
pdf_implicit_coefs_terms_chnk(begchunk:endchunk), stat=ierr )
if( ierr /= 0 ) call endrun(' clubb_ini_cam: failed to allocate pdf_params')

! ----------------------------------------------------------------- !
! Determine how many constituents CLUBB will transport. Note that
Expand Down Expand Up @@ -1831,13 +1832,18 @@ subroutine clubb_ini_cam(pbuf2d)
stats_zt(:), stats_zm(:), stats_sfc(:), &
stats_rad_zt(:), stats_rad_zm(:))

allocate(out_zt(pcols,pverp,stats_zt(1)%num_output_fields))
allocate(out_zm(pcols,pverp,stats_zm(1)%num_output_fields))
allocate(out_sfc(pcols,1,stats_sfc(1)%num_output_fields))
allocate(out_zt(pcols,pverp,stats_zt(1)%num_output_fields), stat=ierr)
if( ierr /= 0 ) call endrun( 'clubb_ini_cam: Unable to allocate out_zt' )
allocate(out_zm(pcols,pverp,stats_zm(1)%num_output_fields), stat=ierr)
if( ierr /= 0 ) call endrun( 'clubb_ini_cam: Unable to allocate out_zm' )
allocate(out_sfc(pcols,1,stats_sfc(1)%num_output_fields), stat=ierr)
if( ierr /= 0 ) call endrun( 'clubb_ini_cam: Unable to allocate out_sfc' )

if ( stats_metadata%l_output_rad_files ) then
allocate(out_radzt(pcols,pverp,stats_rad_zt(1)%num_output_fields))
allocate(out_radzm(pcols,pverp,stats_rad_zm(1)%num_output_fields))
allocate(out_radzt(pcols,pverp,stats_rad_zt(1)%num_output_fields), stat=ierr)
if( ierr /= 0 ) call endrun( 'clubb_ini_cam: Unable to allocate out_radzt' )
allocate(out_radzm(pcols,pverp,stats_rad_zm(1)%num_output_fields), stat=ierr)
if( ierr /= 0 ) call endrun( 'clubb_ini_cam: Unable to allocate out_radzm' )
end if

endif
Expand Down Expand Up @@ -3796,12 +3802,14 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
ptend_loc%q(i,k,ixcldliq) = (rcm(i,k) - state1%q(i,k,ixcldliq)) / hdtime ! Tendency of liquid water
ptend_loc%s(i,k) = (clubb_s(i,k) - state1%s(i,k)) / hdtime ! Tendency of static energy

rtm_integral_ltend(i) = rtm_integral_ltend(i) + ptend_loc%q(i,k,ixcldliq)*state1%pdel(i,k)/gravit
rtm_integral_vtend(i) = rtm_integral_vtend(i) + ptend_loc%q(i,k,ixq)*state1%pdel(i,k)/gravit
rtm_integral_ltend(i) = rtm_integral_ltend(i) + ptend_loc%q(i,k,ixcldliq)*state1%pdel(i,k)
rtm_integral_vtend(i) = rtm_integral_vtend(i) + ptend_loc%q(i,k,ixq)*state1%pdel(i,k)

end do
end do


rtm_integral_ltend(i) = rtm_integral_ltend(i)/gravit
rtm_integral_vtend(i) = rtm_integral_vtend(i)/gravit

if (clubb_do_adv) then
if (macmic_it == cld_macmic_num_steps) then
Expand Down Expand Up @@ -4761,10 +4769,10 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
if ( abs( stats_metadata%stats_tsamp/delt - floor(stats_metadata%stats_tsamp/delt) ) > 1.e-8_r8 ) then
l_error = .true. ! This will cause the run to stop.
write(fstderr,*) 'Error: stats_tsamp should be an even multiple of ', &
'delt (which is dtmain). Check the appropriate ', &
'model.in file.'
'the clubb time step (delt below)'
write(fstderr,*) 'stats_tsamp = ', stats_metadata%stats_tsamp
write(fstderr,*) 'delt = ', delt
call endrun ("stats_init_clubb: CLUBB stats_tsamp must be an even multiple of the timestep")
endif

! Initialize zt (mass points)
Expand All @@ -4777,6 +4785,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
enddo
ntot = i - 1
if ( ntot == nvarmax_zt ) then
l_error = .true.
write(fstderr,*) "There are more statistical variables listed in ", &
"clubb_vars_zt than allowed for by nvarmax_zt."
write(fstderr,*) "Check the number of variables listed for clubb_vars_zt ", &
Expand All @@ -4788,16 +4797,22 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
stats_zt(j)%num_output_fields = ntot
stats_zt(j)%kk = nnzp

allocate( stats_zt(j)%z( stats_zt(j)%kk ) )
allocate( stats_zt(j)%z( stats_zt(j)%kk ), stat=ierr )
if( ierr /= 0 ) call endrun("stats_init_clubb: Failed to allocate stats_zt%z")

allocate( stats_zt(j)%accum_field_values( 1, 1, stats_zt(j)%kk, stats_zt(j)%num_output_fields ) )
allocate( stats_zt(j)%accum_num_samples( 1, 1, stats_zt(j)%kk, stats_zt(j)%num_output_fields ) )
allocate( stats_zt(j)%l_in_update( 1, 1, stats_zt(j)%kk, stats_zt(j)%num_output_fields ) )
allocate( stats_zt(j)%accum_field_values( 1, 1, stats_zt(j)%kk, stats_zt(j)%num_output_fields ), stat=ierr )
if( ierr /= 0 ) call endrun("stats_init_clubb: Failed to allocate stats_zt%accum_field_values")
allocate( stats_zt(j)%accum_num_samples( 1, 1, stats_zt(j)%kk, stats_zt(j)%num_output_fields ), stat=ierr )
if( ierr /= 0 ) call endrun("stats_init_clubb: Failed to allocate stats_zt%accum_num_samples")
allocate( stats_zt(j)%l_in_update( 1, 1, stats_zt(j)%kk, stats_zt(j)%num_output_fields ), stat=ierr )
if( ierr /= 0 ) call endrun("stats_init_clubb: Failed to allocate stats_zt%l_in_update")
call stats_zero( stats_zt(j)%kk, stats_zt(j)%num_output_fields, stats_zt(j)%accum_field_values, &
stats_zt(j)%accum_num_samples, stats_zt(j)%l_in_update )

allocate( stats_zt(j)%file%grid_avg_var( stats_zt(j)%num_output_fields ) )
allocate( stats_zt(j)%file%z( stats_zt(j)%kk ) )
allocate( stats_zt(j)%file%grid_avg_var( stats_zt(j)%num_output_fields ), stat=ierr )
if( ierr /= 0 ) call endrun("stats_init_clubb: Failed to allocate stats_zt%file%grid_avg_var")
allocate( stats_zt(j)%file%z( stats_zt(j)%kk ), stat=ierr )
if( ierr /= 0 ) call endrun("stats_init_clubb: Failed to allocate stats_zt%file%z")

! Default initialization for array indices for zt
call stats_init_zt_api( clubb_vars_zt, &
Expand All @@ -4814,6 +4829,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
end do
ntot = i - 1
if ( ntot == nvarmax_zm ) then
l_error = .true. ! This will cause the run to stop.
write(fstderr,*) "There are more statistical variables listed in ", &
"clubb_vars_zm than allowed for by nvarmax_zm."
write(fstderr,*) "Check the number of variables listed for clubb_vars_zm ", &
Expand Down Expand Up @@ -4889,6 +4905,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
end do
ntot = i - 1
if ( ntot == nvarmax_rad_zm ) then
l_error = .true. ! This will cause the run to stop.
write(fstderr,*) "There are more statistical variables listed in ", &
"clubb_vars_rad_zm than allowed for by nvarmax_rad_zm."
write(fstderr,*) "Check the number of variables listed for clubb_vars_rad_zm ", &
Expand Down Expand Up @@ -4928,6 +4945,7 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
end do
ntot = i - 1
if ( ntot == nvarmax_sfc ) then
l_error = .true. ! This will cause the run to stop.
write(fstderr,*) "There are more statistical variables listed in ", &
"clubb_vars_sfc than allowed for by nvarmax_sfc."
write(fstderr,*) "Check the number of variables listed for clubb_vars_sfc ", &
Expand Down Expand Up @@ -4990,20 +5008,29 @@ subroutine stats_init_clubb( l_stats_in, stats_tsamp_in, stats_tout_in, &
if (stats_metadata%l_output_rad_files) then

do i = 1, stats_rad_zt(1)%num_output_fields
call addfld( trim(stats_rad_zt(1)%file%grid_avg_var(i)%name), (/ 'ilev' /), 'A', &
temp1 = trim(stats_rad_zt(1)%file%grid_avg_var(i)%name)
sub = temp1
if (len(temp1) > max_fieldname_len) sub = temp1(1:max_fieldname_len)
call addfld( trim(sub), (/ 'ilev' /), 'A', &
trim(stats_rad_zt(1)%file%grid_avg_var(i)%units), &
trim(stats_rad_zt(1)%file%grid_avg_var(i)%description) )
enddo

do i = 1, stats_rad_zm(1)%num_output_fields
call addfld( trim(stats_rad_zm(1)%file%grid_avg_var(i)%name), (/ 'ilev' /), 'A', &
temp1 = trim(stats_rad_zm(1)%file%grid_avg_var(i)%name)
sub = temp1
if (len(temp1) > max_fieldname_len) sub = temp1(1:max_fieldname_len)
call addfld( trim(sub), (/ 'ilev' /), 'A', &
trim(stats_rad_zm(1)%file%grid_avg_var(i)%units), &
trim(stats_rad_zm(1)%file%grid_avg_var(i)%description) )
enddo
endif

do i = 1, stats_sfc(1)%num_output_fields
call addfld( trim(stats_sfc(1)%file%grid_avg_var(i)%name), horiz_only, 'A', &
temp1 = trim(stats_sfc(1)%file%grid_avg_var(i)%name)
sub = temp1
if (len(temp1) > max_fieldname_len) sub = temp1(1:max_fieldname_len)
call addfld( trim(sub), horiz_only, 'A', &
trim(stats_sfc(1)%file%grid_avg_var(i)%units), &
trim(stats_sfc(1)%file%grid_avg_var(i)%description) )
enddo
Expand Down

0 comments on commit 544e33c

Please sign in to comment.