function [XX,I] = rdmseed(varargin)
%RDMSEED Read miniSEED format file.
% X = RDMSEED(F) reads file F and returns a M-by-1 structure X containing
% M blocks ("data records") of a miniSEED file with headers, blockettes,
% and data in dedicated fields, in particular, for each data block X(i):
% t: time vector (DATENUM format)
% d: data vector (double)
% BLOCKETTES: existing blockettes (substructures)
%
% Known blockettes are 100, 500, 1000, 1001 and 2000. Others will be
% ignored with a warning message.
%
% X = RDMSEED(F,ENCODINGFORMAT,WORDORDER,RECORDLENGTH), when file F does
% not include the Blockette 1000 (like Seismic Handler outputs), specifies:
% - ENCODINGFORMAT: FDSN code (see below); default is 10 = Steim-1;
% - WORDORDER: 1 = big-endian (default), 0 = little-endian;
% - RECORDLENGTH: must be a power of 2, at least 256 (default is 4096).
% If the file contains Blockette 1000 (which is mandatory in the SEED
% convention...), these 3 arguments are ignored.
%
% X = RDMSEED without input argument opens user interface to select the
% file from disk.
%
% [X,I] = RDMSEED(...) returns a N-by-1 structure I with N the detected
% number of different channels, and the following fields:
% ChannelFullName: channel name,
% XBlockIndex: channel's vector index into X,
% ClockDrift: vector of time interval errors, in seconds,
% between each data block (relative to sampling
% period). This can be compared to "Max Clock Drift"
% value of a Blockette 52.
% = 0 in perfect case
% < 0 tends to overlapping
% > 0 tends to gapping
% OverlapBlockIndex: index of blocks (into X) having a significant
% overlap with previous block (less than 0.5
% sampling period).
% OverlapTime: time vector of overlapped blocks (DATENUM format).
% GapBlockIndex: index of blocks (into X) having a significant gap
% with next block (more than 0.5 sampling period).
% GapTime: time vector of gapped blocks (DATENUM format).
%
% RDMSEED(...) without output arguments plots the imported signal by
% concatenating all the data records, in one single plot if single channel
% is detected, or subplots for multi-channels file. Gaps are shown with
% red stars, overlaps with green circles.
%
% [...] = RDMSEED(F,...,'plot') forces the plot with output arguments.
%
% Some instructions for usage of the returned structure:
%
% - to get concatenated time and data vectors from a single-channel file:
% X = rdmseed(f,'plot');
% t = cat(1,X.t);
% d = cat(1,X.d);
%
% - to get the list of channels in a multi-channel file:
% [X,I] = rdmseed(f);
% cat(1,I.ChannelFullName)
%
% - to extract the station component i from a multi-channel file:
% [X,I] = rdmseed(f);
% k = I(i).XBlockIndex;
% plot(cat(1,X(k).t),cat(1,X(k).d))
% datetick('x')
% title(I(i).ChannelFullName)
%
% Known encoding formats are the following FDSN codes:
% 0: ASCII
% 1: 16-bit integer
% 2: 24-bit integer (untested)
% 3: 32-bit integer
% 4: IEEE float32
% 5: IEEE float64
% 10: Steim-1
% 11: Steim-2
% 12: GEOSCOPE 24-bit (untested)
% 13: GEOSCOPE 16/3-bit gain ranged
% 14: GEOSCOPE 16/4-bit gain ranged (untested)
% 19: Steim-3 (alpha and untested)
%
% See also MKMSEED to export data in miniSEED format.
%
%
% Author: Franois Beauducel <beauducel@ipgp.fr>
% Institut de Physique du Globe de Paris
% Created: 2010-09-17
% Updated: 2012-04-21
%
% Acknowledgments:
% Ljupco Jordanovski, Jean-Marie Saurel, Mohamed Boubacar, Jonathan Berger,
% Shahid Ullah.
%
% References:
% IRIS (2010), SEED Reference Manual: SEED Format Version 2.4, May 2010,
% IFDSN/IRIS/USGS, http://www.iris.edu
% Trabant C. (2010), libmseed: the Mini-SEED library, IRIS DMC.
% Steim J.M. (1994), 'Steim' Compression, Quanterra Inc.
% History:
% [2012-04-21]
% - Correct bug with Steim + little-endian coding
% (thanks to Shahid Ullah)
% [2012-03-21]
% - Adds IDs for warning messages
% [2011-11-10]
% - Correct bug with multiple channel name length (thanks to
% Jonathan Berger)
% [2011-10-27]
% - Add LocationIdentifier to X.ChannelFullName
% [2011-10-24]
% - Validation of IEEE double encoding (with PQL)
% - Import/plot data even with file integrity problem (like PQL)
% [2011-07-21]
% - Validation of ASCII encoding format (logs)
% - Blockettes are now stored in substructures below a single
% field X.BLOCKETTES
% - Add import of blockettes 500 and 2000
% - Accept multi-channel files with various data coding
% [2010-10-16]
% - Alpha-version of Steim-3 decoding...
% - Extend output parameters with channel detection
% - Add gaps and overlaps on plots
% - Add possibility to force the plot
% [2010-10-02]
% - Add the input formats for GEOSCOPE multiplexed old data files
% - Additional output argument with gap and overlap analysis
% - Create a plot when no output argument are specified
% - Optimize script coding (30 times faster STEIM decoding!)
%
% [2010-09-28]
% - Correction of a problem with STEIM-1 nibble 3 decoding (one
% 32-bit difference)
% - Add reading of files without blockette 1000 with additional
% input arguments (like Seismic Handler output files).
% - Uses warning() function instead of fprintf().
%
% Copyright (c) 2012, Franois Beauducel, covered by BSD License.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
error(nargchk(0,6,nargin))
% default input arguments
dbflag = 0;
makeplot = 0;
ef = 10;
wo = 1;
rl = 2^12;
if nargin < 1
[filename,pathname] = uigetfile('*','Please select a miniSEED file...');
f = fullfile(pathname,filename);
else
f = varargin{1};
end
if ~ischar(f) | ~exist(f,'file')
error('File %s does not exist.',f);
end
if nargin > 1
dbflag = strcmp(varargin(end),'debug');
makeplot = strcmp(varargin(end-dbflag),'plot');
end
if nargin > (1 + makeplot + dbflag)
ef = varargin{2};
if ~isnumeric(ef) | ~any(ef==[0:5,10:19,30:33])
error('Argument ENCODINGFORMAT must be a valid FDSN code value.');
end
end
if nargin > (2 + makeplot + dbflag)
wo = varargin{3};
if ~isnumeric(wo) | (wo ~= 0 & wo ~= 1)
error('Argument WORDORDER must be 0 or 1.');
end
end
if nargin > (3 + makeplot + dbflag)
rl = varargin{4};
if ~isnumeric(rl) | rl < 256 | rem(log(rl)/log(2),1) ~= 0
error('Argument RECORDLENGTH must be
- 1
- 2
前往页