-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEQ_read.m
executable file
·72 lines (57 loc) · 2.2 KB
/
EQ_read.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
function [ data ] = EQ_read (inFile)
% EQ_read.m
% Reads in .eq files to extract event information
% Nathanael Wong Zhixin, Feng Lujia
%
% This script reads in the event information line by line based on flags at
% the front of each line.
%
% INPUT:
% -- inFile : file name
%
% OUTPUT:
% -- data : information of earthquake event
%
% FORMAT OF CALL: EQ_read (file)
%
% OVERVIEW:
% 1) This function will first open the file for reading and set aside a
% data structure to hold the information
%
% 2) The function will then read in the file line by line and break it up
% into flags and input parameters. Based on the flag, the data will go
% into each respective holder
%
% 3) When there are no more lines, then the function ends.
%
% VERSIONS:
% 1) -- Final version validated on 20190812 by Nathanael Wong
%%%%%%%%%%%%%%%%%%%%%%%%%% CHECK IF FILE EXISTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
if exist(inFile,'file') ~= 2, error('File does not exist!');
else, finFile = fopen(inFile,'r');
end
%%%%%%%%%%%%%%%%%%%%%%%%% INITIALIZING PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%
data.EQID = {}; data.type = []; data.xyz = []; data.dgeo = [];
data.slip = []; data.inv0 = []; data.invX = []; data.invN = [];
%%%%%%%%%%%%%%%%%%%%%%%%%%%% READ FILE BY LINE %%%%%%%%%%%%%%%%%%%%%%%%%%%%
while 1
tline = fgetl(finFile); % read in line by line
if ischar(tline) ~= 1, break; end % exit if end file
[ flag,input ] = strtok(tline); % read flag for each line
if (EQ_read_skip(flag)), continue; end % omit comment lines
if strcmpi (flag,'EQID'), data.EQID = strtrim(input); %#ok<*ST2NM>
elseif strcmpi (flag,'Type'), data.type = str2num(input);
elseif strcmpi (flag,'XYZ'), data.xyz = str2num(input);
elseif strcmpi (flag,'DGeo'), data.dgeo = str2num(input);
elseif strcmpi (flag,'Slip'), data.slip = str2num(input);
elseif strcmpi (flag,'Inv0'), data.inv0 = str2num(input);
elseif strcmpi (flag,'InvX'), data.invX = str2num(input);
elseif strcmpi (flag,'InvN'), data.invN = str2num(input);
end
end
end
function out = EQ_read_skip(str)
if strncmpi(str,'#',1) || isempty(str), out = true();
else, out = false();
end
end