00001
00002
00003
00004
00005
00006
00007
00008
00018
00019 module ssht_error_mod
00020
00021 use ssht_types_mod, only: STRING_LEN, SSHT_PROMPT
00022
00023 implicit none
00024
00025 private
00026
00027
00028
00029
00030
00031
00032 public :: ssht_error
00033
00034
00035
00036
00037
00038
00039 integer, parameter :: SSHT_ERROR_NUM = 12
00040
00041 integer, public, parameter ::
00042 SSHT_ERROR_NONE = 0,
00043 SSHT_ERROR_INIT = 1,
00044 SSHT_ERROR_NOT_INIT = 2,
00045 SSHT_ERROR_INIT_FAIL = 3,
00046 SSHT_ERROR_MEM_ALLOC_FAIL = 4,
00047 SSHT_ERROR_ARTH = 5,
00048 SSHT_ERROR_SIZE_WARNING = 6,
00049 SSHT_ERROR_SIZE_INVALID = 7,
00050 SSHT_ERROR_SIZE_NOT_DEF = 8,
00051 SSHT_ERROR_ARG_INVALID = 9,
00052 SSHT_ERROR_ARG_WARNING = 10,
00053 SSHT_ERROR_INDEX_INVALID = 11,
00054 SSHT_ERROR_FILEIO = 12
00055
00056
00057
00058
00060 character(len=STRING_LEN), parameter ::
00061 error_comment(SSHT_ERROR_NUM+1) =
00062 (/
00063 'No error ',
00064 'Attempt to initialise object that has already been initialised ',
00065 'Object not initialised ',
00066 'Object initialisation failed ',
00067 'Memory allocation failed ',
00068 'Arithmetic exception ',
00069 'Warning: Sizes not in recommended range ',
00070 'Invalid sizes ',
00071 'Sizes not defined ',
00072 'Arguments invalid ',
00073 'Argument warning ',
00074 'Index invalid ',
00075 'File IO error '
00076 /)
00077
00079 logical, parameter ::
00080 halt_default(SSHT_ERROR_NUM+1) =
00081 (/
00082 .false.,
00083 .true.,
00084 .true.,
00085 .true.,
00086 .true.,
00087 .true.,
00088 .false.,
00089 .true.,
00090 .true.,
00091 .true.,
00092 .false.,
00093 .true.,
00094 .true. /)
00095
00096
00097
00098
00099 contains
00100
00101
00102
00103
00104
00123
00124 subroutine ssht_error(error_code, procedure, comment_add, &
00125 comment_out, halt_in)
00126
00127 integer, intent(in) :: error_code
00128 character(len=*), intent(in), optional :: procedure, comment_add
00129 character(len=*), intent(inout), optional :: comment_out
00130 logical, intent(in), optional :: halt_in
00131
00132 logical :: halt
00133 character(len=STRING_LEN) :: comment_prefix
00134
00135 write(comment_prefix, '(a,a)') SSHT_PROMPT, 'SSHT_ERROR: '
00136
00137
00138
00139
00140
00141 if(present(procedure)) then
00142
00143 if(present(comment_add)) then
00144 write(*,'(a,a,a,a,a,a)') trim(comment_prefix), ' Error ''', &
00145 trim(error_comment(error_code+1)), &
00146 ''' occured in procedure ''', &
00147 trim(procedure), &
00148 ''''
00149 write(*,'(a,a,a)') trim(comment_prefix), &
00150 ' - ', trim(comment_add)
00151 else
00152 write(*,'(a,a,a,a,a,a)') trim(comment_prefix), ' Error ''', &
00153 trim(error_comment(error_code+1)), &
00154 ''' occured in procedure ''', &
00155 trim(procedure), &
00156 ''''
00157 end if
00158
00159 else
00160
00161 if(present(comment_add)) then
00162 write(*,'(a,a,a)') trim(comment_prefix), &
00163 ' ', trim(error_comment(error_code+1))
00164 write(*,'(a,a,a)') trim(comment_prefix), &
00165 ' - ', trim(comment_add)
00166 else
00167 write(*,'(a,a,a)') trim(comment_prefix), ' ', trim(error_comment(error_code+1))
00168 end if
00169
00170 end if
00171
00172
00173 if(present(comment_out)) comment_out = error_comment(error_code+1)
00174
00175
00176
00177
00178
00179 if( present(halt_in) ) then
00180 halt = halt_in
00181 else
00182 halt = halt_default(error_code+1)
00183 end if
00184
00185 if( halt ) then
00186 write(*,'(a,a,a,a,a,a)') trim(comment_prefix), ' ', &
00187 'Halting program execution ', &
00188 'due to error ''', trim(error_comment(error_code+1)), ''''
00189 stop
00190 end if
00191
00192 end subroutine ssht_error
00193
00194
00195 end module ssht_error_mod