Changeset 16571


Ignore:
Timestamp:
10/29/13 08:57:04 (11 years ago)
Author:
bdef
Message:

Fixing timestep issues for results with differnet number of time step

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/contrib/paraview/exportVTK.m

    r16500 r16571  
    4242solnames=fields(res_struct);
    4343num_of_sols=length(solnames);
     44num_of_timesteps=1;
    4445%building solution structure
    4546for i=1:num_of_sols
    4647        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
    4752end
    4853
    49 %looking for multiple time steps
    50 num_of_timesteps=size(sol_struct{1},2);
     54for step=1:num_of_timesteps;
     55       
     56        timestep=step;
    5157
    52 for step=1:num_of_timesteps;
    53         %by default, we take the timestep from the first solution sturcture
    54         timestep=sol_struct{1}(step).step;
    55        
    5658        FID = fopen(strcat(path,filesep,name,filesep,name,'.vtk',int2str(timestep),'.vtk'),'w+');
    5759        fprintf(FID,'# vtk DataFile Version 2.0 \n');
     
    8486        %loop over the different solution structures
    8587        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
    8795                %getting the number of fields in the solution
    88                 fieldnames=fields(sol_struct{j}(step));
     96                fieldnames=fields(sol_struct{j}(timestep));
    8997                num_of_fields=length(fieldnames);
    9098               
    9199                %check which field is a real result and print
    92100                        for k=1:num_of_fields
    93                         if ((length(sol_struct{j}(step).(fieldnames{k})))== ...
     101                        if ((length(sol_struct{j}(timestep).(fieldnames{k})))== ...
    94102                                        num_of_points);
    95103                                %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;
    98106                                fprintf(FID,'SCALARS %s float 1 \n',fieldnames{k});
    99107                                fprintf(FID,'LOOKUP_TABLE default\n');
    100108                                s='%e\n';
    101                                 fprintf(FID,s,sol_struct{j}(step).(fieldnames{k}));
     109                                fprintf(FID,s,sol_struct{j}(timestep).(fieldnames{k}));
    102110        end             
    103111          end
     
    108116        for j= 1:nargin-2
    109117                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);
    112120                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);
    114122                                %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});
    118126                                fprintf(FID,'LOOKUP_TABLE default\n');
    119127                                s='%e\n';
    120                                 fprintf(FID,s,res_struct.(solnames{k}));
     128                                fprintf(FID,s,res_struct.(fieldnames{k}));
    121129            end         
    122130                end
Note: See TracChangeset for help on using the changeset viewer.