source: MML/trunk/machine/SOLEIL/StorageRing/RadiaMapGui/RadiaMapGui.m @ 17

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

To have a stable version on the server.

  • Property svn:executable set to *
File size: 18.5 KB
Line 
1function varargout = RadiaMapGui(varargin)
2% RADIAMAPGUI M-file for RadiaMapGui.fig
3%      RADIAMAPGUI, by itself, creates a new RADIAMAPGUI or raises the existing
4%      singleton*.
5%
6%      H = RADIAMAPGUI returns the handle to a new RADIAMAPGUI or the handle to
7%      the existing singleton*.
8%
9%      RADIAMAPGUI('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in RADIAMAPGUI.M with the given input arguments.
11%
12%      RADIAMAPGUI('Property','Value',...) creates a new RADIAMAPGUI or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before RadiaMapGui_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to RadiaMapGui_OpeningFcn via varargin.
17%
18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19%      instance to run (singleton)".
20%
21% See also: GUIDE, GUIDATA, GUIHANDLES
22
23% Edit the above text to modify the response to help RadiaMapGui
24
25% Last Modified by GUIDE v2.5 07-Jan-2011 15:24:20
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30                   'gui_Singleton',  gui_Singleton, ...
31                   'gui_OpeningFcn', @RadiaMapGui_OpeningFcn, ...
32                   'gui_OutputFcn',  @RadiaMapGui_OutputFcn, ...
33                   'gui_LayoutFcn',  [] , ...
34                   'gui_Callback',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46
47% --- Executes just before RadiaMapGui is made visible.
48function RadiaMapGui_OpeningFcn(hObject, eventdata, handles, varargin)
49% This function has no output args, see OutputFcn.
50% hObject    handle to figure
51% eventdata  reserved - to be defined in a future version of MATLAB
52% handles    structure with handles and user data (see GUIDATA)
53% varargin   command line arguments to RadiaMapGui (see VARARGIN)
54
55% Choose default command line output for RadiaMapGui
56handles.output = hObject;
57
58% Update handles structure
59guidata(hObject, handles);
60
61% UIWAIT makes RadiaMapGui wait for user response (see UIRESUME)
62% uiwait(handles.figure1);
63
64%set default value for the plot StartLn, plot EndLn, plot data after
65% smooth Ln, Length of the undulator when generate 2D map from 1D map data
66handles.EndLn = str2double(get(handles.EndLn,'String'));
67handles.StartLn= str2double(get(handles.StartLn,'String'));
68handles.plotsmoothLn = str2double(get(handles.plotsmoothLn,'String'));
69handles.Length = str2double(get(handles.Length,'String'));
70
71% Update handles structure
72guidata(hObject, handles);
73
74
75
76% --- Outputs from this function are returned to the command line.
77function varargout = RadiaMapGui_OutputFcn(hObject, eventdata, handles)
78% varargout  cell array for returning output args (see VARARGOUT);
79% hObject    handle to figure
80% eventdata  reserved - to be defined in a future version of MATLAB
81% handles    structure with handles and user data (see GUIDATA)
82
83% Get default command line output from handles structure
84varargout{1} = handles.output;
85
86
87function edit1_Callback(hObject, eventdata, handles)
88% hObject    handle to edit1 (see GCBO)
89% eventdata  reserved - to be defined in a future version of MATLAB
90% handles    structure with handles and user data (see GUIDATA)
91
92
93% Hints: get(hObject,'String') returns contents of edit1 as text
94%        str2double(get(hObject,'String')) returns contents of edit1 as a double
95
96
97% --- Executes during object creation, after setting all properties.
98function edit1_CreateFcn(hObject, eventdata, handles)
99% hObject    handle to edit1 (see GCBO)
100% eventdata  reserved - to be defined in a future version of MATLAB
101% handles    empty - handles not created until after all CreateFcns called
102
103% Hint: edit controls usually have a white background on Windows.
104%       See ISPC and COMPUTER.
105if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
106    set(hObject,'BackgroundColor','white');
107end
108
109
110
111% --- Executes on button press in open2Dmap.
112function open2Dmap_Callback(hObject, eventdata, handles)
113% hObject    handle to open2Dmap (see GCBO)
114% eventdata  reserved - to be defined in a future version of MATLAB
115% handles    structure with handles and user data (see GUIDATA)
116
117
118%set the 'smooth finish' display window to its initial value
119h = handles.smoothfinish;
120set(h,'String','finish smooth ???','Foregroundcolor','y');
121
122
123% select the file name to read
124[FileName,PathName,FilterIndex] = uigetfile('*.dat');
125%save the whole path
126handles.openfilename = [PathName,FileName];
127handles.FileName = FileName;
128handles.PathName = PathName;
129
130
131
132% get the file name and read the file
133[x Bx,Bz,Px,Pz,Lu] = ReadRadiaMap(handles.openfilename);
134% save the data the all handles
135handles.x = x;
136handles.Px = Px;
137handles.Pz = Pz;
138handles.Lu = Lu;
139handles.Bx = Bx;
140handles.Bz = Bz;
141handles.forder = '2nd';
142handles.funit = '[T2m2]';
143%pass the file name to all the callbacks
144guidata(hObject,handles);
145
146
147
148%display the open file name in the display text window
149h = handles.displayOpenFile;
150set(h,'String',handles.openfilename);
151
152%display the horizontal and vertical points in the display text window
153h1 = handles.Hpoints;
154set(h1,'String',Px);
155h2 = handles.Vpoints;
156set(h2,'String',Pz);
157
158
159
160% --- Executes on button press in displayOpenFile.
161function displayOpenFile_Callback(hObject, eventdata, handles)
162% hObject    handle to displayOpenFile (see GCBO)
163% eventdata  reserved - to be defined in a future version of MATLAB
164% handles    structure with handles and user data (see GUIDATA)
165
166% Hint: get(hObject,'Value') returns toggle state of displayOpenFile
167
168
169
170
171function StartLn_Callback(hObject, eventdata, handles)
172% hObject    handle to StartLn (see GCBO)
173% eventdata  reserved - to be defined in a future version of MATLAB
174% handles    structure with handles and user data (see GUIDATA)
175
176% Hints: get(hObject,'String') returns contents of StartLn as text
177%        str2double(get(hObject,'String')) returns contents of StartLn as a double
178
179%get the user input start line number
180StartLn = str2double(get(hObject,'String'));
181%save the start line number to all handles
182handles.StartLn = StartLn;
183guidata(hObject,handles);
184
185% --- Executes during object creation, after setting all properties.
186function StartLn_CreateFcn(hObject, eventdata, handles)
187% hObject    handle to StartLn (see GCBO)
188% eventdata  reserved - to be defined in a future version of MATLAB
189% handles    empty - handles not created until after all CreateFcns called
190
191% Hint: edit controls usually have a white background on Windows.
192%       See ISPC and COMPUTER.
193if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
194    set(hObject,'BackgroundColor','white');
195end
196
197
198
199function EndLn_Callback(hObject, eventdata, handles)
200% hObject    handle to EndLn (see GCBO)
201% eventdata  reserved - to be defined in a future version of MATLAB
202% handles    structure with handles and user data (see GUIDATA)
203
204% Hints: get(hObject,'String') returns contents of EndLn as text
205%        str2double(get(hObject,'String')) returns contents of EndLn as a double
206
207EndLn = str2double(get(hObject,'String'));
208
209%get the user input end line number
210EndLn = str2double(get(hObject,'String'));
211%save the end line number to all handles
212handles.EndLn = EndLn;
213guidata(hObject,handles);
214
215
216
217
218% --- Executes during object creation, after setting all properties.
219function EndLn_CreateFcn(hObject, eventdata, handles)
220% hObject    handle to EndLn (see GCBO)
221% eventdata  reserved - to be defined in a future version of MATLAB
222% handles    empty - handles not created until after all CreateFcns called
223
224% Hint: edit controls usually have a white background on Windows.
225%       See ISPC and COMPUTER.
226if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
227    set(hObject,'BackgroundColor','white');
228end
229
230
231
232% --- Executes on button press in PlotBxx.
233function PlotBxx_Callback(hObject, eventdata, handles)
234% hObject    handle to PlotBxx (see GCBO)
235% eventdata  reserved - to be defined in a future version of MATLAB
236% handles    structure with handles and user data (see GUIDATA)
237
238PlotRadiaMap_Bxx(handles.StartLn,handles.EndLn,handles.x,handles.Bx,handles.forder,handles.funit);
239
240
241% --- Executes on button press in PlotBxy.
242function PlotBxy_Callback(hObject, eventdata, handles)
243% hObject    handle to PlotBxy (see GCBO)
244% eventdata  reserved - to be defined in a future version of MATLAB
245% handles    structure with handles and user data (see GUIDATA)
246
247% plot the radia map Bx versus y
248PlotRadiaMap_Bxy(handles.StartLn,handles.EndLn,handles.x,handles.Bx,handles.forder,handles.funit);
249
250% --- Executes on button press in PlotBxxy.
251function PlotBxxy_Callback(hObject, eventdata, handles)
252% hObject    handle to PlotBxxy (see GCBO)
253% eventdata  reserved - to be defined in a future version of MATLAB
254% handles    structure with handles and user data (see GUIDATA)
255
256% plot the 2D mesh of Bx
257 PlotRadiaMap_Bxxy(handles.x,handles.Bx,handles.forder,handles.funit);
258 
259 
260 % --- Executes on button press in PlotByx.
261function PlotByx_Callback(hObject, eventdata, handles)
262% hObject    handle to PlotByx (see GCBO)
263% eventdata  reserved - to be defined in a future version of MATLAB
264% handles    structure with handles and user data (see GUIDATA)
265
266PlotRadiaMap_Byx(handles.StartLn,handles.EndLn,handles.x,handles.Bz,handles.forder,handles.funit);
267
268% --- Executes on button press in PlotByy.
269function PlotByy_Callback(hObject, eventdata, handles)
270% hObject    handle to PlotByy (see GCBO)
271% eventdata  reserved - to be defined in a future version of MATLAB
272% handles    structure with handles and user data (see GUIDATA)
273
274% plot the radia map By versus y
275PlotRadiaMap_Byy(handles.StartLn,handles.EndLn,handles.x,handles.Bz,handles.forder,handles.funit);
276
277% --- Executes on button press in PlotByxy.
278function PlotByxy_Callback(hObject, eventdata, handles)
279% hObject    handle to PlotByxy (see GCBO)
280% eventdata  reserved - to be defined in a future version of MATLAB
281% handles    structure with handles and user data (see GUIDATA)
282
283% plot the 2D mesh of By
284 PlotRadiaMap_Byxy(handles.x,handles.Bz,handles.forder,handles.funit);
285
286
287% --- Executes on button press in closefigure.
288function closefigure_Callback(hObject, eventdata, handles)
289% hObject    handle to closefigure (see GCBO)
290% eventdata  reserved - to be defined in a future version of MATLAB
291% handles    structure with handles and user data (see GUIDATA)
292
293%close all figures except figure: GUI
294figs=findobj('Type','Figure');
295close(figs(figs~=gcbf));
296
297
298
299% --- Executes on button press in pushbutton11.
300function pushbutton11_Callback(hObject, eventdata, handles)
301% hObject    handle to pushbutton11 (see GCBO)
302% eventdata  reserved - to be defined in a future version of MATLAB
303% handles    structure with handles and user data (see GUIDATA)
304
305
306% --- Executes on button press in Smooth.
307function Smooth_Callback(hObject, eventdata, handles)
308% hObject    handle to Smooth (see GCBO)
309% eventdata  reserved - to be defined in a future version of MATLAB
310% handles    structure with handles and user data (see GUIDATA)
311
312%smooth the data and save the data with the file extension: interpolation
313[sx,sBx,sBz] = SmoothRadiaMap(handles.PathName,handles.FileName,handles.x,handles.Bx,handles.Bz,...
314               handles.Px,handles.Pz,handles.Lu,handles.forder,handles.funit);
315
316 handles.sx = sx;
317 handles.sBx = sBx;
318 handles.sBz = sBz;
319 guidata(hObject,handles);
320 
321%display 'the smooth is finished' in the display text window
322h = handles.smoothfinish;
323set(h,'String','finish smooth !!!','Foregroundcolor','g');
324
325
326% --- Executes on button press in plotsmooth.
327function plotsmooth_Callback(hObject, eventdata, handles)
328% hObject    handle to plotsmooth (see GCBO)
329% eventdata  reserved - to be defined in a future version of MATLAB
330% handles    structure with handles and user data (see GUIDATA)
331
332%get the line number to plot
333Ln = handles.plotsmoothLn;
334% plot the radia map after smooth
335PlotSmoothRadiaMap(Ln,handles.x,handles.Bx,handles.Bz,handles.sx,...
336                   handles.sBx,handles.sBz,handles.forder,handles.funit);
337
338% --- Executes on button press in smoothfinish.
339function smoothfinish_Callback(hObject, eventdata, handles)
340% hObject    handle to smoothfinish (see GCBO)
341% eventdata  reserved - to be defined in a future version of MATLAB
342% handles    structure with handles and user data (see GUIDATA)
343
344% Hint: get(hObject,'Value') returns toggle state of smoothfinish
345
346
347% --- Executes on button press in open1Dmap.
348function open1Dmap_Callback(hObject, eventdata, handles)
349% hObject    handle to open1Dmap (see GCBO)
350% eventdata  reserved - to be defined in a future version of MATLAB
351% handles    structure with handles and user data (see GUIDATA)
352
353% select the file name to read
354[FileName,PathName,FilterIndex] = uigetfile('*.dat');
355setappdata(hObject,'UserFileName',FileName);
356setappdata(hObject,'UserPathName',PathName);
357
358% --- Executes on button press in Gen2Dmap.
359function Gen2Dmap_Callback(hObject, eventdata, handles)
360% hObject    handle to Gen2Dmap (see GCBO)
361% eventdata  reserved - to be defined in a future version of MATLAB
362% handles    structure with handles and user data (see GUIDATA)
363
364%get the user opened path name and file name
365PathName = getappdata(handles.open1Dmap,'UserPathName');
366FileName = getappdata(handles.open1Dmap,'UserFileName');
367% get the undulator Length
368Length = handles.Length;
369
370GenFieldMap(PathName,FileName,Length);
371
372
373
374function Length_Callback(hObject, eventdata, handles)
375% hObject    handle to Length (see GCBO)
376% eventdata  reserved - to be defined in a future version of MATLAB
377% handles    structure with handles and user data (see GUIDATA)
378
379% Hints: get(hObject,'String') returns contents of Length as text
380%        str2double(get(hObject,'String')) returns contents of Length as a double
381
382        handles.Length = str2double(get(hObject,'String'));
383        guidata(hObject,handles); %update the data
384
385      %  setappdata(hObject,'Length',Length);
386
387% --- Executes during object creation, after setting all properties.
388function Length_CreateFcn(hObject, eventdata, handles)
389% hObject    handle to Length (see GCBO)
390% eventdata  reserved - to be defined in a future version of MATLAB
391% handles    empty - handles not created until after all CreateFcns called
392
393% Hint: edit controls usually have a white background on Windows.
394%       See ISPC and COMPUTER.
395if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
396    set(hObject,'BackgroundColor','white');
397end
398
399
400
401function plotsmoothLn_Callback(hObject, eventdata, handles)
402% hObject    handle to plotsmoothLn (see GCBO)
403% eventdata  reserved - to be defined in a future version of MATLAB
404% handles    structure with handles and user data (see GUIDATA)
405
406% Hints: get(hObject,'String') returns contents of plotsmoothLn as text
407%        str2double(get(hObject,'String')) returns contents of plotsmoothLn as a double
408
409     handles.plotsmoothLn = str2double(get(hObject,'String'));
410     guidata(hObject,handles);
411
412    % setappdata(hObject,'plotsmoothLn',Ln);
413     
414% --- Executes during object creation, after setting all properties.
415function plotsmoothLn_CreateFcn(hObject, eventdata, handles)
416% hObject    handle to plotsmoothLn (see GCBO)
417% eventdata  reserved - to be defined in a future version of MATLAB
418% handles    empty - handles not created until after all CreateFcns called
419
420% Hint: edit controls usually have a white background on Windows.
421%       See ISPC and COMPUTER.
422if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
423    set(hObject,'BackgroundColor','white');
424end
425
426
427% --- Executes on button press in deleteline.
428function deleteline_Callback(hObject, eventdata, handles)
429% hObject    handle to deleteline (see GCBO)
430% eventdata  reserved - to be defined in a future version of MATLAB
431% handles    structure with handles and user data (see GUIDATA)
432
433
434%get the value of str to delete 'horizontal' or 'vertical' line
435str= getappdata(handles.popupmenu1,'str');
436
437% get the value of delete line
438deleteLnstr= getappdata(handles.deleteLn,'str');
439
440% plot the radia map after smooth
441DeleteLineRadiaMap(handles.PathName,handles.FileName,handles.x,handles.Bx,handles.Bz,handles.Lu,...
442                   handles.forder,handles.funit,deleteLnstr,str);
443
444
445
446
447% --- Executes on selection change in popupmenu1.
448function popupmenu1_Callback(hObject, eventdata, handles)
449% hObject    handle to popupmenu1 (see GCBO)
450% eventdata  reserved - to be defined in a future version of MATLAB
451% handles    structure with handles and user data (see GUIDATA)
452
453% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
454%        contents{get(hObject,'Value')} returns selected item from popupmenu1
455
456            contents = get(hObject,'String');
457            val = get(hObject,'Value');
458 % Set current data to the selected data set.
459             setappdata(hObject,'str',contents{val});
460
461% --- Executes during object creation, after setting all properties.
462function popupmenu1_CreateFcn(hObject, eventdata, handles)
463% hObject    handle to popupmenu1 (see GCBO)
464% eventdata  reserved - to be defined in a future version of MATLAB
465% handles    empty - handles not created until after all CreateFcns called
466
467% Hint: popupmenu controls usually have a white background on Windows.
468%       See ISPC and COMPUTER.
469if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
470    set(hObject,'BackgroundColor','white');
471end
472
473
474
475function deleteLn_Callback(hObject, eventdata, handles)
476% hObject    handle to deleteLn (see GCBO)
477% eventdata  reserved - to be defined in a future version of MATLAB
478% handles    structure with handles and user data (see GUIDATA)
479
480% Hints: get(hObject,'String') returns contents of deleteLn as text
481%        str2double(get(hObject,'String')) returns contents of deleteLn as a double
482
483 contents = get(hObject,'String');
484            val = get(hObject,'Value');
485 % Set current data to the selected data set.
486             setappdata(hObject,'str',contents{val});
487     
488
489% --- Executes during object creation, after setting all properties.
490function deleteLn_CreateFcn(hObject, eventdata, handles)
491% hObject    handle to deleteLn (see GCBO)
492% eventdata  reserved - to be defined in a future version of MATLAB
493% handles    empty - handles not created until after all CreateFcns called
494
495% Hint: edit controls usually have a white background on Windows.
496%       See ISPC and COMPUTER.
497if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
498    set(hObject,'BackgroundColor','white');
499end
Note: See TracBrowser for help on using the repository browser.