00001 /*------------------------------------------------------------------------- 00002 This software is provided 'as-is', without any express or implied warranty. 00003 In no event will the authors be held liable for any damages arising from 00004 the use of this software. 00005 00006 Permission is granted to anyone to use this software for any purpose, 00007 including commercial applications, and to alter it and redistribute it 00008 freely, subject to the following restrictions: 00009 00010 1. The origin of this software must not be misrepresented; you must not 00011 claim that you wrote the original software. If you use this software 00012 in a product, an acknowledgment in the product documentation would be 00013 appreciated but is not required. 00014 00015 2. Altered source versions must be plainly marked as such, and must not 00016 be misrepresented as being the original software. 00017 00018 3. This notice may not be removed or altered from any source distribution. 00019 -------------------------------------------------------------------------*/ 00020 00021 #ifndef FORTRAN_MACROS_H 00022 #define FORTRAN_MACROS_H 00023 00024 /**************************************************************/ 00025 /* Include file used to interface with FORTRAN */ 00026 /**************************************************************/ 00027 00028 /* FMNAME is used when you prototype a FORTRAN routine for calling from C */ 00029 /* (which you HAVE to do), or when you create the subroutine */ 00030 /* INTEGER FMNAME(abc,ABC) (INTEGER ival, REAL rval); */ 00031 /* void FMNAME(abc,ABC) (INTEGER ival, REAL rval) */ 00032 /* { *ival = 1; *rval = 2.0; return; } */ 00033 /* FMCALL is used when you call a FORTRAN subroutine from C */ 00034 /* VINTEGER ival; */ 00035 /* VREAL rval; */ 00036 /* FMCALL(abc,ABC) (&ival, &rval); */ 00037 00038 /* STR_PSTR is used in receiving arguments from FORTRAN */ 00039 /* STR_PLEN is used in end of arguments from FORTRAN (no comma before it) */ 00040 /* STR_PTR is used to get the address of a string from FORTRAN */ 00041 /* STR_LEN is used to get the length of a string from FORTRAN */ 00042 /* INTEGER FMNAME(abc,ABC) (STR_PSTR(str), INTEGER ival */ 00043 /* STR_PLEN(str)) */ 00044 /* { char *pointer = STR_PTR(str); int length = STR_LEN(str); } */ 00045 00046 #ifdef NO_CONCATENATION 00047 # define IDENTITY(x) x 00048 # define CONCATENATE(a,b) IDENTITY(a)b 00049 #else 00050 # define CONCATENATE(a,b) a##b 00051 #endif 00052 00053 /* upper case Fortran name */ 00054 00055 #if defined(UPPERCASE) 00056 # define FMNAME(lname,uname) uname 00057 # define FMCALL(lname,uname) uname 00058 00059 /* upper case Fortran name with trailing underscore */ 00060 00061 #elif defined(UPPERCASE_) 00062 # define FMNAME(lname,uname) CONCATENATE(uname,_) 00063 # define FMCALL(lname,uname) CONCATENATE(uname,_) 00064 00065 /* upper case Fortran name with 2 trailing underscores */ 00066 00067 #elif defined(UPPERCASE__) 00068 # define FMNAME(lname,uname) CONCATENATE(uname,__) 00069 # define FMCALL(lname,uname) CONCATENATE(uname,__) 00070 00071 /* lower case Fortran name */ 00072 00073 #elif defined(LOWERCASE) 00074 # define FMNAME(lname,uname) lname 00075 # define FMCALL(lname,uname) lname 00076 00077 /* lower case Fortran name with trailing underscore */ 00078 00079 #elif defined(LOWERCASE_) 00080 # define FMNAME(lname,uname) CONCATENATE(lname,_) 00081 # define FMCALL(lname,uname) CONCATENATE(lname,_) 00082 00083 /* lower case Fortran name with 2 trailing underscores */ 00084 00085 #elif defined(LOWERCASE__) 00086 # define FMNAME(lname,uname) CONCATENATE(lname,__) 00087 # define FMCALL(lname,uname) CONCATENATE(lname,__) 00088 00089 /* Cray Super Computer */ 00090 00091 #elif defined(_CRAY) || defined(cray) 00092 # include <fortran.h> 00093 # define FMNAME(lname,uname) uname 00094 # define FMCALL(lname,uname) uname 00095 # define STR_PSTR(str) _fcd str 00096 # define STR_PLEN(str) 00097 # define STR_PTR(str) _fcdtocp (str) 00098 # define STR_LEN(str) _fcdlen (str) 00099 00100 /* Vax VMS */ 00101 00102 #elif defined(VMS) 00103 # include <descrip.h> 00104 # define FMNAME(lname,uname) uname 00105 # define FMCALL(lname,uname) uname 00106 # define STR_PSTR(str) struct dsc$descriptor_s *str 00107 # define STR_PLEN(str) 00108 # define STR_PTR(str) str->dsc$a_pointer 00109 # define STR_LEN(str) str->dsc$w_length 00110 00111 /* MS Windows */ 00112 00113 #elif defined(_WIN32) 00114 # if defined(__NUTC__) || defined(__WIN32_BINARY__) 00115 # define FMNAME(lname,uname) __cdecl lname 00116 # define FMCALL(lname,uname) lname 00117 # define STR_PSTR(str) char *str 00118 # define STR_PLEN(str) , int CONCATENATE(Len,str) 00119 # else 00120 # ifndef WIN32_FORTRAN 00121 # define WIN32_FORTRAN 00122 # endif 00123 # define FMNAME(lname,uname) __stdcall uname 00124 # define FMCALL(lname,uname) uname 00125 # define STR_PSTR(str) char *str, int CONCATENATE(Len,str) 00126 # define STR_PLEN(str) 00127 # endif 00128 # define STR_PTR(str) str 00129 # define STR_LEN(str) CONCATENATE(Len,str) 00130 00131 /* assume lower case Fortran name with trailing underscore */ 00132 00133 #else 00134 # define FMNAME(lname,uname) CONCATENATE(lname,_) 00135 # define FMCALL(lname,uname) CONCATENATE(lname,_) 00136 00137 #endif 00138 00139 #ifndef STR_PSTR 00140 # define STR_PSTR(str) char *str 00141 # define STR_PLEN(str) , int CONCATENATE(Len,str) 00142 # define STR_PTR(str) str 00143 # define STR_LEN(str) CONCATENATE(Len,str) 00144 #endif 00145 00146 /*************/ 00147 /* Datatypes */ 00148 /*************/ 00149 00150 typedef char VCHARACTER; 00151 typedef int VINTEGER; 00152 typedef double VREAL; 00153 typedef float VFLOAT; 00154 00155 typedef VCHARACTER * CHARACTER; 00156 typedef VINTEGER * INTEGER; 00157 typedef VREAL * REAL; 00158 #if !defined(_WIN32) || !defined(_WINDEF_) 00159 typedef VFLOAT * PFLOAT; 00160 #endif 00161 00162 /**************/ 00163 /* Prototypes */ 00164 /**************/ 00165 00166 #ifdef __cplusplus 00167 extern "C" { 00168 #endif 00169 00170 /*****************************************************************************/ 00171 /* tocstr - convert a fortran character string into a fortran integer array */ 00172 /* that has a trailing null character to look like a c-string */ 00173 /* */ 00174 /* character str (in) Fortran chacter string */ 00175 /* integer icstr(*) (out) Fortran integer array */ 00176 /* */ 00177 /* notes: */ 00178 /* 1) Trailing blanks are removed, and leading/trailing '"' are also. */ 00179 /* 2) To keep the trailing blanks, quote them '"' */ 00180 /* 3) It is a little faster to call this routine without any trailing */ 00181 /* blanks; ex. call tocstr (abc[1:notblk], icstr) */ 00182 /*****************************************************************************/ 00183 00184 void FMNAME(tocstr,TOCSTR) ( 00185 STR_PSTR(str), /* (in) Fortran character string */ 00186 CHARACTER icstr /* (out) Fortran integer array */ 00187 STR_PLEN(str) /* (in) Compiler passed len of str */ 00188 ); 00189 00190 /*****************************************************************************/ 00191 /* frcstr - convert a fortran integer array into a fortran character string */ 00192 /* */ 00193 /* integer icstr(*) (in) Fortran integer array */ 00194 /* character str (out) Fortran chacter string */ 00195 /*****************************************************************************/ 00196 00197 void FMNAME(frcstr,FRCSTR) ( 00198 CHARACTER icstr, /* (in) Fortran integer array */ 00199 STR_PSTR(str) /* (out) Fortran character string */ 00200 STR_PLEN(str) /* (in) Compiler passed len of str */ 00201 ); 00202 00203 /*************************************************************************/ 00204 /* fstr_to_cstr - convert a fortran character string into a c character */ 00205 /* string */ 00206 /*************************************************************************/ 00207 00208 void fstr_to_cstr ( 00209 char *str, /* (in) Pointer to character string */ 00210 int ilen, /* (in) Max length of str */ 00211 char *icstr /* (out) C character string */ 00212 ); 00213 00214 /*************************************************************************/ 00215 /* cstr_to_fstr - convert a c character string into a fortran character */ 00216 /* string */ 00217 /*************************************************************************/ 00218 00219 void cstr_to_fstr ( 00220 char *icstr, /* (in) C character string */ 00221 int ilen, /* (in) Max length of str */ 00222 char *str /* (out) Pointer to character string */ 00223 ); 00224 00225 #ifdef __cplusplus 00226 } 00227 #endif 00228 00229 #endif /* FORTRAN_MACROS_H */