%  oetsettings 

%% Initialize

   outputfile = 'http://dtvirt5.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/sedimentatlas_waddenzee/korrel.nc';
   outputfile = 'http://opendap.deltares.nl:8080/thredds/dodsC/opendap/rijkswaterstaat/sedimentatlas_waddenzee/korrel.nc';
   outputfile = '..\cache\korrel.nc';

%% Check contents

   nc_dump(outputfile);

%% Load precise (kwartet)

   [D,M] = nc2struct(outputfile);

%%
j = 1;
sedimentatlas_plot_diameter(D.diameter,D.phi(j,:),D.cumphi(j,:),'t.png')
%% Calculate derived parameters
% * Rijkswaterstaat, 2004. Zwarts, L. (2004). Bodemgesteldheid en mechanische kokkelvisserij in de
%   Waddenzee. Rijkswaterstaat Waterdienst RIZA report 2004.028. Available
%   from: http://www.rijkswaterstaat.nl (in Dutch).

   D.pmud16_from_16 = 0.2988.*sum(D.phi(:,17:end),2)'; % mud if D < 16 um
   D.pmud16_from_63 = 0.1879.*sum(D.phi(:,13:end),2)'; % mud if D < 63 um
   M.pmud16_from_16.units = M.phi.units
   
%% Plot   
   clf
   caxis            (log10([.1 50]))
   scatter          (D.lon,D.lat,20,log10(D.pmud16_from_16),'filled')
   [ax,h]=colorbarwithtitle('percentage mud in bed');
   set              (ax,'YTick',log10([.1 .2 .5 1 2 5 10 20 50]))
   set(ax,'YTickLabel',{'.1','.2','.5','1','2','5','10','20','50','100'})   
   axislat          (52)
   tickmap          ('ll')
   grid on
   print2screensize ('sediment_atlas_waddenzee_EVAII_mud_content')
   
%% Plot in Google Earth

    description = ['<hr> Sediment Atlas WaddenZee: size distribution curves from 7502 sediment surface grabs.',...
     'Mud content is derived from sediment distribution curves usingh EVA II formulations.',...
     'This is a proof-of-concept demo of how scatter point could'...
     'be presented in Google Earth for easy navigation in time space. '...
     'The data in this proof-of-concept demo is a cache that is updated every now and then.'...
     'For data and meta-data please visit the original source: <a href="http://www.waddenzee.nl/Sedimentatlas.729.0.html">www.waddenzee.nl</a>.'....
     'or ask the publisher Rojkswaterstaat <a href="http://www.helpdeskwater.nl">www.helpdeskwater.nl</a>.'...
     '<hr><table bgcolor="#333333" cellpadding="3" cellspacing="1"><tbody><tr><td colspan="2" bgcolor="#666666"><div style="color:#FFFFFF;">Credits:</div></td></tr>',...
     '<tr><td    bgcolor="#FFFFFF">data source     </td><td bgcolor="#FFFFFF">Rijkswaterstaat</td></tr>',...
     '<tr><td    bgcolor="#FFFFFF">data source url </td><td bgcolor="#FFFFFF">http://www.waddenzee.nl</td></tr>',...
     '<tr><td    bgcolor="#FFFFFF">data provider   </td><td bgcolor="#FFFFFF">OpenEarth</td>',...
     '<tr><td    bgcolor="#FFFFFF">data distributor</td><td bgcolor="#FFFFFF">http://www.OpenEarth.eu</td>',...
     '</tr></tbody></table><hr>',...
     '<p><font size="1" face="courier" color="gray">$HeadURL$ $Id$</font></p>'];


   KMLscatter(D.lat,D.lon,log10(D.pmud16_from_16),...
          'name',cellstr((num2str(D.pmud16_from_16'))),...
      'fileName','sediment_atlas_waddenzee_EVAII_mud_content.kml',...
   'description',description,...
       'kmlName','Sediment Atlas WaddenZee: mud content',...
  'CBcolorTitle','mud content [%]',...
   'markerAlpha',.8,...
     'CBcolorMap'      ,@(m) jet(m),...
     'CBcolorSteps'    ,length(jet),...
     'CBcLim'          ,log10([.1 50]),...
     'CBcolorTick'     ,log10([.1 .2 .5 1 2 5 10 20 50]),...
     'CBcolorTickLabel',{'.1','.2','.5','1','2','5','10','20','50'},...
     'CBcolorTitle'    ,'mud fraction [%]'); % white letters with black halo)
    
%% test for log-scales on colorbar

  KMLcolorbar('CBfileName','sediment_atlas_waddenzee_EVAII_mud_content_colorbar.kml',...
     'CBcolorMap'      ,@(m) jet(m),...
     'CBcolorSteps'    ,length(jet),...
     'CBcLim'          ,log10([.1 50]),...
     'CBcolorTick'     ,log10([.1 .2 .5 1 2 5 10 20 50]),...
     'CBcolorTickLabel',{'.1','.2','.5','1','2','5','10','20','50'},...
     'CBcolorTitle'    ,'mud fraction [%]',...
     'CBtemplateHor'   ,[],'CBtemplateVer',[],...
     'CBthickness'     ,.05,'CBalignmargin',0.02,...
     'CBfontrgb'       ,[1 1 1],'CBbgcolor',[0 0 0],'CBtitlergb',[1 1 1],'CBframergb',[1 1 1]); % white letters with black halo
     



