% Last modified: 06/09/2012 by Pete

%% Stochastic Flow Past an Obstacle Saving Script

% create save directory and save parameters at first time step
if ( t == 0 )
    
    savedir = sprintf( '%s/Save/%s', trunk, tag ) ;
    if ( ~exist( savedir, 'dir' ) )
        mkdir(savedir)
    end
    
    if ( ~exist( sprintf( '%s/%s', savedir, subtag ), 'dir' ) )
        mkdir( sprintf( '%s/%s', savedir, subtag ) )
    end
    
    savefile = sprintf( '%s/%s/param.mat', savedir, subtag ) ;
    save(savefile)
    fprintf( 'Saved ''%s''.\n', savefile )
    
end


%% plot

if ( GenFig )
    
    figure(1), clf
    
    shapenames = {'circle',...
                  'square',...
                  'upstream-pointing triangle',...
                  'downstream-pointing triangle',...
                  'diamond'} ;
    titlestr = shapenames{shape} ;
    u_tmp = [ NaN ; u(2:end) ] ;
    v_tmp = [ NaN ; v(2:end) ] ;
    rho_tmp = [ NaN ; rho(2:end) ] ;
    
    % render flow field with vorticity and streamlines
    Pete_plotfield
    
end


%% save

% save data
savefile = sprintf( '%s/%s/%05d.mat', savedir, subtag, round(100*t) ) ;
save( savefile, 't', 'u', 'v', 'ui', 'vi', 'YYt', 'obsstep', ...
    'loglikes', 'runtime' )
fprintf( 'Saved ''%s''.\n', savefile )

if ( GenFig )
    
    % save plot
    savefile = sprintf( '%s/%s/%05d.jpg', ...
        savedir, subtag, round(100*t) ) ;
    print( 1, '-djpeg85', '-r200', savefile )
    fprintf( 'Saved ''%s''.\n', savefile )
    
end

