00001 #ifndef _DYLIB_FORTRAN_H 00002 #define _DYLIB_FORTRAN_H 00003 /* 00004 This file is part of the support library for the OsiDylp LP distribution. 00005 00006 Copyright (C) 2005 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 program is free software; you can redistribute it and/or modify it 00014 under the terms of the GNU General Public License as published by the Free 00015 Software Foundation; either version 2 of the License, or (at your option) 00016 any later version. 00017 00018 This program is distributed in the hope that it will be useful, but WITHOUT 00019 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00020 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00021 more details. 00022 00023 You should have received a copy of the GNU General Public License along 00024 with this program; if not, write to the Free Software Foundation, Inc., 00025 51 Franklin St., Fifth Floor, Boston, MA 02110-1301 USA 00026 */ 00027 00028 /* 00029 @(#)fortran.h 1.1 09/01/99 00030 svn/cvs: $Id: dylib_fortran.h 71 2006-06-09 04:21:15Z andreasw $ 00031 */ 00032 00033 /* 00034 Common typedefs, definitions, macros, etc., which are handy when constructing 00035 C code that must talk to Fortran code. 00036 00037 Off the top, typedefs and defines for the basic equivalences between 00038 Fortran and C data types. This list isn't complete, but it covers the 00039 common ones. (Taken from the Sun Fortran Programmer's Guide.) 00040 */ 00041 00042 typedef short int integer_2 ; 00043 typedef long int integer ; 00044 typedef long int logical ; 00045 typedef float real ; 00046 typedef double double_precision ; 00047 00048 #define TRUEL 1L 00049 #define FALSEL 0L 00050 00051 /* 00052 A note about string handling in mixed code. C goes by the convention that 00053 strings are terminated by a '\0' character, and padded with '\0' on the 00054 rare occasions when padding is necessary. Fortran, on the other hand, keeps 00055 an explicit (though hidden) length, and pads with ' '. The two forms are 00056 just not compatible. Take care when passing strings back and forth. Adding 00057 an explicit null in the Fortran definition of the string is your best bet. 00058 The output routines in io.c and errs.c expect this, and do not make use of 00059 the 'hidden' parameter giving the string length. 00060 */ 00061 00062 /* 00063 Some macros to help with Fortran arrays. 2-D arrays should simply be declared 00064 as array[rows*cols], and let the macro take care of the rest. This avoids 00065 complications due to column-major order in Fortran vs. row-major order in C. 00066 00067 NOTE that these macros assume you are using the Fortran indexing convention, 00068 which starts at 1. 00069 */ 00070 00071 #define f_chr(zz_ptr,zz_ndx,zz_strsze) (*(zz_ptr+((zz_ndx)-1)*(zz_strsze))) 00072 #define f_arr1(zz_ptr,zz_ndx) (*(zz_ptr+(zz_ndx)-1)) 00073 #define f_arr2(zz_ptr,zz_row,zz_col,zz_collen) \ 00074 (*(zz_ptr+((zz_col)-1)*(zz_collen)+((zz_row)-1))) 00075 00076 00077 /* 00078 These codes are used by the Fortran part of the code to identify arguments 00079 supplied to errmsg_, warn_, and outfmt_. The Fortran code sees them from 00080 the common block argcod_, which is initialised in errs.c:errinit (from the 00081 io library. Do not rearrange the structure declaration without making 00082 corresponding changes in the Fortran common block. 00083 00084 The codes ftnargVARNAME and ftnargCONNAME are peculiar to the bonsai MILP 00085 program (which prompted the development of the Fortran interface for i/o 00086 and error messages) and likely of little use in other contexts. At best, 00087 modifications to the routines in errs.c and io.c are required to support 00088 them. 00089 */ 00090 00091 #define ftnargINTEGER ((integer) 1) 00092 #define ftnargDOUBLE_PRECISION ((integer) 2) 00093 #define ftnargCHARACTER ((integer) 3) 00094 #define ftnargVARNAME ((integer) 4) 00095 #define ftnargCONNAME ((integer) 5) 00096 #define ftnargEND ((integer) 6) 00097 00098 extern struct { integer integer_code ; 00099 integer double_precision_code ; 00100 integer character_code ; 00101 integer varname_code ; 00102 integer conname_code ; 00103 integer end_code ; } argcod_ ; 00104 00105 #endif /* _DYLIB_FORTRAN_H */