function [vDate, vH33, vGTZ, vHmO, vTPE, vTmO2] = readwaves(strPath, strInFile, nCols);
% function [vDate, vH33, vGTZ, vHmO, vTPE, vTmO2] = readwaves(strPath, strInFile, nCols);
%
% Reads raw data with time series of wave information for periods with significant 
% storms in the Belgiam coast.
% The data has been prepared for the MICORE project: www.micore.eu
% Raw data is in ASCII files and this function is called by another
% functions to convert these raw data files into netCDF format.
%
% #INPUTS:  -strPath: string with the directory path where the raw data is
%            saved. Relative paths are allowed, e.g. '../raw/19931115/'.
%            Include the / sign at the end of the string.
%           -strInFile: string with the name of the input ASCII file.
%            Usually it is a file with 6 columns (date, H33, GTZ, HmO, TPE,
%            TmO2) (date, Hm0, TPE, Tm02, RLF, RHF)???????
%            but some files have only 4 columns (date, Hm0, TPE, Tm02) or 5
%            columns (date, H33, GTZ, TPE, Tm02) (date, H33, GTZ, Hm0,
%            Tm02)??????????????? 
%           -nCols: total number of columns in the file, taking into
%            account the first column with the date.
%
% #OUTPUTS: -vDate: vector (n rowsx 1 col) with the dates in Serial Date Number Format 
%           -vH33: vector (n rowsx 1 col) with the Significant wave height of the 1/3 of the highest waves in m
%           -vGTZ: vector (n rowsx 1 col) with the Average wave period in s
%           -vHmO: vector (n rowsx 1 col) with the Significant wave height from the spectrum in m
%           -vTPE: vector (n rowsx 1 col) with the Peak period, period with the highest energy in s
%           -vTmO2: vector (n rowsx 1 col) with the Wave period of the spectrum of momentum m0 and m2 Tm02=sqrt(m0/m2) in s
%
% #REMARKS: The format of the raw data ASCII file is:
%           - Lines of comments starting with % sign
%           - 1st column date: YYYYMMDD.HHmmSS
%           - 2nd to 9th column: magnitudes. Number of columns may vary. 
%             Order of columns is not the same. Nodata values are -999.00
%

% International Marine and Dredging Consultants, IMDC
% www.imdc.be
% Antwerp, Belgium
%
% Written by: Fernando Toro, Piet Haerens
%             fto@imdc.be
% Date: July 2009
% Modified:
% Date:

% Read water levels file from IMDC data
path = fullfile(strPath, strInFile);
if (nCols == 4)
    data = load(path);
    values = [data(:,1) -999*ones(size(data,1),1) -999*ones(size(data,1),1) data(:,2) data(:,3)  data(:,4)];
elseif (nCols == 5)
    data = load(path);
    values = [data(:,1) data(:,2) -999*ones(size(data,1),1)  data(:,3) data(:,4) data(:,5)];
else
    data = load(path);
    values = [data(:,1) data(:,2) data(:,3) data(:,4) data(:,5) data(:,6)];
end
vDate = datenum(num2str(values(:,1),'%15.4f'), 'yyyymmdd.HHMM');
vH33 = values(:,2);
vGTZ = values(:,3);
vHmO = values(:,4);
vTPE = values(:,5);
vTmO2 = values(:,6);
