function [vDate, vLevel] = readwaterlevels(strPath, strInFile, strZRef);
% function [vDate, vLevel] = readwaterlevels(strPath, strInFile, strZRef);
%
% Reads raw data with water level time series 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
%           -strZRef: Reference system used for the water levels (i.e. NAP
%            (used in The Netherlands) or TAW (used in Belgium).
%            TAW = 2.303 + NAP
%
% #OUTPUTS: -vDate: vector (n rowsx 1 col) with the dates in Serial Date Number Format 
%           -vLevel: vector (n rowsx 1 col) with the water levels in meters 
%           and in TAW
%
% #REMARKS: The format of the raw data ASCII file is:
%           - Lines of comments starting with % sign
%           - First column date: YYYYMMDD.HHmmSS
%           - Second column: water level in meters with respect to NAP or
%           TAW. 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:

% Conversion factor from NAP to TAW
nNAP2TAW = 2.303;

% Read water levels file from IMDC data
path = fullfile(strPath, strInFile);
values = load(path);
vDate = datenum(num2str(values(:,1),'%15.4f'), 'yyyymmdd.HHMM');
if (strcmpi(strZRef,'NAP'))
    vLevel = values(:,2) + nNAP2TAW;
else
    vLevel = values(:,2);
end
