ICON Community Interface 0.4.0
Loading...
Searching...
No Matches
simple_python_plugin.py
Go to the documentation of this file.
1"""
2Test plugin for the ICON Community Interface (ComIn)
3
4This simple test plugin shows how to use the basic features of
5ComIn analogous to simple_c_plugin and simple_fortran_plugin.
6
7@authors 11/2023 :: ICON Community Interface <comin@icon-model.org>
8
9SPDX-License-Identifier: BSD-3-Clause
10
11Please see the file LICENSE in the root of the source tree for this code.
12Where software is supplied by third parties, it is indicated in the
13headers of the routines.
14"""
15
16import numpy as np
17import sys
18import argparse
19
20parser = argparse.ArgumentParser()
21parser.add_argument("--hello", help="just a dummy argument")
22parser.add_argument("arg", help="just a dummy argument")
23
24# allows the script to be called from the command line e.g. with "--help"
25try:
26 import comin
27
28 args = parser.parse_args(comin.current_get_plugin_info().args)
29except ImportError:
30 parser.parse_args()
31
32print(args)
34
35# request to add a variable
36comin.var_request_add(("simple_python_var", 1), False)
37
38# request to add a tracer
39comin.var_request_add(("simple_python_tracer", -1), False)
40comin.metadata_set(("simple_python_tracer", -1), tracer=True)
41
42
43@comin.EP_SECONDARY_CONSTRUCTOR
45 global pres, simple_python_var, simple_python_tracer
46 print("simple_python_constructor called!", file=sys.stderr)
47 pres = comin.var_get(
48 [comin.EP_ATM_WRITE_OUTPUT_BEFORE], ("pres", 1), comin.COMIN_FLAG_READ
49 )
50 simple_python_var = comin.var_get(
51 [comin.EP_ATM_WRITE_OUTPUT_BEFORE],
52 ("simple_python_var", 1),
53 comin.COMIN_FLAG_READ | comin.COMIN_FLAG_WRITE,
54 )
55 simple_python_tracer = comin.var_get(
56 [comin.EP_ATM_WRITE_OUTPUT_BEFORE],
57 ("simple_python_tracer", 1),
58 comin.COMIN_FLAG_READ | comin.COMIN_FLAG_WRITE,
59 )
60 print("tracer dim_semantics:", simple_python_tracer.dim_semantics)
61 print("tracer ncontained:", simple_python_tracer.ncontained)
62
63
64@comin.EP_ATM_WRITE_OUTPUT_BEFORE
66 print("simple_python_diagfct called!", file=sys.stderr)
67 np.asarray(simple_python_var)[:] = np.asarray(pres) + 42.0
68 np.asarray(simple_python_tracer)[:] = np.asarray(simple_python_var) / 1337.0
69
70
71@comin.EP_DESTRUCTOR
73 print("simple_python_destructor called!", file=sys.stderr)
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
current_get_plugin_info()
returns object describing the current plugin
Definition comin.py:146