Hello,<div><br></div><div>Paraview crashes when reading a binary VTK file.  I am writing out that file using the Matlab function below.  When written out in ASCII the file is read and interpreted correctly; when written out in binary paraview just crashes without giving any details as to where and why it crashed.  I hope someone has an idea: after several hours of debugging I am at a loss.</div>
<div><br></div><div><div>% Export mesh to a VTK 1.0 file as an unstructured grid.</div><div>%</div><div>% function vtk_export_mesh (theFile,Connectivity,Points,Cell_types,options)</div><div>%</div><div>% theFile= File name as a string,</div>
<div>% Connectivity= connectivity array, one row per cell,</div><div>% Points= Coordinate array, one row per point,</div><div>% Cell_types= Cell type code: L2=3, T3=5, Q4=9, T4=10, H8=12</div><div>function vtk_export_mesh (theFile,Connectivity,Points,Cell_types,options)</div>
<div>    binary= ~true;</div><div>    scalars=[]; scalars_name= [&#39;Data&#39;];</div><div>    if ( exist ( &#39;options&#39;, &#39;var&#39;) )</div><div>        if (isfield(options, &#39;binary&#39;))</div><div>            binary= options.binary;</div>
<div>        end</div><div>        if (isfield(options, &#39;scalars&#39;))</div><div>            scalars= options.scalars;</div><div>        end</div><div>        if (isfield(options, &#39;scalars_name&#39;))</div><div>            scalars_name= options.scalars_name;</div>
<div>        end</div><div>    end</div><div>    if (~iscell(Connectivity))</div><div>        Connectivity={Connectivity};</div><div>    end</div><div>    if (~iscell(Cell_types))</div><div>        Cell_types={Cell_types};</div>
<div>    end</div><div>    [pathstr, name, ext] = fileparts(theFile);</div><div>    if (~strcmp(ext,&#39;vtk&#39;))</div><div>        theFile = [theFile &#39;.vtk&#39;];</div><div>    end</div><div>    fid=fopen(theFile,&#39;w&#39;);</div>
<div>    if (fid==-1)</div><div>        warning ([&#39;Could not open &#39; theFile])</div><div>        return</div><div>    end</div><div>    fprintf(fid,&#39;# vtk DataFile Version 3.0\n&#39;);</div><div>    fprintf(fid,&#39;Really cool data\n&#39;);</div>
<div>    if (~binary)</div><div>        fprintf(fid,&#39;ASCII\n&#39;);</div><div>    else</div><div>        fprintf(fid,&#39;BINARY\n&#39;);</div><div>    end</div><div>    fprintf(fid,&#39;\n&#39;);</div><div>    fprintf(fid,&#39;DATASET UNSTRUCTURED_GRID\n&#39;);</div>
<div>    fprintf(fid,&#39;POINTS %d double\n&#39;,size(Points,1));%</div><div>    if (~binary)</div><div>        for i= 1:size(Points, 1)</div><div>            fprintf(fid,&#39;%g %g %g\n&#39;,Points(i,:));</div><div>        end</div>
<div>    else</div><div>        fwrite(fid,cast(Points,&#39;double&#39;),&#39;double&#39;);</div><div>    end</div><div>    fprintf(fid,&#39;\n&#39;);</div><div>    fprintf(fid,&#39;\n&#39;);</div><div>    </div><div>    for k=1:length(Connectivity)</div>
<div>        f=Connectivity{k};</div><div>        ctype=zeros(size(f, 1),1)+Cell_types{k};</div><div>        fprintf(fid,&#39;CELLS %d %d\n&#39;,size(f,1),(size(f,1)*(size(f,2)+1)));%</div><div>        if (~binary)</div><div>
            for i= 1:size(f, 1)</div><div>                fprintf(fid,&#39;%d &#39;,size(f,2));</div><div>                for j= 1: size(f,2)</div><div>                    fprintf(fid,&#39;%d &#39;,f(i,j)-1);</div><div>                end</div>
<div>                fprintf(fid,&#39;\n&#39;);</div><div>            end</div><div>        else</div><div>            fwrite(fid,cast([zeros(size(f,1),1)+size(f,2),f-1],&#39;int32&#39;),&#39;int32&#39;);</div><div>        end</div>
<div>        fprintf(fid,&#39;\n&#39;);</div><div>        fprintf(fid,&#39;\n&#39;);</div><div>        fprintf(fid,&#39;CELL_TYPES %d\n&#39;,size(f,1));%</div><div>        if (~binary)</div><div>            for i= 1:size(f, 1)</div>
<div>                fprintf(fid,&#39;%d\n&#39;,ctype(i));</div><div>            end</div><div>        else</div><div>            fwrite(fid,cast(ctype,&#39;int32&#39;),&#39;int32&#39;);</div><div>        end</div><div>        fprintf(fid,&#39;\n&#39;);</div>
<div>        fprintf(fid,&#39;\n&#39;);</div><div>    end</div><div>    </div><div>    if (~isempty(scalars))</div><div>        fprintf(fid,&#39;point_data %d\n&#39;,length(scalars));%</div><div>        fprintf(fid,&#39;SCALARS %s float\n&#39;,scalars_name);%</div>
<div>        fprintf(fid,&#39;LOOKUP_TABLE default\n&#39;);%</div><div>        if (~binary)</div><div>            for j= 1:length(scalars)</div><div>                    fprintf(fid,&#39;%s\n&#39;,scalars(j));</div><div>                end</div>
<div>        else</div><div>            fwrite(fid,cast(scalars,&#39;single&#39;),&#39;single&#39;);</div><div>        end</div><div>    end</div><div>    fprintf(fid,&#39;\n&#39;);</div><div>    fid=fclose(fid);</div><div>
end</div><div><br></div>-- <br>Petr Krysl<div>University of California, San Diego</div><div>Skype: <a href="http://Petr.Krysl.UCSD.EDU" target="_blank">Petr.Krysl.UCSD.EDU</a></div><div><a href="http://hogwarts.ucsd.edu/~pkrysl/" target="_blank">http://hogwarts.ucsd.edu/~pkrysl/</a></div>
<br>
</div>