%The files contain some coastal and marine data in UK.
% 
% There were tow different types of files, include different data sets.
% The files contain information 
   %7.3011e+05  7.8303e-01  5.7308e+00  9.0436e+01  3.5340e+00  4.7439e+00
   %7.3011e+05  7.2437e-01  5.7308e+00  9.1143e+01  3.5024e+00  4.4612e+00
   %7.3011e+05  6.6146e-01  4.7362e+00  9.2292e+01  3.4580e+00  4.2692e+00
   %......
 % The first column is the day number, second column wave height(m), third 
 % third column is peak wave period(s), the forth is wave direction(deg),
 % the fifth column shows TM02 wave period(s), and the last column contains
 % information on mean period(s).
 % This information show occurence of a big hurricane on 27 dec. 1998. 
 % cbcNews.ca web page was checked for evaluating the correction of the
 % data.
 % The other files look like:
 %7.3011200e+05   2.7279670e+00   5.6827210e-02   2.9919720e-01
 %7.3011202e+05   3.1396942e+00   3.4829278e-02   2.8218862e-01
 %....
 % the first column shows the day number, the second column is total water
 % elevation(m), the third column is u-velocity(m/s) and the forth one shows
 % v-velocity(m/s).
javaaddpath('C:\Users\mahtab\TU Delft\checkout\OpenEarthTools\io\nctools\toolsUI-2.2.22.jar')
 

datadir='../Raw/';
files=dir([datadir '*.txt']);
filename={files.name};

% MAIN PROGRAM
  % the "htdp" files are the files containing 6 variables as been explaied
  % in the previous lines.
  % the "zudv" files are the files with four variables.
for i=1:length(files)
    text=filename{i};
  % in this section an array with the dimension of 1x6 is defined for the 
  % "htdp" files.
    if (~isempty(findstr(text,'htdP1')))
       htd = readhtd([datadir filename{i}]);
       htd2netcf([filename{i} '.nc'], htd)
    elseif (~isempty(findstr(text,'zuvP1')))
       zuv = readzuv([datadir filename{i}]);
       zuv2netcf([filename{i} '.nc'], zuv)
    end

end







