Changeset 16490
- Timestamp:
- 10/21/13 16:43:38 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m
r16353 r16490 1 function exportVTK(filename,model )1 function exportVTK(filename,model,varargin) 2 2 % vtk export 3 3 % function exportVTK(filename,model) … … 11 11 %------------------------------------------------------------------ 12 12 % model this is md 13 %------------------------------------------------------------------ 14 % By default only the results are exported, you can add whichever 15 % field you need as a string: 16 % add 'geometry' to export md.geometry 13 17 % 14 18 % Basile de Fleurian: … … 35 39 %this is the result structure 36 40 res_struct=model.results; 37 38 41 %Getting all the solutions of the model 39 42 solnames=fields(res_struct); 40 43 num_of_sols=length(solnames); 41 42 44 %building solution structure 43 45 for i=1:num_of_sols … … 48 50 num_of_timesteps=size(sol_struct{1},2); 49 51 50 for i=1:num_of_timesteps;52 for step=1:num_of_timesteps; 51 53 %by default, we take the timestep from the first solution sturcture 52 timestep=sol_struct{1}( i).step;54 timestep=sol_struct{1}(step).step; 53 55 54 56 FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+'); … … 66 68 P=[points zeros(num_of_points,3-dim)]; 67 69 fprintf(FID,s,P'); 68 70 69 71 fprintf(FID,'CELLS %d %d\n',num_of_elt,num_of_elt*(point_per_elt+1)); 70 72 s='%d'; 71 for k=1:point_per_elt73 for j=1:point_per_elt 72 74 s=horzcat(s,{' %d'}); 73 75 end 74 76 s=cell2mat(horzcat(s,{'\n'})); 75 77 fprintf(FID,s,[(point_per_elt)*ones(num_of_elt,1) model.mesh.elements-1]'); 76 78 77 79 fprintf(FID,'CELL_TYPES %d\n',num_of_elt); 78 80 s='%d\n'; 79 81 fprintf(FID,s,celltype*ones(num_of_elt,1)); 80 82 fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points)); 83 81 84 %loop over the different solution structures 82 85 for j=1:num_of_sols 83 86 84 87 %getting the number of fields in the solution 85 fieldnames=fields(sol_struct{j}( i));88 fieldnames=fields(sol_struct{j}(step)); 86 89 num_of_fields=length(fieldnames); 87 90 88 91 %check which field is a real result and print 89 fprintf(FID,'POINT_DATA %s \n',num2str(num_of_points)); 90 for k=1:num_of_fields 91 92 if ((length(sol_struct{j}(i).(fieldnames{k})))==num_of_points); 92 for k=1:num_of_fields 93 if ((length(sol_struct{j}(step).(fieldnames{k})))==num_of_points); 93 94 fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k}); 94 95 fprintf(FID,'LOOKUP_TABLE default\n'); 95 96 s='%e\n'; 96 fprintf(FID,s,sol_struct{j}(i).(fieldnames{k})); 97 fprintf(FID,s,sol_struct{j}(step).(fieldnames{k})); 98 end 99 end 100 end 101 102 %loop on arguments, if something other than result is asked, do 103 %it now 104 for j= 1:nargin-2 105 res_struct=model.(varargin{j}); 106 solnames=fields(res_struct); 107 num_of_sols=length(solnames); 108 for k=1:num_of_sols 109 if ((length(res_struct.(solnames{k})))==num_of_points); 110 fprintf(FID,'SCALARS %s float 1 \n',solnames{k}); 111 fprintf(FID,'LOOKUP_TABLE default\n'); 112 s='%e\n'; 113 fprintf(FID,s,res_struct.(solnames{k})); 97 114 end 98 end 99 end 100 fclose(FID); 101 end 115 end 116 end 117 fclose(FID); 102 118 end
Note:
See TracChangeset
for help on using the changeset viewer.