clear all
close all

praw=fullfile('..','Raw');
pconv=fullfile('..','Processed');

load(fullfile(praw,'baseline_11_08'))

nx1=400;
ny1=300;

[x2,y2] = convertCoordinates(bathy(:,1),bathy(:,2),'CS1.code',27493,'CS2.code',4326);

[xx,yy,zz]=data2grid2(x2,y2,bathy(:,3),nx1,ny1,[],[]);

outputfile=fullfile(pconv,'Faro_baseline_11_08.nc');

nc_create_empty(outputfile);
nc_add_dimension(outputfile, 'long', ny1);
nc_add_dimension(outputfile, 'lat', nx1);
% nc_add_dimension(outputfile, 'time', npr);

longVariable = struct(...
    'Name', 'lon', ...
    'Nctype', 'float', ...
    'Dimension', {{'long', 'lat'}}, ...
    'Attribute', struct('Name', 'unit', 'Value', 'degree_west') ...
    );

% longvariable.Attribute(end+1)= struct('Name','standard_name'
nc_addvar(outputfile, longVariable);

% jhgjgasdf

latVariable = struct(...
    'Name', 'lat', ...
    'Nctype', 'float', ...
    'Dimension', {{'long', 'lat'}}, ...
    'Attribute', struct('Name', 'unit', 'Value', 'degree_north') ...
    );
nc_addvar(outputfile, latVariable);

% timeVariable = struct(...
%     'Name', 'year', ...
%     'Nctype', 'float', ...
%     'Dimension', {{'time'}}, ...
%     'Attribute', struct('Name', 'unit', 'Value', 'year') ...
%     );
% nc_addvar(outputfile, timeVariable);
heightVariable = struct(...
    'Name', 'height', ...
    'Nctype', 'float', ...
    'Dimension', {{'long', 'lat'}}, ...
    'Attribute', struct('Name', 'unit', 'Value', 'm') ...
    );
nc_addvar(outputfile, heightVariable);

nc_varput(outputfile, 'height', zz)
% nc_varput(outputfile, 'year', sdate)
nc_varput(outputfile, 'lon', xx)
nc_varput(outputfile, 'lat', yy)

% surface(nc_varget(outputfile, 'height')')

nc_dump(outputfile)
