Index: issm/trunk/src/m/classes/thermal.m
===================================================================
--- issm/trunk/src/m/classes/thermal.m	(revision 19105)
+++ issm/trunk/src/m/classes/thermal.m	(revision 20500)
@@ -18,28 +18,4 @@
 	end
 	methods
-		function createxml(self,fid) % {{{
-			fprintf(fid, '<!-- thermal -->\n');            
-
-			% thermal solution parameters
-			fprintf(fid,'%s\n%s\n%s\n','<frame key="1" label="Thermal solution parameters">','<section name="thermal" />');                    
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n','  <parameter key ="spctemperature" type="',class(self.spctemperature),'" default="',convert2str(self.spctemperature),'">','     <section name="thermal" />','     <help> temperature constraints (NaN means no constraint) [K] </help>','  </parameter>');
-
-			% penalty_threshold drop-down (0, 1, or 2)
-			fprintf(fid,'%s\n%s\n%s\n%s\n','  <parameter key ="penalty_threshold" type="alternative"  optional="false">','     <section name="thermal" />','     <help> 0: no, 1: artificial_diffusivity, 2: SUPG </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 ="stabilization" type="',class(self.stabilization),'" default="',convert2str(self.stabilization),'">','     <section name="thermal" />','     <help> maximum number of non linear iterations </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="steadystate" />','     <help> relative tolerance criterion [K] </help>','  </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="thermal" />','     <help> stabilize unstable thermal constraints that keep zigzagging after n iteration (default is 0, no stabilization) </help>','  </parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n','  <parameter key ="penalty_lock" type="',class(self.penalty_lock),'" default="',convert2str(self.penalty_lock),'">','     <section name="thermal" />','     <help> threshold to declare convergence of thermal solution (default is 0)  </help>','  </parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n','  <parameter key ="penalty_factor" type="',class(self.penalty_factor),'" default="',convert2str(self.penalty_factor),'">','     <section name="thermal" />','     <help> scaling exponent (default is 3) </help>','  </parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n','  <parameter key ="isenthalpy" type="',class(self.isenthalpy),'" default="',convert2str(self.isenthalpy),'">','     <section name="thermal" />','     <help> use an enthalpy formulation to include temperate ice (default is 0) </help>','  </parameter>');
-			fprintf(fid,'%s%s%s%s%s\n%s\n%s\n%s\n','  <parameter key ="isdynamicbasalspc" type="',class(self.isdynamicbasalspc),'" default="',convert2str(self.isdynamicbasalspc),'">','     <section name="thermal" />','     <help> enable dynamic setting of basal forcing. recommended for enthalpy formulation (default is 0)  </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="thermal" />','     <help> additional outputs requested </help>','  </parameter>');
-			fprintf(fid,'%s\n%s\n','</frame>');    
-
-		end % }}}
 		function self = extrude(self,md) % {{{
 			self.spctemperature=project3d(md,'vector',self.spctemperature,'type','node','layer',md.mesh.numberoflayers,'padding',NaN);
@@ -99,9 +75,15 @@
 
 			md = checkfield(md,'fieldname','thermal.stabilization','numel',[1],'values',[0 1 2]);
-			md = checkfield(md,'fieldname','thermal.spctemperature','timeseries',1);
+			md = checkfield(md,'fieldname','thermal.spctemperature','Inf',1,'timeseries',1,'>=',0);
 			if (ismember(EnthalpyAnalysisEnum(),analyses) & md.thermal.isenthalpy & dimension(md.mesh)==3),
-				pos=find(md.thermal.spctemperature(1:md.mesh.numberofvertices,:)~=NaN);
+
+				%Make sure the spc are less than melting point
+				TEMP=md.thermal.spctemperature(1:md.mesh.numberofvertices,:);
 				replicate=repmat(md.geometry.surface-md.mesh.z,1,size(md.thermal.spctemperature,2));
-				md = checkfield(md,'fieldname','thermal.spctemperature(find(md.thermal.spctemperature(1:md.mesh.numberofvertices,:)~=NaN))','<=',md.materials.meltingpoint-md.materials.beta*md.materials.rho_ice*md.constants.g*replicate(pos)+10^-5,'message','spctemperature should be less or equal than the adjusted melting point');
+				pos=find(~isnan(TEMP));
+				md = checkfield(md,'fieldname','thermal.spctemperature','field',TEMP(pos)',...
+					'<=',md.materials.meltingpoint-md.materials.beta*md.materials.rho_ice*md.constants.g*replicate(pos)+10^-5,...
+					'message','spctemperature should be less or equal than the adjusted melting point');
+
 				md = checkfield(md,'fieldname','thermal.isenthalpy','numel',[1],'values',[0 1]);
 				md = checkfield(md,'fieldname','thermal.isdynamicbasalspc','numel', [1],'values',[0 1]);
@@ -151,4 +133,18 @@
 			WriteData(fid,'data',outputs,'enum',ThermalRequestedOutputsEnum(),'format','StringArray');
         	end % }}}
+		function savemodeljs(self,fid,modelname) % {{{
+		
+			writejs1Darray(fid,[modelname '.thermal.spctemperature'],self.spctemperature);
+			writejsdouble(fid,[modelname '.thermal.penalty_threshold'],self.penalty_threshold);
+			writejsdouble(fid,[modelname '.thermal.stabilization'],self.stabilization);
+			writejsdouble(fid,[modelname '.thermal.reltol'],self.reltol);
+			writejsdouble(fid,[modelname '.thermal.maxiter'],self.maxiter);
+			writejsdouble(fid,[modelname '.thermal.penalty_lock'],self.penalty_lock);
+			writejsdouble(fid,[modelname '.thermal.penalty_factor'],self.penalty_factor);
+			writejsdouble(fid,[modelname '.thermal.isenthalpy'],self.isenthalpy);
+			writejsdouble(fid,[modelname '.thermal.isdynamicbasalspc'],self.isdynamicbasalspc);
+			writejscellstring(fid,[modelname '.thermal.requested_outputs'],self.requested_outputs);
+
+		end % }}}
 	end
 end
