Index: /issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m
===================================================================
--- /issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m	(revision 16304)
+++ /issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m	(revision 16305)
@@ -1,3 +1,3 @@
-function exportVTK(filename,model,Solution)
+function exportVTK(filename,model)
 % vtk export
 % function exportVTK(filename,model,Solution)
@@ -19,11 +19,9 @@
 mkdir(filename);
 
+%get the element related variables
 points=[model.mesh.x model.mesh.y model.mesh.z];
 [num_of_points,dim]=size(points);
 [num_of_elt]=size(model.mesh.elements,1);
 [point_per_elt]=size(model.mesh.elements,2);
-sol_enum=EnumToString(Solution);
-
-sol_struct=model.results.(sol_enum);
 
 %Select the type of element function of the number of nodes per elements
@@ -36,19 +34,31 @@
 end
 
+%sol_enum=EnumToString(Solution);
+
+%this is the result structure
+res_struct=model.results;
+
+%Getting all the solutions of the model
+solnames=fields(res_struct);
+num_of_sols=length(solnames);
+
+%building solution structure 
+for i=1:num_of_sols
+	sol_struct{i}=res_struct.(solnames{i});
+end
+
 %looking for multiple time steps
-num_of_timesteps=size(sol_struct,2);
+num_of_timesteps=size(sol_struct{1},2);
 
-%getting the number of fields in the solution
-fieldnames=fields(sol_struct(1));
-num_of_fields=length(fieldnames);
-
-if num_of_timesteps==1; %just one timestep only write one file
-
-	FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk'),'w+');
+for i=1:num_of_timesteps;
+	%by default, we take the timestep from the first solution sturcture
+	timestep=sol_struct{1}(i).step;
+	
+	FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+');
 	fprintf(FID,'# vtk DataFile Version 2.0 \n');
 	fprintf(FID,'Data for run %s \n',model.miscellaneous.name);
 	fprintf(FID,'ASCII \n');
 	fprintf(FID,'DATASET UNSTRUCTURED_GRID \n');
-
+	
 	fprintf(FID,'POINTS %d float\n',num_of_points);
 	if(dim==3);
@@ -59,71 +69,37 @@
 	P=[points zeros(num_of_points,3-dim)];
 	fprintf(FID,s,P');
-
+ 
 	fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1));
 	s='%d';
 	for k=1:point_per_elt
-    s=horzcat(s,{' %d'});
+		s=horzcat(s,{' %d'});
   end
 	s=cell2mat(horzcat(s,{'\n'}));
 	fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]');
-
+ 
 	fprintf(FID,'CELL_TYPES %d\n',num_of_elt);
 	s='%d\n';
 	fprintf(FID,s,celltype*ones(num_of_elt,1));
+	
+	%loop over the different solution structures
+	for j=1:num_of_sols
 
-	%check which field is a real result and print	
-	fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points));
-	for j=1:num_of_fields
-
-		if (length(sol_struct(1).(fieldnames{j}))==num_of_points);
-			fprintf(FID,'SCALARS %s float 1 \n',fieldnames{j});
-			fprintf(FID,'LOOKUP_TABLE default\n');
-			s='%e\n';
-			fprintf(FID,s,sol_struct.(fieldnames{j}));
-	  end
-  end
-		fclose(FID);
-else
-	for i=1:num_of_timesteps;
-		timestep=sol_struct(i).step;
-		FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+');
-		fprintf(FID,'# vtk DataFile Version 2.0 \n');
-		fprintf(FID,'Data for run %s \n',model.miscellaneous.name);
-		fprintf(FID,'ASCII \n');
-		fprintf(FID,'DATASET UNSTRUCTURED_GRID \n');
-
-		fprintf(FID,'POINTS %d float\n',num_of_points);
-		if(dim==3);
-			s='%f %f %f \n';
-		elseif(dim==2);
-			s='%f %f \n';
-   end
-		P=[points zeros(num_of_points,3-dim)];
-		fprintf(FID,s,P');
-
-		fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1));
-		s='%d';
-		for k=1:point_per_elt
-			s=horzcat(s,{' %d'});
-  	end
-		s=cell2mat(horzcat(s,{'\n'}));
-		fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]');
-
-		fprintf(FID,'CELL_TYPES %d\n',num_of_elt);
-		s='%d\n';
-		fprintf(FID,s,celltype*ones(num_of_elt,1));
-
+		%getting the number of fields in the solution
+		fieldnames=fields(sol_struct{j}(i));
+		num_of_fields=length(fieldnames);
+		
 		%check which field is a real result and print
 		fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points));
-		for j=1:num_of_fields
-
-			if (length(sol_struct(1).(fieldnames{j}))==num_of_points);
-				fprintf(FID,'SCALARS %s float 1 \n',fieldnames{j});
+		for k=1:num_of_fields
+			
+			if ((length(sol_struct{j}(i).(fieldnames{k})))==num_of_points);
+				fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k});
 				fprintf(FID,'LOOKUP_TABLE default\n');
 				s='%e\n';
-				fprintf(FID,s,sol_struct(i).(fieldnames{j}));
+				fprintf(FID,s,sol_struct{j}(i).(fieldnames{k}));
 	    end		
-    end 
-		fclose(FID);
+     end 
+	 end
+	 fclose(FID);
   end
 end
