Scroll to navigation

FINDENT(1) User Commands FINDENT(1)

NAME

findent - Indents, converts and relabels Fortran programs.

SYNOPSIS

findent [OPTION]...

Findent reads from STDIN and writes to STDOUT.

DESCRIPTION

Findent indents and optionally relabels a Fortran source. Findent can convert from fixed form to free form and vice-versa, and can supplement single END statements, see 'Refactor' below. Comment lines with '!' in column one are not indented.
You can correct findent related indenting errors by inserting comment lines:
! findentfix: <fortran statement>
where <fortran statement> is for example DO, END, WHERE() etcetera. Findent will adjust the indentation according to <fortran statement>.
Errors in OPTIONS are silently ignored.
Options marked with [NO_ENV] are ignored if given via environment variable FINDENT_FLAGS.
In the long options, you can replace '_' with '-'.
Below: <n> denotes an unsigned decimal number.
<c> denotes a character.

General options:

print this text. [NO_ENV]
print man page. [NO_ENV]
print some background information. [NO_ENV]
print ChangeLog. [NO_ENV]
prints findent version. [NO_ENV]
guess free or fixed, prints 'fixed' or 'free' and exits. [NO_ENV]

' ': (default) do not change continuation characters.
'0': create numbered continuation characters.
other: use that continuation character.
default for conversion from free to fixed is '&'.
(0/1) 1: indent include statements to starting indent (default:0).
(0/1) 1: move statement labels to start of line.
(default: free: 1, fixed: 0)
prints computed indentation of last line.
(for usage with vim) [NO_ENV]
prints line number of last line usable.
as start for indenting(for usage with vim). [NO_ENV]
determine automatically input format (free or fixed).
force input format fixed (default: auto).
force input format free (default:auto).
do not change indent (useful in combination with -R).
use only first <n> characters of each line.
default=0: take whole lines.
same as above, but use gfortran convention.
for counting the characters with tabbed lines.
example: --input_line_length=72g.
maximum output indent, default 100, 0: no limit.
force fixed format output.
force free format output.
output format same is input format.
1/0: do/don't indent openmp conditionals (default: 1).
NOTE: for free format, the omp sentinel must be '!$ '.
refactor subroutines etc: the END line.
of a subroutine, program etc. is, if possible, replaced by
'end subroutine <name>' or
'end function <name>' or
'end procedure <name>' or
'end program <name>' or
'end block data <name>' or
'end module <name>' or
'end submodule <name>'
'end interface <name>'
'end type <name>'
where <name> is the name of the appropriate procedure, subroutine etc.
NOTE1: if the END line contains a continuation the results are undefined.
NOTE2: a line like 'end function fun' will be replaced by.
'end subroutine sub' if the END line ends 'subroutine sub'.
NOTE3: the flag --refactor_procedures is deprecated, use --refactor_end.
same as -Rr, but 'END SUBROUTINE <name>'. in stead of 'end subroutine <name>' etc.
shuffles existing labels,
primarily meant for demo and debugging.
see also the notes under --relabel below.
renumber labels: n1 = starting index,
n2 is increment (default:1000,10).
if n1=0 or n2=0, relabeling is disabled.
see also RELABEL below.
NOTE1: use only SYNTAX-CORRECT SOURCES with this option.
NOTE2: CHECK the functionality of your program after using this option.
NOTE3: after finding an error (missing label, ill formatted label list, ...)
findent will stop relabeling, but will continue indenting
and/or converting.
1: reset label numbering at start of subroutine/function/program. 0: do not reset label numbering (default: 0).
generate report. [NO_ENV]
n=0, or flag omitted: do not generate report.
n=1: generate summary (only error message or OK message).
n=2: generate report of original and renumbered labels (default).
NOTE: if n >= 0, no output of the fortran source.
replace redundant white space with one space.
n=0, or flag omitted: do not replace redundant spaces.
NOTE1: use with care, avoid pieces of code with not terminated
strings and use Fortran code without syntax errors:
changes are irreversible.
NOTE2: for statements containing an hollerith, this flag is ignored.
ignore next flags marked with [NO_ENV] (used by wfindent).

Indenting options:

starting indent (default:0).
determine starting indent from first line.
all indents except I,c,C,e (default: 3).
ASSOCIATE indent.
BLOCK indent.
DO indent.
IF indent.
ENUM indent.
FORALL indent.
INTERFACE indent.
MODULE indent.
FUNCTION,
SUBROUTINE and PROGRAM indent.
SELECT indent.
TYPE indent.
WHERE indent.
CRITICAL indent.
CHANGE TEAM indent.
restart indent after CONTAINS.
continuation indent except
for lines starting with '&' (see flag -K).
NOTE: free to free only.
continuation lines not preceded
by '&' are untouched.
NOTE: free to free only.
continuation lines not preceded
by '&' are default indented.
NOTE: free to free only.
indent lines starting with '&' (free only).
align continuation lines not preceded
by '&' with preceding unmatched left parenthesis.
n=0, or flag omitted: do not align.
n=1: do align (default).
NOTE1: free to free only.
NOTE1: for statements containing an hollerith, this flag is ignored.
Next defaults are: all - all/2.
CASE negative indent.
NOTE: also for RANK, TYPEIS and CLASSIS.
CONTAINS negative indent.
ENTRY negative indent.

Dependencies:

output dependency information only, other flags are ignored. [NO_ENV]
This can be used to generate a dependencies file for usage with make(1).
The format of this information:
Fortran source -> findent output
include "file1" -> inc file1
#include "file2" -> cpp file2
#include <file3> -> std file3
??include 'file4' -> coc file4
use module1 -> use module1
submodule(m) subm -> use m
mod m:subm
module module2 -> mod module2
outputs a sh(1) script that serves as a an example
to generate dependencies for use in make(1). [NO_ENV]

Environment:

findent parses the environment variable FINDENT_FLAGS before the command-line flags.

Usage with vim:

outputs directions to use findent in (g)vim. [NO_ENV]
outputs file 'fortran.vim', see --vim_help. [NO_ENV]
outputs file 'findent.vim', see --vim_help. [NO_ENV]

Usage with gedit:

outputs directions to use findent in gedit. [NO_ENV]
outputs script 'findent-gedit', see --gedit_help. [NO_ENV]
outputs file 'findent.plugin', see --gedit_help. [NO_ENV]
outputs file 'python.py', see --gedit_help. [NO_ENV]

Usage with emacs:

outputs directions to use findent in emacs. [NO_ENV]
outputs script 'findent.el', see --emacs_help. [NO_ENV]

Self replication:

outputs source tar ball to stdout [NO_ENV]
Example: create the tar.gz file:
findent --selfrep > findent.tar.gz
Example: create the unpacked source tar ball:
findent --selfrep | tar zxf -

RELABEL:

The following constructs are candidates for relabeling:
- 100,110,120,130: label
- X: integer or real or logical expression
- I: identifier
- [,]: optional comma
- ...: not parsed by findent, can be anything except '=...'
- [IF]: optional IF(...)


100 ... ! statement or format label
IF(...) 110,120,130
IF(...) 110,120
DO 100[,] I=X,...
DO 100[,] WHILE(...)
DO 100[,] CONCURRENT(...)
DO 100
[IF] ACCEPT 100...
[IF] ASSIGN 100 TO I
[IF] BACKSPACE(...,ERR=100,...)
[IF] CALL I(...,*100,...,$110,...,&120,...)
[IF] CLOSE(...,ERR=100,...)
[IF] DECODE(...,100,...,ERR=110,...)
[IF] DELETE(...,ERR=110,...)
[IF] ENCODE(...,100,...,ERR=110,...)
[IF] ENDFILE(...,ERR=100,...)
[IF] FIND(...,ERR=110,...)
[IF] FLUSH(...,ERR=100,...)
[IF] GOTO 100
[IF] GOTO I[,](100,110,120)
[IF] GOTO(100,110,120)...
[IF] INQUIRE(...,ERR=100,...)
[IF] OPEN(...,ERR=100,...)
[IF] PRINT 100...
[IF] READ 100...
[IF] READ(...,100,...)
[IF] READ(...,ERR=100,...,END=110,EOR=120,...,FMT=130)...
[IF] REREAD 100...
[IF] REREAD(...,100,...)
[IF] REREAD(...,ERR=100,...,END=110,EOR=120,...,FMT=130)...
[IF] REWIND(...,ERR=100,...)
[IF] REWRITE(...,100) ...
[IF] REWRITE(...,ERR=100,...,FMT=110,...,EOR=120)...
[IF] TYPE 100...
[IF] WAIT(...,ERR=100,...,END=110,...,EOR=120,...)
[IF] WRITE(...,100) ...
[IF] WRITE(...,ERR=100,...,FMT=110,...,EOR=120)...

Examples:

Indent: findent < in.f > out.f
findent -i2 -r0 < in.f > out.f

Relabel: findent --relabel < in.f > out.f

Convert fixed to free form: findent -ofree < prog.f > prog.f90

Convert free to fixed form: findent -ofixed < prog.f90 > prog.f

Refactor 'end': findent -Rr < in.f90 > out.f90

BUGS:

*
Also for free-format, findent is space-insensitive, while the standard states that space must be used as general separator.

*
There are some issues with labels in a continuation when converting from free to fixed format. For example:

123&
4 continue

The problems arise because it is not possible to define a statement label in a continuation in fixed format.

*
When converting from fixed format to free format, findent discards white space in a string if the string contains a continuation, e.g:
print *,"a
+b"

is converted to:
print *,"a&
&b"

*
Relabel issues
In some cases, findent refuses to relabel.
To see the cause, use the flag '--query-relabel=1', e.g.:
findent --relabel=10,10 --query-relabel=1
If the fortran source contains label-related errors, or when findent misbehaves, relabeling can create havoc. So: test.

DONATIONS

Donations to support the maintenance of this program are welcome: https://paypal.me/wvermin

COPYRIGHT

This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2023 findent-4.3.2