%MMP_read_eng.m
%  a script to read a user-specified MMP ascii ENG file 
%  and make availabe in the work space the following variables:
% esnum epres ecurr evolt edpdt engtime psdate pedate pstart pstop

directory=input(' Enter the name of the directory holding the data file: ','s');
prof_num=input('    And the profile number you want to read: ');

  efile=['E',sprintf('%7.7i',prof_num)];


filename=[directory '/' efile '.TXT'];

if(exist('epres'));
clear esnum epres ecurr evolt edpdt engtime psdate pedate pstart pstop;
end

if exist(filename,'file');
eval(['load ',filename]);
   eng=eval(efile);
   disp(['Loading ENG file:  ',filename]);

        esnum=[1:1:length(eng)]; 
       epres=eng(:,9); 
       ecurr=eng(:,7);
       evolt=eng(:,8); 
       edpdt=eng(:,10);
       emo=eng(:,1);
       eday=eng(:,2);
       eyr=eng(:,3);
       ehr=eng(:,4);
       emin=eng(:,5);
       esec=eng(:,6);
	       engtime=datenum(eyr,emo,eday,ehr,emin,esec);
%
       psdate=datestr(engtime(1),2);
       pedate=datestr(engtime(end),2);      
       pstart=datestr(engtime(1),13);
       pstop=datestr(engtime(end),13);


else

disp(['File not found or is unaccessible ']);
    disp(['ENG file in question:  ',filename]);

end


