function varargout = GUIforWeekdayPredictor(varargin)
% GUIFORWEEKDAYPREDICTOR M-file for GUIforWeekdayPredictor.fig
% GUIFORWEEKDAYPREDICTOR, by itself, creates a new GUIFORWEEKDAYPREDICTOR or raises the existing
% singleton*.
%
% H = GUIFORWEEKDAYPREDICTOR returns the handle to a new GUIFORWEEKDAYPREDICTOR or the handle to
% the existing singleton*.
%
% GUIFORWEEKDAYPREDICTOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUIFORWEEKDAYPREDICTOR.M with the given input arguments.
%
% GUIFORWEEKDAYPREDICTOR('Property','Value',...) creates a new GUIFORWEEKDAYPREDICTOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUIforWeekdayPredictor_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUIforWeekdayPredictor_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUIforWeekdayPredictor
% Last Modified by GUIDE v2.5 07-Mar-2011 14:33:58
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUIforWeekdayPredictor_OpeningFcn, ...
'gui_OutputFcn', @GUIforWeekdayPredictor_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
% --- Executes just before GUIforWeekdayPredictor is made visible.
function GUIforWeekdayPredictor_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUIforWeekdayPredictor (see VARARGIN)
% Choose default command line output for GUIforWeekdayPredictor
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes GUIforWeekdayPredictor wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUIforWeekdayPredictor_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function year_CreateFcn(hObject, eventdata, handles)
% hObject handle to year (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function year_Callback(hObject, eventdata, handles)
% hObject handle to year (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
year = str2double(get(hObject , 'string'));
if isnan(year)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
% Save the new volume value
handles.metricdata.year = year;
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of year as text
% str2double(get(hObject,'String')) returns contents of year as a double
% --- Executes during object creation, after setting all properties.
function month_CreateFcn(hObject, eventdata, handles)
% hObject handle to month (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function month_Callback(hObject, eventdata, handles)
% hObject handle to month (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
month = str2double(get(hObject , 'string'));
if isnan(month)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
if (month > 12)
set(hObject, 'String', 0);
errordlg('Input must be less than 13','Error');
end
A = month;
while A == 1 || A == 3 || A == 5 || A == 7 || A == 8 || A == 10 || A == 12
if (handles.metricdata.date > 31)
set(hObject, 'String', 0);
errordlg('Input Date must be less than 32','Error');
end
break
end
while A == 4 || A == 6 || A == 9 || A == 11
if (handles.metricdata.date > 30)
set(hObject, 'String', 0);
errordlg('Input Date must be less than 31','Error');
end
break
end
B = handles.metricdata.year;
while A == 2
if (rem(B,4) ~= 0)
if (handles.metricdata.date > 28)
set(hObject, 'String', 0);
errordlg('Input Date must be less than 29','Error');
end
else
if (handles.metricdata.date > 29)
set(hObject, 'String', 0);
errordlg('Input Date must be less than 29','Error');
end
end
break
end
% Save the new volume value
handles.metricdata.month = month;
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of month as text
% str2double(get(hObject,'String')) returns contents of month as a double
% --- Executes during object creation, after setting all properties.
function date_CreateFcn(hObject, eventdata, handles)
% hObject handle to date (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function date_Callback(hObject, eventdata, handles)
% hObject handle to date (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
date = str2double(get(hObject , 'string'));
if isnan(date)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
A = handles.metricdata.month;
while A == 1 || A == 3 || A == 5 || A == 7 || A == 8 || A == 10 || A == 12
if (date > 31)
set(hObject, 'String', 0);
errordlg('Input must be less than 32','Error');
end
break
end
while A == 4 || A == 6 || A == 9 || A == 11
if (date > 30)
set(hObject, 'String', 0);
errordlg('Input must be less than 31','Error');
end
break
end
B = handles.metricdata.year;
while A == 2
if (rem(B,4) ~= 0)
if (date > 28)
set(hObject, 'String', 0);
errordlg('Input must be less than 29','Error');
end
else
if (date > 29)
set(hObject, 'String', 0);
errordlg('Input must be less than 29','Error');
end
end
break
end
% Save the new volume value
handles.metricdata.date = date;
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of date as text
% str2double(get(hObject,'String')) returns contents of date as a
% double
% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
% hObject handle to calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (handles.metricdata.year == 0)
if (handles.metricdata.month == 0)
if (handles.metricdata.date == 0)
set(handles.weekday, 'String', '-----')
end
end
end
K1 = 0;
G1 = 0;
T4 = [0 3 3 6 1 4 6 2 5 0 3 5];
for Q2 = 1:1:12;
while handles.metricdata.month == Q2
m = T4(1,Q2);
break
end
end
K = abs(handles.metricdata.year - 1900);
while (K >= 28)
K1 = K - 28;
K = K1;
end
K2 = [0 5 3 1 6 4 2];
for Q1 = 0:4:24;
if (K1 >= Q1) && (K1 < Q1+4)
m1 = K2(1,((Q1+4)./4));
M = abs(Q1 - K1);
end
end
m2 = handles.metricdata.date + m + m1 + M;
while m2 >= 7
m2 = m2 - 7;
end
G = {'Sunday','Monday','Tuesday','Wednusday','Thursday','Friday','Saturday'};
for Q = 0:1:6
if (Q == m2)
G1 = (G(1,Q+1));
end
end
if (m2 == 0)
m2 = 7;
end
m3 = handles.metricdata.date + (7 - m2);
mnum = 0;
if ( m3 ~= 7 || m3 ~= 14 || m3 ~= 21 || m3 ~= 28 )
mnum = mnum + 1;
end
while m3 >= 7
m3 = m3 - 7;
mnum = mnum + 1;
end
weekday = G1;
set(handles.weekday, 'String', weekday);
pday = date;
set(handles.pday, 'String', pday);
weeknumber = mnum;
set(handles.weeknumber, 'String', weeknumber);
% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
initialize_gui(gcbf, handles, true);
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
if isfield(handles, 'metricdata') && ~isreset
return;
end
handles.metricdata.year = 0;
handles.metricdata.month = 0;
handles.metricdata.date = 0;
set(handles.year, 'String', handles.metricdata.year);
set(handles.month, 'String', handles.metricdata.month);
set(handles.date, 'String', handles.metricdata.date);
set(handles.weekday, 'String', '-----');
set(handles.weeknumber, 'String', '-----');
set(handles.pday, 'String', date);
% Update handles structure
guidata(handles.figure1, handles);
% --- Executes during object creation, after setting all properties.
function pday_CreateFcn(hObject, eventdata, handles)
% hObject handle to pday (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function weeknumber_CreateFcn(hObject, eventdata, handles)
% hObject handle to weeknumber (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called