Computes the gravity effect of one (or two) grids by the method of Okabe


gmt grdgravmag3d grdfile_top [grdfile_bot] [ -Cdensity ] [ -Ethickness ] [ -Fxy_file ] [ -Goutgrid ] [ -Hargs ] [ -Iincrement ] [ -Lz_obs ] [ -Q[nn_pad]|[pad_dist]|[region] ] [ -Rregion ] [ -Sradius ] [ -V[level] ] [ -Zlevel[b|t] ] [ -fflags ] [ -x+a|n|-n ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.


grdgravmag3d will compute the gravity anomaly of a body described by one or (optionally) two grids The output can either be along a given set of xy locations or on a grid. This method is not particularly fast but allows computing the anomaly of arbitrarily complex shapes.

Required Arguments

grdfile_top [grdfile_bot]

Grid file whose gravity effect is going to be computed. If two grids are provided then the gravity/magnetic effect of the volume between them is computed.


Sets body density in SI. Append either a constant or the name of a grid file with variable densities. This option is mutually exclusive with -H


Provide locations where the anomaly will be computed. Note this option is mutually exclusive with -G.


Optionally, append =ID for writing a specific file format. The following modifiers are supported:

  • +d - Divide data values by given divisor [Default is 1].

  • +n - Replace data values matching invalid with a NaN.

  • +o - Offset data values by the given offset, or append a for automatic range offset to preserve precision for integer grids [Default is 0].

  • +s - Scale data values by the given scale, or append a for automatic scaling to preserve precision for integer grids [Default is 1].

Note: Any offset is added before any scaling. +sa also sets +oa (unless overridden). To write specific formats via GDAL, use =gd and supply driver (and optionally dataType) and/or one or more concatenated GDAL -co options using +c. See the “Writing grids and images” cookbook section for more details.

Optional Arguments


To provide the layer thickness in m [Default = 500 m].

-Hf_dec/f_dip/m_int/m_dec/m_dip -Hmagfile -Hx|y|z|h|t -H+i|g|r|f|n

Sets parameters for computation of magnetic anomaly (Can be used multiple times).

f_dec/f_dip -> geomagnetic declination/inclination

m_int/m_dec/m_dip -> body magnetic intensity/declination/inclination

OR for a grid mode

magfile, where magfile is the name of the magnetic intensity file.

To compute a component, specify any of:

x|X|e|E to compute the E-W component.

y|Y|n|N to compute the N-S component.

z|Z to compute the Vertical component.

h|H to compute the Horizontal component.

t|T|f|F to compute the total field.

If we want to compute the magnetic anomalies over a large region where the ambient magnetic field can no longer be assumed to be constant we can set variable inclinations and declinations via IGRF. Set any of -H+i|g|r|f|n to do that


Set the grid spacing as x_inc [and optionally y_inc].

Geographical (degrees) coordinates: Optionally, append an increment unit. Choose among:

  • d - Indicate arc degrees

  • m - Indicate arc minutes

  • s - Indicate arc seconds

If one of e (meter), f (foot), k (km), M (mile), n (nautical mile) or u (US survey foot), the the increment will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on PROJ_ELLIPSOID). If y_inc is not given or given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude.

All coordinates: The following modifiers are supported:

  • +e - Slightly adjust the max x (east) or y (north) to fit exactly the given increment if needed [Default is to slightly adjust the increment to fit the given domain].

  • +n - Define the number of nodes rather than the increment, in which case the increment is recalculated from the number of nodes, the registration (see GMT File Formats), and the domain. Note: If -Rgrdfile is used then the grid spacing and the registration have already been initialized; use -I and -R to override these values.


Sets level of observation [Default = 0]. That is the height (z) at which anomalies are computed.

Extend the domain of computation with respect to output -R region.

-Qnn_pad artificially extends the width of the outer rim of cells to have a fake width of n_pad * dx[/dy].

-Qpad_dist extend the region by west-pad, east+pad, etc.

-Qregion Same syntax as -R.


Specify the region of interest. Note: This overrides the source grid region (Default: use same region as input) (See full description) (See cookbook information).


Set search radius in km (valid only in the two grids mode OR when -E) [Default = 30 km]. This option serves to speed up the computation by not computing the effect of prisms that are further away than radius from the current node.


Select verbosity level [w]. (See full description) (See cookbook information).


level of reference plane [Default = 0]. Use this option when the triangles describe a non-closed surface and the volume is defined from each triangle and this reference level. An example will be the water depth to compute a Bouguer anomaly. Use -Zb or Zt to close the body at its bottom (for example, to compute the effect of a dome) or at its top (to compute the effect of a spoon).


Geographic grids (dimensions of longitude, latitude) will be converted to meters via a “Flat Earth” approximation using the current ellipsoid parameters.


Choose the number of processors used in multi-threading (Only available with multi-threading builds).

+a Use all available processors.

n Use n processors (not more than max available off course).

-n Use (all - n) processors.

-^ or just -

Print a short message about the syntax of the command, then exit (Note: on Windows just use -).

-+ or just +

Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.

-? or no arguments

Print a complete usage (help) message, including the explanation of all options, then exit.


Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.

Grid Distance Units

If the grid does not have meter as the horizontal unit, append +uunit to the input file name to convert from the specified unit to meter. If your grid is geographic, convert distances to meters by supplying -fflags instead.


Suppose you want to compute the gravity effect of the phantom “Sandy Island” together with its not phantom seamount

gmt grdgravmag3d sandy_bat.grd -C1700 -Z-4300 -fg -I1m -Gsandy_okb.grd -V

To compute the vertical component due to a magnetization stored in mag.grd over a zone defined by the surface bat.grd, using variable declination and inclination provided the IGRF and using 4 processors, do:

gmt grdgravmag3d bat.grd -E10000 -Gcomp_Z.grd -Hz -H+n -H+mmag.grd -x4 -V -S50

See Also

gmt, gmtgravmag3d, talwani2d, talwani3d


Okabe, M., 1979, Analytical expressions for gravity anomalies due to polyhedral bodies and translation into magnetic anomalies, Geophysics, 44, 730-741.