clc;cc
OPT.ncdir  = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/ferrybox/';
OPT.ncdir  = 'd:\opendap\rijkswaterstaat\ferrybox\';
OPT.kmldir = 'd:\kml\rijkswaterstaat\ferrybox\';
ncfile = 'ferrybox_salinity.nc';

[D,M]      = nc2struct(fullfile(OPT.ncdir,ncfile));

%%

years = unique(year(D.datenum));
kmlnames = {};

for yyyy=years'
    for m=1:12
        
        mm = num2str(m,'%0.2d');
        mask = find(year(D.datenum)==yyyy & month(D.datenum)==m);
        
        if length(mask)>1
            
            disp(num2str([yyyy*100+m]))
            kmlname = fullfile(OPT.kmldir,[filenameext(ncfile),'_',num2str(yyyy),'-',mm,'.kmz']);

            pngNames = KMLscatter(D.lat(mask),D.lon(mask),D.salinity(mask),...
                    'name',cellstr(num2str(make1D(D.salinity(mask)),'%0.1f')),...
                'fileName',kmlname,...
                 'kmlName',[M.salinity.standard_name,' ',num2str(yyyy),'_',mm],...
                  'timeIn',D.datenum(mask),...
                 'timeOut',D.datenum(mask([2:end end])),...
            'CBcolorTitle',mktex([M.salinity.standard_name,' [',M.salinity.units,']']),...
                  'CBcLim',M.salinity.actual_range);
              
         
        end
    end         
end


