function install(varargin)
% INSTALL   Install script for COPRA.
%    INSTALL creates the COPRA folder and (optionally) 
%    the needed entries in the startup.m file.
% 
%    INSTALL PATH creates the COPRA folder 
%    in the specified PATH.
%    
%    This installation script was generated by using 
%    the MAKEINSTALL tool. For further information
%    visit http://matlab.pucicu.de

% Copyright (c) 2008-2015
% Norbert Marwan, Potsdam Institute for Climate Impact Research, Germany
% http://www.pik-potsdam.de
%
% Copyright (c) 2001-2008
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% THIS IS A GENERATED INSTALL-FILE, DO NOT EDIT!
% Generation date: 06-Sep-2016 14:11:56
% $Date: 2015/07/09 16:18:06 $
% $Revision: 3.35 $

install_file='';install_path='';installfile_info.date='';installfile_info.bytes=[];
time_stamp='';checksum='';checksum_file=''; instpaths = '';
errcode=0;

  
  
try
  warning('off')
  if isoctave
     disp(['  You are trying to install the toolbox in Octave.',10,'  Some compatibility issues might appear.'])
     warning('off','Octave:possible-matlab-short-circuit-operator')
     more off
  end
  if nargin
    install_path = varargin{1};
  end

  if exist('install.log','file') == 2, delete('install.log'), end
  %rehash
  disp('----------------------')
  disp('  INSTALLATION COPRA');
  disp('----------------------')
  install_file=[mfilename,'.m'];
  currentpath=pwd; time_stamp='time_stamp not yet obtained'; checksum='checksum not yet obtained';
  fid = 0;
  
%%%%%%% read the archive
%%%%%%% and look for checksum and date in archive
  errcode=90;
  disp('  Reading the archiv ')
  fid=fopen(install_file,'r'); 
  fseek(fid,0,'eof'); eofbyte=ftell(fid);
  fseek(fid,31233,'bof'); % location where the container starts
  while 1
     temp=fgetl(fid);
     startbyte=ftell(fid);
     if length(temp)>1
       if strcmpi(temp,'%<-- Header begins here -->')
          errcode=90.1;
          checksum=fgetl(fid);
          temp1=fgetl(fid);
          temp2=fgetl(fid);
       end
       if strcmpi(temp,'%<-- Header ends here -->')
          startbyte=ftell(fid);
          break
       end
     end
  end
  checksum(1:2)=[];
  fseek(fid,startbyte,'bof');
  errcode=90.2;
  A=fread(fid,eofbyte);
  errcode=90.3;
  checksum_file=dec2hex(sum((1:length(A))'.*A));
  if ~strcmpi(checksum_file,checksum)
    error(['The installation file is corrupt!',10,'Ensure that the archive container was ',...
           'not modified (check FTP/ ',10,'proxy/ firewall settings, anti-virus scanner for emails etc.)!'])
  else
    disp(['  Checksum test passed (', checksum,')'])
  end
  fclose(fid);

  disp(['  COPRA version ', temp2(3:end),''])
  time_stamp=temp1(3:end); disp(['  COPRA time stamp ', time_stamp,'']); 
  
  errcode=91;
  if isunix
    toolboxpath='COPRA';
  else
    toolboxpath='COPRA';
  end
  
  
%%%%%%% check for older versions
  
  p=path; i1=0;
  rem_old = '';
  
  while any([findstr([lower(toolboxpath),'demo'],lower(p)) findstr(lower(toolboxpath),lower(p)) findstr('copra_o1',lower(p)) findstr('copra_o2',lower(p))]>i1) && ~strcmpi('N',rem_old)
    errcode=92;
    i1=[findstr([lower(toolboxpath),'demo'],lower(p)) findstr(lower(toolboxpath),lower(p)) findstr('copra_o1',lower(p)) findstr('copra_o2',lower(p))];
    if ~isempty(i1)
      i1=i1(1);
      if isunix, i2=findstr(':',p); else i2=findstr(';',p); end
      i3=i2(i2>i1);                 % last index pathname
      if ~isempty(i3), i3=i3(1)-1; else i3=length(p); end
      i4=i2(i2<i1);                 % first index pathname
      if ~isempty(i4), i4=i4(end)+1; else i4=1; end
      oldtoolboxpath=p(i4:i3);
      if isempty(rem_old)
          disp(['  Old COPRA found in ', oldtoolboxpath,''])
          rem_old = input('> Delete old toolbox? Y/N [Y]: ','s');
      end
      if isempty(rem_old), rem_old = 'Y'; end
      if strcmpi('Y',rem_old)
%%%%%%% removing old entries in startup-file
        errcode=94;
        rmpath(oldtoolboxpath)
        err = savepath;
        if err, disp('  ** Warning: No write access to pathdef.m file!'), end
        if i4>1, p(i4-1:i3)=''; else p(i4:i3)=''; end
        startup_exist = exist('startup','file');
        if isoctave startup_exist = exist(fullfile('~','.octaverc'),'file'); end
        if startup_exist
             startupfile=which('startup');
             startuppath=startupfile(1:findstr('startup.m',startupfile)-1);
             if isoctave
                startuppath = ['~',filesep];
                startupfile = fullfile('~','.octaverc');
             end
             errcode=94.1;
             if ~isunix
               if isoctave
                   toolboxroot=fullfile(matlabroot);
               else
                   toolboxroot=fullfile(matlabroot,'toolbox');
               end
               curr_pwd = pwd; home_pwd = matlabroot; 
             else
               toolboxroot=startuppath;
               curr_pwd = pwd; cd ('~'); home_pwd = pwd; cd(curr_pwd);
             end
             fid = fopen(startupfile,'r');
             k = 1;
             while 1
                 tmp = fgetl(fid);
                 if ~ischar(tmp), break, end
                 instpaths{k} = tmp;
                 k = k + 1;
             end
             fclose(fid);
             k=1;
             while k <= length(instpaths)
               if findstr(oldtoolboxpath,strrep(instpaths{k},'~',home_pwd))
                 errcode=94.2;
                 instpaths(k)=[];
               else
                 k=k+1;
               end
             end
             fid=fopen(startupfile,'w');
             errcode=94.3;
             if fid < 0
               disp(['  ** Warning: Could not get access to ',startupfile,'.']);
               disp('  ** Could not remove toolbox from the startup.m file.');
               disp('  ** Ensure that you have write access!');
             else
               for i2=1:length(instpaths), 
                 fprintf(fid,'%s\n', char(instpaths{i2})); 
               end
               fclose(fid);
             end
        end
%%%%%%% removing old paths
        errcode=93;
        if exist(oldtoolboxpath,'dir') == 7
           disp(['  Change to ',oldtoolboxpath,''])
           cd(oldtoolboxpath)
           dirnames='';filenames='';
           temp='.:';
           errcode=93.1;
           while ~isempty(temp)
             [temp1 temp]=strtok(temp,':');
             if ~isempty(temp1)
               dirnames=[dirnames; {temp1}];
               x2=dir(temp1);
               for i=1:length(x2)
                 if ~x2(i).isdir, filenames=[filenames; {[temp1,'/', x2(i).name]}]; end
         	   if x2(i).isdir && ~strcmp(x2(i).name,'.') && ~strcmp(x2(i).name,'..'), temp=[temp,temp1,filesep,x2(i).name,':']; end
               end
             end
           end
           errcode=93.2;
           if isoctave, confirm_recursive_rmdir (false, 'local'); end
           dirnames=strrep(dirnames,['.',filesep],'');
           for i=1:length(dirnames),l(i)=length(dirnames{i}); end
           [i i4]=sort(l);
           dirnames=dirnames(fliplr(i4));
           errcode=93.3;
           for i=1:length(dirnames)
              if dirnames{i} == '.', continue, end
              delete([dirnames{i}, filesep,'*']),
              if exist('rmdir') == 5 && exist(dirnames{i}) == 7, rmdir(dirnames{i},'s'); else, delete(dirnames{i}), end
              disp(['  Removing files in ',char(dirnames{i}),''])
           end
           errcode=93.4;
           cd(currentpath)
           if exist('rmdir') == 5 && exist(oldtoolboxpath) == 7, rmdir(oldtoolboxpath,'s'); else, delete(oldtoolboxpath), end
           errcode=93.5;
           disp(['  Removing ',oldtoolboxpath,''])
        end
%%%%%%%
      end
    end
    p = path; i1 = 0;
  end
  clear p i i1 i2 i3 i4 temp* x2
  
%%%%%%% add entry into startpath in startup.m
  i=findstr(toolboxpath,path);
  startupPos = 0;
  startup_exist = exist('startup','file');
  if isoctave startup_exist = exist(fullfile('~','.octaverc'),'file'); end
  if startup_exist
        errcode=95.1;
        startupfile=which('startup');
        startuppath=startupfile(1:findstr('startup.m',startupfile)-1);
        if isoctave
           startuppath = ['~',filesep];
           startupfile = fullfile('~','.octaverc');
        end
  
        if ~isunix
           errcode=95.11;
           %toolboxroot=fullfile(matlabroot,'toolbox');
           if isoctave
               toolboxroot=matlabroot;
           else
               toolboxroot=strtok(userpath,';');
           end
        else
           errcode=95.12;
           toolboxroot=startuppath;
        end
        fid = fopen(startupfile,'r');
        k = 1;
        while 1
            tmp = fgetl(fid);
            if ~ischar(tmp), break, end
            instpaths{k} = tmp;
            k = k + 1;
        end
        fclose(fid);
  end
  if isempty(i)
     errcode=95;
     startupfilestr = 'startup.m';
     if isoctave startupfilestr = fullfile('~','.octaverc'); toolboxroot = pkg('prefix'); end

     %% check whether the default toolbox path exists
     err = 1;
     if ~isunix
           errcode=95.01;
           if isoctave
               toolboxroot=matlabroot;
           else
               if isempty(userpath), userpath('reset'), end
               toolboxroot=strtok(userpath,';');
           end
           if exist(toolboxroot,'file') ~= 7, err=mkdir(toolboxroot); end
           cd(toolboxroot)
           startupfile=fullfile(toolboxroot,'startup.m');
           if isoctave, startupfile=fullfile('~','.octaverc');end
           instpaths={''};
     else
           errcode=95.02;
           cd ~
           startuppath=[pwd,filesep];
           if isoctave
              status = fileattrib(pkg('prefix'));
              result = stat(pkg('prefix'));
              uid = geteuid;
              if status && result.uid ~= uid
                  disp(['  ** No writeable package folder found. Will define it as ~/octave.',10,'     If installation fails, you have to create it manually, set it by',10,'     calling ''pkg prefix ~/octave'' and re-run the installation!'])
                  err=mkdir('~/octave');
                  pkg prefix ~/octave;
                  toolboxroot = pkg('prefix');
              end

              if exist(pkg('prefix'),'file') ~= 7, err=mkdir(pkg('prefix')); end
              cd(pkg('prefix'))
  	          startupfile=fullfile(startuppath,'.octaverc');
           else
              if isempty(userpath), userpath('reset'), end
              if isempty(userpath) % i.e. userpath reset failed
                  if ~exist('matlab','dir'), mkdir('matlab'), end % we should be in the home folder
                  userpath([pwd,'/matlab'])
              end
              up = textscan(userpath,'%s','delimiter',':'); up=up{1};
              startuppath = '';
              for k = 1:length(up)
                  if exist(up{k},'file') == 7
                      startuppath = up{k};
                  end
              end
              if isempty(startuppath)
                  err=mkdir(up{1});
                  startuppath = up{1};
              end
              cd(startuppath)
              startupfile=fullfile(startuppath,'startup.m');
           end
     end
     if ~err, error('Could not create toolbox path. Please check whether you have write access or whether there is another file of such a name blocking the creation of the path.'), end
           
     if exist(startupfilestr,'file')
        errcode=95.1;
     else
        errcode=95.2;
        if ~isunix
           errcode=95.21;
           if isoctave
               toolboxroot=matlabroot;
               startupfile=fullfile('~','.octaverc');
           else
               toolboxroot=strtok(userpath,';');
               startupfile=fullfile(toolboxroot,'startup.m');
           end
           cd(toolboxroot)
           instpaths={''};
        else
           errcode=95.22;
           cd ~
           startuppath=[pwd,filesep];
           if isoctave
              cd(pkg('prefix'))
              startupfile=fullfile(startuppath,'.octaverc');
           else
              up = textscan(userpath,'%s','delimiter',':'); up=up{1};
              startuppath = '';
              for k = 1:length(up)
                  if exist(up{k},'file') == 7
                      startuppath = up{k};
                  end
              end
              if isempty(startuppath)
                  err=mkdir(up{1});
                  startuppath = up{1};
              end
              cd(startuppath)
              startupfile=fullfile(startuppath,'startup.m');
           end
           
  	     toolboxroot=startuppath;
  	     instpaths={''};
        end
     end
    
     errcode=95.23;
     if ~isempty(install_path)
           switch ( exist(install_path,'dir') )
              case 0
                in = input(['> Create ', install_path, '? Y/N [Y]: '],'s');
                if isempty(in), in = 'Y'; end
                if strcmpi('Y',in)
                   err = mkdir(install_path);
                   if ~err
                     disp(['  ** Could not create ', install_path, '! Using ',startuppath,' as installation path.'])
                   else                
                     toolboxroot = install_path;
                   end                
                else 
                   disp(['  ** Do not create ', install_path, '! Using ',startuppath,' as installation path.'])
                end
              case 2
                disp(['  ** ', install_path, ' is not a directory! Using ',startuppath,' as installation path.'])
              case 7
                toolboxroot = install_path;
           end
     end

     errcode=95.3;
     TBfullpath=fullfile(toolboxroot,toolboxpath);
     if ~exist(TBfullpath,'dir'), mkdir(toolboxroot,toolboxpath); end

%%%%%%% resolve relative path (starting with ./ and ../) to absolute path

     isrelpath = findstr('./',TBfullpath);
     isrelpathDos = findstr('.\',TBfullpath);
     if ( ~isempty(isrelpath) && isrelpath == 1 ) || ( ~isempty(isrelpathDos) && isrelpathDos == 1 )
         TBfullpath = fullfile(pwd, TBfullpath(3:end));
     end

     isrelpath = findstr('../',TBfullpath);
     isrelpathDos = findstr('..\',TBfullpath);
     if ( ~isempty(isrelpath) && isrelpath == 1 ) || ( ~isempty(isrelpathDos) && isrelpathDos == 1 )
         TBfullpath = fullfile(pwd, TBfullpath(4:end));
     end
     

%%%%%%% ask where to add entry in startup file

     disp(['> In order to get permanent access, the toolbox should be added',10,'> to the top (default) or end (E) of your startup path.'])
     in = input('> Add toolbox permanently into your startup path (highly recommended)? Y/E/N [Y]: ','s');
     if isempty(in), in = 'Y'; end
     if strcmpi('Y',in)
       startupPos = '-begin';
       disp('  Adding Toolbox at the top of the startup.m file')
     elseif strcmpi('E',in)
       startupPos = '-end';
       disp('  Adding Toolbox at the end of the startup.m file')
     end

     if startupPos
         errcode=95.4;
         loc = ['addpath ''',TBfullpath,''' ', startupPos];
         if ~ismember(loc, instpaths)
             instpaths{end+1} = loc;
         end
     end

  else
     errcode=96;
     startupfile=which('startup');
     startuppath=startupfile(1:findstr('startup.m',startupfile)-1);
     if isoctave
         startuppath = ['~', filesep];
         startupfile = fullfile('~','.octaverc');
     end
     if ~isunix
        if isoctave
            toolboxroot=matlabroot;
        else
            toolboxroot=strtok(userpath,';');
        end
        %toolboxroot=fullfile(matlabroot,'toolbox');
     else
        toolboxroot=startuppath;
     end
    
        errcode=96.21;
        if ~isempty(install_path)
           switch ( exist(install_path,'dir') )
              case 0
                disp(['> Create ', install_path, '?'])
                in = input('> Create ', install_path, '? Y/N [Y]: ','s');
                if isempty(in), in = 'Y'; end
                if strcmpi('Y',in)
                   err = mkdir(install_path);
                   if ~err
                     disp(['  ** Could not create ', install_path, '! Using ',startuppath,' as installation path.'])
                   else                
                     toolboxroot = install_path;
                   end                
                else 
                   disp(['  ** Do not create ', install_path, '! Using ',startuppath,' as installation path.'])
                end
              case 2
                disp(['  ** ', install_path, ' is not a directory! Using ',startuppath,' as installation path.'])
              case 7
                toolboxroot = install_path;
           end
        end
        TBfullpath=fullfile(toolboxroot,toolboxpath);
        if ~exist(TBfullpath,'dir'), mkdir(toolboxroot,toolboxpath); end
  end
  
  
%%%%%%% read the archive
  errcode=97;
  fprintf('  Importing the archiv ')
  cd(currentpath)
  max_sc=30;
  scale=[sprintf('%3.0f',0),'% |',repmat(' ',1,max_sc),'|'];
  fprintf('%s',scale)
  b=''; c.file=''; c.data=''; bfile=''; folder=''; i2=0;
    
    % read ASCII
    errcode=97.1;
    i1=findstr(char(A'),'%<-- ASCII begins here');
    i2=findstr(char(A'),'%<-- ASCII ends here -->');
    
    for k=1:length(i1),
      wb=round(i1(k)*max_sc/eofbyte);
      errcode=97.11;
      scale=[sprintf('%3.0f',100*wb/max_sc),'% |',repmat('*',1,wb),repmat(' ',1,max_sc-wb),'|'];
      fprintf([repmat('\b',1,max_sc+7),'%s'],scale)
      B=A(i1(k):i2(k)-2);
     
      i4=find(B == 10);
      i3=[0;i4(1:end-1)]+1;
      filename=strrep(...
                strrep(char(B(i3(1):i4(1)-1)'),'%<-- ASCII begins here: __',''),...
  	      '__ -->','');
      errcode=['97.1',reshape(dec2hex(double(filename))',1,length(filename)*2)];
      filename = strrep(filename, '/', filesep);
      i6=findstr(filename, filesep);
      if i6>0
         folder=[folder; {filename(1:i6(end)-1)}];
      end
      c(k).file={filename};
      c(k).data=strrep(char(B(i4(1)+3:end)'),[char(10),'%@'],char(10));
    end
  
    % read binary
    errcode=97.2;
    i1=findstr(char(A'),'%<-- Binary begins here');
    i2=findstr(char(A'),'%<-- Binary ends here -->');
    for k=1:length(i1),
      wb=round(i1(k)*max_sc/eofbyte);
      errcode=97.21;
      scale=[sprintf('%3.0f',100*wb/max_sc),'% |',repmat('*',1,wb),repmat(' ',1,max_sc-wb),'|'];
      fprintf([repmat('\b',1,max_sc+7),'%s'],scale)
      B=A(i1(k):i2(k));
  
      i4=find(B == 10);
      i3=[0;i4(1:end-1)]+1;
      i5=findstr(char(B(i3(1):i4(1))'),'__');
      filename=char(B(i5(1)+2:i5(2)-1)');
      errcode=['97.2',reshape(dec2hex(double(filename))',1,length(filename)*2)];
      filename = strrep(filename, '/', filesep);
      i6=findstr(filename, filesep);
      if i6>0
      folder=[folder; {filename(1:i6(end)-1)}];
      end
      bfile=[bfile; {filename}];
      nbytes=str2double(char(B(i5(3)+2:i5(4)-1)'));
      if nbytes>=2
        temp=reshape(B(i4(1)+1:i4(1)+nbytes),2,nbytes/2);
        b=[b;{temp(2,:)}];
      else
        b=[b;{''}];
      end
  
    end
    wb=max_sc;
    scale=[sprintf('%3.0f',100*wb/max_sc),'% |',repmat('*',1,wb),repmat(' ',1,max_sc-wb),'|'];
    fprintf([repmat('\b',1,max_sc+7),'%s'],scale)
  fprintf('\n')
  clear temp* i i1 i2 i3 i4 i5 i6 A B
  
  errcode='97.3';
  if exist(TBfullpath,'dir') ~= 7, error(['Could not enter toolbox path',10,'  ', TBfullpath,10,'. Please check whether you have write access or whether there is another file of such a name blocking the creation of the path.']), end
  cd(TBfullpath)
  disp(['  Toolbox folder is ',TBfullpath,''])
  
%%%%%%% make sub-directories
  errcode='97.4';
  for i=1:length(folder);
     i1=folder{i}; i2='.'; olddir=pwd;
     if exist([TBfullpath, filesep, i1],'file') ~= 7
        while ~isempty(i2) && ~isempty(i1)
          cd(i2)
          [i2 i1]=strtok(i1,filesep);
          if exist([pwd, filesep, i2],'file') ~= 7 && exist([pwd, filesep, i2],'file')
             disp(['  ** Warning: Found ', i2, ' will be overwritten.'])
             errcode=['97.5',reshape(dec2hex(double(i2))',1,length(i2)*2)];
             delete(i2)
          end
          if ~exist([pwd, filesep, i2],'file')
            disp(['  Make directory ',pwd, filesep, i2])
            errcode=['97.6',reshape(dec2hex(double(i2))',1,length(i2)*2)];
            err = mkdir(i2);
            if err==0, disp(['  ** Warning: Could not create ',pwd, filesep, i2,'!',10,'     Installation will probably fail.']), end
            errcode=97.7;
            temppath = strrep(pwd,TBfullpath,'');
            if ~strcmpi(i2,'private') && all(i2 ~= '@') && all(i2 ~= '+') && all(temppath ~= '+')
                 % add entries in startup.m
                 if isempty(startupPos) startupPos = '-end'; end
                 loc = ['addpath ''',pwd, filesep, i2,''' ', startupPos];
                 eval(loc);
                 if ~any(ismember(loc, instpaths)) && all(startupPos~=0)
                     instpaths{end+1} = loc;
                 end
            end
          end
        end
        cd(olddir)
     end
  end
  
%%%%%%% make toolbox accessible in the current matlab session
  if ~startupPos, startupPos = '-end'; end
  addpath(TBfullpath,startupPos);


%%%%%%% write startup file
  if startupPos
    errcode=95.4;
    if ~exist('startupfile','var')
        if isoctave
            startupfile = fullfile('~','.octaverc');
        else
            up = textscan(userpath,'%s','delimiter',':'); up=up{1};
            startuppath = '';
            for k = 1:length(up)
                if exist(up{k},'file') == 7
                    startuppath = up{k};
                end
            end
            if isempty(startuppath)
                err=mkdir(up{1});
                startuppath = up{1};
            end
            startupfile = fullfile(startuppath,'startup.m');
        end
    end

    fid=fopen(startupfile,'w');
    if fid < 0
      disp(['  ** Warning: Could not get access to ',startupfile,'.']);
      disp('  ** Could not add toolbox into the startup.m file.');
      disp('  ** Ensure that you have write access!');
    else
      %for i2=1:length(instpaths), fprintf(fid,'%s\n', char(instpaths{i2})); disp(char(instpaths{i2}));end
      for i2=1:length(instpaths), fprintf(fid,'%s\n', char(instpaths{i2})); end
      fclose(fid);
    end
  end


%%%%%%% write the programme files
  errcode=98;
  num_errors=0;
  for i=1:length(c),
    disp(['  Creating ',char(c(i).file)])
    fid=fopen(char(c(i).file),'w');
    if fid < 0
       disp(['  ** Warning: Could not get access to ',char(c(i).file),'.']);
       disp('  ** Ensure that you have write access in this filesystem!');
       num_errors=num_errors+1;
       if num_errors == 2; 
         disp('Abort!')
         disp('Too much errors due to write access failure in this filesystem.')
         cd(currentpath), return
       end
    else
      if strcmpi(c(i).file,'info.xml')
        v=version;
        release=str2double(v(findstr(v,'(R')+2:findstr(v,')')-1));
        if release>12, area='toolbox'; icon_path='$toolbox/matlab/icons'; else area='matlab'; icon_path='$toolbox/matlab/general'; end
        i3=findstr(c(i).data,'<matlabrelease>'); i4=findstr(c(i).data,'</matlabrelease>');
        if ~isempty(i3) && i4>i3;
          c(i).data=strrep(c(i).data,c(i).data(i3:i4-1),['<matlabrelease>',num2str(release)]);
        end
        i3=findstr(c(i).data,'<area>'); i4=findstr(c(i).data,'</area>');
        if ~isempty(i3) && i4>i3;
          c(i).data=strrep(c(i).data,c(i).data(i3:i4-1),['<area>',area]);
        end
        c(i).data=strrep(c(i).data,'<icon>$toolbox/matlab/general',['<icon>',icon_path]);
        c(i).data=strrep(c(i).data,'<icon>$toolbox/matlab/icons',['<icon>',icon_path]);
      end
      fprintf(fid,'%s',char(c(i).data));
      fclose(fid);
    end
  end

%%%%%%% pcode the programme files
  for i=1:length(c),
    try
      [tPath tFile tExt]=fileparts(char(c(i).file));
      if strcmpi(tExt,'.m') && ~strcmpi(tFile,'Readme') && ~strcmpi(tFile,'Contents')
        if mislocked(char(c(i).file)), munlock(char(c(i).file)); clear(char(c(i).file)); end
        disp(['  Pcode ',char(c(i).file),''])
        if sum(c(i).file == '.') < 2
           pcode(char(c(i).file),'-inplace')
        end  
      end  
    catch
    end
  end

%%%%%%% write the binary files
  num_errors=0;
  for i=1:length(b),
    disp(['  Creating ',char(bfile(i)),''])
    fid=fopen(char(bfile(i)),'w');
    if fid < 0
       disp(['  ** Warning: Could not get access to ',char(bfile(i)),'.']);
       disp('  ** Ensure that you have write access in this filesystem!');
       num_errors=num_errors+1;
       if num_errors == 2; 
         disp('Abort!')
         disp('Too much errors due to write access failure in this filesystem.')
         cd(currentpath), return
       end
    else
      fwrite(fid,b{i}); 
      fclose(fid);
    end
  end
  tx=version; tx=strtok(tx,'.'); 
  if str2double(tx)>=5 && exist('rehash','builtin'), rehash, end
  if str2double(tx)>=6 && exist('rehash','builtin'), eval('rehash toolboxcache'), end
  
%%%%%%% removing installation file
  errcode=99;
  cd(currentpath)
  i = input('> Delete installation file? Y/N [Y]: ','s');
  if isempty(i), i = 'Y'; end
  
  if strcmpi('Y',i)
    disp('  Removing installation file')
    delete(install_file)
  end
  
  disp('  Installation finished!')
  
  if ~exist('rehash','builtin')
    disp('  ** Warning: Could not rehash your Matlab system.')
    disp('  ** Probably a restart of Matlab will be necessary in order')
    disp('  ** to get access to the installed toolbox.')
  end
  
  disp('----------------------')
  disp('Please refer to the README.txt file!')
  disp('For an overview type:')
  disp(['helpwin ',toolboxpath])
  warning('on')
  if isoctave
      more on
  end
  
  
%%%%%%% error handling

catch
  z2=whos;x_lasterr=lasterr;y_lastwarn=lastwarn;
  if ~strcmpi(x_lasterr,'Interrupt')
    if fid>-1, 
      try, z_ferror=ferror(fid); catch, z_ferror=''; end
    else
      z_ferror='File not found.'; 
    end
    installfile_info=dir([currentpath,filesep,install_file]);
    fid=fopen(fullfile(currentpath,'install.log'),'w');
    checksum_test=findstr(x_lasterr,'The installation file is corrupt!');
    if isempty(checksum_test),checksum_test=0; end
    if ~checksum_test
      fprintf(fid,'%s\n','A critical error has occurred. Please inform the distributor');
      fprintf(fid,'%s\n','of the toolbox, where the error occured and send us the entire');
      fprintf(fid,'%s\n','screen output of the installation, the following error');
      fprintf(fid,'%s\n','report, and the informations about the toolbox (distributor,');
      fprintf(fid,'%s\n','name, URL etc.). Provide a brief description of what you were');
      fprintf(fid,'%s\n','doing when this problem occurred.');
      fprintf(fid,'%s\n','E-mail or FAX this information to us at:');
      fprintf(fid,'%s\n','    E-mail:  marwan@pik-potsdam.de');
      fprintf(fid,'%s\n','       Fax:  ++49 +331 288 2640');
      fprintf(fid,'%s\n\n\n','Thank you for your assistance.');
      fprintf(fid,'%s\n',repmat('-',50,1));
      fprintf(fid,'%s\n',datestr(now,0));
      fprintf(fid,'%s\n',['Matlab ',char(version),' on ',computer]);
      fprintf(fid,'%s\n',repmat('-',50,1));
      fprintf(fid,'%s\n','Makeinstall Version ==> 3.35 ');
      fprintf(fid,'%s\n',['Install File ==> ',install_file,'/',installfile_info.date,'/',num2str(installfile_info.bytes)]);
      fprintf(fid,'%s\n',['Container ==> ',time_stamp,'/',checksum]);
      fprintf(fid,'%s\n\n',repmat('-',50,1));
      fprintf(fid,'%s\n',x_lasterr);
      fprintf(fid,'%s\n',y_lastwarn);
      fprintf(fid,'%s\n',z_ferror);
      fprintf(fid,'%s\n',[' errorcode ==> ',num2str(errcode)]);
      fprintf(fid,'%s\n',' workspace dump ==>');
      if ~isempty(z2), 
        fprintf(fid,'%s\n',['Name',char(9),'Size',char(9),'Bytes',char(9),'Class']);
        for j=1:length(z2);
          fprintf(fid,'%s',[z2(j).name,char(9),num2str(z2(j).size),char(9),num2str(z2(j).bytes),char(9),z2(j).class]);
          if ~strcmp(z2(j).class,'cell') && ~strcmp(z2(j).class,'struct')
            content=eval(z2(j).name);
            try, content=mat2str(content(1:min([size(content,1),500]),1:min([size(content,2),500])));end
            fprintf(fid,'\t%s',content(1:min([length(content),500])));
          elseif strcmp(z2(j).class,'cell')
            content=eval(z2(j).name);
            fprintf(fid,'\t');
            for j2=1:min([length(content),500])
              if isnumeric(content{j2})
                fprintf(fid,'{%s} ',content{j2}(1:end));
              elseif iscell(content{j2})
                fprintf(fid,'{%s} ',content{j2}{1:end});
              end
            end
          elseif strcmp(z2(j).class,'struct')
            content=fieldnames(eval(z2(j).name));
            content=char(content); content(:,end+1)=' '; content=content';
            fprintf(fid,'\t%s',content(:)');
          end
          fprintf(fid,'%s\n','');
        end
      end
    else
      fprintf(fid,'%s\n','Installation aborted due to a failed checksum test!');
      fprintf(fid,'%s\n',['Checksum should be:     ', checksum]);
      fprintf(fid,'%s\n\n',['Checksum of archive is: ', checksum_file]);
      fprintf(fid,'%s\n','Ensure that the installation file was not modified by any');
      fprintf(fid,'%s\n','other programme, as an anti-virus scanner for emails, a');
      fprintf(fid,'%s\n','mis-configured HTTP proxy or FTP programme.');
    end
    fclose(fid);
    disp('----------------------------');
    disp('       ERROR OCCURED ');
    disp('    during installation');
    disp('----------------------------');
    disp(x_lasterr);
    if errcode == 95.21
       disp('----------------------------');
       disp('   This error means that the toolbox directory could not');
       disp('   be created. Probably, there is a file of the same name.');
       disp('   or there are in-appropriate permission settings in its');
       disp('   parent folder.');
       disp('   Please check the output of the following command:');
       disp('      userpath(''reset'')');
       disp('   which might help to locate the problem.');
       disp('----------------------------');
    end
    if ~checksum_test
      disp(z_ferror);
      disp(['   errorcode is ',num2str(errcode)]);
      disp('----------------------------');
      disp('   A critical error has occurred. Please inform the distributor');
      disp('   of the toolbox, where the error occured and send us the entire');
      disp('   screen output of the installation, the error report report');
      disp('   and the informations about the toolbox (distributor, name,');
      disp('   URL etc.). For your convenience, this information has been')
      disp('   recorded in: ')
      disp(['   ',fullfile(currentpath,'install.log')]), disp(' ')
      disp('   Provide a brief description of what you were doing when ')
      disp('   this problem occurred.'), disp(' ')
      disp('   E-mail or FAX this information to us at:')
      disp('       E-mail:  marwan@pik-potsdam.de')
      disp('          Fax:  ++49 +331 288 2640'), disp(' ')
      disp('   Thank you for your assistance.')
    end
  end
  warning('on')
  cd(currentpath)
  if isoctave
      more on
  end
end

function flag = isoctave
% ISOCTAVE   Checks whether the code is running in Octave
%   ISOCTAVE is returning the value TRUE if executed within the
%   Octave environment, else it is returning FALSE (e.g. when
%   called within Matlab.

a = ver('Octave');

if ~isempty(a) && strfind(a(1).Name,'Octave')
    flag = true;
else
    flag = false;
end
% -------------------------------------------
% GENERATED ENTRIES - DO NOT MODIFY ANYTHING!
%<-- Header begins here -->
%@985BCCDA4BA
%@06-Sep-2016 14:11:56
%@1.13b 
%<-- Header ends here -->
%<-- ASCII begins here: __Contents.m__ -->
%@% COPRA
%@% Version 1.13b 06-Sep-2016
%@%
%@%    copra          -  Constructing Proxy Record Age models
%@%    copragui       -  User Interface for COPRA
%@%    example_script -  COPRA
%@%    mcagemodels    -  Perform MC simulations for paleoclimate proxy age-depth relationships.
%@
%@% Generated at 23-Nov-2013 22:55:47 by MAKEINSTALL
%@% Modified at 06-Sep-2016 14:11:56 by MAKEINSTALL
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __README.txt__ -->
%@######################## Readme COPRA (17.10.2014) #########################################
%@
%@COPRA is a depth-age modeling program that transforms age-uncertainties to proxy-uncertainties. In its present form, it runs in both Octave and Matlab.
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ PROGRAM REQUIREMENTS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
%@
%@In Octave, COPRA requires Octave 3.6 or later. It was tested for Ubuntu Precise, with the required packages installed from the 
%@https://launchpad.net/~mvanderkolff/+archive/octave-3.6 and it requires the package octave-signal (Version 1.1.2 --> in PPA of M.v.d.Kolff)
%@
%@Some warnings (regarding, e.g., the use of single quotes '', which are supported, but not default in Octave) can be switched off by 
%@     warning('off','Octave:possible-matlab-short-circuit-operator')
%@
%@COPRA was also tested in Matlab R2010/2011/2012. It requires the statistics toolbox.
%@
%@In Matlab, a graphical user interface (GUI) is available. To use it, the GUI Layout Toolbox must be installed. For Matlab versions R2014a and older, we provide a convenient installer at
%@http://tocsy.pik-potsdam.de/COPRA/layoutInstall.m
%@(the original can be found at http://www.mathworks.com/matlabcentral/fileexchange/27758-gui-layout-toolbox)
%@For Matlab R2014b and newer, use: 
%@http://www.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox
%@
%@
%@Further third-party scripts are included in the COPRA package:
%@
%@* newid.m (by Mathworks, uses setdefaultbutton.m and getnicedialoglocation.m) Improved input dialog (compared to inputdlg)
%@  http://www.mathworks.se/support/solutions/en/data/1-39UWQT/?solution=1-39UWQT 
%@
%@* LimitSizeFig.m To be able to limit the GUI's size
%@  http://www.mathworks.com/matlabcentral/fileexchange/38527-limit-figure-size/content/LimitSizeFig.m
%@
%@* findjobj.m Find java handles of matlab graphic objects (counterpart to findobj, used in GUI to make cooler buttons)
%@  http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects
%@
%@* uicomponent.m  An enhanced replacement for UICONTROL & JAVACOMPONENT (used here for editable drop-down menus (JComboBox))
%@  http://www.mathworks.com/matlabcentral/fileexchange/14583-uicomponent-expands-uicontrol-to-all-java-classes
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ TO RUN @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
%@To run COPRA, start octave and type 
%@copra(). For a start, you can use the test datasets in the folder COPRA/data/test/. When prompted for age-depth information, start with the example dataset which is located in the COPRA data folder:
%@
%@octave:2> d=copra()
%@#######################################
%@               COPRA v1.01
%@########################################
%@Select input age-depth data
%@[]: ~/octave/COPRA/data/LayercountGood/testagemodel_good.txt
%@Select proxy data file (e.g. isotope measurements)
%@[]: ~/octave/COPRA/data/LayercountGood/isotope-test-good.txt
%@
%@You will be prompted if you want to change or remove pointwise age estimates, and if you want to treat potential hiatuses. All relevant variables will be returned with the structure d after copra finishes. To use Copra in a script you can run individual segments again, as shown in the example_script.m.
%@
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ TEST DATA @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
%@In the folder COPRA/data/test/ you find three types of test datasets. 
%@
%@* With a hiatus
%@
%@* With reversals (tractable and non-tractable) 
%@
%@* Without complications but with an additional layer counting chronology. (GoodLayercounting). Note that including layercounting data will take computation time!
%@
%@For each file you will find an isotope and an agemodel file in the subfolders.
%@For the 'good' case there is also layer counting data. 
%@
%@The datasets were generated using the file testagemodel.m.
%@Growth rates of 0.5-1.5mm/yr and a core length of 1m were assumed. The core was sampled at 10 equidistant depths for 'radiometric dating'. The isotope signal is a sinusoid with a period of 150 years (no noise).
%@
%@The agemodels are not commented.
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ DATA REQUIREMENTS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@Data should be provided in the correct format (e.g. can be exported from spreadsheet)
%@* The dating table:
%@  -> as a .csv or .txt file without column headers (the command C=load('agemodelfile.csv') should not throw an error!) and in the order 'depth', 'age', 'ageerror'
%@	
%@* The proxy data should contain the columns 1) 'depth' and 2) 'proxy value' without (or with commented) column headers, so that it can be read using the matlab LOAD command. Depths should be monotonous and unique (no double depths), no NaN values.
%@
%@* The layer counting data should be provided in columns of the order 1) 'depth', 2) 'age', 3) 'deptherror', again, in a format that can be LOADed in Matlab or Octave. The age in the layer counting is to be determined *relative* to the first layer (first layer has age zero!).
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ OUTPUT @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@* command line copra has up to 3 optional output arguments (will be saved in the Matlab workspace):
%@    - T_unc  = [proxy depth, proxy value, all results of agemodel simulations];
%@    - T_cert = [age value, mean proxy value, median proxy value, age error, proxy error];
%@    - d: data structure containing all kinds of parameters of the last run. this can also be used as input, e.g.
%@      . from .mat file: copra('d_test.mat'), where d_test is either located in the COPRA main folder or the output folder
%@      . from Matlab workspace: copra(d)
%@
%@* furthermore, running from command line automatically generates 3 files 
%@    - a .txt file containing the table with results (output folder)
%@    - a .mat file containing the structure d, see above (output folder)
%@    - a logfile (.m) containing various information about the last run
%@
%@* using the GUI (copraGUI), the .mat, .txt, logfile and the plots can saved to files using the buttons in the lower right corner. The GUI does not save anything to the Matlab workspace
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ COPYRIGHT @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@
%@@ This program is in developmental stage and is not to be redistributed
%@@ and/ or modified.
%@@ Copyright (c) 2012-2016:
%@@ Kira Rehfeld, Bedartha Goswami, Norbert Marwan
%@@ Potsdam Institute for Climate Impact Research, Germany
%@@ Sebastian Breitenbach, Ruhr-Universitaet Bochum, Germany
%@@ http://www.pik-potsdam.de
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __copra.m__ -->
%@function varargout = copra(varargin)
%@% COPRA Constructing Proxy Record Age models
%@%
%@%    COPRA starts the workflow of selecting and modifying
%@%    dating measurements as well as proxy records and
%@%    calculating age-depth models.
%@%
%@%    USAGE:
%@%       copra
%@%
%@%    EXAMPLE: [T_unc,T_cert,d]=copra;
%@%
%@%       1) Prepare the input files (agemodel, proxy and, if available, layer
%@%       counting data) according to specifications in the README.txt file.
%@%       
%@%       2) Be patient with bugs, please! We are aware of some bugs already, which are going to be fixed soon.
%@%          In case of questions regarding the code, feel free to contact
%@%       rehfeld@pik-potsdam.de
%@%       goswami@pik-potsdam.de
%@%       marwan@pik-potsdam.de
%@%       sebastian.breitenbach@erdw.ethz.ch
%@%
%@%    CAUTION!
%@%       * Using cubic/spline interpolation on cores with irregular accumulation
%@%         behaviour leads to extremely long computation times, as the
%@%         monotonicity is violated easily by cubic/spline interpolation.
%@%       * Test data with correct format are found in the 
%@%         data/LayercountGood - folder
%@%       * Adding layer counted section(s) will prolong the computation
%@%         significantly! To test if layer counting is working, use a small
%@%         number of layercounted years (e.g., 10).
%@%
%@
%@
%@%%%%COPYRIGHT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@% Copyright (c) 2013:
%@% Kira Rehfeld, Bedartha Goswami, Norbert Marwan
%@% Potsdam Institute for Climate Impact Research, Germany
%@% Sebastian Breitenbach, Daniel Juncu, ETH Zürich, Switzerland
%@% http://www.pik-potsdam.de
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@
%@close all;
%@warning on;
%@
%@% find version info in Contents.m and create startup info
%@nfill=40;
%@fillstr = [repmat('#',1,nfill),'\n'];
%@skipstr = '\n';
%@msgstr = [repmat(' ',1,nfill),'\n'];
%@
%@if exist('Contents.m','file')
%@    fid = fopen('Contents.m');
%@    tmp_v = textscan(fid,'%s');
%@    for i = 1:length(tmp_v{1})        
%@        if strncmp(tmp_v{1}(i),'Version',7)           
%@            copra_version = cell2mat(tmp_v{1}(i+1));
%@            break
%@        end
%@    end
%@    fclose(fid);
%@    msgstr=['               COPRA v',copra_version, '\n'];
%@else
%@    msgstr=['               COPRA\n'];
%@end
%@
%@fprintf([skipstr,fillstr,msgstr,fillstr]);
%@
%@
%@%% 1.0 Definitions/ Default parameter setting
%@
%@
%@guistring='';
%@gui=0;
%@d.agename='yr BP';
%@d.depthname='Depth (mm)';
%@d.M=2000;
%@d.am_commented=0;
%@d.guistring=[];
%@d.gui=0;
%@d.uselog = 0;
%@d.use_d = 0;
%@
%@
%@% process was cancelled
%@if isnumeric(d) && d == -1
%@    disp('Cancelled by user');
%@    return
%@end
%@
%@
%@%% get input variables
%@check_interp={'linear','pchip','cubic','spline'};   % linear, pchip, cubic, spline
%@check_interp_short={'li','pc','cu','sp'};   % linear, pchip, cubic, spline
%@check_gui={'nog','gui','sil'};              % gui, nogui, silent
%@
%@if nargin
%@    idxNum = find(cellfun('isclass',varargin,'double'));
%@    idxChar = find(cellfun('isclass',varargin,'char'));
%@    idxStruct = find(cellfun('isclass',varargin,'struct'));
%@    
%@    % get numerical input arguments (data)
%@    if ~isempty(idxNum) && length(idxNum) >= 4
%@        % placeholder
%@    end
%@    if ~isempty(idxChar)
%@        % check interpolation method, gui etc.
%@        temp_interp = 0; temp_gui = 0; 
%@        charargin = cell(length(idxChar), 1);
%@        
%@        for i=1:length(idxChar),
%@           %varargin{idxChar(i)}(4)='0'; % what was this for??
%@           charargin{i} = varargin{idxChar(i)}; % store all char inputs in this cell array
%@           temp_interp = temp_interp + strcmpi(varargin{idxChar(i)}(1:2),check_interp_short'); 
%@           temp_gui = temp_gui + strcmpi(varargin{idxChar(i)}(1:3),check_gui');            
%@        end
%@        
%@                     
%@        temp_interp = min(find(temp_interp));
%@        if ~isempty(temp_interp)
%@            input_interp_method = check_interp{temp_interp};
%@        end
%@        d.gui = min(find(temp_gui))-1;
%@        if isempty(d.gui), d.gui=0; end
%@        
%@        % get struct input arguments from file (data)
%@        find_d = strfind(charargin,'.mat'); % find mat-file (d) amongst the char inputs
%@        n_charargin = find(~cellfun('isempty', find_d)); % find its position among the char input arguments
%@        
%@        if any(n_charargin)
%@            % look for d in the output folder and in the mainfolder
%@            try
%@                load(strcat('output/',charargin{n_charargin}));
%@            catch exception
%@                try
%@                    (load(charargin{n_charargin}));
%@                catch exception2
%@                    rethrow(exception)
%@                end
%@            end    
%@                    
%@                
%@            d.use_d = 1;
%@            d.gui = 0;  
%@        end
%@                           
%@    end
%@
%@    % get struct input arguments from workspace (data)
%@    if ~isempty(idxStruct) 
%@        d = varargin{idxStruct};    
%@        d.use_d = 1;
%@        d.gui = 0;        
%@    end
%@
%@end
%@
%@%% get parameters
%@
%@% get/create logfile
%@if ~d.use_d
%@    d = getlogfilename(d);
%@    savelog(d.log,'d.log','filename')
%@elseif ~isfield(d,'log')
%@    d.log = ['log_COPRA_',datestr(now,'yyyymmdd'),'.m'];
%@    fid = fopen(d.log,'w');frewind(fid);fclose(fid);   
%@end
%@
%@savelog(d.log,'d.M', 'Number of Monte Carlo samples')
%@
%@% interpolation method
%@if ~isfield(d,'interp_method')
%@    d.interp_method = 'pchip';
%@elseif exist('input_interp_method','var') && ~strcmp(d.interp_method,input_interp_method)
%@    d.interp_method = input_interp_method;
%@end
%@
%@if strcmpi(d.interp_method,'cubic')
%@    d.interp_method = 'pchip';
%@    disp('CUBIC interpolation option is obsolete. Changed to PCHIP')
%@end
%@
%@savelog(d.log,'d.interp_method','Interpolation method')
%@
%@
%@
%@%% 1.1 Import age model and proxy data/ Definitions
%@d = loaddata(d);
%@
%@%% 1.2 Ask for gray value data/ layer counting data, if it exists, input, else, continue
%@
%@lc = [];
%@
%@choice = input('Do you wish to provide layer count data? [Yes/NO]: ','s');
%@if isempty(choice)
%@    choice = 'No';
%@end
%@
%@choice = lower(choice);
%@
%@
%@switch choice(1)
%@    case 'y'
%@        d.adinf = 1;
%@       	d.dlc = getlayercount();
%@        % process was cancelled
%@        if isnumeric(d.dlc) && dlc == -1
%@            disp('Cancelled by user');
%@            return
%@        end
%@    case 'n'
%@        d.dlc=[];
%@        d.adinf = 0;
%@end
%@
%@
%@
%@%% 2 Check for Age reversal
%@d.revType = chkRevs(d); % output arg not assigned
%@
%@if any(d.revType)
%@   savelog(d.log,'','***** Reversals found! *****')
%@   savelog(d.log,'d.revType','(0=no reversal, 1=tractable, 2=non-tractable reversal)')
%@end
%@
%@
%@
%@%% 3 Plot age model and color the 'reversed' points, if a reversal is non-tractrable
%@hiatus = zeros(size(d.depth,1),1); % tracks splits of the agemodel introduced for hiatus treatment
%@hiatus(end) = 1; 
%@d.hiatus = hiatus; 
%@
%@d = processages_cl(d);
%@
%@
%@%% 4a Hiatus detection/ Assessing Growth rates
%@d.hiatus=[];
%@d = chkhiatus_cl(d);
%@
%@finalagemodel=[d.depth, d.age, d.ageerror]; % only to be compatible with old version, should be removed in the future
%@
%@
%@%% 4b MC age depth simulation 
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@%%%% CORE MC simulations%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@d = mcagemodels(d);
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@
%@%% 5a Plot agemodel
%@% plot-type options: mean, median, spaghetti
%@plotagemodel(d,'spaghetti');
%@
%@%% Final output: 5b Transform time uncertain to time certain time series
%@% Resampling onto grid corresponding to mean ages at sampling depths, spaghetti plot
%@d = resample_certain(d);
%@
%@saveresults(d)
%@
%@%% 5c Plot the proxy records
%@% plot-type options: mean, median, spaghetti
%@plotproxyrecords(d,'mean','95');
%@plotproxyrecords(d,'spaghetti');
%@
%@%% Output
%@if nargout >= 1
%@   varargout{1}=d.T_unc; % time uncertain results: depth, proxy, time matrix
%@end
%@if nargout >= 2
%@    varargout{2}=d.T_cert; % time certain results: age, proxy (mean of distr), age_error (std of time matrix),proxyerror (std of prx at mean time)
%@end
%@if nargout == 3
%@    varargout{3}=d;
%@end
%@%% 6 Final End Message
%@display('Age-Depth relationship determined!')
%@warning on
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __copraGUI.m__ -->
%@function copraGUI
%@% Graphical User Interface for COPRA
%@%
%@% REQUIREMENTS:
%@% - MATLAB 7.10 (R2010a) 
%@%   (not tested on earlier versions)
%@% - GUI Layout Toolbox
%@% For more information type
%@% >>help copra
%@%
%@%
%@    warning on
%@    % check if the GUI Layout Toolbox is installed
%@    v = ver;
%@    if ~any(strcmp('GUI Layout Toolbox', {v.Name})) 
%@        error(['You must install the GUI Layout Toolbox in order to use the',...
%@            ' graphical user interface of COPRA. Follow the instructions on the <a href="http://tocsy.pik-potsdam.de/copra.php">COPRA</a> webpage'...
%@            ' or download it directly from <a href="http://www.mathworks.com/matlabcentral/fileexchange/27758-gui-layout-toolbox">Mathworks</a>']);
%@    end
%@    
%@    % matlab version
%@    d. matlab_version = str2double(v(find(strcmp({v(:).Name},'MATLAB'))).Version);
%@    
%@    close all
%@    %% Definitions/ Default parameter setting
%@    
%@    d.agename = 'yr BP';
%@    d.depthname = 'Depth (mm)';
%@    d.am_commented = 0;
%@    d.samplename = 'some sample';
%@    d.proxyname = 'some proxy';
%@    d.removePts = [];
%@    d.incErr = [];
%@    d.gui = 1;
%@    
%@    
%@
%@    % set title bar colors
%@    colorScheme = [.1 .8 .1];
%@    
%@    % set GUI position
%@    normleft = 0.1;
%@    normbottom = 0.1;
%@    normwidth = 0.75;
%@    normheight = 0.75;
%@        
%@    % find version info in Contents.m and create startup info  
%@    
%@    if exist('Contents.m','file')
%@        fid = fopen('Contents.m');
%@        tmp_v = textscan(fid,'%s');
%@        for i = 1:length(tmp_v{1})        
%@            if strncmp(tmp_v{1}(i),'Version',7)           
%@                copra_version = cell2mat(tmp_v{1}(i+1));
%@                break
%@            end
%@        end
%@        fclose(fid);
%@        copra_title = ['COPRA v',copra_version,];
%@    else
%@         copra_title= ['COPRA'];
%@    end
%@    
%@    
%@    
%@    % Main layout, divided in top and bottom part
%@    h.fig = figure('name',copra_title,'NumberTitle','off','MenuBar','none','ToolBar','figure',...
%@        'Units','Normalized','Position',[normleft normbottom normwidth normheight],'Visible','off','ResizeFcn',{@figResize});  
%@    
%@        
%@    % determine GUI extent
%@    d.figPos = getpixelposition(h.fig);
%@    d.figHeight = d.figPos(4);
%@    
%@    % remove toolbar items which are not needed
%@    toolbarMod1 = findall(h.fig);
%@    tM2 = findall(toolbarMod1,'ToolTipString','Save Figure');
%@    tM3 = findall(toolbarMod1,'ToolTipString','Edit Plot');
%@    tM4 = findall(toolbarMod1,'ToolTipString','New Figure');
%@    tM5 = findall(toolbarMod1,'ToolTipString','Open File');
%@    tM6 = findall(toolbarMod1,'ToolTipString','Print Figure');
%@    tM7 = findall(toolbarMod1,'ToolTipString','Link Plot');
%@    tM8 = findall(toolbarMod1,'ToolTipString','Insert Colorbar');
%@    tM9 = findall(toolbarMod1,'ToolTipString','Insert Legend');
%@    tM10 = findall(toolbarMod1,'ToolTipString','Hide Plot Tools');
%@    tM11 = findall(toolbarMod1,'ToolTipString','Show Plot Tools and Dock Figure');
%@    set([tM2,tM3,tM4,tM5,tM6,tM7,tM8,tM9,tM10,tM11],'Visible','Off')
%@    
%@    
%@    setappdata(h.fig,'d',d);
%@    
%@    h.mainLayout = uiextras.VBox('Parent', h.fig);
%@    
%@    h.mainLayoutTop = uiextras.HBox('Parent', h.mainLayout);
%@    h.mainLayoutBot = uiextras.HBox('Parent', h.mainLayout);  
%@    
%@    
%@    %% Input, top left panel (1)
%@    h.dataLayout = uiextras.VBox('Parent',h.mainLayoutTop);
%@    h.dataPanel = uiextras.BoxPanel('Parent',h.dataLayout,'Title','1. Input data','FontSize',12,'FontWeight','bold',...
%@        'TitleColor',colorScheme);
%@    h.dataInput = uiextras.VBox('Parent',h.dataPanel);
%@    h.dataButton = uiextras.VBox('Parent',h.dataLayout);
%@    
%@        
%@    % load age-depth data 
%@    h.load_AD_panel = uiextras.Panel('Parent',h.('dataInput'),'Title','Load Age-Depth data','FontWeight','bold');
%@    h.load_AD_layout = uiextras.HBox('Parent',h.('load_AD_panel'),'Spacing', 2);
%@    h.load_AD_box = uicontrol('parent',h.('load_AD_layout'),'Style','edit','units','normalized','BackgroundColor','white',...
%@                            'HorizontalAlignment','left');
%@    h.load_AD_button = uicontrol('parent',h.('load_AD_layout'),'style','pushbutton',...
%@                            'string', '...','FontWeight','bold');
%@    
%@    set(h.load_AD_layout,'Sizes', [-1 40],'Spacing', 5);
%@    
%@    % load proxy data                     
%@    h.load_proxy_panel = uiextras.Panel('Parent',h.('dataInput'),'Title','Load proxy data','FontWeight','bold');
%@    h.load_proxy_layout = uiextras.HBox('Parent',h.('load_proxy_panel'),'Spacing', 2);
%@    h.load_proxy_box = uicontrol('parent',h.('load_proxy_layout'),'Style','edit','units','normalized','BackgroundColor','white',...
%@                            'HorizontalAlignment','left');
%@    h.load_proxy_button = uicontrol('parent',h.('load_proxy_layout'),'style','pushbutton',...
%@                            'string', '...','FontWeight','bold');
%@    set(h.load_proxy_layout,'Sizes', [-1 40],'Spacing', 5);
%@                        
%@          
%@    % load layer count data      
%@    h.load_lc_panel = uiextras.Panel('Parent',h.('dataInput'),'Title','Load layer count data','FontWeight','bold');
%@    h.load_lc_layout = uiextras.Grid('Parent',h.('load_lc_panel'),'Spacing', 1); 
%@    h.load_lc_checkbox = uicontrol('Parent',h.('load_lc_layout'),'String','Load layer count data?','Style','checkbox');  
%@    h.load_lc_box = uicontrol('Parent',h.('load_lc_layout'),'Style','edit','units','normalized','BackgroundColor','white',...
%@                            'HorizontalAlignment','left','enable','off');
%@    uiextras.Empty( 'Parent', h.('load_lc_layout'));
%@    h.load_lc_button = uicontrol('Parent',h.('load_lc_layout'),'style','pushbutton',...
%@                            'string', '...','FontWeight','bold','enable','off');     
%@    set(h.load_lc_layout,'ColumnSizes', [-1 40],'RowSizes', [20 25]);   
%@    
%@    % Interpolation method
%@    h.interpMethod_panel = uiextras.Panel('Parent',h.('dataInput'),'Title','Interpolation method','FontWeight','bold');
%@    h.interpMethod = uicontrol('Parent',h.('interpMethod_panel'),'Style','popupmenu','string','PCHIP|Linear|Spline',...
%@            'HorizontalAlignment','right','Units','Normalized','BackgroundColor','white');
%@    
%@    % name the sample and the proxy
%@    h.sample_name_panel = uiextras.Panel('Parent',h.('dataInput'),'Title','Sample name','FontWeight','bold');
%@    h.sample_name_input = uicontrol('parent',h.('sample_name_panel'),'Style','edit','units','normalized','BackgroundColor','white',...
%@                            'HorizontalAlignment','left','String','Sample');
%@    h.proxy_name_panel = uiextras.Panel('Parent',h.('dataInput'),'Title','Proxy','FontWeight','bold');
%@    h.proxy_name_input = uicontrol('parent',h.('proxy_name_panel'),'Style','edit','units','normalized','BackgroundColor','white',...
%@        'HorizontalAlignment','left','String','Proxy');
%@    
%@    % number of MC
%@     h.No_MC = uiextras.Panel('Parent',h.('dataInput'),'Title','Number of MC:','FontWeight','bold');     
%@     h.MC_input = uicontrol('Parent',h.('No_MC'),'Style','edit','string','2000',...
%@            'HorizontalAlignment','right','Units','Normalized','BackgroundColor','white');
%@    
%@    % start the simulation    
%@    h.go_button = uicontrol('Parent',h.('dataButton'),'style','pushbutton',...
%@                           'string', 'Continue','FontWeight','bold','FontSize',9);  
%@                                                                    
%@    % set input layout structure   
%@    if d.figHeight < 700 % make sure the text stays in the panel for low res
%@        set(h.dataInput,'Sizes', [-1 -1 -1.5 -1 -1 -1 -1],'Spacing', 5);    
%@    else        
%@        set(h.dataInput,'Sizes', [36 36 54 36 36 36 36],'Spacing', 5);
%@    end
%@    
%@    set(h.dataLayout,'Sizes', [-1 30],'Spacing', 0);
%@
%@    %% plot age-depth data, top centre panel (2)
%@    h.plot_AD_layout = uiextras.VBox('Parent', h.mainLayoutTop);
%@    h.plot_AD_panel = uiextras.BoxPanel('Parent',h.plot_AD_layout,'Title',...
%@        '2. Modify Age-depth data','FontSize',12,'FontWeight','bold','TitleColor',colorScheme);
%@    h.plot_AD_buttbox = uiextras.HBox('Parent',h.plot_AD_layout);
%@    h.plot_AD_removePts = uicontrol('Parent',h.('plot_AD_buttbox'),'style','pushbutton',...
%@        'string', 'Remove points','enable','off'); 
%@    h.plot_AD_incErr = uicontrol('Parent',h.('plot_AD_buttbox'),'style','pushbutton',...
%@        'string', 'Increase error bars','enable','off');  
%@    h.plot_AD_hiatus = uicontrol('Parent',h.('plot_AD_buttbox'),'style','pushbutton',...
%@        'string', 'Add hiatus','enable','off');          
%@    h.plot_AD_reset = uicontrol('Parent',h.('plot_AD_buttbox'),'style','pushbutton',...
%@        'string', 'Reset','enable','off'); 
%@    h.plot_AD_process = uicontrol('Parent',h.('plot_AD_buttbox'),'style','pushbutton',...
%@        'string','Construct Agemodel','FontWeight','bold','FontSize',9,'enable','off'); 
%@   
%@    %% make figure visible
%@    % can not do it earlier, otherwise HG2 (2014b and newer) will lead to
%@    % error
%@    % can also not doing to late, java objects might not be initialized
%@    % before use... ahahha!?!?!?
%@    %drawnow
%@    set(h.fig,'Visible','on');
%@    
%@     
%@    %% get java handle of the Hiatus button to make it more powerful!
%@    % this needs to be done AFTER the GUI is made visible
%@    % findjobj relies on unsupported and undocumented MATLAB, should be
%@    % watched in future MATLAB releases
%@    jh_hiatus = findjobj(h.plot_AD_hiatus);
%@       
%@    set(h.plot_AD_layout,'Sizes', [-1 30], 'Spacing', 0);
%@    
%@    
%@    
%@    %% plot agemodel, top right panel (3)
%@    h.plot_AM_layout = uiextras.VBox('Parent', h.mainLayoutTop);
%@    h.plot_AM_panel = uiextras.BoxPanel('Parent',h.plot_AM_layout,'Title','3. Agemodel Plot',...
%@        'FontSize',12,'FontWeight','bold','TitleColor',colorScheme);  
%@    h.plot_AM_button = uicontrol('Parent',h.('plot_AM_layout'),'style','pushbutton',...
%@        'string','Construct Proxy Record','FontWeight','bold','FontSize',9,'enable','off');
%@    
%@    set(h.plot_AM_layout,'Sizes', [-1 30], 'Spacing', 0);
%@
%@    %% plot proxy record, bottom left panel (4)
%@    h.plot_PR_panel = uiextras.BoxPanel('Parent',h.mainLayoutBot,'Title','4. Proxy record Plot',...
%@        'FontSize',12,'FontWeight','bold','TitleColor',colorScheme);
%@    %% plot and export options, bottom right panel (top, 5)
%@    h.options_export_box = uiextras.VBox('Parent',h.mainLayoutBot);
%@    
%@    h.options_panel = uiextras.BoxPanel('Parent',h.('options_export_box'),'Title','5. Options',...
%@        'FontSize',12,'FontWeight','bold','TitleColor',colorScheme);
%@    h.options_layout = uiextras.VBox('Parent',h.('options_panel'));
%@    
%@    % enter confidence bounds
%@    % attention: this relies on two undocumented matlab utilities:
%@    % uiflowcontainer and javacomponent (which is used by uicomponent). The
%@    % functions might be changed or even removed in future matlab releases 
%@    
%@    h.confboundsAgeLayout = uiflowcontainer('v0','Parent', h.('options_layout'));
%@    
%@    h.confboundsAgeText = uicontrol('Parent',h.confboundsAgeLayout,'String','Age confidence interval:','Style','text',...
%@        'HorizontalAlignment','left','FontWeight','bold','FontSize',9.2);     
%@    % use uicomponent for editable drop down menu
%@    h.confboundsAgeInput = uicomponent('Parent',h.confboundsAgeLayout,'style','JComboBox',{'95','99','90'},'editable',true); 
%@    %h.confboundsAgeInput = uicontrol('parent',h.('confboundsAgeLayout'),'Style','popupmenu','String','95|99|90',...
%@    %    'BackgroundColor','white');    
%@    h.confboundsAgeUnit = uicontrol('Parent',h.confboundsAgeLayout,'Style','text',...
%@        'String','%');
%@    
%@           
%@    set(h.confboundsAgeText, 'WidthLimits',[2,inf])
%@    set(h.confboundsAgeInput, 'WidthLimits',[35,35])
%@    set(h.confboundsAgeUnit, 'WidthLimits',[10,10])
%@    
%@    
%@    h.confboundsProxyLayout = uiflowcontainer('v0','Parent', h.('options_layout'));
%@    
%@    h.confboundsProxyText = uicontrol('Parent',h.('confboundsProxyLayout'),'String','Proxy confidence interval:','Style','text',...
%@        'HorizontalAlignment','left','FontWeight','bold','Fontsize',9.2);     
%@    % use uicomponent for editable drop down menu
%@    h.confboundsProxyInput = uicomponent('Parent',h.confboundsProxyLayout,'style','JComboBox',{'95','99','90'},'editable',true); % editable drop-down
%@    %h.confboundsProxyInput = uicontrol('Parent',h.('confboundsProxyLayout'),'Style','edit',...
%@    %    'String','95','BackgroundColor','white');    
%@    h.confboundsProxyUnit = uicontrol('Parent',h.('confboundsProxyLayout'),'Style','text',...
%@        'String','%');
%@    
%@    set(h.confboundsProxyText, 'WidthLimits',[2,inf])
%@    set(h.confboundsProxyInput, 'WidthLimits',[35,35])
%@    set(h.confboundsProxyUnit, 'WidthLimits',[10,10])   
%@    
%@       
%@    % choose the plot-type for agemodel
%@    plotType_AM_box = uiextras.Panel('Parent',h.('options_layout'),'Title','Plot type Agemodel','FontSize',10, 'FontWeight','bold');
%@    h.plotType_AM_menu = uicontrol('parent',plotType_AM_box,'Style','popupmenu','String','Spaghetti|Mean|Median|Grayscale',...
%@        'BackgroundColor','white');
%@    
%@    % choose the plot-type for proxy record    
%@    plotType_PR_box = uiextras.Panel('Parent',h.('options_layout'),'Title','Plot type Proxy Record','FontSize',10, 'FontWeight','bold');
%@    
%@    % change this bit for new Matlab version for now, because it can not
%@    % handle mean and median plots, unclear why
%@    if d.matlab_version < 8.4  
%@        h.plotType_PR_menu = uicontrol('parent',plotType_PR_box,'Style','popupmenu','String','Median|Mean|Spaghetti',...
%@            'BackgroundColor','white');
%@    else
%@        h.plotType_PR_menu = uicontrol('parent',plotType_PR_box,'Style','popupmenu','String','Spaghetti|Median|Mean',...
%@            'BackgroundColor','white');
%@    end
%@    % refresh button
%@    h.plotType_refresh = uicontrol('Parent',h.('options_export_box'),'style','pushbutton',...
%@        'string', 'Refresh','FontWeight','bold','enable','off'); 
%@    
%@    set(h.options_layout,'Sizes',[20 20 40 40],'Spacing', 2); 
%@      
%@  
%@    %% export data, bottom right panel (bottom, 6)
%@    h.export_panel = uiextras.BoxPanel('Parent',h.('options_export_box'),'Title','6. Export',...
%@        'FontSize',12,'FontWeight','bold','TitleColor',colorScheme);
%@    h.export_layout = uiextras.VBox('Parent', h.export_panel);    
%@    h.export_results_butt = uicontrol('Parent',h.('export_layout'),'style','pushbutton',...
%@        'string', 'Export results table','FontWeight','bold','FontSize',9,'enable','off'); 
%@    h.export_fig_butt_AM = uicontrol('Parent',h.('export_layout'),'style','pushbutton',...
%@        'string', 'Export Agemodel plot','FontWeight','bold','FontSize',9,'enable','off'); 
%@    h.export_fig_butt_PR = uicontrol('Parent',h.('export_layout'),'style','pushbutton',...
%@        'string', 'Export Proxy Record plot','FontWeight','bold','FontSize',9,'enable','off'); 
%@    h.export_log_butt = uicontrol('Parent',h.('export_layout'),'style','pushbutton',...
%@        'string', 'Export logfile','FontWeight','bold','FontSize',9,'enable','off'); 
%@    h.export_data_butt = uicontrol('Parent',h.('export_layout'),'style','pushbutton',...
%@        'string', 'Export data structure','FontWeight','bold','FontSize',9,'enable','off'); 
%@       
%@    set(h.options_export_box,'Sizes',[-1 30 150],'Spacing', 2); 
%@      
%@    %% set main layout structure
%@    set(h.mainLayoutTop,'Sizes', [200 -1 -1],'Spacing', 5);
%@    set(h.mainLayoutBot,'Sizes', [-1 210],'Spacing', 5);
%@    set(h.mainLayout,'Sizes', [-1 -1],'Spacing', 1);
%@    
%@        
%@    %% set button callbacks etc   
%@    hiatus_tooltip = '<html>Add a hiatus:<br>Left click: Graphically (Adjust line using the cursor)<br>Ctrl + Left Click: Numerically';
%@    set(h.plot_AD_hiatus,'tooltip', hiatus_tooltip) 
%@    
%@    set(h.load_AD_button,'callback', {@browseAD, h}); % call file dialog for AD file
%@    set(h.load_proxy_button,'callback', {@browseProxy, h}); % call file dialog for proxy file
%@    set(h.load_lc_checkbox,'callback', {@checkLC, h}); % check LC data yes/no
%@    set(h.load_lc_button,'callback', {@browseLC, h}); % call file dialog for lc file
%@    set(h.go_button,'callback', {@continueButt1, h}) % continue to panel 2
%@    set(h.plot_AD_removePts,'callback', {@remove, h}) % %remove points
%@    set(h.plot_AD_incErr,'callback', {@increase, h}) % increase error bars    
%@    set(jh_hiatus,'MousePressedCallback',{@setHiatus, h}) % set hiatus   
%@    set(h.plot_AD_process,'callback', {@processAges, h}) % construct agemodel
%@    set(h.plot_AD_reset,'callback', {@resetFct, h}) % reset points
%@    set(h.plot_AM_button,'callback', {@constructProxy, h}) % construct proxy records
%@    set(h.plotType_refresh,'callback', {@refreshPlots, h}) % refresh plots
%@    set(h.export_results_butt,'callback', {@exportResultsButt, h}) % export data
%@    set(h.export_fig_butt_AM,'callback', {@exportFigButtAM, h}) % export agemodel plot
%@    set(h.export_fig_butt_PR,'callback', {@exportFigButtPR, h}) % export proxy record plot
%@    set(h.export_log_butt,'callback', {@exportLog, h}) % export logfile    
%@    set(h.export_data_butt,'callback', {@exportData, h}) % export logfile 
%@    
%@        
%@          
%@    % limit GUI extent
%@    % needs to come AFTER the was made visible 
%@    LimitSizeFig(h.fig,'min',[750, 666])
%@    
%@    %% Callback events
%@    % these are the functions which are called upon pressing the various
%@    % buttons
%@    
%@    function figResize(~, ~)         
%@        d.figPos = getpixelposition(h.fig);
%@        d.figHeight = d.figPos(4);
%@                
%@        if d.figHeight < 700 % make sure the text stays in the panel for low res
%@            set(h.dataInput,'Sizes', [-1 -1 -1.5 -1 -1 -1 -1],'Spacing', 5);            
%@        else
%@            set(h.dataInput,'Sizes', [36 36 54 36 36 36 36],'Spacing', 5);
%@        end
%@    end 
%@
%@    function browseAD(hObject,event,h)
%@        [fileAD, pathAD] = uigetfile({'*.txt';'*.csv'},'Select age-depth dataset','data');
%@        full_path_AD = strcat(pathAD,fileAD);
%@        setappdata(h.fig,'fullAD',full_path_AD)
%@        set(h.load_AD_box,'String',full_path_AD);
%@    end
%@
%@    function browseProxy(hObject,event,h)
%@        [fileProxy, pathProxy] = uigetfile({'*.txt';'*.csv'},'Select proxy dataset','data');
%@        full_path_proxy = strcat(pathProxy,fileProxy);
%@        setappdata(h.fig,'fullPRXY',full_path_proxy)
%@        set(h.load_proxy_box,'String',full_path_proxy);
%@    end
%@
%@        
%@     
%@    function checkLC(hObject,event, h)
%@        val = get(h.load_lc_checkbox,'value');
%@       
%@        if val
%@            set(h.load_lc_box,'enable','on')
%@            set(h.load_lc_button,'enable','on')
%@        else
%@            set(h.load_lc_box,'enable','off')
%@            set(h.load_lc_button,'enable','off')            
%@        end
%@        
%@        setappdata(h.fig,'d',d)
%@    end
%@
%@    function browseLC(hObject,event,h)
%@        [fileLC, pathLC] = uigetfile({'*.txt';'*.csv'},'Select layer count dataset','data');
%@        full_path_lc = strcat(pathLC, fileLC);
%@        setappdata(h.fig,'fullLC',full_path_lc)
%@        set(h.load_lc_box,'String',full_path_lc);
%@    end
%@
%@    function continueButt1(hObject, event, h)
%@        d = getappdata(h.fig,'d');        
%@               
%@        d.filenameAD = getappdata(h.fig,'fullAD');
%@        d.filenameProxy = getappdata(h.fig,'fullPRXY');
%@        d.filenameLC = getappdata(h.fig,'fullLC');
%@        d.samplename = get(h.sample_name_input,'string');
%@        d.proxyname = get(h.proxy_name_input,'string');        
%@              
%@        % refresh buttons             
%@        set(h.plot_AM_button,'enable','off')
%@        set(h.export_results_butt,'enable','off'); 
%@        set(h.export_fig_butt_AM,'enable','off'); 
%@        set(h.export_fig_butt_PR,'enable','off');
%@        set(h.plotType_refresh,'enable','off');   
%@        set(h.export_log_butt,'enable','off');
%@        set(h.export_data_butt,'enable','off');
%@        
%@        d.hia_counter = 0;
%@        d.hia_counter_numIn = 0;
%@        d.cursorbar = [];
%@        
%@        % reset plots
%@        allAxes = findall(h.fig,'type','axes');
%@        
%@        for i = 1:length(allAxes)
%@            cla(allAxes(i));
%@            set(allAxes(i),'visible','off');
%@        end
%@        
%@        h.AD_axes = axes('Parent',h.('plot_AD_panel'));
%@                                
%@        d = GUI_loaddata(d);       
%@        
%@        if any(d.bad_input)
%@            
%@            % disable buttons
%@            set(h.plot_AD_removePts,'enable','off'); 
%@            set(h.plot_AD_incErr,'enable','off');  
%@            set(h.plot_AD_hiatus,'enable','off');        
%@            set(h.plot_AD_reset,'enable','off'); 
%@            set(h.plot_AD_process,'enable','off');
%@            
%@        else
%@            % enable buttons
%@            set(h.plot_AD_removePts,'enable','on'); 
%@            set(h.plot_AD_incErr,'enable','on');  
%@            set(h.plot_AD_hiatus,'enable','on');        
%@            set(h.plot_AD_reset,'enable','on'); 
%@            set(h.plot_AD_process,'enable','on'); 
%@            
%@            valLC = get(h.load_lc_checkbox,'value');
%@            
%@            if valLC
%@                d.adinf = 1;
%@                d.dlc = GUI_getlayercount(d);
%@            else
%@                d.dlc=[];
%@                d.adinf = 0;
%@            end
%@            
%@            % initializations
%@            d.hiatus = zeros(size(d.age));
%@            d.hiatus(end) = 1; 
%@            d.hia_depth = [];            
%@            d.hia_depth_numIn = [];
%@            d.rev_treat = zeros(size(d.age));
%@            
%@            % plot dataset  
%@            GUI_plotAD(d);
%@            
%@            setappdata(h.fig,'d',d);  
%@            guidata(hObject, h);
%@        end
%@    end
%@
%@    function remove(hObject,event,h)
%@        d = getappdata(h.fig,'d');  
%@        h = guidata(hObject);
%@        removePts = newid('Enter the numbers of points you would like to have removed (seperated by SPACE):', 'Point removal', [1 50]);
%@        
%@        if any(size(removePts)) 
%@            removePts = str2num(removePts{:});  
%@            
%@            % remove selected points
%@            d.rev_treat(removePts) = 1;
%@            
%@            for i = 1:length(removePts)
%@                removeID(i) = find(d.id==removePts(i));
%@            end                   
%@            
%@            % save information about all points that were removed for
%@            % logfile
%@            d.removePts(end+1:end+length(removePts)) = removePts;
%@            
%@            % backup unmodified data
%@            if ~exist('d.depth_backup','var')
%@                d.depth_backup = d.depth;
%@                d.age_backup = d.age;
%@                d.ageerror_backup = d.ageerror;
%@                d.id_backup = d.id;
%@            end
%@            
%@            % delete entries of removed points
%@            d.depth(removeID) = [];
%@            d.age(removeID) = [];
%@            d.ageerror(removeID) = [];
%@            d.id(removeID) = [];
%@            d.hiatus(removeID) = [];   
%@            
%@        end
%@        
%@        % plot modified data
%@        axes(h.AD_axes); cla;
%@        GUI_plotAD(d);
%@        
%@        guidata(hObject,h)
%@        setappdata(h.fig,'d',d);        
%@    end
%@
%@    function increase(hObject,event,h)
%@        d = getappdata(h.fig,'d');
%@        h = guidata(hObject);
%@        incErr = newid('Enter the numbers of points of which you would like to increase errors by 10% (seperated by SPACE):', 'Increase error bars', [1 50]);
%@        
%@        if any(size(incErr))
%@            incErr = str2num(incErr{:});   
%@            d.rev_treat(incErr) = 2;
%@            
%@            % increase selected errorbars
%@            for i = 1:length(incErr)
%@                incErrID(i) = find(d.id==incErr(i));
%@            end
%@            
%@            if any(incErrID)
%@                d.ageerror(incErrID) = d.ageerror(incErrID)*1.1;
%@            end
%@            
%@            % save information about all points that were removed for
%@            % logfile
%@            d.incErr(end+1:end+length(incErr)) = incErr;
%@            
%@            % plot modified data
%@            axes(h.AD_axes); cla;
%@            GUI_plotAD(d);
%@            
%@            guidata(hObject,h)
%@            setappdata(h.fig,'d',d);     
%@        end
%@    end
%@
%@    function setHiatus(hObject,event,h)
%@        d = getappdata(h.fig,'d'); 
%@        h = guidata(h.plot_AD_hiatus);
%@        
%@               
%@       
%@        if d.matlab_version < 8.4
%@            % find out how the button was clicked
%@            clickType = get(get(hObject,'MousePressedCallbackData'),...
%@                'modifiers');
%@            
%@            switch clickType
%@                case 18 % 18: ctrl + left mouse
%@                    hia_depth_str = newid('Enter hiatus depth (in mm) (if several: seperated by SPACE):', 'Enter Hiatus(es)', [1 50]);
%@                    
%@                    if any(size(hia_depth_str));
%@                        hia_depth_numIn = str2num(hia_depth_str{:});
%@                        
%@                        hia_counter_numIn_old = d.hia_counter_numIn;
%@                        d.hia_counter_numIn = hia_counter_numIn_old + length(hia_depth_numIn) ;
%@                        d.hia_depth_numIn(hia_counter_numIn_old+1:hia_counter_numIn_old+length(hia_depth_numIn)) = hia_depth_numIn;
%@                        
%@                        % plot the dataset including hiatus
%@                        axes(h.AD_axes); cla;
%@                        GUI_plotAD(d);
%@                    end
%@                    
%@                otherwise
%@                    d.hia_counter = d.hia_counter + 1;
%@                    
%@                    set(h.fig,'CurrentPoint',[0 0]) % it is necessary to reset the current point away from the h.AD_axes for the cursorbar
%@                    % define Hiatus depth using the cursorbar. This is an
%@                    % undocuemented and unsupported object, should be watched
%@                    % in future MATLAB releases.
%@                    cursorbar = graphics.cursorbar(h.AD_axes); drawnow; %,'Position', [1 200]); drawnow
%@                    cursorbar.CursorLineColor = [1,0,0]; % default=[0,0,0]='k'
%@                    cursorbar.CursorLineStyle = '--';       % default='-'
%@                    cursorbar.CursorLineWidth = 0.5;        % default=1
%@                    cursorbar.Orientation = 'horizontal';     % =default
%@                    cursorbar.BottomMarker = 'none';
%@                    cursorbar.TopMarker = 'none';
%@                    %datacursormode on
%@                    
%@                    d.cursorbar(d.hia_counter) = cursorbar;
%@            end   
%@        else
%@            hia_depth_str = newid('Enter hiatus depth (in mm) (if several: seperated by SPACE):', 'Enter Hiatus(es)', [1 50]);
%@            
%@            if any(size(hia_depth_str));
%@                hia_depth_numIn = str2num(hia_depth_str{:});
%@                
%@                hia_counter_numIn_old = d.hia_counter_numIn;
%@                d.hia_counter_numIn = hia_counter_numIn_old + length(hia_depth_numIn) ;
%@                d.hia_depth_numIn(hia_counter_numIn_old+1:hia_counter_numIn_old+length(hia_depth_numIn)) = hia_depth_numIn;
%@                
%@                % plot the dataset including hiatus
%@                axes(h.AD_axes); cla;
%@                GUI_plotAD(d);
%@            end                 
%@                                            
%@            
%@        end
%@        setappdata(h.fig,'d',d);
%@        guidata(h.plot_AD_hiatus, h);
%@    
%@    end
%@
%@    function resetFct(hObject,event,h)       
%@        d = getappdata(h.fig,'d');
%@        %h = guidata(hObject);
%@             
%@        % reset plots
%@        allAxes = findall(h.fig,'type','axes');
%@        
%@        for i = 1:length(allAxes)
%@            cla(allAxes(i));
%@            set(allAxes(i),'visible','off');
%@        end
%@        
%@        % disable buttons
%@        set(h.plot_AM_button,'enable','off')
%@        set(h.export_results_butt,'enable','off'); 
%@        set(h.export_fig_butt_AM,'enable','off'); 
%@        set(h.export_fig_butt_PR,'enable','off');
%@        set(h.plotType_refresh,'enable','off');   
%@        set(h.export_log_butt,'enable','off');
%@        set(h.export_data_butt,'enable','off');
%@      
%@        
%@        d = GUI_loaddata(d);               
%@         
%@        
%@        % reset data
%@        if exist('d.depth_backup','var')
%@            d.depth = d.depth_backup;
%@            d.age = d.age_backup;
%@            d.ageerror = d.ageerror_backup;
%@            d.id = d.id_backup;
%@        end
%@                   
%@        d.hiatus = zeros(size(d.age));
%@        d.hiatus(end) = 1;
%@        d.hia_depth = [];
%@        d.hia_depth_numIn = [];
%@        d.removePts = [];
%@        d.incErr = [];
%@        d.rev_treat = zeros(size(d.age));
%@        d.hia_counter = 0;
%@        d.hia_counter_numIn = 0;
%@        d.cursorbar = []; 
%@                
%@        
%@        % plot
%@        h.AD_axes = axes('Parent',h.('plot_AD_panel'));        
%@        GUI_plotAD(d);
%@        
%@        setappdata(h.fig,'d',d);
%@        guidata(hObject,h)
%@    end
%@        
%@    function processAges(hObject,event,h)
%@        d = getappdata(h.fig,'d'); 
%@        
%@        length_hia_numIn = length(d.hia_depth_numIn);
%@        
%@        % get hiatuses from numerical input
%@        for i = 1:length_hia_numIn
%@            d.hia_depth = d.hia_depth_numIn;
%@        end
%@        
%@        % get hiatuses from graphical input
%@        for i = 1:d.hia_counter
%@            d.cursPos = get(d.cursorbar(i),'Position'); % get the cursorbar position
%@            d.hia_depth(length_hia_numIn + i) = d.cursPos(2); % get y-value (depth) of the position
%@        end
%@            
%@        d.hia_depth = sort(d.hia_depth);
%@                 
%@        cla(axes('Parent',h.('plot_PR_panel')));
%@        set(axes('Parent',h.('plot_PR_panel')),'visible','off');
%@            
%@        if any(d.hia_depth)
%@            d = GUI_specifyHiatus(d);
%@        else
%@            d.hiatus = zeros(size(d.age));
%@            d.hiatus(end) = 1;
%@            d.hia_depth = [];
%@            d.hia_depth_numIn = [];
%@        end
%@        
%@        % get parameters
%@        d.confbnds_age = str2double(h.confboundsAgeInput.JavaComponent.getSelectedItem);
%@        d.confbnds_prxy = str2double(h.confboundsProxyInput.JavaComponent.getSelectedItem);
%@        d.M = eval(get(h.MC_input,'String')); 
%@        
%@        interpMethod_list = cellstr(get(h.interpMethod,'string'));
%@        d.interp_method = lower(interpMethod_list{get(h.interpMethod,'value')});
%@                
%@        % plot types
%@        plotType_AM_list = cellstr(get(h.plotType_AM_menu,'string')); 
%@        plotType_AM = plotType_AM_list{get(h.plotType_AM_menu,'value')};       
%@        
%@                    
%@               
%@        d.revType = chkRevs(d);
%@                     
%@        d = mcagemodels(d);
%@        
%@        
%@        if ~d.cancelFlag
%@            d = resample_certain(d);
%@            
%@            % plot agemodel
%@            axes('Parent',h.('plot_AM_panel'));
%@            hold on
%@            plotagemodel(d,plotType_AM,d.confbnds_age);                   
%@            %axis tight
%@            hold off
%@            
%@            set(h.plot_AM_button,'enable','on')
%@            set(h.export_results_butt,'enable','off'); 
%@            set(h.export_fig_butt_AM,'enable','off'); 
%@            set(h.export_fig_butt_PR,'enable','off'); 
%@            set(h.export_log_butt,'enable','off');
%@            set(h.export_data_butt,'enable','off');
%@            set(h.plotType_refresh,'enable','off');  
%@            setappdata(h.fig,'d',d)
%@            
%@        else
%@            % reset plots
%@            cla(axes('Parent',h.('plot_AM_panel')));
%@            cla(axes('Parent',h.('plot_PR_panel')));
%@            
%@            
%@            % disable buttons
%@            set(h.plot_AM_button,'enable','off')
%@            set(h.export_results_butt,'enable','off'); 
%@            set(h.export_fig_butt_AM,'enable','off'); 
%@            set(h.export_fig_butt_PR,'enable','off');
%@            set(h.export_log_butt,'enable','off');
%@            set(h.export_data_butt,'enable','off');
%@            set(h.plotType_refresh,'enable','off');   
%@        end
%@          
%@        setappdata(h.fig,'d',d);
%@             
%@    end
%@    
%@
%@
%@    function constructProxy(hObject,event,h)
%@        d = getappdata(h.fig,'d');                
%@        
%@        d.confbnds_prxy = str2double(h.confboundsProxyInput.JavaComponent.getSelectedItem);
%@        
%@        % plot types           
%@        plotType_PR_list = cellstr(get(h.plotType_PR_menu,'string')); 
%@        d.plotType_PR = plotType_PR_list{get(h.plotType_PR_menu,'value')};           
%@                
%@        % plot proxy record
%@        axes('Parent',h.('plot_PR_panel'));
%@        hold on
%@        plotproxyrecords(d,d.plotType_PR,d.confbnds_prxy);        
%@        axis tight
%@        hold off
%@        
%@        set(h.plotType_refresh,'enable','on');        
%@        set(h.export_results_butt,'enable','on'); 
%@        set(h.export_fig_butt_AM,'enable','on'); 
%@        set(h.export_fig_butt_PR,'enable','on'); 
%@        set(h.export_log_butt,'enable','on');
%@        set(h.export_data_butt,'enable','on');
%@        
%@        setappdata(h.fig,'d',d)
%@        
%@    end
%@
%@    function refreshPlots(hObject, event, h)        
%@        d = getappdata(h.fig,'d');  
%@        h = guidata(hObject);   % this is required so that e.g. h.AD_axes does not get lost
%@        
%@        d.samplename = get(h.sample_name_input,'string');
%@        d.proxyname = get(h.proxy_name_input,'string');     
%@                     
%@        d.confbnds_prxy = str2double(h.confboundsProxyInput.JavaComponent.getSelectedItem);
%@        d.confbnds_age = str2double(h.confboundsAgeInput.JavaComponent.getSelectedItem);
%@        
%@                
%@        % plot types
%@        plotType_AM_list = cellstr(get(h.plotType_AM_menu,'string')); 
%@        plotType_AM = plotType_AM_list{get(h.plotType_AM_menu,'value')};
%@        
%@        plotType_PR_list = cellstr(get(h.plotType_PR_menu,'string')); 
%@        d.plotType_PR = plotType_PR_list{get(h.plotType_PR_menu,'value')};
%@        
%@         
%@        % plots
%@        cla(axes('Parent',h.('plot_PR_panel')));
%@        cla(axes('Parent',h.('plot_AM_panel')));       
%@        
%@         % plot agemodel
%@        axes('Parent',h.('plot_AM_panel'));
%@        hold on
%@        plotagemodel(d,plotType_AM,d.confbnds_age); 
%@        %axis tight
%@        hold off
%@        
%@        
%@        % plot proxy record
%@        axes('Parent',h.('plot_PR_panel'));
%@        hold on
%@        plotproxyrecords(d,d.plotType_PR,d.confbnds_prxy);  
%@        axis tight
%@        hold off       
%@        
%@        setappdata(h.fig,'d',d)
%@        guidata(hObject,h)
%@        
%@    end
%@
%@    function exportResultsButt(hObject,event,h)
%@        d = getappdata(h.fig,'d');  
%@                        
%@        [fileEX_results, pathEX_results] = uiputfile('output/*.txt','Export results');
%@        d.full_path_EX_results = strcat(pathEX_results,fileEX_results);
%@        saveresults(d);
%@        
%@    end
%@
%@    function exportFigButtAM(hObject,event,h)
%@        d = getappdata(h.fig,'d'); 
%@        
%@        % check whether output folder exists (if not, create it)
%@        if ~exist('./output','dir')
%@            mkdir('./output')
%@        end
%@        
%@        [fileEX_AM, pathEX_AM] = uiputfile({'*.jpg';'*.bmp';'*.eps';'*.fig';'*.png';'*.tif';'*.pdf'},...
%@            'Export Agemodel plot','output');
%@        full_path_EX_AM = strcat(pathEX_AM,fileEX_AM);       
%@        
%@        plotType_AM_list = cellstr(get(h.plotType_AM_menu,'string')); 
%@        plotType_AM = plotType_AM_list{get(h.plotType_AM_menu,'value')};
%@
%@        
%@        if ~isequal(fileEX_AM,0) && ~isequal(pathEX_AM,0)
%@            exportFig = figure('name','Export Agemodel plot');
%@            % plot agemodel
%@            hold on
%@            plotagemodel(d,plotType_AM,d.confbnds_age);  
%@            axis tight
%@            hold off
%@            
%@            saveas(exportFig,full_path_EX_AM);
%@            close(exportFig)
%@        end
%@    end
%@
%@    function exportFigButtPR(hObject,event,h)
%@        d = getappdata(h.fig,'d'); 
%@        
%@        % check whether output folder exists (if not, create it)
%@        if ~exist('./output','dir')
%@            mkdir('./output')
%@        end
%@        
%@        [fileEX_PR, pathEX_PR] = uiputfile({'*.jpg';'*.bmp';'*.eps';'*.fig';'*.png';'*.tif'},...
%@            'Export Proxy records plot','output');
%@        full_path_EX_PR = strcat(pathEX_PR,fileEX_PR);  
%@                
%@        plotType_PR_list = cellstr(get(h.plotType_PR_menu,'string')); 
%@        plotType_PR = plotType_PR_list{get(h.plotType_PR_menu,'value')};
%@        
%@        if ~isequal(fileEX_PR,0) && ~isequal(pathEX_PR,0)                            
%@                        
%@            exportFig = figure('name','Export proxy record plot');
%@            
%@            % plot proxy record
%@            hold on
%@            plotproxyrecords(d,plotType_PR,d.confbnds_prxy);            
%@            axis tight
%@            hold off
%@            
%@            saveas(exportFig,full_path_EX_PR);
%@            close(exportFig)
%@        end
%@    end
%@
%@    function exportLog(hObject,event,h)
%@        d = getappdata(h.fig,'d'); 
%@        
%@        % check whether output folder exists (if not, create it)
%@        if ~exist('./output','dir')
%@            mkdir('./output')
%@        end
%@        
%@        [fileEX_log, pathEX_log] = uiputfile('*.m',...
%@            'Export Logfile','output');
%@        full_path_EX_log = strcat(pathEX_log,fileEX_log);
%@        
%@        if ~isequal(fileEX_log,0) && ~isequal(pathEX_log,0)                            
%@                        
%@            d.log = fileEX_log;
%@            logLoc = full_path_EX_log;
%@            fid = fopen(logLoc,'w');frewind(fid);fclose(fid); % overwrite old logifle if necessary
%@            GUI_writeLog(d);
%@            
%@        end
%@        
%@        
%@    end
%@
%@    function exportData(hObject,event,h)
%@        d = getappdata(h.fig,'d'); 
%@        
%@        % check whether output folder exists (if not, create it)
%@        if ~exist('./output','dir')
%@            mkdir('./output')
%@        end
%@        
%@        [fileEX_data, pathEX_data] = uiputfile('output/*.mat','Export data structure');
%@        d.full_path_EX_data = strcat(pathEX_data,fileEX_data);
%@        
%@        save(d.full_path_EX_data,'d');
%@        
%@          
%@        
%@    end
%@        
%@end
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __copraclean.m__ -->
%@function copraclean
%@%COPRACLEAN   Removes COPRA.
%@%    COPRACLEAN removes all files of COPRA from
%@%    the filesystem and its entry from the Matlab
%@%    startup file.
%@%    
%@%    This installation script was generated by using 
%@%    the MAKEINSTALL tool. For further information
%@%    visit http://matlab.pucicu.de
%@
%@% Copyright (c) 2008-2015
%@% Norbert Marwan, Potsdam Institute for Climate Impact Research, Germany
%@% http://www.pik-potsdam.de
%@%
%@% Copyright (c) 2002-2008
%@% Norbert Marwan, Potsdam University, Germany
%@% http://www.agnld.uni-potsdam.de
%@%
%@% Generation date: 06-Sep-2016 14:11:56
%@% $Date: 2015/07/09 16:18:06 $
%@% $Revision: 3.35 $
%@
%@error(nargchk(0,0,nargin));
%@
%@try
%@  if isoctave
%@      more off
%@  end
%@  fid = 0;
%@  warning('off')
%@  disp('----------------------')
%@  disp('    REMOVING COPRA    ')
%@  disp('----------------------')
%@  currentpath=pwd;
%@  oldtoolboxpath = fileparts(which(mfilename));
%@
%@  disp(['  COPRA found in ', oldtoolboxpath,''])
%@  i = input('> Delete COPRA? Y/N [Y]: ','s');
%@  if isempty(i), i = 'Y'; end
%@
%@  if strcmpi('Y',i)
%@%%%%%%% check for entries in startup
%@  
%@        p=path; i1=0; i = ''; number_warnings_pathdef = 0;
%@  
%@        while findstr(upper('COPRA'),upper(p)) > i1
%@           i1=findstr(upper('COPRA'),upper(p));
%@           if ~isempty(i1)
%@               i1=i1(end);
%@               if isunix, i2=findstr(':',p); else, i2=findstr(';',p); end
%@               i3=i2(i2>i1);                 % last index pathname
%@               if ~isempty(i3), i3=i3(1)-1; else, i3=length(p); end
%@               i4=i2(i2<i1);                 % first index pathname
%@               if ~isempty(i4), i4=i4(end)+1; else, i4=1; end
%@               rmtoolboxpath=p(i4:i3);
%@%%%%%%% removing entry in startup-file
%@               rmpath(rmtoolboxpath)
%@               err = savepath;
%@               if number_warnings_pathdef == 0 && err, disp('  ** Warning: No write access to pathdef.m file!'), number_warnings_pathdef = number_warnings_pathdef+1; end
%@               if i4>1, p(i4-1:i3)=''; else, p(i4:i3)=''; end
%@               startup_exist = exist('startup','file');
%@               if isoctave startup_exist = exist(fullfile('~','.octaverc'),'file'); end
%@               if startup_exist
%@                    startupfile=which('startup');
%@                    startuppath=startupfile(1:findstr('startup.m',startupfile)-1);
%@                    if isoctave
%@                        startuppath = ['~',filesep];
%@                        startupfile = fullfile('~','.octaverc');
%@                    end
%@                    fid = fopen(startupfile,'r');
%@                    k = 1;
%@                    while 1
%@                       tmp = fgetl(fid);
%@                       if ~ischar(tmp), break, end
%@                       instpaths{k} = tmp;
%@                       k = k + 1;
%@                    end
%@                    k=1;
%@                    while k <= length(instpaths)
%@                        if ~isempty(findstr(rmtoolboxpath,instpaths{k}))
%@                            disp(['  Removing startup entry ', instpaths{k}])
%@                            instpaths(k)=[];
%@                        end
%@                        k=k+1;
%@                    end
%@                    fid=fopen(startupfile,'w');
%@                    for i2=1:length(instpaths), 
%@                        fprintf(fid,'%s\n', char(instpaths{i2})); 
%@                    end
%@                    fclose(fid);
%@               end
%@           end
%@           p = path; i1 = 0;
%@       end
%@%%%%%%% removing old paths
%@        if exist(oldtoolboxpath,'dir') == 7
%@           if isoctave, confirm_recursive_rmdir (false, 'local'); end
%@           disp(['  Removing files in ',oldtoolboxpath,''])
%@           cd(oldtoolboxpath)
%@           dirnames='';filenames='';
%@           temp='.:';
%@           while ~isempty(temp)
%@               [temp1 temp]=strtok(temp,':');
%@               if ~isempty(temp1)
%@                   dirnames=[dirnames; {temp1}];
%@                   x2=dir(temp1);
%@                   for i=1:length(x2)
%@                       if ~x2(i).isdir, filenames=[filenames; {[temp1,'/', x2(i).name]}]; end
%@         	             if x2(i).isdir && ~strcmp(x2(i).name,'.') && ~strcmp(x2(i).name,'..'), temp=[temp,temp1,filesep,x2(i).name,':']; end
%@                   end
%@               end
%@           end
%@           dirnames = strrep(dirnames,['.',filesep],'');
%@           dirnames(strcmpi('.',dirnames)) = [];
%@           l = zeros(length(dirnames),1); for i=1:length(dirnames),l(i)=length(dirnames{i}); end
%@           [i i4]=sort(l); i4 = i4(:);
%@           dirnames=dirnames(flipud(i4));
%@           for i=1:length(dirnames)
%@              delete([dirnames{i}, filesep,'*'])
%@              if exist('rmdir') == 5 && exist(dirnames{i}) == 7, rmdir(dirnames{i},'s'); else, delete(dirnames{i}), end
%@              disp(['  Removing files in ',char(dirnames{i}),''])
%@           end
%@           if exist(currentpath), cd(currentpath), else, cd .., end
%@           if strcmpi(currentpath,oldtoolboxpath), cd .., end
%@           if exist('rmdir') == 5 && exist(oldtoolboxpath) == 7, rmdir(oldtoolboxpath,'s'); else, delete(oldtoolboxpath), end
%@           disp(['  Removing folder ',oldtoolboxpath,''])
%@        end
%@       disp(['  COPRA now removed.'])
%@  else
%@       disp(['  Nothing happened. Keep smiling.'])
%@  end
%@  tx=version; tx=strtok(tx,'.'); if str2double(tx)>=6 && exist('rehash','builtin'), rehash, end
%@  warning on
%@  if isoctave
%@      more on
%@  end
%@  if exist(currentpath,'dir') ~= 7, cd(fileparts(currentpath)), else, cd(currentpath), end
%@  
%@%%%%%%% error handling
%@
%@catch
%@  x=lasterr;y=lastwarn;
%@  if ~strcmpi(lasterr,'Interrupt')
%@    if fid>-1, 
%@      try, z=ferror(fid); catch, z='No error in the installation I/O process.'; end
%@    else
%@      z='File not found.'; 
%@    end
%@    fid=fopen('deinstall.log','w');
%@    fprintf(fid,'%s\n','A critical error has occurred. Please inform the distributor');
%@    fprintf(fid,'%s\n','of the toolbox, where the error occured and send us the entire');
%@    fprintf(fid,'%s\n','screen output of the installation, the following error');
%@    fprintf(fid,'%s\n','report, and the informations about the toolbox (distributor,');
%@    fprintf(fid,'%s\n','name, URL etc.). Provide a brief description of what you were');
%@    fprintf(fid,'%s\n','doing when this problem occurred.');
%@    fprintf(fid,'%s\n','E-mail or FAX this information to us at:');
%@    fprintf(fid,'%s\n','    E-mail:  marwan@pik-potsdam.de');
%@    fprintf(fid,'%s\n','       Fax:  ++49 +331 288 2640');
%@    fprintf(fid,'%s\n\n\n','Thank you for your assistance.');
%@    fprintf(fid,'%s\n',repmat('-',50,1));
%@    fprintf(fid,'%s\n',datestr(now,0));
%@    fprintf(fid,'%s\n',['Matlab ',char(version),' on ',computer]);
%@    fprintf(fid,'%s\n',repmat('-',50,1));
%@    fprintf(fid,'%s\n','COPRA');
%@    fprintf(fid,'%s\n',x);
%@    fprintf(fid,'%s\n',y);
%@    fprintf(fid,'%s\n',z);
%@    fclose(fid);
%@    disp('----------------------------');
%@    disp('       ERROR OCCURED ');
%@    disp('   during deinstallation');
%@    disp('----------------------------');
%@    disp(x);
%@    disp(z);
%@    disp('----------------------------');
%@    disp('   A critical error has occurred. Please inform the distributor');
%@    disp('   of the toolbox, where the error occured and send us the entire');
%@    disp('   screen output of the installation, the error report report');
%@    disp('   and the informations about the toolbox (distributor, name,');
%@    disp('   URL etc.). For your convenience, this information has been')
%@    disp('   recorded in: ')
%@    disp(['   ',fullfile(pwd,'deinstall.log')]), disp(' ')
%@    disp('   Provide a brief description of what you were doing when ')
%@    disp('   this problem occurred.'), disp(' ')
%@    disp('   E-mail or FAX this information to us at:')
%@    disp('       E-mail:  marwan@pik-potsdam.de')
%@    disp('          Fax:  ++49 +331 288 2640'), disp(' ')
%@    disp('   Thank you for your assistance.')
%@  end
%@  warning('on')
%@  if exist(currentpath,'dir') == 7, cd(fileparts(currentpath)), else, cd(currentpath), end
%@  if isoctave
%@      more on
%@  end
%@end
%@
%@function flag = isoctave
%@% ISOCTAVE   Checks whether the code is running in Octave
%@%   ISOCTAVE is returning the value TRUE if executed within the
%@%   Octave environment, else it is returning FALSE (e.g. when
%@%   called within Matlab.
%@
%@a = ver('Octave');
%@
%@if ~isempty(a) && strfind(a(1).Name,'Octave')
%@    flag = true;
%@else
%@    flag = false;
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __example_script.m__ -->
%@%% Scripting COPRA
%@% COPRA is a software for modeling the age-depth relationship, or
%@% accumulation history, of paleoclimate archives. Given a dating table and
%@% proxy measurements, it is used to return a time series for paleoclimate
%@% proxies. 
%@
%@% Running COPRA interactively, data can be read in and the dating table
%@% manipulated. Since 2000 MC iterations can take a long time for difficult
%@% datasets where layercounting is included, one option is to run COPRA
%@% once, interactively, with only few, e.g. 10, MC iterations (the variable
%@% M can be set in the file COPRA directly.). The returned data
%@% structure d is, however, now initialized with the relevant data to
%@% perform the age-depth simulations! Therefore, the relevant engine
%@% (mcagemodels.m) can be run non-interactively, and the output stored/
%@% visualized effectively.
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INTRO
%@% The data structure is as follows:
%@% d: Datastruct with fields
%@% Fields of d
%@% % d = 
%@% % 
%@% %             depth: [19x1 double]
%@% %               age: [19x1 double]
%@% %          ageerror: [19x1 double]
%@% %           comment: {19x1 cell}
%@% %            d_prxy: [8094x1 double]
%@% %            v_prxy: [8094x1 double]
%@% %        samplename: 'YOK-G'
%@% %         proxyname: '\delta^{18}O'
%@% %     interp_method: 'linear'
%@% %           agename: 'yr BP'
%@% %         depthname: 'Depth (mm)'
%@% %                 M: 2000
%@% %      am_commented: 0
%@% %         guistring: []
%@% %               gui: 0
%@% %             adinf: 1
%@% %               dlc: [1x1 struct]
%@% %           revType: [18x1 double]
%@% %            hiatus: [19x1 double]
%@% %         hia_depth: []
%@%%% where d.depth, d.age and d. ageerror together make up the
%@%%% 'finalagemodel', or the refined/ modified dating table. d.d_prxy 
%@%%% and d.v_prxy are the depths and values of the proxy measurements that
%@%%% will be assigned ages to after age modeling. d.M gives the number of
%@%%% Monte Carlo iterations, and d.interp_method defines the method that is
%@%%% used to interpolate the proxy ages from the ages of the dating table.
%@%%% d.adinf is 1 if layer counting data is provided, in which case the
%@%%% variable d.dlc is non-empty and itself contains a data structure with
%@%%% depth, year and deptherror for the layer counting. d.revType classifies
%@%%% the differences between successive ages in the dating table: it
%@%%% contains 1s for tractable and 2s for nontractable reversals (see COPRA_O
%@%%% paper). d.hiatus, similarly, contains 1s at the points where the age
%@%%% model should be split, i.e. where it should be non-continuous, with the
%@%%% variable d.hia_depth giving the exact depth at which the hiatus
%@%%% occurred.
%@
%@
%@%% EXAMPLES
%@
%@
%@%% 1a Simple, good example for a chronology (this should run first)
%@% dating table in COPRA_OROOT/data/test/LayercountGood/testagemodel_good.txt
%@% proxy data in COPRA_OROOT/data/test/isotope-test-good.txt
%@% Run copra to put dating table & proxy data into the data structure d (to
%@% re-run if necessary) and to get the Spaghettis you want to feed to the
%@% similarity function (T_unc).
%@
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@%% Part 1: data import
%@
%@% (A) load data and create data structure by hand
%@datafolder = 'data/LayercountGood/';
%@am = load([datafolder,'testagemodel_good.txt']);
%@iso = load([datafolder,'isotope-test-good.txt']);
%@lc = load([datafolder,'layercount-test-25.txt']);
%@d.depth = am(:,1); % date location (depth)
%@d.age = am(:,2); % dated age
%@d.ageerror = am(:,3); % dating error
%@d.d_prxy = iso(:,1); % proxy measurement location (depth)
%@d.v_prxy = iso(:,2); % proxy value
%@d.id = 1:length(d.depth); % data point id's
%@d.dlc.d_lc = lc(:,1); % layer location (depth)
%@d.dlc.v_lc = lc(:,2); % layer age
%@d.dlc.e_lc = lc(:,3); % layer age error
%@d.proxyname = 'delta 18O';
%@d.samplename = 'testdata';
%@d.log = 'test.log'; % name of the file for logging all steps
%@d.agename='kBP';
%@d.depthname='mm';
%@
%@% (B) or create data structure using the loaddata function
%@%d = loaddata;
%@
%@
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@%% Part 2: data processing
%@% removing of dating points, increasing dating errors, etc.
%@
%@d = processages_cl(d);
%@
%@
%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@%% Part 3: make age models using MC
%@
%@d.M = 20; % we have to specify the number of MC runs
%@d.adinf = 1; % forces the MC simulation to consider also the layer counting
%@d = mcagemodels(d);
%@
%@
%@plot(d.T_unc(:,3:end),d.d_prxy, d.age, d.depth,'.r')
%@xlabel('age')
%@ylabel('depth')
%@axis ij
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __info.xml__ -->
%@<productinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.mathworks.com/namespace/info/v1/info.xsd">
%@<?xml-stylesheet type="text/xsl" href="http://www.mathworks.com/namespace/info/v1/info.xsd"?>
%@
%@<matlabrelease>NaN</matlabrelease>
%@<name>Copra</name>
%@<type>matlab</type>
%@<icon>$toolbox/matlab/general/matlabicon.gif</icon>
%@
%@<list>
%@
%@<listitem>
%@<label>Help</label>
%@<callback>helpwin Copra/</callback>
%@<icon>$toolbox/matlab/general/bookicon.gif</icon>
%@</listitem>
%@
%@</list>
%@
%@</productinfo>
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __mcagemodels.m__ -->
%@function d = mcagemodels(d)
%@% MCAGEMODELS Perform MC simulations for paleoclimate proxy age-depth relationships.
%@%    AGEMODS = MCAGEMODELS(D) where AGEMODS are potential age-depth relationships
%@%    that are monotonous and their spread reflects the dating errors.
%@
%@%%%%%%%%%%%%%%
%@% TO BE COMMENTED !!!!
%@
%@d_input = d.depth;
%@a_input = d.age;
%@ae_input = d.ageerror;
%@
%@
%@if ~isfield(d,'hiatus'); d.hiatus = zeros(length(d.depth),1); d.hiatus(end) = 1; end
%@if ~isfield(d,'hia_depth'); d.hia_depth = []; end
%@if ~isfield(d,'interp_method'); d.interp_method = 'pchip'; end
%@
%@d_prxy = d.d_prxy;
%@v_prxy = d.v_prxy;
%@hiatus = d.hiatus;
%@hia_depth = d.hia_depth;
%@M = d.M;
%@interp_method = d.interp_method;
%@adinf = d.adinf;
%@dlc = d.dlc;
%@
%@if adinf == 1
%@    agemods = [];
%@else
%@    agemods = zeros(length(d_prxy),M);
%@end
%@idx = find(hiatus);
%@
%@% MC simulations are performed for each segment s according to the split
%@% table given by d.hiatus at the depths given by d.hia_depth. In other
%@% words - a hiatus has to be placed *between* two dates in the dating
%@% table, otherwise the MC simulation will not make sense/ work.
%@for s = 1:length(idx)
%@    if s == 1
%@        %*%%*%%*% Top segment
%@        depth = d_input(1:idx(s));        
%@        age = a_input(1:idx(s));
%@        ageerror = ae_input(1:idx(s)); %*%%*%%*%
%@        
%@        if s ~= length(idx)
%@            tmpu = 0.5*(d_input(idx(s))+d_input(idx(s)+1));
%@            tmpu = find(d_prxy<tmpu,1,'last');
%@        else
%@            tmpu = length(d_prxy);
%@        end
%@        depthout = d_prxy(1:tmpu);
%@        if hia_depth
%@            tmpu = find(d_prxy<=hia_depth(s),1,'last');
%@            depthout = d_prxy(1:tmpu);
%@        end
%@        
%@    elseif s > 1 && s < length(idx)
%@        %*%%*% Middle segment
%@        %depth = d_input(idx(s-1):idx(s));%%%%% dating table entries ...
%@        depth = d_input((idx(s-1)+1):idx(s));%%%%% dating table entries ...
%@        age = a_input(idx(s-1)+1:idx(s));%%%%%%% ... in split section ...
%@        ageerror = ae_input(idx(s-1)+1:idx(s));% ... for interpolation...
%@        tmpu = find(d_prxy<tmpu,1,'last'); % find last proxy depth above half way of pt 7
%@        
%@        tmpl = 0.5*(d_input(idx(s-1))+d_input(idx(s-1)+1)); % find first proxy depth for this section
%@        
%@        %$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@
%@        %tmpl = find(d_prxy>=tmpl,1,'first');
%@        tmpl = find(d_prxy>tmpl,1,'first');
%@        %$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@
%@        depthout = d_prxy(tmpl:tmpu);
%@        % % % %           size(depthout)
%@        if ~isempty(hia_depth(s))
%@            tmpu = find(d_prxy<=hia_depth(s),1,'last');
%@            tmpl = find(d_prxy>hia_depth(s-1),1,'first');
%@            depthout = d_prxy(tmpl:tmpu);
%@            
%@        end
%@
%@    elseif s == length(idx) && s ~= 1 % find the end point 
%@        %*%%*%%*%%*% Bottom segment
%@        %depth = d_input(idx(s-1)+1:idx(s));
%@        depth = d_input((idx(s-1)+1):idx(s));
%@        age = a_input(idx(s-1)+1:idx(s));
%@        ageerror = ae_input(idx(s-1)+1:idx(s));
%@        tmpl = 0.5*(d_input(idx(s-1))+d_input(idx(s-1)+1));
%@        %$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@
%@        %tmpl = find(d_prxy>=tmpl,1,'first');
%@        tmpl = find(d_prxy>tmpl,1,'first');
%@        %$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@%$^&*@
%@        depthout = d_prxy(tmpl:end);
%@        %        if hia_depth(s)
%@        if hia_depth(s-1)
%@            tmpl = find(d_prxy>hia_depth(s-1),1,'first');
%@            depthout = d_prxy(tmpl:end);
%@        end
%@    end
%@    
%@    if adinf == 1 % if layer counting was performed, additional MC steps are taken, 
%@        % otherwise the segments are simulated individually
%@        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@        d_lc = dlc.d_lc; % depth of the layer
%@        v_lc = dlc.v_lc; % layer count value (year)
%@        e_lc = dlc.e_lc; % error in layer count value (depth)
%@        
%@        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@        % Create monotonic M-number of Monte Carlo replicates
%@        disp('Performing the initial MC simulations for the point ages')
%@        [t_new, x_new, time, cancelFlag] = makemonotone(depth,age,ageerror,depthout, ...
%@            M,interp_method);
%@        if cancelFlag
%@            break
%@        end
%@        
%@        % Test for reversal at the end (due to extrapolation) and correct for it by
%@        % adding an extra point (legacy, makemonotone)
%@        % [tmp, tmp_, time] = chkEndRevs(t_new,x_new,time,d);
%@        
%@        disp('Performing the MC simulations for the layercounting data')
%@        
%@%         depth_combine = [depth; d_lc];
%@%         age_combine = [age; v_lc];
%@%         deptherr_combine = [zeros(length(depth),1); e_lc];
%@%         ageerr_combine = [ae_input; zeros(length(d_lc),1)];
%@%         
%@%         [depth_combine cmb_idx] = sort(depth_combine);
%@%         age_combine = age_combine(cmb_idx);
%@%         deptherr_combine = deptherr_combine(cmb_idx);
%@%         ageerr_combine = ageerr_combine(cmb_idx);
%@        
%@        %[tmp, tmp_, tmp__, time_lc] = makemonotoneLC(depth_combine,age_combine,ageerr_combine,deptherr_combine,v_lc,...
%@        %    d_lc,M,interp_method);
%@        [tmp, tmp_, tmp__, time_lc, cancelFlag] = makemonotoneLC(d_lc,v_lc,[],e_lc,v_lc,...
%@            d_lc,M,interp_method);
%@        if cancelFlag
%@            break
%@        end
%@        clear tmp tmp_ tmp__
%@        %%%% -------------------
%@        mu_lc = mean(time_lc,2);
%@        sd_lc = std(time_lc,[],2);
%@        mu_dp = interp1(depthout,mean(time,2),depth,interp_method,'extrap');
%@        sd_dp = interp1(depthout,std(time,[],2),depth,interp_method,'extrap');
%@        
%@        agefromdp = interp1(depthout,mean(time,2),d_lc,interp_method,'extrap');
%@        ko = linspace(min(age),max(age),1000);
%@        tmp = repmat(ko,length(mu_lc),1) + repmat(mu_lc,1,1000);
%@        Rsq = sqrt(sum((tmp - repmat(agefromdp,1,1000)).^2));
%@        ko = ko(Rsq==min(Rsq));
%@        
%@        depth_all = unique(sort([depth;d_lc]));
%@        tmp_mu = zeros(length(depth_all),2);
%@        tmp_sd = zeros(length(depth_all),2);
%@        j = 1; % counter (index) for vector "depth"
%@        k = 1; % counter (index) for vector "d_lc"
%@        for i = 1:length(depth_all)
%@            if k <= length(d_lc)  && j <= length(depth)
%@                if depth(j) < d_lc(k)
%@                    tmp_mu(i,:) = [mu_dp(j),mu_dp(j)];
%@                    tmp_sd(i,:) = [sd_dp(j),sd_dp(j)];
%@                    j = j+1;
%@                elseif depth(j) == d_lc(k)
%@                    tmp_mu(i,:) = [mu_dp(j),mu_lc(k)+ko];
%@                    tmp_sd(i,:) = [sd_dp(j),sd_lc(k)];
%@                    j = j+1;
%@                    k = k+1;
%@                else
%@                    tmp_mu(i,:) = [mu_lc(k)+ko,mu_lc(k)+ko];
%@                    tmp_sd(i,:) = [sd_lc(k),sd_lc(k)];
%@                    k= k+1;
%@                end
%@            elseif j > length(depth)
%@                tmp_mu(i,:) = [mu_lc(k)+ko,mu_lc(k)+ko];
%@                tmp_sd(i,:) = [sd_lc(k),sd_lc(k)];
%@                k= k+1;
%@            elseif k > length(d_lc)
%@                tmp_mu(i,:) = [mu_dp(j),mu_dp(j)];
%@                tmp_sd(i,:) = [sd_dp(j),sd_dp(j)];
%@                j = j+1;
%@            end
%@        end
%@        clear tmp agefromdp mu_lc mu_sd mu_dp sd_dp ko i j k
%@        %%%% -------------------
%@        %%%% Final Monte Carlo
%@        disp('Final MC')
%@        [tmp, tmp_, time, cancelFlag] = makemonotone(depth_all,tmp_mu,tmp_sd,depthout,...
%@            M,interp_method);
%@        agemods = [agemods; time]; 
%@        clear tmp tmp_
%@        if cancelFlag
%@            break
%@        end
%@    else
%@        % Create monotonic M-number of Monte Carlo replicates
%@        disp('Monte Carlo runs')        
%@        [t_new, x_new, time, cancelFlag] = makemonotone(depth,age,ageerror,depthout,...
%@            M,interp_method);
%@        
%@        if cancelFlag
%@            break
%@        end
%@            
%@        
%@        % Test for reversal at the end (due to extrapolation) and correct for it by
%@        % adding an extra point
%@        %        [tmp, tmp_, time] = chkEndRevs(t_new,x_new,time,d);
%@        %      clear tmp tmp_
%@        %size(time)
%@        if s == 1
%@            agemods(1:tmpu,:) = time;
%@        elseif s > 1 && s < length(idx)
%@            agemods(tmpl:tmpu,:) = time;
%@        elseif s == length(idx) && s ~= 1
%@            agemods(tmpl:end,:) = time;
%@        end
%@        
%@        
%@    end
%@    
%@    clear depthout
%@end
%@
%@
%@d.cancelFlag = cancelFlag;
%@d.T_unc=[d_prxy,v_prxy,agemods]; % depth-certain, proxy certain, time uncertain
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __processages_cl.m__ -->
%@function d = processages_cl(varargin)
%@% PROCESSAGES_CL Interactive modification of dating data.
%@%     PROCESSAGES_CL(DATASTRUCT) checks for reversals by using
%@%     the struct DATASTRUCT with the fields DATASTRUCT.DEPTH,
%@%     DATASTRUCT.AGE, DATASTRUCT.AGEERROR, DATASTRUCT.SAMPLENAME.
%@
%@
%@
%@%% default values
%@
%@if nargin
%@    d = varargin{:};
%@else
%@    d = [];
%@end
%@
%@if ~isfield(d,'filenameAD'); d.filenameAD = ''; end
%@if ~isfield(d,'filenameProxy'); d.filenameProxy = ''; end
%@if ~isfield(d,'samplename'); d.samplename = ''; end
%@if ~isfield(d,'proxyname'); d.proxyname = ''; end
%@if ~isfield(d,'age'); d.age = []; end
%@if ~isfield(d,'depth'); d.depth = []; end
%@if ~isfield(d,'ageerror'); d.ageerror = []; end
%@if ~isfield(d,'revType'); d.revType = []; end
%@%if ~isfield(d,'hiatus'); d.hiatus = []; end
%@if ~isfield(d,'removePts'); d.removePts = []; end
%@if ~isfield(d,'incErr'); d.incErr = []; end
%@if ~isfield(d,'comment'); d.comment = ''; end
%@
%@
%@axlab_fontsize = 14;
%@
%@idx = []; % indices of the points to be treated
%@
%@%%
%@newtreatment = 1;
%@if isfield(d,'rev_treat') && any(d.rev_treat)
%@    
%@    rev_treat = d.rev_treat;
%@    incErr = d.incErr;
%@    removePts = d.removePts;
%@    
%@   choices={'Define new treatment', 'Use old treatment from logfile', 'Cancel'};
%@   if isoctave
%@       choice = menu('Treatment in log file found. Define new or use old treatment?','Define new', 'Use old', 'Cancel');
%@   else
%@       choice = input('Treatment in log file found. Define new or use old treatment?\n [1] Define new\n [2] Use old (default)\n [3] Cancel');
%@   end
%@   if ~isoctave && isempty(choice)
%@       choice = 2;
%@   end
%@   switch choice
%@       case 1 % define new
%@           disp(choices{choice})
%@           newtreatment = 1;
%@           % initiate arrays for new treatment
%@           rev_treat = 0; % vector with points to be treated
%@           incErr = 0; % vector for selected pts for error bar increase
%@           removePts = 0; % vector for selected pts which are to be removed
%@       case 2 % use old
%@           disp(choices{choice})
%@           newtreatment = 0;
%@       case 3 % cancel everything
%@           disp('Cancel')
%@           return
%@   end
%@   
%@else
%@    
%@    % initiate arrays for new treatment
%@    rev_treat = 0; % vector with points to be treated
%@    incErr = 0; % vector for selected pts for error bar increase
%@    removePts = 0; % vector for selected pts which are to be removed
%@    
%@   
%@end
%@
%@finalagemodel=[];
%@
%@treat = 1;
%@
%@
%@%% Check reversals
%@%%%d.rev_type=chkrevs(depth,age,ageerror,filenameLog);
%@d.revType=chkRevs(d);
%@rev_type=d.revType;
%@
%@%% Display agemodel
%@
%@age_depth_fig1 = figure;
%@set(age_depth_fig1,'Units','normalized','Position',[.1 .5 .3 .4])
%@
%@errorbarxy(d.age,d.depth,d.ageerror,[])
%@axis ij; grid on
%@xlabel(d.agename,'fontsize',axlab_fontsize,'fontweight','bold')
%@ylabel(d.depthname,'fontsize',axlab_fontsize,'fontweight','bold')
%@ylim([-1 max(d.depth)+max(d.depth)/10])
%@for i = 1:length(d.age)
%@    text(- range(xlim)/100 + d.age(i),range(ylim)/25 + d.depth(i),num2str(d.id(i)))     
%@end
%@
%@if any(rev_type==1)
%@    plot(d.age(find(rev_type == 1)),d.depth(find(rev_type == 1)),'o','color',[1 0 0],'linew',2)
%@end
%@if any(rev_type==2)
%@    plot(d.age(find(rev_type == 2)),d.depth(find(rev_type == 2)),'o','color',[1 0 1],'linew',2)
%@end
%@
%@
%@
%@
%@%% Modify dating table
%@% remove points
%@%warning('Missing parts [TBD]!')
%@% increase error bars
%@
%@reversal=true;% always enter the inspection loop for the agemodel at least once
%@ptremoved=false; %for legend entries if pts are removed
%@ptincrease=false;%for legend entries if pts are selected for increasing errors
%@
%@while reversal
%@    if any(rev_type==1)&~(any(rev_type==2))% tractable problem only
%@        % legend entry
%@%         legend([h1  hMarkersTract ], 'Agemodel with 2\sigma error bars',...
%@%             'Tractable reversal','Location','SouthOutside')
%@%         
%@        disp('Reversals')
%@         revs=find(rev_type>0);
%@         %rev_type
%@         
%@        for i=1:length(revs)
%@            if rev_type(revs(i))==1
%@            text(d.age(revs(i)),d.depth(revs(i)),'\leftarrow tract', 'color', [.3 .6 0],'rot',90)
%@            else
%@            text(d.age(revs(i)),d.depth(revs(i)),'\leftarrow nontract', 'color', [.8 .1 0],'rot',90)
%@            end
%@        end
%@        % do treat! otherwise error
%@%         fprintf(fid_metadata,['Tractable reversal found. Monotonous ',...
%@%             'age-depth relationships can be established, but you may
%@%             ',... 'want to modify th agemodel data.\n']);
%@        disp('Tractable reversal found. Monotonous age-depth relationships can be established, but you may want to modify the agemodel data.');
%@        
%@        if ~newtreatment & any(rev_treat)
%@            disp(['Treatment of points ',num2str(find(rev_treat)), ' is defined from old log file.'])
%@            disp(['   Increase errors at points: ',num2str(find(incErr)), '.'])
%@            disp(['   Remove points: ',num2str(find(removePts)), '.'])
%@            
%@            choices={'Yes', 'No', 'Cancel'};
%@            if isoctave
%@                choice = menu('You chose to use a treatment from an old logfile. Do you wish to treat additional points?','Yes','No','Cancel');
%@            else
%@                choice = input('You chose to use a treatment from an old logfile. Do you wish to treat additional points?\n [1] Yes\n [2] No (default)\n [3] Cancel');
%@            end
%@            
%@            if ~isoctave && isempty(choice)
%@                choice = 2;
%@            end
%@            
%@            savelog(d.log,'','Treatment of tractable reversals:')
%@            switch choice
%@                case 1 % modify/treat agemodel
%@                    disp(choices{choice})
%@                    savelog(d.log,'','modify')
%@                    treat=true;
%@                    reversal=true;
%@                case 2 % use as is/ don't treat
%@                    disp(choices{choice})
%@                    savelog(d.log,'','do not treat')
%@                    treat=false;
%@                    reversal=false;
%@                case 3 % cancel everything
%@                    savelog(d.log,'','cancelled')
%@                    disp('Cancel')
%@                    break
%@             end
%@            
%@        else
%@        
%@
%@            choices={'Treat', 'Use as is', 'Cancel'};
%@            if isoctave
%@                choice = menu('Choose whether the agemodel should be treated','Treat','Use as is','Cancel');  
%@            else
%@                choice = input('Choose whether the agemodel should be treated\n [1] Treat\n [2] Use as is (default)\n [3] Cancel\n');            
%@            end
%@            if ~isoctave && isempty(choice)
%@                choice = 2;
%@            end
%@            %sprintf('Do %s.', choices{choice})
%@            savelog(d.log,'','Treatment of tractable reversals:')
%@            switch choice
%@                case 1 % modify/treat agemodel
%@                    disp(choices{choice})
%@                    savelog(d.log,'','modify')
%@                    treat=true;
%@                    reversal=true;
%@                case 2 % use as is/ don't treat
%@                    disp(choices{choice})
%@                    savelog(d.log,'','do not treat')
%@                    treat=false;
%@                    reversal=false;
%@                case 3 % cancel everything
%@                    savelog(d.log,'','cancelled')
%@                    disp('Cancel')
%@                    break
%@            end
%@        end
%@        
%@    elseif any(rev_type==2)%non-tractable problem
%@        % control the legend-entries
%@        if any(rev_type==1) %if mixed tractable & non-tractable
%@            %%%legend([h1  hMarkersTract hMarkersNT ],...
%@            %%%    'Agemodel with 2\sigma error bars', 'Tractable reversal',...
%@            %%%    'Non-tractable-reversal','Location','SouthOutside')
%@        else % purely non-tractable
%@            %%%legend([h1   hMarkersNT ], 'Agemodel with 2\sigma error bars',...
%@            %%%    'non-tractable-reversal','Location','SouthOutside')
%@        end
%@        
%@        
%@        disp('Non-tractable reversal! It will not be possible to get a monotonous age-depth relationship out of this! Please modify the current agemodel data to continue.')
%@        
%@        
%@       if ~newtreatment & any(rev_treat)
%@            disp(['Treatment of points ',num2str(find(rev_treat)), ' is defined from old log file.'])
%@            disp(['   Increase errors at points: ',num2str(find(incErr)), '.'])
%@            disp(['   Remove points: ',num2str(find(removePts)), '.'])
%@            
%@            choices = {'Yes', 'No', 'Cancel'};
%@            if isoctave
%@                choice = menu('You chose to use a treatment from an old logfile. Do you wish to treat additional points?','Yes','No','Cancel');
%@            else
%@                choice = input('You chose to use a treatment from an old logfile. Do you wish to treat additional points?\n [1] Yes\n [2] No (default)\n [3] Cance\nl');
%@            end
%@            
%@            if ~isoctave && isempty(choice)
%@                choice = 2;
%@            end
%@            
%@            savelog(d.log,'','Treatment of tractable reversals:')
%@            switch choice
%@                case 1 % modify/treat agemodel
%@                    disp(choices{choice})
%@                    savelog(d.log,'','modify')
%@                    treat=true;
%@                    reversal=true;
%@                case 2 % use as is/ don't treat
%@                    disp(choices{choice})
%@                    savelog(d.log,'','do not treat')
%@                    treat=false;
%@                    reversal=false;
%@                case 3 % cancel everything
%@                    savelog(d.log,'','cancelled')
%@                    disp('Cancel')
%@                    break
%@             end
%@            
%@        else
%@        
%@
%@            choices={'Treat', 'Use as is', 'Cancel'};
%@            if isoctave
%@                choice = menu('Choose whether the agemodel should be treated','Treat','Use as is','Cancel');  
%@            else
%@                choice = input('Choose whether the agemodel should be treated\n [1] Treat\n [2] Use as is (default)\n [3] Cancel\n');            
%@            end
%@            if ~isoctave && isempty(choice)
%@                choice = 2;
%@            end
%@            %sprintf('Do %s.', choices{choice})
%@            savelog(d.log,'','Treatment of tractable reversals:')
%@            switch choice
%@                case 1 % modify/treat agemodel
%@                    disp(choices{choice})
%@                    savelog(d.log,'','modify')
%@                    treat=true;
%@                    reversal=true;
%@                case 2 % use as is/ don't treat
%@                    disp(choices{choice})
%@                    savelog(d.log,'','do not treat')
%@                    treat=false;
%@                    reversal=false;
%@                case 3 % cancel everything
%@                    savelog(d.log,'','cancelled')
%@                    disp('Cancel')
%@                    break
%@            end
%@        end
%@        
%@    else % no reversal, start diagnosis/ exploration only if explicitly desired
%@    %    legend(h1, 'Agemodel with 2\sigma error
%@    %    bars','Location','SouthOutside')
%@        
%@        disp('Good, consistent dating material. Monotonous age-depth relationships can be established.');
%@        savelog(d.log,'',['Good, consistent dating material. ',...
%@             'Monotonous age-depth relationships can be established.']);
%@
%@       if ~newtreatment & any(rev_treat)
%@       		formatSpec = '%i\t';
%@            disp(['Treatment of points ',[num2str(find(rev_treat),formatSpec)]', ' is defined from old log file.'])
%@            disp(['   Increase errors at points: ',num2str(find(incErr)), '.'])
%@            disp(['   Remove points: ',num2str(removePts), '.'])
%@            
%@            choices = {'Yes', 'No', 'Cancel'};
%@            if isoctave
%@                choice = menu('You chose to use a treatment from an old logfile. Do you wish to treat additional points?','Yes','No','Cancel');
%@            else
%@                choice = input('You chose to use a treatment from an old logfile. Do you wish to treat additional points?\n [1] Yes\n [2] No (default)\n [3] Cancel\n');
%@            end
%@            
%@            if ~isoctave && isempty(choice)
%@                choice = 2;
%@            end
%@            
%@            savelog(d.log,'','Treatment of tractable reversals:')
%@            switch choice
%@                case 1 % modify/treat agemodel
%@                    disp(choices{choice})
%@                    savelog(d.log,'','modify')
%@                    treat=true;
%@                    reversal=true;
%@                case 2 % use as is/ don't treat
%@                    disp(choices{choice})
%@                    savelog(d.log,'','do not treat')
%@                    treat=false;
%@                    reversal=false;
%@                case 3 % cancel everything
%@                    savelog(d.log,'','cancelled')
%@                    disp('Cancel')
%@                    break
%@             end
%@            
%@       else
%@        
%@            choices={'Treat', 'Use as is', 'Cancel'};
%@            if isoctave
%@                choice = menu('Choose whether the agemodel should be treated','Treat','Use as is','Cancel');  
%@            else
%@                choice = input('Choose whether the agemodel should be treated\n [1] Treat\n [2] Use as is (default)\n [3] Cancel\n');            
%@            end
%@            if ~isoctave && isempty(choice)
%@                choice = 2;
%@            end          
%@            %sprintf('Do %s.', choices{choice})
%@            savelog(d.log,'','Treatment of tractable reversals:')
%@            switch choice                
%@                case 1 % modify/treat agemodel
%@                    disp(choices{choice})
%@                    savelog(d.log,'','modify')
%@                    treat=true;
%@                    reversal=true;
%@                case 2 % use as is/ don't treat
%@                    disp(choices{choice})
%@                    savelog(d.log,'','do not treat')
%@                    treat=false;
%@                    reversal=false;
%@                case 3 % cancel everything
%@                    savelog(d.log,'','cancelled')
%@                    disp('Cancel')
%@                    break
%@            end
%@        end
%@                
%@	 end
%@    
%@    %%%%%%%%%%%%%%%%%%%%%% % end of first options popup
%@    %% Treatment of points (Removal, Increase of Error Bars, Query comment info, Zoom)
%@    
%@    disp(['Tractable reversals around point(s): ', sprintf('%g ',d.id(rev_type==1))])
%@    disp(['Non-tractable reversals around point(s): ' sprintf('%g ',d.id(rev_type==2))])
%@    
%@    savelog(d.log,'',['Tractable reversals around point(s): ', sprintf('%g ',d.id(rev_type==1))])
%@    savelog(d.log,'',['Non-tractable reversals around point(s): ' sprintf('%g ',d.id(rev_type==2))])
%@
%@   
%@    while treat & newtreatment% tractable or non-tractable reversal
%@        
%@        
%@        % while selection goes on & until ENTER is hit:
%@        reply = input('Which point do you want to modify? [none]');
%@        if isempty(reply)
%@            treat=false;
%@            continue % exit the while loop
%@        else % if the indicated pt's index is in the valid range
%@            if isnumeric(reply) & reply <= max(d.id) 
%@                idx=find(reply == d.id,1);
%@            else
%@                disp('Please indicate a point in the range')
%@            end
%@        end
%@        
%@%%%clear choice
%@        % treat this point! Ask user, how
%@        treatm={'Removal', 'Increase error','Query information','Cancel selection'};
%@        if isoctave
%@            choice = menu('Choose how the point should be treated:','Removal','Increase error','Query information','Cancel selection');
%@        else
%@            choice = input('Choose how the point should be treated\n [1] Removal (default)\n [2] Increase error\n [3] Query information\n [4] Cancel selection\n');
%@        end
%@        if ~isoctave && isempty(choice)
%@            choice = 1;
%@        end
%@        %             sprintf('%s for this point', treatm{choice})
%@        
%@        switch choice
%@            case 1 % removal of the point
%@                disp(treatm{choice})
%@                rev_treat(idx)=1;
%@                removePts=(rev_treat==1);
%@                % plot the 'selected' points that will be deleted
%@                % ['Removing pt: ' sprintf(idx)]
%@                disp(['Removing point: ',num2str(d.id(idx))])
%@                if ~ptremoved,
%@                    ptremoved=true;
%@                end
%@                savelog(d.log,'',['Point ',num2str(d.id(idx)),' should be removed.'])
%@
%@            case 2 % increase of the error bars for pts
%@                disp(treatm{choice})
%@                rev_treat(idx)=2;
%@                incErr = (rev_treat==2);
%@       %         hnew=plot(age(incErr),depth(incErr),
%@       %         '^','LineWidth', 2, 'MarkerSize', 10,'color',[.1 .9
%@       %         .0]);
%@                
%@                if ~ptincrease, % update legend
%@            %            [LEGH,OBJH,OUTH,OUTM] = legend;
%@             %           legend([OUTH;hnew],OUTM{:},'increase
%@             %           error','Location','SouthOutside')
%@                        ptincrease=true;
%@                end
%@                savelog(d.log,'',['For point ',num2str(d.id(idx)),' errorbar should be increased.'])
%@                
%@            case 3 % Display comment for this point
%@                if am_commented % if comment info available
%@                    disp('age depth comment')
%@                    disp([d.age(idx) d.depth(idx) d.comment(idx,:)])
%@                    
%@                else % if it isn't, use ID
%@                    disp('age depth index')
%@                    disp([d.age(idx) d.depth(idx) d.id(idx)])
%@                end
%@                
%@            case 4 % cancel selection, try again
%@                disp(treatm{choice})
%@                continue
%@        end
%@    end
%@    
%@    d.rev_treat = rev_treat;
%@    d.incErr = incErr;
%@    d.removePts = removePts;
%@    
%@    savelog(d.log,'d.rev_treat','Treated points:')
%@    savelog(d.log,'d.incErr',' - Increase errorbars:')
%@    savelog(d.log,'d.removePts',' - Remove points:')
%@
%@    %end % if treat
%@    
%@    % confirm that the changes are to be made
%@    %%%reply = questdlg('The points will be altered. Do you want to continue?', 'Proceed?', 'Proceed', 'Cancel', '');
%@    if isoctave
%@        reply = menu('The points will be altered. Do you want to continue?', 'Proceed', 'Cancel');
%@    else
%@        reply = input('The points will be altered. Do you want to continue?\n [1] Proceed (default)\n [2] Cancel\n');
%@    end
%@    
%@    if isempty(reply)
%@        reply = 1;
%@    end
%@    
%@    if (reply==1)
%@        
%@        if any(incErr),
%@            increase=true;
%@            while increase
%@                savelog(d.log,'',['Increased error of point ',num2str(find(incErr)),' by 10%.'])
%@                display('Increase errorbar size by 10%');
%@                d.ageerror(incErr)=d.ageerror(incErr)*1.1;
%@                errorbarxy(d.age(incErr),d.depth(incErr),d.ageerror(incErr),[]);
%@                % choice = questdlg('What to do now?','Options - increase
%@                % error bars', 'Increase further','Finish');
%@                if isoctave
%@                    choice = menu('Options- increase error bars', 'Increase', 'Finish');
%@                else
%@                    choice = input('Options- increase error bars\n [1] Increase\n [2] Finish (default)\n');
%@                end
%@                if isempty(choice)
%@                    choice = 2;
%@                end
%@                % Handle response
%@                switch choice
%@                    case 1
%@                        %disp([choice ' the error bars'])
%@                        increase=true;
%@                        reversal=true;
%@                    case 2
%@                        disp('Finish tuning of the age model, proceed with MC estimation')
%@                        increase=false;
%@                        reversal=false;
%@                end
%@            end
%@        else
%@            
%@            disp('No error bars increased, go on to remove points')
%@            %fprintf(fid_metadata,['No error bars increased, go on ',...
%@            %   'to remove points.\n']);
%@            reversal=false;
%@            treat=false;
%@        end
%@
%@        if any(removePts)
%@            % ask if the points should be removed?
%@            fprintf('Removed point no. %g \n', d.id(removePts))
%@            savelog(d.log,'',['Point ',num2str(d.id(removePts)),' removed.'])
%@            d.depth(removePts) = [];
%@            d.age(removePts) = [];
%@            d.ageerror(removePts) = [];
%@            d.id(removePts) = [];
%@     %       split(removePts)=[];
%@            disp('Proceed with other treatment')
%@            disp(choice)
%@            reversal=true;
%@        else
%@            disp('no points removed, no error bars increased, go on to MC estimation')
%@            %                 fprintf(fid_metadata,['No points removed, no error ',...
%@            %                     'bars increased, go on to MC estimation.\n']);
%@            reversal=false;
%@            treat=false;
%@        end
%@        
%@        
%@    else
%@        %reversal=true; % error/ exit loop
%@        close all
%@        error('Script terminated. Bye!')
%@    end %endofproceed
%@    
%@    
%@    
%@    
%@    %% Check the agemodel again if there are any non-tractable reversals left
%@    
%@    
%@    
%@    %  end   % of treatment
%@    %%%%%%%%%%%%%%%%%%%%%% % end of treatment section, the rest is executed
%@    %%%%%%%%%%%%%%%%%%%%%% for ALL agemodels
%@    
%@    d.revType=chkRevs(d.depth,d.age,d.ageerror);
%@    rev_type=d.revType;
%@    if any(rev_type==2),
%@        disp('You HAVE to treat the agemodel since it has a non-tractable reversal!')
%@        %         fprintf(fid_metadata,['You HAVE to treat the agemodel since ',...
%@        %             'it has a non-tractable reversal!']);
%@        treat=true;
%@        reversal=true;
%@        newtreatment = 1;
%@        
%@        continue; % go on to do the reversal thing again
%@        
%@    else
%@        disp('OK, agemodel correct(ed)')
%@        %fprintf(fid_metadata,'OK, agemodel correct(ed)\n');
%@        treat=false;
%@        reversal=false;
%@    end
%@    
%@end   % of treatment
%@%  closefigwithwarning(fig1,3)
%@age_depth_fig2 = figure;
%@set(age_depth_fig2,'Units','normalized','Position',[.1 .5 .3 .4])
%@
%@errorbarxy(d.age,d.depth,d.ageerror,[])
%@axis ij; grid on
%@xlabel(d.agename,'fontsize',axlab_fontsize,'fontweight','bold')
%@ylabel(d.depthname,'fontsize',axlab_fontsize,'fontweight','bold')
%@ylim([-1 max(d.depth)+max(d.depth)/10])
%@for i = 1:length(d.age)
%@    text(- range(xlim)/100 + d.age(i),range(ylim)/25 + d.depth(i),num2str(d.id(i)))     
%@end
%@
%@%% save treatment
%@d.rev_treat = rev_treat; % vector with points to be treated
%@d.incErr = incErr; % vector for selected pts for error bar increase
%@d.removePts = removePts; % vector for selected pts which are to be removed
%@
%@
%@%% save agemodel to log
%@finalagemodel = [d.depth d.age d.ageerror];
%@savelog(d.log,'finalagemodel','Corrected age model without reversals:')
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __resample_certain.m__ -->
%@function d = resample_certain(d)
%@% RESAMPLE_certain transforms the time-uncertain series (time) into proxy uncertain
%@% series.
%@%   RESAMPLE_CERTAIN(TIME,D) resamples the ensemble of time-uncertain
%@%   age-depth relationships TIME given the proxy information in the data
%@%   structure D. The data structure S holds display information. D_LC is
%@%   non-empty if layer counting data was included, in which case the start
%@%   and end depths of layercounting are needed. ADINF is nonzero if
%@%   layercounting was performed.
%@
%@
%@if d.adinf,
%@d_lc=d.dlc.d_lc;
%@else d_lc=[];
%@end
%@hia_depth=d.hia_depth;
%@adinf=d.adinf;
%@agename=d.agename;
%@M=d.M;
%@interp_method=d.interp_method;
%@time = d.T_unc(:,3:end);
%@
%@
%@samplename=d.samplename;
%@proxyname=d.proxyname;
%@v_prxy=d.v_prxy;
%@d_prxy=d.d_prxy;
%@depth=d.depth;
%@age=d.age;
%@hiatus=d.hiatus;
%@
%@t = mynanmean(time,2); % interpolate to the mean time values corresponding to the depths at which the proxy was measured
%@temp = zeros(length(t),size(time,2));
%@
%@for i = 1:size(time,2)
%@    temp(:,i) = interp1(time(:,i), v_prxy, t, 'linear')';
%@end
%@%prx_err = mynanstd(temp,2);
%@if ischar(d.confbnds_prxy)
%@   confInt_prxy = str2double(d.confbnds_prxy);
%@else
%@   confInt_prxy = d.confbnds_prxy;
%@end
%@if ischar(d.confbnds_age)
%@   confInt_age = str2double(d.confbnds_age);
%@else
%@   confInt_age = d.confbnds_age;
%@end
%@
%@prx_err = quantile(temp,[0.5-confInt_prxy/200 0.5+confInt_prxy/200],2);
%@prx_val_mean = mynanmean(temp,2);
%@prx_val_median = mynanmedian(temp,2);
%@%age_err = mynanstd(time,2);
%@age_err = quantile(time,[0.5-confInt_age/200 0.5+confInt_age/200],2);
%@age_val = t;
%@% ------------------------
%@% prx = mynanmean(temp,2);
%@% prxm = mynanmedian(temp,2);
%@% prxs = mynanstd(temp,2);
%@% idx = find(hiatus);
%@
%@
%@% ------------------------
%@% Figure params
%@figpos = [1.5,1.5,9,3.5];
%@lw = 0.2;
%@% ------------------------
%@% ----- Get ages for d_lc depths (only the start and end depths)
%@if numel(d_lc) > 0
%@    X = interp1(d_prxy,age_val,[d_lc(1);d_lc(end)]);
%@    x_lo = X(1);x_hi = X(end);
%@    clear X
%@end
%@
%@% %% Histogram: distribution of observed values for each year.
%@% h_hist=figure('Name','Figure: Proxy record (Histogram)','Toolbar','None',...
%@%     'Units','inches','OuterPosition',[1,5,8.5,5]);
%@% i = floor(size(temp,1)-size(temp,1)/2);
%@% subplot(1,2,1)
%@% plot(temp(i,:)), axis square
%@% xlabel('%%% Realisations'), ylabel(proxyname)
%@% title(['Values of ',proxyname,'at age ', num2str(t(i)),' ' ,agename], 'fontweight', 'bold')
%@% subplot(1,2,2)
%@% hist(temp(i,:)), axis square
%@% xlabel(proxyname)
%@% title(['Histogram of ',proxyname,'at age ', num2str(t(i)),' ' ,agename], 'fontweight', 'bold')
%@% % ----------------------------------------
%@
%@% %%
%@% % We can choose the mean or the median in order to get the value for any
%@% % year. Moreover, and much more important, we can find the 95% confidence
%@% % interval for the data based on the 2 sigma of the distributiond.
%@% % ----------------------------------------
%@
%@% %% Spaghetti Plot
%@% hspagh=figure('Name','Figure: Proxy record (Spaghetti)','Toolbar','None',...
%@%     'Units','inches','OuterPosition',figpos);
%@% hold on
%@% y_lo = min(min(temp));
%@% y_up = max(max(temp));
%@% if adinf == 1
%@%     rectangle('Position',[x_lo,y_lo,x_hi-x_lo,0.99*(y_up-y_lo)],...
%@%         'FaceColor',[.85 .85 .85],'EdgeColor','None')
%@% end
%@% sunset = [0.99 , 0.94, 0.83];
%@% for s = 1:length(idx)
%@%     if s == 1
%@%         tmpl = 1;
%@%         if s ~= length(idx)             % hiatus at first measured age
%@%             tmp = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@%             if hia_depth
%@%                 tmp = hia_depth;
%@%             end
%@%             tmpu = find(d_prxy<tmp,1,'last');
%@%             hia_lo = tmpu;
%@%             hia_hi = find(d_prxy>=tmp,1,'first');            
%@%             rectangle('Position',[t(hia_lo),y_lo,t(hia_hi)-t(hia_lo),...
%@%                 0.99*(y_up-y_lo)],'FaceColor',sunset,'EdgeColor','none')
%@%         else                            % no hiatus
%@%             tmpu = length(d_prxy);
%@%         end        
%@%     elseif s > 1 && s < length(idx)     % hiatus somewhere in between
%@%         tmp = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@%         if hia_depth
%@%             tmp = hia_depth;
%@%         end
%@%         tmpu = find(d_prxy<tmp,1,'last');
%@%         tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@%         tmpl = find(d_prxy>=tmpl,1,'first');
%@% %         if hia_depth
%@% %             tmpu = find(d_prxy<=hia_depth,1,'last');
%@% %             tmpl = find(d_prxy>=hia_depth,1,'first');
%@% %         end
%@%         hia_lo = tmpu;
%@%         hia_hi = find(d_prxy>=tmp,1,'first');
%@%         rectangle('Position',[t(hia_lo),y_lo,t(hia_hi)-t(hia_lo),...
%@%             0.99*(y_up-y_lo)],'FaceColor',sunset,'EdgeColor','none')
%@%     elseif s == length(idx) && s ~= 1   % marks end of vector
%@%         tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@%         if hia_depth
%@%             tmpl = hia_depth;
%@%         end
%@%         tmpl = find(d_prxy>=tmpl,1,'first');
%@%         tmpu = length(t);
%@%     end    
%@%     tmpx = t(tmpl:tmpu);
%@%     tmpy = temp(tmpl:tmpu,:);
%@%     plot(tmpx,tmpy,'LineWidth',lw)
%@%     clear tmpx tmpy tmp hia_lo hia_hi
%@% end
%@
%@% set(gca,'fontsize',10)             % General minimum fontsize in figure
%@% axlabftsz = 12;                              % fontsize for axis labels
%@% ylabel(proxyname,'fontsize',axlabftsz,'fontweight', 'bold')
%@% % ---- Set X-axis limits
%@% xhi = max(age);xlo=min(age);
%@% set(gca,'XLim',[xlo-(xhi-xlo)*0.1,xhi+(xhi-xlo)*0.1])
%@% % ---- Set XTicks (ALWAYS ONLY 7 in number)
%@% xlo = min(xlim);xhi = max(xlim);
%@% xtik = xlo:(xhi-xlo)/8:xhi;
%@% xtik(1) = [];
%@% set(gca,'XTick',xtik)
%@% % ---- Set XTickLabels
%@% if length(find(age<1000)) > length(age)/2 % >50% ages less than 1000 BP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i),'%5.1f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (BP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% elseif 0.5*(length(find(age>1e3)) + length(find(age<1e6))) > ...
%@%         length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i)/1e3,'%4.2f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (kBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% elseif 0.5*(length(find(age>1e6)) + length(find(age<1e9))) > ...
%@%         length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i)/1e6,'%4.2f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (MBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% end
%@% % ---- End Set XTickLabels
%@% % ----------
%@% title([samplename,' ', proxyname,' records for regular, average sampling and', num2str(M), ...
%@%     ' different MC simulations'], 'fontweight', 'bold','fontsize',axlabftsz)
%@% set(gca,'xlim',[min(t),max(xlim)])
%@% set(gca,'ylim',[y_lo,y_up])
%@% box on
%@% % ----------------------------------------
%@
%@% %% Figure for the mean of the proxy records
%@% figpos(2) = figpos(2) + 1.5;
%@% hmean=figure('Name','Figure: Proxy record (Mean)','Toolbar','None',...
%@%     'Units','inches','OuterPosition',figpos);
%@% hold on
%@% y_up = max(prx+2*prxs);
%@% y_lo = min(prx-2*prxs);
%@% if adinf == 1
%@%     rectangle('Position',[x_lo,y_lo,x_hi-x_lo,0.99*(y_up-y_lo)],...
%@%         'FaceColor',[.85 .85 .85],'EdgeColor','None')
%@% end
%@% for s = 1:length(idx)
%@%     if s == 1
%@%         tmpl = 1;
%@%         if s ~= length(idx)             % hiatus at first measured age
%@%             tmp = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@%             if hia_depth
%@%                 tmp = hia_depth;
%@%             end
%@%             tmpu = find(d_prxy<tmp,1,'last');
%@%             hia_lo = tmpu;
%@%             hia_hi = find(d_prxy>=tmp,1,'first');
%@%             rectangle('Position',[t(hia_lo),y_lo,t(hia_hi)-t(hia_lo),...
%@%                 0.99*(y_up-y_lo)],'FaceColor',sunset,'EdgeColor','none')
%@%         else                            % no hiatus
%@%             tmpu = length(d_prxy);
%@%         end        
%@%     elseif s > 1 && s < length(idx)     % hiatus somewhere in between
%@%         tmp = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@%         if hia_depth
%@%             tmp = hia_depth;
%@%         end
%@%         tmpu = find(d_prxy<tmp,1,'last');
%@%         tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@%         tmpl = find(d_prxy>=tmpl,1,'first');
%@% %         if hia_depth
%@% %             tmpu = find(d_prxy<=hia_depth,1,'last');
%@% %             tmpl = find(d_prxy>=hia_depth,1,'first');
%@% %         end
%@%         hia_lo = tmpu;
%@%         hia_hi = find(d_prxy>=tmp,1,'first');
%@%         rectangle('Position',[t(hia_lo),y_lo,t(hia_hi)-t(hia_lo),...
%@%             0.99*(y_up-y_lo)],'FaceColor',sunset,'EdgeColor','none')
%@%     elseif s == length(idx) && s ~= 1   % marks end of vector
%@%         tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@%         if hia_depth
%@%             tmpl = hia_depth;
%@%         end
%@%         tmpl = find(d_prxy>=tmpl,1,'first');
%@%         tmpu = length(t);
%@%     end    
%@%     tmpx = t(tmpl:tmpu);
%@%     tmpy = prx(tmpl:tmpu);
%@%     tmpe = prxs(tmpl:tmpu);
%@%     h1 = plot(tmpx,tmpy);
%@%     h2 = plot(tmpx,tmpy+2*tmpe,'r--',tmpx,tmpy-2*tmpe,'r--');
%@%     clear tmpx tmpy tmp hia_lo hia_hi
%@% end
%@
%@% h = [h1;h2];
%@% set(gca,'fontsize',10)             % General minimum fontsize in figure
%@% axlabftsz = 12;                              % fontsize for axis labels
%@% ylabel(proxyname,'fontsize',axlabftsz,'fontweight', 'bold')
%@% % ---- Set X-axis limits
%@% xhi = max(age);xlo=min(age);
%@% set(gca,'XLim',[xlo-(xhi-xlo)*0.1,xhi+(xhi-xlo)*0.1])
%@% % ---- Set XTicks (ALWAYS ONLY 7 in number)
%@% xlo = min(xlim);xhi = max(xlim);
%@% xtik = xlo:(xhi-xlo)/8:xhi;
%@% xtik(1) = [];
%@% set(gca,'XTick',xtik)
%@% % ---- Set XTickLabels
%@% if length(find(age<1000)) > length(age)/2 % >50% ages less than 1000 BP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i),'%5.1f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (BP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% elseif 0.5*(length(find(age>1e3)) + length(find(age<1e6))) > ...
%@%         length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i)/1e3,'%4.2f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (kBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% elseif 0.5*(length(find(age>1e6)) + length(find(age<1e9))) > ...
%@%         length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i)/1e6,'%4.2f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (MBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% end
%@% % ---- End Set XTickLabels
%@% % ----------
%@% h(3) = [];
%@% legend(h,{'Mean';'2\sigma (95% conf. int.)'},...
%@%     'Location','SouthOutside')
%@% title([samplename,' ', proxyname,...
%@%     ' Mean record for regular, average sampling;', num2str(M), ...
%@%     ' different MC simulations; (' interp_method ') interpolation'],...
%@%     'fontweight', 'bold','fontsize',axlabftsz)
%@% set(gca,'xlim',[min(t),max(xlim)])
%@% set(gca,'ylim',[y_lo,y_up])
%@% box on
%@% % ----------------------------------------
%@
%@% %% Figure for the median of the proxy records
%@% figpos(2) = figpos(2) + 1.5;
%@% hmed=figure('Name','Figure: Proxy record (Median)','Toolbar','None',...
%@%     'Units','inches','OuterPosition',figpos);
%@
%@% hold on
%@% y_up = max(prxm+2*prxs);
%@% y_lo = min(prxm-2*prxs);
%@% if adinf == 1
%@%     rectangle('Position',[x_lo,y_lo,x_hi-x_lo,0.99*(y_up-y_lo)],...
%@%         'FaceColor',[.85 .85 .85],'EdgeColor','None')
%@% end
%@% for s = 1:length(idx)
%@%     if s == 1
%@%         tmpl = 1;
%@%         if s ~= length(idx)             % hiatus at first measured age
%@%             tmp = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@%             if hia_depth
%@%                 tmp = hia_depth;
%@%             end
%@%             tmpu = find(d_prxy<tmp,1,'last');            
%@%             hia_lo = tmpu;
%@%             hia_hi = find(d_prxy>=tmp,1,'first');
%@%             rectangle('Position',[t(hia_lo),y_lo,t(hia_hi)-t(hia_lo),...
%@%                 0.99*(y_up-y_lo)],'FaceColor',sunset,'EdgeColor','none')
%@%         else                            % no hiatus
%@%             tmpu = length(d_prxy);
%@%         end        
%@%     elseif s > 1 && s < length(idx)     % hiatus somewhere in between
%@%         tmp = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@%         if hia_depth
%@%             tmp = hia_depth;
%@%         end
%@%         tmpu = find(d_prxy<tmp,1,'last');
%@%         tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@%         tmpl = find(d_prxy>=tmpl,1,'first');
%@% %         if hia_depth
%@% %             tmpu = find(d_prxy<=hia_depth,1,'last');
%@% %             tmpl = find(d_prxy>=hia_depth,1,'first');
%@% %         end
%@%         hia_lo = tmpu;
%@%         hia_hi = find(d_prxy>=tmp,1,'first');
%@%         rectangle('Position',[t(hia_lo),y_lo,t(hia_hi)-t(hia_lo),...
%@%             0.99*(y_up-y_lo)],'FaceColor',sunset,'EdgeColor','none')
%@%     elseif s == length(idx) && s ~= 1   % marks end of vector
%@%         tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@%         if hia_depth
%@%             tmpl = hia_depth;
%@%         end
%@%         tmpl = find(d_prxy>=tmpl,1,'first');        
%@%         tmpu = length(t);
%@%     end    
%@%     tmpx = t(tmpl:tmpu);
%@%     tmpy = prxm(tmpl:tmpu);
%@%     tmpe = prxs(tmpl:tmpu);
%@%     h1 = plot(tmpx,tmpy);
%@%     h2 = plot(tmpx,tmpy+2*tmpe,'r--',tmpx,tmpy-2*tmpe,'r--');
%@%     clear tmpx tmpy tmp hia_lo hia_hi
%@% end
%@% h = [h1;h2];
%@% h(3) = [];
%@% set(gca,'fontsize',10)             % General minimum fontsize in figure
%@% axlabftsz = 12;                              % fontsize for axis labels
%@% ylabel(proxyname,'fontsize',axlabftsz,'fontweight', 'bold')
%@% % ---- Set X-axis limits
%@% xhi = max(age);xlo=min(age);
%@% set(gca,'XLim',[xlo-(xhi-xlo)*0.1,xhi+(xhi-xlo)*0.1])
%@% % ---- Set XTicks (ALWAYS ONLY 7 in number)
%@% xlo = min(xlim);xhi = max(xlim);
%@% xtik = xlo:(xhi-xlo)/8:xhi;
%@% xtik(1) = [];
%@% set(gca,'XTick',xtik)
%@% % ---- Set XTickLabels
%@% if length(find(age<1000)) > length(age)/2 % >50% ages less than 1000 BP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i),'%5.1f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (BP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% elseif 0.5*(length(find(age>1e3)) + length(find(age<1e6))) > ...
%@%         length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i)/1e3,'%4.2f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (kBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% elseif 0.5*(length(find(age>1e6)) + length(find(age<1e9))) > ...
%@%         length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@%     xtiklab = cell(size(xtik));
%@%     for i = 1:length(xtik)
%@%         xtiklab{i} = num2str(xtik(i)/1e6,'%4.2f');
%@%     end
%@%     set(gca,'XTickLabel',xtiklab)
%@%     xlabel('Age (MBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@% end
%@% % ---- End Set XTickLabels
%@% % ----------
%@% legend(h,{'Median';'2\sigma (95% conf. int.)';[interp_method, ' interp.']},...
%@%     'Location','SouthOutside')
%@% title([samplename,' ', proxyname,...
%@%     ' Median record for', num2str(M), ...
%@%     ' different MC simulations, ' interp_method ' interpolation'],...
%@%     'fontweight', 'bold','fontsize',axlabftsz)
%@% set(gca,'xlim',[min(t),max(xlim)])
%@% set(gca,'ylim',[y_lo,y_up])
%@% box on
%@
%@
%@%% export to variables
%@T_unc=[d_prxy,v_prxy,time]; % depth-certain, proxy certain, time uncertain
%@T_cert=[age_val,prx_val_mean,prx_val_median,age_err,prx_err];
%@
%@%varargout{1}=[hmed h_hist hspagh hmean];
%@
%@d.T_unc = T_unc;
%@d.T_cert = T_cert;
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/GUI_getlayercount.m__ -->
%@function varargout = GUI_getlayercount(d)
%@% GETLAYERCOUNT Import layer count information.
%@%     DATA = GETLAYERCOUNT(GUI,LOGFILENAME) imports data of layer count
%@%     records. GUI specifies whether a GUI is used or not, LOGFILENAME
%@%     is the name of the file, where all meta information is saved or loaded
%@%     from.
%@
%@
%@
%@
%@%% init
%@filenameLC = d.filenameLC;
%@lc = [];
%@
%@
%@%% import layer count data
%@
%@if exist(filenameLC)
%@    % load layer count data
%@    lc = load(filenameLC);
%@
%@    % check for monotonicity of the layer count data
%@    if any(diff(lc(:,2))) < 0
%@        error('Layer count data must be monotonic!')
%@    end
%@else
%@    warning('Enter layer count data path!')
%@end
%@
%@
%@
%@%% return data
%@if nargout == 1 && size(lc,2) == 3 
%@    data.d_lc = lc(:,1);
%@    data.v_lc = lc(:,2);
%@    data.e_lc = lc(:,3);
%@    varargout{1} = data;
%@elseif nargout == 3 && size(lc,2) == 3
%@    varargout{1} = lc(:,1);
%@    varargout{2} = lc(:,2);
%@    varargout{3} = lc(:,3);
%@end
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/GUI_loaddata.m__ -->
%@function d = GUI_loaddata(d)
%@% GETDATA Import dating table and proxy data.
%@%     DATA = GETDATA(STRUCT) imports data of datings and proxy
%@%     records. 
%@
%@%% import age model data and check for number of headerlines
%@
%@
%@nHeaderlines = 0;
%@fid = fopen(d.filenameAD, 'r');
%@
%@ if fid < 0 | exist(d.filenameProxy,'file') == 0
%@     error('File not found.')
%@ end
%@
%@while 1
%@    c = textscan(fid,'%f%f%f','headerlines',nHeaderlines,'whitespace',' \b\t,;');
%@       
%@    if (isempty(c{1})) % still a headerline
%@        nHeaderlines = nHeaderlines + 1;
%@    else % data section reached, break
%@        break
%@    end
%@end
%@fclose(fid);
%@
%@
%@% variables
%@d.depth = c{1};
%@d.age = c{2};
%@d.ageerror = c{3};
%@%comment = c{4};
%@d.id = 1:length(d.depth);
%@
%@
%@clear c
%@clear fid
%@
%@%% Import proxy data
%@nHeaderlines = 0;
%@fid = fopen(d.filenameProxy, 'r');
%@
%@while 1
%@    
%@    % import dating data
%@    if isoctave % octave calling
%@        c = textscan2(fid,'%f%f%f','headerlines',nHeaderlines,'whitespace',' \b\t,;');
%@    else % matlab calling
%@        c = textscan(fid,'%f%f%f','headerlines',nHeaderlines,'whitespace',' \b\t,;');
%@    end
%@    
%@    if (isempty(c{1})) % still a headerline
%@        nHeaderlines = nHeaderlines + 1;
%@    else % data section reached, break
%@        break
%@    end
%@end
%@fclose(fid);
%@
%@% remove the rows that contain nan's from the data
%@% for i = 1:2
%@%     [nan_row,nan_col] = find(isnan(c{i}));
%@%      c{1}(nan_row) = []; 
%@%      c{2}(nan_row) = [];
%@% end
%@
%@% variables
%@d.d_prxy = c{1};
%@d.v_prxy = c{2};
%@
%@clear c
%@
%@%% check if inputfiles have correct stratigraphic order
%@d.bad_input = 0;
%@strata_check_prxy = zeros(1,length(d.d_prxy)-1);
%@strata_check_depth = zeros(1,length(d.depth)-1);
%@
%@for i = 2:length(d.d_prxy)
%@    strata_check_prxy(i-1) = d.d_prxy(i) - d.d_prxy(i-1);
%@end
%@
%@for i = 2:length(d.depth)
%@    strata_check_depth(i-1) = d.depth(i) - d.depth(i-1);
%@end
%@
%@badLines_prxy = find(strata_check_prxy <= 0);
%@badLines_depth = find(strata_check_depth <= 0);
%@
%@if any(badLines_prxy) && any(badLines_depth)
%@    uiwait(errordlg(['ERROR: Both input files contain multiple or incorrectly ordered '...
%@        'depth entries! Check around the lines:', sprintf('\n') ,num2str(badLines_depth), ' (AD file)',...
%@        sprintf('\n'), num2str(badLines_prxy),' (Proxy file)'], 'Input file error',...
%@        'replace'));
%@    d.bad_input = 1;
%@elseif any(badLines_prxy)
%@    uiwait(errordlg(['ERROR: The proxy file contains multiple or incorrectly ordered '...
%@        'depth entries! Check around the lines: ',num2str(badLines_prxy)], 'Proxy file error',...
%@        'replace'));
%@    d.bad_input = 1;
%@elseif any(badLines_depth)
%@    uiwait(errordlg(['ERROR: The age-depth file contains multiple or incorrectly ordered '...
%@        'depth entries! Check around the lines: ',num2str(badLines_depth)], 'AD file error',...
%@        'replace'));
%@    d.bad_input = 1;
%@end
%@
%@%% checking for NaNs in the imported data
%@nanidx = isnan(d.depth) + isnan(d.age) + isnan(d.ageerror);
%@if any(nanidx)
%@    uiwait(msgbox('Age-Depth data contains NaNs! NaNs will be removed.','COPRA','modal'));
%@    nanidx = find(nanidx);
%@    d.depth(nanidx) = [];
%@    d.age(nanidx) = [];
%@    d.ageerror(nanidx) = [];
%@    d.nan_AD = nanidx;
%@end
%@
%@
%@
%@if length(d.d_prxy) ~= length(d.v_prxy)
%@    errordlg('Column length in proxy record differ. Please check the proxy record file!','COPRA')
%@end
%@
%@nanidx = isnan(d.d_prxy) + isnan(d.v_prxy);
%@if any(nanidx)
%@    uiwait(msgbox('Proxy data contains NaNs! NaNs will be removed!','COPRA','modal'));
%@    nanidx = find(nanidx);
%@    d.d_prxy(nanidx) = [];
%@    d.v_prxy(nanidx) = [];
%@    d.nan_prxy = nanidx;
%@end
%@
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/GUI_plotAD.m__ -->
%@function d = GUI_plotAD(d)
%@% Plots the age-depth input dataset from the graphical COPRA
%@
%@%%
%@hia_depth = d.hia_depth_numIn;
%@
%@errorbarxy(d.age,d.depth,d.ageerror,[])
%@hold on
%@
%@if hia_depth
%@    for i=1:length(hia_depth)
%@        line(get(gca,'xlim'),[hia_depth(i) hia_depth(i)],'color','r','Linestyle','--')
%@    end
%@end
%@
%@axis ij
%@grid on
%@ylim([-1 max(d.depth)+max(d.depth)/10])
%@for i = 1:length(d.age)
%@    text(- range(xlim)/100 + d.age(i),range(ylim)/25 + d.depth(i),num2str(d.id(i)))     
%@end
%@
%@hold off
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/GUI_specifyHiatus.m__ -->
%@function d = GUI_specifyHiatus(d)
%@% specify Hiatus depth
%@%%
%@depth = d.depth;
%@d.hiatus = zeros(size(d.age));
%@d.hiatus(end) = 1;
%@
%@for hiatNo = 1:length(d.hia_depth)    
%@            
%@         
%@    tmp1  = find(depth < d.hia_depth(hiatNo),1,'last'); % compare to dating table...
%@    tmp2  = find(depth > d.hia_depth(hiatNo),1,'first');% ... should lie between two dating points
%@    if ~isempty(tmp1) && ~isempty(tmp2)
%@        disp(['Hiatus between ' sprintf(' %g ', d.id(tmp1)) 'and' sprintf(' %g ', d.id(tmp2)) ])
%@        d.hiatus(tmp1) = 1;
%@    else
%@        error('The entered depth must be within the depth range of the dating table');
%@    end
%@end
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/GUI_writeLog.m__ -->
%@function GUI_writeLog(d)
%@% write the logfile if requested 
%@
%@%%
%@
%@% log logfilename
%@savelog(d.log,'d.log','filename')
%@
%@% name of sample and proxy
%@savelog(d.log,'d.samplename','project name:')
%@savelog(d.log,'d.proxyname','name of the proxy:')
%@
%@% log filenames
%@savelog(d.log,'d.filenameAD','Name of the file with the datings:')
%@savelog(d.log,'d.filenameProxy','Name of the proxy data file:')
%@
%@% log NaN-removals
%@if exist('d.nan_AD','var')
%@    savelog(d.log,'d.nan_AD','NaNs removed in the age-depth data:')
%@end
%@if exist('d.nan_prxy','var')
%@    savelog(d.log,'d.nan_prxy','NaNs removed in the proxy data:')
%@end
%@
%@
%@% raw Age-depth data
%@if any(d.removePts)
%@    savelog(d.log,'d.id_backup',['Raw data',10,'% ID:'])
%@    savelog(d.log,'d.depth_backup',['depth:'])
%@    savelog(d.log,'d.age_backup','age:')
%@    savelog(d.log,'d.ageerror_backup','ageerror:')
%@else
%@    savelog(d.log,'d.id',['Dating values',10,'% ID:'])
%@    savelog(d.log,'d.depth',['depth:'])
%@    savelog(d.log,'d.age','age:')
%@    savelog(d.log,'d.ageerror','ageerror:')
%@end
%@
%@% proxy data
%@savelog(d.log,'d.d_prxy','depth axis proxy record:')
%@savelog(d.log,'d.v_prxy','values of the proxy record:')
%@
%@
%@
%@if any(d.removePts) || any(d.incErr)
%@    % treatment of points
%@    savelog(d.log,'d.rev_treat','Treated points:')
%@    savelog(d.log,'d.removePts','Removed points number:')
%@    savelog(d.log,'d.incErr', 'Increased error bars of points number:')
%@    
%@    % Age-depth data after treatment
%@    savelog(d.log,'d.id',['Modified data',10,'% ID:'])
%@    savelog(d.log,'d.depth',['depth:'])
%@    savelog(d.log,'d.age','age:')
%@    savelog(d.log,'d.ageerror','ageerror:')
%@end
%@
%@% Hiatus
%@if any(d.hia_depth)
%@    savelog(d.log,'d.hia_depth','Hiatus depth(s):')
%@end
%@% correctd agemodel
%@finalagemodel = [d.depth d.age d.ageerror];
%@savelog(d.log,'finalagemodel','Corrected age model without reversals:')
%@
%@% Number of MC
%@savelog(d.log,'d.M', 'Number of Monte Carlo samples')
%@
%@% interpolation method
%@savelog(d.log,'d.interp_method','Interpolation method')
%@
%@% confidence bounds
%@savelog(d.log,'d.confbnds_prxy','Confidence bounds Proxy (in output file):')
%@savelog(d.log,'d.confbnds_age','Confidence bounds Ages (in output file):')
%@
%@
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/LimitSizeFig.m__ -->
%@function Out = LimitSizeFig(FigH, Prop, Ext)
%@% LimitSizeFig - Set minimum and maximum figure size
%@% Out = LimitSizeFig(FigH, Prop, Ext)
%@% INPUT:
%@%   FigH: Handle of a Matlab figure.
%@%         Optional, default: current figure.
%@%   Prop: String, command:
%@%         'min': Set minimum extent.
%@%         'max': Set maximum extent.
%@%         'get': Reply a struct with fields MinSize and MaxSize. If not limited,
%@%                the empty matrix [] is replied.
%@%         'clear': Clear the min and max limits.
%@%   Ext:  Extent as [1 x 2] vector, minimal width and height in pixels.
%@%         The inner position is affected.
%@%
%@% OUTPUT:
%@%   Out:  Output for the 'get' command.
%@%
%@% EXAMPLES:
%@%   FigH = figure;
%@%   LimitSizeFig(FigH, 'min', [200, 200])
%@%   LimitSizeFig('max', [400, 400])       % Uses GCF
%@%   Limit = LimitSizeFig(FigH, 'get')
%@%
%@% Tested: Matlab 7.7, 7.8, 7.13, WinXP/32, Win7/64
%@%         Not compatible to Matlab 6.5.
%@% Author: Jan Simon, Heidelberg, (C) 2012 matlab.THISYEAR(a)nMINUSsimon.de
%@
%@% $JRev: R-c V:002 Sum:yOpp5+kQXtGq Date:08-Oct-2012 01:18:52 $
%@% $License: BSD (use/copy/change/redistribute on own risk, mention the author) $
%@% $UnitTest: uTest_LimitSizeFig $
%@% $File: Tools\GLGui\LimitSizeFig.m $
%@% History:
%@% 001: 07-Oct-2012 15:02, First version.
%@
%@% Initialize: ==================================================================
%@% Global Interface: ------------------------------------------------------------
%@if ~usejava('jvm')
%@   % Should this be an error, a warning or a message??
%@   warning(['JSimon:', mfilename, ':NeedJava'], ...
%@            '*** %s: Java is required.', mfilename);
%@   return;
%@end
%@
%@% Initial values: --------------------------------------------------------------
%@% Program Interface: -----------------------------------------------------------
%@% Parse the inputs:
%@switch nargin
%@   case 0
%@      FigH = gcf;
%@      Prop = 'min';
%@      Ext  = [];
%@   case 1
%@      if numel(FigH) == 1 && ishandle(FigH)  % LimitSizeFig(FigH)
%@         Prop = 'min';
%@         Ext  = [];
%@      elseif ischar(FigH)                    % LimitSizeFig('string')
%@         Prop = FigH;
%@         Ext  = [];
%@         FigH = GetCurrentFigure;
%@      else                                   % LimitSizeFig([W, H])
%@         Prop = 'min';
%@         Ext  = FigH;
%@         FigH = GetCurrentFigure;
%@      end
%@   case 2
%@      if ischar(FigH)                        % LimitSizeFig('string', [W, H])
%@         Ext  = Prop;
%@         Prop = FigH;
%@         FigH = GetCurrentFigure;
%@      elseif numel(FigH) == 1 && ishandle(FigH)
%@         if ischar(Prop)                     % LimitSizeFig(FigH, 'string')
%@            Ext  = [];
%@         else                                % LimitSizeFig(FigH, [W, H])
%@            Ext  = Prop;
%@            Prop = 'min';
%@         end
%@      else
%@         error(['JSimon:', mfilename, ':BadHandle'], ...
%@            '*** %s: 1st input is not a figure handle or string.', mfilename);
%@      end
%@   case 3
%@      % Nothing to do
%@   otherwise
%@end
%@
%@% Check if input is a figure handle:
%@if numel(FigH) ~= 1 || ~ishandle(FigH) || ...     % Short-circuit
%@      ~strcmpi(get(FigH, 'Type'), 'figure')
%@   error(['JSimon:', mfilename, ':BadHandle'], ...
%@          '*** %s: 1st input is not a figure handle.', mfilename);
%@end
%@
%@% User Interface: --------------------------------------------------------------
%@% Do the work: =================================================================
%@% Get the Java frame:
%@jFrame = get(handle(FigH), 'JavaFrame');  % Fails in Matlab < 7.0
%@try    % R2008a until R2014a
%@   jClient = jFrame.fHG1Client;
%@catch
%@   try % R2014b and newer
%@       jClient = jFrame.fHG2Client;
%@    catch  % R2007b and earlier
%@       jClient = jFrame.fFigureClient;
%@   end
%@end
%@
%@% The com.mathworks.hg.peer.FigureFrameProxy is empty, if no DRAWNOW allowed to
%@% update the figure since its creation:
%@jWindow = jClient.getWindow;
%@if isempty(jWindow)
%@   drawnow;
%@   pause(0.02);
%@   jWindow = jClient.getWindow;       
%@end
%@
%@% Apply, clear or get the limits:
%@if strncmpi(Prop, 'min', 3)
%@   Ext = GetExtent(FigH, Ext);   
%@   jWindow.setMinimumSize(java.awt.Dimension(Ext(1), Ext(2)));
%@elseif strncmpi(Prop, 'max', 3)
%@   Ext = GetExtent(FigH, Ext);
%@   jWindow.setMaximumSize(java.awt.Dimension(Ext(1), Ext(2)));
%@elseif strcmpi(Prop, 'clear')
%@   jWindow.setMinimumSize([]);
%@   jWindow.setMaximumSize([]);
%@elseif strcmpi(Prop, 'get')
%@   % Get difference to outer limits:
%@   bakUnits = get(FigH, 'Units');
%@   set(FigH, 'Units', 'pixels');
%@   DiffPos = get(FigH, 'OuterPosition') - get(FigH, 'Position');
%@   set(FigH, 'Units', bakUnits);
%@
%@   jDim        = jWindow.getMinimumSize;
%@   Out.MinSize = [jDim.getWidth, jDim.getHeight] - DiffPos(3:4);
%@   jDim        = jWindow.getMaximumSize;
%@   Out.MaxSize = [jDim.getWidth, jDim.getHeight] - DiffPos(3:4);
%@end
%@
%@% return;
%@
%@% ******************************************************************************
%@function FigH = GetCurrentFigure()
%@% A DRAWNOW is required when the figure is created to update the Java handle.
%@% See GCF.
%@
%@FigH = get(0, 'CurrentFigure');
%@
%@if isempty(FigH)
%@   FigH = figure;
%@   drawnow;
%@end
%@
%@% return;
%@
%@% ******************************************************************************
%@function Ext = GetExtent(FigH, Ext)
%@% Get or convert extent to outer position.
%@
%@bakUnits = get(FigH, 'Units');
%@set(FigH, 'Units', 'pixels');
%@OuterPos = get(FigH, 'OuterPosition');
%@if isempty(Ext)
%@   Ext = OuterPos(3:4);
%@elseif isnumeric(Ext) && numel(Ext) == 2 && all(Ext >= 0)
%@   InnerPos = get(FigH, 'Position');
%@   Ext      = [Ext(1) + OuterPos(3) - InnerPos(3), ...
%@               Ext(2) + OuterPos(4) - InnerPos(4)];
%@else
%@   error(['JSimon:', mfilename, ':BadSize'], ...
%@          '*** %s: Extent must be a positive [1 x 2] vector.', mfilename);
%@end
%@set(FigH, 'Units', bakUnits);
%@
%@% return;
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/chkEndRevs.m__ -->
%@function [t_new, x_new, time] = chkEndRevs(t_new,x_new,time,d)
%@% chkEndRevs Make sure that there is no reversal due to extrapolation.
%@% Part of COPRA_O1.0
%@    
%@    depth=d.depth;
%@    age=d.age;
%@    d_prxy=d.d_prxy;
%@    ageerror=d.ageerror;
%@    varnce=1;
%@    interp_method=d.interp;
%@    
%@    
%@    if any(diff(time(end-1:end,:)) < 0) % if reversals at end
%@    disp('Reversal at end!')
%@        goback = 2; % size of last piece over which will be interpolated, must be > 1!
%@        depth(end+1,1) = d_prxy(end,1); % add a new last point to the age model, which is at the depth of the last measurement point
%@        last_points = interp1(depth(end-goback:end-1), age(end-goback +1:end), depth(end-goback:end),'linear','extrap');
%@        age(end+1) = last_points(end); % new last point in age model
%@        ageerror(end+1) = sum(ageerror(end-goback+1:end)); % allow a larger dating error    
%@        %%%%%%%
%@        N = length(ageerror);
%@        i = varnce*randn(N, M);
%@        t_new = repmat(age, 1, M) + repmat(ageerror, 1, M) .* i; % time with errors
%@        x_new = repmat(depth, 1, M) + .1 * randn(N, M)/2; % dating positions with erros
%@        time = interp1(depth, t_new, d_prxy,interp_method,'extrap');      %cubic interpolation
%@    end
%@end
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/chkRevs.m__ -->
%@function revType = chkRevs(varargin)
%@% CHKREVS Checks an agemodel for reversals.
%@%     REVS = CHKREVS(DEPTH,AGE,AGEERROR) checks whether the age model
%@%     given by the triplet DEPTH, AGE, and AGEERROR contains (tractable and
%@%     non-tractable) reversals. 
%@%     REVS is a vector of length(AGE) with entries for no-reversals (REVS=0),
%@%     tractable reversals (REVS=1) and non-tractable reversals (REVS=2).
%@%
%@%     REVS = CHKREVS(DATASTRUCT) checks for reversals by using the
%@%     struct DATASTRUCT with the fields DATASTRUCT.DEPTH, DATASTRUCT.AGE,
%@%     and DATASTRUCT.AGEERROR.
%@
%@%% check input 
%@
%@
%@mynarginchk(nargin, 1, 3)
%@
%@% get input variables
%@if nargin
%@    idxNum = find(cellfun('isclass',varargin,'double'));
%@    idxStruct = find(cellfun('isclass',varargin,'struct'));
%@    % get numerical input arguments (data)
%@    if ~isempty(idxNum) && length(idxNum) >= 3
%@            d.depth = varargin{idxNum(1)};
%@            d.age = varargin{idxNum(2)};
%@            d.ageerror = varargin{idxNum(3)};
%@    end
%@    % get struct input arguments (data)
%@    if ~isempty(idxStruct)
%@            d = varargin{idxStruct(1)};
%@    end
%@end
%@if isfield(d,'gui') == 0; d.gui = 0; end
%@
%@%%
%@if any(diff(d.depth)<0)
%@    error('Age is not increasing monotonously along the core!')
%@end
%@
%@
%@%% differentiate between non-tractable and tractable reversals
%@% Each two successive dating points will have a reversion type and get a treatment prescribed
%@% later. 
%@% 0=no reversal, 1=tractable, 2=non-tractable reversal
%@
%@nontract = ((d.age(1:end-1)-2*d.ageerror(1:end-1))>(d.age(2:end)+2*d.ageerror(2:end))) & (d.age(1:end-1)>d.age(2:end));
%@tract = ((d.age(1:end-1)-2*d.ageerror(1:end-1))<=(d.age(2:end)+2*d.ageerror(2:end))) & (d.age(1:end-1)>d.age(2:end));
%@
%@revType = 2*nontract + tract;
%@
%@%% display a warning message
%@warnStr = '';
%@if any(tract)
%@    warnStr = [warnStr, '(1) Tractable reversal with overlapping or ', ...
%@            'touching 2 std. error.',10];
%@end
%@
%@if any(nontract)
%@    warnStr = [warnStr, '(2) Non-tractable reversal: 2 std. ',...
%@            'error bars do not overlap.',10];
%@end
%@
%@%warnStr
%@if any(tract)||any(nontract)
%@    if d.gui == 1 && ~isoctave
%@        h = warndlg(warnStr,'Age reversal found!'); % matlab legacy
%@    elseif d.gui == 0
%@        warnStr = ['Age reversal found!',10,warnStr];
%@        disp(warnStr)
%@    end
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/chkhiatus_cl.m__ -->
%@function d = chkhiatus_cl(d)
%@% CHKhiatus Checks the growth rate of the age model, indicating potential hiatuses.
%@%   CHKhiatus_CL(D) checks whether the age model given in structure D
%@%   contains potential growth rate changes that could indicate a growth
%@%   interruption (hiatus). The entries in vector D.HIATUS are one if a hiatus
%@%   is to be treated by splitting the age model construction. Hiatuses can
%@%   also be specified by hand, with the corresponding depths exported in
%@%   D.HIA_DEPTH.
%@
%@hia_depth=[];
%@
%@depth = d.depth;
%@age = d.age;
%@d.hiatus = zeros(size(d.age));
%@d.hiatus(end) = 1;
%@d.hia_depth = [];
%@%% Hiatus detection
%@% sedimentation or accumulation rate in depth/time should be strictly positive, though because of uncertainty reversals may occur.
%@sedrate=diff(depth)./diff(age);
%@% sedrate gives an estimate of the slope between two points in the agemodel
%@
%@% Assuming Gaussianity the left-sided t-test will tell us whether the local slope at one point is significantly lower than the rest.
%@for i=1:length(sedrate),
%@    sedrem=sedrate;
%@    sedrem(i)=[]; % remove the point we're testing for from the data
%@    %%%h(i)=ttest(sedrem,sedrate(i),0.1, 'right'); % test whether the overall slope mean is significantly lower than the local slope
%@    if isoctave
%@        p_hi=t_test(sedrem,sedrate(i),'>');
%@        if p_hi < 0.005
%@            h(i)=1;
%@        else
%@            h(i)=0;
%@        end
%@        clear sedrem
%@        clear p_hi
%@        
%@    else
%@        h(i)=ttest(sedrem,sedrate(i),0.005, 'right'); % test whether the overall slope mean is significantly lower than the local slope
%@    end
%@end
%@
%@% display info on potential hiatuses:
%@idx=find(h>0);
%@if ~isempty(idx)
%@    disp(['Potential hiatus(es) after dating points: ' sprintf('%g  ', d.id(idx))])
%@    % assign hiatus depths at midpoint between dating point idx(i) and
%@    % idx(i)+1
%@    hia_depth=zeros(length(idx),1);
%@    %for i=1:length(idx)
%@        %d.depth(idx)
%@        hia_depth=(d.depth(idx)+d.depth(idx+1))/2;
%@    %end
%@    disp(['Potential hiatus(es) at ' sprintf('%g ', hia_depth) d.depthname])
%@end
%@%d.hia_depth=hia_depth;
%@%% Display/ ask
%@%********************%********************%********************%********************
%@if isempty(idx) % no hiatus detected
%@    disp(['Checking growth rates: No potential hiatus found. You can either proceed',...
%@        'to age-model construction or specify a hiatus yourself.']);
%@    choices={'Proceed to age-model construction',...
%@        'Specify a hiatus myself', 'Cancel (Exits entire program!)'};
%@    %%%choice=menu(['Checking growth rates: No potential hiatus found! What do you',...
%@    %%%   'wish to do?'],choices);
%@    if isoctave 
%@        disp(['Checking growth rates: No potential hiatus found. You can either proceed',...
%@        'to age-model construction or specify a hiatus yourself.']);
%@        choice = menu(['Checking growth rates: No potential hiatus found! What do you','wish to do?'],'Proceed to age-model construction',...
%@        'Specify a hiatus myself', 'Cancel (Exits entire program!)');
%@    else
%@        choice = input(['Checking growth rates: No potential hiatus found! What do you','wish to do?\n'...
%@        '[1] Proceed to age-model construction (default)\n [2] Specify a hiatus myself\n [3] Cancel (Exits entire program!)\n']);
%@    end
%@    if isempty(choice)
%@        choice = 1;
%@    end
%@    fprintf('Do %s.\n', choices{choice})
%@    
%@    switch choice
%@        case 1
%@            return
%@            % assign variables hia_depth and hiatus
%@            d.hia_depth=[];
%@            % return to copra
%@        case 2
%@             hia_depth=[];
%@            d.hia_depth=[];
%@            specifyhiatus=true;
%@            hiatno=0;
%@            while specifyhiatus
%@                hiatno=hiatno+1;
%@                prompt = 'Enter hiatus depth:';
%@                d.hia_depth(hiatno) = input(prompt); % hiatus depth
%@                tmp1  = find(depth < d.hia_depth(hiatno),1,'last'); % compare to dating table...
%@                tmp2  = find(depth > d.hia_depth(hiatno),1,'first');% ... should lie between two dating points
%@                if ~isempty(tmp1) && ~isempty(tmp2)
%@                    disp(['Hiatus between ' sprintf(' %g ', d.id(tmp1)) 'and' sprintf(' %g ', d.id(tmp2)) ])
%@                    d.hiatus(tmp1)=1;
%@                else
%@                    error('The entered depth must be within the depth range of the dating table');
%@                end
%@                % If a hiatus is specified manually, the agemodel will
%@                % always be split --> other manipulations could be
%@                % performed on the dating table itself!
%@                % Question dialogue for additional hiatuses
%@                choiceIn = input('Do you wish to enter another hiatus? [Yes/NO]: ','s');
%@                if isempty(choiceIn)
%@                   % choice = 'n';
%@                   specifyhiatus=false;
%@                else
%@                    switch(lower(choiceIn(1)))
%@                        case {'y','yes', 'j'}
%@                            specifyhiatus=true;
%@                        otherwise
%@                            specifyhiatus=false;
%@                    end
%@                end
%@            end% specifyhiatus
%@            % define hiatus by depth
%@
%@        case 3 % cancel everything
%@            error('Cancel')
%@    end
%@%********************%********************%********************%********************    
%@else % hiatus was found
%@    % list hiatus depth/ position
%@    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%@    %     hiatus = true;
%@    hia_idx = zeros(length(idx),2);
%@    for i = 1:length(idx)
%@        hia_idx(i,:) = [idx(i),idx(i)+1];
%@    end
%@    
%@    
%@    choices={'Proceed with potential hiatus(es)',...
%@        'Specify a hiatus myself',...
%@        'Ignore them. Proceed to Age Model construction.',...
%@        'Cancel (Exits entire program!)'};
%@    %%%choice=menu('Potential hiatuses. What do you wish to do?',choices);
%@    if isoctave
%@        disp(['Checking growth: Potential hiatus(es) detected. You can decide to',...
%@            ' accept or specify one yourself.']);
%@        choice = menu('Potential hiatuses found. What do you wish to do?','Proceed with potential hiatus(es)','Specify a hiatus myself','Ignore them. Return to Age Model construction.','Cancel (Exits entire program!)');
%@    else
%@        choice = input(['Potential hiatuses found. What do you wish to do?\n [1]',...
%@        ' Proceed with potential hiatus(es)\n [2] Specify a hiatus myself\n [3]',...
%@        ' Ignore them. Proceed to Age Model construction (default)\n [4] Cancel (Exits entire program!)\n']);
%@    end
%@    if isempty(choice)
%@        choice = 3;
%@    end
%@    fprintf('Do %s.\n', choices{choice})
%@    switch choice
%@        case 1 % accept the detected hiatus
%@            d.hia_depth=hia_depth;
%@            d.hiatus(idx)=1;
%@%             d
%@%             d.hia_depth
%@%             d.hiatus
%@%             d = treathiatus_cl(d);
%@%             
%@            
%@        case 2 % specify a hiatus yourself
%@            hia_depth=[];
%@            d.hia_depth=[];
%@            specifyhiatus=true;
%@            hiatno=0;
%@            while specifyhiatus
%@                hiatno=hiatno+1;
%@                prompt = 'Enter hiatus depth:';
%@                d.hia_depth(hiatno) = (input(prompt)); % hiatus depth
%@                tmp1  = find(depth < d.hia_depth(hiatno),1,'last'); % compare to dating table...
%@                tmp2  = find(depth > d.hia_depth(hiatno),1,'first');% ... should lie between two dating points
%@                if ~isempty(tmp1) && ~isempty(tmp2)
%@                    disp(['Hiatus between ' sprintf(' %g ', d.id(tmp1)) 'and' sprintf(' %g ', d.id(tmp2)) ])
%@                    d.hiatus(tmp1)=1;
%@                else
%@                    error('The entered depth must be within the depth range of the dating table');
%@                end
%@                % If a hiatus is specified manually, the agemodel will
%@                % always be split --> other manipulations could be
%@                % performed on the dating table itself!
%@                % Question dialogue for additional hiatuses
%@                choiceIn = input('Do you wish to enter another hiatus? [Yes/NO]: ','s');
%@                if isempty(choiceIn)
%@                   % choice = 'n';
%@                   specifyhiatus=false;
%@                else
%@                    switch(lower(choiceIn(1)))
%@                        case {'y','yes', 'j'}
%@                            specifyhiatus=true;
%@                        otherwise
%@                            specifyhiatus=false;
%@                    end
%@                end
%@            end% specifyhiatus
%@        case 3 % return to am construction
%@            return
%@        case 4 % cancel everything
%@            error('Cancel')
%@    end
%@            
%@
%@end
%@%********************%********************%********************%********************
%@
%@
%@%%
%@%disp('chkhiatus')
%@if(sum(d.hiatus)<2) % if no hiatus is found/ treated by splitting the agemodel, make sure the correct hiatus vector is returned.
%@    d.hiatus=zeros(length(d.age),1);d.hiatus(end)=1;
%@else 
%@   disp('Hiatus(es) recognized')
%@end
%@
%@savelog(d.log,'d.hia_depth','Hiatus depth(s):')
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/errorbarxy.m__ -->
%@function varargout=errorbarxy(x,y,xerr,yerr,varargin)
%@% ERRORBARXY   Plots a time series with errorbars in x- and y-direction.
%@%   ERRORBARXY(X,Y,XERR,YERR) plots vector Y versus vector X
%@%   together with errors given by vextors XERR and YERR.
%@%
%@%   H=ERRORBARXY() returns the handle of the plot.
%@%   [H HX HY]=ERRORBAR() returns also the handles of the
%@%   errorbars.
%@
%@
%@mynarginchk(nargin,3,5)
%@
%@mt = 'o';mec = 'k'; mfc = 'k'; ms = 6.5;lt = '-';lw = 1.5;
%@caplw = 1; capsz = 1;lc = 'k';
%@
%@
%@hold on
%@hm = plot(x,y,mt,'MarkerEdgeColor',mec,'MarkerFaceColor',mfc,...
%@    'MarkerSize',ms);
%@
%@hx = zeros(length(x),3);
%@if ~isempty(xerr)
%@    for i = 1:length(x)
%@        hx(i,1) = line([x(i)-xerr(i),x(i)+xerr(i)],[y(i),y(i)],'LineStyle',lt,...
%@            'LineWidth',lw,'Color',lc);
%@        yunits = 0.01*(abs(diff(ylim)));
%@        capszy = capsz*yunits;
%@        hx(i,2) = line([x(i)-xerr(i),x(i)-xerr(i)],[y(i)-capszy,y(i)+capszy],...
%@            'LineStyle',lt,'LineWidth',caplw,'Color',lc);
%@        hx(i,3) = line([x(i)+xerr(i),x(i)+xerr(i)],[y(i)-capszy,y(i)+capszy],...
%@            'LineStyle',lt,'LineWidth',caplw,'Color',lc);
%@    end    
%@end
%@
%@hy = zeros(length(x),3);
%@if ~isempty(yerr)
%@    for i = 1:length(y)
%@        hy(i,1) = line([x(i),x(i)],[y(i)-yerr(i),y(i)+yerr(i)],'LineStyle',lt,...
%@            'LineWidth',lw,'Color',lc);
%@        xunits = 0.01*(abs(diff(xlim)));
%@        capszx = capsz*xunits;
%@        hy(i,2) = line([x(i)-capszx,x(i)+capszx],[y(i)-yerr(i),y(i)-yerr(i)],...
%@            'LineStyle',lt,'LineWidth',caplw,'Color',lc);
%@        hy(i,3) = line([x(i)-capszx,x(i)+capszx],[y(i)+yerr(i),y(i)+yerr(i)],...
%@            'LineStyle',lt,'LineWidth',caplw,'Color',lc);
%@    end    
%@end
%@
%@if nargout == 1
%@    varargout{1} = hm;
%@elseif nargout == 2
%@    varargout{1} = hm;
%@    varargout{2} = hx;    
%@elseif nargout == 3
%@    varargout{1} = hm;
%@    varargout{2} = hx;
%@    varargout{3} = hy;
%@end
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/findjobj.m__ -->
%@function [handles,levels,parentIdx,listing] = findjobj(container,varargin) %#ok<*CTCH,*ASGLU,*MSNU,*NASGU>
%@%findjobj Find java objects contained within a specified java container or Matlab GUI handle
%@%
%@% Syntax:
%@%    [handles, levels, parentIds, listing] = findjobj(container, 'PropName',PropValue(s), ...)
%@%
%@% Input parameters:
%@%    container - optional handle to java container uipanel or figure. If unsupplied then current figure will be used
%@%    'PropName',PropValue - optional list of property pairs (case insensitive). PropName may also be named -PropName
%@%         'position' - filter results based on those elements that contain the specified X,Y position or a java element
%@%                      Note: specify a Matlab position (X,Y = pixels from bottom left corner), not a java one
%@%         'size'     - filter results based on those elements that have the specified W,H (in pixels)
%@%         'class'    - filter results based on those elements that contain the substring  (or java class) PropValue
%@%                      Note1: filtering is case insensitive and relies on regexp, so you can pass wildcards etc.
%@%                      Note2: '-class' is an undocumented findobj PropName, but only works on Matlab (not java) classes
%@%         'property' - filter results based on those elements that possess the specified case-insensitive property string
%@%                      Note1: passing a property value is possible if the argument following 'property' is a cell in the
%@%                             format of {'propName','propValue'}. Example: FINDJOBJ(...,'property',{'Text','click me'})
%@%                      Note2: partial property names (e.g. 'Tex') are accepted, as long as they're not ambiguous
%@%         'depth'    - filter results based on specified depth. 0=top-level, Inf=all levels (default=Inf)
%@%         'flat'     - same as specifying: 'depth',0
%@%         'not'      - negates the following filter: 'not','class','c' returns all elements EXCEPT those with class 'c'
%@%         'persist'  - persist figure components information, allowing much faster results for subsequent invocations
%@%         'nomenu'   - skip menu processing, for "lean" list of handles & much faster processing;
%@%                      This option is the default for HG containers but not for figure, Java or no container
%@%         'print'    - display all java elements in a hierarchical list, indented appropriately
%@%                      Note1: optional PropValue of element index or handle to java container
%@%                      Note2: normally this option would be placed last, after all filtering is complete. Placing this
%@%                             option before some filters enables debug print-outs of interim filtering results.
%@%                      Note3: output is to the Matlab command window unless the 'listing' (4th) output arg is requested
%@%         'list'     - same as 'print'
%@%         'debug'    - list found component positions in the Command Window
%@%
%@% Output parameters:
%@%    handles   - list of handles to java elements
%@%    levels    - list of corresponding hierarchy level of the java elements (top=0)
%@%    parentIds - list of indexes (in unfiltered handles) of the parent container of the corresponding java element
%@%    listing   - results of 'print'/'list' options (empty if these options were not specified)
%@%
%@%    Note: If no output parameter is specified, then an interactive window will be displayed with a
%@%    ^^^^  tree view of all container components, their properties and callbacks.
%@%
%@% Examples:
%@%    findjobj;                     % display list of all javaelements of currrent figure in an interactive GUI
%@%    handles = findjobj;           % get list of all java elements of current figure (inc. menus, toolbars etc.)
%@%    findjobj('print');            % list all java elements in current figure
%@%    findjobj('print',6);          % list all java elements in current figure, contained within its 6th element
%@%    handles = findjobj(hButton);                                     % hButton is a matlab button
%@%    handles = findjobj(gcf,'position',getpixelposition(hButton,1));  % same as above but also return hButton's panel
%@%    handles = findjobj(hButton,'persist');                           % same as above, persist info for future reuse
%@%    handles = findjobj('class','pushbutton');                        % get all pushbuttons in current figure
%@%    handles = findjobj('class','pushbutton','position',123,456);     % get all pushbuttons at the specified position
%@%    handles = findjobj(gcf,'class','pushbutton','size',23,15);       % get all pushbuttons with the specified size
%@%    handles = findjobj('property','Text','not','class','button');    % get all non-button elements with 'text' property
%@%    handles = findjobj('-property',{'Text','click me'});             % get all elements with 'text' property = 'click me'
%@%
%@% Sample usage:
%@%    hButton = uicontrol('string','click me');
%@%    jButton = findjobj(hButton,'nomenu');
%@%      % or: jButton = findjobj('property',{'Text','click me'});
%@%    jButton.setFlyOverAppearance(1);
%@%    jButton.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
%@%    set(jButton,'FocusGainedCallback',@myMatlabFunction);   % some 30 callback points available...
%@%    jButton.get;   % list all changeable properties...
%@%
%@%    hEditbox = uicontrol('style','edit');
%@%    jEditbox = findjobj(hEditbox,'nomenu');
%@%    jEditbox.setCaretColor(java.awt.Color.red);
%@%    jEditbox.KeyTypedCallback = @myCallbackFunc;  % many more callbacks where this came from...
%@%    jEdit.requestFocus;
%@%
%@% Technical explanation & details:
%@%    http://undocumentedmatlab.com/blog/findjobj/
%@%    http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/
%@%
%@% Known issues/limitations:
%@%    - Cannot currently process multiple container objects - just one at a time
%@%    - Initial processing is a bit slow when the figure is laden with many UI components (so better use 'persist')
%@%    - Passing a simple container Matlab handle is currently filtered by its position+size: should find a better way to do this
%@%    - Matlab uipanels are not implemented as simple java panels, and so they can't be found using this utility
%@%    - Labels have a write-only text property in java, so they can't be found using the 'property',{'Text','string'} notation
%@%
%@% Warning:
%@%    This code heavily relies on undocumented and unsupported Matlab functionality.
%@%    It works on Matlab 7+, but use at your own risk!
%@%
%@% Bugs and suggestions:
%@%    Please send to Yair Altman (altmany at gmail dot com)
%@%
%@% Change log:
%@%    2014-10-20: Additional fixes for R2014a, R2014b
%@%    2014-10-13: Fixes for R2014b
%@%    2014-01-04: Minor fix for R2014a; check for newer FEX version up to twice a day only
%@%    2013-12-29: Only check for newer FEX version in non-deployed mode; handled case of invisible figure container
%@%    2013-10-08: Fixed minor edge case (retrieving multiple scroll-panes)
%@%    2013-06-30: Additional fixes for the upcoming HG2
%@%    2013-05-15: Fix for the upcoming HG2
%@%    2013-02-21: Fixed HG-Java warnings
%@%    2013-01-23: Fixed callbacks table grouping & editing bugs; added hidden properties to the properties tooltip; updated help section
%@%    2013-01-13: Improved callbacks table; fixed tree refresh failure; fixed: tree node-selection didn't update the props pane nor flash the selected component
%@%    2012-07-25: Fixes for R2012a as well as some older Matlab releases
%@%    2011-12-07: Fixed 'File is empty' messages in compiled apps
%@%    2011-11-22: Fix suggested by Ward
%@%    2011-02-01: Fixes for R2011a
%@%    2010-06-13: Fixes for R2010b; fixed download (m-file => zip-file)
%@%    2010-04-21: Minor fix to support combo-boxes (aka drop-down, popup-menu) on Windows
%@%    2010-03-17: Important release: Fixes for R2010a, debug listing, objects not found, component containers that should be ignored etc.
%@%    2010-02-04: Forced an EDT redraw before processing; warned if requested handle is invisible
%@%    2010-01-18: Found a way to display label text next to the relevant node name
%@%    2009-10-28: Fixed uitreenode warning
%@%    2009-10-27: Fixed auto-collapse of invisible container nodes; added dynamic tree tooltips & context-menu; minor fix to version-check display
%@%    2009-09-30: Fix for Matlab 7.0 as suggested by Oliver W; minor GUI fix (classname font)
%@%    2009-08-07: Fixed edge-case of missing JIDE tables
%@%    2009-05-24: Added support for future Matlab versions that will not support JavaFrame
%@%    2009-05-15: Added sanity checks for axes items
%@%    2009-04-28: Added 'debug' input arg; increased size tolerance 1px => 2px
%@%    2009-04-23: Fixed location of popupmenus (always 20px high despite what's reported by Matlab...); fixed uiinspect processing issues; added blog link; narrower action buttons
%@%    2009-04-09: Automatic 'nomenu' for uicontrol inputs; significant performance improvement
%@%    2009-03-31: Fixed position of some Java components; fixed properties tooltip; fixed node visibility indication
%@%    2009-02-26: Indicated components visibility (& auto-collapse non-visible containers); auto-highlight selected component; fixes in node icons, figure title & tree refresh; improved error handling; display FindJObj version update description if available
%@%    2009-02-24: Fixed update check; added dedicated labels icon
%@%    2009-02-18: Fixed compatibility with old Matlab versions
%@%    2009-02-08: Callbacks table fixes; use uiinspect if available; fix update check according to new FEX website
%@%    2008-12-17: R2008b compatibility
%@%    2008-09-10: Fixed minor bug as per Johnny Smith
%@%    2007-11-14: Fixed edge case problem with class properties tooltip; used existing object icon if available; added checkbox option to hide standard callbacks
%@%    2007-08-15: Fixed object naming relative property priorities; added sanity check for illegal container arg; enabled desktop (0) container; cleaned up warnings about special class objects
%@%    2007-08-03: Fixed minor tagging problems with a few Java sub-classes; displayed UIClassID if text/name/tag is unavailable
%@%    2007-06-15: Fixed problems finding HG components found by J. Wagberg
%@%    2007-05-22: Added 'nomenu' option for improved performance; fixed 'export handles' bug; fixed handle-finding/display bugs; "cleaner" error handling
%@%    2007-04-23: HTMLized classname tooltip; returned top-level figure Frame handle for figure container; fixed callbacks table; auto-checked newer version; fixed Matlab 7.2 compatibility issue; added HG objects tree
%@%    2007-04-19: Fixed edge case of missing figure; displayed tree hierarchy in interactive GUI if no output args; workaround for figure sub-menus invisible unless clicked
%@%    2007-04-04: Improved performance; returned full listing results in 4th output arg; enabled partial property names & property values; automatically filtered out container panels if children also returned; fixed finding sub-menu items
%@%    2007-03-20: First version posted on the MathWorks file exchange: <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14317">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14317</a>
%@%
%@% See also:
%@%    java, handle, findobj, findall, javaGetHandles, uiinspect (on the File Exchange)
%@
%@% License to use and modify this code is granted freely to all interested, as long as the original author is
%@% referenced and attributed as such. The original author maintains the right to be solely associated with this work.
%@
%@% Programmed and Copyright by Yair M. Altman: altmany(at)gmail.com
%@% $Revision: 1.43 $  $Date: 2014/10/20 04:24:43 $
%@
%@    % Ensure Java AWT is enabled
%@    error(javachk('awt'));
%@
%@    persistent pContainer pHandles pLevels pParentIdx pPositions
%@
%@    try
%@        % Initialize
%@        handles = handle([]);
%@        levels = [];
%@        parentIdx = [];
%@        positions = [];   % Java positions start at the top-left corner
%@        %sizes = [];
%@        listing = '';
%@        hg_levels = [];
%@        hg_handles = handle([]);  % HG handles are double
%@        hg_parentIdx = [];
%@        nomenu = false;
%@        menuBarFoundFlag = false;
%@        hFig = [];
%@
%@        % Force an EDT redraw before processing, to ensure all uicontrols etc. are rendered
%@        drawnow;  pause(0.02);
%@
%@        % Default container is the current figure's root panel
%@        if nargin
%@            if isempty(container)  % empty container - bail out
%@                return;
%@            elseif ischar(container)  % container skipped - this is part of the args list...
%@                varargin = {container, varargin{:}};
%@                origContainer = getCurrentFigure;
%@                [container,contentSize] = getRootPanel(origContainer);
%@            elseif isequal(container,0)  % root
%@                origContainer = handle(container);
%@                container = com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame;
%@                contentSize = [container.getWidth, container.getHeight];
%@            elseif ishghandle(container) % && ~isa(container,'java.awt.Container')
%@                container = container(1);  % another current limitation...
%@                hFig = ancestor(container,'figure');
%@                origContainer = handle(container);
%@                if isa(origContainer,'uimenu')
%@                    % getpixelposition doesn't work for menus... - damn!
%@                    varargin = {'class','MenuPeer', 'property',{'Label',strrep(get(container,'Label'),'&','')}, varargin{:}};
%@                elseif ~isa(origContainer, 'figure') && ~isempty(hFig) && ~isa(origContainer, 'matlab.ui.Figure')
%@                    % See limitations section above: should find a better way to directly refer to the element's java container
%@                    try
%@                        % Note: 'PixelBounds' is undocumented and unsupported, but much faster than getpixelposition!
%@                        % ^^^^  unfortunately, its Y position is inaccurate in some cases - damn!
%@                        %size = get(container,'PixelBounds');
%@                        pos = fix(getpixelposition(container,1));
%@                        %varargin = {'position',pos(1:2), 'size',pos(3:4), 'not','class','java.awt.Panel', varargin{:}};
%@                    catch
%@                        try
%@                            figName = get(hFig,'name');
%@                            if strcmpi(get(hFig,'number'),'on')
%@                                figName = regexprep(['Figure ' num2str(hFig) ': ' figName],': $','');
%@                            end
%@                            mde = com.mathworks.mde.desk.MLDesktop.getInstance;
%@                            jFig = mde.getClient(figName);
%@                            if isempty(jFig), error('dummy');  end
%@                        catch
%@                            warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');  % R2008b compatibility
%@                            jFig = get(get(hFig,'JavaFrame'),'FigurePanelContainer');
%@                        end
%@                        pos = [];
%@                        try
%@                            pxsize = get(container,'PixelBounds');
%@                            pos = [pxsize(1)+5, jFig.getHeight - (pxsize(4)-5)];
%@                        catch
%@                            % never mind...
%@                        end
%@                    end
%@                    if size(pos,2) == 2
%@                        pos(:,3:4) = 0;
%@                    end
%@                    if ~isempty(pos)
%@                        if isa(handle(container),'uicontrol') && strcmp(get(container,'style'),'popupmenu')
%@                            % popupmenus (combo-box dropdowns) are always 20px high
%@                            pos(2) = pos(2) + pos(4) - 20;
%@                            pos(4) = 20;
%@                        end
%@                        %varargin = {'position',pos(1:2), 'size',size(3:4)-size(1:2)-10, 'not','class','java.awt.Panel', varargin{:}};
%@                        varargin = {'position',pos(1:2)+[0,pos(4)], 'size',pos(3:4), 'not','class','java.awt.Panel', 'nomenu', varargin{:}};
%@                    end
%@                elseif isempty(hFig)
%@                    hFig = handle(container);
%@                end
%@                [container,contentSize] = getRootPanel(hFig);
%@            elseif isjava(container)
%@                % Maybe a java container obj (will crash otherwise)
%@                origContainer = container;
%@                contentSize = [container.getWidth, container.getHeight];
%@            else
%@                error('YMA:findjobj:IllegalContainer','Input arg does not appear to be a valid GUI object');
%@            end
%@        else
%@            % Default container = current figure
%@            origContainer = getCurrentFigure;
%@            [container,contentSize] = getRootPanel(origContainer);
%@        end
%@
%@        % Check persistency
%@        if isequal(pContainer,container)
%@            % persistency requested and the same container is reused, so reuse the hierarchy information
%@            [handles,levels,parentIdx,positions] = deal(pHandles, pLevels, pParentIdx, pPositions);
%@        else
%@            % Pre-allocate space of complex data containers for improved performance
%@            handles = repmat(handles,1,1000);
%@            positions = zeros(1000,2);
%@
%@            % Check whether to skip menu processing
%@            nomenu = paramSupplied(varargin,'nomenu');
%@
%@            % Traverse the container hierarchy and extract the elements within
%@            traverseContainer(container,0,1);
%@
%@            % Remove unnecessary pre-allocated elements
%@            dataLen = length(levels);
%@            handles  (dataLen+1:end) = [];
%@            positions(dataLen+1:end,:) = [];
%@        end
%@
%@        % Process persistency check before any filtering is done
%@        if paramSupplied(varargin,'persist')
%@            [pContainer, pHandles, pLevels, pParentIdx, pPositions] = deal(container,handles,levels,parentIdx,positions);
%@        end
%@
%@        % Save data for possible future use in presentObjectTree() below
%@        allHandles = handles;
%@        allLevels  = levels;
%@        allParents = parentIdx;
%@        selectedIdx = 1:length(handles);
%@        %[positions(:,1)-container.getX, container.getHeight - positions(:,2)]
%@
%@        % Debug-list all found compponents and their positions
%@        if paramSupplied(varargin,'debug')
%@            for handleIdx = 1 : length(allHandles)
%@                thisObj = handles(handleIdx);
%@                pos = sprintf('%d,%d %dx%d',[positions(handleIdx,:) getWidth(thisObj) getHeight(thisObj)]);
%@                disp([repmat(' ',1,levels(handleIdx)) '[' pos '] ' char(toString(thisObj))]);
%@            end
%@        end
%@
%@        % Process optional args
%@        % Note: positions is NOT returned since it's based on java coord system (origin = top-left): will confuse Matlab users
%@        processArgs(varargin{:});
%@
%@        % De-cell and trim listing, if only one element was found (no use for indented listing in this case)
%@        if iscell(listing) && length(listing)==1
%@            listing = strtrim(listing{1});
%@        end
%@
%@        % If no output args and no listing requested, present the FINDJOBJ interactive GUI
%@        if nargout == 0 && isempty(listing)
%@
%@            % Get all label positions
%@            hg_labels = [];
%@            labelPositions = getLabelsJavaPos(container);
%@
%@            % Present the GUI (object tree)
%@            if ~isempty(container)
%@                presentObjectTree();
%@            else
%@                warnInvisible(varargin{:});
%@            end
%@
%@        % Display the listing, if this was specifically requested yet no relevant output arg was specified
%@        elseif nargout < 4 && ~isempty(listing)
%@            if ~iscell(listing)
%@                disp(listing);
%@            else
%@                for listingIdx = 1 : length(listing)
%@                    disp(listing{listingIdx});
%@                end
%@            end
%@        end
%@
%@        % Display a warning if the requested handle was not found because it's invisible
%@        if nargout && isempty(handles)
%@            warnInvisible(varargin{:});
%@        end
%@
%@        return;  %debug point
%@
%@    catch
%@        % 'Cleaner' error handling - strip the stack info etc.
%@        err = lasterror;  %#ok
%@        err.message = regexprep(err.message,'Error using ==> [^\n]+\n','');
%@        if isempty(findstr(mfilename,err.message))
%@            % Indicate error origin, if not already stated within the error message
%@            err.message = [mfilename ': ' err.message];
%@        end
%@        rethrow(err);
%@    end
%@
%@    %% Display a warning if the requested handle was not found because it's invisible
%@    function warnInvisible(varargin)
%@        try
%@            if strcmpi(get(hFig,'Visible'),'off')
%@                pos = get(hFig,'Position');
%@                set(hFig, 'Position',pos-[5000,5000,0,0], 'Visible','on');
%@                drawnow; pause(0.01);
%@                [handles,levels,parentIdx,listing] = findjobj(origContainer,varargin{:});
%@                set(hFig, 'Position',pos, 'Visible','off');
%@            end
%@        catch
%@            % ignore - move on...
%@        end
%@        try
%@            stk = dbstack;
%@            stkNames = {stk.name};
%@            OutputFcnIdx = find(~cellfun(@isempty,regexp(stkNames,'_OutputFcn')));
%@            if ~isempty(OutputFcnIdx)
%@                OutputFcnName = stkNames{OutputFcnIdx};
%@                warning('YMA:FindJObj:OutputFcn',['No Java reference was found for the requested handle, because the figure is still invisible in ' OutputFcnName '()']);
%@            elseif ishandle(origContainer) && isprop(origContainer,'Visible') && strcmpi(get(origContainer,'Visible'),'off')
%@                warning('YMA:FindJObj:invisibleHandle','No Java reference was found for the requested handle, probably because it is still invisible');
%@            end
%@        catch
%@            % Never mind...
%@        end
%@    end
%@
%@    %% Check existence of a (case-insensitive) optional parameter in the params list
%@    function [flag,idx] = paramSupplied(paramsList,paramName)
%@        %idx = find(~cellfun('isempty',regexpi(paramsList(cellfun(@ischar,paramsList)),['^-?' paramName])));
%@        idx = find(~cellfun('isempty',regexpi(paramsList(cellfun('isclass',paramsList,'char')),['^-?' paramName])));  % 30/9/2009 fix for ML 7.0 suggested by Oliver W
%@        flag = any(idx);
%@    end
%@
%@    %% Get current figure (even if its 'HandleVisibility' property is 'off')
%@    function curFig = getCurrentFigure
%@        oldShowHidden = get(0,'ShowHiddenHandles');
%@        set(0,'ShowHiddenHandles','on');  % minor fix per Johnny Smith
%@        curFig = gcf;
%@        set(0,'ShowHiddenHandles',oldShowHidden);
%@    end
%@
%@    %% Get Java reference to top-level (root) panel - actually, a reference to the java figure
%@    function [jRootPane,contentSize] = getRootPanel(hFig)
%@        try
%@            contentSize = [0,0];  % initialize
%@            jRootPane = hFig;
%@            figName = get(hFig,'name');
%@            if strcmpi(get(hFig,'number'),'on')
%@                figName = regexprep(['Figure ' num2str(hFig) ': ' figName],': $','');
%@            end
%@            mde = com.mathworks.mde.desk.MLDesktop.getInstance;
%@            jFigPanel = mde.getClient(figName);
%@            jRootPane = jFigPanel;
%@            jRootPane = jFigPanel.getRootPane;
%@        catch
%@            try
%@                warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');  % R2008b compatibility
%@                jFrame = get(hFig,'JavaFrame');
%@                jFigPanel = get(jFrame,'FigurePanelContainer');
%@                jRootPane = jFigPanel;
%@                jRootPane = jFigPanel.getComponent(0).getRootPane;
%@            catch
%@                % Never mind
%@            end
%@        end
%@        try
%@            % If invalid RootPane - try another method...
%@            warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');  % R2008b compatibility
%@            jFrame = get(hFig,'JavaFrame');
%@            jAxisComponent = get(jFrame,'AxisComponent');
%@            jRootPane = jAxisComponent.getParent.getParent.getRootPane;
%@        catch
%@            % Never mind
%@        end
%@        try
%@            % If invalid RootPane, retry up to N times
%@            tries = 10;
%@            while isempty(jRootPane) && tries>0  % might happen if figure is still undergoing rendering...
%@                drawnow; pause(0.001);
%@                tries = tries - 1;
%@                jRootPane = jFigPanel.getComponent(0).getRootPane;
%@            end
%@
%@            % If still invalid, use FigurePanelContainer which is good enough in 99% of cases... (menu/tool bars won't be accessible, though)
%@            if isempty(jRootPane)
%@                jRootPane = jFigPanel;
%@            end
%@            contentSize = [jRootPane.getWidth, jRootPane.getHeight];
%@
%@            % Try to get the ancestor FigureFrame
%@            jRootPane = jRootPane.getTopLevelAncestor;
%@        catch
%@            % Never mind - FigurePanelContainer is good enough in 99% of cases... (menu/tool bars won't be accessible, though)
%@        end
%@    end
%@
%@    %% Traverse the container hierarchy and extract the elements within
%@    function traverseContainer(jcontainer,level,parent)
%@        persistent figureComponentFound menuRootFound
%@
%@        % Record the data for this node
%@        %disp([repmat(' ',1,level) '<= ' char(jcontainer.toString)])
%@        thisIdx = length(levels) + 1;
%@        levels(thisIdx) = level;
%@        parentIdx(thisIdx) = parent;
%@        handles(thisIdx) = handle(jcontainer,'callbackproperties');
%@        try
%@            positions(thisIdx,:) = getXY(jcontainer);
%@            %sizes(thisIdx,:) = [jcontainer.getWidth, jcontainer.getHeight];
%@        catch
%@            positions(thisIdx,:) = [0,0];
%@            %sizes(thisIdx,:) = [0,0];
%@        end
%@        if level>0
%@            positions(thisIdx,:) = positions(thisIdx,:) + positions(parent,:);
%@            if ~figureComponentFound && ...
%@               strcmp(jcontainer.getName,'fComponentContainer') && ...
%@               isa(jcontainer,'com.mathworks.hg.peer.FigureComponentContainer')   % there are 2 FigureComponentContainers - only process one...
%@
%@                % restart coordinate system, to exclude menu & toolbar areas
%@                positions(thisIdx,:) = positions(thisIdx,:) - [jcontainer.getRootPane.getX, jcontainer.getRootPane.getY];
%@                figureComponentFound = true;
%@            end
%@        elseif level==1
%@            positions(thisIdx,:) = positions(thisIdx,:) + positions(parent,:);
%@        else
%@            % level 0 - initialize flags used later
%@            figureComponentFound = false;
%@            menuRootFound = false;
%@        end
%@        parentId = length(parentIdx);
%@
%@        % Traverse Menu items, unless the 'nomenu' option was requested
%@        if ~nomenu
%@            try
%@                for child = 1 : getNumMenuComponents(jcontainer)
%@                    traverseContainer(jcontainer.getMenuComponent(child-1),level+1,parentId);
%@                end
%@            catch
%@                % Probably not a Menu container, but maybe a top-level JMenu, so discard duplicates
%@                %if isa(handles(end).java,'javax.swing.JMenuBar')
%@                if ~menuRootFound && strcmp(class(java(handles(end))),'javax.swing.JMenuBar')  %faster...
%@                    if removeDuplicateNode(thisIdx)
%@                        menuRootFound = true;
%@                        return;
%@                    end
%@                end
%@            end
%@        end
%@
%@        % Now recursively process all this node's children (if any), except menu items if so requested
%@        %if isa(jcontainer,'java.awt.Container')
%@        try  % try-catch is faster than checking isa(jcontainer,'java.awt.Container')...
%@            %if jcontainer.getComponentCount,  jcontainer.getComponents,  end
%@            if ~nomenu || menuBarFoundFlag || isempty(strfind(class(jcontainer),'FigureMenuBar'))
%@                lastChildComponent = java.lang.Object;
%@                child = 0;
%@                while (child < jcontainer.getComponentCount)
%@                    childComponent = jcontainer.getComponent(child);
%@                    % Looping over menus sometimes causes jcontainer to get mixed up (probably a JITC bug), so identify & fix
%@                    if isequal(childComponent,lastChildComponent)
%@                        child = child + 1;
%@                        childComponent = jcontainer.getComponent(child);
%@                    end
%@                    lastChildComponent = childComponent;
%@                    %disp([repmat(' ',1,level) '=> ' num2str(child) ': ' char(class(childComponent))])
%@                    traverseContainer(childComponent,level+1,parentId);
%@                    child = child + 1;
%@                end
%@            else
%@                menuBarFoundFlag = true;  % use this flag to skip further testing for FigureMenuBar
%@            end
%@        catch
%@            % do nothing - probably not a container
%@            %dispError
%@        end
%@
%@        % ...and yet another type of child traversal...
%@        try
%@            if ~isdeployed  % prevent 'File is empty' messages in compiled apps
%@                jc = jcontainer.java;
%@            else
%@                jc = jcontainer;
%@            end
%@            for child = 1 : jc.getChildCount
%@                traverseContainer(jc.getChildAt(child-1),level+1,parentId);
%@            end
%@        catch
%@            % do nothing - probably not a container
%@            %dispError
%@        end
%@
%@        % TODO: Add axis (plot) component handles
%@    end
%@
%@    %% Get the XY location of a Java component
%@    function xy = getXY(jcontainer)
%@            % Note: getX/getY are better than get(..,'X') (mem leaks),
%@            % ^^^^  but sometimes they fail and revert to getx.m ...
%@            % Note2: try awtinvoke() catch is faster than checking ismethod()...
%@            % Note3: using AWTUtilities.invokeAndWait() directly is even faster than awtinvoke()...
%@            try %if ismethod(jcontainer,'getX')
%@                %positions(thisIdx,:) = [jcontainer.getX, jcontainer.getY];
%@                cls = getClass(jcontainer);
%@                location = com.mathworks.jmi.AWTUtilities.invokeAndWait(jcontainer,getMethod(cls,'getLocation',[]),[]);
%@                x = location.getX;
%@                y = location.getY;
%@            catch %else
%@                try
%@                    x = com.mathworks.jmi.AWTUtilities.invokeAndWait(jcontainer,getMethod(cls,'getX',[]),[]);
%@                    y = com.mathworks.jmi.AWTUtilities.invokeAndWait(jcontainer,getMethod(cls,'getY',[]),[]);
%@                catch
%@                    try
%@                        x = awtinvoke(jcontainer,'getX()');
%@                        y = awtinvoke(jcontainer,'getY()');
%@                    catch
%@                        x = get(jcontainer,'X');
%@                        y = get(jcontainer,'Y');
%@                    end
%@                end
%@            end
%@            %positions(thisIdx,:) = [x, y];
%@            xy = [x,y];
%@    end
%@
%@    %% Get the number of menu sub-elements
%@    function numMenuComponents  = getNumMenuComponents(jcontainer)
%@
%@        % The following line will raise an Exception for anything except menus
%@        numMenuComponents = jcontainer.getMenuComponentCount;
%@
%@        % No error so far, so this must be a menu container...
%@        % Note: Menu subitems are not visible until the top-level (root) menu gets initial focus...
%@        % Try several alternatives, until we get a non-empty menu (or not...)
%@        % TODO: Improve performance - this takes WAY too long...
%@        if jcontainer.isTopLevelMenu && (numMenuComponents==0)
%@            jcontainer.requestFocus;
%@            numMenuComponents = jcontainer.getMenuComponentCount;
%@            if (numMenuComponents == 0)
%@                drawnow; pause(0.001);
%@                numMenuComponents = jcontainer.getMenuComponentCount;
%@                if (numMenuComponents == 0)
%@                    jcontainer.setSelected(true);
%@                    numMenuComponents = jcontainer.getMenuComponentCount;
%@                    if (numMenuComponents == 0)
%@                        drawnow; pause(0.001);
%@                        numMenuComponents = jcontainer.getMenuComponentCount;
%@                        if (numMenuComponents == 0)
%@                            jcontainer.doClick;  % needed in order to populate the sub-menu components
%@                            numMenuComponents = jcontainer.getMenuComponentCount;
%@                            if (numMenuComponents == 0)
%@                                drawnow; %pause(0.001);
%@                                numMenuComponents = jcontainer.getMenuComponentCount;
%@                                jcontainer.doClick;  % close menu by re-clicking...
%@                                if (numMenuComponents == 0)
%@                                    drawnow; %pause(0.001);
%@                                    numMenuComponents = jcontainer.getMenuComponentCount;
%@                                end
%@                            else
%@                                % ok - found sub-items
%@                                % Note: no need to close menu since this will be done when focus moves to the FindJObj window
%@                                %jcontainer.doClick;  % close menu by re-clicking...
%@                            end
%@                        end
%@                    end
%@                    jcontainer.setSelected(false);  % de-select the menu
%@                end
%@            end
%@        end
%@    end
%@
%@    %% Remove a specific tree node's data
%@    function nodeRemovedFlag = removeDuplicateNode(thisIdx)
%@        nodeRemovedFlag = false;
%@        for idx = 1 : thisIdx-1
%@            if isequal(handles(idx),handles(thisIdx))
%@                levels(thisIdx) = [];
%@                parentIdx(thisIdx) = [];
%@                handles(thisIdx) = [];
%@                positions(thisIdx,:) = [];
%@                %sizes(thisIdx,:) = [];
%@                nodeRemovedFlag = true;
%@                return;
%@            end
%@        end
%@    end
%@
%@    %% Process optional args
%@    function processArgs(varargin)
%@
%@        % Initialize
%@        invertFlag = false;
%@        listing = '';
%@
%@        % Loop over all optional args
%@        while ~isempty(varargin) && ~isempty(handles)
%@
%@            % Process the arg (and all its params)
%@            foundIdx = 1 : length(handles);
%@            if iscell(varargin{1}),  varargin{1} = varargin{1}{1};  end
%@            if ~isempty(varargin{1}) && varargin{1}(1)=='-'
%@                varargin{1}(1) = [];
%@            end
%@            switch lower(varargin{1})
%@                case 'not'
%@                    invertFlag = true;
%@                case 'position'
%@                    [varargin,foundIdx] = processPositionArgs(varargin{:});
%@                    if invertFlag,  foundIdx = ~foundIdx;  invertFlag = false;  end
%@                case 'size'
%@                    [varargin,foundIdx] = processSizeArgs(varargin{:});
%@                    if invertFlag,  foundIdx = ~foundIdx;  invertFlag = false;  end
%@                case 'class'
%@                    [varargin,foundIdx] = processClassArgs(varargin{:});
%@                    if invertFlag,  foundIdx = ~foundIdx;  invertFlag = false;  end
%@                case 'property'
%@                    [varargin,foundIdx] = processPropertyArgs(varargin{:});
%@                    if invertFlag,  foundIdx = ~foundIdx;  invertFlag = false;  end
%@                case 'depth'
%@                    [varargin,foundIdx] = processDepthArgs(varargin{:});
%@                    if invertFlag,  foundIdx = ~foundIdx;  invertFlag = false;  end
%@                case 'flat'
%@                    varargin = {'depth',0, varargin{min(2:end):end}};
%@                    [varargin,foundIdx] = processDepthArgs(varargin{:});
%@                    if invertFlag,  foundIdx = ~foundIdx;  invertFlag = false;  end
%@                case {'print','list'}
%@                    [varargin,listing] = processPrintArgs(varargin{:});
%@                case {'persist','nomenu','debug'}
%@                    % ignore - already handled in main function above
%@                otherwise
%@                    error('YMA:findjobj:IllegalOption',['Option ' num2str(varargin{1}) ' is not a valid option. Type ''help ' mfilename ''' for the full options list.']);
%@            end
%@
%@            % If only parent-child pairs found
%@            foundIdx = find(foundIdx);
%@            if ~isempty(foundIdx) && isequal(parentIdx(foundIdx(2:2:end)),foundIdx(1:2:end))
%@                % Return just the children (the parent panels are uninteresting)
%@                foundIdx(1:2:end) = [];
%@            end
%@            
%@            % If several possible handles were found and the first is the container of the second
%@            if length(foundIdx) == 2 && isequal(handles(foundIdx(1)).java, handles(foundIdx(2)).getParent)
%@                % Discard the uninteresting component container
%@                foundIdx(1) = [];
%@            end
%@
%@            % Filter the results
%@            selectedIdx = selectedIdx(foundIdx);
%@            handles   = handles(foundIdx);
%@            levels    = levels(foundIdx);
%@            parentIdx = parentIdx(foundIdx);
%@            positions = positions(foundIdx,:);
%@
%@            % Remove this arg and proceed to the next one
%@            varargin(1) = [];
%@
%@        end  % Loop over all args
%@    end
%@
%@    %% Process 'print' option
%@    function [varargin,listing] = processPrintArgs(varargin)
%@        if length(varargin)<2 || ischar(varargin{2})
%@            % No second arg given, so use the first available element
%@            listingContainer = handles(1);  %#ok - used in evalc below
%@        else
%@            % Get the element to print from the specified second arg
%@            if isnumeric(varargin{2}) && (varargin{2} == fix(varargin{2}))  % isinteger doesn't work on doubles...
%@                if (varargin{2} > 0) && (varargin{2} <= length(handles))
%@                    listingContainer = handles(varargin{2});  %#ok - used in evalc below
%@                elseif varargin{2} > 0
%@                    error('YMA:findjobj:IllegalPrintFilter','Print filter index %g > number of available elements (%d)',varargin{2},length(handles));
%@                else
%@                    error('YMA:findjobj:IllegalPrintFilter','Print filter must be a java handle or positive numeric index into handles');
%@                end
%@            elseif ismethod(varargin{2},'list')
%@                listingContainer = varargin{2};  %#ok - used in evalc below
%@            else
%@                error('YMA:findjobj:IllegalPrintFilter','Print filter must be a java handle or numeric index into handles');
%@            end
%@            varargin(2) = [];
%@        end
%@
%@        % use evalc() to capture output into a Matlab variable
%@        %listing = evalc('listingContainer.list');
%@
%@        % Better solution: loop over all handles and process them one by one
%@        listing = cell(length(handles),1);
%@        for componentIdx = 1 : length(handles)
%@            listing{componentIdx} = [repmat(' ',1,levels(componentIdx)) char(handles(componentIdx).toString)];
%@        end
%@    end
%@
%@    %% Process 'position' option
%@    function [varargin,foundIdx] = processPositionArgs(varargin)
%@        if length(varargin)>1
%@            positionFilter = varargin{2};
%@            %if (isjava(positionFilter) || iscom(positionFilter)) && ismethod(positionFilter,'getLocation')
%@            try  % try-catch is faster...
%@                % Java/COM object passed - get its position
%@                positionFilter = positionFilter.getLocation;
%@                filterXY = [positionFilter.getX, positionFilter.getY];
%@            catch
%@                if ~isscalar(positionFilter)
%@                    % position vector passed
%@                    if (length(positionFilter)>=2) && isnumeric(positionFilter)
%@                        % Remember that java coordinates start at top-left corner, Matlab coords start at bottom left...
%@                        %positionFilter = java.awt.Point(positionFilter(1), container.getHeight - positionFilter(2));
%@                        filterXY = [container.getX + positionFilter(1), container.getY + contentSize(2) - positionFilter(2)];
%@
%@                        % Check for full Matlab position vector (x,y,w,h)
%@                        %if (length(positionFilter)==4)
%@                        %    varargin{end+1} = 'size';
%@                        %    varargin{end+1} = fix(positionFilter(3:4));
%@                        %end
%@                    else
%@                        error('YMA:findjobj:IllegalPositionFilter','Position filter must be a java UI component, or X,Y pair');
%@                    end
%@                elseif length(varargin)>2
%@                    % x,y passed as separate arg values
%@                    if isnumeric(positionFilter) && isnumeric(varargin{3})
%@                        % Remember that java coordinates start at top-left corner, Matlab coords start at bottom left...
%@                        %positionFilter = java.awt.Point(positionFilter, container.getHeight - varargin{3});
%@                        filterXY = [container.getX + positionFilter, container.getY + contentSize(2) - varargin{3}];
%@                        varargin(3) = [];
%@                    else
%@                        error('YMA:findjobj:IllegalPositionFilter','Position filter must be a java UI component, or X,Y pair');
%@                    end
%@                else
%@                    error('YMA:findjobj:IllegalPositionFilter','Position filter must be a java UI component, or X,Y pair');
%@                end
%@            end
%@
%@            % Compute the required element positions in order to be eligible for a more detailed examination
%@            % Note: based on the following constraints: 0 <= abs(elementX-filterX) + abs(elementY+elementH-filterY) < 7
%@            baseDeltas = [positions(:,1)-filterXY(1), positions(:,2)-filterXY(2)];  % faster than repmat()...
%@            %baseHeight = - baseDeltas(:,2);% -abs(baseDeltas(:,1));
%@            %minHeight = baseHeight - 7;
%@            %maxHeight = baseHeight + 7;
%@            %foundIdx = ~arrayfun(@(b)(invoke(b,'contains',positionFilter)),handles);  % ARGH! - disallowed by Matlab!
%@            %foundIdx = repmat(false,1,length(handles));
%@            %foundIdx(length(handles)) = false;  % faster than repmat()...
%@            foundIdx = (abs(baseDeltas(:,1)) < 7) & (abs(baseDeltas(:,2)) < 7); % & (minHeight >= 0);
%@            %fi = find(foundIdx);
%@            %for componentIdx = 1 : length(fi)
%@                %foundIdx(componentIdx) = handles(componentIdx).getBounds.contains(positionFilter);
%@
%@                % Search for a point no farther than 7 pixels away (prevents rounding errors)
%@                %foundIdx(componentIdx) = handles(componentIdx).getLocationOnScreen.distanceSq(positionFilter) < 50;  % fails for invisible components...
%@
%@                %p = java.awt.Point(positions(componentIdx,1), positions(componentIdx,2) + handles(componentIdx).getHeight);
%@                %foundIdx(componentIdx) = p.distanceSq(positionFilter) < 50;
%@
%@                %foundIdx(componentIdx) = sum(([baseDeltas(componentIdx,1),baseDeltas(componentIdx,2)+handles(componentIdx).getHeight]).^2) < 50;
%@
%@                % Following is the fastest method found to date: only eligible elements are checked in detailed
%@            %    elementHeight = handles(fi(componentIdx)).getHeight;
%@            %    foundIdx(fi(componentIdx)) = elementHeight > minHeight(fi(componentIdx)) && ...
%@            %                                 elementHeight < maxHeight(fi(componentIdx));
%@                %disp([componentIdx,elementHeight,minHeight(fi(componentIdx)),maxHeight(fi(componentIdx)),foundIdx(fi(componentIdx))])
%@            %end
%@
%@            varargin(2) = [];
%@        else
%@            foundIdx = [];
%@        end
%@    end
%@
%@    %% Process 'size' option
%@    function [varargin,foundIdx] = processSizeArgs(varargin)
%@        if length(varargin)>1
%@            sizeFilter = lower(varargin{2});
%@            %if (isjava(sizeFilter) || iscom(sizeFilter)) && ismethod(sizeFilter,'getSize')
%@            try  % try-catch is faster...
%@                % Java/COM object passed - get its size
%@                sizeFilter = sizeFilter.getSize;
%@                filterWidth  = sizeFilter.getWidth;
%@                filterHeight = sizeFilter.getHeight;
%@            catch
%@                if ~isscalar(sizeFilter)
%@                    % size vector passed
%@                    if (length(sizeFilter)>=2) && isnumeric(sizeFilter)
%@                        %sizeFilter = java.awt.Dimension(sizeFilter(1),sizeFilter(2));
%@                        filterWidth  = sizeFilter(1);
%@                        filterHeight = sizeFilter(2);
%@                    else
%@                        error('YMA:findjobj:IllegalSizeFilter','Size filter must be a java UI component, or W,H pair');
%@                    end
%@                elseif length(varargin)>2
%@                    % w,h passed as separate arg values
%@                    if isnumeric(sizeFilter) && isnumeric(varargin{3})
%@                        %sizeFilter = java.awt.Dimension(sizeFilter,varargin{3});
%@                        filterWidth  = sizeFilter;
%@                        filterHeight = varargin{3};
%@                        varargin(3) = [];
%@                    else
%@                        error('YMA:findjobj:IllegalSizeFilter','Size filter must be a java UI component, or W,H pair');
%@                    end
%@                else
%@                    error('YMA:findjobj:IllegalSizeFilter','Size filter must be a java UI component, or W,H pair');
%@                end
%@            end
%@            %foundIdx = ~arrayfun(@(b)(invoke(b,'contains',sizeFilter)),handles);  % ARGH! - disallowed by Matlab!
%@            foundIdx(length(handles)) = false;  % faster than repmat()...
%@            for componentIdx = 1 : length(handles)
%@                %foundIdx(componentIdx) = handles(componentIdx).getSize.equals(sizeFilter);
%@                % Allow a 2-pixel tollerance to account for non-integer pixel sizes
%@                foundIdx(componentIdx) = abs(handles(componentIdx).getWidth  - filterWidth)  <= 3 && ...  % faster than getSize.equals()
%@                                         abs(handles(componentIdx).getHeight - filterHeight) <= 3;
%@            end
%@            varargin(2) = [];
%@        else
%@            foundIdx = [];
%@        end
%@    end
%@
%@    %% Process 'class' option
%@    function [varargin,foundIdx] = processClassArgs(varargin)
%@        if length(varargin)>1
%@            classFilter = varargin{2};
%@            %if ismethod(classFilter,'getClass')
%@            try  % try-catch is faster...
%@                classFilter = char(classFilter.getClass);
%@            catch
%@                if ~ischar(classFilter)
%@                    error('YMA:findjobj:IllegalClassFilter','Class filter must be a java object, class or string');
%@                end
%@            end
%@
%@            % Now convert all java classes to java.lang.Strings and compare to the requested filter string
%@            try
%@                foundIdx(length(handles)) = false;  % faster than repmat()...
%@                jClassFilter = java.lang.String(classFilter).toLowerCase;
%@                for componentIdx = 1 : length(handles)
%@                    % Note: JVM 1.5's String.contains() appears slightly slower and is available only since Matlab 7.2
%@                    foundIdx(componentIdx) = handles(componentIdx).getClass.toString.toLowerCase.indexOf(jClassFilter) >= 0;
%@                end
%@            catch
%@                % Simple processing: slower since it does extra processing within opaque.char()
%@                for componentIdx = 1 : length(handles)
%@                    % Note: using @toChar is faster but returns java String, not a Matlab char
%@                    foundIdx(componentIdx) = ~isempty(regexpi(char(handles(componentIdx).getClass),classFilter));
%@                end
%@            end
%@
%@            varargin(2) = [];
%@        else
%@            foundIdx = [];
%@        end
%@    end
%@
%@    %% Process 'property' option
%@    function [varargin,foundIdx] = processPropertyArgs(varargin)
%@        if length(varargin)>1
%@            propertyName = varargin{2};
%@            if iscell(propertyName)
%@                if length(propertyName) == 2
%@                    propertyVal  = propertyName{2};
%@                    propertyName = propertyName{1};
%@                elseif length(propertyName) == 1
%@                    propertyName = propertyName{1};
%@                else
%@                    error('YMA:findjobj:IllegalPropertyFilter','Property filter must be a string (case insensitive name of property) or cell array {propName,propValue}');
%@                end
%@            end
%@            if ~ischar(propertyName)
%@                error('YMA:findjobj:IllegalPropertyFilter','Property filter must be a string (case insensitive name of property) or cell array {propName,propValue}');
%@            end
%@            propertyName = lower(propertyName);
%@            %foundIdx = arrayfun(@(h)isprop(h,propertyName),handles);  % ARGH! - disallowed by Matlab!
%@            foundIdx(length(handles)) = false;  % faster than repmat()...
%@
%@            % Split processing depending on whether a specific property value was requested (ugly but faster...)
%@            if exist('propertyVal','var')
%@                for componentIdx = 1 : length(handles)
%@                    try
%@                        % Find out whether this element has the specified property
%@                        % Note: findprop() and its return value schema.prop are undocumented and unsupported!
%@                        prop = findprop(handles(componentIdx),propertyName);  % faster than isprop() & enables partial property names
%@
%@                        % If found, compare it to the actual element's property value
%@                        foundIdx(componentIdx) = ~isempty(prop) && isequal(get(handles(componentIdx),prop.Name),propertyVal);
%@                    catch
%@                        % Some Java classes have a write-only property (like LabelPeer with 'Text'), so we end up here
%@                        % In these cases, simply assume that the property value doesn't match and continue
%@                        foundIdx(componentIdx) = false;
%@                    end
%@                end
%@            else
%@                for componentIdx = 1 : length(handles)
%@                    try
%@                        % Find out whether this element has the specified property
%@                        % Note: findprop() and its return value schema.prop are undocumented and unsupported!
%@                        foundIdx(componentIdx) = ~isempty(findprop(handles(componentIdx),propertyName));
%@                    catch
%@                        foundIdx(componentIdx) = false;
%@                    end
%@                end
%@            end
%@            varargin(2) = [];
%@        else
%@            foundIdx = [];
%@        end
%@    end
%@
%@    %% Process 'depth' option
%@    function [varargin,foundIdx] = processDepthArgs(varargin)
%@        if length(varargin)>1
%@            level = varargin{2};
%@            if ~isnumeric(level)
%@                error('YMA:findjobj:IllegalDepthFilter','Depth filter must be a number (=maximal element depth)');
%@            end
%@            foundIdx = (levels <= level);
%@            varargin(2) = [];
%@        else
%@            foundIdx = [];
%@        end
%@    end
%@
%@    %% Convert property data into a string
%@    function data = charizeData(data)
%@        if isa(data,'com.mathworks.hg.types.HGCallback')
%@            data = get(data,'Callback');
%@        end
%@        if ~ischar(data) && ~isa(data,'java.lang.String')
%@            newData = strtrim(evalc('disp(data)'));
%@            try
%@                newData = regexprep(newData,'  +',' ');
%@                newData = regexprep(newData,'Columns \d+ through \d+\s','');
%@                newData = regexprep(newData,'Column \d+\s','');
%@            catch
%@                %never mind...
%@            end
%@            if iscell(data)
%@                newData = ['{ ' newData ' }'];
%@            elseif isempty(data)
%@                newData = '';
%@            elseif isnumeric(data) || islogical(data) || any(ishandle(data)) || numel(data) > 1 %&& ~isscalar(data)
%@                newData = ['[' newData ']'];
%@            end
%@            data = newData;
%@        elseif ~isempty(data)
%@            data = ['''' data ''''];
%@        end
%@    end  % charizeData
%@
%@    %% Prepare a hierarchical callbacks table data
%@    function setProp(list,name,value,category)
%@        prop = eval('com.jidesoft.grid.DefaultProperty();');  % prevent JIDE alert by run-time (not load-time) evaluation
%@        prop.setName(name);
%@        prop.setType(java.lang.String('').getClass);
%@        prop.setValue(value);
%@        prop.setEditable(true);
%@        prop.setExpert(true);
%@        %prop.setCategory(['<html><b><u><font color="blue">' category ' callbacks']);
%@        prop.setCategory([category ' callbacks']);
%@        list.add(prop);
%@    end  % getTreeData
%@
%@    %% Prepare a hierarchical callbacks table data
%@    function list = getTreeData(data)
%@        list = java.util.ArrayList();
%@        names = regexprep(data,'([A-Z][a-z]+).*','$1');
%@        %hash = java.util.Hashtable;
%@        others = {};
%@        for propIdx = 1 : size(data,1)
%@            if (propIdx < size(data,1) && strcmp(names{propIdx},names{propIdx+1})) || ...
%@               (propIdx > 1            && strcmp(names{propIdx},names{propIdx-1}))
%@                % Child callback property
%@                setProp(list,data{propIdx,1},data{propIdx,2},names{propIdx});
%@            else
%@                % Singular callback property => Add to 'Other' category at bottom of the list
%@                others(end+1,:) = data(propIdx,:);  %#ok
%@            end
%@        end
%@        for propIdx = 1 : size(others,1)
%@            setProp(list,others{propIdx,1},others{propIdx,2},'Other');
%@        end
%@    end  % getTreeData
%@
%@    %% Get callbacks table data
%@    function [cbData, cbHeaders, cbTableEnabled] = getCbsData(obj, stripStdCbsFlag)
%@        % Initialize
%@        cbData = {'(no callbacks)'};
%@        cbHeaders = {'Callback name'};
%@        cbTableEnabled = false;
%@        cbNames = {};
%@
%@        try
%@            try
%@                classHdl = classhandle(handle(obj));
%@                cbNames = get(classHdl.Events,'Name');
%@                if ~isempty(cbNames) && ~iscom(obj)  %only java-based please...
%@                    cbNames = strcat(cbNames,'Callback');
%@                end
%@                propNames = get(classHdl.Properties,'Name');
%@            catch
%@                % Try to interpret as an MCOS class object
%@                try
%@                    oldWarn = warning('off','MATLAB:structOnObject');
%@                    dataFields = struct(obj);
%@                    warning(oldWarn);
%@                catch
%@                    dataFields = get(obj);
%@                end
%@                propNames = fieldnames(dataFields);
%@            end
%@            propCbIdx = [];
%@            if ischar(propNames),  propNames={propNames};  end  % handle case of a single callback
%@            if ~isempty(propNames)
%@                propCbIdx = find(~cellfun(@isempty,regexp(propNames,'(Fcn|Callback)$')));
%@                cbNames = unique([cbNames; propNames(propCbIdx)]);  %#ok logical is faster but less debuggable...
%@            end
%@            if ~isempty(cbNames)
%@                if stripStdCbsFlag
%@                    cbNames = stripStdCbs(cbNames);
%@                end
%@                if iscell(cbNames)
%@                    cbNames = sort(cbNames);
%@                    if size(cbNames,1) < size(cbNames,2)
%@                        cbNames = cbNames';
%@                    end
%@                end
%@                hgHandleFlag = 0;  try hgHandleFlag = ishghandle(obj); catch, end  %#ok
%@                try
%@                    obj = handle(obj,'CallbackProperties');
%@                catch
%@                    hgHandleFlag = 1;
%@                end
%@                if hgHandleFlag
%@                    % HG handles don't allow CallbackProperties - search only for *Fcn
%@                    %cbNames = propNames(propCbIdx);
%@                end
%@                if iscom(obj)
%@                    cbs = obj.eventlisteners;
%@                    if ~isempty(cbs)
%@                        cbNamesRegistered = cbs(:,1);
%@                        cbData = setdiff(cbNames,cbNamesRegistered);
%@                        %cbData = charizeData(cbData);
%@                        if size(cbData,2) > size(cbData(1))
%@                            cbData = cbData';
%@                        end
%@                        cbData = [cbData, cellstr(repmat(' ',length(cbData),1))];
%@                        cbData = [cbData; cbs];
%@                        [sortedNames, sortedIdx] = sort(cbData(:,1));
%@                        sortedCbs = cellfun(@charizeData,cbData(sortedIdx,2),'un',0);
%@                        cbData = [sortedNames, sortedCbs];
%@                    else
%@                        cbData = [cbNames, cellstr(repmat(' ',length(cbNames),1))];
%@                    end
%@                elseif iscell(cbNames)
%@                    cbNames = sort(cbNames);
%@                    %cbData = [cbNames, get(obj,cbNames)'];
%@                    cbData = cbNames;
%@                    oldWarn = warning('off','MATLAB:hg:JavaSetHGProperty');
%@                    warning('off','MATLAB:hg:PossibleDeprecatedJavaSetHGProperty');
%@                    for idx = 1 : length(cbNames)
%@                        try
%@                            cbData{idx,2} = charizeData(get(obj,cbNames{idx}));
%@                        catch
%@                            cbData{idx,2} = '(callback value inaccessible)';
%@                        end
%@                    end
%@                    warning(oldWarn);
%@                else  % only one event callback
%@                    %cbData = {cbNames, get(obj,cbNames)'};
%@                    %cbData{1,2} = charizeData(cbData{1,2});
%@                    try
%@                        cbData = {cbNames, charizeData(get(obj,cbNames))};
%@                    catch
%@                        cbData = {cbNames, '(callback value inaccessible)'};
%@                    end
%@                end
%@                cbHeaders = {'Callback name','Callback value'};
%@                cbTableEnabled = true;
%@            end
%@        catch
%@            % never mind - use default (empty) data
%@        end
%@    end  % getCbsData
%@
%@    %% Get relative (0.0-1.0) divider location
%@    function divLocation = getRalativeDivlocation(jDiv)
%@        divLocation = jDiv.getDividerLocation;
%@        if divLocation > 1  % i.e. [pixels]
%@            visibleRect = jDiv.getVisibleRect;
%@            if jDiv.getOrientation == 0  % vertical
%@                start = visibleRect.getY;
%@                extent = visibleRect.getHeight - start;
%@            else
%@                start = visibleRect.getX;
%@                extent = visibleRect.getWidth - start;
%@            end
%@            divLocation = (divLocation - start) / extent;
%@        end
%@    end  % getRalativeDivlocation
%@
%@    %% Try to set a treenode icon based on a container's icon
%@    function setTreeNodeIcon(treenode,container)
%@        try
%@            iconImage = [];
%@            iconImage = container.getIcon;
%@            if ~isempty(findprop(handle(iconImage),'Image'))  % get(iconImage,'Image') is easier but leaks memory...
%@                iconImage = iconImage.getImage;
%@            else
%@                a=b; %#ok cause an error
%@            end
%@        catch
%@            try
%@                iconImage = container.getIconImage;
%@            catch
%@                try
%@                    if ~isempty(iconImage)
%@                        ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment;
%@                        gd = ge.getDefaultScreenDevice;
%@                        gc = gd.getDefaultConfiguration;
%@                        image = gc.createCompatibleImage(iconImage.getIconWidth, iconImage.getIconHeight);  % a BufferedImage object
%@                        g = image.createGraphics;
%@                        iconImage.paintIcon([], g, 0, 0);
%@                        g.dispose;
%@                        iconImage = image;
%@                    end
%@                catch
%@                    % never mind...
%@                end
%@            end
%@        end
%@        if ~isempty(iconImage)
%@            iconImage = setIconSize(iconImage);
%@            treenode.setIcon(iconImage);
%@        end
%@    end  % setTreeNodeIcon
%@
%@    %% Present the object hierarchy tree
%@    function presentObjectTree()
%@        persistent lastVersionCheck
%@        if isempty(lastVersionCheck),  lastVersionCheck = now-1;  end
%@
%@        import java.awt.*
%@        import javax.swing.*
%@        hTreeFig = findall(0,'tag','findjobjFig');
%@        iconpath = [matlabroot, '/toolbox/matlab/icons/'];
%@        cbHideStd = 0;  % Initial state of the cbHideStdCbs checkbox
%@        if isempty(hTreeFig)
%@            % Prepare the figure
%@            hTreeFig = figure('tag','findjobjFig','menuBar','none','toolBar','none','Name','FindJObj','NumberTitle','off','handleVisibility','off','IntegerHandle','off');
%@            figIcon = ImageIcon([iconpath 'tool_legend.gif']);
%@            drawnow;
%@            try
%@                mde = com.mathworks.mde.desk.MLDesktop.getInstance;
%@                jTreeFig = mde.getClient('FindJObj').getTopLevelAncestor;
%@                jTreeFig.setIcon(figIcon);
%@            catch
%@                warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');  % R2008b compatibility
%@                jTreeFig = get(hTreeFig,'JavaFrame');
%@                jTreeFig.setFigureIcon(figIcon);
%@            end
%@            vsplitPaneLocation = 0.8;
%@            hsplitPaneLocation = 0.5;
%@        else
%@            % Remember cbHideStdCbs checkbox & dividers state for later
%@            userdata = get(hTreeFig, 'userdata');
%@            try cbHideStd = userdata.cbHideStdCbs.isSelected; catch, end  %#ok
%@            try
%@                vsplitPaneLocation = getRalativeDivlocation(userdata.vsplitPane);
%@                hsplitPaneLocation = getRalativeDivlocation(userdata.hsplitPane);
%@            catch
%@                vsplitPaneLocation = 0.8;
%@                hsplitPaneLocation = 0.5;
%@            end
%@
%@            % Clear the figure and redraw
%@            clf(hTreeFig);
%@            figure(hTreeFig);   % bring to front
%@        end
%@
%@        % Traverse all HG children, if root container was a HG handle
%@        if ishghandle(origContainer) %&& ~isequal(origContainer,container)
%@            traverseHGContainer(origContainer,0,0);
%@        end
%@
%@        % Prepare the tree pane
%@        warning('off','MATLAB:uitreenode:MigratingFunction');  % R2008b compatibility
%@        warning('off','MATLAB:uitreenode:DeprecatedFunction'); % R2008a compatibility
%@        tree_h = com.mathworks.hg.peer.UITreePeer;
%@        try tree_h = javaObjectEDT(tree_h); catch, end
%@        tree_hh = handle(tree_h,'CallbackProperties');
%@        hasChildren = sum(allParents==1) > 1;
%@        icon = [iconpath 'upfolder.gif'];
%@        [rootName, rootTitle] = getNodeName(container);
%@        try
%@            root = uitreenode('v0', handle(container), rootName, icon, ~hasChildren);
%@        catch  % old matlab version don't have the 'v0' option
%@            root = uitreenode(handle(container), rootName, icon, ~hasChildren);
%@        end
%@        setTreeNodeIcon(root,container);  % constructor must accept a char icon unfortunately, so need to do this afterwards...
%@        if ~isempty(rootTitle)
%@            set(hTreeFig, 'Name',['FindJObj - ' char(rootTitle)]);
%@        end
%@        nodedata.idx = 1;
%@        nodedata.obj = container;
%@        set(root,'userdata',nodedata);
%@        root.setUserObject(container);
%@        setappdata(root,'childHandle',container);
%@        tree_h.setRoot(root);
%@        treePane = tree_h.getScrollPane;
%@        treePane.setMinimumSize(Dimension(50,50));
%@        jTreeObj = treePane.getViewport.getComponent(0);
%@        jTreeObj.setShowsRootHandles(true)
%@        jTreeObj.getSelectionModel.setSelectionMode(javax.swing.tree.TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
%@        %jTreeObj.setVisible(0);
%@        %jTreeObj.getCellRenderer.setLeafIcon([]);
%@        %jTreeObj.getCellRenderer.setOpenIcon(figIcon);
%@        %jTreeObj.getCellRenderer.setClosedIcon([]);
%@        treePanel = JPanel(BorderLayout);
%@        treePanel.add(treePane, BorderLayout.CENTER);
%@        progressBar = JProgressBar(0);
%@        progressBar.setMaximum(length(allHandles) + length(hg_handles));  % = # of all nodes
%@        treePanel.add(progressBar, BorderLayout.SOUTH);
%@
%@        % Prepare the image pane
%@%disable for now, until we get it working...
%@%{
%@        try
%@            hFig = ancestor(origContainer,'figure');
%@            [cdata, cm] = getframe(hFig);  %#ok cm unused
%@            tempfname = [tempname '.png'];
%@            imwrite(cdata,tempfname);  % don't know how to pass directly to BufferedImage, so use disk...
%@            jImg = javax.imageio.ImageIO.read(java.io.File(tempfname));
%@            try delete(tempfname);  catch  end
%@            imgPanel = JPanel();
%@            leftPanel = JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, imgPanel);
%@            leftPanel.setOneTouchExpandable(true);
%@            leftPanel.setContinuousLayout(true);
%@            leftPanel.setResizeWeight(0.8);
%@        catch
%@            leftPanel = treePanel;
%@        end
%@%}
%@        leftPanel = treePanel;
%@
%@        % Prepare the inspector pane
%@        classNameLabel = JLabel(['      ' char(class(container))]);
%@        classNameLabel.setForeground(Color.blue);
%@        updateNodeTooltip(container, classNameLabel);
%@        inspectorPanel = JPanel(BorderLayout);
%@        inspectorPanel.add(classNameLabel, BorderLayout.NORTH);
%@        % TODO: Maybe uncomment the following when we add the HG tree - in the meantime it's unused (java properties are un-groupable)
%@        %objReg = com.mathworks.services.ObjectRegistry.getLayoutRegistry;
%@        %toolBar = awtinvoke('com.mathworks.mlwidgets.inspector.PropertyView$ToolBarStyle','valueOf(Ljava.lang.String;)','GROUPTOOLBAR');
%@        %inspectorPane = com.mathworks.mlwidgets.inspector.PropertyView(objReg, toolBar);
%@        inspectorPane = com.mathworks.mlwidgets.inspector.PropertyView;
%@        identifiers = disableDbstopError;  %#ok "dbstop if error" causes inspect.m to croak due to a bug - so workaround
%@        inspectorPane.setObject(container);
%@        inspectorPane.setAutoUpdate(true);
%@        % TODO: Add property listeners
%@        % TODO: Display additional props
%@        inspectorTable = inspectorPane;
%@        try
%@            while ~isa(inspectorTable,'javax.swing.JTable')
%@                inspectorTable = inspectorTable.getComponent(0);
%@            end
%@        catch
%@            % R2010a
%@            inspectorTable = inspectorPane.getComponent(0).getScrollPane.getViewport.getComponent(0);
%@        end
%@        toolTipText = 'hover mouse over the red classname above to see the full list of properties';
%@        inspectorTable.setToolTipText(toolTipText);
%@        jideTableUtils = [];
%@        try
%@            % Try JIDE features - see http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf
%@            com.mathworks.mwswing.MJUtilities.initJIDE;
%@            jideTableUtils = eval('com.jidesoft.grid.TableUtils;');  % prevent JIDE alert by run-time (not load-time) evaluation
%@            jideTableUtils.autoResizeAllColumns(inspectorTable);
%@            inspectorTable.setRowAutoResizes(true);
%@            inspectorTable.getModel.setShowExpert(1);
%@        catch
%@            % JIDE is probably unavailable - never mind...
%@        end
%@        inspectorPanel.add(inspectorPane, BorderLayout.CENTER);
%@        % TODO: Add data update listeners
%@
%@        % Prepare the callbacks pane
%@        callbacksPanel = JPanel(BorderLayout);
%@        stripStdCbsFlag = true;  % initial value
%@        [cbData, cbHeaders, cbTableEnabled] = getCbsData(container, stripStdCbsFlag);
%@        %{
%@        %classHdl = classhandle(handle(container));
%@        %eventNames = get(classHdl.Events,'Name');
%@        %if ~isempty(eventNames)
%@        %    cbNames = sort(strcat(eventNames,'Callback'));
%@        %    try
%@        %        cbData = [cbNames, get(container,cbNames)'];
%@        %    catch
%@        %        % R2010a
%@        %        cbData = cbNames;
%@        %        if isempty(cbData)
%@        %            cbData = {};
%@        %        elseif ~iscell(cbData)
%@        %            cbData = {cbData};
%@        %        end
%@        %        for idx = 1 : length(cbNames)
%@        %            cbData{idx,2} = get(container,cbNames{idx});
%@        %        end
%@        %    end
%@        %    cbTableEnabled = true;
%@        %else
%@        %    cbData = {'(no callbacks)',''};
%@        %    cbTableEnabled = false;
%@        %end
%@        %cbHeaders = {'Callback name','Callback value'};
%@        %}
%@        try
%@            % Use JideTable if available on this system
%@            %callbacksTableModel = javax.swing.table.DefaultTableModel(cbData,cbHeaders);  %#ok
%@            %callbacksTable = eval('com.jidesoft.grid.PropertyTable(callbacksTableModel);');  % prevent JIDE alert by run-time (not load-time) evaluation
%@            try
%@                list = getTreeData(cbData);  %#ok
%@                model = eval('com.jidesoft.grid.PropertyTableModel(list);');  %#ok prevent JIDE alert by run-time (not load-time) evaluation
%@
%@                % Auto-expand if only one category
%@                if model.getRowCount==1   % length(model.getCategories)==1 fails for some unknown reason...
%@                    model.expandFirstLevel;
%@                end
%@
%@                %callbacksTable = eval('com.jidesoft.grid.TreeTable(model);');  %#ok prevent JIDE alert by run-time (not load-time) evaluation
%@                callbacksTable = eval('com.jidesoft.grid.PropertyTable(model);');  %#ok prevent JIDE alert by run-time (not load-time) evaluation
%@
%@                %callbacksTable.expandFirstLevel;
%@                callbacksTable.setShowsRootHandles(true);
%@                callbacksTable.setShowTreeLines(false);
%@                %callbacksTable.setShowNonEditable(0);  %=SHOW_NONEDITABLE_NEITHER
%@                callbacksPane = eval('com.jidesoft.grid.PropertyPane(callbacksTable);');  % prevent JIDE alert by run-time (not load-time) evaluation
%@                callbacksPane.setShowDescription(false);
%@            catch
%@                callbacksTable = eval('com.jidesoft.grid.TreeTable(cbData,cbHeaders);');  % prevent JIDE alert by run-time (not load-time) evaluation
%@            end
%@            callbacksTable.setRowAutoResizes(true);
%@            callbacksTable.setColumnAutoResizable(true);
%@            callbacksTable.setColumnResizable(true);
%@            jideTableUtils.autoResizeAllColumns(callbacksTable);
%@            callbacksTable.setTableHeader([]);  % hide the column headers since now we can resize columns with the gridline
%@            callbacksLabel = JLabel(' Callbacks:');  % The column headers are replaced with a header label
%@            callbacksLabel.setForeground(Color.blue);
%@            %callbacksPanel.add(callbacksLabel, BorderLayout.NORTH);
%@
%@            % Add checkbox to show/hide standard callbacks
%@            callbacksTopPanel = JPanel;
%@            callbacksTopPanel.setLayout(BoxLayout(callbacksTopPanel, BoxLayout.LINE_AXIS));
%@            callbacksTopPanel.add(callbacksLabel);
%@            callbacksTopPanel.add(Box.createHorizontalGlue);
%@            jcb = JCheckBox('Hide standard callbacks', cbHideStd);
%@            set(handle(jcb,'CallbackProperties'), 'ActionPerformedCallback',{@cbHideStdCbs_Callback,callbacksTable});
%@            try
%@                set(jcb, 'userdata',callbacksTable, 'tooltip','Hide standard Swing callbacks - only component-specific callbacks will be displayed');
%@            catch
%@                jcb.setToolTipText('Hide standard Swing callbacks - only component-specific callbacks will be displayed');
%@                %setappdata(jcb,'userdata',callbacksTable);
%@            end
%@            callbacksTopPanel.add(jcb);
%@            callbacksPanel.add(callbacksTopPanel, BorderLayout.NORTH);
%@        catch
%@            % Otherwise, use a standard Swing JTable (keep the headers to enable resizing)
%@            callbacksTable = JTable(cbData,cbHeaders);
%@        end
%@        cbToolTipText = 'Callbacks may be ''strings'', @funcHandle or {@funcHandle,arg1,...}';
%@        callbacksTable.setToolTipText(cbToolTipText);
%@        callbacksTable.setGridColor(inspectorTable.getGridColor);
%@        cbNameTextField = JTextField;
%@        cbNameTextField.setEditable(false);  % ensure that the callback names are not modified...
%@        cbNameCellEditor = DefaultCellEditor(cbNameTextField);
%@        cbNameCellEditor.setClickCountToStart(intmax);  % i.e, never enter edit mode...
%@        callbacksTable.getColumnModel.getColumn(0).setCellEditor(cbNameCellEditor);
%@        if ~cbTableEnabled
%@            callbacksTable.getColumnModel.getColumn(1).setCellEditor(cbNameCellEditor);
%@        end
%@        hModel = callbacksTable.getModel;
%@        set(handle(hModel,'CallbackProperties'), 'TableChangedCallback',{@tbCallbacksChanged,container,callbacksTable});
%@        %set(hModel, 'UserData',container);
%@        try
%@            cbScrollPane = callbacksPane; %JScrollPane(callbacksPane);
%@            %cbScrollPane.setHorizontalScrollBarPolicy(cbScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
%@        catch
%@            cbScrollPane = JScrollPane(callbacksTable);
%@            cbScrollPane.setVerticalScrollBarPolicy(cbScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
%@        end
%@        callbacksPanel.add(cbScrollPane, BorderLayout.CENTER);
%@        callbacksPanel.setToolTipText(cbToolTipText);
%@
%@        % Prepare the top-bottom JSplitPanes
%@        vsplitPane = JSplitPane(JSplitPane.VERTICAL_SPLIT, inspectorPanel, callbacksPanel);
%@        vsplitPane.setOneTouchExpandable(true);
%@        vsplitPane.setContinuousLayout(true);
%@        vsplitPane.setResizeWeight(0.8);
%@
%@        % Prepare the left-right JSplitPane
%@        hsplitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, vsplitPane);
%@        hsplitPane.setOneTouchExpandable(true);
%@        hsplitPane.setContinuousLayout(true);
%@        hsplitPane.setResizeWeight(0.6);
%@        pos = getpixelposition(hTreeFig);
%@
%@        % Prepare the bottom pane with all buttons
%@        lowerPanel = JPanel(FlowLayout);
%@        blogUrlLabel = '<a href="http://UndocumentedMatlab.com">Undocumented<br>Matlab.com</a>';
%@        jWebsite = createJButton(blogUrlLabel, @btWebsite_Callback, 'Visit the UndocumentedMatlab.com blog');
%@        jWebsite.setContentAreaFilled(0);
%@        lowerPanel.add(jWebsite);
%@        lowerPanel.add(createJButton('Refresh<br>tree',        {@btRefresh_Callback, origContainer, hTreeFig}, 'Rescan the component tree, from the root down'));
%@        lowerPanel.add(createJButton('Export to<br>workspace', {@btExport_Callback,  jTreeObj, classNameLabel}, 'Export the selected component handles to workspace variable findjobj_hdls'));
%@        lowerPanel.add(createJButton('Request<br>focus',       {@btFocus_Callback,   jTreeObj, root}, 'Set the focus on the first selected component'));
%@        lowerPanel.add(createJButton('Inspect<br>object',      {@btInspect_Callback, jTreeObj, root}, 'View the signature of all methods supported by the first selected component'));
%@        lowerPanel.add(createJButton('Check for<br>updates',   {@btCheckFex_Callback}, 'Check the MathWorks FileExchange for the latest version of FindJObj'));
%@
%@        % Display everything on-screen
%@        globalPanel = JPanel(BorderLayout);
%@        globalPanel.add(hsplitPane, BorderLayout.CENTER);
%@        globalPanel.add(lowerPanel, BorderLayout.SOUTH);
%@        [obj, hcontainer] = javacomponent(globalPanel, [0,0,pos(3:4)], hTreeFig);
%@        set(hcontainer,'units','normalized');
%@        drawnow;
%@        hsplitPane.setDividerLocation(hsplitPaneLocation);  % this only works after the JSplitPane is displayed...
%@        vsplitPane.setDividerLocation(vsplitPaneLocation);  % this only works after the JSplitPane is displayed...
%@        %restoreDbstopError(identifiers);
%@
%@        % Refresh & resize the screenshot thumbnail
%@%disable for now, until we get it working...
%@%{
%@        try
%@            hAx = axes('Parent',hTreeFig, 'units','pixels', 'position',[10,10,250,150], 'visible','off');
%@            axis(hAx,'image');
%@            image(cdata,'Parent',hAx);
%@            axis(hAx,'off');
%@            set(hAx,'UserData',cdata);
%@            set(imgPanel, 'ComponentResizedCallback',{@resizeImg, hAx}, 'UserData',lowerPanel);
%@            imgPanel.getGraphics.drawImage(jImg, 0, 0, []);
%@        catch
%@            % Never mind...
%@        end
%@%}
%@        % If all handles were selected (i.e., none were filtered) then only select the first
%@        if (length(selectedIdx) == length(allHandles)) && ~isempty(selectedIdx)
%@            selectedIdx = 1;
%@        end
%@
%@        % Store handles for callback use
%@        userdata.handles = allHandles;
%@        userdata.levels  = allLevels;
%@        userdata.parents = allParents;
%@        userdata.hg_handles = hg_handles;
%@        userdata.hg_levels  = hg_levels;
%@        userdata.hg_parents = hg_parentIdx;
%@        userdata.initialIdx = selectedIdx;
%@        userdata.userSelected = false;  % Indicates the user has modified the initial selections
%@        userdata.inInit = true;
%@        userdata.jTree = jTreeObj;
%@        userdata.jTreePeer = tree_h;
%@        userdata.vsplitPane = vsplitPane;
%@        userdata.hsplitPane = hsplitPane;
%@        userdata.classNameLabel = classNameLabel;
%@        userdata.inspectorPane = inspectorPane;
%@        userdata.callbacksTable = callbacksTable;
%@        userdata.jideTableUtils = jideTableUtils;
%@        try
%@            userdata.cbHideStdCbs = jcb;
%@        catch
%@            userdata.cbHideStdCbs = [];
%@        end
%@
%@        % Update userdata for use in callbacks
%@        try
%@            set(tree_h,'userdata',userdata);
%@        catch
%@            setappdata(handle(tree_h),'userdata',userdata);
%@        end
%@        try
%@            set(callbacksTable,'userdata',userdata);
%@        catch
%@            setappdata(callbacksTable,'userdata',userdata);
%@        end
%@        set(hTreeFig,'userdata',userdata);
%@
%@        % Select the root node if requested
%@        % Note: we must do so here since all other nodes except the root are processed by expandNode
%@        if any(selectedIdx==1)
%@            tree_h.setSelectedNode(root);
%@        end
%@
%@        % Set the initial cbHideStdCbs state
%@        try
%@            if jcb.isSelected
%@                drawnow;
%@                evd.getSource.isSelected = jcb.isSelected;
%@                cbHideStdCbs_Callback(jcb,evd,callbacksTable);
%@            end
%@        catch
%@            % never mind...
%@        end
%@
%@        % Set the callback functions
%@        set(tree_hh, 'NodeExpandedCallback', {@nodeExpanded, tree_h});
%@        set(tree_hh, 'NodeSelectedCallback', {@nodeSelected, tree_h});
%@
%@        % Set the tree mouse-click callback
%@        % Note: default actions (expand/collapse) will still be performed?
%@        % Note: MousePressedCallback is better than MouseClickedCallback
%@        %       since it fires immediately when mouse button is pressed,
%@        %       without waiting for its release, as MouseClickedCallback does
%@        handleTree = tree_h.getScrollPane;
%@        jTreeObj = handleTree.getViewport.getComponent(0);
%@        jTreeObjh = handle(jTreeObj,'CallbackProperties');
%@        set(jTreeObjh, 'MousePressedCallback', {@treeMousePressedCallback,tree_h});  % context (right-click) menu
%@        set(jTreeObjh, 'MouseMovedCallback',   @treeMouseMovedCallback);    % mouse hover tooltips
%@
%@        % Update userdata
%@        userdata.inInit = false;
%@        try
%@            set(tree_h,'userdata',userdata);
%@        catch
%@            setappdata(handle(tree_h),'userdata',userdata);
%@        end
%@        set(hTreeFig,'userdata',userdata);
%@
%@        % Pre-expand all rows
%@        %treePane.setVisible(false);
%@        expandNode(progressBar, jTreeObj, tree_h, root, 0);
%@        %treePane.setVisible(true);
%@        %jTreeObj.setVisible(1);
%@
%@        % Hide the progressbar now that we've finished expanding all rows
%@        try
%@            hsplitPane.getLeftComponent.setTopComponent(treePane);
%@        catch
%@            % Probably not a vSplitPane on the left...
%@            hsplitPane.setLeftComponent(treePane);
%@        end
%@        hsplitPane.setDividerLocation(hsplitPaneLocation);  % need to do it again...
%@
%@        % Set keyboard focus on the tree
%@        jTreeObj.requestFocus;
%@        drawnow;
%@
%@        % Check for a newer version (only in non-deployed mode, and only twice a day)
%@        if ~isdeployed && now-lastVersionCheck > 0.5
%@            checkVersion();
%@            lastVersionCheck = now;
%@        end
%@
%@        % Reset the last error
%@        lasterr('');  %#ok
%@    end
%@
%@    %% Rresize image pane
%@    function resizeImg(varargin)  %#ok - unused (TODO: waiting for img placement fix...)
%@        try
%@            hPanel = varargin{1};
%@            hAx    = varargin{3};
%@            lowerPanel = get(hPanel,'UserData');
%@            newJPos = cell2mat(get(hPanel,{'X','Y','Width','Height'}));
%@            newMPos = [1,get(lowerPanel,'Height'),newJPos(3:4)];
%@            set(hAx, 'units','pixels', 'position',newMPos, 'Visible','on');
%@            uistack(hAx,'top');  % no good...
%@            set(hPanel,'Opaque','off');  % also no good...
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@        return;
%@    end
%@
%@    %% "dbstop if error" causes inspect.m to croak due to a bug - so workaround by temporarily disabling this dbstop
%@    function identifiers = disableDbstopError
%@        dbStat = dbstatus;
%@        idx = find(strcmp({dbStat.cond},'error'));
%@        identifiers = [dbStat(idx).identifier];
%@        if ~isempty(idx)
%@            dbclear if error;
%@            msgbox('''dbstop if error'' had to be disabled due to a Matlab bug that would have caused Matlab to crash.', 'FindJObj', 'warn');
%@        end
%@    end
%@
%@    %% Restore any previous "dbstop if error"
%@    function restoreDbstopError(identifiers)  %#ok
%@        for itemIdx = 1 : length(identifiers)
%@            eval(['dbstop if error ' identifiers{itemIdx}]);
%@        end
%@    end
%@
%@    %% Recursively expand all nodes (except toolbar/menubar) in startup
%@    function expandNode(progressBar, tree, tree_h, parentNode, parentRow)
%@        try
%@            if nargin < 5
%@                parentPath = javax.swing.tree.TreePath(parentNode.getPath);
%@                parentRow = tree.getRowForPath(parentPath);
%@            end
%@            tree.expandRow(parentRow);
%@            progressBar.setValue(progressBar.getValue+1);
%@            numChildren = parentNode.getChildCount;
%@            if (numChildren == 0)
%@                pause(0.0002);  % as short as possible...
%@                drawnow;
%@            end
%@            nodesToUnExpand = {'FigureMenuBar','MLMenuBar','MJToolBar','Box','uimenu','uitoolbar','ScrollBar'};
%@            numChildren = parentNode.getChildCount;
%@            for childIdx = 0 : numChildren-1
%@                childNode = parentNode.getChildAt(childIdx);
%@
%@                % Pre-select the node based upon the user's FINDJOBJ filters
%@                try
%@                    nodedata = get(childNode, 'userdata');
%@                    try
%@                        userdata = get(tree_h, 'userdata');
%@                    catch
%@                        userdata = getappdata(handle(tree_h), 'userdata');
%@                    end
%@                    %fprintf('%d - %s\n',nodedata.idx,char(nodedata.obj))
%@                    if ~ishghandle(nodedata.obj) && ~userdata.userSelected && any(userdata.initialIdx == nodedata.idx)
%@                        pause(0.0002);  % as short as possible...
%@                        drawnow;
%@                        if isempty(tree_h.getSelectedNodes)
%@                            tree_h.setSelectedNode(childNode);
%@                        else
%@                            newSelectedNodes = [tree_h.getSelectedNodes, childNode];
%@                            tree_h.setSelectedNodes(newSelectedNodes);
%@                        end
%@                    end
%@                catch
%@                    % never mind...
%@                    dispError
%@                end
%@
%@                % Expand child node if not leaf & not toolbar/menubar
%@                if childNode.isLeafNode
%@
%@                    % This is a leaf node, so simply update the progress-bar
%@                    progressBar.setValue(progressBar.getValue+1);
%@
%@                else
%@                    % Expand all non-leaves
%@                    expandNode(progressBar, tree, tree_h, childNode);
%@
%@                    % Re-collapse toolbar/menubar etc., and also invisible containers
%@                    % Note: if we simply did nothing, progressbar would not have been updated...
%@                    try
%@                        childHandle = getappdata(childNode,'childHandle');  %=childNode.getUserObject
%@                        visible = childHandle.isVisible;
%@                    catch
%@                        visible = 1;
%@                    end
%@                    visible = visible && isempty(findstr(get(childNode,'Name'),'color="gray"'));
%@                    %if any(strcmp(childNode.getName,nodesToUnExpand))
%@                    %name = char(childNode.getName);
%@                    if any(cellfun(@(s)~isempty(strmatch(s,char(childNode.getName))),nodesToUnExpand)) || ~visible
%@                        childPath = javax.swing.tree.TreePath(childNode.getPath);
%@                        childRow = tree.getRowForPath(childPath);
%@                        tree.collapseRow(childRow);
%@                    end
%@                end
%@            end
%@        catch
%@            % never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Create utility buttons
%@    function hButton = createJButton(nameStr, handler, toolTipText)
%@        try
%@            jButton = javax.swing.JButton(['<html><body><center>' nameStr]);
%@            jButton.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
%@            jButton.setToolTipText(toolTipText);
%@            try
%@                minSize = jButton.getMinimumSize;
%@            catch
%@                minSize = jButton.getMinimumSize;  % for HG2 - strange indeed that this is needed!
%@            end
%@            jButton.setMinimumSize(java.awt.Dimension(minSize.getWidth,35));
%@            hButton = handle(jButton,'CallbackProperties');
%@            set(hButton,'ActionPerformedCallback',handler);
%@        catch
%@            % Never mind...
%@            a= 1;
%@        end
%@    end
%@
%@    %% Flash a component off/on for the specified duration
%@    % note: starts with 'on'; if numTimes is odd then ends with 'on', otherwise with 'off'
%@    function flashComponent(jComps,delaySecs,numTimes)
%@        persistent redBorder redBorderPanels
%@        try
%@            % Handle callback data from right-click (context-menu)
%@            if iscell(numTimes)
%@                [jComps,delaySecs,numTimes] = deal(numTimes{:});
%@            end
%@
%@            if isempty(redBorder)  % reuse if possible
%@                redBorder = javax.swing.border.LineBorder(java.awt.Color.red,2,0);
%@            end
%@            for compIdx = 1 : length(jComps)
%@                try
%@                    oldBorder{compIdx} = jComps(compIdx).getBorder;  %#ok grow
%@                catch
%@                    oldBorder{compIdx} = [];  %#ok grow
%@                end
%@                isSettable(compIdx) = ismethod(jComps(compIdx),'setBorder');  %#ok grow
%@                if isSettable(compIdx)
%@                    try
%@                        % some components prevent border modification:
%@                        oldBorderFlag = jComps(compIdx).isBorderPainted;
%@                        if ~oldBorderFlag
%@                            jComps(compIdx).setBorderPainted(1);
%@                            isSettable(compIdx) = jComps(compIdx).isBorderPainted;  %#ok grow
%@                            jComps(compIdx).setBorderPainted(oldBorderFlag);
%@                        end
%@                    catch
%@                        % do nothing...
%@                    end
%@                end
%@                if compIdx > length(redBorderPanels)
%@                    redBorderPanels{compIdx} = javax.swing.JPanel;
%@                    redBorderPanels{compIdx}.setBorder(redBorder);
%@                    redBorderPanels{compIdx}.setOpaque(0);  % transparent interior, red border
%@                end
%@                try
%@                    redBorderPanels{compIdx}.setBounds(jComps(compIdx).getBounds);
%@                catch
%@                    % never mind - might be an HG handle
%@                end
%@            end
%@            for idx = 1 : 2*numTimes
%@                if idx>1,  pause(delaySecs);  end  % don't pause at start
%@                visible = mod(idx,2);
%@                for compIdx = 1 : length(jComps)
%@                    try
%@                        jComp = jComps(compIdx);
%@
%@                        % Prevent Matlab crash (java buffer overflow...)
%@                        if isa(jComp,'com.mathworks.mwswing.desk.DTSplitPane') || ...
%@                           isa(jComp,'com.mathworks.mwswing.MJSplitPane')
%@                            continue;
%@
%@                        % HG handles are highlighted by setting their 'Selected' property
%@                        elseif isa(jComp,'uimenu')
%@                            if visible
%@                                oldColor = get(jComp,'ForegroundColor');
%@                                setappdata(jComp,'findjobj_oldColor',oldColor);
%@                                set(jComp,'ForegroundColor','red');
%@                            else
%@                                oldColor = getappdata(jComp,'findjobj_oldColor');
%@                                set(jComp,'ForegroundColor',oldColor);
%@                                rmappdata(jComp,'ForegroundColor');
%@                            end
%@
%@                        elseif ishghandle(jComp)
%@                            if visible
%@                                set(jComp,'Selected','on');
%@                            else
%@                                set(jComp,'Selected','off');
%@                            end
%@
%@                        else %if isjava(jComp)
%@
%@                            jParent = jComps(compIdx).getParent;
%@
%@                            % Most Java components allow modifying their borders
%@                            if isSettable(compIdx)
%@                                if visible
%@                                    jComp.setBorder(redBorder);
%@                                    try jComp.setBorderPainted(1); catch, end  %#ok
%@                                else %if ~isempty(oldBorder{compIdx})
%@                                    jComp.setBorder(oldBorder{compIdx});
%@                                end
%@                                jComp.repaint;
%@
%@                            % The other Java components are highlighted by a transparent red-border
%@                            % panel that is placed on top of them in their parent's space
%@                            elseif ~isempty(jParent)
%@                                if visible
%@                                    jParent.add(redBorderPanels{compIdx});
%@                                    jParent.setComponentZOrder(redBorderPanels{compIdx},0);
%@                                else
%@                                    jParent.remove(redBorderPanels{compIdx});
%@                                end
%@                                jParent.repaint
%@                            end
%@                        end
%@                    catch
%@                        % never mind - try the next component (if any)
%@                    end
%@                end
%@                drawnow;
%@            end
%@        catch
%@            % never mind...
%@            dispError;
%@        end
%@        return;  % debug point
%@    end  % flashComponent
%@
%@    %% Select tree node
%@    function nodeSelected(src, evd, tree)  %#ok
%@        try
%@            if iscell(tree)
%@                [src,node] = deal(tree{:});
%@            else
%@                node = evd.getCurrentNode;
%@            end
%@            %nodeHandle = node.getUserObject;
%@            nodedata = get(node,'userdata');
%@            nodeHandle = nodedata.obj;
%@            try
%@                userdata = get(src,'userdata');
%@            catch
%@                try
%@                    userdata = getappdata(java(src),'userdata');
%@                catch
%@                    userdata = getappdata(src,'userdata');
%@                end
%@                if isempty(userdata)
%@                    try userdata = get(java(src),'userdata'); catch, end
%@                end
%@            end
%@            if ~isempty(nodeHandle) && ~isempty(userdata)
%@                numSelections  = userdata.jTree.getSelectionCount;
%@                selectionPaths = userdata.jTree.getSelectionPaths;
%@                if (numSelections == 1)
%@                    % Indicate that the user has modified the initial selection (except if this was an initial auto-selected node)
%@                    if ~userdata.inInit
%@                        userdata.userSelected = true;
%@                        try
%@                            set(src,'userdata',userdata);
%@                        catch
%@                            try
%@                                setappdata(java(src),'userdata',userdata);
%@                            catch
%@                                setappdata(src,'userdata',userdata);
%@                            end
%@                        end
%@                    end
%@
%@                    % Update the fully-qualified class name label
%@                    numInitialIdx = length(userdata.initialIdx);
%@                    thisHandle = nodeHandle;
%@                    try
%@                        if ~ishghandle(thisHandle)
%@                            thisHandle = java(nodeHandle);
%@                        end
%@                    catch
%@                        % never mind...
%@                    end
%@                    if ~userdata.inInit || (numInitialIdx == 1)
%@                        userdata.classNameLabel.setText(['      ' char(class(thisHandle))]);
%@                    else
%@                        userdata.classNameLabel.setText([' ' num2str(numInitialIdx) 'x handles (some handles hidden by unexpanded tree nodes)']);
%@                    end
%@                    if ishghandle(thisHandle)
%@                        userdata.classNameLabel.setText(userdata.classNameLabel.getText.concat(' (HG handle)'));
%@                    end
%@                    userdata.inspectorPane.dispose;  % remove props listeners - doesn't work...
%@                    updateNodeTooltip(nodeHandle, userdata.classNameLabel);
%@
%@                    % Update the data properties inspector pane
%@                    % Note: we can't simply use the evd nodeHandle, because this node might have been DE-selected with only one other node left selected...
%@                    %nodeHandle = selectionPaths(1).getLastPathComponent.getUserObject;
%@                    nodedata = get(selectionPaths(1).getLastPathComponent,'userdata');
%@                    nodeHandle = nodedata.obj;
%@                    %identifiers = disableDbstopError;  % "dbstop if error" causes inspect.m to croak due to a bug - so workaround
%@                    userdata.inspectorPane.setObject(thisHandle);
%@
%@                    % Update the callbacks table
%@                    try
%@                        stripStdCbsFlag = getappdata(userdata.callbacksTable,'hideStdCbs');
%@                        [cbData, cbHeaders, cbTableEnabled] = getCbsData(nodeHandle, stripStdCbsFlag);  %#ok cbTableEnabled unused
%@                        try
%@                            % Use JideTable if available on this system
%@                            list = getTreeData(cbData);  %#ok
%@                            callbacksTableModel = eval('com.jidesoft.grid.PropertyTableModel(list);');  %#ok prevent JIDE alert by run-time (not load-time) evaluation
%@                            
%@                            % Expand if only one category
%@                            if length(callbacksTableModel.getCategories)==1
%@                                callbacksTableModel.expandFirstLevel;
%@                            end
%@                        catch
%@                            callbacksTableModel = javax.swing.table.DefaultTableModel(cbData,cbHeaders);
%@                        end
%@                        set(handle(callbacksTableModel,'CallbackProperties'), 'TableChangedCallback',{@tbCallbacksChanged,nodeHandle,userdata.callbacksTable});
%@                        %set(callbacksTableModel, 'UserData',nodeHandle);
%@                        userdata.callbacksTable.setModel(callbacksTableModel)
%@                        userdata.callbacksTable.setRowAutoResizes(true);
%@                        userdata.jideTableUtils.autoResizeAllColumns(userdata.callbacksTable);
%@                    catch
%@                        % never mind...
%@                        %dispError
%@                    end
%@                    pause(0.005);
%@                    drawnow;
%@                    %restoreDbstopError(identifiers);
%@
%@                    % Highlight the selected object (if visible)
%@                    flashComponent(nodeHandle,0.2,3);
%@
%@                elseif (numSelections > 1)  % Multiple selections
%@
%@                    % Get the list of all selected nodes
%@                    jArray = javaArray('java.lang.Object', numSelections);
%@                    toolTipStr = '<html>';
%@                    sameClassFlag = true;
%@                    for idx = 1 : numSelections
%@                        %jArray(idx) = selectionPaths(idx).getLastPathComponent.getUserObject;
%@                        nodedata = get(selectionPaths(idx).getLastPathComponent,'userdata');
%@                        try
%@                            if ishghandle(nodedata.obj)
%@                                if idx==1
%@                                    jArray = nodedata.obj;
%@                                else
%@                                    jArray(idx) = nodedata.obj;
%@                                end
%@                            else
%@                                jArray(idx) = java(nodedata.obj);
%@                            end
%@                        catch
%@                            jArray(idx) = nodedata.obj;
%@                        end
%@                        toolTipStr = [toolTipStr '&nbsp;' class(jArray(idx)) '&nbsp;'];  %#ok grow
%@                        if (idx < numSelections),  toolTipStr = [toolTipStr '<br>'];  end  %#ok grow
%@                        try
%@                            if (idx > 1) && sameClassFlag && ~isequal(jArray(idx).getClass,jArray(1).getClass)
%@                                sameClassFlag = false;
%@                            end
%@                        catch
%@                            if (idx > 1) && sameClassFlag && ~isequal(class(jArray(idx)),class(jArray(1)))
%@                                sameClassFlag = false;
%@                            end
%@                        end
%@                    end
%@                    toolTipStr = [toolTipStr '</html>'];
%@
%@                    % Update the fully-qualified class name label
%@                    if sameClassFlag
%@                        classNameStr = class(jArray(1));
%@                    else
%@                        classNameStr = 'handle';
%@                    end
%@                    if all(ishghandle(jArray))
%@                        if strcmp(classNameStr,'handle')
%@                            classNameStr = 'HG handles';
%@                        else
%@                            classNameStr = [classNameStr ' (HG handles)'];
%@                        end
%@                    end
%@                    classNameStr = [' ' num2str(numSelections) 'x ' classNameStr];
%@                    userdata.classNameLabel.setText(classNameStr);
%@                    userdata.classNameLabel.setToolTipText(toolTipStr);
%@
%@                    % Update the data properties inspector pane
%@                    %identifiers = disableDbstopError;  % "dbstop if error" causes inspect.m to croak due to a bug - so workaround
%@                    if isjava(jArray)
%@                        jjArray = jArray;
%@                    else
%@                        jjArray = javaArray('java.lang.Object', numSelections);
%@                        for idx = 1 : numSelections
%@                            jjArray(idx) = java(jArray(idx));
%@                        end
%@                    end
%@                    userdata.inspectorPane.getRegistry.setSelected(jjArray, true);
%@
%@                    % Update the callbacks table
%@                    try
%@                        % Get intersecting callback names & values
%@                        stripStdCbsFlag = getappdata(userdata.callbacksTable,'hideStdCbs');
%@                        [cbData, cbHeaders, cbTableEnabled] = getCbsData(jArray(1), stripStdCbsFlag);  %#ok cbHeaders & cbTableEnabled unused
%@                        if ~isempty(cbData)
%@                            cbNames = cbData(:,1);
%@                            for idx = 2 : length(jArray)
%@                                [cbData2, cbHeaders2] = getCbsData(jArray(idx), stripStdCbsFlag);  %#ok cbHeaders2 unused
%@                                if ~isempty(cbData2)
%@                                    newCbNames = cbData2(:,1);
%@                                    [cbNames, cbIdx, cb2Idx] = intersect(cbNames,newCbNames);  %#ok cb2Idx unused
%@                                    cbData = cbData(cbIdx,:);
%@                                    for cbIdx = 1 : length(cbNames)
%@                                        newIdx = find(strcmp(cbNames{cbIdx},newCbNames));
%@                                        if ~isequal(cbData2,cbData) && ~isequal(cbData2{newIdx,2}, cbData{cbIdx,2})
%@                                            cbData{cbIdx,2} = '<different values>';
%@                                        end
%@                                    end
%@                                else
%@                                    cbData = cbData([],:);  %=empty cell array
%@                                end
%@                                if isempty(cbData)
%@                                    break;
%@                                end
%@                            end
%@                        end
%@                        cbHeaders = {'Callback name','Callback value'};
%@                        try
%@                            % Use JideTable if available on this system
%@                            list = getTreeData(cbData);  %#ok
%@                            callbacksTableModel = eval('com.jidesoft.grid.PropertyTableModel(list);');  %#ok prevent JIDE alert by run-time (not load-time) evaluation
%@                            
%@                            % Expand if only one category
%@                            if length(callbacksTableModel.getCategories)==1
%@                                callbacksTableModel.expandFirstLevel;
%@                            end
%@                        catch
%@                            callbacksTableModel = javax.swing.table.DefaultTableModel(cbData,cbHeaders);
%@                        end
%@                        set(handle(callbacksTableModel,'CallbackProperties'), 'TableChangedCallback',{@tbCallbacksChanged,jArray,userdata.callbacksTable});
%@                        %set(callbacksTableModel, 'UserData',jArray);
%@                        userdata.callbacksTable.setModel(callbacksTableModel)
%@                        userdata.callbacksTable.setRowAutoResizes(true);
%@                        userdata.jideTableUtils.autoResizeAllColumns(userdata.callbacksTable);
%@                    catch
%@                        % never mind...
%@                        dispError
%@                    end
%@
%@                    pause(0.005);
%@                    drawnow;
%@                    %restoreDbstopError(identifiers);
%@
%@                    % Highlight the selected objects (if visible)
%@                    flashComponent(jArray,0.2,3);
%@                end
%@
%@                % TODO: Auto-highlight selected object (?)
%@                %nodeHandle.requestFocus;
%@            end
%@        catch
%@            dispError
%@        end
%@    end
%@
%@    %% IFF utility function for annonymous cellfun funcs
%@    function result = iff(test,trueVal,falseVal)  %#ok
%@        try
%@            if test
%@                result = trueVal;
%@            else
%@                result = falseVal;
%@            end
%@        catch
%@            result = false;
%@        end
%@    end
%@
%@    %% Get an HTML representation of the object's properties
%@    function dataFieldsStr = getPropsHtml(nodeHandle, dataFields)
%@        try
%@            % Get a text representation of the fieldnames & values
%@            undefinedStr = '';
%@            hiddenStr = '';
%@            dataFieldsStr = '';  % just in case the following croaks...
%@            if isempty(dataFields)
%@                return;
%@            end
%@            dataFieldsStr = evalc('disp(dataFields)');
%@            if dataFieldsStr(end)==char(10),  dataFieldsStr=dataFieldsStr(1:end-1);  end
%@
%@            % Strip out callbacks
%@            dataFieldsStr = regexprep(dataFieldsStr,'^\s*\w*Callback(Data)?:[^\n]*$','','lineanchors');
%@
%@            % Strip out internal HG2 mirror properties
%@            dataFieldsStr = regexprep(dataFieldsStr,'^\s*\w*_I:[^\n]*$','','lineanchors');
%@            dataFieldsStr = regexprep(dataFieldsStr,'\n\n+','\n');
%@
%@            % Sort the fieldnames
%@            %fieldNames = fieldnames(dataFields);
%@            try
%@                [a,b,c,d] = regexp(dataFieldsStr,'(\w*): ');
%@                fieldNames = strrep(d,': ','');
%@            catch
%@                fieldNames = fieldnames(dataFields);
%@            end
%@            try
%@                [fieldNames, sortedIdx] = sort(fieldNames);
%@                s = strsplit(dataFieldsStr, sprintf('\n'))';
%@                dataFieldsStr = strjoin(s(sortedIdx), sprintf('\n'));
%@            catch
%@                % never mind... - ignore, leave unsorted
%@            end
%@
%@            % Convert into a Matlab handle()
%@            %nodeHandle = handle(nodeHandle);
%@            try
%@                % ensure this is a Matlab handle, not a java object
%@                nodeHandle = handle(nodeHandle, 'CallbackProperties');
%@            catch
%@                try
%@                    % HG handles don't allow CallbackProperties...
%@                    nodeHandle = handle(nodeHandle);
%@                catch
%@                    % Some Matlab class objects simply cannot be converted into a handle()
%@                end
%@            end
%@
%@            % HTMLize tooltip data
%@            % First, set the fields' font based on its read-write status
%@            for fieldIdx = 1 : length(fieldNames)
%@                thisFieldName = fieldNames{fieldIdx};
%@                %accessFlags = get(findprop(nodeHandle,thisFieldName),'AccessFlags');
%@                try
%@                    hProp = findprop(nodeHandle,thisFieldName);
%@                    accessFlags = get(hProp,'AccessFlags');
%@                    visible = get(hProp,'Visible');
%@                catch
%@                    accessFlags = [];
%@                    visible = 'on';
%@                    try if hProp.Hidden, visible='off'; end, catch, end
%@                end
%@                %if isfield(accessFlags,'PublicSet') && strcmp(accessFlags.PublicSet,'on')
%@                if (~isempty(hProp) && isprop(hProp,'SetAccess') && isequal(hProp.SetAccess,'public')) || ...  % isequal(...'public') and not strcmpi(...) because might be a cell array of classes
%@                   (~isempty(accessFlags) && isfield(accessFlags,'PublicSet') && strcmpi(accessFlags.PublicSet,'on'))
%@                    % Bolden read/write fields
%@                    thisFieldFormat = ['<b>' thisFieldName '</b>:$2'];
%@                %elseif ~isfield(accessFlags,'PublicSet')
%@                elseif (isempty(hProp) || ~isprop(hProp,'SetAccess')) && ...
%@                       (isempty(accessFlags) || ~isfield(accessFlags,'PublicSet'))
%@                    % Undefined - probably a Matlab-defined field of com.mathworks.hg.peer.FigureFrameProxy...
%@                    thisFieldFormat = ['<font color="blue">' thisFieldName '</font>:$2'];
%@                    undefinedStr = ', <font color="blue">undefined</font>';
%@                else % PublicSet=='off'
%@                    % Gray-out & italicize any read-only fields
%@                    thisFieldFormat = ['<font color="#C0C0C0">' thisFieldName '</font>:<font color="#C0C0C0">$2</font>'];
%@                end
%@                if strcmpi(visible,'off')
%@                    %thisFieldFormat = ['<i>' thisFieldFormat '</i>']; %#ok<AGROW>
%@                    thisFieldFormat = regexprep(thisFieldFormat, {'(.*):(.*)','<.?b>'}, {'<i>$1:<i>$2',''}); %'(.*):(.*)', '<i>$1:<i>$2');
%@                    hiddenStr = ', <i>hidden</i>';
%@                end
%@                dataFieldsStr = regexprep(dataFieldsStr, ['([\s\n])' thisFieldName ':([^\n]*)'], ['$1' thisFieldFormat]);
%@            end
%@        catch
%@            % never mind... - probably an ambiguous property name
%@            %dispError
%@        end
%@
%@        % Method 1: simple <br> list
%@        %dataFieldsStr = strrep(dataFieldsStr,char(10),'&nbsp;<br>&nbsp;&nbsp;');
%@
%@        % Method 2: 2-column <table>
%@        dataFieldsStr = regexprep(dataFieldsStr, '^\s*([^:]+:)([^\n]*)\n^\s*([^:]+:)([^\n]*)$', '<tr><td>&nbsp;$1</td><td>&nbsp;$2</td><td>&nbsp;&nbsp;&nbsp;&nbsp;$3</td><td>&nbsp;$4&nbsp;</td></tr>', 'lineanchors');
%@        dataFieldsStr = regexprep(dataFieldsStr, '^[^<]\s*([^:]+:)([^\n]*)$', '<tr><td>&nbsp;$1</td><td>&nbsp;$2</td><td>&nbsp;</td><td>&nbsp;</td></tr>', 'lineanchors');
%@        dataFieldsStr = ['(<b>documented</b>' undefinedStr hiddenStr ' &amp; <font color="#C0C0C0">read-only</font> fields)<p>&nbsp;&nbsp;<table cellpadding="0" cellspacing="0">' dataFieldsStr '</table>'];
%@    end
%@
%@    %% Update tooltip string with a node's data
%@    function updateNodeTooltip(nodeHandle, uiObject)
%@        try
%@            toolTipStr = class(nodeHandle);
%@            dataFieldsStr = '';
%@
%@            % Add HG annotation if relevant
%@            if ishghandle(nodeHandle)
%@                hgStr = ' HG Handle';
%@            else
%@                hgStr = '';
%@            end
%@
%@            % Prevent HG-Java warnings
%@            oldWarn = warning('off','MATLAB:hg:JavaSetHGProperty');
%@            warning('off','MATLAB:hg:PossibleDeprecatedJavaSetHGProperty');
%@            warning('off','MATLAB:hg:Root');
%@
%@            % Note: don't bulk-get because (1) not all properties are returned & (2) some properties cause a Java exception
%@            % Note2: the classhandle approach does not enable access to user-defined schema.props
%@            ch = classhandle(handle(nodeHandle));
%@            dataFields = [];
%@            [sortedNames, sortedIdx] = sort(get(ch.Properties,'Name'));
%@            for idx = 1 : length(sortedIdx)
%@                sp = ch.Properties(sortedIdx(idx));
%@                % TODO: some fields (see EOL comment below) generate a Java Exception from: com.mathworks.mlwidgets.inspector.PropertyRootNode$PropertyListener$1$1.run
%@                if strcmp(sp.AccessFlags.PublicGet,'on') % && ~any(strcmp(sp.Name,{'FixedColors','ListboxTop','Extent'}))
%@                    try
%@                        dataFields.(sp.Name) = get(nodeHandle, sp.Name);
%@                    catch
%@                        dataFields.(sp.Name) = '<font color="red">Error!</font>';
%@                    end
%@                else
%@                    dataFields.(sp.Name) = '(no public getter method)';
%@                end
%@            end
%@            dataFieldsStr = getPropsHtml(nodeHandle, dataFields);
%@        catch
%@            % Probably a non-HG java object
%@            try
%@                % Note: the bulk-get approach enables access to user-defined schema-props, but not to some original classhandle Properties...
%@                try
%@                    oldWarn3 = warning('off','MATLAB:structOnObject');
%@                    dataFields = struct(nodeHandle);
%@                    warning(oldWarn3);
%@                catch
%@                    dataFields = get(nodeHandle);
%@                end
%@                dataFieldsStr = getPropsHtml(nodeHandle, dataFields);
%@            catch
%@                % Probably a missing property getter implementation
%@                try
%@                    % Inform the user - bail out on error
%@                    err = lasterror;  %#ok
%@                    dataFieldsStr = ['<p>' strrep(err.message, char(10), '<br>')];
%@                catch
%@                    % forget it...
%@                end
%@            end
%@        end
%@
%@        % Restore warnings
%@        try warning(oldWarn); catch, end
%@
%@        % Set the object tooltip
%@        if ~isempty(dataFieldsStr)
%@            toolTipStr = ['<html>&nbsp;<b><font color="blue">' char(toolTipStr) '</font></b>' hgStr ':&nbsp;' dataFieldsStr '</html>'];
%@        end
%@        uiObject.setToolTipText(toolTipStr);
%@    end
%@
%@    %% Expand tree node
%@    function nodeExpanded(src, evd, tree)  %#ok
%@        % tree = handle(src);
%@        % evdsrc = evd.getSource;
%@        evdnode = evd.getCurrentNode;
%@
%@        if ~tree.isLoaded(evdnode)
%@
%@            % Get the list of children TreeNodes
%@            childnodes = getChildrenNodes(tree, evdnode);
%@
%@            % Add the HG sub-tree (unless already included in the first tree)
%@            childHandle = getappdata(evdnode.handle,'childHandle');  %=evdnode.getUserObject
%@            if evdnode.isRoot && ~isempty(hg_handles) && ~isequal(hg_handles(1).java, childHandle)
%@                childnodes = [childnodes, getChildrenNodes(tree, evdnode, true)];
%@            end
%@
%@            % If we have a single child handle, wrap it within a javaArray for tree.add() to "swallow"
%@            if (length(childnodes) == 1)
%@                chnodes = childnodes;
%@                childnodes = javaArray('com.mathworks.hg.peer.UITreeNode', 1);
%@                childnodes(1) = java(chnodes);
%@            end
%@
%@            % Add child nodes to the current node
%@            tree.add(evdnode, childnodes);
%@            tree.setLoaded(evdnode, true);
%@        end
%@    end
%@
%@    %% Get an icon image no larger than 16x16 pixels
%@    function iconImage = setIconSize(iconImage)
%@        try
%@            iconWidth  = iconImage.getWidth;
%@            iconHeight = iconImage.getHeight;
%@            if iconWidth > 16
%@                newHeight = fix(iconHeight * 16 / iconWidth);
%@                iconImage = iconImage.getScaledInstance(16,newHeight,iconImage.SCALE_SMOOTH);
%@            elseif iconHeight > 16
%@                newWidth = fix(iconWidth * 16 / iconHeight);
%@                iconImage = iconImage.getScaledInstance(newWidth,16,iconImage.SCALE_SMOOTH);
%@            end
%@        catch
%@            % never mind... - return original icon
%@        end
%@    end  % setIconSize
%@
%@    %% Get list of children nodes
%@    function nodes = getChildrenNodes(tree, parentNode, isRootHGNode)
%@        try
%@            iconpath = [matlabroot, '/toolbox/matlab/icons/'];
%@            nodes = handle([]);
%@            try
%@                userdata = get(tree,'userdata');
%@            catch
%@                userdata = getappdata(handle(tree),'userdata');
%@            end
%@            hdls = userdata.handles;
%@            nodedata = get(parentNode,'userdata');
%@            if nargin < 3
%@                %isJavaNode = ~ishghandle(parentNode.getUserObject);
%@                isJavaNode = ~ishghandle(nodedata.obj);
%@                isRootHGNode = false;
%@            else
%@                isJavaNode = ~isRootHGNode;
%@            end
%@
%@            % Search for this parent node in the list of all nodes
%@            parents = userdata.parents;
%@            nodeIdx = nodedata.idx;
%@
%@            if isJavaNode && isempty(nodeIdx)  % Failback, in case userdata doesn't work for some reason...
%@                for hIdx = 1 : length(hdls)
%@                    %if isequal(handle(parentNode.getUserObject), hdls(hIdx))
%@                    if isequal(handle(nodedata.obj), hdls(hIdx))
%@                        nodeIdx = hIdx;
%@                        break;
%@                    end
%@                end
%@            end
%@            if ~isJavaNode
%@                if isRootHGNode  % =root HG node
%@                    thisChildHandle = userdata.hg_handles(1);
%@                    childName = getNodeName(thisChildHandle);
%@                    hasGrandChildren = any(parents==1);
%@                    icon = [];
%@                    if hasGrandChildren && length(hg_handles)>1
%@                        childName = childName.concat(' - HG root container');
%@                        icon = [iconpath 'figureicon.gif'];
%@                    end
%@                    try
%@                        nodes = uitreenode('v0', thisChildHandle, childName, icon, ~hasGrandChildren);
%@                    catch  % old matlab version don't have the 'v0' option
%@                        try
%@                            nodes = uitreenode(thisChildHandle, childName, icon, ~hasGrandChildren);
%@                        catch
%@                            % probably an invalid handle - ignore...
%@                        end
%@                    end
%@
%@                    % Add the handler to the node's internal data
%@                    % Note: could also use 'userdata', but setUserObject() is recommended for TreeNodes
%@                    % Note2: however, setUserObject() sets a java *BeenAdapter object for HG handles instead of the required original class, so use setappdata
%@                    %nodes.setUserObject(thisChildHandle);
%@                    setappdata(nodes,'childHandle',thisChildHandle);
%@                    nodedata.idx = 1;
%@                    nodedata.obj = thisChildHandle;
%@                    set(nodes,'userdata',nodedata);
%@                    return;
%@                else  % non-root HG node
%@                    parents = userdata.hg_parents;
%@                    hdls    = userdata.hg_handles;
%@                end  % if isRootHGNode
%@            end  % if ~isJavaNode
%@
%@            % If this node was found, get the list of its children
%@            if ~isempty(nodeIdx)
%@                %childIdx = setdiff(find(parents==nodeIdx),nodeIdx);
%@                childIdx = find(parents==nodeIdx);
%@                childIdx(childIdx==nodeIdx) = [];  % faster...
%@                numChildren = length(childIdx);
%@                for cIdx = 1 : numChildren
%@                    thisChildIdx = childIdx(cIdx);
%@                    thisChildHandle = hdls(thisChildIdx);
%@                    childName = getNodeName(thisChildHandle);
%@                    try
%@                        visible = thisChildHandle.Visible;
%@                        if visible
%@                            try visible = thisChildHandle.Width > 0; catch, end  %#ok
%@                        end
%@                        if ~visible
%@                            childName = ['<HTML><i><font color="gray">' char(childName) '</font></i></html>'];  %#ok grow
%@                        end
%@                    catch
%@                        % never mind...
%@                    end
%@                    hasGrandChildren = any(parents==thisChildIdx);
%@                    try
%@                        isaLabel = isa(thisChildHandle.java,'javax.swing.JLabel');
%@                    catch
%@                        isaLabel = 0;
%@                    end
%@                    if hasGrandChildren && ~any(strcmp(class(thisChildHandle),{'axes'}))
%@                        icon = [iconpath 'foldericon.gif'];
%@                    elseif isaLabel
%@                        icon = [iconpath 'tool_text.gif'];
%@                    else
%@                        icon = [];
%@                    end
%@                    try
%@                        nodes(cIdx) = uitreenode('v0', thisChildHandle, childName, icon, ~hasGrandChildren);
%@                    catch  % old matlab version don't have the 'v0' option
%@                        try
%@                            nodes(cIdx) = uitreenode(thisChildHandle, childName, icon, ~hasGrandChildren);
%@                        catch
%@                            % probably an invalid handle - ignore...
%@                        end
%@                    end
%@
%@                    % Use existing object icon, if available
%@                    try
%@                        setTreeNodeIcon(nodes(cIdx),thisChildHandle);
%@                    catch
%@                        % probably an invalid handle - ignore...
%@                    end
%@
%@                    % Pre-select the node based upon the user's FINDJOBJ filters
%@                    try
%@                        if isJavaNode && ~userdata.userSelected && any(userdata.initialIdx == thisChildIdx)
%@                            pause(0.0002);  % as short as possible...
%@                            drawnow;
%@                            if isempty(tree.getSelectedNodes)
%@                                tree.setSelectedNode(nodes(cIdx));
%@                            else
%@                                newSelectedNodes = [tree.getSelectedNodes, nodes(cIdx).java];
%@                                tree.setSelectedNodes(newSelectedNodes);
%@                            end
%@                        end
%@                    catch
%@                        % never mind...
%@                    end
%@
%@                    % Add the handler to the node's internal data
%@                    % Note: could also use 'userdata', but setUserObject() is recommended for TreeNodes
%@                    % Note2: however, setUserObject() sets a java *BeenAdapter object for HG handles instead of the required original class, so use setappdata
%@                    % Note3: the following will error if invalid handle - ignore
%@                    try
%@                        if isJavaNode
%@                            thisChildHandle = thisChildHandle.java;
%@                        end
%@                        %nodes(cIdx).setUserObject(thisChildHandle);
%@                        setappdata(nodes(cIdx),'childHandle',thisChildHandle);
%@                        nodedata.idx = thisChildIdx;
%@                        nodedata.obj = thisChildHandle;
%@                        set(nodes(cIdx),'userdata',nodedata);
%@                    catch
%@                        % never mind (probably an invalid handle) - leave unchanged (like a leaf)
%@                    end
%@                end
%@            end
%@        catch
%@            % Never mind - leave unchanged (like a leaf)
%@            %error('YMA:findjobj:UnknownNodeType', 'Error expanding component tree node');
%@            dispError
%@        end
%@    end
%@
%@    %% Get a node's name
%@    function [nodeName, nodeTitle] = getNodeName(hndl,charsLimit)
%@        try
%@            % Initialize (just in case one of the succeding lines croaks)
%@            nodeName = '';
%@            nodeTitle = '';
%@            if ~ismethod(hndl,'getClass')
%@                try
%@                    nodeName = class(hndl);
%@                catch
%@                    nodeName = hndl.type;  % last-ditch try...
%@                end
%@            else
%@                nodeName = hndl.getClass.getSimpleName;
%@            end
%@
%@            % Strip away the package name, leaving only the regular classname
%@            if ~isempty(nodeName) && ischar(nodeName)
%@                nodeName = java.lang.String(nodeName);
%@                nodeName = nodeName.substring(nodeName.lastIndexOf('.')+1);
%@            end
%@            if (nodeName.length == 0)
%@                % fix case of anonymous internal classes, that do not have SimpleNames
%@                try
%@                    nodeName = hndl.getClass.getName;
%@                    nodeName = nodeName.substring(nodeName.lastIndexOf('.')+1);
%@                catch
%@                    % never mind - leave unchanged...
%@                end
%@            end
%@
%@            % Get any unique identifying string (if available in one of several fields)
%@            labelsToCheck = {'label','title','text','string','displayname','toolTipText','TooltipString','actionCommand','name','Tag','style'}; %,'UIClassID'};
%@            nodeTitle = '';
%@            strField = '';  %#ok - used for debugging
%@            while ((~isa(nodeTitle,'java.lang.String') && ~ischar(nodeTitle)) || isempty(nodeTitle)) && ~isempty(labelsToCheck)
%@                try
%@                    nodeTitle = get(hndl,labelsToCheck{1});
%@                    strField = labelsToCheck{1};  %#ok - used for debugging
%@                catch
%@                    % never mind - probably missing prop, so skip to next one
%@                end
%@                labelsToCheck(1) = [];
%@            end
%@            if length(nodeTitle) ~= numel(nodeTitle)
%@                % Multi-line - convert to a long single line
%@                nodeTitle = nodeTitle';
%@                nodeTitle = nodeTitle(:)';
%@            end
%@            if isempty(char(nodeTitle))
%@                % No title - check whether this is an HG label whose text is gettable
%@                try
%@                    location = hndl.getLocationOnScreen;
%@                    pos = [location.getX, location.getY, hndl.getWidth, hndl.getHeight];
%@                    %dist = sum((labelPositions-repmat(pos,size(labelPositions,1),[1,1,1,1])).^2, 2);
%@                    dist = sum((labelPositions-repmat(pos,[size(labelPositions,1),1])).^2, 2);
%@                    [minVal,minIdx] = min(dist);
%@                    % Allow max distance of 8 = 2^2+2^2 (i.e. X&Y off by up to 2 pixels, W&H exact)
%@                    if minVal <= 8  % 8=2^2+2^2
%@                        nodeTitle = get(hg_labels(minIdx),'string');
%@                        % Preserve the label handles & position for the tooltip & context-menu
%@                        %hg_labels(minIdx) = [];
%@                        %labelPositions(minIdx,:) = [];
%@                    end
%@                catch
%@                    % never mind...
%@                end
%@            end
%@            if nargin<2,  charsLimit = 25;  end
%@            extraStr = regexprep(nodeTitle,{sprintf('(.{%d,%d}).*',charsLimit,min(charsLimit,length(nodeTitle)-1)),' +'},{'$1...',' '},'once');
%@            if ~isempty(extraStr)
%@                if ischar(extraStr)
%@                    nodeName = nodeName.concat(' (''').concat(extraStr).concat(''')');
%@                else
%@                    nodeName = nodeName.concat(' (').concat(num2str(extraStr)).concat(')');
%@                end
%@                %nodeName = nodeName.concat(strField);
%@            end
%@        catch
%@            % Never mind - use whatever we have so far
%@            %dispError
%@        end
%@    end
%@
%@    %% Strip standard Swing callbacks from a list of events
%@    function evNames = stripStdCbs(evNames)
%@        try
%@            stdEvents = {'AncestorAdded',  'AncestorMoved',    'AncestorRemoved', 'AncestorResized', ...
%@                         'ComponentAdded', 'ComponentRemoved', 'ComponentHidden', ...
%@                         'ComponentMoved', 'ComponentResized', 'ComponentShown', ...
%@                         'FocusGained',    'FocusLost',        'HierarchyChanged', ...
%@                         'KeyPressed',     'KeyReleased',      'KeyTyped', ...
%@                         'MouseClicked',   'MouseDragged',     'MouseEntered',  'MouseExited', ...
%@                         'MouseMoved',     'MousePressed',     'MouseReleased', 'MouseWheelMoved', ...
%@                         'PropertyChange', 'VetoableChange',   ...
%@                         'CaretPositionChanged',               'InputMethodTextChanged', ...
%@                         'ButtonDown',     'Create',           'Delete'};
%@            stdEvents = [stdEvents, strcat(stdEvents,'Callback'), strcat(stdEvents,'Fcn')];
%@            evNames = setdiff(evNames,stdEvents)';
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Callback function for <Hide standard callbacks> checkbox
%@    function cbHideStdCbs_Callback(src, evd, callbacksTable, varargin)  %#ok
%@        try
%@            % Store the current checkbox value for later use
%@            if nargin < 3
%@                try
%@                    callbacksTable = get(src,'userdata');
%@                catch
%@                    callbacksTable = getappdata(src,'userdata');
%@                end
%@            end
%@            if evd.getSource.isSelected
%@                setappdata(callbacksTable,'hideStdCbs',1);
%@            else
%@                setappdata(callbacksTable,'hideStdCbs',[]);
%@            end
%@
%@            % Rescan the current node
%@            try
%@                userdata = get(callbacksTable,'userdata');
%@            catch
%@                userdata = getappdata(callbacksTable,'userdata');
%@            end
%@            nodepath = userdata.jTree.getSelectionModel.getSelectionPath;
%@            try
%@                ed.getCurrentNode = nodepath.getLastPathComponent;
%@                nodeSelected(handle(userdata.jTreePeer),ed,[]);
%@            catch
%@                % ignore - probably no node selected
%@            end
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Callback function for <UndocumentedMatlab.com> button
%@    function btWebsite_Callback(src, evd, varargin)  %#ok
%@        try
%@            web('http://UndocumentedMatlab.com','-browser');
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Callback function for <Refresh data> button
%@    function btRefresh_Callback(src, evd, varargin)  %#ok
%@        try
%@            % Set cursor shape to hourglass until we're done
%@            hTreeFig = varargin{2};
%@            set(hTreeFig,'Pointer','watch');
%@            drawnow;
%@            object = varargin{1};
%@
%@            % Re-invoke this utility to re-scan the container for all children
%@            findjobj(object);
%@        catch
%@            % Never mind...
%@        end
%@
%@        % Restore default cursor shape
%@        set(hTreeFig,'Pointer','arrow');
%@    end
%@
%@    %% Callback function for <Export> button
%@    function btExport_Callback(src, evd, varargin)  %#ok
%@        try
%@            % Get the list of all selected nodes
%@            if length(varargin) > 1
%@                jTree = varargin{1};
%@                numSelections  = jTree.getSelectionCount;
%@                selectionPaths = jTree.getSelectionPaths;
%@                hdls = handle([]);
%@                for idx = 1 : numSelections
%@                    %hdls(idx) = handle(selectionPaths(idx).getLastPathComponent.getUserObject);
%@                    nodedata = get(selectionPaths(idx).getLastPathComponent,'userdata');
%@                    try
%@                        hdls(idx) = handle(nodedata.obj,'CallbackProperties');
%@                    catch
%@                        if idx==1  % probably due to HG2: can't convert object to handle([])
%@                            hdls = nodedata.obj;
%@                        else
%@                            hdls(idx) = nodedata.obj;
%@                        end
%@                    end
%@                end
%@
%@                % Assign the handles in the base workspace & inform user
%@                assignin('base','findjobj_hdls',hdls);
%@                classNameLabel = varargin{2};
%@                msg = ['Exported ' char(classNameLabel.getText.trim) ' to base workspace variable findjobj_hdls'];
%@            else
%@                % Right-click (context-menu) callback
%@                data = varargin{1};
%@                obj = data{1};
%@                varName = data{2};
%@                if isempty(varName)
%@                    varName = inputdlg('Enter workspace variable name','FindJObj');
%@                    if isempty(varName),  return;  end  % bail out on <Cancel>
%@                    varName = varName{1};
%@                    if isempty(varName) || ~ischar(varName),  return;  end  % bail out on empty/null
%@                    varName = genvarname(varName);
%@                end
%@                assignin('base',varName,handle(obj,'CallbackProperties'));
%@                msg = ['Exported object to base workspace variable ' varName];
%@            end
%@            msgbox(msg,'FindJObj','help');
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Callback function for <Request focus> button
%@    function btFocus_Callback(src, evd, varargin)  %#ok
%@        try
%@            % Request focus for the specified object
%@            object = getTopSelectedObject(varargin{:});
%@            object.requestFocus;
%@        catch
%@            try
%@                object = object.java.getPeer.requestFocus;
%@                object.requestFocus;
%@            catch
%@                % Never mind...
%@                %dispError
%@            end
%@        end
%@    end
%@
%@    %% Callback function for <Inspect> button
%@    function btInspect_Callback(src, evd, varargin)  %#ok
%@        try
%@            % Inspect the specified object
%@            if length(varargin) == 1
%@                object = varargin{1};
%@            else
%@                object = getTopSelectedObject(varargin{:});
%@            end
%@            if isempty(which('uiinspect'))
%@
%@                % If the user has not indicated NOT to be informed about UIInspect
%@                if ~ispref('FindJObj','dontCheckUIInspect')
%@
%@                    % Ask the user whether to download UIINSPECT (YES, no, no & don't ask again)
%@                    answer = questdlg({'The object inspector requires UIINSPECT from the MathWorks File Exchange. UIINSPECT was created by Yair Altman, like this FindJObj utility.','','Download & install UIINSPECT?'},'UIInspect','Yes','No','No & never ask again','Yes');
%@                    switch answer
%@                        case 'Yes'  % => Yes: download & install
%@                            try
%@                                % Download UIINSPECT
%@                                baseUrl = 'http://www.mathworks.com/matlabcentral/fileexchange/17935';
%@                                fileUrl = [baseUrl '?controller=file_infos&download=true'];
%@                                %file = urlread(fileUrl);
%@                                %file = regexprep(file,[char(13),char(10)],'\n');  %convert to OS-dependent EOL
%@
%@                                % Install...
%@                                %newPath = fullfile(fileparts(which(mfilename)),'uiinspect.m');
%@                                %fid = fopen(newPath,'wt');
%@                                %fprintf(fid,'%s',file);
%@                                %fclose(fid);
%@                                [fpath,fname,fext] = fileparts(which(mfilename));
%@                                zipFileName = fullfile(fpath,'uiinspect.zip');
%@                                urlwrite(fileUrl,zipFileName);
%@                                unzip(zipFileName,fpath);
%@                                rehash;
%@                            catch
%@                                % Error downloading: inform the user
%@                                msgbox(['Error in downloading: ' lasterr], 'UIInspect', 'warn');  %#ok
%@                                web(baseUrl);
%@                            end
%@
%@                            % ...and now run it...
%@                            %pause(0.1); 
%@                            drawnow;
%@                            dummy = which('uiinspect');  %#ok used only to load into memory
%@                            uiinspect(object);
%@                            return;
%@
%@                        case 'No & never ask again'   % => No & don't ask again
%@                            setpref('FindJObj','dontCheckUIInspect',1);
%@
%@                        otherwise
%@                            % forget it...
%@                    end
%@                end
%@                drawnow;
%@
%@                % No UIINSPECT available - run the good-ol' METHODSVIEW()...
%@                methodsview(object);
%@            else
%@                uiinspect(object);
%@            end
%@        catch
%@            try
%@                if isjava(object)
%@                    methodsview(object)
%@                else
%@                    methodsview(object.java);
%@                end
%@            catch
%@                % Never mind...
%@                dispError
%@            end
%@        end
%@    end
%@
%@    %% Callback function for <Check for updates> button
%@    function btCheckFex_Callback(src, evd, varargin)  %#ok
%@        try
%@            % Check the FileExchange for the latest version
%@            web('http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14317');
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Check for existence of a newer version
%@    function checkVersion()
%@        try
%@            % If the user has not indicated NOT to be informed
%@            if ~ispref('FindJObj','dontCheckNewerVersion')
%@
%@                % Get the latest version date from the File Exchange webpage
%@                baseUrl = 'http://www.mathworks.com/matlabcentral/fileexchange/';
%@                webUrl = [baseUrl '14317'];  % 'loadFile.do?objectId=14317'];
%@                webPage = urlread(webUrl);
%@                modIdx = strfind(webPage,'>Updates<');
%@                if ~isempty(modIdx)
%@                    webPage = webPage(modIdx:end);
%@                    % Note: regexp hangs if substr not found, so use strfind instead...
%@                    %latestWebVersion = regexprep(webPage,'.*?>(20[\d-]+)</td>.*','$1');
%@                    dateIdx = strfind(webPage,'class="date">');
%@                    if ~isempty(dateIdx)
%@                        latestDate = webPage(dateIdx(end)+13 : dateIdx(end)+23);
%@                        try
%@                            startIdx = dateIdx(end)+27;
%@                            descStartIdx = startIdx + strfind(webPage(startIdx:startIdx+999),'<td>');
%@                            descEndIdx   = startIdx + strfind(webPage(startIdx:startIdx+999),'</td>');
%@                            descStr = webPage(descStartIdx(1)+3 : descEndIdx(1)-2);
%@                            descStr = regexprep(descStr,'</?[pP]>','');
%@                        catch
%@                            descStr = '';
%@                        end
%@
%@                        % Get this file's latest date
%@                        thisFileName = which(mfilename);  %#ok
%@                        try
%@                            thisFileData = dir(thisFileName);
%@                            try
%@                                thisFileDatenum = thisFileData.datenum;
%@                            catch  % old ML versions...
%@                                thisFileDatenum = datenum(thisFileData.date);
%@                            end
%@                        catch
%@                            thisFileText = evalc('type(thisFileName)');
%@                            thisFileLatestDate = regexprep(thisFileText,'.*Change log:[\s%]+([\d-]+).*','$1');
%@                            thisFileDatenum = datenum(thisFileLatestDate,'yyyy-mm-dd');
%@                        end
%@
%@                        % If there's a newer version on the File Exchange webpage (allow 2 days grace period)
%@                        if (thisFileDatenum < datenum(latestDate,'dd mmm yyyy')-2)
%@
%@                            % Ask the user whether to download the newer version (YES, no, no & don't ask again)
%@                            msg = {['A newer version (' latestDate ') of FindJObj is available on the MathWorks File Exchange:'], '', ...
%@                                   ['\color{blue}' descStr '\color{black}'], '', ...
%@                                   'Download & install the new version?'};
%@                            createStruct.Interpreter = 'tex';
%@                            createStruct.Default = 'Yes';
%@                            answer = questdlg(msg,'FindJObj','Yes','No','No & never ask again',createStruct);
%@                            switch answer
%@                                case 'Yes'  % => Yes: download & install newer file
%@                                    try
%@                                        %fileUrl = [baseUrl '/download.do?objectId=14317&fn=findjobj&fe=.m'];
%@                                        fileUrl = [baseUrl '/14317?controller=file_infos&download=true'];
%@                                        %file = urlread(fileUrl);
%@                                        %file = regexprep(file,[char(13),char(10)],'\n');  %convert to OS-dependent EOL
%@                                        %fid = fopen(thisFileName,'wt');
%@                                        %fprintf(fid,'%s',file);
%@                                        %fclose(fid);
%@                                        [fpath,fname,fext] = fileparts(thisFileName);
%@                                        zipFileName = fullfile(fpath,[fname '.zip']);
%@                                        urlwrite(fileUrl,zipFileName);
%@                                        unzip(zipFileName,fpath);
%@                                        rehash;
%@                                    catch
%@                                        % Error downloading: inform the user
%@                                        msgbox(['Error in downloading: ' lasterr], 'FindJObj', 'warn');  %#ok
%@                                        web(webUrl);
%@                                    end
%@                                case 'No & never ask again'   % => No & don't ask again
%@                                    setpref('FindJObj','dontCheckNewerVersion',1);
%@                                otherwise
%@                                    % forget it...
%@                            end
%@                        end
%@                    end
%@                else
%@                    % Maybe webpage not fully loaded or changed format - bail out...
%@                end
%@            end
%@        catch
%@            % Never mind...
%@        end
%@    end
%@
%@    %% Get the first selected object (might not be the top one - depends on selection order)
%@    function object = getTopSelectedObject(jTree, root)
%@        try
%@            object = [];
%@            numSelections  = jTree.getSelectionCount;
%@            if numSelections > 0
%@                % Get the first object specified
%@                %object = jTree.getSelectionPath.getLastPathComponent.getUserObject;
%@                nodedata = get(jTree.getSelectionPath.getLastPathComponent,'userdata');
%@            else
%@                % Get the root object (container)
%@                %object = root.getUserObject;
%@                nodedata = get(root,'userdata');
%@            end
%@            object = nodedata.obj;
%@        catch
%@            % Never mind...
%@            dispError
%@        end
%@    end
%@
%@    %% Update component callback upon callbacksTable data change
%@    function tbCallbacksChanged(src, evd, object, table)
%@        persistent hash
%@        try
%@            % exit if invalid handle or already in Callback
%@            %if ~ishandle(src) || ~isempty(getappdata(src,'inCallback')) % || length(dbstack)>1  %exit also if not called from user action
%@            if isempty(hash), hash = java.util.Hashtable;  end
%@            if ~ishandle(src) || ~isempty(hash.get(src)) % || length(dbstack)>1  %exit also if not called from user action
%@                return;
%@            end
%@            %setappdata(src,'inCallback',1);  % used to prevent endless recursion   % can't use getappdata(src,...) because it fails on R2010b!!!
%@            hash.put(src,1);
%@
%@            % Update the object's callback with the modified value
%@            modifiedColIdx = evd.getColumn;
%@            modifiedRowIdx = evd.getFirstRow;
%@            if modifiedRowIdx>=0 %&& modifiedColIdx==1  %sanity check - should always be true
%@                %table = evd.getSource;
%@                %object = get(src,'userdata');
%@                modifiedRowIdx = table.getSelectedRow;  % overcome issues with hierarchical table
%@                cbName = strtrim(table.getValueAt(modifiedRowIdx,0));
%@                try
%@                    cbValue = strtrim(char(table.getValueAt(modifiedRowIdx,1)));
%@                    if ~isempty(cbValue) && ismember(cbValue(1),'{[@''')
%@                        cbValue = eval(cbValue);
%@                    end
%@                    if (~ischar(cbValue) && ~isa(cbValue, 'function_handle') && (~iscell(cbValue) || iscom(object(1))))
%@                        revertCbTableModification(table, modifiedRowIdx, modifiedColIdx, cbName, object, '');
%@                    else
%@                        for objIdx = 1 : length(object)
%@                            obj = object(objIdx);
%@                            if ~iscom(obj)
%@                                try
%@                                    try
%@                                        if isjava(obj)
%@                                            obj = handle(obj,'CallbackProperties');
%@                                        end
%@                                    catch
%@                                        % never mind...
%@                                    end
%@                                    set(obj, cbName, cbValue);
%@                                catch
%@                                    try
%@                                        set(handle(obj,'CallbackProperties'), cbName, cbValue);
%@                                    catch
%@                                        % never mind - probably a callback-group header
%@                                    end
%@                                end
%@                            else
%@                                cbs = obj.eventlisteners;
%@                                if ~isempty(cbs)
%@                                    cbs = cbs(strcmpi(cbs(:,1),cbName),:);
%@                                    obj.unregisterevent(cbs);
%@                                end
%@                                if ~isempty(cbValue) && ~strcmp(cbName,'-')
%@                                    obj.registerevent({cbName, cbValue});
%@                                end
%@                            end
%@                        end
%@                    end
%@                catch
%@                    revertCbTableModification(table, modifiedRowIdx, modifiedColIdx, cbName, object, lasterr)  %#ok
%@                end
%@            end
%@        catch
%@            % never mind...
%@        end
%@        %setappdata(src,'inCallback',[]);  % used to prevent endless recursion   % can't use setappdata(src,...) because it fails on R2010b!!!
%@        hash.remove(src);
%@    end
%@
%@    %% Revert Callback table modification
%@    function revertCbTableModification(table, modifiedRowIdx, modifiedColIdx, cbName, object, errMsg)  %#ok
%@        try
%@            % Display a notification MsgBox
%@            msg = 'Callbacks must be a ''string'', or a @function handle';
%@            if ~iscom(object(1)),  msg = [msg ' or a {@func,args...} construct'];  end
%@            if ~isempty(errMsg),  msg = {errMsg, '', msg};  end
%@            msgbox(msg, ['Error setting ' cbName ' value'], 'warn');
%@
%@            % Revert to the current value
%@            curValue = '';
%@            try
%@                if ~iscom(object(1))
%@                    curValue = charizeData(get(object(1),cbName));
%@                else
%@                    cbs = object(1).eventlisteners;
%@                    if ~isempty(cbs)
%@                        cbs = cbs(strcmpi(cbs(:,1),cbName),:);
%@                        curValue = charizeData(cbs(1,2));
%@                    end
%@                end
%@            catch
%@                % never mind... - clear the current value
%@            end
%@            table.setValueAt(curValue, modifiedRowIdx, modifiedColIdx);
%@        catch
%@            % never mind...
%@        end
%@    end  % revertCbTableModification
%@
%@    %% Get the Java positions of all HG text labels
%@    function labelPositions = getLabelsJavaPos(container)
%@        try
%@            labelPositions = [];
%@
%@            % Ensure we have a figure handle
%@            try
%@                h = hFig;  %#ok unused
%@            catch
%@                hFig = getCurrentFigure;
%@            end
%@
%@            % Get the figure's margins from the Matlab properties
%@            hg_labels = findall(hFig, 'Style','text');
%@            units = get(hFig,'units');
%@            set(hFig,'units','pixels');
%@            outerPos = get(hFig,'OuterPosition');
%@            innerPos = get(hFig,'Position');
%@            set(hFig,'units',units);
%@            margins = abs(innerPos-outerPos);
%@
%@            figX = container.getX;        % =outerPos(1)
%@            figY = container.getY;        % =outerPos(2)
%@            %figW = container.getWidth;   % =outerPos(3)
%@            figH = container.getHeight;   % =outerPos(4)
%@
%@            % Get the relevant screen pixel size
%@            %monitorPositions = get(0,'MonitorPositions');
%@            %for monitorIdx = size(monitorPositions,1) : -1 : 1
%@            %    screenSize = monitorPositions(monitorIdx,:);
%@            %    if (outerPos(1) >= screenSize(1)) % && (outerPos(1)+outerPos(3) <= screenSize(3))
%@            %        break;
%@            %    end
%@            %end
%@            %monitorBaseY = screenSize(4) - monitorPositions(1,4);
%@
%@            % Compute the labels' screen pixel position in Java units ([0,0] = top left)
%@            for idx = 1 : length(hg_labels)
%@                matlabPos = getpixelposition(hg_labels(idx),1);
%@                javaX = figX + matlabPos(1) + margins(1);
%@                javaY = figY + figH - matlabPos(2) - matlabPos(4) - margins(2);
%@                labelPositions(idx,:) = [javaX, javaY, matlabPos(3:4)];  %#ok grow
%@            end
%@        catch
%@            % never mind...
%@            err = lasterror;  %#ok debug point
%@        end
%@    end
%@
%@    %% Traverse an HG container hierarchy and extract the HG elements within
%@    function traverseHGContainer(hcontainer,level,parent)
%@        try
%@            % Record the data for this node
%@            thisIdx = length(hg_levels) + 1;
%@            hg_levels(thisIdx) = level;
%@            hg_parentIdx(thisIdx) = parent;
%@            try
%@                hg_handles(thisIdx) = handle(hcontainer);
%@            catch
%@                hg_handles = handle(hcontainer);
%@            end
%@            parentId = length(hg_parentIdx);
%@
%@            % Now recursively process all this node's children (if any)
%@            %if ishghandle(hcontainer)
%@            try  % try-catch is faster than checking ishghandle(hcontainer)...
%@                allChildren = allchild(handle(hcontainer));
%@                for childIdx = 1 : length(allChildren)
%@                    traverseHGContainer(allChildren(childIdx),level+1,parentId);
%@                end
%@            catch
%@                % do nothing - probably not a container
%@                %dispError
%@            end
%@
%@            % TODO: Add axis (plot) component handles
%@        catch
%@            % forget it...
%@        end
%@    end
%@
%@    %% Debuggable "quiet" error-handling
%@    function dispError
%@        err = lasterror;  %#ok
%@        msg = err.message;
%@        for idx = 1 : length(err.stack)
%@            filename = err.stack(idx).file;
%@            if ~isempty(regexpi(filename,mfilename))
%@                funcname = err.stack(idx).name;
%@                line = num2str(err.stack(idx).line);
%@                msg = [msg ' at <a href="matlab:opentoline(''' filename ''',' line ');">' funcname ' line #' line '</a>']; %#ok grow
%@                break;
%@            end
%@        end
%@        disp(msg);
%@        return;  % debug point
%@    end
%@
%@    %% ML 7.0 - compatible ischar() function
%@    function flag = ischar(data)
%@        try
%@            flag = builtin('ischar',data);
%@        catch
%@            flag = isa(data,'char');
%@        end
%@    end
%@
%@    %% Set up the uitree context (right-click) menu
%@    function jmenu = setTreeContextMenu(obj,node,tree_h)
%@          % Prepare the context menu (note the use of HTML labels)
%@          import javax.swing.*
%@          titleStr = getNodeTitleStr(obj,node);
%@          titleStr = regexprep(titleStr,'<hr>.*','');
%@          menuItem0 = JMenuItem(titleStr);
%@          menuItem0.setEnabled(false);
%@          menuItem0.setArmed(false);
%@          %menuItem1 = JMenuItem('Export handle to findjobj_hdls');
%@          if isjava(obj), prefix = 'j';  else,  prefix = 'h';  end  %#ok<NOCOM>
%@          varname = strrep([prefix strtok(char(node.getName))], '$','_');
%@          varname = genvarname(varname);
%@          varname(2) = upper(varname(2));  % ensure lowerCamelCase
%@          menuItem1 = JMenuItem(['Export handle to ' varname]);
%@          menuItem2 = JMenuItem('Export handle to...');
%@          menuItem3 = JMenuItem('Request focus (bring to front)');
%@          menuItem4 = JMenuItem('Flash component borders');
%@          menuItem5 = JMenuItem('Display properties & callbacks');
%@          menuItem6 = JMenuItem('Inspect object');
%@
%@          % Set the menu items' callbacks
%@          set(handle(menuItem1,'CallbackProperties'), 'ActionPerformedCallback', {@btExport_Callback,{obj,varname}});
%@          set(handle(menuItem2,'CallbackProperties'), 'ActionPerformedCallback', {@btExport_Callback,{obj,[]}});
%@          set(handle(menuItem3,'CallbackProperties'), 'ActionPerformedCallback', {@requestFocus,obj});
%@          set(handle(menuItem4,'CallbackProperties'), 'ActionPerformedCallback', {@flashComponent,{obj,0.2,3}});
%@          set(handle(menuItem5,'CallbackProperties'), 'ActionPerformedCallback', {@nodeSelected,{tree_h,node}});
%@          set(handle(menuItem6,'CallbackProperties'), 'ActionPerformedCallback', {@btInspect_Callback,obj});
%@
%@          % Add all menu items to the context menu (with internal separator)
%@          jmenu = JPopupMenu;
%@          jmenu.add(menuItem0);
%@          jmenu.addSeparator;
%@          handleValue=[];  try handleValue = double(obj); catch, end;  %#ok
%@          if ~isempty(handleValue)
%@              % For valid HG handles only
%@              menuItem0a = JMenuItem('Copy handle value to clipboard');
%@              set(handle(menuItem0a,'CallbackProperties'), 'ActionPerformedCallback', sprintf('clipboard(''copy'',%.99g)',handleValue));
%@              jmenu.add(menuItem0a);
%@          end
%@          jmenu.add(menuItem1);
%@          jmenu.add(menuItem2);
%@          jmenu.addSeparator;
%@          jmenu.add(menuItem3);
%@          jmenu.add(menuItem4);
%@          jmenu.add(menuItem5);
%@          jmenu.add(menuItem6);
%@    end  % setTreeContextMenu
%@
%@    %% Set the mouse-press callback
%@    function treeMousePressedCallback(hTree, eventData, tree_h)  %#ok hTree is unused
%@        if eventData.isMetaDown  % right-click is like a Meta-button
%@            % Get the clicked node
%@            clickX = eventData.getX;
%@            clickY = eventData.getY;
%@            jtree = eventData.getSource;
%@            treePath = jtree.getPathForLocation(clickX, clickY);
%@            try
%@                % Modify the context menu based on the clicked node
%@                node = treePath.getLastPathComponent;
%@                userdata = get(node,'userdata');
%@                obj = userdata.obj;
%@                jmenu = setTreeContextMenu(obj,node,tree_h);
%@
%@                % TODO: remember to call jmenu.remove(item) in item callback
%@                % or use the timer hack shown here to remove the item:
%@                %    timerFcn = {@menuRemoveItem,jmenu,item};
%@                %    start(timer('TimerFcn',timerFcn,'StartDelay',0.2));
%@
%@                % Display the (possibly-modified) context menu
%@                jmenu.show(jtree, clickX, clickY);
%@                jmenu.repaint;
%@
%@                % This is for debugging:
%@                userdata.tree = jtree;
%@                setappdata(gcf,'findjobj_hgtree',userdata)
%@            catch
%@                % clicked location is NOT on top of any node
%@                % Note: can also be tested by isempty(treePath)
%@            end
%@        end
%@    end  % treeMousePressedCallback
%@
%@    %% Remove the extra context menu item after display
%@    function menuRemoveItem(hObj,eventData,jmenu,item) %#ok unused
%@        jmenu.remove(item);
%@    end  % menuRemoveItem
%@
%@    %% Get the title for the tooltip and context (right-click) menu
%@    function nodeTitleStr = getNodeTitleStr(obj,node)
%@        try
%@            % Display the full classname and object name in the tooltip
%@            %nodeName = char(node.getName);
%@            %nodeName = strrep(nodeName, '<HTML><i><font color="gray">','');
%@            %nodeName = strrep(nodeName, '</font></i></html>','');
%@            nodeName = char(getNodeName(obj,99));
%@            [objClass,objName] = strtok(nodeName);
%@            objName = objName(3:end-1);  % strip leading ( and trailing )
%@            if isempty(objName),  objName = '(none found)';  end
%@            nodeName = char(node.getName);
%@            objClass = char(obj.getClass.getName);
%@            nodeTitleStr = sprintf('<html>Class name: <font color="blue">%s</font><br>Text/title: %s',objClass,objName);
%@
%@            % If the component is invisible, state this in the tooltip
%@            if ~isempty(strfind(nodeName,'color="gray"'))
%@                nodeTitleStr = [nodeTitleStr '<br><font color="gray"><i><b>*** Invisible ***</b></i></font>'];
%@            end
%@            nodeTitleStr = [nodeTitleStr '<hr>Right-click for context-menu'];
%@        catch
%@            % Possible not a Java object - try treating as an HG handle
%@            try
%@                handleValueStr = sprintf('#: <font color="blue"><b>%.99g<b></font>',double(obj));
%@                try
%@                    type = '';
%@                    type = get(obj,'type');
%@                    type(1) = upper(type(1));
%@                catch
%@                    if ~ishandle(obj)
%@                        type = ['<font color="red"><b>Invalid <i>' char(node.getName) '</i>'];
%@                        handleValueStr = '!!!</b></font><br>Perhaps this handle was deleted after this UIInspect tree was<br>already drawn. Try to refresh by selecting any valid node handle';
%@                    end
%@                end
%@                nodeTitleStr = sprintf('<html>%s handle %s',type,handleValueStr);
%@                try
%@                    % If the component is invisible, state this in the tooltip
%@                    if strcmp(get(obj,'Visible'),'off')
%@                        nodeTitleStr = [nodeTitleStr '<br><center><font color="gray"><i>Invisible</i></font>'];
%@                    end
%@                catch
%@                    % never mind...
%@                end
%@            catch
%@                % never mind... - ignore
%@            end
%@        end
%@    end  % getNodeTitleStr
%@
%@    %% Handle tree mouse movement callback - used to set the tooltip & context-menu
%@    function treeMouseMovedCallback(hTree, eventData)
%@          try
%@              x = eventData.getX;
%@              y = eventData.getY;
%@              jtree = eventData.getSource;
%@              treePath = jtree.getPathForLocation(x, y);
%@              try
%@                  % Set the tooltip string based on the hovered node
%@                  node = treePath.getLastPathComponent;
%@                  userdata = get(node,'userdata');
%@                  obj = userdata.obj;
%@                  tooltipStr = getNodeTitleStr(obj,node);
%@                  set(hTree,'ToolTipText',tooltipStr)
%@              catch
%@                  % clicked location is NOT on top of any node
%@                  % Note: can also be tested by isempty(treePath)
%@              end
%@          catch
%@              dispError;
%@          end
%@          return;  % denug breakpoint
%@    end  % treeMouseMovedCallback
%@
%@    %% Request focus for a specific object handle
%@    function requestFocus(hTree, eventData, obj)  %#ok hTree & eventData are unused
%@        % Ensure the object handle is valid
%@        if isjava(obj)
%@            obj.requestFocus;
%@            return;
%@        elseif ~ishandle(obj)
%@            msgbox('The selected object does not appear to be a valid handle as defined by the ishandle() function. Perhaps this object was deleted after this hierarchy tree was already drawn. Refresh this tree by selecting a valid node handle and then retry.','FindJObj','warn');
%@            beep;
%@            return;
%@        end
%@
%@        try
%@            foundFlag = 0;
%@            while ~foundFlag
%@                if isempty(obj),  return;  end  % sanity check
%@                type = get(obj,'type');
%@                obj = double(obj);
%@                foundFlag = any(strcmp(type,{'figure','axes','uicontrol'}));
%@                if ~foundFlag
%@                    obj = get(obj,'Parent');
%@                end
%@            end
%@            feval(type,obj);
%@        catch
%@            % never mind...
%@            dispError;
%@        end
%@    end  % requestFocus
%@
%@
%@end  % FINDJOBJ
%@
%@
%@%% TODO TODO TODO
%@%{
%@- Enh: Improve performance - esp. expandNode() (performance solved in non-interactive mode)
%@- Enh: Add property listeners - same problem in MathWork's inspect.m
%@- Enh: Display additional properties - same problem in MathWork's inspect.m
%@- Enh: Add axis (plot, Graphics) component handles
%@- Enh: Group callbacks according to the first word (up to 2nd cap letter)
%@- Enh: Add figure thumbnail image below the java tree (& indicate corresponding jObject when selected)
%@- Enh: scroll initially-selected node into view (problem because treenode has no pixel location)
%@- Fix: java exceptions when getting some fields (com.mathworks.mlwidgets.inspector.PropertyRootNode$PropertyListener$1$1.run)
%@- Fix: use EDT if available (especially in flashComponent)
%@%}
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/getlayercount.m__ -->
%@function varargout = getlayercount(varargin)
%@% GETLAYERCOUNT Import layer count information.
%@%     DATA = GETLAYERCOUNT(GUI,LOGFILENAME) imports data of layer count
%@%     records. GUI specifies whether a GUI is used or not, LOGFILENAME
%@%     is the name of the file, where all meta information is saved or loaded
%@%     from.
%@
%@
%@
%@
%@%% init
%@filenameLC = '';
%@lc = [];
%@
%@%% get the filename of the layer count data
%@
%@    filenameLC_in = input(['Select layer count data',10,'[',filenameLC,']: '],'s');
%@    if ~isempty(filenameLC_in) 
%@        filenameLC = filenameLC_in;
%@    end
%@    
%@%% import layer count data
%@
%@if exist(filenameLC)
%@    % load layer count data
%@    lc = load(filenameLC);
%@
%@    % check for monotonicity of the layer count data
%@    if any(diff(lc(:,2))) < 0
%@        error('Layer count data must be monotonic!')
%@    end
%@else
%@    warning('Selection of layer count data canceled!')
%@end
%@
%@
%@
%@%% return data
%@if nargout == 1 && size(lc,2) == 3 
%@    data.d_lc = lc(:,1);
%@    data.v_lc = lc(:,2);
%@    data.e_lc = lc(:,3);
%@    varargout{1} = data;
%@elseif nargout == 3 && size(lc,2) == 3
%@    varargout{1} = lc(:,1);
%@    varargout{2} = lc(:,2);
%@    varargout{3} = lc(:,3);
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/getlogfilename.m__ -->
%@function d = getlogfilename(d_in)
%@% GETLOGFILENAME Checks name or existence of log file.
%@
%@%% create the new logfilename
%@filenameLog = ['log_COPRA_',datestr(now,'yyyymmdd'),'.m'];
%@
%@
%@if nargin
%@    d = d_in;
%@else
%@    d.log = filenameLog;
%@end
%@
%@
%@if ~isfield(d,'log')
%@    d.log = filenameLog;
%@end
%@
%@% check whether an old log file exists
%@logfile = dir('log*.m');
%@
%@if ~isempty(logfile)
%@	    choiceIn = input(['Old log file (',logfile(end).name,') found.',10,'Should it be used? [YES/No]: '],'s');
%@        if ~isempty(choiceIn) && strcmpi(choiceIn(1),'N')
%@            %if strcmpi(filenameLog,logfile(end).name)
%@                filenameLog = strrep(filenameLog,'.m','_1.m');
%@                disp(['Warning: Logfile renamed to ',filenameLog])                
%@            %end
%@            
%@            d.log = filenameLog;
%@        else
%@            
%@            d.log = logfile(end).name;
%@            d.uselog = 1;
%@            
%@            % load existing information from logfile
%@            eval('caller',strrep(d.log,'.m',''))
%@            
%@                                                
%@        end
%@end
%@
%@% clear logfile
%@fid = fopen(d.log,'w');frewind(fid);fclose(fid);   
%@
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/getnicedialoglocation.m__ -->
%@function figure_size = getnicedialoglocation(figure_size, figure_units)
%@% adjust the specified figure position to fig nicely over GCBF
%@% or into the upper 3rd of the screen
%@
%@%  Copyright 1999-2006 The MathWorks, Inc.
%@%  $Revision: 1.1.6.3 $
%@
%@%%%%%% PLEASE NOTE %%%%%%%%%
%@%%%%%% This file has also been copied into:
%@%%%%%% matlab/toolbox/ident/idguis
%@%%%%%% If this functionality is changed, please
%@%%%%%% change it also in idguis.
%@%%%%%% PLEASE NOTE %%%%%%%%%
%@
%@parentHandle = gcbf;
%@propName = 'Position';
%@if isempty(parentHandle)
%@    parentHandle = 0;
%@    propName = 'ScreenSize';
%@end
%@
%@old_u = get(parentHandle,'Units');
%@set(parentHandle,'Units',figure_units);
%@container_size=get(parentHandle,propName);
%@set(parentHandle,'Units',old_u);
%@
%@figure_size(1) = container_size(1)  + 1/2*(container_size(3) - figure_size(3));
%@figure_size(2) = container_size(2)  + 2/3*(container_size(4) - figure_size(4));
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/isgui.m__ -->
%@function [gui guistr] = isgui(varargin)
%@% ISGUI Checks structure varargin for input.
%@
%@
%@error(nargchk(1, 1, nargin, 'struct'))
%@
%@argin = varargin{1};
%@
%@idxChar = find(cellfun('isclass',argin,'char'));
%@check_gui = {'sil','nog','gui'}; % nogui, gui, silent
%@gui = 1;
%@
%@if ~isempty(argin{1}) 
%@    gui = 0;
%@    for i = 1:length(idxChar), 
%@        gui = gui + strcmpi(argin{idxChar(i)}(1:3),check_gui');
%@    end
%@    if any(gui)
%@        gui = min(find(gui))-2;
%@        if nargout > 1, guistr = check_gui(gui+2); end
%@    else
%@        gui = 1;
%@        if nargout > 1, guistr = 'gui'; end
%@    end
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/isoctave.m__ -->
%@function flag = isoctave
%@% ISOCTAVE   Checks whether the code is running in Octave
%@%   ISOCTAVE is returning the value TRUE if executed within the
%@%   Octave environment, else it is returning FALSE (e.g. when
%@%   called within Matlab.
%@
%@% Copyright (c) 2013
%@% Norbert Marwan, Potsdam Institute for Climate Impact Research, Germany
%@% http://www.pik-potsdam.de
%@%
%@% $Date: 2013/08/30 13:45:06 $
%@% $Revision: 1.1 $
%@
%@a = ver('Octave');
%@
%@if ~isempty(a) && strfind(a(1).Name,'Octave')
%@    flag = true;
%@else
%@    flag = false;
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/loaddata.m__ -->
%@function varargout = loaddata(varargin)
%@% GETDATA Import dating table and proxy data.
%@%     DATA = GETDATA(STRUCT) imports data of datings and proxy
%@%     records. 
%@
%@%% default values
%@
%@d.filenameAD = '';
%@d.filenameProxy = '';
%@d.id = [];
%@d.depth = [];
%@d.age = [];
%@d.ageerror = [];
%@d.comment = '';
%@d.d_prxy = [];
%@d.v_prxy = [];
%@d.samplename = '';
%@d.proxyname = '';
%@
%@if nargin
%@    d = varargin{:};
%@else
%@    d = [];
%@end
%@
%@if ~isfield(d,'gui'); d.gui = 0; end
%@if ~isfield(d,'filenameAD'); d.filenameAD = ''; end
%@if ~isfield(d,'filenameProxy'); d.filenameProxy = ''; end
%@if ~isfield(d,'samplename'); d.samplename = ''; end
%@if ~isfield(d,'proxyname'); d.proxyname = ''; end
%@
%@if ~isfield(d,'log'); d.log = ''; end
%@
%@
%@%% specify filenames
%@filenameAD_in = input(['Select input age-depth data',10,'[',d.filenameAD,']: '],'s');
%@filenameProxy_in = input(['Select proxy data file (e.g. isotope measurements)',10,'[',d.filenameProxy,']: '],'s');
%@if ~isempty(filenameAD_in) 
%@    d.filenameAD = filenameAD_in;
%@end
%@if ~isempty(filenameProxy_in)
%@    d.filenameProxy = filenameProxy_in;
%@end
%@
%@% log
%@savelog(d.log,'d.filenameAD','Name of the file with the datings:')
%@savelog(d.log,'d.filenameProxy','Name of the proxy data file:')
%@
%@
%@
%@%% import age model data and check for number of headerlines
%@nHeaderlines = 0;
%@fid = fopen(d.filenameAD, 'r');
%@
%@if fid < 0 || ~exist(d.filenameProxy,'file')
%@    error('File not found.')
%@end
%@
%@while 1
%@    
%@    % import dating data
%@    if isoctave % octave calling        
%@        c = textscan2(fid,'%f%f%f','headerlines',nHeaderlines,'whitespace',' \b\t,;');
%@    else % matlab calling
%@        c = textscan(fid,'%f%f%f','headerlines',nHeaderlines,'whitespace',' \b\t,;');
%@    end
%@    
%@    if (isempty(c{1})) % still a headerline
%@        nHeaderlines = nHeaderlines + 1;
%@    else % data section reached, break
%@        break
%@    end
%@end
%@fclose(fid);
%@
%@
%@% variables
%@d.depth = c{1};
%@d.age = c{2};
%@d.ageerror = c{3};
%@%comment = c{4};
%@d.id = 1:length(d.depth);
%@
%@clear c
%@clear fid
%@
%@%% Import proxy data
%@
%@data = load(d.filenameProxy);
%@d.d_prxy = data(:,1); %depth of isotope samples (assumed to be in mm)
%@d.v_prxy = data(:,2); %measured value for (isotope) sample, eg. d18O
%@clear data
%@
%@%% check if inputfiles have correct stratigraphic order
%@
%@strata_check_prxy = zeros(1,length(d.d_prxy)-1);
%@strata_check_depth = zeros(1,length(d.depth)-1);
%@
%@for i = 2:length(d.d_prxy)
%@    strata_check_prxy(i-1) = d.d_prxy(i) - d.d_prxy(i-1);
%@end
%@
%@for i = 2:length(d.depth)
%@    strata_check_depth(i-1) = d.depth(i) - d.depth(i-1);
%@end
%@
%@badLines_prxy = find(strata_check_prxy <= 0);
%@badLines_depth = find(strata_check_depth <= 0);
%@
%@if any(badLines_prxy) && any(badLines_depth)
%@    error(['ERROR: Both input files contain multiple or incorrectly ordered '...
%@        'depth entries! Check around the lines:', sprintf('\n') ,num2str(badLines_depth), ' (AD file)',...
%@        sprintf('\n'), num2str(badLines_prxy),' (Proxy file)']);    
%@elseif any(badLines_prxy)
%@    error(['ERROR: The proxy file contains multiple or incorrectly ordered '...
%@        'depth entries! Check around the lines: ',num2str(badLines_prxy)]);    
%@elseif any(badLines_depth)
%@    error(['ERROR: The age-depth file contains multiple or incorrectly ordered '...
%@        'depth entries! Check around the lines: ',num2str(badLines_depth)]);    
%@end
%@
%@%% checking for NaNs in the imported data
%@nanidx = isnan(d.depth) + isnan(d.age) + isnan(d.ageerror);
%@if any(nanidx)
%@    display('Age-Depth data contains NaNs! NaNs will be removed.')
%@    nanidx = find(nanidx);
%@    d.depth(nanidx) = [];
%@    d.age(nanidx) = [];
%@    d.ageerror(nanidx) = [];
%@    % log
%@    savelog(d.log,'nanidx','NaNs removed in the age-depth data:')
%@end
%@
%@if length(d.d_prxy) ~= length(d.v_prxy)
%@    error('Column length in proxy record differ. Please check the proxy record file!')
%@end
%@
%@nanidx = isnan(d.d_prxy) + isnan(d.v_prxy);
%@if any(nanidx)
%@    display('Proxy data contains NaNs! NaNs will be removed!')
%@    nanidx = find(nanidx);
%@    d.d_prxy(nanidx) = [];
%@    d.v_prxy(nanidx) = [];
%@    savelog(d.log,'nanidx','NaNs removed in the proxy data:')
%@end
%@
%@% log
%@savelog(d.log,'d.id',['Dating values',10,'% ID:'])
%@savelog(d.log,'d.depth',['depth:'])
%@savelog(d.log,'d.age','age:')
%@savelog(d.log,'d.ageerror','ageerror:')
%@savelog(d.log,'d.d_prxy','depth axis proxy record:')
%@savelog(d.log,'d.v_prxy','values of the proxy record:')
%@
%@%% naming of the project
%@prompt = {'Enter a project name',...
%@    'Enter a name for the chosen proxy'};
%@issue = 'Name the project and proxy';
%@numlines = 1;
%@
%@if isempty(d.samplename) && isempty(d.proxyname)
%@    defaultanswer = {['copra_',date],'\delta^{18}O'};
%@else
%@    defaultanswer = {d.samplename,d.proxyname};
%@end
%@
%@%%
%@
%@disp(issue)
%@d.samplename = input([prompt{1}, ' [', defaultanswer{1},']: '],'s');
%@d.proxyname = input([prompt{2}, ' [', defaultanswer{2},']: '],'s');
%@
%@if isempty(d.samplename)
%@    d.samplename = defaultanswer{1};
%@end
%@
%@if isempty(d.proxyname)
%@    d.proxyname = defaultanswer{2};
%@end
%@
%@
%@% log
%@savelog(d.log,'d.samplename','project name:')
%@savelog(d.log,'d.proxyname','name of the proxy:')
%@
%@
%@
%@%% check whether output folder exists (if not, create it)
%@if ~exist('output','dir')
%@    [err errmsg] = mkdir('output');
%@    if err
%@        warning('Create folder ''ouput''')
%@    else
%@        error(errmsg)
%@    end
%@end
%@
%@%% Ask which confidence bounds should be used in the output
%@if ~isfield(d,'confbnds_prxy')
%@    
%@    correctInput = 0;
%@    
%@    while (~(correctInput == 1))
%@        d.confbnds_prxy = input('Confidence interval (in %) for the PROXY in the output file? [95]:','s');
%@        
%@        % set default value
%@        if isempty(d.confbnds_prxy)
%@            d.confbnds_prxy = 95;
%@            correctInput = 1;
%@        else         
%@            d.confbnds_prxy = str2double(d.confbnds_prxy);  
%@            
%@            % check if input is ok
%@            if length(d.confbnds_prxy) > 1 || isnan(d.confbnds_prxy)
%@                warning(['The confidence interval must be only one value, e.g. 95, which will yield an ',...
%@                    'interval from 2.5 % to 97.5 %'])                
%@                clear d.confbnds_prxy;
%@            elseif d.confbnds_prxy > 100 || d.confbnds_prxy < 0
%@                warning('The value must lie between 0 and 100');
%@                clear d.confbnds_prxy;
%@            else                    
%@                correctInput = 1;
%@            end
%@            
%@        end
%@        
%@    end  
%@    
%@       
%@    correctInput = 0;
%@    while (~(correctInput == 1))
%@       d.confbnds_age = input('Confidence interval (in %) for AGE in the output file? [95]:','s');
%@        
%@       % set default value
%@       if isempty(d.confbnds_age)
%@           d.confbnds_age = 95;
%@           correctInput = 1;
%@       else
%@           d.confbnds_age = str2double(d.confbnds_age);
%@              
%@           if length(d.confbnds_age) > 1 || isnan(d.confbnds_age)
%@               warning(['The confidence interval must be only one value, e.g. 95, which will yield an ',...
%@                   'interval from 2.5 % to 97.5 %'])
%@               clear d.confbnds_prxy;
%@           elseif d.confbnds_age > 100 || d.confbnds_age < 0
%@               warning('The value must lie between 0 and 100')
%@               clear d.confbnds_prxy;
%@           else
%@               correctInput = 1;
%@           end 
%@       end
%@       
%@    end
%@          
%@end
%@
%@% save values to logfile
%@savelog(d.log,'d.confbnds_prxy','Confidence interval Proxy (in output file):')
%@savelog(d.log,'d.confbnds_age','Confidence interval Ages (in output file):')
%@
%@
%@%% return data
%@
%@if nargout == 1
%@    varargout{1} = d;
%@    
%@elseif nargout == 5
%@    varargout{1} = ddepth;
%@    varargout{2} = dage;
%@    varargout{3} = dageerror;
%@    varargout{6} = dcomment;
%@    varargout{4} = dd_prxy;
%@    varargout{5} = dv_prxy;
%@    varargout{7} = dsamplename;
%@    varargout{8} = dproxyname;
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/makemonotone.m__ -->
%@function [t_new, x_new, time, cancelFlag] = makemonotone(depth,age,ageerror,...
%@    interp_scale,M,interp_method)
%@% MAKEMONOTONE emulates monotonous MC age-depth relationships for the
%@% dating table (depth age ageerror) and the given interpolation
%@% preferences.
%@
%@% output variables:
%@% t_new - M realisations of the ages in the age model  
%@% x_new - M realisations of the depths in the age model
%@% time  - M realisations of interpolated time axis for the proxy record
%@
%@    N = length(ageerror);
%@    varnce = 1;
%@    i = varnce*randn(N, M);
%@    
%@    if size(age,2) == 1
%@        t_new = repmat(age, 1, M) + repmat(ageerror, 1, M) .* i; 
%@        x_new = repmat(depth, 1, M) + .1 * randn(N, M)/2;              
%@    elseif size(age,2) == 2        
%@        ncolsa = 2;
%@        idx = find(diff(age,1,2));
%@        if ~isempty(idx)
%@            n = 2^(size(idx,1));
%@            mu_ = repmat(age,1,n/ncolsa);
%@            sd_ = repmat(ageerror,1,n/ncolsa);
%@            for m = 1:numel(idx)
%@                k = 2^m;
%@                k_ = size(mu_,2)/k;
%@                for j = 1:k
%@                    colstart = 1 + (j-1)*k_;
%@                    colend = colstart + k_ -1;
%@                    mu_(idx(m),colstart:colend) = age(idx(m),mod(j,ncolsa)+1);
%@                    sd_(idx(m),colstart:colend) = ageerror(idx(m),mod(j,ncolsa)+1);
%@                end
%@            end
%@            alpha = linspace(0,1,n+1)';
%@            sel = rand(1,M);
%@            t_new = zeros(N,M);
%@            for m = 1:n
%@                t_tmp = repmat(mu_(:,m), 1, M) + repmat(sd_(:,m), 1, M) .* i;
%@                t_new(:,alpha(m)<sel&sel<alpha(m+1)) = t_tmp(:,alpha(m)<sel&sel<alpha(m+1));
%@            end
%@            clear t_tmp
%@        else
%@            age = age(:,1);ageerror = ageerror(:,1);
%@            t_new = repmat(age, 1, M) + repmat(ageerror, 1, M) .* i;
%@        end
%@        x_new = repmat(depth, 1, M) + .1 * randn(N, M)/2;        
%@    else
%@        error('The age data has to be one- or two-column matrix')
%@    end
%@    
%@    time = interp1(depth, t_new, interp_scale,interp_method,'extrap');
%@	
%@        
%@    k=1; % no of non-reversed trajectories for MC simulation
%@    agerev=0; % no of simulated agedepth trajectories that were reversed
%@    
%@    if ~isoctave
%@        h = waitbar(0,'MonteCarlo Simulation running ... please wait.','CreateCancelBtn',...
%@            'setappdata(gcbf,''canceling'',1)');      
%@    else
%@        h = waitbar(0,'MonteCarlo Simulation running ... please wait.');
%@    end
%@    
%@    cancelFlag = 0;
%@    setappdata(h,'canceling',0);
%@    
%@    
%@    while k < M+1
%@        % cancel computation
%@        if getappdata(h, 'canceling');
%@            cancelFlag = 1;
%@            break
%@        end 
%@        
%@        waitbar(k/(M+1))      
%@               
%@        monoton=false;
%@        while ~monoton,
%@            time(:,k) = interp1(depth, t_new(:,k), interp_scale,interp_method,'extrap');      %cubic interpolation of MC simulated depth error
%@            
%@            % check monotonicity
%@            if all(diff(time(:,k))>=0)
%@                monoton=true; % OK
%@                k = k+1;
%@            else 
%@                agerev = agerev+1; %number of reversed MC ages
%@                if size(age,2) == 1 || isempty(idx)
%@                    t_new(:,k) = age + ageerror .* randn(N,1) .*varnce;
%@                elseif size(age,2) == 2  && ~isempty(idx)
%@                    sel = rand();
%@                    t_tmp = zeros(N,n);
%@                    for m = 1:n
%@                        t_tmp(:,m) = mu_(:,m) + sd_(:,m) .*randn(N,1).*varnce;
%@                    end
%@                    idx_ = find(alpha>sel,1,'first');
%@                    t_new(:,k) = t_tmp(:,idx_-1);
%@                end
%@                x_new(:,k) = depth + .1 * randn(N, 1)/2; 
%@                monoton=false; % try again
%@%                 if agerev > 10000, monoton=true;k = M+1;end
%@                if agerev==100000, 
%@                    k,
%@                    warning('difficult to ensure monotonicity of the agemodel: reversal or bottleneck?');end
%@                if agerev > 100000000, 
%@                    k,
%@                    error('100 Mio tries, monotonous age-depth relationship for dating data difficult to ensure. Reverse age-depth relationship.');end
%@            end
%@
%@        end
%@        
%@    end
%@    delete(h)
%@    if cancelFlag
%@        disp('Simulation canceled')
%@    else
%@        disp('No of reversed tries:')
%@        disp(agerev)        
%@%    In total: agerev 'reversals'
%@    end
%@%    In total: agerev 'reversals'
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/makemonotoneLC.m__ -->
%@function [t_new, x_new, deep, time, cancelFlag] = makemonotoneLC(depth,age,ageerror,...
%@    deptherror,interp_scale_age,interp_scale_depth,M,interp_method)
%@% MAKEMONOTONE emulates monotonous MC age-depth relationships for the
%@% dating table (depth age ageerror) and the given interpolation
%@% preferences.
%@    if isempty(ageerror)
%@        ageerror = zeros(size(age));
%@    end
%@    if isempty(deptherror)
%@        deptherror = zeros(size(depth));
%@    end
%@    
%@    N = length(ageerror);
%@    varnce = 1;
%@    i = varnce*randn(N, M);
%@    
%@    t_new = repmat(age, 1, M) + repmat(ageerror, 1, M) .* i;
%@    x_new = repmat(depth, 1, M) + repmat(deptherror, 1, M) .* i;
%@    
%@    time = zeros(N,M);
%@    deep = zeros(N,M);
%@    
%@    for i = 1:M        
%@        time(:,i) = interp1(x_new(:,i),t_new(:,i),interp_scale_depth,interp_method,'extrap');
%@        deep(:,i) = interp1(t_new(:,i),x_new(:,i),interp_scale_age,interp_method,'extrap');
%@    end
%@            
%@    k=1; % no of non-reversed trajectories for MC simulation
%@    agerev=0; % no of simulated agedepth trajectories that were reversed
%@    if ~isoctave
%@        h = waitbar(0,'MonteCarlo Simulation running ... please wait.','CreateCancelBtn',...
%@            'setappdata(gcbf,''canceling'',1)');      
%@    else
%@        h = waitbar(0,'MonteCarlo Simulation running ... please wait.');
%@    end
%@    
%@    cancelFlag = 0;
%@    setappdata(h,'canceling',0);
%@
%@    while k < M+1
%@        % cancel computation
%@        if getappdata(h, 'canceling');
%@            cancelFlag = 1;
%@            break
%@        end 
%@        
%@        waitbar(k/(M+1))
%@        
%@        monoton=false;
%@        while ~monoton,
%@            
%@            time(:,k) = interp1(x_new(:,k),t_new(:,k),interp_scale_depth,interp_method,'extrap');
%@            deep(:,k) = interp1(t_new(:,k),x_new(:,k),interp_scale_age,interp_method,'extrap');
%@            
%@            % check monotonicity
%@            if all(diff(time(:,k))>=0) && all(diff(deep(:,k))>=0)
%@                monoton=true; % OK
%@                k = k+1;
%@            else 
%@                agerev = agerev+1; %number of reversed MC ages                
%@                t_new(:,k) = age + ageerror .* randn(N,1) .*varnce;
%@                x_new(:,k) = depth + deptherror .* randn(N,1) .*varnce;
%@                monoton=false; % try again
%@                if agerev > 50000, warning('difficult to ensure monotonicity of the layercounting data');monoton=true;k = M+1;end
%@                if agerev > 500000, error('100000 tries, monotonous age-depth relationship for layercounting data difficult to ensure');monoton=true;k = M+1;end
%@
%@            end
%@
%@        end
%@    end
%@    delete(h)
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/mynanmean.m__ -->
%@function y = mynanmean(x, dim)
%@% MYNANMEAN Mean value, ignoring NaNs.
%@
%@idx_nan = isnan(x);
%@x(idx_nan) = 0;
%@
%@if nargin == 1
%@    dim = find(size(x) ~= 1, 1);
%@end
%@
%@y = sum(x,dim) ./ sum(~idx_nan,dim);
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/mynanmedian.m__ -->
%@function y = mynanmedian(x,dim)
%@% MYNANMEDIAN    Median value, ignoring NaNs.
%@
%@if nargin == 1
%@    y = prctile(x, 50);
%@else
%@    y = prctile(x, 50,dim);
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/mynanstd.m__ -->
%@function y = mynanstd(x,dim)
%@% MYNANSTD    Standard deviation, ignoring NaNs.
%@
%@idx_nan = isnan(x);
%@
%@dims = size(x);
%@
%@if nargin == 1
%@    dim = find(dims ~= 1, 1);
%@end
%@
%@tile = ones(size(dims));
%@tile(dim) = dims(dim);
%@
%@normx = x - repmat(mynanmean(x, dim), tile);
%@y = sqrt(mynansum(abs(normx).^2, dim) ./ sum(~idx_nan,dim)); 
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/mynansum.m__ -->
%@function y = mynansum(x,dim)
%@% MYNANSUM    Sum, ignoring NaNs.
%@
%@if nargin == 1
%@    dim = find(size(x) ~= 1, 1);
%@end
%@
%@x(isnan(x)) = 0;
%@y = sum(x, dim);
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/mynarginchk.m__ -->
%@function mynarginchk(noarg,minarg,maxarg)
%@%MYNARGINCHK A replacement for the Matlab narginchk.
%@%   Checks whether noargs is between minarg and maxarg and returns an error if not.
%@
%@if noarg > maxarg
%@	error(['Too many input arguments (maximal ', num2str(maxarg),').'])
%@end
%@if noarg < minarg
%@	error(['Not enough input arguments (minimal ', num2str(minarg),').'])
%@end
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/newid.m__ -->
%@function Answer=inputdlg(Prompt, Title, NumLines, DefAns, Resize)
%@%INPUTDLG Input dialog box.
%@%  ANSWER = INPUTDLG(PROMPT) creates a modal dialog box that returns user
%@%  input for multiple prompts in the cell array ANSWER. PROMPT is a cell
%@%  array containing the PROMPT strings.
%@%
%@%  INPUTDLG uses UIWAIT to suspend execution until the user responds.
%@%
%@%  ANSWER = INPUTDLG(PROMPT,NAME) specifies the title for the dialog.
%@%
%@%  ANSWER = INPUTDLG(PROMPT,NAME,NUMLINES) specifies the number of lines for
%@%  each answer in NUMLINES. NUMLINES may be a constant value or a column
%@%  vector having one element per PROMPT that specifies how many lines per
%@%  input field. NUMLINES may also be a matrix where the first column
%@%  specifies how many rows for the input field and the second column
%@%  specifies how many columns wide the input field should be.
%@%
%@%  ANSWER = INPUTDLG(PROMPT,NAME,NUMLINES,DEFAULTANSWER) specifies the
%@%  default answer to display for each PROMPT. DEFAULTANSWER must contain
%@%  the same number of elements as PROMPT and must be a cell array of
%@%  strings.
%@%
%@%  ANSWER = INPUTDLG(PROMPT,NAME,NUMLINES,DEFAULTANSWER,OPTIONS) specifies
%@%  additional options. If OPTIONS is the string 'on', the dialog is made
%@%  resizable. If OPTIONS is a structure, the fields Resize, WindowStyle, and
%@%  Interpreter are recognized. Resize can be either 'on' or
%@%  'off'. WindowStyle can be either 'normal' or 'modal'. Interpreter can be
%@%  either 'none' or 'tex'. If Interpreter is 'tex', the prompt strings are
%@%  rendered using LaTeX.
%@%
%@%  Examples:
%@%
%@%  prompt={'Enter the matrix size for x^2:','Enter the colormap name:'};
%@%  name='Input for Peaks function';
%@%  numlines=1;
%@%  defaultanswer={'20','hsv'};
%@%
%@%  answer=inputdlg(prompt,name,numlines,defaultanswer);
%@%
%@%  options.Resize='on';
%@%  options.WindowStyle='normal';
%@%  options.Interpreter='tex';
%@%
%@%  answer=inputdlg(prompt,name,numlines,defaultanswer,options);
%@%
%@%  See also DIALOG, ERRORDLG, HELPDLG, LISTDLG, MSGBOX,
%@%    QUESTDLG, TEXTWRAP, UIWAIT, WARNDLG .
%@
%@%  Copyright 1994-2005 The MathWorks, Inc.
%@%  $Revision: 1.58.4.11 $
%@
%@%%%%%%%%%%%%%%%%%%%%
%@%%% Nargin Check %%%
%@%%%%%%%%%%%%%%%%%%%%
%@error(nargchk(0,5,nargin));
%@error(nargoutchk(0,1,nargout));
%@
%@%%%%%%%%%%%%%%%%%%%%%%%%%
%@%%% Handle Input Args %%%
%@%%%%%%%%%%%%%%%%%%%%%%%%%
%@if nargin<1
%@    Prompt='Input:';
%@end
%@if ~iscell(Prompt)
%@    Prompt={Prompt};
%@end
%@NumQuest=numel(Prompt);
%@
%@
%@if nargin<2,
%@    Title=' ';
%@end
%@
%@if nargin<3
%@    NumLines=1;
%@end
%@
%@if nargin<4 
%@    DefAns=cell(NumQuest,1);
%@    for lp=1:NumQuest
%@        DefAns{lp}='';
%@    end
%@end
%@
%@if nargin<5
%@    Resize = 'off';
%@end
%@WindowStyle='modal';
%@Interpreter='none';
%@
%@Options = struct([]); %#ok
%@if nargin==5 && isstruct(Resize)
%@    Options = Resize;
%@    Resize  = 'off';
%@    if isfield(Options,'Resize'),      Resize=Options.Resize;           end
%@    if isfield(Options,'WindowStyle'), WindowStyle=Options.WindowStyle; end
%@    if isfield(Options,'Interpreter'), Interpreter=Options.Interpreter; end
%@end
%@
%@[rw,cl]=size(NumLines);
%@OneVect = ones(NumQuest,1);
%@if (rw == 1 & cl == 2) %#ok Handle []
%@    NumLines=NumLines(OneVect,:);
%@elseif (rw == 1 & cl == 1) %#ok
%@    NumLines=NumLines(OneVect);
%@elseif (rw == 1 & cl == NumQuest) %#ok
%@    NumLines = NumLines';
%@elseif (rw ~= NumQuest | cl > 2) %#ok
%@    error('MATLAB:inputdlg:IncorrectSize', 'NumLines size is incorrect.')
%@end
%@
%@if ~iscell(DefAns),
%@    error('MATLAB:inputdlg:InvalidDefaultAnswer', 'Default Answer must be a cell array of strings.');
%@end
%@
%@%%%%%%%%%%%%%%%%%%%%%%%
%@%%% Create InputFig %%%
%@%%%%%%%%%%%%%%%%%%%%%%%
%@FigWidth=175;
%@FigHeight=100;
%@FigPos(3:4)=[FigWidth FigHeight];  %#ok
%@FigColor=get(0,'DefaultUicontrolBackgroundcolor');
%@
%@InputFig=dialog(                     ...
%@    'Visible'          ,'off'      , ...
%@    'KeyPressFcn'      ,@doFigureKeyPress, ...
%@    'Name'             ,Title      , ...
%@    'Pointer'          ,'arrow'    , ...
%@    'Units'            ,'pixels'   , ...
%@    'UserData'         ,'Cancel'   , ...
%@    'Tag'              ,Title      , ...
%@    'HandleVisibility' ,'callback' , ...
%@    'Color'            ,FigColor   , ...
%@    'NextPlot'         ,'add'      , ...
%@    'WindowStyle'      ,WindowStyle, ...
%@    'DoubleBuffer'     ,'on'       , ...
%@    'Resize'           ,Resize       ...
%@    );
%@
%@
%@%%%%%%%%%%%%%%%%%%%%%
%@%%% Set Positions %%%
%@%%%%%%%%%%%%%%%%%%%%%
%@DefOffset    = 5;
%@DefBtnWidth  = 53;
%@DefBtnHeight = 23;
%@
%@TextInfo.Units              = 'pixels'   ;   
%@TextInfo.FontSize           = get(0,'FactoryUIControlFontSize');
%@TextInfo.FontWeight         = get(InputFig,'DefaultTextFontWeight');
%@TextInfo.HorizontalAlignment= 'left'     ;
%@TextInfo.HandleVisibility   = 'callback' ;
%@
%@StInfo=TextInfo;
%@StInfo.Style              = 'text'  ;
%@StInfo.BackgroundColor    = FigColor;
%@
%@
%@EdInfo=StInfo;
%@EdInfo.FontWeight      = get(InputFig,'DefaultUicontrolFontWeight');
%@EdInfo.Style           = 'edit';
%@EdInfo.BackgroundColor = 'white';
%@
%@BtnInfo=StInfo;
%@BtnInfo.FontWeight          = get(InputFig,'DefaultUicontrolFontWeight');
%@BtnInfo.Style               = 'pushbutton';
%@BtnInfo.HorizontalAlignment = 'center';
%@
%@% Add VerticalAlignment here as it is not applicable to the above.
%@TextInfo.VerticalAlignment  = 'bottom';
%@TextInfo.Color              = get(0,'FactoryUIControlForegroundColor');
%@
%@
%@% adjust button height and width
%@btnMargin=1.4;
%@ExtControl=uicontrol(InputFig   ,BtnInfo     , ...
%@                     'String'   ,'OK'        , ...
%@                     'Visible'  ,'off'         ...
%@                     );
%@
%@% BtnYOffset  = DefOffset;
%@BtnExtent = get(ExtControl,'Extent');
%@BtnWidth  = max(DefBtnWidth,BtnExtent(3)+8);
%@BtnHeight = max(DefBtnHeight,BtnExtent(4)*btnMargin);
%@delete(ExtControl);
%@
%@% Determine # of lines for all Prompts
%@TxtWidth=FigWidth-2*DefOffset;
%@ExtControl=uicontrol(InputFig   ,StInfo     , ...
%@                     'String'   ,''         , ...
%@                     'Position' ,[ DefOffset DefOffset 0.96*TxtWidth BtnHeight ] , ...
%@                     'Visible'  ,'off'        ...
%@                     );
%@
%@WrapQuest=cell(NumQuest,1);
%@QuestPos=zeros(NumQuest,4);
%@
%@for ExtLp=1:NumQuest
%@    if size(NumLines,2)==2
%@        [WrapQuest{ExtLp},QuestPos(ExtLp,1:4)]= ...
%@            textwrap(ExtControl,Prompt(ExtLp),NumLines(ExtLp,2));
%@    else
%@        [WrapQuest{ExtLp},QuestPos(ExtLp,1:4)]= ...
%@            textwrap(ExtControl,Prompt(ExtLp),80);
%@    end
%@end % for ExtLp
%@
%@delete(ExtControl);
%@QuestWidth =QuestPos(:,3);
%@QuestHeight=QuestPos(:,4);
%@
%@TxtHeight=QuestHeight(1)/size(WrapQuest{1,1},1);
%@EditHeight=TxtHeight*NumLines(:,1);
%@EditHeight(NumLines(:,1)==1)=EditHeight(NumLines(:,1)==1)+4;
%@
%@FigHeight=(NumQuest+2)*DefOffset    + ...
%@          BtnHeight+sum(EditHeight) + ...
%@          sum(QuestHeight);
%@
%@TxtXOffset=DefOffset;
%@
%@QuestYOffset=zeros(NumQuest,1);
%@EditYOffset=zeros(NumQuest,1);
%@QuestYOffset(1)=FigHeight-DefOffset-QuestHeight(1);
%@EditYOffset(1)=QuestYOffset(1)-EditHeight(1);
%@
%@for YOffLp=2:NumQuest,
%@    QuestYOffset(YOffLp)=EditYOffset(YOffLp-1)-QuestHeight(YOffLp)-DefOffset;
%@    EditYOffset(YOffLp)=QuestYOffset(YOffLp)-EditHeight(YOffLp);
%@end % for YOffLp
%@
%@QuestHandle=[]; %#ok
%@EditHandle=[];
%@
%@AxesHandle=axes('Parent',InputFig,'Position',[0 0 1 1],'Visible','off');
%@
%@inputWidthSpecified = false;
%@
%@for lp=1:NumQuest,
%@    if ~ischar(DefAns{lp}),
%@        delete(InputFig);
%@        %error('Default Answer must be a cell array of strings.');
%@        error('MATLAB:inputdlg:InvalidInput', 'Default Answer must be a cell array of strings.');
%@    end
%@
%@    EditHandle(lp)=uicontrol(InputFig    , ...
%@                             EdInfo      , ...
%@                             'Max'        ,NumLines(lp,1)       , ...
%@                             'Position'   ,[ TxtXOffset EditYOffset(lp) TxtWidth EditHeight(lp) ], ...
%@                             'String'     ,DefAns{lp}           , ...
%@                             'Tag'        ,'Edit',                ...
%@                              'Callback' ,@doEnter);
%@                             
%@
%@    QuestHandle(lp)=text('Parent'     ,AxesHandle, ...
%@                         TextInfo     , ...
%@                         'Position'   ,[ TxtXOffset QuestYOffset(lp)], ...
%@                         'String'     ,WrapQuest{lp}                 , ...
%@                         'Interpreter',Interpreter                   , ...
%@                         'Tag'        ,'Quest'                         ...
%@                         );
%@
%@    MinWidth = max(QuestWidth(:));
%@    if (size(NumLines,2) == 2)
%@        % input field width has been specified.
%@        inputWidthSpecified = true;
%@        EditWidth = setcolumnwidth(EditHandle(lp), NumLines(lp,1), NumLines(lp,2));
%@        MinWidth = max(MinWidth, EditWidth);
%@    end
%@    FigWidth=max(FigWidth, MinWidth+2*DefOffset);
%@
%@end % for lp
%@
%@% fig width may have changed, update the edit fields if they dont have user specified widths.
%@if ~inputWidthSpecified
%@    TxtWidth=FigWidth-2*DefOffset;
%@    for lp=1:NumQuest
%@        set(EditHandle(lp), 'Position', [TxtXOffset EditYOffset(lp) TxtWidth EditHeight(lp)]);
%@    end
%@end
%@
%@FigPos=get(InputFig,'Position');
%@
%@FigWidth=max(FigWidth,2*(BtnWidth+DefOffset)+DefOffset);
%@FigPos(1)=0;
%@FigPos(2)=0;
%@FigPos(3)=FigWidth;
%@FigPos(4)=FigHeight;
%@
%@set(InputFig,'Position',getnicedialoglocation(FigPos,get(InputFig,'Units')));
%@
%@OKHandle=uicontrol(InputFig     ,              ...
%@                   BtnInfo      , ...
%@                   'Position'   ,[ FigWidth-2*BtnWidth-2*DefOffset DefOffset BtnWidth BtnHeight ] , ...
%@                   'KeyPressFcn',@doControlKeyPress , ...
%@                   'String'     ,'OK'        , ...
%@                   'Callback'   ,@doCallback , ...
%@                   'Tag'        ,'OK'        , ...
%@                   'UserData'   ,'OK'          ...
%@                   );
%@
%@setdefaultbutton(InputFig, OKHandle);
%@
%@CancelHandle=uicontrol(InputFig     ,              ...
%@                       BtnInfo      , ...
%@                       'Position'   ,[ FigWidth-BtnWidth-DefOffset DefOffset BtnWidth BtnHeight ]           , ...
%@                       'KeyPressFcn',@doControlKeyPress            , ...
%@                       'String'     ,'Cancel'    , ...
%@                       'Callback'   ,@doCallback , ...
%@                       'Tag'        ,'Cancel'    , ...
%@                       'UserData'   ,'Cancel'      ...
%@                       ); %#ok
%@
%@handles = guihandles(InputFig);
%@handles.MinFigWidth = FigWidth;
%@handles.FigHeight   = FigHeight;
%@handles.TextMargin  = 2*DefOffset;
%@guidata(InputFig,handles);
%@set(InputFig,'ResizeFcn', {@doResize, inputWidthSpecified});
%@
%@% make sure we are on screen
%@movegui(InputFig)
%@
%@% if there is a figure out there and it's modal, we need to be modal too
%@if ~isempty(gcbf) && strcmp(get(gcbf,'WindowStyle'),'modal')
%@    set(InputFig,'WindowStyle','modal');
%@end
%@
%@set(InputFig,'Visible','on');
%@drawnow;
%@
%@if ~isempty(EditHandle)
%@    uicontrol(EditHandle(1));
%@end
%@
%@uiwait(InputFig);
%@
%@if ishandle(InputFig)
%@    Answer={};
%@    if strcmp(get(InputFig,'UserData'),'OK'),
%@        Answer=cell(NumQuest,1);
%@        for lp=1:NumQuest,
%@            Answer(lp)=get(EditHandle(lp),{'String'});
%@        end
%@    end
%@    delete(InputFig);
%@else
%@    Answer={};
%@end
%@
%@function doFigureKeyPress(obj, evd) %#ok
%@switch(evd.Key)
%@ case {'return','space'}
%@  set(gcbf,'UserData','OK');
%@  uiresume(gcbf);
%@ case {'escape'}
%@  delete(gcbf);
%@end
%@
%@function doControlKeyPress(obj, evd) %#ok
%@switch(evd.Key)
%@ case {'return'}
%@  if ~strcmp(get(obj,'UserData'),'Cancel')
%@      set(gcbf,'UserData','OK');
%@      uiresume(gcbf);
%@  else
%@      delete(gcbf)
%@  end
%@ case 'escape'
%@  delete(gcbf)
%@end
%@
%@function doCallback(obj, evd) %#ok
%@if ~strcmp(get(obj,'UserData'),'Cancel')
%@    set(gcbf,'UserData','OK');
%@    uiresume(gcbf);
%@else
%@    delete(gcbf)
%@end
%@
%@function doEnter(obj, evd) %#ok
%@
%@h = get(obj,'Parent');
%@x = get(h,'CurrentCharacter');
%@if unicode2native(x) == 13
%@    doCallback(obj,evd);
%@end
%@
%@function doResize(FigHandle, evd, multicolumn) %#ok
%@% TBD: Check difference in behavior w/ R13. May need to implement
%@% additional resize behavior/clean up.
%@
%@Data=guidata(FigHandle);
%@
%@resetPos = false; 
%@
%@FigPos = get(FigHandle,'Position');
%@FigWidth = FigPos(3);
%@FigHeight = FigPos(4);
%@
%@if FigWidth < Data.MinFigWidth
%@    FigWidth  = Data.MinFigWidth;
%@    FigPos(3) = Data.MinFigWidth;
%@    resetPos = true;
%@end
%@
%@% make sure edit fields use all available space if 
%@% number of columns is not specified in dialog creation.
%@if ~multicolumn
%@    for lp = 1:length(Data.Edit)
%@        EditPos = get(Data.Edit(lp),'Position');
%@        EditPos(3) = FigWidth - Data.TextMargin;
%@        set(Data.Edit(lp),'Position',EditPos);
%@    end
%@end
%@
%@if FigHeight ~= Data.FigHeight
%@    FigPos(4) = Data.FigHeight;
%@    resetPos = true;
%@end
%@
%@if resetPos
%@    set(FigHandle,'Position',FigPos);  
%@end
%@
%@
%@% set pixel width given the number of columns
%@function EditWidth = setcolumnwidth(object, rows, cols)
%@% Save current Units and String.
%@old_units = get(object, 'Units');
%@old_string = get(object, 'String');
%@old_position = get(object, 'Position');
%@
%@set(object, 'Units', 'pixels')
%@set(object, 'String', char(ones(1,cols)*'x'));
%@
%@new_extent = get(object,'Extent');
%@if (rows > 1)
%@    % For multiple rows, allow space for the scrollbar
%@    new_extent = new_extent + 19; % Width of the scrollbar
%@end
%@new_position = old_position;
%@new_position(3) = new_extent(3) + 1;
%@set(object, 'Position', new_position);
%@
%@% reset string and units
%@set(object, 'String', old_string, 'Units', old_units);
%@
%@EditWidth = new_extent(3);
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/plotagemodel.m__ -->
%@function handle_fig = plotagemodel(d,ptype, varargin)
%@% PLOTAGEMODEL_CL plots the agemodels (time) that were derived from M MC
%@% simulations from the dating table in finalagemodel and according to the
%@% information in the data struct d.
%@% ptype gives the plot type, i.e. whether the plot should show
%@% median/mean/mode of the agemodel ensemble, or the whole ensemble
%@% (spaghetti).
%@% the third input argument is the confidence interval
%@% EXAMPLE:
%@% hfig = plotagemodel(d,'mean',95)
%@
%@
%@
%@if ~d.gui
%@    handle_fig = figure('Name', 'Age model');
%@    set(handle_fig,'Units','normalized','Position',[.6 .4 .3 .5])
%@    hold on
%@end
%@
%@adinf = d.adinf;
%@hiatus = d.hiatus;
%@depth = d.depth;
%@age = d.age;
%@ageerror = d.ageerror;
%@age_orig = age;
%@depth_orig = depth;
%@hia_depth = d.hia_depth;
%@samplename = d.samplename;
%@depthname = d.depthname;
%@d_prxy = d.d_prxy;
%@M = d.M;
%@time = d.T_unc(:,3:end);
%@
%@
%@if d.adinf
%@    d_lc = d.dlc.d_lc;
%@else
%@    d_lc=[];
%@end
%@
%@% time
%@spaghetti = 0; gray = 0;
%@% sunset = [0.99 , 0.94, 0.83];
%@
%@x_up = max(max(time));
%@x_lo = min(min(time));
%@
%@switch lower(ptype)
%@    case 'spaghetti'
%@        plttitle = ['Age-Depth relationships for ', ...
%@            num2str(M),' different age models']; 
%@        spaghetti = 1;
%@    case 'mean'
%@        time = mynanmean(time,2);
%@        plttitle = ['Age-Depth relationship: Mean of ', ...
%@            num2str(M),' different age models'];        
%@    case 'median'
%@        time = mynanmedian(time,2);
%@        plttitle = ['Age-Depth relationship: Median of ', ...
%@            num2str(M),' different age models'];         
%@    case 'grayscale'
%@        % plots spaghetti with each spaghetti changing color dependent on
%@        % deviation from mean
%@        time_mean = mynanmean(time,2);
%@        plttitle = ['Age-Depth relationships for ', ...
%@            num2str(M),' different age models']; 
%@        gray = 1;
%@end
%@
%@%sd = mynanstd(time,2);
%@% compute value of the quantiles for given confidence interval
%@if ~spaghetti && ~gray
%@    agemods_time = d.T_unc(:,3:end);
%@    
%@    if isempty(varargin)
%@        try
%@            confInt = d.confbnds_age;
%@            fprintf('No age confindence interval input argument for plotting, using: %u %%\n',confInt);
%@        catch
%@            error('Must specify confidence interval');
%@        end
%@    elseif ~isa(varargin{1},'double')
%@        try
%@            confInt = d.confbnds_age;
%@            fprintf('WARNING: Confidence interval argument must be numeric, using %u %% for now\n',confInt);
%@        catch
%@            error('Confidence interval argument must be numeric');
%@        end        
%@    else
%@        confInt = varargin{1};      
%@    end
%@    
%@    qu = quantile(agemods_time,[0.5-confInt/200 0.5+confInt/200],2);
%@end
%@
%@if adinf == 1
%@    rectangle('Position',[x_lo-(x_up-x_lo)*0.099,d_lc(1),1.2*(x_up-x_lo),...
%@        d_lc(end)-d_lc(1)],'FaceColor',[.85 .85 .85],'EdgeColor','None')
%@end
%@
%@% y_lo = min(d_prxy);
%@% y_up = max(d_prxy);
%@idx = find(hiatus);
%@for s = 1:length(idx)
%@    if s == 1
%@        if s ~= length(idx)
%@            tmpu = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@            tmpu = find(d_prxy<tmpu,1,'last');
%@            %             rectangle('Position',[age(idx(s)),y_lo+0.099*(y_up-y_lo),...
%@            %                 age(idx(s)+1)-age(idx(s)),y_up-y_lo],'FaceColor',...
%@            %                 'c','EdgeColor','None')
%@        else
%@            tmpu = length(d_prxy);
%@        end
%@        if ~isempty(hia_depth)&&hia_depth(s)
%@            tmpu = find(d_prxy<=hia_depth(s),1,'last');
%@        end
%@        
%@        % plot
%@        tmpx = time(1:tmpu,:);
%@        tmpy = d_prxy(1:tmpu);    
%@        
%@        if ~gray
%@            plot(tmpx,tmpy)
%@        else % grayscale plot of spaghetti
%@            tmpz = zeros(size(tmpy));            
%@            tmpxmean = time_mean(1:tmpu);
%@                        
%@            for i = 1:size(tmpx,2)
%@                tmpcol = abs(tmpx(:,i) - tmpxmean).^(1/4);                
%@                               
%@                surface([tmpx(:,i) tmpx(:,i)],[tmpy tmpy],[tmpz tmpz],[tmpcol tmpcol],...
%@                    'facecol','no',...
%@                    'edgecol','interp',...
%@                    'linew',1);
%@            end
%@                colormap('gray')             
%@        end
%@        
%@        tmp_xlo = min(xlim); tmp_xhi = max(xlim);
%@        if any(hia_depth)
%@            line([tmp_xlo,tmp_xhi],[d_prxy(tmpu),d_prxy(tmpu)],'LineStyle',...
%@                '--','LineWidth',1,'Color','k')
%@        end
%@    elseif s > 1 && s < length(idx) % in between
%@        tmpu = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@        tmpu = find(d_prxy<tmpu,1,'last');
%@        tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@        tmpl = find(d_prxy>=tmpl,1,'first');
%@        if hia_depth(s)
%@            tmpu = find(d_prxy<=hia_depth(s),1,'last');
%@            %%&*&*&*%%&*&*&*
%@            tmpl = find(d_prxy> hia_depth(s-1),1,'first');
%@        end
%@        
%@        %plot
%@        tmpx = time(tmpl:tmpu,:);
%@        tmpy = d_prxy(tmpl:tmpu);
%@        
%@        if ~gray
%@            plot(tmpx,tmpy)
%@        else % grayscale plot of spaghetti
%@            tmpz = zeros(size(tmpy));            
%@            tmpxmean = time_mean(tmpl:tmpu);
%@            
%@            for i = 1:size(tmpx,2)
%@                tmpcol = abs(tmpx(:,i) - tmpxmean).^(1/4);                
%@                
%@                surface([tmpx(:,i) tmpx(:,i)],[tmpy tmpy],[tmpz tmpz],[tmpcol tmpcol],...
%@                    'facecol','no',...
%@                    'edgecol','interp',...
%@                    'linew',1);
%@            end
%@            colormap('gray')
%@        end
%@        
%@        tmp_xlo = min(xlim); tmp_xhi = max(xlim);
%@        
%@        % dashed line for hiatus
%@        if any(hia_depth)
%@            line([tmp_xlo,tmp_xhi],ones(2,1)*hia_depth(s),'LineStyle',...
%@                '--','LineWidth',1,'Color','k')
%@        end
%@        
%@    elseif s == length(idx) && s ~= 1
%@        tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@        tmpl = find(d_prxy> tmpl,1,'first');
%@        if hia_depth(s-1)%%&*&*&*
%@            %%&*&*&*
%@            %tmpl = find(d_prxy>=hia_depth(s-1),1,'first');
%@            tmpl = find(d_prxy> hia_depth(s-1),1,'first');
%@            %%&*&*&*
%@        end
%@        
%@        %plot
%@        tmpx = time(tmpl:end,:);
%@        tmpy = d_prxy(tmpl:end);
%@        
%@        if ~gray
%@            plot(tmpx,tmpy)
%@        else % grayscale plot of spaghetti
%@            tmpz = zeros(size(tmpy));            
%@            tmpxmean = time_mean(tmpl:end);
%@                        
%@            for i = 1:size(tmpx,2)
%@                tmpcol = abs(tmpx(:,i) - tmpxmean).^(1/4);                
%@                               
%@                surface([tmpx(:,i) tmpx(:,i)],[tmpy tmpy],[tmpz tmpz],[tmpcol tmpcol],...
%@                    'facecol','no',...
%@                    'edgecol','interp',...
%@                    'linew',1);
%@            end
%@                colormap('gray')             
%@        end
%@        
%@    end
%@    clear tmpx tmpy
%@    
%@    % plot confidence bounds
%@    if spaghetti || gray
%@        continue
%@    else
%@        
%@        if s == 1
%@            plot(qu(1:tmpu,1),d_prxy(1:tmpu),'r--',...
%@                qu(1:tmpu,2),d_prxy(1:tmpu),'r--')
%@        elseif s > 1 && s < length(idx)
%@            plot(qu(tmpl:tmpu,1),d_prxy(tmpl:tmpu),...
%@                'r--',qu(tmpl:tmpu,2),...
%@                d_prxy(tmpl:tmpu),'r--')
%@        elseif s == length(idx) && s ~= 1
%@            plot(qu(tmpl:end,1),d_prxy(tmpl:end),...
%@                'r--',qu(tmpl:end,2),...
%@                d_prxy(tmpl:end),'r--')
%@        end
%@        x_up = max(qu(:,2));
%@        x_lo = min(qu(:,1));
%@        
%@    end
%@        
%@   
%@    clear tmpl tmpu
%@end
%@
%@errorbarxy(age,depth,ageerror,[])
%@if ~gray
%@    plot(age_orig,depth_orig,'ro','markersize',6.4,'LineWidth',1.95)
%@end
%@
%@% ---- Customise plot:
%@%set(gca,'Units','inches','OuterPosition',[0,0,6,6.67])
%@set(gca,'fontsize',12)             % General minimum fontsize in figure
%@axlabftsz = 14;                 % fontsize for axis labels
%@% ---- Set X-axis limits
%@set(gca,'XLim',[x_lo-(x_up-x_lo)*0.1,x_up+(x_up-x_lo)*0.1])
%@% ---- Set XTicks (ALWAYS ONLY 7 in number)
%@xlo = min(xlim); xhi = max(xlim);
%@xdiff = xhi-xlo;
%@xlo_round = round(xlo/100)*100; xhi_round = round(xhi/100)*100;
%@xstep = round((xhi_round-xlo_round)/600)*100;
%@%xtik = xlo:(xhi-xlo)/8:xhi;
%@xtik = xlo_round:xstep:xhi_round;
%@if ~isempty(xtik)
%@    xtik(1) = [];
%@    %xtik=round(xtik/100)*100;%round to next integer
%@    set(gca,'XTick',xtik)
%@    %------------------
%@    % ---- Set XTickLabels
%@    if length(find(age<1000)) > length(age)/2  || xdiff < 1e4% >50% ages less than 1000 BP
%@        xtiklab = cell(size(xtik));
%@        for i = 1:length(xtik)
%@            xtiklab{i} = num2str(xtik(i),'%4.0f');
%@        end
%@        set(gca,'XTickLabel',xtiklab)
%@        xlabel('Age (yrs BP)','fontsize',axlabftsz,'fontweight', 'bold')    
%@    elseif 0.5*(length(find(age>1e3)) + length(find(age<1e6))) > ...
%@            length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@        xtiklab = cell(size(xtik));
%@        for i = 1:length(xtik)
%@            xtiklab{i} = num2str(xtik(i)/1e3,'%4.0f');
%@        end
%@        set(gca,'XTickLabel',xtiklab)
%@        xlabel('Age (kyrs BP)','fontsize',axlabftsz,'fontweight', 'bold')
%@    elseif 0.5*(length(find(age>1e6)) + length(find(age<1e9))) > ...
%@            length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@        xtiklab = cell(size(xtik));
%@        for i = 1:length(xtik)            
%@            xtiklab{i} = num2str(xtik(i)/1e6,'%4.0f');
%@        end
%@        set(gca,'XTickLabel',xtiklab)
%@        xlabel('Age (Myrs BP)','fontsize',axlabftsz,'fontweight', 'bold')
%@    end
%@    % ---- End Set XTickLabels
%@    % ----------
%@end
%@
%@
%@axis square
%@set(gca,'ydir','reverse')
%@set(gca,'XAxisLocation','top'),
%@box on
%@ylabel(depthname,'fontsize',axlabftsz,'fontweight','bold')
%@%title({plttitle,samplename}, 'fontweight', 'bold','fontsize',axlabftsz+2)
%@%clear legend
%@if ~spaghetti && ~gray  
%@    if any(hia_depth)
%@        legend('Agemodel','Hiatus',[num2str(confInt), ' % CI']);
%@    else
%@        legend('Agemodel',[num2str(confInt), ' % CI']);
%@    end
%@end
%@hold off
%@% xlim([x_lo,x_up])
%@ylim([d_prxy(1),d_prxy(end-1)])
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/plotproxyrecords.m__ -->
%@function d = plotproxyrecords(d,ptype,varargin)
%@% PLOTPROXYRECORDS_CL plots the time series of the proxy records 
%@% PLOTPROXYRECORDS_CL plots the time series of the proxy records that were derived from M MC
%@% simulations from the dating table in finalagemodel and according to the
%@% information in the data struct d. ptype gives the plot type, i.e. whether
%@% the plot should show median/mean/mode of the agemodel ensemble, or the
%@% whole ensemble (spaghetti).
%@% the third input argument is the confidence interval
%@% EXAMPLE
%@% hfig=plotproxyrecords(d,'mean',95)
%@
%@
%@if ~d.gui
%@    handle_fig = figure('Name', 'Proxy record');
%@    set(handle_fig,'Units','normalized','Position',[.3 .05 .4 .5])
%@    hold on
%@end
%@
%@hia_depth = d.hia_depth;
%@samplename = strrep(d.samplename,'_','\_');
%@d_prxy = d.d_prxy;
%@v_prxy = d.v_prxy;
%@adinf = d.adinf;
%@hiatus = d.hiatus;
%@depth = d.depth;
%@M = d.M;
%@time = d.T_unc(:,3:end); 
%@
%@
%@if d.adinf
%@    d_lc = d.dlc.d_lc; 
%@else 
%@    d_lc = [];
%@end
%@spaghetti = 0;
%@
%@
%@
%@% sunset = [0.99 , 0.94, 0.83];
%@switch lower(ptype)
%@    case 'spaghetti'
%@        plttitle = ['Proxy time series for ', ...
%@            num2str(M),' different age models'];
%@        x_up = max(max(time));
%@        x_lo = min(min(time));
%@        spaghetti = 1;
%@        proxy=d.T_unc(:,2);
%@        time=d.T_unc(:,3:end);
%@        
%@    case 'mean'
%@        time=d.T_cert(:,1); % mean (=expectation) of the distributions of ages at proxy depths
%@        proxy=d.T_cert(:,2);% mean proxy expectation value at certain times
%@        
%@        plttitle = [' Proxy time series, resampled from ', ...
%@            num2str(M),' different age models'];
%@        x_up = max(time);
%@        x_lo = min(time);
%@                
%@    case 'median'
%@        plttitle = [' Proxy time series, resampled from ', ...
%@            num2str(M),' different age models'];
%@        time = d.T_cert(:,1);
%@        proxy = d.T_cert(:,3);
%@
%@end
%@
%@% compute value of the quantiles for given confidence interval
%@if ~spaghetti
%@    agemod_time = d.T_unc(:,3:end);
%@    t = mynanmean(agemod_time,2); % interpolate to the mean time values corresponding to the depths at which the proxy was measured
%@    temp = zeros(length(t),size(agemod_time,2));
%@    
%@    for i = 1:size(agemod_time,2)
%@        temp(:,i) = interp1(agemod_time(:,i), v_prxy, t, 'linear')';
%@    end
%@        
%@    if isempty(varargin)
%@        try
%@            confInt = d.confbnds_prxy;
%@            fprintf('No proxy  confindence interval input argument for plotting, using: %u %%\n',confInt);
%@        catch
%@            error('Must specify confidence interval');
%@        end
%@    elseif ~isa(varargin{1},'double')
%@        try
%@            confInt = d.confbnds_prxy;
%@            fprintf('WARNING: Confidence interval argument must be numeric, using %u %% for now\n',confInt);
%@        catch
%@            error('Confidence interval argument must be numeric');
%@        end        
%@    else
%@        confInt = varargin{1};      
%@    end
%@    
%@    qu = quantile(temp,[0.5-confInt/200 0.5+confInt/200],2);
%@              
%@end
%@% if adinf == 1
%@%     rectangle('Position',[x_lo-(x_up-x_lo)*0.099,d_lc(1),1.2*(x_up-x_lo),...
%@%         d_lc(end)-d_lc(1)],'FaceColor',[.85 .85 .85],'EdgeColor','None')
%@% end
%@
%@
%@idx = find(hiatus);
%@for s = 1:length(idx) % plot each segment (in case of hiatus(es)) separately   
%@    if s == 1
%@        % top segment
%@        if s ~= length(idx)
%@            tmpu = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@            tmpu = find(d_prxy<tmpu,1,'last');            
%@        else 
%@            tmpu = length(d_prxy);
%@        end
%@        if ~isempty(hia_depth)&&hia_depth(s)
%@            tmpu = find(d_prxy<=hia_depth(s),1,'last');
%@        end
%@        %*****%
%@        tmpx = time(1:tmpu,:);
%@        tmpy=proxy(1:tmpu,:);          
%@        plot(tmpx,tmpy)
%@        %*****%
%@        tmp_xlo = min(xlim); tmp_xhi = max(xlim);
%@        
%@    elseif s > 1 && s < length(idx) % in between
%@        tmpu = 0.5*(depth(idx(s))+depth(idx(s)+1));
%@        tmpu = find(d_prxy<tmpu,1,'last');
%@        tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@        tmpl = find(d_prxy>=tmpl,1,'first');
%@        if hia_depth(s)
%@            tmpu = find(d_prxy<=hia_depth(s),1,'last');
%@            tmpl = find(d_prxy> hia_depth(s-1),1,'first');
%@        end
%@        %*****%
%@        tmpx = time(tmpl:tmpu,:);
%@        tmpy = proxy(tmpl:tmpu,:);
%@        %*****%
%@        plot(tmpx,tmpy)
%@    
%@        
%@        tmp_xlo = min(xlim); tmp_xhi = max(xlim);
%@
%@    elseif s == length(idx) && s ~= 1 % bottom segment
%@        tmpl = 0.5*(depth(idx(s-1))+depth(idx(s-1)+1));
%@        tmpl = find(d_prxy>=tmpl,1,'first');
%@        if hia_depth(s-1)
%@            tmpl = find(d_prxy>hia_depth(s-1),1,'first');
%@        end
%@        %*****%
%@        tmpx = time(tmpl:end,:);
%@        tmpy = proxy(tmpl:end,:);
%@        plot(tmpx,tmpy)
%@        %*****%
%@              
%@    end
%@    clear tmpx tmpy
%@    
%@           
%@    if spaghetti 
%@        continue
%@    else
%@        if ~d.gui
%@            % save standard deviation interval choice for the proxy time series
%@            savelog(d.log,'confInt','Confidence bounds Proxy (in proxy time series plot):')
%@        end
%@        
%@        if s == 1
%@            plot(time(1:tmpu),qu(1:tmpu,1),'r--',...
%@                time(1:tmpu),qu(1:tmpu,2),'r--')
%@        elseif s > 1 && s < length(idx)
%@            plot(time(tmpl:tmpu),qu(tmpl:tmpu,1),...
%@                'r--',time(tmpl:tmpu),...
%@                qu(tmpl:tmpu,2),'r--')
%@        elseif s == length(idx) && s ~= 1
%@            plot(time(tmpl:end),qu(tmpl:end,1),...
%@                'r--',time(tmpl:end),...
%@                qu(tmpl:end,2),'r--')
%@        end
%@    end
%@        
%@    
%@       
%@   
%@    clear tmpl tmpu
%@end
%@
%@
%@% Customize plot 
%@if ~d.gui
%@    set(gca,'fontsize',12)             % General minimum fontsize in figure
%@    axlabftsz = 14;                              % fontsize for axis labels
%@    ylabel(d.proxyname,'fontsize',axlabftsz,'fontweight','bold')
%@    xlabel(d.agename,'fontsize',axlabftsz,'fontweight','bold')
%@    title({plttitle,samplename}, 'fontweight', 'bold','fontsize',axlabftsz+2)
%@    if ~spaghetti 
%@        legend('Proxy record', [num2str(confInt), ' % CI'])
%@    end
%@else
%@    set(gca,'fontsize',10)             % General minimum fontsize in figure
%@    axlabftsz = 12;                              % fontsize for axis labels
%@    ylabel(d.proxyname,'fontsize',axlabftsz,'fontweight','bold')
%@    xlabel(d.agename,'fontsize',axlabftsz,'fontweight','bold')
%@    title({plttitle,samplename}, 'fontweight', 'bold','fontsize',axlabftsz+2)
%@    if ~spaghetti 
%@        legend('Proxy record', [num2str(confInt), ' % CI']);
%@    end
%@end
%@hold off
%@end
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/processages_gui.m__ -->
%@function d = processages_gui(varargin)
%@% PROCESSAGES_GUI Interactive modification of dating data.
%@%     PROCESSAGES_GUI(DEPTH,AGE,AGEERROR,SAMPLENAME,PROXYNAME,LOGFILENAME)
%@%     checks whether the age model given by the triplet DEPTH, AGE, and
%@%     AGEERROR contains (tractable and non-tractable) reversals. SAMPLENAME
%@%     and PROXYNAME contain names for sample and 
%@%     LOGFILENAME is the name of the log file.
%@%
%@%     PROCESSAGES_GUI(DATASTRUCT,LOGFILENAME) checks for reversals by using the
%@%     struct DATASTRUCT with the fields DATASTRUCT.DEPTH, DATASTRUCT.AGE,
%@%     DATASTRUCT.AGEERROR, DATASTRUCT.SAMPLENAME.
%@
%@
%@%% check input 
%@finalagemodel=[];
%@% default values
%@gui = 1;
%@filenameLog = ['log_COPRA_',datestr(now,'yyyymmdd'),'.m'];
%@am_commented = 1;
%@treat = 1;
%@action = '';
%@
%@
%@%narginchk(1, 9) % matlab2012 only (and octave)
%@if (nargin>9)||(nargin<1),error('Number of arguments <1 or >9', nargin), end
%@
%@
%@% get input variables
%@if nargin
%@    idxNum = find(cellfun('isclass',varargin,'double'));
%@    idxChar = find(cellfun('isclass',varargin,'char'));
%@    idxStruct = find(cellfun('isclass',varargin,'struct'));
%@    % get numerical input arguments (data)
%@    if ~isempty(idxNum) && length(idxNum) >= 4
%@            depth = varargin{idxNum(1)};
%@            age = varargin{idxNum(2)};
%@            ageerror = varargin{idxNum(3)};
%@            revType = varargin{idxNum(4)};
%@    end
%@    if ~isempty(idxChar) && length(idxChar) >= 2
%@            samplename = varargin{idxChar(1)};
%@            proxyname = varargin{idxChar(2)};
%@    end
%@    if ~isempty(idxChar) && length(idxChar) == 1
%@            if ~strcmpi(varargin{idxChar(1)}(1:3),'log')
%@                action = varargin{idxChar(1)};
%@                d = get(gcf,'UserData');
%@                filenameLog = d.filenameLog;
%@            end
%@            
%@            
%@    end
%@
%@    % get struct input arguments (data)
%@    if ~isempty(idxStruct)
%@            d = varargin{idxStruct(1)};
%@            depth = d.depth;
%@            age = d.age;
%@            ageerror = d.ageerror;
%@            revType = d.revType;
%@            samplename = d.samplename;
%@            hiatus = d.hiatus;
%@            comment = d.comment;
%@    end
%@    % get char input arguments (filename)
%@    filenameLog = getlogfilename(varargin);
%@    [gui guistring] = isgui(varargin);
%@
%@end
%@
%@%% load existing information from meta file
%@if exist(filenameLog)
%@    eval('caller',strrep(filenameLog,'.m',''))
%@end
%@
%@if ~exist('d','var')
%@    d.depth = depth;
%@    d.age = age;
%@    d.ageerror = ageerror;
%@    d.revType = revType;
%@    d.samplename = samplename;
%@    d.proxyname = proxyname;
%@    d.hiatus = hiatus;
%@    d.comment = comment;
%@    d.filenameLog = filenameLog;
%@    d.treat = treat;
%@end
%@
%@%global depth_orig age_orig ageerror_orig am_commented comment
%@%global rev_treat revType
%@global depthname agename
%@
%@
%@switch action
%@  case 'remove'
%@    idx = getPoint
%@    d = get(gcf,'UserData');
%@    d.remove(idx) = 1;
%@    set(gcf,'UserData',d);
%@    
%@    % plot the 'selected' points that will be deleted
%@    hnew=plot(d.age(idx),d.depth(idx), 'x','linestyle','none','LineWidth', 2, 'MarkerSize', 14,'color',[.8 .2 .0]);
%@    %if ~ptremoved, % update legend if this is the first pt to be removed
%@    %    [LEGH,OBJH,OUTH,OUTM] = legend;
%@    %    legend([OUTH;hnew],OUTM{:},'point to be removed','Location','SouthOutside')
%@    %    ptremoved=true;
%@    %end
%@    return
%@    
%@  case 'increaseerror'
%@    idx = getPoint;
%@    d = get(gcf,'UserData');
%@    d.treat(idx) = 1;
%@    set(gcf,'UserData',d);
%@
%@    % plot the 'selected' points that will be deleted
%@    hnew=plot(d.age(idx),d.depth(idx), '^','linestyle','none','LineWidth', 2, 'MarkerSize', 10,'color',[0 .2 .8]);
%@    %if ~ptremoved, % update legend if this is the first pt to be removed
%@    %    [LEGH,OBJH,OUTH,OUTM] = legend;
%@    %    legend([OUTH;hnew],OUTM{:},'point to be removed','Location','SouthOutside')
%@    %    ptremoved=true;
%@    %end
%@    return
%@    
%@  case 'close'
%@    finalagemodel = -1;
%@    %closefigwithwarning(gcf,3)
%@    close(gcf)
%@    return
%@     
%@  case 'proceed'
%@            
%@            if any(d.treat),
%@                increase=true;
%@%                fprintf(fid_metadata,'Increased error of point no %g \n',...
%@%                    find(increrrbars));
%@ %               fprintf(fid_metadata,'\n');
%@                while increase
%@                    display('Increase errorbar size by 10%');
%@                    d.ageerror
%@                    d.age
%@                    d.depth
%@                    find(d.treat)
%@                    d.ageerror(find(d.treat))=d.ageerror(find(d.treat))*1.1;
%@                    %errorbarxy(d.age(d.treat),d.depth(d.treat),d.ageerror(d.treat),[], 'linestyle', 'none');
%@                    % choice = questdlg('What to do now?','Options - increase error bars', 'Increase further','Finish');
%@                    choice=menu('Options- increase error bars', 'Increase', 'Finish');
%@                    % Handle response
%@                    switch choice
%@                        case 1
%@                            disp([choice ' the error bars'])
%@                            increase=true;
%@                            reversal=true;
%@                        case 2
%@                            disp('Finish tuning of the age model, proceed with MC estimation')
%@                            increase=false;
%@                            reversal=false;
%@                    end
%@                end
%@            else
%@                
%@                disp('No error bars increased, go on to remove points')
%@  %              fprintf(fid_metadata,['No error bars increased, go on ',...
%@  %                  'to remove points.\n']);
%@                reversal=false;
%@                treat=false;
%@            end
%@            
%@            if any(d.remove)
%@                % ask if the points should be removed?
%@                sprintf('Removed point no %g \n', find(d.remove))
%@                d.depth(d.remove)=[];d.age(d.remove)=[];d.ageerror(d.remove)=[];
%@                d.hiatus(d.remove)=[];
%@                % possibly: remove the points from plot
%@                %                 treatm={'Add with other treatment', 'Finish treatment'};
%@                %                 choice=menu('Removing points. Choose what to do now.',treatm);
%@                %
%@                %                 % Handle response
%@                %                 switch choice
%@                %                     case 1
%@                disp('Proceed with other treatment')
%@                disp([choice])
%@                reversal=true;
%@                %                     case 2
%@                %                         disp('Finish tuning of the age model, proceed with MC estimation')
%@                %                         reversal=false;
%@                % end
%@            else
%@                disp('no points removed, no error bars increased, go on to MC estimation')
%@%                fprintf(fid_metadata,['No points removed, no error ',...
%@%                    'bars increased, go on to MC estimation.\n']);
%@                reversal=false;
%@                treat=false;
%@            end
%@            
%@            
%@        
%@            set(gcf,'UserData',d);
%@
%@        
%@        
%@        %% Check the agemodel again if there are any non-tractable reversals left
%@
%@  otherwise
%@   
%@
%@
%@    reversal = true; % always enter the inspection loop for the agemodel at least once
%@    ptremoved = false; % for legend entries if pts are removed
%@    ptincrease = false;% for legend entries if pts are selected for increasing errors
%@
%@    %% prepare figure
%@
%@    fig1 = figure('Name', 'Agemodel','Units','inches',...
%@            'OuterPosition',[5,2.5,7.7,6.67],'Toolbar','None');
%@    dcm = datacursormode(fig1);
%@    set(dcm, 'updatefcn', @showcomments)
%@
%@    d.remove = zeros(length(d.age),1);
%@    d.treat = zeros(length(d.age),1);
%@
%@    set(fig1, 'userdata', d)
%@    plt1 = axes('Units','normalized','OuterPosition',[0,0,0.8,0.99]);
%@
%@    set(gca,'fontsize',12)             % General minimum fontsize in figure
%@    axlabftsz = 14;                              % fontsize for axis labels
%@
%@
%@    h0=uicontrol('Style','pushbutton', ...		% Button Remove
%@                'Units','Normalized',...
%@                'Position',[.8 .84 .16 .044], ...
%@                'String','Remove', ...
%@                'CallBack',['processages remove '],...
%@                'Tag','remove',...
%@                'ToolTip','Switch between thresholded and unthresholded CRP.' );
%@
%@    h0=uicontrol('Style','pushbutton', ...		% Button Increase Error
%@                'Units','Normalized',...
%@                'Position',[.8 .72 .16 .044], ...
%@                'String','Increase Error', ...
%@                'CallBack',['processages increaseerror '],...
%@                'Tag','Unthresh',...
%@                'ToolTip','Switch between thresholded and unthresholded CRP.' );
%@
%@
%@    h0=uicontrol('Style','pushbutton', ...		% Button Show Information
%@                'Units','Normalized',...
%@                'Position',[.8 .6 .16 .044], ...
%@                'String','Show Information', ...
%@                'CallBack',['processages showinfo '],...
%@                'Tag','Unthresh',...
%@                'ToolTip','Switch between thresholded and unthresholded CRP.' );
%@
%@
%@    h0=uicontrol('Style','pushbutton', ...		% Button Unthresholded
%@                'Units','Normalized',...
%@                'Position',[.8 .26 .16 .044], ...
%@                'String','Cancel', ...
%@                'CallBack',['processages close '],...
%@                'Tag','Unthresh',...
%@                'ToolTip','Switch between thresholded and unthresholded CRP.' );
%@
%@
%@    h0=uicontrol('Style','pushbutton', ...		% Button Unthresholded
%@                'Units','Normalized',...
%@                'Position',[.8 .14 .16 .044], ...
%@                'String','Proceed', ...
%@                'CallBack',['processages proceed '],...
%@                'Tag','Unthresh',...
%@                'ToolTip','Switch between thresholded and unthresholded CRP.' );
%@
%@    % ---- Set X-axis limits
%@    xhi = max(age+ageerror);xlo=min(age-ageerror);
%@    set(gca,'XLim',[xlo-(xhi-xlo)*0.1,xhi+(xhi-xlo)*0.1])
%@    %     % ---- Set XTicks (ALWAYS ONLY 7 in number)
%@    %     xlo = min(xlim);xhi = max(xlim);
%@    %     xtik = xlo:(xhi-xlo)/8:xhi;
%@    %     xtik(1) = [];
%@    %     set(gca,'XTick',xtik)
%@    %     % ---- Set XTickLabels
%@    %     if length(find(age<1000)) > length(age)/2 % >50% ages less than 1000 BP
%@    %         xtiklab = cell(size(xtik));
%@    %         for i = 1:length(xtik)
%@    %             xtiklab{i} = num2str(xtik(i),'%4.2f');
%@    %         end
%@    %         set(gca,'XTickLabel',xtiklab)
%@    %         xlabel('Age (BP)','fontsize',axlabftsz,'fontweight', 'bold')
%@    %     elseif 0.5*(length(find(age>1e3)) + length(find(age<1e6))) > ...
%@    %             length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@    %         xtiklab = cell(size(xtik));
%@    %         for i = 1:length(xtik)
%@    %             xtiklab{i} = num2str(xtik(i)/1e3,'%4.2f');
%@    %         end
%@    %         set(gca,'XTickLabel',xtiklab)
%@    %         xlabel('Age (kBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@    %     elseif 0.5*(length(find(age>1e6)) + length(find(age<1e9))) > ...
%@    %             length(age)/2             % >50% ages lie between 1kBP and 1MBP
%@    %         xtiklab = cell(size(xtik));
%@    %         for i = 1:length(xtik)
%@    %             xtiklab{i} = num2str(xtik(i)/1e6,'%4.2f');
%@    %         end
%@    %         set(gca,'XTickLabel',xtiklab)
%@    %         xlabel('Age (MBP)','fontsize',axlabftsz,'fontweight', 'bold')
%@    %     end
%@    % ---- End Set XTickLabels
%@    
%@    clear idx                                         %index of selected pt
%@    % ---------- 
%@    % ---------- Plot Dating Table for given Age-Depth data
%@    % ---------- 
%@    % ---- Initialize figure (dim := width = 6in, height = 6.67in)
%@    % ---- Plot the age-depth data
%@    h1=errorbarxy(age,depth,ageerror,[]);
%@    % ---- Customise plot:
%@    % ----------
%@    t=title(['Dating Table for ', samplename],'fontweight', 'bold',...
%@        'fontsize',16);
%@    axis square
%@    set(gca,'ydir','reverse')
%@    set(gca,'XAxisLocation','top'),
%@    box on
%@    ylabel(depthname,'fontsize',axlabftsz,'fontweight', 'bold')
%@    % ---- End Customise plot
%@    % ----------
%@
%@    %%%%%%%%%%%%%%%%%%%%%%
%@    % Markers for reversal types
%@    % green circles for tractable reversals
%@    hold on;
%@    hMarkersTract = plot(age(revType==1),depth(revType==1),'marker','o','linestyle','none','LineWidth', 2, 'MarkerSize', 10,'color',[.1 .7 .2]);
%@    % royal blue circles for non-tractable
%@    hMarkersNT = plot(age(revType==2),depth(revType==2),'marker','o','linestyle','none','LineWidth', 2, 'MarkerSize', 10,'color',[1 .4 .2]);
%@    %%%%%%%%%%%%%%%%%%%%
%@    % selection of treatment/ use as is/ cancel:
%@    if any(revType==1)&~(any(revType==2))% tractable problem only
%@        % legend entry
%@        legend([h1  hMarkersTract ], 'Agemodel with 2\sigma error bars',...
%@            'Tractable reversal','Location','SouthOutside')
%@        message = 'Tractable reversal found. Monotonous age-depth relationships can be established, but you may want to modify the agemodel data.';
%@
%@
%@    %         % do treat! otherwise error
%@    % %         fprintf(fid_metadata,['Tractable reversal found. Monotonous ',...
%@    % %             'age-depth relationships can be established, but you may ',...
%@    % %             'want to modify th agemodel data.\n']);
%@    %         disp('Tractable reversal found. Monotonous age-depth relationships can be established, but you may want to modify the agemodel data.');
%@    %         choices={'Treat', 'Use as is', 'Cancel'};
%@    %         choice=menu('Choose whether the agemodel should be treated',choices);
%@    %         sprintf('Do %s.', choices{choice})
%@    %         switch choice
%@    %             case 1 % modify/treat agemodel
%@    %                 choices{choice}
%@    %  %               fprintf(fid_metadata,['Do %s.', choices{choice},'\n']);
%@    %                 treat=true;
%@    %                 reversal=true;
%@    %             case 2 % use as is/ don't treat
%@    %                 choices{choice}
%@    % %                fprintf(fid_metadata,['Do %s.', choices{choice},'\n']);
%@    %                 treat=false;
%@    %                 reversal=false;
%@    %             case 3 % cancel everything
%@    %                 error('Cancel')
%@    %                 
%@    %         end
%@    elseif any(revType==2)%non-tractable problem
%@        % control the legend-entries
%@        if any(revType==1) %if mixed tractable & non-tractable
%@            legend([h1  hMarkersTract hMarkersNT ],...
%@                'Agemodel with 2\sigma error bars', 'Tractable reversal',...
%@                'Non-tractable-reversal','Location','SouthOutside')
%@        else % purely non-tractable
%@            legend([h1   hMarkersNT ], 'Agemodel with 2\sigma error bars',...
%@                'non-tractable-reversal','Location','SouthOutside')
%@        end
%@
%@        message = 'Non-tractable reversal! It will not be possible to get a monotonous age-depth relationship out of this! Please modify the current agemodel data to continue.';
%@    %         disp('Non-tractable reversal! It will not be possible to get a monotonous age-depth relationship out of this! Please modify the current agemodel data to continue.')
%@    % %        fprintf(fid_metadata,['Non-tractable reversal! It will not ',...
%@    % %            'be possible to get a monotonous age-depth relationship! ',...
%@    % %            'Please modify current agemodel data to continue.\n']);
%@    %         % better choose to treat or it is not going to work
%@    %         choices={'Treat', 'Cancel'};
%@    %         choice=menu('Choose whether the agemodel should be treated',choices);
%@    %         sprintf('Do %s.', choices{choice})
%@    %         switch choice
%@    %             case 1 % modify/treat agemodel
%@    %                 choices{choice};
%@    %                 treat=true;
%@    %                 reversal=true;
%@    %  %               fprintf(fid_metadata,'Do %s. \n', choices{choice});
%@    %             case 2 % cancel everything
%@    %                 % stop if cancelled
%@    %                 finalagemodel = -1;
%@    %                 return
%@    %                 
%@    %         end
%@
%@    else % no reversal, start diagnosis/ exploration only if explicitly desired
%@        legend(h1, 'Agemodel with 2\sigma error bars','Location','SouthOutside')
%@        message = 'Good, consistent dating material. Monotonous age-depth relationships can be established.';
%@
%@    %         disp('Good, consistent dating material. Monotonous age-depth relationships can be established.');
%@    % %        fprintf(fid_metadata,['\n Good, consistent dating material. ',...
%@    % %            'Monotonous age-depth relationships can be established.\n']);
%@    %         choices={'Treat nevertheless', 'Use as is', 'Cancel'};
%@    %         choice=menu('Choose whether the agemodel should be treated',choices);
%@    %         sprintf('Do %s.', choices{choice})
%@    %         switch choice
%@    %             case 1 % modify/treat agemodel
%@    %                 choices{choice}
%@    %  %               fprintf(fid_metadata,['Do %s.', choices{choice},'\n']);
%@    %                 treat=true;
%@    %                 reversal=true;
%@    %             case 2 % use as is/ don't treat
%@    %                 choices{choice}
%@    % %                fprintf(fid_metadata,['Do %s.', choices{choice},'\n']);
%@    %                 treat=false;
%@    %                 reversal=false;
%@    %             case 3 % cancel everything
%@    %                 error('Cancel')
%@    %                 
%@    %         end
%@    end
%@    return
%@end
%@
%@
%@ 
%@   
%@    %%%%%%%%%%%%%%%%%%%%%% % end of treatment section, the rest is executed
%@    %%%%%%%%%%%%%%%%%%%%%% for ALL agemodels
%@    
%@    revType = chkRevs(d, filenameLog, guistring);
%@    if any(revType==2),
%@        disp('You HAVE to treat the agemodel since it has a non-tractable reversal!')
%@%        fprintf(fid_metadata,['You HAVE to treat the agemodel since ',...
%@%            'it has a non-tractable reversal!']);
%@        d.treat=true;
%@        reversal=true;
%@        
%@    else
%@        disp('OK, agemodel correct(ed)')
%@%        fprintf(fid_metadata,'OK, agemodel correct(ed)\n');
%@        d.treat=false;
%@        reversal=false;
%@    end
%@    
%@    closefigwithwarning(fig1,3)
%@
%@
%@
%@%% Save the (corrected) age model once it doesn't contain a non-tractable reversal anymore& it is treated
%@clear idx
%@finalagemodel=[d.depth d.age d.ageerror];
%@%finalagemodel = agemodel;
%@% save new age model to disk
%@% fid = fopen(['./output/',samplename,'_AgeModelCorrected.txt'],'w');
%@% fprintf(fid,'dist from top (mm)\t time (yr BP)\t std time (yr BP)\n');
%@% for m = 1:length(depth)
%@%     fprintf(fid,'%4.2f\t%4.4f\t%4.2f\n',agemodel(m,1), agemodel(m,2), agemodel(m,3));
%@% end
%@% fclose(fid);
%@% tmp = pwd;
%@% %fprintf(fid_metadata,['Corrected agemodel stored in file: ',tmp,...
%@% %    '/output/',samplename,'_AgeModelCorrected.txt\n\n']);
%@% clear tmp
%@
%@savelog(filenameLog,'finalagemodel','Corrected age model without reversals:')
%@
%@
%@
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/savelog.m__ -->
%@function err = savelog(filename, varname, incomment, flag)
%@% SAVELOG Save metadata as a M-file.
%@%     ERR = SAVELOG(FILENAME, VARNAME, COMMENT, FLAG) saves the content
%@%     of the variable VARNAME in a Matlab M-file in such a way that
%@%     it can be read in Matlab as script. COMMENT FLAG hast bo specified
%@%     as 'w' if a new file has to be created. Else a 
%@%        
%@%     Example:
%@%         a = 1;
%@%         savelog('test.m', 'a', flag)
%@
%@% check comment from input
%@if nargin >= 3
%@    if ischar(incomment)
%@        comment = incomment;
%@    else 
%@        comment = '';
%@    end
%@else
%@    comment = '';
%@end
%@
%@if isempty(filename)
%@    warning('No filename given. Skipped logging.')
%@    return
%@end
%@
%@% check the fopenflag from input
%@if nargin == 4
%@    fopenflag = flag;
%@else
%@    fopenflag = 'a';
%@end
%@
%@% check whether the input for fopenflag was really a char
%@if ~ischar(fopenflag), fopenflag = 'a'; end
%@% check whether the fopenflag is 'w' or 'a'
%@if ~(fopenflag == 'w' || fopenflag == 'a'), fopenflag = 'a'; end
%@
%@% open logfile
%@fid = fopen(filename,fopenflag);
%@fprintf(fid, '%s\n', ['% ',comment]);
%@
%@if ~isempty(varname)
%@    % get data from workspace
%@    data = evalin('caller',varname);
%@
%@    % convert data to string
%@    if size(data,1) == 1 && size(data,2) == 1 % scalar
%@        data_string = num2str(data);
%@        fprintf(fid, '%s;\n\n', [varname,' = ', data_string]);
%@    elseif (size(data,1) == 1 || size(data,2) == 1) && ~iscell(data) && ~ischar(data) % column/ raw vector
%@        data_string = mat2str(data);
%@        fprintf(fid, '%s;\n\n', [varname,' = ', data_string]);
%@    else % matrix
%@        if isnumeric(data) || ischar(data)
%@            fprintf(fid, '%s', [varname,' = [']);
%@        elseif iscell(data)
%@            fprintf(fid, '%s', [varname,' = {']);
%@        end
%@
%@        for i = 1:size(data,1)
%@            if isnumeric(data)
%@                data_string = num2str(data(i,:));
%@            elseif ischar(data)
%@                data_string = ['''',data(i,:),''''];
%@            elseif iscell(data)
%@                data_string = ['''',data{i},''''];
%@            end
%@            if size(data,1) > 1
%@                fprintf(fid, '%s;\n', data_string);
%@            else
%@                fprintf(fid, '%s', data_string);
%@            end
%@        end
%@        if isnumeric(data) || ischar(data)
%@            fprintf(fid, '%s\n\n', '];');
%@
%@        elseif iscell(data)
%@            fprintf(fid, '%s\n\n', '};');
%@        end
%@
%@    end
%@
%@end
%@
%@% close logfile
%@fclose(fid);
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/saveresults.m__ -->
%@function saveresults(d)
%@% SAVERESULTS Exports the age model and proxy records to a file.
%@
%@if ~d.gui
%@    samplename = d.samplename;
%@    interp_method = d.interp_method;
%@    
%@    prxy = d.T_cert(:,2);
%@    ptprstr = 'mean';
%@else
%@    if strcmpi(d.plotType_PR,'median') 
%@        prxy = d.T_cert(:,3);
%@        ptprstr = 'median';
%@    else
%@        prxy = d.T_cert(:,2);
%@        ptprstr = 'mean';
%@    end
%@end
%@
%@age = d.T_cert(:,1);
%@% age_error = d.T_cert(:,3)* d.confbnds_age;
%@% prxy_error = d.T_cert(:,4)* d.confbnds_prxy;
%@age_qu_lo = d.T_cert(:,4);
%@age_qu_up = d.T_cert(:,5);
%@prxy_qu_lo = d.T_cert(:,6);
%@prxy_qu_up = d.T_cert(:,7);
%@
%@time = d.T_unc(:,3); %
%@d_prxy = d.T_unc(:,1); % 
%@
%@% quantile values
%@qu_prxy_lo = 50 - d.confbnds_prxy/2;
%@qu_prxy_up = 50 + d.confbnds_prxy/2;
%@qu_age_lo = 50 - d.confbnds_age/2;
%@qu_age_up = 50 + d.confbnds_age/2;
%@
%@
%@%% check whether output folder exists (if not, create it)
%@if ~exist('./output','dir')
%@    mkdir('./output')
%@end
%@
%@if d.gui
%@    fid = fopen(d.full_path_EX_results,'w');
%@    if fid < 0 
%@        error('Could not open results file.')
%@    end
%@else
%@    fid = fopen(['output/',samplename,'_',interp_method,'_',date '.txt'],'w');
%@    if fid < 0 
%@        error('Could not open results file.')
%@    end
%@end
%@
%@%% Generate ouput file
%@% backslashes '\' have to be removed from the proxyname otherwise we can't
%@% use the string in the output file
%@clean_proxyname = strrep(d.proxyname,'\','');
%@
%@% write headerline
%@%output_header = sprintf('Age (yr BP)\t %s (%s)\t Age:%2.2g%%-Quantile\t Age%2.2g%%-Quantile\t Proxy:%2.2g%%-Quantile\t Proxy%2.2g%%-Quantile\t Depth from top (mm)\n',clean_proxyname,ptprstr,qu_age_lo,qu_age_up,qu_prxy_lo,qu_prxy_up);
%@fprintf(fid,'Age (yr BP)\t %s (%s)\t Age: %3.1f%%-Quantile\t Age: %3.1f%%-Quantile\t Proxy: %3.1f%%-Quantile\t Proxy: %3.1f%%-Quantile\t Depth from top (mm)\n',clean_proxyname,ptprstr,qu_age_lo,qu_age_up,qu_prxy_lo,qu_prxy_up);
%@%fprintf('\nAge:%2.2g%%-Quantile\n',qu_age_up)
%@
%@% write data
%@for i = 1:length(time(:,1))
%@    fprintf(fid,'%4.4f\t%4.4f\t%4.4f\t%4.4f\t%4.4f\t%4.4f\t%4.2f\n',age(i), prxy(i,1),...
%@        age_qu_lo(i),age_qu_up(i),prxy_qu_lo(i),prxy_qu_up(i),d_prxy(i));
%@end
%@   
%@    
%@fclose(fid);
%@
%@if ~d.gui
%@    %% save d
%@    save(['output/d_',samplename,'_',date],'d'); 
%@    %% Export meta-data
%@    disp('Meta-data export disabled.')
%@end
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/setdefaultbutton.m__ -->
%@function setdefaultbutton(figHandle, btnHandle)
%@% WARNING: This feature is not supported in MATLAB and the API and
%@% functionality may change in a future release.
%@
%@%SETDEFAULTBUTTON Set default button for a figure.
%@%  SETDEFAULTBUTTON(BTNHANDLE) sets the button passed in to be the default button
%@%  (the button and callback used when the user hits "enter" or "return"
%@%  when in a dialog box.
%@%
%@%  This function is used by inputdlg.m, msgbox.m, questdlg.m and
%@%  uigetpref.m.
%@%
%@%  Example:
%@%
%@%  f = figure;
%@%  b1 = uicontrol('style', 'pushbutton', 'string', 'first', ...
%@%       'position', [100 100 50 20]);
%@%  b2 = uicontrol('style', 'pushbutton', 'string', 'second', ...
%@%       'position', [200 100 50 20]);
%@%  b3 = uicontrol('style', 'pushbutton', 'string', 'third', ...
%@%       'position', [300 100 50 20]);
%@%  setdefaultbutton(b2);
%@%
%@
%@%  Copyright 2005-2007 The MathWorks, Inc.
%@
%@%--------------------------------------- NOTE ------------------------------------------
%@% This file was copied into matlab/toolbox/local/private.
%@% These two files should be kept in sync - when editing please make sure
%@% that *both* files are modified.
%@
%@% Nargin Check
%@if nargin<1, error('MATLAB:setdefaultbutton:InvalidNumberOfArguments','Too few arguments for setdefaultbutton'); end
%@if nargin>2, error('MATLAB:setdefaultbutton:InvalidNumberOfArguments','Too many arguments for setdefaultbutton'); end
%@
%@if (usejava('awt') == 1)
%@    % We are running with Java Figures
%@    useJavaDefaultButton(figHandle, btnHandle)
%@else
%@    % We are running with Native Figures
%@    useHGDefaultButton(figHandle, btnHandle);
%@end
%@
%@    function useJavaDefaultButton(figH, btnH)
%@        % Get a UDD handle for the figure.
%@        fh = handle(figH);
%@        % Call the setDefaultButton method on the figure handle
%@        fh.setDefaultButton(btnH);
%@    end
%@
%@    function useHGDefaultButton(figHandle, btnHandle)
%@        % First get the position of the button.
%@        btnPos = getpixelposition(btnHandle);
%@
%@        % Next calculate offsets.
%@        leftOffset   = btnPos(1) - 1;
%@        bottomOffset = btnPos(2) - 2;
%@        widthOffset  = btnPos(3) + 3;
%@        heightOffset = btnPos(4) + 3;
%@
%@        % Create the default button look with a uipanel.
%@        % Use black border color even on Mac or Windows-XP (XP scheme) since
%@        % this is in natve figures which uses the Win2K style buttons on Windows
%@        % and Motif buttons on the Mac.
%@        h1 = uipanel(get(btnHandle, 'Parent'), 'HighlightColor', 'black', ...
%@            'BorderType', 'etchedout', 'units', 'pixels', ...
%@            'Position', [leftOffset bottomOffset widthOffset heightOffset]);
%@
%@        % Make sure it is stacked on the bottom.
%@        uistack(h1, 'bottom');
%@    end
%@end
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/textscan2.m__ -->
%@## Copyright (C) 2010-2012 Ben Abbott <bpabbott@mac.com>
%@##
%@## This file is part of Octave.
%@##
%@## Octave is free software; you can redistribute it and/or modify it
%@## under the terms of the GNU General Public License as published by
%@## the Free Software Foundation; either version 3 of the License, or (at
%@## your option) any later version.
%@##
%@## Octave is distributed in the hope that it will be useful, but
%@## WITHOUT ANY WARRANTY; without even the implied warranty of
%@## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%@## General Public License for more details.
%@##
%@## You should have received a copy of the GNU General Public License
%@## along with Octave; see the file COPYING.  If not, see
%@## <http://www.gnu.org/licenses/>.
%@
%@## -*- texinfo -*-
%@## @deftypefn  {Function File} {@var{C} =} textscan (@var{fid}, @var{format})
%@## @deftypefnx {Function File} {@var{C} =} textscan (@var{fid}, @var{format}, @var{n})
%@## @deftypefnx {Function File} {@var{C} =} textscan (@var{fid}, @var{format}, @var{param}, @var{value}, @dots{})
%@## @deftypefnx {Function File} {@var{C} =} textscan (@var{fid}, @var{format}, @var{n}, @var{param}, @var{value}, @dots{})
%@## @deftypefnx {Function File} {@var{C} =} textscan (@var{str}, @dots{})
%@## @deftypefnx {Function File} {[@var{C}, @var{position}] =} textscan (@var{fid}, @dots{})
%@## Read data from a text file or string.
%@##
%@## The file associated with @var{fid} is read and parsed according to
%@## @var{format}.  The function behaves like @code{strread} except it works by
%@## parsing a file instead of a string.  See the documentation of
%@## @code{strread} for details.
%@##
%@## In addition to the options supported by
%@## @code{strread}, this function supports a few more:
%@##
%@## @itemize
%@## @item "collectoutput":
%@## A value of 1 or true instructs textscan to concatenate consecutive columns
%@## of the same class in the output cell array.  A value of 0 or false (default)
%@## leaves output in distinct columns.
%@##
%@## @item "endofline":
%@## Specify "\r", "\n" or "\r\n" (for CR, LF, or CRLF).  If no value is given,
%@## it will be inferred from the file.  If set to "" (empty string) EOLs are
%@## ignored as delimiters and added to whitespace.
%@##
%@## @item "headerlines":
%@## The first @var{value} number of lines of @var{fid} are skipped.
%@##
%@## @item "returnonerror":
%@## If set to numerical 1 or true (default), return normally when read errors
%@## have been encountered.  If set to 0 or false, return an error and no data.
%@## @end itemize
%@##
%@## The optional input @var{n} specifes the number of times to use
%@## @var{format} when parsing, i.e., the format repeat count.
%@##
%@## The output @var{C} is a cell array whose length is given by the number
%@## of format specifiers.
%@##
%@## The second output, @var{position}, provides the position, in characters,
%@## from the beginning of the file.
%@##
%@## @seealso{dlmread, fscanf, load, strread, textread}
%@## @end deftypefn
%@
%@function [C, position] = textscan2 (fid, format = "%f", varargin)
%@
%@  ## Check input
%@  if (nargin < 1)
%@    print_usage ();
%@  endif
%@
%@  if (isempty (format))
%@    format = "%f";
%@  endif
%@
%@  if (! (isa (fid, "double") && fid > 0) && ! ischar (fid))
%@    error ("textscan: first argument must be a file id or character string");
%@  endif
%@
%@  if (! ischar (format))
%@    error ("textscan: FORMAT must be a string");
%@  endif
%@
%@  args = varargin;
%@  if (nargin > 2 && isnumeric (args{1}))
%@    nlines = args{1};
%@  else
%@    nlines = Inf;
%@  endif
%@
%@  if (! any (strcmpi (args, "emptyvalue")))
%@    ## Matlab returns NaNs for missing values
%@    args(end+1:end+2) = {'emptyvalue', NaN};
%@  endif
%@
%@  ## Check default parameter values that differ for strread & textread
%@
%@  ipos = find (strcmpi (args, "whitespace"));
%@  if (isempty (ipos))
%@    ## Matlab default whitespace = " \b\t"
%@    args(end+1:end+2) = {'whitespace', " \b\t"};
%@    whitespace = " \b\t";
%@  else
%@    ## Check if there's at least one string format specifier
%@    fmt = strrep (format, "%", " %");
%@    fmt = regexp (fmt, '[^ ]+', 'match');
%@    fmt = strtrim (fmt(strmatch ("%", fmt)))
%@    has_str_fmt = all (cellfun ("isempty", strfind (strtrim (fmt(strmatch ("%", fmt))), 's')));
%@    ## If there is a format, AND whitespace value = empty,
%@    ## don't add a space (char(32)) to whitespace
%@    if (! (isempty (args{ipos+1}) &&  has_str_fmt))
%@      args{ipos+1} = unique ([" ", ipos+1]);
%@    endif
%@  endif
%@
%@  if (! any (strcmpi (args, "delimiter")))
%@    ## Matlab says default delimiter = whitespace.
%@    ## strread() will pick this up further
%@    args(end+1:end+2) = {'delimiter', ""};
%@  endif
%@
%@  collop = false;
%@  ipos = find (strcmpi (args, "collectoutput"));
%@  if (! isempty (ipos))
%@    ## Search & concatenate consecutive columns of same class requested
%@    if (isscalar (args{ipos+1})
%@        && (islogical (args{ipos+1}) || isnumeric (args{ipos+1})))
%@      collop = args{ipos+1};
%@    else
%@      warning ("textscan: illegal value for CollectOutput parameter - ignored");
%@    endif
%@    ## Remove argument before call to strread() below
%@    args(ipos:ipos+1) = [];
%@  endif
%@
%@  if (any (strcmpi (args, "returnonerror")))
%@    ## Because of the way strread() reads data (columnwise) this parameter
%@    ## can't be neatly implemented.  strread() will pick it up anyway
%@    warning ('textscan: ReturnOnError is not fully implemented');
%@  else
%@    ## Set default value (=true)
%@    args(end+1:end+2) = {"returnonerror", 1};
%@  endif
%@
%@  if (ischar (fid))
%@    ## Read from a text string
%@    if (nargout == 2)
%@      error ("textscan: cannot provide position information for character input");
%@    endif
%@    str = fid;
%@  else
%@    ## Skip header lines if requested
%@    headerlines = find (strcmpi (args, "headerlines"), 1);
%@    ## Beware of zero valued headerline, fskipl would skip to EOF
%@    if (! isempty (headerlines) && (args{headerlines + 1} > 0))
%@      fskipl (fid, varargin{headerlines + 1});
%@      args(headerlines:headerlines+1) = [];
%@    endif
%@    if (isfinite (nlines) && (nlines >= 0))
%@      str = tmp_str = "";
%@      n = 0;
%@      ## FIXME: Can this be done without slow loop?
%@      while (ischar (tmp_str) && n++ < nlines)
%@        tmp_str = fgets (fid);
%@        if (ischar (tmp_str))
%@          str = strcat (str, tmp_str);
%@        endif
%@      endwhile
%@    else
%@      str = fread (fid, "char=>char").';
%@    endif
%@  endif
%@
%@  ## Check for empty result
%@  if (isempty (str))
%@    warning ("textscan: no data read");
%@    C = [];
%@    return;
%@  endif
%@
%@  ## Check value of 'endofline'.  String or file doesn't seem to matter
%@  endofline = find (strcmpi (args, "endofline"), 1);
%@  if (! isempty (endofline))
%@    if (ischar (args{endofline + 1}))
%@      eol_char = args{endofline + 1};
%@      if (isempty (strmatch (eol_char, {"", "\n", "\r", "\r\n"}, 'exact')))
%@        error ("textscan: illegal EndOfLine character value specified");
%@      endif
%@    else
%@      error ("textscan: character value required for EndOfLine");
%@    endif
%@  else
%@    ## Determine EOL from file.  Search for EOL candidates in first 3000 chars
%@    eol_srch_len = min (length (str), 3000);
%@    ## First try DOS (CRLF)
%@    if (! isempty (findstr ("\r\n", str(1 : eol_srch_len))))
%@      eol_char = "\r\n";
%@    ## Perhaps old Macintosh? (CR)
%@    elseif (! isempty (findstr ("\r", str(1 : eol_srch_len))))
%@      eol_char = "\r";
%@    ## Otherwise, use plain UNIX (LF)
%@    else
%@      eol_char = "\n";
%@    endif
%@    ## Set up the default endofline param value
%@    args(end+1:end+2) = {'endofline', eol_char};
%@  endif
%@
%@  ## Determine the number of data fields
%@  num_fields = numel (strfind (format, "%")) - numel (strfind (format, "%*"));
%@
%@  ## Strip trailing EOL to avoid returning stray missing values (f. strread)
%@  if (strcmp (str(end-length (eol_char) + 1 : end), eol_char));
%@    str(end-length (eol_char) + 1 : end) = "";
%@  endif
%@
%@  ## Call strread to make it do the real work
%@  C = cell (1, num_fields);
%@  [C{:}] = strread (str, format, args{:});
%@
%@  ## If requested, collect output columns of same class
%@  if (collop)
%@    C = colloutp (C);
%@  endif
%@
%@  if (nargout == 2)
%@    position = ftell (fid);
%@  endif
%@
%@endfunction
%@
%@
%@## Collect consecutive columns of same class into one cell column
%@function C = colloutp (C)
%@
%@  ## Start at rightmost column and work backwards to avoid ptr mixup
%@  ii = numel (C);
%@  while ii > 1
%@    clss1 = class (C{ii});
%@    jj = ii;
%@    while  (jj > 1 && strcmp (clss1, class (C{jj - 1})))
%@      ## Column to the left is still same class; check next column to the left
%@      --jj;
%@    endwhile
%@    if (jj < ii)
%@      ## Concatenate columns into current column
%@      C{jj} = [C{jj : ii}];
%@      ## Wipe concatenated columns to the right, resume search to the left
%@      C(jj+1 : ii) = [];
%@      ii = jj - 1;
%@    else
%@      ## No similar class in column to the left, search from there
%@      --ii;
%@    endif
%@  endwhile
%@
%@endfunction
%@
%@%!test
%@%! str = "1,  2,  3,  4\n 5,  ,  ,  8\n 9, 10, 11, 12";
%@%! fmtstr = "%f %d %f %s";
%@%! c = textscan (str, fmtstr, 2, "delimiter", ",", "emptyvalue", -Inf);
%@%! assert (isequal (c{1}, [1;5]));
%@%! assert (length (c{1}), 2);
%@%! assert (iscellstr (c{4}));
%@%! assert (isequal (c{3}, [3; -Inf]));
%@
%@%!test
%@%! b = [10:10:100];
%@%! b = [b; 8*b/5];
%@%! str = sprintf ("%g miles/hr = %g kilometers/hr\n", b);
%@%! fmt = "%f miles/hr = %f kilometers/hr";
%@%! c = textscan (str, fmt);
%@%! assert (b(1,:)', c{1}, 1e-5);
%@%! assert (b(2,:)', c{2}, 1e-5);
%@
%@#%!test
%@#%! str = "13, 72, NA, str1, 25\r\n// Middle line\r\n36, na, 05, str3, 6";
%@#%! a = textscan(str, '%d %n %f %s %n', 'delimiter', ',','treatAsEmpty', {'NA', 'na'},'commentStyle', '//');
%@#%! assert (a{1}, int32([13; 36]));
%@#%! assert (a{2}, [72; NaN]);
%@#%! assert (a{3}, [NaN; 5]);
%@#%! assert (a{4}, {"str1"; "str3"});
%@#%! assert (a{5}, [25; 6]);
%@
%@%!test
%@%! str = "Km:10 = hhhBjjj miles16hour\r\n";
%@%! str = [str "Km:15 = hhhJjjj miles241hour\r\n"];
%@%! str = [str "Km:2 = hhhRjjj miles3hour\r\n"];
%@%! str = [str "Km:25 = hhhZ\r\n"];
%@%! fmt = "Km:%d = hhh%1sjjj miles%dhour";
%@%! a = textscan (str, fmt, 'delimiter', ' ');
%@%! assert (a{1}', int32([10 15 2 25]));
%@%! assert (a{2}', {'B' 'J' 'R' 'Z'});
%@%! assert (a{3}', int32([16 241 3 0]));
%@
%@%% Test with default endofline parameter
%@%!test
%@%! c = textscan ("L1\nL2", "%s");
%@%! assert (c{:}, {"L1"; "L2"});
%@
%@%% Test with endofline parameter set to '' (empty) - newline should be in word
%@%!test
%@%! c = textscan ("L1\nL2", "%s", 'endofline', '');
%@%! assert (int8(c{:}{:}), int8([ 76,  49,  10,  76,  50 ]));
%@
%@%!test
%@%! # No delimiters at all besides EOL.  Skip fields, even empty fields
%@%! str = "Text1Text2Text\nTextText4Text\nText57Text";
%@%! c = textscan (str, "Text%*dText%dText");
%@%! assert (c{1}, int32 ([2; 4; 0]));
%@
%@%!test
%@%% CollectOutput test
%@%! b = [10:10:100];
%@%! b = [b; 8*b/5; 8*b*1000/5];
%@%! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b);
%@%! fmt = "%f miles%s %s %f (%f) kilometers %*s";
%@%! c = textscan (str, fmt, 'collectoutput', 1);
%@%! assert (size(c{3}), [10, 2]);
%@%! assert (size(c{2}), [10, 2]);
%@
%@%% Test input validation
%@%!error textscan ()
%@%!error textscan (single (4))
%@%!error textscan ({4})
%@%!error <must be a string> textscan ("Hello World", 2)
%@%!error <cannot provide position information> [C, pos] = textscan ("Hello World")
%@%!error <character value required> textscan ("Hello World", '%s', 'EndOfLine', 3)
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/treathiatus_cl.m__ -->
%@function d = treathiatus_cl(d)
%@% TREATHIATUS_CL Treat growth interruptions in paleoarchives.
%@%   TREATHIATUS_CL(D) gives the user the option
%@%   to split the agemodel at the hiatus position D.HIA_IDX bzw. D.HIATUS and,
%@%   if necessary, also modifies the final age model, e.g. by increasing error
%@%   margins or by removing points.
%@
%@depth = d.depth;
%@age = d.age;
%@ageerror = d.ageerror;
%@age_e_tmp = ageerror;
%@a_input = age;
%@hiatus=d.hiatus;
%@hia_id=find(hiatus>eps);
%@hia_id(end)=[];
%@hia_idx=[hia_id [hia_id+1]]
%@
%@
%@if length(hiatus) ~= length(age)
%@    hiatus = zeros(length(age),1);
%@    hiatus(end) = 1;
%@end
%@rem_hia_trt = zeros(size(age)); % records treatment for points
%@
%@for i = 1:size(hia_idx,1)
%@    % matlab: ' instead of  " characters not valid in statements/ expressions
%@    strcat('Treating hiatus after dating point ',char(' '), int2str(d.id(hia_idx(i))))
%@    treat = true;
%@    while treat
%@        
%@        % treat this point! Ask user, how
%@        treatm={'Split the simulation','Remove point',...
%@            'Increase error','Use as is','Cancel (Exits entire program!)'};
%@        choice=menu('Choose how the hiatus should be treated','Split the simulation','Remove point','Increase error','Use as is','Cancel (Exits entire program!)');
%@        sprintf('%s for this point', treatm{choice})
%@        c = 0;
%@        switch choice
%@            
%@            case 1 % split the simulation
%@                disp(treatm{choice})
%@                hiatus(hia_idx(i,1)) = 1;
%@                treat = false;
%@            case 2 % remove the point
%@                disp(treatm{choice})
%@                rmv_pt = true;
%@                while rmv_pt
%@                    %%%%%%%%%%%%%%%%%%%%% Question dialogue %%%%%%%%%%%%%%%
%@                    reply=input('Which point do you want to remove? [none]');
%@                    if isempty(reply)
%@                        rmv_pt=false;
%@                        continue % exit the while loop
%@                    else % if the indicated pt's index is in the valid range
%@                        if isnumeric(reply)
%@                        idx=reply;
%@                        error(nargchk(1,length(hiatus),idx))
%@                        else
%@                            disp('Please indicate a point in the range')
%@                        end
%@                    end
%@                    %%%%%%%%%%%%%%%%%%%%% Question dialogue %%%%%%%%%%%%%%%
%@
%@
%@                    if rem_hia_trt(idx) == 1
%@                        %%%h = warndlg('Point already removed!',...
%@                        %%%    'Warning: Treat hiatus');
%@                        %%%waitfor(h);
%@			            disp('Warning: Point already removed!');
%@                        continue
%@                    elseif rem_hia_trt(idx) == 2
%@                        %%%h = questdlg(['Errorbars already increased! ',...
%@                        %%%    'Do you want to proceed?'],...
%@                        %%%    'Warning: Treat Hiatus','Yes (Click again)',...
%@                        %%%    'No','Yes (Click again)');
%@		                h = menu('Errorbars already increased! Do you want to proceed?', 'Yes', 'No');
%@                        switch h
%@                            %%%case 'Yes (Click again)'
%@			    case 1
%@                                rem_hia_trt(idx) = 3;
%@                                continue
%@                            %%%case 'No'
%@			    case 2
%@                                continue
%@                        end
%@                    elseif rem_hia_trt(idx) == 0 || rem_hia_trt(idx) == 3
%@                        rem_hia_trt(idx)=1;
%@                        removePts=(rem_hia_trt==1);
%@                        % Further options after removing a point --->
%@                        % The user can choose to: remove more point(s);
%@                        % Undo the last removal; move to a different
%@                        % treatment; or proceed with the current treatment
%@                        choices={'Remove another point',...
%@                            'Undo/change last point removal',...
%@                            'Add a different treatment to this one',...
%@                            'Proceed to Age Model construction',...
%@                            'Exit Program'};
%@                        %%%choice2 = menu('What do you wish to do next?',...
%@                           %%% choices);
%@choice2 = menu('What do you wish to do next?',...
%@'Remove another point',...
%@'Undo/change last point removal',...
%@'Add a different treatment to this one',...
%@'Proceed to Age Model construction',...
%@'Exit Program');
%@                        sprintf('%s for this point', choices{choice2})
%@                        switch choice2
%@                            case 1 % Remove another point
%@                                continue
%@                            case 2 % Undo/change last removal
%@                                rem_hia_trt(idx)=0;
%@                                delete(hnew)
%@                                legend('off')
%@                                continue
%@                            case 3 % move to a diff. treatment after this
%@                                rmv_pt = false;
%@                            case 4 % proceed to age model construction
%@                                depth(removePts)=[]
%@                                age(removePts)=[];
%@                                ageerror(removePts)=[];
%@                                finalagemodel = [depth age ageerror];
%@                                treat = false;
%@                                rmv_pt = false;
%@                            case 5 % cancel everything and exit program
%@                                error('Cancel')
%@                        end
%@                    end
%@                end
%@                
%@            case 3 % increase of the error bars for pt
%@                disp(treatm{choice})
%@                increase_errorbar = true;
%@                while increase_errorbar
%@%                     title(['Click on the point you wish to ',...
%@%                         'increase error for'],'fontweight','bold')
%@%                     a = ginput(1); % select point with left-click
%@%                     if isempty(a)
%@%                         break
%@%                     end
%@%                     %calculate distance between input and data
%@%                     xd=a(1)-age;
%@%                     yd=a(2)-depth;
%@%                     dist=sqrt(xd.^2+yd.^2);
%@%                     b=[];% dummy to avoid tilde in next step
%@%                     [b,idx]=min(dist); % idx := index of the nearest point
%@%                     clear b
%@                %%%%%%%%%%%%%%%%%%%%% Question dialogue %%%%%%%%%%%%%%%
%@                    reply=input('Which point do you want to increase the error bar for (give index)? [none]: ');
%@                    if isempty(reply)
%@                        increase_errorbar=false;
%@                        continue % exit the while loop
%@                    else % if the indicated pt's index is in the valid range
%@                        if isnumeric(reply)
%@                        idx=reply;
%@                        error(nargchk(1,length(hiatus),idx))
%@                        end
%@                    end
%@                    %%%%%%%%%%%%%%%%%%%%% Question dialogue %%%%%%%%%%%%%%%
%@
%@
%@                    
%@                    if rem_hia_trt(idx) == 1
%@                        %%%h = warndlg('Point already removed!',...
%@                        %%%    'Warning: Treat hiatus');
%@                        %%% waitfor(h);
%@			            disp('Warning: Point already removed!')
%@                        continue
%@                    elseif rem_hia_trt(idx) == 2
%@                        %%% h = questdlg(['Errorbars already increased! ',...
%@                        %%%    'Do you want to proceed?'],...
%@                        %%%    'Warning: Treat Hiatus','Yes (Click again)',...
%@                        %%%    'No','Yes (Click again)');
%@			            h = menu('Errorbars already increased! Do you want to proceed?', 'Yes', 'No')
%@                        switch h
%@                            case 1
%@                                rem_hia_trt(idx) = 3;
%@                                continue
%@                            case 2
%@                                continue
%@                        end
%@                    elseif rem_hia_trt(idx) == 0 || rem_hia_trt(idx) == 3
%@                        rem_hia_trt(idx)=2;
%@                        incErr=(rem_hia_trt==2);
%@                        
%@                        increase=true;
%@                        pts = []; ebs = [];
%@                        while increase
%@                            display('Increase errorbar size by 10%');
%@                            age_e_tmp(incErr)=age_e_tmp(incErr)*1.1;
%@                            [pts,ebs] = errorbarxy(age(incErr),...
%@                                depth(incErr),age_e_tmp(incErr),...
%@                                [], 'linestyle', 'none');
%@                            % choice = questdlg('What to do now?','Options - increase error bars', 'Increase further','Finish');
%@                            choice2 = menu('Options: Increase error bars',...
%@                                'Increase', 'Finish');
%@                            % Handle response
%@                            switch choice2
%@                                case 1
%@                                    disp([choice2 ' the error bars'])
%@                                    delete(pts),delete(ebs)
%@                                    continue
%@                                case 2
%@                                    disp('Finish increasing error')
%@                                    increase=false;
%@                            end
%@                        end
%@                        
%@                        % Further options after increasing error once --->
%@                        % The user can choose to: remove more point(s);
%@                        % Undo the last removal; move to a different
%@                        % treatment; or proceed with the current treatment
%@                        choices={'Increase error for another point',...
%@                            'Undo increase error for last point',...
%@                            'Add a different treatment to this one',...
%@                            'Proceed to Age Model construction',...
%@                            'Exit Program'};
%@                        %%%choice2=menu('What do you wish to do next?',choices);
%@choice2=menu('What do you wish to do next?',...
%@'Increase error for another point',...
%@'Undo increase error for last point',...
%@'Add a different treatment to this one',...
%@'Proceed to Age Model construction',...
%@'Exit Program');
%@                        disp(sprintf('%s for this point', choices{choice2}))
%@                        switch choice2
%@                            case 1 % Increase error for another point
%@                                continue
%@                            case 2 % Undo error increase for last point
%@                                delete(hnew),delete(pts),delete(ebs)
%@                                legend('off')
%@                                age_e_tmp(incErr)=ageerror(incErr);
%@                                rem_hia_trt(rem_hia_trt==2) = 0;
%@                                continue
%@                            case 3 % move to a diff. treatment after this
%@                                increase_errorbar = false;
%@                            case 4 % proceed to age model construction
%@                                finalagemodel = [depth age age_e_tmp];
%@                                treat = false;
%@                                increase_errorbar = false;
%@                            case 5 % cancel everything and exit program
%@                                error('Cancel')
%@                        end
%@                    end
%@                    
%@                end
%@                
%@            case 4 % do nothing with this hiatus
%@                treat = false;
%@            case 5 % cancel and exit program
%@                error('Cancel')
%@        end
%@    end
%@    % end while loop for hiatus treatment
%@end
%@
%@ptsremoved = setdiff(a_input,age);
%@if ~isempty(ptsremoved)
%@    hiatus(a_input==ptsremoved) = [];
%@    d.id(a_input==ptsremoved)=[];
%@end
%@d.hiatus = hiatus;
%@hiatus
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __private/uicomponent.m__ -->
%@function [hcomponent,jcomp] = uicomponent(varargin)
%@%UICOMPONENT an enhanced replacement for UICONTROL & JAVACOMPONENT, accepting all Java Swing/AWT style components
%@%
%@%   hcomponent = UICOMPONENT('PropertyName1',value1,'PropertyName2',value2,...) 
%@%   creates a user interface control in the current figure window and returns
%@%   a handle to it. It assigns the default values to any properties you do not
%@%   specify. The default style, like in UICONTROL, is a pushbutton. 
%@%
%@%   UICOMPONENT(parent,...) creates a control in the specified parent handle
%@%   (figure, frame, uipanel, uicontainer, uiflowcontainer or uigridcontainer).
%@%   This is equivalent to UICOMPONENT('Parent',parent,...).
%@%   Note the extension to JAVACOMPONENT, which only accepts figure parents.
%@%   Actually, (due to internal Matlab limitations) the component is always
%@%   created as a child of the figure - the parent is used as a reference
%@%   location for the component's position (relative to the parent).
%@%
%@%   UICOMPONENT(javacomponent,...) uses the pre-existing javacomponent, and
%@%   just places it on-screen and returns a single handle.
%@%
%@%   UICOMPONENT properties can be set at object creation time using
%@%   PropertyName/PropertyValue pair arguments to UICOMPONENT, or 
%@%   changed later using the SET command or handle.prop=value notation.
%@%
%@%   Execute GET(H) to see a list of UICOMPONENT object properties and
%@%   their current values. Execute SET(H) to see a list of UICOMPONENT
%@%   object properties and legal property values. See the
%@%   <a href="matlab:doc uicontrol_props">Uicontrol Properties reference page</a> for more information.
%@%
%@%   UICOMPONENT(H) gives focus to the component specified by the handle H.
%@%   This enables keyboard actions on the selected component, in addition
%@%   to the regular mouse actions.
%@%
%@%   UICOMPONENT is intended as a direct replacement of Matlab's builtin
%@%   UICONTROL and JAVACOMPONENT functions. It accepts all parameters and
%@%   styles that UICONTROL accepts, and in addition also any other presentable 
%@%   <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html">Java Swing/AWT component</a>.
%@%   The calling convention and syntax of UICONTROL were preserved for full
%@%   backwards compatibility.
%@%
%@%   UICOMPONENT('Style',style,{optionalConstructorArgs},...) uses the
%@%   requested style, which includes all of UICONTROL's styles as well as
%@%   any java component (see below). Optional java constructor args may be
%@%   passed to the style upon creation - multiple args as well as a string
%@%   arg should be placed in a cell-array, in order to differentiate them
%@%   from the following PropertyName. In most cases, properties may be 
%@%   modified post-creation, and need not be passed to the constructor.
%@%
%@%   UICONTROL's accepted 'Style' values (case insensitive):
%@%      'pushbutton','togglebutton','radiobutton','checkbox','edit'
%@%      'text','slider','frame','listbox','popupmenu'
%@%
%@%   UICOMPONENT's additional accepted 'Style' values (partial list):
%@%      1) <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/package-summary.html">java.awt.*</a> objects:
%@%         'scrollbar','textcomponent','textarea','textfield','label',
%@%         'list','choice','canvas','container','button','panel',
%@%         'scrollpane','window','dialog','frame','filedialog'
%@%      2) <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/package-summary.html">javax.swing.*</a> objects:
%@%         'CellRendererPane','JComponent','JApplet','JWindow','JDialog',
%@%         'AbstractButton','BasicInternalFrameTitlePane','Box','Box.Filler',
%@%         'JColorChooser','JComboBox','JFileChooser','JInternalFrame',
%@%         'JInternalFrame.JDesktopIcon','JLabel','JLayeredPane','JList',
%@%         'JMenuBar','JOptionPane','JPanel','JPopupMenu','JProgressBar',
%@%         'JRootPane','JScrollBar','JScrollPane','JScrollPane.ScrollBar',
%@%         'JSeparator','JSlider','JSpinner','JSplitPane','JTabbedPane',
%@%         'JTable','JTableHeader','JTextComponent','JToolBar','JToolTip',
%@%         'JTree','JViewport','JButton','JToggleButton','JMenuItem',
%@%         'JCheckBoxMenuItem','JMenu','JRadioButtonMenuItem','JCheckBox',
%@%         'JRadioButton','JDesktopPane','JPopupMenu.Separator','JToolBar.Separator',
%@%         'JEditorPane','JTextArea','JTextField','JTextPane',
%@%         'JFormattedTextField','JPasswordField'
%@%      3) Any fully-qualified class name: 'javax.swing.JSlider','com.mywork.MyClass'...
%@%
%@%   Examples:
%@%      Example 1: (uses regular UICONTROL)
%@%           %creates uicontrol specified in a new figure
%@%           uicomponent('Style','edit','String','hello'); 
%@%     
%@%      Example 2: (uses regular UICONTROL)
%@%           %creates three figures and only puts uicontrol in the second figure
%@%           fig1 = figure;
%@%           fig2 = figure;
%@%           fig3 = figure;
%@%           uicomponent('Parent', fig2, 'Style', 'edit','String','hello');
%@%
%@%      More Examples: (uses UICOMPONENT's additional styles):
%@%           uicomponent('style','jspinner','value',7);  % simple spinner with initial value
%@%           uicomponent('style','javax.swing.jslider','tag','myObj');  % simple horizontal slider
%@%           uicomponent('style','slider', 'position',[50,50,60,150], 'value',70, ...
%@%                       'MajorTickSpacing',20, 'MinorTickSpacing',5, ...
%@%                       'Paintlabels',1,'PaintTicks',1, 'Orientation',1);  % vertical slider
%@%
%@%           h=uicomponent('style','JComboBox',{1,pi,'text'},'editable',true); % editable drop-down
%@%           h.javaComponent.addItem('text2');  % adding data to the drop-down post-creation
%@%           h.ActionPerformedCallback = @myMatlabFunction;  % setting a callback
%@%           uicomponent(h);  % sets the focus to component h (enabled keyboard actions)
%@%           string = h.JavaComponent.getSelectedItem;  % get the currently selected item
%@%           string = get(h,'selecteditem');  % equivalent way to do the same thing
%@%           string = h.sElEcTeDiTeM;  % ...a 3rd way to do the same (note case insensitivity)
%@%
%@%   Callbacks:
%@%     Over 30 callback hooks are exposed to the user (the exact list depends on the selected
%@%     style). These callbacks include mouse movement/clicks, keyboard events, focus gain/loss,
%@%     data changes etc. In most cases, the user would be concerned mainly with the
%@%     'StateChangedCallback', which is triggered whenever some property of the component has
%@%     changed (position, value etc.). In some cases, 'StateChangedCallback' is unavailable
%@%     and the user should use alternative callbacks, like 'ActionPerformedCallback'. Type
%@%     'set(hcomponent)' for the full list of callbacks supported by your specific hcomponent.
%@%
%@%   Programming tips:
%@%     1) Unless UICONTROL is used, the returned hcomponent contains 2 useful properties:
%@%        - JavaComponent - a reference to the created java component.
%@%        - MatlabHGContainer - the numeric handle h to the Matlab HG container. This is the
%@%          value returned by the findall/finobj matlab functions. You can still get/set all the
%@%          component properties using this numeric handle, but they'd be hidden unless you use
%@%          handle(h) or hcomponent, which is the same thing.
%@%     2) JAVACOMPONENT normally sets the container's UserData property to the classname of the
%@%        component (a string). This UICOMPONENT sets UserData to a reference to hcomponent, to
%@%        make it easy for novice users to see all properties without using handle().
%@%     3) The user is referred to <a href="http://java.sun.com/docs/books/tutorial/uiswing/index.html">Sun's official Swing Tutorial</a>
%@%
%@%   Warning:
%@%     This code heavily relies on undocumented and unsupported Matlab functionality.
%@%     It works on Matlab 7+, but use at your own risk!
%@%
%@%   Bugs and suggestions:
%@%     Please send to Yair Altman (altmany at gmail dot com)
%@%
%@%   Change log:
%@%     2007-Apr-10: First version posted on MathWorks file exchange: <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14583">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14583</a>
%@%     2007-Apr-12: Set large initial size for *Chooser classes; fixed Window subclasses issue; fixed help comment; enabled non-figure parent; enabled non-cell ctorArgs; set default Tag prop
%@%     2007-May-18: Handle pre-existing java components
%@%     2007-Jul-19: Handle shortened property names per suggestion by H. Marx
%@%     2014-Oct-10: Fixed for R2014b (HG2)
%@%     2014-Oct-20: Fixed a bug in setting the JavaComponent field
%@%
%@%   See also:
%@%     uicontrol, javacomponent, java, set, get, FINDJOBJ (on the <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14317">file exchange</a>)
%@
%@% License to use and modify this code is granted freely without warranty to all, as long as the original author is
%@% referenced and attributed as such. The original author maintains the right to be solely associated with this work.
%@
%@% Programmed and Copyright by Yair M. Altman: altmany(at)gmail.com
%@% $Revision: 1.5 $  $Date: 2014/10/20 16:28:49 $
%@
%@    % First, try to use uicontrol directly
%@    try
%@        hcomp = uicontrol(varargin{:});
%@    catch
%@        % Ensure that javacomponent is supported on this platform...
%@        error(javachk('awt'));
%@        %if ~usejavacomponent, error('YMA:uicomponent:Unsupported','UICOMPONENT is not supported on this platform'); end
%@
%@        % Check for focus-request
%@        if nargin==1
%@            try
%@                % Request the focus for the supplied component's java peer
%@                hcomp = varargin{1};
%@                hcomp.JavaComponent.requestFocus;
%@
%@                % Succeeded, so exit
%@                hcomponent = hcomp;
%@                return;
%@            catch
%@                error('YMA:uicomponent:IllegalComponent','In uicomponent(h), h must be a handle returned by uicomponent or uicontrol');
%@            end
%@        end
%@
%@        % Parse argnames/values
%@        [parent,pvPairs] = parseparams(varargin);
%@
%@        % Check for pre-existing javaComp
%@        isJavaObj = ~isempty(parent) && isjava(parent{1}(1));
%@        if isJavaObj
%@            javaComp = parent{1}(1);
%@            parent = [];
%@        end
%@
%@        % Get the requested component style, position & parent
%@        [pvPairs,style,ctorArgs]  = getStyle   (pvPairs);
%@        [pvPairs,position]        = getPosition(pvPairs,style);
%@        [pvPairs,position,parent] = getParent  (pvPairs,position,parent);
%@
%@        % Try to create the java component (if not pre-existing)
%@        if ~isJavaObj
%@            try
%@                % Note: feval is WAY faster than awtinvoke, so use feval whenever possible
%@                %javaComp = awtcreate(style);
%@                javaComp = feval(style,ctorArgs{:});
%@            catch
%@                % Maybe user didn't enclose ctorArgs with {}...
%@                javaComp = feval(style,ctorArgs);
%@            end
%@        end
%@
%@        % Place the new component on-screen (invisible until we finish processing - prevents animation)
%@        if ~isa(javaComp,'java.awt.Window')
%@            [jcomp, hcontainer] = javacomponent(javaComp,position,parent);
%@        else
%@            % Workaround for javacomponent's bug with java.awt.Window and sub-classes...
%@            [jcomp, hcontainer] = javacomponentFix(javaComp,position,parent);
%@        end
%@        set(hcontainer,'Visible','off');
%@
%@        % Note: Use the undocumented handle() to get the handle of the component's Matlab container
%@        % ^^^^  This is needed in order to add all of the java component's properties, below
%@        hcomp = handle(hcontainer);
%@
%@        % Move all the container's properties to the component
%@        try curUndoc = get(0,'hideundocumented'); set(0,'hideundocumented','off'); catch, end  % no-go on HG2...
%@        % Note: sometimes dataStruct does NOT contain all java values, so a very short pause is needed
%@        %pause(0.003);  % not needed now that we use localGetData
%@        dataStruct = get(jcomp);
%@        try set(0,'hideundocumented',curUndoc); catch, end  % no-go on HG2...
%@        fieldNames = fieldnames(dataStruct);
%@        for fieldIdx = 1 : length(fieldNames)
%@
%@            % Add this container field to the component
%@            thisFieldName = fieldNames{fieldIdx};
%@            try
%@                jsp = findprop(jcomp,thisFieldName);
%@                try
%@                    % HG1 - R2014a or earlier
%@                    msp = schema.prop(hcomp,thisFieldName,'mxArray');  %jsp.DataType
%@
%@                    % Note: sometimes dataStruct still does NOT contain all java values, so get them directly
%@                    % Note2: unused for now: we use localGetData instead
%@                    %{
%@                    if isempty(dataStruct.(thisFieldName)) && isempty(strfind(thisFieldName,'Callback'))
%@                        if ~isequal(dataStruct.(thisFieldName),get(jcomp,thisFieldName))
%@                            pause(0.001);  %should usually suffice
%@                            %disp(thisFieldName);
%@                            dataStruct.(thisFieldName) = get(jcomp,thisFieldName);
%@                        end
%@                    end
%@                    set(hcomp,thisFieldName,dataStruct.(thisFieldName));
%@                    %}
%@
%@                    % Set the public accessability flags like in the Java original
%@                    msp.AccessFlags.PublicGet = jsp.AccessFlags.PublicGet;
%@                    msp.AccessFlags.PublicSet = jsp.AccessFlags.PublicSet;
%@                    msp.GetFunction = {@localGetData,jcomp,thisFieldName};
%@                    msp.SetFunction = {@localSetData,jcomp,thisFieldName};
%@                    msp.Visible = jsp.Visible;
%@                catch
%@                    % HG2 - R2014b or newer
%@                    msp = addprop(hcomp,thisFieldName);
%@                    if ~jsp.AccessFlags.PublicGet,  msp.GetAccess = 'private';  end
%@                    if ~jsp.AccessFlags.PublicSet,  msp.SetAccess = 'private';  end
%@                    msp.GetMethod = @(h)  localGetData(h,[],jcomp,thisFieldName);
%@                    msp.SetMethod = @(h,v)localSetData(h,v, jcomp,thisFieldName);
%@                    if strcmpi(jsp.Visible,'off'),  msp.Hidden = true;  end
%@                end
%@            catch
%@                % Never mind: property probably already exists...
%@                %disp([thisFieldName ': ' lasterr]);
%@            end
%@
%@            % Link the new props between the two handles
%@            % Note: unused for now: we use localGet/SetData instead
%@            %{
%@            try
%@                % Note: can't use linkprop since jcomp goes out of scope soon and linkprop then deletes all linkages...
%@                linkprops([hcomp,jcomp],thisFieldName);
%@            catch
%@                % Never mind: probably cannot modify this prop
%@            end
%@            %}
%@        end
%@
%@        % Synchronize all props upon state change
%@        % Note: unused for now: we use localGet/SetData instead
%@        %setupChangeCallback(hcomp,jcomp);
%@
%@        % Store the container & component's handles in the component
%@        storeHandles(hcomp,jcomp,hcontainer);
%@
%@        % Process the remainder of the user-supplied args (PV-pairs)
%@        if ~isempty(pvPairs)
%@            try
%@                set(hcomp,pvPairs{:});
%@            catch
%@                set(jcomp,pvPairs{:});  % HG2 - should not be needed!!! all java props should be in hcomp!
%@            end
%@        end
%@
%@        % Display the component on-screen, unless user requested a specific visibility
%@        visIdx = find(strncmpi(pvPairs,'vis',3), 1);
%@        if isempty(visIdx)
%@            set(hcomp,'Visible','on');
%@        end
%@        if isa(javaComp,'java.awt.Window') && strcmpi(hcomp.Visible,'on')
%@            jcomp.validate();
%@            jcomp.show();
%@        end
%@    end
%@
%@    % Refresh the screen
%@    drawnow;
%@
%@    % Return the component handle, if requested
%@    if nargout
%@        hcomponent = hcomp;
%@    end
%@end
%@
%@%% Get the java class from the classname (case-insensitive)
%@function javaClass = getJavaClass(className)
%@    % First get the class-loader fired-up
%@    try
%@        jloader = com.mathworks.jmi.ClassLoaderManager.getClassLoaderManager;
%@    catch
%@        error('YMA:uicomponent:ClassLoaderNotFound', 'Failed to get a valid Java ClassLoader');
%@    end
%@
%@    % First try finding the class without any changes in java.awt or javax.swing
%@    javaClass = findAwtSwingClass(jloader, className);
%@
%@    % If unfound, try fixing the className's case and retry
%@    if isempty(javaClass)
%@        javaClass = findAwtSwingClass(jloader, fixClassNameCase(className));
%@    end
%@end
%@
%@%% Try to find stripped-down class in java.awt.* or javax.swing.*
%@function javaClass = findAwtSwingClass(jloader, className)
%@    % First try using the classname as-is as a first attempt
%@    try
%@        javaClass = char(jloader.findClass(className).getCanonicalName);
%@        % succeeded!
%@    catch
%@        % failed - name might be a stripped-down class name - try javax.swing...
%@        try
%@            javaClass = char(jloader.findClass(['javax.swing.' className]).getCanonicalName);
%@        catch
%@            % failed - try java.awt...
%@            try
%@                javaClass = char(jloader.findClass(['java.awt.' className]).getCanonicalName);
%@            catch
%@                % failed - try javax.swing.J*...
%@                try
%@                    javaClass = char(jloader.findClass(['javax.swing.J' className]).getCanonicalName);
%@                catch
%@                    javaClass = [];
%@                end
%@            end
%@        end
%@    end
%@end
%@
%@%% Try to fix a className's case to the format used by Sun
%@function className = fixClassNameCase(className)
%@    % First lowercase everything
%@    className = lower(className);
%@
%@    % First char is always UPPER, except if part of a package name
%@    if length(strfind(className,'.')) < 2
%@        className(1) = upper(className(1));
%@
%@        % Second char is UPPER if first char == 'J'
%@        if className(1)=='J'
%@            className(2) = upper(className(2));
%@        end
%@    end
%@
%@    % First char following '.' is always UPPER
%@    dotIdx = strfind(className,'.');
%@    for charIdx = 1 : length(dotIdx)
%@        thisIdx = dotIdx(charIdx);
%@        thisToken = className(thisIdx:end);
%@        if ~strncmp(thisToken,'.swing',6) && ~strncmp(thisToken,'.awt',4)
%@            className(thisIdx+1) = upper(className(thisIdx+1));
%@        end
%@
%@        % Second char is UPPER if first char == 'J'
%@        if className(thisIdx+1)=='J'
%@            className(thisIdx+2) = upper(className(thisIdx+2));
%@        end
%@    end
%@
%@    % Finally, some keywords always start with UPPER
%@    tokenWords = '(bar|component|area|field|pane|dialog|renderer|button|internal|frame|title|box|chooser|icon|menu|header|tip|item|)';
%@    className = regexprep(className,tokenWords,'${[upper($1(1)) $1(2:end)]}');
%@end
%@
%@%% Get the requested component style
%@function [pvPairs,style,ctorArgs] = getStyle(pvPairs)
%@    % Get the requested component Style
%@    styleIdx = find(strcmpi(pvPairs,'style'));
%@    style = 'javax.swing.JButton';  % Default style is a JButton
%@    ctorArgs = {};
%@    if any(styleIdx) && styleIdx(end) < length(pvPairs)
%@        style = pvPairs{styleIdx(end)+1};
%@        if ~ischar(style)
%@            error('YMA:uicomponent:InvalidStyle','Invalid component style specified - must be a string');
%@        end
%@
%@        % Get the fully-qualified (canonical) class name for the given Style, if found
%@        newStyle = getJavaClass(style);
%@
%@        % If not found, raise error
%@        if isempty(newStyle)
%@            error('YMA:uicomponent:ClassNotFound', ['Failed to find Java class ''' style '''.']);
%@        end
%@
%@        % Search for optional ctorArgs
%@        while (styleIdx(end)+2 <= length(pvPairs)) && ~ischar(pvPairs{styleIdx(end)+2})
%@            ctorArgs = [ctorArgs pvPairs{styleIdx(end)+2}]; %#ok<AGROW>
%@            pvPairs(styleIdx(end)+2) = [];
%@        end
%@
%@        style = newStyle;
%@        pvPairs([styleIdx,styleIdx+1]) = [];
%@    end
%@end
%@
%@%% Get the requested component position
%@function [pvPairs,position] = getPosition(pvPairs,style)
%@    position = [];  % default position set by javacomponent to [20,20,60,20]
%@    if ~isempty(strfind(lower(style),'chooser'))
%@        position = [0,0,400,250];  % JFileChooser & JColorChooser need a large initial size
%@        % TODO: use getMinimumSize
%@    end
%@    positionIdx = find(strncmpi(pvPairs,'pos',3));
%@    if any(positionIdx) && positionIdx(end) < length(pvPairs)
%@        position = pvPairs{positionIdx(end)+1};
%@        if ~isnumeric(position)
%@            error('YMA:uicomponent:InvalidPosition','Invalid component position specified - must be a 4-element numeric position vector');
%@        end
%@        pvPairs([positionIdx,positionIdx+1]) = [];
%@    end
%@end
%@
%@%% Get the requested component parent
%@function [pvPairs,position,parent] = getParent(pvPairs,position,parent)
%@    % Default parent is the current figure (create new figure if none is open)
%@    if isempty(parent) || ~ishandle(parent{1}(1))
%@        curVis = get(0,'showHiddenHandles');
%@        set(0,'showHiddenHandles','on');
%@        parent = gcf;
%@        set(0,'showHiddenHandles',curVis);
%@    else
%@        parent = parent{1};
%@        if length(parent)>1
%@            warning('YMA:uicomponent:TooManyParents','UICOMPONENT accepts only a single parent container - only first is used');
%@            parent = parent(1);
%@        end
%@    end
%@
%@    % Check if a container parent is specified in the PV pairs - use the last one if possible
%@    parentIdx = find(strcmpi(pvPairs,'parent'));
%@    if any(parentIdx) && parentIdx(end) < length(pvPairs)
%@        parent = pvPairs{parentIdx(end)+1};
%@        pvPairs([parentIdx,parentIdx+1]) = [];
%@    end
%@
%@    % Only figures are currently supported by JAVACOMPONENT as valid parents...
%@    hParent = handle(parent);
%@    if ~ishghandle(parent)
%@        parentStr = '';
%@        try
%@            if isnumeric(parent)
%@                parentStr = num2str(parent);
%@            else
%@                parentStr = char(parent);
%@            end
%@        catch
%@        end
%@        error('YMA:uicomponent:InvalidParentHandle',['Invalid parent handle specified: ' parentStr]);
%@    %elseif ~(isa(hParent,'figure') || isa(hParent,'uicontainer') || isa(hParent,'uiflowcontainer') || isa(hParent,'uigridcontainer'))
%@    elseif ~any(strcmpi(regexprep(class(hParent),'.*\.',''),{'figure','uicontainer','uiflowcontainer','uigridcontainer'}))
%@        % We get here for all parents not accepted by JAVACOMPONENT as valid parents - try a workaround
%@        %error('YMA:uicomponent:InvalidParentType','Invalid parent container specified - only figure/panel handles are accepted');
%@        warning('YMA:uicomponent:NonFigureParent','Non-figure parent was specified - using the parent''s figure as the component''s parent\n(Type "<a href="matlab:warning off YMA:uicomponent:NonFigureParent">warning off YMA:uicomponent:NonFigureParent</a>" to suppress this warning.)');
%@        parentPosition = getpixelposition(parent,true);
%@        if isempty(position)
%@            position = [20,20,60,20];  % default position = bottom-left corner of parent
%@        end
%@        position = position + [parentPosition(1:2),0,0];  % pixel position relative to figure
%@        parent = ancestor(parent,'figure');
%@    end
%@end
%@
%@%% Link property fields
%@function linkprops(handles,propName)
%@    msp = findprop(handles(1),propName);
%@    msp.GetFunction = {@localGetData,handles(2),propName};
%@    msp.SetFunction = {@localSetData,handles(2),propName};
%@
%@    % This is a slower method no longer in use
%@    %{
%@    propertyListeners___ = getappdata(handles(1),'propertyListeners___');
%@    if isempty(propertyListeners___)
%@        propertyListeners___ = handle([]);
%@    end
%@
%@    % Listener to property changes
%@    for hIdx = 1 : length(handles)
%@        prop = findprop(handles(hIdx),propName);
%@        if ~isempty(prop)
%@            listenerIdx = length(propertyListeners___) + 1;
%@            propertyListeners___(listenerIdx) = handle.listener(handles(hIdx),prop,'PropertyPostSet',{@localUpdateProp,handles,listenerIdx});
%@        else
%@            % never mind...
%@            disp(['Problematic property: ' propName]);
%@        end
%@    end
%@    setappdata(handles(1),'propertyListeners___',propertyListeners___);
%@    %}
%@end
%@
%@%% Property update function
%@function localUpdateProp(eventsrc,eventdata,handles,listenerIdx)  %#ok
%@    try
%@        % Determine which is the original & target handles
%@        hSrc = eventdata.AffectedObject;
%@        if isequal(hSrc,handles(1))
%@            % hcomp was modified
%@            hDst = handles(2);  % =jcomp
%@            peerIdx = 1;
%@        else
%@            % jcomp was modified
%@            hDst = handles(1);  % =hcomp
%@            peerIdx = -1;
%@        end
%@
%@        % Exit if handles are already synchronized for this property
%@        propName = eventsrc.Name;
%@        if isEqual(eventdata.NewValue,get(hDst,propName))
%@            return;
%@        end
%@
%@        % Temporarily turn off listener for this property to avoid endless loop
%@        propertyListeners___ = getappdata(handles(1),'propertyListeners___');
%@        hListener = propertyListeners___(listenerIdx+peerIdx);
%@        set(hListener,'Enabled','off');
%@
%@        % Update all linked objects that have this property
%@        %try
%@        %    newValStr = eventdata.NewValue;
%@        %    newValStr = num2str(newValStr);
%@        %catch
%@        %    newValStr = char(newValStr.toString);
%@        %end
%@        %disp([hDst.class ' ' propName ' => ' newValStr]);
%@        if isprop(hDst,propName)
%@            set(hDst,propName,eventdata.NewValue);
%@        end
%@
%@        % Ensure that all props are stil in sync between the handles
%@        % Note: this is needed since the new value may have triggered other changes in the target handle
%@        if ~isprop(handles(1),'StateChangedCallback') || isempty(get(handles(1),'StateChangedCallback'))
%@            % ...But only do this if the state-changed callback (that takes care of this) is not available
%@            syncProps([],[],handles(2),handles(1));
%@        end
%@
%@        % Restore listeners
%@        set(hListener,'Enabled','on');
%@    catch
%@        %disp(lasterr);  % Never mind...
%@    end
%@end
%@
%@%% Check for data equality
%@function equalsFlag = isEqual(srcValue,dstValue)
%@    % Use matlab's generic isequal() method first
%@    equalsFlag = isequal(srcValue,dstValue);
%@    try
%@        if ~equalsFlag
%@            % Many java objects have applicative equals(), so use it whenever possible
%@            % This way, even if the reference changed it may still be considered "equal"
%@            equalsFlag = srcValue.equals(dstValue);
%@        end
%@    catch
%@        % never mind - no equals() method available in this case
%@    end
%@end
%@
%@%% Synchronize java component & Matlab HG container properties
%@function syncProps(eventsrc,eventdata,hSrc,hDst)  %#ok
%@
%@    % Init
%@    srcData = get(hSrc);
%@    dstData = get(hDst);
%@    fieldNames = intersect(fieldnames(srcData),fieldnames(dstData));
%@
%@    % Loop over all fields and check for unsynchronized values
%@    for fieldIdx = 1 : length(fieldNames)
%@        thisFieldName = fieldNames{fieldIdx};
%@        if ~isEqual(srcData.(thisFieldName),dstData.(thisFieldName))
%@            % Found an unsynchronized value - update from jcomp => hcomp
%@            %disp(['  => ' hSrc.class ' ' thisFieldName]);
%@            overrideSet(hDst,thisFieldName,srcData.(thisFieldName));
%@        end
%@    end
%@
%@    % Check for ComponentModifiedCallback
%@    if isprop(hDst,'ComponentChangedCallback') && ~isempty(hDst.ComponentChangedCallback)
%@        overrideSet(hDst,'ComponentChangedCallbackData',eventdata);
%@        hgfeval(hDst.ComponentChangedCallback,hDst,eventdata);
%@    end
%@end
%@
%@%% Temporarily set a property value, EVEN IF it is read-only (PublicSet='off')
%@function overrideSet(object,fieldName,newValue)
%@    try
%@        % Get the property's read/write indication
%@        sp = findprop(object,fieldName);
%@        oldPublicSet = sp.AccessFlags.PublicSet;
%@
%@        % Temporarily allow writing, EVEN IF property is read-only (PublicSet='off')
%@        sp.AccessFlags.PublicSet = 'on';
%@
%@        % Set the property to the new value
%@        set(object,fieldName,newValue);
%@
%@        % Restore the property's original read/write indication
%@        sp.AccessFlags.PublicSet = oldPublicSet;
%@    catch
%@        %disp(lasterr);  % Never mind...
%@    end
%@end
%@
%@%% Setup the component change callback hooks for internal & user-defined uses
%@function setupChangeCallback(hcomp,jcomp)  %#ok - unused for now: we use localGet/SetData
%@    try
%@        % Disable public access to the default StateChangedCallback (used by uicomponent below)
%@        set(hcomp,'StateChangedCallback',{@syncProps,jcomp,hcomp});
%@        sp(1) = findprop(hcomp,'StateChangedCallback');
%@        sp(2) = findprop(hcomp,'StateChangedCallbackData');
%@        % Note: unfortunately, we cannot modify existing jcomp fields (see workaround below)
%@        %sp(3) = findprop(jcomp,'StateChangedCallback');
%@        %sp(4) = findprop(jcomp,'StateChangedCallbackData');
%@        set(sp,'Visible','off');
%@        set(sp,'AccessFlags.PublicSet','off');
%@
%@        % We can't prevent users from modifying jcomp.StateChangedCallback, but we can alert and revert
%@        prop = findprop(jcomp,'StateChangedCallback');
%@        if ~isempty(prop)
%@            propertyListeners___ = getappdata(hcomp,'propertyListeners___');
%@            propertyListeners___(end+1) = handle.listener(jcomp,prop,'PropertyPostSet',{@localAlertCallbackModified,jcomp,hcomp});
%@            setappdata(hcomp,'propertyListeners___',propertyListeners___);
%@        end
%@
%@        % Create a publicly accessible callback hook (called by StateChangedCallback)
%@        clear sp;
%@        sp(1) = schema.prop(hcomp,'ComponentChangedCallback','mxArray');
%@        sp(2) = schema.prop(jcomp,'ComponentChangedCallback','mxArray');
%@        sp(3) = schema.prop(hcomp,'ComponentChangedCallbackData','mxArray');
%@        sp(4) = schema.prop(jcomp,'ComponentChangedCallbackData','mxArray');
%@        linkprops([hcomp,jcomp],'ComponentChangedCallback');
%@        set(sp(3:4),'AccessFlags.PublicSet','off');  % only CallbackData is read-only
%@    catch
%@        % never mind...
%@        %disp(lasterr);
%@    end
%@end
%@
%@%% We can't prevent the user from modifying jcomp.StateChangedCallback, but we can alert and revert
%@function localAlertCallbackModified(eventsrc,eventdata,jcomp,hcomp)  %#ok
%@    % Send a 'soft' warning to Matlab desktop
%@    warning('YMA:uicomponent:InvalidCallbackModified', ...
%@            ['Cannot modify ''StateChangedCallback'' (used internally by uicomponent). ' ...
%@             'Modify ''ComponentChangedCallback'' instead.']);
%@
%@    % Set ComponentChangedCallback to the requested callback
%@    set(jcomp,'ComponentChangedCallback',get(jcomp,'StateChangedCallback'));
%@
%@    % Revert StateChangedCallback
%@    set(jcomp,'StateChangedCallback',{@syncProps,jcomp,hcomp});
%@end
%@
%@%% Store the container & component's handles in the component
%@function storeHandles(hcomp,jcomp,hcontainer)
%@    try
%@        try
%@            % HG1 - R2014a or older:
%@            % Matlab HG container handle
%@            sp(1) = schema.prop(jcomp,'MatlabHGContainer','mxArray');
%@            sp(2) = schema.prop(hcomp,'MatlabHGContainer','mxArray');
%@            set([hcomp,jcomp],'MatlabHGContainer',hcontainer);
%@            linkprops([hcomp,jcomp],'MatlabHGContainer');
%@
%@            % Java component handle (no need to store within jcomp - only in hcomp...)
%@            sp(3) = schema.prop(hcomp,'JavaComponent','mxArray');
%@            set(hcomp,'JavaComponent',jcomp);
%@
%@            % Disable public set of these handles - read only
%@            set(sp,'AccessFlags.PublicSet','off');
%@        catch
%@            % HG2 - R2014b or newer
%@            try addprop(jcomp,'MatlabHGContainer'); catch, end  % probably fails, never mind
%@            try jcomp.MatlabHGContainer = hcontainer; catch, end  % might fail, never mind
%@            addprop(hcomp,'MatlabHGContainer');
%@            hcomp.MatlabHGContainer = hcontainer;
%@
%@            hp = addprop(hcomp,'JavaComponent');
%@            set(hcomp,'JavaComponent',jcomp);
%@            hp.SetAccess = 'private';
%@        end
%@
%@        % Store the javaclassname in the Tag property
%@        set(hcontainer,'Tag',get(hcontainer,'UserData'));
%@
%@        % Store the handle in the container's UserData
%@        % Note: javacomponent placed the jcomp classname in here, but the correct place is
%@        % ^^^^  really in the Tag property, and use UserData to store the handle reference
%@        set(hcontainer,'UserData',hcomp);
%@    catch
%@        % never mind...
%@        %disp(lasterr);
%@    end
%@end
%@
%@%% Get the relevant property value from jcomp
%@function propValue = localGetData(object,propValue,jcomp,propName)  %#ok
%@    propValue = get(jcomp,propName);
%@end
%@
%@%% Set the relevant property value in jcomp
%@function propValue = localSetData(object,propValue,jcomp,propName)  %#ok
%@    set(jcomp,propName,propValue);
%@end
%@
%@%% Workaround for javacomponent's bug with java.awt.Window and sub-classes...
%@function [jcomp, hcontainer] = javacomponentFix(javaComp,position,parent)
%@    % Prepare a Matlab HG container for the java component
%@    % Note: this container will be a child of the requested parent, while javaComp is another window!
%@    if isempty(position)
%@        % Default window size should be larger than javacomponent's default of 60x20
%@        position = [100,100,100,100];
%@    else
%@        % Disallow window sizes less than 100x100
%@        position = [position(1:2) max(position(3:4),100)];
%@    end
%@    hcontainer = hgjavacomponent('Parent',parent,'Units','Pixels','JavaPeer',javaComp,'Position', position);
%@
%@    % Prepare a handle for the java component, including all available callback hooks
%@    jcomp = handle(javaComp,'callbackProperties');
%@
%@    % Prepare deletion callbacks, so that if any of the component or container is deleted, so will the other
%@    set(hcontainer, 'DeleteFcn', {@componentDelete, jcomp});
%@    set(jcomp, 'WindowClosingCallback', {@componentDelete, hcontainer});
%@    hl = handle.listener(jcomp, jcomp, 'ObjectBeingDestroyed', {@componentDelete, hcontainer});
%@    p = schema.prop(jcomp, 'Listeners__', 'handle vector');
%@    set(p,'AccessFlags.Serialize','off','AccessFlags.Copy','off','FactoryValue',[],'Visible','off');
%@    set(jcomp, 'Listeners__', hl);
%@
%@    % Set the new figure's screen position & size
%@    % Note: remember that Matlab origin = bottom left while java origin = top left...
%@    screenSize = get(0,'ScreenSize');
%@    jcomp.setLocation(java.awt.Point(position(1), screenSize(4)-position(2)-position(4)));
%@    jcomp.setSize(java.awt.Dimension(position(3), position(4)));
%@end
%@
%@%% Callback function for Window/Frame Java component deletion
%@function componentDelete(obj, evd, component) %#ok - mlint
%@    % delete component if it exists
%@    if any(ishandle(component))
%@        delete(component);
%@    end
%@end
%@
%@
%@%% TODO TODO TODO
%@%{
%@% To add a *Frame - see C:\Program Files\Matlab 7.4\toolbox\matlab\scribe\scribealign.m:
%@Frame=com.mathworks.mwswing.MJFrame('Align Distribute Tool');
%@Panel=com.mathworks.page.scribealign.ScribeAlignmentPanel;
%@Frame.getContentPane.add(Panel);
%@Frame.setResizable(false);
%@Frame.pack;
%@Frame.show;
%@%}
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/Hiatus/isotope-test-hiatus.txt__ -->
%@ -9.00000000e+00 9.99971411e-01
%@ -6.77755511e+00 9.92537010e-01
%@ -4.55511022e+00 9.72062099e-01
%@ -2.33266533e+00 9.38815689e-01
%@ -1.10220441e-01 8.93234589e-01
%@ 2.11222445e+00 8.35917672e-01
%@ 4.33466934e+00 7.67617997e-01
%@ 6.55711423e+00 6.89232925e-01
%@ 8.77955912e+00 6.01792323e-01
%@ 1.10020040e+01 5.06445034e-01
%@ 1.32244489e+01 4.04443786e-01
%@ 1.54468938e+01 2.97128727e-01
%@ 1.76693387e+01 1.85909824e-01
%@ 1.98917836e+01 7.22483334e-02
%@ 2.21142285e+01 -4.23623967e-02
%@ 2.43366733e+01 -1.56416546e-01
%@ 2.65591182e+01 -2.68415606e-01
%@ 2.87815631e+01 -3.76888072e-01
%@ 3.10040080e+01 -4.80408769e-01
%@ 3.32264529e+01 -5.77617586e-01
%@ 3.54488978e+01 -6.67237338e-01
%@ 3.76713427e+01 -7.48090550e-01
%@ 3.98937876e+01 -8.19114927e-01
%@ 4.21162325e+01 -8.79377311e-01
%@ 4.43386774e+01 -9.28085942e-01
%@ 4.65611222e+01 -9.64600857e-01
%@ 4.87835671e+01 -9.88442302e-01
%@ 5.10060120e+01 -9.99297037e-01
%@ 5.32284569e+01 -9.97022444e-01
%@ 5.54509018e+01 -9.81648410e-01
%@ 5.76733467e+01 -9.53376926e-01
%@ 5.98957916e+01 -9.12579439e-01
%@ 6.21182365e+01 -8.59791970e-01
%@ 6.43406814e+01 -7.95708071e-01
%@ 6.65631263e+01 -7.21169710e-01
%@ 6.87855711e+01 -6.37156216e-01
%@ 7.10080160e+01 -5.44771405e-01
%@ 7.32304609e+01 -4.45229081e-01
%@ 7.54529058e+01 -3.39837087e-01
%@ 7.76753507e+01 -2.29980121e-01
%@ 7.98977956e+01 -1.17101548e-01
%@ 8.21202405e+01 -2.68442780e-03
%@ 8.43426854e+01 1.11767961e-01
%@ 8.65651303e+01 2.24751880e-01
%@ 8.87875752e+01 3.34782883e-01
%@ 9.10100200e+01 4.40415319e-01
%@ 9.32324649e+01 5.40261331e-01
%@ 9.54549098e+01 6.33009085e-01
%@ 9.76773547e+01 7.17440010e-01
%@ 9.98997996e+01 7.92444804e-01
%@ 1.02122244e+02 8.57038012e-01
%@ 1.04344689e+02 9.10370973e-01
%@ 1.06567134e+02 9.51742967e-01
%@ 1.08789579e+02 9.80610426e-01
%@ 1.11012024e+02 9.96594074e-01
%@ 1.13234469e+02 9.99610511e-01
%@ 1.15456914e+02 9.90900816e-01
%@ 1.17679359e+02 9.70837480e-01
%@ 1.19901804e+02 9.39650386e-01
%@ 1.22124248e+02 8.97696872e-01
%@ 1.24346693e+02 8.45457638e-01
%@ 1.26569138e+02 7.83531235e-01
%@ 1.28791583e+02 7.12627211e-01
%@ 1.31014028e+02 6.33557975e-01
%@ 1.33236473e+02 5.47229497e-01
%@ 1.35458918e+02 4.54630917e-01
%@ 1.37681363e+02 3.56823223e-01
%@ 1.39903808e+02 2.54927084e-01
%@ 1.42126253e+02 1.50110016e-01
%@ 1.44348697e+02 4.35730029e-02
%@ 1.46571142e+02 -6.34632654e-02
%@ 1.48793587e+02 -1.69772378e-01
%@ 1.51016032e+02 -2.74136256e-01
%@ 1.53238477e+02 -3.75359108e-01
%@ 1.55460922e+02 -4.72281133e-01
%@ 1.57683367e+02 -5.63791809e-01
%@ 1.59905812e+02 -6.48842615e-01
%@ 1.62128257e+02 -7.26459048e-01
%@ 1.64350701e+02 -7.95751786e-01
%@ 1.66573146e+02 -8.55926880e-01
%@ 1.68795591e+02 -9.06294851e-01
%@ 1.71018036e+02 -9.46278586e-01
%@ 1.73240481e+02 -9.75419957e-01
%@ 1.75462926e+02 -9.93385064e-01
%@ 1.77685371e+02 -9.99968065e-01
%@ 1.79907816e+02 -9.95093532e-01
%@ 1.82130261e+02 -9.78817319e-01
%@ 1.84352705e+02 -9.51325915e-01
%@ 1.86575150e+02 -9.12934314e-01
%@ 1.88797595e+02 -8.64082405e-01
%@ 1.91020040e+02 -8.05329926e-01
%@ 1.93242485e+02 -7.37350058e-01
%@ 1.95464930e+02 -6.60921707e-01
%@ 1.97687375e+02 -5.76920582e-01
%@ 1.99909820e+02 -4.86309159e-01
%@ 2.02132265e+02 -3.90125655e-01
%@ 2.04354709e+02 -2.89472130e-01
%@ 2.06577154e+02 -1.85501863e-01
%@ 2.08799599e+02 -7.94061338e-02
%@ 2.11022044e+02 2.75994225e-02
%@ 2.13244489e+02 1.34288747e-01
%@ 2.15466934e+02 2.39439406e-01
%@ 2.17689379e+02 3.41846591e-01
%@ 2.19911824e+02 4.40336933e-01
%@ 2.22134269e+02 5.33781938e-01
%@ 2.24356713e+02 6.02287325e-01
%@ 2.26579158e+02 6.55221307e-01
%@ 2.28801603e+02 7.05116714e-01
%@ 2.31024048e+02 7.51742159e-01
%@ 2.33246493e+02 7.94881416e-01
%@ 2.35468938e+02 8.34334428e-01
%@ 2.37691383e+02 8.69918232e-01
%@ 2.39913828e+02 9.01467811e-01
%@ 2.42136273e+02 9.28836852e-01
%@ 2.44358717e+02 9.51898434e-01
%@ 2.46581162e+02 9.70545608e-01
%@ 2.48803607e+02 9.84691898e-01
%@ 2.51026052e+02 9.94271701e-01
%@ 2.53248497e+02 9.99240592e-01
%@ 2.55470942e+02 9.99575526e-01
%@ 2.57693387e+02 9.95274952e-01
%@ 2.59915832e+02 9.86358812e-01
%@ 2.62138277e+02 9.72868455e-01
%@ 2.64360721e+02 9.54866443e-01
%@ 2.66583166e+02 9.32436258e-01
%@ 2.68805611e+02 9.05681921e-01
%@ 2.71028056e+02 8.74727505e-01
%@ 2.73250501e+02 8.39716559e-01
%@ 2.75472946e+02 8.00811447e-01
%@ 2.77695391e+02 7.58192589e-01
%@ 2.79917836e+02 7.12057630e-01
%@ 2.82140281e+02 6.62620520e-01
%@ 2.84362725e+02 6.10110522e-01
%@ 2.86585170e+02 5.54771150e-01
%@ 2.88807615e+02 4.96859039e-01
%@ 2.91030060e+02 4.36642755e-01
%@ 2.93252505e+02 3.74401551e-01
%@ 2.95474950e+02 3.10424067e-01
%@ 2.97697395e+02 2.45006999e-01
%@ 2.99919840e+02 1.78453717e-01
%@ 3.02142285e+02 1.11072859e-01
%@ 3.04364729e+02 4.31769032e-02
%@ 3.06587174e+02 -2.49192844e-02
%@ 3.08809619e+02 -9.28999093e-02
%@ 3.11032064e+02 -1.60449713e-01
%@ 3.13254509e+02 -2.27255435e-01
%@ 3.15476954e+02 -2.93007264e-01
%@ 3.17699399e+02 -3.57400279e-01
%@ 3.19921844e+02 -4.20135859e-01
%@ 3.22144289e+02 -4.80923067e-01
%@ 3.24366733e+02 -5.39480006e-01
%@ 3.26589178e+02 -5.95535118e-01
%@ 3.28811623e+02 -6.48828449e-01
%@ 3.31034068e+02 -6.99112853e-01
%@ 3.33256513e+02 -7.46155137e-01
%@ 3.35478958e+02 -9.84378251e-01
%@ 3.37701403e+02 -8.15286146e-01
%@ 3.39923848e+02 -1.57995980e-01
%@ 3.42146293e+02 5.93903093e-01
%@ 3.44368737e+02 9.90169558e-01
%@ 3.46591182e+02 7.93516763e-01
%@ 3.48813627e+02 1.21701539e-01
%@ 3.51036072e+02 -6.22989270e-01
%@ 3.53258517e+02 -9.94630500e-01
%@ 3.55480962e+02 -7.70681232e-01
%@ 3.57703407e+02 -8.52435840e-02
%@ 3.59925852e+02 6.51238416e-01
%@ 3.62148297e+02 9.97755084e-01
%@ 3.64370741e+02 7.46810236e-01
%@ 3.66593186e+02 4.86710975e-02
%@ 3.68815631e+02 -6.78612576e-01
%@ 3.71038076e+02 -9.99539112e-01
%@ 3.73260521e+02 -7.21935846e-01
%@ 3.75482966e+02 -1.20332180e-02
%@ 3.77705411e+02 7.05074970e-01
%@ 3.79927856e+02 9.99980187e-01
%@ 3.82150301e+02 6.96091483e-01
%@ 3.84372745e+02 -2.46208291e-02
%@ 3.86595190e+02 -7.30590046e-01
%@ 3.88817635e+02 -9.99077716e-01
%@ 3.91040080e+02 -6.69311870e-01
%@ 3.93262525e+02 6.12417963e-02
%@ 3.95484970e+02 7.55123521e-01
%@ 3.97707415e+02 9.96832912e-01
%@ 3.99929860e+02 6.41632989e-01
%@ 4.02152305e+02 -9.77804807e-02
%@ 4.04374749e+02 -7.78642432e-01
%@ 4.06597194e+02 -9.93248791e-01
%@ 4.08819639e+02 -6.13092027e-01
%@ 4.11042084e+02 1.34187790e-01
%@ 4.13264529e+02 8.01115182e-01
%@ 4.15486974e+02 9.88330168e-01
%@ 4.17709419e+02 5.83727331e-01
%@ 4.19931864e+02 -1.70414808e-01
%@ 4.22154309e+02 -8.22511575e-01
%@ 4.24376754e+02 -9.82083652e-01
%@ 4.26599198e+02 -5.53578356e-01
%@ 4.28821643e+02 2.06412862e-01
%@ 4.31044088e+02 8.42802864e-01
%@ 4.33266533e+02 9.74517635e-01
%@ 4.35488978e+02 5.22685608e-01
%@ 4.37711423e+02 -2.42133585e-01
%@ 4.39933868e+02 -8.61961786e-01
%@ 4.42156313e+02 -9.65642283e-01
%@ 4.44378758e+02 -4.91090594e-01
%@ 4.46601202e+02 -1.94348574e-01
%@ 4.48823647e+02 -6.28008399e-02
%@ 4.51046092e+02 6.98520001e-02
%@ 4.53268537e+02 2.01275655e-01
%@ 4.55490982e+02 3.29157463e-01
%@ 4.57713427e+02 4.51247088e-01
%@ 4.59935872e+02 5.65396120e-01
%@ 4.62158317e+02 6.69595880e-01
%@ 4.64380762e+02 7.62012763e-01
%@ 4.66603206e+02 8.41020511e-01
%@ 4.68825651e+02 9.05228825e-01
%@ 4.71048096e+02 9.53507831e-01
%@ 4.73270541e+02 9.85007965e-01
%@ 4.75492986e+02 9.99174917e-01
%@ 4.77715431e+02 9.95759392e-01
%@ 4.79937876e+02 9.74821494e-01
%@ 4.82160321e+02 9.36729667e-01
%@ 4.84382766e+02 8.82154211e-01
%@ 4.86605210e+02 8.12055492e-01
%@ 4.88827655e+02 7.27667035e-01
%@ 4.91050100e+02 6.30473825e-01
%@ 4.93272545e+02 5.22186170e-01
%@ 4.95494990e+02 4.04709607e-01
%@ 4.97717435e+02 2.80111371e-01
%@ 4.99939880e+02 1.50584016e-01
%@ 5.02162325e+02 1.84068354e-02
%@ 5.04384770e+02 -1.14094251e-01
%@ 5.06607214e+02 -2.44587620e-01
%@ 5.08829659e+02 -3.70776983e-01
%@ 5.11052104e+02 -4.90441785e-01
%@ 5.13274549e+02 -6.01476285e-01
%@ 5.15496994e+02 -7.01926609e-01
%@ 5.17719439e+02 -7.90025133e-01
%@ 5.19941884e+02 -8.64221589e-01
%@ 5.22164329e+02 -9.23210342e-01
%@ 5.24386774e+02 -9.65953366e-01
%@ 5.26609218e+02 -9.91698512e-01
%@ 5.28831663e+02 -9.99992745e-01
%@ 5.31054108e+02 -9.90690109e-01
%@ 5.33276553e+02 -9.63954304e-01
%@ 5.35498998e+02 -9.20255799e-01
%@ 5.37721443e+02 -8.60363557e-01
%@ 5.39943888e+02 -7.85331501e-01
%@ 5.42166333e+02 -6.96479970e-01
%@ 5.44388778e+02 -5.95372484e-01
%@ 5.46611222e+02 -4.83788231e-01
%@ 5.48833667e+02 -3.63690759e-01
%@ 5.51056112e+02 -2.37193422e-01
%@ 5.53278557e+02 -1.06522194e-01
%@ 5.55501002e+02 2.60235057e-02
%@ 5.57723447e+02 1.09774306e-01
%@ 5.59945892e+02 1.78873678e-01
%@ 5.62168337e+02 2.47100787e-01
%@ 5.64390782e+02 3.14122928e-01
%@ 5.66613226e+02 3.79613274e-01
%@ 5.68835671e+02 4.43252466e-01
%@ 5.71058116e+02 5.04730173e-01
%@ 5.73280561e+02 5.63746604e-01
%@ 5.75503006e+02 6.20013969e-01
%@ 5.77725451e+02 6.73257886e-01
%@ 5.79947896e+02 7.23218714e-01
%@ 5.82170341e+02 7.69652824e-01
%@ 5.84392786e+02 8.12333784e-01
%@ 5.86615230e+02 8.51053462e-01
%@ 5.88837675e+02 8.85623047e-01
%@ 5.91060120e+02 9.15873961e-01
%@ 5.93282565e+02 9.41658689e-01
%@ 5.95505010e+02 9.62851494e-01
%@ 5.97727455e+02 9.79349030e-01
%@ 5.99949900e+02 9.91070849e-01
%@ 6.02172345e+02 9.97959790e-01
%@ 6.04394790e+02 9.99982260e-01
%@ 6.06617234e+02 9.97128396e-01
%@ 6.08839679e+02 9.89412115e-01
%@ 6.11062124e+02 9.76871045e-01
%@ 6.13284569e+02 9.59566341e-01
%@ 6.15507014e+02 9.37582389e-01
%@ 6.17729459e+02 9.11026391e-01
%@ 6.19951904e+02 8.80027846e-01
%@ 6.22174349e+02 8.44737915e-01
%@ 6.24396794e+02 8.05328687e-01
%@ 6.26619238e+02 7.61992338e-01
%@ 6.28841683e+02 7.14940194e-01
%@ 6.31064128e+02 6.64401701e-01
%@ 6.33286573e+02 6.10623307e-01
%@ 6.35509018e+02 5.53867256e-01
%@ 6.37731463e+02 4.94410317e-01
%@ 6.39953908e+02 4.32542425e-01
%@ 6.42176353e+02 3.68565274e-01
%@ 6.44398798e+02 3.02790844e-01
%@ 6.46621242e+02 2.35539879e-01
%@ 6.48843687e+02 1.67140322e-01
%@ 6.51066132e+02 9.79257191e-02
%@ 6.53288577e+02 2.82335891e-02
%@ 6.55511022e+02 -4.15962198e-02
%@ 6.57733467e+02 -1.11223188e-01
%@ 6.59955912e+02 -1.80307785e-01
%@ 6.62178357e+02 -2.48513126e-01
%@ 6.64400802e+02 -3.15506612e-01
%@ 6.66623246e+02 -3.80961556e-01
%@ 6.68845691e+02 -4.91416241e-01
%@ 6.71068136e+02 -6.03130299e-01
%@ 6.73290581e+02 -7.04078296e-01
%@ 6.75513026e+02 -7.92458280e-01
%@ 6.77735471e+02 -8.66692642e-01
%@ 6.79957916e+02 -9.25456274e-01
%@ 6.82180361e+02 -9.67700230e-01
%@ 6.84402806e+02 -9.92670440e-01
%@ 6.86625251e+02 -9.99921179e-01
%@ 6.88847695e+02 -9.89323019e-01
%@ 6.91070140e+02 -9.61065140e-01
%@ 6.93292585e+02 -9.15651955e-01
%@ 6.95515030e+02 -8.53894102e-01
%@ 6.97737475e+02 -7.76893978e-01
%@ 6.99959920e+02 -6.86026059e-01
%@ 7.02182365e+02 -5.82912366e-01
%@ 7.04404810e+02 -4.69393508e-01
%@ 7.06627255e+02 -3.47495832e-01
%@ 7.08849699e+02 -2.19395249e-01
%@ 7.11072144e+02 -8.73783943e-02
%@ 7.13294589e+02 4.61981916e-02
%@ 7.15517034e+02 1.78950126e-01
%@ 7.17739479e+02 3.08507745e-01
%@ 7.19961924e+02 4.32558407e-01
%@ 7.22184369e+02 5.48887769e-01
%@ 7.24406814e+02 6.55419317e-01
%@ 7.26629259e+02 7.50251429e-01
%@ 7.28851703e+02 8.31691324e-01
%@ 7.31074148e+02 8.98285274e-01
%@ 7.33296593e+02 9.48844557e-01
%@ 7.35519038e+02 9.82466675e-01
%@ 7.37741483e+02 9.98551461e-01
%@ 7.39963928e+02 9.96811799e-01
%@ 7.42186373e+02 9.77278741e-01
%@ 7.44408818e+02 9.40300959e-01
%@ 7.46631263e+02 8.86538517e-01
%@ 7.48853707e+02 8.16951091e-01
%@ 7.51076152e+02 7.32780838e-01
%@ 7.53298597e+02 6.35530224e-01
%@ 7.55521042e+02 5.26935200e-01
%@ 7.57743487e+02 4.08934221e-01
%@ 7.59965932e+02 2.83633642e-01
%@ 7.62188377e+02 1.53270116e-01
%@ 7.64410822e+02 2.01706707e-02
%@ 7.66633267e+02 -1.13288827e-01
%@ 7.68855711e+02 -2.44726084e-01
%@ 7.71078156e+02 -3.71794906e-01
%@ 7.73300601e+02 -4.92227075e-01
%@ 7.75523046e+02 -6.03872841e-01
%@ 7.77745491e+02 -7.04739291e-01
%@ 7.79967936e+02 -7.48581113e-01
%@ 7.82190381e+02 -7.83793575e-01
%@ 7.84412826e+02 -8.16650151e-01
%@ 7.86635271e+02 -8.47052083e-01
%@ 7.88857715e+02 -8.74907991e-01
%@ 7.91080160e+02 -9.00134145e-01
%@ 7.93302605e+02 -9.22654724e-01
%@ 7.95525050e+02 -9.42402035e-01
%@ 7.97747495e+02 -9.59316724e-01
%@ 7.99969940e+02 -9.73347948e-01
%@ 8.02192385e+02 -9.84453535e-01
%@ 8.04414830e+02 -9.92600102e-01
%@ 8.06637275e+02 -9.97763164e-01
%@ 8.08859719e+02 -9.99927202e-01
%@ 8.11082164e+02 -9.99085710e-01
%@ 8.13304609e+02 -9.95241220e-01
%@ 8.15527054e+02 -9.88405285e-01
%@ 8.17749499e+02 -9.78598454e-01
%@ 8.19971944e+02 -9.65850202e-01
%@ 8.22194389e+02 -9.50198849e-01
%@ 8.24416834e+02 -9.31691437e-01
%@ 8.26639279e+02 -9.10383596e-01
%@ 8.28861723e+02 -8.86339372e-01
%@ 8.31084168e+02 -8.59631036e-01
%@ 8.33306613e+02 -8.30338865e-01
%@ 8.35529058e+02 -7.98550905e-01
%@ 8.37751503e+02 -7.64362703e-01
%@ 8.39973948e+02 -7.27877020e-01
%@ 8.42196393e+02 -6.89203522e-01
%@ 8.44418838e+02 -6.48458451e-01
%@ 8.46641283e+02 -6.05764279e-01
%@ 8.48863727e+02 -5.61249332e-01
%@ 8.51086172e+02 -5.15047411e-01
%@ 8.53308617e+02 -4.67297387e-01
%@ 8.55531062e+02 -4.18142786e-01
%@ 8.57753507e+02 -3.67731353e-01
%@ 8.59975952e+02 -3.16214612e-01
%@ 8.62198397e+02 -2.63747410e-01
%@ 8.64420842e+02 -2.10487449e-01
%@ 8.66643287e+02 -1.56594817e-01
%@ 8.68865731e+02 -1.02231500e-01
%@ 8.71088176e+02 -4.75609006e-02
%@ 8.73310621e+02 7.25265460e-03
%@ 8.75533066e+02 6.20444101e-02
%@ 8.77755511e+02 1.16649676e-01
%@ 8.79977956e+02 1.70904322e-01
%@ 8.82200401e+02 2.24645273e-01
%@ 8.84422846e+02 2.77710997e-01
%@ 8.86645291e+02 3.29941992e-01
%@ 8.88867735e+02 3.81181264e-01
%@ 8.91090180e+02 4.61204771e-01
%@ 8.93312625e+02 5.39419759e-01
%@ 8.95535070e+02 6.13229977e-01
%@ 8.97757515e+02 6.82032710e-01
%@ 8.99979960e+02 7.45266131e-01
%@ 9.02202405e+02 8.02413891e-01
%@ 9.04424850e+02 8.53009336e-01
%@ 9.06647295e+02 8.96639315e-01
%@ 9.08869739e+02 9.32947558e-01
%@ 9.11092184e+02 9.61637579e-01
%@ 9.13314629e+02 9.82475104e-01
%@ 9.15537074e+02 9.95289977e-01
%@ 9.17759519e+02 9.99977557e-01
%@ 9.19981964e+02 9.96499565e-01
%@ 9.22204409e+02 9.84884401e-01
%@ 9.24426854e+02 9.65226913e-01
%@ 9.26649299e+02 9.37687619e-01
%@ 9.28871743e+02 9.02491397e-01
%@ 9.31094188e+02 8.59925651e-01
%@ 9.33316633e+02 8.10337963e-01
%@ 9.35539078e+02 7.54133254e-01
%@ 9.37761523e+02 6.91770478e-01
%@ 9.39983968e+02 6.23758873e-01
%@ 9.42206413e+02 5.50653807e-01
%@ 9.44428858e+02 4.73052236e-01
%@ 9.46651303e+02 3.91587836e-01
%@ 9.48873747e+02 3.06925827e-01
%@ 9.51096192e+02 2.19757536e-01
%@ 9.53318637e+02 1.30794759e-01
%@ 9.55541082e+02 4.07639438e-02
%@ 9.57763527e+02 -4.95997396e-02
%@ 9.59985972e+02 -1.39558404e-01
%@ 9.62208417e+02 -2.28377468e-01
%@ 9.64430862e+02 -3.15331658e-01
%@ 9.66653307e+02 -3.99710927e-01
%@ 9.68875752e+02 -4.80826254e-01
%@ 9.71098196e+02 -5.58015272e-01
%@ 9.73320641e+02 -6.30647674e-01
%@ 9.75543086e+02 -6.98130362e-01
%@ 9.77765531e+02 -7.59912288e-01
%@ 9.79987976e+02 -8.15488956e-01
%@ 9.82210421e+02 -8.64406542e-01
%@ 9.84432866e+02 -9.06265595e-01
%@ 9.86655311e+02 -9.40724306e-01
%@ 9.88877756e+02 -9.67501293e-01
%@ 9.91100200e+02 -9.86377901e-01
%@ 9.93322645e+02 -9.97199989e-01
%@ 9.95545090e+02 -9.99879186e-01
%@ 9.97767535e+02 -9.94393614e-01
%@ 9.99989980e+02 -9.80788068e-01
%@ 1.00221242e+03 -9.59173647e-01
%@ 1.00443487e+03 -9.29726849e-01
%@ 1.00665731e+03 -8.92688129e-01
%@ 1.00887976e+03 -8.48359937e-01
%@ 1.01110220e+03 -7.97104246e-01
%@ 1.01332465e+03 -7.39339596e-01
%@ 1.01554709e+03 -6.75537680e-01
%@ 1.01776954e+03 -6.06219490e-01
%@ 1.01999198e+03 -5.31951059e-01
%@ 1.02221443e+03 -4.53338847e-01
%@ 1.02443687e+03 -3.71024780e-01
%@ 1.02665932e+03 -2.85681016e-01
%@ 1.02888176e+03 -1.98004451e-01
%@ 1.03110421e+03 -1.08711030e-01
%@ 1.03332665e+03 -1.85299015e-02
%@ 1.03554910e+03 7.18025377e-02
%@ 1.03777154e+03 1.61548655e-01
%@ 1.03999399e+03 2.49975606e-01
%@ 1.04221643e+03 3.36361317e-01
%@ 1.04443888e+03 4.20000384e-01
%@ 1.04666132e+03 5.00209830e-01
%@ 1.04888377e+03 5.76334686e-01
%@ 1.05110621e+03 6.47753334e-01
%@ 1.05332866e+03 7.13882587e-01
%@ 1.05555110e+03 7.74182450e-01
%@ 1.05777355e+03 8.28160528e-01
%@ 1.05999599e+03 8.75376051e-01
%@ 1.06221844e+03 9.15443467e-01
%@ 1.06444088e+03 9.48035596e-01
%@ 1.06666333e+03 9.72886299e-01
%@ 1.06888577e+03 9.89792650e-01
%@ 1.07110822e+03 9.98616598e-01
%@ 1.07333066e+03 9.99286086e-01
%@ 1.07555311e+03 9.91795650e-01
%@ 1.07777555e+03 9.76206453e-01
%@ 1.07999800e+03 9.52645794e-01
%@ 1.08222044e+03 9.21306062e-01
%@ 1.08444289e+03 8.82443171e-01
%@ 1.08666533e+03 8.36374465e-01
%@ 1.08888778e+03 7.83476131e-01
%@ 1.09111022e+03 7.24180122e-01
%@ 1.09333267e+03 6.58970635e-01
%@ 1.09555511e+03 5.88380156e-01
%@ 1.09777756e+03 5.12985109e-01
%@ 1.10000000e+03 4.33401151e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/Hiatus/testagemodel_hiatus.txt__ -->
%@1.00000000e+00 5.00000000e+01 1.25000000e+01
%@1.12000000e+02 1.86746222e+02 1.93373111e+01
%@2.23000000e+02 3.14438144e+02 2.57219072e+01
%@3.34000000e+02 3.95651647e+02 2.97825823e+01
%@4.45000000e+02 1.34304724e+03 7.71523622e+01
%@5.56000000e+02 1.50133291e+03 8.50666453e+01
%@6.67000000e+02 1.58461319e+03 8.92306596e+01
%@7.78000000e+02 1.74403574e+03 9.72017869e+01
%@8.89000000e+02 1.80941410e+03 1.00470705e+02
%@1.00000000e+03 1.91719689e+03 1.05859844e+02
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/LayercountGood/isotope-test-good.txt__ -->
%@ -9.00000000e+00 9.77807874e-01
%@ -6.77755511e+00 9.60910032e-01
%@ -4.55511022e+00 9.39378171e-01
%@ -2.33266533e+00 9.13316131e-01
%@ -1.10220441e-01 8.82849595e-01
%@ 2.11222445e+00 8.48125491e-01
%@ 4.33466934e+00 8.09311275e-01
%@ 6.55711423e+00 7.66594131e-01
%@ 8.77955912e+00 7.20180064e-01
%@ 1.10020040e+01 6.70292906e-01
%@ 1.32244489e+01 6.17173240e-01
%@ 1.54468938e+01 5.61077237e-01
%@ 1.76693387e+01 5.02275422e-01
%@ 1.98917836e+01 4.41051368e-01
%@ 2.21142285e+01 3.77700331e-01
%@ 2.43366733e+01 3.12527822e-01
%@ 2.65591182e+01 2.45848139e-01
%@ 2.87815631e+01 1.77982845e-01
%@ 3.10040080e+01 1.09259223e-01
%@ 3.32264529e+01 4.00086957e-02
%@ 3.54488978e+01 -2.94347749e-02
%@ 3.76713427e+01 -9.87362955e-02
%@ 3.98937876e+01 -1.67561657e-01
%@ 4.21162325e+01 -2.35578948e-01
%@ 4.43386774e+01 -3.02460152e-01
%@ 4.65611222e+01 -3.67882732e-01
%@ 4.87835671e+01 -4.31531187e-01
%@ 5.10060120e+01 -4.93098569e-01
%@ 5.32284569e+01 -5.52287969e-01
%@ 5.54509018e+01 -6.08813943e-01
%@ 5.76733467e+01 -6.62403893e-01
%@ 5.98957916e+01 -7.12799380e-01
%@ 6.21182365e+01 -7.59757370e-01
%@ 6.43406814e+01 -8.03051407e-01
%@ 6.65631263e+01 -8.42472704e-01
%@ 6.87855711e+01 -8.77831151e-01
%@ 7.10080160e+01 -9.08956230e-01
%@ 7.32304609e+01 -9.35697840e-01
%@ 7.54529058e+01 -9.57927018e-01
%@ 7.76753507e+01 -9.75536565e-01
%@ 7.98977956e+01 -9.88441556e-01
%@ 8.21202405e+01 -9.96579758e-01
%@ 8.43426854e+01 -9.99911923e-01
%@ 8.65651303e+01 -9.98421982e-01
%@ 8.87875752e+01 -9.92117121e-01
%@ 9.10100200e+01 -9.81027745e-01
%@ 9.32324649e+01 -9.65207332e-01
%@ 9.54549098e+01 -9.44732178e-01
%@ 9.76773547e+01 -9.19701024e-01
%@ 9.98997996e+01 -8.90234583e-01
%@ 1.02122244e+02 -8.56474959e-01
%@ 1.04344689e+02 -8.18584959e-01
%@ 1.06567134e+02 -7.76747307e-01
%@ 1.08789579e+02 -7.31163768e-01
%@ 1.11012024e+02 -6.82054169e-01
%@ 1.13234469e+02 -5.99021871e-01
%@ 1.15456914e+02 -4.81980016e-01
%@ 1.17679359e+02 -3.55591881e-01
%@ 1.19901804e+02 -2.22308310e-01
%@ 1.22124248e+02 -8.47138631e-02
%@ 1.24346693e+02 5.45233065e-02
%@ 1.26569138e+02 1.92703191e-01
%@ 1.28791583e+02 3.27146286e-01
%@ 1.31014028e+02 4.55245546e-01
%@ 1.33236473e+02 5.74516944e-01
%@ 1.35458918e+02 6.82647638e-01
%@ 1.37681363e+02 7.77540817e-01
%@ 1.39903808e+02 8.57356369e-01
%@ 1.42126253e+02 9.20546555e-01
%@ 1.44348697e+02 9.65886028e-01
%@ 1.46571142e+02 9.92495589e-01
%@ 1.48793587e+02 9.99859242e-01
%@ 1.51016032e+02 9.87834195e-01
%@ 1.53238477e+02 9.56653631e-01
%@ 1.55460922e+02 9.06922185e-01
%@ 1.57683367e+02 8.39604221e-01
%@ 1.59905812e+02 7.56005132e-01
%@ 1.62128257e+02 6.57746022e-01
%@ 1.64350701e+02 5.46732276e-01
%@ 1.66573146e+02 4.25116610e-01
%@ 1.68795591e+02 2.95257325e-01
%@ 1.71018036e+02 1.59672578e-01
%@ 1.73240481e+02 2.09915521e-02
%@ 1.75462926e+02 -1.18096530e-01
%@ 1.77685371e+02 -2.54894552e-01
%@ 1.79907816e+02 -3.86749804e-01
%@ 1.82130261e+02 -5.11105424e-01
%@ 1.84352705e+02 -6.25549980e-01
%@ 1.86575150e+02 -7.27864227e-01
%@ 1.88797595e+02 -8.16064146e-01
%@ 1.91020040e+02 -8.88439415e-01
%@ 1.93242485e+02 -9.43586574e-01
%@ 1.95464930e+02 -9.80436239e-01
%@ 1.97687375e+02 -9.98273845e-01
%@ 1.99909820e+02 -9.96753493e-01
%@ 2.02132265e+02 -9.75904667e-01
%@ 2.04354709e+02 -9.36131653e-01
%@ 2.06577154e+02 -8.78205709e-01
%@ 2.08799599e+02 -8.03250100e-01
%@ 2.11022044e+02 -7.12718324e-01
%@ 2.13244489e+02 -6.08365920e-01
%@ 2.15466934e+02 -4.92216431e-01
%@ 2.17689379e+02 -3.66522163e-01
%@ 2.19911824e+02 -2.33720505e-01
%@ 2.22134269e+02 -9.63866729e-02
%@ 2.24356713e+02 2.70322486e-02
%@ 2.26579158e+02 1.40067382e-01
%@ 2.28801603e+02 2.51300262e-01
%@ 2.31024048e+02 3.59299648e-01
%@ 2.33246493e+02 4.62675908e-01
%@ 2.35468938e+02 5.60098893e-01
%@ 2.37691383e+02 6.50315057e-01
%@ 2.39913828e+02 7.32163585e-01
%@ 2.42136273e+02 8.04591327e-01
%@ 2.44358717e+02 8.66666351e-01
%@ 2.46581162e+02 9.17589935e-01
%@ 2.48803607e+02 9.56706844e-01
%@ 2.51026052e+02 9.83513756e-01
%@ 2.53248497e+02 9.97665748e-01
%@ 2.55470942e+02 9.98980724e-01
%@ 2.57693387e+02 9.87441764e-01
%@ 2.59915832e+02 9.63197341e-01
%@ 2.62138277e+02 9.26559408e-01
%@ 2.64360721e+02 8.77999390e-01
%@ 2.66583166e+02 8.18142108e-01
%@ 2.68805611e+02 7.47757750e-01
%@ 2.71028056e+02 6.67751956e-01
%@ 2.73250501e+02 5.79154163e-01
%@ 2.75472946e+02 4.83104365e-01
%@ 2.77695391e+02 3.80838438e-01
%@ 2.79917836e+02 2.73672243e-01
%@ 2.82140281e+02 1.62984694e-01
%@ 2.84362725e+02 5.02000129e-02
%@ 2.86585170e+02 -6.32305946e-02
%@ 2.88807615e+02 -1.75847611e-01
%@ 2.91030060e+02 -2.86201987e-01
%@ 2.93252505e+02 -3.92873788e-01
%@ 2.95474950e+02 -4.94490461e-01
%@ 2.97697395e+02 -5.89744501e-01
%@ 2.99919840e+02 -6.77410269e-01
%@ 3.02142285e+02 -7.56359764e-01
%@ 3.04364729e+02 -8.25577140e-01
%@ 3.06587174e+02 -8.84171773e-01
%@ 3.08809619e+02 -9.31389723e-01
%@ 3.11032064e+02 -9.66623434e-01
%@ 3.13254509e+02 -9.89419552e-01
%@ 3.15476954e+02 -9.99484759e-01
%@ 3.17699399e+02 -9.96689545e-01
%@ 3.19921844e+02 -9.81069876e-01
%@ 3.22144289e+02 -9.52826732e-01
%@ 3.24366733e+02 -9.12323517e-01
%@ 3.26589178e+02 -8.60081389e-01
%@ 3.28811623e+02 -7.96772551e-01
%@ 3.31034068e+02 -7.23211600e-01
%@ 3.33256513e+02 -6.40345048e-01
%@ 3.35478958e+02 -5.64662739e-01
%@ 3.37701403e+02 -4.92045282e-01
%@ 3.39923848e+02 -4.15825728e-01
%@ 3.42146293e+02 -3.36562053e-01
%@ 3.44368737e+02 -2.54834521e-01
%@ 3.46591182e+02 -1.71241431e-01
%@ 3.48813627e+02 -8.63947400e-02
%@ 3.51036072e+02 -9.15582336e-04
%@ 3.53258517e+02 8.45702780e-02
%@ 3.55480962e+02 1.69437028e-01
%@ 3.57703407e+02 2.53063386e-01
%@ 3.59925852e+02 3.34837153e-01
%@ 3.62148297e+02 4.14159689e-01
%@ 3.64370741e+02 4.90450302e-01
%@ 3.66593186e+02 5.63150493e-01
%@ 3.68815631e+02 6.31728048e-01
%@ 3.71038076e+02 6.95680936e-01
%@ 3.73260521e+02 7.54540977e-01
%@ 3.75482966e+02 8.07877278e-01
%@ 3.77705411e+02 8.55299380e-01
%@ 3.79927856e+02 8.96460124e-01
%@ 3.82150301e+02 9.31058185e-01
%@ 3.84372745e+02 9.58840283e-01
%@ 3.86595190e+02 9.79603033e-01
%@ 3.88817635e+02 9.93194439e-01
%@ 3.91040080e+02 9.99515003e-01
%@ 3.93262525e+02 9.98518454e-01
%@ 3.95484970e+02 9.90212087e-01
%@ 3.97707415e+02 9.74656711e-01
%@ 3.99929860e+02 9.51966201e-01
%@ 4.02152305e+02 9.22306667e-01
%@ 4.04374749e+02 8.85895235e-01
%@ 4.06597194e+02 8.42998463e-01
%@ 4.08819639e+02 7.93930383e-01
%@ 4.11042084e+02 7.39050206e-01
%@ 4.13264529e+02 6.78759691e-01
%@ 4.15486974e+02 6.13500205e-01
%@ 4.17709419e+02 5.43749490e-01
%@ 4.19931864e+02 4.70018168e-01
%@ 4.22154309e+02 3.92846001e-01
%@ 4.24376754e+02 3.12797940e-01
%@ 4.26599198e+02 2.30459992e-01
%@ 4.28821643e+02 1.46434923e-01
%@ 4.31044088e+02 6.13378533e-02
%@ 4.33266533e+02 -2.42082501e-02
%@ 4.35488978e+02 -1.09577133e-01
%@ 4.37711423e+02 -1.94143839e-01
%@ 4.39933868e+02 -2.77289282e-01
%@ 4.42156313e+02 -3.58404785e-01
%@ 4.44378758e+02 -4.36896526e-01
%@ 4.46601202e+02 -4.88685853e-01
%@ 4.48823647e+02 -5.29903220e-01
%@ 4.51046092e+02 -5.69904822e-01
%@ 4.53268537e+02 -6.08598883e-01
%@ 4.55490982e+02 -6.45896627e-01
%@ 4.57713427e+02 -6.81712481e-01
%@ 4.59935872e+02 -7.15964273e-01
%@ 4.62158317e+02 -7.48573418e-01
%@ 4.64380762e+02 -7.79465100e-01
%@ 4.66603206e+02 -8.08568445e-01
%@ 4.68825651e+02 -8.35816679e-01
%@ 4.71048096e+02 -8.61147288e-01
%@ 4.73270541e+02 -8.84502154e-01
%@ 4.75492986e+02 -9.05827694e-01
%@ 4.77715431e+02 -9.25074981e-01
%@ 4.79937876e+02 -9.42199855e-01
%@ 4.82160321e+02 -9.57163027e-01
%@ 4.84382766e+02 -9.69930166e-01
%@ 4.86605210e+02 -9.80471981e-01
%@ 4.88827655e+02 -9.88764285e-01
%@ 4.91050100e+02 -9.94788053e-01
%@ 4.93272545e+02 -9.98529464e-01
%@ 4.95494990e+02 -9.99979936e-01
%@ 4.97717435e+02 -9.99136139e-01
%@ 4.99939880e+02 -9.96000010e-01
%@ 5.02162325e+02 -9.90578745e-01
%@ 5.04384770e+02 -9.82884780e-01
%@ 5.06607214e+02 -9.72935769e-01
%@ 5.08829659e+02 -9.60754538e-01
%@ 5.11052104e+02 -9.46369034e-01
%@ 5.13274549e+02 -9.29812262e-01
%@ 5.15496994e+02 -9.11122208e-01
%@ 5.17719439e+02 -8.90341754e-01
%@ 5.19941884e+02 -8.67518577e-01
%@ 5.22164329e+02 -8.42705039e-01
%@ 5.24386774e+02 -8.15958071e-01
%@ 5.26609218e+02 -7.87339039e-01
%@ 5.28831663e+02 -7.56913604e-01
%@ 5.31054108e+02 -7.24751572e-01
%@ 5.33276553e+02 -6.90926731e-01
%@ 5.35498998e+02 -6.55516688e-01
%@ 5.37721443e+02 -6.18602683e-01
%@ 5.39943888e+02 -5.80269410e-01
%@ 5.42166333e+02 -5.40604816e-01
%@ 5.44388778e+02 -4.99699905e-01
%@ 5.46611222e+02 -4.57648525e-01
%@ 5.48833667e+02 -4.14547156e-01
%@ 5.51056112e+02 -3.70494685e-01
%@ 5.53278557e+02 -3.25592184e-01
%@ 5.55501002e+02 -2.79942671e-01
%@ 5.57723447e+02 -1.69928782e-01
%@ 5.59945892e+02 -3.89295437e-02
%@ 5.62168337e+02 9.27451549e-02
%@ 5.64390782e+02 2.22810647e-01
%@ 5.66613226e+02 3.49010186e-01
%@ 5.68835671e+02 4.69154104e-01
%@ 5.71058116e+02 5.81157803e-01
%@ 5.73280561e+02 6.83077923e-01
%@ 5.75503006e+02 7.73146066e-01
%@ 5.77725451e+02 8.49799472e-01
%@ 5.79947896e+02 9.11708140e-01
%@ 5.82170341e+02 9.57797903e-01
%@ 5.84392786e+02 9.87269065e-01
%@ 5.86615230e+02 9.99610276e-01
%@ 5.88837675e+02 9.94607405e-01
%@ 5.91060120e+02 9.72347256e-01
%@ 5.93282565e+02 9.33216063e-01
%@ 5.95505010e+02 8.77892784e-01
%@ 5.97727455e+02 8.07337325e-01
%@ 5.99949900e+02 7.22773881e-01
%@ 6.02172345e+02 6.25669702e-01
%@ 6.04394790e+02 5.17709625e-01
%@ 6.06617234e+02 4.00766850e-01
%@ 6.08839679e+02 2.76870432e-01
%@ 6.11062124e+02 1.48170078e-01
%@ 6.13284569e+02 1.68988486e-02
%@ 6.15507014e+02 -1.14665590e-01
%@ 6.17729459e+02 -2.44240484e-01
%@ 6.19951904e+02 -3.69577600e-01
%@ 6.22174349e+02 -4.88502233e-01
%@ 6.24396794e+02 -5.98950940e-01
%@ 6.26619238e+02 -6.99007342e-01
%@ 6.28841683e+02 -7.86935378e-01
%@ 6.31064128e+02 -8.61209421e-01
%@ 6.33286573e+02 -9.20540755e-01
%@ 6.35509018e+02 -9.63899929e-01
%@ 6.37731463e+02 -9.90534627e-01
%@ 6.39953908e+02 -9.99982714e-01
%@ 6.42176353e+02 -9.92080257e-01
%@ 6.44398798e+02 -9.66964371e-01
%@ 6.46621242e+02 -9.25070837e-01
%@ 6.48843687e+02 -8.67126544e-01
%@ 6.51066132e+02 -7.94136874e-01
%@ 6.53288577e+02 -7.07368260e-01
%@ 6.55511022e+02 -6.08326209e-01
%@ 6.57733467e+02 -4.98729186e-01
%@ 6.59955912e+02 -3.80478791e-01
%@ 6.62178357e+02 -2.55626767e-01
%@ 6.64400802e+02 -1.26339404e-01
%@ 6.66623246e+02 5.14005482e-03
%@ 6.68845691e+02 8.29101075e-02
%@ 6.71068136e+02 1.49297288e-01
%@ 6.73290581e+02 2.15017477e-01
%@ 6.75513026e+02 2.79777064e-01
%@ 6.77735471e+02 3.43286734e-01
%@ 6.79957916e+02 4.05262753e-01
%@ 6.82180361e+02 4.65428242e-01
%@ 6.84402806e+02 5.23514408e-01
%@ 6.86625251e+02 5.79261749e-01
%@ 6.88847695e+02 6.32421209e-01
%@ 6.91070140e+02 6.82755298e-01
%@ 6.93292585e+02 7.30039144e-01
%@ 6.95515030e+02 7.74061506e-01
%@ 6.97737475e+02 8.14625711e-01
%@ 6.99959920e+02 8.51550536e-01
%@ 7.02182365e+02 8.84671018e-01
%@ 7.04404810e+02 9.13839190e-01
%@ 7.06627255e+02 9.38924742e-01
%@ 7.08849699e+02 9.59815602e-01
%@ 7.11072144e+02 9.76418440e-01
%@ 7.13294589e+02 9.88659082e-01
%@ 7.15517034e+02 9.96482842e-01
%@ 7.17739479e+02 9.99854767e-01
%@ 7.19961924e+02 9.98759793e-01
%@ 7.22184369e+02 9.93202812e-01
%@ 7.24406814e+02 9.83208649e-01
%@ 7.26629259e+02 9.68821955e-01
%@ 7.28851703e+02 9.50107001e-01
%@ 7.31074148e+02 9.27147400e-01
%@ 7.33296593e+02 9.00045723e-01
%@ 7.35519038e+02 8.68923048e-01
%@ 7.37741483e+02 8.33918418e-01
%@ 7.39963928e+02 7.95188218e-01
%@ 7.42186373e+02 7.52905476e-01
%@ 7.44408818e+02 7.07259092e-01
%@ 7.46631263e+02 6.58452995e-01
%@ 7.48853707e+02 6.06705227e-01
%@ 7.51076152e+02 5.52246975e-01
%@ 7.53298597e+02 4.95321532e-01
%@ 7.55521042e+02 4.36183218e-01
%@ 7.57743487e+02 3.75096233e-01
%@ 7.59965932e+02 3.12333488e-01
%@ 7.62188377e+02 2.48175379e-01
%@ 7.64410822e+02 1.82908533e-01
%@ 7.66633267e+02 1.16824536e-01
%@ 7.68855711e+02 5.02186188e-02
%@ 7.71078156e+02 -1.66116523e-02
%@ 7.73300601e+02 -8.33677100e-02
%@ 7.75523046e+02 -1.49751318e-01
%@ 7.77745491e+02 -2.15465906e-01
%@ 7.79967936e+02 -2.70489367e-01
%@ 7.82190381e+02 -3.23404314e-01
%@ 7.84412826e+02 -3.75326089e-01
%@ 7.86635271e+02 -4.26095241e-01
%@ 7.88857715e+02 -4.75555858e-01
%@ 7.91080160e+02 -5.23556047e-01
%@ 7.93302605e+02 -5.69948399e-01
%@ 7.95525050e+02 -6.14590445e-01
%@ 7.97747495e+02 -6.57345088e-01
%@ 7.99969940e+02 -6.98081030e-01
%@ 8.02192385e+02 -7.36673170e-01
%@ 8.04414830e+02 -7.73002994e-01
%@ 8.06637275e+02 -8.06958931e-01
%@ 8.08859719e+02 -8.38436704e-01
%@ 8.11082164e+02 -8.67339645e-01
%@ 8.13304609e+02 -8.93578993e-01
%@ 8.15527054e+02 -9.17074167e-01
%@ 8.17749499e+02 -9.37753013e-01
%@ 8.19971944e+02 -9.55552028e-01
%@ 8.22194389e+02 -9.70416550e-01
%@ 8.24416834e+02 -9.82300931e-01
%@ 8.26639279e+02 -9.91168674e-01
%@ 8.28861723e+02 -9.96992546e-01
%@ 8.31084168e+02 -9.99754662e-01
%@ 8.33306613e+02 -9.99446539e-01
%@ 8.35529058e+02 -9.96069125e-01
%@ 8.37751503e+02 -9.89632790e-01
%@ 8.39973948e+02 -9.80157300e-01
%@ 8.42196393e+02 -9.67671756e-01
%@ 8.44418838e+02 -9.52214500e-01
%@ 8.46641283e+02 -9.33833000e-01
%@ 8.48863727e+02 -9.12583708e-01
%@ 8.51086172e+02 -8.88531877e-01
%@ 8.53308617e+02 -8.61751373e-01
%@ 8.55531062e+02 -8.32324438e-01
%@ 8.57753507e+02 -8.00341440e-01
%@ 8.59975952e+02 -7.65900601e-01
%@ 8.62198397e+02 -7.29107687e-01
%@ 8.64420842e+02 -6.90075690e-01
%@ 8.66643287e+02 -6.48924475e-01
%@ 8.68865731e+02 -6.05780419e-01
%@ 8.71088176e+02 -5.60776016e-01
%@ 8.73310621e+02 -5.14049474e-01
%@ 8.75533066e+02 -4.65744291e-01
%@ 8.77755511e+02 -4.16008811e-01
%@ 8.79977956e+02 -3.64995771e-01
%@ 8.82200401e+02 -3.12861832e-01
%@ 8.84422846e+02 -2.59767097e-01
%@ 8.86645291e+02 -2.05874619e-01
%@ 8.88867735e+02 -1.51349902e-01
%@ 8.91090180e+02 -4.82935259e-02
%@ 8.93312625e+02 5.83259183e-02
%@ 8.95535070e+02 1.64282314e-01
%@ 8.97757515e+02 2.68371149e-01
%@ 8.99979960e+02 3.69409143e-01
%@ 9.02202405e+02 4.66247697e-01
%@ 9.04424850e+02 5.57785950e-01
%@ 9.06647295e+02 6.42983297e-01
%@ 9.08869739e+02 7.20871214e-01
%@ 9.11092184e+02 7.90564272e-01
%@ 9.13314629e+02 8.51270202e-01
%@ 9.15537074e+02 9.02298898e-01
%@ 9.17759519e+02 9.43070267e-01
%@ 9.19981964e+02 9.73120820e-01
%@ 9.22204409e+02 9.92108942e-01
%@ 9.24426854e+02 9.99818777e-01
%@ 9.26649299e+02 9.96162680e-01
%@ 9.28871743e+02 9.81182212e-01
%@ 9.31094188e+02 9.55047672e-01
%@ 9.33316633e+02 9.18056158e-01
%@ 9.35539078e+02 8.70628187e-01
%@ 9.37761523e+02 8.13302922e-01
%@ 9.39983968e+02 7.46732034e-01
%@ 9.42206413e+02 6.71672303e-01
%@ 9.44428858e+02 5.88977006e-01
%@ 9.46651303e+02 4.99586222e-01
%@ 9.48873747e+02 4.04516146e-01
%@ 9.51096192e+02 3.04847533e-01
%@ 9.53318637e+02 2.01713416e-01
%@ 9.55541082e+02 9.62862216e-02
%@ 9.57763527e+02 -1.02355535e-02
%@ 9.59985972e+02 -1.16640971e-01
%@ 9.62208417e+02 -2.21720414e-01
%@ 9.64430862e+02 -3.24279342e-01
%@ 9.66653307e+02 -4.23151864e-01
%@ 9.68875752e+02 -5.17214000e-01
%@ 9.71098196e+02 -6.05396450e-01
%@ 9.73320641e+02 -6.86696757e-01
%@ 9.75543086e+02 -7.60190701e-01
%@ 9.77765531e+02 -8.25042803e-01
%@ 9.79987976e+02 -8.80515824e-01
%@ 9.82210421e+02 -9.25979147e-01
%@ 9.84432866e+02 -9.60915946e-01
%@ 9.86655311e+02 -9.84929060e-01
%@ 9.88877756e+02 -9.97745507e-01
%@ 9.91100200e+02 -9.99219591e-01
%@ 9.93322645e+02 -9.89334554e-01
%@ 9.95545090e+02 -9.68202768e-01
%@ 9.97767535e+02 -9.36064461e-01
%@ 9.99989980e+02 -8.93284979e-01
%@ 1.00221242e+03 -8.40350641e-01
%@ 1.00443487e+03 -7.77863202e-01
%@ 1.00665731e+03 -7.06533021e-01
%@ 1.00887976e+03 -6.27170976e-01
%@ 1.01110220e+03 -5.40679257e-01
%@ 1.01332465e+03 -4.48041100e-01
%@ 1.01554709e+03 -3.50309615e-01
%@ 1.01776954e+03 -2.48595813e-01
%@ 1.01999198e+03 -1.44055976e-01
%@ 1.02221443e+03 -3.78785108e-02
%@ 1.02443687e+03 6.87295566e-02
%@ 1.02665932e+03 1.74556307e-01
%@ 1.02888176e+03 2.78398702e-01
%@ 1.03110421e+03 3.79076264e-01
%@ 1.03332665e+03 4.75444488e-01
%@ 1.03554910e+03 5.66407864e-01
%@ 1.03777154e+03 6.50932319e-01
%@ 1.03999399e+03 7.28056980e-01
%@ 1.04221643e+03 7.96905094e-01
%@ 1.04443888e+03 8.56693998e-01
%@ 1.04666132e+03 9.06744010e-01
%@ 1.04888377e+03 9.46486163e-01
%@ 1.05110621e+03 9.75468668e-01
%@ 1.05332866e+03 9.93362052e-01
%@ 1.05555110e+03 9.99962904e-01
%@ 1.05777355e+03 9.95196184e-01
%@ 1.05999599e+03 9.79116082e-01
%@ 1.06221844e+03 9.51905395e-01
%@ 1.06444088e+03 9.13873455e-01
%@ 1.06666333e+03 8.65452607e-01
%@ 1.06888577e+03 8.07193301e-01
%@ 1.07110822e+03 7.39757827e-01
%@ 1.07333066e+03 6.63912792e-01
%@ 1.07555311e+03 5.80520401e-01
%@ 1.07777555e+03 4.90528658e-01
%@ 1.07999800e+03 3.94960589e-01
%@ 1.08222044e+03 2.94902611e-01
%@ 1.08444289e+03 1.91492182e-01
%@ 1.08666533e+03 8.59048710e-02
%@ 1.08888778e+03 -2.06590056e-02
%@ 1.09111022e+03 -1.26988031e-01
%@ 1.09333267e+03 -2.31873457e-01
%@ 1.09555511e+03 -3.34122947e-01
%@ 1.09777756e+03 -4.32574131e-01
%@ 1.10000000e+03 -5.26107814e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/LayercountGood/layercount-test-10.txt__ -->
%@83.499045	0	0.1
%@84.584559	1	0.101
%@85.670072	2	0.102
%@86.755586	3	0.103
%@87.8411	4	0.104
%@88.926613	5	0.105
%@90.012127	6	0.106
%@91.097641	7	0.107
%@92.183155	8	0.108
%@93.268668	9	0.109
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/LayercountGood/layercount-test-25.txt__ -->
%@83.499045	0	0.1
%@84.584559	1	0.101
%@85.670072	2	0.102
%@86.755586	3	0.103
%@87.8411	4	0.104
%@88.926613	5	0.105
%@90.012127	6	0.106
%@91.097641	7	0.107
%@92.183155	8	0.108
%@93.268668	9	0.109
%@94.354182	10	0.11
%@95.439696	11	0.111
%@96.52521	12	0.112
%@97.610723	13	0.113
%@98.696237	14	0.114
%@99.781751	15	0.115
%@100.86726	16	0.116
%@101.95278	17	0.117
%@103.03829	18	0.118
%@104.12381	19	0.119
%@105.20932	20	0.12
%@106.29483	21	0.121
%@107.38035	22	0.122
%@108.46586	23	0.123
%@109.55137	24	0.124
%@110.63689	25	0.125
%@111.7224	26	0.126
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/LayercountGood/testagemodel_good.txt__ -->
%@1.00000000e+00 5.00000000e+01 1.25000000e+01
%@1.12000000e+02 1.32818654e+02 1.66409327e+01
%@2.23000000e+02 2.98991405e+02 2.49495702e+01
%@3.34000000e+02 4.34315766e+02 3.17157883e+01
%@4.45000000e+02 5.36365330e+02 3.68182665e+01
%@5.56000000e+02 5.93483112e+02 3.96741556e+01
%@6.67000000e+02 7.50656183e+02 4.75328092e+01
%@7.78000000e+02 8.30367294e+02 5.15183647e+01
%@8.89000000e+02 8.96451593e+02 5.48225796e+01
%@1.00000000e+03 1.02364107e+03 6.11820536e+01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/Reversals/isotope-test-reversals.txt__ -->
%@ -9.00000000e+00 9.73075993e-01
%@ -6.77755511e+00 9.56144420e-01
%@ -4.55511022e+00 9.35214420e-01
%@ -2.33266533e+00 9.10373516e-01
%@ -1.10220441e-01 8.81725590e-01
%@ 2.11222445e+00 8.49390443e-01
%@ 4.33466934e+00 8.13503293e-01
%@ 6.55711423e+00 7.74214215e-01
%@ 8.77955912e+00 7.31687510e-01
%@ 1.10020040e+01 6.86101015e-01
%@ 1.32244489e+01 6.37645366e-01
%@ 1.54468938e+01 5.86523196e-01
%@ 1.76693387e+01 5.32948289e-01
%@ 1.98917836e+01 4.77144685e-01
%@ 2.21142285e+01 4.19345746e-01
%@ 2.43366733e+01 3.59793177e-01
%@ 2.65591182e+01 2.98736016e-01
%@ 2.87815631e+01 2.36429593e-01
%@ 3.10040080e+01 1.73134463e-01
%@ 3.32264529e+01 1.09115315e-01
%@ 3.54488978e+01 4.46398659e-02
%@ 3.76713427e+01 -2.00222592e-02
%@ 3.98937876e+01 -8.46006548e-02
%@ 4.21162325e+01 -1.48825265e-01
%@ 4.43386774e+01 -2.12427515e-01
%@ 4.65611222e+01 -2.75141429e-01
%@ 4.87835671e+01 -3.36704751e-01
%@ 5.10060120e+01 -3.96860032e-01
%@ 5.32284569e+01 -4.55355714e-01
%@ 5.54509018e+01 -5.11947179e-01
%@ 5.76733467e+01 -5.66397770e-01
%@ 5.98957916e+01 -6.18479785e-01
%@ 6.21182365e+01 -6.67975426e-01
%@ 6.43406814e+01 -7.14677710e-01
%@ 6.65631263e+01 -7.58391338e-01
%@ 6.87855711e+01 -7.98933507e-01
%@ 7.10080160e+01 -8.36134675e-01
%@ 7.32304609e+01 -8.69839275e-01
%@ 7.54529058e+01 -8.99906359e-01
%@ 7.76753507e+01 -9.26210193e-01
%@ 7.98977956e+01 -9.48640778e-01
%@ 8.21202405e+01 -9.67104314e-01
%@ 8.43426854e+01 -9.81523589e-01
%@ 8.65651303e+01 -9.91838305e-01
%@ 8.87875752e+01 -9.98005327e-01
%@ 9.10100200e+01 -9.99998865e-01
%@ 9.32324649e+01 -9.97810584e-01
%@ 9.54549098e+01 -9.91449633e-01
%@ 9.76773547e+01 -9.80942614e-01
%@ 9.98997996e+01 -9.66333465e-01
%@ 1.02122244e+02 -9.47683279e-01
%@ 1.04344689e+02 -9.25070048e-01
%@ 1.06567134e+02 -8.98588336e-01
%@ 1.08789579e+02 -8.68348885e-01
%@ 1.11012024e+02 -8.34478151e-01
%@ 1.13234469e+02 -7.97117776e-01
%@ 1.15456914e+02 -7.56423994e-01
%@ 1.17679359e+02 -7.12566979e-01
%@ 1.19901804e+02 -6.65730135e-01
%@ 1.22124248e+02 -6.16109323e-01
%@ 1.24346693e+02 -5.63912051e-01
%@ 1.26569138e+02 -5.09356597e-01
%@ 1.28791583e+02 -4.52671103e-01
%@ 1.31014028e+02 -3.94092618e-01
%@ 1.33236473e+02 -3.33866107e-01
%@ 1.35458918e+02 -2.72243426e-01
%@ 1.37681363e+02 -2.09482271e-01
%@ 1.39903808e+02 -1.45845098e-01
%@ 1.42126253e+02 -8.15980263e-02
%@ 1.44348697e+02 -1.70097259e-02
%@ 1.46571142e+02 4.76497062e-02
%@ 1.48793587e+02 1.12109876e-01
%@ 1.51016032e+02 1.76101221e-01
%@ 1.53238477e+02 2.39356142e-01
%@ 1.55460922e+02 3.01610118e-01
%@ 1.57683367e+02 3.62602813e-01
%@ 1.59905812e+02 4.22079167e-01
%@ 1.62128257e+02 4.79790459e-01
%@ 1.64350701e+02 5.35495352e-01
%@ 1.66573146e+02 5.88960898e-01
%@ 1.68795591e+02 6.39963512e-01
%@ 1.71018036e+02 6.88289911e-01
%@ 1.73240481e+02 7.33738002e-01
%@ 1.75462926e+02 7.76117729e-01
%@ 1.77685371e+02 8.15251869e-01
%@ 1.79907816e+02 8.50976768e-01
%@ 1.82130261e+02 8.83143031e-01
%@ 1.84352705e+02 9.11616145e-01
%@ 1.86575150e+02 9.36277040e-01
%@ 1.88797595e+02 9.57022588e-01
%@ 1.91020040e+02 9.73766036e-01
%@ 1.93242485e+02 9.86437365e-01
%@ 1.95464930e+02 9.94983586e-01
%@ 1.97687375e+02 9.99368961e-01
%@ 1.99909820e+02 9.99575149e-01
%@ 2.02132265e+02 9.95601289e-01
%@ 2.04354709e+02 9.87463999e-01
%@ 2.06577154e+02 9.75197308e-01
%@ 2.08799599e+02 9.58852513e-01
%@ 2.11022044e+02 9.38497965e-01
%@ 2.13244489e+02 9.14218783e-01
%@ 2.15466934e+02 8.86116498e-01
%@ 2.17689379e+02 8.54308629e-01
%@ 2.19911824e+02 8.18928192e-01
%@ 2.22134269e+02 7.80123140e-01
%@ 2.24356713e+02 7.38055750e-01
%@ 2.26579158e+02 6.92901940e-01
%@ 2.28801603e+02 6.44850536e-01
%@ 2.31024048e+02 5.94102480e-01
%@ 2.33246493e+02 5.40869992e-01
%@ 2.35468938e+02 4.85375680e-01
%@ 2.37691383e+02 4.27851612e-01
%@ 2.39913828e+02 3.68538344e-01
%@ 2.42136273e+02 3.07683913e-01
%@ 2.44358717e+02 2.45542802e-01
%@ 2.46581162e+02 1.82374873e-01
%@ 2.48803607e+02 1.18444286e-01
%@ 2.51026052e+02 5.40183845e-02
%@ 2.53248497e+02 -1.06334121e-02
%@ 2.55470942e+02 -7.52407415e-02
%@ 2.57693387e+02 -1.39533427e-01
%@ 2.59915832e+02 -2.03242609e-01
%@ 2.62138277e+02 -2.66101866e-01
%@ 2.64360721e+02 -3.27848331e-01
%@ 2.66583166e+02 -3.88223792e-01
%@ 2.68805611e+02 -4.46975769e-01
%@ 2.71028056e+02 -5.03858572e-01
%@ 2.73250501e+02 -5.58634327e-01
%@ 2.75472946e+02 -6.11073970e-01
%@ 2.77695391e+02 -6.60958210e-01
%@ 2.79917836e+02 -7.08078438e-01
%@ 2.82140281e+02 -7.52237607e-01
%@ 2.84362725e+02 -7.93251049e-01
%@ 2.86585170e+02 -8.30947255e-01
%@ 2.88807615e+02 -8.65168585e-01
%@ 2.91030060e+02 -8.95771932e-01
%@ 2.93252505e+02 -9.22629318e-01
%@ 2.95474950e+02 -9.45628429e-01
%@ 2.97697395e+02 -9.64673089e-01
%@ 2.99919840e+02 -9.79683654e-01
%@ 3.02142285e+02 -9.90597354e-01
%@ 3.04364729e+02 -9.97368550e-01
%@ 3.06587174e+02 -9.99968926e-01
%@ 3.08809619e+02 -9.98387606e-01
%@ 3.11032064e+02 -9.92631205e-01
%@ 3.13254509e+02 -9.82723794e-01
%@ 3.15476954e+02 -9.68706805e-01
%@ 3.17699399e+02 -9.50638853e-01
%@ 3.19921844e+02 -9.28595497e-01
%@ 3.22144289e+02 -9.02668917e-01
%@ 3.24366733e+02 -8.72967533e-01
%@ 3.26589178e+02 -8.39615553e-01
%@ 3.28811623e+02 -8.02752448e-01
%@ 3.31034068e+02 -7.62532372e-01
%@ 3.33256513e+02 -7.19123520e-01
%@ 3.35478958e+02 -6.72707420e-01
%@ 3.37701403e+02 -6.23478175e-01
%@ 3.39923848e+02 -5.71641653e-01
%@ 3.42146293e+02 -5.17414626e-01
%@ 3.44368737e+02 -4.61023863e-01
%@ 3.46591182e+02 -4.02705178e-01
%@ 3.48813627e+02 -3.42702450e-01
%@ 3.51036072e+02 -2.81266602e-01
%@ 3.53258517e+02 -2.18654545e-01
%@ 3.55480962e+02 -1.55128114e-01
%@ 3.57703407e+02 -9.09529637e-02
%@ 3.59925852e+02 -2.63974644e-02
%@ 3.62148297e+02 3.82684245e-02
%@ 3.64370741e+02 1.02774282e-01
%@ 3.66593186e+02 1.66850355e-01
%@ 3.68815631e+02 2.30228689e-01
%@ 3.71038076e+02 2.92644247e-01
%@ 3.73260521e+02 3.53836018e-01
%@ 3.75482966e+02 4.13548109e-01
%@ 3.77705411e+02 4.71530814e-01
%@ 3.79927856e+02 5.27541661e-01
%@ 3.82150301e+02 5.81346420e-01
%@ 3.84372745e+02 6.32720090e-01
%@ 3.86595190e+02 6.81447837e-01
%@ 3.88817635e+02 7.27325887e-01
%@ 3.91040080e+02 7.70162389e-01
%@ 3.93262525e+02 8.09778206e-01
%@ 3.95484970e+02 8.46007673e-01
%@ 3.97707415e+02 8.78699284e-01
%@ 3.99929860e+02 9.07716329e-01
%@ 4.02152305e+02 9.32937463e-01
%@ 4.04374749e+02 9.54257216e-01
%@ 4.06597194e+02 9.71586433e-01
%@ 4.08819639e+02 9.84852646e-01
%@ 4.11042084e+02 9.94000378e-01
%@ 4.13264529e+02 9.98991374e-01
%@ 4.15486974e+02 9.99804764e-01
%@ 4.17709419e+02 9.96437145e-01
%@ 4.19931864e+02 9.88902601e-01
%@ 4.22154309e+02 9.77232640e-01
%@ 4.24376754e+02 9.61476063e-01
%@ 4.26599198e+02 9.41698762e-01
%@ 4.28821643e+02 9.17983442e-01
%@ 4.31044088e+02 8.90429275e-01
%@ 4.33266533e+02 8.59151490e-01
%@ 4.35488978e+02 8.24280884e-01
%@ 4.37711423e+02 7.85963280e-01
%@ 4.39933868e+02 7.44358915e-01
%@ 4.42156313e+02 6.99641772e-01
%@ 4.44378758e+02 6.51998849e-01
%@ 4.46601202e+02 6.01629382e-01
%@ 4.48823647e+02 5.48744006e-01
%@ 4.51046092e+02 4.93563878e-01
%@ 4.53268537e+02 4.36319754e-01
%@ 4.55490982e+02 3.77251016e-01
%@ 4.57713427e+02 3.16604681e-01
%@ 4.59935872e+02 2.54634360e-01
%@ 4.62158317e+02 1.91599204e-01
%@ 4.64380762e+02 1.27762813e-01
%@ 4.66603206e+02 6.33921401e-02
%@ 4.68825651e+02 -1.24362733e-03
%@ 4.71048096e+02 -6.58741941e-02
%@ 4.73270541e+02 -1.30229287e-01
%@ 4.75492986e+02 -1.94039783e-01
%@ 4.77715431e+02 -2.57038839e-01
%@ 4.79937876e+02 -3.18963004e-01
%@ 4.82160321e+02 -3.79553321e-01
%@ 4.84382766e+02 -4.38556413e-01
%@ 4.86605210e+02 -4.95725539e-01
%@ 4.88827655e+02 -5.50821628e-01
%@ 4.91050100e+02 -6.03614277e-01
%@ 4.93272545e+02 -6.53882717e-01
%@ 4.95494990e+02 -7.01416734e-01
%@ 4.97717435e+02 -7.46017550e-01
%@ 4.99939880e+02 -7.87498650e-01
%@ 5.02162325e+02 -8.25686570e-01
%@ 5.04384770e+02 -8.60421613e-01
%@ 5.06607214e+02 -8.91558524e-01
%@ 5.08829659e+02 -9.18967093e-01
%@ 5.11052104e+02 -9.42532703e-01
%@ 5.13274549e+02 -9.62156807e-01
%@ 5.15496994e+02 -9.77757339e-01
%@ 5.17719439e+02 -9.89269062e-01
%@ 5.19941884e+02 -9.96643835e-01
%@ 5.22164329e+02 -9.99850818e-01
%@ 5.24386774e+02 -9.98876600e-01
%@ 5.26609218e+02 -9.93725256e-01
%@ 5.28831663e+02 -9.84418326e-01
%@ 5.31054108e+02 -9.70994732e-01
%@ 5.33276553e+02 -9.53510608e-01
%@ 5.35498998e+02 -9.32039070e-01
%@ 5.37721443e+02 -9.06669908e-01
%@ 5.39943888e+02 -8.77509212e-01
%@ 5.42166333e+02 -8.44678926e-01
%@ 5.44388778e+02 -8.08316340e-01
%@ 5.46611222e+02 -7.68573518e-01
%@ 5.48833667e+02 -7.25616655e-01
%@ 5.51056112e+02 -6.79625391e-01
%@ 5.53278557e+02 -6.30792053e-01
%@ 5.55501002e+02 -5.79320853e-01
%@ 5.57723447e+02 -5.25427035e-01
%@ 5.59945892e+02 -4.69335973e-01
%@ 5.62168337e+02 -4.11282230e-01
%@ 5.64390782e+02 -3.51508578e-01
%@ 5.66613226e+02 -2.90264977e-01
%@ 5.68835671e+02 -2.27807540e-01
%@ 5.71058116e+02 -1.64397452e-01
%@ 5.73280561e+02 -1.00299882e-01
%@ 5.75503006e+02 -3.57828754e-02
%@ 5.77725451e+02 2.88837687e-02
%@ 5.79947896e+02 9.34296259e-02
%@ 5.82170341e+02 1.57584777e-01
%@ 5.84392786e+02 2.21080936e-01
%@ 5.86615230e+02 2.83652573e-01
%@ 5.88837675e+02 3.45038025e-01
%@ 5.91060120e+02 4.04980589e-01
%@ 5.93282565e+02 4.63229594e-01
%@ 5.95505010e+02 5.19541455e-01
%@ 5.97727455e+02 5.73680684e-01
%@ 5.99949900e+02 6.25420882e-01
%@ 6.02172345e+02 6.74545678e-01
%@ 6.04394790e+02 7.20849644e-01
%@ 6.06617234e+02 7.64139142e-01
%@ 6.08839679e+02 8.04233144e-01
%@ 6.11062124e+02 8.40963985e-01
%@ 6.13284569e+02 8.74178061e-01
%@ 6.15507014e+02 9.03736478e-01
%@ 6.17729459e+02 9.29515628e-01
%@ 6.19951904e+02 9.51407706e-01
%@ 6.22174349e+02 9.69321164e-01
%@ 6.24396794e+02 9.83181091e-01
%@ 6.26619238e+02 9.92929527e-01
%@ 6.28841683e+02 9.98525705e-01
%@ 6.31064128e+02 9.99946225e-01
%@ 6.33286573e+02 9.97185144e-01
%@ 6.35509018e+02 9.90254010e-01
%@ 6.37731463e+02 9.79181808e-01
%@ 6.39953908e+02 9.64014838e-01
%@ 6.42176353e+02 9.44816528e-01
%@ 6.44398798e+02 9.21667161e-01
%@ 6.46621242e+02 8.94663543e-01
%@ 6.48843687e+02 8.63918599e-01
%@ 6.51066132e+02 8.29560899e-01
%@ 6.53288577e+02 7.91734121e-01
%@ 6.55511022e+02 7.50596449e-01
%@ 6.57733467e+02 7.06319915e-01
%@ 6.59955912e+02 6.59089675e-01
%@ 6.62178357e+02 6.09103237e-01
%@ 6.64400802e+02 5.56569636e-01
%@ 6.66623246e+02 5.01708559e-01
%@ 6.68845691e+02 4.44749424e-01
%@ 6.71068136e+02 3.85930426e-01
%@ 6.73290581e+02 3.25497533e-01
%@ 6.75513026e+02 2.63703468e-01
%@ 6.77735471e+02 2.00806640e-01
%@ 6.79957916e+02 1.37070075e-01
%@ 6.82180361e+02 7.27603064e-02
%@ 6.84402806e+02 8.14626706e-03
%@ 6.86625251e+02 -5.65018386e-02
%@ 6.88847695e+02 -1.20913663e-01
%@ 6.91070140e+02 -1.84819849e-01
%@ 6.93292585e+02 -2.47953149e-01
%@ 6.95515030e+02 -3.10049554e-01
%@ 6.97737475e+02 -3.70849385e-01
%@ 6.99959920e+02 -4.30098389e-01
%@ 7.02182365e+02 -4.87548798e-01
%@ 7.04404810e+02 -5.42960362e-01
%@ 7.06627255e+02 -5.96101362e-01
%@ 7.08849699e+02 -6.46749570e-01
%@ 7.11072144e+02 -6.94693185e-01
%@ 7.13294589e+02 -7.39731715e-01
%@ 7.15517034e+02 -7.81676817e-01
%@ 7.17739479e+02 -8.20353083e-01
%@ 7.19961924e+02 -8.55598776e-01
%@ 7.22184369e+02 -8.87266505e-01
%@ 7.24406814e+02 -9.15223842e-01
%@ 7.26629259e+02 -9.39353872e-01
%@ 7.28851703e+02 -9.59555690e-01
%@ 7.31074148e+02 -9.75744814e-01
%@ 7.33296593e+02 -9.87853544e-01
%@ 7.35519038e+02 -9.95831244e-01
%@ 7.37741483e+02 -9.99644552e-01
%@ 7.39963928e+02 -9.99277522e-01
%@ 7.42186373e+02 -9.94731688e-01
%@ 7.44408818e+02 -9.86026061e-01
%@ 7.46631263e+02 -9.73197046e-01
%@ 7.48853707e+02 -9.56298291e-01
%@ 7.51076152e+02 -9.35400465e-01
%@ 7.53298597e+02 -9.10590958e-01
%@ 7.55521042e+02 -8.81973519e-01
%@ 7.57743487e+02 -8.49667822e-01
%@ 7.59965932e+02 -8.13808963e-01
%@ 7.62188377e+02 -7.74546897e-01
%@ 7.64410822e+02 -7.32045812e-01
%@ 7.66633267e+02 -6.86483440e-01
%@ 7.68855711e+02 -6.38050314e-01
%@ 7.71078156e+02 -5.86948974e-01
%@ 7.73300601e+02 -5.33393116e-01
%@ 7.75523046e+02 -4.77606702e-01
%@ 7.77745491e+02 -4.19823020e-01
%@ 7.79967936e+02 -3.60283712e-01
%@ 7.82190381e+02 -2.99237760e-01
%@ 7.84412826e+02 -2.36940449e-01
%@ 7.86635271e+02 -1.73652294e-01
%@ 7.88857715e+02 -1.09637956e-01
%@ 7.91080160e+02 -4.51651313e-02
%@ 7.93302605e+02 1.94965662e-02
%@ 7.95525050e+02 8.40767325e-02
%@ 7.97747495e+02 1.48305305e-01
%@ 7.99969940e+02 2.11913690e-01
%@ 8.02192385e+02 2.74635889e-01
%@ 8.04414830e+02 3.36209610e-01
%@ 8.06637275e+02 3.96377360e-01
%@ 8.08859719e+02 4.54887530e-01
%@ 8.11082164e+02 5.11495441e-01
%@ 8.13304609e+02 5.65964366e-01
%@ 8.15527054e+02 6.18066529e-01
%@ 8.17749499e+02 6.67584045e-01
%@ 8.19971944e+02 7.14309842e-01
%@ 8.22194389e+02 7.58048520e-01
%@ 8.24416834e+02 7.98617172e-01
%@ 8.26639279e+02 8.35846148e-01
%@ 8.28861723e+02 8.69579761e-01
%@ 8.31084168e+02 8.99676944e-01
%@ 8.33306613e+02 9.26011836e-01
%@ 8.35529058e+02 9.48474309e-01
%@ 8.37751503e+02 9.66970429e-01
%@ 8.39973948e+02 9.81422847e-01
%@ 8.42196393e+02 9.91771128e-01
%@ 8.44418838e+02 9.97971995e-01
%@ 8.46641283e+02 9.99999519e-01
%@ 8.48863727e+02 9.97845220e-01
%@ 8.51086172e+02 9.91518107e-01
%@ 8.53308617e+02 9.81044640e-01
%@ 8.55531062e+02 9.66468615e-01
%@ 8.57753507e+02 9.47850989e-01
%@ 8.59975952e+02 9.25269615e-01
%@ 8.62198397e+02 8.98818927e-01
%@ 8.64420842e+02 8.68609535e-01
%@ 8.66643287e+02 8.34767770e-01
%@ 8.68865731e+02 7.97435153e-01
%@ 8.71088176e+02 7.56767802e-01
%@ 8.73310621e+02 7.12935781e-01
%@ 8.75533066e+02 6.66122387e-01
%@ 8.77755511e+02 6.16523387e-01
%@ 8.79977956e+02 5.64346193e-01
%@ 8.82200401e+02 5.09809003e-01
%@ 8.84422846e+02 4.53139881e-01
%@ 8.86645291e+02 3.94575807e-01
%@ 8.88867735e+02 3.34361687e-01
%@ 8.91090180e+02 2.72749324e-01
%@ 8.93312625e+02 2.09996372e-01
%@ 8.95535070e+02 1.46365252e-01
%@ 8.97757515e+02 8.21220574e-02
%@ 8.99979960e+02 1.75354432e-02
%@ 9.02202405e+02 -4.71245012e-02
%@ 9.04424850e+02 -1.11587379e-01
%@ 9.06647295e+02 -1.75583618e-01
%@ 9.08869739e+02 -2.38845597e-01
%@ 9.11092184e+02 -3.01108766e-01
%@ 9.13314629e+02 -3.62112751e-01
%@ 9.15537074e+02 -4.21602443e-01
%@ 9.17759519e+02 -4.79329069e-01
%@ 9.19981964e+02 -5.35051224e-01
%@ 9.22204409e+02 -5.88535888e-01
%@ 9.24426854e+02 -6.39559399e-01
%@ 9.26649299e+02 -6.87908385e-01
%@ 9.28871743e+02 -7.33380658e-01
%@ 9.31094188e+02 -7.75786062e-01
%@ 9.33316633e+02 -8.14947264e-01
%@ 9.35539078e+02 -8.50700500e-01
%@ 9.37761523e+02 -8.82896256e-01
%@ 9.39983968e+02 -9.11399894e-01
%@ 9.42206413e+02 -9.36092218e-01
%@ 9.44428858e+02 -9.56869968e-01
%@ 9.46651303e+02 -9.73646256e-01
%@ 9.48873747e+02 -9.86350926e-01
%@ 9.51096192e+02 -9.94930849e-01
%@ 9.53318637e+02 -9.99350146e-01
%@ 9.55541082e+02 -9.99590336e-01
%@ 9.57763527e+02 -9.95650414e-01
%@ 9.59985972e+02 -9.87546857e-01
%@ 9.62208417e+02 -9.75313552e-01
%@ 9.64430862e+02 -9.59001657e-01
%@ 9.66653307e+02 -9.38679384e-01
%@ 9.68875752e+02 -9.14431720e-01
%@ 9.71098196e+02 -8.86360062e-01
%@ 9.73320641e+02 -8.54581802e-01
%@ 9.75543086e+02 -8.19229830e-01
%@ 9.77765531e+02 -7.80451983e-01
%@ 9.79987976e+02 -7.38410423e-01
%@ 9.82210421e+02 -6.93280960e-01
%@ 9.84432866e+02 -6.45252317e-01
%@ 9.86655311e+02 -5.94525342e-01
%@ 9.88877756e+02 -5.41312167e-01
%@ 9.91100200e+02 -4.85835319e-01
%@ 9.93322645e+02 -4.28326793e-01
%@ 9.95545090e+02 -3.69027079e-01
%@ 9.97767535e+02 -3.08184159e-01
%@ 9.99989980e+02 -2.46052466e-01
%@ 1.00221242e+03 -1.82891826e-01
%@ 1.00443487e+03 -1.18966364e-01
%@ 1.00665731e+03 -5.45434050e-02
%@ 1.00887976e+03 1.01076446e-02
%@ 1.01110220e+03 7.47164259e-02
%@ 1.01332465e+03 1.39012756e-01
%@ 1.01554709e+03 2.02727759e-01
%@ 1.01776954e+03 2.65594991e-01
%@ 1.01999198e+03 3.27351550e-01
%@ 1.02221443e+03 3.87739183e-01
%@ 1.02443687e+03 4.46505359e-01
%@ 1.02665932e+03 5.03404327e-01
%@ 1.02888176e+03 5.58198147e-01
%@ 1.03110421e+03 6.10657680e-01
%@ 1.03332665e+03 6.60563550e-01
%@ 1.03554910e+03 7.07707058e-01
%@ 1.03777154e+03 7.51891060e-01
%@ 1.03999399e+03 7.92930786e-01
%@ 1.04221643e+03 8.30654613e-01
%@ 1.04443888e+03 8.64904789e-01
%@ 1.04666132e+03 8.95538085e-01
%@ 1.04888377e+03 9.22426397e-01
%@ 1.05110621e+03 9.45457284e-01
%@ 1.05332866e+03 9.64534434e-01
%@ 1.05555110e+03 9.79578071e-01
%@ 1.05777355e+03 9.90525284e-01
%@ 1.05999599e+03 9.97330293e-01
%@ 1.06221844e+03 9.99964642e-01
%@ 1.06444088e+03 9.98417315e-01
%@ 1.06666333e+03 9.92694781e-01
%@ 1.06888577e+03 9.82820972e-01
%@ 1.07110822e+03 9.68837177e-01
%@ 1.07333066e+03 9.50801876e-01
%@ 1.07555311e+03 9.28790488e-01
%@ 1.07777555e+03 9.02895061e-01
%@ 1.07999800e+03 8.73223885e-01
%@ 1.08222044e+03 8.39901039e-01
%@ 1.08444289e+03 8.03065875e-01
%@ 1.08666533e+03 7.62872430e-01
%@ 1.08888778e+03 7.19488787e-01
%@ 1.09111022e+03 6.73096367e-01
%@ 1.09333267e+03 6.23889177e-01
%@ 1.09555511e+03 5.72072991e-01
%@ 1.09777756e+03 5.17864497e-01
%@ 1.10000000e+03 4.61490384e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/Reversals/testagemodel_reversals.txt__ -->
%@1.00000000e+00 5.00000000e+01 1.25000000e+01
%@1.12000000e+02 2.07852087e+02 2.03926044e+01
%@2.23000000e+02 3.45021477e+02 2.72510739e+01
%@3.34000000e+02 2.45021477e+02 2.22510739e+01
%@4.45000000e+02 4.04391682e+02 3.02195841e+01
%@5.56000000e+02 4.73129957e+02 3.36564978e+01
%@6.67000000e+02 4.63129957e+02 3.31564978e+01
%@7.78000000e+02 5.76497601e+02 3.88248800e+01
%@8.89000000e+02 6.44954327e+02 4.22477163e+01
%@1.00000000e+03 7.44071945e+02 4.72035973e+01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/multiproxy/README.txt__ -->
%@######################## Readme COPRA_O1 (26.9.2012) #########################################
%@
%@
%@COPRA_O1 is a depth-age modeling program that transforms age-uncertainties to proxy-uncertainties. In its present form, it runs in both Octave and Matlab. To switch between the two, a variable has to be set in the main copra_o.m file (more instructions in the main file).
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ PROGRAM REQUIREMENTS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
%@
%@In Octave, COPRA_O1 requires Octave 3.6 or later. It was tested for Ubuntu Precise, with the required packages installed from the 
%@https://launchpad.net/~mvanderkolff/+archive/octave-3.6 and it requires the package octave-signal (Version 1.1.2 --> in PPA of M.v.d.Kolff)
%@
%@COPRA_O1 was also tested in Matlab R2010/2011/2012. It requires the statistics toolbox.
%@
%@Some warnings (regarding, e.g., the use of single quotes '', which are supported, but not default in Octave) are currently unavoidable.
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ TO RUN @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
%@To run COPRA, start matlab, open and execute the script 'example_script.m'. For a start, use the test datasets in the folder /data/test/. More instructions are found in the example script and in the header of COPRA_O1.m.
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ TEST DATA @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
%@In the folder Copra_O1/data/test/ you find three types of test datasets. 
%@
%@* With a hiatus
%@
%@* With reversals (tractable and non-tractable) 
%@
%@* Without complications but with an additional layer counting chronology. (GoodLayercounting). Note that including layercounting data will take computation time!
%@
%@For each file you will find an isotope and an agemodel file in the subfolders.
%@For the 'good' case there is also layer counting data. 
%@
%@The datasets were generated using the file testagemodel.m.
%@Growth rates of 0.5-1.5mm/yr and a core length of 1m were assumed. The core was sampled at 10 equidistant depths for 'radiometric dating'. The isotope signal is a sinusoid with a period of 150 years (no noise).
%@
%@The agemodels are not commented.
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ DATA REQUIREMENTS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@Data should be provided in the correct format (e.g. can be exported from spreadsheet)
%@* The dating table:
%@  -> as a .csv or .txt file without column headers (the command C=load('agemodelfile.csv') should not throw an error!) and in the order 'depth', 'age', 'ageerror'
%@	
%@* The proxy data should contain the columns 1) 'depth' and 2) 'proxy value' without (or with commented) column headers, so that it can be read using the matlab LOAD command. Depths should be monotonous and unique (no double depths), no NaN values.
%@
%@* The layer counting data should be provided in columns of the order 1) 'depth', 2) 'age', 3) 'deptherror', again, in a format that can be LOADed in Matlab or Octave. The age in the layer counting is to be determined *relative* to the first layer (first layer has age zero!).
%@
%@@@@@@@@@@@@@@@@@@@@@@@@@ COPYRIGHT @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@
%@@ This program is in developmental stage and is not to be redistributed
%@@ and/ or modified.
%@@ Copyright (c) 2012:
%@@ Kira Rehfeld, Bedartha Goswami, Norbert Marwan
%@@ Potsdam Institute for Climate Impact Research, Germany
%@@ Sebastian Breitenbach, ETH Zürich, Switzerland
%@@ http://www.pik-potsdam.de
%@
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/multiproxy/isotope-test-good_multiproxy.txt__ -->
%@  -9.0000000e+00   9.9983751e-01   6.8772990e-01
%@  -1.5570470e+00   9.2325735e-01   1.9270252e-01
%@   5.8859060e+00   7.1748150e-01  -3.6210606e-01
%@   1.3328859e+01   4.1130513e-01  -8.0458016e-01
%@   2.0771812e+01   4.7572930e-02  -9.9745308e-01
%@   2.8214765e+01  -3.2281637e-01  -8.8089074e-01
%@   3.5657718e+01  -6.4803249e-01  -4.9105375e-01
%@   4.3100671e+01  -8.8256640e-01   5.1120579e-02
%@   5.0543624e+01  -9.9359871e-01   5.7743600e-01
%@   5.7986577e+01  -9.6559213e-01   9.2461613e-01
%@   6.5429530e+01  -8.0246577e-01   9.8495687e-01
%@   7.2872483e+01  -5.2704664e-01   7.3973900e-01
%@   8.0315436e+01  -1.7787544e-01   2.6503532e-01
%@   8.7758389e+01   1.9618670e-01  -2.9188904e-01
%@   9.5201342e+01   5.4279553e-01  -7.5826201e-01
%@   1.0264430e+02   8.1344846e-01  -9.8940287e-01
%@   1.1008725e+02   9.7027177e-01  -9.1360586e-01
%@   1.1753020e+02   9.8856742e-01  -5.2979860e-01
%@   1.2497315e+02   8.5047661e-01   4.5444593e-02
%@   1.3241611e+02   5.7642082e-01   6.0461592e-01
%@   1.3985906e+02   2.1021312e-01   9.4995971e-01
%@   1.4730201e+02  -1.8960117e-01   9.5934223e-01
%@   1.5474497e+02  -5.5910409e-01   6.2944526e-01
%@   1.6218792e+02  -8.3922351e-01   7.6939653e-02
%@   1.6963087e+02  -9.8517697e-01  -5.0277631e-01
%@   1.7707383e+02  -9.7363101e-01  -9.0468118e-01
%@   1.8451678e+02  -8.0643149e-01  -9.8663791e-01
%@   1.9195973e+02  -5.1030844e-01  -7.1966180e-01
%@   1.9940268e+02  -1.3260281e-01  -1.9817122e-01
%@   2.0684564e+02   2.6630192e-01   3.9340429e-01
%@   2.1428859e+02   6.2263318e-01   8.4584905e-01
%@   2.2173154e+02   8.7942461e-01   9.9915215e-01
%@   2.2917450e+02   9.7746477e-01   8.9321538e-01
%@   2.3661745e+02   9.9892933e-01   6.5635724e-01
%@   2.4406040e+02   9.5377003e-01   3.2169023e-01
%@   2.5150336e+02   8.4499876e-01  -6.0914326e-02
%@   2.5894631e+02   6.7987006e-01  -4.3444157e-01
%@   2.6638926e+02   4.6939723e-01  -7.4322932e-01
%@   2.7383221e+02   2.2761782e-01  -9.4126271e-01
%@   2.8127517e+02  -2.9342623e-02  -9.9903127e-01
%@   2.8871812e+02  -2.8434605e-01  -9.0792644e-01
%@   2.9616107e+02  -5.2038494e-01  -6.8152447e-01
%@   3.0360403e+02  -7.2171661e-01  -3.5356327e-01
%@   3.1104698e+02  -8.7491318e-01   2.7085132e-02
%@   3.1848993e+02  -9.6975717e-01   4.0369737e-01
%@   3.2593289e+02  -9.9992293e-01   7.2015154e-01
%@   3.3337584e+02  -9.6339855e-01   9.2929035e-01
%@   3.4081879e+02  -7.6684141e-01   9.6640586e-01
%@   3.4826174e+02  -4.1974499e-01   6.0498459e-01
%@   3.5570470e+02   7.5766403e-03  -1.1364825e-02
%@   3.6314765e+02   4.3345016e-01  -6.2292534e-01
%@   3.7059060e+02   7.7647902e-01  -9.7199783e-01
%@   3.7803356e+02   9.7110064e-01  -9.1149030e-01
%@   3.8547651e+02   9.8011728e-01  -4.6689936e-01
%@   3.9291946e+02   8.0180562e-01   1.7443342e-01
%@   4.0036242e+02   4.7024609e-01   7.4226353e-01
%@   4.0780537e+02   4.8809144e-02   9.9731894e-01
%@   4.1524832e+02  -3.8195662e-01   8.3212453e-01
%@   4.2269128e+02  -7.3971960e-01   3.1628983e-01
%@   4.3013423e+02  -9.5610111e-01  -3.3282294e-01
%@   4.3757718e+02  -9.8974449e-01  -8.4169092e-01
%@   4.4502013e+02  -8.3437621e-01  -9.9592607e-01
%@   4.5246309e+02  -6.0623364e-01  -8.2880814e-01
%@   4.5990604e+02  -3.1041747e-01  -4.5595794e-01
%@   4.6734899e+02   2.0050455e-02   3.0073163e-02
%@   4.7479195e+02   3.4828016e-01   5.0863931e-01
%@   4.8223490e+02   6.3763151e-01   8.6094762e-01
%@   4.8967785e+02   8.5580433e-01   9.9954580e-01
%@   4.9712081e+02   9.7844409e-01   8.9003008e-01
%@   5.0456376e+02   9.9186057e-01   5.5958517e-01
%@   5.1200671e+02   8.9455610e-01   9.0236321e-02
%@   5.1944966e+02   6.9739272e-01  -4.0151159e-01
%@   5.2689262e+02   4.2237970e-01  -7.9359363e-01
%@   5.3433557e+02   1.0021662e-01  -9.8868458e-01
%@   5.4177852e+02  -2.3313360e-01  -9.3835768e-01
%@   5.4922148e+02  -5.4045921e-01  -6.5510540e-01
%@   5.5666443e+02  -7.8247404e-01  -2.2101259e-01
%@   5.6410738e+02  -9.1041056e-01   1.4510266e-01
%@   5.7155034e+02  -9.8368671e-01   4.9173926e-01
%@   5.7899329e+02  -9.9790306e-01   7.7236454e-01
%@   5.8643624e+02  -9.5220606e-01   9.4930725e-01
%@   5.9387919e+02  -8.4933932e-01   9.9881450e-01
%@   6.0132215e+02  -6.9547888e-01   9.1424042e-01
%@   6.0876510e+02  -4.9986242e-01   7.0693827e-01
%@   6.1620805e+02  -2.7423459e-01   4.0473639e-01
%@   6.2365101e+02  -3.2141924e-02   4.8202505e-02
%@   6.3109396e+02   2.1188052e-01  -3.1480210e-01
%@   6.3853691e+02   4.4318182e-01  -6.3554753e-01
%@   6.4597987e+02   6.4787481e-01  -8.7097675e-01
%@   6.5342282e+02   8.1366988e-01  -9.8948565e-01
%@   6.6086577e+02   9.3061283e-01  -9.7516551e-01
%@   6.6830872e+02   9.9153334e-01  -8.3090281e-01
%@   6.7575168e+02   9.9408004e-01  -5.8274338e-01
%@   6.8319463e+02   9.4007355e-01  -2.6043490e-01
%@   6.9063758e+02   8.3258631e-01   9.5011678e-02
%@   6.9808054e+02   6.7773326e-01   4.3836884e-01
%@   7.0552349e+02   4.8432398e-01   7.2594735e-01
%@   7.1296644e+02   2.6336152e-01   9.2115535e-01
%@   7.2040940e+02   2.7416438e-02   9.9915429e-01
%@   7.2785235e+02  -2.1008837e-01   9.5001949e-01
%@   7.3529530e+02  -4.3564125e-01   7.8000292e-01
%@   7.4273826e+02  -6.3641052e-01   5.1073773e-01
%@   7.5018121e+02  -8.0097441e-01   1.7648558e-01
%@   7.5762416e+02  -9.1997089e-01  -1.8022284e-01
%@   7.6506711e+02  -9.8663025e-01  -5.1399945e-01
%@   7.7251007e+02  -9.9716025e-01  -7.8237409e-01
%@   7.7995302e+02  -9.3396036e-01  -9.7199694e-01
%@   7.8739597e+02  -6.9751479e-01  -9.1595650e-01
%@   7.9483893e+02  -3.3208012e-01  -4.8622281e-01
%@   8.0228188e+02   9.4765009e-02   1.4188076e-01
%@   8.0972483e+02   5.0408556e-01   7.1209961e-01
%@   8.1716779e+02   8.2018725e-01   9.9179504e-01
%@   8.2461074e+02   9.8461444e-01   8.6685650e-01
%@   8.3205369e+02   9.6696016e-01   3.8825660e-01
%@   8.3949664e+02   7.7048915e-01  -2.4874479e-01
%@   8.4693960e+02   4.3153415e-01  -7.8426293e-01
%@   8.5438255e+02   1.2776972e-02  -9.9981634e-01
%@   8.6182550e+02  -4.0834301e-01  -8.0746324e-01
%@   8.6926846e+02  -7.5394948e-01  -2.8568013e-01
%@   8.7671141e+02  -9.6013057e-01   3.5265518e-01
%@   8.8415436e+02  -9.8875792e-01   8.4711371e-01
%@   8.9159732e+02  -8.6457823e-01   9.9999062e-01
%@   8.9904027e+02  -6.9920603e-01   9.1737302e-01
%@   9.0648322e+02  -4.8316163e-01   6.8630274e-01
%@   9.1392617e+02  -2.3210199e-01   3.4417241e-01
%@   9.2136913e+02   3.5778326e-02  -5.3653171e-02
%@   9.2881208e+02   3.0106575e-01  -4.4279639e-01
%@   9.3625503e+02   5.4453462e-01  -7.6028467e-01
%@   9.4369799e+02   7.4854049e-01  -9.5474088e-01
%@   9.5114094e+02   8.9829883e-01  -9.9469739e-01
%@   9.5858389e+02   9.8295650e-01  -8.7368830e-01
%@   9.6602685e+02   9.9637827e-01  -6.1129575e-01
%@   9.7346980e+02   9.3759145e-01  -2.4998106e-01
%@   9.8091275e+02   8.1085638e-01   1.5178649e-01
%@   9.8835570e+02   6.2535768e-01   5.2899139e-01
%@   9.9579866e+02   3.9453865e-01   8.2059294e-01
%@   1.0032416e+03   1.3512699e-01   9.7940312e-01
%@   1.0106846e+03  -1.3407747e-01   9.7972267e-01
%@   1.0181275e+03  -3.9356520e-01   8.2149989e-01
%@   1.0255705e+03  -6.2453084e-01   5.3033896e-01
%@   1.0330134e+03  -8.1023606e-01   1.5335662e-01
%@   1.0404564e+03  -9.3722261e-01  -2.4844245e-01
%@   1.0478993e+03  -9.9628765e-01  -6.1003765e-01
%@   1.0553423e+03  -9.8315066e-01  -8.7291430e-01
%@   1.0627852e+03  -8.9876370e-01  -9.9453274e-01
%@   1.0702282e+03  -7.4924238e-01  -9.5521222e-01
%@   1.0776711e+03  -5.4542267e-01  -7.6131573e-01
%@   1.0851141e+03  -3.0207559e-01  -4.4422032e-01
%@   1.0925570e+03  -3.6836780e-02  -5.5239543e-02
%@   1.1000000e+03   2.3107163e-01   3.4268031e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/multiproxy/isotope-test-good_multiproxy_nan.txt__ -->
%@  -9.0000000e+00   9.9983751e-01   6.8772990e-01
%@  -1.5570470e+00   9.2325735e-01   1.9270252e-01
%@   5.8859060e+00   7.1748150e-01  -3.6210606e-01
%@   1.3328859e+01   4.1130513e-01  -8.0458016e-01
%@   2.0771812e+01             NaN  -9.9745308e-01
%@   2.8214765e+01  -3.2281637e-01  -8.8089074e-01
%@   3.5657718e+01  -6.4803249e-01  -4.9105375e-01
%@   4.3100671e+01  -8.8256640e-01   5.1120579e-02
%@   5.0543624e+01  -9.9359871e-01   5.7743600e-01
%@   5.7986577e+01  -9.6559213e-01   9.2461613e-01
%@   6.5429530e+01  -8.0246577e-01   9.8495687e-01
%@   7.2872483e+01  -5.2704664e-01   7.3973900e-01
%@   8.0315436e+01  -1.7787544e-01   2.6503532e-01
%@   8.7758389e+01   1.9618670e-01  -2.9188904e-01
%@   9.5201342e+01   5.4279553e-01  -7.5826201e-01
%@   1.0264430e+02   8.1344846e-01  -9.8940287e-01
%@   1.1008725e+02   9.7027177e-01             NaN
%@   1.1753020e+02   9.8856742e-01  -5.2979860e-01
%@   1.2497315e+02   8.5047661e-01   4.5444593e-02
%@   1.3241611e+02   5.7642082e-01   6.0461592e-01
%@   1.3985906e+02   2.1021312e-01   9.4995971e-01
%@   1.4730201e+02  -1.8960117e-01   9.5934223e-01
%@   1.5474497e+02  -5.5910409e-01   6.2944526e-01
%@   1.6218792e+02  -8.3922351e-01   7.6939653e-02
%@   1.6963087e+02  -9.8517697e-01  -5.0277631e-01
%@   1.7707383e+02  -9.7363101e-01  -9.0468118e-01
%@   1.8451678e+02             NaN  -9.8663791e-01
%@   1.9195973e+02  -5.1030844e-01  -7.1966180e-01
%@   1.9940268e+02  -1.3260281e-01  -1.9817122e-01
%@   2.0684564e+02   2.6630192e-01   3.9340429e-01
%@   2.1428859e+02   6.2263318e-01   8.4584905e-01
%@   2.2173154e+02   8.7942461e-01   9.9915215e-01
%@   2.2917450e+02   9.7746477e-01   8.9321538e-01
%@   2.3661745e+02   9.9892933e-01   6.5635724e-01
%@   2.4406040e+02   9.5377003e-01   3.2169023e-01
%@   2.5150336e+02   8.4499876e-01  -6.0914326e-02
%@   2.5894631e+02   6.7987006e-01  -4.3444157e-01
%@   2.6638926e+02   4.6939723e-01  -7.4322932e-01
%@   2.7383221e+02   2.2761782e-01  -9.4126271e-01
%@   2.8127517e+02  -2.9342623e-02  -9.9903127e-01
%@   2.8871812e+02  -2.8434605e-01  -9.0792644e-01
%@   2.9616107e+02  -5.2038494e-01  -6.8152447e-01
%@   3.0360403e+02  -7.2171661e-01  -3.5356327e-01
%@   3.1104698e+02  -8.7491318e-01   2.7085132e-02
%@   3.1848993e+02  -9.6975717e-01   4.0369737e-01
%@   3.2593289e+02  -9.9992293e-01   7.2015154e-01
%@   3.3337584e+02  -9.6339855e-01   9.2929035e-01
%@   3.4081879e+02  -7.6684141e-01   9.6640586e-01
%@   3.4826174e+02  -4.1974499e-01   6.0498459e-01
%@   3.5570470e+02   7.5766403e-03  -1.1364825e-02
%@   3.6314765e+02   4.3345016e-01  -6.2292534e-01
%@   3.7059060e+02   7.7647902e-01  -9.7199783e-01
%@   3.7803356e+02   9.7110064e-01  -9.1149030e-01
%@   3.8547651e+02   9.8011728e-01  -4.6689936e-01
%@   3.9291946e+02   8.0180562e-01   1.7443342e-01
%@   4.0036242e+02   4.7024609e-01   7.4226353e-01
%@   4.0780537e+02   4.8809144e-02   9.9731894e-01
%@   4.1524832e+02  -3.8195662e-01   8.3212453e-01
%@   4.2269128e+02  -7.3971960e-01   3.1628983e-01
%@   4.3013423e+02  -9.5610111e-01  -3.3282294e-01
%@   4.3757718e+02  -9.8974449e-01  -8.4169092e-01
%@   4.4502013e+02  -8.3437621e-01  -9.9592607e-01
%@   4.5246309e+02  -6.0623364e-01  -8.2880814e-01
%@   4.5990604e+02  -3.1041747e-01  -4.5595794e-01
%@   4.6734899e+02   2.0050455e-02   3.0073163e-02
%@   4.7479195e+02   3.4828016e-01   5.0863931e-01
%@   4.8223490e+02   6.3763151e-01   8.6094762e-01
%@   4.8967785e+02   8.5580433e-01   9.9954580e-01
%@   4.9712081e+02   9.7844409e-01   8.9003008e-01
%@   5.0456376e+02   9.9186057e-01   5.5958517e-01
%@   5.1200671e+02   8.9455610e-01   9.0236321e-02
%@   5.1944966e+02   6.9739272e-01  -4.0151159e-01
%@   5.2689262e+02   4.2237970e-01  -7.9359363e-01
%@   5.3433557e+02   1.0021662e-01  -9.8868458e-01
%@   5.4177852e+02  -2.3313360e-01  -9.3835768e-01
%@   5.4922148e+02  -5.4045921e-01  -6.5510540e-01
%@   5.5666443e+02  -7.8247404e-01  -2.2101259e-01
%@   5.6410738e+02  -9.1041056e-01   1.4510266e-01
%@   5.7155034e+02  -9.8368671e-01   4.9173926e-01
%@   5.7899329e+02  -9.9790306e-01   7.7236454e-01
%@   5.8643624e+02  -9.5220606e-01   9.4930725e-01
%@   5.9387919e+02  -8.4933932e-01   9.9881450e-01
%@   6.0132215e+02  -6.9547888e-01             NaN
%@   6.0876510e+02  -4.9986242e-01   7.0693827e-01
%@   6.1620805e+02  -2.7423459e-01   4.0473639e-01
%@   6.2365101e+02  -3.2141924e-02   4.8202505e-02
%@   6.3109396e+02   2.1188052e-01  -3.1480210e-01
%@   6.3853691e+02   4.4318182e-01  -6.3554753e-01
%@   6.4597987e+02   6.4787481e-01  -8.7097675e-01
%@   6.5342282e+02   8.1366988e-01  -9.8948565e-01
%@   6.6086577e+02   9.3061283e-01  -9.7516551e-01
%@   6.6830872e+02   9.9153334e-01  -8.3090281e-01
%@   6.7575168e+02   9.9408004e-01  -5.8274338e-01
%@   6.8319463e+02   9.4007355e-01  -2.6043490e-01
%@   6.9063758e+02   8.3258631e-01   9.5011678e-02
%@   6.9808054e+02   6.7773326e-01   4.3836884e-01
%@   7.0552349e+02   4.8432398e-01   7.2594735e-01
%@   7.1296644e+02   2.6336152e-01   9.2115535e-01
%@   7.2040940e+02   2.7416438e-02   9.9915429e-01
%@   7.2785235e+02  -2.1008837e-01   9.5001949e-01
%@   7.3529530e+02  -4.3564125e-01   7.8000292e-01
%@   7.4273826e+02  -6.3641052e-01   5.1073773e-01
%@   7.5018121e+02  -8.0097441e-01   1.7648558e-01
%@   7.5762416e+02  -9.1997089e-01  -1.8022284e-01
%@   7.6506711e+02  -9.8663025e-01  -5.1399945e-01
%@   7.7251007e+02  -9.9716025e-01  -7.8237409e-01
%@   7.7995302e+02  -9.3396036e-01  -9.7199694e-01
%@   7.8739597e+02  -6.9751479e-01  -9.1595650e-01
%@   7.9483893e+02  -3.3208012e-01  -4.8622281e-01
%@   8.0228188e+02   9.4765009e-02   1.4188076e-01
%@   8.0972483e+02             NaN   7.1209961e-01
%@   8.1716779e+02   8.2018725e-01   9.9179504e-01
%@   8.2461074e+02   9.8461444e-01   8.6685650e-01
%@   8.3205369e+02   9.6696016e-01   3.8825660e-01
%@   8.3949664e+02   7.7048915e-01  -2.4874479e-01
%@   8.4693960e+02   4.3153415e-01  -7.8426293e-01
%@   8.5438255e+02   1.2776972e-02  -9.9981634e-01
%@   8.6182550e+02  -4.0834301e-01  -8.0746324e-01
%@   8.6926846e+02  -7.5394948e-01  -2.8568013e-01
%@   8.7671141e+02  -9.6013057e-01   3.5265518e-01
%@   8.8415436e+02  -9.8875792e-01   8.4711371e-01
%@   8.9159732e+02  -8.6457823e-01   9.9999062e-01
%@   8.9904027e+02  -6.9920603e-01   9.1737302e-01
%@   9.0648322e+02  -4.8316163e-01   6.8630274e-01
%@   9.1392617e+02  -2.3210199e-01   3.4417241e-01
%@   9.2136913e+02   3.5778326e-02  -5.3653171e-02
%@   9.2881208e+02   3.0106575e-01  -4.4279639e-01
%@   9.3625503e+02   5.4453462e-01  -7.6028467e-01
%@   9.4369799e+02   7.4854049e-01  -9.5474088e-01
%@   9.5114094e+02   8.9829883e-01  -9.9469739e-01
%@   9.5858389e+02   9.8295650e-01  -8.7368830e-01
%@   9.6602685e+02   9.9637827e-01  -6.1129575e-01
%@   9.7346980e+02   9.3759145e-01  -2.4998106e-01
%@   9.8091275e+02   8.1085638e-01   1.5178649e-01
%@   9.8835570e+02   6.2535768e-01   5.2899139e-01
%@   9.9579866e+02   3.9453865e-01   8.2059294e-01
%@   1.0032416e+03   1.3512699e-01   9.7940312e-01
%@   1.0106846e+03  -1.3407747e-01   9.7972267e-01
%@   1.0181275e+03  -3.9356520e-01   8.2149989e-01
%@   1.0255705e+03  -6.2453084e-01   5.3033896e-01
%@   1.0330134e+03  -8.1023606e-01   1.5335662e-01
%@   1.0404564e+03  -9.3722261e-01  -2.4844245e-01
%@   1.0478993e+03  -9.9628765e-01  -6.1003765e-01
%@   1.0553423e+03  -9.8315066e-01  -8.7291430e-01
%@   1.0627852e+03  -8.9876370e-01             NaN
%@   1.0702282e+03  -7.4924238e-01  -9.5521222e-01
%@   1.0776711e+03  -5.4542267e-01  -7.6131573e-01
%@   1.0851141e+03  -3.0207559e-01  -4.4422032e-01
%@   1.0925570e+03  -3.6836780e-02  -5.5239543e-02
%@   1.1000000e+03   2.3107163e-01   3.4268031e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/multiproxy/isotope-test-good_proxy1.txt__ -->
%@  -9.0000000e+00   9.9983751e-01
%@  -1.5570470e+00   9.2325735e-01
%@   5.8859060e+00   7.1748150e-01
%@   1.3328859e+01   4.1130513e-01
%@   2.0771812e+01   4.7572930e-02
%@   2.8214765e+01  -3.2281637e-01
%@   3.5657718e+01  -6.4803249e-01
%@   4.3100671e+01  -8.8256640e-01
%@   5.0543624e+01  -9.9359871e-01
%@   5.7986577e+01  -9.6559213e-01
%@   6.5429530e+01  -8.0246577e-01
%@   7.2872483e+01  -5.2704664e-01
%@   8.0315436e+01  -1.7787544e-01
%@   8.7758389e+01   1.9618670e-01
%@   9.5201342e+01   5.4279553e-01
%@   1.0264430e+02   8.1344846e-01
%@   1.1008725e+02   9.7027177e-01
%@   1.1753020e+02   9.8856742e-01
%@   1.2497315e+02   8.5047661e-01
%@   1.3241611e+02   5.7642082e-01
%@   1.3985906e+02   2.1021312e-01
%@   1.4730201e+02  -1.8960117e-01
%@   1.5474497e+02  -5.5910409e-01
%@   1.6218792e+02  -8.3922351e-01
%@   1.6963087e+02  -9.8517697e-01
%@   1.7707383e+02  -9.7363101e-01
%@   1.8451678e+02  -8.0643149e-01
%@   1.9195973e+02  -5.1030844e-01
%@   1.9940268e+02  -1.3260281e-01
%@   2.0684564e+02   2.6630192e-01
%@   2.1428859e+02   6.2263318e-01
%@   2.2173154e+02   8.7942461e-01
%@   2.2917450e+02   9.7746477e-01
%@   2.3661745e+02   9.9892933e-01
%@   2.4406040e+02   9.5377003e-01
%@   2.5150336e+02   8.4499876e-01
%@   2.5894631e+02   6.7987006e-01
%@   2.6638926e+02   4.6939723e-01
%@   2.7383221e+02   2.2761782e-01
%@   2.8127517e+02  -2.9342623e-02
%@   2.8871812e+02  -2.8434605e-01
%@   2.9616107e+02  -5.2038494e-01
%@   3.0360403e+02  -7.2171661e-01
%@   3.1104698e+02  -8.7491318e-01
%@   3.1848993e+02  -9.6975717e-01
%@   3.2593289e+02  -9.9992293e-01
%@   3.3337584e+02  -9.6339855e-01
%@   3.4081879e+02  -7.6684141e-01
%@   3.4826174e+02  -4.1974499e-01
%@   3.5570470e+02   7.5766403e-03
%@   3.6314765e+02   4.3345016e-01
%@   3.7059060e+02   7.7647902e-01
%@   3.7803356e+02   9.7110064e-01
%@   3.8547651e+02   9.8011728e-01
%@   3.9291946e+02   8.0180562e-01
%@   4.0036242e+02   4.7024609e-01
%@   4.0780537e+02   4.8809144e-02
%@   4.1524832e+02  -3.8195662e-01
%@   4.2269128e+02  -7.3971960e-01
%@   4.3013423e+02  -9.5610111e-01
%@   4.3757718e+02  -9.8974449e-01
%@   4.4502013e+02  -8.3437621e-01
%@   4.5246309e+02  -6.0623364e-01
%@   4.5990604e+02  -3.1041747e-01
%@   4.6734899e+02   2.0050455e-02
%@   4.7479195e+02   3.4828016e-01
%@   4.8223490e+02   6.3763151e-01
%@   4.8967785e+02   8.5580433e-01
%@   4.9712081e+02   9.7844409e-01
%@   5.0456376e+02   9.9186057e-01
%@   5.1200671e+02   8.9455610e-01
%@   5.1944966e+02   6.9739272e-01
%@   5.2689262e+02   4.2237970e-01
%@   5.3433557e+02   1.0021662e-01
%@   5.4177852e+02  -2.3313360e-01
%@   5.4922148e+02  -5.4045921e-01
%@   5.5666443e+02  -7.8247404e-01
%@   5.6410738e+02  -9.1041056e-01
%@   5.7155034e+02  -9.8368671e-01
%@   5.7899329e+02  -9.9790306e-01
%@   5.8643624e+02  -9.5220606e-01
%@   5.9387919e+02  -8.4933932e-01
%@   6.0132215e+02  -6.9547888e-01
%@   6.0876510e+02  -4.9986242e-01
%@   6.1620805e+02  -2.7423459e-01
%@   6.2365101e+02  -3.2141924e-02
%@   6.3109396e+02   2.1188052e-01
%@   6.3853691e+02   4.4318182e-01
%@   6.4597987e+02   6.4787481e-01
%@   6.5342282e+02   8.1366988e-01
%@   6.6086577e+02   9.3061283e-01
%@   6.6830872e+02   9.9153334e-01
%@   6.7575168e+02   9.9408004e-01
%@   6.8319463e+02   9.4007355e-01
%@   6.9063758e+02   8.3258631e-01
%@   6.9808054e+02   6.7773326e-01
%@   7.0552349e+02   4.8432398e-01
%@   7.1296644e+02   2.6336152e-01
%@   7.2040940e+02   2.7416438e-02
%@   7.2785235e+02  -2.1008837e-01
%@   7.3529530e+02  -4.3564125e-01
%@   7.4273826e+02  -6.3641052e-01
%@   7.5018121e+02  -8.0097441e-01
%@   7.5762416e+02  -9.1997089e-01
%@   7.6506711e+02  -9.8663025e-01
%@   7.7251007e+02  -9.9716025e-01
%@   7.7995302e+02  -9.3396036e-01
%@   7.8739597e+02  -6.9751479e-01
%@   7.9483893e+02  -3.3208012e-01
%@   8.0228188e+02   9.4765009e-02
%@   8.0972483e+02   5.0408556e-01
%@   8.1716779e+02   8.2018725e-01
%@   8.2461074e+02   9.8461444e-01
%@   8.3205369e+02   9.6696016e-01
%@   8.3949664e+02   7.7048915e-01
%@   8.4693960e+02   4.3153415e-01
%@   8.5438255e+02   1.2776972e-02
%@   8.6182550e+02  -4.0834301e-01
%@   8.6926846e+02  -7.5394948e-01
%@   8.7671141e+02  -9.6013057e-01
%@   8.8415436e+02  -9.8875792e-01
%@   8.9159732e+02  -8.6457823e-01
%@   8.9904027e+02  -6.9920603e-01
%@   9.0648322e+02  -4.8316163e-01
%@   9.1392617e+02  -2.3210199e-01
%@   9.2136913e+02   3.5778326e-02
%@   9.2881208e+02   3.0106575e-01
%@   9.3625503e+02   5.4453462e-01
%@   9.4369799e+02   7.4854049e-01
%@   9.5114094e+02   8.9829883e-01
%@   9.5858389e+02   9.8295650e-01
%@   9.6602685e+02   9.9637827e-01
%@   9.7346980e+02   9.3759145e-01
%@   9.8091275e+02   8.1085638e-01
%@   9.8835570e+02   6.2535768e-01
%@   9.9579866e+02   3.9453865e-01
%@   1.0032416e+03   1.3512699e-01
%@   1.0106846e+03  -1.3407747e-01
%@   1.0181275e+03  -3.9356520e-01
%@   1.0255705e+03  -6.2453084e-01
%@   1.0330134e+03  -8.1023606e-01
%@   1.0404564e+03  -9.3722261e-01
%@   1.0478993e+03  -9.9628765e-01
%@   1.0553423e+03  -9.8315066e-01
%@   1.0627852e+03  -8.9876370e-01
%@   1.0702282e+03  -7.4924238e-01
%@   1.0776711e+03  -5.4542267e-01
%@   1.0851141e+03  -3.0207559e-01
%@   1.0925570e+03  -3.6836780e-02
%@   1.1000000e+03   2.3107163e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/multiproxy/isotope-test-good_proxy2.txt__ -->
%@  -9.0000000e+00   6.8772990e-01
%@  -1.5570470e+00   1.9270252e-01
%@   5.8859060e+00  -3.6210606e-01
%@   1.3328859e+01  -8.0458016e-01
%@   2.0771812e+01  -9.9745308e-01
%@   2.8214765e+01  -8.8089074e-01
%@   3.5657718e+01  -4.9105375e-01
%@   4.3100671e+01   5.1120579e-02
%@   5.0543624e+01   5.7743600e-01
%@   5.7986577e+01   9.2461613e-01
%@   6.5429530e+01   9.8495687e-01
%@   7.2872483e+01   7.3973900e-01
%@   8.0315436e+01   2.6503532e-01
%@   8.7758389e+01  -2.9188904e-01
%@   9.5201342e+01  -7.5826201e-01
%@   1.0264430e+02  -9.8940287e-01
%@   1.1008725e+02  -9.1360586e-01
%@   1.1753020e+02  -5.2979860e-01
%@   1.2497315e+02   4.5444593e-02
%@   1.3241611e+02   6.0461592e-01
%@   1.3985906e+02   9.4995971e-01
%@   1.4730201e+02   9.5934223e-01
%@   1.5474497e+02   6.2944526e-01
%@   1.6218792e+02   7.6939653e-02
%@   1.6963087e+02  -5.0277631e-01
%@   1.7707383e+02  -9.0468118e-01
%@   1.8451678e+02  -9.8663791e-01
%@   1.9195973e+02  -7.1966180e-01
%@   1.9940268e+02  -1.9817122e-01
%@   2.0684564e+02   3.9340429e-01
%@   2.1428859e+02   8.4584905e-01
%@   2.2173154e+02   9.9915215e-01
%@   2.2917450e+02   8.9321538e-01
%@   2.3661745e+02   6.5635724e-01
%@   2.4406040e+02   3.2169023e-01
%@   2.5150336e+02  -6.0914326e-02
%@   2.5894631e+02  -4.3444157e-01
%@   2.6638926e+02  -7.4322932e-01
%@   2.7383221e+02  -9.4126271e-01
%@   2.8127517e+02  -9.9903127e-01
%@   2.8871812e+02  -9.0792644e-01
%@   2.9616107e+02  -6.8152447e-01
%@   3.0360403e+02  -3.5356327e-01
%@   3.1104698e+02   2.7085132e-02
%@   3.1848993e+02   4.0369737e-01
%@   3.2593289e+02   7.2015154e-01
%@   3.3337584e+02   9.2929035e-01
%@   3.4081879e+02   9.6640586e-01
%@   3.4826174e+02   6.0498459e-01
%@   3.5570470e+02  -1.1364825e-02
%@   3.6314765e+02  -6.2292534e-01
%@   3.7059060e+02  -9.7199783e-01
%@   3.7803356e+02  -9.1149030e-01
%@   3.8547651e+02  -4.6689936e-01
%@   3.9291946e+02   1.7443342e-01
%@   4.0036242e+02   7.4226353e-01
%@   4.0780537e+02   9.9731894e-01
%@   4.1524832e+02   8.3212453e-01
%@   4.2269128e+02   3.1628983e-01
%@   4.3013423e+02  -3.3282294e-01
%@   4.3757718e+02  -8.4169092e-01
%@   4.4502013e+02  -9.9592607e-01
%@   4.5246309e+02  -8.2880814e-01
%@   4.5990604e+02  -4.5595794e-01
%@   4.6734899e+02   3.0073163e-02
%@   4.7479195e+02   5.0863931e-01
%@   4.8223490e+02   8.6094762e-01
%@   4.8967785e+02   9.9954580e-01
%@   4.9712081e+02   8.9003008e-01
%@   5.0456376e+02   5.5958517e-01
%@   5.1200671e+02   9.0236321e-02
%@   5.1944966e+02  -4.0151159e-01
%@   5.2689262e+02  -7.9359363e-01
%@   5.3433557e+02  -9.8868458e-01
%@   5.4177852e+02  -9.3835768e-01
%@   5.4922148e+02  -6.5510540e-01
%@   5.5666443e+02  -2.2101259e-01
%@   5.6410738e+02   1.4510266e-01
%@   5.7155034e+02   4.9173926e-01
%@   5.7899329e+02   7.7236454e-01
%@   5.8643624e+02   9.4930725e-01
%@   5.9387919e+02   9.9881450e-01
%@   6.0132215e+02   9.1424042e-01
%@   6.0876510e+02   7.0693827e-01
%@   6.1620805e+02   4.0473639e-01
%@   6.2365101e+02   4.8202505e-02
%@   6.3109396e+02  -3.1480210e-01
%@   6.3853691e+02  -6.3554753e-01
%@   6.4597987e+02  -8.7097675e-01
%@   6.5342282e+02  -9.8948565e-01
%@   6.6086577e+02  -9.7516551e-01
%@   6.6830872e+02  -8.3090281e-01
%@   6.7575168e+02  -5.8274338e-01
%@   6.8319463e+02  -2.6043490e-01
%@   6.9063758e+02   9.5011678e-02
%@   6.9808054e+02   4.3836884e-01
%@   7.0552349e+02   7.2594735e-01
%@   7.1296644e+02   9.2115535e-01
%@   7.2040940e+02   9.9915429e-01
%@   7.2785235e+02   9.5001949e-01
%@   7.3529530e+02   7.8000292e-01
%@   7.4273826e+02   5.1073773e-01
%@   7.5018121e+02   1.7648558e-01
%@   7.5762416e+02  -1.8022284e-01
%@   7.6506711e+02  -5.1399945e-01
%@   7.7251007e+02  -7.8237409e-01
%@   7.7995302e+02  -9.7199694e-01
%@   7.8739597e+02  -9.1595650e-01
%@   7.9483893e+02  -4.8622281e-01
%@   8.0228188e+02   1.4188076e-01
%@   8.0972483e+02   7.1209961e-01
%@   8.1716779e+02   9.9179504e-01
%@   8.2461074e+02   8.6685650e-01
%@   8.3205369e+02   3.8825660e-01
%@   8.3949664e+02  -2.4874479e-01
%@   8.4693960e+02  -7.8426293e-01
%@   8.5438255e+02  -9.9981634e-01
%@   8.6182550e+02  -8.0746324e-01
%@   8.6926846e+02  -2.8568013e-01
%@   8.7671141e+02   3.5265518e-01
%@   8.8415436e+02   8.4711371e-01
%@   8.9159732e+02   9.9999062e-01
%@   8.9904027e+02   9.1737302e-01
%@   9.0648322e+02   6.8630274e-01
%@   9.1392617e+02   3.4417241e-01
%@   9.2136913e+02  -5.3653171e-02
%@   9.2881208e+02  -4.4279639e-01
%@   9.3625503e+02  -7.6028467e-01
%@   9.4369799e+02  -9.5474088e-01
%@   9.5114094e+02  -9.9469739e-01
%@   9.5858389e+02  -8.7368830e-01
%@   9.6602685e+02  -6.1129575e-01
%@   9.7346980e+02  -2.4998106e-01
%@   9.8091275e+02   1.5178649e-01
%@   9.8835570e+02   5.2899139e-01
%@   9.9579866e+02   8.2059294e-01
%@   1.0032416e+03   9.7940312e-01
%@   1.0106846e+03   9.7972267e-01
%@   1.0181275e+03   8.2149989e-01
%@   1.0255705e+03   5.3033896e-01
%@   1.0330134e+03   1.5335662e-01
%@   1.0404564e+03  -2.4844245e-01
%@   1.0478993e+03  -6.1003765e-01
%@   1.0553423e+03  -8.7291430e-01
%@   1.0627852e+03  -9.9453274e-01
%@   1.0702282e+03  -9.5521222e-01
%@   1.0776711e+03  -7.6131573e-01
%@   1.0851141e+03  -4.4422032e-01
%@   1.0925570e+03  -5.5239543e-02
%@   1.1000000e+03   3.4268031e-01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/multiproxy/testagemodel_good_multiproxy.txt__ -->
%@   1.0000000e+00   5.0000000e+01   1.2500000e+01
%@   1.1200000e+02   1.8397292e+02   1.9198646e+01
%@   2.2300000e+02   3.2729323e+02   2.6364661e+01
%@   3.3400000e+02   4.1949749e+02   3.0974874e+01
%@   4.4500000e+02   5.7641543e+02   3.8820771e+01
%@   5.5600000e+02   6.9592968e+02   4.4796484e+01
%@   6.6700000e+02   7.8338761e+02   4.9169380e+01
%@   7.7800000e+02   8.6850961e+02   5.3425480e+01
%@   8.8900000e+02   1.0228194e+03   6.1140969e+01
%@   1.0000000e+03   1.1189566e+03   6.5947831e+01
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/proxyerror/isotope_test_good__proxyerror_proxy1.txt__ -->
%@  -9.0000000e+00   9.7703145e-01   9.7703145e-03
%@  -1.5570470e+00   9.0277306e-01   9.0277306e-03
%@   5.8859060e+00   7.8101718e-01   7.8101718e-03
%@   1.3328859e+01   6.1816975e-01   6.1816975e-03
%@   2.0771812e+01   4.2279863e-01   4.2279863e-03
%@   2.8214765e+01   2.0518285e-01   2.0518285e-03
%@   3.5657718e+01  -2.3228178e-02  -2.3228178e-04
%@   4.3100671e+01  -2.5041711e-01  -2.5041711e-03
%@   5.0543624e+01  -4.6443088e-01  -4.6443088e-03
%@   5.7986577e+01  -6.5400960e-01  -6.5400960e-03
%@   6.5429530e+01  -8.0917900e-01  -8.0917900e-03
%@   7.2872483e+01  -9.2177517e-01  -9.2177517e-03
%@   8.0315436e+01  -9.8587409e-01  -9.8587409e-03
%@   8.7758389e+01  -9.9810335e-01  -9.9810335e-03
%@   9.5201342e+01  -9.5781952e-01  -9.5781952e-03
%@   1.0264430e+02  -8.6714205e-01  -8.6714205e-03
%@   1.1008725e+02  -7.3084175e-01  -7.3084175e-03
%@   1.1753020e+02  -5.0903529e-01  -5.0903529e-03
%@   1.2497315e+02  -2.2733374e-01  -2.2733374e-03
%@   1.3241611e+02   7.5314536e-02   7.5314536e-04
%@   1.3985906e+02   3.7102327e-01   3.7102327e-03
%@   1.4730201e+02   6.3254559e-01   6.3254559e-03
%@   1.5474497e+02   8.3578461e-01   8.3578461e-03
%@   1.6218792e+02   9.6201371e-01   9.6201371e-03
%@   1.6963087e+02   9.9960203e-01   9.9960203e-03
%@   1.7707383e+02   9.4508614e-01   9.4508614e-03
%@   1.8451678e+02   8.0348919e-01   8.0348919e-03
%@   1.9195973e+02   5.8785805e-01   5.8785805e-03
%@   1.9940268e+02   3.1806116e-01   3.1806116e-03
%@   2.0684564e+02   1.8957830e-02   1.8957830e-04
%@   2.1428859e+02  -2.8189229e-01  -2.8189229e-03
%@   2.2173154e+02  -5.5676861e-01  -5.5676861e-03
%@   2.2917450e+02  -8.4891747e-01  -8.4891747e-03
%@   2.3661745e+02  -9.9406205e-01  -9.9406205e-03
%@   2.4406040e+02  -9.4315373e-01  -9.4315373e-03
%@   2.5150336e+02  -7.0623285e-01  -7.0623285e-03
%@   2.5894631e+02  -3.3002590e-01  -3.3002590e-03
%@   2.6638926e+02   1.1127007e-01   1.1127007e-03
%@   2.7383221e+02   5.3062092e-01   5.3062092e-03
%@   2.8127517e+02   8.4532058e-01   8.4532058e-03
%@   2.8871812e+02   9.9330274e-01   9.9330274e-03
%@   2.9616107e+02   9.4538175e-01   9.4538175e-03
%@   3.0360403e+02   7.1100878e-01   7.1100878e-03
%@   3.1104698e+02   3.3640781e-01   3.3640781e-03
%@   3.1848993e+02  -1.0454085e-01  -1.0454085e-03
%@   3.2593289e+02  -5.2487155e-01  -5.2487155e-03
%@   3.3337584e+02  -8.4168497e-01  -8.4168497e-03
%@   3.4081879e+02  -9.4886747e-01  -9.4886747e-03
%@   3.4826174e+02  -9.9594248e-01  -9.9594248e-03
%@   3.5570470e+02  -9.9008445e-01  -9.9008445e-03
%@   3.6314765e+02  -9.3160473e-01  -9.3160473e-03
%@   3.7059060e+02  -8.2361144e-01  -8.2361144e-03
%@   3.7803356e+02  -6.7184428e-01  -6.7184428e-03
%@   3.8547651e+02  -4.8436948e-01  -4.8436948e-03
%@   3.9291946e+02  -2.7115108e-01  -2.7115108e-03
%@   4.0036242e+02  -4.3521348e-02  -4.3521348e-04
%@   4.0780537e+02   1.8642148e-01   1.8642148e-03
%@   4.1524832e+02   4.0645626e-01   4.0645626e-03
%@   4.2269128e+02   6.0488841e-01   6.0488841e-03
%@   4.3013423e+02   7.7117154e-01   7.7117154e-03
%@   4.3757718e+02   8.9646792e-01   8.9646792e-03
%@   4.4502013e+02   9.7411210e-01   9.7411210e-03
%@   4.5246309e+02   9.9997580e-01   9.9997580e-03
%@   4.5990604e+02   9.7716298e-01   9.7716298e-03
%@   4.6734899e+02   9.0678410e-01   9.0678410e-03
%@   4.7479195e+02   7.9226505e-01   7.9226505e-03
%@   4.8223490e+02   6.3918035e-01   6.3918035e-03
%@   4.8967785e+02   4.5498182e-01   4.5498182e-03
%@   4.9712081e+02   2.4863582e-01   2.4863582e-03
%@   5.0456376e+02   3.0186789e-02   3.0186789e-04
%@   5.1200671e+02  -1.8973166e-01  -1.8973166e-03
%@   5.1944966e+02  -4.0041441e-01  -4.0041441e-03
%@   5.2689262e+02  -5.9160590e-01  -5.9160590e-03
%@   5.3433557e+02  -7.5399937e-01  -7.5399937e-03
%@   5.4177852e+02  -8.7968989e-01  -8.7968989e-03
%@   5.4922148e+02  -9.6255911e-01  -9.6255911e-03
%@   5.5666443e+02  -9.9866577e-01  -9.9866577e-03
%@   5.6410738e+02  -9.8216056e-01  -9.8216056e-03
%@   5.7155034e+02  -9.0896414e-01  -9.0896414e-03
%@   5.7899329e+02  -7.8330149e-01  -7.8330149e-03
%@   5.8643624e+02  -6.1242596e-01  -6.1242596e-03
%@   5.9387919e+02  -4.0620065e-01  -4.0620065e-03
%@   6.0132215e+02  -1.7652906e-01  -1.7652906e-03
%@   6.0876510e+02   6.3331936e-02   6.3331936e-04
%@   6.1620805e+02   2.9953736e-01   2.9953736e-03
%@   6.2365101e+02   5.1845321e-01   5.1845321e-03
%@   6.3109396e+02   7.0744348e-01   7.0744348e-03
%@   6.3853691e+02   8.5559946e-01   8.5559946e-03
%@   6.4597987e+02   9.5436946e-01   9.5436946e-03
%@   6.5342282e+02   9.9805239e-01   9.9805239e-03
%@   6.6086577e+02   9.8412683e-01   9.8412683e-03
%@   6.6830872e+02   9.0181788e-01   9.0181788e-03
%@   6.7575168e+02   6.6403088e-01   6.6403088e-03
%@   6.8319463e+02   3.2256278e-01   3.2256278e-03
%@   6.9063758e+02  -6.9269933e-02  -6.9269933e-04
%@   6.9808054e+02  -4.5028691e-01  -4.5028691e-03
%@   7.0552349e+02  -7.6099656e-01  -7.6099656e-03
%@   7.1296644e+02  -9.5288499e-01  -9.5288499e-03
%@   7.2040940e+02  -9.9599094e-01  -9.9599094e-03
%@   7.2785235e+02  -8.8358389e-01  -8.8358389e-03
%@   7.3529530e+02  -6.3321496e-01  -6.3321496e-03
%@   7.4273826e+02  -2.8397650e-01  -2.8397650e-03
%@   7.5018121e+02   1.0960175e-01   1.0960175e-03
%@   7.5762416e+02   4.8606690e-01   4.8606690e-03
%@   7.6506711e+02   7.8663807e-01   7.8663807e-03
%@   7.7251007e+02   9.6438438e-01   9.6438438e-03
%@   7.7995302e+02   9.9561197e-01   9.9561197e-03
%@   7.8739597e+02   9.3836614e-01   9.3836614e-03
%@   7.9483893e+02   8.1842442e-01   8.1842442e-03
%@   8.0228188e+02   6.4380059e-01   6.4380059e-03
%@   8.0972483e+02   4.2616194e-01   4.2616194e-03
%@   8.1716779e+02   1.8004975e-01   1.8004975e-03
%@   8.2461074e+02  -7.8092256e-02  -7.8092256e-04
%@   8.3205369e+02  -3.3101662e-01  -3.3101662e-03
%@   8.3949664e+02  -5.6182447e-01  -5.6182447e-03
%@   8.4693960e+02  -7.5509465e-01  -7.5509465e-03
%@   8.5438255e+02  -8.9791402e-01  -8.9791402e-03
%@   8.6182550e+02  -9.8074028e-01  -9.8074028e-03
%@   8.6926846e+02  -9.9803946e-01  -9.9803946e-03
%@   8.7671141e+02  -9.4865575e-01  -9.4865575e-03
%@   8.8415436e+02  -8.3588867e-01  -8.3588867e-03
%@   8.9159732e+02  -6.4497075e-01  -6.4497075e-03
%@   8.9904027e+02  -3.4953969e-01  -3.4953969e-03
%@   9.0648322e+02  -1.3174122e-02  -1.3174122e-04
%@   9.1392617e+02   3.2473426e-01   3.2473426e-03
%@   9.2136913e+02   6.2461310e-01   6.2461310e-03
%@   9.2881208e+02   8.5134366e-01   8.5134366e-03
%@   9.3625503e+02   9.7837358e-01   9.7837358e-03
%@   9.4369799e+02   9.9082642e-01   9.9082642e-03
%@   9.5114094e+02   8.8724383e-01   8.8724383e-03
%@   9.5858389e+02   6.7975635e-01   6.7975635e-03
%@   9.6602685e+02   3.9266277e-01   3.9266277e-03
%@   9.7346980e+02   5.9584553e-02   5.9584553e-04
%@   9.8091275e+02  -2.8047159e-01  -2.8047159e-03
%@   9.8835570e+02  -5.8768178e-01  -5.8768178e-03
%@   9.9579866e+02  -8.2606871e-01  -8.2606871e-03
%@   1.0032416e+03  -9.6771494e-01  -9.6771494e-03
%@   1.0106846e+03  -9.9603232e-01  -9.9603232e-03
%@   1.0181275e+03  -9.0770461e-01  -9.0770461e-03
%@   1.0255705e+03  -7.1307585e-01  -7.1307585e-03
%@   1.0330134e+03  -4.3493896e-01  -4.3493896e-03
%@   1.0404564e+03  -1.0586647e-01  -1.0586647e-03
%@   1.0478993e+03   2.3560401e-01   2.3560401e-03
%@   1.0553423e+03   5.4948296e-01   5.4948296e-03
%@   1.0627852e+03   7.9901211e-01   7.9901211e-03
%@   1.0702282e+03   9.5496915e-01   9.5496915e-03
%@   1.0776711e+03   9.9909000e-01   9.9909000e-03
%@   1.0851141e+03   9.2620767e-01   9.2620767e-03
%@   1.0925570e+03   7.4485741e-01   7.4485741e-03
%@   1.1000000e+03   4.7627708e-01   4.7627708e-03
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/proxyerror/isotope_test_good__proxyerror_proxy2.txt__ -->
%@  -9.0000000e+00   4.4688966e-01   4.4688966e-03
%@  -1.5570470e+00   1.1818738e-01   1.1818738e-03
%@   5.8859060e+00  -2.2442888e-01  -2.2442888e-03
%@   1.3328859e+01  -5.4062354e-01  -5.4062354e-03
%@   2.0771812e+01  -7.9317157e-01  -7.9317157e-03
%@   2.8214765e+01  -9.5234095e-01  -9.5234095e-03
%@   3.5657718e+01  -9.9939296e-01  -9.9939296e-03
%@   4.3100671e+01  -9.2878825e-01  -9.2878825e-03
%@   5.0543624e+01  -7.4883898e-01  -7.4883898e-03
%@   5.7986577e+01  -4.8073026e-01  -4.8073026e-03
%@   6.5429530e+01  -1.5602604e-01  -1.5602604e-03
%@   7.2872483e+01   1.8704685e-01   1.8704685e-03
%@   8.0315436e+01   5.0809905e-01   5.0809905e-03
%@   8.7758389e+01   7.6933367e-01   7.6933367e-03
%@   9.5201342e+01   9.3999603e-01   9.3999603e-03
%@   1.0264430e+02   9.9999437e-01   9.9999437e-03
%@   1.1008725e+02   9.4226518e-01   9.4226518e-03
%@   1.1753020e+02   7.1811887e-01   7.1811887e-03
%@   1.2497315e+02   3.3726323e-01   3.3726323e-03
%@   1.3241611e+02  -1.1283805e-01  -1.1283805e-03
%@   1.3985906e+02  -5.3977183e-01  -5.3977183e-03
%@   1.4730201e+02  -8.5588166e-01  -8.5588166e-03
%@   1.5474497e+02  -9.9626501e-01  -9.9626501e-03
%@   1.6218792e+02  -9.3209890e-01  -9.3209890e-03
%@   1.6963087e+02  -6.7655768e-01  -6.7655768e-03
%@   1.7707383e+02  -2.8210813e-01  -2.8210813e-03
%@   1.8451678e+02   1.7026282e-01   1.7026282e-03
%@   1.9195973e+02   5.8767604e-01   5.8767604e-03
%@   1.9940268e+02   8.8442978e-01   8.8442978e-03
%@   2.0684564e+02   9.9959565e-01   9.9959565e-03
%@   2.1428859e+02   9.0952823e-01   9.0952823e-03
%@   2.2173154e+02   6.3271982e-01   6.3271982e-03
%@   2.2917450e+02   4.9875080e-02   4.9875080e-04
%@   2.3661745e+02  -5.8254163e-01  -5.8254163e-03
%@   2.4406040e+02  -9.6182652e-01  -9.6182652e-03
%@   2.5150336e+02  -9.2316893e-01  -9.2316893e-03
%@   2.5894631e+02  -4.8336675e-01  -4.8336675e-03
%@   2.6638926e+02   1.6647279e-01   1.6647279e-03
%@   2.7383221e+02   7.4397490e-01   7.4397490e-03
%@   2.8127517e+02   9.9819761e-01   9.9819761e-03
%@   2.8871812e+02   8.1867350e-01   8.1867350e-03
%@   2.9616107e+02   2.8341120e-01   2.8341120e-03
%@   3.0360403e+02  -3.7500177e-01  -3.7500177e-03
%@   3.1104698e+02  -8.7046522e-01  -8.7046522e-03
%@   3.1848993e+02  -9.8768542e-01  -9.8768542e-03
%@   3.2593289e+02  -6.7572667e-01  -6.7572667e-03
%@   3.3337584e+02  -7.0144412e-02  -7.0144412e-04
%@   3.4081879e+02   2.9900205e-01   2.9900205e-03
%@   3.4826174e+02   6.0536718e-01   6.0536718e-03
%@   3.5570470e+02   8.3974179e-01   8.3974179e-03
%@   3.6314765e+02   9.7425395e-01   9.7425395e-03
%@   3.7059060e+02   9.9290741e-01   9.9290741e-03
%@   3.7803356e+02   8.9348390e-01   8.9348390e-03
%@   3.8547651e+02   6.8780691e-01   6.8780691e-03
%@   3.9291946e+02   4.0033562e-01   4.0033562e-03
%@   4.0036242e+02   6.5256245e-02   6.5256245e-04
%@   4.0780537e+02  -2.7758343e-01  -2.7758343e-03
%@   4.1524832e+02  -5.8741276e-01  -5.8741276e-03
%@   4.2269128e+02  -8.2738672e-01  -8.2738672e-03
%@   4.3013423e+02  -9.6896749e-01  -9.6896749e-03
%@   4.3757718e+02  -9.9531824e-01  -9.9531824e-03
%@   4.4502013e+02  -9.0332268e-01  -9.0332268e-03
%@   4.5246309e+02  -7.1444667e-01  -7.1444667e-03
%@   4.5990604e+02  -4.4771891e-01  -4.4771891e-03
%@   4.6734899e+02  -1.3220416e-01  -1.3220416e-03
%@   4.7479195e+02   1.9771660e-01   1.9771660e-03
%@   4.8223490e+02   5.0609260e-01   5.0609260e-03
%@   4.8967785e+02   7.5932075e-01   7.5932075e-03
%@   4.9712081e+02   9.2980731e-01   9.2980731e-03
%@   5.0456376e+02   9.9897472e-01   9.9897472e-03
%@   5.1200671e+02   9.5928595e-01   9.5928595e-03
%@   5.1944966e+02   8.1506580e-01   8.1506580e-03
%@   5.2689262e+02   5.8202964e-01   5.8202964e-03
%@   5.3433557e+02   2.8557093e-01   2.8557093e-03
%@   5.4177852e+02  -4.2005839e-02  -4.2005839e-04
%@   5.4922148e+02  -3.6500532e-01  -3.6500532e-03
%@   5.5666443e+02  -6.5024272e-01  -6.5024272e-03
%@   5.6410738e+02  -8.7679397e-01  -8.7679397e-03
%@   5.7155034e+02  -9.9016117e-01  -9.9016117e-03
%@   5.7899329e+02  -9.7570992e-01  -9.7570992e-03
%@   5.8643624e+02  -8.3530571e-01  -8.3530571e-03
%@   5.9387919e+02  -5.8707312e-01  -5.8707312e-03
%@   6.0132215e+02  -2.6305611e-01  -2.6305611e-03
%@   6.0876510e+02   9.4918415e-02   9.4918415e-04
%@   6.1620805e+02   4.4064007e-01   4.4064007e-03
%@   6.2365101e+02   7.2948014e-01   7.2948014e-03
%@   6.3109396e+02   9.2415269e-01   9.2415269e-03
%@   6.3853691e+02   9.9952773e-01   9.9952773e-03
%@   6.4597987e+02   9.4587520e-01   9.4587520e-03
%@   6.5342282e+02   7.7012103e-01   7.7012103e-03
%@   6.6086577e+02   4.9495307e-01   4.9495307e-03
%@   6.6830872e+02   1.1488665e-01   1.1488665e-03
%@   6.7575168e+02  -4.6310995e-01  -4.6310995e-03
%@   6.8319463e+02  -8.8108089e-01  -8.8108089e-03
%@   6.9063758e+02  -9.9459810e-01  -9.9459810e-03
%@   6.9808054e+02  -7.6443620e-01  -7.6443620e-03
%@   7.0552349e+02  -2.7012664e-01  -2.7012664e-03
%@   7.1296644e+02   3.1752402e-01   3.1752402e-03
%@   7.2040940e+02   7.9545562e-01   7.9545562e-03
%@   7.2785235e+02   9.9852093e-01   9.9852093e-03
%@   7.3529530e+02   8.5655161e-01   8.5655161e-03
%@   7.4273826e+02   4.1860456e-01   4.1860456e-03
%@   7.5018121e+02  -1.6398951e-01  -1.6398951e-03
%@   7.5762416e+02  -6.8991771e-01  -6.8991771e-03
%@   7.6506711e+02  -9.7744779e-01  -9.7744779e-03
%@   7.7251007e+02  -9.2722498e-01  -9.2722498e-03
%@   7.7995302e+02  -6.0105922e-01  -6.0105922e-03
%@   7.8739597e+02  -2.5322501e-01  -2.5322501e-03
%@   7.9483893e+02   1.3241084e-01   1.3241084e-03
%@   8.0228188e+02   4.9828028e-01   4.9828028e-03
%@   8.0972483e+02   7.8976602e-01   7.8976602e-03
%@   8.1716779e+02   9.6335482e-01   9.6335482e-03
%@   8.2461074e+02   9.9313318e-01   9.9313318e-03
%@   8.3205369e+02   8.7465577e-01   8.7465577e-03
%@   8.3949664e+02   6.2560900e-01   6.2560900e-03
%@   8.4693960e+02   2.8317079e-01   2.8317079e-03
%@   8.5438255e+02  -1.0153941e-01  -1.0153941e-03
%@   8.6182550e+02  -4.7109171e-01  -4.7109171e-03
%@   8.6926846e+02  -7.7031904e-01  -7.7031904e-03
%@   8.7671141e+02  -9.5455249e-01  -9.5455249e-03
%@   8.8415436e+02  -9.9628952e-01  -9.9628952e-03
%@   8.9159732e+02  -8.6815745e-01  -8.6815745e-03
%@   8.9904027e+02  -5.1037400e-01  -5.1037400e-03
%@   9.0648322e+02  -1.9760468e-02  -1.9760468e-04
%@   9.1392617e+02   4.7599592e-01   4.7599592e-03
%@   9.2136913e+02   8.4786949e-01   8.4786949e-03
%@   9.2881208e+02   9.9907631e-01   9.9907631e-03
%@   9.3625503e+02   8.9026327e-01   8.9026327e-03
%@   9.4369799e+02   5.4975006e-01   5.4975006e-03
%@   9.5114094e+02   6.6158760e-02   6.6158760e-04
%@   9.5858389e+02  -4.3465104e-01  -4.3465104e-03
%@   9.6602685e+02  -8.2233844e-01  -8.2233844e-03
%@   9.7346980e+02  -9.9600382e-01  -9.9600382e-03
%@   9.8091275e+02  -9.1044898e-01  -9.1044898e-03
%@   9.8835570e+02  -5.8794044e-01  -5.8794044e-03
%@   9.9579866e+02  -1.1241436e-01  -1.1241436e-03
%@   1.0032416e+03   3.9236871e-01   3.9236871e-03
%@   1.0106846e+03   7.9503379e-01   7.9503379e-03
%@   1.0181275e+03   9.9078316e-01   9.9078316e-03
%@   1.0255705e+03   9.2867105e-01   9.2867105e-03
%@   1.0330134e+03   6.2486275e-01   6.2486275e-03
%@   1.0404564e+03   1.5842751e-01   1.5842751e-03
%@   1.0478993e+03  -3.4924012e-01  -3.4924012e-03
%@   1.0553423e+03  -7.6601442e-01  -7.6601442e-03
%@   1.0627852e+03  -9.8342560e-01  -9.8342560e-03
%@   1.0702282e+03  -9.4489017e-01  -9.4489017e-03
%@   1.0776711e+03  -6.6043737e-01  -6.6043737e-03
%@   1.0851141e+03  -2.0409896e-01  -2.0409896e-03
%@   1.0925570e+03   3.0535830e-01   3.0535830e-03
%@   1.1000000e+03   7.3534292e-01   7.3534292e-03
%@
%<-- ASCII ends here -->
%<-- ASCII begins here: __data/proxyerror/testagemodel_good_proxyerror.txt__ -->
%@   1.0000000e+00   5.0000000e+01   1.2500000e+01
%@   1.1200000e+02   1.3184493e+02   1.6592247e+01
%@   2.2300000e+02   2.4033672e+02   2.2016836e+01
%@   3.3400000e+02   3.9977926e+02   2.9988963e+01
%@   4.4500000e+02   4.8204175e+02   3.4102087e+01
%@   5.5600000e+02   5.6075339e+02   3.8037669e+01
%@   6.6700000e+02   6.4649778e+02   4.2324889e+01
%@   7.7800000e+02   7.8811352e+02   4.9405676e+01
%@   8.8900000e+02   8.8040018e+02   5.4020009e+01
%@   1.0000000e+03   1.0028415e+03   6.0142074e+01
%@
%<-- ASCII ends here -->
