diff --git a/src/soca/Fields/soca_fields_metadata_mod.F90 b/src/soca/Fields/soca_fields_metadata_mod.F90 index c6dc793e9..eb67f3347 100644 --- a/src/soca/Fields/soca_fields_metadata_mod.F90 +++ b/src/soca/Fields/soca_fields_metadata_mod.F90 @@ -8,6 +8,7 @@ module soca_fields_metadata_mod use fckit_configuration_module, only: fckit_configuration, fckit_yamlconfiguration use fckit_pathname_module, only : fckit_pathname +use kinds, only: kind_real implicit none private @@ -24,10 +25,11 @@ module soca_fields_metadata_mod character(len=:), allocatable :: levels !< "1", or "full_ocn" character(len=:), allocatable :: getval_name !< variable name used by UFO character(len=:), allocatable :: getval_name_surface ! name used by UFO for the surface (if this is a 3D field) - character(len=:), allocatable :: io_file !< the restart file domain (ocn, sfc, ice) + character(len=:), allocatable :: io_file !< the restart file domain (ocn, sfc, ice). Or if "CONSTANT" use the value in "constant_value" character(len=:), allocatable :: io_name !< the name use in the restart IO character(len=:), allocatable :: property !< physical property of the field, "none" or "positive_definite" logical :: vert_interp !< true if the field can be vertically interpolated + real(kind=kind_real) :: constant_value !< An optional value to use globally for the field end type @@ -73,6 +75,7 @@ subroutine soca_fields_metadata_create(self, filename) integer :: i, j logical :: bool + real(kind=kind_real) :: r character(len=:), allocatable :: str ! parse all the metadata from a yaml configuration file @@ -116,6 +119,16 @@ subroutine soca_fields_metadata_create(self, filename) end if self%metadata(i)%vert_interp = bool + if(conf_list(i)%get("constant value", r)) then + if (.not. self%metadata(i)%io_file == "") then + str=repeat(" ", 1024) + write(str, *) "error in field metadata file for '", self%metadata(i)%name, & + "' : 'io file' cannot be set if 'constant value' is given" + call abor1_ftn(str) + end if + self%metadata(i)%constant_value = r + self%metadata(i)%io_file = "CONSTANT" + end if end do ! check for duplicates diff --git a/src/soca/Fields/soca_fields_mod.F90 b/src/soca/Fields/soca_fields_mod.F90 index 49218cbbf..56eb72a58 100644 --- a/src/soca/Fields/soca_fields_mod.F90 +++ b/src/soca/Fields/soca_fields_mod.F90 @@ -906,7 +906,11 @@ subroutine soca_fields_read(self, f_conf, vdate) ! built-in variables do i=1,size(self%fields) - if(self%fields(i)%metadata%io_name /= "") then + + if(self%fields(i)%metadata%io_file == "CONSTANT") then + self%fields(i)%val(:,:,:) = self%fields(i)%metadata%constant_value + + else if(self%fields(i)%metadata%io_file /= "") then ! which file are we reading from? select case(self%fields(i)%metadata%io_file) case ('ocn') diff --git a/test/Data/fields_metadata.yml b/test/Data/fields_metadata.yml index e2807aeab..0d3e2f593 100644 --- a/test/Data/fields_metadata.yml +++ b/test/Data/fields_metadata.yml @@ -9,6 +9,8 @@ # getval_name_surface: GetValues variable name for 2D surface of a 3D field (Default: ) # io_file: The restart file domain "ocn", "sfc", or "ice" (Default: ) # io_name: The variable name used in the restart IO (Default: ) +# constant value: Used for "dummy" fields. Sets the entire field to the given constant globally +# This parameter cannot be used with io_file/io_name # -------------------------------------------------------------------------------------------------- @@ -165,3 +167,7 @@ - name: sea_water_depth levels: full_ocn + +# -------------------------------------------------------------------------------------------------- +- name: dummy_atm1 + constant value: 5.0 \ No newline at end of file diff --git a/test/testinput/hofx_3d.yml b/test/testinput/hofx_3d.yml index 03b8690c0..c6e38edd5 100644 --- a/test/testinput/hofx_3d.yml +++ b/test/testinput/hofx_3d.yml @@ -10,7 +10,7 @@ state: ocn_filename: MOM.res.nc ice_filename: cice.res.nc sfc_filename: sfc.res.nc - state variables: [cicen, hicen, hsnon, socn, tocn, ssh, hocn, uocn, vocn, sw, lhf, shf, lw, us, chl] + state variables: [cicen, hicen, hsnon, socn, tocn, ssh, hocn, uocn, vocn, sw, lhf, shf, lw, us, chl, dummy_atm1] window begin: 2018-04-14T00:00:00Z window length: P2D diff --git a/test/testref/hofx_3d.test b/test/testref/hofx_3d.test index 46f405069..e5e27a561 100644 --- a/test/testref/hofx_3d.test +++ b/test/testref/hofx_3d.test @@ -15,6 +15,7 @@ State: lw min=0.0000000000000000 max=88.0360870361328125 mean=31.3955290035652546 us min=0.0043958698226386 max=0.0196578730801191 mean=0.0086443089692577 chl min=0.0000100000000000 max=4.6719899196170607 mean=0.1184829680403295 +dummy_atm1 min=5.0000000000000000 max=5.0000000000000000 mean=5.0000000000000000 H(x): CoolSkin nobs= 200 Min=-4.1785594844341176, Max=25.2197343303870412, RMS=20.1355481819576383