### 5 The C Interface

A preliminary C interface is provided for trial purposes. It may be subject to change in the light of experience.

The interface obeys the rules defined in (PRO)LUN/10.

Briefly, the function name is generated from the Fortran subroutine name by forcing the name to lower case apart from the first character following any underscores, which is forced to upper case. Underscores are then removed.

For example: The C interface function for ‘MSG_OUT’ is ‘msgOut’.

Arguments are provided in the same order as for the Fortran routine with the exception that CHARACTER arrays and returned CHARACTER strings have an additional argument of type int (passed by value) immediately following them to specify a maximum length for the output string(s) including the terminating null for which space must be allowed.

There is a fixed relationship between the type of the Fortran argument and the type of the argument supplied to the C function – it is as follows:

 Fortran type C type INTEGER int REAL float REAL*8 double DOUBLE PRECISION double LOGICAL int CHARACTER char FUNCTION type (*name)() SUBROUTINE void (*name)()

Apart from any argument named ‘status’, given-only scalar arguments (not including character strings) are passed by value. All others are passed by pointer.

Arrays must be passed with the elements stored in the order required by Fortran.

All necessary constants and function prototypes can be defined by:

#include "mers.h"

The header file mers.h is contained in directory /star/include.