Index: issm/trunk/src/m/classes/stressbalance.m
===================================================================
--- issm/trunk/src/m/classes/stressbalance.m	(revision 19105)
+++ issm/trunk/src/m/classes/stressbalance.m	(revision 20500)
@@ -26,48 +26,4 @@
 	end
 	methods
-		function createxml(self,fid) % {{{
-			fprintf(fid, '\n\n');
-			fprintf(fid, '%s\n', '<!-- StressBalance solution parameters: -->');
-
-			% Convergence criteria            
-			fprintf(fid,'%s\n%s\n%s\n','<frame key="1" label="Convergence criteria">','<section name="stressbalance" />'); 
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="restol" type="',      class(self.restol),'" default="',        convert2str(self.restol),'">',	'     <section name="stressbalance" />','     <help> mechanical equilibrium residual convergence criterion </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="reltol" type="',          class(self.reltol),'" default="',            convert2str(self.reltol),'">',     '     <section name="stressbalance" />','     <help> velocity relative convergence criterion, NaN: not applied </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',	'<parameter key ="abstol" type="',        class(self.abstol),'" default="',          convert2str(self.abstol),'">',	'     <section name="stressbalance" />','     <help> velocity absolute convergence criterion, NaN: not applied </help>','</parameter>');
-
-			%is newton drop-down (0,1,or 2)
-			fprintf(fid,'%s\n%s\n%s\n%s\n',    '<parameter key ="isnewton" type="alternative" optional="false">',	'     <section name="stressbalance" />','     <help> 0: Picards fixed point, 1: Newtons method, 2: hybrid </help>');
-			fprintf(fid,'%s\n','       <option value="0" type="string" default="true"> </option>');
-			fprintf(fid,'%s\n','       <option value="1" type="string" default="false"> </option>');
-			fprintf(fid,'%s\n%s\n','       <option value="2" type="string" default="false"> </option>','</parameter>');
-
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="maxiter" type="',  	class(self.maxiter),'" default="',       convert2str(self.maxiter),'">',     '     <section name="stressbalance" />','     <help> maximum number of nonlinear iterations </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="viscosity_overshoot" type="',         class(self.viscosity_overshoot),'" default="',           convert2str(self.viscosity_overshoot),'">',	'     <section name="stressbalance" />','     <help> over-shooting constant new=new+C*(new-old) </help>','</parameter>');
-			fprintf(fid,'%s\n%s\n','</frame>');
-
-			% boundary conditions    
-			fprintf(fid,'%s\n%s\n%s\n','<frame key="2" label="Boundary conditions">','<section name="stressbalance" />'); 			 
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="spcvx" type="',     	class(self.spcvx),'" default="',    	convert2str(self.spcvx),'">',     '     <section name="stressbalance" />','     <help> x-axis velocity constraint (NaN means no constraint) [m/yr] </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="spcvy" type="',     	class(self.spcvy),'" default="',    	convert2str(self.spcvy),'">',	'     <section name="stressbalance" />','     <help> y-axis velocity constraint (NaN means no constraint) [m/yr] </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="spcvz" type="',    	class(self.spcvz),'" default="',    	convert2str(self.spcvz),'">',     '     <section name="stressbalance" />','     <help> z-axis velocity constraint (NaN means no constraint) [m/yr] </help>','</parameter>');
-			fprintf(fid,'%s\n%s\n','</frame>');
-
-			% Rift options   
-			fprintf(fid,'%s\n%s\n%s\n','<frame key="3" label="Rift options">','<section name="stressbalance" />'); 	
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="rift_penalty_threshold" type="',    	class(self.rift_penalty_threshold),'" default="',       convert2str(self.rift_penalty_threshold),'">',     '     <section name="stressbalance" />','     <help> threshold for instability of mechanical constraints </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    	'<parameter key ="rift_penalty_lock" type="',         class(self.rift_penalty_lock),'" default="',           convert2str(self.rift_penalty_lock),'">',	'     <section name="stressbalance" />','     <help> number of iterations before rift penalties are locked </help>','</parameter>');
-			fprintf(fid,'%s\n%s\n','</frame>'); 
-
-			%others
-			fprintf(fid,'%s\n%s\n%s\n','<frame key="4" label="Other">','<section name="stressbalance" />'); 	
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="shelf_dampening" type="',  	class(self.shelf_dampening),'" default="',       convert2str(self.shelf_dampening),'">',     '     <section name="stressbalance" />','     <help> use dampening for floating ice ? Only for FS model </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',  	'<parameter key ="FSreconditioning" type="', 	class(self.FSreconditioning),'" default="',           convert2str(self.FSreconditioning),'">',	'     <section name="stressbalance" />','     <help> multiplier for incompressibility equation. Only for FS model </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="referential" type="',  	class(self.referential),'" default="',       convert2str(self.referential),'">',     '     <section name="stressbalance" />','     <help> local referential </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',  	'<parameter key ="loadingforce" type="', 	class(self.loadingforce),'" default="',           convert2str(self.loadingforce),'">',	'     <section name="stressbalance" />','     <help> loading force applied on each point [N/m^3] </help>','</parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n',    '<parameter key ="requested_outputs" type="',  	class(self.requested_outputs),'" default="',       convert2str(self.requested_outputs),'">',     '     <section name="stressbalance" />','     <help> additional outputs requested </help>','</parameter>');
-
-
-			fprintf(fid,'%s\n%s\n','</frame>'); 
-		end % }}}
 		function self = extrude(self,md) % {{{
 			self.spcvx=project3d(md,'vector',self.spcvx,'type','node');
@@ -133,14 +89,15 @@
 			%Early return
 			if ~ismember(StressbalanceAnalysisEnum(),analyses), return; end
-
-			md = checkfield(md,'fieldname','stressbalance.spcvx','timeseries',1);
-			md = checkfield(md,'fieldname','stressbalance.spcvy','timeseries',1);
-			md = checkfield(md,'fieldname','stressbalance.spcvz','timeseries',1);
-			md = checkfield(md,'fieldname','stressbalance.restol','size',[1 1],'>',0,'NaN',1);
+			if (solution==TransientSolutionEnum & md.transient.isstressbalance == 0), return; end
+
+			md = checkfield(md,'fieldname','stressbalance.spcvx','Inf',1,'timeseries',1);
+			md = checkfield(md,'fieldname','stressbalance.spcvy','Inf',1,'timeseries',1);
+			md = checkfield(md,'fieldname','stressbalance.spcvz','Inf',1,'timeseries',1);
+			md = checkfield(md,'fieldname','stressbalance.restol','size',[1 1],'>',0,'NaN',1,'Inf',1);
 			md = checkfield(md,'fieldname','stressbalance.reltol','size',[1 1]);
 			md = checkfield(md,'fieldname','stressbalance.abstol','size',[1 1]);
 			md = checkfield(md,'fieldname','stressbalance.isnewton','numel',[1],'values',[0 1 2]);
-			md = checkfield(md,'fieldname','stressbalance.FSreconditioning','size',[1 1],'NaN',1);
-			md = checkfield(md,'fieldname','stressbalance.viscosity_overshoot','size',[1 1],'NaN',1);
+			md = checkfield(md,'fieldname','stressbalance.FSreconditioning','size',[1 1],'NaN',1,'Inf',1);
+			md = checkfield(md,'fieldname','stressbalance.viscosity_overshoot','size',[1 1],'NaN',1,'Inf',1);
 			md = checkfield(md,'fieldname','stressbalance.maxiter','size',[1 1],'>=',1);
 			md = checkfield(md,'fieldname','stressbalance.referential','size',[md.mesh.numberofvertices 6]);
@@ -150,5 +107,5 @@
 			%singular solution
 			if ((~(any(~isnan(md.stressbalance.spcvx)) | any(~isnan(md.stressbalance.spcvy)))) & ~any(md.mask.groundedice_levelset>0)),
-				md = checkmessage(md,['model is not well posed (singular). You need at least one node with fixed velocity!']);
+				disp(sprintf('\n !!! Warning: no spc applied, model might not be well posed if no basal friction is applied, check for solution crash\n'));
 			end
 			%CHECK THAT EACH LINES CONTAINS ONLY NAN VALUES OR NO NAN VALUES
@@ -238,7 +195,9 @@
 			WriteData(fid,'object',self,'class','stressbalance','fieldname','referential','format','DoubleMat','mattype',1);
 
-			WriteData(fid,'data',self.loadingforce(:,1),'format','DoubleMat','mattype',1,'enum',LoadingforceXEnum);
-			WriteData(fid,'data',self.loadingforce(:,2),'format','DoubleMat','mattype',1,'enum',LoadingforceYEnum);
-			WriteData(fid,'data',self.loadingforce(:,3),'format','DoubleMat','mattype',1,'enum',LoadingforceZEnum);
+			if size(self.loadingforce,2)==3,
+				WriteData(fid,'data',self.loadingforce(:,1),'format','DoubleMat','mattype',1,'enum',LoadingforceXEnum);
+				WriteData(fid,'data',self.loadingforce(:,2),'format','DoubleMat','mattype',1,'enum',LoadingforceYEnum);
+				WriteData(fid,'data',self.loadingforce(:,3),'format','DoubleMat','mattype',1,'enum',LoadingforceZEnum);
+			end
 
 			%process requested outputs
@@ -251,4 +210,26 @@
 			WriteData(fid,'data',outputs,'enum',StressbalanceRequestedOutputsEnum,'format','StringArray');
 		end % }}}
+		function savemodeljs(self,fid,modelname) % {{{
+		
+			writejs1Darray(fid,[modelname '.stressbalance.spcvx'],self.spcvx);
+			writejs1Darray(fid,[modelname '.stressbalance.spcvy'],self.spcvy);
+			writejs1Darray(fid,[modelname '.stressbalance.spcvz'],self.spcvz);
+			writejsdouble(fid,[modelname '.stressbalance.restol'],self.restol);
+			writejsdouble(fid,[modelname '.stressbalance.reltol'],self.reltol);
+			writejsdouble(fid,[modelname '.stressbalance.abstol'],self.abstol);
+			writejsdouble(fid,[modelname '.stressbalance.isnewton'],self.isnewton);
+			writejsdouble(fid,[modelname '.stressbalance.FSreconditioning'],self.FSreconditioning);
+			writejsdouble(fid,[modelname '.stressbalance.viscosity_overshoot'],self.viscosity_overshoot);
+			writejsdouble(fid,[modelname '.stressbalance.maxiter'],self.maxiter);
+			writejsdouble(fid,[modelname '.stressbalance.shelf_dampening'],self.shelf_dampening);
+			writejs1Darray(fid,[modelname '.stressbalance.vertex_pairing'],self.vertex_pairing);
+			writejsdouble(fid,[modelname '.stressbalance.penalty_factor'],self.penalty_factor);
+			writejsdouble(fid,[modelname '.stressbalance.rift_penalty_lock'],self.rift_penalty_lock);
+			writejsdouble(fid,[modelname '.stressbalance.rift_penalty_threshold'],self.rift_penalty_threshold);
+			writejs2Darray(fid,[modelname '.stressbalance.referential'],self.referential);
+			writejs2Darray(fid,[modelname '.stressbalance.loadingforce'],self.loadingforce);
+			writejscellstring(fid,[modelname '.stressbalance.requested_outputs'],self.requested_outputs);
+
+		end % }}}
 	end
 end
