Index: /issm/trunk/src/mex/KMLOverlay/KMLOverlay.cpp
===================================================================
--- /issm/trunk/src/mex/KMLOverlay/KMLOverlay.cpp	(revision 8606)
+++ /issm/trunk/src/mex/KMLOverlay/KMLOverlay.cpp	(revision 8606)
@@ -0,0 +1,153 @@
+/*\file KMLOverlay.c
+ *\brief: KML file overlay mex module.
+ */
+#include "./KMLOverlay.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	char*   filkml=NULL;
+	char*   filkmz=NULL;
+
+	FILE*   fid=NULL;
+
+	Options* options=NULL;
+	int      nlat=0,nlong=0;
+	double*  lataxis =NULL;
+	double*  longaxis=NULL;
+	int      nimages=0;
+	char**   pimages=NULL;
+	double   dzip=0;
+	char*    czip=NULL;
+
+	/* output: */
+	int     ierror=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		KMLOverlayUsage();
+		_error_("KMLOverlay usage error");
+	}
+	if (nrhs < NRHS) {
+		KMLOverlayUsage();
+		_error_("KMLOverlay usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&filkml,FILENAME);
+	if (verbose) printf("  filkml=\"%s\"\n",filkml);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+//	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	options->Get(&lataxis ,&nlat ,"lataxis" );
+	if (verbose && lataxis) for (i=0; i<nlat; i++) printf("  lataxis [%d]=%g\n",i,lataxis[i]);
+	options->Get(&longaxis,&nlong,"longaxis");
+	if (verbose && longaxis) for (i=0; i<nlong; i++) printf("  longaxis[%d]=%g\n",i,longaxis[i]);
+//	((Option*)options->GetOption("images"))->DeepEcho();
+	options->Get(&pimages,&nimages,"images");
+	if (verbose && pimages) for (i=0; i<nimages; i++) printf("  pimages[%d]=\"%s\"\n",i,pimages[i]);
+	options->Get(&dzip,"zip",0.);
+	if (verbose) printf("  dzip=%g\n",dzip);
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if (nlat  != 2) _error_("Latitudinal axes \"lataxis\" require two double values, not %d.",nlat);
+	if (nlong != 2) _error_("Longitudinal axes \"longaxis\" require two double values, not %d.",nlong);
+	if (!nimages) _error_("No image files provided.");
+
+	if ((int)dzip) {
+		filkmz=filkml;
+		filkml=(char *) xmalloc(8*sizeof(char));
+		strcpy(filkml,"doc.kml");
+	}
+
+	if (!strlen(filkml))
+		strcpy(filkml,"stdout");
+
+	if (verbose) printf("Opening kml overlay file \"%s\".\n",filkml);
+	fid=fopen(filkml,"w");
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	KMLOverlayx(&ierror,
+				lataxis,longaxis,
+				nimages,pimages,
+				fid);
+
+	if (verbose) printf("Closing file \"%s\".\n",filkml);
+	fclose(fid);
+
+	/* Create kmz file, if specified: */
+	if ((int)dzip) {
+		czip=(char *) xmalloc((5+strlen(filkmz)+1+strlen(filkml)+1)*sizeof(char));
+		czip[0]='\0';
+		strcat(czip,"!zip ");
+		strcat(czip,filkmz);
+		strcat(czip," ");
+		strcat(czip,filkml);
+		for (i=0; i<nimages; i++)
+			if (strlen(pimages[i]) && strncmp(pimages[i],"http",4)) {
+				czip=(char *) xrealloc(czip,(strlen(czip)+1+strlen(pimages[i])+1)*sizeof(char));
+				strcat(czip," ");
+				strcat(czip,pimages[i]);
+			}
+		if (verbose) printf("Zipping file \"%s\".\n",filkmz);
+		if (verbose) printf("%s\n",czip);
+
+		if (mexEvalString(czip)) _error_("Error zipping file \"%s\".",filkmz);
+		xfree((void**)&czip);
+		xfree((void**)&filkmz);
+	}
+
+	/*Write data: */
+	WriteData(ERRORFLAG,ierror);
+
+	/*Clean-up*/
+	if (pimages) {
+		for (i=nimages; i>0; i--) xfree((void**)&(pimages[i-1]));
+		xfree((void**)&pimages);
+	}
+	xfree((void**)&longaxis);
+	xfree((void**)&lataxis);
+	delete options;
+	xfree((void**)&filkml);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void KMLOverlayUsage(void)
+{
+	_printf_(true,"KMLOverlay - KML file overlay module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module reads a KML file.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      ierror=KMLMeshWrite(name,notes,elem,nodecon,lat,long,part,data,cmap,kmlfile);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      name       model name (string, may be empty)\n");
+	_printf_(true,"      notes      model notes (string or cell array of strings, may be empty)\n");
+	_printf_(true,"      elem       elements (double array)\n");
+	_printf_(true,"      nodecon    nodal connectivity array (double array, may be empty)\n");
+	_printf_(true,"      lat        nodal latititudes (double vector)\n");
+	_printf_(true,"      long       nodal longitudes (double vector)\n");
+	_printf_(true,"      part       nodal partitions (double vector, may be empty)\n");
+	_printf_(true,"      data       nodal or element data (double vector, may be empty)\n");
+	_printf_(true,"      cmap       color map (double nx3 array, may be empty)\n");
+	_printf_(true,"      kmlfile    KML file name (string)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ierror     error flag (double, non-zero for error)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Example:\n");
+	_printf_(true,"      KMLMeshWrite(md.name,md.notes,md.elements,md.nodeconnectivity,md.lat,md.long,md.part,md.fm_criterion,options.cmap,filekml);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk/src/mex/KMLOverlay/KMLOverlay.h
===================================================================
--- /issm/trunk/src/mex/KMLOverlay/KMLOverlay.h	(revision 8606)
+++ /issm/trunk/src/mex/KMLOverlay/KMLOverlay.h	(revision 8606)
@@ -0,0 +1,31 @@
+/*!\file KMLOverlay.h
+ * \brief: prototype for KML file overlay mex module.
+ */
+
+#ifndef _KMLOVERLAY_H
+#define _KMLOVERLAY_H
+
+/* local prototypes: */
+void KMLOverlayUsage(void);
+
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "KMLOverlay"
+
+
+/* serial input macros: */
+#define FILENAME      prhs[0]
+
+/* serial output macros: */
+#define ERRORFLAG (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  1
+#undef NLHS
+#define NLHS  1
+
+#endif
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 8605)
+++ /issm/trunk/src/mex/Makefile.am	(revision 8606)
@@ -43,4 +43,5 @@
 				KMLFileRead \
 				KMLMeshWrite \
+				KMLOverlay \
 				Mergesolutionfromftog\
 				MeshPartition\
@@ -224,4 +225,7 @@
 			  KMLMeshWrite/KMLMeshWrite.h
 
+KMLOverlay_SOURCES = KMLOverlay/KMLOverlay.cpp\
+			  KMLOverlay/KMLOverlay.h
+
 AverageFilter_SOURCES = AverageFilter/AverageFilter.cpp\
 			  AverageFilter/AverageFilter.h
