function [cross_shore,altitude] = combine_surveys_nr(survey_ind,pair_nr,line)
%%% This function read the NETCDF file vlugtenburg.nc
%%% Single and combined Jetski and Walking Surveys can be extracted by
%%% defining type 'w','j' or 'wj' and '' for both
%%% If no line is specified all lines are exported.
%%% one survey per month is assumed

% 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);

%%% New version Matthieu Feb 2011.. zoekt naar de vlugtenburg root folder
%%% zodat je niet perse in dezelfde folder als de NetCDF file hoeft te
%%% staan 

curdir=pwd;
ind_v=findstr(curdir, 'vlugtenburg');
pathvlugtenburg=[(curdir(1:ind_v+10)) '\'];  % gives back someting like F:\check_outs\tudelft\vlugtenburg\
NetCDFfilename=[pathvlugtenburg 'vlugtenburg.nc'];

cross_shore = nc_varget(NetCDFfilename,'cross_shore',[0],[-1]);
Walking.altitude = nc_varget(NetCDFfilename,'altitude',...
    [survey_ind.Survey_pairs(pair_nr,1)-1 0 0],[1 -1 -1]);
Jetski.altitude = nc_varget(NetCDFfilename,'altitude',...
    [survey_ind.Survey_pairs(pair_nr,2)-1 0 0],[1 -1 -1]);


%%% Old version pre feb 2011
%
%cross_shore = nc_varget('vlugtenburg.nc','cross_shore',[0],[-1]);
%
%Walking.altitude = nc_varget('vlugtenburg.nc','altitude',...
%    [survey_ind.Survey_pairs(pair_nr,1)-1 0 0],[1 -1 -1]);
%Jetski.altitude = nc_varget('vlugtenburg.nc','altitude',...
%    [survey_ind.Survey_pairs(pair_nr,2)-1 0 0],[1 -1 -1]);
%%%



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


% 
% %% Jetski
% % Search for survey index 
% if  exist('type') ~= 1 || sum(type == 'j')
%     Jetski.index = find(m_time >= Begintime &...
%         m_time < Endtime & surveytype(:,1) == 'J');
%     % add survey dates
%     Jetski.date = datestr(m_time(Jetski.index));
%     %extract data from netcdf file (all suvey lines)
%     Jetski.altitude = nc_varget('vlugtenburg.nc','altitude',[Jetski.index-1 0 0],[1 -1 -1]);
%     % recheck NetCDF time
%     Jetski.time2 = nc_varget('vlugtenburg.nc','time',[Jetski.index-1 0],[1 -1]);
% end
% 
% %% Walking
% if  exist('type') ~= 1 || sum(type == 'w')
%     Walking.index = find(m_time > Begintime &...
%         m_time < Endtime & surveytype(:,1) == 'W');
%     Walking.date = datestr(m_time(Walking.index));
%     Walking.altitude = nc_varget('vlugtenburg.nc','altitude',[Walking.index-1 0 0],[1 -1 -1]);
%     Walking.time2 = nc_varget('vlugtenburg.nc','time',[Walking.index-1 0],[1 -1]);
% end

%%
if exist('line') == 1
    for i = 1:length(line)
        if  exist('type') ~= 1 || (sum(type == 'w') && sum(type == 'j'))
            altitude(:,i) = nanmean([Jetski.altitude(line(i),:);Walking.altitude(line(i),:)])';
        elseif sum(type == 'w')
            altitude(:,i) = Walking.altitude(line(i),:)';
        elseif sum(type == 'j')
            altitude(:,i) = Jetski.altitude(line(i),:)';
        end
    end
else
    for i = 1:22
        if  exist('type') ~= 1 || (sum(type == 'w') & sum(type == 'j'))
            altitude(:,i) = nanmean([Jetski.altitude(i,:);Walking.altitude(i,:)])';
        elseif sum(type == 'w')
            altitude(:,i) = Walking.altitude(i,:)';
        elseif sum(type == 'j')
            altitude(:,i) = Jetski.altitude(i,:)';
        end
    end
end