Simbody  3.5
Fortran.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_FORTRAN_H_
2 #define SimTK_SimTKCOMMON_FORTRAN_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2006-12 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
34 // Although we are currently triggering this off the OS, these
35 // really are compiler dependencies.
36 // (1) The calling convention (__stdcall for Windows)
37 // (2) Name capitalization (either all-lower or all-uppercase)
38 // (3) Is a trailing underscore added to the name?
39 // (4) And ugliest, Fortran passes string lengths as a hidden
40 // value parameter. On some compilers, that length follows
41 // the string immediately. On others, all the lengths
42 // appear at the end of the argument list, in the same
43 // order as the strings to which they correspond.
44 // Point (4) requires four ugly macros to be used, two in declarations
45 // and two in calls to Fortran routines. One macro appears immediately
46 // after each string, and the other appears at the end of the argument
47 // list, repeated as many times as necessary. One or the other will
48 // evaluate to nothing.
49 
50 // These macros should be used for whatever the expected default
51 // Fortran behavior is for whatever Fortran is typically used in
52 // conjunction with the current C++ compiler.
53 #ifdef _WIN32
54  #define SimTK_FORTRAN_STDCALL __stdcall
55  #define SimTK_FORTRAN(x,X) X
56  #define SimTK_FORTRAN_STRLEN_FOLLOWS_DECL ,int
57  #define SimTK_FORTRAN_STRLEN_FOLLOWS_CALL(n) ,n
58  #define SimTK_FORTRAN_STRLEN_ATEND_DECL // nothing
59  #define SimTK_FORTRAN_STRLEN_ATEND_CALL(n)
60 #else
61  #define SimTK_FORTRAN_STDCALL
62  #define SimTK_FORTRAN(x,X) x ## _
63  #define SimTK_FORTRAN_STRLEN_FOLLOWS_DECL // nothing
64  #define SimTK_FORTRAN_STRLEN_FOLLOWS_CALL(n)
65  #define SimTK_FORTRAN_STRLEN_ATEND_DECL ,int
66  #define SimTK_FORTRAN_STRLEN_ATEND_CALL(n) ,n
67 #endif
68 
69 // These macros should be used for whatever our chosen LAPACK and
70 // BLAS libraries will look like from here.
71 #ifdef SimTK_USE_ACML_LAPACK
72  #ifdef _WIN32
73  #define SimTK_LAPACK_STDCALL __stdcall
74  #define SimTK_LAPACK(x,X) X
75  #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL ,int
76  #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n) ,n
77  #define SimTK_LAPACK_STRLEN_ATEND_DECL // nothing
78  #define SimTK_LAPACK_STRLEN_ATEND_CALL(n)
79  #else
80  #define SimTK_LAPACK_STDCALL
81  #define SimTK_LAPACK(x,X) x ## _
82  #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL // nothing
83  #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n)
84  #define SimTK_LAPACK_STRLEN_ATEND_DECL ,int
85  #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) ,n
86  #endif
87 #else // default assumes we're using libSimTKlapack
88  #define SimTK_LAPACK_STDCALL
89  #define SimTK_LAPACK(x,X) x ## _
90  #define SimTK_LAPACK_STRLEN_FOLLOWS_DECL // nothing
91  #define SimTK_LAPACK_STRLEN_FOLLOWS_CALL(n)
92  #define SimTK_LAPACK_STRLEN_ATEND_DECL ,int
93  #define SimTK_LAPACK_STRLEN_ATEND_CALL(n) ,n
94 #endif
95 
96 // TODO: Currently this is unused and may not be needed anymore.
97 // Call these routines to intialize the GNU Fortran RTL.
98 //
99 
100 #ifdef USING_G77
101  extern "C" {
102  void f_setsig();
103  void f_init();
104  }
105  #define SimTK_FORTRAN_INIT do {f_setsig(); f_init();} while(false)
106 #endif
107 
108 #endif // SimTK_SimTKCOMMON_FORTRAN_H_