formatted_io2¶
Two models, A & B, that send/receive rows of table data. Model A receives input from a file and then sends it’s output to model B. Model B receives input from model A and sends it’s output to a file.
C Version¶
Model Code:
1#include <stdio.h>
2// Include methods for input/output channels
3#include "YggInterface.h"
4
5#define MYBUFSIZ 1000
6
7int main(int argc, char *argv[]) {
8 // Initialize input/output channels
9 yggAsciiTableInput_t in_channel = yggAsciiTableInput("inputA");
10 yggAsciiTableOutput_t out_channel = yggAsciiTableOutput("outputA", "%6s\t%d\t%f\n");
11
12 // Declare resulting variables and create buffer for received message
13 int flag = 1;
14 size_t name_siz = MYBUFSIZ;
15 char name[MYBUFSIZ];
16 int count = 0;
17 double size = 0.0;
18
19 // Loop until there is no longer input or the queues are closed
20 while (flag >= 0) {
21 name_siz = MYBUFSIZ; // Reset to size of the buffer
22
23 // Receive input from input channel
24 // If there is an error, the flag will be negative
25 // Otherwise, it is the size of the received message
26 flag = yggRecv(in_channel, &name, &name_siz, &count, &size);
27 if (flag < 0) {
28 printf("Model A: No more input.\n");
29 break;
30 }
31
32 // Print received message
33 printf("Model A: %s, %d, %f\n", name, count, size);
34
35 // Send output to output channel
36 // If there is an error, the flag will be negative
37 flag = yggSend(out_channel, name, name_siz, count, size);
38 if (flag < 0) {
39 printf("Model A: Error sending output.\n");
40 break;
41 }
42
43 }
44
45 return 0;
46}
47
1#include <stdio.h>
2// Include methods for input/output channels
3#include "YggInterface.h"
4
5#define MYBUFSIZ 1000
6
7int main(int argc, char *argv[]) {
8 // Initialize input/output channels
9 yggAsciiTableInput_t in_channel = yggAsciiTableInput("inputB");
10 yggAsciiTableOutput_t out_channel = yggAsciiTableOutput("outputB", "%6s\t%d\t%f\n");
11
12 // Declare resulting variables and create buffer for received message
13 int flag = 1;
14 size_t name_siz = MYBUFSIZ;
15 char name[MYBUFSIZ];
16 int count = 0;
17 double size = 0.0;
18
19 // Loop until there is no longer input or the queues are closed
20 while (flag >= 0) {
21 name_siz = MYBUFSIZ; // Reset to size of the buffer
22
23 // Receive input from input channel
24 // If there is an error, the flag will be negative
25 // Otherwise, it is the size of the received message
26 flag = yggRecv(in_channel, &name, &name_siz, &count, &size);
27 if (flag < 0) {
28 printf("Model B: No more input.\n");
29 break;
30 }
31
32 // Print received message
33 printf("Model B: %s, %d, %f\n", name, count, size);
34
35 // Send output to output channel
36 // If there is an error, the flag will be negative
37 flag = yggSend(out_channel, name, name_siz, count, size);
38 if (flag < 0) {
39 printf("Model B: Error sending output.\n");
40 break;
41 }
42
43 }
44
45 return 0;
46}
47
Model YAML:
1models:
2 - name: c_modelA
3 language: c
4 args: ./src/formatted_io2_modelA.c
5 inputs: inputA
6 outputs: outputA
7
8 - name: c_modelB
9 language: c
10 args: ./src/formatted_io2_modelB.c
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table
C++ Version¶
Model Code:
1#include <iostream>
2// Include methods for input/output channels
3#include "YggInterface.hpp"
4
5#define MYBUFSIZ 1000
6
7int main(int argc, char *argv[]) {
8 // Initialize input/output channels
9 YggAsciiTableInput in_channel("inputA");
10 YggAsciiTableOutput out_channel("outputA", "%6s\t%d\t%f\n");
11
12 // Declare resulting variables and create buffer for received message
13 int flag = 1;
14 size_t name_siz = MYBUFSIZ;
15 size_t * const p_name_siz = &name_siz; // Required in C++ to get name size
16 char name[MYBUFSIZ];
17 int count = 0;
18 double size = 0.0;
19
20 // Loop until there is no longer input or the queues are closed
21 while (flag >= 0) {
22 name_siz = MYBUFSIZ; // Reset to buffer size
23
24 // Receive input from input channel
25 // If there is an error, the flag will be negative
26 // Otherwise, it is the size of the received message
27 flag = in_channel.recv(4, &name, &name_siz, &count, &size);
28 if (flag < 0) {
29 std::cout << "Model A: No more input." << std::endl;
30 break;
31 }
32
33 // Print received message
34 std::cout << "Model A: " << name << ", " << count << ", " << size << std::endl;
35
36 // Send output to output channel
37 // If there is an error, the flag will be negative
38 flag = out_channel.send(4, name, name_siz, count, size);
39 if (flag < 0) {
40 std::cout << "Model A: Error sending output." << std::endl;
41 break;
42 }
43
44 }
45
46 return 0;
47}
1#include <iostream>
2// Include methods for input/output channels
3#include "YggInterface.hpp"
4
5#define MYBUFSIZ 1000
6
7int main(int argc, char *argv[]) {
8 // Initialize input/output channels
9 YggAsciiTableInput in_channel("inputB");
10 YggAsciiTableOutput out_channel("outputB", "%6s\t%d\t%f\n");
11
12 // Declare resulting variables and create buffer for received message
13 int flag = 1;
14 size_t name_siz = MYBUFSIZ;
15 size_t * const p_name_siz = &name_siz; // Required in C++ to get name size
16 char name[MYBUFSIZ];
17 int count = 0;
18 double size = 0.0;
19
20 // Loop until there is no longer input or the queues are closed
21 while (flag >= 0) {
22 name_siz = MYBUFSIZ; // Reset to buffer size
23
24 // Receive input from input channel
25 // If there is an error, the flag will be negative
26 // Otherwise, it is the size of the received message
27 flag = in_channel.recv(4, &name, &name_siz, &count, &size);
28 if (flag < 0) {
29 std::cout << "Model B: No more input." << std::endl;
30 break;
31 }
32
33 // Print received message
34 std::cout << "Model B: " << name << ", " << count << ", " << size << std::endl;
35
36 // Send output to output channel
37 // If there is an error, the flag will be negative
38 flag = out_channel.send(4, name, name_siz, count, size);
39 if (flag < 0) {
40 std::cout << "Model B: Error sending output." << std::endl;
41 break;
42 }
43
44 }
45
46 return 0;
47}
Model YAML:
1models:
2 - name: cpp_modelA
3 language: c++
4 args: ./src/formatted_io2_modelA.cpp
5 inputs: inputA
6 outputs: outputA
7
8 - name: cpp_modelB
9 language: c++
10 args: ./src/formatted_io2_modelB.cpp
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table
Fortran Version¶
Model Code:
1program main
2 ! Include methods for input/output channels
3 use fygg
4
5 ! Declare resulting variables and create buffer for received message
6 logical :: flag = .true.
7 type(yggcomm) :: in_channel, out_channel
8 integer(kind=c_size_t), parameter :: MYBUFSIZ = 1000
9 character(len=MYBUFSIZ), target :: msg
10 integer(kind=c_size_t), target :: msg_siz = 0
11 integer, target :: count = 0
12 real(kind=8), target :: siz = 0.0
13
14 ! Initialize input/output channels
15 in_channel = ygg_ascii_table_input("inputA")
16 out_channel = ygg_ascii_table_output("outputA", "%6s\t%d\t%f\n")
17
18 ! Loop until there is no longer input or the queues are closed
19 do while (flag)
20 msg_siz = MYBUFSIZ
21
22 ! Receive input from input channel
23 ! If there is an error, the flag will be negative
24 ! Otherwise, it is the number of variables filled
25 flag = ygg_recv_var(in_channel, [ &
26 yggarg(msg), yggarg(msg_siz), yggarg(count), yggarg(siz)])
27 if (.not.flag) then
28 print *, "Model A: No more input."
29 exit
30 end if
31
32 ! Print received message
33 print *, "Model A: ", msg, count, siz
34
35 ! Send output to output channel
36 ! If there is an error, the flag will be negative
37 flag = ygg_send_var(out_channel, [ &
38 yggarg(msg), yggarg(msg_siz), yggarg(count), yggarg(siz)])
39 if (.not.flag) then
40 print *, "Model A: Error sending output."
41 exit
42 end if
43
44 end do
45
46end program main
1program main
2 ! Include methods for input/output channels
3 use fygg
4
5 ! Declare resulting variables and create buffer for received message
6 logical :: flag = .true.
7 type(yggcomm) :: in_channel, out_channel
8 integer(kind=c_size_t), parameter :: MYBUFSIZ = 1000
9 character(len=MYBUFSIZ), target :: msg
10 integer(kind=c_size_t), target :: msg_siz = 0
11 integer, target :: count = 0
12 real(kind=8), target :: siz = 0.0
13
14 ! Initialize input/output channels
15 in_channel = ygg_ascii_table_input("inputB")
16 out_channel = ygg_ascii_table_output("outputB", "%6s\t%d\t%f\n")
17
18 ! Loop until there is no longer input or the queues are closed
19 do while (flag)
20 msg_siz = MYBUFSIZ
21
22 ! Receive input from input channel
23 ! If there is an error, the flag will be negative
24 ! Otherwise, it is the number of variables filled
25 flag = ygg_recv_var(in_channel, [ &
26 yggarg(msg), yggarg(msg_siz), yggarg(count), yggarg(siz)])
27 if (.not.flag) then
28 print *, "Model B: No more input."
29 exit
30 end if
31
32 ! Print received message
33 print *, "Model B: ", msg, count, siz
34
35 ! Send output to output channel
36 ! If there is an error, the flag will be negative
37 flag = ygg_send_var(out_channel, [ &
38 yggarg(msg), yggarg(msg_siz), yggarg(count), yggarg(siz)])
39 if (.not.flag) then
40 print *, "Model B: Error sending output."
41 exit
42 end if
43
44 end do
45
46end program main
Model YAML:
1models:
2 - name: fortran_modelA
3 language: fortran
4 args: ./src/formatted_io2_modelA.f90
5 inputs: inputA
6 outputs: outputA
7
8 - name: fortran_modelB
9 language: fortran
10 args: ./src/formatted_io2_modelB.f90
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table
Julia Version¶
Model Code:
1# Import library for input/output channels
2using Yggdrasil
3using Printf
4
5# Initialize input/output channels
6in_channel = Yggdrasil.YggInterface("YggAsciiTableInput", "inputA")
7out_channel = Yggdrasil.YggInterface("YggAsciiTableOutput", "outputA",
8 "%6s\t%d\t%f\n")
9
10# Loop until there is no longer input or the queues are closed
11while true
12
13 # Receive input from input channel
14 # If there is an error, the flag will be false
15 flag, msg = in_channel.recv()
16 if (!flag)
17 println("Model A: No more input.")
18 break
19 end
20 name, count, size = msg
21
22 # Print received message
23 @printf("Model A: %s, %d, %f\n", name, count, size)
24
25 # Send output to output channel
26 # If there is an error, the flag will be false
27 flag = out_channel.send(name, count, size)
28 if (!flag)
29 error("Model A: Error sending output.")
30 end
31
32end # while
1# Import library for input/output channels
2using Yggdrasil
3using Printf
4
5# Initialize input/output channels
6in_channel = Yggdrasil.YggInterface("YggAsciiTableInput", "inputB")
7out_channel = Yggdrasil.YggInterface("YggAsciiTableOutput", "outputB",
8 "%6s\t%d\t%f\n")
9
10# Loop until there is no longer input or the queues are closed
11while true
12
13 # Receive input from input channel
14 # If there is an error, the flag will be false
15 flag, msg = in_channel.recv()
16 if (!flag)
17 println("Model B: No more input.")
18 break
19 end
20 name, count, size = msg
21
22 # Print received message
23 @printf("Model B: %s, %d, %f\n", name, count, size)
24
25 # Send output to output channel
26 # If there is an error, the flag will be false
27 flag = out_channel.send(name, count, size)
28 if (!flag)
29 error("Model B: Error sending output.")
30 end
31
32end # while
Model YAML:
1models:
2 - name: julia_modelA
3 language: julia
4 args: ./src/formatted_io2_modelA.jl
5 inputs: inputA
6 outputs: outputA
7
8 - name: julia_modelB
9 language: julia
10 args: ./src/formatted_io2_modelB.jl
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table
Matlab Version¶
Model Code:
1% Initialize input/output channels
2in_channel = YggInterface('YggAsciiTableInput', 'inputA');
3out_channel = YggInterface('YggAsciiTableOutput', 'outputA', '%6s\t%d\t%f\n');
4
5flag = true;
6
7% Loop until there is no longer input or the queues are closed
8while flag
9
10 % Receive input from input channel
11 % If there is an error, the flag will be False.
12 [flag, msg] = in_channel.recv();
13 if (~flag)
14 disp('Model A: No more input.');
15 break;
16 end;
17 name = msg{1};
18 count = msg{2};
19 size = msg{3};
20
21 % Print received message
22 fprintf('Model A: %s, %d, %f\n', name, count, size);
23
24 % Send output to output channel
25 % If there is an error, the flag will be False
26 flag = out_channel.send(name, count, size);
27 if (~flag)
28 error('Model A: Error sending output.');
29 break;
30 end;
31
32end;
1% Initialize input/output channels
2in_channel = YggInterface('YggAsciiTableInput', 'inputB');
3out_channel = YggInterface('YggAsciiTableOutput', 'outputB', '%6s\t%d\t%f\n');
4
5flag = true;
6
7% Loop until there is no longer input or the queues are closed
8while flag
9
10 % Receive input from input channel
11 % If there is an error, the flag will be False.
12 [flag, msg] = in_channel.recv();
13 if (~flag)
14 disp('Model B: No more input.');
15 break;
16 end;
17 name = msg{1};
18 count = msg{2};
19 size = msg{3};
20
21 % Print received message
22 fprintf('Model B: %s, %d, %f\n', name, count, size);
23
24 % Send output to output channel
25 % If there is an error, the flag will be False
26 flag = out_channel.send(name, count, size);
27 if (~flag)
28 error('Model B: Error sending output.');
29 break;
30 end;
31
32end;
Model YAML:
1models:
2 - name: matlab_modelA
3 language: matlab
4 args: ./src/formatted_io2_modelA.m
5 inputs: inputA
6 outputs: outputA
7
8 - name: matlab_modelB
9 language: matlab
10 args: ./src/formatted_io2_modelB.m
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table
Python Version¶
Model Code:
1# Import classes for input/output channels
2from yggdrasil.interface.YggInterface import (
3 YggAsciiTableInput, YggAsciiTableOutput)
4
5# Initialize input/output channels
6in_channel = YggAsciiTableInput('inputA')
7out_channel = YggAsciiTableOutput('outputA', '%6s\t%d\t%f\n')
8
9# Loop until there is no longer input or the queues are closed
10while True:
11
12 # Receive input from input channel
13 # If there is an error, the flag will be False
14 flag, msg = in_channel.recv()
15 if not flag:
16 print("Model A: No more input.")
17 break
18 name, count, size = msg
19
20 # Print received message
21 print('Model A: %s, %d, %f' % (name, count, size))
22
23 # Send output to output channel
24 # If there is an error, the flag will be False
25 flag = out_channel.send(name, count, size)
26 if not flag:
27 raise RuntimeError("Model A: Error sending output.")
1# Import classes for input/output channels
2from yggdrasil.interface.YggInterface import (
3 YggAsciiTableInput, YggAsciiTableOutput)
4
5# Initialize input/output channels
6in_channel = YggAsciiTableInput('inputB')
7out_channel = YggAsciiTableOutput('outputB', '%6s\t%d\t%f\n')
8
9# Loop until there is no longer input or the queues are closed
10while True:
11
12 # Receive input from input channel
13 # If there is an error, the flag will be False
14 flag, msg = in_channel.recv()
15 if not flag:
16 print("Model B: No more input.")
17 break
18 name, count, size = msg
19
20 # Print received message
21 print('Model B: %s, %d, %f' % (name, count, size))
22
23 # Send output to output channel
24 # If there is an error, the flag will be False
25 flag = out_channel.send(name, count, size)
26 if not flag:
27 raise RuntimeError("Model B: Error sending output.")
Model YAML:
1models:
2 - name: python_modelA
3 language: python
4 args: ./src/formatted_io2_modelA.py
5 inputs: inputA
6 outputs: outputA
7
8 - name: python_modelB
9 language: python
10 args: ./src/formatted_io2_modelB.py
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table
R Version¶
Model Code:
1# Import library for input/output
2library(yggdrasil)
3
4# Initialize input/output channels
5in_channel <- YggInterface('YggAsciiTableInput', 'inputA')
6out_channel <- YggInterface('YggAsciiTableOutput', 'outputA', '%6s\t%d\t%f\n')
7
8# Loop until there is no longer input or the queues are closed
9while(TRUE) {
10
11 # Receive input from input channel
12 # If there is an error, the flag will be False
13 c(flag, msg) %<-% in_channel$recv()
14 if (!flag) {
15 print('Model A: No more input.')
16 break
17 }
18 c(name, count, size) %<-% msg
19
20 # Print received message
21 fprintf('Model A: %s, %d, %f', name, count, size)
22
23 # Send output to output channel
24 # If there is an error, the flag will be False
25 flag = out_channel$send(name, count, size)
26 if (!flag) {
27 stop('Model A: Error sending output.')
28 }
29
30}
1# Import library for input/output
2library(yggdrasil)
3
4# Initialize input/output channels
5in_channel <- YggInterface('YggAsciiTableInput', 'inputB')
6out_channel <- YggInterface('YggAsciiTableOutput', 'outputB', '%6s\t%d\t%f\n')
7
8# Loop until there is no longer input or the queues are closed
9while(TRUE) {
10
11 # Receive input from input channel
12 # If there is an error, the flag will be False
13 c(flag, msg) %<-% in_channel$recv()
14 if (!flag) {
15 print('Model B: No more input.')
16 break
17 }
18 c(name, count, size) %<-% msg
19
20 # Print received message
21 fprintf('Model B: %s, %d, %f', name, count, size)
22
23 # Send output to output channel
24 # If there is an error, the flag will be False
25 flag = out_channel$send(name, count, size)
26 if (!flag) {
27 stop('Model B: Error sending output.')
28 }
29
30}
Model YAML:
1models:
2 - name: R_modelA
3 language: R
4 args: ./src/formatted_io2_modelA.R
5 inputs: inputA
6 outputs: outputA
7
8 - name: R_modelB
9 language: R
10 args: ./src/formatted_io2_modelB.R
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.txt # Connection between file and model A input
18 output: inputA
19 filetype: table
20 - input: outputB # Connection between model B output and file
21 output: ./output.txt
22 filetype: table