-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadNGARecord.m
67 lines (58 loc) · 1.92 KB
/
readNGARecord.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
function [acc,dtacc] = readNGARecord(filename)
%
% Read earthquake data from a NGAWest2-compatible ASCII file
%
% [#acc#,#dtacc#] = readNGARecord(#filename#)
%
% Description
% This function is used to read the earthquake record time history data
% from an external NGAWest2-compatible ASCII file. This function is
% compatible with the format of the files that are downloaded by the
% NGAWest2 earthquake database. The link for downloading these records
% is the following:
% https://ngawest2.berkeley.edu/spectras/147393/searches/new
%
% Input parameters
% #filename# (row string): is the name of the NGAWest2-compatible ASCII
% file being read.
%
% Output parameters
% #acc# ([#m# x 1]): is the time history data being read from the file.
% #dtacc# (scalar): time step of the time history data being read from
% the file.
%
%__________________________________________________________________________
% Copyright (c) 2019
% George Papazafeiropoulos
% Captain, Infrastructure Engineer, Hellenic Air Force
% Civil Engineer, M.Sc., Ph.D. candidate, NTUA
% Email: [email protected]
% _________________________________________________________________________
fid=fopen(filename);
if fid<0
error('Unable to open record file')
end
skipline=3;
for i=1:skipline+1
tline = fgetl(fid);
end
match1 = strfind(lower(tline),'npts=');
match2 = strfind(lower(tline),'dt=');
match3 = strfind(lower(tline),',');
match4 = strfind(lower(tline),'se');
nsteps=str2double(tline(match1+5:match3(1)-1));
if nsteps<=0
disp('ERROR: not able to find DT or NPTS');
return;
end
dtacc=str2double(tline(match2+3:match4-1));
if dtacc<=0
disp('ERROR: not able to find DT or NPTS');
return;
end
cac = textscan(fid,'%f%f%f%f%f','Headerlines',skipline+1,'CollectOutput',true );
fclose(fid);
acc = cac{1};
acc=acc';
acc=acc(:);
end