Index: /issm/branches/trunk-larour-SLPS2020/src/c/main/issm_post.cpp
===================================================================
--- /issm/branches/trunk-larour-SLPS2020/src/c/main/issm_post.cpp	(revision 25536)
+++ /issm/branches/trunk-larour-SLPS2020/src/c/main/issm_post.cpp	(revision 25537)
@@ -60,6 +60,6 @@
 	/*Retrieve fields:*/
 	nfields=atoi(argv[5]);
+	fields=xNew<char*>(nfields);
 	for(int i=0;i<nfields;i++){
-		fields=xNew<char*>(nfields);
 		string= argv[6+i];
 		field=xNew<char>(strlen(string)+1);
@@ -69,4 +69,11 @@
 	parameters->AddObject(new StringArrayParam(FieldsEnum,fields,nfields));
 	offset=6+nfields;
+
+	/*free some memory: */
+	for(int i=0;i<nfields;i++){
+		char* field=fields[i]; 
+		xDelete<char>(field);
+	}
+	xDelete<char*>(fields);
 
 	/*Retrieve time steps:*/
@@ -86,6 +93,9 @@
 	for (int i=step1;i<=step2;i++)steps[i-step1]=i;
 	parameters->AddObject(new IntVecParam(StepsEnum,steps,nsteps));
-
 	offset++;
+
+	/*free some memory:*/
+	xDelete<int>(steps);
+
 	/*}}}*/
 	
@@ -113,9 +123,10 @@
 		}
 		parameters->AddObject(new IntVecParam(IndicesEnum,indices,nindices));
+
+		/*free some memory:*/
+		xDelete<int>(indices);
 		
 		ComputeSampleSeries(parameters,results);
 	}
-
-
 
 	else _error_("unknown method: " << method << "\n");
@@ -124,4 +135,8 @@
 	ISSM_MPI_Barrier(ISSM_MPI_COMM_WORLD); _printf0_("Output file.\n");
 	OutputStatistics(parameters,results);
+
+	/*Delete ressources:*/
+	delete parameters; 
+	delete results;
 
 	/*Finalize ISSM:*/
@@ -190,5 +205,5 @@
 		_printf0_("reading file #: " << i << "\n");
 		char file[1000];
-		int  length;
+		long int  length;
 		char* buffer=NULL;
 
@@ -197,6 +212,7 @@
 
 		/*open file: */
-		_printf0_("    opening file:\n");
+		_printf0_("    opening file: " << file << "\n");
 		FILE* fid=fopen(file,"rb");
+		if(fid==NULL) _error_("    could not open file: " << file << "\n");
 
 		/*figure out size of file, and read the whole thing:*/
@@ -505,5 +521,5 @@
 		_printf0_("reading file #: " << i << "\n");
 		char file[1000];
-		int  length;
+		long int  length;
 		char* buffer=NULL;
 
@@ -668,5 +684,5 @@
 		_printf0_("reading file #: " << i << "\n");
 		char file[1000];
-		int  length;
+		long int  length;
 		char* buffer=NULL;
 
@@ -675,5 +691,5 @@
 
 		/*open file: */
-		_printf0_("    opening file:\n");
+		_printf0_("    opening file: " << file < "\n");
 		FILE* fid=fopen(file,"rb");
 		if(fid==NULL)_error_("cound not open file: " << file << "\n");
@@ -715,4 +731,5 @@
 						xMemCpy<IssmDouble>(minxs[counter],doublemat,doublematsize);
 						xsize[counter]=doublematsize;
+						xDelete<IssmDouble>(doublemat);
 					}
 					else _error_("cannot carry out statistics on type " << xtype[counter]); 
@@ -730,4 +747,5 @@
 							if(doublemat[k]<newmin[k])newmin[k]=doublemat[k];
 						}
+						xDelete<IssmDouble>(doublemat);
 					}
 					else _error_("cannot carry out statistics on type " << xtype[counter]); 
@@ -773,4 +791,5 @@
 						timemean[k]+=doublemat[k]/nsteps;
 					}
+					xDelete<IssmDouble>(doublemat);
 				}
 
@@ -899,5 +918,5 @@
 		_printf0_("reading file #: " << i << "\n");
 		char file[1000];
-		int  length;
+		long int  length;
 		char* buffer=NULL;
 
@@ -952,4 +971,5 @@
 						}
 						histogram[counter]=localhistogram;
+						xDelete<IssmDouble>(doublemat);
 					}
 					else _error_("cannot carry out statistics on type " << xtype[counter]); 
@@ -972,4 +992,5 @@
 							localhistogram[k*nbins+index]++;
 						}
+						xDelete<IssmDouble>(doublemat);
 					}
 					else _error_("cannot carry out statistics on type " << xtype[counter]); 
@@ -1018,4 +1039,5 @@
 						timemean[k]+=doublemat[k]/nsteps;
 					}
+					xDelete<IssmDouble>(doublemat);
 				}
 
@@ -1051,4 +1073,5 @@
 		xDelete<char>(buffer);
 	}
+	_printf0_("Start aggregating histogram:\n");
 
 	/*We have agregated histograms across the cluster, now gather them across  the cluster onto
@@ -1088,7 +1111,8 @@
 				/*we are broadcasting double arrays:*/
 				IssmDouble* histo=histogram[counter];
-				IssmDouble*  allhisto=xNew<IssmDouble>(size*nbins);
+				IssmDouble* allhisto=xNew<IssmDouble>(size*nbins);
 				
 				ISSM_MPI_Allreduce(histo,allhisto,size*nbins,ISSM_MPI_PDOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+				xDelete<IssmDouble>(histo);
 
 				/*add to results:*/
@@ -1107,4 +1131,5 @@
 		} /*}}}*/
 	}
+	_printf0_("Start aggregating time mean histogram:\n");
 	
 	/*Now do the same for the time mean fields:*/
@@ -1140,4 +1165,5 @@
 
 			ISSM_MPI_Allreduce(histo,allhisto,size*nbins,ISSM_MPI_PDOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+			xDelete<IssmDouble>(histo);
 			/*add to results at step 1:*/
 			if(my_rank==0){
