Skip to content

Commit

Permalink
Fix a bug in assigning the center coordinates of sphere bodies. (#8679)
Browse files Browse the repository at this point in the history
* Fix a bug in assigning the center coordinates of sphere bodies.

* Change error message

* Fix an issue with 'ellipsoid' too.
  • Loading branch information
joa-quim authored Jan 22, 2025
1 parent 07f03ae commit a2cdd44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/potential/gmtgravmag3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
if (n_par < 8) Ctrl->M.params[BELL][nBELL][7] = Ctrl->npts_circ;
if (n_par < 9) Ctrl->M.params[BELL][nBELL][8] = Ctrl->n_slices;
if (Ctrl->M.params[BELL][nBELL][6] || Ctrl->M.params[SPHERE][nSPHERE][7] <= 0 || Ctrl->M.params[SPHERE][nSPHERE][8] <= 0) {
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'bell' body. Please, RTFM (read the manual).");
GMT_Report(API, GMT_MSG_ERROR, "Bad parameters for the 'bell' body. Please, read the manual.");
return GMT_PARSE_ERROR;
}
Ctrl->M.type[BELL][nBELL] = BELL;
Expand All @@ -344,7 +344,7 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
if (n_par < 3) err_npar = 1;
if (n_par < 6) Ctrl->M.params[CYLINDER][nCIL][5] = Ctrl->npts_circ;
if (Ctrl->M.params[SPHERE][nSPHERE][5] <= 0) {
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'cylinder' body. Please, RTFM (read the manual).");
GMT_Report(API, GMT_MSG_ERROR, "Bad parameters for the 'cylinder' body. Please, read the manual.");
return GMT_PARSE_ERROR;
}
Ctrl->M.type[CYLINDER][nCIL] = CYLINDER;
Expand All @@ -362,8 +362,8 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
if (n_par < 4) err_npar = 1;
if (n_par < 7) Ctrl->M.params[ELLIPSOID][nELL][6] = Ctrl->npts_circ;
if (n_par < 8) Ctrl->M.params[ELLIPSOID][nELL][7] = Ctrl->n_slices;
if (Ctrl->M.params[SPHERE][nSPHERE][6] <= 0 || Ctrl->M.params[SPHERE][nSPHERE][7] <= 0) {
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'ellipsoid' body. Please, RTFM (read the manual).");
if (Ctrl->M.params[ELLIPSOID][nELL][6] <= 0 || Ctrl->M.params[ELLIPSOID][nELL][7] <= 0) {
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'ellipsoid' body. Please, read the manual.");
return GMT_PARSE_ERROR;
}
Ctrl->M.type[ELLIPSOID][nELL] = ELLIPSOID;
Expand All @@ -387,7 +387,7 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
if (n_par < 5) Ctrl->M.params[SPHERE][nSPHERE][4] = Ctrl->npts_circ;
if (n_par < 6) Ctrl->M.params[SPHERE][nSPHERE][5] = Ctrl->n_slices;
if (Ctrl->M.params[SPHERE][nSPHERE][4] <= 0 || Ctrl->M.params[SPHERE][nSPHERE][5] <= 0) {
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'sphere' body. Please, RTFM (read the manual).");
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'sphere' body. Please, read the manual.");
return GMT_PARSE_ERROR;
}
Ctrl->M.type[SPHERE][nSPHERE] = SPHERE;
Expand Down
8 changes: 8 additions & 0 deletions src/potential/solids.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ int five_psoid(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, int body_ty
a = Ctrl->M.params[body_type][nb][0]; b = Ctrl->M.params[body_type][nb][1];
c = Ctrl->M.params[body_type][nb][2]; z_c = Ctrl->M.params[body_type][nb][3];
x0 = Ctrl->M.params[body_type][nb][4]; y0 = Ctrl->M.params[body_type][nb][5];
if (body_type == SPHERE) { /* This has less parameters so the above is wrong. */
b = c = a; z_c = Ctrl->M.params[body_type][nb][1];
x0 = Ctrl->M.params[body_type][nb][2]; y0 = Ctrl->M.params[body_type][nb][3];
}
if (body_type == BELL) {
a = b; b = c; c = Ctrl->M.params[body_type][nb][0];
}

z_top = z_c + c; z_bot = z_c;

n_tri = (hemi) ? 2 * npts_circ * n_slices : 2 * (npts_circ * (n_slices*2 - 1));
Expand Down

0 comments on commit a2cdd44

Please sign in to comment.