Index: /issm/trunk/src/c/objects/IoModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/IoModel.cpp	(revision 3682)
+++ /issm/trunk/src/c/objects/IoModel.cpp	(revision 3682)
@@ -0,0 +1,403 @@
+/*! \file IoModel.cpp
+ * \brief  file containing the methods that will help in processing the input data coming 
+ * into ISSM, from Matlab, or through a binary file opened for reading.
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../shared/shared.h"
+#include "../io/io.h"
+#include "../include/globals.h"
+#include "../include/macros.h"
+#include <string.h>
+#include "stdio.h"
+#include "./objects.h"
+
+/*FUNCTION IoModel::IoModel(){{{1*/
+IoModel::IoModel(){
+	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->elements_type);
+	xfree((void**)&this->gridonhutter);
+	xfree((void**)&this->gridonmacayeal);
+	if (strcmp(this->meshtype,"3d")==0){
+		xfree((void**)&this->elements2d);
+		xfree((void**)&this->deadgrids);
+		xfree((void**)&this->uppernodes);
+		xfree((void**)&this->gridonpattyn);
+	}
+	xfree((void**)&this->solverstring);
+	xfree((void**)&this->elementonbed);
+	xfree((void**)&this->elementonsurface);
+	xfree((void**)&this->gridonbed);
+	xfree((void**)&this->gridonsurface);
+	xfree((void**)&this->gridonstokes);
+	xfree((void**)&this->borderstokes);
+	xfree((void**)&this->thickness);
+	xfree((void**)&this->surface);
+	xfree((void**)&this->bed);
+	xfree((void**)&this->vx_obs);
+	xfree((void**)&this->vy_obs);
+	xfree((void**)&this->vx);
+	xfree((void**)&this->vy);
+	xfree((void**)&this->vz);
+	xfree((void**)&this->pressure);
+	xfree((void**)&this->temperature);
+	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->gridonicesheet);
+	xfree((void**)&this->gridoniceshelf);
+	xfree((void**)&this->pressureload);
+	xfree((void**)&this->spcvelocity);
+	xfree((void**)&this->spcthickness);
+	xfree((void**)&this->spctemperature);
+	xfree((void**)&this->edges);
+	xfree((void**)&this->geothermalflux);
+	xfree((void**)&this->melting_rate);
+	xfree((void**)&this->accumulation_rate);
+	xfree((void**)&this->dhdt);
+	xfree((void**)&this->rheology_B);
+	xfree((void**)&this->rheology_n);
+	xfree((void**)&this->fit);
+	xfree((void**)&this->weights);
+	xfree((void**)&this->cm_jump);
+	xfree((void**)&this->optscal);
+	xfree((void**)&this->maxiter);
+
+
+	/*!Delete structure fields: */
+	xfree((void**)&this->inputfilename);
+	xfree((void**)&this->outputfilename);
+	xfree((void**)&this->repository);
+	xfree((void**)&this->meshtype);
+	xfree((void**)&this->name);
+	
+	xfree((void**)&this->riftinfo);
+	
+	xfree((void**)&this->penalties);
+	xfree((void**)&this->penaltypartitioning);
+	
+	xfree((void**)&this->control_type);
+	
+	/*exterior data: */
+	xfree((void**)&this->my_elements);
+	xfree((void**)&this->my_vertices);
+	xfree((void**)&this->my_nodes);
+	xfree((void**)&this->my_bordervertices);
+	xfree((void**)&this->penaltypartitioning);
+	#endif
+}
+/*}}}*/
+/*FUNCTION IoModel::IoModel(ConstDataHandle iomodel_handle){{{1*/
+IoModel::IoModel(ConstDataHandle iomodel_handle){
+	
+	int i,j;
+		
+	/*First, initialize the structure: */
+	this->IoModelInit();
+	
+	/*Get all the data that consists of scalars, integers and strings: */
+
+	IoModelFetchData(&this->name,iomodel_handle,"name"); 
+	IoModelFetchData(&this->inputfilename,iomodel_handle,"inputfilename"); 
+	IoModelFetchData(&this->outputfilename,iomodel_handle,"outputfilename"); 
+	IoModelFetchData(&this->analysis_type,iomodel_handle,"analysis_type"); 
+	IoModelFetchData(&this->sub_analysis_type,iomodel_handle,"sub_analysis_type"); 
+	IoModelFetchData(&this->qmu_analysis,iomodel_handle,"qmu_analysis"); 
+	IoModelFetchData(&this->control_analysis,iomodel_handle,"control_analysis"); 
+	IoModelFetchData(&this->meshtype,iomodel_handle,"type");
+	/*!Get numberofelements and numberofvertices: */
+	IoModelFetchData(&this->numberofvertices,iomodel_handle,"numberofgrids");
+	IoModelFetchData(&this->numberofelements,iomodel_handle,"numberofelements");
+	/*!In case we are running 3d, we are going to need the collapsed and non-collapsed 2d meshes, from which the 3d mesh was extruded: */
+	if (strcmp(this->meshtype,"3d")==0){
+	
+		/*!Deal with 2d mesh: */
+		IoModelFetchData(&this->numberofelements2d,iomodel_handle,"numberofelements2d");
+		IoModelFetchData(&this->numberofvertices2d,iomodel_handle,"numberofgrids2d");
+		IoModelFetchData(&this->numlayers,iomodel_handle,"numlayers");
+	}
+
+
+	/*elements type: */
+	IoModelFetchData(&this->ishutter,iomodel_handle,"ishutter");
+	IoModelFetchData(&this->ismacayealpattyn,iomodel_handle,"ismacayealpattyn");
+	IoModelFetchData(&this->isstokes,iomodel_handle,"isstokes");
+
+	/*!Get drag_type, drag and p,q: */
+	IoModelFetchData(&this->drag_type,iomodel_handle,"drag_type");
+
+	/*!Get materials: */
+	IoModelFetchData(&this->rho_water,iomodel_handle,"rho_water");
+	IoModelFetchData(&this->rho_ice,iomodel_handle,"rho_ice");
+	IoModelFetchData(&this->g,iomodel_handle,"g");
+
+	/*Get control parameters: */
+	IoModelFetchData(&this->control_type,iomodel_handle,"control_type"); 
+
+	/*!Get solution parameters: */
+	IoModelFetchData(&this->yts,iomodel_handle,"yts");
+	IoModelFetchData(&this->meanvel,iomodel_handle,"meanvel");
+	IoModelFetchData(&this->epsvel,iomodel_handle,"epsvel");
+	IoModelFetchData(&this->verbose,iomodel_handle,"verbose");
+	IoModelFetchData(&this->plot,iomodel_handle,"plot");
+	IoModelFetchData(&this->artificial_diffusivity,iomodel_handle,"artificial_diffusivity");
+	IoModelFetchData(&this->nsteps,iomodel_handle,"nsteps");
+	IoModelFetchData(&this->eps_cm,iomodel_handle,"eps_cm");
+	IoModelFetchData(&this->tolx,iomodel_handle,"tolx");
+	IoModelFetchData(&this->cm_noisedmp,iomodel_handle,"cm_noisedmp");
+	IoModelFetchData(&this->cm_mindmp_value,iomodel_handle,"cm_mindmp_value");
+	IoModelFetchData(&this->cm_mindmp_slope,iomodel_handle,"cm_mindmp_slope");
+	IoModelFetchData(&this->cm_maxdmp_value,iomodel_handle,"cm_maxdmp_value");
+	IoModelFetchData(&this->cm_maxdmp_slope,iomodel_handle,"cm_maxdmp_slope");
+	IoModelFetchData(&this->cm_min,iomodel_handle,"cm_min");
+	IoModelFetchData(&this->cm_max,iomodel_handle,"cm_max");
+	IoModelFetchData(&this->cm_gradient,iomodel_handle,"cm_gradient");
+	IoModelFetchData(&this->eps_res,iomodel_handle,"eps_res");
+	IoModelFetchData(&this->eps_rel,iomodel_handle,"eps_rel");
+	IoModelFetchData(&this->eps_abs,iomodel_handle,"eps_abs");
+	IoModelFetchData(&this->max_nonlinear_iterations,iomodel_handle,"max_nonlinear_iterations");
+	IoModelFetchData(&this->dt,iomodel_handle,"dt");
+	IoModelFetchData(&this->ndt,iomodel_handle,"ndt");
+	IoModelFetchData(&this->penalty_offset,iomodel_handle,"penalty_offset");
+	IoModelFetchData(&this->penalty_melting,iomodel_handle,"penalty_melting");
+	IoModelFetchData(&this->penalty_lock,iomodel_handle,"penalty_lock");
+	IoModelFetchData(&this->sparsity,iomodel_handle,"sparsity");
+	IoModelFetchData(&this->connectivity,iomodel_handle,"connectivity");
+	IoModelFetchData(&this->lowmem,iomodel_handle,"lowmem");
+	IoModelFetchData(&this->solverstring,iomodel_handle,"solverstring");
+	IoModelFetchData(&this->viscosity_overshoot,iomodel_handle,"viscosity_overshoot");
+	IoModelFetchData(&this->artdiff,iomodel_handle,"artificial_diffusivity");
+	IoModelFetchData(&this->stokesreconditioning,iomodel_handle,"stokesreconditioning");
+	IoModelFetchData(&this->waitonlock,iomodel_handle,"waitonlock");
+
+	/*!Get thermal parameters: */
+	IoModelFetchData(&this->beta,iomodel_handle,"beta");
+	IoModelFetchData(&this->meltingpoint,iomodel_handle,"meltingpoint");
+	IoModelFetchData(&this->latentheat,iomodel_handle,"latentheat");
+	IoModelFetchData(&this->heatcapacity,iomodel_handle,"heatcapacity");
+	IoModelFetchData(&this->thermalconductivity,iomodel_handle,"thermalconductivity");
+	IoModelFetchData(&this->min_thermal_constraints,iomodel_handle,"min_thermal_constraints");
+	IoModelFetchData(&this->min_mechanical_constraints,iomodel_handle,"min_mechanical_constraints");
+	IoModelFetchData(&this->stabilize_constraints,iomodel_handle,"stabilize_constraints");
+	IoModelFetchData(&this->mixed_layer_capacity,iomodel_handle,"mixed_layer_capacity");
+	IoModelFetchData(&this->thermal_exchange_velocity,iomodel_handle,"thermal_exchange_velocity");
+	
+	/*qmu: */
+	if(this->qmu_analysis){
+		IoModelFetchData(&this->numberofvariables,iomodel_handle,"numberofvariables");
+		IoModelFetchData(&this->numberofresponses,iomodel_handle,"numberofresponses");
+		IoModelFetchData(&this->qmu_npart,iomodel_handle,"npart");
+	}
+	
+	/*parameter output : */
+	IoModelFetchData(&this->numoutput,iomodel_handle,"numoutput");
+}
+/*}}}*/
+/*FUNCTION IoModel::IoModelInit(void){{{1*/
+void IoModel::IoModelInit(void){
+	
+	/*!initialize all pointers to 0: */
+	this->name=NULL;
+	this->inputfilename=NULL;
+	this->outputfilename=NULL;
+	this->repository=NULL;
+	this->meshtype=NULL;
+	this->analysis_type=0;
+	this->sub_analysis_type=0;
+	this->qmu_analysis=0;
+	this->control_analysis=0;
+	this->solverstring=NULL;
+	this->numberofresponses=0;
+	this->numberofvariables=0;
+	this->qmu_npart=0; 
+	this->numberofelements=0;
+	this->numberofvertices=0;
+	this->x=NULL; 
+	this->y=NULL;
+	this->z=NULL;
+	this->elements=NULL;
+	this->elements_type=NULL;
+	this->numberofvertices2d=0;
+	this->elements2d=NULL;
+	this->deadgrids=NULL;
+	this->numlayers=0;
+	this->uppernodes=NULL;
+	this->gridonhutter=NULL;
+	this->gridonmacayeal=NULL;
+	this->gridonpattyn=NULL;
+	
+	this->vx_obs=NULL;
+	this->vy_obs=NULL;
+	this->vx=NULL;
+	this->vy=NULL;
+	this->vz=NULL;
+	this->pressure=NULL;
+	this->temperature=NULL;
+	this->melting_rate=NULL;
+	this->geothermalflux=NULL;
+	this->elementonbed=NULL;
+	this->elementonsurface=NULL;
+	this->gridonbed=NULL;
+	this->gridonsurface=NULL;
+	this->gridonstokes=NULL;
+	this->borderstokes=NULL;
+	this->thickness=NULL;
+	this->surface=NULL;
+	this->bed=NULL;
+	this->elementoniceshelf=NULL;
+	this->elementonwater=NULL;
+	this->gridonicesheet=NULL;
+	this->gridoniceshelf=NULL;
+
+	this->drag_type=0;
+	this->drag_coefficient=NULL;
+	this->drag_p=NULL;
+	this->drag_q=NULL;
+	
+	
+	this->numberofpressureloads=0;
+	this->pressureload=NULL;
+	this-> spcvelocity=NULL;
+	this-> spctemperature=NULL;
+	this-> spcthickness=NULL;
+	this->numberofedges=0;
+	this->edges=NULL;
+	
+	/*!materials: */
+	this->rho_water=0;
+	this->rho_ice=0;
+	this->g=0;
+	this->rheology_n=NULL;
+	this->rheology_B=NULL;
+
+	/*!control methods: */
+	this->control_type=NULL;
+
+	/*!solution parameters: */
+	this->fit=NULL;
+	this->weights=NULL;
+	this->cm_jump=NULL;
+	this->meanvel=0;
+	this->epsvel=0;
+	this->artificial_diffusivity=0;
+	this->nsteps=0;
+	this->eps_cm=0;
+	this->tolx=0;
+	this->maxiter=NULL;
+	this->cm_noisedmp=0;
+	this->cm_mindmp_value=0;
+	this->cm_mindmp_slope=0;
+	this->cm_maxdmp_value=0;
+	this->cm_maxdmp_slope=0;
+	this->cm_min=0;
+	this->cm_max=0;
+	this->cm_gradient=0;
+	this->verbose=0;
+	this->plot=0;
+	this->eps_res=0;
+	this->eps_rel=0;
+	this->eps_abs=0;
+	this->max_nonlinear_iterations=0;
+	this->dt=0;
+	this->ndt=0;
+	this->penalty_offset=0;
+	this->penalty_melting=0;
+	this->penalty_lock=0;
+	this->sparsity=0;
+	this->connectivity=0;
+	this->lowmem=0;
+	this->optscal=NULL;
+	this->yts=0;
+	this->viscosity_overshoot=0;
+	this->artdiff=0;
+	this->stokesreconditioning=0;
+	this->waitonlock=0;
+
+	/*!thermal parameters: */
+	this->beta=0;
+	this->meltingpoint=0;
+	this->latentheat=0;
+	this->heatcapacity=0;
+	this->thermalconductivity=0;
+	this->min_thermal_constraints=0;
+	this->min_mechanical_constraints=0;
+	this->stabilize_constraints=0;
+	this->mixed_layer_capacity=0;
+	this->thermal_exchange_velocity=0;
+
+	
+	this->numrifts=0;
+	this->riftinfo=NULL;
+
+	/*!penalties: */
+	this->numpenalties=0;
+	this->penalties=NULL;
+	this->penaltypartitioning=NULL;
+
+	/*!basal: */
+	this->accumulation_rate=NULL;
+	this->dhdt=NULL;
+	
+	/*parameter output: */
+	this->numoutput=0;
+
+	/*elements type: */
+	this->ishutter=0;
+	this->ismacayealpattyn=0;
+	this->isstokes=0;
+
+	/*exterior data: */
+	this->my_elements=NULL;
+	this->my_vertices=NULL;
+	this->my_nodes=NULL;
+	this->my_bordervertices=NULL;
+	this->penaltypartitioning=NULL;
+}
+/*}}}*/
+/*FUNCTION IoModel::Echo(int which_part,int rank){{{1*/
+void IoModel::Echo(int which_part,int rank) {
+
+	//which_part  determines what gets echoed, otherwise, we'll get too much output.
+	//1-> penalties
+
+	int i,j;
+
+	if(which_part==1 && my_rank==rank && (strcmp(this->meshtype,"3d")==0)){
+		printf("IoModel penalties: \n");
+		printf("   number of penalties: %i\n",this->numpenalties);
+		printf("   grids: \n");
+
+		for(i=0;i<this->numpenalties;i++){
+			for(j=0;j<this->numlayers;j++){
+				printf("%i ",(int)*(this->penalties+this->numlayers*i+j));
+			}
+			printf("\n");
+		}
+	}
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/IoModel.h
===================================================================
--- /issm/trunk/src/c/objects/IoModel.h	(revision 3682)
+++ /issm/trunk/src/c/objects/IoModel.h	(revision 3682)
@@ -0,0 +1,197 @@
+/* \file IoModel.h
+ * \brief  Header file defining the IoModel structure that will help in processing the input data coming 
+ * into ISSM, from Matlab, or through a binary file opened for reading.
+ * \sa IoModel.cpp
+ */
+
+#ifndef _IOMODEL_H
+#define _IOMODEL_H
+
+#include "../include/types.h"
+
+class IoModel {
+
+	public:
+
+		/*Data: {{{1*/
+		char*   name;
+		char*	  inputfilename;
+		char*	  outputfilename;
+		char*   repository;
+		char*   meshtype;
+		int     analysis_type;
+		int     sub_analysis_type;
+		int     qmu_analysis;
+		int     control_analysis;
+		char*   solverstring;
+
+		/*2d mesh: */
+		int     numberofelements;
+		int     numberofvertices;
+		double* x;
+		double* y;
+		double* z;
+		double* elements;
+		double* elements_type;
+
+		/*3d mesh: */
+		int     numberofvertices2d;
+		int     numberofelements2d;
+		double* elements2d;
+		double* deadgrids;
+		int     numlayers;
+		double* uppernodes;
+
+		/*elements type: */
+		int     ishutter;
+		int     ismacayealpattyn;
+		int     isstokes;
+		double* gridonhutter;
+		double* gridonmacayeal;
+		double* gridonpattyn;
+
+		/*results: */
+		double* vx;
+		double* vy;
+		double* vz;
+		double* pressure;
+		double* temperature;
+
+		/*observations: */
+		double*  vx_obs;
+		double*  vy_obs;
+
+		/*qmu: */
+		int      numberofresponses;
+		int      numberofvariables;
+		int      qmu_npart;
+
+		/*geometry: */
+		double* elementonbed;
+		double* elementonsurface;
+		double* gridonbed;
+		double* gridonsurface;
+		double* gridonstokes;
+		double* borderstokes;
+		double* thickness;
+		double* surface;
+		double* bed;
+		double* elementoniceshelf;
+		double* elementonwater;
+		double* gridonicesheet;
+		double* gridoniceshelf;
+
+		/*friction: */
+		int     drag_type;
+		double* drag_coefficient;
+		double* drag_p;
+		double* drag_q;
+
+		/*boundary conditions: */
+		int     numberofpressureloads;
+		double* pressureload;
+		double* spcvelocity;
+		double* spctemperature;
+		double* spcthickness;
+		double* geothermalflux;
+		int     numberofedges;
+		double* edges;
+
+		/*materials: */
+		double  rho_water,rho_ice;
+		double  g;
+		double* rheology_B;
+		double* rheology_n;
+
+		/*numerical parameters: */
+		double  meanvel;
+		double  epsvel;
+		int     artdiff;
+		double  viscosity_overshoot;
+		double  stokesreconditioning;
+		double  cm_noisedmp;
+		double  cm_mindmp_value;
+		double  cm_mindmp_slope;
+		double  cm_maxdmp_value;
+		double  cm_maxdmp_slope;
+		double  cm_min;
+		double  cm_max;
+		int     cm_gradient;;
+
+		double  cm_noisedampening;
+
+		/*control methods: */
+		char*	control_type;
+
+		/*solution parameters: */
+		double* fit;
+		double* weights;
+		double* cm_jump;
+		int     artificial_diffusivity;
+		int     nsteps;
+		double  eps_cm;
+		double  tolx;
+		double* maxiter;
+		int     verbose;
+		int     plot;
+		double  eps_res;
+		double  eps_rel;
+		double  eps_abs;
+		double  max_nonlinear_iterations;
+		double  dt,ndt;
+		double  penalty_offset;
+		double  penalty_melting;
+		int     penalty_lock;
+		double  sparsity;
+		int     connectivity;
+		int     lowmem;
+		double* optscal;
+		double  yts;
+		double  waitonlock;
+
+		/*thermal parameters: */
+		double beta;
+		double meltingpoint;
+		double latentheat;
+		double  heatcapacity,thermalconductivity;
+		int    min_thermal_constraints;
+		int    min_mechanical_constraints;
+		int    stabilize_constraints;
+		double mixed_layer_capacity;
+		double thermal_exchange_velocity;
+
+		/*rifts: */
+		int      numrifts;
+		double*  riftinfo;
+
+		/*penalties: */
+		int      numpenalties;
+		double*  penalties;
+
+		/*basal: */
+		double*  melting_rate;
+		double*  accumulation_rate;
+		double*  dhdt;
+
+		/*parameter output: */
+		int      numoutput;
+
+		/*exterior partitioning data, to be carried around: */
+		bool*   my_elements;
+		bool*   my_vertices;
+		bool*   my_nodes;
+		bool*   my_bordervertices;
+		int*    penaltypartitioning;
+		int*    singlenodetoelementconnectivity;
+		/*}}}*/
+		/*Methods: {{{1*/
+		~IoModel();
+		IoModel();
+		IoModel(ConstDataHandle iomodel_handle);
+		void IoModelInit(void);
+		void Echo(int which_part,int rank);
+		/*}}}*/
+
+};
+
+#endif  /* _IOMODEL_H */
