%Load and read the data
datadir=fullfile('..','raw');
files=dir(fullfile(datadir, '*.xls'));
xls_file = 'topo_Sept_2009.xls';
[dataset,txt]=xlsread(fullfile(datadir, xls_file),'Total_Profiles_Sep_2009');
x=dataset(:,1);
y=dataset(:,2);
elev=dataset(:,5); %Use more-correct ITALGEOID99 elevation data

% Create new netCdf file
filename=('topo_Sept-2009.nc');
nc_create_empty(filename)

% Add global atributes
nc_attput(filename, nc_global, 'title', 'Lido di Dante/Lido di Classe topography September 2009');
nc_attput(filename, nc_global, 'institution', 'Università di Ferrara');
nc_attput(filename, nc_global, 'source', 'RTK-GPS field measurements')
nc_attput(filename, nc_global, 'comment', 'Surveys undertaken between 15/09/2009 and 17/09/2009')

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

%Add variable attributes
varstruct.Name='x';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'x','units','m')
nc_attput(filename,'x','long_name','x_coordinate')
nc_attput(filename, 'x', 'standard_name', 'projection_x_coordinate')
nc_attput(filename, 'x', 'comment', 'eastings based on WGS84 UTM Zone 32 projection')

varstruct.Name='y';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'y','units','m')
nc_attput(filename,'y','long_name','y_coordinate')
nc_attput(filename, 'y', 'standard_name', 'projection_y_coordinate')
nc_attput(filename, 'y', 'comment', 'northings based on WGS84 UTM Zone 32 projection')

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

%Add variable data
nc_varput(filename, 'x', x)
nc_varput(filename, 'y', y)
nc_varput(filename, 'elevation', elev)

%End file
nc_dump(filename)