get_NCEP_year.m 772 Bytes
Newer Older
1 2 3 4
function year = get_NCEP_year(file)
% Extract the year from a give NCEP file name (either 'uwnd.sig995.YYYY.nc'
% or 'vwnd.sig995.YYYY.nc'). Files are those downloaded from
% ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis/surface/.
Pierre Cazenave's avatar
Pierre Cazenave committed
5
%
6 7
% INPUT:
%   NCEP NetCDF filename (and path)
Pierre Cazenave's avatar
Pierre Cazenave committed
8
%
9 10
% OUTPUT:
%   NCEP data year
Pierre Cazenave's avatar
Pierre Cazenave committed
11
%
12 13
% Author(s):
%   Pierre Cazenave (Plymouth Marine Laboratory)
Pierre Cazenave's avatar
Pierre Cazenave committed
14
%
15 16
% Revision history:
%   2012-10-15 First version
Pierre Cazenave's avatar
Pierre Cazenave committed
17
%
18 19 20 21 22
%==========================================================================

[~, tmp_year, ~] = fileparts(file);
tmp_year = regexp(tmp_year, '\.', 'split');
year = str2double(tmp_year(end));
Pierre Cazenave's avatar
Pierre Cazenave committed
23
if ~isnumeric(year)
24 25
    error('Could not parse the NCEP year from the NCEP file name. Expecting ''uwnd.sig995.YYYY.nc'' or ''vwnd.sig995.YYYY.nc''')
end