Index: /issm/trunk/src/m/model/plot/kmlgroundoverlay.m
===================================================================
--- /issm/trunk/src/m/model/plot/kmlgroundoverlay.m	(revision 7028)
+++ /issm/trunk/src/m/model/plot/kmlgroundoverlay.m	(revision 7028)
@@ -0,0 +1,61 @@
+function kmlgroundoverlay(md,options);
+%KMLGROUNDOVERLAY: create ground overlay image in kml format
+%
+%
+%    options: 
+%         kmlfilename
+%         imagename
+%
+%    Usage: 
+%         kmlgroundoverlay(md,'kmlfilename','temp.kml','imagename','greenland.jpeg');
+%
+
+%first figure out if lat and long were computed!
+if (isempty(md.lat) | isempty(md.long)),
+	error('kmlgroundoverlay error message: project x,y onto lat,long fields of model!');
+end
+
+%process kml options
+kmlfilename=getfieldvalue(options,'kmlfilename','tempfile.kml');
+kmlroot=getfieldvalue(options,'kmlroot','./');
+kmlimagename=getfieldvalue(options,'kmlimagename','tempimage');
+kmlimagetype=getfieldvalue(options,'kmlimagetype','png');
+kmlresolution=getfieldvalue(options,'kmlresolution',1);
+kmlfolder=getfieldvalue(options,'kmlfolder','Ground Overlay');
+kmlfolderdescription=getfieldvalue(options,'kmlfolderdescription','');
+kmlgroundoverlayname=getfieldvalue(options,'kmlgroundoverlayname','');
+kmlgroundoverlaydescription=getfieldvalue(options,'kmlgroundoverlaydescription','');
+
+%figure out  min and max for lat and long of this image:
+west=min(md.long);
+east=max(md.long);
+south=min(md.lat);
+north=max(md.lat);
+
+%print image at high resolution
+printmodel([kmlroot '/' kmlimagename],kmlimagetype,'trim','on','resolution',kmlresolution,'margin','off','frame','off');
+
+%now write kml file
+fid=fopen([kmlroot '/' kmlfilename],'w');
+
+fprintf(fid,'%s\n','<?xml version="1.0" encoding="UTF-8"?>');
+fprintf(fid,'%s\n','<kml xmlns="http://www.opengis.net/kml/2.2">');
+fprintf(fid,'%s\n','<Folder>');
+fprintf(fid,'%s%s%s\n','<name>',kmlfolder,'</name>');
+fprintf(fid,'%s%s%s\n','<description>',kmlfolderdescription,'</description>');
+fprintf(fid,'%s\n','<GroundOverlay>');
+fprintf(fid,'%s%s%s\n','<name>',kmlgroundoverlayname,'</name>');
+fprintf(fid,'%s\n','<description>',kmlgroundoverlaydescription,'</description>');
+fprintf(fid,'%s%s.%s%s\n','<Icon>',kmlimagename,kmlimagetype,'</Icon>');
+fprintf(fid,'%s\n','<LatLonBox>');
+fprintf(fid,'%s%f%s\n','<north>',north,'</north>');
+fprintf(fid,'%s%f%s\n','<south>',south,'</south>');
+fprintf(fid,'%s%f%s\n','<east>',east,'</east>');
+fprintf(fid,'%s%f%s\n','<west>',west,'</west>');
+fprintf(fid,'%s\n','<rotation>0</rotation>');
+fprintf(fid,'%s\n','</LatLonBox>');
+fprintf(fid,'%s\n','</GroundOverlay>');
+fprintf(fid,'%s\n','</Folder>');
+fprintf(fid,'%s\n','</kml>');
+
+fclose(fid);
Index: /issm/trunk/src/m/model/plot/plot_manager.m
===================================================================
--- /issm/trunk/src/m/model/plot/plot_manager.m	(revision 7027)
+++ /issm/trunk/src/m/model/plot/plot_manager.m	(revision 7028)
@@ -210,2 +210,13 @@
 	applyoptions(md,data2,options);
 end
+
+%do ground overlay on kml plot_unit? 
+if (strcmpi(getfieldvalue(options,'kmlgroundoverlay','off'),'on')),
+	if ((nlines*ncols~=1) | (i~=1)),
+		error('cannot kmlgroundoverlay on multi-plots');
+	end
+	
+	%call routine to build kml file and image that goes with it.
+	kmlgroundoverlay(md,options);
+
+end
Index: /issm/trunk/src/m/model/plot/plotdoc.m
===================================================================
--- /issm/trunk/src/m/model/plot/plotdoc.m	(revision 7027)
+++ /issm/trunk/src/m/model/plot/plotdoc.m	(revision 7028)
@@ -58,4 +58,5 @@
 disp('       ''backgroundcolor'': plot background color. (default is ''w'')');
 disp('       ''figurebackgroundcolor'': figure background color. (default is ''none'')');
+disp('       ''coord'':  ''xy'' (default) or ''latlon''');
 disp('       ''colorlevels'':  N or {value1,valu2,value3,...} used if quiver, use different colors for the given number of colors or limits');
 disp('       ''colorbar'': add colorbar (string ''on'' or ''off'')');
@@ -146,4 +147,15 @@
 disp('       ''cdfleg'': (char, ''off'' to turn off cdf legends)');
 disp('       ''segmentnumbering'': (''off'' by default)');
+disp('       ''kmlgroundoverlay'': (''off'' by default)');
+disp('       ''kmlfilename'': (''tempfile.kml'' by default)');
+disp('       ''kmlroot'': (''./'' by default)');
+disp('       ''kmlimagename'': (''tempimage'' by default)');
+disp('       ''kmlimagetype'': (''png'' by default)');
+disp('       ''kmlresolution'': (1 by default)');
+disp('       ''kmlfolder'': (''Ground Overlay'' by default)');
+disp('       ''kmlfolderdescription'': ('''' by default)');
+disp('       ''kmlgroundoverlayname'': ('''' by default)');
+disp('       ''kmlgroundoverlaydescription'': ('''' by default)');
+
 disp('       any options (except ''data'') can be followed by ''#i'' where ''i'' is the subplot number, or ''#all'' if applied to all plots');
 disp('  ');
Index: /issm/trunk/src/m/model/plot/processmesh.m
===================================================================
--- /issm/trunk/src/m/model/plot/processmesh.m	(revision 7027)
+++ /issm/trunk/src/m/model/plot/processmesh.m	(revision 7028)
@@ -14,13 +14,21 @@
 if (isempty(data) | ~isstruct(data)),
 	%first load x,y, etc ... to speed up plot
-	x=md.x;
-	x2d=md.x2d;
-	y=md.y;
-	y2d=md.y2d;
-	z=md.z;
-	z2d=md.z2d;
-	elements2d=md.elements2d;
-	elements=md.elements;
-	elements_type2d=md.elements_type2d;
+
+	if ~strcmpi(getfieldvalue(options,'coord','xy'),'latlon'),
+		x=md.x;
+		x2d=md.x2d;
+		y=md.y;
+		y2d=md.y2d;
+	else
+		x=md.long;
+		x2d=md.x2d;
+		y=md.lat;
+		y2d=md.y2d;
+	end
+		z=md.z;
+		z2d=md.z2d;
+		elements2d=md.elements2d;
+		elements=md.elements;
+		elements_type2d=md.elements_type2d;
 
 	%is it a 2d plot?
@@ -39,4 +47,7 @@
 	%layer projection? 
 	if getfieldvalue(options,'layer',0)>=1,
+		if strcmpi(getfieldvalue(options,'coord','xy'),'latlon'),
+			error('processmesh error message: cannot work with 3D meshes for now');
+		end
 		%we modify the mesh temporarily to a 2d mesh from which the 3d mesh was extruded. 
 		x=x2d;
