From 8736458d52392cba6d1ef2ac34bb438bd839dad5 Mon Sep 17 00:00:00 2001 From: Antoine Cyril David Hoffmann <ahoffman@spcpc606.epfl.ch> Date: Fri, 10 Jul 2020 09:16:35 +0200 Subject: [PATCH] routine for gif creation --- matlab/create_gif.m | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 matlab/create_gif.m diff --git a/matlab/create_gif.m b/matlab/create_gif.m new file mode 100644 index 00000000..8073feac --- /dev/null +++ b/matlab/create_gif.m @@ -0,0 +1,56 @@ +function [ ] = create_gif(x, y, t, h, BASIC, GRID, MODEL, delay, GIFNAME) +title1 = GIFNAME; +FIGDIR = ['../results/', BASIC.SIMID,'/']; +if ~exist(FIGDIR, 'dir') + mkdir(FIGDIR) +end + +if MODEL.CO == -1; CONAME = 'FC'; +elseif MODEL.CO == -2; CONAME = 'DC'; +elseif MODEL.CO == 0; CONAME = 'LB'; end; + +GIFNAME = [GIFNAME,'_Pe_',num2str(GRID.pmaxe),'_Je_',num2str(GRID.jmaxe),... + '_Pi_',num2str(GRID.pmaxi),'_Ji_',num2str(GRID.jmaxi),... + '_etan_',num2str(MODEL.eta_n),'_etaB_',num2str(MODEL.eta_B),'_etaT_',... + num2str(MODEL.eta_T),'_nu_',num2str(MODEL.nu),'_',CONAME]; +GIFNAME = [FIGDIR, GIFNAME,'.gif']; + +% Set colormap boundaries +hmax = max(max(max(h))); +hmin = min(min(min(h))); + +flag = 0; +if hmax == hmin + disp('Warning : h = hmin = hmax = const') +else + % Setup figure frame + fig = figure; + pcolor(x,y,h(:,:,1)); % to set up + colormap jet + colorbar + if not(flag) + caxis([hmin hmax]) + end + axis tight manual % this ensures that getframe() returns a consistent size + hold on + + for n = 1:numel(h(1,1,:)) % time loop + pcolor(x,y,h(:,:,n)); % frame plot + title([title1,', $t \approx$', sprintf('%.3d',ceil(t(n)))]) + drawnow + % Capture the plot as an image + frame = getframe(fig); + im = frame2im(frame); + [imind,cm] = rgb2ind(im,256); + % Write to the GIF File + if n == 1 + imwrite(imind,cm,GIFNAME,'gif', 'Loopcount',inf); + else + imwrite(imind,cm,GIFNAME,'gif','WriteMode','append', 'DelayTime',delay); + end + end + + disp(['Gif saved @ : ',GIFNAME]) +end +end + -- GitLab