%**************************************************************************
% CLUSTER project: User input                      Autor: Christian Maszl * 
% Unit System = [SI]                  Mail: e0025754@student.tuwien.ac.at *
%**************************************************************************

l=size(myfilelist,1);
date1=sscanf(myfilelist{1,1},'%6c',1);
date2=sscanf(myfilelist{l,1},'%6c',1);
% Output number of datapackages (1 package = four satellites)
text1=sprintf('%s %u %s\n','The filelist contains',l,...
	      ' datapackages. 1 package = 4 files (satellite 1-4)');
% Output the date of the earliest and the latest measurement
text2=sprintf('%s %6s %s %6s\n','Start date:',date1,' ->  End date:',date2);
text3=sprintf('%s %u%s','Please enter a [M]anual range from: 1 to',l,...
	      ', view the [F]ilelist or choose [A]ll.');
disp(text1);disp(text2);disp(text3);
user_entry = input('','s') ;
% Show the filelist
if (lower(user_entry)=='f')
   j=1;
   for i=1:size(myfilelist,1)/4
       ausgabe=[  '[' int2str(j  ) '] ' myfilelist{j  ,1} ...
		'  [' int2str(j+1) '] ' myfilelist{j+1,1} ...
		'  [' int2str(j+2) '] ' myfilelist{j+2,1} ...
		'  [' int2str(j+3) '] ' myfilelist{j+3,1}];
       disp(ausgabe);
       j=j+4;
   end
   rest=mod(size(myfilelist,1),4);
   switch rest
     case 1
          ausgabe=[  '[' int2str(j  ) '] ' myfilelist{j  ,1}];
          disp(ausgabe);
     case 2
          ausgabe=[  '[' int2str(j  ) '] ' myfilelist{j  ,1} ...
		   '  [' int2str(j+1) '] ' myfilelist{j+1,1}];
          disp(ausgabe);
     case 3
          ausgabe=[  '[' int2str(j  ) '] ' myfilelist{j  ,1} ...
	           '  [' int2str(j+1) '] ' myfilelist{j+1,1} ...
		   '  [' int2str(j+2) '] ' myfilelist{j+2,1}];
          disp(ausgabe);
     otherwise
    end
    % Read the userinput from the keyboard
    user_entry = input('Please select [A]ll or [M]anual: ','s') ;
else
end
% Check user input for desired operation mode
for i=1:10
    switch lower(user_entry)
        case 'a'
            startloop=1;
            endloop  =l;
            break;
        case 'm'
             sl=input('Start the loop at position: ');
             el=input('End the loop at position:   ');
             if (sl>=1 & el<=l & sl<=el)
                startloop=sl;
                endloop  =el;
                break;
            else
                disp('Invalid input arguments!')
            end
        otherwise
            user_entry = input('Please select [A]ll or [M]anual: ','s');
    end
    if i==10
        disp('10 times invalid input. Please check the manual!')    
    else
    end
end
clear text1 text2 text3 date1 date2 l i j sl el user_entry ausgabe rest;
