Skip to content

Commit a2cdd44

Browse files
authored
Fix a bug in assigning the center coordinates of sphere bodies. (#8679)
* Fix a bug in assigning the center coordinates of sphere bodies. * Change error message * Fix an issue with 'ellipsoid' too.
1 parent 07f03ae commit a2cdd44

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/potential/gmtgravmag3d.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
333333
if (n_par < 8) Ctrl->M.params[BELL][nBELL][7] = Ctrl->npts_circ;
334334
if (n_par < 9) Ctrl->M.params[BELL][nBELL][8] = Ctrl->n_slices;
335335
if (Ctrl->M.params[BELL][nBELL][6] || Ctrl->M.params[SPHERE][nSPHERE][7] <= 0 || Ctrl->M.params[SPHERE][nSPHERE][8] <= 0) {
336-
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'bell' body. Please, RTFM (read the manual).");
336+
GMT_Report(API, GMT_MSG_ERROR, "Bad parameters for the 'bell' body. Please, read the manual.");
337337
return GMT_PARSE_ERROR;
338338
}
339339
Ctrl->M.type[BELL][nBELL] = BELL;
@@ -344,7 +344,7 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
344344
if (n_par < 3) err_npar = 1;
345345
if (n_par < 6) Ctrl->M.params[CYLINDER][nCIL][5] = Ctrl->npts_circ;
346346
if (Ctrl->M.params[SPHERE][nSPHERE][5] <= 0) {
347-
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'cylinder' body. Please, RTFM (read the manual).");
347+
GMT_Report(API, GMT_MSG_ERROR, "Bad parameters for the 'cylinder' body. Please, read the manual.");
348348
return GMT_PARSE_ERROR;
349349
}
350350
Ctrl->M.type[CYLINDER][nCIL] = CYLINDER;
@@ -362,8 +362,8 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
362362
if (n_par < 4) err_npar = 1;
363363
if (n_par < 7) Ctrl->M.params[ELLIPSOID][nELL][6] = Ctrl->npts_circ;
364364
if (n_par < 8) Ctrl->M.params[ELLIPSOID][nELL][7] = Ctrl->n_slices;
365-
if (Ctrl->M.params[SPHERE][nSPHERE][6] <= 0 || Ctrl->M.params[SPHERE][nSPHERE][7] <= 0) {
366-
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'ellipsoid' body. Please, RTFM (read the manual).");
365+
if (Ctrl->M.params[ELLIPSOID][nELL][6] <= 0 || Ctrl->M.params[ELLIPSOID][nELL][7] <= 0) {
366+
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'ellipsoid' body. Please, read the manual.");
367367
return GMT_PARSE_ERROR;
368368
}
369369
Ctrl->M.type[ELLIPSOID][nELL] = ELLIPSOID;
@@ -387,7 +387,7 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
387387
if (n_par < 5) Ctrl->M.params[SPHERE][nSPHERE][4] = Ctrl->npts_circ;
388388
if (n_par < 6) Ctrl->M.params[SPHERE][nSPHERE][5] = Ctrl->n_slices;
389389
if (Ctrl->M.params[SPHERE][nSPHERE][4] <= 0 || Ctrl->M.params[SPHERE][nSPHERE][5] <= 0) {
390-
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'sphere' body. Please, RTFM (read the manual).");
390+
GMT_Report (API, GMT_MSG_ERROR, "Bad parameters for the 'sphere' body. Please, read the manual.");
391391
return GMT_PARSE_ERROR;
392392
}
393393
Ctrl->M.type[SPHERE][nSPHERE] = SPHERE;

src/potential/solids.c

+8
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ int five_psoid(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, int body_ty
143143
a = Ctrl->M.params[body_type][nb][0]; b = Ctrl->M.params[body_type][nb][1];
144144
c = Ctrl->M.params[body_type][nb][2]; z_c = Ctrl->M.params[body_type][nb][3];
145145
x0 = Ctrl->M.params[body_type][nb][4]; y0 = Ctrl->M.params[body_type][nb][5];
146+
if (body_type == SPHERE) { /* This has less parameters so the above is wrong. */
147+
b = c = a; z_c = Ctrl->M.params[body_type][nb][1];
148+
x0 = Ctrl->M.params[body_type][nb][2]; y0 = Ctrl->M.params[body_type][nb][3];
149+
}
150+
if (body_type == BELL) {
151+
a = b; b = c; c = Ctrl->M.params[body_type][nb][0];
152+
}
153+
146154
z_top = z_c + c; z_bot = z_c;
147155

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

0 commit comments

Comments
 (0)