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 pathcallback_syncdata.m
More file actions
71 lines (63 loc) · 2.15 KB
/
callback_syncdata.m
File metadata and controls
71 lines (63 loc) · 2.15 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
function callback_syncdata(hObject,eventdata,varargin)
% CALLBACK_SYNCDATA syncs all weather and daily log data from server
%__________________________________________________________________________
%
% SYNTAX:
% callback_syncdata(hObject)
% callback_syncdata(hObject,[],'menu')
%
% DESCRIPTION:
% callback_syncdata(hObject,'current') syncs all data and daily logs
% from the current season
% callback_syncdata(hObject,[]) syncs all weather data and daily logs
% from the season selected in the GUI
%__________________________________________________________________________
try
% 1 - DEFINE DIRECTORY NAMES AND DESIRED FOLDER
% 1.1 - Local database directory
GUI = guidata(hObject);
database = GUI.settings.paths.database
if ~exist(database,'dir');
try
mkdir(database);
catch
mes = ['Invalid database directory: ', database,...
'. Delete the default.mat file to start again.'];
errorlog(mes);
end
end
% 1.2 - Remote/local database directories to sync
if strcmpi(eventdata,'current');
fldr = getfolder;
else fldr = GUI.season;
end
remote = ['/pub/snow/db/',fldr,'/'];
local = [database,fldr];
% 2 - SYNC WEATHER DATA FROM CURRENT SEASON
if ~exist(local,'dir'); mkdir(local); end
syncdata(local,remote);
% % 3 - UPDATE GUI (Only calls with 'menu' option)
if ~isempty(varargin) && strcmpi(varargin{1},'menu'); %
callback_season(hObject,[]);
end
% 4 - ERROR CATCHING
catch
mes = ['Error with data sync to database (callback_syncdata.m), ',...
'see errorlog.txt.'];
errorlog(mes);
end
%--------------------------------------------------------------------------
% SUBFUNCTION: folder
function fldr = getfolder
% Get the current time
c = clock;
% Determine the current folder based on water-year
if c(2) < 10;
yr2 = num2str(c(1));
yr1 = num2str(c(1)-1);
fldr = [yr1(3:4),'-',yr2(3:4)];
else
yr1 = num2str(c(1));
yr2 = num2str(c(1)+1);
fldr = [yr1(3:4),'-',yr2(3:4)];
end