Index: /issm/trunk/src/mex/Ll2xy/Ll2xy.cpp
===================================================================
--- /issm/trunk/src/mex/Ll2xy/Ll2xy.cpp	(revision 8681)
+++ /issm/trunk/src/mex/Ll2xy/Ll2xy.cpp	(revision 8681)
@@ -0,0 +1,117 @@
+/*\file Ll2xy.c
+ *\brief: lat/long to x/y coordinate mex module.
+ */
+#include "./Ll2xy.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	double  *lat=NULL,*lon=NULL;
+	int     nlat,nlon,ncoord;
+	int     sgn;
+
+	Options* options=NULL;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	double  *x=NULL,*y=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Ll2xyUsage();
+		_error_("Ll2xy usage error");
+	}
+	if (nrhs < NRHS) {
+		Ll2xyUsage();
+		_error_("Ll2xy usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&lat,&nlat,LAT_IN);
+	if (verbose)
+		if   (nlat == 1) printf("  lat=%g\n",lat[0]);
+		else             printf("  lat=[%d values]\n",nlat);
+	FetchData(&lon,&nlon,LON_IN);
+	if (verbose)
+		if   (nlon == 1) printf("  lon=%g\n",lon[0]);
+		else             printf("  lon=[%d values]\n",nlon);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	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();
+	/*  defaults are in x-layer, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if   (nlat != nlon) _error_("Must have same number of lat[%d] and lon[%d] coordinates.",nlat,nlon);
+	else                ncoord=nlat;
+	if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=%d must be +1 (north) or -1 (south).",sgn);
+	if (fabs(cm) > 180.+DBL_EPSILON) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (fabs(sp) >  90.+DBL_EPSILON) _error_("Standard parallel sp=%g must be between -90 (south) and +90 (north) degrees.",sp);
+
+	x=(double *)xmalloc(ncoord*sizeof(double));
+	y=(double *)xmalloc(ncoord*sizeof(double));
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		Ll2xyx(x,y,
+			   lat,lon,ncoord,
+			   sgn,cm,sp);
+	else
+		Ll2xyx(x,y,
+			   lat,lon,ncoord,
+			   sgn);
+
+	/*Write data: */
+	WriteData(X_OUT,x,ncoord);
+	WriteData(Y_OUT,y,ncoord);
+
+	/*Clean-up*/
+	delete options;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Ll2xyUsage(void)
+{
+	_printf_(true,"Ll2xy - lat/long to x/y coordinate transformation module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module transforms lat/long to x/y coordinates.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      lat         latitude coordinates (double vector)\n");
+	_printf_(true,"      lon         longitude coordinates (double vector)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north) or -1 (south))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      x           x coordinates (double vector)\n");
+	_printf_(true,"      y           y coordinates (double vector)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon, 1);\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon, 1,'central_meridian',45,'standard_parallel',70);\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon,-1,'central_meridian', 0,'standard_parallel',71);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk/src/mex/Ll2xy/Ll2xy.h
===================================================================
--- /issm/trunk/src/mex/Ll2xy/Ll2xy.h	(revision 8681)
+++ /issm/trunk/src/mex/Ll2xy/Ll2xy.h	(revision 8681)
@@ -0,0 +1,35 @@
+/*!\file Ll2xy.h
+ * \brief: prototype for lat/long to x/y coordinate mex module.
+ */
+
+#ifndef _LL2XY_H
+#define _LL2XY_H
+
+/* local prototypes: */
+void Ll2xyUsage(void);
+
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Ll2xy"
+
+
+/* serial input macros: */
+#define LAT_IN    prhs[0]
+#define LON_IN    prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define X_OUT    (mxArray**)&plhs[0]
+#define Y_OUT    (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  2
+
+#endif
+
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 8680)
+++ /issm/trunk/src/mex/Makefile.am	(revision 8681)
@@ -44,4 +44,6 @@
 				KMLMeshWrite \
 				KMLOverlay \
+				Xy2ll \
+				Ll2xy \
 				Mergesolutionfromftog\
 				MeshPartition\
@@ -228,4 +230,10 @@
 			  KMLOverlay/KMLOverlay.h
 
+Xy2ll_SOURCES = Xy2ll/Xy2ll.cpp\
+			  Xy2ll/Xy2ll.h
+
+Ll2xy_SOURCES = Ll2xy/Ll2xy.cpp\
+			  Ll2xy/Ll2xy.h
+
 AverageFilter_SOURCES = AverageFilter/AverageFilter.cpp\
 			  AverageFilter/AverageFilter.h
Index: /issm/trunk/src/mex/Xy2ll/Xy2ll.cpp
===================================================================
--- /issm/trunk/src/mex/Xy2ll/Xy2ll.cpp	(revision 8681)
+++ /issm/trunk/src/mex/Xy2ll/Xy2ll.cpp	(revision 8681)
@@ -0,0 +1,117 @@
+/*\file Xy2ll.c
+ *\brief: x/y to lat/long coordinate mex module.
+ */
+#include "./Xy2ll.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	double  *x=NULL,*y=NULL;
+	int     nx,ny,ncoord;
+	int     sgn;
+
+	Options* options=NULL;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	double  *lat=NULL,*lon=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Xy2llUsage();
+		_error_("Xy2ll usage error");
+	}
+	if (nrhs < NRHS) {
+		Xy2llUsage();
+		_error_("Xy2ll usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&x,&nx,X_IN);
+	if (verbose)
+		if   (nx == 1) printf("  x=%g\n",x[0]);
+		else           printf("  x=[%d values]\n",nx);
+	FetchData(&y,&ny,Y_IN);
+	if (verbose)
+		if   (ny == 1) printf("  y=%g\n",y[0]);
+		else           printf("  y=[%d values]\n",ny);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	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();
+	/*  defaults are in x-layer, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if   (nx != ny) _error_("Must have same number of x[%d] and y[%d] coordinates.",nx,ny);
+	else            ncoord=nx;
+	if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=%d must be +1 (north) or -1 (south).",sgn);
+	if (fabs(cm) > 180.+DBL_EPSILON) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (fabs(sp) >  90.+DBL_EPSILON) _error_("Standard parallel sp=%g must be between -90 (south) and +90 (north) degrees.",sp);
+
+	lat=(double *)xmalloc(ncoord*sizeof(double));
+	lon=(double *)xmalloc(ncoord*sizeof(double));
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		Xy2llx(lat,lon,
+			   x,y,ncoord,
+			   sgn,cm,sp);
+	else
+		Xy2llx(lat,lon,
+			   x,y,ncoord,
+			   sgn);
+
+	/*Write data: */
+	WriteData(LAT_OUT,lat,ncoord);
+	WriteData(LON_OUT,lon,ncoord);
+
+	/*Clean-up*/
+	delete options;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Xy2llUsage(void)
+{
+	_printf_(true,"Xy2ll - x/y to lat/long coordinate transformation module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module transforms x/y to lat/long coordinates.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      x           x coordinates (double vector)\n");
+	_printf_(true,"      y           y coordinates (double vector)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north) or -1 (south))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      lat         latitude coordinates (double vector)\n");
+	_printf_(true,"      lon         longitude coordinates (double vector)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y, 1);\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y, 1,'central_meridian',45,'standard_parallel',70);\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y,-1,'central_meridian', 0,'standard_parallel',71);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk/src/mex/Xy2ll/Xy2ll.h
===================================================================
--- /issm/trunk/src/mex/Xy2ll/Xy2ll.h	(revision 8681)
+++ /issm/trunk/src/mex/Xy2ll/Xy2ll.h	(revision 8681)
@@ -0,0 +1,35 @@
+/*!\file Xy2ll.h
+ * \brief: prototype for x/y to lat/long coordinate mex module.
+ */
+
+#ifndef _XY2LL_H
+#define _XY2LL_H
+
+/* local prototypes: */
+void Xy2llUsage(void);
+
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Xy2ll"
+
+
+/* serial input macros: */
+#define X_IN      prhs[0]
+#define Y_IN      prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define LAT_OUT    (mxArray**)&plhs[0]
+#define LON_OUT    (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  2
+
+#endif
+
