%javaaddpath('C:\Users\mahtab\TU
%Delft\checkout\OpenEarthTools\io\nctools\toolsUI-2.2.22.jar')
% define the directory where the raw files are stored
datadir=fullfile('..','raw');
% check which files are in the data directory
files=dir(fullfile(datadir, '*.xls'));
% we're just doing the first one (renamed from filename because this was
% used as output)
dataset=xlsread(fullfile(datadir, files(1).name));
% the file contains 3 columns
x=dataset(:,1);
y=dataset(:,2);
elev=dataset(:,3);
% check how many columns we have
npoints = length(lat);
% we assume that all 3 columns have the same length, better check it...
assert(length(x) == length(y))
assert(length(x) == length(elev))

% this is the file we're saving results to 
filename=('Bathy_micore.nc');
nc_create_empty(filename)
%by using the command length(lat_variable) it shows an error!
nc_add_dimension(filename,'points',npoints)
varstruct.Name='x';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'x','units','m')
nc_attput(filename, 'x', 'standard_name', 'projection_x_coordinate')

varstruct.Name='y';
varstruct.Nctype=nc_double;
varstruct.Dimension={'points'};
nc_addvar(filename,varstruct)
nc_attput(filename,'y','units','meters')
nc_attput(filename, 'y', 'standard_name', 'projection_y_coordinate')

nc_add_dimension(filename,'elev',length(elev))
varstruct.Name='elevation'
varstruct.Nctype=nc_double
varstruct.Dimension={'points'}
nc_addvar(filename,varstruct)
nc_attput(filename,'elevation','units','m')

% there is an error here too!nc_attput(filename,'title','Converting bathymetry data to NETcdf file')
nc_varput(filename, 'elevation', elev)
nc_varput(filename, 'x', x)
nc_varput(filename, 'y', y)

nc_dump(filename)





