INTERFACE / PUBLIC COMPONENTS / NAMELIST / FILES / REFERENCES / ERRORS / BUGS / PLANS / PRIVATE COMPONENTS

MODULE utilities_mod

Contact: Jeff Anderson
Reviewers:  
Revision: $Revision: 1.2 $
Release Name: $Name: pre_hawaii $
Change Date: $Date: 2004/12/22 20:48:13 $
Change history: see CVS log

OVERVIEW

Provides a number of tools used by most DART modules including tools for file IO, diagnostic tools for registering modules and recording namelist arguments, and and error handler.




OTHER MODULES USED

types_mod



PUBLIC INTERFACE

use utilities, only : file_exist
 get_unit
 check_nml_error
 open_file
 timestamp
 close_file
 register_module
 error_handler
 logfileunit
 initialize_utilities
 finalize_utilities
 dump_unit_attributes
 E_DBG, DEGUG
 E_MSG, MESSAGE
 E_WARN, WARNING
 E_ERR, FATAL

NOTES

Optional namelist interface &utilities_nml may be read from file input.nml.




PUBLIC COMPONENTS



var = file_exist(file_name)
 logical                      :: file_exist
 character(len=*), intent(in) :: file_name
 

Description

Returns true if file_name exists in the working directory, else false.

file_exist    True if file_name exists in working directory.
file_name    Name of file to look for.


var = get_unit()
 integer :: get_unit
 

Description

Returns an unused unit number for IO.

get_unit    An unused unit number.


var = check_nml_error(iostat, nml_name)
 integer                      :: check_nml_error
 integer, intent(in)          :: iostat
 character(len=*), intent(in) :: nml_name
 

Description

Given the iostat variable from a namelist read and the name of the namelist, makes sure that the iostat is an acceptable value. If not, generates a call to the error handler.

check_nml_error    Returned error code (same as iostat input).
iostat    Input error code from a namelist read.
nml_name    Name of the namelist that was read.


var = open_file(fname [, form, action])
 integer                                :: open_file
 character(len=*), intent(in)           :: fname
 character(len=*), optional, intent(in) :: form
 character(len=*), optional, intent(in) :: action
 

Description

Returns a unit number that is opened to the file fname. If form is not present or if form is "formatted" or "FORMATTED", file is opened for formatted IO. Otherwise, it is unformatted. The action string is the standard action string for Fortran IO (see F90 language description).

open_file    Unit number opened to file fname.
fname    Name of file to be opened.
form    Format: 'formatted' or 'FORMATTED' give formatted, anything else is unformatted. Default is formatted.
action    Standard fortran string description of requested file open action.


call timestamp([string1, string2, string3,]  pos)
 character(len=*), optional, intent(in) :: string1
 character(len=*), optional, intent(in) :: string2
 character(len=*), optional, intent(in) :: string3
 character(len=*), intent(in)           :: pos
 

Description

Prints the message 'Time is YYYY MM DD HH MM SS' to the logfile along with three optional message strings. If the pos argument is 'end', the message printed is 'Finished... at YYYY MM DD HH MM SS' and the logfile is closed.

string1    An optional message to be printed.
string2    An optional message to be printed.
string3    An optional message to be printed.
pos    If 'end' terminates log_file output.


call close_file(iunit)
 integer, intent(in) :: iunit
 

Description

Closes the given unit number. If the unit is not open, nothing happens.

iunit    File unit to be closed.


call register_module(src,rev,rdate)
 character(len=*), intent(in) :: src
 character(len=*), intent(in) :: rev
 character(len=*), intent(in) :: rdate
 

Description

Writes the source name, revision number and revision date to both the logfileunit and to standard out. All dart modules are supposed to register when first called.

src    CVS source file name.
rev    Revision number of source.
rdate    Date of revision.


call error_handler(level, routine, text, src, rev, rdate [, aut])
 integer, intent(in)                    :: level
 character(len=*), intent(in)           :: routine
 character(len=*), intent(in)           :: text
 character(len=*), intent(in)           :: src
 character(len=*), intent(in)           :: rev
 character(len=*), intent(in)           :: rdate
 character(len=*), optional, intent(in) :: aut
 

Description

Prints an error message to standard out and to the logfileunit. The message contains the routine name, an error message, the CVS source file, revision and revision date, and optionally the author. The level of severity is message, debug, warning, or error. If the level is greater than or equal to the TERMLEVEL (set in the namelist), execution is terminated. The default TERMLEVEL only stops for ERRORS.

level    Error severity (message, debug, warning, error). See below for specific ations.
routine    Name of routine generating error.
text    Error message.
src    Source file containing routine generating message.
rev    Revision number of source file.
rdate    Revision date of source file.
aut    Author of routine.


integer :: E_DBG, DEBUG integer :: E_MSG, MESSAGE integer :: E_WARN, WARNING integer :: E_ERR, FATAL

Description

    Severity levels to be passed to error handler. Levels are debug, message, warning and fatal. The namelist parameter TERMLEVEL can be used to control at which level program termination should occur.


integer :: logfileunit

Description

logfileunit    Unit opened to file for diagnostic output.


call initialize_utilities()
 

Description

Reads the namelist and opens the logfile. Records the values of the namelist and registers this module.



call finalize_utilities()
 

Description

Closes the logfile; using utilities after this call is a bad idea.



call dump_unit_attributes(iunit)
 integer, intent(in) :: iunit
 

Description

Writes all information about the status of the IO unit to the error handler with error level message.

iunit    Unit about which information is requested.


integer :: E_DBG, DEBUG integer :: E_MSG, MESSAGE integer :: E_WARN, WARNING integer :: E_ERR, FATAL

Description

    Severity levels to be passed to error handler. Levels are debug, message, warning and fatal. The namelist parameter TERMLEVEL can be used to control at which level program termination should occur.




We adhere to the F90 standard of starting a namelist with an ampersand '&' and terminating with a slash '/'.

 namelist / utilities_nml /  TERMLEVEL, logfilename


 

Discussion

The namelist controls the way in which the error handler acts. In the default case, only calls with level E_ERR lead to program termination. If TERMLEVEL is set to E_WARN, then warnings or errors lead to termination. If TERMLEVEL is set to E_ERR + 1, then even errors don't lead to termination (be careful doing this).

This namelist is read in a file called input.nml

Contents Type Description
TERMLEVEL integer Level at which calls to error manager terminate program. Default: E_ERR
logfilename character(len=129) File to which the logfile is written. Default: dart_log.out




FILES




REFERENCES


ERROR CODES and CONDITIONS

RoutineMessageComment
get_unit No available units Unable to open enough IO channels
check_nml_error while reading namelist _____ Fatal error reading namelist. This could be caused by having an entry in the namelist input file that is not in the namelist, by having illegal values for namelist variables, or by a variety of other compiler dependent problems.



KNOWN BUGS




FUTURE PLANS




PRIVATE COMPONENTS