Introduction
Codee offers automatic formatting for Fortran source code using the codee format
command.
Installation
Please refer to the Codee Installation Guide
for platform-specific instructions. Note that no license is required to use
codee format
.
Standalone tool
Usage example
The codee format
command formats free-form Fortran files with the following
extensions: .f90
, .f95
, .f03
, .f08
, .f18
.
Consider the following Fortran code:
subroutine grid_pressure_velocity_calc(p,v)
implicit none
integer i, j
real(kind=8) :: dx, dy, p(:,:), v(:,:)
dx = 1.0d-3
dy = 1.0d-3
do j = 1, size(p, 1)
do i = 1,size(p, 2)
p(i,j)=dx*dy*real(i*j,kind=8)
v(i,j)=p(i,j)/(dx+dy)
end do
enddo
call update_boundary_conditions(p,v)
endsubroutine
By simply running the following command:
$ codee format code.f90
Codee will adjust the code indentation, spacing, and other style elements, such
as keywords or the ::
separator:
subroutine grid_pressure_velocity_calc(p, v)
implicit none
integer :: i, j
real(kind=8) :: dx, dy, p(:, :), v(:, :)
dx = 1.0d-3
dy = 1.0d-3
do j = 1, size(p, 1)
do i = 1, size(p, 2)
p(i, j) = dx * dy * real(i * j, kind=8)
v(i, j) = p(i, j) / (dx + dy)
end do
end do
call update_boundary_conditions(p, v)
end subroutine grid_pressure_velocity_calc
Codee can also format entire directories and all contained files by specifying the directory:
$ codee format my-directory
Configuring the style
You can customize the formatting style of codee format
using the --style
option, or by creating a .codee-format
file and using the --config
option.
The --style
option will take precedence over the configuration file:
$ codee format --style "{IndentSize: 2, ColumnLimit: 80}" code.f90
A simple way to create a custom .codee-format
file for your project is to
start with the default configuration:
$ codee format --dump-preset-config default > .codee-format
The configuration file uses a YAML format. It presents a list of configurable options, each accepting different values:
Casing:
Identifiers: Preserve
Keywords: Lowercase
LogicalConstants: Lowercase
LogicalOperators: Lowercase
RelationalOperators: Lowercase
ColumnLimit: 100
IndentSize: 2
...
For a complete list of available options, refer to the Style Options Documentation.
Additional help
Don't forget to run codee format --help
to explore all the options available!
Integrations with other tools
You can find detailed step-by-step guides for integrating Codee format with various tools at the integration section.