Unable to understand how to use the function given on the site below
3 views (last 30 days)
muhammad choudhry on 7 Nov 2022
I am trying to understand the functions and how to use them given on the site below.
Basically, this site have the rainfall data which is in .gz file and these are the matlab function given on the site to work with, but I am unable to understand how to use them, if there is any expert here can suggest me how to use them function to read the .gz file it will save me alot of time and give me a good start. I have been googling since yesterday and still lost.
Found a very useful link:
which is doing the same thing I am after but the file format is .ascii and @Walton Robinson gave a very good explanation but in my case files are.gz and I am not sure how to convert them files into something useful (possibly csv).
The attach notepad file is what I am getting after extracting from gz format which is just gibrish as soon as I extracted, I lost the extension.
It is not letting me upload the file here with error!
File format is unsupported for file:2022_329x432. Use any of these formats:.bmp, .csv, .fig, .gif, .jpg, .jpeg, .m, .mat, .mdl, .mlapp, .mlx, .sfx, .slx, .sbproj, .pdf, .png, .txt, .xls, .xlsx, .zip
Hope I will get some good advice here"
Walter Roberson on 7 Nov 2022
Copy the matlab code from the site you linked to.
Then call the rdnim function passing in the name of the (unzipped) file. It does not matter that you do not see a file extension: the function does not care what the file extension is.
More Answers (1)
Bjorn Gustavsson on 7 Nov 2022
files with the extension .gz are typically compressed with gzip, that use the Lempel-Ziv coding. The most effective way to handle this problem is to simply uncompress the files at once - provided you have disp-space to store the files in an uncompressed format. To do this, simply do:
$ prompt> gunzip *.gz
from a terminal in the data-directory. If you use MS-windows there should be some shell-facility, if not you should be able to do this uncompression from a file-manager?
If you cannot expand all files then you might have to do them one-by-one in you matlab-script. Perhaps something like this:
datafiles = dir('*.gz'); % or however you select the files to process.
for iDF = 1:numel(datafiles)
currfile = datafiles(iDF);
[cf1,cf2,cf3] = fileparts(currfile.name); % cf2 will have the name of the file after gunzipping
disp(fullfile(currfile.folder,cf2)) % this should be the full name of the uncompressed file
cData = load_your_data(fullfile(currfile.folder,cf2)) % or however you load one of your data-files
system(['gzip ',fullfile(currfile.folder,cf2)]) % after processing one file compress it again to reduce disk-usage