function [ok,info,varargout] = kmlCreateAllCoastlineCharts(varargin)
%kmlCreateAllCoastlineCharts  create a KML file for all the charts with MKL, TKL and BKL coastlines 
%
%   The charts for all the sections and their jarkus transects are gathered 
%   in a kml file. It is checked whether the charts are available.
%
%   Syntax:
%   [ok,info,varargout] = kmlCreateAllCoastlineCharts(varargin)
%
%   Input: 
%    varargin = key/value pair(s). Two options are available.
%               keyword = 'kml'  : the filedescriptor of the kml file
%                                    (extension is automatically set to kml).
%                       = 'jpg'  : the path where the jpg chart files
%                                    must be found.
%                       = 'icon' : the filedescriptor of the mask to be
%                                    used to point out where charts can be found.
%    load CoastLineInfo
%      a save must have been done of various data in "CoastLineInfo"
%      charts  : the coast line values for the transects and the years
%      years   : the years with possible data for the coast lines
%      secTrans: the id for the section and the transect = section*10^6 +
%                transect
%      LonLat  : the Lon/lat coordinates for the given transects in secTrans
%      sections: the section numbers and the related section names
%
%   Output:
%      ok        = 0 no correct computation, the function stopped
%                  1 no problems
%      info      = info message
%      varargout = possible section or transsection numbers when the ones
%                  to be used are not found.
%
%   Example
%   plotAllCharts
%
%   See also 

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 <COMPANY>
%       Lou Verhage
%
%       <lou.verhage@deltares.nl>	
%
%       <ADDRESS>
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library 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
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://OpenEarth.nl">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and 
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute 
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 22 Mar 2010
% Created with Matlab version: 7.8.0.347 (R2009a)

% $Id: kmlCreateAllCoastlineCharts.m 4926 2011-04-18 13:00:40Z verhage $
% $Date: 2011-04-18 15:00:40 +0200 (Mon, 18 Apr 2011) $
% $Author: verhage $
% $Revision: 4926 $
% $HeadURL: https://svn.oss.deltares.nl/repos/openearthrawdata/trunk/rijkswaterstaat/kustlijnkaartenboek/scripts/kmlCreateAllCoastlineCharts.m $
% $Keywords: $

%% initialize, get the results from jarkus_GEChart.m
filevariables = {'sections'};
load('CoastLineInfo.mat', filevariables{:});

OPT.kml  = 'testtest.kml';
OPT.jpg  = '';
OPT.icon = '';
OPT = setProperty(OPT,varargin{:});
%% plot the charts for the sections
nrSections = sections.number;
clear filevariables{:}
ok   = true;
info = '';
if nargout > 2
    varargout{1} = [];
end

%% create the kml file
   fName = OPT.kml;
   [ok,info,fid] = kmlWriteHeader(fName,'icon',OPT.icon);
   if ~ok, return, end
%% write the charts information to the kml file
for sec = 1 : length(nrSections)
    waitText = ['section nr=' num2str(sec) '/' num2str(length(nrSections))];
    if sec == 14
        cc=sec;
    end
    [ok,info,tr] = kmlCreateSectionCoastlineCharts(nrSections{sec},'kml',fid, ...
                  'mfile',mfilename,'waittext',waitText,'jpg',OPT.jpg);
    if ~ok
        if nargout > 2, varargout{1} = tr; end
        return
    end
end

% write the closing lines
kmlClose(fid);


