iode.execute_command

iode.execute_command(command: str | List[str])[source]

Execute one or several IODE commands.

Parameters:
command: str or list(str)

IODE command(s) to execute. If multiple commands are passed as one string, each command must end with the special character n.

Examples

>>> from iode import execute_command
>>> from pathlib import Path
>>> output_dir = getfixture('tmp_path')
>>> result_var_file = str(output_dir / "test_var.av")
>>> # execute IODE command one by one
>>> execute_command("$WsClearVar")
iode> $WsClearVar
>>> execute_command("$WsSample 2000Y1 2005Y1")
iode> $WsSample 2000Y1 2005Y1
>>> execute_command("$DataCalcVar A t+1")
iode> $DataCalcVar A t+1
>>> execute_command("$DataCalcVar B t-1")
iode> $DataCalcVar B t-1
>>> execute_command("$DataCalcVar C A/B")
iode> $DataCalcVar C A/B
>>> execute_command("$DataCalcVar D grt A")
iode> $DataCalcVar D grt A
>>> execute_command(f"$WsSaveVar {result_var_file}")
iode> $WsSaveVar ...test_var.av
Saving ...test_var.av
>>> # check content of file test_var.av
>>> with open(result_var_file, "r") as f:
...     print(f.read())
sample 2000Y1 2005Y1
A 1 2 3 4 5 6
B -1 0 1 2 3 4
C -1 na 3 2 1.66666666666667 1.5
D na 100 50 33.3333333333333 25 20