help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] lib_set_print_hook and R interface question


From: Jeff D. Hamann
Subject: [Help-glpk] lib_set_print_hook and R interface question
Date: Tue, 2 Nov 2004 11:24:17 -0800 (PST)
User-agent: SquirrelMail/1.4.0

glpk-group,

I've been working on creating an R interface for the glpk libraries and
would like your advice on a few technical issues. I need to set the
internal message interfaces (printing error messages, solutions, etc) to
the appropriate stream in R (using Rprintf, REprintf, etc. ) and don't
know if it's possible to simply assign the files to stdout, stderr, etc.
or create wrapper functions


   /* set the i/o functions to the same location as the r functions */

   I found these functions in the glplib.h header file and


   void print(char *fmt, ...);
/* print informative message */

   void lib_set_print_hook(void *info, int (*hook)(void *info, char
*msg));
/* install print hook routine */

   void fault(char *fmt, ...);
/* print error message and terminate program execution */

   void lib_set_fault_hook(void *info, int (*hook)(void *info, char
*msg));
/* install fault hook routine */


The printing functions in R are wrappers for fprintf, etc,

Rprintf
REprintf

and I'm trying to figure out how to interface the glpk printing
functions to the R printing functions using the functions listed
above. Since I'm not very familiar with all of the glpk functions, I might
have just enough skill to be dangerous and I thought I should consult the
author before diving into the project.

The function I'm trying to use is,

-- #include "glplib.h"
-- void lib_set_print_hook(void *info, int (*hook)(void *info,
--    char *msg));
--
-- *Description*
--
-- The routine lib_set_print_hook installs the user-defined print hook --
routine.
--
-- The parameter info is a transit pointer passed to the hook routine. --
-- The parameter hook is an entry point to the user-defined print hook --
routine. This routine is called by the routine print every time when -- an
informative message should be output. The routine print passes to -- the
hook routine the transit pointer info and the character string -- msg,
which contains the message. If the hook routine returns zero, -- the
routine print prints the message in an usual way. Otherwise, if -- the
hook routine returns non-zero, the message is not printed.
--
-- In order to uninstall the hook routine the parameter hook should be --
specified as NULL (in this case the parameter info is ignored). */

void lib_set_print_hook(void *info, int (*hook)(void *info, char *msg)) { 
   LIBENV *env = lib_env_ptr();
      env->print_info = info;
      env->print_hook = hook;
      return;
}

Since I'm assuming the Rprintf function can't simply be passed as the hook
argument, I'm guessing I'll have to create a set of wrapper
functions. Also, I cannot figure out from the source code, what the into
argument is supposed to be.

lib_set_print_hook(???, Rprintf );

Thanks,
Jeff.

-- 
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon 97339-1421
phone 541-754-1428
fax 541-752-0288
address@hidden
http://www.forestinformatics.com







reply via email to

[Prev in Thread] Current Thread [Next in Thread]