function bathy2netcdf(infile, output)

% Transform the bathy file (made by raw2bathy.m) into a netCDF 
%   file format. 

comload = ['load ' infile];  %(laod the .mat data file e.g. SITE_bathy_fw#.mat)
eval(comload)
[i,j]=size(bathy);

if infile(1:4)=='cort'
    title ='Cortadura-Cadiz';
%   [date]=textread('Cortadura_bathy_dates1.txt' ,'%10c');
    disp('Enter date of data collection in dd/mm/yyyy format')
    DATE=input('date=','s');
elseif infile(1:4)=='camp'
    title ='Camposoto-Cadiz';
%    [date]=textread('Camposoto_bathy_dates.txt' ,'%10c');
    disp('Enter date of data collection in dd/mm/yyyy format')
    DATE=input('date=');
else
    title =' ';
    disp('Enter date of data collection in dd/mm/yyyy format')
    DATE=input('date=');
end
% CreatenetCDF
nc_create_empty(output)

%Add attributes 
nc_attput(output, nc_global, 'title'           , title);
nc_attput(output, nc_global, 'institution'     , 'UCA');
nc_attput(output, nc_global, 'source'          , 'UCA');
nc_attput(output, nc_global, 'email'           , 'javier.benavanter@uca.es, haris.plomaritis@uca.es');
nc_attput(output, nc_global, 'Conventions'     , 'CF-1.4');
nc_attput(output, nc_global, 'comment'         , ['Data collected on '  DATE])
nc_attput(output, nc_global, 'Vertical_Datum'  , 'Cadiz Local Hydrographic Zero (+42.2538 above elipsoide)');
nc_attput(output, nc_global, 'spatial_ref'     ,  ['PROJCS["ED50 / UTM zone 29N"',...
      'GEOGCS["ED50"',...
      '  DATUM["European_Datum_1950"',...
      '      SPHEROID["International 1924",6378388,297',...
      '          AUTHORITY["EPSG","7022"]]',...
      '      AUTHORITY["EPSG","6230"]]',...
      '  PRIMEM["Greenwich",0',...
      '      AUTHORITY["EPSG","8901"]]',...
      '  UNIT["degree",0.01745329251994328',...
      '      AUTHORITY["EPSG","9122"]]',...
      '  AUTHORITY["EPSG","4230"]]',...
      '  UNIT["metre",1',...
      '  AUTHORITY["EPSG","9001"]]',...
      ' PROJECTION["Transverse_Mercator"]',...
      ' PARAMETER["latitude_of_origin",0]',...
      ' PARAMETER["central_meridian",-9]',...
      ' PARAMETER["scale_factor",0.9996]',...
      ' PARAMETER["false_easting",500000]',...
      ' PARAMETER["false_northing",0]',...
      ' AUTHORITY["EPSG","23029"]',...
      ' AXIS["Easting",EAST]',...
      ' AXIS["Northing",NORTH]]']);


% Add dimensions 
nc_add_dimension(output, 'record', i)

% Add variables
varstruct.Name='Easting';
varstruct.Nctype=nc_double;
varstruct.Dimension={'record'};
nc_addvar(output,varstruct)
nc_attput(output,'Easting','units','m')
nc_attput(output,'Easting','long_name','projection_x_coordinate')
nc_attput(output,'Easting','standard_name', 'projection_x_coordinate')

varstruct.Name='Northing';
varstruct.Nctype=nc_double;
varstruct.Dimension={'record'};
nc_addvar(output,varstruct)
nc_attput(output,'Northing','units','m')
nc_attput(output,'Northing','long_name','projection_y_coordinate')
nc_attput(output,'Northing','standard_name', 'projection_y_coordinate')

varstruct.Name='depth';
varstruct.Nctype=nc_double;
varstruct.Dimension={'record'};
nc_addvar(output,varstruct)
nc_attput(output,'depth','units','m')
nc_attput(output,'depth','long_name','depth below Datum')
nc_attput(output,'depth','standard_name', 'depth')

% Store Variable

nc_varput(output, 'Easting', bathy(:,1))
nc_varput(output, 'Northing', bathy(:,2))
nc_varput(output, 'depth', bathy(:,3))

