chgres_cube 1.14.0
Loading...
Searching...
No Matches
program_setup.F90
Go to the documentation of this file.
1
4
10
11 use esmf
12 use utilities, only : error_handler, to_lower
13
14 implicit none
15
16 private
17
18 character(len=500), public :: varmap_file = "NULL"
19 character(len=500), public :: atm_files_input_grid(6) = "NULL"
23 character(len=500), public :: atm_core_files_input_grid(7) = "NULL"
25 character(len=500), public :: atm_tracer_files_input_grid(6) = "NULL"
27 character(len=500), public :: data_dir_input_grid = "NULL"
28 character(len=500), public :: fix_dir_target_grid = "NULL"
29 character(len=500), public :: mosaic_file_input_grid = "NULL"
30 character(len=500), public :: mosaic_file_target_grid = "NULL"
31 character(len=500), public :: nst_files_input_grid = "NULL"
32 character(len=500), public :: grib2_file_input_grid = "NULL"
34 character(len=500), public :: geogrid_file_input_grid = "NULL"
37 character(len=500), public :: orog_dir_input_grid = "NULL"
39 character(len=500), public :: orog_files_input_grid(6) = "NULL"
40 character(len=500), public :: orog_dir_target_grid = "NULL"
41 character(len=500), public :: orog_files_target_grid(6) = "NULL"
42 character(len=500), public :: sfc_files_input_grid(6) = "NULL"
43 character(len=500), public :: vcoord_file_target_grid = "NULL"
44 character(len=500), public :: thomp_mp_climo_file= "NULL"
45 character(len=15), public :: cres_target_grid = "NULL"
46 character(len=500), public :: atm_weight_file="NULL"
47 character(len=25), public :: input_type="restart"
61 character(len=20), public :: external_model="GFS"
64
65 integer, parameter, public :: max_tracers=100
66 integer, public :: num_tracers
67 integer, public :: num_tracers_input
68
69 logical, allocatable, public :: read_from_input(:)
71
72 character(len=20), public :: tracers(max_tracers)="NULL"
78 character(len=20), public :: tracers_input(max_tracers)="NULL"
83 character(len=20), allocatable, public :: missing_var_methods(:)
85 character(len=20), allocatable, public :: chgres_var_names(:)
87 character(len=20), allocatable, public :: field_var_names(:)
88
89 character(len=500), public :: wam_parm_file="msis21.parm"
90
91 integer, public :: cycle_year = -999
92 integer, public :: cycle_mon = -999
93 integer, public :: cycle_day = -999
94 integer, public :: cycle_hour = -999
95 integer, public :: regional = 0
99 integer, public :: halo_bndy = 0
101 integer, public :: halo_blend = 0
103 integer, public :: nsoill_out = 4
105
106 logical, public :: convert_atm = .false.
107 logical, public :: convert_nst = .false.
108 logical, public :: convert_sfc = .false.
109 logical, public :: wam_cold_start = .false.
110
111 ! Options for replacing vegetation/soil type, veg fraction, and lai with data from the grib2 file
112 ! Default is to use climatology instead
113 logical, public :: vgtyp_from_climo = .true.
117 logical, public :: sotyp_from_climo = .true.
122 logical, public :: vgfrc_from_climo = .true.
126
127 logical, public :: minmax_vgfrc_from_climo = .true.
131 logical, public :: lai_from_climo = .true.
134 logical, public :: tg3_from_soil = .false.
137 logical, public :: use_thomp_mp_climo=.false.
139
140 real, allocatable, public :: drysmc_input(:)
141 real, allocatable, public :: drysmc_target(:)
142 real, allocatable, public :: maxsmc_input(:)
143 real, allocatable, public :: maxsmc_target(:)
144 real, allocatable, public :: refsmc_input(:)
145 real, allocatable, public :: refsmc_target(:)
146 real, allocatable, public :: wltsmc_input(:)
147 real, allocatable, public :: wltsmc_target(:)
148 real, allocatable, public :: bb_target(:)
149 real, allocatable, public :: satpsi_target(:)
150 real(kind=esmf_kind_r4), allocatable, public :: missing_var_values(:)
152
153 public :: read_setup_namelist
155 public :: read_varmap
156 public :: get_var_cond
157
158 contains
159
165 subroutine read_setup_namelist(filename)
166
167 use mpi_f08
168
169 implicit none
170
171 character(len=*), intent(in), optional :: filename
172 character(len=250), allocatable :: filename_to_use
173
174 integer :: i, is, ie, ierr, myrank
175
176 namelist /config/ varmap_file, &
207 halo_bndy, &
208 halo_blend, &
209 nsoill_out, &
211
212 if (present(filename)) then
213 filename_to_use = filename
214 else
215 filename_to_use = "./fort.41"
216 endif
217
218 call mpi_comm_rank(mpi_comm_world, myrank, ierr)
219
220 if (myrank == 0) then
221 print*,"- READ SETUP NAMELIST"
222 open(41, file=trim(filename_to_use), iostat=ierr)
223 if (ierr /= 0) call error_handler("OPENING SETUP NAMELIST.", ierr)
224 read(41, nml=config, iostat=ierr)
225 if (ierr /= 0) call error_handler("READING SETUP NAMELIST.", ierr)
226 close (41)
227 endif
228
229 call mpi_barrier(mpi_comm_world,ierr)
230 call mpi_bcast(varmap_file,len(varmap_file),mpi_character,0,mpi_comm_world,ierr)
231 call mpi_bcast(mosaic_file_target_grid,len(mosaic_file_target_grid),mpi_character,0,mpi_comm_world,ierr)
232 call mpi_bcast(fix_dir_target_grid,len(fix_dir_target_grid),mpi_character,0,mpi_comm_world,ierr)
233 call mpi_bcast(orog_dir_target_grid,len(orog_dir_target_grid),mpi_character,0,mpi_comm_world,ierr)
234 do i = 1, 6
235 call mpi_bcast(orog_files_target_grid(i),len(orog_files_target_grid),mpi_character,0,mpi_comm_world,ierr)
236 enddo
237 call mpi_bcast(mosaic_file_input_grid,len(mosaic_file_input_grid),mpi_character,0,mpi_comm_world,ierr)
238 call mpi_bcast(orog_dir_input_grid,len(orog_dir_input_grid),mpi_character,0,mpi_comm_world,ierr)
239 do i = 1, 6
240 call mpi_bcast(orog_files_input_grid(i),len(orog_files_input_grid),mpi_character,0,mpi_comm_world,ierr)
241 enddo
242 call mpi_bcast(nst_files_input_grid,len(nst_files_input_grid),mpi_character,0,mpi_comm_world,ierr)
243 do i = 1, 6
244 call mpi_bcast(sfc_files_input_grid(i),len(sfc_files_input_grid),mpi_character,0,mpi_comm_world,ierr)
245 call mpi_bcast(atm_files_input_grid(i),len(atm_files_input_grid),mpi_character,0,mpi_comm_world,ierr)
246 call mpi_bcast(atm_tracer_files_input_grid(i),len(atm_tracer_files_input_grid),mpi_character,0,mpi_comm_world,ierr)
247 enddo
248 do i = 1, 7
249 call mpi_bcast(atm_core_files_input_grid(i),len(atm_core_files_input_grid),mpi_character,0,mpi_comm_world,ierr)
250 enddo
251 call mpi_bcast(grib2_file_input_grid,len(grib2_file_input_grid),mpi_character,0,mpi_comm_world,ierr)
252 call mpi_bcast(geogrid_file_input_grid,len(geogrid_file_input_grid),mpi_character,0,mpi_comm_world,ierr)
253 call mpi_bcast(data_dir_input_grid,len(data_dir_input_grid),mpi_character,0,mpi_comm_world,ierr)
254 call mpi_bcast(vcoord_file_target_grid,len(vcoord_file_target_grid),mpi_character,0,mpi_comm_world,ierr)
255 call mpi_bcast(cycle_year,1,mpi_integer,0,mpi_comm_world,ierr)
256 call mpi_bcast(cycle_mon,1,mpi_integer,0,mpi_comm_world,ierr)
257 call mpi_bcast(cycle_day,1,mpi_integer,0,mpi_comm_world,ierr)
258 call mpi_bcast(cycle_hour,1,mpi_integer,0,mpi_comm_world,ierr)
259 call mpi_bcast(convert_atm,1,mpi_logical,0,mpi_comm_world,ierr)
260 call mpi_bcast(convert_nst,1,mpi_logical,0,mpi_comm_world,ierr)
261 call mpi_bcast(convert_sfc,1,mpi_logical,0,mpi_comm_world,ierr)
262 call mpi_bcast(wam_cold_start,1,mpi_logical,0,mpi_comm_world,ierr)
263 call mpi_bcast(vgtyp_from_climo,1,mpi_logical,0,mpi_comm_world,ierr)
264 call mpi_bcast(sotyp_from_climo,1,mpi_logical,0,mpi_comm_world,ierr)
265 call mpi_bcast(vgfrc_from_climo,1,mpi_logical,0,mpi_comm_world,ierr)
266 call mpi_bcast(minmax_vgfrc_from_climo,1,mpi_logical,0,mpi_comm_world,ierr)
267 call mpi_bcast(lai_from_climo,1,mpi_logical,0,mpi_comm_world,ierr)
268 call mpi_bcast(tg3_from_soil,1,mpi_logical,0,mpi_comm_world,ierr)
269 call mpi_bcast(regional,1,mpi_integer,0,mpi_comm_world,ierr)
270 call mpi_bcast(input_type,len(input_type),mpi_character,0,mpi_comm_world,ierr)
271 call mpi_bcast(external_model,len(external_model),mpi_character,0,mpi_comm_world,ierr)
272 call mpi_bcast(wam_parm_file,len(wam_parm_file),mpi_character,0,mpi_comm_world,ierr)
273 call mpi_bcast(atm_weight_file,len(atm_weight_file),mpi_character,0,mpi_comm_world,ierr)
274 do i = 1, max_tracers
275 call mpi_bcast(tracers(i),len(tracers),mpi_character,0,mpi_comm_world,ierr)
276 call mpi_bcast(tracers_input(i),len(tracers_input),mpi_character,0,mpi_comm_world,ierr)
277 enddo
278 call mpi_bcast(halo_bndy,1,mpi_integer,0,mpi_comm_world,ierr)
279 call mpi_bcast(halo_blend,1,mpi_integer,0,mpi_comm_world,ierr)
280 call mpi_bcast(nsoill_out,1,mpi_integer,0,mpi_comm_world,ierr)
281 call mpi_bcast(thomp_mp_climo_file,len(thomp_mp_climo_file),mpi_character,0,mpi_comm_world,ierr)
282
283 call to_lower(input_type)
284
287
288!-------------------------------------------------------------------------
289! Determine CRES of target grid from the name of the orography file.
290!-------------------------------------------------------------------------
291
292 is = 1
293 ie = index(orog_files_target_grid(1), "_oro_") - 1
294
295 if (ie == 0) then
296 call error_handler("CANT DETERMINE CRES FROM OROG FILE.", 1)
297 endif
298
300
301 if (.not. convert_sfc .and. .not. convert_atm) then
302 call error_handler("MUST CONVERT EITHER AN ATM OR SFC FILE.", 1)
303 endif
304
305!-------------------------------------------------------------------------
306! Flag for processing stand-alone regional grid. When '1',
307! remove halo from atmospheric and surface data and output
308! atmospheric lateral boundary condition file. When '2',
309! create lateral boundary file only. When '0' (the default),
310! process normally as a global grid.
311!-------------------------------------------------------------------------
312
313 if (regional > 0) then
314 print*,"- PROCESSING A REGIONAL NEST WITH A BOUNDARY HALO OF ",halo_bndy
315 print*,"- PROCESSING A REGIONAL NEST WITH A BLENDING HALO OF ",halo_blend
316 else
317 halo_bndy = 0
318 halo_blend = 0
319 endif
320
321 num_tracers = 0
322 do is = 1, max_tracers
323 if (trim(tracers(is)) == "NULL") exit
325 print*,"- TRACER NAME IN OUTPUT FILE ", trim(tracers(is))
326 enddo
327
329 do is = 1, max_tracers
330 if (trim(tracers_input(is)) == "NULL") exit
332 print*,"- TRACER NAME IN INPUT FILE ", trim(tracers_input(is))
333 enddo
334
335!-------------------------------------------------------------------------
336! Ensure spo, spo2, and spo3 in tracers list if wam ic is on
337!-------------------------------------------------------------------------
338
339 if( wam_cold_start ) then
340 ierr=3
341 do is = 1, num_tracers
342 if(trim(tracers(is)) == "spo" ) ierr = ierr - 1
343 if(trim(tracers(is)) == "spo2" ) ierr = ierr - 1
344 if(trim(tracers(is)) == "spo3" ) ierr = ierr - 1
345 enddo
346 if (ierr /= 0) then
347 print*,"-ERROR: spo, spo2, and spo3 should be in tracers namelist"
348 call error_handler("WAM TRACER NAMELIST.", ierr)
349 endif
350 print*,"- WAM COLDSTART OPTION IS TURNED ON."
351 endif
352
353!-------------------------------------------------------------------------
354! Ensure program recognizes the input data type.
355!-------------------------------------------------------------------------
356
357 select case (trim(input_type))
358 case ("restart")
359 print*,'- INPUT DATA FROM FV3 TILED RESTART FILES.'
360 case ("history")
361 print*,'- INPUT DATA FROM FV3 TILED HISTORY FILES.'
362#ifdef CHGRES_ALL
363 case ("gaussian_nemsio")
364 print*,'- INPUT DATA FROM FV3 GAUSSIAN NEMSIO FILE.'
365 case ("gfs_gaussian_nemsio")
366 print*,'- INPUT DATA FROM SPECTRAL GFS GAUSSIAN NEMSIO FILE.'
367 case ("gfs_sigio")
368 print*,'- INPUT DATA FROM SPECTRAL GFS SIGIO/SFCIO FILE.'
369#endif
370 case ("gaussian_netcdf")
371 print*,'- INPUT DATA FROM FV3 GAUSSIAN NETCDF FILE.'
372 case ("grib2")
373 print*,'- INPUT DATA FROM A GRIB2 FILE'
374 case default
375 call error_handler("UNRECOGNIZED INPUT DATA TYPE.", 1)
376 end select
377
378!-------------------------------------------------------------------------
379! Ensure proper file variable provided for grib2 input
380!-------------------------------------------------------------------------
381
382 if (trim(input_type) == "grib2") then
383 if (trim(grib2_file_input_grid) == "NULL" .or. trim(grib2_file_input_grid) == "") then
384 call error_handler("FOR GRIB2 DATA, PLEASE PROVIDE GRIB2_FILE_INPUT_GRID", 1)
385 endif
386 endif
387
388 !-------------------------------------------------------------------------
389! For grib2 input, warn about possibly unsupported external model types
390!-------------------------------------------------------------------------
391
392 if (trim(input_type) == "grib2") then
393 if (.not. any((/character(4)::"GFS","NAM","RAP","HRRR","RRFS"/)==trim(external_model))) then
394 call error_handler( "KNOWN SUPPORTED external_model INPUTS ARE GFS, NAM, RAP, HRRR, AND RRFS. " // &
395 "IF YOU WISH TO PROCESS GRIB2 DATA FROM ANOTHER MODEL, YOU MAY ATTEMPT TO DO SO AT YOUR OWN RISK. " // &
396 "ONE WAY TO DO THIS IS PROVIDE NAM FOR external_model AS IT IS A RELATIVELY STRAIGHT-" // &
397 "FORWARD REGIONAL GRIB2 FILE. YOU MAY ALSO COMMENT OUT THIS ERROR MESSAGE IN " // &
398 "program_setup.f90 LINE 389. NO GUARANTEE IS PROVIDED THAT THE CODE WILL WORK OR "// &
399 "THAT THE RESULTING DATA WILL BE CORRECT OR WORK WITH THE ATMOSPHERIC MODEL.", 1)
400 endif
401 endif
402
403!-------------------------------------------------------------------------
404! For grib2 hrrr input without geogrid file input, warn that soil moisture interpolation
405! will be less accurate
406!-------------------------------------------------------------------------
407
408 if (trim(input_type) == "grib2" .and. trim(external_model)=="HRRR") then
409 if (trim(geogrid_file_input_grid) == "NULL" .or. trim(grib2_file_input_grid) == "") then
410 print*, "HRRR DATA DOES NOT CONTAIN SOIL TYPE INFORMATION. WITHOUT"
411 print*, "GEOGRID_FILE_INPUT_GRID SPECIFIED, SOIL MOISTURE INTERPOLATION MAY BE LESS ACCURATE."
412 endif
413 endif
414
415 if (trim(thomp_mp_climo_file) /= "NULL") then
416 use_thomp_mp_climo=.true.
417 print*,"- WILL PROCESS CLIMO THOMPSON MP TRACERS FROM FILE: ", trim(thomp_mp_climo_file)
418 endif
419
420 return
421
422 end subroutine read_setup_namelist
423
448subroutine read_varmap
449
450 implicit none
451
452 integer :: istat, k, nvars, rc, localpet
453 integer :: idum1(1), idum2(2)
454 character(len=500) :: line
455 character(len=20),allocatable :: var_type(:)
456
457 type(esmf_vm) :: vm
458
459 if (trim(input_type) == "grib2") then
460
461 call esmf_vmgetglobal(vm, rc=rc)
462 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
463 call error_handler("IN VMGetGlobal", rc)
464
465 call esmf_vmget(vm, localpet=localpet, rc=rc)
466 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
467 call error_handler("IN VMGet", rc)
468
469 if (localpet == 0) then
470
471 print*,"OPEN VARIABLE MAPPING FILE: ", trim(varmap_file)
472 open(14, file=trim(varmap_file), form='formatted', iostat=istat)
473 if (istat /= 0) then
474 call error_handler("OPENING VARIABLE MAPPING FILE", istat)
475 endif
476
477 nvars = 0
478
479! Loop over lines of file to count the number of variables
480 do
481 read(14, '(A)', iostat=istat) line
482 if (istat/=0) exit
483 if ( trim(line) .eq. '' ) cycle
484 nvars = nvars+1
485 enddo
486 if (nvars == 0) call error_handler("VARMAP FILE IS EMPTY.", -1)
487
488 idum1(1) = nvars
489
490 endif ! localpet == 0
491
492 call esmf_vmbroadcast(vm, idum1, 1, 0, rc=rc)
493 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
494 call error_handler("IN VMBroadcast", rc)
495
496 nvars = idum1(1)
497
498 allocate(chgres_var_names(nvars))
499 allocate(field_var_names(nvars))
500 allocate(missing_var_methods(nvars))
501 allocate(missing_var_values(nvars))
502 allocate(read_from_input(nvars))
503
504 read_from_input(:) = .true.
505
506 if (localpet == 0) then
507
509 allocate(var_type(nvars))
510 rewind(14)
511
512 do k = 1,nvars
513 read(14, *, iostat=istat) chgres_var_names(k), field_var_names(k) , &
514 missing_var_methods(k), missing_var_values(k), var_type(k)
515 if (istat /= 0) call error_handler("READING VARIABLE MAPPING FILE", istat)
516
517 if(trim(var_type(k))=='T') then
520 if ((trim(chgres_var_names(k)) == "ice_aero" .or. trim(chgres_var_names(k)) == "liq_aero") .and. &
521 trim(thomp_mp_climo_file) .ne. "NULL" .and. trim(input_type) == "grib2") then
522 call error_handler("VARMAP TABLE CONTAINS TRACER ENTRIES FOR THOMPSON AEROSOLS liq_aero or "// &
523 "ice_aero. REMOVE THESE ENTRIES OR REMOVE THE NAMELIST ENTRY FOR "// &
524 "thomp_mp_climo_file AND TRY AGAIN.",1)
525 endif
526 endif
527 enddo
528 close(14)
529
531 idum2(1) = num_tracers
532 idum2(2) = num_tracers_input
533
534 deallocate(var_type)
535
536 endif ! localpet = 0
537
538 call esmf_vmbroadcast(vm, idum2, 2, 0, rc=rc)
539 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
540 call error_handler("IN VMBroadcast", rc)
541
542 num_tracers = idum2(1)
543 num_tracers_input = idum2(2)
544
545 call esmf_vmbroadcast(vm, tracers_input, len(tracers_input)*max_tracers, 0, rc=rc)
546 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
547 call error_handler("IN VMBroadcast", rc)
548
549 call esmf_vmbroadcast(vm, chgres_var_names, len(chgres_var_names)*nvars, 0, rc=rc)
550 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
551 call error_handler("IN VMBroadcast", rc)
552
553 call esmf_vmbroadcast(vm, field_var_names, len(field_var_names)*nvars, 0, rc=rc)
554 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
555 call error_handler("IN VMBroadcast", rc)
556
557 call esmf_vmbroadcast(vm, missing_var_methods, len(missing_var_methods)*nvars, 0, rc=rc)
558 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
559 call error_handler("IN VMBroadcast", rc)
560
561 call esmf_vmbroadcast(vm, missing_var_values, nvars, 0, rc=rc)
562 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
563 call error_handler("IN VMBroadcast", rc)
564
565 endif
566end subroutine read_varmap
567
580subroutine get_var_cond(var_name,this_miss_var_method,this_miss_var_value, &
581 this_field_var_name, loc)
582
583 implicit none
584 character(len=20), intent(in) :: var_name
585
586 character(len=20), optional, intent(out) :: this_miss_var_method, &
587 this_field_var_name
588 real(esmf_kind_r4), optional, intent(out):: this_miss_var_value
589
590 integer, optional, intent(out) :: loc
591
592 integer :: i, tmp(size(missing_var_methods))
593
594 i=0
595
596 tmp(:)=0
597 where(chgres_var_names==var_name) tmp=1
598
599 i = maxloc(merge(1.,0.,chgres_var_names == var_name),dim=1) !findloc(chgres_var_names,var_name)
600 print*, i
601 if (maxval(tmp).eq.0) then
602 print*, "WARNING: NO ENTRY FOR ", trim(var_name), " IN VARMAP TABLE. WILL SKIP " // &
603 "VARIABLE IF NOT FOUND IN EXTERNAL MODEL FILE"
604
605 if(present(this_miss_var_method)) this_miss_var_method = "skip"
606 if(present(this_miss_var_value)) this_miss_var_value = -9999.9_esmf_kind_r4
607 if(present(this_field_var_name)) this_field_var_name = "NULL"
608 if(present(loc)) loc = 9999
609 else
610 if(present(this_miss_var_method)) this_miss_var_method = missing_var_methods(i)
611 if(present(this_miss_var_value)) this_miss_var_value = missing_var_values(i)
612 if(present(this_field_var_name)) this_field_var_name = field_var_names(i)
613 if(present(loc)) loc = i
614 endif
615
616end subroutine get_var_cond
617
651 subroutine calc_soil_params_driver(localpet)
652
653 implicit none
654
655 integer, intent(in) :: localpet
656
657 integer, parameter :: num_statsgo = 16
658 real, parameter :: smlow_statsgo = 0.5
659 real, parameter :: smhigh_statsgo = 6.0
660
661! zobler soil type used by spectral gfs prior to June 2017.
662 integer, parameter :: num_zobler = 9
663 real, parameter :: smlow_zobler = 0.5
664 real, parameter :: smhigh_zobler = 6.0
665
666 integer :: num_soil_cats
667
668 real :: bb_statsgo(num_statsgo)
669 real :: maxsmc_statsgo(num_statsgo)
670 real :: satdk_statsgo(num_statsgo)
671 real :: satpsi_statsgo(num_statsgo)
672
673 real :: bb_zobler(num_zobler)
674 real :: maxsmc_zobler(num_zobler)
675 real :: satdk_zobler(num_zobler)
676 real :: satpsi_zobler(num_zobler)
677
678 real, allocatable :: bb(:)
679 real :: smlow, smhigh
680 real, allocatable :: satdk(:)
681 real, allocatable :: satpsi(:)
682 real, allocatable :: satdw(:)
683
684! using stasgo table
685 data bb_statsgo /4.05, 4.26, 4.74, 5.33, 5.33, 5.25, &
686 6.77, 8.72, 8.17, 10.73, 10.39, 11.55, &
687 5.25, -9.99, 4.05, 4.26/
688
689 data maxsmc_statsgo /0.395, 0.421, 0.434, 0.476, 0.476, 0.439, &
690 0.404, 0.464, 0.465, 0.406, 0.468, 0.457, &
691 0.464, -9.99, 0.200, 0.421/
692
693 data satdk_statsgo /1.7600e-4, 1.4078e-5, 5.2304e-6, 2.8089e-6, 2.8089e-6, &
694 3.3770e-6, 4.4518e-6, 2.0348e-6, 2.4464e-6, 7.2199e-6, &
695 1.3444e-6, 9.7384e-7, 3.3770e-6, -9.99, 1.4078e-5, &
696 1.4078e-5/
697
698 data satpsi_statsgo /0.0350, 0.0363, 0.1413, 0.7586, 0.7586, 0.3548, &
699 0.1349, 0.6166, 0.2630, 0.0977, 0.3236, 0.4677, &
700 0.3548, -9.99, 0.0350, 0.0363/
701
702 data bb_zobler /4.26, 8.72, 11.55, 4.74, 10.73, 8.17, &
703 6.77, 5.25, 4.26/
704
705 data maxsmc_zobler /0.421, 0.464, 0.468, 0.434, 0.406, 0.465, &
706 0.404, 0.439, 0.421/
707
708 data satdk_zobler /1.41e-5, 0.20e-5, 0.10e-5, 0.52e-5, 0.72e-5, &
709 0.25e-5, 0.45e-5, 0.34e-5, 1.41e-5/
710
711 data satpsi_zobler /0.040, 0.620, 0.470, 0.140, 0.100, 0.260, &
712 0.140, 0.360, 0.040/
713
714!-------------------------------------------------------------------------
715! Compute soil parameters for the input grid.
716!-------------------------------------------------------------------------
717
718 select case (trim(input_type))
719 case ("gfs_sigio")
720 print*,'- INPUT GRID USED ZOBLER SOIL TYPES.'
721 num_soil_cats = num_zobler
722 case default
723 print*,'- INPUT GRID USED STATSGO SOIL TYPES.'
724 num_soil_cats = num_statsgo
725 end select
726
727 allocate(maxsmc_input(num_soil_cats))
728 allocate(wltsmc_input(num_soil_cats))
729 allocate(drysmc_input(num_soil_cats))
730 allocate(refsmc_input(num_soil_cats))
731 allocate(bb(num_soil_cats))
732 allocate(satdk(num_soil_cats))
733 allocate(satpsi(num_soil_cats))
734 allocate(satdw(num_soil_cats))
735
736 select case (trim(input_type))
737 case ("gfs_sigio")
738 smlow = smlow_zobler
739 smhigh = smhigh_zobler
740 maxsmc_input = maxsmc_zobler
741 bb = bb_zobler
742 satdk = satdk_zobler
743 satpsi = satpsi_zobler
744 case default
745 smlow = smlow_statsgo
746 smhigh = smhigh_statsgo
747 maxsmc_input = maxsmc_statsgo
748 bb = bb_statsgo
749 satdk = satdk_statsgo
750 satpsi = satpsi_statsgo
751 end select
752
753 call calc_soil_params(num_soil_cats, smlow, smhigh, satdk, maxsmc_input, &
754 bb, satpsi, satdw, refsmc_input, drysmc_input, wltsmc_input)
755
756 deallocate(bb, satdk, satpsi, satdw)
757
758 if (localpet == 0) print*,'maxsmc input grid ',maxsmc_input
759 if (localpet == 0) print*,'wltsmc input grid ',wltsmc_input
760
761!-------------------------------------------------------------------------
762! Compute soil parameters for the target grid.
763!-------------------------------------------------------------------------
764
765 print*,'- TARGET GRID USEING STATSGO SOIL TYPES.'
766
767 num_soil_cats = num_statsgo
768
769 allocate(maxsmc_target(num_soil_cats))
770 allocate(wltsmc_target(num_soil_cats))
771 allocate(drysmc_target(num_soil_cats))
772 allocate(refsmc_target(num_soil_cats))
773 allocate(bb_target(num_soil_cats))
774 allocate(satpsi_target(num_soil_cats))
775 allocate(satdk(num_soil_cats))
776 allocate(satdw(num_soil_cats))
777
778 smlow = smlow_statsgo
779 smhigh = smhigh_statsgo
780 maxsmc_target = maxsmc_statsgo
781 bb_target = bb_statsgo
782 satdk = satdk_statsgo
783 satpsi_target = satpsi_statsgo
784
785 call calc_soil_params(num_soil_cats, smlow, smhigh, satdk, maxsmc_target, &
787
788 deallocate(satdk, satdw)
789
790 if (localpet == 0) print*,'maxsmc target grid ',maxsmc_target
791 if (localpet == 0) print*,'wltsmc input grid ',wltsmc_target
792
793 end subroutine calc_soil_params_driver
794
811 subroutine calc_soil_params(num_soil_cats, smlow, smhigh, satdk, &
812 maxsmc, bb, satpsi, satdw, refsmc, drysmc, wltsmc)
813
814 implicit none
815
816 integer, intent(in) :: num_soil_cats
817
818 real, intent(in) :: smlow, smhigh
819 real, intent(in) :: bb(num_soil_cats)
820 real, intent(in) :: maxsmc(num_soil_cats)
821 real, intent(in) :: satdk(num_soil_cats)
822 real, intent(in) :: satpsi(num_soil_cats)
823
824 real, intent(out) :: satdw(num_soil_cats)
825 real, intent(out) :: refsmc(num_soil_cats)
826 real, intent(out) :: drysmc(num_soil_cats)
827 real, intent(out) :: wltsmc(num_soil_cats)
828
829 integer :: i
830
831 real :: refsmc1
832 real :: wltsmc1
833
834 satdw = 0.0
835 refsmc = 0.0
836 wltsmc = 0.0
837 drysmc = 0.0
838
839 do i = 1, num_soil_cats
840
841 if (maxsmc(i) > 0.0) then
842
843 satdw(i) = bb(i)*satdk(i)*(satpsi(i)/maxsmc(i))
844 refsmc1 = maxsmc(i)*(5.79e-9/satdk(i)) **(1.0/(2.0*bb(i)+3.0))
845 refsmc(i) = refsmc1 + (maxsmc(i)-refsmc1) / smhigh
846 wltsmc1 = maxsmc(i) * (200.0/satpsi(i))**(-1.0/bb(i))
847 wltsmc(i) = wltsmc1 - smlow * wltsmc1
848
849!----------------------------------------------------------------------
850! CURRENT VERSION DRYSMC VALUES THAT EQUATE TO WLTSMC.
851! FUTURE VERSION COULD LET DRYSMC BE INDEPENDENTLY SET VIA NAMELIST.
852!----------------------------------------------------------------------
853
854 drysmc(i) = wltsmc(i)
855
856 end if
857
858 END DO
859
860 end subroutine calc_soil_params
861
862 end module program_setup
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data,...
character(len=500), public geogrid_file_input_grid
Name of "geogrid" file, which contains static surface fields on the input grid.
real(kind=esmf_kind_r4), dimension(:), allocatable, public missing_var_values
If input GRIB2 record is missing, the variable is set to this value.
real, dimension(:), allocatable, public drysmc_input
Air dry soil moisture content input grid.
character(len=500), dimension(6), public sfc_files_input_grid
File names containing input surface data.
integer, public num_tracers_input
Number of atmospheric tracers in input file.
character(len=500), public orog_dir_input_grid
Directory containing the input grid orography files.
integer, parameter, public max_tracers
Maximum number of atmospheric tracers processed.
logical, dimension(:), allocatable, public read_from_input
When false, variable was not read from GRIB2 input file.
character(len=500), dimension(6), public atm_tracer_files_input_grid
File names of input atmospheric restart tracer files.
real, dimension(:), allocatable, public refsmc_input
Reference soil moisture content input grid (onset of soil moisture stress).
character(len=500), public grib2_file_input_grid
REQUIRED.
character(len=500), dimension(6), public orog_files_target_grid
Target grid orography files.
subroutine, public read_setup_namelist(filename)
Reads program configuration namelist.
character(len=500), dimension(6), public orog_files_input_grid
Input grid orography files.
subroutine calc_soil_params(num_soil_cats, smlow, smhigh, satdk, maxsmc, bb, satpsi, satdw, refsmc, drysmc, wltsmc)
Compute soil parameters.
real, dimension(:), allocatable, public wltsmc_target
Plant wilting point soil moisture content target grid.
integer, public regional
For regional target grids.
real, dimension(:), allocatable, public refsmc_target
Reference soil moisture content target grid (onset of soil moisture stress).
character(len=500), public wam_parm_file
Full path to msis21.parm for WAM initialization.
logical, public tg3_from_soil
If false, use lowest level soil temperature for the base soil temperature instead of using data from ...
real, dimension(:), allocatable, public wltsmc_input
Plant wilting point soil moisture content input grid.
character(len=500), dimension(7), public atm_core_files_input_grid
File names of input atmospheric restart core files.
character(len=20), dimension(max_tracers), public tracers
Name of each atmos tracer to be processed.
integer, public num_tracers
Number of atmospheric tracers to be processed.
character(len=500), public nst_files_input_grid
File name of input nst data.
character(len=20), dimension(:), allocatable, public field_var_names
The GRIB2 variable name in the varmap table.
logical, public use_thomp_mp_climo
When true, read and process Thompson MP climatological tracers.
character(len=500), public orog_dir_target_grid
Directory containing the target grid orography files.
character(len=20), dimension(:), allocatable, public chgres_var_names
Varmap table variable name as recognized by this program.
integer, public halo_blend
Number of row/cols of blending halo, where model tendencies and lateral boundary tendencies are appli...
logical, public lai_from_climo
If false, interpolate leaf area index from the input data to the target grid instead of using data fr...
character(len=500), public thomp_mp_climo_file
Path/name to the Thompson MP climatology file.
character(len=500), public mosaic_file_target_grid
Target grid mosaic file.
logical, public vgfrc_from_climo
If false, interpolate vegetation fraction from the input data to the target grid instead of using dat...
subroutine, public read_varmap
Reads the variable mapping table, which is required for initializing with GRIB2 data.
character(len=500), public mosaic_file_input_grid
Input grid mosaic file.
real, dimension(:), allocatable, public maxsmc_target
Maximum soil moisture content target grid.
logical, public wam_cold_start
When true, cold start for whole atmosphere model.
integer, public cycle_mon
Cycle month.
logical, public convert_sfc
Convert sfc data when true.
subroutine, public get_var_cond(var_name, this_miss_var_method, this_miss_var_value, this_field_var_name, loc)
Search the variable mapping table to find conditions for handling missing variables.
integer, public halo_bndy
Number of row/cols of lateral halo, where pure lateral bndy conditions are applied (regional target g...
real, dimension(:), allocatable, public maxsmc_input
Maximum soil moisture content input grid.
character(len=20), dimension(:), allocatable, public missing_var_methods
Method to replace missing GRIB2 input records.
integer, public cycle_day
Cycle day.
integer, public nsoill_out
Number of soil levels desired in the output data.
real, dimension(:), allocatable, public bb_target
Soil 'b' parameter, target grid.
character(len=15), public cres_target_grid
Target grid resolution, i.e., C768.
real, dimension(:), allocatable, public drysmc_target
Air dry soil moisture content target grid.
subroutine, public calc_soil_params_driver(localpet)
Driver routine to compute soil parameters for each soil type.
character(len=500), public varmap_file
REQUIRED.
character(len=500), dimension(6), public atm_files_input_grid
File names of input atmospheric data.
character(len=20), dimension(max_tracers), public tracers_input
Name of each atmos tracer record in the input file.
integer, public cycle_hour
Cycle hour.
logical, public convert_atm
Convert atmospheric data when true.
real, dimension(:), allocatable, public satpsi_target
Saturated soil potential, target grid.
character(len=500), public atm_weight_file
File containing pre-computed weights to horizontally interpolate atmospheric fields.
character(len=500), public data_dir_input_grid
Directory containing input atm or sfc files.
character(len=500), public fix_dir_target_grid
Directory containing target grid pre-computed fixed data (ex: soil type).
logical, public sotyp_from_climo
If false, interpolate soil type from the input data to the target grid instead of using data from sta...
logical, public vgtyp_from_climo
If false, interpolate vegetation type from the input data to the target grid instead of using data fr...
character(len=25), public input_type
Input data type:
character(len=20), public external_model
The model that the input data is derived from.
logical, public convert_nst
Convert nst data when true.
character(len=500), public vcoord_file_target_grid
Vertical coordinate definition file.
logical, public minmax_vgfrc_from_climo
If false, interpolate min/max vegetation fraction from the input data to the target grid instead of u...
integer, public cycle_year
Cycle year.