Clone wiki

ug3 / coding

Coding style guide

When writing fortran code for ug3 and while setting up the user.fpp file, please follow these instructions.

  • Look at the ug3 files to learn about the coding style.
  • Do not use tab anywhere in the code, use spaces.
  • Indent code for better readability.
  • Indent by 3 spaces.
  • Do not exceed 80 columns, though this is not strictly necessary.
  • Do not put blank space at the end of a line.
  • Try to use small variable names if possible.
  • Do not use common block.
  • Always use implicit none in every function/subroutine.
  • Do not leave unused variables, unless they are part of standard subroutine arguments.
  • Check all warnings given by compiler and fix them.
  • When printing to screen, do it only on rank=0 process, unless there is a specific reason to print from every process.
  • Do not use stop since this is a parallel program; use the abort0 and abort1 functions which cleanly aborts the program.
  • Use == instead of .eq. and similarly for other comparison operators.
  • Put space between comparison operators, e.g. if(nproc == 1).
  • Put space between addition/subtraction a = b + c
  • Put space between arguments to subroutine/function call foo(x, y, z)
  • Dont put space in enddo and endif.
  • Do not use too many brackets, unless you want to order the computations.