source: MML/trunk/at/lattice/isatelem.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.3 KB
Line 
1function [t, errorstr] = isatelem(ELEM,varargin)
2%ISATELEM tests if an input argument is a valid AT element.
3%
4%  A valid AT element is a MATLAB structure with required
5%   fields 'Length', 'PassMethod', and a set of data fields,
6%   specific to the PassMethod used.
7%   
8%  [TEST, ERRORSTR] = ISATELEM(ELEM)
9%                   = ISATELEM(ELEM, 'display')
10%
11%  TEST     - test result,  1 = valid AT element
12%  ERRORSTR - multi-line error message
13%   
14%  See also PASSMETHOD, ATELEM
15
16
17errorstr = [];
18
19if ~isstruct(ELEM)
20    errorstr = [errorstr,sprintf('%s\n','Input is not a MATLAB structure')];
21else
22    if ~isfield(ELEM,'PassMethod');
23        errorstr = [errorstr,sprintf('%s\n','Required field ''PassMethod'' is missing')];
24    else % check if ELEM has all fields required by PassMethod function
25        EXISTRESULT = exist(ELEM.PassMethod);
26        if EXISTRESULT == 3
27           
28           
29            try % Try to propagate a test particle
30                temp = feval(ELEM.PassMethod,ELEM, [0 0 0 0 0 0]');
31               
32            catch
33                errorstr = [errorstr,sprintf('%s\n',['Specified PassMethod m-file: ''',...
34                        (ELEM.PassMethod), ''' returned an error'])];
35            end
36           
37            ReqFields = feval(ELEM.PassMethod);
38           
39            for field = 1:length(ReqFields)
40                if ~isfield(ELEM,ReqFields{field})
41                    errorstr = [errorstr,sprintf('%s\n',['Required field ''',ReqFields{field}...
42                                ,''' is missing'])];
43                end
44            end
45           
46           
47           
48        elseif EXISTRESULT == 2
49           
50                       
51            try % Try to propagate a test particle
52                temp = feval(ELEM.PassMethod,ELEM, [0 0 0 0 0 0]');
53               
54            catch
55                errorstr = [errorstr,sprintf('%s\n',['Specified PassMethod m-file: ''',...
56                        (ELEM.PassMethod), ''' returned an error'])];
57            end
58           
59        else
60            errorstr = [errorstr,sprintf('%s\n',['Specified PassMethod mex-file or m-file: ''',...
61                        (ELEM.PassMethod), '.',mexext,''' does not exist'])];
62        end
63    end
64   
65end
66
67
68if isempty(errorstr)
69    t = 1;
70else
71    t = 0;
72end
73
74if any(strncmpi(varargin,'disp',4))
75    disp(errorstr);
76end
Note: See TracBrowser for help on using the repository browser.