Commit ade7be8075c912edc4cd38dcbcc1d16afadd970f

Authored by dumoda01
1 parent eabac40a
Exists in master and in 1 other branch snow

Ajout de scripts matlab de preparation des forcages

scripts/matlab/narr_daily2gotm.m 0 → 100755
... ... @@ -0,0 +1,168 @@
  1 +function narr_daily2gotm(year)
  2 +% cf. ftp://ftp.cdc.noaa.gov/Datasets/NARR/monolevel/
  3 +% cf. GOTM
  4 +
  5 +% Dany DUMONT
  6 +% 17/06/2008: Creation
  7 +% 23/02/2011: Put year as an argument
  8 +% ______________________________________________________________________
  9 +
  10 +yrstr = num2str(year);
  11 +
  12 +if mod(year,400) == 0
  13 + nod = 366;
  14 +elseif mod(year,100) == 0
  15 + nod = 365;
  16 +elseif mod(year,4) == 0
  17 + nod = 366;
  18 +else
  19 + nod = 365;
  20 +end
  21 +
  22 +% Time scale given in Matlab serial date number
  23 +init_date = datenum([year 01 01 00 00 00]);
  24 +time = [init_date:1/24:init_date+nod-1/24]';
  25 +timevec = datevec(time);
  26 +tlength = length(time);
  27 +
  28 +% ----------------------------------------------------------------------
  29 +% Momentum flux calculated using
  30 +% wind speed at 10m from NARR 3-hourly reanalysis
  31 +% ----------------------------------------------------------------------
  32 +ncfile = ['uwnd_',yrstr,'_narr_amdgulf.nc'];
  33 +uwnd = nc_varget(ncfile,'UWND'); % m s^-1
  34 +ncfile = ['vwnd_',yrstr,'_narr_amdgulf.nc'];
  35 +vwnd = nc_varget(ncfile,'VWND'); % m s^-1
  36 +% moyenne journali�re des donn�es
  37 +window = 8;
  38 +uwnd = filter(ones(1,window)/window,1,uwnd);
  39 +vwnd = filter(ones(1,window)/window,1,vwnd);
  40 +% interpolation des donn�es aux heures
  41 +uwnd = interp(uwnd,3);
  42 +vwnd = interp(vwnd,3);
  43 +
  44 +% Wind stress calculation
  45 +% cf. Stewart, R.H. (2002) Introduction to Physical Oceanography
  46 +rho = 1.3; % density of air (kg m^-3)
  47 +U = sqrt(uwnd.^2 + vwnd.^2); % velocity amplitude (m s^-1)
  48 +C10 = nan .* ones(length(U),1);
  49 +for i = 1:length(U)
  50 + if (U(i) >= 3 && U(i) < 6)
  51 + C10(i) = (0.29 + 3.1./U(i) + 7.7./U(i).^2).*1e-3;
  52 + elseif U(i) >= 6
  53 + C10(i) = (0.60 + 0.070.*U(i)).*1e-3; % Yelland and Taylor (1996)
  54 + else
  55 + C10(i) = 2.18e-3;
  56 + end
  57 +end
  58 + % C10 = (0.75 + 0.065.*U).*1e-3; % Garratt (1977)
  59 +dir = atan2(vwnd,uwnd); % wind direction (rad)
  60 +tau = rho.*C10.*U.*U; % wind stress amplitude (N m^-2)
  61 +taux = tau.*cos(dir); % zonal wind stress (N m^-2)
  62 +tauy = tau.*sin(dir); % meridional wind stress (N m^-2)
  63 +% figure; plot(U,C10,'ob')
  64 +% figure; plot(U,tau,'ok')
  65 +clear U dir tau C10 rho
  66 +
  67 +% Creation of the file 'narr_momentumflux.dat'
  68 +% file with tx and ty given in N/m^2
  69 +momentumflux = nan .* ones(tlength,8);
  70 +momentumflux(:,1:6) = timevec;
  71 +momentumflux(:,7) = taux;
  72 +momentumflux(:,8) = tauy;
  73 +
  74 +fid = fopen(['narr_daily_momentumflux_',yrstr,'.dat'], 'wt');
  75 +fprintf(fid, '%4.0f-%02.0f-%02.0f %02.0f:%02.0f:%02.0f\t%f\t%f\n', ...
  76 + momentumflux');
  77 +fclose(fid);
  78 +
  79 +% ----------------------------------------------------------------------
  80 +% Incoming shortwave radiative flux and surface heat flux
  81 +% from NARR 3-hourly reanalysis
  82 +% ----------------------------------------------------------------------
  83 +ncfile = ['dswrf_',yrstr,'_narr_amdgulf.nc'];
  84 +dswrf = nc_varget(ncfile,'DSWRF'); % W/m^2
  85 +% moyenne journali�re des donn�es
  86 +dswrf = filter(ones(1,window)/window,1,dswrf);
  87 +% interpolation des donn�es � chaque heure
  88 +dswrf = interp(dswrf,3);
  89 +a = find(dswrf < 0.0);
  90 +dswrf(a) = 0.0;
  91 +
  92 +ncfile = ['uswrf_',yrstr,'_narr_amdgulf.nc'];
  93 +uswrf = nc_varget(ncfile,'USWRF'); % W/m^2
  94 +% moyenne journali�re des donn�es
  95 +uswrf = filter(ones(1,window)/window,1,uswrf);
  96 +% interpolation des donn�es aux heures
  97 +uswrf = interp(uswrf,3);
  98 +
  99 +ncfile = ['dlwrf_',yrstr,'_narr_amdgulf.nc'];
  100 +dlwrf = nc_varget(ncfile,'DLWRF'); % W/m^2
  101 +% moyenne journali�re des donn�es
  102 +dlwrf = filter(ones(1,window)/window,1,dlwrf);
  103 +% interpolation des donn�es � chaque heure
  104 +dlwrf = interp(dlwrf,3);
  105 +
  106 +ncfile = ['ulwrf_',yrstr,'_narr_amdgulf.nc'];
  107 +ulwrf = nc_varget(ncfile,'ULWRF'); % W/m^2
  108 +% moyenne journali�re des donn�es
  109 +ulwrf = filter(ones(1,window)/window,1,ulwrf);
  110 +% interpolation des donn�es � chaque heure
  111 +ulwrf = interp(ulwrf,3);
  112 +
  113 +ncfile = ['shtfl_',yrstr,'_narr_amdgulf.nc'];
  114 +shtfl = nc_varget(ncfile,'SHTFL'); % W/m^2
  115 +% moyenne journali�re des donn�es
  116 +shtfl = filter(ones(1,window)/window,1,shtfl);
  117 +% interpolation des donn�es � chaque heure
  118 +shtfl = interp(shtfl,3);
  119 +
  120 +ncfile = ['lhtfl_',yrstr,'_narr_amdgulf.nc'];
  121 +lhtfl = nc_varget(ncfile,'LHTFL'); % W/m^2
  122 +% moyenne journali�re des donn�es
  123 +lhtfl = filter(ones(1,window)/window,1,lhtfl);
  124 +% interpolation des donn�es � chaque heure
  125 +lhtfl = interp(lhtfl,3);
  126 +
  127 +% Transmitted shortwave radiative flux
  128 +% that include the extinction due to the ice cover
  129 +% (Data from the Canadian Ice Service)
  130 +eval(['load cis_icec_',yrstr])
  131 +swr = (dswrf - uswrf).*(1-icec);
  132 +% No ice effect
  133 +% swr = (dswrf - uswrf);
  134 +
  135 +figure
  136 +t=time-init_date;
  137 +plot(t,dswrf-uswrf,'LineWidth',2,'Color',[0.5 0.5 0.5]); hold on
  138 +plot(t,swr,'-k','LineWidth',2); hold off
  139 +xlim([1 nod]);
  140 +xlabel(['day of year ',yrstr])
  141 +ylabel('W/m^2')
  142 +h = legend('Over ice','Under ice')
  143 +legend(h,'boxoff')
  144 +saveas(gcf,'swr_icec.tiff', 'tiffn')
  145 +
  146 +% Total heat flux (excluding the shortwave)
  147 +% positive = towards the ocean surface
  148 +% qt = dlwrf - ulwrf + shtfl + lhtfl; (????)
  149 +% that include the insulation due to the ice cover
  150 +% (Data from the Canadian Ice Service)
  151 +qt = (dlwrf - ulwrf + shtfl + lhtfl) .* (1-icec);
  152 +% No ice effect
  153 +% qt = dlwrf - ulwrf + shtfl + lhtfl;
  154 +
  155 +% Creation of the file 'heatflux.dat'
  156 +% file with swr and total heat flux in W/m^2
  157 +init_date = datenum([year 01 01 00 00 00]);
  158 +time = [init_date:1/24:init_date+nod-1/24]';
  159 +timevec = datevec(time);
  160 +tlength = length(time);heatflux = nan .* ones(tlength,8);
  161 +heatflux(:,1:6) = timevec;
  162 +heatflux(:,7) = swr;
  163 +heatflux(:,8) = qt;
  164 +
  165 +fid = fopen(['narr_daily_heatflux_ice_',yrstr,'.dat'], 'wt');
  166 +fprintf(fid, '%4.0f-%02.0f-%02.0f %02.0f:%02.0f:%02.0f\t%f\t%f\n', ...
  167 + heatflux');
  168 +fclose(fid);
... ...
scripts/matlab/narr_hourly2gotm.m 0 → 100755
... ... @@ -0,0 +1,152 @@
  1 +function narr_hourly2gotm(year)
  2 +% cf. ftp://ftp.cdc.noaa.gov/Datasets/NARR/monolevel/
  3 +% cf. GOTM
  4 +% Uses the netcdf toolbox
  5 +
  6 +% Dany DUMONT
  7 +% 14/05/2008: Creation
  8 +% 23/02/2011: Put year as an argument
  9 +% ______________________________________________________________________
  10 +
  11 +yrstr = num2str(year)
  12 +
  13 +if mod(year,400) == 0
  14 + nod = 366;
  15 +elseif mod(year,100) == 0
  16 + nod = 365;
  17 +elseif mod(year,4) == 0
  18 + nod = 366;
  19 +else
  20 + nod = 365;
  21 +end
  22 +
  23 +% Time scale given in Matlab serial date number
  24 +init_date = datenum([year 01 01 00 00 00]);
  25 +time = [init_date:1/24:init_date+nod-1/24]';
  26 +timevec = datevec(time);
  27 +tlength = length(time);
  28 +
  29 +% ----------------------------------------------------------------------
  30 +% Momentum flux calculated using
  31 +% wind speed at 10m from NARR 3-hourly reanalysis
  32 +% ----------------------------------------------------------------------
  33 +
  34 +ncfile = ['uwnd_',yrstr,'_narr_amdgulf.nc'];
  35 +uwnd = nc_varget(ncfile,'UWND');
  36 +ncfile = ['vwnd_',yrstr,'_narr_amdgulf.nc'];
  37 +vwnd = nc_varget(ncfile,'VWND');
  38 +% interpolation des donn�es � chaque heure
  39 +uwnd = interp(uwnd,3);
  40 +vwnd = interp(vwnd,3);
  41 +
  42 +% Wind stress calculation
  43 +% cf. Stewart, R.H. (2002) Introduction to Physical Oceanography
  44 +rho = 1.3; % density of air (kg m^-3)
  45 +U = sqrt(uwnd.^2 + vwnd.^2); % velocity amplitude (m s^-1)
  46 +C10 = nan .* ones(length(U),1);
  47 +for i = 1:length(U)
  48 + if (U(i) >= 3 && U(i) < 6)
  49 + C10(i) = (0.29 + 3.1./U(i) + 7.7./U(i).^2).*1e-3;
  50 + elseif U(i) >= 6
  51 + C10(i) = (0.60 + 0.070.*U(i)).*1e-3; % Yelland and Taylor (1996)
  52 + else
  53 + C10(i) = 2.18e-3;
  54 + end
  55 +end
  56 + % C10 = (0.75 + 0.065.*U).*1e-3; % Garratt (1977)
  57 +dir = atan2(vwnd,uwnd); % wind direction (rad)
  58 +tau = rho.*C10.*U.*U; % wind stress amplitude (N m^-2)
  59 +taux = tau.*cos(dir); % zonal wind stress (N m^-2)
  60 +tauy = tau.*sin(dir); % meridional wind stress (N m^-2)
  61 +% figure; plot(U,C10,'ob')
  62 +% figure; plot(U,tau,'ok')
  63 +clear U dir tau C10 rho
  64 +
  65 +% Creation of the file 'narr_momentumflux.dat'
  66 +% file with tx and ty given in N/m^2
  67 +momentumflux = nan .* ones(tlength,8);
  68 +momentumflux(:,1:6) = timevec;
  69 +momentumflux(:,7) = taux;
  70 +momentumflux(:,8) = tauy;
  71 +
  72 +fid = fopen(['narr_hourly_momentumflux_',yrstr,'.dat'], 'wt');
  73 +fprintf(fid, '%4.0f-%02.0f-%02.0f %02.0f:%02.0f:%02.0f\t%f\t%f\n', ...
  74 + momentumflux');
  75 +fclose(fid);
  76 +
  77 +
  78 +% ----------------------------------------------------------------------
  79 +% Incoming shortwave radiative flux and surface heat flux
  80 +% from NARR 3-hourly reanalysis
  81 +% ----------------------------------------------------------------------
  82 +ncfile = ['dswrf_',yrstr,'_narr_amdgulf.nc'];
  83 +dswrf = nc_varget(ncfile,'DSWRF'); % W/m^2
  84 +% interpolation des donn�es � chaque heure
  85 +dswrf = interp(dswrf,3);
  86 +a = find(dswrf < 0.0);
  87 +dswrf(a) = 0.0;
  88 +
  89 +ncfile = ['uswrf_',yrstr,'_narr_amdgulf.nc'];
  90 +uswrf = nc_varget(ncfile,'USWRF'); % W/m^2
  91 +% interpolation des donn�es � chaque heure
  92 +uswrf = interp(uswrf,3);
  93 +
  94 +ncfile = ['dlwrf_',yrstr,'_narr_amdgulf.nc'];
  95 +dlwrf = nc_varget(ncfile,'DLWRF'); % W/m^2
  96 +% interpolation des donn�es � chaque heure
  97 +dlwrf = interp(dlwrf,3);
  98 +
  99 +ncfile = ['ulwrf_',yrstr,'_narr_amdgulf.nc'];
  100 +ulwrf = nc_varget(ncfile,'ULWRF'); % W/m^2
  101 +% interpolation des donn�es � chaque heure
  102 +ulwrf = interp(ulwrf,3);
  103 +
  104 +ncfile = ['shtfl_',yrstr,'_narr_amdgulf.nc'];
  105 +shtfl = nc_varget(ncfile,'SHTFL'); % W/m^2
  106 +% interpolation des donn�es � chaque heure
  107 +shtfl = interp(shtfl,3);
  108 +
  109 +ncfile = ['lhtfl_',yrstr,'_narr_amdgulf.nc'];
  110 +lhtfl = nc_varget(ncfile,'LHTFL'); % W/m^2
  111 +% interpolation des donn�es � chaque heure
  112 +lhtfl = interp(lhtfl,3);
  113 +
  114 +% Transmitted shortwave radiative flux
  115 +% that include the extinction due to the ice cover
  116 +% (Data from Canadian Ice Service)
  117 +eval(['load cis_icec_',yrstr])
  118 +swr = (dswrf - uswrf).*(1.0-icec);
  119 +for ii = 1:length(swr)
  120 + if swr(ii) < 0.0;
  121 + swr(ii) = 0.0;
  122 + end
  123 +end
  124 +% No ice effect
  125 +% swr = (dswrf - uswrf);
  126 +
  127 +% Total heat flux (minus the shortwave)
  128 +% positive = towards the ocean surface
  129 +% qt = dlwrf - ulwrf + shtfl + lhtfl; (????)
  130 +% that include the insulation due to the ice cover
  131 +% (Data from D. Barber group)
  132 +qt = (dlwrf - ulwrf + shtfl + lhtfl) .* (1.0-icec);
  133 +% No ice effect
  134 +% qt = dlwrf - ulwrf + shtfl + lhtfl;
  135 +
  136 +figure; plot(time,qt)
  137 +figure; plot(time,swr)
  138 +
  139 +% Creation of the file 'heatflux.dat'
  140 +% file with swr and total heat flux in W/m^2
  141 +init_date = datenum([year 01 01 00 00 00]);
  142 +time = [init_date:1/24:init_date+nod-1/24]';
  143 +timevec = datevec(time);
  144 +tlength = length(time);heatflux = nan .* ones(tlength,8);
  145 +heatflux(:,1:6) = timevec;
  146 +heatflux(:,7) = swr;
  147 +heatflux(:,8) = qt;
  148 +
  149 +fid = fopen(['narr_hourly_heatflux_ice_',yrstr,'.dat'], 'wt');
  150 +fprintf(fid, '%4.0f-%02.0f-%02.0f %02.0f:%02.0f:%02.0f\t%f\t%f\n', ...
  151 + heatflux');
  152 +fclose(fid);
... ...