Downloading weather files from a server
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello
I am working on a project where i need to periodically download weather forecasts from a server. I have been experimenting with the urlread() and urlwrite() functions which is easy enough. The problem is that the url for the file includes date and time of submission. So i would like to download the most recent files.
an example url: http://dd.weatheroffice.ec.gc.ca/meteocode/ont/csv/2012-01-07T09-30-02Z_FPTO51.0_r1101_CC.csv
where the date and time portion changes. How can i specify a url such that i will get the most recent copy?
댓글 수: 0
채택된 답변
Walter Roberson
2012년 1월 8일
If you urlread() on http://dd.weatheroffice.ec.gc.ca/meteocode/ont/csv/ then you could pick out the most recent file.
댓글 수: 2
Abdul
2015년 8월 9일
편집: Cedric
2015년 8월 9일
I have worked on this and put the data in the separate matrices
close all, clear all, clc
%%download weather forecast data from server
current_files=urlread('http://dd.weatheroffice.ec.gc.ca/meteocode/ont/csv/');
relev_files=strfind(current_files,'FPTO51.0_r1101_TA.csv');
%for most recent file use last index in relev_files
ta_url=['http://dd.weatheroffice.ec.gc.ca/meteocode/ont/csv/',current_files(relev_files(1:end)-21:relev_files(1:end)+20)];
% ta_url=['http://dd.weatheroffice.ec.gc.ca/meteocode/ont/csv/',current_files(relev_files(1:end)-21:relev_files(1:end)+20)];
ta_data=urlread(ta_url)
%%put forecast data into vectors
clc
C = [strsplit(ta_data, '\n')]' ;
D = char(C(2:end-1));
for I = 1:length(D)
E = strsplit(D(I,:), '-');
year(I) = str2num(char(E(1,1)));
month(I) = str2num(char(E(1,2)));
F = char(E(1,3));
G = strsplit(F, 'T');
day(I) = str2num(char(G(1,1)));
H = char(G(1,2));
J = strsplit(H, ':');
hour(I) = str2num(char(J(1,1)));
min(I) = str2num(char(J(1,2)));
K = char(J(1,3));
L = strsplit(K, 'Z');
sec(I) = str2num(char(L(1,1)));
M = char(L(1,2));
N = strsplit(M, ',');
value(I) = str2num(char(N(1,2)));
end
% F = strsplit(D(1,:), 'T')
[year' month' day' hour' min' sec' value']
figure
t = datetime(year, month, day, hour, min, sec);
plot(t, value, '*')
hold on
plot(t, value, '-k', 'Linewidth', 2)
axis tight, grid minor
xlabel('Time')
ylabel('Temperature (°C)')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Web Services에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!