# Import and interpolate data.txt

**URL:** https://community.freefem.org/t/import-and-interpolate-data-txt/2118
**Category:** General Discussion
**Created:** [November 14, 2022, 4:28pm UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118 "2022-11-14T16:28:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)
#### Post date: [November 14, 2022, 4:28pm UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/1 "2022-11-14T16:28:45Z")

</div>

Hi,  
I would like to know how to import and interpolate on my mesh a data (array) of type txt in freefem++. I haven’t seen an example like this in the documentation.  
Thanks

---

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [November 14, 2022, 9:21pm UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/2 "2022-11-14T21:21:57Z")

</div>

I think you can use the `triangulate` function to create a 2D mesh from a set of points. Then, you can define a `P1` FE space, and assign the function values at the corresponding points to a FE variable.

---

<div class="post-metadata">

### Author: ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)
#### Post date: [November 15, 2022, 8:05am UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/3 "2022-11-15T08:05:34Z")

</div>

Thank you very much, I will do it as you said.

---

<div class="post-metadata">

### Author: ![qingYang](https://avatars.discourse-cdn.com/v4/letter/q/9f8e36/32.png) [@qingYang](https://community.freefem.org/u/qingYang)
#### Post date: [December 21, 2023, 9:18am UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/4 "2023-12-21T09:18:57Z")

</div>

Dear, I imported grid data and created a 2D Th using the method you mentioned, but all regions and label inTh are zero. How should I handle this? I want to use this Th to build a layer grid

---

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [December 21, 2023, 11:04am UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/5 "2023-12-21T11:04:20Z")

</div>

Without more information, it is impossible to help. Maybe you could create multiple meshes and fuse them by adding them.

I also suggest you look around in the forum where you can find a lot of information about changing the labels of meshes.

---

<div class="post-metadata">

### Author: ![qingYang](https://avatars.discourse-cdn.com/v4/letter/q/9f8e36/32.png) [@qingYang](https://community.freefem.org/u/qingYang)
#### Post date: [December 21, 2023, 11:53am UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/6 "2023-12-21T11:53:05Z")

</div>

dear, I am a beginner， I’m sorry about my description is not clear.  
What I want to do is as follows: 1.import a 3D mesh, take out the upper surface nodes and their x-axis and y-axis coordinates: nv (x, y); 2.then use the “triangle” function to reconstruct a 2D mesh, and 3.finally use the Th mesh to construct a layer mesh. The problem I am currently facing is that the 2D mesh region and label I have reconstructed are both 0, so I am unable to build layermesh. Thank you again for your help  
My code is as follows：

mesh3 Th3F = readmesh3(“test3Dint.msh”);  
real xx,yy,zz;  
real ZZ=0.05;//the upper surface of 3D mesh  
int j=0;  
real [int] xt(1188),yt(1188); //the nv number of the upper surface  
for( int i=0;i\<Th3F.nv;i++){  
xx=Th3F(i).x;  
yy=Th3F(i).y;  
zz=Th3F(i).z;  
if(zz==ZZ){  
xt[j]=xx;  
yt[j]=yy;  
j=j+1;  
}  
}  
mesh Th=triangulate(xt,yt);  
int[int] regs = regions(Th);  
int[int] labs = labels(Th);  
cout \<\< "Th region number: " \<\< regs \<\< " \nTh labels number: " \<\< labs \<\<endl;  
reuslt:

 ![12.21](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/0568cd19b325345aba5cc2684f41240945aa7a03.png)

---

<div class="post-metadata">

### Author: ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)
#### Post date: [December 22, 2023, 12:37pm UTC](https://community.freefem.org/t/import-and-interpolate-data-txt/2118/7 "2023-12-22T12:37:24Z")

</div>

This video may interest you.

[![](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/9/98f106dcc2447df9babb6b480dedd26ae6d65b66.jpeg "Methods used for Boundary Layer Mesh Generation in Ansys Fluent Meshing Watertight Geometry Workflow") ](https://www.youtube.com/watch?v=t2vWSvbWHGQ&t=14s)

Or

[![](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/051e1f61d34996176016e8ba82a72bde98dbb79c.jpeg "Where to Add Boundary Layers in Ansys Fluent Meshing Watertight Geometry Workflow") ](https://www.youtube.com/watch?v=njtj9FloM7g)
