# EnSight reader example (C++)

**URL:** https://discourse.vtk.org/t/ensight-reader-example-c/2799
**Category:** Support
**Created:** [March 10, 2020, 9:21pm UTC](https://discourse.vtk.org/t/ensight-reader-example-c/2799 "2020-03-10T21:21:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![floF](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@floF](https://discourse.vtk.org/u/floF)
#### Post date: [March 10, 2020, 9:21pm UTC](https://discourse.vtk.org/t/ensight-reader-example-c/2799/1 "2020-03-10T21:21:43Z")

</div>

Hello,

I’m trying to read EnSight Gold data using the VTK library for C++.

Unfortunately I didn’t find any example for this files type, and since my global knowledge in C++ is far from being perfect, I didn’t managed so far to solve my issues by going through the VTK manual…

Here is what I did… and which worked 🙂

> #include \<vtkSmartPointer.h\>  
> #include \<vtkGenericEnSightReader.h\>
> 
> #include \<vtkProperty.h\>  
> #include \<vtkCellCenters.h\>
> 
> int main ( int argc, char \*argv )  
> {  
> //parse command line arguments  
> if(argc \< 2)  
> {  
> std::cerr \<\< “Usage: " \<\< argv[0]  
> \<\< " Filename(.case)” \<\< std::endl;  
> return EXIT\_FAILURE;  
> }
> 
> std::string filename = argv[1];
> 
> //read all the data from the file  
> vtkSmartPointer reader =  
> vtkSmartPointer::New();  
> reader-\>SetCaseFileName(filename.c\_str());  
> reader-\>Update();
> 
> //Check for data content  
> reader-\>PrintSelf(std::cout, vtkIndent(2));
> 
> return EXIT\_SUCCESS;  
> }

My goal would be

- First, to extract the cell center coordinates for each cells (the CellCenter filter might be helpful, but I wasn’t able to push data into it…)
- Go through every scalar and vector data (Cell Data) for every cell, one time step at a time

If needed to better understand my case study, here the case file of my data:

> FORMAT  
> type: ensight gold
> 
> GEOMETRY  
> model: square.geo
> 
> VARIABLE  
> scalar per element: 1 Pressure square.pressure.\*\*\*\*\*  
> vector per element: 1 U1 square.u1.\*\*\*\*\*
> 
> TIME  
> time set: 1  
> number of steps: 3  
> filename start number: 1  
> filename increment: 1  
> time values:  
> 0  
> 10  
> 20

Thank you very much for your help, I’m tried anything possible for a week but I think I reached the maximum of what I can achieve by myself 🙂

---

<div class="post-metadata">

### Author: ![floF](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@floF](https://discourse.vtk.org/u/floF)
#### Post date: [March 21, 2020, 3:31pm UTC](https://discourse.vtk.org/t/ensight-reader-example-c/2799/2 "2020-03-21T15:31:31Z")

</div>

Up !

Since last time I managed to extract scalar data from a given cell, but it is the dirtiest way and I’m pretty sure there is a cleaner way to do it using vtk specific tools (filters, pipelines …)

> //Select iteration 3  
> int itime = 3;  
> reader-\>SetTimeValue(m\_reader-\>GetTimeSets()-\>GetItem(0)-\>GetTuple1(itime));  
> reader-\>Update();  
> // Ouptut scalar pressure of cell 1000  
> vtkSmartPointer pressure = reader-\>GetOutput()-\>GetBlock(0)-\>GetAttributes(vtkCompositeDataSet::CELL)-\>GetScalars (“pressure”);

int icell = 1000;  
cout \<\< pressure-\>GetTuple1(icell) \<\< endl;
