GMIN SANITY module

From Docswiki
Revision as of 17:22, 10 May 2019 by Adk44 (talk | contribs) (Created page with "==Introduction== The GMIN SANITY module is intended to contain basic sanity check functions which can be used to help us check that we aren't doing anything stupid - for e...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The GMIN SANITY module is intended to contain basic sanity check functions which can be used to help us check that we aren't doing anything stupid - for example trying to make a Cartesian displacement in an angle-axis system. You can find it here:

~/svn/GMIN/source/sanity.f90

It contains functions which return .TRUE. if the test is passed, and as a result should be called as follows:

! Sanity check - are the coordinates in XYZ Cartesian? 
! Check if the SIZE is a multiple of 3
   TEST=.FALSE.
   TEST=CHECK_DIMENSION(SIZE(XYZ),3)
   IF (.NOT.TEST) THEN
      STOP 'Coordinates in a non-Cartesian basis passed to ROTATION_ABOUT_AXIS'
   ENDIF

In this way, we can print helpful error messages from the routines where the check fails to aid in debugging problems, without having to recode the entire check each time.

Coding principles

Error creating thumbnail: Unable to save thumbnail to destination
A useful way of thinking while coding

In order to make these checks as easy to use as possible, you must adhere to a few basic coding principles when adding such checks

  • all check functions must return .TRUE. if the check is passed
  • code blocks must be indented in a manner consistent with the rest of the module (3 spaces)
  • variable names must be understandable e.g. MAX_STEP rather than S
  • avoid using GOTOs!
  • all functions must be fully commented (in English)
  • all arguments must be fully explained
  • check functions should NOT print anything - printing should come from where the function is called. See the example call above - printing is done within the STOP command if the check fails.

Example: CHECK_DIMENSION

The call above comes from the GMIN MOVES module. We are using CHECK_DIMENSION to make sure that the coordinate array XYZ being used for moves assuming a Cartesian basis are indeed Cartesian:

FUNCTION CHECK_DIMENSION(ARRAYSIZE, EXPECTED)
! Function to check the dimension of the ARRAY passed in.
! Returns .TRUE. if the dimension is as EXPECTED.
!
! Arguments:
! 
! ARRAYSIZE: The size of the array to be checked
! EXPECTED: The expected dimension of the ARRAY
   IMPLICIT NONE
   INTEGER, INTENT(IN) :: EXPECTED
   INTEGER, INTENT(IN) :: ARRAYSIZE
   LOGICAL             :: CHECK_DIMENSION

   CHECK_DIMENSION=.FALSE.

   IF (MODULO(ARRAYSIZE, EXPECTED) == 0) THEN
      CHECK_DIMENSION=.TRUE.
   ENDIF
END FUNCTION

--Csw34 17:25, 14 April 2014 (UTC)