%% test dunefoot_2nd_deriv

clear;

% addpath('Matlab');
% addpath('subaxis');
addpath('Scripts for 2nd derivative method');

% url = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/jarkus/profiles/transect.nc';
% let's avoid jumps.. jrk is anyway being called too many times. Downloaded manually
url = 'C:\Users\fuentesm\Marilu\Deltares\Projects\Coastviewer\jarkus\scripts\transect_r20240405.nc';
id = nc_varget(url,'id');
tot_years = length(nc_varget(url,'time'));
xDF = NaN(tot_years,length(id)); zDF = NaN(tot_years,length(id));

variab=[];
for ii=1:length(id)
    %try-catch-end: in order to avoid connection problems
    %try 
        disp(['transect #' num2str(ii) ' of ' num2str(length(id))])
        [xDF(:,ii),zDF(:,ii)]  = Dune_foot_2nd_derivative(id(ii)); 
    %catch
%         disp('An error occurred while retrieving information from the internet.');
%         ii
%         variab=[variab, ii];
%         disp('Execution will continue.');
    %end
end

% variab1=[];
% for ii=1:length(variab)
%     try 
%         disp(['transect #' num2str(variab(ii)) ' of ' num2str(length(id))]);
%         [xDF(:,variab(ii)),zDF(:,variab(ii))]  = Dune_foot_2nd_derivative(id(variab(ii))); 
%     catch
%         disp('An error occurred while retrieving information from the internet.');
%         variab(ii)
%         variab1=[variab1, variab(ii)];
%         disp('Execution will continue.');
%     end
% end

% what's this for.. ?
% x DF(:,1863)=NaN;
% zDF(:,1863)=NaN;

% remove old files
if exist('Scripts for 2nd derivative method\DF_2nd_deriv.mat', 'file')==2
  delete('Scripts for 2nd derivative method\DF_2nd_deriv.mat');
end

save('Scripts for 2nd derivative method\DF_2nd_deriv.mat','xDF','zDF','id');

