1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| function [Date_prev_met]=average_temp(station_met_matrice,STM,fnames_STM,nbv)
%average_temp(station_met_matrice,STM,fnames_STM,nbv)
%% Finding catchment points on grid
% find meteorological station corresponding to the catchment
list_station_met=STM.(fnames_STM{nbv});
% find the position of the meteorological stations which correspond to the catchment.
latgrid=NaN(1,length(list_station_met)); longrid=NaN(1,length(list_station_met));
for ii=1:numel(list_station_met)
[latgrid(ii),longrid(ii)]=ind2sub(size(station_met_matrice),find(strcmp(list_station_met{ii},station_met_matrice)));
end
%% Initialization of meteorological matrix
list_day=dir(fullfile('..','..','CMC_forecast','CMC_downscaled'));
list_day={list_day(3:end).name};
list_day=str2double(list_day); list_day=sort(list_day);
Date_prev_met=datevec(datenum(num2str(list_day(1)),'yyyymmdd'):...
datenum(num2str(list_day(end)),'yyyymmdd'));
Date_prev_met=Date_prev_met(:,1:3);
% Matrix(day,member,leadtime)
T=NaN(length(Date_prev_met),20,10);
Tmin=NaN(length(Date_prev_met),20,10);
Tmax=NaN(length(Date_prev_met),20,10);
%% Loop to fill the matricies
% Matrix containing lead time (3h time step til 72, then 6h time step)
horizons=cat(2,3:3:72,78:6:240);
for jj=1:numel(list_day)
for mm=1:20
hourly_tstep=0;
dayly_tstep=0;
for hh=1:numel(horizons)
load(fullfile('..','..','CMC_forecast','CMC_downscaled',...
num2str(list_day(jj)),strcat(num2str(list_day(jj)),...
'00_',num2str(sprintf('%03i',horizons(hh))),'_',...
num2str(sprintf('%03i',mm)),'_','TT','_',num2str(12000))))
hourly_tstep=hourly_tstep+1;
data_hourly(hourly_tstep)=mean2(data(latgrid,longrid));
if rem(horizons(hh),24)==0
dayly_tstep=dayly_tstep+1;
hourly_tstep=0;
data_dayly_mean(dayly_tstep)=mean(data_hourly);
data_dayly_min(dayly_tstep)=min(data_hourly);
data_dayly_max(dayly_tstep)=max(data_hourly);
clear data_hourly_mean data_hourly_min data_hourly_max
end
end
% Ne rempli que les journées où une prev est dispo
T(datenum(num2str(list_day(jj)),'yyyymmdd')==datenum(Date_prev_met),mm,:)=data_dayly_mean;
Tmin(datenum(num2str(list_day(jj)),'yyyymmdd')==datenum(Date_prev_met),mm,:)=data_dayly_min;
Tmax(datenum(num2str(list_day(jj)),'yyyymmdd')==datenum(Date_prev_met),mm,:)=data_dayly_max;
end
end
end |
Partager