Contents

function grainsize2netcdf(varargin)
%GRAINSIZE2NETCDF  create netcdf file of VTV grainsize data
%
%   Read relevant grain size data from Excel file and store it in a netCDF
%   file. This are the grain sizes as used for the VTV (guidelines for the
%   safety assessment of the Dutch dune coast)
%
%   Syntax:
%   grainsize2netcdf(varargin)
%
%   Input:
%   varargin  =
%
%   Example
%   grainsize2netcdf
%
%   See also

%   --------------------------------------------------------------------
%   Copyright (C) 2009 Delft University of Technology
%       C.(Kees) den Heijer
%
%       C.denHeijer@TUDelft.nl
%
%       Faculty of Civil Engineering and Geosciences
%       P.O. Box 5048
%       2600 GA Delft
%       The Netherlands
%
%   This library is free software; you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation; either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library; if not, write to the Free Software
%   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
%   USA
%   or http://www.gnu.org/licenses/licenses.html, http://www.gnu.org/, http://www.fsf.org/
%   --------------------------------------------------------------------

% Created: 16 Feb 2009
% Created with Matlab version: 7.4.0.287 (R2007a)

% $Id: grainsize2netcdf.m 327 2009-04-21 15:29:18Z heijer $
% $Date: 2009-04-21 17:29:18 +0200 (Tue, 21 Apr 2009) $
% $Author: heijer $
% $HeadURL: https://repos.deltares.nl/repos/OpenEarthRawData/trunk/rijkswaterstaat/grainsize_vtv/grainsize2netcdf.m $
% $Keywords:

initialise default arguments

define default arguments and apply input

OPT = struct(...
    'filename', 'grainsize.nc',...
    'sourcefile', 'GrainSizes.xls');

OPT = setProperty(OPT, varargin{:});

read source data from Excel file

Grainsizes = xlsread(OPT.sourcefile);
id = ~isnan(Grainsizes(:,2));
Grainsizes = Grainsizes(id,:);
Grainsizes(:,end-2:end) = Grainsizes(:,end-2:end) * 1e-6;

areacodes = mat2cell(Grainsizes(:,1), ones(size(Grainsizes(:,1))),1)';
areaname = getKustvak(areacodes{:});
stringsize = max(cellfun(@length, areaname));

define netCDF variables

s = struct(...
    'Name', {
        'id'
        'areacode'
        'areaname'
        'alongshore'
        'meanD50'
        'sigmaD50'
        'calcD50'
        },...
    'Nctype', {
        nc_int
        nc_int
        nc_char
        nc_double
        nc_double
        nc_double
        nc_double},...
    'Dimension', {
    {'alongshore'}
    {'alongshore'}
    {'alongshore' 'stringsize'}
    {'alongshore'}
    {'alongshore'}
    {'alongshore'}
    {'alongshore'}});

create empty file

nc_create_empty(OPT.filename)

add dimension

nc_add_dimension(OPT.filename,...
    'alongshore', sum(id));
nc_add_dimension(OPT.filename,...
    'stringsize', stringsize);

add variables

for i = 1:length(s)
    nc_addvar(OPT.filename, s(i));
end

add attributes

nc_attput(OPT.filename, nc_global,...
    'history', ['$HeadURL: https://repos.deltares.nl/repos/OpenEarthRawData/trunk/rijkswaterstaat/grainsize_vtv/grainsize2netcdf.m $' char(10) '$Id: grainsize2netcdf.m 327 2009-04-21 15:29:18Z heijer $' char(10) 'Source data: ' strrep('$HeadURL: https://repos.deltares.nl/repos/OpenEarthRawData/trunk/rijkswaterstaat/grainsize_vtv/grainsize2netcdf.m $', [mfilename '.m'], OPT.sourcefile)])

nc_attput(OPT.filename, 'id', 'long_name', 'identifier');
nc_attput(OPT.filename, 'id', 'comment', 'sum of area code (x1000000) and alongshore coordinate');

nc_attput(OPT.filename, 'areacode', 'long_name', 'area code');
nc_attput(OPT.filename, 'areacode', 'comment', 'codes for the 15 areas as defined by rijkswaterstaat');

nc_attput(OPT.filename, 'areaname', 'long_name', 'area name');
nc_attput(OPT.filename, 'areaname', 'comment', 'codes for the 15 areas as defined by rijkswaterstaat');

nc_attput(OPT.filename, 'alongshore', 'long_name', 'alongshore coordinate');
nc_attput(OPT.filename, 'alongshore', 'units', 'm');

nc_attput(OPT.filename, 'meanD50', 'long_name', 'mean of D50 grain size');
nc_attput(OPT.filename, 'meanD50', 'units', 'm');

nc_attput(OPT.filename, 'sigmaD50', 'long_name', 'standard deviation of D50 grain size');
nc_attput(OPT.filename, 'sigmaD50', 'units', 'm');

nc_attput(OPT.filename, 'calcD50', 'long_name', 'calculation value for D50 grain size');
nc_attput(OPT.filename, 'calcD50', 'units', 'm');

store index variables

nc_varput(OPT.filename, 'id', Grainsizes(:,1)*1e6 + Grainsizes(:,2)*100);

nc_varput(OPT.filename, 'areacode', Grainsizes(:,1));

nc_varput(OPT.filename, 'areaname', char(areaname));

nc_varput(OPT.filename, 'alongshore', Grainsizes(:,2)*100);

nc_varput(OPT.filename, 'meanD50', Grainsizes(:,3));

nc_varput(OPT.filename, 'sigmaD50', Grainsizes(:,4));

nc_varput(OPT.filename, 'calcD50', Grainsizes(:,5));