function survey = extract_surveys(year,month,type)
%%% This function read the NETCDF file vlugtenburg.nc
%%% Single and combined Jetski and Walking Surveys can be extracted
%%% If no line is specified all lines are exported.
%%% one survey per month is assumed
%%% Type should be 'w' 'j' or 'wj' ('jw')

%tijdelijk
% year = 2009;
% month = 7;
% type = 'wj';


% extract index variable time and type from NETCDF
time = nc_varget('vlugtenburg.nc','time',[0 0],[-1 -1]);
surveytype = nc_varget('vlugtenburg.nc','survey_type',[0 0],[-1 -1]);
m_time = datenum(time);

survey.cross_shore = nc_varget('vlugtenburg.nc','cross_shore',[0],[-1]);
survey.X_rd = nc_varget('vlugtenburg.nc','X_RD',[0 0],[-1 -1])';
survey.Y_rd = nc_varget('vlugtenburg.nc','Y_RD',[0 0],[-1 -1])';

% define time window
% currently this is based on one measurement a month
Begintime = datenum([num2str(year) '/' num2str(month) '/01'],'yyyy/mm/dd');
Endtime = datenum([num2str(year) '/' num2str(month+1) '/01'],'yyyy/mm/dd');

% extract and write altitudes
if type == 'j'
    % Search for survey index
    Jetski.index = find(m_time >= Begintime &...
        m_time < Endtime & surveytype(:,1) == 'J');
    % extract data
    survey.altitude = nc_varget('vlugtenburg.nc','altitude',[Jetski.index-1 0 0],[1 -1 -1])';
elseif type == 'w'
    Walking.index = find(m_time >= Begintime &...
        m_time < Endtime & surveytype(:,1) == 'W');
    survey.altitude = nc_varget('vlugtenburg.nc','altitude',[Walking.index-1 0 0],[1 -1 -1])';
elseif sum(type == 'jw')==2 || sum(type == 'wj')==2
    Jetski.index = find(m_time >= Begintime &...
        m_time < Endtime & surveytype(:,1) == 'J');
    Walking.index = find(m_time >= Begintime &...
        m_time < Endtime & surveytype(:,1) == 'W');
    Jetski.altitude = nc_varget('vlugtenburg.nc','altitude',[Jetski.index-1 0 0],[1 -1 -1]);
    Walking.altitude = nc_varget('vlugtenburg.nc','altitude',[Walking.index-1 0 0],[1 -1 -1]);
    for i = 1:22
        survey.altitude(:,i) = nanmean([Jetski.altitude(i,:);Walking.altitude(i,:)])';
    end
end