Read to multiple GLDAS data (ncfile)
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I want to read multiple GLDAS data for evaluate GLDAS TWS.
Using variables are;
time = ncread(ncfile,'time');
longitude = ncread(ncfile,'lon');
latitude = ncread(ncfile,'lat');
swe=ncread(ncfile,'SWE_inst');
soil_moi10=ncread(ncfile,'SoilMoi0_10cm_inst');
soil_moi40=ncread(ncfile,'SoilMoi10_40cm_inst');
soil_moi100=ncread(ncfile,'SoilMoi40_100cm_inst');
soil_moi200=ncread(ncfile,'SoilMoi100_200cm_inst');
cws=ncread(ncfile,'CanopInt_inst');
My data set are include from 2000 to 2022 monthly data.
for example;
GLDAS_NOAH10_M.2.1/2000/GLDAS_NOAH10_M.A200007.021.nc4
GLDAS_NOAH10_M.2.1/2000/GLDAS_NOAH10_M.A200008.021.nc4
GLDAS_NOAH10_M.2.1/2000/GLDAS_NOAH10_M.A200009.021.nc4
GLDAS_NOAH10_M.2.1/2000/GLDAS_NOAH10_M.A200010.021.nc4
GLDAS_NOAH10_M.2.1/2000/GLDAS_NOAH10_M.A200011.021.nc4
GLDAS_NOAH10_M.2.1/2000/GLDAS_NOAH10_M.A200012.021.nc4
...
GLDAS_NOAH10_M.2.1/2022/GLDAS_NOAH10_M.A202207.021.nc4
final product for every month, this formula is used
TWS=swe+(soil_moi10+soil_moi40+soil_moi100+soil_moi200)+cws
how to read all GLDAS data?
Thanks
0 Kommentare
Antworten (1)
Rishav
am 5 Sep. 2023
Hi Erdem,
I understand that you are trying to read all the GLDAS data from 2000 to 2022 on a monthly basis.
Here's an example on how you can read multiple GLDAS data files and calculate the TWS using the provided values:
% Define the directory where your GLDAS data files are stored
dataDir = 'path_to_gldas_data';
% Define the years for which you have data
years = 2000:2022;
% Loop over the years
for year = years
% Loop over the months
for month = 1:12
% Construct the filename for the current month's data
filename = fullfile(dataDir, sprintf('GLDAS_NOAH10_M.2.1/%d/GLDAS_NOAH10_M.A%d%02d.021.nc4', year, year, month));
% Read the GLDAS data for the current month
time = ncread(filename, 'time');
longitude = ncread(filename, 'lon');
latitude = ncread(filename, 'lat');
swe = ncread(filename, 'SWE_inst');
soil_moi10 = ncread(filename, 'SoilMoi0_10cm_inst');
soil_moi40 = ncread(filename, 'SoilMoi10_40cm_inst');
soil_moi100 = ncread(filename, 'SoilMoi40_100cm_inst');
soil_moi200 = ncread(filename, 'SoilMoi100_200cm_inst');
cws = ncread(filename, 'CanopInt_inst');
% Calculate the Total Water Storage (TWS) for the current month
tws = swe + (soil_moi10 + soil_moi40 + soil_moi100 + soil_moi200) + cws;
end
end
Replace 'path_to_gldas_data' with the actual path to your GLDAS data directory.
In this code, you define the directory where your GLDAS data files are stored (dataDir) and the years for which you have data (years). Then, you use nested loops to iterate over each year and each month within that year.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!