[4] | 1 | function varargout = rload(action, varargin) |
---|
| 2 | %enter real numbers into field of input structure |
---|
| 3 | |
---|
| 4 | switch action |
---|
| 5 | %...GenFig//ExecPar |
---|
| 6 | %...DelFigure |
---|
| 7 | %...getWord//GetElement//num |
---|
| 8 | %============================================================= |
---|
| 9 | case 'GenFig' |
---|
| 10 | %============================================================= |
---|
| 11 | % This function generates the figure which holds |
---|
| 12 | % list of elements for real field selection by the user. |
---|
| 13 | % Only re-draw figure after final OK (DeleteFigure) |
---|
| 14 | name=varargin(1); name=name{1}; |
---|
| 15 | avail=varargin(2); avail=avail{1}; |
---|
| 16 | status=varargin(3); status=status{1}; |
---|
| 17 | value=varargin(4); value=value{1}; |
---|
| 18 | title=varargin(5); title=title{1}; |
---|
| 19 | tag=varargin(6); tag=tag{1}; |
---|
| 20 | tlist=varargin(1:4); %temporary lists |
---|
| 21 | |
---|
| 22 | %test if toggle panel already exists |
---|
| 23 | h= findobj(0,'tag',['rload_' tag]); |
---|
| 24 | if ~isempty(h) |
---|
| 25 | delete(h); |
---|
| 26 | end |
---|
| 27 | |
---|
| 28 | newFig = figure('Position',[100 400 900 550],... |
---|
| 29 | 'UserData',tlist,... |
---|
| 30 | 'NumberTitle','off',... |
---|
| 31 | 'tag',['rload_' tag],... |
---|
| 32 | 'Name',['Element Selection: ' title],... |
---|
| 33 | 'MenuBar','none'); |
---|
| 34 | |
---|
| 35 | xpos = 20; %initial x and y offsets of the button |
---|
| 36 | ypos = 530; %330 |
---|
| 37 | |
---|
| 38 | for ind = 1:length(name) |
---|
| 39 | |
---|
| 40 | ypos = ypos - 20; |
---|
| 41 | if ypos < 50 %go to new column if full |
---|
| 42 | ypos = 510; %310 |
---|
| 43 | xpos = xpos + 180; |
---|
| 44 | end |
---|
| 45 | |
---|
| 46 | color='r'; %default |
---|
| 47 | |
---|
| 48 | if ~isempty(avail) |
---|
| 49 | if ~isempty(find(avail==ind)) |
---|
| 50 | color = 'y'; %status ok ==> yellow |
---|
| 51 | end |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | if ~isempty(status) |
---|
| 55 | if ~isempty(find(status==ind)) |
---|
| 56 | color = 'g'; %status ok ==> green |
---|
| 57 | end |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | uicontrol('Style','frame',... |
---|
| 61 | 'Position',[xpos-1 ypos-1 72 22]); %name frame |
---|
| 62 | uicontrol('Style','Text', ... |
---|
| 63 | 'Position',[xpos ypos 70 20], ... |
---|
| 64 | 'ForegroundColor','k', ... |
---|
| 65 | 'BackgroundColor',color, ... |
---|
| 66 | 'FontSize',9,... |
---|
| 67 | 'String',name(ind,:)); %name |
---|
| 68 | |
---|
| 69 | uicontrol('Style','frame',... |
---|
| 70 | 'Position',[xpos+75-1 ypos-1 72 22]); %value frames |
---|
| 71 | |
---|
| 72 | uicontrol('Style','Edit', ... %Edit boxes |
---|
| 73 | 'Position',[xpos+75 ypos 70 20], ... |
---|
| 74 | 'ForegroundColor','k', ... |
---|
| 75 | 'BackgroundColor',color, ... |
---|
| 76 | 'FontSize',9,... |
---|
| 77 | 'tag',['rl' num2str(ind)],... |
---|
| 78 | 'String',value(ind)); |
---|
| 79 | end %end loop on elements |
---|
| 80 | |
---|
| 81 | uicontrol('Style','pushbutton',... |
---|
| 82 | 'Position',[10 10 200 30],... |
---|
| 83 | 'String','Load Values',... |
---|
| 84 | 'Callback','rload(''LoadValues'')',... |
---|
| 85 | 'Tag','rload',... |
---|
| 86 | 'Userdata',tag); %Load New Values |
---|
| 87 | |
---|
| 88 | %%%%%%%% |
---|
| 89 | delta=1.0; |
---|
| 90 | uicontrol('Style','frame',... |
---|
| 91 | 'Position',[250-delta 10-delta 80+2*delta 30+2*delta]); %All Values Same Frame |
---|
| 92 | |
---|
| 93 | uicontrol('Style','text',... |
---|
| 94 | 'Position',[250 10 80 30],... |
---|
| 95 | 'String','All Values Same:'); %All Values Same Text |
---|
| 96 | |
---|
| 97 | uicontrol('Style','edit',... |
---|
| 98 | 'Position',[350 10 50 30],... |
---|
| 99 | 'String','NaN',... |
---|
| 100 | 'Tag','allvalues',... |
---|
| 101 | 'Callback','rload(''AllValues'')'); %All Values Same |
---|
| 102 | %%%%%%%% |
---|
| 103 | |
---|
| 104 | uicontrol('Style','pushbutton',... |
---|
| 105 | 'Position',[550 10 60 30],... |
---|
| 106 | 'String','Cancel',... |
---|
| 107 | 'Callback','delete(gcf)'); %Cancel button |
---|
| 108 | |
---|
| 109 | %============================================================= |
---|
| 110 | case 'AllValues' % *** AllValues *** |
---|
| 111 | %============================================================= |
---|
| 112 | h=findobj(gcf,'tag','allvalues'); |
---|
| 113 | |
---|
| 114 | %retrieve value |
---|
| 115 | val=get(h,'String'); |
---|
| 116 | val=str2num(val); |
---|
| 117 | if isnan(val) |
---|
| 118 | return |
---|
| 119 | end |
---|
| 120 | |
---|
| 121 | %load value into all fields |
---|
| 122 | tlist = get(gcf,'UserData'); |
---|
| 123 | name=tlist{1}; |
---|
| 124 | avail=tlist{2}; |
---|
| 125 | status=tlist{3}; |
---|
| 126 | |
---|
| 127 | for ind = 1:length(name) |
---|
| 128 | if find(ind==avail) & find(ind==status) |
---|
| 129 | rh=findobj(gcf,'tag',['rl' num2str(ind)]); |
---|
| 130 | set(rh,'String',num2str(val)); |
---|
| 131 | end |
---|
| 132 | end |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | %============================================================= |
---|
| 138 | case 'LoadValues' % *** LoadValues *** |
---|
| 139 | %============================================================= |
---|
| 140 | %Callback of the 'LoadValues' button in the GenFig |
---|
| 141 | tlist = get(gcf,'UserData'); |
---|
| 142 | name=tlist{1}; |
---|
| 143 | avail=tlist{2}; |
---|
| 144 | status=tlist{3}; |
---|
| 145 | value=tlist{4}; |
---|
| 146 | |
---|
| 147 | % for ind = 1:length(name) |
---|
| 148 | % rh=findobj(gcf,'tag',['rl' num2str(ind)]); |
---|
| 149 | % value(ind)=str2num(get(rh,'String')); |
---|
| 150 | % end |
---|
| 151 | for ind = 1:length(name) |
---|
| 152 | rh=findobj(gcf,'tag',['rl' num2str(ind)]); |
---|
| 153 | val=str2double(get(rh,'String')); |
---|
| 154 | |
---|
| 155 | %only load into value array if 'val' is a valid real number |
---|
| 156 | if isnan(val) | ~isnumeric(val) | ~length(val)==1 |
---|
| 157 | %flush the bad string out of the edit; replace with current value |
---|
| 158 | set(rh,'String',value(ind)); |
---|
| 159 | disp(['Warning: Invalid load value entry: ', name(ind,:)]); |
---|
| 160 | orbgui('LBox',['Warning: Invalid load value entry: ', name(ind,:)]); |
---|
| 161 | else |
---|
| 162 | value(ind)=val; |
---|
| 163 | end |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | end |
---|
| 167 | tlist=[{tlist{1}} {tlist{2}} {tlist{3}} {value}]; |
---|
| 168 | set(gcf,'UserData',tlist); |
---|
| 169 | hload=findobj(0,'Tag','rload'); %get handle of 'load' button |
---|
| 170 | hload=gco; |
---|
| 171 | tag=get(hload,'Userdata'); %get tag of caller from load button Userdata |
---|
| 172 | h=findobj(0,'Tag',tag); %get handle of caller |
---|
| 173 | instr=get(h,'Userdata'); %get instruction set from caller |
---|
| 174 | eval(instr); %evaluate instruction set |
---|
| 175 | |
---|
| 176 | %============================================================= |
---|
| 177 | otherwise |
---|
| 178 | disp('Warning: no CASE found in rload'); |
---|
| 179 | disp(action); |
---|
| 180 | end % End Switchyard |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | %******************** |
---|
| 185 | function [word,k] = getWord(line, i) |
---|
| 186 | %******************** |
---|
| 187 | |
---|
| 188 | %getWord reads one 'word' or token at a time from a line of char. |
---|
| 189 | |
---|
| 190 | %Input: line is the line being read, i is the pointer to the index |
---|
| 191 | % within that line. |
---|
| 192 | |
---|
| 193 | %Output:word is the token being returned to the main program. |
---|
| 194 | % k is the returned value of i for the main to keep track of. |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | word = []; |
---|
| 198 | |
---|
| 199 | if ~isempty(line) |
---|
| 200 | |
---|
| 201 | while line(i) == ' ' |
---|
| 202 | i = i + 1; |
---|
| 203 | end |
---|
| 204 | |
---|
| 205 | while line(i) ~= ' ' |
---|
| 206 | word = [word line(i)]; |
---|
| 207 | i = i+1; |
---|
| 208 | |
---|
| 209 | if i > length(line) |
---|
| 210 | break; |
---|
| 211 | end |
---|
| 212 | end |
---|
| 213 | |
---|
| 214 | end |
---|
| 215 | |
---|
| 216 | k = i; |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | %************************* |
---|
| 221 | function [index,num,k] = getElmnt(line,i) |
---|
| 222 | %************************* |
---|
| 223 | |
---|
| 224 | % getElmnt reads the values stored for a specific element in the file |
---|
| 225 | % for use in the array. |
---|
| 226 | |
---|
| 227 | % Input: line is the line of text from the file being read. |
---|
| 228 | % i is the index pointer in that line. |
---|
| 229 | |
---|
| 230 | % Output:index and num are data returned to the main program. |
---|
| 231 | % index is the element index (ex: ibpmx) |
---|
| 232 | % num is the data for that element (ex: 1.83E-01). |
---|
| 233 | |
---|
| 234 | % k is the value of i returned to the main program |
---|
| 235 | % to keep track of things. |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | while line(i) == ' ' |
---|
| 239 | i = i + 1; |
---|
| 240 | end |
---|
| 241 | |
---|
| 242 | index = []; |
---|
| 243 | while ~(line(i) == ' ') & ~(line(i) == '-') |
---|
| 244 | index = [index line(i)]; |
---|
| 245 | i = i + 1; |
---|
| 246 | end |
---|
| 247 | index = str2num(index); |
---|
| 248 | |
---|
| 249 | if line(i) == ' ' |
---|
| 250 | i = i + 1; |
---|
| 251 | end |
---|
| 252 | |
---|
| 253 | num = []; |
---|
| 254 | while line(i) ~= ' ' |
---|
| 255 | num = [num line(i)]; |
---|
| 256 | i = i + 1; |
---|
| 257 | |
---|
| 258 | if i > length(line) |
---|
| 259 | break; |
---|
| 260 | end |
---|
| 261 | end |
---|
| 262 | num = sci2num(num); |
---|
| 263 | |
---|
| 264 | k = i; |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | %********************* |
---|
| 269 | function num = sci2num(str) |
---|
| 270 | %********************* |
---|
| 271 | |
---|
| 272 | %Transforms a number from scientific notation to standard form |
---|
| 273 | %for the program to manipulate. |
---|
| 274 | |
---|
| 275 | a = []; |
---|
| 276 | |
---|
| 277 | i = 1; |
---|
| 278 | while str(i) ~= 'E' |
---|
| 279 | a = [a str(i)]; |
---|
| 280 | i = i + 1; |
---|
| 281 | end |
---|
| 282 | |
---|
| 283 | a = str2num(a); |
---|
| 284 | |
---|
| 285 | sign = str(i + 1); |
---|
| 286 | i = i + 2; |
---|
| 287 | |
---|
| 288 | p = [str(i) str(i + 1)]; |
---|
| 289 | p = str2num(p); |
---|
| 290 | |
---|
| 291 | if sign == '+' |
---|
| 292 | num = a*(10^p); |
---|
| 293 | else |
---|
| 294 | num = a*(10^(p * -1)); |
---|
| 295 | end |
---|