Index: issm/trunk/src/c/objects/IoModel.cpp
===================================================================
--- issm/trunk/src/c/objects/IoModel.cpp	(revision 9356)
+++ issm/trunk/src/c/objects/IoModel.cpp	(revision 9362)
@@ -12,4 +12,7 @@
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
 #include "./objects.h"
 #include "./Container/Parameters.h"
@@ -21,220 +24,56 @@
 IoModel::IoModel(){
 	this->fid=NULL;
-	this->parameters=NULL;
-}
-/*}}}*/
-/*FUNCTION IoModel::IoModel(FILE*  iomodel_handle){{{1*/
-IoModel::IoModel(FILE* iomodel_handle){
-	
-	int i,j;
-
-	/*First, keep track of the file handle: */
-	this->fid=iomodel_handle;
-
-	/*Initialize and read parameters:*/
-	this->parameters=new Parameters();
-	this->FetchParameters(this->parameters); /*this routine goes through the input file, and fetches bools, ints, doubles and strings only, nothing memory intensive*/
-
-	/*Initialize the structure: */
-	this->IoModelInit();
-
-}
-/*}}}*/
-/*FUNCTION IoModel::~IoModel(){{{1*/
-IoModel::~IoModel(){
-	
-	int i;
-
-	/*!Two cases here: 
-	 * - serial mode: matlab's memory manager will take care of delete iomodel when returning from Imp. Do nothing here, so as not to confuse 
-	 *                the memory manager.
-     * - in parallel, anything the io layer does (FetchData) did needs to be erased explicitely in the iomodel.
-	 */
-
-	#ifdef _PARALLEL_
-	xfree((void**)&this->x);
-	xfree((void**)&this->y);
-	xfree((void**)&this->z);
-	xfree((void**)&this->elements);
-	xfree((void**)&this->elementconnectivity);
-	xfree((void**)&this->elements_type);
-	xfree((void**)&this->vertices_type);
-	xfree((void**)&this->nodeonhutter);
-	xfree((void**)&this->nodeonmacayeal);
-	xfree((void**)&this->elements2d);
-	xfree((void**)&this->upperelements);
-	xfree((void**)&this->lowerelements);
-	xfree((void**)&this->nodeonpattyn);
-	xfree((void**)&this->elementonbed);
-	xfree((void**)&this->elementonsurface);
-	xfree((void**)&this->nodeonbed);
-	xfree((void**)&this->nodeonsurface);
-	xfree((void**)&this->nodeonstokes);
-	xfree((void**)&this->borderstokes);
-	xfree((void**)&this->thickness_obs);
-	xfree((void**)&this->thickness_coeff);
-	xfree((void**)&this->thickness);
-	xfree((void**)&this->surface);
-	xfree((void**)&this->bed);
-	xfree((void**)&this->bathymetry);
-	xfree((void**)&this->vx_obs);
-	xfree((void**)&this->vy_obs);
-	xfree((void**)&this->vz_obs);
-	xfree((void**)&this->vx);
-	xfree((void**)&this->vy);
-	xfree((void**)&this->vz);
-	xfree((void**)&this->pressure);
-	xfree((void**)&this->temperature);
-	xfree((void**)&this->waterfraction);
-	xfree((void**)&this->drag_coefficient);
-	xfree((void**)&this->drag_p);
-	xfree((void**)&this->drag_q);
-	xfree((void**)&this->elementoniceshelf);
-	xfree((void**)&this->elementonwater);
-	xfree((void**)&this->nodeonicesheet);
-	xfree((void**)&this->nodeoniceshelf);
-	xfree((void**)&this->nodeonwater);
-	xfree((void**)&this->pressureload);
-	xfree((void**)&this->spcvx);
-	xfree((void**)&this->spcvy);
-	xfree((void**)&this->spcvz);
-	xfree((void**)&this->spcthickness);
-	xfree((void**)&this->spcwatercolumn);
-	xfree((void**)&this->spctemperature);
-	xfree((void**)&this->diagnostic_ref);
-	xfree((void**)&this->edges);
-	xfree((void**)&this->geothermalflux);
-	xfree((void**)&this->basal_melting_rate);
-	xfree((void**)&this->watercolumn);
-	xfree((void**)&this->basal_melting_rate_correction);
-	xfree((void**)&this->surface_accumulation_rate);
-	xfree((void**)&this->surface_ablation_rate);
-	xfree((void**)&this->surface_mass_balance);
-	xfree((void**)&this->dhdt);
-	xfree((void**)&this->rheology_B);
-	xfree((void**)&this->rheology_n);
-	xfree((void**)&this->control_type);
-	xfree((void**)&this->cm_responses);
-	xfree((void**)&this->weights);
-	xfree((void**)&this->cm_jump);
-	xfree((void**)&this->cm_min);
-	xfree((void**)&this->cm_max);
-	xfree((void**)&this->optscal);
-	xfree((void**)&this->maxiter);
-
-
-	/*!Delete structure fields: */
-	xfree((void**)&this->riftinfo);
-	xfree((void**)&this->penalties);
-	
-	/*exterior data: */
-	xfree((void**)&this->my_elements);
-	xfree((void**)&this->my_vertices);
-	xfree((void**)&this->my_nodes);
-	xfree((void**)&this->singlenodetoelementconnectivity);
-	xfree((void**)&this->numbernodetoelementconnectivity);
-	#endif
-}
-/*}}}*/
-/*FUNCTION IoModel::IoModelInit{{{1*/
-void IoModel::IoModelInit(void){
-
-	/*exterior data: */
+	this->constants=NULL;
+	
+	this->my_elements=NULL;
+	this->my_nodes=NULL;
+	this->my_vertices=NULL;
+	this->singlenodetoelementconnectivity=NULL;
+	this->numbernodetoelementconnectivity=NULL;
+	
 	this->nodecounter=0;
 	this->loadcounter=0;
 	this->constraintcounter=0;
-	
-	/*!initialize all pointers to 0: */
-	this->x=NULL; 
-	this->y=NULL;
-	this->z=NULL;
-	this->elements=NULL;
-	this->elementconnectivity=NULL;
-	this->elements_type=NULL;
-	this->vertices_type=NULL;
-	this->elements2d=NULL;
-	this->upperelements=NULL;
-	this->lowerelements=NULL;
-	this->nodeonhutter=NULL;
-	this->nodeonmacayeal=NULL;
-	this->nodeonpattyn=NULL;
-	
-	this->vx_obs=NULL;
-	this->vy_obs=NULL;
-	this->vz_obs=NULL;
-	this->vx=NULL;
-	this->vy=NULL;
-	this->vz=NULL;
-	this->pressure=NULL;
-	this->temperature=NULL;
-	this->waterfraction=NULL;
-	this->basal_melting_rate=NULL;
-	this->watercolumn=NULL;
-	this->basal_melting_rate_correction=NULL;
-	this->geothermalflux=NULL;
-	this->elementonbed=NULL;
-	this->elementonsurface=NULL;
-	this->nodeonbed=NULL;
-	this->nodeonsurface=NULL;
-	this->nodeonstokes=NULL;
-	this->borderstokes=NULL;
-	this->thickness_obs=NULL;
-	this->thickness_coeff=NULL;
-	this->thickness=NULL;
-	this->surface=NULL;
-	this->bed=NULL;
-	this->bathymetry=NULL;
-	this->elementoniceshelf=NULL;
-	this->elementonwater=NULL;
-	this->nodeonicesheet=NULL;
-	this->nodeoniceshelf=NULL;
-	this->nodeonwater=NULL;
-
-	this->drag_coefficient=NULL;
-	this->drag_p=NULL;
-	this->drag_q=NULL;
-	
-	
-	this->pressureload=NULL;
-	this-> spcvx=NULL;
-	this-> spcvy=NULL;
-	this-> spcvz=NULL;
-	this-> spctemperature=NULL;
-	this-> spcthickness=NULL;
-	this-> spcwatercolumn=NULL;
-	this-> diagnostic_ref=NULL;
-	this->edges=NULL;
-	
-	/*!materials: */
-	this->rheology_n=NULL;
-	this->rheology_B=NULL;
-
-	/*!solution parameters: */
-	this->control_type=NULL;
-	this->cm_responses=NULL;
-	this->weights=NULL;
-	this->cm_jump=NULL;
-	this->maxiter=NULL;
-	this->cm_min=NULL;
-	this->cm_max=NULL;
-	this->optscal=NULL;
-
-	this->riftinfo=NULL;
-
-	/*!penalties: */
-	this->penalties=NULL;
-
-	/*!surface: */
-	this->surface_mass_balance=NULL;
-   this->surface_accumulation_rate=NULL;
-	this->surface_ablation_rate=NULL;
-	this->dhdt=NULL;
-
-	/*exterior data: */
+
+}
+/*}}}*/
+/*FUNCTION IoModel::IoModel(FILE*  iomodel_handle){{{1*/
+IoModel::IoModel(FILE* iomodel_handle){
+	
+	/*First, keep track of the file handle: */
+	this->fid=iomodel_handle;
+
+	/*Initialize and read constants:*/
+	this->constants=new Parameters();
+	this->FetchParameters(this->constants); /*this routine goes through the input file, and fetches bools, ints, doubles and strings only, nothing memory intensive*/
+
+	/*Initialize data: */
+	this->data=new Parameters();
+	
+	/*Initialize permanent data: */
 	this->my_elements=NULL;
+	this->my_nodes=NULL;
 	this->my_vertices=NULL;
-	this->my_nodes=NULL;
 	this->singlenodetoelementconnectivity=NULL;
 	this->numbernodetoelementconnectivity=NULL;
+	
+	this->nodecounter=0;
+	this->loadcounter=0;
+	this->constraintcounter=0;
+
+
+}
+/*}}}*/
+/*FUNCTION IoModel::~IoModel(){{{1*/
+IoModel::~IoModel(){
+
+	delete this->constants;
+	delete this->data;
+
+	xfree((void**)&this->my_elements);
+	xfree((void**)&this->my_nodes);
+	xfree((void**)&this->my_vertices);
+	xfree((void**)&this->singlenodetoelementconnectivity);
+	xfree((void**)&this->numbernodetoelementconnectivity);
 }
 /*}}}*/
@@ -638,4 +477,76 @@
 	*pndims=ndims;
 	*pnumrecords=numrecords;
+}
+/*}}}*/
+/*FUNCTION IoModel::FetchData(int num,...){{{1*/
+void  IoModel::FetchData(int num,...){
+
+
+	va_list ap;
+	int     dataenum;
+	double* matrix=NULL;
+	int     M,N;
+	int     i;
+
+	/*Go through the entire list of enums and fetch the corresponding data. Add it to the iomodel->data dataset. Everything
+	 *we fetch is a double* : */
+	
+	va_start(ap,num);
+
+	for(i = 0; i <num; i++){
+		
+		dataenum=va_arg(ap, int);
+		this->FetchData(&matrix,&M,&N,dataenum);
+
+		/*Add to this->data: */
+		this->data->AddObject(new DoubleMatParam(dataenum,matrix,M,N));
+		
+		/*Free ressources:*/
+		xfree((void**)&matrix);
+	}
+	va_end(ap);
+
+}
+/*}}}*/
+/*FUNCTION IoModel::DeleteData(int num,...){{{1*/
+void  IoModel::DeleteData(int num,...){
+
+
+	va_list ap;
+	int     dataenum;
+	int     i;
+	DoubleMatParam* parameter=NULL;
+
+	/*Go through the entire list of enums and delete the corresponding data from the iomodel-data dataset: */
+	
+	va_start(ap,num);
+
+	for(i = 0; i <num; i++){
+		
+		dataenum=va_arg(ap, int);
+	
+		parameter=(DoubleMatParam*)this->data->FindParamObject(dataenum); 
+		if(parameter){
+			this->data->DeleteObject((Object*)parameter);
+		}
+		else{
+			/*do nothing, we did not find the data, but this is no reason to error out: */
+		}
+	}
+	va_end(ap);
+
+}
+/*}}}*/
+/*FUNCTION IoModel::get(int dataenum){{{1*/
+double* IoModel::f(int dataenum){
+
+	DoubleMatParam* parameter=NULL;
+		
+	parameter=(DoubleMatParam*)this->data->FindParamObject(dataenum);
+
+	if (parameter==NULL)return NULL; //might be legitimate
+	else{
+		return parameter->GetPointer();
+	}
 }
 /*}}}*/
@@ -935,5 +846,5 @@
 
 	/*Fetch parameters: */
-	this->parameters->FindParam(&numberofelements,NumberOfElementsEnum);
+	this->constants->FindParam(&numberofelements,NumberOfElementsEnum);
 
 	/*First of, find the record for the enum, and get code  of data type: */
