Index: /issm/trunk-jpl/src/c/classes/IssmComm.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/IssmComm.cpp	(revision 13700)
+++ /issm/trunk-jpl/src/c/classes/IssmComm.cpp	(revision 13701)
@@ -19,20 +19,27 @@
 }/*}}}*/
 int IssmComm::GetRank(){  /*{{{*/
-	int my_rank;
+	int my_rank = 0;
+
+	/*for matlab and python modules, comm == -1*/
+	if((int)comm==-1) return my_rank;
+
 	#ifdef _HAVE_MPI_
 	MPI_Comm_rank(comm,&my_rank);
-	#else
-	my_rank=0;
 	#endif
+
 	return my_rank;
 
 }/*}}}*/
 int IssmComm::GetSize(){  /*{{{*/
-	int size;
+
+	int size = 1;
+
+	/*for matlab and python modules, comm == -1*/
+	if((int)comm==-1) return size;
+
 	#ifdef _HAVE_MPI_
 	MPI_Comm_size(comm,&size);
-	#else
-	size=1;
 	#endif
+
 	return size;
 
Index: /issm/trunk-jpl/src/c/include/macros.h
===================================================================
--- /issm/trunk-jpl/src/c/include/macros.h	(revision 13700)
+++ /issm/trunk-jpl/src/c/include/macros.h	(revision 13701)
@@ -23,5 +23,5 @@
 #define _printf_(flag,...) do{if(flag) PrintfFunction(__VA_ARGS__);}while(0)
 /*}}}*/
-/* _error2_ {{{*/
+/* _error_ {{{*/
 /*new Error exception macro*/
 #ifdef _INTEL_WIN_
@@ -82,5 +82,4 @@
 #define ExceptionTrapEnd(); }\
 	catch(ErrorException &exception){\
-		exception.Report(); \
 		return 1;\
 	}\
Index: /issm/trunk-jpl/src/c/matlab/include/matlab_macros.h
===================================================================
--- /issm/trunk-jpl/src/c/matlab/include/matlab_macros.h	(revision 13700)
+++ /issm/trunk-jpl/src/c/matlab/include/matlab_macros.h	(revision 13701)
@@ -20,9 +20,10 @@
  * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 
  * will be trapped*/
-#define MODULEBOOT(); try{ 
+#define MODULEBOOT(); try{ \
+	IssmComm::SetComm(-1);
 
 #define MODULEEND(); }\
 	catch(ErrorException &exception){\
-		mexErrMsgTxt("ISSM Error"); \
+		mexErrMsgTxt(exception.MatlabReport()); \
 	}\
 	catch (exception &e){\
Index: sm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp
===================================================================
--- /issm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp	(revision 13700)
+++ 	(revision )
@@ -1,60 +1,0 @@
-/*\file PrintfFunction.c
- *\brief: this function is used by the _printf_ macro, to take into account the 
- *fact we may be running on a cluster. 
- */
-
-#include <stdarg.h>
-#include <stdio.h>
-#include "../../shared/shared.h"
-#include "../../include/include.h"
-
-#include "mex.h"
-
-int PrintfFunction(char* format,...){
-	/*http://linux.die.net/man/3/vsnprintf*/
-
-	/*string to be printed: */
-	char *buffer = NULL;
-	int   n,size = 100;
-	int         string_size;
-	int  my_rank;
-
-	/*recover my_rank:*/
-	my_rank=IssmComm::GetRank();
-
-	//variable list of arguments
-	va_list args;
-
-	while(true){
-
-		/*allocate buffer for given string size*/
-		buffer=xNew<char>(size);
-
-		/* Try to print in the allocated space. */
-		va_start(args, format);
-#ifndef WIN32
-		n=vsnprintf(buffer,size,format,args);
-#else
-		n=vsnprintf(buffer,size,format,args);
-#endif
-		va_end(args);
-
-		/* If that worked, return the string. */
-		if(n>-1 && n<size) break;
-
-		/* Else try again with more space. */
-		if(n>-1)   /* glibc 2.1 */
-		 size=n+1; /* precisely what is needed */
-		else       /* glibc 2.0 */
-		 size*=2;  /* twice the old size */
-
-		xDelete<char>(buffer);
-	}
-
-	/*Ok, if we are running in parallel, get node 0 to print*/
-	if(my_rank==0)_printString_(buffer);
-
-	/*Clean up and return*/
-	xDelete<char>(buffer);
-	return 1;
-}
Index: /issm/trunk-jpl/src/c/python/include/python_macros.h
===================================================================
--- /issm/trunk-jpl/src/c/python/include/python_macros.h	(revision 13700)
+++ /issm/trunk-jpl/src/c/python/include/python_macros.h	(revision 13701)
@@ -22,12 +22,13 @@
  * will be trapped*/
 #define MODULEBOOT(); \
-	PyObject *output = PyTuple_New(NLHS);        \
+	PyObject *output = PyTuple_New(NLHS); \
 	int       nrhs   = (int)PyTuple_Size(args);  \
 	if(!output) return NULL;\
-	 try{ \
+	try{ \
+	IssmComm::SetComm(-1);
 
 #define MODULEEND(); }\
   catch(ErrorException &exception){\
-	  PyErr_SetString(PyExc_TypeError,"ISSM Error"); \
+	  PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \
 	  return NULL;\
   } \
Index: /issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp	(revision 13700)
+++ /issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp	(revision 13701)
@@ -12,5 +12,5 @@
 #include "../../include/include.h"
 
-ErrorException::ErrorException(const string &what_arg){
+ErrorException::ErrorException(const string &what_arg){/*{{{*/
 
 	what_str=what_arg;
@@ -18,7 +18,6 @@
 	function_name="";
 	file_line=0;
-}
-
-ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){
+}/*}}}*/
+ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/
 
 	what_str=what_arg;
@@ -26,23 +25,11 @@
 	function_name=what_function;
 	file_line=what_line;
-}
-
-ErrorException::~ErrorException() throw(){
-
-	int num_procs;
-
-	/*recover num_procs:*/
-	num_procs=IssmComm::GetSize();
-
-	/*We want the report only for matlab modules, otherwise we get twice the report
-	 * We assume that if num_procs==1, it is a module (FIXME)*/
-	if(num_procs==1) this->Report();
-}
-
-const char* ErrorException::what() const throw(){
+}/*}}}*/
+ErrorException::~ErrorException() throw(){/*{{{*/
+}/*}}}*/
+const char* ErrorException::what() const throw(){/*{{{*/
 	return what_str.c_str();
-}
-
-void ErrorException::Report() const{
+}/*}}}*/
+void ErrorException::Report() const{/*{{{*/
 
 	int my_rank;
@@ -58,12 +45,42 @@
 	else{
 		if(num_procs==1){
-			_printLine_("\n??? Error using ==> " << file_name.c_str() << ":" << file_line);
+			_printLine_("\n??? Error in ==> " << file_name.c_str() << ":" << file_line);
 			_printLine_(function_name.c_str() << " error message: " << what() << "\n");
 		}
 		else{
 			_printLine_("\n[" << my_rank<< "] ??? Error using ==> " << file_name.c_str() << ":" << file_line);
-			_printLine_("[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n");
+			_printLine_(  "[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n");
 		}
 	}
 	return;
-}
+}/*}}}*/
+const char* ErrorException::MatlabReport() const{/*{{{*/
+
+	/*Output*/
+	std::ostringstream buffer;
+
+	if (this->file_line==0){ //WINDOWS
+		 buffer << " error message: " << (this->what_str).c_str();
+	}
+	else{
+		buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";
+		buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();
+	}
+
+	return buffer.str().c_str();
+}/*}}}*/
+const char* ErrorException::PythonReport() const{/*{{{*/
+
+	/*Output*/
+	std::ostringstream buffer;
+
+	if (this->file_line==0){ //WINDOWS
+		buffer << " error message: " << (this->what_str).c_str();
+	}
+	else{
+		buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";
+		buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();
+	}
+
+	return buffer.str().c_str();
+}/*}}}*/
Index: /issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h	(revision 13700)
+++ /issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h	(revision 13701)
@@ -28,4 +28,6 @@
 	virtual const char *what() const throw();
 	void Report() const;
+	const char* MatlabReport() const;
+	const char* PythonReport() const;
 
 };
