ICON Community Interface 0.4.0
Loading...
Searching...
No Matches
test_datatypes.py
Go to the documentation of this file.
1"""
2Test plugin for the ICON Community Interface (ComIn)
3
4Creates variables with different datatypes and checks the corresponding buffer
5
6@authors 12/2024 :: ICON Community Interface <comin@icon-model.org>
7
8SPDX-License-Identifier: BSD-3-Clause
9
10Please see the file LICENSE in the root of the source tree for this code.
11Where software is supplied by third parties, it is indicated in the
12headers of the routines.
13"""
14
15import comin
16import numpy as np
17
18# types to test
19comin_datatypes = {
20 "dp": comin.COMIN_VAR_DATATYPE_DOUBLE,
21 "sp": comin.COMIN_VAR_DATATYPE_FLOAT,
22 "i": comin.COMIN_VAR_DATATYPE_INT,
23}
24numpy_datatypes = {
25 "dp": np.double,
26 "sp": np.single,
27 "i": np.intc,
28}
29
30for name, comin_dt in comin_datatypes.items():
31 descr = ("test_var_" + name, 1)
32 comin.var_request_add(descr, False)
33 comin.metadata_set(descr, datatype=comin_dt)
34
35
36var_handles = {}
37
38
39@comin.EP_SECONDARY_CONSTRUCTOR
41 global var_handles
42 flag = comin.COMIN_FLAG_READ | comin.COMIN_FLAG_WRITE
43 var_handles = {
44 name: comin.var_get(
45 [comin.EP_ATM_TIMELOOP_START], ("test_var_" + name, 1), flag
46 )
47 for name, comin_dt in comin_datatypes.items()
48 }
49
50
51@comin.EP_ATM_TIMELOOP_START
52def check():
53 for name, var_handle in var_handles.items():
54 assert (
55 np.asarray(var_handle).dtype == numpy_datatypes[name]
56 ), f"Check for {name} unsuccessful ({np.asarray(var_handle).dtype} != {numpy_datatypes[name]})"
57 comin.print_info(f"Check for {name} successful ({numpy_datatypes[name]})")
var_get(context, var_descriptor, flag)
get variable object, arguments: [entry point], (name string, domain id), access flag)
Definition comin.py:107
metadata_set(var_descriptor, **kwargs)
sets metadata for a requested field, arguments: name string, domain id, metadata key,...
Definition comin.py:189