DyLP trunk
|
00001 #ifndef _DYLIB_FORTRAN_H 00002 #define _DYLIB_FORTRAN_H 00003 /* 00004 This file is part of the support library for the Dylp LP distribution. 00005 00006 Copyright (C) 2005 -- 2007 Lou Hafer 00007 00008 School of Computing Science 00009 Simon Fraser University 00010 Burnaby, B.C., V5A 1S6, Canada 00011 lou@cs.sfu.ca 00012 00013 This code is licensed under the terms of the Eclipse Public License (EPL). 00014 */ 00015 00016 /* 00017 @(#)fortran.h 1.1 09/01/99 00018 svn/cvs: $Id$ 00019 */ 00020 00021 /* 00022 Common typedefs, definitions, macros, etc., which are handy when constructing 00023 C code that must talk to Fortran code. 00024 00025 Off the top, typedefs and defines for the basic equivalences between 00026 Fortran and C data types. This list isn't complete, but it covers the 00027 common ones. (Taken from the Sun Fortran Programmer's Guide.) 00028 */ 00029 00030 typedef short int integer_2 ; 00031 typedef long int integer ; 00032 typedef long int logical ; 00033 typedef float real ; 00034 typedef double double_precision ; 00035 00036 #define TRUEL 1L 00037 #define FALSEL 0L 00038 00039 /* 00040 A note about string handling in mixed code. C goes by the convention that 00041 strings are terminated by a '\0' character, and padded with '\0' on the 00042 rare occasions when padding is necessary. Fortran, on the other hand, keeps 00043 an explicit (though hidden) length, and pads with ' '. The two forms are 00044 just not compatible. Take care when passing strings back and forth. Adding 00045 an explicit null in the Fortran definition of the string is your best bet. 00046 The output routines in io.c and errs.c expect this, and do not make use of 00047 the 'hidden' parameter giving the string length. 00048 */ 00049 00050 /* 00051 Some macros to help with Fortran arrays. 2-D arrays should simply be declared 00052 as array[rows*cols], and let the macro take care of the rest. This avoids 00053 complications due to column-major order in Fortran vs. row-major order in C. 00054 00055 NOTE that these macros assume you are using the Fortran indexing convention, 00056 which starts at 1. 00057 */ 00058 00059 #define f_chr(zz_ptr,zz_ndx,zz_strsze) (*(zz_ptr+((zz_ndx)-1)*(zz_strsze))) 00060 #define f_arr1(zz_ptr,zz_ndx) (*(zz_ptr+(zz_ndx)-1)) 00061 #define f_arr2(zz_ptr,zz_row,zz_col,zz_collen) \ 00062 (*(zz_ptr+((zz_col)-1)*(zz_collen)+((zz_row)-1))) 00063 00064 00065 /* 00066 These codes are used by the Fortran part of the code to identify arguments 00067 supplied to errmsg_, warn_, and outfmt_. The Fortran code sees them from 00068 the common block argcod_, which is initialised in errs.c:errinit (from the 00069 io library. Do not rearrange the structure declaration without making 00070 corresponding changes in the Fortran common block. 00071 00072 The codes ftnargVARNAME and ftnargCONNAME are peculiar to the bonsai MILP 00073 program (which prompted the development of the Fortran interface for i/o 00074 and error messages) and likely of little use in other contexts. At best, 00075 modifications to the routines in errs.c and io.c are required to support 00076 them. 00077 */ 00078 00079 #define ftnargINTEGER ((integer) 1) 00080 #define ftnargDOUBLE_PRECISION ((integer) 2) 00081 #define ftnargCHARACTER ((integer) 3) 00082 #define ftnargVARNAME ((integer) 4) 00083 #define ftnargCONNAME ((integer) 5) 00084 #define ftnargEND ((integer) 6) 00085 00086 extern struct { integer integer_code ; 00087 integer double_precision_code ; 00088 integer character_code ; 00089 integer varname_code ; 00090 integer conname_code ; 00091 integer end_code ; } argcod_ ; 00092 00093 #endif /* _DYLIB_FORTRAN_H */