%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2009-2012, Centre for Advanced Internet Architectures
% Swinburne University of Technology, Melbourne, Australia
% (CRICOS number 00111D).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% kmlset_shapefile.m
% A helper script for Matlab to convert multiple .kml files into .shp files,
% to be used by Matlab in conjunction with the Mapping Toolbox for displaying
% geolocation information.
% 
% This script needs the "kml_shapefile.m" Matlab script found at
% http://www.mathworks.com/matlabcentral/fileexchange/25104-kml-matlab-shapefile-conversion
% 
% The input .kml files need to be generated by the "per_15min_kml.py" script.
% 
% Unfortunately the kml_shapefile.m script does not convert .kml files without placemark 
% tags, but stops with an error. If such .kml files exist (as could happen if there were no
% probes for that period), the corresponding empty .shp files need to be created manually.
%
% This file is part of the animation_scripts.tar.gz tarball that can be obtained at:
% http://caia.swin.edu.au/sting/tools/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This software was developed by Mattia Rossi <mrossi@swin.edu.au>
%
% This software has been made possible in part by a grant from
% APNIC Pty. Ltd., Canberra, Australia. http://www.apnic.net/
%
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions
% are met:
% 1. Redistributions of source code must retain the above copyright
%    notice, this list of conditions and the following disclaimer.
% 2. Redistributions in binary form must reproduce the above copyright
%    notice, this list of conditions and the following disclaimer in the
%    documentation and/or other materials provided with the distribution.
% 3. The names of the authors, the "Centre for Advanced Internet Architecture"
%    and "Swinburne University of Technology" may not be used to endorse
%    or promote products derived from this software without specific
%    prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND
% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
% OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
% SUCH DAMAGE.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function kmlset_shapefile(filename)
d=dir('*.kml');
s=0;
for i=1:numel(d)
    kmlfile=d(i);
    shpfile=kmlfile.name;
    if s==0
        if strcmp(shpfile,filename)==1
            s=1;
        end
    end
    if s==1
        shpfile(end-3:end)='.shp';
        kml_shapefile(kmlfile.name,shpfile);
    end
end