-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurvesave.m
214 lines (197 loc) · 7.17 KB
/
curvesave.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
function curvesave(varargin)
% CURVESAVE Called by specr and trueref to save current curves to files.
%
% Copyright 2004, Zhang Jiang
hCurrentFig = gcf;
hCurrentAxes = gca;
hLine = findall(gca,'Type','line');
if isempty(hLine)
return;
end
% --- get tags of lines and remove datatipmarkers from hLine
tempHLine = [];;
lineTags = {};
for iLine = 1:length(hLine)
if ~strcmp(get(hLine(iLine),'Tag'),'DataTipMarker')
tempHLine(length(tempHLine)+1) = hLine(iLine);
lineTags{length(lineTags)+1} = get(hLine(iLine),'Tag');
end
end
hLine = tempHLine';
lineTags = fliplr(lineTags);
% --- figure layout for specrsave request
figSize = get(hCurrentFig,'position');
figCenter = [(figSize(1)+figSize(3)/2),...
(figSize(1)+figSize(4)/2)];
figSaveSize = [figSize(1)+5,(figSize(2)+figSize(4))-210,240,210];
hFigSave = figure(...
'Units','pixels',...
'MenuBar','none',...
'Units','pixels',...
'Name','Save to File',...
'NumberTitle','off',...
'IntegerHandle','off',...
'Position',figSaveSize,...
'HandleVisibility','callback',...
'Tag','figsave',...
'Resize','off',...
'WindowStyle','modal',...
'UserData',[]);
% --- layeout panel select curve
panelSelectCurveSize = [10 figSaveSize(4)-70 figSaveSize(3)-20 60];
hPanelSelectCurve = uipanel(...
'Parent',hFigSave,...
'BackgroundColor',get(hFigSave,'Color'),...
'Title','Select curve',...
'Units','pixels',...
'Position',panelSelectCurveSize);
hPopupmenuSelectCurve = uicontrol(...
'Parent',hPanelSelectCurve,...
'Style','popupmenu',...
'BackgroundColor','w',...
'Units','pixels',...
'Position',[10 12.5 panelSelectCurveSize(3)-20 25],...
'String',lineTags,...
'HorizontalAlignment','left',...
'Value',1,...
'Tag','figsave_PopupmenuSelectCurve');
% --- layout panel saving format
panelSelectFormatSize = [10 figSaveSize(4)-panelSelectCurveSize(4)-90 figSaveSize(3)-20 70];
hPanelSelectFormat = uipanel(...
'Parent',hFigSave,...
'BackgroundColor',get(hFigSave,'Color'),...
'Title','Format',...
'Units','pixels',...
'Position',panelSelectFormatSize);
hRadiobutton1 = uicontrol(...
'Parent',hPanelSelectFormat,...
'Style','radiobutton',...
'BackgroundColor',get(hFigSave,'Color'),...
'Position',[10 panelSelectFormatSize(4)-40 panelSelectFormatSize(3)-20 25],...
'String','xdata ydata error',...
'Tag','figsave_radiobuttion1',...
'Value',1,...
'callback',@radiobutton1Fcn);
hRadiobutton2 = uicontrol(...
'Parent',hPanelSelectFormat,...
'Style','radiobutton',...
'BackgroundColor',get(hFigSave,'Color'),...
'Position',[10 panelSelectFormatSize(4)-65 panelSelectFormatSize(3)-20 25],...
'String','xdata ydata',...
'Tag','figsave_radiobuttion2',...
'Value',0,...
'callback',@radiobutton2Fcn);
% --- layout OK and Cancel buttons
hPushbuttonOK = uicontrol(...
'Parent',hFigSave,...
'Style','pushbutton',...
'String','Next',...
'Position',[20 20 (figSaveSize(3)-60)/2 25],...
'callback',{@figsave_OKRequestFcn,hCurrentFig,hCurrentAxes});
hPushbuttonCancel = uicontrol(...
'Parent',hFigSave,...
'Style','pushbutton',...
'String','Cancel',...
'Position',[figSaveSize(3)/2+10 20 (figSaveSize(3)-60)/2 25],...
'Callback',@figsave_CloseRequestFcn);
%================================================================
% --- radiobutton1 callback fcn (save without error)
%================================================================
function radiobutton1Fcn(hObject,eventdata)
hFigSave = gcf;
hRadiobutton1 = findall(hFigSave,'Tag','figsave_radiobuttion1');
hRadiobutton2 = findall(hFigSave,'Tag','figsave_radiobuttion2');
set(hRadiobutton1,'Value',1);
set(hRadiobutton2,'Value',0);
%================================================================
% --- radiobutton1 callback fcn (save with error)
%================================================================
function radiobutton2Fcn(hObject,eventdata)
hFigSave = gcf;
hRadiobutton1 = findall(hFigSave,'Tag','figsave_radiobuttion1');
hRadiobutton2 = findall(hFigSave,'Tag','figsave_radiobuttion2');
set(hRadiobutton1,'Value',0);
set(hRadiobutton2,'Value',1);
%================================================================
% --- close function
%================================================================
function figsave_CloseRequestFcn(hObject,eventdata)
delete(gcf);
return;
%================================================================
% --- print to figure
%================================================================
function figsave_OKRequestFcn(hObject,eventdata,hCurrentFig,hCurrentAxes)
% --- determine the curve to save
hFigSave = gcf;
hRadiobutton1 = findall(hFigSave,'Tag','figsave_radiobuttion1');
hRadiobutton2 = findall(hFigSave,'Tag','figsave_radiobuttion2');
hPopupmenuSelectCurve = findobj(hFigSave,'Tag','figsave_PopupmenuSelectCurve');
curveStrList = get(hPopupmenuSelectCurve,'String');
curveStr = curveStrList{get(hPopupmenuSelectCurve,'Value')};
hLine = findall(hCurrentAxes,'Type','line');
hLine2Save = findall(hLine,'Tag',curveStr);
% --- get setting parameters
hFigSpecr = findall(0,'Tag','specr_Fig');
settings = getappdata(hFigSpecr,'settings');
savepath = settings.savepath;
% --- get data from curve
xdata = get(hLine2Save,'xdata');
ydata = get(hLine2Save,'ydata');
ydataError = getappdata(hLine2Save,'ydataError');
if get(hRadiobutton1,'Value') == 1 % determine saving w/t error
data2save = [xdata' ydata' ydataError];
else
data2save = [xdata' ydata'];
end
% --- go the previous save path
prePath = pwd;
if isempty(savepath)
savepath = pwd;
end
try
go_savepath_str = ['cd ','''',savepath,''''];
eval(go_savepath_str);
catch
go_savepath_str = ['cd ','''',pwd,''''];
eval(go_savepath_str);
end
% --- user choose a file to save
filter={'*.dat','Data File (*.dat)';...
'*.txt','Text Documents (*.txt)';...
'*.*','All Files (*.*)'};
[filename, pathname,filterIndex] = uiputfile(filter,'Save Data As',[curveStr,'.dat']);
% If 'Cancel' was selected then return
if isequal([filename,pathname],[0,0])
restorePath(prePath);
return
else
% Construct the full path and save
File = fullfile(pathname,filename);
switch filterIndex
case 1
if ~ strcmp(File(end-3:end),'.dat')
File=[File '.dat'];
end
case 2
if ~ strcmp(File(end-3:end),'.txt')
File=[File '.txt'];
end
case 3
end
go_savepath_str = ['cd ','''',pathname,'''']; % change path
eval(go_savepath_str);
save_str=['save ',filename,' data2save -ascii -tabs'];
eval(save_str);
end
restorePath(prePath);
settings.savepath = pathname;
setappdata(hFigSpecr,'settings',settings);
settings = getappdata(hFigSpecr,'settings');
delete(hFigSave);
%=========================================================
% --- restore to previous path
%=========================================================
function restorePath(prePath)
path_str = ['cd ','''',prePath,''''];
eval(path_str);