From b166449177c618b00c1fa1b2880244ba0a764d79 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sat, 7 Jan 2023 16:33:40 -0300 Subject: [PATCH 01/12] Multiple minor bug fixes, a few new variables, and changes for better readability. 1. In reproduction, the carbon budget was wrong when REPRO_SCHEME = 2 due to the incorrect site pointers when exchanging seeds. 2. Minor changes to reading met drivers to allow CO2 fertilisation drivers to not follow the met driver cycle only when CO2 drivers exist outside the meteorological cycle. 3. Added a new set of variables to report the area covered by snow (or temporary surface water) 4. Renamed a few variables and subroutines so they reflect more accurately what they are representing. --- ED/build/make/include.mk.macosx | 29 ++-- ED/src/driver/ed_met_driver.f90 | 165 ++++++++++++++---- ED/src/dynamics/disturbance.f90 | 12 ++ ED/src/dynamics/euler_driver.f90 | 2 +- ED/src/dynamics/farq_katul.f90 | 19 +- ED/src/dynamics/fire.f90 | 6 +- ED/src/dynamics/heun_driver.f90 | 2 +- ED/src/dynamics/hybrid_driver.f90 | 2 +- ED/src/dynamics/reproduction.f90 | 13 +- ED/src/dynamics/rk4_copy_patch.f90 | 2 + ED/src/dynamics/rk4_driver.F90 | 2 +- ED/src/dynamics/vegetation_dynamics.f90 | 4 +- ED/src/init/ed_params.f90 | 2 +- ED/src/init/ed_type_init.f90 | 10 +- ED/src/io/average_utils.f90 | 123 ++++++++++--- ED/src/io/ed_init_history.f90 | 16 +- ED/src/memory/ed_state_vars.F90 | 121 ++++++++++++- ED/src/utils/fuse_fiss_utils.f90 | 8 + diff_version.sh | 219 ++++++++++++++++++------ 19 files changed, 585 insertions(+), 172 deletions(-) diff --git a/ED/build/make/include.mk.macosx b/ED/build/make/include.mk.macosx index 69ed3365c..afbfd7cc3 100644 --- a/ED/build/make/include.mk.macosx +++ b/ED/build/make/include.mk.macosx @@ -5,7 +5,7 @@ #----- Define make (gnu make works best). -------------------------------------------------# -MAKE=/usr/bin/make +MAKE=/usr/local/bin/make #------------------------------------------------------------------------------------------# #----- Libraries. -------------------------------------------------------------------------# @@ -20,8 +20,8 @@ BASE=$(ED_ROOT)/build/ # libraries compiled with the same compiler you set for F_COMP and C_COMP. You may still # # be able to compile without HDF5 but it will not run. # #------------------------------------------------------------------------------------------# -ZLIB_PATH=/Users/mlongo/Util/ED2_Libs/zlib-1.2.11 -HDF5_PATH=/Users/mlongo/Util/ED2_Libs/hdf5-1.10.2 +ZLIB_PATH=${HOME}/Util/ED2_Libs/zlib-1.2.11 +HDF5_PATH=${HOME}/Util/ED2_Libs/hdf5-1.12.1 HDF5_INCS=-I$(HDF5_PATH)/include HDF5C_INCS=$(HDF5_INCS) HDF5_LIBS=-L$(ZLIB_PATH)/lib -lz -L$(HDF5_PATH)/lib -lhdf5_fortran -lhdf5 -lhdf5_hl @@ -51,10 +51,10 @@ USE_INTERF=1 #################################### COMPILER SETTINGS ##################################### CMACH=MAC_OS_X FC_TYPE=GNU -F_COMP=gfortran -C_COMP=gcc -LOADER=gfortran -C_LOADER=gcc +F_COMP=gfortran-12 +C_COMP=gcc-12 +LOADER=gfortran-12 +C_LOADER=gcc-12 LIBS= MOD_EXT=mod ############################################################################################ @@ -88,20 +88,17 @@ endif ifeq ($(KIND_COMP),A) F_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=snan \ -finit-integer=-2147483648 -ffpe-trap=invalid,zero,overflow,underflow \ - -fcheck=all -frecursive -fsignaling-nans -Werror -mmacosx-version-min=10.12 \ - -fopenmp -static - C_OPTS= -O0 -DLITTLE -g -static + -fcheck=all -frecursive -fsignaling-nans -Werror -fopenmp -fbacktrace -static + C_OPTS= -O0 -DLITTLE -g -fbacktrace -static LOADER_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=snan \ -finit-integer=-2147483648 -ffpe-trap=invalid,zero,overflow,underflow \ - -fcheck=all -frecursive -fsignaling-nans -Werror \ - -mmacosx-version-min=10.12 -fopenmp + -fcheck=all -frecursive -fsignaling-nans -Werror -fopenmp -fbacktrace #---------------------------------------------------------------------------------------# endif ifeq ($(KIND_COMP),E) - F_OPTS= -O3 -ffree-line-length-none -frecursive -mmacosx-version-min=10.12 -fopenmp \ - -static - C_OPTS= -O0 -DLITTLE -g -static - LOADER_OPTS= -O3 -ffree-line-length-none -frecursive -mmacosx-version-min=10.12 -fopenmp + F_OPTS= -O3 -ffree-line-length-none -frecursive -fopenmp -fbacktrace -static + C_OPTS= -O3 -DLITTLE -g -fbacktrace -static + LOADER_OPTS= -O3 -ffree-line-length-none -frecursive -fopenmp -fbacktrace #---------------------------------------------------------------------------------------# endif #------------------------------------------------------------------------------------------# diff --git a/ED/src/driver/ed_met_driver.f90 b/ED/src/driver/ed_met_driver.f90 index e6fb7449a..f4db066f3 100644 --- a/ED/src/driver/ed_met_driver.f90 +++ b/ED/src/driver/ed_met_driver.f90 @@ -527,7 +527,6 @@ subroutine read_met_drivers_init ! We now retrieve the met driver year based on the stored sequence. ! !------------------------------------------------------------------------------------! iyear = current_time%year-iyeara+1 - year_use = metyears(iyear) gridloop: do igr = 1,ngrids @@ -545,8 +544,30 @@ subroutine read_met_drivers_init !------------------------------------------------------------------------------! not_cycle_co2 = (met_nv(iformat) == 1 .and. trim(met_vars(iformat,1)) == 'co2') if (not_cycle_co2) then - year_use = current_time%year - endif + !---------------------------------------------------------------------------! + ! Make sure that the special CO2 file exists. If not, then use the ! + ! default met cycle years. ! + !---------------------------------------------------------------------------! + write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)),current_time%year & + ,mname(current_time%month),'.h5' + inquire(file=trim(infile),exist=exans) + if (exans) then + !----- Allow CO2 outside met cycle. -------------------------------------! + year_use = current_time%year + !------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. -----------! + year_use = metyears(iyear) + !------------------------------------------------------------------------! + end if + !---------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. --------------! + year_use = metyears(iyear) + !---------------------------------------------------------------------------! + end if + !------------------------------------------------------------------------------! + !----- Create the file name and check whether it exists. ----------------------! write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)), year_use & ,mname(current_time%month),'.h5' @@ -599,12 +620,33 @@ subroutine read_met_drivers_init y2 = current_time%year end if iyear = y2 - iyeara + 1 - year_use_2 = metyears(iyear) - - ! Again consider the special case of not cycling co2 + + !------------------------------------------------------------------------------# + ! Again consider the special case of not cycling co2 + !------------------------------------------------------------------------------# if (not_cycle_co2) then - year_use_2 = y2 - endif + !---------------------------------------------------------------------------! + ! Make sure that the special CO2 file exists. If not, then use the ! + ! default met cycle years. ! + !---------------------------------------------------------------------------! + write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)),y2 & + ,mname(current_time%month),'.h5' + inquire(file=trim(infile),exist=exans) + if (exans) then + !----- Allow CO2 outside met cycle. -------------------------------------! + year_use_2 = y2 + !------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. -----------! + year_use_2 = metyears(iyear) + !------------------------------------------------------------------------! + end if + !---------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. --------------! + year_use_2 = metyears(iyear) + !---------------------------------------------------------------------------! + end if !----- Now, open the file once. -----------------------------------------------! write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)), year_use_2 & ,mname(m2),'.h5' @@ -615,7 +657,7 @@ subroutine read_met_drivers_init call fatal_error('Cannot open met driver input file '//trim(infile)//'!' & ,'read_met_drivers_init','ed_met_driver.f90') end if - + !----- Loop over variables. ---------------------------------------------------! varloop: do iv = 1, met_nv(iformat) @@ -674,6 +716,8 @@ subroutine read_met_drivers type(edtype) , pointer :: cgrid character(len=str_len) :: infile integer :: igr + integer :: year_cyc + integer :: year_cyc_2 integer :: year_use integer :: ncyc integer :: iformat @@ -694,17 +738,17 @@ subroutine read_met_drivers !----- If we need to recycle over years, find the appropriate year to apply. --------! - year_use = current_time%year + year_cyc = current_time%year ncyc = metcycf - metcyc1 + 1 !----- If we are after the last year... ---------------------------------------------! - do while(year_use > metcycf) - year_use = year_use - ncyc + do while(year_cyc > metcycf) + year_cyc = year_cyc - ncyc end do !----- If we are before the first year... -------------------------------------------! - do while(year_use < metcyc1) - year_use = year_use + ncyc + do while(year_cyc < metcyc1) + year_cyc = year_cyc + ncyc end do gridloop: do igr=1,ngrids @@ -713,7 +757,6 @@ subroutine read_met_drivers !----- Loop over the different file formats --------------------------------------! formloop: do iformat = 1, nformats - !------------------------------------------------------------------------------! ! SPECIAL CASE FOR CO2: ! ! Usually we do not want to cycle CO2 but only the other meteorology. ! @@ -722,8 +765,32 @@ subroutine read_met_drivers !------------------------------------------------------------------------------! not_cycle_co2 = (met_nv(iformat) == 1 .and. trim(met_vars(iformat,1)) == 'co2') if (not_cycle_co2) then - year_use = current_time%year - endif + !---------------------------------------------------------------------------! + ! Make sure that the special CO2 file exists. If not, then use the ! + ! default met cycle years. ! + !---------------------------------------------------------------------------! + write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)),current_time%year & + ,mname(current_time%month),'.h5' + inquire(file=trim(infile),exist=exans) + if (exans) then + !----- Allow CO2 outside met cycle. -------------------------------------! + year_use = current_time%year + !------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. -----------! + year_use = year_cyc + !------------------------------------------------------------------------! + end if + !---------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. --------------! + year_use = year_cyc + !---------------------------------------------------------------------------! + end if + !------------------------------------------------------------------------------! + + + !----- Create the file name and check whether it exists. ----------------------! write(infile,'(a,i4.4,a,a)')trim(met_names(iformat)), year_use, & mname(current_time%month),'.h5' @@ -766,37 +833,63 @@ subroutine read_met_drivers !------------------------------------------------------------------------------! ! For all interpolated variables, we also need the next time. ! !------------------------------------------------------------------------------! - !------ Find next month and year ----------------------------------------------! - m2 = current_time%month + 1 - y2 = current_time%year - year_use_2 = year_use - - + !------------------------------------------------------------------------------! - ! If this takes us into the next year, increment year and reset month to ! - ! January. ! + ! Find next month and year. If this takes us into the next year, increment ! + ! year and reset month to January. ! !------------------------------------------------------------------------------! - if(m2 == 13)then + m2 = current_time%month + 1 + select case (m2) + case (13) m2 = 1 y2 = current_time%year + 1 - year_use_2 = y2 + year_cyc_2 = y2 !----- If we are now after the last year... --------------------------------! - do while(year_use_2 > metcycf) - year_use_2 = year_use_2 - ncyc + do while(year_cyc_2 > metcycf) + year_cyc_2 = year_cyc_2 - ncyc end do - + !---------------------------------------------------------------------------! + !----- If we are now before the first year... ------------------------------! do while(year_use_2 < metcyc1) - year_use_2 = year_use_2 + ncyc + year_cyc_2 = year_cyc_2 + ncyc end do - end if + !---------------------------------------------------------------------------! + case default + !---- Same year as the previous month. -------------------------------------! + y2 = current_time%year + year_cyc_2 = year_cyc + !---------------------------------------------------------------------------! + end select - ! Again, consider the special case for not_cycle_co2 + !---- Again, consider the special case for not_cycle_co2. ---------------------! if (not_cycle_co2) then - year_use_2 = y2 - endif - + !---------------------------------------------------------------------------! + ! Make sure that the special CO2 file exists. If not, then use the ! + ! default met cycle years. ! + !---------------------------------------------------------------------------! + write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)),y2 & + ,mname(current_time%month),'.h5' + inquire(file=trim(infile),exist=exans) + if (exans) then + !----- Allow CO2 outside met cycle. -------------------------------------! + year_use_2 = y2 + !------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. -----------! + year_use_2 = year_cyc_2 + !------------------------------------------------------------------------! + end if + !---------------------------------------------------------------------------! + else + !----- Typical case. Pool data from the meteorological cycle. --------------! + year_use = year_cyc_2 + !---------------------------------------------------------------------------! + end if + !------------------------------------------------------------------------------! + + !----- Now, open the file once. -----------------------------------------------! write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)), year_use_2 & ,mname(m2),'.h5' diff --git a/ED/src/dynamics/disturbance.f90 b/ED/src/dynamics/disturbance.f90 index f1dc10627..ad0728a26 100644 --- a/ED/src/dynamics/disturbance.f90 +++ b/ED/src/dynamics/disturbance.f90 @@ -2265,6 +2265,9 @@ subroutine increment_patch_vars(csite,np,cp,area_fac,cb_enthalpy,can_exner,cb_ma csite%fmean_sfcw_mass (np) = csite%fmean_sfcw_mass (np) & + csite%fmean_sfcw_mass (cp) & * area_fac + csite%fmean_snowfac (np) = csite%fmean_snowfac (np) & + + csite%fmean_snowfac (cp) & + * area_fac csite%fmean_rshort_gnd (np) = csite%fmean_rshort_gnd (np) & + csite%fmean_rshort_gnd (cp) & * area_fac @@ -2487,6 +2490,9 @@ subroutine increment_patch_vars(csite,np,cp,area_fac,cb_enthalpy,can_exner,cb_ma csite%dmean_sfcw_fliq ( np) = csite%dmean_sfcw_fliq ( np) & + csite%dmean_sfcw_fliq ( cp) & * area_fac + csite%dmean_snowfac ( np) = csite%dmean_snowfac ( np) & + + csite%dmean_snowfac ( cp) & + * area_fac csite%dmean_rshort_gnd ( np) = csite%dmean_rshort_gnd ( np) & + csite%dmean_rshort_gnd ( cp) & * area_fac @@ -2770,6 +2776,9 @@ subroutine increment_patch_vars(csite,np,cp,area_fac,cb_enthalpy,can_exner,cb_ma csite%mmean_sfcw_fliq ( np) = csite%mmean_sfcw_fliq ( np) & + csite%mmean_sfcw_fliq ( cp) & * area_fac + csite%mmean_snowfac ( np) = csite%mmean_snowfac ( np) & + + csite%mmean_snowfac ( cp) & + * area_fac csite%mmean_rshort_gnd ( np) = csite%mmean_rshort_gnd ( np) & + csite%mmean_rshort_gnd ( cp) & * area_fac @@ -3065,6 +3074,9 @@ subroutine increment_patch_vars(csite,np,cp,area_fac,cb_enthalpy,can_exner,cb_ma csite%qmean_sfcw_fliq ( :,np) = csite%qmean_sfcw_fliq ( :,np) & + csite%qmean_sfcw_fliq ( :,cp) & * area_fac + csite%qmean_snowfac ( :,np) = csite%qmean_snowfac ( :,np) & + + csite%qmean_snowfac ( :,cp) & + * area_fac csite%qmean_soil_energy (:,:,np) = csite%qmean_soil_energy (:,:,np) & + csite%qmean_soil_energy (:,:,cp) & * area_fac diff --git a/ED/src/dynamics/euler_driver.f90 b/ED/src/dynamics/euler_driver.f90 index 416104399..a1bcbb0b5 100644 --- a/ED/src/dynamics/euler_driver.f90 +++ b/ED/src/dynamics/euler_driver.f90 @@ -97,7 +97,7 @@ subroutine euler_timestep(cgrid) ! Update the monthly rainfall. ! !------------------------------------------------------------------------------! imon = current_time%month - cpoly%avg_monthly_pcpg(imon,isi) = cpoly%avg_monthly_pcpg(imon,isi) & + cpoly%avg_monthly_accp(imon,isi) = cpoly%avg_monthly_accp(imon,isi) & + cmet%pcpg * dtlsm !------------------------------------------------------------------------------! diff --git a/ED/src/dynamics/farq_katul.f90 b/ED/src/dynamics/farq_katul.f90 index 31ac9b186..cb3cd6ea7 100644 --- a/ED/src/dynamics/farq_katul.f90 +++ b/ED/src/dynamics/farq_katul.f90 @@ -247,9 +247,6 @@ subroutine katul_lphys(ib,can_prss,can_rhos,can_shv,can_co2,ipft,leaf_par,leaf_t !update photosynthetic parameters with water stress select case (h2o_plant_lim) - case (0,1,2,3) - ! use fsw to account for water stress in photosyn_driv - water_stress_factor = 1. case (4) ! leaf water potential will influence stomata optimization ! at two different scales @@ -268,6 +265,9 @@ subroutine katul_lphys(ib,can_prss,can_rhos,can_shv,can_co2,ipft,leaf_par,leaf_t 1. / (1. + & 0.1 * (leaf_psi / leaf_psi_tlp(ipft)) ** 6.0))) lambda8 = lambda8 * dble(exp(stoma_beta(ipft) * dmax_leaf_psi)) + case default + ! use fsw to account for water stress in photosyn_driv + water_stress_factor = 1. end select !thispft(ib)%vm0 = thispft(ib)%vm0 * dble(water_stress_factor) @@ -409,9 +409,6 @@ subroutine optimization_solver8(ib,ipft,lambda, real(kind=8) :: test_dcidg real(kind=8) :: test_dfcdg real(kind=8) :: test_dfedg - real(kind=8) :: test_fc_light - real(kind=8) :: test_fc_rubp - real(kind=8) :: test_fc_3rd real(kind=8) :: opt_ci_light real(kind=8) :: opt_ci_rubp real(kind=8) :: opt_ci_3rd @@ -852,16 +849,6 @@ subroutine photosynthesis_stomata_solver8(ib,gsc,limit_case, real(kind=8) :: a,b,c !! Coefficients of the quadratic equation to solve ci real(kind=8) :: rad !! sqrt(b2-4ac) real(kind=8) :: dbdg,dcdg !! derivatives of b,c wrt. gsc - real(kind=8) :: ci_rubp !! ci for rubp-limited scenario - real(kind=8) :: dcidg_rubp !! derivative of ci wrt. gsc for rubp-limited scenario - real(kind=8) :: dfcdg_rubp !! derivative of fc wrt. gsc for rubp-limited scenario - real(kind=8) :: ci_light !! ci for light-limited scenario - real(kind=8) :: dcidg_light !! derivative of ci wrt. gsc for light-limited scenario - real(kind=8) :: dfcdg_light !! derivative of fc wrt. gsc for light-limited scenario - real(kind=8) :: ci_3rd !! ci for TPU/CO2-limited scenario - real(kind=8) :: dcidg_3rd !! derivative of ci wrt. gsc for TPU/CO2-limited scenario - real(kind=8) :: dfcdg_3rd !! derivative of fc wrt. gsc for TPU/CO2-limited scenario - !------------------------------------------------------------------------------------! diff --git a/ED/src/dynamics/fire.f90 b/ED/src/dynamics/fire.f90 index 0df3bcbf3..b93c9703e 100644 --- a/ED/src/dynamics/fire.f90 +++ b/ED/src/dynamics/fire.f90 @@ -62,7 +62,7 @@ subroutine fire_frequency(cgrid) real :: fuel real :: ignition_rate real :: mean_fire_intensity - real :: sum_pcpg + real :: sum_accp logical :: people_around !------------------------------------------------------------------------------------! @@ -97,8 +97,8 @@ subroutine fire_frequency(cgrid) ! Find the total rainfall of the past year and reset the counter for this ! ! month. ! !------------------------------------------------------------------------------! - sum_pcpg = sum(cpoly%avg_monthly_pcpg(:,isi)) - cpoly%avg_monthly_pcpg(imon,isi) = 0. + sum_accp = sum(cpoly%avg_monthly_accp(:,isi)) + cpoly%avg_monthly_accp(imon,isi) = 0. !------------------------------------------------------------------------------! diff --git a/ED/src/dynamics/heun_driver.f90 b/ED/src/dynamics/heun_driver.f90 index c3c9631b6..d5aae0d2d 100644 --- a/ED/src/dynamics/heun_driver.f90 +++ b/ED/src/dynamics/heun_driver.f90 @@ -98,7 +98,7 @@ subroutine heun_timestep(cgrid) ! Update the monthly rainfall. ! !------------------------------------------------------------------------------! imon = current_time%month - cpoly%avg_monthly_pcpg(imon,isi) = cpoly%avg_monthly_pcpg(imon,isi) & + cpoly%avg_monthly_accp(imon,isi) = cpoly%avg_monthly_accp(imon,isi) & + cmet%pcpg * dtlsm !------------------------------------------------------------------------------! diff --git a/ED/src/dynamics/hybrid_driver.f90 b/ED/src/dynamics/hybrid_driver.f90 index 7aaf1d59f..54689f0d7 100644 --- a/ED/src/dynamics/hybrid_driver.f90 +++ b/ED/src/dynamics/hybrid_driver.f90 @@ -107,7 +107,7 @@ subroutine hybrid_timestep(cgrid) ! Update the monthly rainfall. ! !---------------------------------------------------------------------! imon = current_time%month - cpoly%avg_monthly_pcpg(imon,isi) = cpoly%avg_monthly_pcpg(imon,isi) & + cpoly%avg_monthly_accp(imon,isi) = cpoly%avg_monthly_accp(imon,isi) & + cmet%pcpg * dtlsm !---------------------------------------------------------------------! diff --git a/ED/src/dynamics/reproduction.f90 b/ED/src/dynamics/reproduction.f90 index 170fec5a8..52ab6a4d6 100644 --- a/ED/src/dynamics/reproduction.f90 +++ b/ED/src/dynamics/reproduction.f90 @@ -179,6 +179,7 @@ subroutine reproduction_driver(cgrid,month,veget_dyn_on) !----- The big loops start here. -------------------------------------------------! polyloop: do ipy = 1,cgrid%npolygons + cpoly => cgrid%polygon(ipy) !------------------------------------------------------------------------------! ! Check whether this is late spring/early summer. This is needed for ! @@ -187,8 +188,8 @@ subroutine reproduction_driver(cgrid,month,veget_dyn_on) !------------------------------------------------------------------------------! late_spring = (cgrid%lat(ipy) >= 0.0 .and. month == 6) .or. & (cgrid%lat(ipy) < 0.0 .and. month == 12) + !------------------------------------------------------------------------------! - cpoly => cgrid%polygon(ipy) siteloop_sort: do isi = 1,cpoly%nsites csite => cpoly%site(isi) @@ -1286,8 +1287,8 @@ subroutine seed_dispersal(cpoly,late_spring) ! of them will land again in this patch, and we correct for this further ! ! down. ! !------------------------------------------------------------------------! - csite%cbudget_seedrain(donpa) = csite%cbudget_seedrain(donpa) & - - bseed_maygo * frqsumi + donsite%cbudget_seedrain(donpa) = donsite%cbudget_seedrain(donpa) & + - bseed_maygo * frqsumi !------------------------------------------------------------------------! @@ -1314,7 +1315,7 @@ subroutine seed_dispersal(cpoly,late_spring) ! (4) RPY = DPA * AD * AR (1->3) ! ! (5) RPA = DPA * AD (4->2, regardless of the patch) ! !------------------------------------------------------------------------! - bseed_xpatch = bseed_maygo * csite%area(donpa) * cpoly%area(donsi) + bseed_xpatch = bseed_maygo * donsite%area(donpa) * cpoly%area(donsi) !------------------------------------------------------------------------! @@ -1343,8 +1344,8 @@ subroutine seed_dispersal(cpoly,late_spring) ! subtracted all the non-local dispersal outside the receptor site ! ! loop. ! !------------------------------------------------------------------! - csite%cbudget_seedrain(recpa) = csite%cbudget_seedrain(recpa) & - + bseed_xpatch * frqsumi + recsite%cbudget_seedrain(recpa) = recsite%cbudget_seedrain(recpa) & + + bseed_xpatch * frqsumi !------------------------------------------------------------------! diff --git a/ED/src/dynamics/rk4_copy_patch.f90 b/ED/src/dynamics/rk4_copy_patch.f90 index 9fbeff87e..fc7556a37 100644 --- a/ED/src/dynamics/rk4_copy_patch.f90 +++ b/ED/src/dynamics/rk4_copy_patch.f90 @@ -2092,6 +2092,8 @@ subroutine initp2modelp(hdid,initp,csite,ipa,nighttime,wbudget_loss2atm,ebudget_ + csite%ground_shv (ipa) * dtlsm_o_frqsum csite%fmean_can_ggnd (ipa) = csite%fmean_can_ggnd (ipa) & + csite%ggnet (ipa) * dtlsm_o_frqsum + csite%fmean_snowfac (ipa) = csite%fmean_snowfac (ipa) & + + csite%snowfac (ipa) * dtlsm_o_frqsum !------------------------------------------------------------------------------------! ! Snow/pounding layers. We keep track of the total, not individual layers. ! ! Energy will be integrated as an extensive variable, we will convert it by the ! diff --git a/ED/src/dynamics/rk4_driver.F90 b/ED/src/dynamics/rk4_driver.F90 index ae758614c..38ba31935 100644 --- a/ED/src/dynamics/rk4_driver.F90 +++ b/ED/src/dynamics/rk4_driver.F90 @@ -112,7 +112,7 @@ subroutine rk4_timestep(cgrid) ! Update the monthly rainfall. ! !------------------------------------------------------------------------------! imon = current_time%month - cpoly%avg_monthly_pcpg(imon,isi) = cpoly%avg_monthly_pcpg(imon,isi) & + cpoly%avg_monthly_accp(imon,isi) = cpoly%avg_monthly_accp(imon,isi) & + cmet%pcpg * dtlsm !------------------------------------------------------------------------------! diff --git a/ED/src/dynamics/vegetation_dynamics.f90 b/ED/src/dynamics/vegetation_dynamics.f90 index 645ae24c9..c30e6dcd7 100644 --- a/ED/src/dynamics/vegetation_dynamics.f90 +++ b/ED/src/dynamics/vegetation_dynamics.f90 @@ -34,7 +34,7 @@ subroutine veg_dynamics_driver(new_month,new_year,gr_tfact0,veget_dyn_on) , yr_day ! ! intent(in) use mem_polygons , only : maxpatch ! ! intent(in) use average_utils , only : normalize_ed_today_vars & ! sub-routine - , normalize_ed_todaynpp_vars & ! sub-routine + , copy_today_to_dmean_vars & ! sub-routine , zero_ed_today_vars ! ! sub-routine use canopy_radiation_coms, only : ihrzrad ! ! intent(in) use hrzshade_utils , only : split_hrzshade & ! sub-routine @@ -129,7 +129,7 @@ subroutine veg_dynamics_driver(new_month,new_year,gr_tfact0,veget_dyn_on) !------ update dmean and mmean values for NPP allocation terms ------------------! - call normalize_ed_todayNPP_vars(cgrid) + call copy_today_to_dmean_vars(cgrid) !---------------------------------------------------------------------------------! diff --git a/ED/src/init/ed_params.f90 b/ED/src/init/ed_params.f90 index 98b14d90b..f991239ae 100644 --- a/ED/src/init/ed_params.f90 +++ b/ED/src/init/ed_params.f90 @@ -525,7 +525,7 @@ subroutine init_decomp_params() rh0 = 0.700 ! 0.701 ! 0.425 rh_q10 = 1.500 ! 1.500 ! 1.893 rh_p_smoist = 1.600 ! 0.836 ! 0.606 - rh_p_oxygen = 0.600 ! 0.404 ! 0.164 + rh_p_oxygen = 0.450 ! 0.404 ! 0.164 !---------------------------------------------------------------------------------------! diff --git a/ED/src/init/ed_type_init.f90 b/ED/src/init/ed_type_init.f90 index 456c93fd4..51a7b1187 100644 --- a/ED/src/init/ed_type_init.f90 +++ b/ED/src/init/ed_type_init.f90 @@ -1128,6 +1128,7 @@ subroutine init_ed_patch_vars(csite,ipaa,ipaz,lsl) csite%fmean_sfcw_mass (ipaa:ipaz) = 0.0 csite%fmean_sfcw_temp (ipaa:ipaz) = 0.0 csite%fmean_sfcw_fliq (ipaa:ipaz) = 0.0 + csite%fmean_snowfac (ipaa:ipaz) = 0.0 csite%fmean_rshort_gnd (ipaa:ipaz) = 0.0 csite%fmean_par_gnd (ipaa:ipaz) = 0.0 csite%fmean_rlong_gnd (ipaa:ipaz) = 0.0 @@ -1210,6 +1211,7 @@ subroutine init_ed_patch_vars(csite,ipaa,ipaz,lsl) csite%dmean_sfcw_mass (ipaa:ipaz) = 0.0 csite%dmean_sfcw_temp (ipaa:ipaz) = 0.0 csite%dmean_sfcw_fliq (ipaa:ipaz) = 0.0 + csite%dmean_snowfac (ipaa:ipaz) = 0.0 csite%dmean_rshort_gnd (ipaa:ipaz) = 0.0 csite%dmean_par_gnd (ipaa:ipaz) = 0.0 csite%dmean_rlong_gnd (ipaa:ipaz) = 0.0 @@ -1286,6 +1288,7 @@ subroutine init_ed_patch_vars(csite,ipaa,ipaz,lsl) csite%mmean_sfcw_mass (ipaa:ipaz) = 0.0 csite%mmean_sfcw_temp (ipaa:ipaz) = 0.0 csite%mmean_sfcw_fliq (ipaa:ipaz) = 0.0 + csite%mmean_snowfac (ipaa:ipaz) = 0.0 csite%mmean_rshort_gnd (ipaa:ipaz) = 0.0 csite%mmean_par_gnd (ipaa:ipaz) = 0.0 csite%mmean_rlong_gnd (ipaa:ipaz) = 0.0 @@ -1409,6 +1412,7 @@ subroutine init_ed_patch_vars(csite,ipaa,ipaz,lsl) csite%qmean_sfcw_mass (:,ipaa:ipaz) = 0.0 csite%qmean_sfcw_temp (:,ipaa:ipaz) = 0.0 csite%qmean_sfcw_fliq (:,ipaa:ipaz) = 0.0 + csite%qmean_snowfac (:,ipaa:ipaz) = 0.0 csite%qmean_rshort_gnd (:,ipaa:ipaz) = 0.0 csite%qmean_par_gnd (:,ipaa:ipaz) = 0.0 csite%qmean_rlong_gnd (:,ipaa:ipaz) = 0.0 @@ -1684,7 +1688,7 @@ subroutine init_ed_site_vars(cpoly) ! by actual rainfall after 12 months. In the future we may initialise with climato- ! ! logical rainfall. ! !------------------------------------------------------------------------------------! - cpoly%avg_monthly_pcpg(:,:) = 500. + cpoly%avg_monthly_accp(:,:) = 500. !------------------------------------------------------------------------------------! @@ -2084,6 +2088,7 @@ subroutine init_ed_poly_vars(cgrid) cgrid%fmean_sfcw_mass (ipy) = 0.0 cgrid%fmean_sfcw_temp (ipy) = 0.0 cgrid%fmean_sfcw_fliq (ipy) = 0.0 + cgrid%fmean_snowfac (ipy) = 0.0 cgrid%fmean_rshort_gnd (ipy) = 0.0 cgrid%fmean_par_gnd (ipy) = 0.0 cgrid%fmean_rlong_gnd (ipy) = 0.0 @@ -2257,6 +2262,7 @@ subroutine init_ed_poly_vars(cgrid) cgrid%dmean_sfcw_mass (ipy) = 0.0 cgrid%dmean_sfcw_temp (ipy) = 0.0 cgrid%dmean_sfcw_fliq (ipy) = 0.0 + cgrid%dmean_snowfac (ipy) = 0.0 cgrid%dmean_rshort_gnd (ipy) = 0.0 cgrid%dmean_par_gnd (ipy) = 0.0 cgrid%dmean_rlong_gnd (ipy) = 0.0 @@ -2414,6 +2420,7 @@ subroutine init_ed_poly_vars(cgrid) cgrid%mmean_sfcw_mass (ipy) = 0.0 cgrid%mmean_sfcw_temp (ipy) = 0.0 cgrid%mmean_sfcw_fliq (ipy) = 0.0 + cgrid%mmean_snowfac (ipy) = 0.0 cgrid%mmean_rshort_gnd (ipy) = 0.0 cgrid%mmean_par_gnd (ipy) = 0.0 cgrid%mmean_rlong_gnd (ipy) = 0.0 @@ -2656,6 +2663,7 @@ subroutine init_ed_poly_vars(cgrid) cgrid%qmean_sfcw_mass (:,ipy) = 0.0 cgrid%qmean_sfcw_temp (:,ipy) = 0.0 cgrid%qmean_sfcw_fliq (:,ipy) = 0.0 + cgrid%qmean_snowfac (:,ipy) = 0.0 cgrid%qmean_rshort_gnd (:,ipy) = 0.0 cgrid%qmean_par_gnd (:,ipy) = 0.0 cgrid%qmean_rlong_gnd (:,ipy) = 0.0 diff --git a/ED/src/io/average_utils.f90 b/ED/src/io/average_utils.f90 index 152c09294..722b61051 100644 --- a/ED/src/io/average_utils.f90 +++ b/ED/src/io/average_utils.f90 @@ -493,6 +493,9 @@ subroutine aggregate_polygon_fmean(cgrid) cgrid%fmean_sfcw_mass (ipy) = cgrid%fmean_sfcw_mass (ipy) & + csite%fmean_sfcw_mass (ipa) & * patch_wgt + cgrid%fmean_snowfac (ipy) = cgrid%fmean_snowfac (ipy) & + + csite%fmean_snowfac (ipa) & + * patch_wgt cgrid%fmean_rshort_gnd (ipy) = cgrid%fmean_rshort_gnd (ipy) & + csite%fmean_rshort_gnd (ipa) & * patch_wgt @@ -1425,11 +1428,13 @@ subroutine zero_ed_fmean_vars(cgrid) cgrid%fmean_sfcw_mass ( ipy) = 0.0 cgrid%fmean_sfcw_temp ( ipy) = 0.0 cgrid%fmean_sfcw_fliq ( ipy) = 0.0 + cgrid%fmean_snowfac ( ipy) = 0.0 cgrid%fmean_soil_energy (:,ipy) = 0.0 cgrid%fmean_soil_mstpot (:,ipy) = 0.0 cgrid%fmean_soil_water (:,ipy) = 0.0 cgrid%fmean_soil_temp (:,ipy) = 0.0 cgrid%fmean_soil_fliq (:,ipy) = 0.0 + cgrid%fmean_snowfac ( ipy) = 0.0 cgrid%fmean_rshort_gnd ( ipy) = 0.0 cgrid%fmean_par_gnd ( ipy) = 0.0 cgrid%fmean_rlong_gnd ( ipy) = 0.0 @@ -1574,6 +1579,7 @@ subroutine zero_ed_fmean_vars(cgrid) csite%fmean_sfcw_mass ( ipa) = 0.0 csite%fmean_sfcw_temp ( ipa) = 0.0 csite%fmean_sfcw_fliq ( ipa) = 0.0 + csite%fmean_snowfac ( ipa) = 0.0 csite%fmean_soil_energy (:,ipa) = 0.0 csite%fmean_soil_mstpot (:,ipa) = 0.0 csite%fmean_soil_water (:,ipa) = 0.0 @@ -2059,6 +2065,9 @@ subroutine integrate_ed_dmean_vars(cgrid) cgrid%dmean_sfcw_mass (ipy) = cgrid%dmean_sfcw_mass (ipy) & + cgrid%fmean_sfcw_mass (ipy) & * frqsum_o_daysec + cgrid%dmean_snowfac (ipy) = cgrid%dmean_snowfac (ipy) & + + cgrid%fmean_snowfac (ipy) & + * frqsum_o_daysec cgrid%dmean_rshort_gnd (ipy) = cgrid%dmean_rshort_gnd (ipy) & + cgrid%fmean_rshort_gnd (ipy) & * frqsum_o_daysec @@ -2363,6 +2372,9 @@ subroutine integrate_ed_dmean_vars(cgrid) csite%dmean_sfcw_mass (ipa) = csite%dmean_sfcw_mass (ipa) & + csite%fmean_sfcw_mass (ipa) & * frqsum_o_daysec + csite%dmean_snowfac (ipa) = csite%dmean_snowfac (ipa) & + + csite%fmean_snowfac (ipa) & + * frqsum_o_daysec csite%dmean_rshort_gnd (ipa) = csite%dmean_rshort_gnd (ipa) & + csite%fmean_rshort_gnd (ipa) & * frqsum_o_daysec @@ -2812,10 +2824,11 @@ end subroutine normalize_ed_today_vars !=======================================================================================! !=======================================================================================! - ! SUBROUTINE: NORMALIZE_ED_TODAYNPP_VARS - !> \brief This subroutine will scale the daily NPP allocation terms + ! SUBROUTINE: COPY_TODAY_TO_DMEAN_VARS + !> \brief This subroutine scales the daily NPP allocation terms and transfer today + !! variables to dmean. !---------------------------------------------------------------------------------------! - subroutine normalize_ed_todayNPP_vars(cgrid) + subroutine copy_today_to_dmean_vars(cgrid) use ed_state_vars , only : edtype & ! structure , polygontype & ! structure , sitetype & ! structure @@ -2833,47 +2846,70 @@ subroutine normalize_ed_todayNPP_vars(cgrid) integer :: isi integer :: ipa integer :: ico + !------------------------------------------------------------------------------------! + + !------ Skip sub-routine and do nothing in case we are not writing daily averages. --! + if (.not. writing_long) return + !------------------------------------------------------------------------------------! + + + !------------------------------------------------------------------------------------! + ! Loop through polygons. ! + !------------------------------------------------------------------------------------! polyloop: do ipy=1,cgrid%npolygons cpoly => cgrid%polygon(ipy) + + !---------------------------------------------------------------------------------! + ! Loop through sites. ! + !---------------------------------------------------------------------------------! siteloop: do isi=1,cpoly%nsites csite => cpoly%site(isi) - patchloop: do ipa=1,csite%npatches + !------------------------------------------------------------------------------! + ! Loop through patches. ! + !------------------------------------------------------------------------------! + patchloop: do ipa=1,csite%npatches cpatch => csite%patch(ipa) - - !----- Included a loop so it won't crash with empty cohorts... -------------! + + !---------------------------------------------------------------------------! + ! Loop through cohorts. This must be a loop, so it won't crash with ! + ! empty patches. ! + !---------------------------------------------------------------------------! cohortloop: do ico=1,cpatch%ncohorts !------------------------------------------------------------------------! ! We now update the daily means of NPP allocation terms ! ! and we convert them to kgC/plant/yr ! !------------------------------------------------------------------------! - if (writing_long) then - cpatch%dmean_nppleaf (ico) = cpatch%today_nppleaf (ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppfroot (ico) = cpatch%today_nppfroot (ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppsapwood(ico) = cpatch%today_nppsapwood(ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppbark (ico) = cpatch%today_nppbark (ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppcroot (ico) = cpatch%today_nppcroot (ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppseeds (ico) = cpatch%today_nppseeds (ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppwood (ico) = cpatch%today_nppwood (ico) & - * yr_day / cpatch%nplant (ico) - cpatch%dmean_nppdaily (ico) = cpatch%today_nppdaily (ico) & - * yr_day / cpatch%nplant (ico) - end if + cpatch%dmean_nppleaf (ico) = cpatch%today_nppleaf (ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppfroot (ico) = cpatch%today_nppfroot (ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppsapwood(ico) = cpatch%today_nppsapwood(ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppbark (ico) = cpatch%today_nppbark (ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppcroot (ico) = cpatch%today_nppcroot (ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppseeds (ico) = cpatch%today_nppseeds (ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppwood (ico) = cpatch%today_nppwood (ico) & + * yr_day / cpatch%nplant (ico) + cpatch%dmean_nppdaily (ico) = cpatch%today_nppdaily (ico) & + * yr_day / cpatch%nplant (ico) + !------------------------------------------------------------------------! end do cohortloop + !---------------------------------------------------------------------------! end do patchloop + !------------------------------------------------------------------------------! end do siteloop + !---------------------------------------------------------------------------------! end do polyloop + !------------------------------------------------------------------------------------! return - end subroutine normalize_ed_todayNPP_vars + end subroutine copy_today_to_dmean_vars !=======================================================================================! !=======================================================================================! @@ -3702,6 +3738,7 @@ subroutine zero_ed_dmean_vars(cgrid) cgrid%dmean_sfcw_mass (ipy) = 0.0 cgrid%dmean_sfcw_temp (ipy) = 0.0 cgrid%dmean_sfcw_fliq (ipy) = 0.0 + cgrid%dmean_snowfac (ipy) = 0.0 cgrid%dmean_soil_energy (:,ipy) = 0.0 cgrid%dmean_soil_mstpot (:,ipy) = 0.0 cgrid%dmean_soil_water (:,ipy) = 0.0 @@ -3824,6 +3861,7 @@ subroutine zero_ed_dmean_vars(cgrid) csite%dmean_sfcw_mass (ipa) = 0.0 csite%dmean_sfcw_temp (ipa) = 0.0 csite%dmean_sfcw_fliq (ipa) = 0.0 + csite%dmean_snowfac (ipa) = 0.0 csite%dmean_soil_energy (:,ipa) = 0.0 csite%dmean_soil_mstpot (:,ipa) = 0.0 csite%dmean_soil_water (:,ipa) = 0.0 @@ -4426,6 +4464,9 @@ subroutine integrate_ed_mmean_vars(cgrid) cgrid%mmean_sfcw_mass (ipy) = cgrid%mmean_sfcw_mass (ipy) & + cgrid%dmean_sfcw_mass (ipy) & * ndaysi + cgrid%mmean_snowfac (ipy) = cgrid%mmean_snowfac (ipy) & + + cgrid%dmean_snowfac (ipy) & + * ndaysi cgrid%mmean_soil_energy (:,ipy) = cgrid%mmean_soil_energy (:,ipy) & + cgrid%dmean_soil_energy (:,ipy) & * ndaysi @@ -4951,6 +4992,9 @@ subroutine integrate_ed_mmean_vars(cgrid) csite%mmean_sfcw_mass (ipa) = csite%mmean_sfcw_mass (ipa) & + csite%dmean_sfcw_mass (ipa) & * ndaysi + csite%mmean_snowfac (ipa) = csite%mmean_snowfac (ipa) & + + csite%dmean_snowfac (ipa) & + * ndaysi csite%mmean_soil_energy (:,ipa) = csite%mmean_soil_energy (:,ipa) & + csite%dmean_soil_energy (:,ipa) & * ndaysi @@ -6086,6 +6130,7 @@ subroutine zero_ed_mmean_vars(cgrid) cgrid%mmean_sfcw_mass (ipy) = 0.0 cgrid%mmean_sfcw_temp (ipy) = 0.0 cgrid%mmean_sfcw_fliq (ipy) = 0.0 + cgrid%mmean_snowfac (ipy) = 0.0 cgrid%mmean_soil_energy (:,ipy) = 0.0 cgrid%mmean_soil_mstpot (:,ipy) = 0.0 cgrid%mmean_soil_water (:,ipy) = 0.0 @@ -6274,6 +6319,7 @@ subroutine zero_ed_mmean_vars(cgrid) csite%mmean_sfcw_mass (ipa) = 0.0 csite%mmean_sfcw_temp (ipa) = 0.0 csite%mmean_sfcw_fliq (ipa) = 0.0 + csite%mmean_snowfac (ipa) = 0.0 csite%mmean_soil_energy (:,ipa) = 0.0 csite%mmean_soil_mstpot (:,ipa) = 0.0 csite%mmean_soil_water (:,ipa) = 0.0 @@ -6838,6 +6884,9 @@ subroutine integrate_ed_qmean_vars(cgrid) cgrid%qmean_sfcw_mass (t,ipy) = cgrid%qmean_sfcw_mass (t,ipy) & + cgrid%fmean_sfcw_mass (ipy) & * ndaysi + cgrid%qmean_snowfac (t,ipy) = cgrid%qmean_snowfac (t,ipy) & + + cgrid%fmean_snowfac (ipy) & + * ndaysi cgrid%qmean_soil_energy (:,t,ipy) = cgrid%qmean_soil_energy (:,t,ipy) & + cgrid%fmean_soil_energy (:,ipy) & * ndaysi @@ -7230,6 +7279,9 @@ subroutine integrate_ed_qmean_vars(cgrid) csite%qmean_sfcw_mass (t,ipa) = csite%qmean_sfcw_mass (t,ipa) & + csite%fmean_sfcw_mass (ipa) & * ndaysi + csite%qmean_snowfac (t,ipa) = csite%qmean_snowfac (t,ipa) & + + csite%fmean_snowfac (ipa) & + * ndaysi csite%qmean_soil_energy (:,t,ipa) = csite%qmean_soil_energy (:,t,ipa) & + csite%fmean_soil_energy (:,ipa) & * ndaysi @@ -7796,6 +7848,25 @@ subroutine normalize_ed_qmean_vars(cgrid) + !---------------------------------------------------------------------------! + ! Find the derived properties for the canopy air space. ! + !---------------------------------------------------------------------------! + do t=1,ndcycle + can_exner = press2exner ( csite%qmean_can_prss (t,ipa)) + csite%qmean_can_temp(t,ipa) = extheta2temp( can_exner & + , csite%qmean_can_theta(t,ipa)) + csite%qmean_can_rhos(t,ipa) = idealdenssh ( csite%qmean_can_prss (t,ipa) & + , csite%qmean_can_temp (t,ipa) & + , csite%qmean_can_shv (t,ipa)) + csite%qmean_can_dmol(t,ipa) = idealdmolsh ( csite%qmean_can_prss (t,ipa) & + , csite%qmean_can_temp (t,ipa) & + , csite%qmean_can_shv (t,ipa)) + end do + !---------------------------------------------------------------------------! + + + + !---------------------------------------------------------------------------! ! Soil matric potential, temperature, and liquid water. ! !---------------------------------------------------------------------------! @@ -8163,6 +8234,7 @@ subroutine zero_ed_qmean_vars(cgrid) cgrid%qmean_sfcw_mass (:,ipy) = 0.0 cgrid%qmean_sfcw_temp (:,ipy) = 0.0 cgrid%qmean_sfcw_fliq (:,ipy) = 0.0 + cgrid%qmean_snowfac (:,ipy) = 0.0 cgrid%qmean_soil_energy (:,:,ipy) = 0.0 cgrid%qmean_soil_mstpot (:,:,ipy) = 0.0 cgrid%qmean_soil_water (:,:,ipy) = 0.0 @@ -8309,6 +8381,7 @@ subroutine zero_ed_qmean_vars(cgrid) csite%qmean_sfcw_mass (:,ipa) = 0.0 csite%qmean_sfcw_temp (:,ipa) = 0.0 csite%qmean_sfcw_fliq (:,ipa) = 0.0 + csite%qmean_snowfac (:,ipa) = 0.0 csite%qmean_soil_energy (:,:,ipa) = 0.0 csite%qmean_soil_mstpot (:,:,ipa) = 0.0 csite%qmean_soil_water (:,:,ipa) = 0.0 diff --git a/ED/src/io/ed_init_history.f90 b/ED/src/io/ed_init_history.f90 index f4d91cc49..d9c77c35a 100644 --- a/ED/src/io/ed_init_history.f90 +++ b/ED/src/io/ed_init_history.f90 @@ -1004,6 +1004,8 @@ subroutine fill_history_grid_p11dmean(cgrid,ipy,py_index) ,'DMEAN_SFCW_TEMP_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%dmean_sfcw_fliq (ipy:ipy) & ,'DMEAN_SFCW_FLIQ_PY ',dsetrank,iparallel,.false.,foundvar) + call hdf_getslab_r(cgrid%dmean_snowfac (ipy:ipy) & + ,'DMEAN_SNOWFAC_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%dmean_rshort_gnd (ipy:ipy) & ,'DMEAN_RSHORT_GND_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%dmean_par_gnd (ipy:ipy) & @@ -1432,6 +1434,8 @@ subroutine fill_history_grid_p11mmean(cgrid,ipy,py_index) ,'MMEAN_SFCW_TEMP_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%mmean_sfcw_fliq (ipy:ipy) & ,'MMEAN_SFCW_FLIQ_PY ',dsetrank,iparallel,.false.,foundvar) + call hdf_getslab_r(cgrid%mmean_snowfac (ipy:ipy) & + ,'MMEAN_SNOWFAC_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%mmean_rshort_gnd (ipy:ipy) & ,'MMEAN_RSHORT_GND_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%mmean_par_gnd (ipy:ipy) & @@ -2055,6 +2059,8 @@ subroutine fill_history_grid_m11(cgrid,ipy,py_index) ,'QMEAN_SFCW_TEMP_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%qmean_sfcw_fliq (:,ipy) & ,'QMEAN_SFCW_FLIQ_PY ',dsetrank,iparallel,.false.,foundvar) + call hdf_getslab_r(cgrid%qmean_snowfac (:,ipy) & + ,'QMEAN_SNOWFAC_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%qmean_rshort_gnd (:,ipy) & ,'QMEAN_RSHORT_GND_PY ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(cgrid%qmean_par_gnd (:,ipy) & @@ -3257,8 +3263,8 @@ subroutine fill_history_polygon(cpoly,pysi_index,nsites_global,nsites_now,is_bur memoffs (2) = 0_8 call hdf_getslab_r(cpoly%lambda_fire & ,'LAMBDA_FIRE ',dsetrank,iparallel,.true.,foundvar) - call hdf_getslab_r(cpoly%avg_monthly_pcpg & - ,'AVG_MONTHLY_PCPG ',dsetrank,iparallel,.true.,foundvar) + call hdf_getslab_r(cpoly%avg_monthly_accp & + ,'AVG_MONTHLY_ACCP ',dsetrank,iparallel,.true.,foundvar) call hdf_getslab_r(cpoly%crop_yield & ,'CROP_YIELD_SI ',dsetrank,iparallel,.true.,foundvar) !------------------------------------------------------------------------------------! @@ -4069,6 +4075,8 @@ subroutine fill_history_site(csite,sipa_index,npatches_global,is_burnt) ,'DMEAN_SFCW_TEMP_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%dmean_sfcw_fliq & ,'DMEAN_SFCW_FLIQ_PA ',dsetrank,iparallel,.false.,foundvar) + call hdf_getslab_r(csite%dmean_snowfac & + ,'DMEAN_SNOWFAC_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%dmean_rshort_gnd & ,'DMEAN_RSHORT_GND_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%dmean_par_gnd & @@ -4238,6 +4246,8 @@ subroutine fill_history_site(csite,sipa_index,npatches_global,is_burnt) ,'MMEAN_SFCW_TEMP_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%mmean_sfcw_fliq & ,'MMEAN_SFCW_FLIQ_PA ',dsetrank,iparallel,.false.,foundvar) + call hdf_getslab_r(csite%mmean_snowfac & + ,'MMEAN_SNOWFAC_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%mmean_rshort_gnd & ,'MMEAN_RSHORT_GND_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%mmean_par_gnd & @@ -4443,6 +4453,8 @@ subroutine fill_history_site(csite,sipa_index,npatches_global,is_burnt) ,'QMEAN_SFCW_TEMP_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%qmean_sfcw_fliq & ,'QMEAN_SFCW_FLIQ_PA ',dsetrank,iparallel,.false.,foundvar) + call hdf_getslab_r(csite%qmean_snowfac & + ,'QMEAN_SNOWFAC_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%qmean_rshort_gnd & ,'QMEAN_RSHORT_GND_PA ',dsetrank,iparallel,.false.,foundvar) call hdf_getslab_r(csite%qmean_par_gnd & diff --git a/ED/src/memory/ed_state_vars.F90 b/ED/src/memory/ed_state_vars.F90 index d72654bec..056347b6c 100644 --- a/ED/src/memory/ed_state_vars.F90 +++ b/ED/src/memory/ed_state_vars.F90 @@ -1869,6 +1869,7 @@ module ed_state_vars real,pointer,dimension(:) :: fmean_sfcw_mass ! tiny_sfcwater_mass) then csite%fmean_sfcw_energy (recp) = csite%fmean_sfcw_energy (recp) & @@ -7775,6 +7777,8 @@ subroutine fuse_2_patches(csite,donp,recp,mzg,mzs,cmet,lsl,ntext_soil,green_leaf * csite%dmean_sfcw_mass (recp) * rawgt csite%dmean_sfcw_mass (recp) = csite%dmean_sfcw_mass (donp) * dawgt & + csite%dmean_sfcw_mass (recp) * rawgt + csite%dmean_snowfac (recp) = csite%dmean_snowfac (donp) * dawgt & + + csite%dmean_snowfac (recp) * rawgt !----- Check whether there is enough surface water. ---------------------------! if (csite%dmean_sfcw_mass(recp) > tiny_sfcwater_mass) then csite%dmean_sfcw_energy (recp) = csite%dmean_sfcw_energy (recp) & @@ -8169,6 +8173,8 @@ subroutine fuse_2_patches(csite,donp,recp,mzg,mzs,cmet,lsl,ntext_soil,green_leaf * csite%mmean_sfcw_mass (recp) * rawgt csite%mmean_sfcw_mass (recp) = csite%mmean_sfcw_mass (donp) * dawgt & + csite%mmean_sfcw_mass (recp) * rawgt + csite%mmean_snowfac (recp) = csite%mmean_snowfac (donp) * dawgt & + + csite%mmean_snowfac (recp) * rawgt !----- Check whether there is enough surface water. ---------------------------! if (csite%mmean_sfcw_mass(recp) > tiny_sfcwater_mass) then csite%mmean_sfcw_energy (recp) = csite%mmean_sfcw_energy (recp) & @@ -8520,6 +8526,8 @@ subroutine fuse_2_patches(csite,donp,recp,mzg,mzs,cmet,lsl,ntext_soil,green_leaf * csite%qmean_sfcw_mass (t,recp) * rawgt csite%qmean_sfcw_mass (t,recp) = csite%qmean_sfcw_mass (t,donp) * dawgt & + csite%qmean_sfcw_mass (t,recp) * rawgt + csite%qmean_snowfac (t,recp) = csite%qmean_snowfac (t,donp) * dawgt & + + csite%qmean_snowfac (t,recp) * rawgt !----- Check whether there is enough surface water. ------------------------! if (csite%qmean_sfcw_mass(t,recp) > tiny_sfcwater_mass) then csite%qmean_sfcw_energy (t,recp) = csite%qmean_sfcw_energy(t,recp) & diff --git a/diff_version.sh b/diff_version.sh index 77a083c15..d3be988ac 100755 --- a/diff_version.sh +++ b/diff_version.sh @@ -24,9 +24,11 @@ subdirs="ED BRAMS Ramspost R-utils" #------ Editor to use (I've only tested with nedit, use others at your own risk). ---------# editor="nedit" #------ Two paths with EDBRAMS (full path). -----------------------------------------------# -ours="${HOME}/EDBRAMS" -theirs="${HOME}/MainLine/EDBRAMS" -ournew=true +ours="${HOME}/Downloads/MLN-EDBRAMS" +theirs="${HOME}/Downloads/MLO-EDBRAMS" +ournew=false +#------ Working path when implementing a partial merge (otherwise, leave it blank). -------# +work="${HOME}/Models/EDBRAMS" #------------------------------------------------------------------------------------------# @@ -45,7 +47,24 @@ esac #------------------------------------------------------------------------------------------# # Remove any comparison file that may exist. # #------------------------------------------------------------------------------------------# -/bin/rm -f notthesame.* +/bin/rm -f notthesame.* \~notthesame.* +#------------------------------------------------------------------------------------------# + + +#------------------------------------------------------------------------------------------# +# Add settings for partial merge (if sought). # +#------------------------------------------------------------------------------------------# +if [[ "${work}" == "" ]] +then + #---- Disable work version (preferred method, much less messy). ------------------------# + load_work=false + work=${theirs} + #---------------------------------------------------------------------------------------# +else + #---- Enable work version (more prone to complications, be careful). -------------------# + load_work=true + #---------------------------------------------------------------------------------------# +fi #------------------------------------------------------------------------------------------# @@ -60,11 +79,11 @@ do #---------------------------------------------------------------------------------------# for ext in ${exts} do - if [ ${subdir} == "R-utils" ] && [ ${ext} == ".txt" ] + if [[ ${subdir} == "R-utils" ]] && [[ ${ext} == ".txt" ]] then srcours="${ours}/${subdir}/samap" srctheirs="${theirs}/${subdir}/samap" - elif [ ${subdir} == "R-utils" ] + elif [[ ${subdir} == "R-utils" ]] then srcours="${ours}/${subdir}" srctheirs="${theirs}/${subdir}" @@ -82,12 +101,14 @@ do for fileours in ${lookuptable} do file=$(basename ${fileours}) - newpath=$(dirname ${fileours} | sed s@${ours}@${theirs}@g) + theirpath=$(dirname ${fileours} | sed s@${ours}@${theirs}@g) + workpath=$(dirname ${fileours} | sed s@${ours}@${work}@g) case "${myos}" in Darwin|Cygwin) #---- Case-insensitive file system. ---------------------------------------------# - filetheirs="${newpath}/${file}" - alt="" + filetheirs="${theirpath}/${file}" + filework="${workpath}/${file}" + theirs_alt="" ;; #--------------------------------------------------------------------------------# *) @@ -95,64 +116,154 @@ do case "${ext}" in ".f90") alt_file=$(echo ${file} | sed s@"\\.f90"@".F90"@g) - if [ -s "${newpath}/${alt_file}" ] + if [[ -s "${theirpath}/${alt_file}" ]] then - filetheirs="${newpath}/${alt_file}" - alt=".F90" + filetheirs="${theirpath}/${alt_file}" + theirs_alt=".F90" else - filetheirs="${newpath}/${file}" - alt="" + filetheirs="${theirpath}/${file}" + theirs_alt="" fi ;; ".F90") alt_file=$(echo ${file} | sed s@"\\.F90"@".f90"@g) - if [ -s "${newpath}/${alt_file}" ] + if [[ -s "${theirpath}/${alt_file}" ]] then - filetheirs="${newpath}/${alt_file}" - alt=".f90" + filetheirs="${theirpath}/${alt_file}" + theirs_alt=".f90" else - filetheirs="${newpath}/${file}" - alt="" + filetheirs="${theirpath}/${file}" + theirs_alt="" fi ;; *) - filetheirs="${newpath}/${file}" - alt="" + filetheirs="${theirpath}/${file}" + theirs_alt="" ;; esac - ;; #--------------------------------------------------------------------------------# + + + #----- Probably Linux or Unix, assume case-sensitive file system. ---------------# + case "${ext}" in + ".f90") + alt_file=$(echo ${file} | sed s@"\\.f90"@".F90"@g) + if [[ -s "${workpath}/${alt_file}" ]] + then + filework="${workpath}/${alt_file}" + work_alt=".F90" + else + filework="${workpath}/${file}" + work_alt="" + fi + ;; + ".F90") + alt_file=$(echo ${file} | sed s@"\\.F90"@".f90"@g) + if [[ -s "${workpath}/${alt_file}" ]] + then + filework="${workpath}/${alt_file}" + work_alt=".f90" + else + filework="${workpath}/${file}" + work_alt="" + fi + ;; + *) + filework="${workpath}/${file}" + work_alt="" + ;; + esac + #--------------------------------------------------------------------------------# + + ;; esac - filetheirs="${newpath}/${file}" - if [ -s ${filetheirs} ] + + + #-----------------------------------------------------------------------------------# + # If we are doing partial merge, we must check the existence three-way, # + # otherwise we compare just the "ours" and "theirs". # + #-----------------------------------------------------------------------------------# + if [[ -s ${filetheirs} ]] then - ldif=$(diff -ibB <(grep -vE "^\s*!" ${fileours}) <(grep -vE "^\s*!" ${filetheirs}) | wc -l) - if [ ${ldif} -gt 0 ] - then - woroot=$(echo ${fileours} | sed s@"${srcours}/"@""@g) - case "${alt}" in - .f90|.F90) - echo "${woroot} has changed. New extension is ${alt}." - ;; - *) - echo "${woroot} has changed." - ;; - esac - if ${ournew} - then - diff -uibB <(grep -vE "^\s*!" ${filetheirs}) <(grep -vE "^\s*!" ${fileours})\ - > notthesame${ext} - else - diff -uibB <(grep -vE "^\s*!" ${fileours}) <(grep -vE "^\s*!" ${filetheirs})\ - > notthesame${ext} - fi - ${editor} ${fileours} ${filetheirs} notthesame${ext} 1> /dev/null 2> /dev/null - /bin/rm -f notthesame${ext} - fi + #---- Check for extension change. -----------------------------------------------# + woroot=$(echo ${fileours} | sed s@"${srcours}/"@""@g) + case "${theirs_alt}" in + .f90|.F90) + if ${ournew} + then + ext_mess="Old extension was ${theirs_alt}." + else + ext_mess="New extension is ${theirs_alt}." + fi + ;; + *) + ext_mess="" + ;; + esac + #--------------------------------------------------------------------------------# + + + + #--------------------------------------------------------------------------------# + # Check for changes (ignoring spaces and commented lines). # + #--------------------------------------------------------------------------------# + ldif=$(diff -ibB <(grep -vE "^\s*!" ${fileours}) <(grep -vE "^\s*!" ${filetheirs}) | wc -l) + if [[ ${ldif} -gt 0 ]] + then + change=true + if [[ "${ext_mess}" == "" ]] + then + echo "File ${woroot}. Code has changed." + else + echo "File ${woroot}. Code has changed. ${ext_mess}" + fi + elif [[ "${ext_mess}" == "" ]] + then + change=false + else + change=false + echo "File ${woroot}. ${ext_mess}" + fi + #--------------------------------------------------------------------------------# + + + #--------------------------------------------------------------------------------# + # If files have changes, report differences. # + #--------------------------------------------------------------------------------# + if ${change} + then + #----- Write differences to a temporary file. --------------------------------# + if ${ournew} + then + diff -uibB <(grep -vE "^\s*!" ${filetheirs}) \ + <(grep -vE "^\s*!" ${fileours}) > notthesame${ext} + else + diff -uibB <(grep -vE "^\s*!" ${fileours}) \ + <(grep -vE "^\s*!" ${filetheirs}) > notthesame${ext} + fi + #-----------------------------------------------------------------------------# + + + #----- Open editor with all files needed. ------------------------------------# + if ${load_work} && [[ -s ${filework} ]] + then + ${editor} ${filework} ${filetheirs} notthesame${ext} \ + 1> /dev/null 2> /dev/null + /bin/rm -f notthesame${ext} + elif ${load_work} + then + ${editor} ${filetheirs} notthesame${ext} 1> /dev/null 2> /dev/null + echo " ---> Working file is missing!" + else + ${editor} ${fileours} ${filetheirs} notthesame${ext} \ + 1> /dev/null 2> /dev/null + fi + #-----------------------------------------------------------------------------# + fi else - woroot=$(echo ${fileours} | sed s@"${srcours}/"@""@g) - echo "${woroot} is exclusive to ${ours} version." - fi #if [ -s ${filetheirs} ] + woroot=$(echo ${fileours} | sed s@"${srcours}/"@""@g) + echo "${woroot} is exclusive to ${ours} version." + fi #if [[ -s ${filetheirs} ]] done #for fileours in ${lookuptable} #-------------------------------------------------------------------------------------# @@ -165,13 +276,13 @@ do for filetheirs in ${lookuptable} do file=$(basename ${filetheirs}) - newpath=$(dirname ${filetheirs} | sed s@${theirs}@${ours}@g) - fileours="${newpath}/${file}" - if [ ! -s ${fileours} ] + ourpath=$(dirname ${filetheirs} | sed s@${theirs}@${ours}@g) + fileours="${ourpath}/${file}" + if [[ ! -s ${fileours} ]] then woroot=$(echo ${filetheirs} | sed s@"${srctheirs}/"@""@g) echo "${woroot} is exclusive to ${theirs} version." - fi #if [ -s ${filetheirs} ] + fi #if [[ -s ${filetheirs} ]] done #for fileours in ${lookuptable} #-------------------------------------------------------------------------------------# done #for ext in ${exts} From 37bdbcdd4392e0f458ebe3b1f88595e70d94453b Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 4 Jun 2023 17:59:34 -0700 Subject: [PATCH 02/12] Added a few other bug fixes. --- ED/src/driver/ed_driver.F90 | 21 ++++++--- ED/src/driver/ed_met_driver.f90 | 66 +++++++++++++++++++-------- ED/src/dynamics/disturbance.f90 | 2 +- ED/src/dynamics/farq_katul.f90 | 3 +- ED/src/dynamics/forestry.f90 | 4 ++ ED/src/init/landuse_init.f90 | 4 +- ED/src/io/ed_read_ed10_20_history.f90 | 13 ++++-- ED/src/mpi/ed_para_init.f90 | 4 +- 8 files changed, 81 insertions(+), 36 deletions(-) diff --git a/ED/src/driver/ed_driver.F90 b/ED/src/driver/ed_driver.F90 index 1c7ff8724..8e0cfaeb0 100644 --- a/ED/src/driver/ed_driver.F90 +++ b/ED/src/driver/ed_driver.F90 @@ -185,7 +185,8 @@ subroutine ed_driver() !---------------------------------------------------------------------------------------! - if (trim(runtype) == 'HISTORY' ) then + select case (trim(runtype)) + case ('HISTORY') !------------------------------------------------------------------------------------! ! Initialize the model state as a replicate image of a previous state. ! !------------------------------------------------------------------------------------! @@ -210,7 +211,7 @@ subroutine ed_driver() if (nnodetot /= 1 ) call MPI_Barrier(MPI_COMM_WORLD,ierr) #endif !------------------------------------------------------------------------------------! - else + case default !------------------------------------------------------------------------------------! ! Initialize state properties of polygons/sites/patches/cohorts. ! @@ -218,7 +219,7 @@ subroutine ed_driver() if (mynum == nnodetot) write (unit=*,fmt='(a)') ' [+] Load_Ecosystem_State...' call load_ecosystem_state() !------------------------------------------------------------------------------------! - end if + end select !---------------------------------------------------------------------------------------! ! In case the runs is going to produce detailed output, we eliminate all patches ! @@ -294,11 +295,14 @@ subroutine ed_driver() ! Initialise some derived variables. Skip this in case the simulation is resuming ! ! from HISTORY. ! !---------------------------------------------------------------------------------------! - if (trim(runtype) /= 'HISTORY' ) then + select case (trim(runtype)) + case ('HISTORY') + continue + case default do ifm=1,ngrids call update_derived_props(edgrid_g(ifm)) end do - end if + end select !---------------------------------------------------------------------------------------! @@ -307,11 +311,14 @@ subroutine ed_driver() ! Initialise drought phenology. This should be done after the soil moisture has ! ! been set up. ! !---------------------------------------------------------------------------------------! - if (runtype /= 'HISTORY') then + select case (trim(runtype)) + case ('HISTORY') + continue + case default do ifm=1,ngrids call first_phenology(edgrid_g(ifm)) end do - end if + end select !---------------------------------------------------------------------------------------! diff --git a/ED/src/driver/ed_met_driver.f90 b/ED/src/driver/ed_met_driver.f90 index f4db066f3..abc07cfda 100644 --- a/ED/src/driver/ed_met_driver.f90 +++ b/ED/src/driver/ed_met_driver.f90 @@ -345,6 +345,8 @@ subroutine read_met_drivers_init type(edtype) , pointer :: cgrid character(len=str_len) :: infile integer :: igr + integer :: year_cyc + integer :: year_cyc_2 integer :: year_use integer :: iformat integer :: iv @@ -526,8 +528,18 @@ subroutine read_met_drivers_init !------------------------------------------------------------------------------------! ! We now retrieve the met driver year based on the stored sequence. ! !------------------------------------------------------------------------------------! - iyear = current_time%year-iyeara+1 - + !----- If we need to recycle over years, find the appropriate year to apply. --------! + year_cyc = current_time%year + ncyc = metcycf - metcyc1 + 1 + !----- If we are after the last year... ---------------------------------------------! + do while(year_cyc > metcycf) + year_cyc = year_cyc - ncyc + end do + !----- If we are before the first year... -------------------------------------------! + do while(year_cyc < metcyc1) + year_cyc = year_cyc + ncyc + end do + !------------------------------------------------------------------------------------! gridloop: do igr = 1,ngrids @@ -535,7 +547,7 @@ subroutine read_met_drivers_init !----- Loop over the different file formats --------------------------------------! formloop: do iformat = 1, nformats - + !------------------------------------------------------------------------------! ! SPECIAL CASE FOR CO2: ! ! Usually we do not want to cycle CO2 but only the other meteorology. ! @@ -557,13 +569,13 @@ subroutine read_met_drivers_init !------------------------------------------------------------------------! else !----- Typical case. Pool data from the meteorological cycle. -----------! - year_use = metyears(iyear) + year_use = year_cyc !------------------------------------------------------------------------! end if !---------------------------------------------------------------------------! else !----- Typical case. Pool data from the meteorological cycle. --------------! - year_use = metyears(iyear) + year_use = year_cyc !---------------------------------------------------------------------------! end if !------------------------------------------------------------------------------! @@ -579,6 +591,7 @@ subroutine read_met_drivers_init write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE =',year_use write (unit=*,fmt='(a)' ) '------------------------------' call fatal_error('Cannot open met driver input file '//trim(infile)//'!' & @@ -594,7 +607,7 @@ subroutine read_met_drivers_init !----- Loop over variables. and read the data. --------------------------------! do iv = 1, met_nv(iformat) offset = 0 - call read_ol_file(infile,iformat, iv, mname(current_time%month) & + call read_ol_file(infile,iformat, iv, mname(current_time%month) & ,current_time%year, offset, cgrid) end do @@ -605,21 +618,35 @@ subroutine read_met_drivers_init !------------------------------------------------------------------------------! ! For all interpolated variables, we also need the next time. ! !------------------------------------------------------------------------------! - !------ Find next month and year ----------------------------------------------! - m2 = current_time%month + 1 - + !------------------------------------------------------------------------------! - ! If this takes us into the next year, take the next year in sequence and ! - ! reset month to January. ! + ! Find next month and year. If this takes us into the next year, increment ! + ! year and reset month to January. ! !------------------------------------------------------------------------------! - if (m2 == 13) then + m2 = current_time%month + 1 + select case (m2) + case (13) m2 = 1 y2 = current_time%year + 1 - else - !----- Otherwise, use the same year. ---------------------------------------! - y2 = current_time%year - end if - iyear = y2 - iyeara + 1 + year_cyc_2 = y2 + + !----- If we are now after the last year... --------------------------------! + do while(year_cyc_2 > metcycf) + year_cyc_2 = year_cyc_2 - ncyc + end do + !---------------------------------------------------------------------------! + + !----- If we are now before the first year... ------------------------------! + do while(year_use_2 < metcyc1) + year_cyc_2 = year_cyc_2 + ncyc + end do + !---------------------------------------------------------------------------! + case default + !---- Same year as the previous month. -------------------------------------! + y2 = current_time%year + year_cyc_2 = year_cyc + !---------------------------------------------------------------------------! + end select !------------------------------------------------------------------------------# ! Again consider the special case of not cycling co2 @@ -638,13 +665,13 @@ subroutine read_met_drivers_init !------------------------------------------------------------------------! else !----- Typical case. Pool data from the meteorological cycle. -----------! - year_use_2 = metyears(iyear) + year_use_2 = year_cyc_2 !------------------------------------------------------------------------! end if !---------------------------------------------------------------------------! else !----- Typical case. Pool data from the meteorological cycle. --------------! - year_use_2 = metyears(iyear) + year_use_2 = year_cyc_2 !---------------------------------------------------------------------------! end if !----- Now, open the file once. -----------------------------------------------! @@ -757,6 +784,7 @@ subroutine read_met_drivers !----- Loop over the different file formats --------------------------------------! formloop: do iformat = 1, nformats + !------------------------------------------------------------------------------! ! SPECIAL CASE FOR CO2: ! ! Usually we do not want to cycle CO2 but only the other meteorology. ! diff --git a/ED/src/dynamics/disturbance.f90 b/ED/src/dynamics/disturbance.f90 index ad0728a26..ea34fe56f 100644 --- a/ED/src/dynamics/disturbance.f90 +++ b/ED/src/dynamics/disturbance.f90 @@ -1563,7 +1563,7 @@ subroutine site_disturbance_rates(year, cgrid) !---------------------------------------------------------------------------! case default !------ Read anthropogenic disturbance from external data set. -------------! - if (clutime%landuse(12) < 0 .or. clutime%landuse(14) < 0) then + if (clutime%landuse(12) < 0. .or. clutime%landuse(14) < 0.) then find_target = .true. cpoly%primary_harvest_target (isi) = 0. cpoly%secondary_harvest_target(isi) = 0. diff --git a/ED/src/dynamics/farq_katul.f90 b/ED/src/dynamics/farq_katul.f90 index cb3cd6ea7..0e184f0b1 100644 --- a/ED/src/dynamics/farq_katul.f90 +++ b/ED/src/dynamics/farq_katul.f90 @@ -848,7 +848,8 @@ subroutine photosynthesis_stomata_solver8(ib,gsc,limit_case, real(kind=8) :: k1,k2 !! Variable used in photosynthesis equation real(kind=8) :: a,b,c !! Coefficients of the quadratic equation to solve ci real(kind=8) :: rad !! sqrt(b2-4ac) - real(kind=8) :: dbdg,dcdg !! derivatives of b,c wrt. gsc + real(kind=8) :: dbdg !! derivatives of b wrt. gsc + real(kind=8) :: dcdg !! derivatives of c wrt. gsc !------------------------------------------------------------------------------------! diff --git a/ED/src/dynamics/forestry.f90 b/ED/src/dynamics/forestry.f90 index 320513cbf..39a27c12a 100644 --- a/ED/src/dynamics/forestry.f90 +++ b/ED/src/dynamics/forestry.f90 @@ -142,6 +142,10 @@ subroutine find_lambda_harvest(cpoly,isi,onsp,lambda_harvest) ! croplands and pastures. ! !---------------------------------------------------------------------------------! select case(ilu) + case (1,8) + !---- Pasture or cropland. Do nothing. ----------------------------------------! + continue + !------------------------------------------------------------------------------! case (2:7) hcoh_loop: do ico=1,cpatch%ncohorts ipft = cpatch%pft(ico) diff --git a/ED/src/init/landuse_init.f90 b/ED/src/init/landuse_init.f90 index 77de83090..b2839475d 100644 --- a/ED/src/init/landuse_init.f90 +++ b/ED/src/init/landuse_init.f90 @@ -112,7 +112,7 @@ subroutine read_landuse_matrix write (unit=*,fmt='(a)') ' so MAX_LU_YEARS >= IYEARZ-IYEARA+1, then recompile' write (unit=*,fmt='(a)') ' your model.' call fatal_error ('Simulation is too long for anthropogenic disturbance.' & - ,'landuse_init','landuse_init.f90') + ,'read_landuse_matrix','landuse_init.f90') end if !------------------------------------------------------------------------------------! @@ -301,7 +301,7 @@ subroutine read_landuse_matrix write (unit=*,fmt='(a,1x,i6)') ' - Nharvest:',nharvest write (unit=*,fmt='(a)') '------------------------------------' call fatal_error('Land use area is zero, it doesn''t make any sense!' & - ,'landuse_init','landuse_init.f90') + ,'read_landuse_matrix','landuse_init.f90') else lu_area_i = 1. / lu_area end if diff --git a/ED/src/io/ed_read_ed10_20_history.f90 b/ED/src/io/ed_read_ed10_20_history.f90 index 083c6e93e..23d16cf17 100644 --- a/ED/src/io/ed_read_ed10_20_history.f90 +++ b/ED/src/io/ed_read_ed10_20_history.f90 @@ -882,11 +882,16 @@ subroutine read_ed10_ed20_history_file !------------------------------------------------------------------! !------------------------------------------------------------------! - ! Initialise SLA with the look-up table value, this may be ! - ! updated during phenology initialisation, but an initial assign- ! - ! ment is needed to obtain area indices. ! + ! Initialise SLA, Vm0, Rd0, and with the look-up table value. ! + ! These variables may be updated during phenology initialisation, ! + ! or trait plasticity, but they must have an initial assignment so ! + ! we can even calculate the initial area indices and inicial trait ! + ! values needed for the trait update. ! !------------------------------------------------------------------! - cpatch%sla(ic2) = SLA(ipft(ic)) + cpatch%sla (ic2) = SLA (ipft(ic)) + cpatch%vm_bar(ic2) = Vm0 (ipft(ic)) + cpatch%rd_bar(ic2) = Rd0 (ipft(ic)) + cpatch%llspan(ic2) = leaf_lifespan(ipft(ic)) !------------------------------------------------------------------! diff --git a/ED/src/mpi/ed_para_init.f90 b/ED/src/mpi/ed_para_init.f90 index b34a0f3dd..2037f5714 100644 --- a/ED/src/mpi/ed_para_init.f90 +++ b/ED/src/mpi/ed_para_init.f90 @@ -517,7 +517,6 @@ subroutine ed_parvec_work(ifm,nxp,nyp) , npolys_run & ! intent(out) , ed_alloc_work_vec & ! subroutine , ed_nullify_work_vec ! ! subroutine - use soil_coms , only : ed_nstyp ! ! intent(in) use mem_polygons , only : maxsite ! ! intent(in) implicit none !----- Arguments. ----------------------------------------------------------------------! @@ -659,7 +658,8 @@ subroutine ed_load_work_from_history() real , external :: dist_gc !---------------------------------------------------------------------------------------! - + write (unit=*,fmt='(a)') ' Welcome to ed_load_work_from_history!' + !---------------------------------------------------------------------------------------! ! Here we decide whether this is a history or an ED-2.1 restart run. In case none ! From 3bb4d124a640c71bbd2f2568026bfecc2fe37cc6 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 12:22:51 -0700 Subject: [PATCH 03/12] Included missing variable declaration in edcp_driver.F90 and replaced huge(1.) statement with huge_num to avoid floating point exception errors. --- BRAMS/src/ed2/edcp_driver.F90 | 3 ++- ED/src/init/ed_type_init.f90 | 3 ++- diff_version.sh | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BRAMS/src/ed2/edcp_driver.F90 b/BRAMS/src/ed2/edcp_driver.F90 index ffa40b50d..08c0da483 100644 --- a/BRAMS/src/ed2/edcp_driver.F90 +++ b/BRAMS/src/ed2/edcp_driver.F90 @@ -63,7 +63,8 @@ subroutine ed_coup_driver() integer :: jd2 integer :: ierr integer :: igr - integer :: ping + integer :: ping + logical :: new_day real :: wtime1 real :: wtime2 real :: wtime_start ! wall time diff --git a/ED/src/init/ed_type_init.f90 b/ED/src/init/ed_type_init.f90 index 51a7b1187..ad93868f8 100644 --- a/ED/src/init/ed_type_init.f90 +++ b/ED/src/init/ed_type_init.f90 @@ -1526,6 +1526,7 @@ subroutine init_ed_site_vars(cpoly) , writing_eorq & ! intent(in) , writing_dcyc & ! intent(in) , economics_scheme ! ! intent(in) + use consts_coms , only : huge_num ! ! intent(in) implicit none !----- Arguments. -------------------------------------------------------------------! type(polygontype), target :: cpoly @@ -1678,7 +1679,7 @@ subroutine init_ed_site_vars(cpoly) ! Initialise the minimum monthly temperature with a very large value, this is ! ! going to be reduced as the canopy temperature is updated. ! !------------------------------------------------------------------------------------! - cpoly%min_monthly_temp(:) = huge(1.) + cpoly%min_monthly_temp(:) = huge_num !------------------------------------------------------------------------------------! diff --git a/diff_version.sh b/diff_version.sh index d3be988ac..3e69ceee0 100755 --- a/diff_version.sh +++ b/diff_version.sh @@ -38,8 +38,8 @@ work="${HOME}/Models/EDBRAMS" # Extensions. Decide how much to check. # #------------------------------------------------------------------------------------------# case "${comptype}" in -partial) exts=".c .f90 .F90" ;; -*) exts=".c .f90 .F90 .r .txt" ;; +partial) exts=".c .F90 .f90" ;; +*) exts=".c .F90 .f90 .r .txt" ;; esac #------------------------------------------------------------------------------------------# From ba7de5eb1870f598af1cff1c825ac84557fd8655 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 13:07:24 -0700 Subject: [PATCH 04/12] Turned ping into a vector of dimension 1 in ed_state_vars.F90, so the CI compiles correctly (the compiler doesn't like that the same MPI function is used for scalars and vectors). --- ED/src/memory/ed_state_vars.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ED/src/memory/ed_state_vars.F90 b/ED/src/memory/ed_state_vars.F90 index 056347b6c..1bb968a69 100644 --- a/ED/src/memory/ed_state_vars.F90 +++ b/ED/src/memory/ed_state_vars.F90 @@ -12833,7 +12833,7 @@ subroutine filltab_alltypes !----- Local variables (MPI variables). ---------------------------------------------! #if defined(RAMS_MPI) integer :: ierr - integer :: ping + integer , dimension(1) :: ping integer :: uniqueid integer , dimension(MPI_STATUS_SIZE) :: status #endif From f1332c99ac1c9d9a9ade947c143b15802864a4ab Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 13:12:48 -0700 Subject: [PATCH 05/12] Turn ping into a 2D array to see if the MPI interface errors are fixed. --- ED/build/make/include.mk.macosx | 11 +++++------ ED/src/memory/ed_state_vars.F90 | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ED/build/make/include.mk.macosx b/ED/build/make/include.mk.macosx index afbfd7cc3..5b84b9f33 100644 --- a/ED/build/make/include.mk.macosx +++ b/ED/build/make/include.mk.macosx @@ -20,8 +20,8 @@ BASE=$(ED_ROOT)/build/ # libraries compiled with the same compiler you set for F_COMP and C_COMP. You may still # # be able to compile without HDF5 but it will not run. # #------------------------------------------------------------------------------------------# -ZLIB_PATH=${HOME}/Util/ED2_Libs/zlib-1.2.11 -HDF5_PATH=${HOME}/Util/ED2_Libs/hdf5-1.12.1 +ZLIB_PATH=/usr/local +HDF5_PATH=/usr/local HDF5_INCS=-I$(HDF5_PATH)/include HDF5C_INCS=$(HDF5_INCS) HDF5_LIBS=-L$(ZLIB_PATH)/lib -lz -L$(HDF5_PATH)/lib -lhdf5_fortran -lhdf5 -lhdf5_hl @@ -51,10 +51,9 @@ USE_INTERF=1 #################################### COMPILER SETTINGS ##################################### CMACH=MAC_OS_X FC_TYPE=GNU -F_COMP=gfortran-12 -C_COMP=gcc-12 -LOADER=gfortran-12 -C_LOADER=gcc-12 +F_COMP=/usr/local/bin/gfortran-12 +C_COMP=/usr/local/bin/gcc-12 +LOADER=/usr/local/bin/gfortran-12 LIBS= MOD_EXT=mod ############################################################################################ diff --git a/ED/src/memory/ed_state_vars.F90 b/ED/src/memory/ed_state_vars.F90 index 1bb968a69..d42925302 100644 --- a/ED/src/memory/ed_state_vars.F90 +++ b/ED/src/memory/ed_state_vars.F90 @@ -12833,7 +12833,7 @@ subroutine filltab_alltypes !----- Local variables (MPI variables). ---------------------------------------------! #if defined(RAMS_MPI) integer :: ierr - integer , dimension(1) :: ping + integer , dimension(1,1) :: ping integer :: uniqueid integer , dimension(MPI_STATUS_SIZE) :: status #endif From a45bb91a34f558045bb22b4a0eb564d916637b56 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 13:22:55 -0700 Subject: [PATCH 06/12] Reverting to scalar. We will need a different approach to ensure the compilation works. --- ED/src/memory/ed_state_vars.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ED/src/memory/ed_state_vars.F90 b/ED/src/memory/ed_state_vars.F90 index d42925302..056347b6c 100644 --- a/ED/src/memory/ed_state_vars.F90 +++ b/ED/src/memory/ed_state_vars.F90 @@ -12833,7 +12833,7 @@ subroutine filltab_alltypes !----- Local variables (MPI variables). ---------------------------------------------! #if defined(RAMS_MPI) integer :: ierr - integer , dimension(1,1) :: ping + integer :: ping integer :: uniqueid integer , dimension(MPI_STATUS_SIZE) :: status #endif From cc7b79c0aaa15deb2980e4e743274506192ebcdd Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 16:00:37 -0700 Subject: [PATCH 07/12] Temporarily disabling mpi compilation from CI. --- ED/build/make/include.mk.travisci | 40 +++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/ED/build/make/include.mk.travisci b/ED/build/make/include.mk.travisci index 243995438..35ade16d0 100644 --- a/ED/build/make/include.mk.travisci +++ b/ED/build/make/include.mk.travisci @@ -39,17 +39,27 @@ USE_COLLECTIVE_MPIO=0 + +#------------------------------------------------------------------------------------------# +# This should be 1 unless you are running with -gen-interfaces. Interfaces usually # +# make the compilation to crash when the -gen-interfaces option are on, so this flag # +# bypass all interfaces in the code. # +#------------------------------------------------------------------------------------------# +USE_INTERF=1 +#------------------------------------------------------------------------------------------# + + + #################################### COMPILER SETTINGS ##################################### CMACH=TRAVISCI FC_TYPE=GNU -F_COMP=mpif90 -C_COMP=mpicc -LOADER=mpif90 +F_COMP=gfortran +C_COMP=gcc +LOADER=gfortran LIBS= MOD_EXT=mod #------------------------------------------------------------------------------------------# -USE_INTERF=1 ##################################### COMPILER OPTIONS ##################################### @@ -62,19 +72,19 @@ ifeq ($(KIND_COMP),) endif #------------------------------------------------------------------------------------------# ifeq ($(KIND_COMP),$(filter $(KIND_COMP), A B C D)) - F_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=nan \ - -ffpe-trap=invalid,zero,overflow,underflow -fbacktrace -fbounds-check \ - -frecursive - C_OPTS= -O0 -DLITTLE -g - LOADER_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=nan \ - -ffpe-trap=invalid,zero,overflow,underflow -fbacktrace -fbounds-check \ - -frecursive + F_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=snan \ + -finit-integer=-2147483648 -ffpe-trap=invalid,zero,overflow,underflow \ + -fcheck=all -frecursive -fsignaling-nans -Werror -fopenmp -fbacktrace -static + C_OPTS= -O0 -DLITTLE -g -fbacktrace -static + LOADER_OPTS= -O0 -ffree-line-length-none -g -fimplicit-none -Wall -finit-real=snan \ + -finit-integer=-2147483648 -ffpe-trap=invalid,zero,overflow,underflow \ + -fcheck=all -frecursive -fsignaling-nans -Werror -fopenmp -fbacktrace #---------------------------------------------------------------------------------------# endif ifeq ($(KIND_COMP),E) - F_OPTS= -O3 -ffree-line-length-none -frecursive -fno-whole-file -static - C_OPTS= -O0 -DLITTLE -g -static - LOADER_OPTS= -O3 -ffree-line-length-none -frecursive -fno-whole-file + F_OPTS= -O3 -ffree-line-length-none -frecursive -fopenmp -fbacktrace -static + C_OPTS= -O3 -DLITTLE -g -fbacktrace -static + LOADER_OPTS= -O3 -ffree-line-length-none -frecursive -fopenmp -fbacktrace #---------------------------------------------------------------------------------------# endif #------------------------------------------------------------------------------------------# @@ -91,7 +101,7 @@ endif MPI_PATH= PAR_INCS= PAR_LIBS= -PAR_DEFS=-DRAMS_MPI +PAR_DEFS= #------------------------------------------------------------------------------------------# From a1136d95bfbfd81fc39a7a751d2859f16490afc3 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 16:21:21 -0700 Subject: [PATCH 08/12] Expand error message in ed_met_driver for better debugging. --- ED/src/driver/ed_met_driver.f90 | 35 ++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/ED/src/driver/ed_met_driver.f90 b/ED/src/driver/ed_met_driver.f90 index abc07cfda..dea3142f6 100644 --- a/ED/src/driver/ed_met_driver.f90 +++ b/ED/src/driver/ed_met_driver.f90 @@ -588,11 +588,17 @@ subroutine read_met_drivers_init call shdf5_open_f(trim(infile),'R') else write (unit=*,fmt='(a)' ) '------------------------------' - write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 - write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf - write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear - write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc - write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE =',year_use + write (unit=*,fmt='(a,1x,a)' ) ' - MET_VARS =',trim(met_vars(iformat,1)) + write (unit=*,fmt='(a,1x,l1)' ) ' - CYCLE_CO2 =',.not. not_cycle_co2 + write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 + write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf + write (unit=*,fmt='(a,1x,i12)') ' - NCYC =',ncyc + write (unit=*,fmt='(a,1x,i12)') ' - NYEARS =',nyears + write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear + write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CURR =',current_time%month + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CURR =',current_time%year + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE =',year_use write (unit=*,fmt='(a)' ) '------------------------------' call fatal_error('Cannot open met driver input file '//trim(infile)//'!' & ,'read_met_drivers_init','ed_met_driver.f90') @@ -656,8 +662,7 @@ subroutine read_met_drivers_init ! Make sure that the special CO2 file exists. If not, then use the ! ! default met cycle years. ! !---------------------------------------------------------------------------! - write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)),y2 & - ,mname(current_time%month),'.h5' + write(infile,fmt='(a,i4.4,a,a)') trim(met_names(iformat)),y2,mname(m2),'.h5' inquire(file=trim(infile),exist=exans) if (exans) then !----- Allow CO2 outside met cycle. -------------------------------------! @@ -681,6 +686,22 @@ subroutine read_met_drivers_init if (exans) then call shdf5_open_f(trim(infile),'R') else + write (unit=*,fmt='(a)' ) '------------------------------' + write (unit=*,fmt='(a,1x,a)' ) ' - MET_VARS =',trim(met_vars(iformat,1)) + write (unit=*,fmt='(a,1x,l1)' ) ' - CYCLE_CO2 =',.not. not_cycle_co2 + write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 + write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf + write (unit=*,fmt='(a,1x,i12)') ' - NCYC =',ncyc + write (unit=*,fmt='(a,1x,i12)') ' - NYEARS =',nyears + write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear + write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CURR =',current_time%month + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CURR =',current_time%year + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE =',year_use + write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CYC_2 =',m2 + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC_2 =',year_cyc_2 + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE_2 =',year_use_2 + write (unit=*,fmt='(a)' ) '------------------------------' call fatal_error('Cannot open met driver input file '//trim(infile)//'!' & ,'read_met_drivers_init','ed_met_driver.f90') end if From 08c92e871485dd88f0a3021be24e762d292803ab Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 16:31:53 -0700 Subject: [PATCH 09/12] Fixed a couple of typo in the do while loops in ed_met_driver.f90. --- ED/src/driver/ed_met_driver.f90 | 39 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/ED/src/driver/ed_met_driver.f90 b/ED/src/driver/ed_met_driver.f90 index dea3142f6..22cf8ba18 100644 --- a/ED/src/driver/ed_met_driver.f90 +++ b/ED/src/driver/ed_met_driver.f90 @@ -632,8 +632,8 @@ subroutine read_met_drivers_init m2 = current_time%month + 1 select case (m2) case (13) - m2 = 1 - y2 = current_time%year + 1 + m2 = 1 + y2 = current_time%year + 1 year_cyc_2 = y2 !----- If we are now after the last year... --------------------------------! @@ -643,7 +643,7 @@ subroutine read_met_drivers_init !---------------------------------------------------------------------------! !----- If we are now before the first year... ------------------------------! - do while(year_use_2 < metcyc1) + do while(year_cyc_2 < metcyc1) year_cyc_2 = year_cyc_2 + ncyc end do !---------------------------------------------------------------------------! @@ -787,7 +787,7 @@ subroutine read_met_drivers !----- If we need to recycle over years, find the appropriate year to apply. --------! year_cyc = current_time%year - ncyc = metcycf - metcyc1 + 1 + ncyc = metcycf - metcyc1 + 1 !----- If we are after the last year... ---------------------------------------------! do while(year_cyc > metcycf) @@ -848,6 +848,19 @@ subroutine read_met_drivers if(exans)then call shdf5_open_f(trim(infile),'R') else + write (unit=*,fmt='(a)' ) '------------------------------' + write (unit=*,fmt='(a,1x,a)' ) ' - MET_VARS =',trim(met_vars(iformat,1)) + write (unit=*,fmt='(a,1x,l1)' ) ' - CYCLE_CO2 =',.not. not_cycle_co2 + write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 + write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf + write (unit=*,fmt='(a,1x,i12)') ' - NCYC =',ncyc + write (unit=*,fmt='(a,1x,i12)') ' - NYEARS =',nyears + write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear + write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CURR =',current_time%month + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CURR =',current_time%year + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE =',year_use + write (unit=*,fmt='(a)' ) '------------------------------' call fatal_error('Cannot open met driver input file '//trim(infile)//'!' & ,'read_met_drivers','ed_met_driver.f90') end if @@ -901,7 +914,7 @@ subroutine read_met_drivers !---------------------------------------------------------------------------! !----- If we are now before the first year... ------------------------------! - do while(year_use_2 < metcyc1) + do while(year_cyc_2 < metcyc1) year_cyc_2 = year_cyc_2 + ncyc end do !---------------------------------------------------------------------------! @@ -946,6 +959,22 @@ subroutine read_met_drivers if (exans) then call shdf5_open_f(trim(infile),'R') else + write (unit=*,fmt='(a)' ) '------------------------------' + write (unit=*,fmt='(a,1x,a)' ) ' - MET_VARS =',trim(met_vars(iformat,1)) + write (unit=*,fmt='(a,1x,l1)' ) ' - CYCLE_CO2 =',.not. not_cycle_co2 + write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 + write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf + write (unit=*,fmt='(a,1x,i12)') ' - NCYC =',ncyc + write (unit=*,fmt='(a,1x,i12)') ' - NYEARS =',nyears + write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear + write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CURR =',current_time%month + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CURR =',current_time%year + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE =',year_use + write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CYC_2 =',m2 + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC_2 =',year_cyc_2 + write (unit=*,fmt='(a,1x,i12)') ' - YEAR_USE_2 =',year_use_2 + write (unit=*,fmt='(a)' ) '------------------------------' call fatal_error ('Cannot open met driver input file '//trim(infile)//'!' & ,'read_met_drivers','ed_met_driver.f90') end if From c11f2a504c733089fcaba2924c27e0a839b9b109 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 16:36:38 -0700 Subject: [PATCH 10/12] Fixed error messages by excluding non-declared variables. --- ED/src/driver/ed_met_driver.f90 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ED/src/driver/ed_met_driver.f90 b/ED/src/driver/ed_met_driver.f90 index 22cf8ba18..8323013ef 100644 --- a/ED/src/driver/ed_met_driver.f90 +++ b/ED/src/driver/ed_met_driver.f90 @@ -854,8 +854,6 @@ subroutine read_met_drivers write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf write (unit=*,fmt='(a,1x,i12)') ' - NCYC =',ncyc - write (unit=*,fmt='(a,1x,i12)') ' - NYEARS =',nyears - write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CURR =',current_time%month write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CURR =',current_time%year write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc @@ -965,8 +963,6 @@ subroutine read_met_drivers write (unit=*,fmt='(a,1x,i12)') ' - METCYC1 =',metcyc1 write (unit=*,fmt='(a,1x,i12)') ' - METCYCF =',metcycf write (unit=*,fmt='(a,1x,i12)') ' - NCYC =',ncyc - write (unit=*,fmt='(a,1x,i12)') ' - NYEARS =',nyears - write (unit=*,fmt='(a,1x,i12)') ' - IYEAR =',iyear write (unit=*,fmt='(a,1x,i12)') ' - MONTH_CURR =',current_time%month write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CURR =',current_time%year write (unit=*,fmt='(a,1x,i12)') ' - YEAR_CYC =',year_cyc From 5b59c4d89c099138ead8544e4b4470a12315e261 Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 16:43:45 -0700 Subject: [PATCH 11/12] Fixed copy/paste error. --- ED/src/driver/ed_met_driver.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ED/src/driver/ed_met_driver.f90 b/ED/src/driver/ed_met_driver.f90 index 8323013ef..a5e6d6628 100644 --- a/ED/src/driver/ed_met_driver.f90 +++ b/ED/src/driver/ed_met_driver.f90 @@ -944,7 +944,7 @@ subroutine read_met_drivers !---------------------------------------------------------------------------! else !----- Typical case. Pool data from the meteorological cycle. --------------! - year_use = year_cyc_2 + year_use_2 = year_cyc_2 !---------------------------------------------------------------------------! end if !------------------------------------------------------------------------------! From e0f97d919b90ae5662caf59ce0b946e1b1c49dfe Mon Sep 17 00:00:00 2001 From: Marcos Longo Date: Sun, 11 Jun 2023 17:36:01 -0700 Subject: [PATCH 12/12] Add option to crash ed_filelist.F90 when the extension is not recognised. --- ED/src/utils/ed_filelist.F90 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ED/src/utils/ed_filelist.F90 b/ED/src/utils/ed_filelist.F90 index 88dd482bc..b8da21e54 100644 --- a/ED/src/utils/ed_filelist.F90 +++ b/ED/src/utils/ed_filelist.F90 @@ -202,6 +202,15 @@ subroutine ed1_fileinfo(text,nfiles,full_list,ntype,type_list,tlon_list,tlat_lis okdot = 3 case ('.lu') okdot = 2 + case default + write (unit=*,fmt='(a)' ) '----------------------------------------------' + write (unit=*,fmt='(a)' ) ' Unrecognised extension for ED1 file style! ' + write (unit=*,fmt='(a)' ) '----------------------------------------------' + write (unit=*,fmt='(a,1x,a)' ) ' TEXT = ',trim(text) + write (unit=*,fmt='(a,1x,i12)') ' NFILES = ',nfiles + write (unit=*,fmt='(a,1x,a)' ) ' FULL_LIST(1st) = ',trim(full_list(1)) + write (unit=*,fmt='(a)' ) '----------------------------------------------' + call fatal_error('Invalid file extension','ed1_fileinfo','ed_filelist.F90') end select