I have data that is a set of triangles with a value assigned to each triangle that I would like to contour. One way to do that is to convert the data to a regular grid. This is output from a fault slip model. I looked at the GMT functions contour and triangulate, but those are for data measured at points so they do new triangulations and then interpolate between the points. I already have triangles and the values are for the triangles, not the vertices.

One of the functions of the modeling software that I use writes out the triangles with their “Z” values in a text format that can be plotted with the GMT psxy -C$cpt command (see below), but I wonder if there is a way to make a regular grid out of the “Z” values. Do I have to convert the triangles that I have back to a set of points that are the centroids of each triangular patch and then put that into the regular gridding functions of GMT?

Generally yes. In your case (relatively small number of points), I would use greenspline since you can use your centroid (x,y,z) values directly as constraints (i.e. no blockm* need) and pick whatever output -R -I you want. You can even give it a mask grid to limit extrapolations outside your bounding polygon, or deal with that later via grdmask and grdmath.

Since you compute the values at centroids, can you know also the values at the vertices? If yes, you could feed that network information directly to pscontour and it would do the contouring without further need to triangulate it again.

The model fault slip value is the slip for the whole triangular patch, but I could approximate it as being at the centroid. There are no values at the vertices as those are discontinuities.

Thanks, I did not know about greenspline. It looks like that will work well for the interpolation when I write out the slip values at the centroids.

I did not mention earlier that my values are actually (x,y,z,slip) or (x,y,z,w) as the fault model is a 3-D surface represented by triangular patches. In this particular case, the fault dip is shallow, so interpolating (x,y,slip) should be reasonable for a map view. I see that greenspline also has a 3D option, so I might try that also.