Constants in Co-array Fortran
Constants are values that do not change. They can be character strings, boolean values, or numeric values.
Here’s an example:
Explanation
parameter
Declarations: Here, constants are declared using theparameter
attribute.s
is a character string constant.n
is an integer constant.d
is a real constant computed as3e20 / n
.
Printing Constants: The program uses the
print
statement to output each constant.
Running the Program
To compile and run the Fortran program:
Precision Note
In Fortran, you can use arbitrary precision for constant expressions. Constants do not have a type until explicitly given one, e.g., by using them in a context that requires a specific type. Here, int(d, 8)
converts the real constant d
to an integer.
Intrinsic Functions
For demonstration, a dummy sin
function is provided. Replace this with the Fortran intrinsic sin
function for practical usage.
Now that you understand constants in Fortran, let’s delve deeper into other language features.