%           tidevel.m
%                    uses tidecoef to make tide coeficients for 
%                             a bunch of vel bins
fprefix=input('file prefix for velocity (in quotes) ');
fpout=input('file prefix for output files ');
eval(concat('load ',fprefix,'vel.bin'));           % load raw
fnav=input('file prefix for nav ');
eval(concat('load ',fnav,'nav.bin'));              % load cal file
m=input('lowest subscript number ');
n=input('highest subscript number ');
tnew=input('tnew ');
eval('tbin=cleanall(tbin);')

tidecommand=concat('save ',fpout,'cof.tid date ');
newcommand=concat('save ',fpout,'vel.tid date tnew');
for i=m:n;
  uname=concat('u',int2str(i),'bin');
  vname=concat('v',int2str(i),'bin');
%                         clean out all bad points
  eval(concat(uname,'=cleanall(',uname,');'))
  eval(concat(vname,'=cleanall(',vname,');'))
  inname=concat('(',uname,',',vname,',tbin);');
  outname=concat('[u',int2str(i),'coef,v',int2str(i),'coef]');
%                              run tidecoef
  command=concat(outname,'=tidecoef',inname)
  eval(command)
  inname=concat('(u',int2str(i),'coef,v',int2str(i),'coef,tnew);');
  outname=concat('[u',int2str(i),'new,v',int2str(i),'new]');
%                              run tidesamp
  command=concat(outname,'=tidesamp',inname)
  eval(command)
  tidecommand=concat(tidecommand,' u',int2str(i),'coef v',int2str(i),'coef');
  newcommand=concat(newcommand,' u',int2str(i),'new v',int2str(i),'new');
end

%                             save everything
tidecommand
eval(tidecommand)
newcommand
eval(newcommand)
