forked from MouseLightPipeline/pipeline-stitching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_date_from_input_folder_path.m
68 lines (58 loc) · 1.81 KB
/
sample_date_from_input_folder_path.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
function result = sample_date_from_input_folder_path(input_folder_path)
result_or_empty = sample_date_from_input_folder_path_helper(input_folder_path) ;
if isempty(result_or_empty) ,
error('Unable to determine sample date for path %s', input_folder_path) ;
else
result = result_or_empty ;
end
end
function result = sample_date_from_input_folder_path_helper(input_folder_path)
if isempty(input_folder_path) || isequal(input_folder_path, '/') ,
% Down to the root, so give up
result = '' ;
else
[parent_path, leaf_name] = split_path(input_folder_path) ;
if is_date(leaf_name) ,
result = leaf_name ;
else
% Recurse, hopefully will find a date farther up the path
% hierarchy
result = sample_date_from_input_folder_path_helper(parent_path) ;
end
end
end
function result = is_date(str)
parts = strsplit(str, '-') ;
if length(parts)==3 ,
year_as_string = parts{1} ;
month_as_string = parts{2} ;
day_as_string = parts{3} ;
result = is_year(year_as_string) && is_month(month_as_string) && is_day(day_as_string) ;
else
result = false ;
end
end
function result = is_year(str)
if length(str)==4 ,
year = str2double(str) ;
result = ~isnan(year) && round(year)==year ;
else
result = false ;
end
end
function result = is_month(str)
if length(str)==2 ,
month = str2double(str) ;
result = ~isnan(month) && round(month)==month && 1<=month && month<=12 ;
else
result = false ;
end
end
function result = is_day(str)
if length(str)==2 ,
day = str2double(str) ;
result = ~isnan(day) && round(day)==day && 1<=day && day<=31 ;
else
result = false ;
end
end