scitools.com

← Metric catalog

Program Units is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Program Units

API ID: CountDeclProgUnit
Languages: Fortran
Targets: Architectures, Files, Project

Number of non-nested modules, block data units, and subprograms.

Only counts program units declared directly in the file — a subprogram nested inside a module's own CONTAINS section doesn't add to this total, even though the module itself does.

For example:


MODULE sample_mod
  IMPLICIT NONE
CONTAINS
  SUBROUTINE mod_internal_sub(x)
    INTEGER, INTENT(IN) :: x
    PRINT *, x
  END SUBROUTINE mod_internal_sub
END MODULE sample_mod


SUBROUTINE ext_sub(x)
  INTEGER, INTENT(IN) :: x
  PRINT *, x
END SUBROUTINE ext_sub


FUNCTION ext_func(x) RESULT(y)
  INTEGER, INTENT(IN) :: x
  INTEGER :: y
  y = x + 1
END FUNCTION ext_func


PROGRAM sample
  USE sample_mod
  IMPLICIT NONE
  INTEGER :: ext_func
  CALL mod_internal_sub(1)
  CALL ext_sub(2)
  PRINT *, ext_func(3)
END PROGRAM sample

sample.f90 declares four non-nested program units: the module sample_mod, the external subroutine ext_sub, the external function ext_func, and the main program sample — so CountDeclProgUnit = 4. mod_internal_sub, nested inside sample_mod's CONTAINS section, doesn't add to this count, though it does count toward Subprograms (which, for Fortran, counts subroutines and functions wherever they're declared, nested or not, but not the enclosing module itself).

See Modules for just the module count.

Targets By Language: Configuration: