Automatic Downloading and automatic unzip of tarred and gunzipped files.

2 次查看(过去 30 天)
So I the code I have currently can download several .tar.gz files within a loop, the amount of files downloaded can be altered by changing the variable year and the day within the file. After this succession of the loop, the code automatically progress onto the unzipping part, there is something at which I can't seem to crack is the fact that the code that is written only unzips the last file it downloads rather than all the files downloaded, what do I need to change to the code so that it would unzip all the files downloaded?
Many Thanks
url_https='https://data.cosmic.ucar.edu';
for year = 2022:2022
for day = 001:001
dataUrl = sprintf('%s/gnss-ro/cosmic2/nrt/level1b/%d/%03d/podTc2_nrt_%d_%03d.tar.gz',url_https, year, day, year, day);
dataFile = sprintf('podTc2_nrt_%d_%03d.tar.gz', year, day);
FileFullPath = websave(dataFile, dataUrl);
end
end
DownloadedFile=sprintf('podTc2_nrt_%d_%03d', year, day);
unzip_Files=untar(FileFullPath,DownloadedFile);
ncvars={'TEC','elevation','time','x_LEO','y_LEO','z_LEO','x_GPS','y_GPS','z_GPS'};
projectdir=(DownloadedFile);
dinfo=dir(fullfile(projectdir,'*.0001_nc'));
num_files=length(dinfo);
filenames=fullfile(projectdir,{dinfo.name});
TECs=cell(num_files,1);
Elevations=cell(num_files,1);
times=cell(num_files,1);
x_LEOs=cell(num_files,1);
y_LEOs=cell(num_files,1);
z_LEOs=cell(num_files,1);
x_GPSs=cell(num_files,1);
y_GPSs=cell(num_files,1);
z_GPSs=cell(num_files,1);
for i=1 : num_files
this_file=filenames{i};
TECs{i}=ncread(this_file,ncvars{1});
Elevations{i}=ncread(this_file,ncvars{2});
times{i}=ncread(this_file,ncvars{3});
x_LEOs{i}=ncread(this_file,ncvars{4});
y_LEOs{i}=ncread(this_file,ncvars{5});
z_LEOs{i}=ncread(this_file,ncvars{6});
x_GPSs{i}=ncread(this_file,ncvars{7});
y_GPSs{i}=ncread(this_file,ncvars{8});
z_GPSs{i}=ncread(this_file,ncvars{9});
delete(this_file)
end
  1 个评论
Tianchu Lu
Tianchu Lu 2022-9-12
So this code automatically downloads a file from a data website between the first day of the calendar year, and after downloading it would unzip that file perfectly. But if i want to download four days within a calendar year, the downloading part would download the specific days without any problem. The problem occurs when the downloading part occurs such that it would only unzip the last file it has downloaded. Hopefully I have explained that a bit better.

请先登录,再进行评论。

采纳的回答

Saffan
Saffan 2023-9-7
Hi Tianchu,
To unzip all the downloaded files instead of just the last one, you need to move the unzipping part inside the loop that downloads the files as shown in the following code snippet:
for year = 2022:2022
for day = 001:004
dataUrl = sprintf('%s/gnss-ro/cosmic2/nrt/level1b/%d/%03d/podTc2_nrt_%d_%03d.tar.gz',url_https, year, day, year, day);
dataFile = sprintf('podTc2_nrt_%d_%03d.tar.gz', year, day);
FileFullPath = websave(dataFile, dataUrl);
DownloadedFile=sprintf('podTc2_nrt_%d_%03d', year, day);
unzip_Files=untar(FileFullPath,DownloadedFile);
end
end
Please refer to this for more information:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by