function oct_nc_add_tides(fname,Ntides,start_tide_mjd,components)
%
%  Further Information:  
%  http://www.croco-ocean.org
%  
%  This file is part of CROCOTOOLS
%
%  CROCOTOOLS is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published
%  by the Free Software Foundation; either version 2 of the License,
%  or (at your option) any later version.
%
%  CROCOTOOLS is distributed in the hope that it will be useful, but
%  WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with this program; if not, write to the Free Software
%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
%  MA  02111-1307  USA
%
%  Copyright (c) 2001-2006 by Patrick Marchesiello
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ncid = netcdf.open(fname, 'NC_WRITE');
%%redef(nc);		% for Octave compatibility
%
%  Add dimension
%
did_tide_period = netcdf.defDim(ncid, 'tide_period', Ntides);
%
%  Add variables and attributes
%
vid_tide_period = netcdf.defVar(ncid, 'tide_period', 'NC_DOUBLE', did_tide_period);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_period'), 'long_name', 'Tide angular period');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_period'), 'units', 'Hours');

vid_tide_Ephase = netcdf.defVar(ncid, 'tide_Ephase', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Ephase'), 'long_name', 'Tidal elevation phase angle');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Ephase'), 'units', 'Degrees');

vid_tide_Eamp = netcdf.defVar(ncid, 'tide_Eamp', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Eamp'), 'long_name', 'Tidal elevation amplitude');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Eamp'), 'units', 'Meter');

vid_tide_Cmin = netcdf.defVar(ncid, 'tide_Cmin', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cmin'), 'long_name', 'Tidal current oct_ellipse semi-minor axis');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cmin'), 'units', 'Meter second-1');

vid_tide_Cmax = netcdf.defVar(ncid, 'tide_Cmax', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cmax'), 'long_name', 'Tidal current, oct_ellipse semi-major axis');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cmax'), 'units', 'Meter second-1');

vid_tide_Cangle = netcdf.defVar(ncid, 'tide_Cangle', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cangle'), 'long_name', 'Tidal current inclination angle');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cangle'), 'units', 'Degrees between semi-major axis and East');

vid_tide_Cphase = netcdf.defVar(ncid, 'tide_Cphase', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cphase'), 'long_name', 'Tidal current phase angle');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Cphase'), 'units', 'Degrees');

vid_tide_Pamp = netcdf.defVar(ncid, 'tide_Pamp', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Pamp'), 'long_name', 'Tidal potential amplitude');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Pamp'), 'units', 'Meter');

vid_tide_Pphase = netcdf.defVar(ncid, 'tide_Pphase', 'NC_DOUBLE', [did_xi_rho, did_eta_rho, did_tide_period]);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Pphase'), 'long_name', 'Tidal potential phase angle');
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.inqVarID(ncid, 'tide_Pphase'), 'units', 'Degrees');

% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'date', date);
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'start_tide_mjd', start_tide_mjd);
% [conv] línea ncchar duplicada omitida
netcdf.putAtt(ncid, netcdf.getConstant('NC_GLOBAL'), 'components', components);

netcdf.close(ncid);
