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

#define M 10    /* No of Blocks */
#define N 10000    /* No of Iterations */

/* BLOCK VARIABLE NAMES */
#define Oscilator_time_OUT1 RESULT[0]
#define Oscilator_time_relative RESULT[1]
#define Oscilator_sin1_OUT1 RESULT[2]
#define Oscilator_sin2_OUT1 RESULT[3]
#define Oscilator_cos1_OUT1 RESULT[4]
#define Oscilator_cos2_OUT1 RESULT[5]
#define Oscilator_prod1_OUT1 RESULT[6]
#define Oscilator_prod2_OUT1 RESULT[7]
#define Oscilator_sum_OUT1 RESULT[8]
#define Oscilator_y RESULT[9]

double RESULT[M][N];

/* EQUATIONS */
void _eq_init(const double time, const double delta) {
    Oscilator_time_OUT1[0] = time;
    Oscilator_sin1_OUT1[0] = sin(Oscilator_time_OUT1[0]);
    Oscilator_cos1_OUT1[0] = cos(Oscilator_time_OUT1[0]);
    Oscilator_prod1_OUT1[0] = (Oscilator_cos1_OUT1[0]) * (Oscilator_time_OUT1[0]);
    Oscilator_sin2_OUT1[0] = sin(Oscilator_prod1_OUT1[0]);
    Oscilator_prod2_OUT1[0] = (Oscilator_time_OUT1[0]) * (Oscilator_sin1_OUT1[0]);
    Oscilator_cos2_OUT1[0] = cos(Oscilator_prod2_OUT1[0]);
    Oscilator_sum_OUT1[0] = (Oscilator_sin2_OUT1[0]) + (Oscilator_cos2_OUT1[0]);
    Oscilator_y[0] = Oscilator_sum_OUT1[0];
}

void _eq_iter(const unsigned int i, const double time, const double delta) {
    Oscilator_time_OUT1[i] = time;
    Oscilator_sin1_OUT1[i] = sin(Oscilator_time_OUT1[i]);
    Oscilator_cos1_OUT1[i] = cos(Oscilator_time_OUT1[i]);
    Oscilator_prod1_OUT1[i] = (Oscilator_cos1_OUT1[i]) * (Oscilator_time_OUT1[i]);
    Oscilator_sin2_OUT1[i] = sin(Oscilator_prod1_OUT1[i]);
    Oscilator_prod2_OUT1[i] = (Oscilator_time_OUT1[i]) * (Oscilator_sin1_OUT1[i]);
    Oscilator_cos2_OUT1[i] = cos(Oscilator_prod2_OUT1[i]);
    Oscilator_sum_OUT1[i] = (Oscilator_sin2_OUT1[i]) + (Oscilator_cos2_OUT1[i]);
    Oscilator_y[i] = Oscilator_sum_OUT1[i];
}

/* SIMULATOR */
int main(int argc, char *args[]) {
    double delta = 0.1;
    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", "Oscilator_time_OUT1", Oscilator_time_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_time_relative", Oscilator_time_relative[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_sin1_OUT1", Oscilator_sin1_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_sin2_OUT1", Oscilator_sin2_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_cos1_OUT1", Oscilator_cos1_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_cos2_OUT1", Oscilator_cos2_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_prod1_OUT1", Oscilator_prod1_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_prod2_OUT1", Oscilator_prod2_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_sum_OUT1", Oscilator_sum_OUT1[N - 1]);
    printf("\t%-20s = %12.4f\n", "Oscilator_y", Oscilator_y[N - 1]);
}