Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/AquaCropv7.2 integration #1633

Open
wants to merge 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
9c5e022
DEV: initial implementation AC71
lbusschaert Jan 22, 2024
31bfd5d
final fixes for original v7.1
lbusschaert Feb 7, 2024
2264d31
ENH: first major clean-up
lbusschaert Feb 8, 2024
cc29df7
"ENH: major clean-up 2, change of SOILPARM.TBL"
lbusschaert Feb 10, 2024
ca84a2e
ENH: WCM removal
lbusschaert Feb 10, 2024
572e117
ENH: simplified lis.config
lbusschaert Feb 10, 2024
fa7207c
DEV: run AC with LIS forcings
lbusschaert Mar 4, 2024
217202c
ENH: corrections for forcing ref height
lbusschaert Mar 5, 2024
74594ac
removal of MERRA2_AC
lbusschaert Mar 5, 2024
65ee56d
ENH: ac71 reads crop information from LDT
lbusschaert Mar 6, 2024
6bdaf62
DEV: spatial crops for AC71
lbusschaert Mar 6, 2024
e927640
ENH: minor edits
lbusschaert Mar 6, 2024
8f8dbc3
ENH: cleaning-up of vars before restart
lbusschaert Mar 11, 2024
ace8c8d
DEV: working restart option for ac.7.1
lbusschaert Apr 4, 2024
893b7c7
ENH: Nrsoillayers and initial cdts in lis.config
lbusschaert Apr 17, 2024
697deb6
ENH: crop and sim period defined in lis.config
lbusschaert Apr 17, 2024
abc73f7
ENH: coupling to LIS irrigation module (sprinkler)
lbusschaert Apr 18, 2024
4f89f84
ENH: cleaning up of output vars and units
lbusschaert May 3, 2024
81852ae
ENH: clean up
lbusschaert May 3, 2024
6feb0eb
ENH: final clean-up before LDT
lbusschaert May 3, 2024
56af948
DEV: AC71 in LDT
lbusschaert May 13, 2024
80ebd88
ENH: AC crop constant crop assignment
lbusschaert May 13, 2024
c3e8074
ENH: add check for model timestep
lbusschaert May 14, 2024
b5e0107
BUG: check for daily time step AC fixed
lbusschaert May 21, 2024
d250313
DEV: implementation of Trecord for GDD
lbusschaert May 24, 2024
987f8cb
BUG: typo fix
lbusschaert May 24, 2024
9d3109d
DOC: better comments
lbusschaert May 24, 2024
01705a9
ENH: added MPI_barrier -- requires testing on larger domain
lbusschaert May 24, 2024
10489d3
ENH: fixed 365-6 sim period
lbusschaert May 27, 2024
b3fdb13
BUG: fixed if statement
lbusschaert May 27, 2024
fdbb411
ENH: two arrays to use kess memory
lbusschaert May 27, 2024
c15c120
GDD implementation including Trecord
mbechtold May 28, 2024
02143f7
Merge branch 'ac.7.1_integration_v0' of https://github.com/lbusschaer…
mbechtold May 28, 2024
6c1c2d8
ENH: corrected for mpi
lbusschaert May 28, 2024
a2d164d
Merge branch 'ac.7.1_integration_v0' of https://github.com/lbusschaer…
mbechtold May 28, 2024
b3edf48
BUG: bug fix
mbechtold May 28, 2024
cc221d8
BUG: bug fix
mbechtold May 28, 2024
afaac24
DOC: minor comment
lbusschaert May 29, 2024
948d952
BUG: do not reach end of simulation
lbusschaert May 30, 2024
a3a1557
BUG: GDD implemetation
mbechtold May 30, 2024
1212376
remove Makefile
mbechtold May 30, 2024
a540b67
Merge branch 'ac.7.1_integration_v0' of https://github.com/lbusschaer…
mbechtold May 30, 2024
7f38df4
BUG: GDD implemetation
mbechtold May 31, 2024
8925881
BUG: met forcing reading (finalize-init)
lbusschaert May 31, 2024
e766e6a
Merge branch 'ac.7.1_integration_v0' of https://github.com/lbusschaer…
mbechtold May 31, 2024
f5048fd
BUG: check if end of LIS run
lbusschaert Jun 1, 2024
844ef44
DEV: layers and compartments def in LDT and read in LIS
lbusschaert Jun 1, 2024
283dc5e
Revert "ENH: coupling to LIS irrigation module (sprinkler)"
lbusschaert Jun 1, 2024
7737642
DEV: allow irrigation in AC71
lbusschaert Jun 1, 2024
bae29d6
BUG: LIS_hist mod for irr
lbusschaert Jun 1, 2024
301e4cc
ENH: sperate forcing heights to T,q and u,v
lbusschaert Jun 3, 2024
4b19f5e
BUG: report actual direction
lbusschaert Jun 6, 2024
226882a
BUG: GDD implemetation
mbechtold Jun 13, 2024
75c2273
BUG: fix for GDD implementation including external Trecord
mbechtold Jun 13, 2024
6bbf78b
BUG: end if statement missing
mbechtold Jun 14, 2024
5d0cb53
BUG: T CONST freezing
mbechtold Jun 15, 2024
3bb7fdd
BUG: fixed netcdf bug
lbusschaert Jun 17, 2024
86a9803
DEV: irrigation implementation (all options) + other fixes
lbusschaert Jun 17, 2024
b2cf4b2
Merge branch 'ac.7.1_integration_v0' into ac.7.1_integration_v0
lbusschaert Jun 17, 2024
5c95d9f
Merge pull request #2 from mbechtold/ac.7.1_integration_v0
lbusschaert Jun 17, 2024
d14621f
ENH: testing and development after GDD merge
lbusschaert Jul 8, 2024
339cc70
DEV: last changes for ac71, moving to ac72
lbusschaert Oct 1, 2024
108b5e0
DEV: renamed to ac72 before change of ac_modules
lbusschaert Oct 1, 2024
4dead5f
ENH: switch to AquaCropv7.2
lbusschaert Oct 2, 2024
3551c5a
DEV: tmin/tmax climatology ready in LDT
lbusschaert Oct 7, 2024
1614f23
ENH: climatological tmin/tmax read in LIS
lbusschaert Oct 7, 2024
fe58e9e
ENH: 0-diff calendar day crop testcases
lbusschaert Oct 10, 2024
18701cd
ENH: 0-diff GDD test case
lbusschaert Oct 21, 2024
7040596
BUG: fixed output irrigation
lbusschaert Oct 22, 2024
d89efef
BUG: fixed reading of ref climate in case of very long growth cycle
lbusschaert Oct 22, 2024
c6b508a
BUG: fix bug and prep restarting
lbusschaert Oct 22, 2024
b8a57cf
ENH: transition from aquacrop in dp to sp
lbusschaert Oct 23, 2024
410b844
BUG: LIS clock adjustment for restart
lbusschaert Oct 23, 2024
363c9d4
WIP: towards a working restart
lbusschaert Oct 25, 2024
81b3d61
ENH/STY: added restart vars and header update
lbusschaert Oct 25, 2024
f4731f5
Merge branch 'master' of github.com:NASA-LIS/LISF into ac.7.2_integra…
lbusschaert Oct 25, 2024
a94fb31
ENH: working restart
lbusschaert Oct 31, 2024
020e9dd
ENH: consistency fixes
lbusschaert Oct 31, 2024
252a5e5
ENH: minor fixes
lbusschaert Oct 31, 2024
6f0437e
ENH: minor fixes
lbusschaert Nov 4, 2024
1673435
TST: added test ldt and lis test cases
lbusschaert Nov 4, 2024
9ff66ea
ENH: minor ldt fix
lbusschaert Nov 4, 2024
628678b
ENH: undid change in metforc
lbusschaert Nov 4, 2024
5c7fb18
ENH: minor changes after comments on PR
lbusschaert Nov 5, 2024
1638147
delete user.cfg
lbusschaert Nov 6, 2024
62317a7
DOC: added AquaCrop config entries to config.adoc files
lbusschaert Nov 6, 2024
ac19e78
DOC: added AquaCrop LIS outputs to .adoc file
lbusschaert Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions ldt/configs/ldt.config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Surface model types: "LSM"
|RDHM.3.5.6 |Sacramento+snow17
|GeoWRSI.2 |GeoWRSI, v2.0
|SiB2 |SiB v2
|AquaCrop.7.2 |AquaCrop 7.2
ifdef::devonly[]
|FASST |FASST
|CABLE |CABLE
Expand Down Expand Up @@ -2987,6 +2988,49 @@ SiB2 resolution (dx): 0.05
SiB2 resolution (dy): 0.05
....

`AquaCrop crop type data source:` specifies the data source for the crop types. Only current option is "`CONSTANT`".

`AquaCrop crop library directory:` specifies the location of the crop library directory containing the AC_Crop.Inventory file and the AC_Crop.List directory containing the crop files.

`AquaCrop crop type:` specifies the crop type used for the "`CONSTANT`" crop type data source option.

`AquaCrop number of soil layers:` specifies the number of soil layers (from top to bottom).

`AquaCrop soil layer thickness:` specifies the thickness of each soil layer.

`AquaCrop temperature climatology directory:` specifies the directory containing the monthly climatologies of minimum and maximum temperatures used for the a priori parametrization of the fertility. The files are provided as formatted monthly .txt files for Tmin and Tmax.

`AquaCrop reference year for climatology`: specifies the reference year to be used for the a priori parametrization of the fertility (usually set to the center of the period used to compute the climatologies).

`AquaCrop temperature climatology spatial transform`: specifies the spatial transformation for the climatologies of minimum and maximum temperatures. Options include:

[cols="<,<",]
|===
|Value |Description

|none |Data on same grid as LDT domain
|neighbor |Reinterpolate by selecting nearest gridcell neighbor
|bilinear |Reinterpolate by using bilinear interpolation
|===

.Example _ldt.config_ entry
....
##AquaCrop crop file directories
AquaCrop crop type data source: "CONSTANT"
AquaCrop crop library directory: ./crop_params_dir/
AquaCrop crop type: "crop_type"

##AquaCrop soil layers
AquaCrop number of soil layers: 2
AquaCrop soil layer thickness: 0.3 0.9

##AquaCrop tmin/tmax climatology
AquaCrop temperature climatology directory: ./climatologies_dir/
AquaCrop reference year for climatology: 2011
AquaCrop temperature climatology spatial transform: "bilinear"
....


==== WRSI model parameter files

`WRSI landmask file:` specifies the location of the GeoWRSI 2.0 land mask file (default file is in *BIL format).
Expand Down
2 changes: 1 addition & 1 deletion ldt/make/Filepath
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dirs := . ../main ../core ../interp ../plugins ../lib/bil ../lib/xmrg ../params/mask ../params/landcover ../params/soils ../params/topo ../params/albedo ../params/gfrac ../params/LAISAI ../params/slopetype ../params/tbot ../params/pet ../params/climateparms ../params/crop_parms ../params/irrigation ../params/catchment ../params/CLM2 ../params/GeoWRSI ../params/FLAKE ../params/HYMAP ../params/JULES ../params/Mosaic ../params/Noah ../params/RDHM ../params/RUC ../params/SACHTET ../params/Snow17 ../params/SnowModel ../params/SiB2 ../params/VIC ../params/glacier ../runmodes/ANNproc ../runmodes/DApreproc ../runmodes/LSMparamproc ../runmodes/EnsRstpreproc ../runmodes/NUWRFpreproc ../runmodes/Metforcproc ../runmodes/MetTimeDScale ../runmodes/climoRstproc ../runmodes/rstTransformProc ../runmodes/StatDscaleMetForc ../runmodes/OPTUEproc/ ../domains/latlon ../domains/gaussian ../domains/hrap ../domains/lambert ../domains/polar ../domains/merc ../domains/easev2 ../DAobs/MCD15A2H_LAI ../DAobs/LISlsmSMobs ../DAobs/LISlsmPrecipobs ../DAobs/LISlsmTEFFobs ../DAobs/synthetic_sm ../DAobs/NASA_AMSRE_sm ../DAobs/LPRM_AMSREsm ../DAobs/LPRMvod ../DAobs/ESACCI_sm ../DAobs/WindSat_sm ../DAobs/GRACE_tws ../DAobs/GRACEQL_tws ../DAobs/SMOPS ../DAobs/ASCAT_TUW ../DAobs/SMOS_L2sm ../DAobs/SMOS_NESDIS ../DAobs/GCOMW_AMSR2L3snd ../DAobs/GCOMW_AMSR2L3sm ../DAobs/Aquarius_L2sm ../DAobs/simGRACE_JPL ../DAobs/SMMR_SNWD ../DAobs/SSMI_SNWD ../DAobs/ANSA_SNWD ../DAobs/NASA_SMAPsm ../DAobs/SMOS_NRTNN_L2sm ../DAobs/NASA_SMAPvod ../DAobs/GLASSlai ../DAobs/THySM ../DAobs/GEOS_FP_TEFFobs ../DAobs/SMAP_E_OPLsm ../DAobs/VIIRS_GVF ../DAobs/CDFS_GVF ../RESTRICTED/usaf/usaf ../metforcing/agrradps ../metforcing/cmap ../metforcing/cmorph ../metforcing/ecmwf ../metforcing/gdas ../metforcing/geos5fcst ../metforcing/gfs ../metforcing/gldas ../metforcing/gswp1 ../metforcing/gswp2 ../metforcing/merra2 ../metforcing/era5 ../metforcing/nam242 ../metforcing/narr ../metforcing/princeton ../metforcing/nldas2 ../metforcing/WRFoutv2 ../metforcing/WRFAKdom ../metforcing/stg2 ../metforcing/stg4 ../metforcing/3B42RTV7 ../metforcing/3B42V6 ../metforcing/3B42V7 ../metforcing/RFE2Daily ../metforcing/RFE2gdas ../metforcing/chirps2 ../MetforcScale ../ANNdata/LISlsmSM ../ANNdata/synthetic_sm ../ANNdata/LPRM_AMSREsm ../ANNdata/MODIS_LST ../ANNdata/MOD10A1 ../ANNdata/GHCNsnwd ../ANNdata/GCOMW_AMSR2_TB ../statDscale/BayesianMerging ../statDscale/Climo ../params/CLM45 ../USAFSI ../SMAP_E_OPL ../runmodes/USAFSI ../runmodes/LISHydropreproc ../runmodes/SMAP_E_OPL ../params/Crocus ../runmodes/obsSim ../obsSim/NatureRun/LISout/ ../obsSim/OSSEmask/LISout/ ../obsSim/OSSEmask/AMSR2/ ../obsSim/OSSEmask/TSMM/ ../obsSim/OSSEmask/MODIS/ ../obsSim/OSSEmask/Sentinel1A/
dirs := . ../main ../core ../interp ../plugins ../lib/bil ../lib/xmrg ../params/mask ../params/landcover ../params/soils ../params/topo ../params/albedo ../params/gfrac ../params/LAISAI ../params/slopetype ../params/tbot ../params/pet ../params/climateparms ../params/crop_parms ../params/irrigation ../params/catchment ../params/CLM2 ../params/GeoWRSI ../params/FLAKE ../params/HYMAP ../params/JULES ../params/Mosaic ../params/Noah ../params/AquaCrop ../params/RDHM ../params/RUC ../params/SACHTET ../params/Snow17 ../params/SnowModel ../params/SiB2 ../params/VIC ../params/glacier ../runmodes/ANNproc ../runmodes/DApreproc ../runmodes/LSMparamproc ../runmodes/EnsRstpreproc ../runmodes/NUWRFpreproc ../runmodes/Metforcproc ../runmodes/MetTimeDScale ../runmodes/climoRstproc ../runmodes/rstTransformProc ../runmodes/StatDscaleMetForc ../runmodes/OPTUEproc/ ../domains/latlon ../domains/gaussian ../domains/hrap ../domains/lambert ../domains/polar ../domains/merc ../domains/easev2 ../DAobs/MCD15A2H_LAI ../DAobs/LISlsmSMobs ../DAobs/LISlsmPrecipobs ../DAobs/LISlsmTEFFobs ../DAobs/synthetic_sm ../DAobs/NASA_AMSRE_sm ../DAobs/LPRM_AMSREsm ../DAobs/LPRMvod ../DAobs/ESACCI_sm ../DAobs/WindSat_sm ../DAobs/GRACE_tws ../DAobs/GRACEQL_tws ../DAobs/SMOPS ../DAobs/ASCAT_TUW ../DAobs/SMOS_L2sm ../DAobs/SMOS_NESDIS ../DAobs/GCOMW_AMSR2L3snd ../DAobs/GCOMW_AMSR2L3sm ../DAobs/Aquarius_L2sm ../DAobs/simGRACE_JPL ../DAobs/SMMR_SNWD ../DAobs/SSMI_SNWD ../DAobs/ANSA_SNWD ../DAobs/NASA_SMAPsm ../DAobs/SMOS_NRTNN_L2sm ../DAobs/NASA_SMAPvod ../DAobs/GLASSlai ../DAobs/THySM ../DAobs/GEOS_FP_TEFFobs ../DAobs/SMAP_E_OPLsm ../DAobs/VIIRS_GVF ../DAobs/CDFS_GVF ../RESTRICTED/usaf/usaf ../metforcing/agrradps ../metforcing/cmap ../metforcing/cmorph ../metforcing/ecmwf ../metforcing/gdas ../metforcing/geos5fcst ../metforcing/gfs ../metforcing/gldas ../metforcing/gswp1 ../metforcing/gswp2 ../metforcing/merra2 ../metforcing/era5 ../metforcing/nam242 ../metforcing/narr ../metforcing/princeton ../metforcing/nldas2 ../metforcing/WRFoutv2 ../metforcing/WRFAKdom ../metforcing/stg2 ../metforcing/stg4 ../metforcing/3B42RTV7 ../metforcing/3B42V6 ../metforcing/3B42V7 ../metforcing/RFE2Daily ../metforcing/RFE2gdas ../metforcing/chirps2 ../MetforcScale ../ANNdata/LISlsmSM ../ANNdata/synthetic_sm ../ANNdata/LPRM_AMSREsm ../ANNdata/MODIS_LST ../ANNdata/MOD10A1 ../ANNdata/GHCNsnwd ../ANNdata/GCOMW_AMSR2_TB ../statDscale/BayesianMerging ../statDscale/Climo ../params/CLM45 ../USAFSI ../SMAP_E_OPL ../runmodes/USAFSI ../runmodes/LISHydropreproc ../runmodes/SMAP_E_OPL ../params/Crocus ../runmodes/obsSim ../obsSim/NatureRun/LISout/ ../obsSim/OSSEmask/LISout/ ../obsSim/OSSEmask/AMSR2/ ../obsSim/OSSEmask/TSMM/ ../obsSim/OSSEmask/MODIS/ ../obsSim/OSSEmask/Sentinel1A/
295 changes: 295 additions & 0 deletions ldt/params/AquaCrop/AquaCrop_parmsMod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
!-----------------------BEGIN NOTICE -- DO NOT EDIT-----------------------
! NASA Goddard Space Flight Center
! Land Information System Framework (LISF)
! Version 7.5
!
! Copyright (c) 2024 United States Government as represented by the
! Administrator of the National Aeronautics and Space Administration.
! All Rights Reserved.
!-------------------------END NOTICE -- DO NOT EDIT-----------------------
module AquaCrop_parmsMod
!BOP
!
! !MODULE: AquaCrop_parmsMod
!
! !DESCRIPTION:
! \subsubsection{Overview}
! This routines in this module provides routines to read the AquaCrop
! crop type from the AC_Crop.Inventory
!
! !REVISION HISTORY:
!
! 10 May 2024; Michel Becthold, Louise Busschaert, initial implementation
!
#if(defined USE_NETCDF3 || defined USE_NETCDF4)
use netcdf
#endif
use ESMF
use LDT_coreMod
use LDT_historyMod
use LDT_paramDataMod
use LDT_logMod
use LDT_paramMaskCheckMod
use LDT_constantsMod, only : LDT_CONST_PATH_LEN

implicit none

PRIVATE
!------------------------------------------------------------------------------
! !PUBLIC MEMBER FUNCTIONS:
!------------------------------------------------------------------------------
public :: AquaCropParms_init !allocates memory for required structures
public :: AquaCropParms_writeHeader
public :: AquaCropParms_writeData

!------------------------------------------------------------------------------
! !PUBLIC TYPES:
!------------------------------------------------------------------------------
public :: AquaCrop_struc

type, public :: aquacrop_type_dec
! - AquaCrop LSM-specific:
type(LDT_paramEntry) :: cropt ! crop type
type(LDT_paramEntry) :: comp_size ! compartment size
type(LDT_paramEntry) :: tmin_cli ! tmin climatology
type(LDT_paramEntry) :: tmax_cli ! tmax climatology
integer :: nlayers ! number of soil layers
real :: lthickness(5) ! thickness of layers, max 5 layers for AC
integer :: max_comp ! fixed to 12
integer :: tempcli_refyr ! reference year for cli
character(len=LDT_CONST_PATH_LEN) :: tempclimdir
character(125) :: tempclimfile
character(125) :: tempclim_gridtransform
end type aquacrop_type_dec

type(aquacrop_type_dec), allocatable :: AquaCrop_struc(:)



contains

subroutine AquaCropParms_init(flag)
! !USES:
use LDT_fileIOMod, only : LDT_readDomainConfigSpecs
use LDT_logMod, only : LDT_verify
!
! !DESCRIPTION:
!
! Allocates memory for data structures for reading
! the required AquaCrop datasets
!
! The routines invoked are:
! \begin{description}
! \item[read_CONSTANT_AC_crop]\newline
! calls the reader of the crop type via the Crop.Inventory
! (for now: only CONSTANT method is implemented)
! \item[define_AC_compartments]\newline
! calls the calculation fo the compartment number/size
! \item[read_AC_Tclim]\newline
! calls the reader of the Tmin and Tmax climatologies
! \end{description}
!
!EOP
implicit none
integer :: flag
integer :: n,i,c,r,m,k
integer :: rc

character*3 :: months(12)
data months /'jan','feb','mar','apr','may','jun','jul','aug',&
'sep','oct','nov','dec'/

! _____________________________________________________________________

allocate(AquaCrop_struc(LDT_rc%nnest))
do n=1,LDT_rc%nnest
AquaCrop_struc(n)%max_comp = 12
! Set crop type
call set_param_attribs(Aquacrop_struc(n)%cropt, "AC_CROPT",&
units="-", &
full_name="Aquacrop crop type")
call ESMF_ConfigFindLabel(LDT_config,"AquaCrop crop type data source:",rc=rc)
call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%cropt%source,rc=rc)
call LDT_verify(rc,"AquaCrop crop type data source: not defined")
allocate(Aquacrop_struc(n)%cropt%value(&
LDT_rc%lnc(n),LDT_rc%lnr(n),&
Aquacrop_struc(n)%cropt%vlevels))
select case (AquaCrop_struc(n)%cropt%source)
case( "CONSTANT" )
call read_CONSTANT_AC_crop(&
n,AquaCrop_struc(n)%cropt%value(:,:,1))
case default
write(LDT_logunit,*) "[WARN] crop type data source not valid for AquaCrop."
write(LDT_logunit,*) " Please select: CONSTANT"
write(LDT_logunit,*) "Program stopping ..."
call LDT_endrun
end select
! End crop type

! Define compartment size
call set_param_attribs(Aquacrop_struc(n)%comp_size, "AC_comp_size",&
units="m", &
full_name="Aquacrop compartment size")
Aquacrop_struc(n)%comp_size%vlevels = AquaCrop_struc(n)%max_comp
Aquacrop_struc(n)%comp_size%num_bins = AquaCrop_struc(n)%max_comp
allocate(Aquacrop_struc(n)%comp_size%value(&
LDT_rc%lnc(n),LDT_rc%lnr(n),&
Aquacrop_struc(n)%comp_size%vlevels))
call define_AC_compartments(n, AquaCrop_struc(n)%comp_size%value(:,:,:))


!! Read temperature climatology file
! Read options from ldt.config
call ESMF_ConfigFindLabel(LDT_config,"AquaCrop temperature climatology directory:",rc=rc)
call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%tempclimdir,rc=rc)
call LDT_verify(rc,"AquaCrop temperature climatology directory: not defined")

call ESMF_ConfigFindLabel(LDT_config,"AquaCrop reference year for climatology:",rc=rc)
call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%tempcli_refyr,rc=rc)
call LDT_verify(rc,"AquaCrop reference year for climatology: not defined")

call ESMF_ConfigFindLabel(LDT_config,"AquaCrop temperature climatology spatial transform:",rc=rc)
call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%tempclim_gridtransform,rc=rc)
call LDT_verify(rc,"AquaCrop temperature climatology spatial transform: not defined")

LDT_rc%monthlyData(n) = .true.

! tmin
call set_param_attribs(Aquacrop_struc(n)%tmin_cli, "AC_Tmin_clim",&
units="K", &
full_name="minimum temperature climatology")
Aquacrop_struc(n)%tmin_cli%vlevels = 12
Aquacrop_struc(n)%tmin_cli%num_bins = 12
allocate(Aquacrop_struc(n)%tmin_cli%value(&
LDT_rc%lnc(n),LDT_rc%lnr(n),&
Aquacrop_struc(n)%tmin_cli%vlevels))

! tmax
call set_param_attribs(Aquacrop_struc(n)%tmax_cli, "AC_Tmax_clim",&
units="K", &
full_name="maximum temperature climatology")
Aquacrop_struc(n)%tmax_cli%vlevels = 12
Aquacrop_struc(n)%tmax_cli%num_bins = 12
allocate(Aquacrop_struc(n)%tmax_cli%value(&
LDT_rc%lnc(n),LDT_rc%lnr(n),&
Aquacrop_struc(n)%tmax_cli%vlevels))

! Call function to read monthly data
do k = 1,12
AquaCrop_struc(n)%tempclimfile = &
trim(AquaCrop_struc(n)%tempclimdir)//'tmin.'//&
trim(months(k))//'.txt'
call read_AC_Tclim(n, AquaCrop_struc(n)%tmin_cli%value(:,:,k))
AquaCrop_struc(n)%tempclimfile = &
trim(AquaCrop_struc(n)%tempclimdir)//'tmax.'//&
trim(months(k))//'.txt'
call read_AC_Tclim(n, AquaCrop_struc(n)%tmax_cli%value(:,:,k))
enddo ! end months

enddo ! End nest

end subroutine AquaCropParms_init

subroutine AquaCropParms_writeHeader(n,ftn,dimID,monthID)

use netcdf

integer :: n,i
integer :: ftn
integer :: dimID(3)
integer :: monthID

integer :: ndimID(3) ! 3D, vlevel>1
character(25) :: str

ndimID(1) = dimID(1)
ndimID(2) = dimID(2)

call LDT_writeNETCDFdataHeader(n,ftn,dimID,&
Aquacrop_struc(n)%cropt)
call LDT_verify(nf90_def_dim(ftn,'compartment',&
AquaCrop_struc(n)%max_comp,ndimID(3)))
ndimID(1) = dimID(1)
ndimID(2) = dimID(2)
call LDT_writeNETCDFdataHeader(n,ftn,ndimID,&
Aquacrop_struc(n)%comp_size)

ndimID(3) = monthID
call LDT_writeNETCDFdataHeader(n,ftn,ndimID,&
Aquacrop_struc(n)%tmin_cli)
call LDT_writeNETCDFdataHeader(n,ftn,ndimID,&
Aquacrop_struc(n)%tmax_cli)

! Add number of soil layers
call LDT_verify(nf90_put_att(ftn,NF90_GLOBAL,"SOIL_LAYERS", &
AquaCrop_struc(n)%nlayers))
! Add thickness of soil layers
do i=1,AquaCrop_struc(n)%nlayers
write (str, '(i0)') i
call LDT_verify(nf90_put_att(ftn,NF90_GLOBAL,"THICKNESS_LAYER_"//trim(str),&
AquaCrop_struc(n)%lthickness(i)))
! Add Reference year for temperature climatology
call LDT_verify(nf90_put_att(ftn,NF90_GLOBAL,"AC_CLIM_REF_YEAR", &
AquaCrop_struc(n)%tempcli_refyr))
enddo

end subroutine AquaCropParms_writeHeader

subroutine AquaCropParms_writeData(n,ftn)

integer :: n
integer :: ftn

call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%cropt)
call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%comp_size)
call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%tmin_cli)
call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%tmax_cli)

end subroutine AquaCropParms_writeData


!BOP
! !ROUTINE: set_param_attribs
! \label{set_param_attribs}
!
! !INTERFACE:
subroutine set_param_attribs(paramEntry, short_name, &
units, full_name )

! !DESCRIPTION:
! This routine reads over the parameter attribute entries
! in the param_attribs.txt file.
!
! !USES:
type(LDT_paramEntry),intent(inout) :: paramEntry
character(len=*), intent(in) :: short_name
character(len=*), optional :: units
character(len=*), optional :: full_name

character(20) :: unit_temp
character(100):: name_temp
! ____________________________________________________

if(present(units)) then
unit_temp = units
else
unit_temp = "none"
endif
if(present(full_name)) then
name_temp = full_name
else
name_temp = trim(short_name)
endif

paramEntry%short_name = trim(short_name)
paramEntry%vlevels = 1
paramEntry%selectOpt = 1
paramEntry%source = "AquaCrop"
paramEntry%units = unit_temp
paramEntry%num_times = 1
paramEntry%num_bins = 1
paramEntry%standard_name = trim(name_temp)

end subroutine set_param_attribs

end module AquaCrop_parmsMod
Loading