Variables in Co-array Fortran
Our first example demonstrates how to declare and use variables in Co-array Fortran. Variables are explicitly declared and used by the compiler to check type-correctness of operations.
To run the program, save it as variables.f90
and compile it using a Co-array Fortran compiler:
Let’s break down the key points:
In Co-array Fortran, we use
implicit none
to ensure all variables are explicitly declared.Variables are declared with their type and, optionally, their initial value.
For character variables, we need to specify the length using
character(len=X)
.Multiple variables of the same type can be declared and initialized in a single line.
Logical variables use
.true.
and.false.
for boolean values.Variables declared without initialization are automatically zero-valued (or the equivalent for their type).
Co-array Fortran doesn’t have a shorthand syntax for variable declaration and initialization like Go’s
:=
. We always use the full declaration.The
print *
statement is used for output, similar to Go’sfmt.Println
.
Co-array Fortran has strong typing and requires explicit variable declarations, which helps catch errors at compile-time and makes the code more self-documenting.