# Convert a tesseroid model to prisms and calculate in Cartesian coordinatesΒΆ

The `tess2prism_flatten.sh`

script
converts a tesseroid model to prisms
(using the `--flatten`

flag in `tessmodgen`

) and
calculates the gravitational potential, gravitational attraction,
and gravity gradient tensor
in Cartesian coordinates:

```
#!/bin/bash
# Generate a prism model from a tesseroid model by
# flattening the tesseroids (1 degree = 111.11 km).
# This way the converted prisms can be used
# with the prism* programs in Cartesian coordinates.
tess2prism --flatten < tess-model.txt > prism-model.txt
# Generate a regular grid in Cartesian coordinates,
# pipe the grid to the computation programs,
# and dump the result on output.txt
tessgrd -r-3e06/3e06/-3e06/3e06 -b50/50 -z250e03 | \
prismpot prism-model.txt | \
prismgx prism-model.txt | \
prismgy prism-model.txt | \
prismgz prism-model.txt | \
prismgxx prism-model.txt | prismgxy prism-model.txt | \
prismgxz prism-model.txt | prismgyy prism-model.txt | \
prismgyz prism-model.txt | prismgzz prism-model.txt > output.txt
```

The tesseroid model file looks like this:

```
# Test tesseroid model file
10 15 10 15 0 -30000 500
-15 -10 -10 10 0 -50000 200
-15 5 -16 -10 0 -30000 -300
```

and the converted prism model looks like this:

```
# Prisms converted from tesseroid model with tess2prism 1.1dev
# local time: Tue May 8 14:55:02 2012
# tesseroids file: stdin
# conversion type: flatten
# format: x1 x2 y1 y2 z1 z2 density
# Test tesseroid model file
1111100 1666650 1111100 1666650 0 30000 487.534658568521
-1111100 1111100 -1666650 -1111100 0 50000 198.175508383774
-1777760 -1111100 -1666650 555550 0 30000 -291.9029748328
```

Note that the density of prisms is altered. This is so that the tesseroid and corresponding prism have the same mass.

The result should look like the following (“column” means the column of the output file).