-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathgetstreamidx.m
56 lines (50 loc) · 1.87 KB
/
getstreamidx.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
function [idx,streamcode]=getstreamidx(data)
%GETSTREAMIDX Returns index array for separating dataset into streams
%
% Usage: idx=getstreamidx(data)
% [idx,streamcode]=getstreamidx(data)
%
% Description:
% IDX=GETSTREAMIDX(DATA) returns an array of indices that indicate
% records in SEIZMO structure DATA belonging to a stream. A stream is
% defined by the fields KNETWK, KSTNM, KHOLE, and KCMPNM. Only the
% third character of KCMPNM is allowed to vary between records for a
% single stream. This means that sites with multiple sensors will be
% treated as separate streams as well as sensors that have multiple
% streams of digitization (ie BH? and HH? channels would be treated as
% separate streams).
%
% [IDX,STREAMCODE]=GETSTREAMIDX(DATA) also returns the unique stream
% codes used to separate the streams.
%
% Notes:
% - Case insensitive; all characters are upper-cased.
%
% Examples:
% % Break a dataset up into separate streams:
% idx=getstreamidx(data)
% for i=1:max(idx)
% streamdata{i}=data(idx==i);
% end
%
% See also: GETNETWORKIDX, GETSTATIONIDX, GETCOMPONENTIDX, GETSITEIDX
% Version History:
% June 28, 2009 - initial version
% Jan. 29, 2010 - cleaned up unnecessary code
% Aug. 11, 2010 - nargchk fix, doc update
% Jan. 28, 2012 - pass char array to strnlen, doc update
% Sep. 5, 2013 - fixed error from strnlen char<=>cell conversion
%
% Written by Garrett Euler (ggeuler at wustl dot edu)
% Last Updated Sep. 5, 2013 at 22:55 GMT
% todo:
% check nargin
error(nargchk(1,1,nargin));
% get header info
kname=upper(getheader(data,'kname'));
% get stream groups
% - truncate kcmpnm to first 2 characters
[streamcode,idx,idx]=unique(strcat(...
kname(:,1),'.',kname(:,2),'.',kname(:,3),'.',...
strnlen(char(kname(:,4)),2)));
end