Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Basics
- 3 Short introduction to Linux
- 4 Interpolation
- 5 Taking derivatives
- 6 Numerical integration
- 7 Solution of nonlinear equations
- 8 Differential equations
- 9 Matrices
- 10 Random processes and Monte Carlo simulation
- References
- Appendix A The ROOT system
- Appendix B Free scientific libraries
- Appendix C FORTRAN and C++
- Appendix D Program listings
- Index
Appendix C - FORTRAN and C++
Published online by Cambridge University Press: 04 August 2010
- Frontmatter
- Contents
- Preface
- 1 Introduction
- 2 Basics
- 3 Short introduction to Linux
- 4 Interpolation
- 5 Taking derivatives
- 6 Numerical integration
- 7 Solution of nonlinear equations
- 8 Differential equations
- 9 Matrices
- 10 Random processes and Monte Carlo simulation
- References
- Appendix A The ROOT system
- Appendix B Free scientific libraries
- Appendix C FORTRAN and C++
- Appendix D Program listings
- Index
Summary
Before we can discuss how to call FORTRAN functions from C++, we need first to look at some of the differences.
The most important difference is that FORTRAN passes variables by reference, while C++, like C, passes by value. This in turn means that any FORTRAN routine expects to get a reference, so you have to make sure your program passes the variables appropriately.
When you use arrays in your program, you have to take into account that the first array element in FORTRAN is a(1), while in C++ it would be a[0]. Multi-dimensional arrays are stored differently in memory. Array A(3,5) in FORTRAN would be A(1,1), A(2,1), A(3,1), A(1,2), while in C++ the corresponding arrangement would be A(0,0), A(0,1), A(0,2), A(0,3), A(0,4), A(1,0) and so on.
C++ is a strongly typed language; if you do not define a variable your program will not compile. FORTRAN has by default an implicit type convention: any variable which starts with letters i through n is an integer, while any other variable is a real variable. Unless the programmer has used the “implicit none” statement any FORTRAN compiler will adhere to the standards.
FORTRAN is case insensitive, while C++ clearly distinguishes between Dummy and dummy.
[…]
- Type
- Chapter
- Information
- Introductory Computational Physics , pp. 119 - 120Publisher: Cambridge University PressPrint publication year: 2006