
%% specify

   OPT.make_nc        = 0;
   OPT.load_raw       = 'F:\checkouts\OpenEarthRawData\rijkswaterstaat\kustlidar\raw\'; % choose from 3 options
   OPT.save_nc        = 'F:\opendap\thredds\rijkswaterstaat\kustlidar\';
   OPT.copy_nc        = '\\opendap\opendap\rijkswaterstaat\kustlidar\'; % option
   OPT.make_catalog   = 0;

   OPT.make_kml       = 1; % 2d fast
   OPT.make_kml3d     = 0; % 3d slow
   OPT.load_nc        = OPT.save_nc;
   OPT.base_nc        = 'F:\opendap\thredds\';
   OPT.save_kml       = 'F:\_KML\rijkswaterstaat\kustlidar\'; % for writing
   OPT.copy_kml       = ''; % option

   OPT.make_overview  = 0;
   OPT.serviceBaseURL = 'http://opendap.deltares.nl/thredds/';
   OPT.serviceBase    = 'dodsC/opendap/'; % for THREDDS opendap
   OPT.link_kml       = 'http://dtvirt5.deltares.nl/kml/'; %{'http://dtvirt5.deltares.nl/kml/'   ,'F:\_KML\'                            };
   OPT.link_nc        = {OPT.serviceBaseURL                  ,OPT.base_nc                           };
   OPT.link_service   = {OPT.serviceBase                     ,''                                    };
   OPT.link_name      = {'kustlidar_overview.kml'            ,'kustlidar_overview_local_machine.kml'};
   
   % full url: OPT.link_nc + OPT.link_service + OPT.path
   
   OPT.path           = 'rijkswaterstaat/kustlidar/'

%% generate netCDF files

   if OPT.make_nc
      % TO DO pass save_nc as command line options to python
      system(['python ',fullfile(fileparts(mfilename('fullpath')),'scrips','kustlidar_raw2nc.py')])  % ! rename scrips
   end
   
   if 0 % OK
   if OPT.copy2server
   end
   end

%% generate catalog.nc

   if OPT.make_catalog
   nc_cf_opendap2catalog(OPT.load_nc,...
                         'save',1,...
                   'urlPathFcn',@(s) strrep(s,OPT.base_nc,path2os([OPT.serviceBaseURL,OPT.serviceBase,OPT.path],'linux')));
   end

%% generate network-linked-tiled-png KML file set

   if OPT.make_kml
      % TO DO pass options
      run(fullfile(fileparts(mfilename('fullpath')),'scrips','kustlidar2kml.m'))  % ! rename directory scrips
   end

%% generate 3D KML renderings tile

   if OPT.make_kml3d
      nc_cf_gridset2kml(     'load_nc',OPT.load_nc,...
                             'datestr','YYYY-mm',...
                            'save_kml',OPT.save_kml)
   end
   % copy kml 2 server
   
%% generate KML overview files with links to netCDF and 3D kml tiles

   nc_cf_gridset_overview('fileName',[OPT.save_kml filesep 'kustlidar_overview.kml'],...
                  'link2prerendered',OPT.make_kml3d,...
                          'load_kml',OPT.save_kml,...
                        'kmlPathFcn',@(s) strrep(s,OPT.save_kml,OPT.link_kml),...
                           'datestr','YYYY-mm',...
                            'load_nc',OPT.load_nc,...
                        'urlPathFcn',@(s) path2os(strrep(s,'url'       ,[OPT.serviceBaseURL,OPT.serviceBase,     ]),'http'),...
                        'urlPathFcn',@(s) path2os(strrep(s,OPT.base_nc ,[OPT.serviceBaseURL,OPT.serviceBase,     ]),'http'),...
                        'ftpPathFcn',@(s) path2os(strrep(s,'url'       ,[OPT.serviceBaseURL,'fileServer/opendap/']),'http'),...
                        'ftpPathFcn',@(s) path2os(strrep(s,OPT.base_nc ,[OPT.serviceBaseURL,'fileServer/opendap/']),'http'),...
                       'description','<a href="http://www.rijkswaterstaat.nl">Rijkswaterstaat</a> kusthoogte provided by <a href="http://www.openearth.nl"> OpenEarthTools</a>');
