VTK file (*.vtu) not being correctly read

Hi,

I’m having a problem with creating VTK data files for use with ParaView. I’m writing out point data as an unstructured grid but ParaView can’t seem to read it. Here’s an example of my .vtu file for 20 points with some associated scalar data:

<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <UnstructuredGrid>
    <Piece NumberOfCells="20" NumberOfPoints="20">
      <Points>
        <DataArray Name="points" type="Float64" format="ascii" NumberofComponents="3">
          0.9191090317991818 0.4523130130592968 0.4455559100158843 0.6421955999238554 0.1757747380313244 0.9770526614339072
          0.7537122297291767 0.0493769993144870 0.7293940090533850 0.1393145681027350 0.2924753386949548 0.3122350583311531
          0.0873195479896001 0.0667991310914613 0.8947552392940534 0.7880020580364918 0.7511564859911245 0.7832735951745574
          0.3261509370344888 0.0637715240806562 0.2620003413345412 0.5410678214759677 0.4319083194117714 0.3094831861549427
          0.2402351758680060 0.3641724134430167 0.1294506297724709 0.5454229255759049 0.1519715256925609 0.4221713562335928
          0.4005545036798892 0.5467103397159158 0.9397650349673574 0.7151918872797569 0.4432930376023336 0.3670428731605497
          0.8366799410811948 0.0360613100029110 0.4347749726828846 0.5884811425466829 0.8228931912295053 0.9170935543593193
          0.2961545640333596 0.2732926831299841 0.9472939210005341 0.2810176906539642 0.1689852192728417 0.2547729480887090
          0.7055972446574292 0.6443697547109174 0.7097035779964328 0.4225964301897521 0.1075410788025926 0.0499764048396870
          0.0573159852472062 0.3532450981171027 0.1347439306209732 0.7470273067071216 0.3857036581156064 0.5065059431067037
        </DataArray>
      </Points>
      <Cells>
        <DataArray Name="connectivity" type="Int32" format="ascii" NumberofComponents="1">
          1 2 3 4 5 6
          7 8 9 10 11 12
          13 14 15 16 17 18
          19 20
        </DataArray>
        <DataArray Name="offsets" type="Int32" format="ascii" NumberofComponents="1">
          1 2 3 4 5 6
          7 8 9 10 11 12
          13 14 15 16 17 18
          19 20
        </DataArray>
        <DataArray Name="types" type="UInt8" format="ascii" NumberofComponents="1">
          1 1 1 1 1 1
          1 1 1 1 1 1
          1 1 1 1 1 1
          1 1
        </DataArray>
      </Cells>
      <PointData Scalars="1_temp">
        <DataArray Name="1_temp" type="Float64" format="ascii" NumberofComponents="1">
          0.4204270035661765 0.9490145030363609 0.7864711816566549 0.4815468959885630 0.0119215535827562 0.0597207807092479
          0.8257177483439162 0.4046369872739349 0.0531531123171690 0.2596390482071086 0.2811506610562717 0.9433030410624577
          0.8936293596271191 0.2022892694899581 0.1003608087345019 0.5730430655359530 0.7453773741488717 0.6007604785160442
          0.9092395428890321 0.9385777624120453
        </DataArray>
        <DataArray Name="2_pressure" type="Float64" format="ascii" NumberofComponents="1">
          0.5890720970505128 0.3268986086578718 0.1448144482177102 0.2576384903723663 0.8574458883976873 0.6839737520406283
          0.9986326035811655 0.3194556656082242 0.4534082266242594 0.8676221777748950 0.6385221808378060 0.3318923019829476
          0.5419776327479333 0.1123238088406830 0.8165234436255825 0.2209316463478144 0.5149742681090496 0.5260877679247680
          0.2770886884732112 0.9044206316605501
        </DataArray>
      </PointData>
      <CellData>
      </CellData>
    </Piece>
  </UnstructuredGrid>
</VTKFile>

This looks correct to me, based on what I can see in in the documentation but I get an error when trying to open in ParaView.

ERROR: In C:\glr\builds\paraview\paraview-ci\build\superbuild\paraview\src\VTK\Common\Core\vtkPoints.cxx, line 166
vtkPoints (0000019324F41DF0): Number of components is different...can't set data

ERROR: In C:\glr\builds\paraview\paraview-ci\build\superbuild\paraview\src\VTK\IO\XML\vtkXMLReader.cxx, line 922
vtkXMLUnstructuredGridReader (0000019325100BE0): Array has 0 allocated elements, but 60 were requested to be read

ERROR: In C:\glr\builds\paraview\paraview-ci\build\superbuild\paraview\src\VTK\IO\XML\vtkXMLUnstructuredDataReader.cxx, line 504
vtkXMLUnstructuredGridReader (0000019325100BE0): Cannot read points array from Points in piece 0.  The data array in the element may be too short.

I’m afraid I don’t see what the problem is or what I have gotten wrong. Maybe someone can point out the error to me.

There appear to be some errors in capitalization. ( Name=“Point” and NumberOfComponents). Also, connectivity must be specified as integers beginning with zero.

<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <UnstructuredGrid>
    <Piece NumberOfCells="20" NumberOfPoints="20">
      <Points>
        <DataArray Name="Points" type="Float64" format="ascii" NumberOfComponents="3">
          0.9191090317991818 0.4523130130592968 0.4455559100158843 0.6421955999238554 0.1757747380313244 0.9770526614339072
          0.7537122297291767 0.0493769993144870 0.7293940090533850 0.1393145681027350 0.2924753386949548 0.3122350583311531
          0.0873195479896001 0.0667991310914613 0.8947552392940534 0.7880020580364918 0.7511564859911245 0.7832735951745574
          0.3261509370344888 0.0637715240806562 0.2620003413345412 0.5410678214759677 0.4319083194117714 0.3094831861549427
          0.2402351758680060 0.3641724134430167 0.1294506297724709 0.5454229255759049 0.1519715256925609 0.4221713562335928
          0.4005545036798892 0.5467103397159158 0.9397650349673574 0.7151918872797569 0.4432930376023336 0.3670428731605497
          0.8366799410811948 0.0360613100029110 0.4347749726828846 0.5884811425466829 0.8228931912295053 0.9170935543593193
          0.2961545640333596 0.2732926831299841 0.9472939210005341 0.2810176906539642 0.1689852192728417 0.2547729480887090
          0.7055972446574292 0.6443697547109174 0.7097035779964328 0.4225964301897521 0.1075410788025926 0.0499764048396870
          0.0573159852472062 0.3532450981171027 0.1347439306209732 0.7470273067071216 0.3857036581156064 0.5065059431067037
        </DataArray>
      </Points>
      <Cells>
        <DataArray Name="connectivity" type="Int32" format="ascii" NumberOfComponents="1">
          0 1 2 3 4 5
          6 7 8 9 10 11
          12 13 14 15 16 17
          18 19
        </DataArray>
        <DataArray Name="offsets" type="Int32" format="ascii" NumberOfComponents="1">
          1 2 3 4 5 6
          7 8 9 10 11 12
          13 14 15 16 17 18
          19 20
        </DataArray>
        <DataArray Name="types" type="UInt8" format="ascii" NumberOfComponents="1">
          1 1 1 1 1 1
          1 1 1 1 1 1
          1 1 1 1 1 1
          1 1
        </DataArray>
      </Cells>
      <PointData Scalars="1_temp">
        <DataArray Name="1_temp" type="Float64" format="ascii" NumberOfComponents="1">
          0.4204270035661765 0.9490145030363609 0.7864711816566549 0.4815468959885630 0.0119215535827562 0.0597207807092479
          0.8257177483439162 0.4046369872739349 0.0531531123171690 0.2596390482071086 0.2811506610562717 0.9433030410624577
          0.8936293596271191 0.2022892694899581 0.1003608087345019 0.5730430655359530 0.7453773741488717 0.6007604785160442
          0.9092395428890321 0.9385777624120453
        </DataArray>
        <DataArray Name="2_pressure" type="Float64" format="ascii" NumberOfComponents="1">
          0.5890720970505128 0.3268986086578718 0.1448144482177102 0.2576384903723663 0.8574458883976873 0.6839737520406283
          0.9986326035811655 0.3194556656082242 0.4534082266242594 0.8676221777748950 0.6385221808378060 0.3318923019829476
          0.5419776327479333 0.1123238088406830 0.8165234436255825 0.2209316463478144 0.5149742681090496 0.5260877679247680
          0.2770886884732112 0.9044206316605501
        </DataArray>
      </PointData>
      <CellData>
      </CellData>
    </Piece>
  </UnstructuredGrid>
</VTKFile>

Thanks! The capitalisation of NumberOfComponents was the culprit as I had been changing the connectivity to test that. Fresh eyes are brilliant for spotting simple things!