/**
 *  Generated from the Python CBD Simulator
 *  In order to compile:
 *      gcc example.c lsolve.c -lm
 */

#include <math.h>
#include <stdio.h>
#include <time.h>
#include "lsolve.h"

#define M 14    /* No of Blocks */
#define N 100    /* No of Iterations */

/* BLOCK VARIABLE NAMES */
#define test_sum_OUT1 RESULT[0]
#define test_sum_IN1 RESULT[1]
#define test_sum_IN2 RESULT[2]
#define test_three_OUT1 RESULT[3]
#define test_seven_OUT1 RESULT[4]
#define test_mult_OUT1 RESULT[5]
#define test_mult_IN1 RESULT[6]
#define test_mult_IN2 RESULT[7]
#define test_x RESULT[8]
#define test_x_OUT1 RESULT[9]
#define test_x_IN1 RESULT[10]
#define test_y RESULT[11]
#define test_y_OUT1 RESULT[12]
#define test_y_IN1 RESULT[13]

double RESULT[M][N];

/* EQUATIONS */
void _eq_init(const double time, const double delta) {
    test_three_OUT1[0] = 3.0;
    test_seven_OUT1[0] = 7;
    test_sum_IN1[0] = test_three_OUT1[0];
    test_mult_IN1[0] = test_seven_OUT1[0];

    /* Algebraic Loop */
    double _C4[2][3] = {{ -1.000000, 1 * test_mult_IN1[0] + 0, 0.000000 }, { 1.000000, -1.000000, 0 - test_sum_IN1[0] }};
    agloop(&_C4, 2, &test_sum_OUT1[0], &test_mult_OUT1[0]);

    test_sum_IN2[0] = test_mult_OUT1[0];
    test_mult_IN2[0] = test_sum_OUT1[0];
    test_x_IN1[0] = test_sum_OUT1[0];
    test_x_OUT1[0] = test_x_IN1[0];
    test_x[0] = test_x_OUT1[0];
    test_y_IN1[0] = test_mult_OUT1[0];
    test_y_OUT1[0] = test_y_IN1[0];
    test_y[0] = test_y_OUT1[0];
}

void _eq_iter(const unsigned int i, const double time, const double delta) {
    test_three_OUT1[i] = 3.0;
    test_seven_OUT1[i] = 7;
    test_sum_IN1[i] = test_three_OUT1[i];
    test_mult_IN1[i] = test_seven_OUT1[i];

    /* Algebraic Loop */
    double _C4[2][3] = {{ -1.000000, 1 * test_mult_IN1[i] + 0, 0.000000 }, { 1.000000, -1.000000, 0 - test_sum_IN1[i] }};
    agloop(&_C4, 2, &test_sum_OUT1[i], &test_mult_OUT1[i]);

    test_sum_IN2[i] = test_mult_OUT1[i];
    test_mult_IN2[i] = test_sum_OUT1[i];
    test_x_IN1[i] = test_sum_OUT1[i];
    test_x_OUT1[i] = test_x_IN1[i];
    test_x[i] = test_x_OUT1[i];
    test_y_IN1[i] = test_mult_OUT1[i];
    test_y_OUT1[i] = test_y_IN1[i];
    test_y[i] = test_y_OUT1[i];
}

/* SIMULATOR */
int main(int argc, char *args[]) {
    double delta = 1.0;
    double time = 0.0;

    _eq_init(0.0, delta);
    for(int i = 1; i < N; ++i) {
        time += delta;
        _eq_iter(i, time, delta);
    }

    printf("\t%-20s = %12.4f\n", "TIME", time);
    printf("\t%-20s = %12.4f\n", "test_sum_OUT1", test_sum_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_sum_IN1", test_sum_IN1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_sum_IN2", test_sum_IN2[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_three_OUT1", test_three_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_seven_OUT1", test_seven_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_mult_OUT1", test_mult_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_mult_IN1", test_mult_IN1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_mult_IN2", test_mult_IN2[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_x", test_x[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_x_OUT1", test_x_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_x_IN1", test_x_IN1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_y", test_y[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_y_OUT1", test_y_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "test_y_IN1", test_y_IN1[N - 1]);
}