diff --git a/Data_Storage.h b/Data_Storage.h index 9e5d34b..25b14be 100644 --- a/Data_Storage.h +++ b/Data_Storage.h @@ -20,28 +20,17 @@ * THE SOFTWARE. * * AUTHORS: Michael Schellenberger Costa: mschellenbergercosta@gmail.com - * - * Based on: A thalamocortical neural mass model of the EEG during NREM sleep and its response - * to auditory stimulation. - * M Schellenberger Costa, A Weigenand, H-VV Ngo, L Marshall, J Born, T Martinetz, - * JC Claussen. - * PLoS Computational Biology (in review). */ -/****************************************************************************************************/ -/* Functions for data storage */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Functions for data storage */ +/******************************************************************************/ #pragma once +#include #include "Thalamic_Column.h" -/****************************************************************************************************/ -/* Save data */ -/****************************************************************************************************/ -void get_data(int counter, Thalamic_Column& Col, double* Vt, double* Vr, double* ah) { - Vt [counter] = Col.Vt [0]; - Vr [counter] = Col.Vr [0]; - ah [counter] = Col.act_h (); +void get_data(unsigned counter, Thalamic_Column& Thalamus, std::vector pData) { + pData[0][counter] = Thalamus.Vt [0]; + pData[0][counter] = Thalamus.Vr [0]; + pData[0][counter] = Thalamus.act_h (); } -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ diff --git a/NM_Thalamus.pro b/NM_Thalamus.pro index f6c53f8..0e7cabf 100644 --- a/NM_Thalamus.pro +++ b/NM_Thalamus.pro @@ -6,14 +6,17 @@ CONFIG -= qt TARGET = Thalamus.cpp SOURCES += Thalamic_Column.cpp \ - Thalamus.cpp \ - Thalamus_mex.cpp + Thalamus.cpp \ + Thalamus_mex.cpp HEADERS += Data_Storage.h \ - ODE.h \ - Random_Stream.h \ - Thalamic_Column.h - -QMAKE_CXXFLAGS += -std=c++11 -O3 + ODE.h \ + Random_Stream.h \ + Thalamic_Column.h SOURCES -= Thalamus_mex.cpp + +QMAKE_CXXFLAGS += -std=c++11 +QMAKE_CXXFLAGS_RELEASE -= -O1 +QMAKE_CXXFLAGS_RELEASE -= -O2 +QMAKE_CXXFLAGS_RELEASE *= -O3 diff --git a/Random_Stream.h b/Random_Stream.h index f5fb19a..29d013e 100644 --- a/Random_Stream.h +++ b/Random_Stream.h @@ -23,58 +23,35 @@ * Stefanie Gareis: gareis@inb.uni-luebeck.de */ -/****************************************************************************************************/ -/* Random number streams */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Random number streams */ +/******************************************************************************/ #pragma once #include -/****************************************************************************************************/ -/* Struct for normal distribution */ -/****************************************************************************************************/ -struct random_stream_normal -{ - /* Random number engine: Mersenne-Twister */ +class random_stream_normal { +public: + explicit random_stream_normal(double mean, double stddev) + : mt(rand()), norm_dist(mean, stddev) {} + explicit random_stream_normal(double mean, double stddev, double seed) + : mt(seed), norm_dist(mean, stddev) {} + + double operator ()(void) { return norm_dist(mt); } +private: std::mt19937_64 mt; - /* Random number generator: Normal-distribution */ std::normal_distribution norm_dist; - - /* Constructors */ - random_stream_normal(){} - random_stream_normal(double mean, double stddev) - : mt(rand()) , norm_dist(mean, stddev) - {} - - /* Overwrites the function-call operator "( )" */ - double operator( )(void) { - return norm_dist(mt); - } }; -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ -/****************************************************************************************************/ -/* Struct for uniform int distribution */ -/****************************************************************************************************/ -struct random_stream_uniform_int -{ - /* Random number engine: Mersenne-Twister */ +class random_stream_uniform_int { +public: + explicit random_stream_uniform_int(int lower_bound, int upper_bound) + : mt(rand()), uniform_dist(lower_bound, upper_bound) {} + explicit random_stream_uniform_int(int lower_bound, int upper_bound, double seed) + : mt(seed), uniform_dist(lower_bound, upper_bound) {} + + double operator ()(void) { return uniform_dist(mt); } +private: std::mt19937_64 mt; - /* Random number generator: Uniform integer-distribution */ std::uniform_int_distribution<> uniform_dist; - - /* Constructors */ - random_stream_uniform_int(){} - random_stream_uniform_int(double lower_bound, double upper_bound) - : mt(rand()) , uniform_dist(lower_bound, upper_bound) - {} - - /* Overwrites the function-call operator "( )" */ - double operator( )(void) { - return uniform_dist(mt); - } }; -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ + diff --git a/Thalamic_Column.cpp b/Thalamic_Column.cpp index 29de11b..f9dd008 100644 --- a/Thalamic_Column.cpp +++ b/Thalamic_Column.cpp @@ -25,299 +25,228 @@ * to auditory stimulation. * M Schellenberger Costa, A Weigenand, H-VV Ngo, L Marshall, J Born, T Martinetz, * JC Claussen. - * PLoS Computational Biology (in review). + * PLoS Computational Biology http://dx.doi.org/10.1371/journal.pcbi.1005022 */ -/****************************************************************************************************/ -/* Functions of the thalamic module */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Functions of the thalamic module */ +/******************************************************************************/ #include "Thalamic_Column.h" -/****************************************************************************************************/ -/* Initialization of RNG */ -/****************************************************************************************************/ + +/******************************************************************************/ +/* Initialization of RNG */ +/******************************************************************************/ void Thalamic_Column::set_RNG(void) { - extern const double dt; - /* Number of independent random variables */ - int N = 1; - - /* Create RNG for each stream */ - for (int i=0; i #include -#include "Random_Stream.h" -using std::vector; - -/****************************************************************************************************/ -/* Macro for vector initialization */ -/****************************************************************************************************/ -#ifndef _INIT -#define _INIT(x) {x, 0.0, 0.0, 0.0, 0.0} -#endif -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ +#include "Random_Stream.h" -/****************************************************************************************************/ -/* Implementation of the thalamic module */ -/****************************************************************************************************/ class Thalamic_Column { public: - /* Constructors for compile check */ - Thalamic_Column(void) - {set_RNG();} - - /* Constructor for simulation */ - Thalamic_Column(double* Par) - : g_LK (Par[0]), g_h (Par[1]) - {set_RNG();} - - /* Iterate one time step through SRK4 */ - void iterate_ODE (void); - - /* Data storage access */ - friend void get_data (int, Thalamic_Column&, double*, double*, double*); + Thalamic_Column(double* Par) + : g_LK (Par[0]), g_h (Par[1]) {set_RNG();} + /* Iterate one time step through SRK4 */ + void iterate_ODE (void); private: - /* Declaration of private functions */ - /* Initialize the RNGs */ - void set_RNG (void); - - /* Firing rates */ - double get_Qt (int) const; - double get_Qr (int) const; - - /* Synaptic currents */ - double I_et (int) const; - double I_gt (int) const; - double I_er (int) const; - double I_gr (int) const; - - /* Activation functions */ - double m_inf_T_t (int) const; - double m_inf_T_r (int) const; - double m_inf_h (int) const; - double tau_m_h (int) const; - double P_h (int) const; - double act_h (void)const; - - /* Deactivation functions */ - double h_inf_T_t (int) const; - double h_inf_T_r (int) const; - double tau_h_T_t (int) const; - double tau_h_T_r (int) const; - - /* Currents */ - double I_L_t (int) const; - double I_L_r (int) const; - double I_LK_t (int) const; - double I_LK_r (int) const; - double I_T_t (int) const; - double I_T_r (int) const; - double I_h (int) const; - - /* Noise functions */ - double noise_xRK (int,int) const; - double noise_aRK (int) const; - - /* ODE functions */ - void set_RK (int); - void add_RK (void); - - /* Declaration and Initialization of parameters */ - /* Membrane time in ms */ - const double tau_t = 20.; - const double tau_r = 20.; - - /* Maximum firing rate in ms^-1 */ - const double Qt_max = 400.E-3; - const double Qr_max = 400.E-3; - - /* Sigmoid threshold in mV */ - const double theta_t = -58.5; - const double theta_r = -58.5; - - /* Sigmoid gain in mV */ - const double sigma_t = 6.; - const double sigma_r = 6.; - - /* Scaling parameter for sigmoidal mapping (dimensionless) */ - const double C1 = (M_PI/sqrt(3)); - - /* PSP rise time in ms^-1 */ - const double gamma_e = 70E-3; - const double gamma_g = 100E-3; - - /* Membrane capacitance in muF/cm^2 */ - const double C_m = 1.; - - /* Weights/ conductivities */ - /* Leak in aU */ - const double g_L = 1.; - - /* Synaptic conductivity in ms */ - const double g_AMPA = 1.; - const double g_GABA = 1.; - - /* Potassium leak current in mS/m^2 */ - double g_LK = 0.033; - - /* T current in mS/m^2 */ - const double g_T_t = 3; - const double g_T_r = 2.3; - - /* h current in mS/m^2 */ - double g_h = 0.02; - - /* Reversal potentials in mV */ - /* Synaptic */ - const double E_AMPA = 0.; - const double E_GABA = -70.; - - /* Leak */ - const double E_L_t = -70.; - const double E_L_r = -70.; - - /* Potassium */ - const double E_K = -100.; - - /* I_T current */ - const double E_Ca = 120.; - - /* I_h current */ - const double E_h = -40.; - - /* Calcium parameters */ - const double alpha_Ca = -51.8E-6; /* influx per spike in nmol */ - const double tau_Ca = 10.; /* calcium time constant in ms */ - const double Ca_0 = 2.4E-4; /* resting concentration */ - - /* I_h activation parameters */ - const double k1 = 2.5E7; - const double k2 = 4E-4; - const double k3 = 1E-1; - const double k4 = 1E-3; - const double n_P = 4.; - const double g_inc = 2.; - - /* Noise parameters in ms^-1 */ - const double mphi = 0E-3; - const double dphi = 0E-3; - double input = 0.0; - - /* Connectivities (dimensionless) */ - const double N_tr = 3.; - const double N_rt = 5.; - const double N_rr = 25.; - - /* Parameters for SRK4 iteration */ - const vector A = {0.5, 0.5, 1.0, 1.0}; - const vector B = {0.75, 0.75, 0.0, 0.0}; - - /* Random number generators */ - vector MTRands; - - /* Container for noise */ - vector Rand_vars; - - /* Population variables */ - vector Vt = _INIT(E_L_t), /* TC membrane voltage */ - Vr = _INIT(E_L_r), /* RE membrane voltage */ - Ca = _INIT(Ca_0), /* Calcium concentration of TC population */ - s_et = _INIT(0.0), /* PostSP from TC population to TC population */ - s_er = _INIT(0.0), /* PostSP from TC population to RE population */ - s_gt = _INIT(0.0), /* PostSP from RE population to TC population */ - s_gr = _INIT(0.0), /* PostSP from RE population to RE population */ - x_et = _INIT(0.0), /* derivative of s_et */ - x_er = _INIT(0.0), /* derivative of s_er */ - x_gt = _INIT(0.0), /* derivative of s_gt */ - x_gr = _INIT(0.0), /* derivative of s_gr */ - h_T_t = _INIT(0.0), /* inactivation of T channel */ - h_T_r = _INIT(0.0), /* inactivation of T channel */ - m_h = _INIT(0.0), /* activation of h channel */ - m_h2 = _INIT(0.0); /* activation of h channel bound with protein */ + /* Declaration of private functions */ + /* Initialize the RNGs */ + void set_RNG (void); + + /* Firing rates */ + double get_Qt (int) const; + double get_Qr (int) const; + + /* Synaptic currents */ + double I_et (int) const; + double I_gt (int) const; + double I_er (int) const; + double I_gr (int) const; + + /* Activation functions */ + double m_inf_T_t (int) const; + double m_inf_T_r (int) const; + double m_inf_h (int) const; + double tau_m_h (int) const; + double P_h (int) const; + double act_h (void)const; + + /* Deactivation functions */ + double h_inf_T_t (int) const; + double h_inf_T_r (int) const; + double tau_h_T_t (int) const; + double tau_h_T_r (int) const; + + /* Currents */ + double I_L_t (int) const; + double I_L_r (int) const; + double I_LK_t (int) const; + double I_LK_r (int) const; + double I_T_t (int) const; + double I_T_r (int) const; + double I_h (int) const; + + /* Noise functions */ + double noise_xRK (int,int) const; + double noise_aRK (int) const; + + /* ODE functions */ + void set_RK (int); + void add_RK (void); + + /* Helper functions */ + inline std::vector init (double value) + {return {value, 0.0, 0.0, 0.0, 0.0};} + + inline void add_RK (std::vector& var) + {var[0] = (-3*var[0] + 2*var[1] + 4*var[2] + 2*var[3] + var[4])/6;} + + inline void add_RK_noise (std::vector& var, unsigned noise) + {var[0] = (-3*var[0] + 2*var[1] + 4*var[2] + 2*var[3] + var[4])/6 + noise_aRK(noise);} + + /* Declaration and Initialization of parameters */ + /* Membrane time in ms */ + const double tau_t = 20.; + const double tau_r = 20.; + + /* Maximum firing rate in ms^-1 */ + const double Qt_max = 400.E-3; + const double Qr_max = 400.E-3; + + /* Sigmoid threshold in mV */ + const double theta_t = -58.5; + const double theta_r = -58.5; + + /* Sigmoid gain in mV */ + const double sigma_t = 6.; + const double sigma_r = 6.; + + /* Scaling parameter for sigmoidal mapping (dimensionless) */ + const double C1 = (M_PI/sqrt(3)); + + /* PSP rise time in ms^-1 */ + const double gamma_e = 70E-3; + const double gamma_g = 100E-3; + + /* Membrane capacitance in muF/cm^2 */ + const double C_m = 1.; + + /* Weights/ conductivities */ + /* Leak in aU */ + const double g_L = 1.; + + /* Synaptic conductivity in ms */ + const double g_AMPA = 1.; + const double g_GABA = 1.; + + /* Potassium leak current in mS/m^2 */ + double g_LK = 0.033; + + /* T current in mS/m^2 */ + const double g_T_t = 3; + const double g_T_r = 2.3; + + /* h current in mS/m^2 */ + double g_h = 0.02; + + /* Reversal potentials in mV */ + /* Synaptic */ + const double E_AMPA = 0.; + const double E_GABA = -70.; + + /* Leak */ + const double E_L_t = -70.; + const double E_L_r = -70.; + + /* Potassium */ + const double E_K = -100.; + + /* I_T current */ + const double E_Ca = 120.; + + /* I_h current */ + const double E_h = -40.; + + /* Calcium parameters */ + const double alpha_Ca = -51.8E-6; /* influx per spike in nmol */ + const double tau_Ca = 10.; /* calcium time constant in ms */ + const double Ca_0 = 2.4E-4; /* resting concentration */ + + /* I_h activation parameters */ + const double k1 = 2.5E7; + const double k2 = 4E-4; + const double k3 = 1E-1; + const double k4 = 1E-3; + const double n_P = 4.; + const double g_inc = 2.; + + /* Noise parameters in ms^-1 */ + const double mphi = 0E-3; + const double dphi = 0E-3; + double input = 0.0; + + /* Connectivities (dimensionless) */ + const double N_tr = 3.; + const double N_rt = 5.; + const double N_rr = 25.; + + /* Parameters for SRK4 iteration */ + const std::vector A = {0.5, 0.5, 1.0, 1.0}; + const std::vector B = {0.75, 0.75, 0.0, 0.0}; + + /* Random number generators */ + std::vector MTRands; + + /* Container for noise */ + std::vector Rand_vars; + + /* Population variables */ + std::vector Vt = init(E_L_t), /* TC membrane voltage */ + Vr = init(E_L_r), /* RE membrane voltage */ + Ca = init(Ca_0), /* Calcium concentration of TC population */ + s_et = init(0.0), /* PostSP from TC population to TC population */ + s_er = init(0.0), /* PostSP from TC population to RE population */ + s_gt = init(0.0), /* PostSP from RE population to TC population */ + s_gr = init(0.0), /* PostSP from RE population to RE population */ + x_et = init(0.0), /* derivative of s_et */ + x_er = init(0.0), /* derivative of s_er */ + x_gt = init(0.0), /* derivative of s_gt */ + x_gr = init(0.0), /* derivative of s_gr */ + h_T_t = init(0.0), /* inactivation of T channel */ + h_T_r = init(0.0), /* inactivation of T channel */ + m_h = init(0.0), /* activation of h channel */ + m_h2 = init(0.0); /* activation of h channel bound with protein */ + + /* Data storage access */ + friend void get_data (unsigned, Thalamic_Column&, std::vector); }; /****************************************************************************************************/ /* end */ diff --git a/Thalamus.cpp b/Thalamus.cpp index edec717..2ee9e3a 100644 --- a/Thalamus.cpp +++ b/Thalamus.cpp @@ -25,52 +25,46 @@ * to auditory stimulation. * M Schellenberger Costa, A Weigenand, H-VV Ngo, L Marshall, J Born, T Martinetz, * JC Claussen. - * PLoS Computational Biology (in review). + * PLoS Computational Biology http://dx.doi.org/10.1371/journal.pcbi.1005022 */ -/****************************************************************************************************/ -/* Main file for compilation tests */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Main file for compilation and runtime tests */ +/******************************************************************************/ #include #include + #include "Thalamic_Column.h" -/****************************************************************************************************/ -/* Fixed simulation settings */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Fixed simulation settings */ +/******************************************************************************/ typedef std::chrono::high_resolution_clock::time_point timer; -extern const int T = 30; /* Simulation length s */ -extern const int res = 1E4; /* number of iteration steps per s */ -extern const double dt = 1E3/res; /* duration of a timestep in ms */ -extern const double h = sqrt(dt); /* squareroot of dt for SRK iteration */ -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ - +extern const int T = 30; /* Time until data is stored in s */ +extern const int res = 1E4; /* Number of iteration steps per s */ +extern const double dt = 1E3/res; /* Duration of a time step in ms */ +extern const double h = sqrt(dt); /* Square root of dt for SRK iteration */ -/****************************************************************************************************/ -/* Main simulation routine */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Main simulation routine */ +/******************************************************************************/ int main(void) { - /* Initialize the populations */ - Thalamic_Column Thalamus = Thalamic_Column(); + std::vector param = {0.2, 0.06}; + Thalamic_Column Thalamus (param.data()); - /* Take the time of the simulation */ - timer start,end; + /* Take the time of the simulation */ + timer start,end; - /* Simulation */ - start = std::chrono::high_resolution_clock::now(); - for (int t=0; t< T*res; ++t) { - Thalamus.iterate_ODE(); - } - end = std::chrono::high_resolution_clock::now(); + /* Simulation */ + start = std::chrono::high_resolution_clock::now(); + for (unsigned t=0; t< T*res; ++t) { + Thalamus.iterate_ODE(); + } + end = std::chrono::high_resolution_clock::now(); - /* Time consumed by the simulation */ - double dif = 1E-3*std::chrono::duration_cast( end - start ).count(); - std::cout << "simulation done!\n"; - std::cout << "took " << dif << " seconds" << "\n"; - std::cout << "end\n"; + /* Time consumed by the simulation */ + double dif = 1E-3*std::chrono::duration_cast( end - start ).count(); + std::cout << "simulation done!\n"; + std::cout << "took " << dif << " seconds" << "\n"; + std::cout << "end\n"; } -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ diff --git a/Thalamus_mex.cpp b/Thalamus_mex.cpp index ad1ef58..218aa9c 100644 --- a/Thalamus_mex.cpp +++ b/Thalamus_mex.cpp @@ -28,86 +28,87 @@ * PLoS Computational Biology (in review). */ -/****************************************************************************************************/ -/* Implementation of the simulation as MATLAB routine (mex compiler) */ -/* mex command is given by: */ -/* mex CXXFLAGS="\$CXXFLAGS -std=c++11 -O3" Thalamus_mex.cpp Thalamic_Column.cpp */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Implementation of the simulation as MATLAB routine (mex compiler) */ +/* mex command is given by: */ +/* mex CXXFLAGS="\$CXXFLAGS -std=c++11 -O3" Thalamus_mex.cpp */ +/* Thalamic_Column.cpp */ +/******************************************************************************/ #include "mex.h" #include "matrix.h" + +#include +#include + #include "Data_Storage.h" -mxArray* SetMexArray(int N, int M); +#include "Thalamic_Column.h" +mxArray* GetMexArray(int N, int M); -/****************************************************************************************************/ -/* Fixed simulation settings */ -/****************************************************************************************************/ -extern const int onset = 15; /* time until data is stored in s */ -extern const int res = 1E3; /* number of iteration steps per s */ -extern const int red = res/100; /* number of iterations that is saved */ -extern const double dt = 1E3/res; /* duration of a timestep in ms */ -extern const double h = sqrt(dt); /* squareroot of dt for SRK iteration */ -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Fixed simulation settings */ +/******************************************************************************/ +extern const int onset = 20; /* Time until data is stored in s */ +extern const int res = 1E4; /* Number of iteration steps per s */ +extern const int red = 1E2; /* Number of iterations steps not saved */ +extern const double dt = 1E3/res; /* Duration of a time step in ms */ +extern const double h = sqrt(dt); /* Square root of dt for SRK iteration */ -/****************************************************************************************************/ -/* Simulation routine */ -/* lhs defines outputs */ -/* rhs defines inputs */ -/****************************************************************************************************/ +/******************************************************************************/ +/* Simulation routine */ +/* lhs defines outputs */ +/* rhs defines inputs */ +/******************************************************************************/ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { - /* Initialize the seeder */ - srand(time(NULL)); + /* Initialize the seeder */ + srand(time(NULL)); - /* Fetch inputs */ - const int T = (int) (mxGetScalar(prhs[0])); /* Duration of simulation in s */ - const int Time = (T+onset)*res; /* Total number of iteration steps */ - double* Param_Thalamus = mxGetPr (prhs[1]); /* Parameters of cortical module */ + /* Fetch inputs */ + const int T = (int) (mxGetScalar(prhs[0])); /* Duration of simulation in s */ + const int Time = (T+onset)*res; /* Total number of iteration steps */ + double* Param_Thalamus = mxGetPr (prhs[1]); /* Parameters of cortical module */ - /* Initialize the populations */ - Thalamic_Column Thalamus(Param_Thalamus); + /* Initialize the populations */ + Thalamic_Column Thalamus(Param_Thalamus); - /* Create data containers */ - mxArray* Vt = SetMexArray(1, T*res/red); - mxArray* Vr = SetMexArray(1, T*res/red); - mxArray* ah = SetMexArray(1, T*res/red); + /* Create data containers */ + std::vector dataArray; + dataArray.reserve(3); + dataArray.push_back(GetMexArray(1, T*res/red)); // Vt + dataArray.push_back(GetMexArray(1, T*res/red)); // Vr + dataArray.push_back(GetMexArray(1, T*res/red)); // act_h - /* Pointer to the actual data block */ - double* Pr_Vt = mxGetPr(Vt); - double* Pr_Vr = mxGetPr(Vr); - double* Pr_ah = mxGetPr(ah); + /* Pointer to the data blocks */ + std::vector dataPointer; + dataPointer.reserve(dataArray.size()); + for (auto &dataptr : dataArray) { + dataPointer.push_back(mxGetPr(dataptr)); + } - /* Simulation */ - int count = 0; - for (int t=0; t=onset*res && t%red==0){ - get_data(count, Thalamus, Pr_Vt, Pr_Vr, Pr_ah); - ++count; - } - } + /* Simulation */ + int count = 0; + for (unsigned t=0; t < Time; ++t) { + Thalamus.iterate_ODE(); + if(t >= onset*res && t%red == 0){ + get_data(count, Thalamus, dataPointer); + ++count; + } + } - /* Output of the simulation */ - plhs[0] = Vt; - plhs[1] = Vr; - plhs[2] = ah; -return; + /* Return the data containers */ + nlhs = dataArray.size()+1; + for (auto &dataptr : dataArray) { + plhs[std::distance(&dataptr, dataArray.data())] = dataptr; + } + return; } -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/ - -/****************************************************************************************************/ -/* Create MATLAB data container */ -/****************************************************************************************************/ -mxArray* SetMexArray(int N, int M) { - mxArray* Array = mxCreateDoubleMatrix(0, 0, mxREAL); - mxSetM(Array, N); - mxSetN(Array, M); - mxSetData(Array, mxMalloc(sizeof(double)*M*N)); - return Array; +/******************************************************************************/ +/* Create MATLAB data containers */ +/******************************************************************************/ +mxArray* GetMexArray(int N, int M) { + mxArray* Array = mxCreateDoubleMatrix(0, 0, mxREAL); + mxSetM(Array, N); + mxSetN(Array, M); + mxSetData(Array, mxMalloc(sizeof(double)*M*N)); + return Array; } -/****************************************************************************************************/ -/* end */ -/****************************************************************************************************/