|
| 1 | +!-----------------------BEGIN NOTICE -- DO NOT EDIT----------------------- |
| 2 | +! NASA Goddard Space Flight Center |
| 3 | +! Land Information System Framework (LISF) |
| 4 | +! Version 7.5 |
| 5 | +! |
| 6 | +! Copyright (c) 2024 United States Government as represented by the |
| 7 | +! Administrator of the National Aeronautics and Space Administration. |
| 8 | +! All Rights Reserved. |
| 9 | +!-------------------------END NOTICE -- DO NOT EDIT----------------------- |
| 10 | +#include "LDT_misc.h" |
| 11 | +module AquaCrop_parmsMod |
| 12 | +!BOP |
| 13 | +! |
| 14 | +! !MODULE: AquaCrop_parmsMod |
| 15 | +! |
| 16 | +! !DESCRIPTION: |
| 17 | +! \subsubsection{Overview} |
| 18 | +! This routines in this module provides routines to read the AquaCrop |
| 19 | +! crop type from the AC_Crop.Inventory |
| 20 | +! |
| 21 | +! !REVISION HISTORY: |
| 22 | +! |
| 23 | +! 10 May 2024; Michel Becthold, Louise Busschaert, initial implementation |
| 24 | +! |
| 25 | + use LDT_constantsMod, only: LDT_CONST_PATH_LEN |
| 26 | + use LDT_paramDataMod, only: LDT_paramEntry |
| 27 | + |
| 28 | + implicit none |
| 29 | + |
| 30 | + PRIVATE |
| 31 | + !------------------------------------------------------------------------------ |
| 32 | + ! !PUBLIC MEMBER FUNCTIONS: |
| 33 | + !------------------------------------------------------------------------------ |
| 34 | + public :: AquaCropParms_init !allocates memory for required structures |
| 35 | + public :: AquaCropParms_writeHeader |
| 36 | + public :: AquaCropParms_writeData |
| 37 | + |
| 38 | + !------------------------------------------------------------------------------ |
| 39 | + ! !PUBLIC TYPES: |
| 40 | + !------------------------------------------------------------------------------ |
| 41 | + public :: AquaCrop_struc |
| 42 | + |
| 43 | + type, public :: aquacrop_type_dec |
| 44 | + ! - AquaCrop LSM-specific: |
| 45 | + type(LDT_paramEntry) :: cropt ! crop type |
| 46 | + type(LDT_paramEntry) :: comp_size ! compartment size |
| 47 | + type(LDT_paramEntry) :: tmin_cli ! tmin climatology |
| 48 | + type(LDT_paramEntry) :: tmax_cli ! tmax climatology |
| 49 | + integer :: nlayers ! number of soil layers |
| 50 | + real :: lthickness(5) ! thickness of layers, max 5 layers for AC |
| 51 | + integer :: max_comp ! fixed to 12 |
| 52 | + integer :: tempcli_refyr ! reference year for cli |
| 53 | + character(len=LDT_CONST_PATH_LEN) :: tempclimdir |
| 54 | + character(len=LDT_CONST_PATH_LEN) :: tempclimfile |
| 55 | + character(125) :: tempclim_gridtransform |
| 56 | + end type aquacrop_type_dec |
| 57 | + |
| 58 | + type(aquacrop_type_dec), allocatable :: AquaCrop_struc(:) |
| 59 | + |
| 60 | +contains |
| 61 | + |
| 62 | + subroutine AquaCropParms_init(flag) |
| 63 | + |
| 64 | + ! !USES: |
| 65 | + use ESMF |
| 66 | + use LDT_coreMod, only: LDT_rc, LDT_config |
| 67 | + use LDT_logMod, only: LDT_verify, LDT_logunit, LDT_endrun |
| 68 | + ! |
| 69 | + ! !DESCRIPTION: |
| 70 | + ! |
| 71 | + ! Allocates memory for data structures for reading |
| 72 | + ! the required AquaCrop datasets |
| 73 | + ! |
| 74 | + ! The routines invoked are: |
| 75 | + ! \begin{description} |
| 76 | + ! \item[read_CONSTANT_AC_crop]\newline |
| 77 | + ! calls the reader of the crop type via the Crop.Inventory |
| 78 | + ! (for now: only CONSTANT method is implemented) |
| 79 | + ! \item[define_AC_compartments]\newline |
| 80 | + ! calls the calculation fo the compartment number/size |
| 81 | + ! \item[read_AC_Tclim]\newline |
| 82 | + ! calls the reader of the Tmin and Tmax climatologies |
| 83 | + ! \end{description} |
| 84 | + ! |
| 85 | + !EOP |
| 86 | + implicit none |
| 87 | + |
| 88 | + integer, intent(in) :: flag |
| 89 | + |
| 90 | + integer :: n,k |
| 91 | + integer :: rc |
| 92 | + |
| 93 | + external :: read_CONSTANT_AC_crop |
| 94 | + external :: define_AC_compartments |
| 95 | + external :: read_AC_Tclim |
| 96 | + |
| 97 | + character*3 :: months(12) |
| 98 | + data months /'jan','feb','mar','apr','may','jun','jul','aug', & |
| 99 | + 'sep','oct','nov','dec'/ |
| 100 | + |
| 101 | + ! _____________________________________________________________________ |
| 102 | + |
| 103 | + allocate(AquaCrop_struc(LDT_rc%nnest)) |
| 104 | + do n=1,LDT_rc%nnest |
| 105 | + AquaCrop_struc(n)%max_comp = 12 |
| 106 | + ! Set crop type |
| 107 | + call set_param_attribs(Aquacrop_struc(n)%cropt, "AC_CROPT",& |
| 108 | + units="-", & |
| 109 | + full_name="Aquacrop crop type") |
| 110 | + call ESMF_ConfigFindLabel(LDT_config,"AquaCrop crop type data source:",rc=rc) |
| 111 | + call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%cropt%source,rc=rc) |
| 112 | + call LDT_verify(rc,"AquaCrop crop type data source: not defined") |
| 113 | + allocate(Aquacrop_struc(n)%cropt%value(& |
| 114 | + LDT_rc%lnc(n),LDT_rc%lnr(n),& |
| 115 | + Aquacrop_struc(n)%cropt%vlevels)) |
| 116 | + select case (AquaCrop_struc(n)%cropt%source) |
| 117 | + case( "CONSTANT" ) |
| 118 | + call read_CONSTANT_AC_crop(& |
| 119 | + n,AquaCrop_struc(n)%cropt%value(:,:,1)) |
| 120 | + case default |
| 121 | + write(LDT_logunit,*) "[ERR] crop type data source not valid for AquaCrop." |
| 122 | + write(LDT_logunit,*) " Please select: CONSTANT" |
| 123 | + write(LDT_logunit,*) "Program stopping ..." |
| 124 | + call LDT_endrun |
| 125 | + end select |
| 126 | + ! End crop type |
| 127 | + |
| 128 | + ! Define compartment size |
| 129 | + call set_param_attribs(Aquacrop_struc(n)%comp_size, "AC_comp_size",& |
| 130 | + units="m", & |
| 131 | + full_name="Aquacrop compartment size") |
| 132 | + Aquacrop_struc(n)%comp_size%vlevels = AquaCrop_struc(n)%max_comp |
| 133 | + Aquacrop_struc(n)%comp_size%num_bins = AquaCrop_struc(n)%max_comp |
| 134 | + allocate(Aquacrop_struc(n)%comp_size%value(& |
| 135 | + LDT_rc%lnc(n),LDT_rc%lnr(n),& |
| 136 | + Aquacrop_struc(n)%comp_size%vlevels)) |
| 137 | + call define_AC_compartments(n, AquaCrop_struc(n)%comp_size%value(:,:,:)) |
| 138 | + |
| 139 | + |
| 140 | + !! Read temperature climatology file |
| 141 | + ! Read options from ldt.config |
| 142 | + call ESMF_ConfigFindLabel(LDT_config,"AquaCrop temperature climatology directory:",rc=rc) |
| 143 | + call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%tempclimdir,rc=rc) |
| 144 | + call LDT_verify(rc,"AquaCrop temperature climatology directory: not defined") |
| 145 | + |
| 146 | + call ESMF_ConfigFindLabel(LDT_config,"AquaCrop reference year for climatology:",rc=rc) |
| 147 | + call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%tempcli_refyr,rc=rc) |
| 148 | + call LDT_verify(rc,"AquaCrop reference year for climatology: not defined") |
| 149 | + |
| 150 | + call ESMF_ConfigFindLabel(LDT_config,"AquaCrop temperature climatology spatial transform:",rc=rc) |
| 151 | + call ESMF_ConfigGetAttribute(LDT_config,AquaCrop_struc(n)%tempclim_gridtransform,rc=rc) |
| 152 | + call LDT_verify(rc,"AquaCrop temperature climatology spatial transform: not defined") |
| 153 | + |
| 154 | + LDT_rc%monthlyData(n) = .true. |
| 155 | + |
| 156 | + ! tmin |
| 157 | + call set_param_attribs(Aquacrop_struc(n)%tmin_cli, "AC_Tmin_clim",& |
| 158 | + units="K", & |
| 159 | + full_name="minimum temperature climatology") |
| 160 | + Aquacrop_struc(n)%tmin_cli%vlevels = 12 |
| 161 | + Aquacrop_struc(n)%tmin_cli%num_bins = 12 |
| 162 | + allocate(Aquacrop_struc(n)%tmin_cli%value(& |
| 163 | + LDT_rc%lnc(n),LDT_rc%lnr(n),& |
| 164 | + Aquacrop_struc(n)%tmin_cli%vlevels)) |
| 165 | + |
| 166 | + ! tmax |
| 167 | + call set_param_attribs(Aquacrop_struc(n)%tmax_cli, "AC_Tmax_clim",& |
| 168 | + units="K", & |
| 169 | + full_name="maximum temperature climatology") |
| 170 | + Aquacrop_struc(n)%tmax_cli%vlevels = 12 |
| 171 | + Aquacrop_struc(n)%tmax_cli%num_bins = 12 |
| 172 | + allocate(Aquacrop_struc(n)%tmax_cli%value(& |
| 173 | + LDT_rc%lnc(n),LDT_rc%lnr(n),& |
| 174 | + Aquacrop_struc(n)%tmax_cli%vlevels)) |
| 175 | + |
| 176 | + ! Call function to read monthly data |
| 177 | + do k = 1,12 |
| 178 | + AquaCrop_struc(n)%tempclimfile = & |
| 179 | + trim(AquaCrop_struc(n)%tempclimdir)//'tmin.'//& |
| 180 | + trim(months(k))//'.txt' |
| 181 | + call read_AC_Tclim(n, AquaCrop_struc(n)%tmin_cli%value(:,:,k)) |
| 182 | + AquaCrop_struc(n)%tempclimfile = & |
| 183 | + trim(AquaCrop_struc(n)%tempclimdir)//'tmax.'//& |
| 184 | + trim(months(k))//'.txt' |
| 185 | + call read_AC_Tclim(n, AquaCrop_struc(n)%tmax_cli%value(:,:,k)) |
| 186 | + enddo ! end months |
| 187 | + |
| 188 | + enddo ! End nest |
| 189 | + |
| 190 | + end subroutine AquaCropParms_init |
| 191 | + |
| 192 | + subroutine AquaCropParms_writeHeader(n,ftn,dimID,monthID) |
| 193 | + |
| 194 | + use LDT_historyMod, only: LDT_writeNetcdfDataHeader |
| 195 | + use LDT_logMod, only: LDT_verify |
| 196 | +#if(defined USE_NETCDF3 || defined USE_NETCDF4) |
| 197 | + use netcdf |
| 198 | +#endif |
| 199 | + |
| 200 | + implicit none |
| 201 | + |
| 202 | + integer, intent(in) :: n |
| 203 | + integer, intent(in) :: ftn |
| 204 | + integer, intent(in) :: dimID(3) |
| 205 | + integer, intent(in) :: monthID |
| 206 | + |
| 207 | + integer :: i |
| 208 | + integer :: ndimID(3) ! 3D, vlevel>1 |
| 209 | + character(25) :: str |
| 210 | + |
| 211 | + ndimID(1) = dimID(1) |
| 212 | + ndimID(2) = dimID(2) |
| 213 | + |
| 214 | +#if(defined USE_NETCDF3 || defined USE_NETCDF4) |
| 215 | + |
| 216 | + call LDT_writeNETCDFdataHeader(n,ftn,dimID,& |
| 217 | + Aquacrop_struc(n)%cropt) |
| 218 | + call LDT_verify(nf90_def_dim(ftn,'compartment',& |
| 219 | + AquaCrop_struc(n)%max_comp,ndimID(3))) |
| 220 | + ndimID(1) = dimID(1) |
| 221 | + ndimID(2) = dimID(2) |
| 222 | + call LDT_writeNETCDFdataHeader(n,ftn,ndimID,& |
| 223 | + Aquacrop_struc(n)%comp_size) |
| 224 | + |
| 225 | + ndimID(3) = monthID |
| 226 | + call LDT_writeNETCDFdataHeader(n,ftn,ndimID,& |
| 227 | + Aquacrop_struc(n)%tmin_cli) |
| 228 | + call LDT_writeNETCDFdataHeader(n,ftn,ndimID,& |
| 229 | + Aquacrop_struc(n)%tmax_cli) |
| 230 | + |
| 231 | + ! Add number of soil layers |
| 232 | + call LDT_verify(nf90_put_att(ftn,NF90_GLOBAL,"SOIL_LAYERS", & |
| 233 | + AquaCrop_struc(n)%nlayers)) |
| 234 | + ! Add thickness of soil layers |
| 235 | + do i=1,AquaCrop_struc(n)%nlayers |
| 236 | + write (str, '(i0)') i |
| 237 | + call LDT_verify(nf90_put_att(ftn,NF90_GLOBAL,"THICKNESS_LAYER_"//trim(str),& |
| 238 | + AquaCrop_struc(n)%lthickness(i))) |
| 239 | + ! Add Reference year for temperature climatology |
| 240 | + call LDT_verify(nf90_put_att(ftn,NF90_GLOBAL,"AC_CLIM_REF_YEAR", & |
| 241 | + AquaCrop_struc(n)%tempcli_refyr)) |
| 242 | + enddo |
| 243 | +#endif |
| 244 | + |
| 245 | + end subroutine AquaCropParms_writeHeader |
| 246 | + |
| 247 | + subroutine AquaCropParms_writeData(n,ftn) |
| 248 | + |
| 249 | + use LDT_historyMod, only: LDT_writeNetcdfData |
| 250 | + |
| 251 | + implicit none |
| 252 | + |
| 253 | + integer, intent(in) :: n |
| 254 | + integer, intent(in) :: ftn |
| 255 | + |
| 256 | + call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%cropt) |
| 257 | + call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%comp_size) |
| 258 | + call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%tmin_cli) |
| 259 | + call LDT_writeNETCDFdata(n,ftn,AquaCrop_struc(n)%tmax_cli) |
| 260 | + |
| 261 | + end subroutine AquaCropParms_writeData |
| 262 | + |
| 263 | + !BOP |
| 264 | + ! !ROUTINE: set_param_attribs |
| 265 | + ! \label{set_param_attribs} |
| 266 | + ! |
| 267 | + ! !INTERFACE: |
| 268 | + subroutine set_param_attribs(paramEntry, short_name, & |
| 269 | + units, full_name ) |
| 270 | + |
| 271 | + ! !DESCRIPTION: |
| 272 | + ! This routine reads over the parameter attribute entries |
| 273 | + ! in the param_attribs.txt file. |
| 274 | + ! |
| 275 | + ! !USES: |
| 276 | + use LDT_paramDataMod, only: LDT_paramEntry |
| 277 | + |
| 278 | + implicit none |
| 279 | + |
| 280 | + type(LDT_paramEntry),intent(inout) :: paramEntry |
| 281 | + character(len=*), intent(in) :: short_name |
| 282 | + character(len=*), optional :: units |
| 283 | + character(len=*), optional :: full_name |
| 284 | + |
| 285 | + character(20) :: unit_temp |
| 286 | + character(100):: name_temp |
| 287 | + ! ____________________________________________________ |
| 288 | + |
| 289 | + if(present(units)) then |
| 290 | + unit_temp = units |
| 291 | + else |
| 292 | + unit_temp = "none" |
| 293 | + endif |
| 294 | + if(present(full_name)) then |
| 295 | + name_temp = full_name |
| 296 | + else |
| 297 | + name_temp = trim(short_name) |
| 298 | + endif |
| 299 | + |
| 300 | + paramEntry%short_name = trim(short_name) |
| 301 | + paramEntry%vlevels = 1 |
| 302 | + paramEntry%selectOpt = 1 |
| 303 | + paramEntry%source = "AquaCrop" |
| 304 | + paramEntry%units = unit_temp |
| 305 | + paramEntry%num_times = 1 |
| 306 | + paramEntry%num_bins = 1 |
| 307 | + paramEntry%standard_name = trim(name_temp) |
| 308 | + |
| 309 | + end subroutine set_param_attribs |
| 310 | + |
| 311 | +end module AquaCrop_parmsMod |
0 commit comments