This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradthermGUI.m
More file actions
280 lines (234 loc) · 10.1 KB
/
Copy pathradthermGUI.m
File metadata and controls
280 lines (234 loc) · 10.1 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
function varargout = radthermGUI(varargin)
% RADTHERMGUI M-file for radthermGUI.fig
%__________________________________________________________________________
% USAGE: [h] = radthermGUI(MAINgui,eventdata);
%
% INPUT: MAINgui - handle to calling object on Program Control window
% eventdata - not used, MATLAB required
%
% OUTPUT: h = gui handle for radtherm input figure
%
% This m-file is generated automatically by MATLAB's GUIDE program and then
% was modified.
%
% PROGRAM OUTLINE:
% 1 - INITILIZATION CODE - DO NOT EDIT
% 2 - EXECUTES JUST BEFORE RADTHERMGUI IS MADE VISIBLE.
% 3 - OUTPUTS FROM THIS FUNCTION ARE RETURNED TO THE COMMAND LINE.
% CALLBACK: callback_saverdt
% CALLBACK: callback_openrdt
% CALLBACK: callback_station
% CALLBACK: updatetime
% CALLBACK: callback_savefile
% CALLBACK: exit
%__________________________________________________________________________
% 1 - INITILIZATION CODE - DO NOT EDIT
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @radthermGUI_OpeningFcn, ...
'gui_OutputFcn', @radthermGUI_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% 2 - EXECUTES JUST BEFORE RADTHERMGUI IS MADE VISIBLE
function radthermGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% 2.1 - Set the handles structure for radtherm and program control gui
r = handles;
h = guihandles(varargin{1});
% 2.2 - Set Update time callback
set(r.updatetime,'Callback',{@updatetime,varargin{1}});
updatetime(r.updatetime,1,varargin{1});
% 2.3 - Initilize the stations menus
s = {'staAIRT','staSOLAR','staWIND','staHUMID','staLWIR',...
'staWINDIR'};
u = {{'C','F'},'W/m^2',{'m/s','mph'},'%','W/m^2','deg'};
use = getselected(varargin{1},'all');
for i = 1:length(s);
set(r.(s{i}),'String',use,'Callback',{@callback_station},...
'UserData',{u{i},h});
callback_station(r.(s{i}),1);
end
% 2.4 - Set Build RadTherm File and exit callback
set(r.save,'Callback',{@callback_savefile});
set(r.exit,'Callback',{@exit});
% 2.5 - Set open/save *.rdt callbacks and open default file
set(r.openfile,'Callback',{@callback_openrdt},...
'UserData',varargin{1});
callback_openrdt(r.openfile,1,'radtherm.rdt');
set(r.savefile,'Callback',{@callback_saverdt},...
'UserData',varargin{1});
% 3 - OUTPUTS FROM THIS FUNCTION ARE RETURNED TO THE COMMAND LINE
function varargout = radthermGUI_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%--------------------------------------------------------------------------
% CALLBACK: callback_saverdt
function callback_saverdt(hObject,eventdata)
% CALLBACK_SAVERDT saves a *.rdt that stores the settings for GUI
% 1 - Extract SAVED path and build handle strings
h = guihandles(hObject);
user = get(hObject,'UserData');
GUI = guidata(user);
pth = GUI.settings.paths.saved;
A = {'AIRT','SOLAR','WIND','HUMID','LWIR','WINDIR'};
% 2 - Determine the settings file to open
[fn,pn] = uiputfile({'*.rdt','RadTherm Settings (*.rdt)'},...
'Save RadTherm Settings...',[pth,'*.rdt']);
if fn == 0; return; end
filename = [pn,fn];
% 3 - Extract information from GUI
for i = 1:length(A);
t{1} = ['sta',A{i}]; t{2} = A{i}; % Tags for weather/station menu
for ii = 1:length(t);
str = get(h.(t{ii}),'String');
B.(t{ii}) = str{get(h.(t{ii}),'Value')};
end
end
% 4 - Write file
save(filename,'-mat','-struct','B');
%--------------------------------------------------------------------------
% CALLBACK: callback_openrdt
function callback_openrdt(hObject,eventdata,varargin)
% CALLBACK_OPENRDT opens a *.rdt that stores the settings for GUI
% 1 - Extract SAVED path and build handle strings
h = guihandles(hObject);
user = get(hObject,'UserData');
GUI = guidata(user);
pth = GUI.settings.paths.saved;
% 2 - Determine the settings file to open
% 2.1 - Determine the file to open
if ~isempty(varargin); filename = varargin{1};
else
[fn,pn] = uigetfile({'*.rdt','RadTherm Settings (*.rdt)'},...
'Open RadTherm Settings...',pth);
filename = [pn,fn];
end
% 2.2 - Test the file exists
if ~exist(filename); disp('File does not exist.'); return; end
% 2.3 - Open/read the file
B = load(filename,'-mat');
% 3 - Set variables
fn = fieldnames(B);
for i = 1:length(fn);
str = get(h.(fn{i}),'string');
idx = strmatch(B.(fn{i}),str);
if isempty(idx); idx = 1; end
set(h.(fn{i}),'value',idx(1));
if strmatch('str',fn{i}); callback_station(h.(fn{i}),[]); end
end
%--------------------------------------------------------------------------
% CALLBACK: callback_station
function callback_station(hObject,eventdata)
% CALLBACK_STATION updates the weather variables if a station is selected.
% 1 - Get the user data from the station menu
r = guihandles(hObject);
user = get(hObject,'UserData');
h = user{2}; % Handle to Program Control Window
% 2 - Determine the station that was selected
str = get(hObject,'String');
station = str{get(hObject,'Value')};
% 3 - Get the station data structure and group items to appropriate unit
data = get(h.(station),'UserData');
unit = user{1};
if ~iscell(unit); unit = {unit}; end
grp = group_items(data.variables,unit,'unit');
% 4 - Updata the weather variable popup menu
tag = get(hObject,'Tag');
wx = tag(4:length(tag));
set(r.(wx),'String',[grp{:}],'UserData',data,'Value',1);
%--------------------------------------------------------------------------
% CALLBACK: updatetime
function updatetime(hObject,eventdata,gui)
% hObject,eventdata - not used
% gui - Program Control handle
% rad -
% 1 - Set the start and end dates
r = guihandles(hObject);
GUI = guidata(gui);
S = GUI.time;
set(r.strt,'String',datestr(S(1),'mmm-dd-yy HH:MM'));
set(r.stop,'String',datestr(S(2),'mmm-dd-yy HH:MM'));
% 2 - Set user data of save button to store times
set(r.save,'UserData',S);
% 3 - Set the filename
fname = ['w',datestr(S(1),'mmddyy'),'.txt'];
set(r.fname,'String',fname);
%--------------------------------------------------------------------------
% CALLBACK: callback_savefile
function callback_savefile(hObject,eventdata)
% CALLBACK_SAVEFILE - executes when the user press build RadTherm button
% hObject - calling function handle
% eventdata - not used
% 1 - EXTRACT DATA FROM MENU's
% 1.1 - Handle tags of variable popup menus
list = {'AIRT','SOLAR','WIND','HUMID','LWIR','WINDIR'};
% 1.2 - Cycle through each variable option and extract data
r = guihandles(hObject);
for i = 1:length(list);
user = get(r.(list{i}),'UserData'); % Complete station data
str = get(r.(list{i}),'String');
item = str{get(r.(list{i}),'Value')}; % Selected variable
data{i}(:,1) = user.Time; % Time data
temp = user.variables.(item).data; % Variable data
unit = user.variables.(item).unit; % Variable data
data{i}(:,2) = getunit(unit,'convert',temp,'metric');
end
% 2 - BUILD DATA ARRAY's WITH EQUIVALENT TIMES
% 2.1 - Build the time array for output file using interval
t = get(hObject,'UserData');
int = str2double(get(r.interval,'String'));
if isnan(int); int = 30; end
time = t(1):1/1440*int:t(2);
% 2.2 - Cycle through data and interpolate desired data
for i = 1:length(data);
x = data{i}(:,1); Y = data{i}(:,2); xi = time;
RAD(:,i) = interp1(x,Y,xi,'pchip');
end
% 3 - WRITE THE FILE TO A TEXT FILE
% 3.1 - Build a numeric array containing all necessary data
% 3.1.1 - Build time array and zeros array
TM = str2double(cellstr((datestr(time,'HHMM'))));
n = size(RAD,1); Z(1:n,1) = 0;
% 3.1.2 - Build complete data array and title row
RAD = [TM,RAD(:,1:4),Z,RAD(:,5:6),Z];
TITLE = {'TIME',list{1:4},'CLOUD',list{5:6},'RAINRATE'};
% 3.2 - Output the data
% 3.2.1 - Determine file for writing
fname = ['w',datestr(t(1),'mmddyy'),'.txt'];
[fl,pth] = uiputfile(fname,'Save file as...');
if fl == 0; return; end
output = [pth,fl];
% 3.2.2 - Write to file
fid = fopen(output,'w');
try
% Format statements for header and data (space deliminated)
headformat = '%4s %8s %8s %8s %8s %8s %8s %8s %8s\n';
dataformat = ['%04.0f %8.3f %8.3f %8.3f %8.3f %8.3f ',...
'%8.3f %8.3f %8.3f\n'];
% Write Data
fprintf(fid,'%s\n','04'); % Print the '4'
fprintf(fid,headformat,TITLE{:}); % Print the headers
fprintf(fid,dataformat,RAD'); % Print the data
fclose(fid); % Closes file
% 3.2.3 - Catch error if the above fails
catch
fclose(fid);
errordlg('Problem writing file, check input file',...
'ERROR (radtherm.m)');
return
end
%--------------------------------------------------------------------------
% CALLBACK: exit
function exit(hObject,eventedata)
h = guihandles(hObject); close(h.figure1);