Hello,<br><br>Matlab offers the possibility to compile C programs and use them as matlab functions. This is called Mex files and works almost like making a dll. I used Visual Studio 2005 Pro and FWTools 1.2.1 in order to be able to use GDAL inside Matlab.
<br><br>The simple C program I made is below and just take a string in input and returns 1.<br><br>---------------------------------Start Code-----------------------------------------<br>#include "gdal_priv.h"<br>
#include "mex.h"<br><br>void mexFunction(int nlhs, mxArray *plhs[],<br> int nrhs, const mxArray *prhs[])<br>{<br><br> double *y;<br> char *pszFilename;<br> int bufLen;<br> int status;
<br><br> /* Create a 1-by-1 matrix for the return argument. */<br> plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);<br><br> /* Input must be a string. */<br> if (mxIsChar(prhs[0]) != 1)<br> mexErrMsgTxt("Input must be a string.");
<br><br> /* Input must be a row vector. */<br> if (mxGetM(prhs[0]) != 1)<br> mexErrMsgTxt("Input must be a row vector");<br><br> /* Get the length of the input string. */<br> bufLen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
<br><br> /* Allocate memory for input string. */<br> pszFilename = (char *) mxCalloc(bufLen, sizeof(char));<br><br> /* Copy string data from prhs[0] into a C string inputBuf. */<br> status = mxGetString(prhs[0], pszFilename, bufLen);
<br> if (status != 0)<br> mexWarnMsgTxt("Not enough space. String is truncated.");<br><br> /*GDALDataset *poDataset;<br><br> GDALAllRegister();*/<br><br> /*poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
<br> if( poDataset == NULL ) {<br> } else {<br> mexWarnMsgTxt("Could not open dataset.");<br> }*/<br><br> /* Assign a pointer to the output. */<br> y = mxGetPr(plhs[0]);<br><br> *y = 1.0
;<br>}<br>--------------------------------------------End Code-------------------------------------<br><br>Without #include "gdal_priv.h" everything is fine, but with there is a problem of dependency (Matlab cannot find some library) althought all gdal (all found in FWTools\bin) dlls are in path (checked with depends walker).
<br>Discussion with Matlab support identified the problem in "gdal_priv.h" line 56 #include <vector>. AFAIK, <vector> is a STL standard C++ library.<br>Did I missed something ? linking with some special library ?
<br><br>Thanks for your help.<br>Guillaume.<br>