The CONTAINS statement separates the body of a main program, external subprogram, or module subprogram from any internal subprograms that it may contain. Similarly, it separates the specification part of a module from any module subprograms.
For a CONTAINS statement associated with subprograms, the following rules apply:
MODULE A ... CONTAINS ! Module subprogram must follow SUBROUTINE B(X) ... CONTAINS ! Internal subprogram must follow FUNCTION C(Y) ... END FUNCTION END SUBROUTINE END MODULE