formatted_io7 Example¶
Python Version¶
Model Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Import classes for input/output channels
from cis_interface.interface.CisInterface import CisInput, CisOutput
# Initialize input/output channels
in_channel = CisInput('inputA')
out_channel = CisOutput('outputA')
# Loop until there is no longer input or the queues are closed
while True:
# Receive input from input channel
# If there is an error, the flag will be False
flag, obj = in_channel.recv()
if not flag:
print("Model A: No more input.")
break
# Print received message
print('Model A: %s' % str(obj))
# Send output to output channel
# If there is an error, the flag will be False
flag = out_channel.send(obj)
if not flag:
raise RuntimeError("Model A: Error sending output.")
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Import classes for input/output channels
from cis_interface.interface.CisInterface import CisInput, CisOutput
# Initialize input/output channels
in_channel = CisInput('inputB')
out_channel = CisOutput('outputB')
# Loop until there is no longer input or the queues are closed
while True:
# Receive input from input channel
# If there is an error, the flag will be False
flag, obj = in_channel.recv()
if not flag:
print("Model B: No more input.")
break
# Print received message
print('Model B: %s' % str(obj))
# Send output to output channel
# If there is an error, the flag will be False
flag = out_channel.send(obj)
if not flag:
raise RuntimeError("Model B: Error sending output.")
|
Model YAML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | models:
- name: python_modelA
language: python
args: ./src/formatted_io7_modelA.py
inputs:
- name: inputA
type: object
outputs:
- name: outputA
type: object
- name: python_modelB
language: python
args: ./src/formatted_io7_modelB.py
inputs:
- name: inputB
type: object
outputs:
- name: outputB
type: object
connections:
- input: outputA # Connection between model A output & model B input
output: inputB
- input: ./Input/input.txt # Connection between file and model A input
output: inputA
filetype: map
- input: outputB # Connection between model B output and file
output: ./output.txt
filetype: map
|
Matlab Version¶
Model Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | % Initialize input/output channels
in_channel = CisInterface('CisInput', 'inputA');
out_channel = CisInterface('CisOutput', 'outputA');
flag = true;
% Loop until there is no longer input or the queues are closed
while flag
% Receive input from input channel
% If there is an error, the flag will be False.
[flag, obj] = in_channel.recv();
if (~flag)
disp('Model A: No more input.');
break;
end;
% Print received message
fprintf('Model A:');
disp(obj);
% Send output to output channel
% If there is an error, the flag will be False
flag = out_channel.send(obj);
if (~flag)
error('Model A: Error sending output.');
break;
end;
end;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | % Initialize input/output channels
in_channel = CisInterface('CisInput', 'inputB');
out_channel = CisInterface('CisOutput', 'outputB');
flag = true;
% Loop until there is no longer input or the queues are closed
while flag
% Receive input from input channel
% If there is an error, the flag will be False.
[flag, obj] = in_channel.recv();
if (~flag)
disp('Model B: No more input.');
break;
end;
% Print received message
fprintf('Model B:');
disp(obj);
% Send output to output channel
% If there is an error, the flag will be False
flag = out_channel.send(obj);
if (~flag)
error('Model B: Error sending output.');
break;
end;
end;
|
Model YAML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | models:
- name: matlab_modelA
language: matlab
args: ./src/formatted_io7_modelA.m
inputs:
- name: inputA
type: object
outputs:
- name: outputA
type: object
- name: matlab_modelB
language: matlab
args: ./src/formatted_io7_modelB.m
inputs:
- name: inputB
type: object
outputs:
- name: outputB
type: object
connections:
- input: outputA # Connection between model A output & model B input
output: inputB
- input: ./Input/input.txt # Connection between file and model A input
output: inputA
filetype: map
- input: outputB # Connection between model B output and file
output: ./output.txt
filetype: map
|