0001 function [pass, err_str] = valid_inv_model(imdl)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 pass = 1;
0015 err_str = '';
0016
0017
0018 if ~isstruct(imdl)
0019 pass = 0;
0020 err_str = [err_str '- not a struct\n'];
0021 end
0022
0023
0024
0025 f = {'name', 'char', ...
0026 'fwd_model', 'struct', ...
0027 'solve', 'function', ...
0028 'reconst_type','char', ...
0029 'type', 'char'};
0030
0031
0032
0033 for i=1:length(f)/2
0034 x=2*(i-1)+1;
0035 y=x+1;
0036 if ~isfield(imdl, f{x})
0037 pass = 0;
0038 err_str = [err_str '- missing required field: "' f{x} '"\n'];
0039 elseif strcmp(f{y},'function')
0040 if ~isfunc(imdl.(f{x}))
0041 pass = 0;
0042 err_str = [err_str '- expected function (pointer or string): "' f{x} '"\n'];
0043 end
0044 elseif ~isa(imdl.(f{x}), f{y})
0045 pass = 0;
0046 err_str = [err_str '- required field "' f{x} '" is not a ' f{y} '\n'];
0047 end
0048 end
0049
0050 [pass_local, err_str_local] = valid_fwd_model(imdl.fwd_model);
0051 if ~pass_local
0052 pass = 0;
0053 disp(err_str_local);
0054 err_str_local = strrep(err_str_local, ' "', ' "fwd_model.');
0055 err_str = [err_str err_str_local];
0056 end
0057 clear err_str_local pass_local;
0058
0059 if ~strcmp(imdl.type, 'inv_model')
0060 pass = 0;
0061 err_str = [err_str '- field "type" must be "inv_model"\n'];
0062 end
0063
0064
0065
0066 f = {'rec_model', 'struct'};
0067 for i=1:length(f)/2
0068 x=2*(i-1)+1;
0069 y=x+1;
0070 if isfield(imdl, f{x}) && ~isa(imdl.(f{x}), f{y})
0071 pass = 0;
0072 err_str = [err_str '- optional field "' f{x} '" is not a ' f{y} '\n'];
0073 end
0074 end
0075
0076 if isfield(imdl, 'rec_model')
0077 [pass_local, err_str_local] = valid_fwd_model(imdl.rec_model, 'rec_model');
0078 if ~pass_local
0079 pass = 0;
0080 disp(err_str_local);
0081 err_str_local = strrep(err_str_local, ' "', ' "rec_model.');
0082 err_str = [err_str err_str_local];
0083 end
0084 clear err_str_local pass_local;
0085 end
0086
0087
0088
0089 f = {'inv_model', ...
0090 'fmdl', ...
0091 'fwd_mdl'};
0092 for i=1:length(f)
0093 x=i;
0094 if isfield(imdl, f{x})
0095 pass = 0;
0096 err_str = [err_str '- illegal field "' f{x} '" found\n'];
0097 end
0098 end
0099
0100
0101 if ~pass
0102 err_str = err_str(1:end-2);
0103 end
0104 if ( nargout == 0 ) && ~pass
0105 error(sprintf(['Reasons:\n' err_str]));
0106 end
0107
0108 function t=isfunc(f)
0109 t=isa(f, 'function_handle') || isa(f, 'char');