Commit 9995008ee8995e085247d0581a37588e3c3fcbee

Authored by Dany Dumont
1 parent 84ed20a5
Exists in master and in 1 other branch snow

Ajout de ecmwf2gotm.m, un script qui formate les donnees de re-analyse ECMWF en …

…fichier meteo pour GOTM (airsea.nml).
Showing 1 changed file with 96 additions and 0 deletions   Show diff stats
scripts/matlab/ecmwf2gotm.m 0 → 100755
... ... @@ -0,0 +1,96 @@
  1 +function ecmwf2gotm(region,file,lon,lat,year)
  2 +% Format meteorological variables from ECMWF for GOTM.
  3 +%
  4 +% Variables:
  5 +%
  6 +% T2M 2 meter temperature (degK)
  7 +% U10 10 meter zonal wind component (m/s)
  8 +% V10 10 meter meriodional wind component (m/s)
  9 +% D2M 2 meter dewpoint temperature (degK)
  10 +% MSL Mean sea level pressure (Pa)
  11 +% TCC Total cloud cover (0-1)
  12 +%
  13 +% Function arguments
  14 +%
  15 +% region 'pc' - Potter Cove
  16 +% 'ap' - Antarctic Peninsula and Weddell Sea
  17 +% 'gsl' - Golfe Saint-Laurent
  18 +% 'now' - North Water
  19 +% 'amg' - Amundsen Gulf
  20 +% 'gsj' - Golfo San Jorge
  21 +% file String to be usd in the output file name
  22 +% lon longitude in degrees_east (0-360)
  23 +% lat latitude in degrees_north (-90-90)
  24 +% year year to be extracted
  25 +%
  26 +% cf. data-portal.ecmwf.int/data/d/interim_daily/
  27 +% cf. GOTM
  28 +% Uses the netcdf toolbox
  29 +
  30 +% Dany DUMONT
  31 +% 14/05/2011: Creation
  32 +% 24/01/2013: Standardized and adapted to the data file organization
  33 +% ______________________________________________________________________
  34 +
  35 +yrstr = num2str(year);
  36 +disp(yrstr)
  37 +
  38 +if mod(year,400) == 0
  39 + nod = 366;
  40 +elseif mod(year,100) == 0
  41 + nod = 365;
  42 +elseif mod(year,4) == 0
  43 + nod = 366;
  44 +else
  45 + nod = 365;
  46 +end
  47 +
  48 +% Time scale given in Matlab serial date number
  49 +init_date = datenum([year 01 01 00 00 00]);
  50 +time = (init_date:6/24:init_date+nod-6/24)';
  51 +timevec = datevec(time);
  52 +%tlength = length(time);
  53 +
  54 +datadir = ['/sas/usagers/dumoda01/shared/data/ecmwf/',region,'/6hourly/'];
  55 +
  56 +ncfile = [datadir,'ecmwf_',region,'_meteo_',yrstr,'.nc'];
  57 +hlon = double(nc_varget(ncfile,'longitude'));
  58 +hlat = double(nc_varget(ncfile,'latitude'));
  59 +u10 = nc_varget(ncfile,'u10');
  60 +v10 = nc_varget(ncfile,'v10');
  61 +msl = nc_varget(ncfile,'msl');
  62 +t2m = nc_varget(ncfile,'t2m');
  63 +d2m = nc_varget(ncfile,'d2m');
  64 +tcc = nc_varget(ncfile,'tcc');
  65 +
  66 +% Unit conversion
  67 +t2m = t2m - 273.15; % degK to degC
  68 +d2m = d2m - 273.15; % degK to degC
  69 +msl = msl./100; % Pa to hPa
  70 +
  71 +% Extract index position
  72 +tol = 0.8;
  73 +i = find(hlon < lon + tol & hlon > lon - tol,1);
  74 +j = find(hlat < lat + tol & hlat > lat - tol,1);
  75 +if isempty(i) || isempty(j)
  76 + disp('** Error : Can not find the specified lat/lon location.' )
  77 + disp('** Verify that you have specified the longitude in the')
  78 + disp('** [0-360] degree interval (e.g. 296 instead of -64)' )
  79 + return
  80 +end
  81 +
  82 +% Extract one point and form the array
  83 +u10 = squeeze(u10(:,j,i));
  84 +v10 = squeeze(v10(:,j,i));
  85 +msl = squeeze(msl(:,j,i));
  86 +t2m = squeeze(t2m(:,j,i));
  87 +d2m = squeeze(d2m(:,j,i));
  88 +tcc = squeeze(tcc(:,j,i));
  89 +
  90 +array = cat(2,timevec,u10,v10,msl,t2m,d2m,tcc);
  91 +
  92 +% Write the file in the GOTM format
  93 +fid = fopen(['ecmwf_',file,'_meteo_',yrstr,'.dat'], 'w');
  94 +fprintf(fid, '%4.0f-%02.0f-%02.0f %02.0f:%02.0f:%02.0f\t%3.2f\t%3.2f\t%4.1f\t%3.2f\t%3.2f\t%1.2f\n', ...
  95 + array');
  96 +fclose(fid);
... ...