1 /*------------------------------------------------------------------------- 2 This software is provided 'as-is', without any express or implied warranty. 3 In no event will the authors be held liable for any damages arising from 4 the use of this software. 5 6 Permission is granted to anyone to use this software for any purpose, 7 including commercial applications, and to alter it and redistribute it 8 freely, subject to the following restrictions: 9 10 1. The origin of this software must not be misrepresented; you must not 11 claim that you wrote the original software. If you use this software 12 in a product, an acknowledgment in the product documentation would be 13 appreciated but is not required. 14 15 2. Altered source versions must be plainly marked as such, and must not 16 be misrepresented as being the original software. 17 18 3. This notice may not be removed or altered from any source distribution. 19 -------------------------------------------------------------------------*/ 20 21 #ifndef FORTRAN_MACROS_H 22 #define FORTRAN_MACROS_H 23 24 /**************************************************************/ 25 /* Include file used to interface with FORTRAN */ 26 /**************************************************************/ 27 28 /* FMNAME is used when you prototype a FORTRAN routine for calling from C */ 29 /* (which you HAVE to do), or when you create the subroutine */ 30 /* INTEGER FMNAME(abc,ABC) (INTEGER ival, REAL rval); */ 31 /* void FMNAME(abc,ABC) (INTEGER ival, REAL rval) */ 32 /* { *ival = 1; *rval = 2.0; return; } */ 33 /* FMCALL is used when you call a FORTRAN subroutine from C */ 34 /* VINTEGER ival; */ 35 /* VREAL rval; */ 36 /* FMCALL(abc,ABC) (&ival, &rval); */ 37 38 /* STR_PSTR is used in receiving arguments from FORTRAN */ 39 /* STR_PLEN is used in end of arguments from FORTRAN (no comma before it) */ 40 /* STR_PTR is used to get the address of a string from FORTRAN */ 41 /* STR_LEN is used to get the length of a string from FORTRAN */ 42 /* INTEGER FMNAME(abc,ABC) (STR_PSTR(str), INTEGER ival */ 43 /* STR_PLEN(str)) */ 44 /* { char *pointer = STR_PTR(str); int length = STR_LEN(str); } */ 45 46 #ifdef NO_CONCATENATION 47 # define IDENTITY(x) x 48 # define CONCATENATE(a,b) IDENTITY(a)b 49 #else 50 # define CONCATENATE(a,b) a##b 51 #endif 52 53 /* upper case Fortran name */ 54 55 #if defined(UPPERCASE) 56 # define FMNAME(lname,uname) uname 57 # define FMCALL(lname,uname) uname 58 59 /* upper case Fortran name with trailing underscore */ 60 61 #elif defined(UPPERCASE_) 62 # define FMNAME(lname,uname) CONCATENATE(uname,_) 63 # define FMCALL(lname,uname) CONCATENATE(uname,_) 64 65 /* upper case Fortran name with 2 trailing underscores */ 66 67 #elif defined(UPPERCASE__) 68 # define FMNAME(lname,uname) CONCATENATE(uname,__) 69 # define FMCALL(lname,uname) CONCATENATE(uname,__) 70 71 /* lower case Fortran name */ 72 73 #elif defined(LOWERCASE) 74 # define FMNAME(lname,uname) lname 75 # define FMCALL(lname,uname) lname 76 77 /* lower case Fortran name with trailing underscore */ 78 79 #elif defined(LOWERCASE_) 80 # define FMNAME(lname,uname) CONCATENATE(lname,_) 81 # define FMCALL(lname,uname) CONCATENATE(lname,_) 82 83 /* lower case Fortran name with 2 trailing underscores */ 84 85 #elif defined(LOWERCASE__) 86 # define FMNAME(lname,uname) CONCATENATE(lname,__) 87 # define FMCALL(lname,uname) CONCATENATE(lname,__) 88 89 /* Cray Super Computer */ 90 91 #elif defined(_CRAY) || defined(cray) 92 # include <fortran.h> 93 # define FMNAME(lname,uname) uname 94 # define FMCALL(lname,uname) uname 95 # define STR_PSTR(str) _fcd str 96 # define STR_PLEN(str) 97 # define STR_PTR(str) _fcdtocp (str) 98 # define STR_LEN(str) _fcdlen (str) 99 100 /* Vax VMS */ 101 102 #elif defined(VMS) 103 # include <descrip.h> 104 # define FMNAME(lname,uname) uname 105 # define FMCALL(lname,uname) uname 106 # define STR_PSTR(str) struct dsc$descriptor_s *str 107 # define STR_PLEN(str) 108 # define STR_PTR(str) str->dsc$a_pointer 109 # define STR_LEN(str) str->dsc$w_length 110 111 /* MS Windows */ 112 113 #elif defined(_WIN32) 114 # if defined(__NUTC__) || defined(__WIN32_BINARY__) 115 # define FMNAME(lname,uname) __cdecl lname 116 # define FMCALL(lname,uname) lname 117 # define STR_PSTR(str) char *str 118 # define STR_PLEN(str) , int CONCATENATE(Len,str) 119 # else 120 # ifndef WIN32_FORTRAN 121 # define WIN32_FORTRAN 122 # endif 123 # define FMNAME(lname,uname) __stdcall uname 124 # define FMCALL(lname,uname) uname 125 # define STR_PSTR(str) char *str, int CONCATENATE(Len,str) 126 # define STR_PLEN(str) 127 # endif 128 # define STR_PTR(str) str 129 # define STR_LEN(str) CONCATENATE(Len,str) 130 131 /* assume lower case Fortran name with trailing underscore */ 132 133 #else 134 # define FMNAME(lname,uname) CONCATENATE(lname,_) 135 # define FMCALL(lname,uname) CONCATENATE(lname,_) 136 137 #endif 138 139 #ifndef STR_PSTR 140 # define STR_PSTR(str) char *str 141 # define STR_PLEN(str) , int CONCATENATE(Len,str) 142 # define STR_PTR(str) str 143 # define STR_LEN(str) CONCATENATE(Len,str) 144 #endif 145 146 /*************/ 147 /* Datatypes */ 148 /*************/ 149 150 typedef char VCHARACTER; 151 typedef int VINTEGER; 152 typedef double VREAL; 153 typedef float VFLOAT; 154 155 typedef VCHARACTER * CHARACTER; 156 typedef VINTEGER * INTEGER; 157 typedef VREAL * REAL; 158 #if !defined(_WIN32) || !defined(_WINDEF_) 159 typedef VFLOAT * PFLOAT; 160 #endif 161 162 /**************/ 163 /* Prototypes */ 164 /**************/ 165 166 #ifdef __cplusplus 167 extern "C" { 168 #endif 169 170 /*****************************************************************************/ 171 /* tocstr - convert a fortran character string into a fortran integer array */ 172 /* that has a trailing null character to look like a c-string */ 173 /* */ 174 /* character str (in) Fortran chacter string */ 175 /* integer icstr(*) (out) Fortran integer array */ 176 /* */ 177 /* notes: */ 178 /* 1) Trailing blanks are removed, and leading/trailing '"' are also. */ 179 /* 2) To keep the trailing blanks, quote them '"' */ 180 /* 3) It is a little faster to call this routine without any trailing */ 181 /* blanks; ex. call tocstr (abc[1:notblk], icstr) */ 182 /*****************************************************************************/ 183 184 void FMNAME(tocstr,TOCSTR) ( 185 STR_PSTR(str), /* (in) Fortran character string */ 186 CHARACTER icstr /* (out) Fortran integer array */ 187 STR_PLEN(str) /* (in) Compiler passed len of str */ 188 ); 189 190 /*****************************************************************************/ 191 /* frcstr - convert a fortran integer array into a fortran character string */ 192 /* */ 193 /* integer icstr(*) (in) Fortran integer array */ 194 /* character str (out) Fortran chacter string */ 195 /*****************************************************************************/ 196 197 void FMNAME(frcstr,FRCSTR) ( 198 CHARACTER icstr, /* (in) Fortran integer array */ 199 STR_PSTR(str) /* (out) Fortran character string */ 200 STR_PLEN(str) /* (in) Compiler passed len of str */ 201 ); 202 203 /*************************************************************************/ 204 /* fstr_to_cstr - convert a fortran character string into a c character */ 205 /* string */ 206 /*************************************************************************/ 207 208 void fstr_to_cstr ( 209 char *str, /* (in) Pointer to character string */ 210 int ilen, /* (in) Max length of str */ 211 char *icstr /* (out) C character string */ 212 ); 213 214 /*************************************************************************/ 215 /* cstr_to_fstr - convert a c character string into a fortran character */ 216 /* string */ 217 /*************************************************************************/ 218 219 void cstr_to_fstr ( 220 char *icstr, /* (in) C character string */ 221 int ilen, /* (in) Max length of str */ 222 char *str /* (out) Pointer to character string */ 223 ); 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif /* FORTRAN_MACROS_H */ 230