Home > lattice > isatelem.m

isatelem

PURPOSE ^

ISATELEM tests if an input argument is a valid AT element.

SYNOPSIS ^

function [t, errorstr] = isatelem(ELEM,varargin)

DESCRIPTION ^

ISATELEM tests if an input argument is a valid AT element.
 
  A valid AT element is a MATLAB structure with required 
   fields 'Length', 'PassMethod', and a set of data fields,
   specific to the PassMethod used.
   
  [TEST, ERRORSTR] = ISATELEM(ELEM)
                   = ISATELEM(ELEM, 'display')

  TEST     - test result,  1 = valid AT element
  ERRORSTR - multi-line error message
    
  See also PASSMETHOD, ATELEM

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [t, errorstr] = isatelem(ELEM,varargin)
0002 %ISATELEM tests if an input argument is a valid AT element.
0003 %
0004 %  A valid AT element is a MATLAB structure with required
0005 %   fields 'Length', 'PassMethod', and a set of data fields,
0006 %   specific to the PassMethod used.
0007 %
0008 %  [TEST, ERRORSTR] = ISATELEM(ELEM)
0009 %                   = ISATELEM(ELEM, 'display')
0010 %
0011 %  TEST     - test result,  1 = valid AT element
0012 %  ERRORSTR - multi-line error message
0013 %
0014 %  See also PASSMETHOD, ATELEM
0015 
0016 
0017 errorstr = [];
0018 
0019 if ~isstruct(ELEM)
0020     errorstr = [errorstr,sprintf('%s\n','Input is not a MATLAB structure')];
0021 else
0022     if ~isfield(ELEM,'PassMethod');
0023         errorstr = [errorstr,sprintf('%s\n','Required field ''PassMethod'' is missing')];
0024     else % check if ELEM has all fields required by PassMethod function
0025         EXISTRESULT = exist(ELEM.PassMethod);
0026         if EXISTRESULT == 3
0027             
0028             
0029             try % Try to propagate a test particle
0030                 temp = feval(ELEM.PassMethod,ELEM, [0 0 0 0 0 0]');
0031                 
0032             catch
0033                 errorstr = [errorstr,sprintf('%s\n',['Specified PassMethod m-file: ''',...
0034                         (ELEM.PassMethod), ''' returned an error'])];
0035             end
0036             
0037             ReqFields = feval(ELEM.PassMethod);
0038             
0039             for field = 1:length(ReqFields)
0040                 if ~isfield(ELEM,ReqFields{field})
0041                     errorstr = [errorstr,sprintf('%s\n',['Required field ''',ReqFields{field}...
0042                                 ,''' is missing'])];
0043                 end
0044             end
0045             
0046             
0047             
0048         elseif EXISTRESULT == 2
0049             
0050                        
0051             try % Try to propagate a test particle
0052                 temp = feval(ELEM.PassMethod,ELEM, [0 0 0 0 0 0]');
0053                 
0054             catch
0055                 errorstr = [errorstr,sprintf('%s\n',['Specified PassMethod m-file: ''',...
0056                         (ELEM.PassMethod), ''' returned an error'])];
0057             end
0058             
0059         else
0060             errorstr = [errorstr,sprintf('%s\n',['Specified PassMethod mex-file or m-file: ''',...
0061                         (ELEM.PassMethod), '.',mexext,''' does not exist'])];
0062         end
0063     end
0064     
0065 end
0066 
0067 
0068 if isempty(errorstr)
0069     t = 1;
0070 else
0071     t = 0;
0072 end
0073 
0074 if any(strncmpi(varargin,'disp',4))
0075     disp(errorstr);
0076 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005