-
Notifications
You must be signed in to change notification settings - Fork 9
/
CSPargusFilename.m
236 lines (208 loc) · 6.99 KB
/
CSPargusFilename.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
function name = CSPargusFilename(i1, i2, i3, i4, i5,i6)
% argusFilename -- create an Argus file name based on relevant data FOR
% COASTSNAP (MDH alteration)
%
% name = argusFilename( I ) builds the name based on the
% data found in I. I is (am?) a struct with the following
% fields as a minimum:
%
% i.time -- epoch time (string or number)
% i.station -- name of station, e.g. 'argus00'
% i.camera -- camera number
% i.type -- type of the image, e.g. 'snap'
% i.user -- username that contributed the photo (e.g. Instagram username)
% i.format -- format for the data, e.g. 'jpg'.
%
% NOTE that this struct looks very much like the struct returned from
% parseFilename. There is a reason for that. Fields not mentioned above
% are ignored in building the filename. Also note that 'epoch' will
% be treated as 'time' if 'time' is not present.
%
% OR
% name = argusFilename( TIME, STATION, CAMERA, TYPE, USERNAME, FORMAT ) does
% the same thing without the nice, clean, pretty, convenient,
% tidy, easy struct. Wouldn't you like to use structs?
%
% If 'camera' is specified as -1 (the number), the camera specification
% will be ommitted from the resulting name. This is how you can build
% names for runup, stereo, etc.
%
% Note: Nothing checks to see if this file really exists. It's just
% creating a name in the correct format.
%
% Example: argusFilename( 9000, 'foobear', 1, 'snap','mitch', 'jpg' )
% ans = 9000.Thu.Jan.01_02_30_00.GMT.1970.foobear.c1.snap.mitch.jpg
%
% $Id: argusFilename.m 196 2016-06-02 20:47:36Z stanley $
% $Log: argusFilename.m,v $
% Revision 1.27 2018/06/12 08:39:00 mitch
% altered to make it suitable to CoastSnap environment where having the username
% of the person that took the photo is critical
%
% Revision 1.26 2012/01/31 23:04:49 stanley
% fixed comments to remove version info
%
% Revision 1.25 2008/11/22 00:02:58 stanley
% fix creation of names with dot-terminal or two-dots
%
% Revision 1.24 2008/09/12 21:46:13 stanley
% added a DBTestConnect -- dies silently without DB access
%
% Revision 1.23 2007/12/04 18:12:36 stanley
% added error test for non-station
%
% Revision 1.22 2006/05/09 22:19:05 stanley
% added small rounding constant to datevec time
%
% Revision 1.21 2006/05/02 17:16:56 stanley
% missed one bit
%
% Revision 1.20 2006/05/01 22:04:42 stanley
% added fixes for localTZ for sites. ick...
%
% Revision 1.19 2004/10/13 18:49:04 stanley
% Deal with cx camera 'numbers'
%
% Revision 1.18 2004/03/25 16:55:24 stanley
% auto insert keywords
%
% recordPath;
% DBTestConnect;
if nargin == 6
i.time = i1;
i.station = i2;
i.camera = i3;
i.type = i4;
i.user = i5;
i.format = i6;
elseif nargin == 1
i = i1;
else
error('Invalid input list');
end
% make 'epoch' a synonym for 'time'
try
% look for 'time', ok if there
t = getfield(i,'time');
catch
% no 'time', look for 'epoch'
try
t = getfield(i,'epoch');
catch
error('no time or epoch field in input');
end
end
i.time = t;
if ischar( i.time )
i.time = str2num(i.time);
end
% allow wildcard camera spec from empty camera
if isempty(i.camera)
camData = '.c*';
% allow cx for multi-camera names
elseif ischar(i.camera)
camData = ['.c' i.camera ];
% reverse the parseFilename of data type files -- they get -1 for camera
elseif (i.camera == -1)
camData = '';
% all else just puts in camera number
else
camData = [ '.c' num2str(i.camera) ];
end
% one last check -- time must be int
i.time = floor(i.time);
% Stefan, May 2002: Get TZname/offset from table site. If empty, than
% use default GMT
% station = DBGetStationsByName(i.station,i.time);
%MDH, June 2018 make small adjustment to incorporate CoastSnap DB info
site = CSPreadSiteDB(i.station);
TZName = site.timezone.name;
TZoffset = site.timezone.gmt_offset;
%if isempty(station)
% no station by that name, punt!
% site.useLocalNames = 0;
% site.TZName = 'GMT';
% site.TZoffset = 0;
% warning( [ 'DB has no station ' i.station ', assuming GMT' ] );
% else
% site = DBGetTableEntry('site','id',station.siteID);
% end;
% If local TZstring in filename, than use that one & convert timestring
% to local time
% if site.useLocalNames
% TZName = site.TZName;
% TZoffset = site.TZoffset;
% % end;
% % if ~isempty(TZName) & ~isempty(TZoffset)
time = i.time+TZoffset*3600; %convert TZoffset in hours to seconds
% else
% TZName = 'GMT';
% time = i.time;
% end
% hey! what this 0.01 anyway!?!.
% taking integer seconds into double matlab time results in quantizing
% error! int->double->datevec->round sometimes results in seconds
% of 59.99999, which should have been rounded by datevec into a
% normalized 0 seconds and +1 minutes. "floor" is wrong -- 59.99999
% should be 0 +1min and not 59. So, add very small time which should
% ALWAYS round out of the second pos but never cause rollover into
% minutes. Tried .5 (normal rounding) but example
% (1.131267000000000e+09) rounded to +1 second. Sigh.
d = round(datevec(epoch2Matlab(time+0.01)));
dmon = datestr(epoch2Matlab(time), 3);
dday = datestr(epoch2Matlab(time), 8);
if isfield( i, 'short' )
name = sprintf( ...
['%d.%02d%02d%02d.%s%s.%s.%s'], ...
i.time, ...
d(4), ...
d(5), ...
d(6), ...
i.station, ...
camData, i.type, i.format );
else
name = sprintf( ...
['%d.%s.%s.%02d_%02d_%02d_%02d.%s.%4d.%s%s.%s.%s.%s'], ...
i.time, ...
dday, ...
dmon, ...
d(3), ...
d(4), ...
d(5), ...
d(6), ...
TZName, ...
d(1), ...
i.station, ...
camData, i.type,i.user, i.format );
end;
% one last fix. Empty type or format may leave double dots or dot at
% end of name. remove.
if( name(end) == '.' )
name = name(1:end-1);
end
boo = strfind(name, '..');
if ~isempty(boo)
for i=boo
name = [name(1:i-1) name(i+1:end)];
end
end
%
%
% Copyright (C) 2017 Coastal Imaging Research Network
% and Oregon State University
% This program is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation, version 3 of the
% License.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see
% <http://www.gnu.org/licenses/>.
% CIRN: https://coastal-imaging-research-network.github.io/
% CIL: http://cil-www.coas.oregonstate.edu
%
%key UAVProcessingToolbox
%