%Load and read the data
datadir=fullfile('..','raw\ADCP');
files=dir(fullfile(datadir, '*.xls'));
xls_file = 'FUniti.xls';
[dataset,txt]=xlsread(fullfile(datadir, xls_file),'data-adcp-Uniti');
times = datenum(dataset(14:end,2)+2000,dataset(14:end,3),dataset(14:end,4),dataset(14:end,5),dataset(14:end,6),dataset(14:end,7));
depth = dataset(14:end,10);%Data starts at row 14
WL = dataset(14:end,11);%Data starts at row 14
Veast = dataset(14:end,12);%Data starts at row 14
Vnorth = dataset(14:end,14);%Data starts at row 14
Vmean = dataset(14:end,16);%Data starts at row 14
Dir = dataset(14:end,18);%Data starts at row 14

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

% Add global atributes
nc_attput(filename, nc_global, 'title', 'Fiumi Uniti ADCP current measurements');
nc_attput(filename, nc_global, 'institution', 'Università di Ferrara');
nc_attput(filename, nc_global, 'source', 'ADCP current measurements')
nc_attput(filename, nc_global, 'comment', 'Located at mouth of Uniti 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', 'ADCP situated 3.55m 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')

varstruct.Name='u';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'u','units','m/s')
nc_attput(filename,'u','long_name','eastward_velocity')
nc_attput(filename, 'u', 'standard_name', 'eastward_sea_water_velocity')

varstruct.Name='v';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'v','units','m/s')
nc_attput(filename,'v','long_name','northward_velocity')
nc_attput(filename, 'v', 'standard_name', 'northward_sea_water_velocity')

varstruct.Name='dir';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'dir','units','degrees from north')
nc_attput(filename,'dir','long_name','direction')
nc_attput(filename, 'dir', 'standard_name', 'direction_of_sea_water_velocity')

%Add variable data
nc_varput(filename, 't', times)
nc_varput(filename, 'D', depth)
nc_varput(filename, 'wl', WL)
nc_varput(filename, 'u', Veast)
nc_varput(filename, 'v', Vnorth)
nc_varput(filename, 'dir', Dir)

%End file
nc_dump(filename)