%Load and read the data
datadir=fullfile('..','raw\S4');
files=dir(fullfile(datadir, '*.xls'));
xls_file = 's4_april09_surfzone.xls';
[dataset,txt]=xlsread(fullfile(datadir, xls_file),'S4_April09');
dates = datenum(txt(3:end,2),'mm/dd/yy');
times = dates+dataset(:,3); %Add hours to dates
depth = dataset(:,5); %Mean high water above sensor
hsig = dataset(:,7); %Significant wave height
tz = dataset(:,11); %zero-upcrossing wave period (Tz)

% Create new netCdf file
filename=('s4_april09_surfzone.nc');
nc_create_empty(filename)

% Add global atributes
nc_attput(filename, nc_global, 'title', 'Bevano surfzone S4 measurements');
nc_attput(filename, nc_global, 'institution', 'Università di Ferrara');
nc_attput(filename, nc_global, 'source', 'S4 measurements')
nc_attput(filename, nc_global, 'comment', 'Located at north of Bevano River mouth in surfzone')

%Add dimensions
nc_add_dimension(filename,'points',length(times))
%nc_add_dimension(filename,'elev',length(elev))

%Add variable attributes
varstruct.Name='t';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'t','units','days')
nc_attput(filename,'t','long_name','time')
nc_attput(filename, 't', 'standard_name', 'time')
nc_attput(filename, 't', 'comment', 'days since 1 January 0 AD (standard MATLAB date format)')

varstruct.Name='D';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'D','units','m')
nc_attput(filename,'D','long_name','depth')
nc_attput(filename, 'D', 'standard_name', 'depth')
nc_attput(filename, 'D', 'comment', 'Mean high water above sensor')

varstruct.Name='hs';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'hs','units','m')
nc_attput(filename,'hs','long_name','significant_wave_height')
nc_attput(filename, 'hs', 'standard_name', 'sea_surface_wave_significant_height')

varstruct.Name='tz';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'tz','units','s')
nc_attput(filename,'tz','long_name','wave_period')
nc_attput(filename, 'tz', 'standard_name', 'sea_surface_wave_zero_upcrossing_period')


%Add variable data
nc_varput(filename, 't', times)
nc_varput(filename, 'D', depth)
nc_varput(filename, 'hs', hsig)
nc_varput(filename, 'tz', tz)


%End file
nc_dump(filename)