Note: The gdxmrw utilities have been developed by Steven P. Dirkse (GAMS Development) and Michael C. Ferris (University of Wisconsin Madiscon
A common question goes along the lines of “How can I construct an interface between GAMS and Matlab?” The answer to that depends on the situation, but one general guideline I offer is to break the process into smaller steps by using rgdx and wgdx to move the data around and only use the gams call to run the model, not to pass data to or from GAMS. This offers a number of advantages:
This problem and its solution are discussed in a recent Matlab help forum article. I have this problem on my Windows 7 desktop machine, and I could solve it by saving the pathdef.m file to the Matlab start directory C:\Users\sdirkse\Documents\MATLAB. There are a couple of problems with this fix though: it is specific to how Matlab is started (desktop shortcuts can specify different start directories) and it doesn't maintain a separate pathdef.m file for different Matlab versions. In spite of these problems, you should ensure that your Matlab system starts with the GAMS system directory in the Matlab Path. The GDXMRW utilities will not function if the GAMS system directory is not in the Matlab Path, and setting this manually at the start of each session is annoying and easy to forget.
I run Matlab on a machine where I have no root privileges so updating the system-wide
pathdef.m is not possible. However, Matlab checks the MATLABPATH environment variable on startup and prepends that to its search path, so setting this in your
.bashrc or similar startup file should have the desired affect. For example, I have something like this:
oxon$grep MAT .bashrc export MATLABPATH=/usr/local/gams/23.7.2:/home/steve/comp-pak/src/interfaces/Matlab oxon$echo $MATLABPATH /usr/local/gams/23.7.2:/home/steve/comp-pak/src/interfaces/Matlab
The full text of the error message is:
last error message: Undefined function or method 'gams' for input arguments of type 'char'. last error identifier: MATLAB:UndefinedFunction See testinst log file testinstlog.txt for details ??? Error using ==> testinst at 127 Error in testinst: terminating prematurely
and the file testinstlog.txt reads something like:
Date = 15-Jul-2011 Matlab version = 184.108.40.2065 (R2011a) Error in testinst: terminating prematurely last error message: Undefined function or method 'gams' for input arguments of type 'char'. last error identifier: MATLAB:UndefinedFunction
The error message indicates that you did not set the path to GAMS in Matlab or that you run an old GAMS version which does not include gams.m and the mex library files.
Matlab fails to load binary MEX-files if it cannot find all .dll files referenced by the MEX-file. Thus the message above is somewhat misleading: it gives the impression that the specified Mex-file is invalid or not found, instead of pointing out the missing dependencies. More information on this error, including suggested fixes, can be found on the Matlab Web site here.
We have found that users getting this error message are sometimes missing the Microsoft Visual C++ Redistributable runtime libraries. These can be installed via Windows Update. Note that many versions of these libraries are available. The version of the Microsoft Visual C++ Redistributable that is required depends on what version of MSVC++ was used to build the MEX-file. Most likely, the 2012 or 2013 version is the one needed, and it is safe to install both of them.
If you must, you can peek into the MEX-files for the string MSVCR to learn more. A dependency on MSVCR110.dll is satisfied by the Microsoft Visual C++ 2012 Redistributable. A dependency on MSVCR120.dll is satisfied by the Microsoft Visual C++ 2013 Redistributable. At this time (Jan 2017) we don't use newer compilers, and nothing older can be actively supported.