  function do_convert2()
% Routine to read in files of ACM, CTD and ENG data 
% from each MMP profile: A*.TXT, C*.TXT, E*.TXT 
% assign variable names and output as Matlab-format data files raw*.mat
% to a user-specified data directory
%
% Input: a series of .TXT files created by MRL's unpacking program unpk2_07 
% Output: a series of raw*.mat files
%
% MFC & JMT 02/2002
%   modified for use with GUI, and added some error checking 3/02 ETM  
%      (was MMP_asc2mat.m)
%

tmp=findobj(gcf,'Tag','inEd');
direc=char(get(tmp,'String'));
tmp=findobj(gcf,'Tag','outEd');
outdir=char(get(tmp,'String'));
tmp=findobj(gcf,'Tag','drngEd');
prof_lim=get(tmp,'String');

% the main data loop
nlim=str2num(char(prof_lim));
  stas=[nlim(1):1:nlim(2)];

for mm=1:length(stas)

%define the input data file names

  efile=['E',sprintf('%7.7i',(stas(mm)))];
  afile=['A',sprintf('%7.7i',(stas(mm)))];
  cfile=['C',sprintf('%7.7i',(stas(mm)))];
  
% assign the proper sort of slash, for PC & Unix
arch=computer;
if (strcmp(arch,'PCWIN')) 
   slsh='\';
else
   slsh='/';
end

%now load the respective files and assign the variables
%  ENGINEERING FILE

 if exist([direc slsh efile,'.TXT'])
     eval(['load ',direc slsh efile,'.TXT']);
     eng=eval(efile);
  elseif exist ([direc slsh,'e',sprintf('%7.7i',(stas(mm))),'.txt'])
    eval(['load '  direc slsh ,'e',sprintf('%7.7i',(stas(mm))),'.txt'])
    eng=eval(['e',sprintf('%7.7i',(stas(mm)))]);
  else
    msg=['the ENG file specified was not found: please re-enter the path and click CONVERT again'];
    msg_window(msg);
  end

  disp([sprintf('\n'),'Processing ENG file:  ',efile]);
       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);

%  CTD FILE

 if exist([direc slsh cfile,'.TXT'])
     eval(['load ',direc slsh cfile,'.TXT']);
     ctd=eval(cfile);
  elseif exist ([direc slsh,'c',sprintf('%7.7i',(stas(mm))),'.txt'])
     eval(['load '  direc slsh,'c',sprintf('%7.7i',(stas(mm))),'.txt'])
     ctd=eval(['c',sprintf('%7.7i',(stas(mm)))]);
  else
    msg=['the file CTD specified was not found: please re-enter the path and click CONVERT again'];
    msg_window(msg);
  end

 disp(['Processing CTD file:  ',cfile]);

       csnum=[1:1:length(ctd)];
       ccond=ctd(:,1);
       ctemp=ctd(:,2); 
       cpres=ctd(:,3);

%  ACM FILE

 if exist([direc slsh afile,'.TXT'])
     eval(['load ',direc slsh afile,'.TXT']);
     acm=eval(afile);
  elseif exist ([direc slsh,'a',sprintf('%7.7i',(stas(mm))),'.txt'])
     eval(['load '  direc slsh,'a',sprintf('%7.7i',(stas(mm))),'.txt'])
     acm=eval(['a',sprintf('%7.7i',(stas(mm)))]);
  else
    msg=['the ACM file specified was not found: please re-enter the path and click CONVERT again'];
    msg_window(msg);
  end

  disp(['Processing ACM file:  ',afile]);

        asnum=[1:1:length(acm)];
        aTx=acm(:,1); 
        aTy=acm(:,2);
        aHx=acm(:,3);
	aHy=acm(:,4);
        aHz=acm(:,5); 
        Vab=acm(:,6); 
        Vcd=acm(:,7); 
        Vef=acm(:,8); 
        Vgh=acm(:,9);



clear A* C* E* a0* c0* e0*

eval(['save ',outdir slsh,'raw',sprintf('%4.4i',stas(mm)),'.mat psdate pedate pstart pstop esnum epres ecurr evolt edpdt engtime csnum ccond ctemp cpres asnum Vab Vcd Vef Vgh aTx aTy aHx aHy aHz'])

clear eng ctd acm esnum epres ecurr evolt edpdt csnum ccond ctemp 
clear cpres asnum Vab Vcd Vef Vgh aTy aHx aHy aHz engtime


end	%looping on sets

