function A = odv2meta
%odv2meta   crawl a local set of ODV files to get meta-data (TEST BETA)
%
% get meta-info from all CTDCAST files in a user-defined directory one by one.
%
%See web : <a href="http://odv.awi.de">odv.awi.de</a>
%See also: OceanDataView

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL
% $Keywords:

OPT.directory = [fileparts(mfilename('fullpath')),filesep,'usergd30d98-data_centre630-260409_result\'];
OPT.prefix    = 'result_CTDCAST';
OPT.mask      = '*.txt';
OPT.pause     = 0;

%% File loop

   OPT.files     = dir([OPT.directory,filesep,OPT.prefix,'*',OPT.mask]);
   
   clear A
   
   A.filename    = [];
   A.lon         = repmat(nan,[1 length(OPT.files)]); %Latitude 1","Latitude 2","Longitude 1","Longitude 2
   A.lat         = repmat(nan,[1 length(OPT.files)]);
   A.nt          = repmat(nan,[1 length(OPT.files)]);
   A.datenum_min = repmat(nan,[1 length(OPT.files)]);% "Start date","Start time","End date","End time"
   A.datenum_max = repmat(nan,[1 length(OPT.files)]);

for ifile=1:length(OPT.files)
   
   OPT.filename = OPT.files(ifile).name;
	
   disp(['Processing ',num2str(ifile),'/',num2str(length(OPT.files)),': ',filename(OPT.filename)])

%% 0 Read raw data

   D         = odvread([OPT.directory,filesep,OPT.filename]);
   
   A.filename   {ifile} =      OPT.filename;
   A.lon        (ifile) =        D.lon;
   A.lat        (ifile) =        D.lat;
   A.nt         (ifile) = length(D.data.datenum);
   A.datenum_min(ifile) =    min(D.data.datenum);
   A.datenum_max(ifile) =    max(D.data.datenum);
   A.bot_depth  (ifile) =        D.bot_depth;
   A.station    (ifile) =        D.;
   A.cruise     (ifile) =        D.;
   
   
   if OPT.pause
   pausedisp
   end
       
end % ifile       

%% Coastline of world & North Sea

   L(1).lon = nc_varget('http://opendap.deltares.nl:8080/thredds/dodsC/opendap/noaa/gshhs/gshhs_c.nc','lon');
   L(1).lat = nc_varget('http://opendap.deltares.nl:8080/thredds/dodsC/opendap/noaa/gshhs/gshhs_c.nc','lat');

   L(2).lon = nc_varget('http://opendap.deltares.nl:8080/thredds/dodsC/opendap/deltares/landboundaries/northsea.nc','lon');
   L(2).lat = nc_varget('http://opendap.deltares.nl:8080/thredds/dodsC/opendap/deltares/landboundaries/northsea.nc','lat');

%% Plot distribution in space

   figure('name','ODV spatial distribution')
   
   plot      (A.lon,A.lat,'.')
   OPT.cticks = 10.^[0:1:2];
   caxis     (log10([OPT.cticks([1 end])]))
   plotc     (A.lon,A.lat,log10(A.nt))
   [ax,h]=colorbarwithtitle('n [#]',log10(OPT.cticks));
   set(ax,'yticklabel',num2str(OPT.cticks'))
   hold on
   plot      (L(1).lon,L(1).lat,'color',[.5 .5 .5])
   plot      (L(2).lon,L(2).lat,'k')
   axislat   (52)
   axis([min(A.lon) max(A.lon) min(A.lat) max(A.lat)])%axis      ([-5 10 48 60])
   grid       on
   tickmap   ('ll')
   box        on
   print2screensize([OPT.directory,filesep,'inventory_space.png'])

%% Plot distribution in time

   figure('name','ODV temporal distribution')
   
   t = A.datenum_min;t(t==0)=nan;% remove 0's from datenum
   H.edges = floor(min(t)):dt:ceil(max(t));
   [H.n,H.bin]=histc(A.datenum_min,H.edges)
   bar       (H.edges,H.n,'histc')
   datetick  ('x')
   grid       on
   ylabel    ('n[#]')
   title     (['# observsations per ',dt,' days'])
   print2screensize([OPT.directory,filesep,'inventory_time.png'])

%% Save

   units.filename    = 'string';
   units.lon         = 'degrees_east';
   units.lat         = 'degrees_north';
   units.nt          = '#';
   units.datenum_min = 'days since 0000 00:00';
   units.datenum_max = 'days since 0000 00:00';
   units.bot_depth   = 'm';
   
   A.filename = char(A.filename);

   header = {'Generated by $Id$',...
             ['This file has been created with struct2xls.m > xlswrite.m @ ',datestr(now)]};

   struct2xls([OPT.directory,filesep,'inventory.xls'],A,'units',units,'header',header);

