Files
Earthquake/new_version/downloadFile.m
2022-05-27 23:30:28 +03:00

51 lines
1.4 KiB
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

%% By L_DelOff
% Функция формирует ссылку и скачивает архив с сайта NOAA
% status=0 - cкачал успешно
function status=downloadFile(url)
global param
%% Дебаг
if 1%param.downloadEvent.debug
param.downloadEvent.debug=1;
param.downloadEvent.loglevel=3;
param.data.path='D:\Git\earthquake\DATA\';
url='https://satdat.ngdc.noaa.gov/dmsp/data/f18/ssies/2014/03/PS.CKGWC_SC.U_DI.A_GP.SIES3-F18-R99990-B9999090-APGA_AR.GLOBAL_DD.20140303_TP.000001-235959_DF.EDR.gz';
end
%% Начало
if param.downloadEvent.loglevel==3
message=['Скачиваю... \n'];
fprintf(message)
end
%% Вытаскиваю из URL имя файла
a=find((ismember(url,'/')));
filename=url(a(end)+1:end);
%% Путь для скачивания
filepath=[param.data.path 'temp/' filename];
%% Проверяю, можно ли записать в темп
if ~isfolder([param.data.path 'temp'])
mkdir([param.data.path 'temp'])
end
%% Скачиваю
try
outfilename = websave(filepath,url);
status=0;
catch ME
warning(ME.message);
switch ME.identifier
case 'MATLAB:webservices:HTTP404StatusCodeError'
status=404;
otherwise
ME
status=-1;
end
end
if param.downloadEvent.loglevel==3
if status==0
message=['\bГотово \n'];
fprintf(message)
end
end
end