%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');

load(fullfile(datadir,'infinity_processed'));

dirout=fullfile('..','Processed');

% check how many columns we have
npoints = length(infinity.sdate);

% this is the file we're saving results to 
filename=fullfile(dirout,'offshore_data.nc');

nam={'sea_level';'Hm0';'Tp';'m0';'Hs';'Hm';'H10';'Hmax';'Tmean';'Ts'};
unn={'m';'m';'1/s';'m';'m';'m';'m';'m';'1/s';'1/s'};
snam={'sea level';'Significant wave height-Hm0';'Peak wave period-Tp';'m0';'Significant wave height-Hs';'Average wave height-Hm';'10% exceedence wave height value-H_10';'Maximum wave height-H_max';'Average period-T_mean';'Significant period-T_s'};
nc_create_empty(filename)
%by using the command length(lat_variable) it shows an error!
nc_add_dimension(filename,'records',npoints)

for i=1:length(nam)
    
    varstruct.Name=nam{i};
    varstruct.Nctype=nc_double;
    varstruct.Dimension={'records'};
    nc_addvar(filename,varstruct)
    nc_attput(filename,nam{i},'units',unn{i})
    nc_attput(filename, nam{i}, 'standard_name', snam{i})
    
end

for i=1:length(nam)

    nc_varput(filename, nam{i}, eval(['infinity.' infinity.names{i}]))
    
end

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

nc_dump(filename)





