Skip to content

Commit 788aeab

Browse files
committed
reformat and clean up the code
fix a typo add error message
1 parent 898148e commit 788aeab

File tree

4 files changed

+40
-38
lines changed

4 files changed

+40
-38
lines changed

components/elm/src/biogeophys/SurfaceAlbedoMod.F90

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,27 +242,27 @@ subroutine SurfaceAlbedo(bounds, &
242242
! Cosine solar zenith angle for next time step
243243

244244
deg2rad = SHR_CONST_PI/180._r8
245-
do g = bounds%begg,bounds%endg
246-
coszen_gcell(g) = shr_orb_cosz (nextsw_cday, grc_pp%lat(g), grc_pp%lon(g), declinp1)
245+
if (.not. use_finetop_rad) then
246+
do g = bounds%begg,bounds%endg
247+
coszen_gcell(g) = shr_orb_cosz (nextsw_cday, grc_pp%lat(g), grc_pp%lon(g), declinp1)
248+
cosinc_gcell(g) = coszen_gcell(g)
249+
end do
250+
else
251+
do g = bounds%begg,bounds%endg
252+
coszen_gcell(g) = shr_orb_cosz (nextsw_cday, grc_pp%lat(g), grc_pp%lon(g), declinp1)
253+
sza = acos(coszen_gcell(g)) ! solar zenith angle
254+
saa = shr_orb_azimuth(nextsw_cday, grc_pp%lat(g), grc_pp%lon(g), declinp1, sza) ! solar azimuth angle
255+
256+
slope_rad = grc_pp%slope_deg(g) * deg2rad
257+
aspect_rad = grc_pp%aspect_deg(g) * deg2rad
258+
259+
cosinc_gcell(g) = cos(slope_rad) * coszen_gcell(g) + sin(slope_rad) * sin(sza) * cos(aspect_rad - saa)
260+
cosinc_gcell(g) = max(-1._r8, min(cosinc_gcell(g), 1._r8))
261+
262+
if (cosinc_gcell(g) <= 0._r8) cosinc_gcell(g) = 0.1_r8 ! although direct solar radiation is zero, we need to calculate diffuse albedo in this case
263+
end do
264+
endif
247265

248-
if (use_finetop_rad) then
249-
! solar zenith angle
250-
sza = acos(coszen_gcell(g))
251-
! solar azimuth angle
252-
saa = shr_orb_azimuth(nextsw_cday, grc_pp%lat(g), grc_pp%lon(g), declinp1, sza)
253-
254-
slope_rad = grc_pp%slope_deg(g) * deg2rad
255-
aspect_rad = grc_pp%aspect_deg(g) * deg2rad
256-
257-
cosinc_gcell(g) = cos(slope_rad) * coszen_gcell(g) + sin(slope_rad) * sin(sza) * cos(aspect_rad - saa)
258-
cosinc_gcell(g) = max(-1._r8, min(cosinc_gcell(g), 1._r8))
259-
!write(iulog,*) 'cosinc_gcell',cosinc_gcell(g)
260-
!write(iulog,*) 'coszen_gcell',coszen_gcell(g)
261-
if (cosinc_gcell(g) <= 0._r8) cosinc_gcell(g) = 0.1_r8 ! although direct solar radiation is zero, we need to calculate diffuse albedo in this case
262-
else
263-
cosinc_gcell(g) = coszen_gcell(g)
264-
endif
265-
end do
266266
do c = bounds%begc,bounds%endc
267267
g = col_pp%gridcell(c)
268268
coszen_col(c) = coszen_gcell(g)

components/elm/src/main/atm2lndMod.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ subroutine topographic_effects_on_radiation(bounds, atm2lnd_vars, nextsw_cday, d
540540
f_short_dir(g) = 1._r8
541541
f_short_dif(g) = 1._r8
542542
f_short_refl(g,:) = 0._r8
543-
sza(g) = nan
544-
saa(g) = nan
545-
cosinc(g) = nan
543+
sza(g) = spval
544+
saa(g) = spval
545+
cosinc(g) = spval
546546
! scale shortwave radiation
547547
if (cossza > 0.0872_r8) then ! just modify when SZA > 85 degree 0.0872_r8
548548

components/elm/src/main/atm2lndType.F90

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ subroutine InitAllocate(this, bounds)
331331
allocate(this%forc_uovern (begg:endg)) ; this%forc_uovern (:) = ival
332332

333333
if ( use_finetop_rad ) then
334-
allocate(this%f_short_dir (begg:endg)) ; this%f_short_dir (:) = nan
335-
allocate(this%f_short_dif (begg:endg)) ; this%f_short_dif (:) = nan
336-
allocate(this%f_short_refl (begg:endg,numrad)) ; this%f_short_refl (:,:) = nan
337-
allocate(this%f_long_dif (begg:endg)) ; this%f_long_dif (:) = nan
338-
allocate(this%f_long_refl (begg:endg)) ; this%f_long_refl (:) = nan
339-
allocate(this%sza (begg:endg)) ; this%sza (:) = nan
340-
allocate(this%saa (begg:endg)) ; this%saa (:) = nan
341-
allocate(this%cosinc (begg:endg)) ; this%cosinc (:) = nan
334+
allocate(this%f_short_dir (begg:endg)) ; this%f_short_dir (:) = spval
335+
allocate(this%f_short_dif (begg:endg)) ; this%f_short_dif (:) = spval
336+
allocate(this%f_short_refl (begg:endg,numrad)) ; this%f_short_refl (:,:) = spval
337+
allocate(this%f_long_dif (begg:endg)) ; this%f_long_dif (:) = spval
338+
allocate(this%f_long_refl (begg:endg)) ; this%f_long_refl (:) = spval
339+
allocate(this%sza (begg:endg)) ; this%sza (:) = spval
340+
allocate(this%saa (begg:endg)) ; this%saa (:) = spval
341+
allocate(this%cosinc (begg:endg)) ; this%cosinc (:) = spval
342342
allocate(this%forc_solad_pp_grc (begg:endg,numrad)) ; this%forc_solad_pp_grc (:,:) = ival
343343
allocate(this%forc_solai_pp_grc (begg:endg,numrad)) ; this%forc_solai_pp_grc (:,:) = ival
344344
allocate(this%forc_solar_pp_grc (begg:endg)) ; this%forc_solar_pp_grc (:) = ival
@@ -578,11 +578,9 @@ subroutine InitHistory(this, bounds)
578578
call hist_addfld1d (fname='LWdown_PP', units='W/m^2', &
579579
avgflag='A', long_name='atmospheric longwave radiation (PP)', &
580580
ptr_gcell=this%forc_lwrad_not_downscaled_pp_grc, default='inactive')
581-
endif
582581

583-
if ( use_finetop_rad ) then
584-
this%forc_solad_pp_grc(begg:endg, :) = 0._r8
585-
this%forc_solai_pp_grc(begg:endg, :) = 0._r8
582+
this%forc_solad_pp_grc(begg:endg, :) = 0._r8
583+
this%forc_solai_pp_grc(begg:endg, :) = 0._r8
586584
endif
587585

588586
end subroutine InitHistory

components/elm/src/main/controlMod.F90

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,13 +1122,17 @@ subroutine control_print ()
11221122
if (use_top_solar_rad) then
11231123
write(iulog,*) ' use TOP solar radiation parameterization instead of PP'
11241124
else
1125-
write(iulog,*) ' use_top_solar_rad is False, so do not run TOP solar radiation parameterization'
1125+
write(iulog,*) ' use_top_solar_rad is False, so do not run TOP solar radiation parameterization'
11261126
end if
11271127

1128-
if (use_finetop_rad) then
1128+
if (use_finetop_rad .and. use_top_solar_rad) then
1129+
write(iulog,*) ' cannot use both TOP and fineTOP radiation parameterizations simultaneously'
1130+
call endrun(msg=' ERROR: use_finetop_rad and use_top_solar_rad cannot both be set to true.'//&
1131+
errMsg(__FILE__, __LINE__))
1132+
else if (use_finetop_rad .and. (.not. use_top_solar_rad)) then
11291133
write(iulog,*) ' use fineTOP radiation parameterization instead of PP'
11301134
else
1131-
write(iulog,*) ' use_finetop_rad is False, so do not run fineTOP radiation parameterization'
1135+
write(iulog,*) ' use_finetop_rad is False, so do not run fineTOP radiation parameterization'
11321136
end if
11331137

11341138
if (use_cn) then

0 commit comments

Comments
 (0)