source: MML/trunk/machine/SOLEIL/StorageRing/orbit/rload.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 7.0 KB
Line 
1function varargout = rload(action, varargin)
2%enter real numbers into field of input structure
3
4switch action
5%...GenFig//ExecPar
6%...DelFigure
7%...getWord//GetElement//num
8%=============================================================
9case '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)
14name=varargin(1);    name=name{1};
15avail=varargin(2);   avail=avail{1};
16status=varargin(3);  status=status{1};
17value=varargin(4);   value=value{1};
18title=varargin(5);   title=title{1};
19tag=varargin(6);     tag=tag{1};
20tlist=varargin(1:4);   %temporary lists
21
22%test if toggle panel already exists
23h= findobj(0,'tag',['rload_' tag]);
24if ~isempty(h)
25    delete(h);
26end
27
28newFig = 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               
35xpos = 20;              %initial x and y offsets of the button
36ypos = 530;  %330
37
38for 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));
79end   %end loop on elements
80
81uicontrol('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%%%%%%%%
89delta=1.0;
90uicontrol('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     
97uicontrol('Style','edit',...
98          'Position',[350 10 50 30],...
99          'String','NaN',...
100          'Tag','allvalues',...
101          'Callback','rload(''AllValues'')');      %All Values Same
102%%%%%%%%
103
104uicontrol('Style','pushbutton',...
105          'Position',[550 10 60 30],...
106          'String','Cancel',...
107          'Callback','delete(gcf)');               %Cancel button
108
109%=============================================================
110case 'AllValues'                             % *** AllValues ***
111%=============================================================
112h=findobj(gcf,'tag','allvalues');
113
114%retrieve value
115val=get(h,'String');
116val=str2num(val);
117if isnan(val)
118    return
119end
120
121%load value into all fields
122tlist = get(gcf,'UserData');   
123name=tlist{1};
124avail=tlist{2};
125status=tlist{3};
126
127for 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
132end
133
134
135
136
137%=============================================================
138case 'LoadValues'                             % *** LoadValues ***
139%=============================================================
140%Callback of the 'LoadValues' button in the GenFig
141tlist = get(gcf,'UserData');   
142name=tlist{1};
143avail=tlist{2};
144status=tlist{3};
145value=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   
151for 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
166end   
167tlist=[{tlist{1}} {tlist{2}} {tlist{3}} {value}];
168set(gcf,'UserData',tlist);     
169hload=findobj(0,'Tag','rload'); %get handle of 'load' button
170hload=gco;
171tag=get(hload,'Userdata');      %get tag of caller from load button Userdata
172h=findobj(0,'Tag',tag);         %get handle of caller
173instr=get(h,'Userdata');        %get instruction set from caller
174eval(instr);                    %evaluate instruction set
175
176%=============================================================
177otherwise
178disp('Warning: no CASE found in rload');
179disp(action);
180end   % End Switchyard
181
182
183
184%********************
185function [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
197word = [];
198
199if ~isempty(line)
200
201while line(i) == ' '
202  i = i + 1;
203end
204
205while line(i) ~= ' '
206  word = [word line(i)];
207  i = i+1;
208
209  if i > length(line)
210        break;
211  end
212end
213
214end
215
216k = i;
217
218
219
220%*************************
221function [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                 
238while line(i) == ' '
239        i = i + 1;
240end
241
242index = [];
243while ~(line(i) == ' ') & ~(line(i) == '-')
244        index = [index line(i)];
245        i = i + 1;
246end
247index = str2num(index);
248
249if line(i) == ' '
250        i = i + 1;
251end
252
253num = [];
254while line(i) ~= ' '
255        num = [num line(i)];
256        i = i + 1;
257
258        if i > length(line)
259                break;
260        end
261end
262num = sci2num(num);
263
264k = i;
265
266
267
268%*********************
269function num = sci2num(str)
270%*********************
271
272%Transforms a number from scientific notation to standard form
273%for the program to manipulate.
274
275a = [];
276
277i = 1;
278while str(i) ~= 'E'
279        a = [a str(i)];
280        i = i + 1;
281end
282
283a = str2num(a);
284
285sign = str(i + 1);
286i = i + 2;
287
288p = [str(i) str(i + 1)];
289p = str2num(p);
290
291if sign == '+'
292        num = a*(10^p);
293else
294        num = a*(10^(p * -1));
295end   
Note: See TracBrowser for help on using the repository browser.