% convertSuppleties2nc
%
% Generates suppleties.nc which contains the information about nourishments
% applied along the Dutch coast over the years.
% 
% Available info:
%
% Code      Nourishment code [valid just for the old .xls databases]
%           id is deprecated in newer versions.
%
% Area      Kustvak relative to the nourishment
% 
% Date      Starting date / ending date
%
% Transect  Starting transect / ending transect
%
%
% 
% Within suppleties.nc, data can be analized using the following available
% structures:
% 
% (1.) rows and columns as in the source (.../rijkswaterstaat/suppleties/Suppletiedatabase-31-12-2010.xls)
% (2.) matrix (alongshore, time), following the same structure of jarkus transect.nc
%
%
% Nourishments info are taken from Deltares repository (.xls format) @
% https://repos.deltares.nl/repos/OpenEarthRawData/trunk/rijkswaterstaat/suppleties/Suppletiedatabase-31-12-2010.xls
%
% giorgio.santinelli@deltares.nl
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear

%% settings
% suppleties
OPT.ncpath1    = 'https://repos.deltares.nl/repos/OpenEarthRawData/trunk/rijkswaterstaat/suppleties/';
OPT.ncpath1    = fileparts(mfilename('fullpath')); % local
OPT.Filename1  = 'd:\checkouts\OpenEarthRawData\suppleties\raw\Suppletiedatabase_gegevens_2018.xlsx'; % 'Suppletiedatabase-22-08-2012.xls';
OPT.Filename3  = 'Versterkingen-19-11-2012.xls';

% general settings
OPT.fillvalue    = NaN;
OPT.refdatenum   = datenum(1970,1,1);
OPT.outputfile   = 'suppleties.nc';
OPT.disp         = true;
OPT.dump         = true;

% jarkus database for info about RSP, latlon, RDNew
OPT.ncpath2      = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/';
OPT.Filename2    = 'transect.nc';

%%
% read nourishments from SUPPLETIES database (m3/m)
suppl = rws_suppletiedatabase(OPT.Filename1);

% read nourishments from second (with approximate info) database: VERSTERKINGEN
supplV = xls2struct(OPT.Filename3);
supplV.areacode = rws_kustvak(supplV.p_kustvak);
if iscell(supplV.areacode)
   supplV.areacode = ([supplV.areacode{:}]);
end

supplV.datenum0     = datenum(supplV.p_beginuitvoering,supplV.p_beginmnduitv,1);
supplV.datenum1     = datenum(supplV.p_einduitvoering, supplV.p_eindmnduitv ,1);
supplV_ncode   = supplV.n_code; % n_code is changed to char.
supplV_bdatum  = supplV.datenum0; % no day is specified [1st of the month is taken]
supplV_edatum  = supplV.datenum1; % no day is specified [1st of the month is taken]
supplV_vol     = supplV.volume; %suppletievolume [m3]
supplV_braai   = supplV.l_beginraai*100; %beginraai suppletie [decam]
supplV_eraai   = supplV.l_eindraai*100; %eindraai suppletie [decam]
supplV_dist    = (supplV_eraai-supplV_braai); 
supplV_dist(supplV_dist==0) = NaN;
supplV_vol2    = supplV_vol./(supplV_dist)/10; %suppletievolume [m3/m]
supplV_vol2(isnan(supplV_vol2))=0;

% add VERSTERKINGEN lines to structure suppl, so that variables suppl_* will contain it 
fld = fieldnames(supplV);
for ind = 1:length(fld)
    dum = fld{ind};
    if eval(['isa(suppl.' dum ', ''double'' )'])
        if eval(['isa(supplV.' dum ', ''double'' )']);
            eval(['suppl.' dum '(end+1:end+length(supplV.' dum ')) = supplV.' dum]);
        elseif eval(['isa(supplV.' dum ', ''cell'' )']);
            eval(['suppl.' dum '(end+1:end+length(supplV.' dum ')) = NaN(length(supplV.' dum '),1)']);
        end
    elseif eval(['isa(suppl.' dum ', ''cell'' )'])
        if eval(['isa(supplV.' dum ', ''cell'' )']);
            eval(['suppl.' dum '(end+1:end+length(supplV.' dum ')) = supplV.' dum ]);
        elseif eval(['isa(supplV.' dum ', ''double'' )']);
            eval(['suppl.' dum '(end+1:end+length(supplV.' dum ')) = {'''';'''';'''';''''}']); % dumb to create cell of char
        end
    end
end
    
    
suppl_ncode   = suppl.n_code; % n_code is changed to char.
suppl_bdatum  = suppl.datenum0; % no day is specified [1st of the month is taken]
suppl_edatum  = suppl.datenum1; % no day is specified [1st of the month is taken]
suppl_vol     = suppl.volume; %suppletievolume [m3]
suppl_braai   = suppl.l_beginraai*100; %beginraai suppletie [decam]
suppl_eraai   = suppl.l_eindraai*100; %eindraai suppletie [decam]
suppl_dist    = (suppl_eraai-suppl_braai); 
suppl_dist(suppl_dist==0) = NaN;
suppl_vol2    = suppl_vol./(suppl_dist)/10; %suppletievolume [m3/m]
suppl_vol2(isnan(suppl_vol2))=0;

suppl_kustvak           = suppl.p_kustvak;
suppl_location          = suppl.p_plaatsnaam;
suppl_opdrachtgever     = suppl.p_opdrachtgever;
suppl_doelstelling      = suppl.p_doelstelling;
suppl_kustverdediging   = suppl.l_kustverdediging;

suppl_ghw               = suppl.l_ghw;
suppl_glw               = suppl.l_glw;
suppl_trendkustlijn     = suppl.l_trendkustlijn;
suppl_beginjaartrend    = suppl.l_beginjaartrend;
suppl_eindjaartrend     = suppl.l_eindjaartrend;
suppl_geteigeul         = suppl.l_geteigeul;
suppl_zandgolf          = suppl.l_zandgolf;
suppl_brekerbanken      = suppl.l_brekerbanken;

suppl_type              = (suppl.b_typewerk)';
suppl_type_flag         = zeros(length(suppl_vol),1);  % not in the .xls dataset
for k = 1:length(suppl_vol)
    switch lower(char(suppl_type(k)))
        case {'strandsuppletie', 'strandsuppletie banket', 'strandsuppletie+vooroever',...
                'banket', 'strand (zwakke sch.)', 'strand-duinsuppletie',...
                'strandsuppletie+duinverzwaring'}
            suppl_type_flag(k)         = 1;
        case {'onderwatersuppletie', 'vooroever', 'vooroeversuppletie',...
                'geulwand', 'geulwandsuppletie'}
            suppl_type_flag(k)         = 2;
        case {'duin', 'duinverzwaring', 'landwaartse duinverzwaring',...
                'zeewaartse duinverzwaring', 'dijkverzwaring', 'duinverzwaring en strandsuppletie',...
                'zeewaartse duinverzwaring en strandsuppletie'}
            suppl_type_flag(k)         = 3;
        otherwise
            suppl_type_flag(k)         = 4;
    end
end

suppl_minkorrelvoor	    = suppl.b_minkorrelvoor;
suppl_maxkorrelvoor     = suppl.b_maxkorrelvoor;
suppl_minkorrelna	    = suppl.b_minkorrelna;
suppl_maxkorrelna       = suppl.b_maxkorrelna;	
suppl_methode           = suppl.b_methode;
suppl_banketbreedte     = suppl.b_banketbreedte;
suppl_vooroever         = suppl.b_vooroever;
suppl_strand            = suppl.b_strand;
suppl_duin              = suppl.b_duin;

suppl_geonaam         = suppl.w_geonaam;
suppl_afstand         = suppl.w_afstandsuppletie;
suppl_depth           = suppl.w_diepte;
suppl_x1              = suppl.w_x1;
suppl_x2              = suppl.w_x2;
suppl_x3              = suppl.w_x3;
suppl_x4              = suppl.w_x4;
suppl_y1              = suppl.w_y1;
suppl_y2              = suppl.w_y2;
suppl_y3              = suppl.w_y3;
suppl_y4              = suppl.w_y4;
suppl_minkorrelbodem  = suppl.w_minkorrelbodem;
suppl_maxkorrelbodem  = suppl.w_maxkorrelbodem;

suppl_werkwijze      = suppl.u_werkwijze;
suppl_materieel      = suppl.u_materieel;
suppl_varend         = suppl.u_varend;
suppl_hydraulisch    = suppl.u_hydraulisch;
suppl_peildatum      = suppl.d_peildatum;
suppl_levensduur     = suppl.d_levensduur;
suppl_herhalingstijd = suppl.d_herhalingstijd;
suppl_ontwerpmethode = suppl.d_ontwerpmethode;
suppl_modellen       = suppl.d_modellen;
suppl_meetraaien     = suppl.m_meetraaien;
suppl_werkbreedte    = suppl.m_werkbreedte;
suppl_inpeiling      = suppl.m_inpeiling;
suppl_uitpeiling     = suppl.m_uitpeiling;
suppl_overigepeiling = suppl.m_overigepeiling;
suppl_opmerkingen    = suppl.o_opmerkingen;
suppl_update         = suppl.x_update;

% starting time from OPT.refdatenum
suppl_bdatum  = suppl_bdatum - OPT.refdatenum;
suppl_edatum  = suppl_edatum - OPT.refdatenum;
suppl_datum   = [suppl_bdatum suppl_edatum];

% two-columns raai definition
suppl_areacode = cell2mat(rws_kustvak(suppl_kustvak))';

suppl_raai     = [suppl_areacode*1e6 + suppl_braai... 
    suppl_areacode*1e6 + suppl_eraai];

% four-columns extraction corner-points definition
suppl_x    = [suppl_x1 suppl_x2 suppl_x3 suppl_x4];
suppl_y    = [suppl_y1 suppl_y2 suppl_y3 suppl_y4];

% read jarkus information
id       = nc_varget([OPT.ncpath2 OPT.Filename2],'id');
rsp_lat  = nc_varget([OPT.ncpath2 OPT.Filename2],'rsp_lat');
rsp_lon  = nc_varget([OPT.ncpath2 OPT.Filename2],'rsp_lon');
rsp_x    = nc_varget([OPT.ncpath2 OPT.Filename2],'rsp_x');
rsp_y    = nc_varget([OPT.ncpath2 OPT.Filename2],'rsp_y');
areacode = nc_varget([OPT.ncpath2 OPT.Filename2],'areacode');
areaname = nc_varget([OPT.ncpath2 OPT.Filename2],'areaname');
along    = nc_varget([OPT.ncpath2 OPT.Filename2],'alongshore');

transectid = id - areacode*1e6;

% structure similar to jarkus transect.nc
% year of nourishment
ini_year   = str2double(datestr(min(suppl_bdatum + OPT.refdatenum),'yyyy')); % 1st nourishment: 1952
end_year   = str2double(datestr(max(suppl_bdatum + OPT.refdatenum),'yyyy')); % last nourishment: 2012
n_time     = datenum((ini_year : end_year)',01,01) - OPT.refdatenum; % days after 1970, 01, 01
n_year     = end_year - ini_year + 1;

% id nourishment

% definition of different type of volumes
Vol_beach     = zeros(length(id),n_year);
Vol_shoreface = zeros(length(id),n_year);
Vol_dune      = zeros(length(id),n_year);
Vol_other     = zeros(length(id),n_year);

% definition of start and end time for different type of volumes 
% (it's not possible to define 2 single matrixes for it: occurrence of two 
% differtent types of nourishments for the same transect, in the same year).
Time_start_beach      = NaN(length(id),n_year); Time_end_beach     = NaN(length(id),n_year);
Time_start_shoreface  = NaN(length(id),n_year); Time_end_shoreface = NaN(length(id),n_year);
Time_start_dune       = NaN(length(id),n_year); Time_end_dune      = NaN(length(id),n_year);
Time_start_other      = NaN(length(id),n_year); Time_end_other     = NaN(length(id),n_year);

for i = 1:length(id)
    disp(['id ' num2str(i) ' of ' num2str(length(id))]);
    for j = 1:n_year % year from 1952
        for k = 1:length(suppl_vol) % rows in the .xls database
            if ismember(cellstr(areaname(i,:)), suppl_kustvak(k,1)) && ...
                suppl_braai(k) <= transectid(i) && suppl_eraai(k) >= transectid(i) && ...
                str2double(datestr(suppl_bdatum(k) + OPT.refdatenum,'yyyy')) == (ini_year + j -1);
                
                % be careful at the type of nourishments. It might change
                % depending on versions.
                switch lower(char(suppl_type(k)))
                    case {'strandsuppletie', 'strandsuppletie banket', 'strandsuppletie+vooroever',...
                            'banket', 'strand (zwakke sch.)', 'strand-duinsuppletie',...
                            'strandsuppletie+duinverzwaring'}
						if Vol_beach(i,j) == 0
                            Vol_beach(i,j)        = suppl_vol2(k);
                            Time_start_beach(i,j) = suppl_bdatum(k);
                            Time_end_beach(i,j)   = suppl_edatum(k);
                        else
						    Vol_beach(i,j)        = Vol_beach(i,j) + suppl_vol2(k);
                            Time_start_beach(i,j) = min(Time_start_beach(i,j), suppl_bdatum(k));
                            Time_end_beach(i,j)   = max(Time_end_beach(i,j), suppl_edatum(k));
						end
						
                    case {'onderwatersuppletie', 'vooroever', 'vooroeversuppletie',...
                            'geulwand', 'geulwandsuppletie'}
						if Vol_shoreface(i,j) == 0
                            Vol_shoreface(i,j)        = suppl_vol2(k);
                            Time_start_shoreface(i,j) = suppl_bdatum(k);
                            Time_end_shoreface(i,j)   = suppl_edatum(k);
                        else
						    Vol_shoreface(i,j)        = Vol_shoreface(i,j) + suppl_vol2(k);
                            Time_start_shoreface(i,j) = min(Time_start_shoreface(i,j), suppl_bdatum(k));
                            Time_end_shoreface(i,j)   = max(Time_end_shoreface(i,j), suppl_edatum(k));
						end
                        
                    case {'duin', 'duinverzwaring', 'landwaartse duinverzwaring',...
                            'zeewaartse duinverzwaring', 'dijkverzwaring', 'duinverzwaring en strandsuppletie',...
                            'zeewaartse duinverzwaring en strandsuppletie'}
						if Vol_dune(i,j) == 0
                            Vol_dune(i,j)        = suppl_vol2(k);
                            Time_start_dune(i,j) = suppl_bdatum(k);
                            Time_end_dune(i,j)   = suppl_edatum(k);
                        else
						    Vol_dune(i,j)        = Vol_dune(i,j) + suppl_vol2(k);
                            Time_start_dune(i,j) = min(Time_start_dune(i,j), suppl_bdatum(k));
                            Time_end_dune(i,j)   = max(Time_end_dune(i,j), suppl_edatum(k));
						end
                        
                    otherwise
						if Vol_other(i,j) == 0
                            Vol_other(i,j)        = suppl_vol2(k);
                            Time_start_other(i,j) = suppl_bdatum(k);
                            Time_end_other(i,j)   = suppl_edatum(k);
                        else
						    Vol_other(i,j)        = Vol_other(i,j) + suppl_vol2(k);
                            Time_start_other(i,j) = min(Time_start_other(i,j), suppl_bdatum(k));
                            Time_end_other(i,j)   = max(Time_end_other(i,j), suppl_edatum(k));
						end
                        
                end
                
            end
        end
    end
end



%% create empty file
nc_create_empty(OPT.outputfile)

%% Add overall meta info
%  http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html#description-of-file-contents
%------------------

attval =  sprintf('created on %s', datestr(now));

nc_attput(OPT.outputfile, nc_global, 'title'         , 'nourishments along the Dutch coast');
nc_attput(OPT.outputfile, nc_global, 'institution'   , 'Rijkswaterstaat'); % Deltares?
nc_attput(OPT.outputfile, nc_global, 'source'        , 'https://svn.oss.deltares.nl/repos/openearthrawdata/trunk/rijkswaterstaat/suppleties/Suppletiedatabase-22-08-2012.xls'); % ?
nc_attput(OPT.outputfile, nc_global, 'history'       , ['Data processed from rijkswaterstaat nourishments database, ', attval]);
nc_attput(OPT.outputfile, nc_global, 'references'    , 'original source: http://www.rijkswaterstaat.nl , Deltares storage: http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/suppleties/ , converted with script convertSuppleties2nc.m');
% nc_attput(OPT.outputfile, nc_global, 'email'         , '');
nc_attput(OPT.outputfile, nc_global, 'comment'       , 'Data is presented in two different structures. One follows the fields in the .xls file provided by Rws. The other follows Jarkus transect.nc structure');
nc_attput(OPT.outputfile, nc_global, 'version'       , '0.2');
nc_attput(OPT.outputfile, nc_global, 'Conventions'   , 'CF-1.6');
% spatial reference using wkt. approach used by gdal.
nc_attput(OPT.outputfile, nc_global, 'spatial_ref', 'COMPD_CS["Amersfoort / RD New + NAP",PROJCS["Amersfoort / RD New",GEOGCS["Amersfoort",DATUM["Amersfoort",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[565.04,49.91,465.84,-0.40939438743923684,-0.35970519561431136,1.868491000350572,0.8409828680306614],AUTHORITY["EPSG","6289"]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943295],AXIS["Geodetic latitude",NORTH],AXIS["Geodetic longitude",EAST],AUTHORITY["EPSG","4289"]],PROJECTION["Oblique Stereographic",AUTHORITY["EPSG","9809"]],PARAMETER["central_meridian",5.387638888888891],PARAMETER["latitude_of_origin",52.15616055555556],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000.0],PARAMETER["false_northing",463000.0],UNIT["m",1.0],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","28992"]],VERT_CS["Normaal Amsterdams Peil",VERT_DATUM["Normaal Amsterdams Peil",2005,AUTHORITY["EPSG","5109"]],UNIT["m",1.0],AXIS["Gravity-related height",UP],AUTHORITY["EPSG","5709"]],AUTHORITY["EPSG","7415"]]');
% nc_attput(OPT.outputfile, nc_global, 'CF:featureType', 'stationTimeSeries');
nc_attput(OPT.outputfile, nc_global, 'terms_for_use' , 'These data can be used freely for research purposes provided that the following source is acknowledged: Rijkswaterstaat');
% nc_attput(OPT.outputfile, nc_global, 'disclaimer'    , 'This data is made available 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.');

%% create dimensions
% add dimensions
nc_adddim(OPT.outputfile, 'nourishment', length(suppl_vol)); % 0); % excel rows number
nc_adddim(OPT.outputfile, 'n_time'     , length(n_time));
nc_adddim(OPT.outputfile, 'alongshore' , length(along));
nc_adddim(OPT.outputfile, 'bounds'     , 2);
nc_adddim(OPT.outputfile, 'rect-bounds', 4);
nc_adddim(OPT.outputfile, 'stringsize' , 500); % comments make CHARs' bigger in size

%% add variables
clear nc
i = 0;

%% add epsg

% smaller variables first
[lon,lat,OPT2] = convertCoordinates(0,0,'CS1.code',28992,'CS2.code',4326);
%[CoordinateSystems, Operations , CoordSysCart ,CoordSysGeo] = GetCoordinateSystems();
epsg           = 28992;

i = i + 1;
nc(i).Name      = 'epsg';
nc(i).Nctype    = 'int';
nc(i).Dimension = {};
nc(i).Attribute = struct('Name', ...
   {'grid_mapping_name', ...
    'semi_major_axis', ...
    'semi_minor_axis', ...
    'inverse_flattening', ...
    'latitude_of_projection_origin', ...
    'longitude_of_projection_origin', ...
    'false_easting', ...
    'false_northing', ...
    'scale_factor_at_projection_origin',...
    'comment'}, ...
    'Value', ...
    {OPT2.proj_conv1.method.name,    ...
    OPT2.CS1.ellips.semi_major_axis, ...
    OPT2.CS1.ellips.semi_minor_axis, ...
    OPT2.CS1.ellips.inv_flattening,  ...
    OPT2.proj_conv1.param.value(strcmp(OPT2.proj_conv1.param.name,'Latitude of natural origin'    )), ...
    OPT2.proj_conv1.param.value(strcmp(OPT2.proj_conv1.param.name,'Longitude of natural origin'   )),...
    OPT2.proj_conv1.param.value(strcmp(OPT2.proj_conv1.param.name,'False easting'                 )),...
    OPT2.proj_conv1.param.value(strcmp(OPT2.proj_conv1.param.name,'False northing'                )),...
    OPT2.proj_conv1.param.value(strcmp(OPT2.proj_conv1.param.name,'Scale factor at natural origin')),...
    'value is equal to EPSG code'});

%% same structure as the excel file

% nourishment code, excel structure
i = i + 1;
nc(i).Name         = 'n_code'; % n_code is changed to char
nc(i).Nctype       = 'char'; 
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'nourishment code');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'nourishment identification code as defined by rws, referring to old database');

% suppl_datum (in place of suppl_bdatum & suppl_edatum), not in the excel structure
i = i + 1;
nc(i).Name         = 'date';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment', 'bounds'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'begin-date and end-date');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'first column is the beginning date, second column is the ending date, as they are in the rws database');

% suppl_raai, not in the excel structure, but created from beg-/end-stretch
i = i + 1;
nc(i).Name         = 'stretch';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment', 'bounds'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'begin-stretch and end-stretch');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'decam');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'first column is the beginning stretch, second column is the ending stretch, as they are in the rws database');

% suppl_Kustvak, excel structure
i = i + 1;
nc(i).Name         = 'kustvak';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'kustvak name');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'area name as it is in the rws database');

% suppl_location, excel structure
i = i + 1;
nc(i).Name         = 'location';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'location name');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'location name as it is in the rws database');

% suppl_opdrachtgever, excel structure
i = i + 1;
nc(i).Name         = 'authorizing_department';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'authorizing department');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'client name as it is in the rws database');

% suppl_doelstelling, excel structure
i = i + 1;
nc(i).Name         = 'purpose';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'purpose of the nourishment');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'purpose of the nourishment as it is in the rws database');

% suppl_kustverdediging, excel structure
i = i + 1;
nc(i).Name         = 'coastal_defense';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'existing coastal defense');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'existing coastal defense as it is in the rws database');

% suppl_ghw, excel structure
i = i + 1;
nc(i).Name         = 'mean_high_water';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'mean high water');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'mean high water as it is in the rws database');

% suppl_glw, excel structure
i = i + 1;
nc(i).Name         = 'mean_low_water';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'mean low water');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'mean low water as it is in the rws database');

% suppl_trendkustlijn, excel structure
i = i + 1;
nc(i).Name         = 'trend_coastline';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'trend of the coastline');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'trend of the coastline as it is in the rws database');

% suppl_beginjaartrend, excel structure
i = i + 1;
nc(i).Name         = 'beg_year_trend';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'beginning year of trend calculation');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'beginning year of trend calculation as it is in the rws database');

% suppl_eindjaartrend, excel structure
i = i + 1;
nc(i).Name         = 'end_year_trend';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'ending year of trend calculation');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'ending year of trend calculation as it is in the rws database');

% suppl_geteigeul, excel structure
i = i + 1;
nc(i).Name         = 'tidal_channel';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'presence of any tidal channel');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'presence of any tidal channel as it is in the rws database');

% suppl_zandgolf, excel structure
i = i + 1;
nc(i).Name         = 'sand_wave';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'presence of any sand wave');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'presence of any sand wave as it is in the rws database');

% suppl_brekerbanken, excel structure
i = i + 1;
nc(i).Name         = 'breaker_bar';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'presence of any breaker bar');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'presence of any breaker bar as it is in the rws database');

% suppl_type, excel structure
i = i + 1;
nc(i).Name         = 'type';
nc(i).Nctype       = 'char'; 
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'nourishment type');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'nourishment type as it is in the rws database');

% suppl_type_flag, excel structure
% flags for suppl_type [not present in the excel dataset]
%     id=1 beach nourishment
%     id=2 shoreface nourishment
%     id=3 dune nourishment
%     id=4 other nourishment
i = i + 1;
nc(i).Name      = 'type_flag';
nc(i).Nctype    = 'int';
nc(i).Dimension = {'nourishment'};
flag_values     = [ 1          2             3             4           ]; 
nc(i).Attribute    = struct('Name' ,{'long_name', 'flag_values', 'flag_meanings', 'comment'},...
                     'Value',{'nourishment type',  flag_values  ,'beach shoreface dune other', 'nourishment type with flags instead of chars, unlike it is in the rws database'});
 
% suppl_vol, excel structure
i = i + 1;
nc(i).Name         = 'vol';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'nourishment volume');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm^3');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'nourishment volume as it is in the rws database');

% suppl_minkorrelvoor, excel structure
i = i + 1;
nc(i).Name         = 'min_grainsize_before';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'minimum grainsize before the execution');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'micron');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'minimum grainsize before the execution as it is in the rws database');

% suppl_maxkorrelvoor, excel structure
i = i + 1;
nc(i).Name         = 'max_grainsize_before';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'maximum grainsize before the execution');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'micron');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'maximum grainsize before the execution as it is in the rws database');

% suppl_minkorrelna, excel structure
i = i + 1;
nc(i).Name         = 'min_grainsize_after';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'minimum grainsize after the execution');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'micron');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'minimum grainsize after the execution as it is in the rws database');

% suppl_maxkorrelna, excel structure
i = i + 1;
nc(i).Name         = 'max_grainsize_after';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'maximum grainsize after the execution');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'micron');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'maximum grainsize after the execution as it is in the rws database');

% suppl_methode, excel structure
i = i + 1;
nc(i).Name         = 'sieving_method';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'sieving method for the grainsize');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'sieving method for the grainsize as it is in the rws database');

% suppl_banketbreedte, excel structure
i = i + 1;
nc(i).Name         = 'bank_width';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'bank width');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'bank width as it is in the rws database');

% suppl_vooroever, excel structure
i = i + 1;
nc(i).Name         = 'foreshore_slope';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'foreshore slope');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'percentage');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'foreshore slope as it is in the rws database');

% suppl_strand, excel structure
i = i + 1;
nc(i).Name         = 'beach_slope';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'beach slope');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'percentage');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'beach slope as it is in the rws database');

% suppl_duin, excel structure
i = i + 1;
nc(i).Name         = 'dune_slope';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'dune slope');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'percentage');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'dune slope as it is in the rws database');

% suppl_geonaam, excel structure
i = i + 1;
nc(i).Name         = 'geo_name';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'geo-name of the extraction area');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'geo-name of the extraction area as it is in the rws database');

% suppl_afstand, excel structure
i = i + 1;
nc(i).Name         = 'extraction_distance';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'extraction distance');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'distance of the extraction area as it is in the rws database');

% suppl_depth, excel structure
i = i + 1;
nc(i).Name         = 'extraction_depth';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'extraction depth');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'depth of extraction area as it is in the rws database');

% suppl_x, using x1, x2, x3, x4 which are in the excel structure
i = i + 1;
nc(i).Name         = 'x_corner';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment', 'rect-bounds'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'x-coordinate of extraction corner-points');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'x-coordinate of extraction corner-points created from x1, x2, x3, x4 as they are in the rws database');

% suppl_y, using y1, y2, y3, y4 which are in the excel structure
i = i + 1;
nc(i).Name         = 'y_corner';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment', 'rect-bounds'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'y-coordinate of extraction corner-points');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'y-coordinate of extraction corner-points created from y1, y2, y3, y4 as they are in the rws database');

% suppl_minkorrelbodem, excel structure
i = i + 1;
nc(i).Name         = 'min_grainsize_bottom';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'minimum grainsize of the bottom');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'micron');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'minimum grainsize of the bottom as it is in the rws database');

% suppl_maxkorrelbodem, excel structure
i = i + 1;
nc(i).Name         = 'max_grainsize_bottom';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'maximum grainsize of the bottom');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'maximum grainsize of the bottom as it is in the rws database');

% suppl_werkwijze, excel structure
i = i + 1;
nc(i).Name         = 'implementation';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'implementation of the execution');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'implementation of the execution works as it is in the rws database');

% suppl_materieel, excel structure
i = i + 1;
nc(i).Name         = 'equipment';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'used equipment');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'used equipment as it is in the rws database');

% suppl_varend, excel structure
i = i + 1;
nc(i).Name         = 'sailing_distance';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'sailing transport-distance');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'sailing transport-distance from the nourishment as it is in the rws database');

% suppl_hydraulisch, excel structure
i = i + 1;
nc(i).Name         = 'hydraulic_distance';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'hydraulic transport-distance');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'hydraulic transport-distance from the nourishment as it is in the rws database');

% suppl_peildatum, excel structure
i = i + 1;
nc(i).Name         = 'survey_date';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'date of the survey');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'date of the survey as it is in the rws database');

% suppl_levensduur, excel structure
i = i + 1;
nc(i).Name         = 'expected_life';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'expected life of the nourishment');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'year');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'expected life of the nourishment as it is in the rws database');

% suppl_herhalingstijd, excel structure
i = i + 1;
nc(i).Name         = 'return_period';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'expected return period of the nourishment');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'year');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'expected return period of the nourishment as it is in the rws database');

% suppl_ontwerpmethode, excel structure
i = i + 1;
nc(i).Name         = 'design_method';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'used design method');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'used design method as it is in the rws database');

% suppl_modellen, excel structure
i = i + 1;
nc(i).Name         = 'model';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'applied model');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'applied model as it is in the rws database');

% suppl_meetraaien, excel structure
i = i + 1;
nc(i).Name         = 'measurement_trans';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'number of transects for monitoring');
nc(i).Attribute(2) = struct('Name', 'comment'       ,'Value', 'number of transects for monitoring as it is in the rws database');

% suppl_werkbreedte, excel structure
i = i + 1;
nc(i).Name         = 'working_width';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'working width of transects');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'working width of transects as it is in the rws database');

% suppl_inpeiling, excel structure
i = i + 1;
nc(i).Name         = 'survey_date_before';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'date of survey before the nourishment');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'date of survey before the nourishment as it is in the rws database');

% suppl_uitpeiling, excel structure
i = i + 1;
nc(i).Name         = 'survey_date_after';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'date of survey after the nourishment');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'date of survey after the nourishment as it is in the rws database');

% suppl_overigepeiling, excel structure
i = i + 1;
nc(i).Name         = 'survey_other';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'nourishment'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'logical value for presence of other surveys');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'presence of other surveys as it is in the rws database');

nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'other survey');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'other surveys as it is in the rws database');

% suppl_opmerkingen, excel structure
i = i + 1;
nc(i).Name         = 'other_comments';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'additional comments');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'additional comments as in the rws database');

% suppl_update, excel structure
i = i + 1;
nc(i).Name         = 'update';
nc(i).Nctype       = 'char';
nc(i).Dimension    = {'nourishment','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'date of update execution');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'date of update execution as it is in the rws database');


%% structure similar to transect.nc

% id
i = i + 1;
nc(i).Name      = 'id';
nc(i).Nctype    = 'int';
nc(i).Dimension = {'alongshore'};
nc(i).Attribute = struct('Name' ,{'long_name' ,'comment'},'Value',{'identifier','sum of area code (x1000000) and alongshore coordinate'});

% n_time
i = i + 1;
nc(i).Name      = 'n_time';
nc(i).Nctype    = 'double';
nc(i).Dimension = {'n_time'};
nc(i).Attribute(1) = struct('Name', 'standard_name' ,'Value', 'time');
% nc(i).Attribute(2) = struct('Name', 'axis'          ,'Value', 'T');
nc(i).Attribute(2) = struct('Name', 'units'         ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'       ,'Value', 'beginning year for the specific nourishment');

% areaname
i = i + 1;
nc(i).Name         = 'areaname';
nc(i).Nctype       = 'char'; 
nc(i).Dimension    = {'alongshore','stringsize'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'name of coastal area');
nc(i).Attribute(2) = struct('Name', 'comment'   ,'Value', 'name of coastal areas as defined by rijkswaterstaat');

% alongshore
i = i + 1;
nc(i).Name         = 'alongshore';
nc(i).Nctype       = 'double'; 
nc(i).Dimension    = {'alongshore'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'alongshore coordinate');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'alongshore coordinate within the 15 coastal areas as defined by rijkswaterstaat');

% rsp_lat
i = i + 1;
nc(i).Name         = 'rsp_lat';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'beach pole - latitude');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'degrees_north');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'Location of the beach pole (Rijks strand paal)');  

% rsp_lon
i = i + 1;
nc(i).Name         = 'rsp_lon';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'beach pole - longitude');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'degrees_east');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'Location of the beach pole (Rijks strand paal)');  

% rsp_x
i = i + 1;
nc(i).Name         = 'rsp_x';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'beach pole - x coordinate');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'axis'      ,'Value', 'X');
nc(i).Attribute(4) = struct('Name', 'comment'   ,'Value', 'Location of the beach pole (Rijks strand paal)');

% rsp_y
i = i + 1;
nc(i).Name         = 'rsp_y';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'beach pole - y coordinate');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm');
nc(i).Attribute(3) = struct('Name', 'axis'      ,'Value', 'Y');
nc(i).Attribute(4) = struct('Name', 'comment'   ,'Value', 'Location of the beach pole (Rijks strand paal)');

% vol_beach
i = i + 1;
nc(i).Name         = 'vol_beach';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'volume per transect: beach nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm^3/m');
nc(i).Attribute(3) = struct('Name', '_FillValue','Value', 0);
nc(i).Attribute(4) = struct('Name', 'comment'   ,'Value', 'volume per transect, obtained dividing nourishment volume per alongshore length');  

% vol_shoreface
i = i + 1;
nc(i).Name         = 'vol_shoreface';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'volume per transect: shoreface nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm^3/m');
nc(i).Attribute(3) = struct('Name', '_FillValue','Value', 0);
nc(i).Attribute(4) = struct('Name', 'comment'   ,'Value', 'volume per transect, obtained dividing nourishment volume per alongshore length');  

% vol_dune
i = i + 1;
nc(i).Name         = 'vol_dune';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'volume per transect: dune nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm^3/m');
nc(i).Attribute(3) = struct('Name', '_FillValue','Value', 0);
nc(i).Attribute(4) = struct('Name', 'comment'   ,'Value', 'volume per transect, obtained dividing nourishment volume per alongshore length');

% vol_other
i = i + 1;
nc(i).Name         = 'vol_other';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'volume per transect: other type of nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'm^3/m');
nc(i).Attribute(3) = struct('Name', '_FillValue','Value', 0);
nc(i).Attribute(4) = struct('Name', 'comment'   ,'Value', 'volume per transect, obtained dividing nourishment volume per alongshore length');


% start and end time for each type of nourishment (no idea for better efficiency yet)
% time_start_beach
i = i + 1;
nc(i).Name         = 'time_start_beach';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'start time per transect for beach nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'start time for a specific nourishment type, per transect. In case of several nourishments, the minimum value holds');  

% time_end_beach
i = i + 1;
nc(i).Name         = 'time_end_beach';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'end time per transect for beach nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'end time for a specific nourishment type, per transect. In case of several nourishments, the maximum value holds');  

% time_start_shore
i = i + 1;
nc(i).Name         = 'time_start_shoreface';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'start time per transect for shoreface nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'start time for a specific nourishment type, per transect. In case of several nourishments, the minimum value holds');  

% time_end_shore
i = i + 1;
nc(i).Name         = 'time_end_shoreface';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'end time per transect for shoreface nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'end time for a specific nourishment type, per transect. In case of several nourishments, the maximum value holds');  

% time_start_dune
i = i + 1;
nc(i).Name         = 'time_start_dune';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'start time per transect for dune nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'start time for a specific nourishment type, per transect. In case of several nourishments, the minimum value holds');  

% time_end_dune
i = i + 1;
nc(i).Name         = 'time_end_dune';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'end time per transect for dune nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'end time for a specific nourishment type, per transect. In case of several nourishments, the maximum value holds');  

% time_start_other
i = i + 1;
nc(i).Name         = 'time_start_other';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'start time per transect for other type of nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'start time for a specific nourishment type, per transect. In case of several nourishments, the minimum value holds');  

% time_end_other
i = i + 1;
nc(i).Name         = 'time_end_other';
nc(i).Nctype       = 'double';
nc(i).Dimension    = {'alongshore','n_time'};
nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'end time per transect for other type of nourishment');
nc(i).Attribute(2) = struct('Name', 'units'     ,'Value', 'days since 1970-01-01 00:00 +1:00');
nc(i).Attribute(3) = struct('Name', 'comment'   ,'Value', 'end time for a specific nourishment type, per transect. In case of several nourishments, the maximum value holds');  


% code, different from n_code: structure similar to jarkus. 
% Cannot do it: issue with more than 1 code for a specific transect and for a specific year
% i = i + 1;
% nc(i).Name         = 'code';
% nc(i).Nctype       = 'integer';
% nc(i).Dimension    = {'alongshore','n_time'};
% nc(i).Attribute(1) = struct('Name', 'long_name' ,'Value', 'code of nourishment per transect');


%% create variables with attributes
for i = 1:length(nc)
    if OPT.disp;disp(['adding ',num2str(i),' ',nc(i).Name]);end
    nc_addvar(OPT.outputfile, nc(i));
end

%% store variables

nc_varput(OPT.outputfile, 'n_code'                  , char(cellfun(@(x) num2str(x),suppl_ncode,'Un',0)));
nc_varput(OPT.outputfile, 'date'                    , suppl_datum);
nc_varput(OPT.outputfile, 'stretch'                 , suppl_raai);
nc_varput(OPT.outputfile, 'kustvak'                 , char(suppl_kustvak));
nc_varput(OPT.outputfile, 'location'                , char(cellfun(@(x) char(x),suppl_location,'Un',0)));
nc_varput(OPT.outputfile, 'type'                    , char(suppl_type));
nc_varput(OPT.outputfile, 'type_flag'               , suppl_type_flag);
nc_varput(OPT.outputfile, 'vol'                     , suppl_vol);
nc_varput(OPT.outputfile, 'authorizing_department'  , char(suppl_opdrachtgever));
nc_varput(OPT.outputfile, 'purpose'                 , char(suppl_doelstelling));
nc_varput(OPT.outputfile, 'coastal_defense'         , char(suppl_kustverdediging));
nc_varput(OPT.outputfile, 'mean_high_water'         , suppl_ghw);
nc_varput(OPT.outputfile, 'mean_low_water'          , suppl_glw);
nc_varput(OPT.outputfile, 'trend_coastline'         , suppl_trendkustlijn);
nc_varput(OPT.outputfile, 'beg_year_trend'          , suppl_beginjaartrend);
nc_varput(OPT.outputfile, 'end_year_trend'          , suppl_eindjaartrend);
nc_varput(OPT.outputfile, 'tidal_channel'           , char(suppl_geteigeul));
nc_varput(OPT.outputfile, 'sand_wave'               , char(suppl_zandgolf));
nc_varput(OPT.outputfile, 'breaker_bar'             , char(suppl_brekerbanken));
nc_varput(OPT.outputfile, 'min_grainsize_before'    , suppl_minkorrelvoor);
nc_varput(OPT.outputfile, 'max_grainsize_before'    , suppl_maxkorrelvoor);
nc_varput(OPT.outputfile, 'min_grainsize_after'     , suppl_minkorrelna);
nc_varput(OPT.outputfile, 'max_grainsize_after'     , suppl_maxkorrelna);
nc_varput(OPT.outputfile, 'sieving_method'          , char(suppl_methode));
nc_varput(OPT.outputfile, 'bank_width'              , suppl_banketbreedte);
nc_varput(OPT.outputfile, 'foreshore_slope'         , suppl_vooroever);
nc_varput(OPT.outputfile, 'beach_slope'             , suppl_strand);
nc_varput(OPT.outputfile, 'dune_slope'              , suppl_duin);
nc_varput(OPT.outputfile, 'geo_name'                , char(suppl_geonaam));
nc_varput(OPT.outputfile, 'extraction_distance'     , char(suppl_afstand));
nc_varput(OPT.outputfile, 'extraction_depth'        , suppl_depth);
nc_varput(OPT.outputfile, 'x_corner'                , suppl_x);
nc_varput(OPT.outputfile, 'y_corner'                , suppl_y);
nc_varput(OPT.outputfile, 'min_grainsize_bottom'    , suppl_minkorrelbodem);
nc_varput(OPT.outputfile, 'max_grainsize_bottom'    , suppl_maxkorrelbodem);
nc_varput(OPT.outputfile, 'implementation'          , char(suppl_werkwijze));
nc_varput(OPT.outputfile, 'equipment'               , char(suppl_materieel));
nc_varput(OPT.outputfile, 'sailing_distance'        , char(suppl_varend));
nc_varput(OPT.outputfile, 'hydraulic_distance'      , char(cellfun(@(x) num2str(x),suppl_hydraulisch,'Un',0)));
nc_varput(OPT.outputfile, 'survey_date'             , char(suppl_peildatum));
nc_varput(OPT.outputfile, 'expected_life'           , suppl_levensduur);
nc_varput(OPT.outputfile, 'return_period'           , suppl_herhalingstijd);
nc_varput(OPT.outputfile, 'design_method'           , char(suppl_ontwerpmethode));
nc_varput(OPT.outputfile, 'model'                   , char(suppl_modellen));
nc_varput(OPT.outputfile, 'measurement_trans'       , suppl_meetraaien);
nc_varput(OPT.outputfile, 'working_width'           , suppl_werkbreedte);
nc_varput(OPT.outputfile, 'survey_date_before'      , char(suppl_inpeiling));
nc_varput(OPT.outputfile, 'survey_date_after'       , char(suppl_uitpeiling));
nc_varput(OPT.outputfile, 'survey_other'            , cell2mat(cellfun(@(x) double(x),suppl_overigepeiling,'Un',0)));
nc_varput(OPT.outputfile, 'other_comments'          , char(suppl_opmerkingen));
nc_varput(OPT.outputfile, 'update'                  , char(suppl_update));

nc_varput(OPT.outputfile, 'id'                , id);
nc_varput(OPT.outputfile, 'areaname'          , areaname);
nc_varput(OPT.outputfile, 'alongshore'        , along);
nc_varput(OPT.outputfile, 'n_time'            , n_time);
nc_varput(OPT.outputfile, 'rsp_lat'           , rsp_lat);
nc_varput(OPT.outputfile, 'rsp_lon'           , rsp_lon);
nc_varput(OPT.outputfile, 'rsp_x'             , rsp_x);
nc_varput(OPT.outputfile, 'rsp_y'             , rsp_y);
nc_varput(OPT.outputfile, 'vol_beach'         , Vol_beach);
nc_varput(OPT.outputfile, 'vol_shoreface'     , Vol_shoreface);
nc_varput(OPT.outputfile, 'vol_dune'          , Vol_dune);
nc_varput(OPT.outputfile, 'vol_other'         , Vol_other);

nc_varput(OPT.outputfile, 'time_start_beach'     , Time_start_beach);
nc_varput(OPT.outputfile, 'time_end_beach'       , Time_end_beach);
nc_varput(OPT.outputfile, 'time_start_shoreface' , Time_start_shoreface);
nc_varput(OPT.outputfile, 'time_end_shoreface'   , Time_end_shoreface);
nc_varput(OPT.outputfile, 'time_start_dune'      , Time_start_dune);
nc_varput(OPT.outputfile, 'time_end_dune'        , Time_end_dune);
nc_varput(OPT.outputfile, 'time_start_other'     , Time_start_other);
nc_varput(OPT.outputfile, 'time_end_other'       , Time_end_other);

%% check
if OPT.dump
    nc_dump(OPT.outputfile);
end

%% end

