Simbody
|
00001 #ifndef SimTK_SimTKCOMMON_FORTRAN_H_ 00002 #define SimTK_SimTKCOMMON_FORTRAN_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * SimTK Core: SimTKcommon * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK Core biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org. * 00011 * * 00012 * Portions copyright (c) 2006 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Permission is hereby granted, free of charge, to any person obtaining a * 00017 * copy of this software and associated documentation files (the "Software"), * 00018 * to deal in the Software without restriction, including without limitation * 00019 * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 00020 * and/or sell copies of the Software, and to permit persons to whom the * 00021 * Software is furnished to do so, subject to the following conditions: * 00022 * * 00023 * The above copyright notice and this permission notice shall be included in * 00024 * all copies or substantial portions of the Software. * 00025 * * 00026 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 00027 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 00028 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 00029 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 00030 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 00031 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 00032 * USE OR OTHER DEALINGS IN THE SOFTWARE. * 00033 * -------------------------------------------------------------------------- */ 00034 00042 // Although we are currently triggering this off the OS, these 00043 // really are compiler dependencies. 00044 // (1) The calling convention (__stdcall for Windows) 00045 // (2) Name capitalization (either all-lower or all-uppercase) 00046 // (3) Is a trailing underscore added to the name? 00047 // (4) And ugliest, Fortran passes string lengths as a hidden 00048 // value parameter. On some compilers, that length follows 00049 // the string immediately. On others, all the lengths 00050 // appear at the end of the argument list, in the same 00051 // order as the strings to which they correspond. 00052 // Point (4) requires four ugly macros to be used, two in declarations 00053 // and two in calls to Fortran routines. One macro appears immediately 00054 // after each string, and the other appears at the end of the argument 00055 // list, repeated as many times as necessary. One or the other will 00056 // evaluate to nothing. 00057 00058 // These macros should be used for whatever the expected default 00059 // Fortran behavior is for whatever Fortran is typically used in 00060 // conjunction with the current C++ compiler. 00061 #ifdef _WIN32 00062 #define SimTK_FORTRAN_STDCALL __stdcall 00063 #define SimTK_FORTRAN(x,X) X 00064 #define SimTK_FORTRAN_STRLEN_FOLLOWS_DECL ,int 00065 #define SimTK_FORTRAN_STRLEN_FOLLOWS_CALL(n) ,n 00066 #define SimTK_FORTRAN_STRLEN_ATEND_DECL // nothing 00067 #define SimTK_FORTRAN_STRLEN_ATEND_CALL(n) 00068 #else 00069 #define SimTK_FORTRAN_STDCALL 00070 #define SimTK_FORTRAN(x,X) x ## _ 00071 #define SimTK_FORTRAN_STRLEN_FOLLOWS_DECL // nothing 00072 #define SimTK_FORTRAN_STRLEN_FOLLOWS_CALL(n) 00073 #define SimTK_FORTRAN_STRLEN_ATEND_DECL ,int 00074 #define SimTK_FORTRAN_STRLEN_ATEND_CALL(n) ,n 00075 #endif 00076 00077 // These macros should be used for whatever our chosen LAPACK and 00078 // BLAS libraries will look like from here. 00079 #ifdef SimTK_USE_ACML_LAPACK 00080 #ifdef _WIN32 00081 #define SimTK_LAPACK_STDCALL __stdcall 00082 #define SimTK_LAPACK(x,X) X 00083 #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL ,int 00084 #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n) ,n 00085 #define SimTK_LAPACK_STRLEN_ATEND_DECL // nothing 00086 #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) 00087 #else 00088 #define SimTK_LAPACK_STDCALL 00089 #define SimTK_LAPACK(x,X) x ## _ 00090 #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL // nothing 00091 #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n) 00092 #define SimTK_LAPACK_STRLEN_ATEND_DECL ,int 00093 #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) ,n 00094 #endif 00095 #else // default assumes we're using libSimTKlapack 00096 #define SimTK_LAPACK_STDCALL 00097 #define SimTK_LAPACK(x,X) x ## _ 00098 #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL // nothing 00099 #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n) 00100 #define SimTK_LAPACK_STRLEN_ATEND_DECL ,int 00101 #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) ,n 00102 #endif 00103 00104 // TODO: Currently this is unused and may not be needed anymore. 00105 // Call these routines to intialize the GNU Fortran RTL. 00106 // 00107 00108 #ifdef USING_G77 00109 extern "C" { 00110 void f_setsig(); 00111 void f_init(); 00112 } 00113 #define SimTK_FORTRAN_INIT do {f_setsig(); f_init();} while(false) 00114 #endif 00115 00116 #endif // SimTK_SimTKCOMMON_FORTRAN_H_