Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 20935)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 20936)
@@ -294,56 +294,19 @@
 
 	/*intermediary*/
-	int         i;
-	int         analysis_type;
-	FILE       *IOMODEL = NULL;
-	FILE       *toolkitsoptionsfid = NULL;
-	FILE       *output_fid = NULL;
-	int         my_rank;
+	FILE *IOMODEL            = NULL;
+	FILE *toolkitsoptionsfid = NULL;
+	FILE *output_fid         = NULL;
 
 	/*recover my_rank:*/
-	my_rank=IssmComm::GetRank();
-
-	/*Initialize internal data: */
-	this->solution_type    = in_solution_type;
-	this->analysis_counter = nummodels-1;   //point to last analysis_type carried out.
-	this->results          = new Results(); //not initialized by CreateDataSets
-	/*Open input file on cpu 0 and create IoModel */
+	int my_rank=IssmComm::GetRank();
+
+	/*Open input file descriptor on cpu 0: */
 	if(my_rank==0) IOMODEL = pfopen0(inputfilename ,"rb");
-	IoModel* iomodel = new IoModel(IOMODEL,in_solution_type,trace,X);
-
-	/*Figure out what analyses are activated for this solution*/
-	SolutionAnalysesList(&this->analysis_type_list,&this->nummodels,iomodel,this->solution_type);
 
 	/*Open toolkits file: */
 	toolkitsoptionsfid=pfopen(toolkitsfilename,"r");
 
-	/*create datasets for all analyses*/
-	ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,iomodel,toolkitsoptionsfid,rootpath,this->solution_type,this->nummodels,this->analysis_type_list);
-
-
-	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
-	for(i=0;i<nummodels;i++){
-
-		if(VerboseMProcessor()) _printf0_("   Processing finite element model of analysis " << EnumToStringx(analysis_type_list[i]) << ":\n");
-		analysis_type=analysis_type_list[i];
-		this->SetCurrentConfiguration(analysis_type);
-
-		if(VerboseMProcessor()) _printf0_("      configuring element and loads\n");
-		ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
-
-		if(i==0){
-			if(VerboseMProcessor()) _printf0_("      creating vertex PIDs\n");
-			VerticesDofx(vertices,parameters); 
-
-			if(VerboseMProcessor()) _printf0_("      detecting active vertices\n");
-			GetMaskOfIceVerticesLSMx(this);
-		}
-
-		if(VerboseMProcessor()) _printf0_("      resolving node constraints\n");
-		SpcNodesx(nodes,constraints,parameters,analysis_type); 
-
-		if(VerboseMProcessor()) _printf0_("      creating nodal degrees of freedom\n");
-		NodesDofx(nodes,parameters,analysis_type);
-	}
+	/*Now, go create FemModel:*/
+	this->InitFromFids(rootpath,IOMODEL,toolkitsoptionsfid,in_solution_type,trace,X);
 
 	/*Close input file and toolkits file descriptors: */
@@ -363,14 +326,7 @@
 	this->parameters->AddObject(new StringParam(RestartFileNameEnum,restartfilename));
 
-	/*Clean up*/
-	delete iomodel;
 }/*}}}*/
 void FemModel::InitFromFids(char* rootpath, FILE* IOMODEL, FILE* toolkitsoptionsfid, int in_solution_type, bool trace, IssmPDouble* X){/*{{{*/
 	
-	/*intermediary*/
-	int         i;
-	int         analysis_type;
-	
-
 	/*Initialize internal data: */
 	this->solution_type    = in_solution_type;
@@ -388,9 +344,11 @@
 
 	/*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
-	for(i=0;i<nummodels;i++){
+	for(int i=0;i<nummodels;i++){
 
 		if(VerboseMProcessor()) _printf0_("   Processing finite element model of analysis " << EnumToStringx(analysis_type_list[i]) << ":\n");
-		analysis_type=analysis_type_list[i];
-		this->SetCurrentConfiguration(analysis_type);
+		this->SetCurrentConfiguration(analysis_type_list[i]);
+
+		if(VerboseMProcessor()) _printf0_("      configuring element and loads\n");
+		ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
 		
 		if(i==0){
@@ -403,16 +361,12 @@
 
 		if(VerboseMProcessor()) _printf0_("      resolving node constraints\n");
-		SpcNodesx(nodes,constraints,parameters,analysis_type); 
+		SpcNodesx(nodes,constraints,parameters,analysis_type_list[i]); 
 
 		if(VerboseMProcessor()) _printf0_("      creating nodal degrees of freedom\n");
-		NodesDofx(nodes,parameters,analysis_type);
-
-		if(VerboseMProcessor()) _printf0_("      configuring element and loads\n");
-		ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
+		NodesDofx(nodes,parameters,analysis_type_list[i]);
 	}
 
 	/*Clean up*/
 	delete iomodel;
-
 }/*}}}*/
 void FemModel::Marshall(char** pmarshalled_data, int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
