How to download multiple data files at once using matlab
조회 수: 17 (최근 30일)
이전 댓글 표시
I need to call on a website and download data for each and every day for the month of july. Im curious what command or format can help me do this. For example this is the code to retrieve 1 day of the year.
filename='weather_data_2019_255.txt';
if isfile(filename)
fprintf('already have the file |%s|\n',filename);
else
url='http://www.weather.unh.edu/data/2019/255.txt';
outname=websave(filename,url);
fprintf('got weather data file |%s|\n',outname);
end
How can i change the filename to allow me to download filename='weather_data_2019_(182-212).txt. I'm assuming I need to create a start date and a end date and create an output filename. May someone teach me how I can do this. Thank you very much.
댓글 수: 0
채택된 답변
meghannmarie
2019년 10월 1일
Try this. I also put where you could change year also.
year = 2019;
start_jd = 182;
end_jd = 212;
for jd = start_jd:end_jd
filename=['weather_data_' num2str(year) '_' num2str(jd) '.txt'];
if isfile(filename)
fprintf('already have the file |%s|\n',filename);
else
url=['http://www.weather.unh.edu/data/' num2str(year) '/' num2str(jd) '.txt'];
outname=websave(filename,url);
fprintf('got weather data file |%s|\n',outname);
end
end
댓글 수: 3
meghannmarie
2020년 3월 31일
Is the start_cd and end_cd just the calendar day? If so, I would calculate the calender day from the julian day.
year = 2018;
month = 10;
time = 0900;
start_jd = 279;
end_jd = 289;
for jd = start_jd:end_jd
cd = day(datetime((year-1),12,31) + days(jd));
filename = ['https://podaac-tools.jpl.nasa.gov/drive/files/allData/ghrsst/data/GDS2/L4/GLOB/JPL/MUR/v4.1/' num2str(year) '/' num2str(jd) '/' num2str(year) num2str(month) num2str(cd) num2str(time) '-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc']
if isfile(filename)
fprintf('already have the file |%s|\n',filename);
else
url=['https://podaac-tools.jpl.nasa.gov/drive/files/allData/ghrsst/data/GDS2/L4/GLOB/JPL/MUR/v4.1/' num2str(year) '/' num2str(jd) '/' num2str(year) num2str(month) num2str(cd) num2str(time) '-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc'];
outname=websave(filename,url);
fprintf('got weather data file |%s|\n',outname);
end
end
Belinda Finlay
2020년 4월 2일
Meghannmarie, thanks, that was a massive help.
I have all that working well; however, the data I am trying to gather is a file on a webpage, rather than a pages with data on it. When you access the webpage manually you have to click on the file to commence the download, hence when I use the code above it create a file with a html link, rather than downloading the file. Is there something you can recommend to correct this?
This the screen shot of the file I am trying to grab: (its the.nc file I am trying to download.) from herehttps://podaac-tools.jpl.nasa.gov/drive/files/allData/ghrsst/data/GDS2/L4/GLOB/JPL/MUR/v4.1/2018/279
my code is:
options = weboptions('Username', 'insertusername', 'Password', 'insertpassword');
year = 2018;
month = 10;
time = 0900;
start_jd = 279;
end_jd = 289;
for jd = start_jd:end_jd
cd = day(datetime((year-1),12,31) + days(jd));
filename = ['sst' num2str(year) '_' num2str(jd) '.nc'];
if isfile(filename)
fprintf('already have the file |%s|\n',filename);
else
url=['https://podaac-tools.jpl.nasa.gov/drive/files/allData/ghrsst/data/GDS2/L4/GLOB/JPL/MUR/v4.1/' num2str(year) '/' num2str(jd)];
outname=websave(filename,url,options);
fprintf('got weather data file |%s|\n',outname);
end
end
This the screen shot of the file I am trying to grab: (its the.nc file I am trying to download.) from herehttps://podaac-tools.jpl.nasa.gov/drive/files/allData/ghrsst/data/GDS2/L4/GLOB/JPL/MUR/v4.1/2018/279
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!