Index: issm/trunk/m4/issm_options.m4
===================================================================
--- issm/trunk/m4/issm_options.m4	(revision 19105)
+++ issm/trunk/m4/issm_options.m4	(revision 20500)
@@ -173,7 +173,8 @@
 			export CFLAGS="-DWIN32 -D_INTEL_WIN_"
 			export CXXFLAGS="-DWIN32 -D_INTEL_WIN_"
+			IS_WINDOWS=yes
 		elif  test $VENDOR = intel-win7-32; then
 			export CC=cl
-			export CXX=cccl
+			export CXX=cl
 			export CXXFLAGS="-DWIN32 -D_INTEL_WIN_ -EHsc"
 			export CFLAGS="-DWIN32 -D_INTEL_WIN_ -EHsc"
@@ -181,8 +182,9 @@
 			export OS_LDFLAG="-Wl,"
 			export RANLIB=true
+			IS_WINDOWS=yes
 			OSLIBS="-Wl,kernel32.lib -Wl,user32.lib -Wl,gdi32.lib -Wl,winspool.lib -Wl,comdlg32.lib -Wl,advapi32.lib -Wl,shell32.lib -Wl,ole32.lib -Wl,oleaut32.lib -Wl,uuid.lib -Wl,odbc32.lib -Wl,odbccp32.lib"
 		elif  test $VENDOR = intel-win7-64; then
 			export CC=cl
-			export CXX=cccl
+			export CXX=cl
 			export CXXFLAGS="-DWIN32 -D_INTEL_WIN_ -EHsc"
 			export CFLAGS="-DWIN32 -D_INTEL_WIN_ -EHsc"
@@ -190,4 +192,25 @@
 			export OS_LDFLAG="-Wl,"
 			export RANLIB=true
+			IS_WINDOWS=yes
+			OSLIBS="-Wl,kernel32.lib -Wl,user32.lib -Wl,gdi32.lib -Wl,winspool.lib -Wl,comdlg32.lib -Wl,advapi32.lib -Wl,shell32.lib -Wl,ole32.lib -Wl,oleaut32.lib -Wl,uuid.lib -Wl,odbc32.lib -Wl,odbccp32.lib"
+		elif  test $VENDOR = MSVC-Win64; then
+			export CC=cl
+			export CXX=cl
+			export CXXFLAGS="-DWIN32 -D_INTEL_WIN_ -D_HAVE_PETSC_MPI_ -EHsc"
+			export CFLAGS="-DWIN32 -D_INTEL_WIN_ -D_HAVE_PETSC_MPI_ -EHsc"
+			export AR="ar-lib lib"
+			export OS_LDFLAG="-Wl,"
+			export RANLIB=true
+			IS_WINDOWS=yes
+			OSLIBS="-Wl,kernel32.lib -Wl,user32.lib -Wl,gdi32.lib -Wl,winspool.lib -Wl,comdlg32.lib -Wl,advapi32.lib -Wl,shell32.lib -Wl,ole32.lib -Wl,oleaut32.lib -Wl,uuid.lib -Wl,odbc32.lib -Wl,odbccp32.lib"
+		elif  test $VENDOR = MSVC-Win64-par; then
+			export CC=cl
+			export CXX=cl
+			export CXXFLAGS="-DWIN32 -D_INTEL_WIN_ -EHsc"
+			export CFLAGS="-DWIN32 -D_INTEL_WIN_ -EHsc"
+			export AR="ar-lib lib"
+			export OS_LDFLAG="-Wl,"
+			export RANLIB=true
+			IS_WINDOWS=yes
 			OSLIBS="-Wl,kernel32.lib -Wl,user32.lib -Wl,gdi32.lib -Wl,winspool.lib -Wl,comdlg32.lib -Wl,advapi32.lib -Wl,shell32.lib -Wl,ole32.lib -Wl,oleaut32.lib -Wl,uuid.lib -Wl,odbc32.lib -Wl,odbccp32.lib"
 		elif test $VENDOR = intel-linux; then
@@ -201,4 +224,7 @@
 			export CFLAGS=" -D_INTEL_LINUX_"
 			export CXXFLAGS=" -D_INTEL_LINUX_"
+		elif test $VENDOR = intel-lonestar; then
+			export CC=icc
+			export CXX=icpc
 		elif test $VENDOR = intel-discover; then
 			export CC=icc
@@ -255,5 +281,4 @@
 
 		AC_DEFINE([_HAVE_MATLAB_],[1],[with matlab in ISSM src])
-  		MATLABINCL="-I$MATLAB_ROOT/extern/include/"
 		
 		dnl 4. get MEXLIB MEXLINK and MEXEXT (experimental) except for windows
@@ -262,18 +287,23 @@
   			*cygwin*) 
   				if  test $VENDOR = intel-win7-32; then
-  					MEXLIB="-Wl,./../../c/libISSMCore.a -Wl,libISSMApi.a -Wl,libISSMMatlab.a -Wl,./../../c/libISSMModules.a -Wl,libmx.lib -Wl,libmex.lib -Wl,libmat.lib ${OSLIBS} -Wl,libf2cblas.lib -Wl,libf2clapack.lib" 
-               MEXLINK="-Wl,/LIBPATH:`cygpath -m ${MATLAB_ROOT}/extern/lib/win32/microsoft` -no-undefined -Wl,/export:mexFunction -Wl,/LD"
+  					MEXLIB="-Wl,libmx.lib -Wl,libmex.lib -Wl,libmat.lib ${OSLIBS} -Wl,libf2cblas.lib -Wl,libf2clapack.lib" 
+               MEXLINK="-Wl,/LIBPATH:`cygpath -m ${MATLAB_ROOT}/extern/lib/win32/microsoft` -Wl,/link -Wl,/EXPORT:mexFunction -Wl,/DLL"
 					MEXEXT=`$MATLAB_ROOT/bin/mexext.bat`
 					MEXEXT=".$MEXEXT"
-  				elif  test l-win7-64; then
-  					MEXLIB="-Wl,./../../c/libISSMCore.a -Wl,libISSMApi.a -Wl,libISSMMatlab.a -Wl,./../../c/libISSMModules.a -Wl,libmx.lib -Wl,libmex.lib -Wl,libmat.lib ${OSLIBS} -Wl,libf2cblas.lib -Wl,libf2clapack.lib" 
-               MEXLINK="-Wl,/LIBPATH:`cygpath -m ${MATLAB_ROOT}/extern/lib/win64/microsoft` -no-undefined -Wl,/export:mexFunction -Wl,/LD" 
+  				elif test $VENDOR = intel-win7-64; then
+  					MEXLIB="-Wl,libmx.lib -Wl,libmex.lib -Wl,libmat.lib ${OSLIBS} -Wl,libf2cblas.lib -Wl,libf2clapack.lib" 
+               MEXLINK="-Wl,/LIBPATH:`cygpath -m ${MATLAB_ROOT}/extern/lib/win64/microsoft` -Wl,/link -Wl,/EXPORT:mexFunction -Wl,/DLL" 
+					MEXEXT=".mexw64"
+  				elif test $VENDOR = MSVC-Win64 || test $VENDOR = MSVC-Win64-par; then
+  					MEXLIB="-Wl,libmx.lib -Wl,libmex.lib -Wl,libmat.lib ${OSLIBS} -Wl,libf2cblas.lib -Wl,libf2clapack.lib" 
+               MEXLINK="-Wl,/link -Wl,/LIBPATH:`cygpath -m ${MATLAB_ROOT}/extern/lib/win64/microsoft` -Wl,/link -Wl,/EXPORT:mexFunction -Wl,/DLL" 
+  					MATLABINCL="-I`cygpath -m $MATLAB_ROOT/extern/include/`"
 					MEXEXT=".mexw64"
   				fi
-
   			;;
 		   *)
+           MATLABINCL="-I$MATLAB_ROOT/extern/include/"
            MEXLINK=$($MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep LDFLAGS     | sed -e "s/         LDFLAGS            = //g")
-           MEXLIB=$( $MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep CXXLIBS     | sed -e "s/         CXXLIBS            = //g")
+			  MEXLIB=$( $MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep CXXLIBS     | sed -e "s/         CXXLIBS            = //g")
 		     MEXEXT=$( $MATLAB_ROOT/bin/mex -v 2>&1 < /dev/null | grep LDEXTENSION | sed -e "s/         LDEXTENSION        = //g")
 				dnl version 2014 and up
@@ -290,5 +320,6 @@
 
 				dnl Make sure mexFunction.map is not in MEXLIB to avoid problems with global variables
-				MEXLINK=$(echo $MEXLINK | sed -e "s/,-expo.*mexFunction\\.map\"//g" | sed -e "s/-[[^ ]]*mexFunction\\.map//g")
+				dnl MEXLINK=$(echo $MEXLINK | sed -e "s/,-expo.*mexFunction\\.map\"//g" | sed -e "s/-[[^ ]]*mexFunction\\.map//g")
+				MEXLINK="" dnl We actually don't need MEXLINK????
 
   			;;
@@ -299,4 +330,6 @@
 	   fi
 
+		AC_MSG_CHECKING([whether matlab is enabled])
+
 		AC_SUBST([MATLABINCL])
 		MATLABWRAPPEREXT=$MEXEXT
@@ -306,4 +339,28 @@
 	fi
 	dnl }}}
+	dnl windows {{{
+	AC_MSG_CHECKING([Checking if this is a Win build... ])
+	AM_CONDITIONAL([WINDOWS], [test x$IS_WINDOWS = xyes])
+	AC_MSG_RESULT(done)
+	dnl }}}
+	dnl javascript{{{
+	AC_ARG_WITH([javascript],
+	  AS_HELP_STRING([--with-javascript], [compile javascript wrappers? default is no.]),
+	  [JAVASCRIPT=$withval],[JAVASCRIPT="no"]) 
+
+	dnl Check whether javascript wrappers are desired
+	AC_MSG_CHECKING([for javascript])
+	if test "x$JAVASCRIPT" = "xno" ; then
+		HAVE_JAVASCRIPT=no
+	else
+		HAVE_JAVASCRIPT=yes
+		AC_DEFINE([_HAVE_JAVASCRIPT_],[1],[with javascript])
+	fi
+	AC_MSG_RESULT($HAVE_JAVASCRIPT)
+	AM_CONDITIONAL([JAVASCRIPT],[test x$HAVE_JAVASCRIPT = xyes])
+	JAVASCRIPTWRAPPEREXT=.js
+	AC_SUBST([JAVASCRIPTWRAPPEREXT])
+
+	dnl }}}
 	dnl triangle {{{
 	AC_ARG_WITH([triangle-dir],
@@ -332,4 +389,5 @@
 		case "${host_os}" in
 				*cygwin*)
+				TRIANGLEINCL="/I`cygpath -m $TRIANGLE_ROOT/`"
 				TRIANGLELIB="-Wl,`cygpath -m $TRIANGLE_ROOT/`triangle.lib"
 				;;
@@ -338,5 +396,10 @@
 				;;
 				*darwin*)
-				TRIANGLELIB=$TRIANGLE_ROOT/triangle.a
+				if test "x$HAVE_JAVASCRIPT" = "xyes"; then
+					dnl go to the bit code, not the library.
+					TRIANGLELIB=$TRIANGLE_ROOT/triangle.o 
+				else
+					TRIANGLELIB=$TRIANGLE_ROOT/triangle.a
+				fi
 				;;
 			esac
@@ -396,10 +459,13 @@
 
 		AC_MSG_CHECKING(for dakota version)
-		if test -f "$DAKOTA_ROOT/../src/src/CommandLineHandler.C"; then
-			DAKOTA_VERSION=`cat $DAKOTA_ROOT/../src/src/CommandLineHandler.C | grep 'DAKOTA version' | grep 'release' | grep -v // | sed 's/.*DAKOTA version //' | sed 's/ .*//' `
+		if test -f "$DAKOTA_ROOT/VERSION"; then
+		 DAKOTA_VERSION=`cat $DAKOTA_ROOT/VERSION | grep 'DAKOTA Version' | sed 's/.*DAKOTA Version //' | sed 's/ .*//' `
+		else if test -f "$DAKOTA_ROOT/../src/src/CommandLineHandler.C"; then
+		 DAKOTA_VERSION=`cat $DAKOTA_ROOT/../src/src/CommandLineHandler.C | grep 'DAKOTA version' | grep 'release' | grep -v // | sed 's/.*DAKOTA version //' | sed 's/ .*//' `
 		else if test -f "$DAKOTA_ROOT/../src/src/CommandLineHandler.cpp"; then
-			DAKOTA_VERSION=`cat $DAKOTA_ROOT/../src/src/CommandLineHandler.cpp | grep 'DAKOTA version' | grep 'release' | grep -v // | sed 's/.*DAKOTA version //' | sed 's/ .*//' `
+		 DAKOTA_VERSION=`cat $DAKOTA_ROOT/../src/src/CommandLineHandler.cpp | grep 'DAKOTA version' | grep 'release' | grep -v // | sed 's/.*DAKOTA version //' | sed 's/ .*//' `
 		else
-			AC_MSG_ERROR([Dakota CommandLineHandler.C or CommandLineHandler.cpp file not found to determine DAKOTA_VERSION!]);
+		 AC_MSG_ERROR([Dakota CommandLineHandler.C or CommandLineHandler.cpp file not found to determine DAKOTA_VERSION!]);
+		fi
 		fi
 		fi
@@ -410,8 +476,11 @@
 		case "${host_os}" in
 			*cygwin*)
-				if      test x$DAKOTA_VERSION = x4.2 || test x$DAKOTA_VERSION = x4.2+; then
-					DAKOTALIB="-L$DAKOTA_ROOT/lib -ldakota -lteuchos -lpecos -lfftw3 -llhs -levidence -lsurfpack -lconmin -lddace -lfsudace -ljega -lcport -lopt -lpsuade -lnewmat -lncsuopt -lgsl -lquadrature -lcoliny -lcolin -lpebbl -lutilib -l3po -lnappspack -lappspack -lconveyor -lshared -lcdd -lamplsolver"
-				else if test x$DAKOTA_VERSION = x5.1 || test x$DAKOTA_VERSION = x5.2; then
+				if test x$DAKOTA_VERSION = x5.1 || test x$DAKOTA_VERSION = x5.2; then
 					DAKOTALIB="-L$DAKOTA_ROOT/lib -L$BOOST_ROOT/lib -ldakota -lteuchos -lpecos -llhs -lsparsegrid -lsurfpack -lconmin -lddace -lfsudace -ljega -lcport -loptpp -lpsuade -lncsuopt -lcolin -linterfaces -lmomh -lscolib -lpebbl -ltinyxml -lutilib -l3po -lhopspack -lnidr -lamplsolver -lboost_signals -lboost_regex -lboost_filesystem"
+				else if test x$DAKOTA_VERSION = x6.1 || test x$DAKOTA_VERSION = x6.2; then
+				   DAKOTAFLAGS="-DDISABLE_DAKOTA_CONFIG_H -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DDAKOTA_PLUGIN -DBOOST_DISABLE_ASSERTS -DDAKOTA_HAVE_BOOST_FS -DHAVE_UNISTD_H -DHAVE_SYSTEM -DHAVE_WORKING_FORK -DHAVE_WORKING_VFORK -DHAVE_SYS_WAIT_H -DHAVE_USLEEP -DDAKOTA_F90 -DDAKOTA_HAVE_MPI -DHAVE_PECOS -DHAVE_SURFPACK -DDAKOTA_COLINY -DDAKOTA_UTILIB -DHAVE_ADAPTIVE_SAMPLING -DHAVE_CONMIN -DDAKOTA_DDACE -DHAVE_FSUDACE -DDAKOTA_HOPS -DHAVE_JEGA -DHAVE_NCSU -DHAVE_NL2SOL -DHAVE_OPTPP -DDAKOTA_OPTPP -DHAVE_PSUADE -DHAVE_AMPL"
+					DAKOTALIB="-L$DAKOTA_ROOT/lib -L$BOOST_ROOT/lib -ldakota_src -ldream -lfsudace -lddace -lnomad -lpecos_src -lscolib -ljega_fe -llhs -lpebbl -lcolin -linterfaces -llhs_mods -lmoga -loptpp -lsoga -lsurfpack -lutilib -lconmin -ldakota_src_fortran -llhs_mod -lncsuopt -lsurfpack_fortran -lteuchos -l3po -lamplsolver -lcport -ldfftpack -leutils -lfsudace -lhopspack -ljega -lnidr -lpecos -lpsuade -ltinyxml -lutilities -lsparsegrid -lboost_serialization -lboost_signals -lboost_regex -lboost_filesystem -lboost_system"
+					AC_DEFINE([DISABLE_DAKOTA_CONFIG_H],[1],[disabling DAKOTA_CONFIG_H])
+					AC_DEFINE([DAKOTA_HAVE_MPI],[1],[enabling parallel MPI])
 				else
 					AC_MSG_ERROR([Dakota version not found or version ($DAKOTA_VERSION) not supported!]);
@@ -420,11 +489,16 @@
 			;;
 			*linux*)
-				if      test x$DAKOTA_VERSION = x4.2 || test x$DAKOTA_VERSION = x4.2+; then
-					DAKOTALIB="-L$DAKOTA_ROOT/lib -ldakota -lteuchos -lpecos -lfftw3 -llhs -levidence -lsurfpack -lconmin -lddace -lfsudace -ljega -lcport -lopt -lpsuade -lnewmat -lncsuopt -lgsl -lquadrature -lcoliny -lcolin -lpebbl -lutilib -l3po -lnappspack -lappspack -lconveyor -lshared -lcdd -lamplsolver"
-				else if test x$DAKOTA_VERSION = x5.1 || test x$DAKOTA_VERSION = x5.2; then
+				if test x$DAKOTA_VERSION = x5.1 || test x$DAKOTA_VERSION = x5.2; then
 					DAKOTALIB="-L$DAKOTA_ROOT/lib -ldakota -lteuchos -lpecos -llhs -lsparsegrid -lsurfpack -lconmin -lddace -lfsudace -ljega -lcport -loptpp -lpsuade -lncsuopt -lcolin -linterfaces -lmomh -lscolib -lpebbl -ltinyxml -lutilib -l3po -lhopspack -lnidr -lamplsolver -lboost_signals -lboost_regex -lboost_filesystem -lboost_system -ldl"
 				else if test x$DAKOTA_VERSION = x5.3 || test x$DAKOTA_VERSION = x5.3.1; then
 					DAKOTAFLAGS="-DDISABLE_DAKOTA_CONFIG_H -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DDAKOTA_PLUGIN -DBOOST_DISABLE_ASSERTS -DDAKOTA_HAVE_BOOST_FS -DHAVE_UNISTD_H -DHAVE_SYSTEM -DHAVE_WORKING_FORK -DHAVE_WORKING_VFORK -DHAVE_SYS_WAIT_H -DHAVE_USLEEP -DDAKOTA_F90 -DDAKOTA_HAVE_MPI -DHAVE_PECOS -DHAVE_SURFPACK -DDAKOTA_COLINY -DDAKOTA_UTILIB -DHAVE_ADAPTIVE_SAMPLING -DHAVE_CONMIN -DDAKOTA_DDACE -DHAVE_FSUDACE -DDAKOTA_HOPS -DHAVE_JEGA -DHAVE_NCSU -DHAVE_NL2SOL -DHAVE_OPTPP -DDAKOTA_OPTPP -DHAVE_PSUADE -DHAVE_AMPL"
 					DAKOTALIB="-L$DAKOTA_ROOT/lib -L$BOOST_ROOT/lib -ldakota_src -lpecos_src -lscolib -ljega_fe -llhs -lpebbl -lcolin -linterfaces -lmods -lmoga -loptpp -lsampling -lsoga -lsurfpack -lutilib -lconmin -ldakota_src_fortran -lmod -lncsuopt -lsurfpack_fortran -lteuchos -l3po -lamplsolver -lanalyzer -lbose -lcport -ldace -ldfftpack -leutils -lfsudace -lhopspack -ljega -lnidr -lpecos -lpsuade -lrandom -ltinyxml -lutilities -lsparsegrid -lboost_signals -lboost_regex -lboost_filesystem -lboost_system"
+					AC_DEFINE([DISABLE_DAKOTA_CONFIG_H],[1],[disabling DAKOTA_CONFIG_H])
+					AC_DEFINE([DAKOTA_HAVE_MPI],[1],[enabling parallel MPI])
+				else if test x$DAKOTA_VERSION = x6.1 || test x$DAKOTA_VERSION = x6.2; then
+				   DAKOTAFLAGS="-DDISABLE_DAKOTA_CONFIG_H -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DDAKOTA_PLUGIN -DBOOST_DISABLE_ASSERTS -DDAKOTA_HAVE_BOOST_FS -DHAVE_UNISTD_H -DHAVE_SYSTEM -DHAVE_WORKING_FORK -DHAVE_WORKING_VFORK -DHAVE_SYS_WAIT_H -DHAVE_USLEEP -DDAKOTA_F90 -DDAKOTA_HAVE_MPI -DHAVE_PECOS -DHAVE_SURFPACK -DDAKOTA_UTILIB -DHAVE_ADAPTIVE_SAMPLING -DHAVE_CONMIN -DDAKOTA_DDACE -DHAVE_FSUDACE -DDAKOTA_HOPS -DHAVE_NCSU -DHAVE_NL2SOL -DHAVE_OPTPP -DDAKOTA_OPTPP -DHAVE_PSUADE -DHAVE_AMPL"
+					DAKOTALIB="-L$DAKOTA_ROOT/lib -L$BOOST_ROOT/lib -ldakota_src -ldream -lfsudace -lddace -lnomad -lpecos_src -llhs -llhs_mods -loptpp -lsurfpack -lconmin -ldakota_src_fortran -llhs_mod -lncsuopt -lsurfpack_fortran -lteuchos -lamplsolver -lcport -ldfftpack -lfsudace -lhopspack -lnidr -lpecos -lpsuade -lsparsegrid -lboost_serialization -lboost_signals -lboost_regex -lboost_filesystem -lboost_system"
+					AC_DEFINE([DISABLE_DAKOTA_CONFIG_H],[1],[disabling DAKOTA_CONFIG_H])
+					AC_DEFINE([DAKOTA_HAVE_MPI],[1],[enabling parallel MPI])
 				else
 					AC_MSG_ERROR([Dakota version not found or version ($DAKOTA_VERSION) not supported!]);
@@ -434,8 +508,5 @@
 			;;
 			*darwin*)
-				if      test x$DAKOTA_VERSION = x4.2 || test x$DAKOTA_VERSION = x4.2+; then
-					DAKOTALIB="-L$DAKOTA_ROOT/lib -ldakota -lteuchos -lpecos -lfftw3 -llhs -levidence -lsurfpack -lconmin -lddace -lfsudace -ljega -lcport -lopt -lpsuade -lnewmat -lncsuopt -lgsl -lquadrature -lcoliny -lcolin -lpebbl -lutilib -l3po -lnappspack -lappspack -lconveyor -lshared -lcdd -lamplsolver" 
-					dnl DAKOTALIB+= "-lgslcblas -L/usr/lib -lblas -llapack"
-				else if test x$DAKOTA_VERSION = x5.1 || test x$DAKOTA_VERSION = x5.2; then
+				if test x$DAKOTA_VERSION = x5.1 || test x$DAKOTA_VERSION = x5.2; then
 					DAKOTALIB="-L$DAKOTA_ROOT/lib -ldakota -lteuchos -lpecos -llhs -lsparsegrid -lsurfpack -lconmin -lddace -lfsudace -ljega -lcport -loptpp -lpsuade -lncsuopt -lcolin -linterfaces -lmomh -lscolib -lpebbl -ltinyxml -lutilib -l3po -lhopspack -lnidr -lamplsolver -lboost_signals -lboost_regex -lboost_filesystem -lboost_system"
 					dnl DAKOTALIB+= "-lgslcblas -L/usr/lib -lblas -llapack"
@@ -443,9 +514,16 @@
 					DAKOTAFLAGS="-DDISABLE_DAKOTA_CONFIG_H -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DDAKOTA_PLUGIN -DBOOST_DISABLE_ASSERTS -DDAKOTA_HAVE_BOOST_FS -DHAVE_UNISTD_H -DHAVE_SYSTEM -DHAVE_WORKING_FORK -DHAVE_WORKING_VFORK -DHAVE_SYS_WAIT_H -DHAVE_USLEEP -DDAKOTA_F90 -DDAKOTA_HAVE_MPI -DHAVE_PECOS -DHAVE_SURFPACK -DDAKOTA_COLINY -DDAKOTA_UTILIB -DHAVE_ADAPTIVE_SAMPLING -DHAVE_CONMIN -DDAKOTA_DDACE -DHAVE_FSUDACE -DDAKOTA_HOPS -DHAVE_JEGA -DHAVE_NCSU -DHAVE_NL2SOL -DHAVE_OPTPP -DDAKOTA_OPTPP -DHAVE_PSUADE -DHAVE_AMPL"
 					DAKOTALIB="-L$DAKOTA_ROOT/lib -L$BOOST_ROOT/lib -ldakota_src -lpecos_src -lscolib -ljega_fe -llhs -lpebbl -lcolin -linterfaces -lmods -lmoga -loptpp -lsampling -lsoga -lsurfpack -lutilib -lconmin -ldakota_src_fortran -lmod -lncsuopt -lsurfpack_fortran -lteuchos -l3po -lamplsolver -lanalyzer -lbose -lcport -ldace -ldfftpack -leutils -lfsudace -lhopspack -ljega -lnidr -lpecos -lpsuade -lrandom -ltinyxml -lutilities -lsparsegrid -lboost_signals -lboost_regex -lboost_filesystem -lboost_system"
+					AC_DEFINE([DISABLE_DAKOTA_CONFIG_H],[1],[disabling DAKOTA_CONFIG_H])
+					AC_DEFINE([DAKOTA_HAVE_MPI],[1],[enabling parallel MPI])
+				else if test x$DAKOTA_VERSION = x6.1 || test x$DAKOTA_VERSION = x6.2; then
+				   DAKOTAFLAGS="-DDISABLE_DAKOTA_CONFIG_H -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DDAKOTA_PLUGIN -DBOOST_DISABLE_ASSERTS -DDAKOTA_HAVE_BOOST_FS -DHAVE_UNISTD_H -DHAVE_SYSTEM -DHAVE_WORKING_FORK -DHAVE_WORKING_VFORK -DHAVE_SYS_WAIT_H -DHAVE_USLEEP -DDAKOTA_F90 -DDAKOTA_HAVE_MPI -DHAVE_PECOS -DHAVE_SURFPACK -DDAKOTA_UTILIB -DHAVE_ADAPTIVE_SAMPLING -DHAVE_CONMIN -DDAKOTA_DDACE -DHAVE_FSUDACE -DDAKOTA_HOPS -DHAVE_NCSU -DHAVE_NL2SOL -DHAVE_OPTPP -DDAKOTA_OPTPP -DHAVE_PSUADE -DHAVE_AMPL"
+					DAKOTALIB="-L$DAKOTA_ROOT/lib -L$BOOST_ROOT/lib -ldakota_src -ldream -lfsudace -lddace -lnomad -lpecos_src -llhs -llhs_mods -loptpp -lsurfpack -lconmin -ldakota_src_fortran -llhs_mod -lncsuopt -lsurfpack_fortran -lteuchos -lamplsolver -lcport -ldfftpack -lfsudace -lhopspack -lnidr -lpecos -lpsuade -lsparsegrid -lboost_serialization -lboost_signals -lboost_regex -lboost_filesystem -lboost_system"
+					AC_DEFINE([DISABLE_DAKOTA_CONFIG_H],[1],[disabling DAKOTA_CONFIG_H])
+					AC_DEFINE([DAKOTA_HAVE_MPI],[1],[enabling parallel MPI])
 				else
 					AC_MSG_ERROR([Dakota version not found or version ($DAKOTA_VERSION) not supported!]);
 				fi
 				fi
-                                fi
+				fi
 			;;
 		esac
@@ -486,4 +564,5 @@
 		AC_SUBST([DAKOTALIB])
 	fi
+	AM_CONDITIONAL([ISSM_DAKOTA],[test x$DAKOTA_MAJOR = x6])
 	dnl }}}
 	dnl python{{{
@@ -508,5 +587,5 @@
 	dnl python specifics
 	if test "x$HAVE_PYTHON" = "xyes"; then
-		AC_MSG_CHECKING(for python version)
+		AC_MSG_CHECKING([for python version])
 		dnl Query Python for its version number.  Getting [:3] seems to be the
 		dnl best way to do this; it's what "site.py" does in the standard library.
@@ -523,5 +602,16 @@
 		fi
 
-		PYTHONINCL=-I$PYTHON_ROOT/include
+		AC_MSG_CHECKING([for python header file Python.h])
+		dnl Python.h mighty be in different locations:
+		if test -f "$PYTHON_ROOT/include/Python.h"; then
+			PYTHONINCL=-I$PYTHON_ROOT/include
+		else if test -f "$PYTHON_ROOT/include/python$PYTHON_VERSION/Python.h"; then
+			PYTHONINCL=-I$PYTHON_ROOT/include/python$PYTHON_VERSION
+		else
+			AC_MSG_ERROR([Python.h not found, locate this file and contact ISSM developers]);
+		fi
+		fi
+		AC_MSG_RESULT(found)
+
 		PYTHONLIB="-L$PYTHON_ROOT/lib -lpython$PYTHON_VERSION"
 		PYTHONEXT=.so
@@ -624,4 +714,31 @@
 	fi
 	dnl }}}
+	dnl esmf{{{
+	AC_ARG_WITH([esmf-dir],
+		AS_HELP_STRING([--with-esmf-dir=DIR], [esmf root directory.]),
+		[ESMF_ROOT=$withval],[ESMF_ROOT="no"]) 
+
+	dnl Check whether esmf is enabled
+	AC_MSG_CHECKING([for esmf])
+	if test "x$ESMF_ROOT" = "xno" ; then
+		HAVE_ESMF=no
+	else
+		HAVE_ESMF=yes
+		if ! test -d "$ESMF_ROOT"; then
+			AC_MSG_ERROR([esmf directory provided ($ESMF_ROOT) does not exist]);
+		fi
+	fi
+	AC_MSG_RESULT($HAVE_ESMF)
+	
+	dnl esmf headers and libraries
+	if test "x$HAVE_ESMF" == "xyes"; then
+		ESMFINCL="-I$ESMF_ROOT/include"
+		ESMFLIB="-L$ESMF_ROOT/lib -lesmf"
+		AC_DEFINE([_HAVE_ESMF_],[1],[with esmf in ISSM src])
+		AC_SUBST([ESMFINCL])
+		AC_SUBST([ESMFLIB])
+	fi
+	AM_CONDITIONAL([ESMF], [test x$HAVE_ESMF = xyes])
+	dnl }}}
 	dnl adolc{{{
 	AC_ARG_WITH([adolc-dir],
@@ -651,4 +768,5 @@
 	fi
 	AM_CONDITIONAL([ADOLC], [test x$HAVE_ADOLC = xyes])
+        AM_COND_IF(ADOLC,[CXXFLAGS+=" -std=c++11"])
 	dnl }}}
 	dnl adolc-version{{{
@@ -840,6 +958,9 @@
 		if  test x$VENDOR = xintel-win7-32; then
 			MPI_LIBDIR=`cygpath -m $MPI_LIBDIR`
-			MPIINCL=`cygpath -m $MPI_INCLUDE`
+			MPI_INCLUDE=`cygpath -m $MPI_INCLUDE`
 		elif test x$VENDOR = xintel-win7-64; then
+			MPI_LIBDIR="/I`cygpath -m $MPI_LIBDIR`"
+			MPI_INCLUDE=`cygpath -m $MPI_INCLUDE`
+		elif test x$VENDOR = xMSVC-Win64 || test x$VENDOR = xMSVC-Win64-par; then
 			MPI_LIBDIR=`cygpath -m $MPI_LIBDIR`
 			MPI_INCLUDE=`cygpath -m $MPI_INCLUDE`
@@ -847,10 +968,15 @@
 
 		if test -z "$MPI_LIBDIR"; then
-			MPIINCL=-I"$MPI_INCLUDE"
 			MPILIB="$MPI_LIBFLAGS"
 		else
+			MPILIB="-L$MPI_LIBDIR $MPI_LIBFLAGS"
+		fi
+
+		if  test x$IS_WINDOWS = xyes; then
+			MPIINCL=/I"$MPI_INCLUDE"
+		else 
 			MPIINCL=-I"$MPI_INCLUDE"
-			MPILIB="-L$MPI_LIBDIR $MPI_LIBFLAGS"
-		fi
+		fi
+
 		AC_DEFINE([_HAVE_MPI_],[1],[with Mpi in ISSM src])
 		AC_DEFINE([HAVE_MPI],[1],[Mpi Flag for Dakota (DO NOT REMOVE)])
@@ -925,6 +1051,6 @@
 					PETSCLIB=-Wl,/LIBPATH:`cygpath -w $PETSC_ROOT/lib`  -Wl,libpetscksp.lib  -Wl,libpetscdm.lib  -Wl,libpetscmat.lib  -Wl,libpetscvec.lib  -Wl,libpetscsnes.lib  -Wl,libpetscts.lib  -Wl,libmpiuni.lib  -Wl,libpetsc.lib
 				else
-					PETSCLIB="-L$PETSC_ROOT/lib  -Wl,libpetsc.lib"
-					if test $PETSC_MAJOR -gt 3 || test $PETSC_MINOR -ge 3; then PETSCLIB+="  -Wl,libmetis.lib"; fi
+					PETSCLIB="/link -Wl,/LIBPATH:`cygpath -m $PETSC_ROOT/lib`  -Wl,libpetsc.lib"
+					PETSCINCL="/I`cygpath -m $PETSC_ROOT/include`"
 				fi
 				;;
@@ -936,4 +1062,7 @@
 					if test $PETSC_MAJOR -gt 3 || test $PETSC_MINOR -ge 3; then PETSCLIB+=" -lmetis"; fi
 				fi
+				if test "x$host_os_version" = "x3.0.101-0.31.1_1.0502.8394-cray_gem_s" ; then
+					PETSCLIB="-L$PETSC_ROOT/lib -lcraypetsc_gnu_real -lmetis"
+				fi 
 				;;
 				*darwin*)
@@ -953,5 +1082,5 @@
 	dnl }}}
 	dnl metis{{{
-	if test "$HAVE_PETSC" = "yes" && test "x$PETSC_MAJOR" = "x3" && test $PETSC_MINOR -ge 3; then
+	if test "$HAVE_PETSC" = "yes" && test "x$PETSC_MAJOR" = "x3" && test $PETSC_MINOR -ge 3 && test "x$VENDOR" != "xMSVC-Win64" && test "x$VENDOR" != "xMSVC-Win64-par"; then
 		dnl in petsc >=3.3, metis is provided
 		HAVE_METIS="yes"
@@ -991,5 +1120,6 @@
 				case "${host_os}" in
 					*cygwin*)
-					METISLIB="-L$METIS_ROOT -Wl,libmetis.lib"
+					METISINCL="/I`cygpath -m $METIS_ROOT/Lib`" 
+					METISLIB="-Wl,/link -Wl,/LIBPATH:`cygpath -m $METIS_ROOT` -Wl,libmetis.lib"
 					;;
 					*linux*)
@@ -1213,5 +1343,8 @@
 		BLASLAPACKINCL=""
 		if test x$VENDOR = xintel-discover; then
-			BLASLAPACKLIB=-L"$BLASLAPACK_ROOT -lmkl_lapack -lmkl -lguide -lpthread"
+		   dnl works for intel 11
+			dnl BLASLAPACKLIB=-L"$BLASLAPACK_ROOT -lmkl_lapack -lmkl -lguide -lpthread "
+			dnl dnl works for intel 13
+			BLASLAPACKLIB=-L"$BLASLAPACK_ROOT -lmkl_lapack95_lp64 -lmkl_rt " 
 		else
 			dnl: branch on whether we are running on windows or linux.
@@ -1252,10 +1385,15 @@
 	dnl mkl headers and libraries
 	if test "x$HAVE_MKL" == "xyes"; then
+	 dnl look at $ISSM_DIR/externalpackages/petsc/install/lib/petsc/conf/petscvariables BLASLAPACK_LIB
 		MKLINCL=""
 		if test x$VENDOR = xintel-pleiades; then
-			MKLLIB=-L"$MKL_ROOT -lmkl_core -lmkl_blas95_lp64 -lmkl_lapack95_lp64 -liomp5 -lpthread -lmkl_intel_thread -lmkl_intel_sp2dp"
+         MKLLIB="-Wl,-rpath,$MKL_ROOT -L/$MKL_ROOT -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm"
+		elif test x$VENDOR = xintel-discover; then
+			MKLLIB=-L"$MKL_ROOT -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -L/usr/lib64/ -lpthread -lm"
 		elif test x$VENDOR = xintel-acenet; then
 			MKLLIB=-L"$MKL_ROOT -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm"
 		elif test x$VENDOR = xintel-gp; then
+			MKLLIB=-L"$MKL_ROOT -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm"
+		elif test x$VENDOR = xintel-lonestar; then
 			MKLLIB=-L"$MKL_ROOT -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm"
 		else
@@ -1846,5 +1984,5 @@
 	AC_ARG_WITH([cxxoptflags],
 	  AS_HELP_STRING([--with-cxxoptflags = CXXOPTFLAGS], [optimization using CXX flags, ex: --with-cxxoptflags=-march=opteron -O3]),
-	  [CXXOPTFLAGS=$withval],[CXXOPTFLAGS="-g -O2"]) 
+	  [CXXOPTFLAGS=$withval],[CXXOPTFLAGS="-g -O2 -fPIC"]) 
 	AC_MSG_CHECKING(for c++ optimization flags)
 	AC_SUBST([CXXOPTFLAGS])
@@ -1871,5 +2009,5 @@
 		;;
 		*darwin*)
-		MULTITHREADINGLIB="-L/usr/lib/ -lpthread"
+		MULTITHREADINGLIB="-lpthread"
 		;;
 		esac
