Simbody
3.4 (development)
|
00001 #ifndef SimTK_SimTKCOMMON_FORTRAN_H_ 00002 #define SimTK_SimTKCOMMON_FORTRAN_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKcommon * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK 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/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2006-12 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00034 // Although we are currently triggering this off the OS, these 00035 // really are compiler dependencies. 00036 // (1) The calling convention (__stdcall for Windows) 00037 // (2) Name capitalization (either all-lower or all-uppercase) 00038 // (3) Is a trailing underscore added to the name? 00039 // (4) And ugliest, Fortran passes string lengths as a hidden 00040 // value parameter. On some compilers, that length follows 00041 // the string immediately. On others, all the lengths 00042 // appear at the end of the argument list, in the same 00043 // order as the strings to which they correspond. 00044 // Point (4) requires four ugly macros to be used, two in declarations 00045 // and two in calls to Fortran routines. One macro appears immediately 00046 // after each string, and the other appears at the end of the argument 00047 // list, repeated as many times as necessary. One or the other will 00048 // evaluate to nothing. 00049 00050 // These macros should be used for whatever the expected default 00051 // Fortran behavior is for whatever Fortran is typically used in 00052 // conjunction with the current C++ compiler. 00053 #ifdef _WIN32 00054 #define SimTK_FORTRAN_STDCALL __stdcall 00055 #define SimTK_FORTRAN(x,X) X 00056 #define SimTK_FORTRAN_STRLEN_FOLLOWS_DECL ,int 00057 #define SimTK_FORTRAN_STRLEN_FOLLOWS_CALL(n) ,n 00058 #define SimTK_FORTRAN_STRLEN_ATEND_DECL // nothing 00059 #define SimTK_FORTRAN_STRLEN_ATEND_CALL(n) 00060 #else 00061 #define SimTK_FORTRAN_STDCALL 00062 #define SimTK_FORTRAN(x,X) x ## _ 00063 #define SimTK_FORTRAN_STRLEN_FOLLOWS_DECL // nothing 00064 #define SimTK_FORTRAN_STRLEN_FOLLOWS_CALL(n) 00065 #define SimTK_FORTRAN_STRLEN_ATEND_DECL ,int 00066 #define SimTK_FORTRAN_STRLEN_ATEND_CALL(n) ,n 00067 #endif 00068 00069 // These macros should be used for whatever our chosen LAPACK and 00070 // BLAS libraries will look like from here. 00071 #ifdef SimTK_USE_ACML_LAPACK 00072 #ifdef _WIN32 00073 #define SimTK_LAPACK_STDCALL __stdcall 00074 #define SimTK_LAPACK(x,X) X 00075 #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL ,int 00076 #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n) ,n 00077 #define SimTK_LAPACK_STRLEN_ATEND_DECL // nothing 00078 #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) 00079 #else 00080 #define SimTK_LAPACK_STDCALL 00081 #define SimTK_LAPACK(x,X) x ## _ 00082 #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL // nothing 00083 #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n) 00084 #define SimTK_LAPACK_STRLEN_ATEND_DECL ,int 00085 #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) ,n 00086 #endif 00087 #else // default assumes we're using libSimTKlapack 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 00096 // TODO: Currently this is unused and may not be needed anymore. 00097 // Call these routines to intialize the GNU Fortran RTL. 00098 // 00099 00100 #ifdef USING_G77 00101 extern "C" { 00102 void f_setsig(); 00103 void f_init(); 00104 } 00105 #define SimTK_FORTRAN_INIT do {f_setsig(); f_init();} while(false) 00106 #endif 00107 00108 #endif // SimTK_SimTKCOMMON_FORTRAN_H_