backwards

A single model using the deprecated “Cis” versions of the interface.

C Version

Model Code:

 1#include <stdio.h>
 2// Include methods for input/output channels
 3#include "CisInterface.h"
 4
 5#define MYBUFSIZ 1000
 6
 7int main(int argc, char *argv[]) {
 8  // Initialize input/output channels
 9  cisInput_t in_channel = cisInput("inputA");
10  cisOutput_t out_channel = cisOutput("outputA");
11
12  // Declare resulting variables and create buffer for received message
13  int flag = 1;
14  char buf[MYBUFSIZ];
15
16  // Loop until there is no longer input or the queues are closed
17  while (flag >= 0) {
18  
19    // Receive input from input channel
20    // If there is an error, the flag will be negative
21    // Otherwise, it is the size of the received message
22    flag = cis_recv(in_channel, buf, MYBUFSIZ);
23    if (flag < 0) {
24      printf("Model A: No more input.\n");
25      break;
26    }
27
28    // Print received message
29    printf("Model A: %s\n", buf);
30
31    // Send output to output channel
32    // If there is an error, the flag will be negative
33    flag = cis_send(out_channel, buf, flag);
34    if (flag < 0) {
35      printf("Model A: Error sending output.\n");
36      break;
37    }
38
39  }
40  
41  return 0;
42}
43
 1#include <stdio.h>
 2// Include methods for input/output channels
 3#include "CisInterface.h"
 4
 5#define MYBUFSIZ 1000
 6
 7int main(int argc, char *argv[]) {
 8  // Initialize input/output channels
 9  cisInput_t in_channel = cisInput("inputB");
10  cisOutput_t out_channel = cisOutput("outputB");
11
12  // Declare resulting variables and create buffer for received message
13  int flag = 1;
14  char buf[MYBUFSIZ];
15
16  // Loop until there is no longer input or the queues are closed
17  while (flag >= 0) {
18  
19    // Receive input from input channel
20    // If there is an error, the flag will be negative
21    // Otherwise, it is the size of the received message
22    flag = cis_recv(in_channel, buf, MYBUFSIZ);
23    if (flag < 0) {
24      printf("Model B: No more input.\n");
25      break;
26    }
27
28    // Print received message
29    printf("Model B: %s\n", buf);
30
31    // Send output to output channel
32    // If there is an error, the flag will be negative
33    flag = cis_send(out_channel, buf, flag);
34    if (flag < 0) {
35      printf("Model B: Error sending output.\n");
36      break;
37    }
38
39  }
40  
41  return 0;
42}
43

Model YAML:

 1models:
 2  - name: c_modelA
 3    language: c
 4    args: ./src/backwards_modelA.c
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: c_modelB
 9    language: c
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt

CMake Version

Model Code:

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

Model YAML:

 1models:
 2  - name: cmake_modelA
 3    language: cmake
 4    args: ./src/backwards_modelA.cpp
 5    target: backwards_modelA
 6    inputs: inputA
 7    outputs: outputA
 8
 9  - name: cmake_modelB
10    language: cmake
11    args: ./src/backwards_modelB.cpp
12    target: backwards_modelB
13    inputs: inputB
14    outputs: outputB
15
16connections:
17  - input: outputA  # Connection between model A output & model B input
18    output: inputB
19  - input: ./Input/input.txt  # Connection between file and model A input
20    output: inputA
21  - input: outputB  # Connection between model B output and file
22    output: ./output.txt

C++ Version

Model Code:

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

Model YAML:

 1models:
 2  - name: cpp_modelA
 3    language: c++
 4    args: ./src/backwards_modelA.cpp
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: cpp_modelB
 9    language: c++
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt

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(yggchar_r) :: msg  ! Structure wrapping reallocatable string
 9  integer(kind=c_size_t), target :: msg_siz = 0
10
11  ! initialize input/output channels
12  in_channel = ygg_input("inputA")
13  out_channel = ygg_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_realloc(in_channel, &
22          [yggarg(msg), yggarg(msg_siz)])
23     if (.not.flag) then
24        print *, "Model A: No more input."
25        exit
26     end if
27
28     ! Print received message
29     print *, "Model A: ", msg%x
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, &
34          [yggarg(msg), yggarg(msg_siz)])
35     if (.not.flag) then
36        print *, "Model A: Error sending output."
37        exit
38     end if
39
40  end do
41
42end 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(yggchar_r) :: msg  ! Structure wrapping reallocatable string
 9  integer(kind=c_size_t), target :: msg_siz = 0
10
11  ! initialize input/output channels
12  in_channel = ygg_input("inputB")
13  out_channel = ygg_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_realloc(in_channel, &
22          [yggarg(msg), yggarg(msg_siz)])
23     if (.not.flag) then
24        print *, "Model B: No more input."
25        exit
26     end if
27
28     ! Print received message
29     print *, "Model B: ", msg%x
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, &
34          [yggarg(msg), yggarg(msg_siz)])
35     if (.not.flag) then
36        print *, "Model B: Error sending output."
37        exit
38     end if
39
40  end do
41
42end program main

Model YAML:

 1models:
 2  - name: fortran_modelA
 3    language: fortran
 4    args: ./src/backwards_modelA.f90
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: fortran_modelB
 9    language: fortran
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt

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, msg = in_channel.recv()
15    if (!flag)
16        println("Model A: No more input.")
17	break
18    end
19
20    # Print received message
21    @printf("Model A: %s", msg)
22
23    # Send output to output channel
24    # If there is an error, the flag will be false
25    flag = out_channel.send(msg)
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, msg = in_channel.recv()
15    if (!flag)
16        println("Model B: No more input.")
17	break
18    end
19
20    # Print received message
21    @printf("Model B: %s", msg)
22
23    # Send output to output channel
24    # If there is an error, the flag will be false
25    flag = out_channel.send(msg)
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/backwards_modelA.jl
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: julia_modelB
 9    language: julia
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt

Make Version

Model Code:

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

Model YAML:

 1models:
 2  - name: make_modelA
 3    language: make
 4    args: ./src/backwards_modelA.c
 5    target: backwards_modelA
 6    inputs: inputA
 7    outputs: outputA
 8
 9  - name: make_modelB
10    language: make
11    args: ./src/backwards_modelB.c
12    target: backwards_modelB
13    inputs: inputB
14    outputs: outputB
15
16connections:
17  - input: outputA  # Connection between model A output & model B input
18    output: inputB
19  - input: ./Input/input.txt  # Connection between file and model A input
20    output: inputA
21  - input: outputB  # Connection between model B output and file
22    output: ./output.txt

Matlab Version

Model Code:

 1% Initialize input/output channels 
 2in_channel = CisInterface('CisInput', 'inputA');
 3out_channel = CisInterface('CisOutput', '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, msg] = 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: %s\n', char(msg));
20
21  % Send output to output channel
22  % If there is an error, the flag will be False
23  flag = out_channel.send(msg);
24  if (~flag)
25    error('Model A: Error sending output.');
26    break;
27  end;
28  
29end;
 1% Initialize input/output channels 
 2in_channel = CisInterface('CisInput', 'inputB');
 3out_channel = CisInterface('CisOutput', '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, msg] = 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: %s\n', char(msg));
20
21  % Send output to output channel
22  % If there is an error, the flag will be False
23  flag = out_channel.send(msg);
24  if (~flag)
25    error('Model B: Error sending output.');
26    break;
27  end;
28  
29end;

Model YAML:

 1models:
 2  - name: matlab_modelA
 3    language: matlab
 4    args: ./src/backwards_modelA.m
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: matlab_modelB
 9    language: matlab
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt

Python Version

Model Code:

 1# Import classes for input/output channels
 2from yggdrasil.interface.CisInterface import CisInput, CisOutput
 3
 4# Initialize input/output channels
 5in_channel = CisInput('inputA')
 6out_channel = CisOutput('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, msg = 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' % msg)
20
21    # Send output to output channel
22    # If there is an error, the flag will be False
23    flag = out_channel.send(msg)
24    if not flag:
25        raise RuntimeError("Model A: Error sending output.")
 1# Import classes for input/output channels
 2from yggdrasil.interface.CisInterface import CisInput, CisOutput
 3
 4# Initialize input/output channels
 5in_channel = CisInput('inputB')
 6out_channel = CisOutput('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, msg = 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' % msg)
20
21    # Send output to output channel
22    # If there is an error, the flag will be False
23    flag = out_channel.send(msg)
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/backwards_modelA.py
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: python_modelB
 9    language: python
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt

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, msg) %<-% in_channel$recv()
14  if (!flag) {
15    print('Model A: No more input.')
16    break
17  }
18
19  # Print received message
20  fprintf('Model A: %s', msg)
21
22  # Send output to output channel
23  # If there is an error, the flag will be False
24  flag = out_channel$send(msg)
25  if (!flag) {
26    stop('Model A: Error sending output.')
27  }
28
29}
 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, msg) %<-% in_channel$recv()
14  if (!flag) {
15    print('Model B: No more input.')
16    break
17  }
18
19  # Print received message
20  fprintf('Model B: %s', msg)
21
22  # Send output to output channel
23  # If there is an error, the flag will be False
24  flag = out_channel$send(msg)
25  if (!flag) {
26    stop('Model B: Error sending output.')
27  }
28
29}

Model YAML:

 1models:
 2  - name: R_modelA
 3    language: R
 4    args: ./src/backwards_modelA.R
 5    inputs: inputA
 6    outputs: outputA
 7
 8  - name: R_modelB
 9    language: R
10    args: ./src/backwards_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  - input: outputB  # Connection between model B output and file
20    output: ./output.txt