WG: [Coin-ipopt] Matlab interface

Andreas Waechter andreasw at watson.ibm.com
Mon Jun 20 11:18:06 EDT 2005


At some earlier point, a colleague had written a MEX interface for Ipopt
(years back...) and we ran into the same problem.

If I remember correctly, the problem is that under Windows the MEX
"executable" cannot write to standard output directly.  Instead some
Matlab-provided function must be used (something like mexPrintf?).

Because of those problems, all output of Ipopt to standard out is directed
through the subroutine "C_OUT" (see COIN/Ipopt/IPOPT/ipopt/c_out.f).  In
principle, the only change necessary to fix the problem you describe, all
that has to be done is to replace the line containing "WRITE(*,8000)" by
some appropriate call to a Matlab function.

Since mexPrintf expects a C-style string, this probably has to go through
a C-wrapper function, i.e., instead of those "WRITE(*,8000)" statement a C
function is called that then transfers the Fortran-style string (without
'\0') to a C-style string (adding '\n\0' at the end, after copying!!!) and
then calling mexPrintf from C.  Here, the lines with WRITE(*,8000) only in
them (no LINES argument) are responsible for printing empty lines.

I hope that all output to files is still working, so that it is really
only C_OUT that has to be adapted.


On Mon, 20 Jun 2005 jens.pettersson at se.abb.com wrote:

> Hi Steinar,
>  to cut a long story short:
> I managed to compile and create a mex-Dll using MSVC .NET and your files.
> It is also possible to call this dll from Matlab but for some reasons it
> crashes in the Ipopt-dll.
> I debugged to find the error and it seams that the crash occurs when the
> first "write" commando is excecuted. I tested by manually comment away the
> write commando whcih caused the latest crash but then it only crashed on
> the next one, etc.
> Is there any one who knows why the seemingly inocent write- comando in
> Fortran does not work with mex-files??
> Also, I mean that the code is full with "write":s so there is not point in
> commenting away all af them.... ??
> //Jens

More information about the Coin-ipopt mailing list