1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include<stdio.h>
#include "libdavid.h" //include the library with the algorithm method
void display(const mxArray* in, double* tab);
double* CreerTableau(size_t N);
int main()
{
mxArray *in1, *in2, *in3, *in4, *in5; /* Define input parameters
mxArray *out = NULL;/* and output parameters to be passed to the library functions */
float x;
double* tab1;
double N=25; //number of points
double data1[] = {1,2}; //we get the row vector with the lower parameter boundaries, size[Pdim,1]
double data2[] = {10,20}; //we get the row vector with the upper parameter boundaries, size[Pdim,1]
double data3[] = {2}; //Dimension of the parameter space, Pdim, size[1,1]
tab1 = CreerTableau(N);
if( !mclInitializeApplication(NULL,0) )
{
fprintf(stderr, "Could not initialize the application.\n");
return -1;
}
in1 = mxCreateDoubleMatrix(1,2,mxREAL); //The desired number of rows, The desired number of columns,Specify either mxREAL or mxCOMPLEX.
in2 = mxCreateDoubleMatrix(1,2,mxREAL);
in3 = mxCreateDoubleMatrix(1,1,mxREAL);
memcpy(mxGetPr(in1), data1, 2*sizeof(double)); //on copie ds la partie reelle de tous les elements de in1 le double data1
memcpy(mxGetPr(in2), data2, 2*sizeof(double)); //mxGetPr return The address of the first element of the real data
memcpy(mxGetPr(in3), data3, 1*sizeof(double));
/* Call the library intialization routine and make sure that the
* library was initialized properly. */
if (!libdavidInitialize()){
fprintf(stderr,"Could not initialize the library.\n");
return -2;
}
else
{
/* Call the library function */
mlfInitdoe(1, &out, in3, in1, in2);
printf("we have %d points to evaluate \n", mxGetNumberOfElements(out)/2);
/* Display the return value of the library function */
printf("the points to evaluate are :\n");
display(out, tab1);
for(i1=0; i1<N; i1++)
{
printf("the point %d to evaluate has for cordinate : %lf %lf \n",i1, tab1[i1], tab1[i1+N]);
printf("\n");
}
printf(" \n ");
mxDestroyArray(out); out=0;
printf("End Program : ");
scanf("%f", &x);
libdavidTerminate();
mxDestroyArray(in1); in1 = 0;
mxDestroyArray(in2); in2 = 0;
mxDestroyArray(in3); in3 = 0;
}
mclTerminateApplication();
return 0;
}
void display(const mxArray* in, double* tab)
{
int i=0, j=0; /* loop index variables */
int r=0, c=0; /* variables to store the row and column length of the matrix */
int k=0;
double *data; /* variable to point to the double data stored within the mxArray */
//double array [taille];
/* Get the size of the matrix */
r = mxGetM(in); //number of rows
c = mxGetN(in); //number of columns
/* Get a pointer to the double data in mxArray */
data = mxGetPr(in); //Get real data elements in mxArray
/* Loop through the data and display the same in matrix format */
for( i = 0; i < r; i++ )
{
printf("%d ",i);
for( j = 0; j < c; j++){
//printf(" %04.2f\t",data[i*c+j]);
k=2*i+j;
tab[k] = data[i*c+j];
printf(" number %d : %lf \n",k,tab[k]);
//add the way to keep each data to can reuse it and evaluate it
}
printf("\n");
}
printf("\n");
};
double* CreerTableau(size_t N)
{
double* tab = malloc(N* sizeof *tab);
return tab;
} |
Partager