- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

# D:/Basile/VisualCppProjects/hydroMEX3/hydroMEX3/hydro_source/return_mex_arguments.cpp

Go to the documentation of this file.

    00001
    00009 #include <vector>
    00010
    00011 #include "Datas.h"
    00012 #include "return_mex_arguments.h"
    00013
    00014 #include "../CVODEincludes.h"  // ODE solver includes
    00015
    00016 using namespace std;
    00017
    00018
    00019 #ifndef PI_DEF
    00020 #define pi 3.141592653589793
    00021 #define PI 3.141592653589793
    00022 #endif
    00023
    00024 #define Ith(v,i)    NV_Ith_S(v,i)       /* Ith numbers components 1..NEQ */
    00025
    00026
    00027
    00028
    00029  vector <double> sout00;
    00030  vector <double> sout01;
    00031  vector <double> sout02;
    00032  vector <double> sout03;
    00033  vector <double> sout04;
    00034  vector <double> sout05;
    00035  vector <double> sout06;
    00036  vector <double> sout07;
    00037  vector <double> sout08;
    00038  vector <double> sout09;
    00039  vector <double> sout10;
    00040  vector <double> sout11;
    00041  vector <double> timev;
    00042
    00043 void store_state(double time, N_Vector state_at_t)
    00044 {
    00045         sout00.push_back(Ith(state_at_t,0));
    00046         sout01.push_back(Ith(state_at_t,1));
    00047         sout02.push_back(Ith(state_at_t,2));
    00048         sout03.push_back(Ith(state_at_t,3));
    00049         sout04.push_back(Ith(state_at_t,4));
    00050         sout05.push_back(Ith(state_at_t,5));
    00051         sout06.push_back(Ith(state_at_t,6));
    00052         sout07.push_back(Ith(state_at_t,7));
    00053         sout08.push_back(Ith(state_at_t,8));
    00054         sout09.push_back(Ith(state_at_t,9));
    00055         sout10.push_back(Ith(state_at_t,10));
    00056         sout11.push_back(Ith(state_at_t,11));
    00057         timev.push_back(time);
    00058 }
    00059
    00060 void return_args(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], ODE_data *f_dat)
    00061 {
    00062         double *outArray;
    00063         double *outTime;
    00064         double *numStep;
    00065         long n, m, N, M;
    00066
    00067         N=12;
    00068         M=sout00.size();
    00069
    00070         if (nlhs>0)
    00071         {
    00072                 plhs[0] = mxCreateDoubleMatrix(N, M, mxREAL);
    00073                 outArray = mxGetPr(plhs[0]);
    00074                 for (m=M-1; m>=0; m--)
    00075                 {
    00076                         outArray[m*N+0] = sout00.back(); sout00.pop_back();
    00077                         outArray[m*N+1] = sout01.back(); sout01.pop_back();
    00078                         outArray[m*N+2] = sout02.back(); sout02.pop_back();
    00079                         outArray[m*N+3] = sout03.back(); sout03.pop_back();
    00080                         outArray[m*N+4] = sout04.back(); sout04.pop_back();
    00081                         outArray[m*N+5] = sout05.back(); sout05.pop_back();
    00082                         outArray[m*N+6] = sout06.back(); sout06.pop_back();
    00083                         outArray[m*N+7] = sout07.back(); sout07.pop_back();
    00084                         outArray[m*N+8] = sout08.back(); sout08.pop_back();
    00085                         outArray[m*N+9] = sout09.back(); sout09.pop_back();
    00086                         outArray[m*N+10]= sout10.back(); sout10.pop_back();
    00087                         outArray[m*N+11]= sout11.back(); sout11.pop_back();
    00088                 }
    00089         }
    00090         if (nlhs>1)
    00091         {
    00092                 plhs[1] = mxCreateDoubleMatrix(1, M, mxREAL);
    00093                 outTime = mxGetPr(plhs[1]);
    00094                 for (m=M-1; m>=0; m--)
    00095                 {
    00096                         outTime[m] = timev.back(); timev.pop_back();
    00097                 }
    00098         }
    00099         if (nlhs>2)
    00100         {
    00101                 plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
    00102                 numStep = mxGetPr(plhs[2]);
    00103                 numStep[0]=f_dat->CumulNumOfSteps;
    00104         }
    00105 }
    00106