gpp4
1.3.1
|
Header file for Fortran APIs. More...
#include "ccp4_types.h"
Go to the source code of this file.
Macros | |
#define | _LVTOB(l) ((long) ((l) == 0 ? 0 : 1)) |
#define | _BTOLV(l) ((int) ((l) == 0 ? 0 : 1)) |
#define | FTN_STR(s) s |
#define | FTN_LEN(s) s##_len |
#define | char_struct(s) |
#define | fill_char_struct(s, str) |
#define | init_char_struct(s, str, size) |
#define | FORTRAN_SUBR(NAME, name, p_sun, p_stardent, p_mvs) void name##_ p_sun |
#define | FORTRAN_CALL(NAME, name, p_sun, p_stardent, p_mvs) name##_ p_sun |
#define | FORTRAN_FUN(val, NAME, name, p_sun, p_stardent, p_mvs) val name##_ p_sun |
Typedefs | |
typedef pstr | fpstr |
typedef unsigned int | ftn_logical |
Functions | |
char * | ccp4_FtoCString (fpstr str1, int str1_len) |
void | ccp4_CtoFString (fpstr str1, int str1_len, const char *cstring) |
Header file for Fortran APIs.
#define char_struct | ( | s | ) |
#define fill_char_struct | ( | s, | |
str | |||
) |
#define FORTRAN_CALL | ( | NAME, | |
name, | |||
p_sun, | |||
p_stardent, | |||
p_mvs | |||
) | name##_ p_sun |
Macro to call a Fortran subroutine from a C function.
NAME | Subroutine name in upper case |
name | Subroutine name in lower case |
p_sun | Argument list in Sun style |
p_stardent | Argument list in Stardent style |
p_mvs | Argument list in MVS style |
Referenced by ccp4_CtoFString(), ccp4f_mem_tidy(), and FORTRAN_SUBR().
#define FORTRAN_FUN | ( | val, | |
NAME, | |||
name, | |||
p_sun, | |||
p_stardent, | |||
p_mvs | |||
) | val name##_ p_sun |
Macro to define a function such that it is callable as a Fortran function.
val | Data type of return value. |
NAME | Function name in upper case |
name | Function name in lower case |
p_sun | Argument list in Sun style |
p_stardent | Argument list in Stardent style |
p_mvs | Argument list in MVS style |
Referenced by ccp4_CtoFString(), and FORTRAN_SUBR().
#define FORTRAN_SUBR | ( | NAME, | |
name, | |||
p_sun, | |||
p_stardent, | |||
p_mvs | |||
) | void name##_ p_sun |
Macro to define a function such that it is callable as a Fortran subroutine.
NAME | Subroutine name in upper case |
name | Subroutine name in lower case |
p_sun | Argument list in Sun style |
p_stardent | Argument list in Stardent style |
p_mvs | Argument list in MVS style |
Referenced by ccp4_CtoFString().
#define init_char_struct | ( | s, | |
str, | |||
size | |||
) |
typedef pstr fpstr |
Macro FORTRAN_SUBR(NAME,name,p_send,p_sstruct,p_sflw) makes function header statements that allow for linking with programs written in FORTRAN.
NAME | name of the FORTRAN subroutine in capital letters |
name | name of the FORTRAN subroutine in small letters |
p_send | parameter list (in brackets) with string lengths attached to the end of it (see below) |
p_sstruct | parameter list (in brackets) with strings passed as complex parameters, or structures |
p_sflw | parameter list (in brackets) with string lengths following immediately the string parameters (see below) |
All non-string parameters must be passed as pointers, in the same order as they enter the FORTRAN call. Rules for the string parameters are as follows.
whenever length of string is passed as a separate parameter ( CALL_LIKE_SUN, CALL_LIKE_HPUX, CALL_LIKE_MVS ) 'fpstr' is identical to 'pstr'. You may choose arbitrary name for the string, but you MUST use the same name, appended with suffix '_len', for its length (see example below).
CALL_LIKE_STARDENT : 'fpstr' is identical to 'PSStrPar' CALL_LIKE_VMS : 'fpstr' is identical to 'dsc$descriptor_s *'With 'fpstr' type, two important macro definition come:
Three parameter lists, each enclosed in brackets, should be given. These lists retain the general order of parameters in the corresponding fortran call. Non-string parameters are passed as pointers. String parameters and their lengths are passed differently in different lists:
Example:
FORTRAN statement
is translated to
The macro should replace ordinary function header statements to assure compatibility with FORTRAN links. In header files, do not forget to add semicolon:
while in source files use simply
Macro FORTRAN_CALL(NAME,name,p_send,p_sstruct,p_sflw) calls function defined with macro FORTRAN_SUBR(...), from a C/C++ application. Its parameters and their meaning are exactly identical to those of FORTRAN_SUBR(...). FORTRAN_CALL(...) should be followed by semicolon.
void ccp4_CtoFString | ( | fpstr | str1, |
int | str1_len, | ||
const char * | cstring | ||
) |
Creates a Fortran string from an input C string for passing back to Fortran call. Characters after null-terminator may be junk, so pad with spaces. If input cstring is NULL, return blank string.
str1 | pointer Fortran to string |
str1_len | Fortran length of string |
cstring | input C string |
References ccp4_fatal(), ccp4_FtoCString(), ccp4_nan(), ccp4_utils_bml(), ccp4_utils_chmod(), ccp4_utils_hgetlimits(), ccp4_utils_isnan(), ccp4_utils_mkdir(), ccp4_utils_outbuf(), ccp4_utils_print(), ccp4_utils_setenv(), FORTRAN_CALL, FORTRAN_FUN, FORTRAN_SUBR, and float_uint_uchar::i.
Referenced by ccp4f_mem_tidy(), and FORTRAN_SUBR().
char* ccp4_FtoCString | ( | fpstr | str1, |
int | str1_len | ||
) |
Creates a null-terminated C string from an input string obtained from a Fortran call. Trailing blanks are removed. If input string is blank then return string "\0". Memory assigned by malloc, so can be freed.
str1 | pointer to string |
str1_len | Fortran length of string |
References ccp4_utils_flength(), and ccp4_utils_malloc().
Referenced by ccp4_CtoFString(), ccp4f_mem_tidy(), ccp4spg_mem_tidy(), and FORTRAN_SUBR().