Changeset 16571
- Timestamp:
- 10/29/13 08:57:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m ¶
r16500 r16571 42 42 solnames=fields(res_struct); 43 43 num_of_sols=length(solnames); 44 num_of_timesteps=1; 44 45 %building solution structure 45 46 for i=1:num_of_sols 46 47 sol_struct{i}=res_struct.(solnames{i}); 48 %looking for multiple time steps 49 if(size(sol_struct{i},2)>num_of_timesteps); 50 num_of_timesteps=size(sol_struct{i},2); 51 end 47 52 end 48 53 49 %looking for multiple time steps 50 num_of_timesteps=size(sol_struct{1},2); 54 for step=1:num_of_timesteps; 55 56 timestep=step; 51 57 52 for step=1:num_of_timesteps;53 %by default, we take the timestep from the first solution sturcture54 timestep=sol_struct{1}(step).step;55 56 58 FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+'); 57 59 fprintf(FID,'# vtk DataFile Version 2.0 \n'); … … 84 86 %loop over the different solution structures 85 87 for j=1:num_of_sols 86 88 %dealing with results on different timesteps 89 if(size(sol_struct{j},2)>timestep); 90 timestep = step; 91 else 92 timestep = size(sol_struct{j},2); 93 end 94 87 95 %getting the number of fields in the solution 88 fieldnames=fields(sol_struct{j}( step));96 fieldnames=fields(sol_struct{j}(timestep)); 89 97 num_of_fields=length(fieldnames); 90 98 91 99 %check which field is a real result and print 92 100 for k=1:num_of_fields 93 if ((length(sol_struct{j}( step).(fieldnames{k})))== ...101 if ((length(sol_struct{j}(timestep).(fieldnames{k})))== ... 94 102 num_of_points); 95 103 %paraview does not like NaN, replacing 96 pos=find(isnan(sol_struct{j}( step).(fieldnames{k})));97 sol_struct{j}( step).(fieldnames{k})(pos)=-9999;104 pos=find(isnan(sol_struct{j}(timestep).(fieldnames{k}))); 105 sol_struct{j}(timestep).(fieldnames{k})(pos)=-9999; 98 106 fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k}); 99 107 fprintf(FID,'LOOKUP_TABLE default\n'); 100 108 s='%e\n'; 101 fprintf(FID,s,sol_struct{j}( step).(fieldnames{k}));109 fprintf(FID,s,sol_struct{j}(timestep).(fieldnames{k})); 102 110 end 103 111 end … … 108 116 for j= 1:nargin-2 109 117 res_struct=model.(varargin{j}); 110 solnames=fields(res_struct);111 num_of_ sols=length(solnames);118 fieldnames=fields(res_struct); 119 num_of_fields=length(fieldnames); 112 120 for k=1:num_of_sols 113 if ((length(res_struct.( solnames{k})))==num_of_points);121 if ((length(res_struct.(fieldnames{k})))==num_of_points); 114 122 %paraview does not like NaN, replacing 115 pos=find(isnan(res_struct.( solnames{k})));116 res_struct.( solnames{k})(pos)=-9999;117 fprintf(FID,'SCALARS %s float 1 \n', solnames{k});123 pos=find(isnan(res_struct.(fieldnames{k}))); 124 res_struct.(fieldnames{k})(pos)=-9999; 125 fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k}); 118 126 fprintf(FID,'LOOKUP_TABLE default\n'); 119 127 s='%e\n'; 120 fprintf(FID,s,res_struct.( solnames{k}));128 fprintf(FID,s,res_struct.(fieldnames{k})); 121 129 end 122 130 end
Note:
See TracChangeset
for help on using the changeset viewer.