Repository navigation
Expand file tree
/
Copy pathdownload_time_series.m
More file actions
62 lines (51 loc) · 2.5 KB
/
Copy pathdownload_time_series.m
File metadata and controls
62 lines (51 loc) · 2.5 KB
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
function [ ] = download_time_series(outputDir, rec, metadata)
% Copy selected time series to the working directory, if they are available
% for direct download. For further details on file locations, see database
% metadata files.
% identify the relevant file format
if ~isempty(strfind(metadata.dirLocation{1},'nga_files')) %% NGA-West1 data
% check for number of ground motion components
if size(metadata.Filename,2) == 1 % only one ground motion component
nComp = 1;
else
nComp = 2;
end
for i = 1:length(rec)
for j = 1:nComp
% Download the selected ground motion from the NGA database
url = [char(metadata.dirLocation{rec(i)}) char(metadata.Filename{rec(i),j})]; % source data
if nComp == 2
filename = [outputDir '/GM' num2str(i) '_comp' num2str(j) '.txt']; % save file to the current directory
else
filename = [outputDir '/GM' num2str(i) '.txt']; % save file to the current directory
end
urlwrite(url,filename); % urlwrite(URL,filename) reads web content at the specified URL and saves it to the file specified by filename
end
end
elseif ~isempty(strfind(metadata.dirLocation{1},'bbpvault')) %% BBP data
display('BroadBand Platform data are currently not available for download');
elseif ~isempty(strfind(metadata.dirLocation{1},'ngawest2')) %% NGA-West2 data
display('NGA-West2 data are currently not available for download');
return
elseif ~isempty(strfind(metadata.dirLocation{1},'CyberShake')) %% CyberShake data
if size(metadata.Filename,2) == 1 % only one ground motion component
nComp = 1;
else
nComp = 2;
end
for i = 1:length(rec)
for j = 1:nComp
% Download the selected ground motion from the NGA database
sourceFile = [char(metadata.dirLocation{rec(i)}) char(metadata.Filename{rec(i),j})]; % source data
if nComp == 2
filename = [outputDir '/GM' num2str(i) '_comp' num2str(j) '.txt']; % save file to the current directory
else
filename = [outputDir '/GM' num2str(i) '.txt']; % save file to the current directory
end
copyfile(sourceFile,filename); % urlwrite(URL,filename) reads web content at the specified URL and saves it to the file specified by filename
end
end
else
display('Unknown database format');
return
end