#include <iostream>
#include <cstring>
#include "code_Peaks_2017.h"

int main()
{
    const long values = 10000;
    int i, choice;
    TD2Hdl     X = nullptr, Y   = nullptr;
    TD3Hdl     Parameters       = nullptr;
    std::string parameterNames[] = {"shape", "center", "amplitude",
                                    "surface", "half width at half maximum",
                                    "collisional half width at half maximum",
                                    "d0", "w2", "d2", "eta", "nuVC", "beta",
                                    "vMP", "sample", "center-in"};

    X = (TD2Hdl)malloc(sizeof(TD2*)), Y = (TD2Hdl)malloc(sizeof(TD2*));
    X[0] = (TD2*)malloc(sizeof(TD2) + (values-1) * sizeof(double)); //allocate a structure and some memory on top for the array
    Y[0] = (TD2*)malloc(sizeof(TD2) + (values-1) * sizeof(double));
    X[0]->dimSize = values;

    for (i = 0; i < values; ++i) {
        X[0]->elt[i] = i;
        Y[0]->elt[i] = 0;
    }


    Parameters = (TD3Hdl)malloc(sizeof(TD3*));
    Parameters[0] = (TD3*)malloc(sizeof(TD3) + 14 * sizeof(double));
    Parameters[0]->dimSizes[0] = 1;
    Parameters[0]->dimSizes[1] = 15;
    memset(Parameters[0]->elt, 0, 15 * sizeof(double));

    for (i = 0; i < 15; ++i) {
      //std::cout << "Please assign the value of the " << parameterNames[i] << " parameter: ";
        std::cin >> Parameters[0]->elt[i];
    }

    //std::cout << "Choose the method of computation (1 - GPU, 0 - CPU): ";
    std::cin >> choice;

    if (choice == 0) Peaks(0,&X,&Y,&Parameters);
    else PeaksGPU(0, &X, &Y, &Parameters);


    // for (i = 0; i < values; ++i) {
    //std::cout<<"Y[" <<i <<"] = " <<Y[0]->elt[i] <<std::endl;
    // }

    free(X[0]);
    free(X);
    free(Y[0]);
    free(Y);
    free(Parameters[0]);
    free(Parameters);
    return 0;
}
