% THIS MATLAB SCRIPT IS MAG's CONVERSION OF MVP2MAT.M
% TO MVP2MAT_MMP.M
% To read in separate files for ACM,CTD,ENG
% A*.TXT, C*.TXT, E*.TXT
% from the test new MMP test off of Hawaii in Jan 2001
%
%  And convert them to the same MATLAB format we are used to 
%  dealing with
%
% This matlab script takes a range .TXT files profiles
% in the directory.
% These files were created by FSI's program OFFLOAD.EXE
%
%MFC 22 Jan 2001


stas=input('input the range of profiles you want to process :   ');
direc=input('input the directory where these files sit  :  ','s');
outdir=input('input output directory for raw*.mat files :  ','s');

for mm=1:length(stas)
  efile=['E',sprintf('%7.7i',(stas(mm)))];
  afile=['A',sprintf('%7.7i',(stas(mm)))];
  cfile=['C',sprintf('%7.7i',(stas(mm)))];

%  ENGINEERING FILES

  eval(['load ',direc,'/',efile,'.TXT']);
  eng=eval(efile);
  disp([sprintf('\n'),'Processing ENG file:  ',efile]);
       esnum=[1:1:length(eng)]; 
       epres=eng(:,9); 
       ecurr=eng(:,7);
       eV1=eng(:,8); 
       eV2=[]; 
       edpdt=eng(:,10);


% 28 Feb 2001  John wants to add new variable engtime

       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);

% For this hawaii test time was off by 5 hours!

        engtime=engtime+5/24;
       

       psdate=datestr(engtime(1),2);
       pedate=datestr(engtime(end),2);      
       pstart=datestr(engtime(1),13);
       pstop=datestr(engtime(end),13);

%       psdate=[num2str(eng(1,1)),'/',num2str(eng(1,2)),'/',num2str(eng(1,3))];
%       if length(psdate)==8
%            psdate=psdate([1:4 7:8]); 
%%            cdate=psdate;
%            adate=psdate;
%       elseif length(psdate)==9
%            psdate=psdate([1:5 8:9]); 
%%            cdate=psdate;
%            adate=psdate;
%       elseif length(psdate)==10
%            psdate=psdate([1:6 9:10]); 
%            cdate=psdate;
%            adate=psdate;
%       else
%%           disp('There is a problem with psdate');
%       end
%        
%
%       pedate=[num2str(eng(end,1)),'/',num2str(eng(end,2)),'/',num2str(eng(end,3))];
%       if length(pedate)==8
%            pedate=pedate([1:4 7:8]); 
%       elseif length(pedate)==9
%            pedate=pedate([1:5 8:9]); 
%       elseif length(pedate)==10
%            pedate=pedate([1:6 9:10]); 
%      else
%           disp('There is a problem with pedate');
%       end
%        
%
%       pstart=[num2str(eng(1,4)),':',num2str(eng(1,5)),':',num2str(eng(1,6))];
%       pstop=[num2str(eng(end,4)),':',num2str(eng(end,5)),':',num2str(eng(end,6))];


%  CTD FILES

  eval(['load ',direc,'/',cfile,'.TXT']);
  ctd=eval(cfile);
  disp(['Processing CTD file:  ',cfile]);


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


%  ACM FILES

   eval(['load ',direc,'/',afile,'.TXT']);
   acm=eval(afile);
   disp(['Processing ACM file:  ',afile]);

        asnum=[1:1:length(eng)];
        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*

eval(['save ',outdir,'/raw',sprintf('%4.4i',stas(mm)),'.mat'])

clear eng ctd acm esnum epres ecurr eV1 eV2 ept csnum ccon ctemp 
clear cpres asnum aVx aVy aVz aTx aTy aHx aHy aHz engtime


end	%looping on sets

