ILOG CPLEX 11.0 User's Manual > Programming Considerations > Managing Input and Output > Controlling Message Channels > Example: Callable Library Message Channels |
Example: Callable Library Message Channels |
INDEX PREVIOUS NEXT |
This example shows you how to use the ILOG CPLEX message handler from the Callable Library. It captures all messages generated by ILOG CPLEX and displays them on screen along with a label indicating which channel sent the message. It also creates a user channel to receive output generated by the program itself. The user channel accepts user-generated messages, displays them on screen with a label, and records them in a file without the label.
The complete program lpex5.c
appears online in the standard distribution at yourCPLEXinstallation/examples/src
. This example derives from lpex1.c
, a program in the ILOG CPLEX Getting Started manual. There are a few differences between the two examples:
ourmsgfunc
(rather than the C functions printf
or fprintf(stderr, . . .)
) manages all output. The program itself or CPXmsg
from the ILOG CPLEX Callable Library calls ourmsgfunc
. In fact, CPXmsg
is a replacement for printf
, allowing a message to appear in more than one place, for example, both on screen and in a file.
CPXopenCPLEX
can you call CPXmsg
. And only after you call CPXgetchannels
can you use the default ILOG CPLEX channels. Therefore, calls to ourmsgfunc
print directly any messages that occur before the program gets the address of cpxerror
(a channel). After a call to CPXgetchannels
gets the address of cpxerror
, and after a call to CPXaddfuncdest
associates the message function ourmsgfunc
with cpxerror
, then error messages are generated by calls to CPXmsg
.
TERMINATE:
label, any error must be generated with care in case the error message function has not been set up properly. Thus, ourmsgfunc
is also called directly to generate any error messages there.
CPXaddchannel
initializes the channel ourchannel
. The Callable Library routine fopen
opens the file lpex5.out
to accept solution information. A call to the ILOG CPLEX Callable Library routine CPXaddfpdest
associates that file with that channel. Solution information is also displayed on screen since ourmsgfunc
is associated with that new channel, too. Thus in the loops near the end of main
, when the solution is printed, only one call to CPXmsg
suffices to put the output both on screen and into the file. A call to CPXdelchannel
deletes ourchannel
.
CPXcloseCPLEX
will automatically delete file- and function-destinations for channels, it is a good practice to call CPXdelfpdest
and CPXdelfuncdest
at the end of your programs.
Copyright © 1987-2007 ILOG S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |