%script to run PIV analysis for PICS Pellet and Sand Study 20140915

%% 
pnseq='C:\Users\gracec\Documents\PICS\YR141204\Sequences';  %Path containing the SEQ files
pnout='C:\Users\gracec\Documents\PICS\YR141204\Analysis'; %Path to write results
if ~exist(pnout,'file') %if output directory doesn't exist, create it
    mkdir(pnout);
end
files=dir(fullfile(pnseq,'*.seq')); %list of SEQ files for processing
nf=length(files); %number of files in the list
%nstart=1; %starting index in the file list
%nf=45; %ending index of file list
nstart=67;
for k=nstart:nf
   fnseq=fullfile(pnseq,files(k).name);
   fnout=fullfile(pnout,['piv_',strrep(files(k).name,'.seq','.mat')]);
   hdr=load_SEQ(fnseq);
   fps=hdr.FrameRate;
   m=im_background(fnseq,'mode',50);
   piv=im_piv(fnseq,m,[8,10],'bwrep');
   save(fnout,'piv','-v7')
   %create video of PIV results
   opts.fps=fps;
   video_piv(fnseq,m,piv,strrep(fnout,'.mat','.avi'),opts)
end
