next up previous contents
Next: destroy_watchgroup Up: Reference Manual Previous: create_watchgroup



destroys a StopWatch watch

subroutine destroy_watch (watch, clock, err)

type (watchtype), intent(INOUT) :: watch
type (watchtype), intent(INOUT) :: watch(:)

character(len=*), optional, intent(IN) :: clock
character(len=*), optional, intent(IN) :: clock(:)

integer, optional, intent(OUT) :: err

Destroys the specified clocks of the specified watches. If the watch has no remaining clocks after the specified clocks are destroyed, then the watch is destroyed and associated memory freed. To avoid memory leaks, watches should be destroyed when no longer useful, before being recreated, and before returning from a subroutine in which the watch is a local variable.

One or more watches must be specified. The argument watch can be a single variable of type watchtype (see stopwatch(3)) to destroy one watch, or an array of type watchtype to destroy several watches.

The optional argument clock specifies which clocks to destroy on the specified watch(es). If omitted, the current default clocks (see option_stopwatch(3)) are destroyed. If present, clock must be a character string containing 'cpu', 'user', 'sys', or 'wall', or an array of such character strings.

If present, the optional intent OUT integer argument err returns a status code. The code is the sum of the values listed below.

An error message will be printed to a specified I/O unit (unit 6 by default) if print_errors is TRUE (default is TRUE). The error message contains more detail about the cause of the error than can be obtained from just the status code, so you should set print_errors to TRUE if you have trouble determining the cause of the error.

If abort_errors is TRUE (default is FALSE), the program will terminate on an error condition. Otherwise, the program will continue execution but the watch(es) will not be destroyed.

See option_stopwatch(3) for further information on print_errors, abort_errors and I/O units.

The relevant status codes and messages are:

No errors; execution successful.

Watch needs to be created. This error occurs if you attempt to destroy a watch that has already been destroyed. The watch must first be created again. See also the comment about watches that have never been created in the BUGS section.

Invalid clock type. This occurs if clock is present and one of the specified clocks is not supported by the implementation. See inquiry_stopwatch(3) to determine what clocks are available.

Failed to allocate required memory. When destroy_watch is called with an array or group of watches, temporary memory is allocated. This error occurs if the Fortran allocate statement returns a nonzero status indicating that memory could not be allocated. Avoid memory leaks by always destroying watches and groups before recreating them, and destroying local variable watches and groups before returning from a subroutine.

Error occurred while deallocating memory. This error occurs if the Fortran deallocate statement returns a nonzero status while deallocating the memory for the watch or temporary memory used for an array or group of watches. The watches are destroyed, but be aware that other problems could develop as a result of the deallocate error.

In addition to the run time diagnostics generated by StopWatch , the following problems may arise:

Since watch has intent OUT, you cannot use an array constructor as an actual argument to construct an array of watches. Some compilers will recognize this as a compile time error, but will generate an obscure error message, such as ``no specific match for generic name''.

In Fortran 90, the character strings in an array constructor must all have the same length. Pad three letter clock names with a blank on the right to make a four character string, for example, 'cpu '.

type (watchtype) w1, w2(3)
integer errcode

call destroy_watch(w1)
call destroy_watch(w2, (/'sys ', 'user'/), err=errcode)

The first call destroys the default clocks on a single watch. Assuming the default clocks have not changed since the watch was created, the watch will be destroyed. The second call destroys the sys and user clocks on three watches given as an array and returns a status code. Assuming the watch also had the cpu or wall clock, the watches are not destroyed.

It cannot be determined whether or not a watch variable or watch group has been created (passed as an argument to create_watch or create_watchgroup). If a watch or watch group that has never been created is passed into destroy_watch, it might generate a Fortran error due to passing a pointer with undefined association status to the Fortran intrinsic function associated. Some compilers will allow this as an extension to the Fortran 90 standard and recognize that the pointer is not associated, in which case the ``Watch needs to be created'' error message is generated.

next up previous contents
Next: destroy_watchgroup Up: Reference Manual Previous: create_watchgroup