Programming in C


This section is dedicated to programmers who want to write applications (or service routines) in the ANSI C programming language. Since the GIPSY programming environment supports both Fortran and C as programming languages, there are some restrictions on what type of arguments may be passed to the routines. Also the module names have some restrictions since each operating system interfaces C and Fortran differently.

Function Arguments and Names

Each operating system has different ideas about how to interface Fortran modules with C modules. Therefore a portable Fortran to C (and vice versa) interface was developed at the Kapteyn Institute. This interface sets a number of restraints on the types of arguments passed to other service routines and on the names of servant routines.

Module names

Almost any routine in the GIPSY library is both C callable and Fortran callable. C programmers append `_c' to the lower case Fortran name. For example, a Fortran task would start with `CALL INIT', and a C task with `init_c();'.

Argument Types

The types of arguments which may be passed from one routine to the other, whether the called routines are written in C or Fortran, are:
       Fortran           C
       ----------------- ------
       CHARACTER         fchar
       COMPLEX           complex
       DOUBLE PRECISION  double
       INTEGER           fint
       LOGICAL           bool
       REAL              float
The non-C types in this table are all defined in include file gipsyc.h, so each C program or function must include this file (after the standard C include files but before the definition files).


A fint is an integer which has the same number of bytes as the Fortran integer. Since C supports three integer types (short, int, long) and since the number of bytes occupied by these types is system dependent, C programmers must use fint for portability reasons.

fint will be one of the following, depending on the operating system:

      typedef short  fint;
      typedef int    fint;
      typedef long   fint;


A bool is also an integer which has the same number of bytes as the Fortran logical.


A complex is a struct consisting of two floats, one carrying the real part, the second carrying the imaginary part.
      typedef struct { float r; float i; } complex;


An fchar is a struct equivalent to a Fortran character variable or constant. fchar carries the address of the first element of the string and the length of the string. Note that this string is not null-terminated!
      typedef struct { char *a; fint l; } fchar;

Function types

The Fortran routines which correspond with C functions are the following:
      Fortran                    C
      -----------------------    -------------------------
      SUBROUTINE       SS(..)    void     ss_c(..)
      CHARACTER*(*)    CC(..)    void     cc_c(fchar r,..)
      COMPLEX          CX(..)    complex  cx_c(..)
      DOUBLE PRECISION DD(..)    double   dd_c(..)
      INTEGER          II(..)    fint     ii_c(..)
      LOGICAL          LL(..)    bool     ll_c(..)
      REAL             RR(..)    float    rr_c(..)
Note that Fortran character functions become voids in C with an extra argument being the destination of the character function.

Standard C library

Although most operating systems support ANSI C, some of them don't have the standard C include files and libraries. Therefore the eXtended C library was developed at the Kapteyn Institute to add the most important missing functions, or to replace those which are available on the operation systems but not working according to ANSI C specifications.

We have tried to supply the C programmer with the most interesting of those functions. These functions are defined in the following ANSI C include files.

Note that these include files reside in $gip_inc, and that they must be included using the "" notation instead of <>.
Programming GIPSY