function tide2netcdf(output)

% Transform the data cube (made by add_data.m) into a netCDF 
%   file format. 

A = importdata('C:\MICORE\Tide\Cadiz_Tide_Data\Cadiz_SL_cor.txt',' ',0);

DATES_F= char(A.textdata(:,2));
HOURS_F= char(A.textdata(:,3));
% datain = A.data;
YY_F = str2num(DATES_F(:,1:4));
MM_F = str2num(DATES_F(:,6:7));
DD_F = str2num(DATES_F(:,9:10));
HH_F = str2num(HOURS_F(:,1:2));
MN_F = str2num(HOURS_F(:,4:5));
SS_F = str2num(HOURS_F(:,7:8));

DATE = [YY_F MM_F DD_F HH_F MN_F SS_F];

elev = A.data;

[i,j]=size(DATE);


% CreatenetCDF
nc_create_empty(output)

%Add attributes 

   nc_attput(output, nc_global, 'title'           , 'Cadiz Tidal Data');
   nc_attput(output, nc_global, 'institution'     , 'UCA');
   nc_attput(output, nc_global, 'source'          , 'Spanish Instritude of Oceanography IEO');
   nc_attput(output, nc_global, 'email'           , 'haris.plomaritis@uca.es , MJesus.garcia@md.ieo.es');
   nc_attput(output, nc_global, 'Conventions'     , 'CF-1.4');
   nc_attput(output, nc_global, 'Location'        , '-6.2867, 36.5400');


% Add dimensions 


nc_add_dimension(output, 'Time', i)
nc_adddim(output, 'datelength', j)


% Add variables

DateVariable = struct(...
     'Name', 'DATE', ...
     'Nctype', 'double', ...
     'Dimension', {{'Time','datelength'}}, ...
     'Attribute', struct('Name', 'Date_and_Time_GMT', 'Value', '[YEAR MONTH DAY HOURS MINUTES SECONDS]') ...
     );

nc_addvar(output, DateVariable);

WLVariable = struct(...
    'Name', 'WL', ...
    'Nctype', 'float', ...
    'Dimension', {{'Time'}}, ...
    'Attribute', struct('Name', 'Sea_Surface_Height', 'Value', 'metre') ...
    );
nc_addvar(output, WLVariable);

% Store Variable

nc_varput(output, 'DATE', DATE)
nc_varput(output, 'WL', elev)
