Skip to content

Commit

Permalink
Merge branch 'main' into 338-consistency_ice_veg_soil
Browse files Browse the repository at this point in the history
  • Loading branch information
C. Carouge committed Aug 7, 2024
2 parents b7068d4 + e6be17c commit 6311935
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/offline/cable.nml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
output%params = .TRUE. ! input parameters used to produce run
output%patch = .TRUE. ! write per patch
output%balances = .TRUE. ! energy and water balances
check%ranges = 0 ! variable ranges, input and output
check%ranges = 0 ! variable ranges, input and output
check%energy_bal = .TRUE. ! energy balance
check%mass_bal = .TRUE. ! water/mass balance
verbose = .TRUE. ! write details of every grid cell init and params to log?
Expand Down
2 changes: 1 addition & 1 deletion src/offline/cable_checks.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ MODULE cable_checks_module
ESoil = [-0.0015, 0.0015], &
TVeg = [-0.0003, 0.0003], &
ECanop = [-0.0003, 0.0003], &
PotEvap = [-0.0006, 0.0006], &
PotEvap = [-0.005, 0.005], & !note should encompass Evap
ACond = [0.0, 1.0], &
SoilWet = [-0.4, 1.2], &
Albedo = [0.0, 1.0], &
Expand Down
3 changes: 1 addition & 2 deletions src/offline/cable_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ PROGRAM cable_offline_driver
NRRRR, & !
ctime, & ! day count for casacnp
LOY, & ! days in year
count_sum_casa, & ! number of time steps over which casa pools &
count_sum_casa ! number of time steps over which casa pools &
!and fluxes are aggregated (for output)
wlogn = 10001

REAL :: dels ! time step size in seconds

Expand Down
3 changes: 1 addition & 2 deletions src/offline/cable_iovars.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ MODULE cable_IO_vars_module

PUBLIC
PRIVATE r_2, mvtype, mstype
!mrd561 debug
INTEGER :: wlogn

! ============ Timing variables =====================
REAL :: shod ! start time hour-of-day
Expand Down Expand Up @@ -494,6 +492,7 @@ SUBROUTINE set_group_output_values
output%Qsb = .TRUE.
output%Evap = .TRUE.
output%ECanop = .TRUE.
output%PotEvap = .TRUE.
output%TVeg = .TRUE.
output%ESoil = .TRUE.
output%HVeg = .TRUE.
Expand Down
6 changes: 5 additions & 1 deletion src/offline/cable_mpimaster.F90
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ SUBROUTINE mpidrv_master (comm)
verbose, fixedCO2,output,check,patchout, &
patch_type,landpt,soilparmnew,&
defaultLAI, sdoy, smoy, syear, timeunits, exists, output, &
latitude,longitude, calendar
latitude,longitude, calendar, set_group_output_values
USE cable_common_module, ONLY: ktau_gl, kend_gl, knode_gl, cable_user, &
cable_runtime, fileName, myhome, &
redistrb, wiltParam, satuParam, CurYear, &
Expand Down Expand Up @@ -407,6 +407,10 @@ SUBROUTINE mpidrv_master (comm)
ENDIF

! INITIALISATION depending on nml settings
! Initialise flags to output individual variables according to group
! options from the namelist file
CALL set_group_output_values()

IF (TRIM(cable_user%MetType) .EQ. 'gswp' .OR. TRIM(cable_user%MetType) .EQ. 'gswp3') THEN
IF ( CABLE_USER%YearStart.EQ.0 .AND. ncciy.GT.0) THEN
CABLE_USER%YearStart = ncciy
Expand Down
110 changes: 58 additions & 52 deletions src/offline/cable_mpiworker.F90
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ MODULE cable_mpiworker
INTEGER :: restart_t

! worker's logfile unit
!INTEGER :: wlogn
!INTEGER :: logn
!debug moved to iovars -- easy to pass around

PUBLIC :: mpidrv_worker
Expand All @@ -127,13 +127,14 @@ SUBROUTINE mpidrv_worker (comm)
USE cable_IO_vars_module, ONLY: logn,gswpfile,ncciy,leaps, globalMetfile, &
verbose, fixedCO2,output,check,patchout, &
patch_type,soilparmnew,&
defaultLAI, wlogn
defaultLAI, NO_CHECK
USE cable_common_module, ONLY: ktau_gl, kend_gl, knode_gl, cable_user, &
cable_runtime, filename, myhome, &
redistrb, wiltParam, satuParam, CurYear, &
IS_LEAPYEAR, calcsoilalbedo, &
kwidth_gl, gw_params
USE casa_ncdf_module, ONLY: is_casa_time
USE cable_checks_module, ONLY: constant_check_range
USE casa_ncdf_module, ONLY: is_casa_time
USE cable_input_module, ONLY: open_met_file,load_parameters, &
get_met_data,close_met_file
USE cable_output_module, ONLY: create_restart,open_output_file, &
Expand Down Expand Up @@ -318,11 +319,11 @@ SUBROUTINE mpidrv_worker (comm)
IF ( CABLE_USER%LogWorker ) THEN
CALL MPI_Comm_rank (comm, rank, ierr)
WRITE(cRank,FMT='(I4.4)')rank
wlogn = 1000+rank
OPEN(wlogn,FILE="cable_log_"//cRank,STATUS="REPLACE")
logn = 1000+rank
OPEN(logn,FILE="cable_log_"//cRank,STATUS="REPLACE")
ELSE
wlogn = 1000
OPEN(wlogn, FILE="/dev/null")
logn = 1000
OPEN(logn, FILE="/dev/null")
ENDIF

! INITIALISATION depending on nml settings
Expand Down Expand Up @@ -458,10 +459,15 @@ SUBROUTINE mpidrv_worker (comm)
& rough,rad,sum_flux,bal)

!mrd561 debug
WRITE(wlogn,*) ' ssat_vec min',MINVAL(soil%ssat_vec),MINLOC(soil%ssat_vec)
WRITE(wlogn,*) ' sfc_vec min',MINVAL(soil%sfc_vec),MINLOC(soil%sfc_vec)
WRITE(wlogn,*) ' wb min',MINVAL(ssnow%wb),MINLOC(ssnow%wb)
CALL flush(wlogn)
WRITE(logn,*) ' ssat_vec min',MINVAL(soil%ssat_vec),MINLOC(soil%ssat_vec)
WRITE(logn,*) ' sfc_vec min',MINVAL(soil%sfc_vec),MINLOC(soil%sfc_vec)
WRITE(logn,*) ' wb min',MINVAL(ssnow%wb),MINLOC(ssnow%wb)
CALL flush(logn)

IF (check%ranges /= NO_CHECK) THEN
WRITE (logn, *) "Checking parameter ranges"
CALL constant_check_range(soil, veg, 0, met)
END IF

IF (cable_user%call_climate) THEN
CALL worker_climate_types(comm, climate, ktauday )
Expand Down Expand Up @@ -501,9 +507,9 @@ SUBROUTINE mpidrv_worker (comm)

IF ( CABLE_USER%CASA_DUMP_READ .OR. CABLE_USER%CASA_DUMP_WRITE ) &
CALL worker_casa_dump_types(comm, casamet, casaflux, phen, climate)
WRITE(wlogn,*) 'cable_mpiworker, POPLUC: ', CABLE_USER%POPLUC
WRITE(logn,*) 'cable_mpiworker, POPLUC: ', CABLE_USER%POPLUC
WRITE(*,*) 'cable_mpiworker, POPLUC: ', CABLE_USER%POPLUC
CALL flush(wlogn)
CALL flush(logn)
IF ( CABLE_USER%POPLUC ) &
CALL worker_casa_LUC_types( comm, casapool, casabal)

Expand Down Expand Up @@ -536,7 +542,7 @@ SUBROUTINE mpidrv_worker (comm)


IF( icycle>0 .AND. spincasa) THEN
WRITE(wlogn,*) 'EXT spincasacnp enabled with mloop= ', mloop
WRITE(logn,*) 'EXT spincasacnp enabled with mloop= ', mloop
CALL worker_spincasacnp(dels,kstart,kend,mloop,veg,soil,casabiome,casapool, &
casaflux,casamet,casabal,phen,POP,climate,LALLOC, icomm, ocomm)
SPINconv = .FALSE.
Expand Down Expand Up @@ -591,8 +597,8 @@ SUBROUTINE mpidrv_worker (comm)
! increment total timstep counter
ktau_tot = ktau_tot + 1

WRITE(wlogn,*) 'ktau -',ktau_tot
CALL flush(wlogn)
WRITE(logn,*) 'ktau -',ktau_tot
CALL flush(logn)

! globally (WRT code) accessible kend through USE cable_common_module
ktau_gl = ktau_gl + 1
Expand Down Expand Up @@ -631,7 +637,7 @@ SUBROUTINE mpidrv_worker (comm)

! MPI: receive casa_dump_data for this step from the master
ELSEIF ( IS_CASA_TIME("dread", yyyy, ktau, kstart, koffset, &
kend, ktauday, wlogn) ) THEN
kend, ktauday, logn) ) THEN
CALL MPI_Recv (MPI_BOTTOM, 1, casa_dump_t, 0, ktau_gl, icomm, stat, ierr)
END IF

Expand Down Expand Up @@ -681,8 +687,8 @@ SUBROUTINE mpidrv_worker (comm)
! ENDIF

IF ( IS_CASA_TIME("write", yyyy, ktau, kstart, &
koffset, kend, ktauday, wlogn) ) THEN
! write(wlogn,*), 'IN IS_CASA', casapool%cplant(:,1)
koffset, kend, ktauday, logn) ) THEN
! write(logn,*), 'IN IS_CASA', casapool%cplant(:,1)
! CALL MPI_Send (MPI_BOTTOM,1, casa_t,0,ktau_gl,ocomm,ierr)
ENDIF

Expand Down Expand Up @@ -722,15 +728,15 @@ SUBROUTINE mpidrv_worker (comm)
! ENDIF


CALL flush(wlogn)
CALL flush(logn)
IF (icycle >0 .AND. cable_user%CALL_POP) THEN

IF (CABLE_USER%POPLUC) THEN

WRITE(wlogn,*), 'before MPI_Send casa_LUC'
WRITE(logn,*), 'before MPI_Send casa_LUC'
! worker sends casa updates required for LUC calculations here
CALL MPI_Send (MPI_BOTTOM, 1, casa_LUC_t, 0, 0, ocomm, ierr)
WRITE(wlogn,*), 'after MPI_Send casa_LUC'
WRITE(logn,*), 'after MPI_Send casa_LUC'
! master calls LUCDriver here
! worker receives casa and POP updates
CALL MPI_Recv( POP%pop_grid(1), POP%np, pop_t, 0, 0, icomm, stat, ierr )
Expand Down Expand Up @@ -782,7 +788,7 @@ SUBROUTINE mpidrv_worker (comm)
! ! Write to screen and log file:
! WRITE(*,'(A18,I3,A24)') ' Spinning up: run ',INT(ktau_tot/kend), &
! ' of data set complete...'
! WRITE(wlogn,'(A18,I3,A24)') ' Spinning up: run ',INT(ktau_tot/kend), &
! WRITE(logn,'(A18,I3,A24)') ' Spinning up: run ',INT(ktau_tot/kend), &
! ' of data set complete...'
!
! ! IF not 1st run through whole dataset:
Expand Down Expand Up @@ -877,7 +883,7 @@ SUBROUTINE mpidrv_worker (comm)

! Close log file
! MPI: closes handle to /dev/null in workers
CLOSE(wlogn)
CLOSE(logn)


RETURN
Expand Down Expand Up @@ -6792,7 +6798,7 @@ SUBROUTINE worker_restart_type (comm, canopy, air)
!mcd287 CALL MPI_Reduce (tsize, tsize, 1, MPI_INTEGER, MPI_SUM, 0, comm, ierr)
WRITE(*,*) 'b4 reduce wk', tsize, MPI_DATATYPE_NULL, 1, MPI_INTEGER, MPI_SUM, 0, comm, ierr
CALL flush(6)
!call flush(wlogn)
!call flush(logn)
CALL MPI_Reduce (tsize, MPI_DATATYPE_NULL, 1, MPI_INTEGER, MPI_SUM, 0, comm, ierr)

DEALLOCATE(types)
Expand Down Expand Up @@ -7226,7 +7232,7 @@ SUBROUTINE worker_spincasacnp( dels,kstart,kend,mloop,veg,soil,casabiome,casapoo
USE biogeochem_mod, ONLY : biogeochem

!mrd561 debug
USE cable_IO_vars_module, ONLY: wlogn
USE cable_IO_vars_module, ONLY: logn

IMPLICIT NONE
!CLN CHARACTER(LEN=99), INTENT(IN) :: fcnpspin
Expand Down Expand Up @@ -7568,11 +7574,11 @@ SUBROUTINE worker_spincasacnp( dels,kstart,kend,mloop,veg,soil,casabiome,casapoo
ENDDO ! end of nyear

ENDDO ! end of nloop
WRITE(wlogn,*) 'b4 MPI_SEND'
WRITE(logn,*) 'b4 MPI_SEND'
CALL MPI_Send (MPI_BOTTOM, 1, casa_t, 0, 0, ocomm, ierr)
WRITE(wlogn,*) 'after MPI_SEND'
WRITE(logn,*) 'after MPI_SEND'
IF(CABLE_USER%CALL_POP) CALL worker_send_pop (POP, ocomm)
WRITE(wlogn,*) 'cplant', casapool%cplant
WRITE(logn,*) 'cplant', casapool%cplant

END SUBROUTINE worker_spincasacnp

Expand All @@ -7596,7 +7602,7 @@ SUBROUTINE worker_CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
USE biogeochem_mod, ONLY : biogeochem

!mrd561 debug
USE cable_IO_vars_module, ONLY: wlogn
USE cable_IO_vars_module, ONLY: logn

IMPLICIT NONE
!CLN CHARACTER(LEN=99), INTENT(IN) :: fcnpspin
Expand Down Expand Up @@ -7695,45 +7701,45 @@ SUBROUTINE worker_CASAONLY_LUC( dels,kstart,kend,veg,soil,casabiome,casapool, &
ENDIF

IF(idoy==mdyear) THEN ! end of year
WRITE(wlogn,*) 'b4 MPI_SEND,casa_LUC_t', casapool%cplant(:,2)
CALL flush(wlogn)
WRITE(logn,*) 'b4 MPI_SEND,casa_LUC_t', casapool%cplant(:,2)
CALL flush(logn)
CALL MPI_Send (MPI_BOTTOM, 1, casa_LUC_t, 0, 0, ocomm, ierr)
WRITE(wlogn,*) 'after MPI_SEND,casa_LUC_t', casapool%cplant(:,2)
CALL flush(wlogn)
WRITE(logn,*) 'after MPI_SEND,casa_LUC_t', casapool%cplant(:,2)
CALL flush(logn)
StemNPP(:,1) = casaflux%stemnpp
StemNPP(:,2) = 0.0

CALL MPI_Comm_rank (icomm, rank, ierr)
WRITE(wlogn,*)
WRITE(wlogn,*),'rank receiving pop_grid from master', rank
!$ write(wlogn,*) 'b4 MPI_Recv, pop_t cmass: ', POP%pop_grid%cmass_sum
!$ write(wlogn,*) 'b4 MPI_Recv, pop_t LU: ', POP%pop_grid%LU
WRITE(logn,*)
WRITE(logn,*),'rank receiving pop_grid from master', rank
!$ write(logn,*) 'b4 MPI_Recv, pop_t cmass: ', POP%pop_grid%cmass_sum
!$ write(logn,*) 'b4 MPI_Recv, pop_t LU: ', POP%pop_grid%LU
CALL MPI_Recv( POP%pop_grid(1), POP%np, pop_t, 0, 0, icomm, stat, ierr )
!$ write(wlogn,*)
!$ write(wlogn,*) 'after MPI_Recv, pop_t cmass: ', POP%pop_grid%cmass_sum
WRITE(wlogn,*) 'after MPI_Recv, pop_t '
CALL flush(wlogn)
!$ write(logn,*)
!$ write(logn,*) 'after MPI_Recv, pop_t cmass: ', POP%pop_grid%cmass_sum
WRITE(logn,*) 'after MPI_Recv, pop_t '
CALL flush(logn)
IF (cable_user%CALL_POP .AND. POP%np.GT.0) THEN ! CALL_POP
WRITE(wlogn,*), 'b4 POPdriver', POP%pop_grid%cmass_sum
WRITE(logn,*), 'b4 POPdriver', POP%pop_grid%cmass_sum
CALL POPdriver(casaflux,casabal,veg, POP)

ENDIF
!$ write(wlogn,*)
!$ write(wlogn,*) 'after POPstep cmass: ', POP%pop_grid%cmass_sum
WRITE(wlogn,*) 'after POPstep ', POP%pop_grid%cmass_sum
CALL flush(wlogn)
!$ write(logn,*)
!$ write(logn,*) 'after POPstep cmass: ', POP%pop_grid%cmass_sum
WRITE(logn,*) 'after POPstep ', POP%pop_grid%cmass_sum
CALL flush(logn)
CALL worker_send_pop (POP, ocomm)
WRITE(wlogn,*) 'after worker_send_pop'
CALL flush(wlogn)
WRITE(logn,*) 'after worker_send_pop'
CALL flush(logn)
ENDIF


ENDDO
! receive updates to CASA pools resulting from LUC
WRITE(wlogn,*)
WRITE(wlogn,*) 'b4 mpi_recv casa_LUC_t '
WRITE(logn,*)
WRITE(logn,*) 'b4 mpi_recv casa_LUC_t '
CALL MPI_Recv (MPI_BOTTOM, 1, casa_LUC_t, 0, nyear, icomm, stat, ierr)
WRITE(wlogn,*) 'after mpi_recv casa_LUC_t: '
WRITE(logn,*) 'after mpi_recv casa_LUC_t: '
ENDDO

END SUBROUTINE WORKER_CASAONLY_LUC
Expand Down
11 changes: 10 additions & 1 deletion src/offline/cable_output.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ MODULE cable_output_module
Qmom, Qle, Qh, Qg, NEE, SWnet, &
LWnet, SoilMoist, SoilTemp, Albedo, &
visAlbedo, nirAlbedo, SoilMoistIce, &
Qs, Qsb, Evap, BaresoilT, SWE, SnowT, &
Qs, Qsb, Evap, PotEvap, BaresoilT, SWE, SnowT, &
RadT, VegT, Ebal, Wbal, AutoResp, RootResp, &
StemResp, LeafResp, HeteroResp, GPP, NPP, LAI, &
ECanop, TVeg, ESoil, CanopInt, SnowDepth, &
Expand Down Expand Up @@ -549,6 +549,13 @@ SUBROUTINE open_output_file(dels, soil, veg, bgc, rough, met)
ALLOCATE(out%Evap(mp))
out%Evap = 0.0 ! initialise
END IF
IF(output%PotEvap) THEN
CALL define_ovar(ncid_out, ovid%PotEvap,'PotEvap', 'kg/m^2/s', &
'Potential evaporation', patchout%PotEvap, 'dummy', &
xID, yID, zID, landID, patchID, tID)
ALLOCATE(out%PotEvap(mp))
out%PotEvap = 0.0 ! initialise
END IF
IF(output%ECanop) THEN
CALL define_ovar(ncid_out, ovid%Ecanop, 'ECanop', 'kg/m^2/s', &
'Wet canopy evaporation', patchout%ECanop, 'dummy', &
Expand Down Expand Up @@ -1732,6 +1739,8 @@ SUBROUTINE write_output(dels, ktau, met, canopy, casaflux, casapool, casamet, ss
CALL generate_out_write_acc(output%Qsb, ovid%Qsb, 'Qsb', out%Qsb, REAL(ssnow%rnof2/dels, 4), ranges%Qsb, patchout%Qsb, out_settings)
! Evap: total evapotranspiration [kg/m^2/s]
CALL generate_out_write_acc(output%Evap, ovid%Evap, 'Evap', out%Evap, REAL(canopy%fe/air%rlam, 4), ranges%Evap, patchout%Evap, out_settings)
! PotEVap: potential evapotranspiration [kg/m^2/s]
CALL generate_out_write_acc(output%PotEvap, ovid%PotEvap, 'PotEvap', out%PotEvap, REAL(canopy%epot/dels, 4), ranges%PotEvap, patchout%PotEvap, out_settings)
! ECanop: interception evaporation [kg/m^2/s]
CALL generate_out_write_acc(output%ECanop, ovid%ECanop, 'ECanop', out%ECanop, REAL(canopy%fevw/air%rlam, 4), ranges%ECanop, patchout%ECanop, out_settings)
! TVeg: vegetation transpiration [kg/m^2/s]
Expand Down
2 changes: 1 addition & 1 deletion src/offline/cable_soilparm.nml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ soilin%bch=4.2,7.1,11.4,5.15,10.4,10.4,7.12,5.83,7.1,
soilin%clay=0.09,0.3,0.67,0.2,0.42,0.48,0.27,0.17,0.3,
soilin%css=7*850,1920,2100,
soilin%hyds=0.000166,0.000004,0.000001,0.000021,0.000002,0.000001,0.000006,0.0008,0.000001,
soilin%rhosoil=1600,1600,1381,1373,1476,1521,1373,1537,910,
soilin%rhosoil=1600,1600,1381,1373,1476,1521,1373,1537,917,
soilin%sand=0.83,0.37,0.16,0.6,0.52,0.27,0.58,0.13,0.37,
soilin%sfc=0.143,0.301,0.367,0.218,0.31,0.37,0.255,0.45,0.301,
soilin%silt=0.08,0.33,0.17,0.2,0.06,0.25,0.15,0.7,0.33,
Expand Down
3 changes: 0 additions & 3 deletions src/offline/casa_cable.F90
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ SUBROUTINE POPdriver(casaflux,casabal,veg, POP)
!! vh_js !!
INTEGER, allocatable :: Iw(:) ! array of indices corresponding to woody (shrub or forest) tiles

! INTEGER, INTENT(IN) :: wlogn
INTEGER , parameter :: wlogn=6

if (.NOT.Allocated(LAIMax)) allocate(LAIMax(mp))
if (.NOT.Allocated(Cleafmean)) allocate(Cleafmean(mp))
if (.NOT.Allocated(Crootmean)) allocate(Crootmean(mp))
Expand Down
Loading

0 comments on commit 6311935

Please sign in to comment.