Doxygen Source Code Documentation
ErrEval.m
Go to the documentation of this file.00001 function Decis = ErrEval (FuncName, ErrCode);
00002 %
00003 % Decis = ErrEval (FuncName, ErrCode);
00004 %
00005 %This function displays an error message based on ErrCode and
00006 %returns 1 if it's a lethal error (Err_) , or 0 if it's
00007 %an error or a warning (Wrn_)that does not require aborting a function
00008 %
00009 %
00010 %ErrCode is a string made out of two parts
00011 % The first part is a 4 letter string containing
00012 % Err_ or Wrn_ depending on wether it's an error or
00013 % a warning.
00014 % The second part is a string that indicates the type of
00015 % error encountered.
00016 %
00017 %Defined values of ErrCode are :
00018 % No %No problem
00019 % BadInpSize %One of the input variables has a bad size
00020 % BadInOut %Bad combination of input and output parameters
00021 % FewInp %Not enough inputs
00022 % ManyInp %Too many inputs
00023 % FewOut %Not enough outputs
00024 % ManyOut %Too many outputs
00025 % SubFunc %An error has occurred in a function within the script
00026 % BadOpt %Bad Option
00027 % BadOptCombo %Bad Option Combination
00028 % InpFieldMiss %A field is missing from one of the input structures
00029 % OptFieldMiss %A fiels is missing from the Options structures
00030 % EmptyInp %Input data is empty
00031 % FileExist %File exists
00032 % FileNotExist %File does not exist
00033 % To pass a generic message, replace the ErrCode by any ther string
00034 %
00035 % Here's a typical example of the function usage
00036 % if (ErrEval ('LoadSliceData','Err_Image Type Not Supported')), err = 1; return;end
00037 %
00038 %
00039 % Ziad Saad Thu Mar 26 11:43:51 CST 1998
00040
00041
00042 if (eq_str(ErrCode,'No')), %in case you send a No only to
00043 Decis = 0;
00044 return;
00045 end
00046
00047 if (length(ErrCode) < 5),
00048 fprintf (2,'\nError in ErrEval, ErrCode %s is ambiguous.\nReturning a 1 decision.\n\n\a',ErrCode);
00049 Decis = 1;
00050 return;
00051 end
00052
00053
00054 tmp = ErrCode(1:3);
00055
00056 switch tmp
00057 case 'Err'
00058 Decis = 1;
00059 case 'Wrn'
00060 Decis = 0;
00061 otherwise
00062 fprintf (2,'\nError in ErrEval, prefix %s from %s is ambiguous.\nReturning a 1 decision.\n\n\a',tmp, ErrCode);
00063 Decis = 1;
00064 return;
00065 end
00066
00067 tmp = ErrCode(5:length(ErrCode));
00068
00069 switch tmp
00070 case 'No'
00071 Decis = 0; %even if it was Err_No
00072 return;
00073 case 'BadInpSize'
00074 s = 'Bad size of at least one of the input parameters.';
00075 case 'BadInOut',
00076 s = 'Bad combination of input and output parameters.';
00077 case 'FewInp'
00078 s = 'Too few inputs.';
00079 case 'ManyInp'
00080 s = 'Too many inputs.';
00081 case 'FewOut'
00082 s = 'Too few outputs';
00083 case 'ManyOut'
00084 s = 'Too many outputs';
00085 case 'SubFunc'
00086 s = 'Error (or Warning) in a function within this function (or script).';
00087 case 'BadOpt'
00088 s = 'Bad Option';
00089 case 'InpFieldMiss',
00090 s = 'A field is missing from one of the input structures.';
00091 case 'OptFieldMiss',
00092 s = 'A field is missing from the Options structure.';
00093 case 'BadOptCombo',
00094 s = 'Bad Combinations of Options.';
00095 case 'EmptyInp',
00096 s = 'One or all of input data is empty.';
00097 case 'FileExist',
00098 s = 'File specified exists.';
00099 case 'FileNotExist',
00100 s = 'File specified does not exist.';
00101 otherwise
00102 s = tmp;
00103 end
00104
00105 %For the error message
00106 if (Decis),
00107 fprintf (2,'\a\nError in %s : %s\n\n',FuncName,s);
00108 else
00109 fprintf (2,'\nWarning from %s : %s\n\n',FuncName,s);
00110 end
00111
00112 return;