Index: /issm/trunk-jpl/src/m/classes/model.m
===================================================================
--- /issm/trunk-jpl/src/m/classes/model.m	(revision 28223)
+++ /issm/trunk-jpl/src/m/classes/model.m	(revision 28224)
@@ -1753,5 +1753,5 @@
 			random_part=fix(rand(1)*10000);
 			id=[md.miscellaneous.name '-' regexprep(datestr(now),'[^\w'']','') '-' num2str(random_part)  '-' getenv('USER') '-' oshostname() '.upload']; 
-			eval(['save ' id ' md']);
+			save('id','md');
 
 			%Now, upload the file: 
@@ -1765,5 +1765,5 @@
 
 			%get locally rid of file that was uploaded
-			eval(['delete ' id]);
+			delete(id);
 
 		end % }}}
@@ -1782,70 +1782,87 @@
 
 			%get locally rid of file that was downloaded
-			eval(['delete ' name]);
+			delete(name);
 
 		end % }}}
 		function saveasstruct(md,filename) % {{{
 
-			fields=sort(properties('model')); %sort fields so that comparison of binary files is easier
+			%Get all model fields
+			mdfields=properties('model');
+
 			disp('Converting all model fields to struct...');
 			warning off MATLAB:structOnObject
+			for i=1:length(mdfields),
+
+				%convert md field to struct
+				field=mdfields{i};
+				field_struct = struct(md.(field));
+
+				%Check that there is no class remaining in the field
+				subfields = fields(field_struct);
+				for i=1:numel(subfields)
+					if isobject(field_struct.(subfields{i}))
+						disp(['skipping ' subfields{i} ' because it is an object'])
+						field_struct = rmfield(field_struct, subfields{i});
+					end
+				end
+				md.(field) = field_struct;
+			end
+
+			disp('Converting model to struct...');
+			md=struct(md);
+
+			disp(['Saving as ' filename '...']);
+			warning on MATLAB:structOnObject
+			save(filename,'md','-v7.3')
+
+		end % }}}
+		function savemodeljs(md,modelname,websiteroot,varargin) % {{{
+
+			%the goal of this routine is to save the model as a javascript array that can be included in any html 
+			%file: 
+
+			options=pairoptions(varargin{:});
+			optimization=getfieldvalue(options,'optimize',0);
+
+
+			%disp: 
+			disp(['saving model ''' modelname ''' in file ' websiteroot '/js/' modelname '.js']);
+
+			%open file for writing and declare the model:
+			fid=fopen([websiteroot '/js/' modelname '.js'],'w');
+			fprintf(fid,'var %s=new model();\n',modelname);
+
+			%now go through all the classes and fwrite all the corresponding fields: 
+
+			fields=properties('model');
 			for i=1:length(fields),
 				field=fields{i};
-				md.(field) = struct(md.(field));
-			end
-			disp('Converting model to struct...');
-			md=struct(md);
-			warning on MATLAB:structOnObject
-			disp(['Saving as ' filename '...']);
-			save(filename,'md','-v7.3')
-		end % }}}
-function savemodeljs(md,modelname,websiteroot,varargin) % {{{
-
-	%the goal of this routine is to save the model as a javascript array that can be included in any html 
-	%file: 
-
-	options=pairoptions(varargin{:});
-	optimization=getfieldvalue(options,'optimize',0);
-
-
-	%disp: 
-	disp(['saving model ''' modelname ''' in file ' websiteroot '/js/' modelname '.js']);
-
-	%open file for writing and declare the model:
-	fid=fopen([websiteroot '/js/' modelname '.js'],'w');
-	fprintf(fid,'var %s=new model();\n',modelname);
-
-	%now go through all the classes and fwrite all the corresponding fields: 
-
-	fields=properties('model');
-	for i=1:length(fields),
-		field=fields{i};
-
-		%Some properties do not need to be saved
-		if ismember(field,{'results','cluster' }),
-			continue;
+
+				%Some properties do not need to be saved
+				if ismember(field,{'results','cluster' }),
+					continue;
+				end
+
+				%some optimization: 
+				if optimization==1,
+					%optimize for plotting only:
+					if ~ismember(field,{'geometry','mesh','mask'}),
+						continue;
+					end
+				end
+
+				%Check that current field is an object
+				if ~isobject(md.(field))
+					error(['field ''' char(field) ''' is not an object']);
+				end
+
+				%savemodeljs for current object
+				%disp(['javascript saving ' field '...']);
+				savemodeljs(md.(field),fid,modelname);
+			end
+
+			%done, close file:
+			fclose(fid);
 		end
-
-		%some optimization: 
-		if optimization==1,
-			%optimize for plotting only:
-			if ~ismember(field,{'geometry','mesh','mask'}),
-				continue;
-			end
-		end
-
-		%Check that current field is an object
-		if ~isobject(md.(field))
-			error(['field ''' char(field) ''' is not an object']);
-		end
-
-		%savemodeljs for current object
-		%disp(['javascript saving ' field '...']);
-		savemodeljs(md.(field),fid,modelname);
-	end
-
-	%done, close file:
-	fclose(fid);
-end
 	end
 end
