Unrecongnized keyword in vtk file

Dear ParaView support,

I am trying to visualize a vtk file, but it gave me an ‘Unrecongnized keyword’ error. The full message is

ERROR: In /opt/glr/paraview/paraview-ci/build/superbuild/paraview/src/VTK/IO/Legacy/vtkUnstructuredGridReader.cxx, line 320
vtkUnstructuredGridReader (0x7fcdb1a1a570): Unrecognized keyword: �

Is it because the data is not written correctly in vtk file or something else. Any help would be appreciated. The attached is one example file.
CPG_Reservoir0001.vtk (1.5 MB)

You file is full of garbage characters. Did you look at the contents?

Thanks for your reply. Sorry I am very new to paraview and vtk. I am not sure how to open vtk files and check their contents. Do you have any suggestions.

It’s a text file.

Hi Todd, really appreciate your help. I looked into the vtk files. Is it true that the problem starts from POINTS data. Sorry for keeping asking stupid questions.

Below is the part of Matlab code used to save the data into vtk files. Do you notice any obvious mistake that could cause the problem.

        function PlotReservoirSolution(obj, Reservoir, Grid)
            %Write a VTK file for Reservoir
            fileID = fopen(strcat(obj.FileName, '_Reservoir', num2str(obj.VTKindex,'%04d'),'.vtk'), 'w');
            fprintf(fileID, '# vtk DataFile Version 2.0\n');
            fprintf(fileID, 'DARSim 2 Reservoir Simulator\n');
            if obj.isBinary
                fprintf(fileID, 'BINARY\n');
            else
            	fprintf(fileID, 'ASCII\n');
            end
            fprintf(fileID, '\n');
            %
            fprintf(fileID, 'DATASET UNSTRUCTURED_GRID\n');
            VTK_Nodes = Grid.CornerPointGridData.Nodes;
            if Grid.CornerPointGridData.N_TotalCells ~= Grid.CornerPointGridData.N_ActiveCells
                obj.ReferenceDepth = max(VTK_Nodes(:,3));
                % If the domain is a Cartesian box, there is no need to invert the Z coordinates.
                % But if the domain is not a Cartesian boxTherefore, the Z coordinates are inverted only for the sake of the visualization.
                VTK_Nodes(:,3) = obj.ReferenceDepth - VTK_Nodes(:,3);
            end
            fprintf(fileID, ['POINTS ' num2str(Grid.CornerPointGridData.N_Nodes) ' double\n']);
            if obj.isBinary
                fwrite(fileID, VTK_Nodes','float', 'b');
            else
                fprintf(fileID, '%f %f %f\n',VTK_Nodes');
            end
            fprintf(fileID, '\n');
            %
            fprintf(fileID, ['CELLS ' num2str(Grid.N) ' ' num2str(Grid.N*(1+8)) '\n']);
            indMatrix = horzcat(8*ones(Grid.N,1) , Grid.CornerPointGridData.Cells.Vertices-1 );
            if obj.isBinary
                fwrite(fileID, indMatrix','float', 'b');
            else
                fprintf(fileID, '%d %d %d %d %d %d %d %d %d\n', indMatrix');
            end
 
            fprintf(fileID, '\n');
            %
            fprintf(fileID, ['CELL_TYPES ' num2str(Grid.N) '\n']);
            if obj.isBinary
                fwrite(fileID, 11*ones(1,Grid.N),'float', 'b');
            else
                fprintf(fileID, '%d ', 11*ones(1,Grid.N));
            end
 
            fprintf(fileID, '\n\n');
 
            % Print all existing variables
            fprintf(fileID, 'CELL_DATA %d\n', Grid.N);
            N_var = double(Reservoir.State.Properties.Count);
            Names = Reservoir.State.Properties.keys;
            for i=1:N_var
                if strcmp(Reservoir.State.Properties(Names{i}).Type, 'scalar')
                    obj.PrintScalar2VTK(fileID, Reservoir.State.Properties(Names{i}).Value, [' ',Names{i}]);
                else
                    obj.PrintVector2VTK(fileID, Reservoir.State.Properties(Names{i}).Value, [' ',Names{i}]);
                end
                fprintf(fileID, '\n');
            end
 
            % Add the "isFractured" flag for reservoir grid cells that are overlapped by a fracture (if any)
            if ~isempty(Grid.ListOfFracturedReservoirCells)
                isFractured = zeros(Grid.N,1);
                isFractured(Grid.ListOfFracturedReservoirCells) = 1;
                obj.PrintScalar2VTK(fileID, isFractured, ' isFractured');
                fprintf(fileID, '\n');
            end
 
            % Add the "isPerforated" flag for reservoir grid cells that are overlapped by a fracture (if any)
            if ~isempty(Grid.ListOfPerforatedCells)
                isPerforated = zeros(Grid.N,1);
                isPerforated(Grid.ListOfPerforatedCells) = 1;
                obj.PrintScalar2VTK(fileID, isPerforated, ' isPerforated');
                fprintf(fileID, '\n');
            end
 
            % Add the cell indices
            obj.PrintScalar2VTK(fileID, [1:Grid.N]', ' Index');
            fprintf(fileID, '\n');
 
            % Add the cell volumes
            obj.PrintScalar2VTK(fileID, Grid.Volume, ' Volume');
            fprintf(fileID, '\n');
 
            % Add ADM ACTIVETime
            obj.PrintScalar2VTK(fileID, Grid.ActiveTime, ' ACTIVETime');
            fprintf(fileID, '\n');
 
            % Add ADM ACTIVEFine (coarse grids)
            obj.PrintScalar2VTK(fileID, Grid.Active, ' ACTIVEFine');
            fprintf(fileID, '\n');
 
            fclose(fileID);
 
            if obj.PlotInterfaces
                obj.PlotInternalFaces(Reservoir, Grid);
            end
        end

The data output is binary so it’s impossible to analyse. I suggest you generate the equivalent ASCII file and see if that can be read first.

image

1 Like

Thanks for the tips. I will try it now.

In the VTK file, the precision of POINTS is set to double.

POINTS 10302 double

On the other hand, the matlab source code specifies a precision of float.

  fwrite(fileID, VTK_Nodes','float', 'b');

This may be causing inconsistencies.

1 Like

Hi Todd and Kyoshimi,

Thanks for your help. Firstly, I tried to follow Todd’s suggestion, generating the equivalent ASCII file. Everything works in that way. Paraview can read the file with no problem. The attached is an example ASCII file.

So I would say the problem is rooted from those fwrite commands used to save the data to binary files, like you suggested. I also noticed that inconsistency and tried to change the fwrite command to

fwrite(fileID, VTK_Nodes','double', 'b');

but the paraview would crash when I tried to visualize it. Below is a picture of the crash message. Do you guys know what may causes this problem.
CPG_Reservoir0000.vtk (2.3 MB)

Did you check PrintScalar2VTK() as well?

Hi Todd, yes, it is written in this way. I did not notice an obvious mistake.

 function PrintScalar2VTK(obj, fileID, scalar, name)
            %Print a scalar in VTK format
            fprintf(fileID, '\n');
            fprintf(fileID, strcat('SCALARS  ', name,' double 1\n'));
            fprintf(fileID, 'LOOKUP_TABLE default\n');
            if obj.isBinary
                fwrite(fileID, scalar', 'double', 'b');
            else
            	fprintf(fileID,'%1.5e ', scalar);
            end
        end

I think you need to start with a file containing just a couple of points, cells and scalars to see what is causing the crash by a process of elimination. Gradually adding more data as the read succeeds.

1 Like

At least, since CELLS and CELL_TYPES are integer arrays, you should specify ‘int’ as the precision of fwrite to output them.

1 Like

Hi Kyoshimi and Todd,

Thanks for your reply again. You are right! I changed the fwrite commands to

fwrite(fileID, VTK_Nodes','double', 'b');
fwrite(fileID, indMatrix','int', 'b');
fwrite(fileID, 11*ones(1,Grid.N),'int', 'b');

for POINTS, CELLS and CELL_TYPES respectively. It works this time. Paraview read the binary file with no problem. The attached is a newly generated BINARY file example.
CPG_Reservoir0000.vtk (1.6 MB)

It seems like indeed the problem is caused by the inconsistencies when specifying the precision. Thank you both for the helpful discussion. Really appreciate that.

All the best,
Ziliang

@Ziliang,

I seem to have the same issue, but I have troubles reconstructing the correct version from your initial code and the corrections in your last post. Would you mind sharing the final code?