MONC
fieldslicer-operator.F90
Go to the documentation of this file.
1 
7  use grids_mod, only : z_index, y_index, x_index
9  use logging_mod, only : log_error, log_log
10  implicit none
11 
12 #ifndef TEST_MODE
13  private
14 #endif
15 
17 contains
25  subroutine perform_fieldslicer_operator(io_configuration, field_values, action_attributes, source_monc_location, &
26  source_monc, operator_result_values)
27  type(io_configuration_type), intent(inout) :: io_configuration
28  type(hashmap_type), intent(inout) :: field_values
29  type(map_type), intent(inout) :: action_attributes
30  integer, intent(in) :: source_monc_location, source_monc
31  real(kind=DEFAULT_PRECISION), dimension(:), allocatable, intent(inout) :: operator_result_values
32 
33  character(len=STRING_LENGTH) :: field_to_slice
34  integer :: i, j, dimension_to_slice, index_to_slice, number_dims, sliced_size, source_dim
35  integer, dimension(:), allocatable :: dim_starts, dim_ends, dim_weights, indexes
36  type(data_values_type), pointer :: field_local_values
37  type(io_configuration_field_type) :: corresponding_field_definition
38 
39  field_to_slice=get_action_attribute_string(action_attributes, "field")
40  ! NSE
41  if (get_prognostic_field_configuration(io_configuration, field_to_slice, "", corresponding_field_definition)) then
42  dimension_to_slice=get_dimension_to_slice(action_attributes)
43  index_to_slice=get_action_attribute_integer(action_attributes, "index")
44 
45  if (io_configuration%registered_moncs(source_monc_location)%local_dim_starts(dimension_to_slice) .le. index_to_slice .and.&
46  io_configuration%registered_moncs(source_monc_location)%local_dim_ends(dimension_to_slice) .ge. index_to_slice) then
47  field_local_values=>get_data_value_by_field_name(field_values, field_to_slice)
48 
49  call determine_dimension_bounds(corresponding_field_definition, io_configuration%registered_moncs(source_monc_location), &
50  dimension_to_slice, index_to_slice, dim_starts, dim_ends, dim_weights, number_dims, sliced_size)
51 
52  allocate(operator_result_values(sliced_size), indexes(number_dims))
53  indexes=dim_starts
54  do i=1, sliced_size
55  source_dim=1
56  do j=1, number_dims
57  source_dim=source_dim+(indexes(j)-1)*dim_weights(j)
58  end do
59  operator_result_values(i)=field_local_values%values(source_dim)
60  indexes(1)=indexes(1)+1
61  do j=1, number_dims
62  if (indexes(j) .gt. dim_ends(j)) then
63  indexes(j)=dim_starts(j)
64  if (j .lt. number_dims) indexes(j+1)=indexes(j+1)+1
65  end if
66  end do
67  end do
68  deallocate(dim_starts, dim_ends, dim_weights, indexes)
69  end if
70  end if
71  end subroutine perform_fieldslicer_operator
72 
83  subroutine determine_dimension_bounds(corresponding_field_definition, registered_monc_info, dimension_to_slice, &
84  index_to_slice, dim_starts, dim_ends, dim_weights, number_dims, sliced_size)
85  type(io_configuration_field_type), intent(in) :: corresponding_field_definition
86  type(io_configuration_registered_monc_type), intent(in) :: registered_monc_info
87  integer, intent(in) :: dimension_to_slice, index_to_slice
88  integer, dimension(:), allocatable, intent(out) :: dim_starts, dim_ends, dim_weights
89  integer, intent(out) :: number_dims, sliced_size
90 
91  integer :: i, j, dimension_id, amount_to_add
92  integer, dimension(:), allocatable :: dim_sizes
93  logical :: found_slice_field
94 
95  number_dims=corresponding_field_definition%dimensions
96  allocate(dim_sizes(number_dims), dim_starts(number_dims), dim_ends(number_dims), dim_weights(number_dims))
97  found_slice_field=.false.
98 
99  do i=1, number_dims
100  dimension_id=convert_dimension_str_to_id(corresponding_field_definition%dim_size_defns(i))
101  if (dimension_id==dimension_to_slice) then
102  dim_sizes(i)=1
103  dim_starts(i)=index_to_slice
104  dim_ends(i)=index_to_slice
105  found_slice_field=.true.
106  else
107  dim_sizes(i)=registered_monc_info%local_dim_sizes(dimension_id)
108  dim_starts(i)=1
109  dim_ends(i)=registered_monc_info%local_dim_sizes(dimension_id)
110  end if
111  end do
112  if (.not. found_slice_field) call log_log(log_error, "Can not find dimension to slice in provided field")
113  sliced_size=0
114  do i=1, number_dims
115  amount_to_add=1
116  dim_weights(i)=1
117  do j=1, i
118  if (j .lt. i) dim_weights(i)=dim_weights(i)*registered_monc_info%local_dim_sizes(j)
119  amount_to_add=amount_to_add*dim_sizes(j)
120  end do
121  sliced_size=sliced_size+amount_to_add
122  end do
123  deallocate(dim_sizes)
124  end subroutine determine_dimension_bounds
125 
129  type(list_type) function fieldslicer_operator_get_required_fields(action_attributes)
130  type(map_type), intent(inout) :: action_attributes
131 
132  character(len=STRING_LENGTH) :: field_to_slice
133 
134  field_to_slice=get_action_attribute_string(action_attributes, "field")
135  call c_add_string(fieldslicer_operator_get_required_fields, field_to_slice)
137 
140  integer function get_dimension_to_slice(action_attributes)
141  type(map_type), intent(inout) :: action_attributes
142 
143  get_dimension_to_slice=convert_dimension_str_to_id(get_action_attribute_string(action_attributes, "dimension"))
144  end function get_dimension_to_slice
145 
149  integer function convert_dimension_str_to_id(dim_str)
150  character(len=STRING_LENGTH), intent(in) :: dim_str
151 
152  if (dim_str .eq. "x") then
154  else if (dim_str .eq. "y") then
156  else if (dim_str .eq. "z") then
158  end if
159  end function convert_dimension_str_to_id
160 end module fieldslicer_operator_mod
Slices a field based upon the selected dimension and index.
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
subroutine, public perform_fieldslicer_operator(io_configuration, field_values, action_attributes, source_monc_location, source_monc, operator_result_values)
Performs the actual field slicing.
integer function get_dimension_to_slice(action_attributes)
Retrieves the integer index of the dimension to slice.
integer function convert_dimension_str_to_id(dim_str)
Converts a dimension string to the corresponding numeric ID.
Contains functionality for managing and extracting data from the raw data dumps that the IO server re...
Definition: datautils.F90:3
Logging utility.
Definition: logging.F90:2
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
integer, parameter, public z_index
Grid index parameters.
Definition: grids.F90:14
integer function, public get_action_attribute_integer(action_attributes, field_name)
Retrieves the name of a field from the attributes specified in the configuration. ...
Definition: datautils.F90:114
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
A hashmap structure, the same as a map but uses hashing for greatly improved performance when storing...
Definition: collections.F90:94
subroutine, public log_log(level, message, str)
Logs a message at the specified level. If the level is above the current level then the message is ig...
Definition: logging.F90:75
logical function, public get_prognostic_field_configuration(io_configuration, field_name, field_namespace, prognostic_config, prognostic_containing_data_defn)
Retrieves the prognostic field configuration corresponding to a specific field name and returns wheth...
Map data structure that holds string (length 20 maximum) key value pairs.
Definition: collections.F90:86
subroutine determine_dimension_bounds(corresponding_field_definition, registered_monc_info, dimension_to_slice, index_to_slice, dim_starts, dim_ends, dim_weights, number_dims, sliced_size)
Determines the bounds for each dimension which is specified via the configuration file...
Collection data structures.
Definition: collections.F90:7
Configuration that representes the state of a registered MONC process.
integer, parameter, public string_length
Default length of strings.
Definition: datadefn.F90:10
type(list_type) function, public fieldslicer_operator_get_required_fields(action_attributes)
Retrieves a list of the required fields for running this operator.
character(len=string_length) function, public get_action_attribute_string(action_attributes, field_name)
Retrieves the name of a field from the attributes specified in the configuration. ...
Definition: datautils.F90:101
List data structure which implements a doubly linked list. This list will preserve its order...
Definition: collections.F90:60
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
Configuration associated with the representation of a specific data field.
Adds a string to the end of the list.
integer, parameter, public y_index
Definition: grids.F90:14
Parses the XML configuration file to produce the io configuration description which contains the data...
integer, parameter, public x_index
Definition: grids.F90:14