Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 25529)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 25530)
@@ -147,4 +147,5 @@
 	./shared/io/Comm/IssmComm.cpp \
 	./shared/io/Marshalling/IoCodeConversions.cpp \
+	./shared/io/Marshalling/Marshalling.cpp \
 	./shared/LatLong/Ll2xyx.cpp \
 	./shared/LatLong/Xy2llx.cpp \
Index: /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp	(revision 25530)
+++ /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.cpp	(revision 25530)
@@ -0,0 +1,145 @@
+/*!\file:  Marshalling.cpp
+ * \brief implement marshall
+ */ 
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./Marshalling.h"
+
+WriteCheckpointFunctor::WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE){/*{{{*/
+	this->pmarshalled_data = pmarshalled_data_in;
+}/*}}}*/
+void WriteCheckpointFunctor::Echo(void){/*{{{*/
+	printf("WriteCheckpointFunctor Echo:\n");
+	printf("   pmarshalled_data: %p\n",pmarshalled_data);
+}/*}}}*/
+void WriteCheckpointFunctor::call(char* & value){/*{{{*/
+	int size = strlen(value)+1;
+	this->call(size);
+	this->call(value,size);
+};/*}}}*/
+
+LoadCheckpointFunctor::LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD){/*{{{*/
+	this->pmarshalled_data = pmarshalled_data_in;
+}/*}}}*/
+void LoadCheckpointFunctor::Echo(void){/*{{{*/
+	printf("LoadCheckpointFunctor Echo:\n");
+	printf("   pmarshalled_data: %p\n",pmarshalled_data);
+}/*}}}*/
+void LoadCheckpointFunctor::call(char* & value){/*{{{*/
+	int size;
+	this->call(size);
+	this->call(value,size);
+};/*}}}*/
+
+SizeCheckpointFunctor::SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE){/*{{{*/
+	this->marshalled_data_size = 0;
+}/*}}}*/
+int  SizeCheckpointFunctor::MarshalledSize(void){/*{{{*/
+	return this->marshalled_data_size;
+};/*}}}*/
+void SizeCheckpointFunctor::Echo(void){/*{{{*/
+	printf("SizeCheckpointFunctor Echo:\n");
+	printf("   marshalled_data_size: %i\n",marshalled_data_size);
+}/*}}}*/
+void SizeCheckpointFunctor::call(char* & value){/*{{{*/
+	int size = strlen(value)+1;
+	this->call(size);
+	this->call(value,size);
+};/*}}}*/
+
+#if defined(_HAVE_CODIPACK_) && !defined(_WRAPPERS_)
+CountDoublesFunctor::CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES){/*{{{*/
+	this->double_count= 0;
+}/*}}}*/
+int  CountDoublesFunctor::DoubleCount(void){/*{{{*/
+	return this->double_count;
+};/*}}}*/
+void CountDoublesFunctor::Echo(void){/*{{{*/
+	printf("CountDoublesFunctor Echo:\n");
+	printf("   double_count: %i\n",double_count);
+}/*}}}*/
+void CountDoublesFunctor::call(IssmDouble value){/*{{{*/
+	this->double_count++;
+}/*}}}*/
+void CountDoublesFunctor::call(IssmDouble* value,int size){/*{{{*/
+	if(value) this->double_count+= size;
+}/*}}}*/
+
+RegisterInputFunctor::RegisterInputFunctor(int* identifiers_in,int size_max_in) : MarshallHandle(AD_REGISTERINPUT){/*{{{*/
+	this->double_count = 0;
+	this->identifiers  = identifiers_in;
+	this->size_max         = size_max_in;
+	this->tape_codi    = &(IssmDouble::getGlobalTape());
+}/*}}}*/
+void RegisterInputFunctor::Echo(void){/*{{{*/
+	printf("RegisterInputFunctor Echo:\n");
+	printf("   double_count: %i\n",double_count);
+}/*}}}*/
+void RegisterInputFunctor::call(IssmDouble value){/*{{{*/
+	_assert_(this->double_count<size_max);
+	this->tape_codi->registerInput(value);
+	this->identifiers[this->double_count] = value.getGradientData();
+	this->double_count++;
+}/*}}}*/
+void RegisterInputFunctor::call(IssmDouble* value,int size){/*{{{*/
+	if(value){
+		for(int i=0;i<size;i++){
+			_assert_(this->double_count<size_max);
+			this->tape_codi->registerInput(value[i]);
+			this->identifiers[this->double_count] = value[i].getGradientData();
+			this->double_count++;
+		}
+	}
+}/*}}}*/
+
+RegisterOutputFunctor::RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){/*{{{*/
+	this->double_count = 0;
+	this->tape_codi    = &(IssmDouble::getGlobalTape());
+}/*}}}*/
+void RegisterOutputFunctor::Echo(void){/*{{{*/
+	printf("RegisterOutputFunctor Echo:\n");
+	printf("   double_count: %i\n",double_count);
+}/*}}}*/
+void RegisterOutputFunctor::call(IssmDouble value){/*{{{*/
+	this->tape_codi->registerOutput(value);
+	this->double_count++;
+}/*}}}*/
+void RegisterOutputFunctor::call(IssmDouble* value,int size){/*{{{*/
+	if(value){
+		for(int i=0;i<size;i++){
+			this->tape_codi->registerOutput(value[i]);
+			this->double_count++;
+		}
+	}
+}/*}}}*/
+
+SetAdjointFunctor::SetAdjointFunctor(double* adjoint_in,int size_max_in) : MarshallHandle(AD_SETADJOINT){/*{{{*/
+	this->double_count = 0;
+	this->tape_codi    = &(IssmDouble::getGlobalTape());
+	this->adjoint      = adjoint_in;
+	this->size_max     = size_max_in;
+}/*}}}*/
+void SetAdjointFunctor::Echo(void){/*{{{*/
+	printf("SetAdjointFunctor Echo:\n");
+	printf("   double_count: %i\n",double_count);
+}/*}}}*/
+void SetAdjointFunctor::call(IssmDouble value){/*{{{*/
+	_assert_(this->double_count<size_max);
+	value.gradient() = this->adjoint[this->double_count];
+	this->double_count++;
+}/*}}}*/
+void SetAdjointFunctor::call(IssmDouble* value,int size){/*{{{*/
+	if(value){
+		for(int i=0;i<size;i++){
+			_assert_(this->double_count<size_max);
+			value[i].gradient() = this->adjoint[this->double_count];
+			this->double_count++;
+		}
+	}
+}/*}}}*/
+#endif
Index: /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h	(revision 25529)
+++ /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h	(revision 25530)
@@ -42,18 +42,11 @@
 
 	public:
-		WriteCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_WRITE),pmarshalled_data(pmarshalled_data_in){}
-		void Echo(void){
-			printf("WriteCheckpointFunctor Echo:\n");
-			printf("   pmarshalled_data: %p\n",pmarshalled_data);
-		}
+		WriteCheckpointFunctor(char** pmarshalled_data_in);
+		void Echo(void);
 		template<typename T> void call(T & value){
 			memcpy(*pmarshalled_data,&value,sizeof(T));
 			*pmarshalled_data+=sizeof(T);
 		}
-		void call(char* & value){
-			int size = strlen(value)+1;
-			this->call(size);
-			this->call(value,size);
-		};
+		void call(char* & value);
 		template<typename T> void call(T* & value,int size){
 			bool pointer_null = true;
@@ -72,18 +65,11 @@
 
 	public:
-		LoadCheckpointFunctor(char** pmarshalled_data_in) : MarshallHandle(MARSHALLING_LOAD),pmarshalled_data(pmarshalled_data_in){}
-		void Echo(void){
-			printf("LoadCheckpointFunctor Echo:\n");
-			printf("   pmarshalled_data: %p\n",pmarshalled_data);
-		}
+		LoadCheckpointFunctor(char** pmarshalled_data_in);
+		void Echo(void);
+		void call(char* & value);
 		template<typename T> void call(T & value){
 			memcpy(&value,*pmarshalled_data,sizeof(T));
 			*pmarshalled_data+=sizeof(T);
 		}
-		void call(char* & value){
-			int size;
-			this->call(size);
-			this->call(value,size);
-		};
 		template<typename T> void call(T* & value,int size){
 			bool pointer_null;
@@ -105,18 +91,11 @@
 
 	public:
-		SizeCheckpointFunctor(void) : MarshallHandle(MARSHALLING_SIZE),marshalled_data_size(0){}
-		int MarshalledSize(void){return this->marshalled_data_size;};
-		void Echo(void){
-			printf("SizeCheckpointFunctor Echo:\n");
-			printf("   marshalled_data_size: %i\n",marshalled_data_size);
-		}
+		SizeCheckpointFunctor(void);
+		int MarshalledSize(void);
+		void Echo(void);
 		template<typename T> void call(T & value){
 			marshalled_data_size+=sizeof(T);
 		}
-		void call(char* & value){
-			int size = strlen(value)+1;
-			this->call(size);
-			this->call(value,size);
-		};
+		void call(char* & value);
 		template<typename T> void call(T* & value,int size){
 			bool pointer_null = true;
@@ -135,60 +114,27 @@
 
 	public:
-		CountDoublesFunctor(void) : MarshallHandle(AD_COUNTDOUBLES),double_count(0){}
-		int DoubleCount(void){return this->double_count;};
-		void Echo(void){
-			printf("CountDoublesFunctor Echo:\n");
-			printf("   double_count: %i\n",double_count);
-		}
-		template<typename T> void call(T & value){
-			/*General case: do nothing*/
-		}
-		template<typename T> void call(T* & value,int size){
-			/*General case: do nothing*/
-		}
-		void call(IssmDouble value){
-			this->double_count++;
-		}
-		void call(IssmDouble* value,int size){
-			if(value) this->double_count+= size;
-		}
+		CountDoublesFunctor(void);
+		int  DoubleCount(void);
+		void Echo(void);
+		template<typename T> void call(T & value){/*General case: do nothing*/}
+		template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
+		void call(IssmDouble value);
+		void call(IssmDouble* value,int size);
 }; /*}}}*/
 class RegisterInputFunctor:   public MarshallHandle{ /*{{{*/
 
 	private:
-		int   double_count;
-		int*  identifiers;
-		IssmDouble::TapeType* tape_codi;
-
-	public:
-		RegisterInputFunctor(int* identifiers_in) : MarshallHandle(AD_REGISTERINPUT){
-			this->double_count = 0;
-			this->identifiers  = identifiers_in;
-			this->tape_codi    = &(IssmDouble::getGlobalTape());
-		}
-		void Echo(void){
-			printf("RegisterInputFunctor Echo:\n");
-			printf("   double_count: %i\n",double_count);
-		}
-		template<typename T> void call(T & value){
-			/*General case: do nothing*/
-		}
-		template<typename T> void call(T* & value,int size){
-			/*General case: do nothing*/
-		}
-		void call(IssmDouble value){
-			this->tape_codi->registerInput(value);
-			this->identifiers[this->double_count] = value.getGradientData();
-			this->double_count++;
-		}
-		void call(IssmDouble* value,int size){
-			if(value){
-				for(int i=0;i<size;i++){
-					this->tape_codi->registerInput(value[i]);
-					this->identifiers[this->double_count] = value[i].getGradientData();
-					this->double_count++;
-				}
-			}
-		}
+		int  double_count;
+		int *identifiers;
+		int  size_max;
+		IssmDouble::TapeType *tape_codi;
+
+	public:
+		RegisterInputFunctor(int* identifiers_in,int size_max_in);
+		void Echo(void);
+		template<typename T> void call(T & value){/*General case: do nothing*/}
+		template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
+		void call(IssmDouble value);
+		void call(IssmDouble* value,int size);
 }; /*}}}*/
 class RegisterOutputFunctor:  public MarshallHandle{ /*{{{*/
@@ -199,30 +145,10 @@
 
 	public:
-		RegisterOutputFunctor(void) : MarshallHandle(AD_REGISTEROUTPUT){
-			this->double_count = 0;
-			this->tape_codi    = &(IssmDouble::getGlobalTape());
-		}
-		void Echo(void){
-			printf("RegisterOutputFunctor Echo:\n");
-			printf("   double_count: %i\n",double_count);
-		}
-		template<typename T> void call(T & value){
-			/*General case: do nothing*/
-		}
-		template<typename T> void call(T* & value,int size){
-			/*General case: do nothing*/
-		}
-		void call(IssmDouble value){
-			this->tape_codi->registerOutput(value);
-			this->double_count++;
-		}
-		void call(IssmDouble* value,int size){
-			if(value){
-				for(int i=0;i<size;i++){
-					this->tape_codi->registerOutput(value[i]);
-					this->double_count++;
-				}
-			}
-		}
+		RegisterOutputFunctor(void);
+		void Echo(void);
+		template<typename T> void call(T & value){/*General case: do nothing*/}
+		template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
+		void call(IssmDouble value);
+		void call(IssmDouble* value,int size);
 }; /*}}}*/
 class SetAdjointFunctor:      public MarshallHandle{ /*{{{*/
@@ -230,35 +156,15 @@
 	private:
 		int                   double_count;
+		int                   size_max;
 		IssmDouble::TapeType* tape_codi;
 		double*               adjoint;
 
 	public:
-		SetAdjointFunctor(double* adjoint_in) : MarshallHandle(AD_SETADJOINT){
-			this->double_count = 0;
-			this->tape_codi    = &(IssmDouble::getGlobalTape());
-			this->adjoint      = adjoint_in;
-		}
-		void Echo(void){
-			printf("SetAdjointFunctor Echo:\n");
-			printf("   double_count: %i\n",double_count);
-		}
-		template<typename T> void call(T & value){
-			/*General case: do nothing*/
-		}
-		template<typename T> void call(T* & value,int size){
-			/*General case: do nothing*/
-		}
-		void call(IssmDouble value){
-			value.gradient() = this->adjoint[this->double_count];
-			this->double_count++;
-		}
-		void call(IssmDouble* value,int size){
-			if(value){
-				for(int i=0;i<size;i++){
-					value[i].gradient() = this->adjoint[this->double_count];
-					this->double_count++;
-				}
-			}
-		}
+		SetAdjointFunctor(double* adjoint_in,int size_max_in);
+		void Echo(void);
+		template<typename T> void call(T & value){/*General case: do nothing*/}
+		template<typename T> void call(T* & value,int size){/*General case: do nothing*/}
+		void call(IssmDouble value);
+		void call(IssmDouble* value,int size);
 }; /*}}}*/
 #endif
@@ -293,3 +199,3 @@
 }
 
-#endif	
+#endif
