formatted_io7

Two models, A & B, that send/receive key/value maps. 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
 5int main(int argc, char *argv[]) {
 6  // Initialize input/output channels
 7  yggInput_t in_channel = yggJSONObjectInput("inputA");
 8  yggOutput_t out_channel = yggJSONObjectOutput("outputA");
 9
10  // Declare resulting variables and create buffer for received message
11  int flag = 1;
12  json_object_t obj = init_json_object();
13
14  // Loop until there is no longer input or the queues are closed
15  while (flag >= 0) {
16  
17    // Receive input from input channel
18    // If there is an error, the flag will be negative
19    // Otherwise, it is the size of the received message
20    flag = yggRecv(in_channel, &obj);
21    if (flag < 0) {
22      printf("Model A: No more input.\n");
23      break;
24    }
25
26    // Print received message
27    printf("Model A:\n");
28    display_json_object(obj);
29
30    // Send output to output channel
31    // If there is an error, the flag will be negative
32    flag = yggSend(out_channel, obj);
33    if (flag < 0) {
34      printf("Model A: Error sending output.\n");
35      break;
36    }
37
38  }
39
40  // Free dynamically allocated obj structure
41  free_json_object(&obj);
42  
43  return 0;
44}
45
 1#include <stdio.h>
 2// Include methods for input/output channels
 3#include "YggInterface.h"
 4
 5int main(int argc, char *argv[]) {
 6  // Initialize input/output channels
 7  yggInput_t in_channel = yggJSONObjectInput("inputB");
 8  yggOutput_t out_channel = yggJSONObjectOutput("outputB");
 9
10  // Declare resulting variables and create buffer for received message
11  int flag = 1;
12  json_object_t obj = init_json_object();
13
14  // Loop until there is no longer input or the queues are closed
15  while (flag >= 0) {
16  
17    // Receive input from input channel
18    // If there is an error, the flag will be negative
19    // Otherwise, it is the size of the received message
20    flag = yggRecv(in_channel, &obj);
21    if (flag < 0) {
22      printf("Model B: No more input.\n");
23      break;
24    }
25
26    // Print received message
27    printf("Model B:\n");
28    display_json_object(obj);
29
30    // Send output to output channel
31    // If there is an error, the flag will be negative
32    flag = yggSend(out_channel, obj);
33    if (flag < 0) {
34      printf("Model B: Error sending output.\n");
35      break;
36    }
37
38  }
39
40  // Free dynamically allocated obj structure
41  free_json_object(&obj);
42  
43  return 0;
44}
45

Model YAML:

 1models:
 2  - name: c_modelA
 3    language: c
 4    args: ./src/formatted_io7_modelA.c
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: c_modelB
13    language: c
14    args: ./src/formatted_io7_modelB.c
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map

C++ Version

Model Code:

 1#include <iostream>
 2// Include methods for input/output channels
 3#include "YggInterface.hpp"
 4
 5int main(int argc, char *argv[]) {
 6  // Initialize input/output channels
 7  YggJSONObjectInput in_channel("inputA");
 8  YggJSONObjectOutput out_channel("outputA");
 9
10  // Declare resulting variables and create buffer for received message
11  int flag = 1;
12  rapidjson::Document obj;
13
14  // Loop until there is no longer input or the queues are closed
15  while (flag >= 0) {
16  
17    // Receive input from input channel
18    // If there is an error, the flag will be negative
19    // Otherwise, it is the size of the received message
20    flag = in_channel.recv(1, &obj);
21    if (flag < 0) {
22      std::cout << "Model A: No more input." << std::endl;
23      break;
24    }
25
26    // Print received message
27    printf("Model A:\n");
28    std::cerr << document2string(obj) << std::endl;
29
30    // Send output to output channel
31    // If there is an error, the flag will be negative
32    flag = out_channel.send(1, &obj);
33    if (flag < 0) {
34      std::cout << "Model A: Error sending output." << std::endl;
35      break;
36    }
37
38  }
39
40  return 0;
41}
 1#include <iostream>
 2// Include methods for input/output channels
 3#include "YggInterface.hpp"
 4
 5int main(int argc, char *argv[]) {
 6  // Initialize input/output channels
 7  YggJSONObjectInput in_channel("inputB");
 8  YggJSONObjectOutput out_channel("outputB");
 9
10  // Declare resulting variables and create buffer for received message
11  int flag = 1;
12  rapidjson::Document obj;
13
14  // Loop until there is no longer input or the queues are closed
15  while (flag >= 0) {
16  
17    // Receive input from input channel
18    // If there is an error, the flag will be negative
19    // Otherwise, it is the size of the received message
20    flag = in_channel.recv(1, &obj);
21    if (flag < 0) {
22      std::cout << "Model B: No more input." << std::endl;
23      break;
24    }
25
26    // Print received message
27    printf("Model B:\n");
28    std::cerr << document2string(obj) << std::endl;
29
30    // Send output to output channel
31    // If there is an error, the flag will be negative
32    flag = out_channel.send(1, &obj);
33    if (flag < 0) {
34      std::cout << "Model B: Error sending output." << std::endl;
35      break;
36    }
37
38  }
39
40  return 0;
41}

Model YAML:

 1models:
 2  - name: cpp_modelA
 3    language: cpp
 4    args: ./src/formatted_io7_modelA.cpp
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: cpp_modelB
13    language: cpp
14    args: ./src/formatted_io7_modelB.cpp
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map

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  type(ygggeneric) :: obj
 9  obj = init_generic()
10
11  ! initialize input/output channels
12  in_channel = ygg_json_object_input("inputA")
13  out_channel = ygg_json_object_output("outputA")
14
15  ! Loop until there is no longer input or the queues are closed
16  do while (flag)
17
18     ! Receive input from input channel
19     ! If there is an error, the flag will be negative
20     ! Otherwise, it is the number of variables filled
21     flag = ygg_recv_var(in_channel, yggarg(obj))
22     if (.not.flag) then
23        print *, "Model A: No more input."
24        exit
25     end if
26
27     ! Print received message
28     print *, "Model A:"
29     call display_generic(obj)
30
31     ! Send output to output channel
32     ! If there is an error, the flag will be negative
33     flag = ygg_send_var(out_channel, yggarg(obj))
34     if (.not.flag) then
35        print *, "Model A: Error sending output."
36        exit
37     end if
38
39  end do
40
41end 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  type(ygggeneric) :: obj
 9  obj = init_generic()
10
11  ! initialize input/output channels
12  in_channel = ygg_json_object_input("inputB")
13  out_channel = ygg_json_object_output("outputB")
14
15  ! Loop until there is no longer input or the queues are closed
16  do while (flag)
17
18     ! Receive input from input channel
19     ! If there is an error, the flag will be negative
20     ! Otherwise, it is the number of variables filled
21     flag = ygg_recv_var(in_channel, yggarg(obj))
22     if (.not.flag) then
23        print *, "Model B: No more input."
24        exit
25     end if
26
27     ! Print received message
28     print *, "Model B:"
29     call display_generic(obj)
30
31     ! Send output to output channel
32     ! If there is an error, the flag will be negative
33     flag = ygg_send_var(out_channel, yggarg(obj))
34     if (.not.flag) then
35        print *, "Model B: Error sending output."
36        exit
37     end if
38
39  end do
40
41end program main

Model YAML:

 1models:
 2  - name: fortran_modelA
 3    language: fortran
 4    args: ./src/formatted_io7_modelA.f90
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: fortran_modelB
13    language: fortran
14    args: ./src/formatted_io7_modelB.f90
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map

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("YggInput", "inputA")
 7out_channel = Yggdrasil.YggInterface("YggOutput", "outputA")
 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, obj = in_channel.recv()
15    if (!flag)
16        println("Model A: No more input.")
17	break
18    end
19
20    # Print received message
21    println(obj)
22
23    # Send output to output channel
24    # If there is an error, the flag will be false
25    flag = out_channel.send(obj)
26    if (!flag)
27        error("Model A: Error sending output.")
28    end
29
30end  # while
 1# Import library for input/output channels
 2using Yggdrasil
 3using Printf
 4
 5# Initialize input/output channels
 6in_channel = Yggdrasil.YggInterface("YggInput", "inputB")
 7out_channel = Yggdrasil.YggInterface("YggOutput", "outputB")
 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, obj = in_channel.recv()
15    if (!flag)
16        println("Model B: No more input.")
17	break
18    end
19
20    # Print received message
21    println(obj)
22
23    # Send output to output channel
24    # If there is an error, the flag will be false
25    flag = out_channel.send(obj)
26    if (!flag)
27        error("Model B: Error sending output.")
28    end
29
30end  # while

Model YAML:

 1models:
 2  - name: julia_modelA
 3    language: julia
 4    args: ./src/formatted_io7_modelA.jl
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: julia_modelB
13    language: julia
14    args: ./src/formatted_io7_modelB.jl
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map

Matlab Version

Model Code:

 1% Initialize input/output channels 
 2in_channel = YggInterface('YggInput', 'inputA');
 3out_channel = YggInterface('YggOutput', 'outputA');
 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, obj] = in_channel.recv();
13  if (~flag)
14    disp('Model A: No more input.');
15    break;
16  end;
17
18  % Print received message
19  fprintf('Model A:');
20  disp(obj);
21
22  % Send output to output channel
23  % If there is an error, the flag will be False
24  flag = out_channel.send(obj);
25  if (~flag)
26    error('Model A: Error sending output.');
27    break;
28  end;
29  
30end;
 1% Initialize input/output channels 
 2in_channel = YggInterface('YggInput', 'inputB');
 3out_channel = YggInterface('YggOutput', 'outputB');
 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, obj] = in_channel.recv();
13  if (~flag)
14    disp('Model B: No more input.');
15    break;
16  end;
17
18  % Print received message
19  fprintf('Model B:');
20  disp(obj);
21
22  % Send output to output channel
23  % If there is an error, the flag will be False
24  flag = out_channel.send(obj);
25  if (~flag)
26    error('Model B: Error sending output.');
27    break;
28  end;
29  
30end;

Model YAML:

 1models:
 2  - name: matlab_modelA
 3    language: matlab
 4    args: ./src/formatted_io7_modelA.m
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: matlab_modelB
13    language: matlab
14    args: ./src/formatted_io7_modelB.m
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map

Python Version

Model Code:

 1# Import classes for input/output channels
 2from yggdrasil.interface.YggInterface import YggInput, YggOutput
 3
 4# Initialize input/output channels
 5in_channel = YggInput('inputA')
 6out_channel = YggOutput('outputA')
 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    flag, obj = in_channel.recv()
14    if not flag:
15        print("Model A: No more input.")
16        break
17
18    # Print received message
19    print('Model A: %s' % str(obj))
20
21    # Send output to output channel
22    # If there is an error, the flag will be False
23    flag = out_channel.send(obj)
24    if not flag:
25        raise RuntimeError("Model A: Error sending output.")
 1# Import classes for input/output channels
 2from yggdrasil.interface.YggInterface import YggInput, YggOutput
 3
 4# Initialize input/output channels
 5in_channel = YggInput('inputB')
 6out_channel = YggOutput('outputB')
 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    flag, obj = in_channel.recv()
14    if not flag:
15        print("Model B: No more input.")
16        break
17
18    # Print received message
19    print('Model B: %s' % str(obj))
20
21    # Send output to output channel
22    # If there is an error, the flag will be False
23    flag = out_channel.send(obj)
24    if not flag:
25        raise RuntimeError("Model B: Error sending output.")

Model YAML:

 1models:
 2  - name: python_modelA
 3    language: python
 4    args: ./src/formatted_io7_modelA.py
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: python_modelB
13    language: python
14    args: ./src/formatted_io7_modelB.py
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map

R Version

Model Code:

 1# Import library for input/output
 2library(yggdrasil)
 3
 4# Initialize input/output channels
 5in_channel <- YggInterface('YggInput', 'inputA')
 6out_channel <- YggInterface('YggOutput', 'outputA')
 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, obj) %<-% in_channel$recv()
14  if (!flag) {
15    print('Model A: No more input.')
16    break
17  }
18
19  # Print received message
20  print('Model A:')
21  print(obj)
22
23  # Send output to output channel
24  # If there is an error, the flag will be False
25  flag = out_channel$send(obj)
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('YggInput', 'inputB')
 6out_channel <- YggInterface('YggOutput', 'outputB')
 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, obj) %<-% in_channel$recv()
14  if (!flag) {
15    print('Model B: No more input.')
16    break
17  }
18
19  # Print received message
20  print('Model B:')
21  print(obj)
22
23  # Send output to output channel
24  # If there is an error, the flag will be False
25  flag = out_channel$send(obj)
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_io7_modelA.R
 5    inputs:
 6      - name: inputA
 7        type: object
 8    outputs:
 9      - name: outputA
10        type: object
11
12  - name: R_modelB
13    language: R
14    args: ./src/formatted_io7_modelB.R
15    inputs:
16      - name: inputB
17        type: object
18    outputs:
19      - name: outputB
20        type: object
21
22connections:
23  - input: outputA  # Connection between model A output & model B input
24    output: inputB
25  - input: ./Input/input.txt  # Connection between file and model A input
26    output: inputA
27    filetype: map
28  - input: outputB  # Connection between model B output and file
29    output: ./output.txt
30    filetype: map