|
| 1 | +function result = check_tags(ABBREVIATION,DESCRIPTION,WEIGHT,data,varargin) |
| 2 | +%CHECK_TAGS checks if tag's properties are correct: |
| 3 | + |
| 4 | +%ABBREVIATION, DESCRIPTION = unique, non-empty |
| 5 | +%WEIGHT = integer, non-empty |
| 6 | + |
| 7 | + |
| 8 | + result = 0; |
| 9 | + %Do not check for dublicates (edit) |
| 10 | + if ~isempty(varargin) |
| 11 | + if isempty(ABBREVIATION) |
| 12 | + errordlg('Abbreviation cannot be empty','Error'); |
| 13 | + return; |
| 14 | + elseif isempty(DESCRIPTION) |
| 15 | + errordlg('Name cannot be empty','Error'); |
| 16 | + return; |
| 17 | + elseif isempty(WEIGHT) |
| 18 | + errordlg('Weight cannot be empty','Error'); |
| 19 | + return; |
| 20 | + elseif isempty(str2num(WEIGHT)) |
| 21 | + errordlg('Weight needs to have an interger value','Error'); |
| 22 | + return; |
| 23 | + else |
| 24 | + result = 1; |
| 25 | + return; |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + %Do full check |
| 30 | + %Abbrevistion (non-empty, unique) |
| 31 | + if isempty(ABBREVIATION) |
| 32 | + errordlg('Abbreviation cannot be empty','Error'); |
| 33 | + return; |
| 34 | + else |
| 35 | + for i = 2:size(data,1) |
| 36 | + if isequal(ABBREVIATION,data{i,1}) |
| 37 | + errordlg('Abbreviation already exists','Error'); |
| 38 | + return; |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + %Description (non-empty, unique) |
| 43 | + if isempty(DESCRIPTION) |
| 44 | + errordlg('Name cannot be empty','Error'); |
| 45 | + return; |
| 46 | + else |
| 47 | + for i = 2:size(data,1) |
| 48 | + if isequal(DESCRIPTION,data{i,2}) |
| 49 | + errordlg('Name already exists','Error'); |
| 50 | + return; |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | + %Weight (non-empty, numeric) |
| 55 | + if isempty(WEIGHT) |
| 56 | + errordlg('Weight cannot be empty','Error'); |
| 57 | + return; |
| 58 | + elseif isempty(str2num(WEIGHT)) |
| 59 | + errordlg('Weight needs to have an interger value','Error'); |
| 60 | + return; |
| 61 | + end |
| 62 | + |
| 63 | + result = 1; |
| 64 | + |
| 65 | +end |
| 66 | + |
0 commit comments