@@ -22,6 +22,8 @@ module SoilStateInitTimeConstMod
2222 ! !PRIVATE DATA:
2323 ! Control variables (from namelist)
2424 logical , private :: organic_frac_squared ! If organic fraction should be squared (as in CLM4.5)
25+ logical , private :: parameters_in_file ! If soil hydraulic parameters should be read from file
26+ logical , private :: parameters_in_file_adj ! If adjusted soil hydraulic parameters should be read from file
2527
2628 character (len=* ), parameter , private :: sourcefile = &
2729 __FILE__
@@ -55,11 +57,14 @@ subroutine ReadNL( nlfilename )
5557
5658 character (len=* ), parameter :: nl_name = ' clm_soilstate_inparm' ! Namelist name
5759 ! MUST agree with name in namelist and read
58- namelist / clm_soilstate_inparm / organic_frac_squared
60+ namelist / clm_soilstate_inparm / organic_frac_squared, parameters_in_file, &
61+ parameters_in_file_adj
5962
6063 ! preset values
6164
6265 organic_frac_squared = .false.
66+ parameters_in_file = .false.
67+ parameters_in_file_adj = .false.
6368
6469 if ( masterproc )then
6570
@@ -80,6 +85,14 @@ subroutine ReadNL( nlfilename )
8085 end if
8186
8287 call shr_mpi_bcast(organic_frac_squared, mpicom)
88+ call shr_mpi_bcast(parameters_in_file, mpicom)
89+ call shr_mpi_bcast(parameters_in_file_adj, mpicom)
90+
91+ ! Check for incompatible namelist settings
92+ if (parameters_in_file .and. parameters_in_file_adj) then
93+ call endrun(msg= ' ERROR: parameters_in_file and parameters_in_file_adj cannot both be .true.' // &
94+ errmsg(sourcefile, __LINE__))
95+ end if
8396
8497 end subroutine ReadNL
8598
@@ -167,9 +180,6 @@ subroutine SoilStateInitTimeConst(bounds, soilstate_inst, nlfilename)
167180 integer :: begp, endp
168181 integer :: begc, endc
169182 integer :: begg, endg
170- ! SHP start
171- logical :: parameters_in_file, parameters_in_file_adj
172- ! SHP end
173183 !- ----------------------------------------------------------------------
174184
175185 begp = bounds% begp; endp= bounds% endp
@@ -240,15 +250,19 @@ subroutine SoilStateInitTimeConst(bounds, soilstate_inst, nlfilename)
240250 allocate (sand3d(begg:endg,nlevsoifl))
241251 allocate (clay3d(begg:endg,nlevsoifl))
242252! SHP start
243- allocate (thetas(begg:endg,nlevsoifl))
244- allocate (shape_param(begg:endg,nlevsoifl))
245- allocate (psis_sat(begg:endg,nlevsoifl))
246- allocate (ks(begg:endg,nlevsoifl))
247-
248- allocate (thetas_adj(begg:endg,nlevgrnd))
249- allocate (shape_param_adj(begg:endg,nlevgrnd))
250- allocate (psis_sat_adj(begg:endg,nlevgrnd))
251- allocate (ks_adj(begg:endg,nlevgrnd))
253+ if (parameters_in_file) then
254+ allocate (thetas(begg:endg,nlevsoifl))
255+ allocate (shape_param(begg:endg,nlevsoifl))
256+ allocate (psis_sat(begg:endg,nlevsoifl))
257+ allocate (ks(begg:endg,nlevsoifl))
258+ end if
259+
260+ if (parameters_in_file_adj) then
261+ allocate (thetas_adj(begg:endg,nlevgrnd))
262+ allocate (shape_param_adj(begg:endg,nlevgrnd))
263+ allocate (psis_sat_adj(begg:endg,nlevgrnd))
264+ allocate (ks_adj(begg:endg,nlevgrnd))
265+ end if
252266! SHP end
253267
254268 ! Determine organic_max from parameter file
@@ -279,65 +293,59 @@ subroutine SoilStateInitTimeConst(bounds, soilstate_inst, nlfilename)
279293
280294 call ncd_io(ncid= ncid, varname= ' PCT_SAND' , flag= ' read' , data = sand3d, dim1name= grlnd, readvar= readvar)
281295 if (.not. readvar) then
282- call endrun(msg= ' ERROR: PCT_SAND NOT on surfdata file' // errMsg(sourcefile, __LINE__))
296+ call endrun(msg= ' ERROR: PCT_SAND NOT on surfdata file' // errMsg(sourcefile, __LINE__))
283297 end if
284298
285299 call ncd_io(ncid= ncid, varname= ' PCT_CLAY' , flag= ' read' , data = clay3d, dim1name= grlnd, readvar= readvar)
286300 if (.not. readvar) then
287- call endrun(msg= ' ERROR: PCT_CLAY NOT on surfdata file' // errMsg(sourcefile, __LINE__))
301+ call endrun(msg= ' ERROR: PCT_CLAY NOT on surfdata file' // errMsg(sourcefile, __LINE__))
288302 end if
289303
290304! SHP start
291305 ! include option to also read hydraulic parameters from file. Keep it variable so that the code also works for surface files that were
292306 ! generated without parameter perturbation and parameter as input variables
293307
294- call ncd_io(ncid= ncid, varname= ' THETAS' , flag= ' read' , data = thetas, dim1name= grlnd, readvar= readvar)
295- if (.not. readvar) then
296- parameters_in_file = .False.
297- else
298- parameters_in_file = .True.
299- end if
308+ if (parameters_in_file) then
309+ call ncd_io(ncid= ncid, varname= ' THETAS' , flag= ' read' , data = thetas, dim1name= grlnd, readvar= readvar)
310+ if (.not. readvar) then
311+ call endrun(msg= ' ERROR: THETAS NOT on surfdata file' // errMsg(sourcefile, __LINE__))
312+ end if
300313
301- if (parameters_in_file) then ! read also other paramters, if one of them is not included, use sand and clay to compute parameters
302- ! via pedotransfer function
303314 call ncd_io(ncid= ncid, varname= ' SHAPE_PARAM' , flag= ' read' , data = shape_param, dim1name= grlnd, readvar= readvar)
304315 if (.not. readvar) then
305- parameters_in_file = .False.
316+ call endrun(msg = ' ERROR: SHAPE_PARAM NOT on surfdata file ' // errMsg(sourcefile, __LINE__))
306317 end if
307318
308319 call ncd_io(ncid= ncid, varname= ' PSIS_SAT' , flag= ' read' , data = psis_sat, dim1name= grlnd, readvar= readvar)
309320 if (.not. readvar) then
310- parameters_in_file = .False.
321+ call endrun(msg = ' ERROR: PSIS_SAT NOT on surfdata file ' // errMsg(sourcefile, __LINE__))
311322 end if
312323
313324 call ncd_io(ncid= ncid, varname= ' KSAT' , flag= ' read' , data = ks, dim1name= grlnd, readvar= readvar)
314325 if (.not. readvar) then
315- parameters_in_file = .False.
326+ call endrun(msg = ' ERROR: KSAT NOT on surfdata file ' // errMsg(sourcefile, __LINE__))
316327 end if
317328 end if
318329
319- call ncd_io(ncid= ncid, varname= ' THETAS_adj' , flag= ' read' , data = thetas_adj, dim1name= grlnd, readvar= readvar)
320- if (.not. readvar) then
321- parameters_in_file_adj = .False.
322- else
323- parameters_in_file_adj = .True.
324- end if
330+ if (parameters_in_file_adj) then
331+ call ncd_io(ncid= ncid, varname= ' THETAS_adj' , flag= ' read' , data = thetas_adj, dim1name= grlnd, readvar= readvar)
332+ if (.not. readvar) then
333+ call endrun(msg= ' ERROR: THETAS_ADJ NOT on surfdata file' // errMsg(sourcefile, __LINE__))
334+ end if
325335
326- if (parameters_in_file_adj) then ! read also other paramters, if one of them is not included, use sand and clay to compute parameters
327- ! via pedotransfer function
328336 call ncd_io(ncid= ncid, varname= ' SHAPE_PARAM_adj' , flag= ' read' , data = shape_param_adj, dim1name= grlnd, readvar= readvar)
329337 if (.not. readvar) then
330- parameters_in_file_adj = .False.
338+ call endrun(msg = ' ERROR: SHAPE_PARAM_adj NOT on surfdata file ' // errMsg(sourcefile, __LINE__))
331339 end if
332340
333341 call ncd_io(ncid= ncid, varname= ' PSIS_SAT_adj' , flag= ' read' , data = psis_sat_adj, dim1name= grlnd, readvar= readvar)
334342 if (.not. readvar) then
335- parameters_in_file_adj = .False.
343+ call endrun(msg = ' ERROR: PSIS_SAT_adj NOT on surfdata file ' // errMsg(sourcefile, __LINE__))
336344 end if
337345
338346 call ncd_io(ncid= ncid, varname= ' KSAT_adj' , flag= ' read' , data = ks_adj, dim1name= grlnd, readvar= readvar)
339347 if (.not. readvar) then
340- parameters_in_file_adj = .False.
348+ call endrun(msg = ' ERROR: KSAT_adj NOT on surfdata file ' // errMsg(sourcefile, __LINE__))
341349 end if
342350 end if
343351! SHP end
@@ -744,8 +752,12 @@ subroutine SoilStateInitTimeConst(bounds, soilstate_inst, nlfilename)
744752 deallocate (sand3d, clay3d, organic3d)
745753 deallocate (zisoifl, zsoifl, dzsoifl)
746754! SHP start
747- deallocate (thetas, shape_param, psis_sat, ks)
748- deallocate (thetas_adj, shape_param_adj, psis_sat_adj, ks_adj)
755+ if (parameters_in_file) then
756+ deallocate (thetas, shape_param, psis_sat, ks)
757+ end if
758+ if (parameters_in_file_adj) then
759+ deallocate (thetas_adj, shape_param_adj, psis_sat_adj, ks_adj)
760+ end if
749761! SHP end
750762
751763 end subroutine SoilStateInitTimeConst
0 commit comments