3 OASIS3-MCT C API

OASIS3-MCT is distributed with C bindings and can be called from models written in C and in C++. These bindings leverage the Fortran ISO_C_BINDING standard. The C bindings can be compiled into static or shared libraries by the OASIS3-MCT TopMakefileOasis3 as documented in 6.1.

The C interfaces largely match up with equivalent interfaces in Fortran. An interface named oasis_interface in Fortran can be expected to be named oasis_c_interface in C.

All of the C interfaces return an integer error code which can be tested against the OASIS_Ok (or the equivalent OASIS_Success) constant. The OASIS_CHECK_ERR macro aborts OASIS3-MCT with a meaningful message in the debug files in case of failure. For most of the functions, the return code is consistent with the kinfo argument in the Fortran interfaces (see section 2.2). However, for the put and get communication functions, the return error code only indicates success or failure, while the detailed status is returned by the kinfo argument (equivalent to the returned value of info argument for the Fortran oasis_put and oasis_get routines, see section 2.2.7).

For example, the following constructs are equivalent in the two languages:

call oasis_get_localcomm(localcomm, kinfo)
if (kinfo .ne. OASIS_Ok)  &
   &  call OASIS_Abort(comp_id, "oasis_get_localcomm", &
   &  "Runtime error", __FILE__, __LINE__)

and

OASIS_CHECK_ERR(oasis_get_localcomm(localcomm))

For convenience a similar macro OASIS_CHECK_MPI_ERR has been defined for testing the return code of any MPI function against MPI_SUCCESS and cleanly aborting OASIS3-MCT in case of failure.


Use of these C bindings are illustrated in practical examples in directories /C in the different subdirectories in pyoasis/examples/. Notes and deviations from the Fortran standard are noted below.