Documentation for OpenFLUID
2.2.0
FortranCPP.hpp
Go to the documentation of this file.
1
/*
2
3
This file is part of OpenFLUID software
4
Copyright(c) 2007, INRA - Montpellier SupAgro
5
6
7
== GNU General Public License Usage ==
8
9
OpenFLUID is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
OpenFLUID is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23
== Other Usage ==
24
25
Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26
license, and requires a written agreement between You and INRA.
27
Licensees for Other Usage of OpenFLUID may use this file in accordance
28
with the terms contained in the written agreement between You and INRA.
29
30
*/
31
32
/**
33
@file FortranCPP.hpp
34
35
@author Jean-Christophe Fabre <jean-christophe.fabre@inra.fr>
36
37
38
@see http://www-h.eng.cam.ac.uk/help/tpl/languages/mixinglanguages.html
39
@see http://www.neurophys.wisc.edu/comp/docs/notes/not017.html
40
@see http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html
41
@see http://arnholm.org/software/cppf77/cppf77.htm
42
@see http://www.aei.mpg.de/~jthorn/c2f.html
43
44
Below are examples of C++ simulators calling Fortran subroutines.
45
46
47
Fortran source code:
48
@include wares/FortranMoreSubr.f90
49
50
51
Declaration of Fortran subroutines to call (In C++ code):
52
@snippet wares/FortranMoreSim.cpp fortran_decl
53
54
55
Use of Fortran subroutines tFrom C++ code:
56
@snippet wares/FortranMoreSim.cpp fortran_use
57
58
59
@cond OpenFLUID:completion
60
{
61
"contexts" : ["SIMULATOR", "OBSERVER"],
62
"menupath" : ["Fortran integration"],
63
"title" : "Include FortranCPP header",
64
"text" : "#include <openfluid/tools/FortranCPP.hpp>"
65
}
66
@endcond
67
*/
68
69
70
#ifndef __OPENFLUID_TOOLS_FORTRANCPP_HPP__
71
#define __OPENFLUID_TOOLS_FORTRANCPP_HPP__
72
73
/**
74
@cond OpenFLUID:completion
75
{
76
"contexts" : ["SIMULATOR", "OBSERVER"],
77
"menupath" : ["Fortran integration", "Declaration of external code"],
78
"title" : "Declaration block",
79
"text" : "BEGIN_EXTERN_FORTRAN\n%%CURSOR%%\nEND_EXTERN_FORTRAN"
80
}
81
@endcond
82
83
@cond OpenFLUID:completion
84
{
85
"contexts" : ["SIMULATOR", "OBSERVER"],
86
"menupath" : ["Fortran integration", "Declaration of external code"],
87
"title" : "Beginning of declaration block",
88
"text" : "BEGIN_EXTERN_FORTRAN"
89
}
90
@endcond
91
92
@cond OpenFLUID:completion
93
{
94
"contexts" : ["SIMULATOR", "OBSERVER"],
95
"menupath" : ["Fortran integration", "Declaration of external code"],
96
"title" : "End of declaration block",
97
"text" : "END_EXTERN_FORTRAN"
98
}
99
@endcond
100
*/
101
#ifdef __cplusplus
102
# define BEGIN_EXTERN_FORTRAN \
103
extern "C"
\
104
{
105
# define END_EXTERN_FORTRAN }
106
#else
107
# define BEGIN_EXTERN_FORTRAN
108
# define END_EXTERN_FORTRAN
109
#endif
110
111
112
// =====================================================================
113
// =====================================================================
114
115
116
// calling function or subroutine from a F90 module
117
118
/**
119
Macro for declaration of an external fortran function
120
@param[in] x the name of the function
121
122
@cond OpenFLUID:completion
123
{
124
"contexts" : ["SIMULATOR", "OBSERVER"],
125
"menupath" : ["Fortran integration", "Declaration of external code", "Fortran"],
126
"title" : "Declare function",
127
"text" : "EXTERN_FFUNCTION(%%SEL_START%%Name%%SEL_END%%)(%%CMT_START%%parameters%%CMT_END%%)"
128
}
129
@endcond
130
*/
131
#define EXTERN_FFUNCTION(x) x##_
132
133
/**
134
Macro for calling an external fortran function
135
@param[in] x the name of the function
136
137
@cond OpenFLUID:completion
138
{
139
"contexts" : ["SIMULATOR", "OBSERVER"],
140
"menupath" : ["Fortran integration", "Call of external code", "Fortran"],
141
"title" : "Call function",
142
"text" : "CALL_FFUNCTION(%%SEL_START%%Name%%SEL_END%%)(parameters)"
143
}
144
@endcond
145
*/
146
#define CALL_FFUNCTION(x) x##_
147
148
/**
149
Macro for declaration of an external fortran subroutine
150
@param[in] x the name of the subroutine
151
152
@cond OpenFLUID:completion
153
{
154
"contexts" : ["SIMULATOR", "OBSERVER"],
155
"menupath" : ["Fortran integration", "Declaration of external code", "Fortran"],
156
"title" : "Declare subroutine",
157
"text" : "EXTERN_FSUBROUTINE(%%SEL_START%%Name%%SEL_END%%)(parameters)"
158
}
159
@endcond
160
*/
161
#define EXTERN_FSUBROUTINE(x) void x##_
162
163
/**
164
Macro for calling an external fortran subroutine
165
@param[in] x the name of the subroutine
166
167
168
@cond OpenFLUID:completion
169
{
170
"contexts" : ["SIMULATOR", "OBSERVER"],
171
"menupath" : ["Fortran integration", "Call of external code", "Fortran"],
172
"title" : "Call subroutine",
173
"text" : "CALL_FSUBROUTINE(%%SEL_START%%Name%%SEL_END%%)(parameters)"
174
}
175
@endcond
176
*/
177
#define CALL_FSUBROUTINE(x) x##_
178
179
180
// =====================================================================
181
// =====================================================================
182
183
184
/**
185
Macro for declaration of an external fortran90 function in a module
186
@param[in] x the name of the module
187
@param[in] y the name of the function
188
189
@cond OpenFLUID:completion
190
{
191
"contexts" : ["SIMULATOR", "OBSERVER"],
192
"menupath" : ["Fortran integration", "Declaration of external code", "Fortran90"],
193
"title" : "Declare function in module",
194
"text" : "EXTERN_FMODFUNCTION(%%SEL_START%%Module%%SEL_END%%,Name)(parameters)"
195
}
196
@endcond
197
*/
198
#define EXTERN_FMODFUNCTION(x,y) __##x##_MOD_##y
199
200
/**
201
Macro for calling an external fortran90 function in a module
202
@param[in] x the name of the module
203
@param[in] y the name of the function
204
205
@cond OpenFLUID:completion
206
{
207
"contexts" : ["SIMULATOR", "OBSERVER"],
208
"menupath" : ["Fortran integration", "Call of external code", "Fortran90"],
209
"title" : "Call function in module",
210
"text" : "CALL_FMODFUNCTION(%%SEL_START%%Module%%SEL_END%%,Name)(parameters)"
211
}
212
@endcond
213
*/
214
#define CALL_FMODFUNCTION(x,y) __##x##_MOD_##y
215
216
/**
217
Macro for declaration of an external fortran90 subroutine in a module
218
@param[in] x the name of the module
219
@param[in] y the name of the subroutine
220
221
@cond OpenFLUID:completion
222
{
223
"contexts" : ["SIMULATOR", "OBSERVER"],
224
"menupath" : ["Fortran integration", "Declaration of external code", "Fortran90"],
225
"title" : "Declare subroutine in module",
226
"text" : "EXTERN_FMODSUBROUTINE(%%SEL_START%%Module%%SEL_END%%,Name)(parameters)"
227
}
228
@endcond
229
*/
230
#define EXTERN_FMODSUBROUTINE(x,y) void __##x##_MOD_##y
231
232
/**
233
Macro for calling an external fortran90 subroutine in a module
234
@param[in] x the name of the module
235
@param[in] y the name of the subroutine
236
237
@cond OpenFLUID:completion
238
{
239
"contexts" : ["SIMULATOR", "OBSERVER"],
240
"menupath" : ["Fortran integration", "Call of external code", "Fortran90"],
241
"title" : "Call subroutine in module",
242
"text" : "CALL_FMODSUBROUTINE(%%SEL_START%%Module%%SEL_END%%,Name)(parameters)"
243
}
244
@endcond
245
*/
246
#define CALL_FMODSUBROUTINE(x,y) __##x##_MOD_##y
247
248
249
// =====================================================================
250
// =====================================================================
251
252
253
// Numeric data handling
254
255
/**
256
Macro for fortran REAL type in C++ (float)
257
258
@cond OpenFLUID:completion
259
{
260
"contexts" : ["SIMULATOR", "OBSERVER"],
261
"menupath" : ["Fortran integration", "Types"],
262
"title" : "Single precision float",
263
"text" : "FREAL %%SEL_START%%Val%%SEL_END%%"
264
}
265
@endcond
266
*/
267
#define FREAL float
268
269
/**
270
Macro for fortran REAL type in C++ (double)
271
272
@cond OpenFLUID:completion
273
{
274
"contexts" : ["SIMULATOR", "OBSERVER"],
275
"menupath" : ["Fortran integration", "Types"],
276
"title" : "Double precision float",
277
"text" : "FREAL8 %%SEL_START%%Val%%SEL_END%%"
278
}
279
@endcond
280
*/
281
#define FREAL8 double
282
283
/**
284
@cond OpenFLUID:completion
285
{
286
"contexts" : ["SIMULATOR", "OBSERVER"],
287
"menupath" : ["Fortran integration", "Types"],
288
"title" : "Double double precision float",
289
"text" : "FREAL16 %%SEL_START%%Val%%SEL_END%%"
290
}
291
@endcond
292
*/
293
#define FREAL16 long double
294
295
/**
296
Macro for fortran INT type in C++ (int)
297
298
@cond OpenFLUID:completion
299
{
300
"contexts" : ["SIMULATOR", "OBSERVER"],
301
"menupath" : ["Fortran integration", "Types"],
302
"title" : "Integer",
303
"text" : "FINT %%SEL_START%%Val%%SEL_END%%"
304
}
305
@endcond
306
*/
307
#define FINT int
308
309
/**
310
Macro for fortran INT*2 type in C++ (short int)
311
312
@cond OpenFLUID:completion
313
{
314
"contexts" : ["SIMULATOR", "OBSERVER"],
315
"menupath" : ["Fortran integration", "Types"],
316
"title" : "Short integer",
317
"text" : "FINT2 %%SEL_START%%Val%%SEL_END%%"
318
}
319
@endcond
320
*/
321
#define FINT2 short int
322
323
/**
324
Macro for fortran INT*8 type in C++ (long int)
325
326
@cond OpenFLUID:completion
327
{
328
"contexts" : ["SIMULATOR", "OBSERVER"],
329
"menupath" : ["Fortran integration", "Types"],
330
"title" : "Long integer",
331
"text" : "FINT8 %%SEL_START%%Val%%SEL_END%%"
332
}
333
@endcond
334
*/
335
#define FINT8 long int
336
337
338
/**
339
@cond OpenFLUID:completion
340
{
341
"contexts" : ["SIMULATOR", "OBSERVER"],
342
"menupath" : ["Fortran integration", "Types"],
343
"title" : "Logical",
344
"text" : "FLOGICAL %%SEL_START%%Val%%SEL_END%%"
345
}
346
@endcond
347
*/
348
#define FLOGICAL int
349
350
/**
351
@cond OpenFLUID:completion
352
{
353
"contexts" : ["SIMULATOR", "OBSERVER"],
354
"menupath" : ["Fortran integration", "Types"],
355
"title" : "Logical (boolean)",
356
"text" : "FLOGICAL1 %%SEL_START%%Val%%SEL_END%%"
357
}
358
@endcond
359
*/
360
#define FLOGICAL1 bool
361
362
363
// =====================================================================
364
// =====================================================================
365
366
367
// Character and string handling
368
369
/**
370
@cond OpenFLUID:completion
371
{
372
"contexts" : ["SIMULATOR", "OBSERVER"],
373
"menupath" : ["Fortran integration", "Types"],
374
"title" : "Character",
375
"text" : "FCHARACTER %%SEL_START%%Val%%SEL_END%%"
376
}
377
@endcond
378
*/
379
#define FCHARACTER char
380
381
/**
382
@cond OpenFLUID:completion
383
{
384
"contexts" : ["SIMULATOR", "OBSERVER"],
385
"menupath" : ["Fortran integration", "Types"],
386
"title" : "String",
387
"text" : "FSTRING %%SEL_START%%Val%%SEL_END%%"
388
}
389
@endcond
390
*/
391
#define FSTRING char*
392
393
/**
394
@cond OpenFLUID:completion
395
{
396
"contexts" : ["SIMULATOR", "OBSERVER"],
397
"menupath" : ["Fortran integration", "Types"],
398
"title" : "String length",
399
"text" : "FSTRINGLEN %%SEL_START%%Val%%SEL_END%%"
400
}
401
@endcond
402
*/
403
#define FSTRINGLEN int
404
405
406
// =====================================================================
407
// =====================================================================
408
409
410
// Conversion of std::string
411
412
/**
413
@cond OpenFLUID:completion
414
{
415
"contexts" : ["SIMULATOR", "OBSERVER"],
416
"menupath" : ["Fortran integration", "Functions"],
417
"title" : "Convert std::string to Fortran string content",
418
"text" : "STD2FSTRING(%%SEL_START%%str%%SEL_END%%)"
419
}
420
@endcond
421
*/
422
#define STD2FSTRING(str) (strdup((str).c_str()))
423
424
/**
425
@cond OpenFLUID:completion
426
{
427
"contexts" : ["SIMULATOR", "OBSERVER"],
428
"menupath" : ["Fortran integration", "Functions"],
429
"title" : "Convert std::string to Fortran string length",
430
"text" : "STD2FSTRINGLEN(%%SEL_START%%str%%SEL_END%%)"
431
}
432
@endcond
433
*/
434
#define STD2FSTRINGLEN(str) (strlen((str).c_str()))
435
436
/**
437
@cond OpenFLUID:completion
438
{
439
"contexts" : ["SIMULATOR", "OBSERVER"],
440
"menupath" : ["Fortran integration", "Functions"],
441
"title" : "Convert std::string to Fortran string content and length",
442
"text" : "STD2FSTRINGFULL(%%SEL_START%%str%%SEL_END%%)"
443
}
444
@endcond
445
*/
446
#define STD2FSTRINGFULL(str) (strdup((str).c_str()),strlen((str).c_str()))
447
448
449
#endif
/* __OPENFLUID_TOOLS_FORTRANCPP_HPP__ */
450
tools
FortranCPP.hpp
Generated by
1.9.1