# Unrecongnized keyword in vtk file

**URL:** https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776
**Category:** ParaView Support
**Created:** [January 13, 2022, 9:44pm UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776 "2022-01-13T21:44:57Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 13, 2022, 9:44pm UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/1 "2022-01-13T21:44:57Z")

</div>

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](https://discourse.paraview.org/uploads/short-url/jKDk4lrDGx8ShnZydwThkRk5lNg.vtk) (1.5 MB)

---

<div class="post-metadata">

### Author: ![todoooo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/todoooo/32/2819_2.png) [@todoooo](https://discourse.paraview.org/u/todoooo)
#### Post date: [January 14, 2022, 7:52am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/2 "2022-01-14T07:52:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 14, 2022, 8:08am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/3 "2022-01-14T08:08:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![todoooo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/todoooo/32/2819_2.png) [@todoooo](https://discourse.paraview.org/u/todoooo)
#### Post date: [January 14, 2022, 8:09am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/4 "2022-01-14T08:09:56Z")

</div>

It’s a text file.

---

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 14, 2022, 10:09am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/5 "2022-01-14T10:09:49Z")

</div>

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.

```auto
        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

```

---

<div class="post-metadata">

### Author: ![todoooo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/todoooo/32/2819_2.png) [@todoooo](https://discourse.paraview.org/u/todoooo)
#### Post date: [January 14, 2022, 10:27am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/6 "2022-01-14T10:27:59Z")

</div>

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](https://discourse.paraview.org/uploads/default/original/2X/2/24b0a44762317b6681e0781310e8a7bd09c6e920.png)

---

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 14, 2022, 10:29am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/7 "2022-01-14T10:29:19Z")

</div>

Thanks for the tips. I will try it now.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [January 14, 2022, 11:37am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/8 "2022-01-14T11:37:21Z")

</div>

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**.

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

```

This may be causing inconsistencies.

---

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 17, 2022, 10:10am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/9 "2022-01-17T10:10:44Z")

</div>

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

```auto
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](https://discourse.paraview.org/uploads/short-url/2uNxSpc00x1HnYCSpAillxx1W79.vtk) (2.3 MB)

 ![crash message](https://discourse.paraview.org/uploads/default/original/2X/9/9746a00623cdd3a4e489fe3b615df04c255c18d4.png)

---

<div class="post-metadata">

### Author: ![todoooo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/todoooo/32/2819_2.png) [@todoooo](https://discourse.paraview.org/u/todoooo)
#### Post date: [January 17, 2022, 10:23am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/10 "2022-01-17T10:23:39Z")

</div>

Did you check **PrintScalar2VTK()** as well?

---

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 17, 2022, 10:27am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/11 "2022-01-17T10:27:09Z")

</div>

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

```auto
 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

```

---

<div class="post-metadata">

### Author: ![todoooo](https://discourse.paraview.org/user_avatar/discourse.paraview.org/todoooo/32/2819_2.png) [@todoooo](https://discourse.paraview.org/u/todoooo)
#### Post date: [January 17, 2022, 10:52am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/12 "2022-01-17T10:52:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [January 17, 2022, 11:40am UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/13 "2022-01-17T11:40:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ziliang](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Ziliang](https://discourse.paraview.org/u/Ziliang)
#### Post date: [January 17, 2022, 2:14pm UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/14 "2022-01-17T14:14:59Z")

</div>

Hi Kyoshimi and Todd,

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

```auto
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](https://discourse.paraview.org/uploads/short-url/fqd4ShqAAAjqyiGVHSe8S1RZO2s.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

---

<div class="post-metadata">

### Author: ![Jann5s](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jann5s/32/11607_2.png) [@Jann5s](https://discourse.paraview.org/u/Jann5s)
#### Post date: [May 15, 2023, 1:52pm UTC](https://discourse.paraview.org/t/unrecongnized-keyword-in-vtk-file/8776/15 "2023-05-15T13:52:20Z")

</div>

@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?
