Index: /issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m
===================================================================
--- /issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m	(revision 16570)
+++ /issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m	(revision 16571)
@@ -42,16 +42,18 @@
 solnames=fields(res_struct);
 num_of_sols=length(solnames);
+num_of_timesteps=1;
 %building solution structure 
 for i=1:num_of_sols
 	sol_struct{i}=res_struct.(solnames{i});
+	%looking for multiple time steps
+	if(size(sol_struct{i},2)>num_of_timesteps);
+		num_of_timesteps=size(sol_struct{i},2);
+  end
 end
 
-%looking for multiple time steps
-num_of_timesteps=size(sol_struct{1},2);
+for step=1:num_of_timesteps;
+	
+	timestep=step;
 
-for step=1:num_of_timesteps;
-	%by default, we take the timestep from the first solution sturcture
-	timestep=sol_struct{1}(step).step;
-	
 	FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+');
 	fprintf(FID,'# vtk DataFile Version 2.0 \n');
@@ -84,20 +86,26 @@
 	%loop over the different solution structures
 	for j=1:num_of_sols
-		
+		%dealing with results on different timesteps
+		if(size(sol_struct{j},2)>timestep);
+			timestep = step;
+		else
+			timestep = size(sol_struct{j},2);
+	  end
+
 		%getting the number of fields in the solution
-		fieldnames=fields(sol_struct{j}(step));
+		fieldnames=fields(sol_struct{j}(timestep));
 		num_of_fields=length(fieldnames);
 		
 		%check which field is a real result and print
 			for k=1:num_of_fields
-			if ((length(sol_struct{j}(step).(fieldnames{k})))== ...
+			if ((length(sol_struct{j}(timestep).(fieldnames{k})))== ...
 					num_of_points);
 				%paraview does not like NaN, replacing
-				pos=find(isnan(sol_struct{j}(step).(fieldnames{k})));
-				sol_struct{j}(step).(fieldnames{k})(pos)=-9999;
+				pos=find(isnan(sol_struct{j}(timestep).(fieldnames{k})));
+				sol_struct{j}(timestep).(fieldnames{k})(pos)=-9999;
 				fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k});
 				fprintf(FID,'LOOKUP_TABLE default\n');
 				s='%e\n';
-				fprintf(FID,s,sol_struct{j}(step).(fieldnames{k}));
+				fprintf(FID,s,sol_struct{j}(timestep).(fieldnames{k}));
     	end		
 	  end 
@@ -108,15 +116,15 @@
 	for j= 1:nargin-2
 		res_struct=model.(varargin{j});
-		solnames=fields(res_struct);
-		num_of_sols=length(solnames);
+		fieldnames=fields(res_struct);
+		num_of_fields=length(fieldnames);
 		for k=1:num_of_sols
-			if ((length(res_struct.(solnames{k})))==num_of_points);
+			if ((length(res_struct.(fieldnames{k})))==num_of_points);
 				%paraview does not like NaN, replacing
-				pos=find(isnan(res_struct.(solnames{k})));
-				res_struct.(solnames{k})(pos)=-9999;
-				fprintf(FID,'SCALARS %s float 1 \n',solnames{k});
+				pos=find(isnan(res_struct.(fieldnames{k})));
+				res_struct.(fieldnames{k})(pos)=-9999;
+				fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k});
 				fprintf(FID,'LOOKUP_TABLE default\n');
 				s='%e\n';
-				fprintf(FID,s,res_struct.(solnames{k}));
+				fprintf(FID,s,res_struct.(fieldnames{k}));
 	    end		
 		end 
