source: issm/trunk-jpl/src/m/DataProcessing/data_processing_tool.m@ 12996

Last change on this file since 12996 was 33, checked in by seroussi, 16 years ago

initial input

  • Property svn:executable set to *
File size: 11.8 KB
Line 
1function varargout = data_processing_tool(varargin)
2%DATA_PROCESSING_TOOL - GUI to process binary data
3%
4% this routine is a GUI that helps the user to open
5% a binary file (Little Endian, Big Endian, Float 32,
6% double,...) and save a Matlab file (.mat) with the
7% processed data and the coordinates
8%
9% Usage:
10% data_processing_tool
11
12 gui_Singleton = 1;
13 gui_State = struct('gui_Name', mfilename, ...
14 'gui_Singleton', gui_Singleton, ...
15 'gui_OpeningFcn', @data_processing_tool_OpeningFcn, ...
16 'gui_OutputFcn', @data_processing_tool_OutputFcn, ...
17 'gui_LayoutFcn', [] , ...
18 'gui_Callback', []);
19 if nargin && ischar(varargin{1})
20 gui_State.gui_Callback = str2func(varargin{1});
21 end
22
23 if nargout
24 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
25 else
26 gui_mainfcn(gui_State, varargin{:});
27 end
28end
29
30function data_processing_tool_OpeningFcn(hObject, eventdata, handles, varargin)
31 handles.output = hObject;
32
33 %enable toolbar (useful for caxis...)
34 set(hObject,'toolbar','figure');
35
36 % Update handles structure
37 guidata(hObject, handles);
38
39 %this variable used to prevent users from breaking the GUI
40 %the variable is set to 1 once the data has been processed
41 handles.processDataCompleted=0;
42
43 %initialize other variables
44 handles.Msize=NaN;
45 handles.Nsize=NaN;
46 handles.numvectors=NaN;
47 handles.endian=NaN;
48 handles.datatype=NaN;
49 handles.dx=NaN;
50 handles.dy=NaN;
51 handles.xEast=NaN;
52 handles.yNorth=NaN;
53
54 %two files permitted
55 set(handles.inputFile,'Max',1);
56 set(handles.inputFile,'Min',0);
57
58 % Update handles structure
59 guidata(hObject, handles);
60end
61
62% --- Outputs from this function are returned to the command line.
63function varargout = data_processing_tool_OutputFcn(hObject, eventdata, handles)
64
65 % Get default command line output from handles structure
66 varargout{1} = handles.output;
67end
68
69
70function inputFile_Callback(hObject, eventdata, handles)
71%no code needed for this callback, the listbox is only used as a visual
72end
73
74function addFiles_pushbutton_Callback(hObject, eventdata, handles)
75 %gets input file(s) from user. the sample data files have extension .s2p
76 [input_file,pathname] = uigetfile( ...
77 {'*.*', 'All Files (*.*)'}, ...
78 'Select files', ...
79 'MultiSelect', 'on');
80
81 %if file selection is cancelled, pathname should be zero
82 %and nothing should happen
83 if pathname==0
84 return
85 end
86
87 handles.processDataCompleted=1;
88
89 %gets the current data file names inside the listbox
90 inputFileName=get(handles.inputFile,'String');
91
92 %if they only select one file, then the data will not be a cell
93 inputFileName= fullfile(pathname,input_file);
94
95 %updates the gui to display all filenames in the listbox
96 set(handles.inputFile,'String',inputFileName);
97
98 %make sure first file is always selected so it doesn't go out of range
99 %the GUI will break if this value is out of range
100 set(handles.inputFile,'Value',1);
101
102 % Update handles structure
103 guidata(hObject, handles);
104end
105
106function reset_pushbutton_Callback(hObject, eventdata, handles)
107 %resets the GUI by clearing all relevant fields
108
109 handles.processDataCompleted = 0;
110
111 %clears the axes
112 cla(handles.axes1,'reset');
113
114 %set the popupmenu to default value
115% set(handles.plot_popupmenu,'Value',1);
116
117 %clears the contents of the listbox
118 set(handles.inputFile,'String','');
119 set(handles.inputFile,'Value',0);
120
121 %updates the handles structure
122 guidata(hObject, handles);
123end
124
125function plotdata_pushbutton_Callback(hObject, eventdata, handles)
126
127 %get the list of input file names from the listbox
128 inputFileName=get(handles.inputFile,'String');
129
130 %checks to see if the user selected any input files
131 %if not, nothing happens
132 if isempty(inputFileName)
133 errordlg('Select a file first!')
134 return
135 end
136
137 %disables the button while data is processing
138 disableButtons(handles);
139 refresh(data_processing_tool);
140
141 %parse options
142 if ~isnan(handles.Msize)
143 M=handles.Msize;
144 else
145 errordlg('Number of lines (M) not valid')
146 return
147 end
148 if ~isnan(handles.Nsize)
149 N=handles.Nsize;
150 else
151 errordlg('Number of rows (N) not valid')
152 return
153 end
154 if ~isnan(handles.numvectors)
155 numvectors=handles.numvectors;
156 %change M
157 M=numvectors*M;
158 else
159 numvectors=1;
160 end
161 if ~isnan(handles.endian)
162 endian=handles.endian;
163 else
164 endian=1;
165 end
166 if ~isnan(handles.datatype)
167 datatype=handles.datatype;
168 else
169 datatype='float32';
170 end
171
172 %open file
173 if endian==1
174 fid=fopen(inputFileName,'r','ieee-be');
175 else
176 fid=fopen(inputFileName,'r','ieee-le');
177 end
178
179 %read file
180 [u, numpoints]=fread(fid, [M,N],datatype);
181
182 %close file
183 fclose(fid);
184
185 %Pair of vectors?
186 if numvectors==2,
187 vx=u(1:2:M,:);vx=flipud(vx');
188 vy=u(2:2:M,:);vx=flipud(vx');
189
190 %keep track
191 handles.vx=vx;
192 handles.vy=vy;
193
194 u=sqrt(vx.^2+vy.^2);
195 end
196
197 cla(handles.axes1); %clear the axes
198 axes(handles.axes1); %set the axes to plot
199 grid on
200 imagesc(u)
201 colorbar
202
203 %keep track
204 handles.u=u;
205
206 %to see whether the data has been processed or not
207 handles.processDataCompleted=2;
208
209 %data is done processing, so re-enable the buttons
210 enableButtons(handles);
211 guidata(hObject, handles);
212end
213
214function plotcoord_Callback(hObject, eventdata, handles)
215
216 %check
217 if handles.processDataCompleted<2
218 errordlg('Process data first !')
219 return
220 end
221
222 %parse options
223 if ~isnan(handles.dx)
224 dx=handles.dx;
225 else
226 errordlg('value of x-spacing not supported')
227 return
228 end
229 if ~isnan(handles.dy)
230 dy=handles.dy;
231 else
232 errordlg('value of y-spacing not supported')
233 return
234 end
235 if ~isnan(handles.xEast)
236 xEast=handles.xEast;
237 else
238 errordlg('value of xEast not supported')
239 return
240 end
241 if ~isnan(handles.yNorth)
242 yNorth=handles.yNorth;
243 else
244 errordlg('value of yNorth not supported')
245 return
246 end
247
248 disableButtons(handles);
249
250 %process coordinates
251 u=handles.u;
252 s=size(u);
253 M=s(1)+1;
254 N=s(2)+1;
255
256 %correction North and East -> real
257 yNorth=yNorth-M*dy; % corner north
258 x_m=xEast+dx*(0:N-1)';
259 y_m=yNorth+dy*(0:M-1)';
260
261 %plot new axes
262 cla(handles.axes1); %clear the axes
263 axes(handles.axes1); %set the axes to plot
264 grid on
265 imagesc(x_m,y_m,handles.u)
266 set(handles.axes1,'Ydir','Normal');
267 colorbar
268
269 %Keep track of x_m and y_m
270 handles.x_m=x_m;
271 handles.y_m=y_m;
272
273 %to see whether the data has been processed or not
274 handles.processDataCompleted=3;
275
276 %data is done processing, so re-enable the buttons
277 enableButtons(handles);
278 guidata(hObject, handles);
279
280end
281
282
283function save_pushbutton_Callback(hObject, eventdata, handles)
284 %if the data hasn't been processed yet,
285 %nothing happens when this button is pressed
286 if (handles.processDataCompleted ~= 3)
287 return
288 end
289
290 disableButtons(handles);
291
292 if handles.numvectors==2,
293
294 prompt={'Enter the name of the variable 1:','Enter the name of the variable 2:','Enter the name of the file:'};
295 name='Save Matlab File';
296 numlines=1;
297 defaultanswer={'vx','vy','ProcessedFile'};
298 answer=inputdlg(prompt,name,numlines,defaultanswer);
299 variablename1=answer{1};
300 variablename2=answer{2};
301 filename=answer{3};
302
303 if ~isempty(variablename1) & ~isempty(variablename2) & ~isempty(filename)
304 %get the variables
305 x_m=handles.x_m;
306 y_m=handles.y_m;
307 eval([variablename1 ' = handles.vx;']);
308 eval([variablename2 ' = handles.vy;']);
309 x_m=handles.x_m;
310 eval(['save ' filename ' x_m y_m ' variablename1 ' ' variablename2 ]);
311 disp(['in the file ' filename ' have been saved the following variables: x_m, y_m, ' variablename1 ' and ' variablename2])
312 end
313 else
314 prompt={'Enter the name of the variable:','Enter the name of the file:'};
315 name='Save Matlab File';
316 numlines=1;
317 defaultanswer={'thickness','ProcessedFile'};
318 answer=inputdlg(prompt,name,numlines,defaultanswer);
319 variablename=answer{1};
320 filename=answer{2};
321
322 if ~isempty(variablename) & ~isempty(filename)
323 %get the variables
324 x_m=handles.x_m;
325 y_m=handles.y_m;
326 eval([variablename ' = handles.u;']);
327 eval(['save ' filename ' x_m y_m ' variablename]);
328 disp(['in the file ' filename ' have been saved the following variables: x_m, y_m, and ' variablename])
329 end
330 end
331 enableButtons(handles);
332 guidata(hObject, handles);
333end
334
335function inputFile_CreateFcn(hObject, eventdata, handles)
336 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
337 set(hObject,'BackgroundColor','white');
338 end
339end
340
341function disableButtons(handles)
342 set(handles.figure1,'Pointer','watch');
343 set(handles.plotdata_pushbutton,'Enable','off');
344 set(handles.plotcoord,'Enable','off');
345 set(handles.save_pushbutton,'Enable','off');
346 set(handles.addFiles_pushbutton,'Enable','off');
347 set(handles.reset_pushbutton,'Enable','off');
348end
349
350function enableButtons(handles)
351 set(handles.figure1,'Pointer','arrow');
352 set(handles.plotdata_pushbutton,'Enable','on');
353 set(handles.plotcoord,'Enable','on');
354 set(handles.save_pushbutton,'Enable','on');
355 set(handles.addFiles_pushbutton,'Enable','on');
356 set(handles.reset_pushbutton,'Enable','on');
357end
358
359function EndianType_Callback(hObject, eventdata, handles)
360 handles.endian=get(handles.EndianType,'Value');
361 guidata(hObject, handles);
362end
363
364function EndianType_CreateFcn(hObject, eventdata, handles)
365 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
366 set(hObject,'BackgroundColor','white');
367 end
368end
369
370function DataType_Callback(hObject, eventdata, handles)
371
372 datatype= get(handles.DataType,'Value');
373 switch datatype
374 case 1
375 string='float32';
376
377 case 2
378 string='single';
379
380 case 3
381 string='float64';
382
383 case 4
384 string='double';
385 end
386 handles.datatype=string;
387 guidata(hObject, handles);
388end
389
390function DataType_CreateFcn(hObject, eventdata, handles)
391 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
392 set(hObject,'BackgroundColor','white');
393 end
394end
395
396function PairOfVectors_Callback(hObject, eventdata, handles)
397 handles.numvectors = get(handles.PairOfVectors,'Value');
398 guidata(hObject, handles);
399end
400
401function PairOfVectors_CreateFcn(hObject, eventdata, handles)
402 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
403 set(hObject,'BackgroundColor','white');
404 end
405end
406
407function Msize_Callback(hObject, eventdata, handles)
408 handles.Msize=eval(get(hObject,'String'));
409 guidata(hObject, handles);
410end
411
412function Msize_CreateFcn(hObject, eventdata, handles)
413 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
414 set(hObject,'BackgroundColor','white');
415 end
416end
417
418function Nsize_Callback(hObject, eventdata, handles)
419 handles.Nsize=eval(get(hObject,'String'));
420 guidata(hObject, handles);
421end
422
423function Nsize_CreateFcn(hObject, eventdata, handles)
424 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
425 set(hObject,'BackgroundColor','white');
426 end
427end
428
429function dx_Callback(hObject, eventdata, handles)
430 handles.dx=eval(get(hObject,'String'));
431 guidata(hObject, handles);
432end
433function dx_CreateFcn(hObject, eventdata, handles)
434 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
435 set(hObject,'BackgroundColor','white');
436 end
437end
438
439function dy_Callback(hObject, eventdata, handles)
440 handles.dy=eval(get(hObject,'String'));
441 guidata(hObject, handles);
442end
443function dy_CreateFcn(hObject, eventdata, handles)
444 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
445 set(hObject,'BackgroundColor','white');
446 end
447end
448
449function xEast_Callback(hObject, eventdata, handles)
450 handles.xEast=eval(get(hObject,'String'));
451 guidata(hObject, handles);
452end
453function xEast_CreateFcn(hObject, eventdata, handles)
454 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
455 set(hObject,'BackgroundColor','white');
456 end
457end
458
459function yNorth_Callback(hObject, eventdata, handles)
460 handles.yNorth=eval(get(hObject,'String'));
461 guidata(hObject, handles);
462end
463function yNorth_CreateFcn(hObject, eventdata, handles)
464 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
465 set(hObject,'BackgroundColor','white');
466 end
467end
Note: See TracBrowser for help on using the repository browser.