Skip to content

Commit

Permalink
Support for forcing field scaling. See COSIMA/access-om2#133
Browse files Browse the repository at this point in the history
  • Loading branch information
nichannah committed Feb 5, 2019
1 parent 1d2133d commit 36ebce2
Show file tree
Hide file tree
Showing 11 changed files with 1,699 additions and 8 deletions.
14 changes: 11 additions & 3 deletions atm/src/forcing.F90
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ subroutine forcing_init_fields(self, fields, forcing_date, min_dt, calendar)
integer :: i
character(kind=CK, len=:), allocatable :: cname, fieldname
character(kind=CK, len=:), allocatable :: filename_template
character(kind=CK, len=:), allocatable :: scaling_filename
character(len=1024) :: filename
character(len=9) :: calendar_str
logical :: found
logical :: found, scaling_found

min_dt = huge(min_dt)
calendar_str = ''
Expand All @@ -83,6 +84,8 @@ subroutine forcing_init_fields(self, fields, forcing_date, min_dt, calendar)
call self%core%get(fp, "filename", filename_template, found)
call assert(found, "Entry 'filename' not found in forcing config.")

call self%core%get(fp, "scaling_filename", scaling_filename, scaling_found)

call self%core%get(fp, "fieldname", fieldname, found)
call assert(found, "Entry 'fieldname' not found in forcing config.")

Expand All @@ -92,8 +95,13 @@ subroutine forcing_init_fields(self, fields, forcing_date, min_dt, calendar)
! Get the shape of forcing fields
filename = filename_for_year(filename_template, forcing_date%getYear())
! Initialise a new field object.
call fields(i)%init(cname, fieldname, filename_template, filename, &
self%logger)
if (scaling_found) then
call fields(i)%init(cname, fieldname, filename_template, &
filename, self%logger, scaling_filename)
else
call fields(i)%init(cname, fieldname, filename_template, &
filename, self%logger)
endif

if (fields(i)%dt < min_dt) then
min_dt = fields(i)%dt
Expand Down
31 changes: 29 additions & 2 deletions libcouple/src/field.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ module field_mod
type, public :: field
character(len=64) :: name
character(len=1024) :: filename_template
character(len=1024) :: scaling_filename
type(datetime) :: timestamp
integer :: oasis_varid
integer :: oasis_partid

integer :: dt
character(len=9) :: calendar
type(ncvar_type) :: ncvar
type(ncvar_type) :: ncvar, scaling_ncvar
real, dimension(:, :), allocatable :: data_array
real, dimension(:, :), allocatable :: scaling_data_array

type(logger_type) :: logger
contains
Expand All @@ -31,11 +33,13 @@ module field_mod

contains

subroutine field_init(self, name, ncname, filename_template, filename, logger)
subroutine field_init(self, name, ncname, filename_template, &
filename, logger, scaling_filename)
class(field), intent(inout) :: self
character(len=*), intent(in) :: name, ncname
character(len=*), intent(in) :: filename_template, filename
type(logger_type), intent(in) :: logger
character(len=*), intent(in), optional :: scaling_filename

self%name = name
self%filename_template = filename_template
Expand All @@ -48,6 +52,13 @@ subroutine field_init(self, name, ncname, filename_template, filename, logger)
self%dt = self%ncvar%dt
self%calendar = self%ncvar%calendar

if (present(scaling_filename)) then
self%scaling_filename = scaling_filename
call self%scaling_ncvar%init(ncname, scaling_filename)
allocate(self%scaling_data_array(self%ncvar%nx, self%ncvar%ny))
self%scaling_data_array(:, :) = HUGE(1.0)
endif

end subroutine

subroutine field_update_data(self, filename, forcing_date)
Expand Down Expand Up @@ -81,6 +92,22 @@ subroutine field_update_data(self, filename, forcing_date)
call self%ncvar%read_data(indx, self%data_array)
self%timestamp = forcing_date

! Read the scaling data for this date and apply it (if there is any)
if (allocated(self%scaling_data_array)) then
indx = self%scaling_ncvar%get_index_for_datetime(forcing_date, .true.)
if (indx /= -1) then
call self%scaling_ncvar%read_data(indx, self%scaling_data_array)
call self%logger%write(LOG_DEBUG, &
'{ "field_update_data-scaling_file" : "'// &
trim(self%scaling_filename)//'" }')
call self%logger%write(LOG_DEBUG, &
'{ "field_update_data-scaling_date" : "'// &
forcing_date%isoformat()//'" }')
self%data_array(:, :) = self%data_array(:, :) * &
self%scaling_data_array(:, :)
endif
endif

end subroutine field_update_data

function get_shape(self)
Expand Down
13 changes: 13 additions & 0 deletions tests/FORCING_SCALING/accessom2.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
&accessom2_nml
log_level = 'DEBUG'
ice_ocean_timestep = 5400
enable_simple_timers = .true.
&end

&date_manager_nml
forcing_start_date = '1900-01-01T00:00:00'
forcing_end_date = '1901-01-01T00:00:00'
! Runtime for a single job/submit, format is years, months, seconds,
! two of which must be zero.
restart_period = 0, 0, 86400
&end
7 changes: 7 additions & 0 deletions tests/FORCING_SCALING/atm.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
&atm_nml
accessom2_config_dir = './'
&end

&runoff_nml
remap_weights_file = '../test_data/rmp_jrar_to_cict_CONSERV.nc'
&end
Loading

0 comments on commit 36ebce2

Please sign in to comment.