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