[Coin-lpsolver] Fortran/CLP interface help

Matthew Saltzman mjs at exchange.clemson.edu
Sun Nov 18 15:28:29 EST 2007


On Fri, 2007-11-16 at 15:37 -0600, Jose Luis Ceciliano Meza wrote:
> Hi all,
>  
> I tried to post my question before, but something happened because my
> message is not shown on the subject file. I would to ask your help
> again on using CLP from Fortran.

Jose-

The C interface that JP referred to in the earlier thread is still your
best hope.  But you will need to write more wrappers or (probably
better) modify that interface to a "native" FORTRAN interface, which
would save a level of wrapper functions.

C and FORTRAN 77 (at least) have compatible calling sequences in many
compilers, as long as several rules are followed.

First, FORTRAN calls everything by reference.  C calls everything by
value, except that an array parameter is converted to a pointer to its
first element.  That means functions that have any non-array value
parameters will have to be wrapped again with functions that get the
addresses of those arguments instead.  For example:
        
        int original_function(int x)
        {
           ...
        }
        
        int new_wrapper(int *x)
        {
           return original_function(*x);
        }

Then you can call new_wrapper() from FORTRAN.

Second, FORTRAN strings are not simply null-terminated arrays of
characters as they are in C.  There is additional information associated
with FORTRAN strings (the length) that gets passed as hidden parameters
(i.e., you don't write them as part of your FORTRAN source, but they are
added automatically by the compiler), and there is no null-termination
requirement.  This means that any C function that has a char* parameter
must be wrapped again by a C function that receives the appropriate
magic calling sequence and converts the FORTRAN strings to C strings.
Unfortunately, there is no standard for the magic calling sequence.  The
technical documentation for Visual FORTRAN should describe how to to
construct the appropriate C calling sequences for that compiler.  (I
don't have access to Visual FORTRAN.  Alternatively, you could go with a
gcc-based compiler.  The interfaces there are pretty well documented.)

There is a similar issue for passing file descriptors.

Hope that helps.  If you do choose to write the FORTRAN interface, I
think that would be a useful contribution to the project (though I'm not
the final arbiter of contributions to CLP.)

-- 
                Matthew Saltzman

Clemson University Math Sciences
mjs AT clemson DOT edu
http://www.math.clemson.edu/~mjs



More information about the Clp mailing list