Index: /issm/trunk-jpl/src/m/plot/plot_transient_movie.m
===================================================================
--- /issm/trunk-jpl/src/m/plot/plot_transient_movie.m	(revision 26864)
+++ /issm/trunk-jpl/src/m/plot/plot_transient_movie.m	(revision 26865)
@@ -42,4 +42,25 @@
 	end
 
+	%Do we have an output?
+	isavi = 0;
+	isgif = 0;
+	ismp4 = 0;
+	if exist(options,'transient_movie_output'),
+		filename=getfieldvalue(options,'transient_movie_output');
+		[pathstr,name,ext] = fileparts(filename);
+		if strcmp(ext,'.gif')
+			isgif = 1;
+		elseif strcmp(ext,'.mp4')
+			ismp4 = 1;
+		elseif strcmp(ext,'.avi')
+			isavi = 1;
+		end
+	end
+	if isavi || ismp4
+		vid=VideoWriter([filename(1:end-4),'.avi'],'Motion JPEG AVI');
+		vid.FrameRate = 2; 
+		open(vid); 
+	end
+
 	%calculate caxis
 	if ~exist(options,'caxis'),
@@ -53,4 +74,8 @@
 	end
 
+
+	%Process mesh once for all
+	[x y z elements is2d isplanet]=processmesh(md,results(i).(field),options);
+
 	%display movie
 	nstep=1;
@@ -60,14 +85,41 @@
 		if ~isempty(results(i).(field)),
 			%process data
-			[x y z elements is2d isplanet]=processmesh(md,results(i).(field),options);
 			[data datatype]=processdata(md,results(i).(field),options);
 
 			clf;
-			titlestring=[field ' at time ' num2str(results(i).time,'%7.2f') ' year'];
+			titlestring=[field ' (time ' num2str(results(i).time,'%7.2f') ' yr)'];
 			plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options)
 			apply_options_movie(md,options,titlestring);
 
-			if exist(options,'transient_movie_output'),
-				set(gcf,'Renderer','zbuffer','color','white'); %fixes a bug on Mac OS X (not needed in future Matlab version)
+			%Add grounding line
+			if exist(options,'groundingline')
+				contours=isoline(md, results(i).MaskOceanLevelset,'output','matrix');
+				hold on
+				plot(contours(:,1),contours(:,2),getfieldvalue(options,'groundingline'));
+			end
+
+			%Add ice front
+			if exist(options,'icefront')
+				contours=isoline(md, results(i).MaskIceLevelset,'output','matrix');
+				hold on
+				plot(contours(:,1),contours(:,2),getfieldvalue(options,'icefront'));
+			end
+
+			if isgif
+				frame=getframe(gcf);
+				im = frame2im(frame);
+				[imind,cmap] = rgb2ind(im,256);
+				if i==1
+					imwrite(imind, cmap, filename, 'DelayTime',getfieldvalue(options,'transient_movie_time',.5), 'LoopCount',inf)
+				else
+					imwrite(imind, cmap, filename, 'WriteMode','append');
+				end
+			elseif isavi || ismp4
+				F=getframe(gcf);
+				writeVideo(vid, F);
+			end
+
+			if exist(options,'transient_movie_output')
+				%set(gcf,'Renderer','zbuffer','color','white'); %fixes a bug on Mac OS X (not needed in future Matlab version)
 				if nstep==1,
 					%initialize images and frame
@@ -87,7 +139,20 @@
 
 	%output movie if requested.
-	if exist(options,'transient_movie_output'),
-		filename=getfieldvalue(options,'transient_movie_output');
-		imwrite(images,map,filename,'DelayTime',getfieldvalue(options,'transient_movie_time',2),'LoopCount',inf)
+	if isavi || ismp4
+		close(vid);
+	end
+	if ismp4
+		while(~exist([filename]))
+			disp(['Waiting for ' filename ]);
+			pause(1)
+		end
+		filename = filename(1:end-4);
+		command=sprintf('ffmpeg -y -i %s.avi -c:v libx264 -crf 19 -preset slow -c:a libfaac -b:a 192k -ac 2 %s.mp4',filename,filename);
+		system(command);
+		filename = [filename '.mp4'];
+		disp(['Movie saved also as ' filename]);
+	end
+	if isgif
+		imwrite(images,map,filename,'DelayTime',getfieldvalue(options,'transient_movie_time',.5),'LoopCount',inf)
 	end
 
