%Load and read the data
datadir=fullfile('..','raw\tide');
files=dir(fullfile(datadir, '*.xls'));
xls_file = 'tide_FBevano.xls';
[dataset,txt]=xlsread(fullfile(datadir, xls_file),'tide_FBevano');
times = x2mdate(dataset(:,1)); %Convert Excel dates to Matlab dates
depth = dataset(:,3); %Mean high water above sensor
wl = dataset(:,9); %Calculated level above MSL

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

% Add global atributes
nc_attput(filename, nc_global, 'title', 'Bevano river mouth tide measurements');
nc_attput(filename, nc_global, 'institution', 'Università di Ferrara');
nc_attput(filename, nc_global, 'source', 'Pressure transducer measurements')
nc_attput(filename, nc_global, 'comment', 'Located inside mouth of Bevano River')

%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, calculated to be 0.78 m below MSL')

varstruct.Name='wl';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'wl','units','m')
nc_attput(filename,'wl','long_name','water_level')
nc_attput(filename, 'wl', 'standard_name', 'sea_surface_height_above_sea_level')
nc_attput(filename,'wl','comment','reference level is mean sea level in Genova')

%Add variable data
nc_varput(filename, 't', times)
nc_varput(filename, 'D', depth)
nc_varput(filename, 'wl', wl)

%End file
nc_dump(filename)