Apply readgeoraster on unzipped (by gunzip) asc.gz file

4 vues (au cours des 30 derniers jours)
Shulamit Nussboim
Shulamit Nussboim le 11 Mai 2021
Commenté : Walter Roberson le 12 Mai 2021
Hi,
I have a bunch of rain radar files which are very large files, though all are zipped. I attach a code to unzip, read and sum them (the code name is 'bunchoffiles'). I tried only on 7 of the files, so the loop runs 7 times, but there are 18,070 unzipped files. The code :
% This script unzips asc.gz (zipped ascii files) from a folder, reads one
% file each time and saves and sums it with the result of the previous
% iteration , then deletes the unzipped file to save memory.
clear all
close all
myFolder = 'C:\Users\user\Documents\Shulamit\PhD\Data_PhD\Hydrology\Rain\radar\RadarDataForShulamit';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, 'RMcomp*.asc.gz'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
sumascfile=zeros(561);
for k = 1 : 7 %length(theFiles)
gunzip(theFiles(k).name)%unzip and read asc.gz files
filename=dir('*.asc')
ascfile=readgeoraster(filename.name)
sumascfile=ascfile(k)+sumascfile
delete *.asc
end
The ending of each original file is asc.gz and to unzip them I used gunzip. However when I use the unzipped file namesfrom the 'struct', I cannot read data by readgeoraster and I get this error note:
Error using readgeoraster (line 97)
Unable to read 'RMcomp_201910150000.asc'. Format may not be supported, file may be corrupt, or a supporting file may have
been specified.
Error in bunchoffiles (line 15)
ascfile=readgeoraster(filename.name)
Herein several file names examples.
Files names for example are :
RMcomp_201910150000.asc.gz
RMcomp_201910150010.asc.gz
RMcomp_201910150020.asc.gz
RMcomp_201910150030.asc.gz
etc.
*In the windows folder I cnnot see the ending asc.gz. It appears only in the 'currecnt Folder' of Matlab.
Thanks in advance

Réponses (1)

Shulamit Nussboim
Shulamit Nussboim le 12 Mai 2021
I finally managed to do this:
% This script unzips asc.gz (zipped ascii files) from a folder, reads one
% file each time and saves and sums it with the result of the previous
% iteration , then deletes the unzipped file to save memory.
clear all
close all
myFolder = 'C:\Users\user\Documents\Shulamit\PhD\Data_PhD\Hydrology\Rain\radar\RadarDataForShulamit';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, 'RMcomp*.asc.gz'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
sumascfile=zeros(561);
for k = 1 : 7 %length(theFiles)
filename=gunzip(theFiles(k).name)%unzip and read asc.gz files
filename=dir('*.asc')
ascfile=load(filename.name)
sumascfile=ascfile(k)+sumascfile;
delete *.asc
end

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by