function [D1, D2, D3, D4, a_report,b_report,c_report,d_report,e_report,...
	  names,doit]=yuri(instrument,datapath,tempdirpath,filename,...
	              advanced,isdat_db,option)
%*************************************************************************
% CLUSTER project: BIN-Files to MatLab             Autor: Christian Maszl  
% Unit System = [SI]                  Mail: e0025754@student.tuwien.ac.at 
%*************************************************************************
%
% Version 1.0 - 20.8.2004
%
% This script is the interface to the program of Yuri
% Kothjaintsev (IRFU).

%*************************************************************************
% Computation interval in sec (default=86400 - 1day)
t_interval  = advanced(1,4);
% Interpolation method for the position vectors
interpolmeth= 'spline';
% Quantity r for position vectors
quantity    = 'r';
% Store path of the m-Files
path        = pwd;
%*************************************************************************

% datapath MUST point to the /data/cluster directory and NOT to 
% /data/cluster/DDS/. getData will also look for files in some other
% directories. Take care that at the end of /data/cluster is NO / !
datapath=strrep(datapath,'/DDS/','');

% Extract the date from the filename and set the starttime of the 
% computation (default=0:0:1 -> 1sec after midnight)
% Store year
datum(1,1)=2000+str2double(sscanf(filename,'%2c',1));
% Store month
datum(1,2)=str2double(sscanf(filename,'%*2c%2c',1));
% Store day
datum(1,3)=str2double(sscanf(filename,'%*4c%2c',1));
% Store hour    (0=default)
datum(1,4)=advanced(1,1);
% Store minute  (0=default)
datum(1,5)=advanced(1,2);
% Store seconds (1 after midnight=default)
datum(1,6)=advanced(1,3)+1;
%*************************************************************************

% The subroutine getData can't handle large intervals of t_interval
% - Split intervall in 4 pieces (trial).
% [] Rework getData to support large ranges.
t_interval=t_interval/4;
% Find starttime in seconds
starttime(1,1)=datum(1,4)*3600+datum(1,5)*60+datum(1,6);
starttime(1,2)=starttime(1,1)+t_interval+1;
starttime(1,3)=starttime(1,2)+t_interval+1;
starttime(1,4)=starttime(1,3)+t_interval+1;
% Define error variables for the error report
% 4 satellites, 4 time intervals
a_report      =zeros(4,4);
b_report      =zeros(4,1);
c_report      =zeros(4,1);
d_report      =zeros(4,4);
e_report      =zeros(4,4);
errorcount_B  =0;
errorcount_r  =0;
% Enables sorting no matter if there are empty arrays
doit='n';
% Disables filling with zeros and a time line of empty arrays
skip='n';
% Check for operation mode 
if     (size(instrument,2)==4)
    if (instrument=='whip' | instrument=='bfgm')
        modus=1;
    else
    end
    if (instrument=='ncis' | instrument=='vcis')
        modus=2;
    else
    end
    % Set the width of ncis ... to find the time t
    if (instrument=='ncis')
        width=2;
    else
    end
    if (instrument=='vcis')
        width=4;
    else
    end
elseif (size(instrument,2)==3)    
    if (instrument=='edi'  | instrument=='sax' )  
        modus=1;
        if (instrument=='sax')	
	% Don't try to fill empty arrays with time
	    skip ='y';
	else
	end
    else
    end
    if (instrument=='vce')
        modus=2;
	% Set the width of vce ... to find the time t
	width=4;
    else
    end
 elseif (size(instrument,2)==1) 
    if (instrument=='r'    | instrument=='b'   )
        modus=1;
    else
    end
    if (instrument=='e')
        modus=2;
    else
    end
    if (instrument=='p')
        modus=3;
    else
    end
    % Set the width of e ... to find the time t
    if (instrument=='e')
        width=2;
    else
    end
    if (instrument=='a')
        modus=1;
    else
    end
else
    modus=0;
end
%*************************************************************************
% Deal with cells with one enclosed matrix 
%*************************************************************************
if (modus==1)
% Use Yuri's subroutine to get B1-B4. i choose the satellite
for i=1:1:4
    % The following loop is necessary due to the splitting of the data
    for j=1:1:4
        if (j==4)
        % -5 makes sure that the range stay one second smaller than 
        % a whole day.
            t_interval=t_interval-5;
        end
        % Convert the new starttimes in hh mm ss
        hours     =timedim(starttime(1,j),'seconds','hours');
        datum(1,4)=hours-rem(hours  ,1);
        minutes=rem(hours,1)*60;
        datum(1,5)=minutes-rem(minutes,1);
        seconds=rem(minutes,1)*60;
        datum(1,6)=seconds-rem(seconds,1);
        % Use try - catch to intercept errors of GetData
	try
	% Use Yuri's subroutine to get B1-B4.
	    eval(['B',int2str(i),'=getData(ClusterDB(isdat_db,datapath,'...
                  'tempdirpath),toepoch(datum),t_interval,',int2str(i), ...
                  ',instrument,option);']);
        % Convert cell to array 
            eval(['names(i,:)=B',int2str(i),'{:,1};']);
	    eval(['B',int2str(i),'=B',int2str(i),'{:,2};']);
	    data_B='y';
	catch
            eval(['B',int2str(i),'=[0 0 0 0];']);
	    data_B='n';
	    errorcount_B=errorcount_B+1;
	    if (errorcount_B==4)
	        names(i,:)='No Data!';
                b_report(i) =1;
	    else
            end  	    
	end
	try
	% Use Yuri's subroutine to get r1-r4 for every ~five
        % minutes - interpolate. 
            eval(['r',int2str(i),'=getData(ClusterDB(isdat_db,datapath,'...
                  'tempdirpath),toepoch(datum),t_interval,',int2str(i), ...
                  ',quantity,option);']);
	    eval(['r',int2str(i),'=r',int2str(i),'{:,2};']);
	    data_r='y';
	catch
	    eval(['r',int2str(i),'=[0 0 0 0];']);
	    data_r    ='n';
	    errorcount_r=errorcount_r+1;
	    if (errorcount_r==4)
                c_report(i)=1;
            else
            end
	end
	% Perform error check
	if (data_B=='y' & data_r=='y')
	else
	    if     (data_B=='y' & data_r=='n')
	            a_report(i,j)=1;
	    elseif (data_B=='n' & data_r=='y')
	            d_report(i,j)=1;
	    elseif (data_B=='n' & data_r=='n')
	            e_report(i,j)=1;
	    else
	    end	          
	end
	
	% Interpolate the position vector
        % [z]=av_interp(x,y,method) interpolates x to the time line of y
            eval(['r',int2str(i),'=av_interp(r',int2str(i), ...
	         ',B',int2str(i),',interpolmeth);']);
        % Store variables in temporary variable Dtemp  
            eval(['Dtemp',int2str(i),int2str(j),'=[B',int2str(i), ...
                 ' r',int2str(i),'(:,2:4)];']);
	% Free memory	
            clear B* r*;
    end
    % Construct DX for the sorting routine
    eval(['D',int2str(i),'=[Dtemp',int2str(i),int2str(1),'; Dtemp',...
          int2str(i),int2str(2),';Dtemp',int2str(i),int2str(3),    ...
          '; Dtemp',int2str(i),int2str(4),'];']);
    % Delete lines with no data
    eval(['indexlist=find(D',int2str(i),'(:,1));']);
    eval(['D',int2str(i),'=D',int2str(i),'(indexlist,:);']);
    % Resert for the next satellite
    errorcount_B=0;
    errorcount_r=0;
    clear Dtemp*;
    % Kick getData out of the memory. This should solve the problem
    % with log periods (more than 30 days).
    clear functions;
end
% Clear files in the temp directory
cd(tempdirpath);
delete('tB_*');
% Restore the path to the m-Files
cd(path);
query1=isempty(D1);
query2=isempty(D2);
query3=isempty(D3);
query4=isempty(D4);
% Skip if instrument=sax
if (skip=='y')
else
  % EDI only delivers three arrays, fill the empty one with time
  % and zeros to you the sorting routine.
  if(query1==1 | query4==1)
     if(query1==1 & query4==0)
        D1=zeros(size(D4,1),size(D4,2));
        % Fill with timeline of D4
        D1(:,1)=D4(:,1);
     else
     end
     if(query1==0 & query4==1)
        D4=zeros(size(D1,1),size(D1,2));
        % Fill with timeline of D4
        D4(:,1)=D1(:,1);
     else
     end
  else
  end
  if(query1==2 | query3==1)
     if(query2==1 & query3==0)
        D2=zeros(size(D3,1),size(D3,2));
        % Fill with timeline of D4
        D2(:,1)=D3(:,1);
     else
     end
     if(query2==0 & query3==1)
        D3=zeros(size(D2,1),size(D2,2));
        % Fill with timeline of D4
        D3(:,1)=D2(:,1);
     else
     end
  else
  end
end
if (isempty(D1)==0 | isempty(D2)==0 | isempty(D3)==0 | ...
    isempty(D4)==0 )
    % Enable sorting again!
    doit='y';
else
    doit='n';
end
else
end
%*************************************************************************
% Deal with cells with two enclosed matrices 
%*************************************************************************
if (modus==2)
% Use Yuri's subroutine to get B1-B4. i choose the satellite
for i=1:1:4
    % The following loop is necessary due to the splitting of the data
    for j=1:1:4
        if (j==4)
        % -4 makes sure that the range stay one second smaller than 
        % a whole day.
            t_interval=t_interval-5;
        end
        % Convert the new starttimes in hh mm ss
        hours     =timedim(starttime(1,j),'seconds','hours');
        datum(1,4)=hours-rem(hours  ,1);
        minutes=rem(hours,1)*60;
        datum(1,5)=minutes-rem(minutes,1);
        seconds=rem(minutes,1)*60;
        datum(1,6)=seconds-rem(seconds,1);
        % Use try - catch to intercept erros of GetData
	try
	% Use Yuri's subroutine to get B1-B4.
	    eval(['B',int2str(i),'=getData(ClusterDB(isdat_db,datapath,'...
                  'tempdirpath),toepoch(datum),t_interval,',int2str(i), ...
                  ',instrument,option);']);
	    data_B='y';
	catch
	    disp('Error in getData.m!');
	    eval(['B',int2str(i),'=[];']);
	end
	% Fill with zeros if empty
	query1=eval(['isempty(B',int2str(i),')']);
	if (query1==1)
            if     (size(instrument,2)==1)  
	            if (instrument=='e')
		        eval(['A',int2str(i),'=[0 0];']);
	                eval(['C',int2str(i),'=[0 0];']);
		    else
		    end		        
	    elseif (size(instrument,2)==3)
	            if (instrument=='vce')
                        eval(['A',int2str(i),'=[0 0 0 0];']);
                        eval(['C',int2str(i),'=[0 0 0 0];']);		      
		    else
		    end
            elseif (size(instrument,2)==4)  
	            if     (instrument=='ncis')
                        eval(['A',int2str(i),'=[0 0];']);
	                eval(['C',int2str(i),'=[0 0];']);
		    elseif (instrument=='vcis')
		        eval(['A',int2str(i),'=[0 0 0 0];']);
	                eval(['C',int2str(i),'=[0 0 0 0];']);
		    else
		    end   
	    else
	    end
	    data_B='n';
	    errorcount_B=errorcount_B+1;
	    if (errorcount_B==4)
                names{i,1}='No Data!';
                names{i,2}='No Data!';
                b_report(i) =1;
	    else
            end  	    
	else
	    % Convert cell to array 
	    try
               eval(['names(i,:)=B',int2str(i),'{:,1};']);
	    catch
	       names{i,1}='No Data!';
	       names{i,2}='No Data!'; 
	    end
	    try
               eval(['A',int2str(i),'=B',int2str(i),'{:,2};']);
	    catch
	       eval(['A',int2str(i),'=[];']);
	    end
	    try
	       eval(['C',int2str(i),'=B',int2str(i),'{:,3};']);
	    catch
	       eval(['C',int2str(i),'=[];']);
	    end  
	end
        % Check for empty cell. 
        query1=eval(['isempty(A',int2str(i),')']);
	query2=eval(['isempty(C',int2str(i),')']);
	if(query1==1 | query2==1)
	   if(query1==1 & query2==0)
	      eval(['A',int2str(i),'=zeros(size(C',int2str(i),',1),size(C',int2str(i),',2));']);
	      % Write T (time) into the empty cell
              eval(['A',int2str(i),'(:,1)=C',int2str(i),'(:,1);']);
	   else
	   end
	   if(query1==0 & query2==1)
	      eval(['C',int2str(i),'=zeros(size(A',int2str(i),',1),size(A',int2str(i),',2));']); 
	      % Write T (time) into the empty cell
	      eval(['C',int2str(i),'(:,1)=A',int2str(i),'(:,1);']);
	   else
	   end
	else
	 % Find minimum length of A and C and bring both to the same length
	   eval(['l=min(size(A',int2str(i),',1),size(C',int2str(i),',1));']);
	   eval(['A',int2str(i),'=A',int2str(i),'(1:l,:);']);
	   eval(['C',int2str(i),'=C',int2str(i),'(1:l,:);']);
	end
	try
        % Use Yuri's subroutine to get r1-r4 for every five
        % minutes - interpolate. 
            eval(['r',int2str(i),'=getData(ClusterDB(isdat_db,datapath,'...
                  'tempdirpath),toepoch(datum),t_interval,',int2str(i), ...
                  ',quantity,option);']);
	    eval(['r',int2str(i),'=r',int2str(i),'{:,2};']);
	    data_r='y';
	catch
	    eval(['r',int2str(i),'(1,:)=0;']);
	    data_r    ='n';
	    errorcount_r=errorcount_r+1;
	    if (errorcount_r==4)
                c_report(i)=1;
            else
            end
	end
	% Perform error check
	if (data_B=='y' & data_r=='y')
	else
	    if     (data_B=='y' & data_r=='n')
	            a_report(i,j)=1;
	    elseif (data_B=='n' & data_r=='y')
	            d_report(i,j)=1;
	    elseif (data_B=='n' & data_r=='n')
	            e_report(i,j)=1;
	    else
	    end	          
	end
	% Interpolate the position vector
        % [z]=av_interp(x,y,method) interpolates x to the time line of y
	    eval(['r',int2str(i),'=av_interp(r',int2str(i), ...
	         ',A',int2str(i),',interpolmeth);']);
	% Store variables in temporary variable Dtemp  
            eval(['Dtemp',int2str(i),int2str(j),'=[A',int2str(i), ...
                 ' C',int2str(i), ' r',int2str(i),'(:,2:4)];']);
	% Free memory	
            clear B* r*;
    end
    % Construct DX for the sorting routine
    eval(['D',int2str(i),'=[Dtemp',int2str(i),int2str(1),'; Dtemp',...
          int2str(i),int2str(2),';Dtemp',int2str(i),int2str(3),    ...
          '; Dtemp',int2str(i),int2str(4),'];']);
    % Delete lines with no data
    eval(['indexlist=find(D',int2str(i),'(:,1));']);
    eval(['D',int2str(i),'=D',int2str(i),'(indexlist,:);']);
    % Resert for the next satellite
    errorcount_B=0;
    errorcount_r=0;
    clear Dtemp*;
    % Kick getData out of the memory. This should solve the problem
    % with log periods (more than 30 days).
    clear functions;
 end
% Clear files in the temp directory
cd(tempdirpath);
delete('tB_*');
% Restore the path to the m-Files
cd(path);
query1=isempty(D1);
query2=isempty(D2);
query3=isempty(D3);
query4=isempty(D4);
% NCIS sometimes delivers three arrays, fill the empty one with time
% and zeros to you the sorting routine.
if(query1==1 | query4==1)
   if(query1==1 & query4==0)
      D1=zeros(size(D4,1),size(D4,2));
      % Fill with timeline of D4
      D1(:,1)=D4(:,1);
   else
   end
   if(query1==0 & query4==1)
      D4=zeros(size(D1,1),size(D1,2));
      % Fill with timeline of D4
      D4(:,1)=D1(:,1);
   else
   end
else
end
if(query2==1 | query3==1)
   if(query2==1 & query3==0)
      D2=zeros(size(D3,1),size(D3,2));
      % Fill with timeline of D4
      D2(:,1)=D3(:,1);
   else
   end
   if(query2==0 & query3==1)
      D3=zeros(size(D2,1),size(D2,2));
      % Fill with timeline of D4
      D3(:,1)=D2(:,1);
   else
   end
else
end
if (isempty(D1)==0 | isempty(D2)==0 | isempty(D3)==0 | ...
    isempty(D4)==0 )
    % Enable sorting again!
    doit='y';
else
    doit='n';
end
else
end
%**************************************************************************
% Deal with cells with seven enclosed matrices 
%**************************************************************************
if (modus==3)
% Use Yuri's subroutine to get B1-B4. i choose the satellite
for i=1:1:4
    % The following loop is necessary due to the splitting of the data
    for j=1:1:4
        if (j==4)
        % -4 makes sure that the range stay one second smaller than 
        % a whole day.
            t_interval=t_interval-5;
        end
        % Convert the new starttimes in hh mm ss
        hours     =timedim(starttime(1,j),'seconds','hours');
        datum(1,4)=hours-rem(hours  ,1);
        minutes=rem(hours,1)*60;
        datum(1,5)=minutes-rem(minutes,1);
        seconds=rem(minutes,1)*60;
        datum(1,6)=seconds-rem(seconds,1);
        % Use try -> catch to intercept erros of GetData
	try
	% Use Yuri's subroutine to get B1-B4.
	    eval(['B',int2str(i),'=getData(ClusterDB(isdat_db,datapath,'...
                  'tempdirpath),toepoch(datum),t_interval,',int2str(i), ...
                  ',instrument,option);']);
	    data_B='y';
	catch
	    disp('Error in getData.m!');
	    eval(['B',int2str(i),'=[];']);
	end
	query1=eval(['isempty(B',int2str(i),')']);
	if (query1==1)
            eval(['A',int2str(i),'=[0 0];']);
            eval(['C',int2str(i),'=[0 0];']);
            eval(['D',int2str(i),'=[0 0];']);	    
            eval(['E',int2str(i),'=[0 0];']);	    
            eval(['F',int2str(i),'=[0 0];']);	    
            eval(['G',int2str(i),'=[0 0];']);	    
	    eval(['H',int2str(i),'=[0 0 0];']);
	    data_B='n';
	    errorcount_B=errorcount_B+1;
	    if (errorcount_B==4)
	        for k=1:1:7
	            names{i,k}='No Data!';
	        end
                b_report(i) =1;
	    else
            end  	    
	else
	% Convert cell to array 
            try
               eval(['names(i,:)=B',int2str(i),'{:,1};']);
            catch
	       for k=1:1:7
	           names{i,k}='No Data!';
	       end
	    end
	    try
	       eval(['A',int2str(i),'=B',int2str(i),'{:,2};']);
	    catch
	       eval(['A',int2str(i),'=[];']);
	    end
	    try
	       eval(['H',int2str(i),'=B',int2str(i),'{:,3};']);
	    catch
	       eval(['H',int2str(i),'=[];']);
	    end
	    try
	       eval(['C',int2str(i),'=B',int2str(i),'{:,4};']);
	    catch
	       eval(['C',int2str(i),'=[];']);
	    end
	    try
	       eval(['D',int2str(i),'=B',int2str(i),'{:,5};']);
	    catch
	       eval(['D',int2str(i),'=[];']);
	    end
	    try
	       eval(['E',int2str(i),'=B',int2str(i),'{:,6};']);
	    catch
	       eval(['E',int2str(i),'=[];']);
	    end
	    try
	       eval(['F',int2str(i),'=B',int2str(i),'{:,7};']);
	    catch
               eval(['F',int2str(i),'=[];']);
	    end
	    try
	       eval(['G',int2str(i),'=B',int2str(i),'{:,8};']);
	    catch
	       eval(['G',int2str(i),'=[];']);
	    end
	end
	% Check for empty cells
	query1=eval(['isempty(A',int2str(i),')']);
	query2=eval(['isempty(H',int2str(i),')']);
        query3=eval(['isempty(C',int2str(i),')']);	
	query4=eval(['isempty(D',int2str(i),')']);
	query5=eval(['isempty(E',int2str(i),')']);
	query6=eval(['isempty(F',int2str(i),')']);
	query7=eval(['isempty(G',int2str(i),')']);
	if ( query1==1 | query2==1 |query3==1 | query4==1 | query5==1 ...
	   | query6==1 | query7==1)
	% [] Find the empty arrays and fill them with a timeline 
	
	else
	% Find minimum length of A-G and bring all to the same size
	   eval(['l=min([size(A',int2str(i),',1) size(H',int2str(i),',1) '...
		       ' size(C',int2str(i),',1) size(D',int2str(i),',1) '...
	               ' size(E',int2str(i),',1) size(F',int2str(i),',1) '...
	               ' size(G',int2str(i),',1)]);']);
           eval(['A',int2str(i),'=A',int2str(i),'(1:l,:);']);
	   eval(['H',int2str(i),'=H',int2str(i),'(1:l,:);']);
	   eval(['C',int2str(i),'=C',int2str(i),'(1:l,:);']);
	   eval(['D',int2str(i),'=D',int2str(i),'(1:l,:);']);
	   eval(['E',int2str(i),'=E',int2str(i),'(1:l,:);']);
	   eval(['F',int2str(i),'=F',int2str(i),'(1:l,:);']);
	   eval(['G',int2str(i),'=G',int2str(i),'(1:l,:);']);
	end
	try
	% Use Yuri's subroutine to get r1-r4 for every five
        % minutes - interpolate. 
            eval(['r',int2str(i),'=getData(ClusterDB(isdat_db,datapath,'...
                  'tempdirpath),toepoch(datum),t_interval,',int2str(i), ...
                  ',quantity,option);']);
	    eval(['r',int2str(i),'=r',int2str(i),'{:,2};']);
	    data_r='y';
	catch
	    eval(['r',int2str(i),'(1,:)=0;']);
	    data_r    ='n';
	    errorcount_r=errorcount_r+1;
	    if (errorcount_r==4)
                c_report(i)=1;
            else
            end
	end
	% Perform error check
	if (data_B=='y' & data_r=='y')
	else
	    if     (data_B=='y' & data_r=='n')
	            a_report(i,j)=1;
	    elseif (data_B=='n' & data_r=='y')
	            d_report(i,j)=1;
	    elseif (data_B=='n' & data_r=='n')
	            e_report(i,j)=1;
	    else
	    end	          
	end
	
	% Interpolate the position vector
        % [z]=av_interp(x,y,method) interpolates x to the time line of y
            eval(['r',int2str(i),'=av_interp(r',int2str(i), ...
	         ',A',int2str(i),',interpolmeth);']);
        % Store variables in temporary variable Dtemp  
            eval(['Dtemp',int2str(i),int2str(j),'=[A',int2str(i), ...
                 ' H',int2str(i), ' C',int2str(i),...
		 ' D',int2str(i), ' E',int2str(i),...
		 ' F',int2str(i), ' G',int2str(i),...
		  ' r',int2str(i),'(:,2:4)];']);
	% Free memory	
            clear B* r*;
    end
    % Construct DX for the sorting routine
    eval(['D',int2str(i),'=[Dtemp',int2str(i),int2str(1),'; Dtemp',...
          int2str(i),int2str(2),';Dtemp',int2str(i),int2str(3),    ...
          '; Dtemp',int2str(i),int2str(4),'];']);
    % Delete lines with no data
    eval(['indexlist=find(D',int2str(i),'(:,1));']);
    eval(['D',int2str(i),'=D',int2str(i),'(indexlist,:);']);
    % Resert for the next satellite
    errorcount_B=0;
    errorcount_r=0;
    clear Dtemp*;
    % Kick getData out of the memory. This should solve the problem
    % with log periods (more than 30 days).
    clear functions;
 end
% Clear files in the temp directory
cd(tempdirpath);
delete('tB_*');
% Restore the path to the m-Files
cd(path);
query1=isempty(D1);
query2=isempty(D2);
query3=isempty(D3);
query4=isempty(D4);
% Sometimes delivers three arrays, fill the empty one with time
% and zeros to you the sorting routine.
if(query1==1 | query4==1)
   if(query1==1 & query4==0)
      D1=zeros(size(D4,1),size(D4,2));
      % Fill with timeline of D4
      D1(:,1)=D4(:,1);
   else
   end
   if(query1==0 & query4==1)
      D4=zeros(size(D1,1),size(D1,2));
      % Fill with timeline of D4
      D4(:,1)=D1(:,1);
   else
   end
else
end
if(query2==1 | query3==1)
   if(query2==1 & query3==0)
      D2=zeros(size(D3,1),size(D3,2));
      % Fill with timeline of D4
      D2(:,1)=D3(:,1);
   else
   end
   if(query2==0 & query3==1)
      D3=zeros(size(D2,1),size(D2,2));
      % Fill with timeline of D4
      D3(:,1)=D2(:,1);
   else
   end
else
end
if (isempty(D1)==0 | isempty(D2)==0 | isempty(D3)==0 | ...
    isempty(D4)==0 )
    % Enable sorting again!
    doit='y';
else
    doit='n';
end
else
end
%**************************************************************************
% Here start the part that is equal for all datatypes
%**************************************************************************
% Convert the ISDAT epoch in hours of the specific day
for i=1:1:4
  eval(['T',int2str(i),'=fromepoch(D',int2str(i),'(:,1));']);
  eval(['dayhour=T',int2str(i),'(:,4)+T',int2str(i),'(:,5)/60+T', ...
	int2str(i),'(:,6)/3600;']);
  eval(['D',int2str(i),'(:,1)=dayhour;']);

% Yuri's program mix the times when you calculate over a whole day
% -> sort the rows
   eval(['D',int2str(i),'=sortrows(D',int2str(i),',1);']);
end
if (modus==2)
    for i=1:1:4
        eval(['T',int2str(i),'=fromepoch(D',int2str(i),'(:,width+1));']);
        eval(['dayhour=T',int2str(i),'(:,4)+T',int2str(i),'(:,5)/60+T', ...
	int2str(i),'(:,6)/3600;']);
        eval(['D',int2str(i),'(:,width+1)=dayhour;']);
    end
else
end

%**************************************************************************
% SUPPORTED DATA TYPES
%**************************************************************************
% POSITION data [GSE]

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  r             Cell       R1                 : x 4   t x y z      nosave 
% Comment: Interpolate with av_interp to an arbitrary timeline.
%**************************************************************************
% PHASE data

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  a             Cell       A1                 : x 2    t a         nosave
% Comment: Interpolate with av_interp to an arbitrary timeline.
%**************************************************************************
% SPIN axis vector [GSE]

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  sax           Cell       SAX1               : x 3    x y z       nosave
% Comment: 
%**************************************************************************
% FGM magnetometer data [GSE+DSI]

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  b             Cell       BPP1               : x 4    t x y z     nosave
% Comment: 4sec data

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  bfgm          Cell       B1                 : x 4    t x y z     nosave
% Comment: 45msec data
%**************************************************************************
% CIS (Cluster Ion Spectrometry [GSE+DSI]

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  ncis          Cell       NCp1               : x 2   t p          nosave
%                           NCh1               : x 2   t h         

%  vcis          Cell       VCp1               : x 4   t x y z      nosave
%                           VCh1               : x 4   t x y z     

%  vce           Cell       VCEp1              : x 4   t x y z      nosave
%                           VCEh1              : x 4   t x y z     
% Comment: VCE will only work if you run VCIS and B before! Note
%          that the option 'nosave' has to be disabled in this
%          case. VCE reads the data from mB.mat and mC.mat 
%**************************************************************************
% WHISPER (Wave of HIgh frequency and Sounder for Probing of Electron 
%          density by Relaxation)

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  whip          Cell       WHIP1              : x 2    t w         nosave
%**************************************************************************
% EDI (Electron Drift instrument)

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  edi           Cell       EDI1               : x 4    t x y z     nosave
%**************************************************************************
% ASPOC (Active Spacecraft Potential Control) -> Probe potential

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  p             Cell       P10Hz1p1           : x 2    t x         nosave
%                           P10Hz1p2           : x 2    t x         
%                           P10Hz1p3           : x 2    t x         
%                           P10Hz1p4           : x 2    t x         
%                           P10Hz1             : x 2    t x         
%                           P1                 : x 2    t x         
%                           NVps1              : x 3    t x y
%**************************************************************************
% EFW (Electron Field and Wave instrument)

% [parameter]   [output]   [names in {1,1}]   [size]   [format]    [option]
%  e             Cell       we[X]p12           : x 2    t x         nosave
%                           we[X]p34           : x 2    t x         
%**************************************************************************

