Skip to content

Commit

Permalink
Merge branch 'master' into longopts-gmtspatial
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWessel committed Nov 24, 2023
2 parents ba2f199 + 1190187 commit 8f9dcae
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 26 deletions.
14 changes: 7 additions & 7 deletions src/geodesy/earthtide.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ GMT_LOCAL void earthtide_solid_grd (struct GMT_CTRL *GMT, struct EARTHTIDE_CTRL
int k, mjd, year, month, day, hour, min;
uint32_t row, col, n_columns = 0, n_rows = 0;
size_t ij_n = 0, ij_e = 0, ij_u = 0, n_inc = 0, e_inc = 0, u_inc = 0;
float *grd_n, *grd_e, *grd_u;
gmt_grdfloat *grd_n, *grd_e, *grd_u;
double fmjd, xsta[3], rsun[3], etide[3], rmoon[3];
double lat, ut, vt, wt, *lons;
double west = 0, south = 0, x_inc = 0, y_inc = 0;
Expand All @@ -1122,21 +1122,21 @@ GMT_LOCAL void earthtide_solid_grd (struct GMT_CTRL *GMT, struct EARTHTIDE_CTRL
e_inc = 1;
}
else
grd_e = (float *)malloc (1 * sizeof (float));
grd_e = (gmt_grdfloat *)malloc (1 * sizeof (gmt_grdfloat));

if (Ctrl->G.do_north) {
grd_n = Grid[Y_COMP]->data;
n_inc = 1;
}
else
grd_n = (float *)malloc (1 * sizeof (float));
grd_n = (gmt_grdfloat *)malloc (1 * sizeof (gmt_grdfloat));

if (Ctrl->G.do_up) {
grd_u = Grid[Z_COMP]->data;
u_inc = 1;
}
else
grd_u = (float *)malloc (1 * sizeof (float));
grd_u = (gmt_grdfloat *)malloc (1 * sizeof (gmt_grdfloat));

/* Get header params. Since all three have the same dims we stop when we find the first grid required */
for (k = 0; k < N_COMPS; k++) {
Expand Down Expand Up @@ -1171,9 +1171,9 @@ GMT_LOCAL void earthtide_solid_grd (struct GMT_CTRL *GMT, struct EARTHTIDE_CTRL
earthtide_detide (xsta, mjd, fmjd, rsun, rmoon, etide, &leapflag);
/* determine local geodetic horizon components (topocentric) */
earthtide_rge (lat, lons[col], &ut, &vt, &wt, etide[0], etide[1], etide[2]); /* tide vect */
grd_n[ij_n] = (float)vt;
grd_e[ij_e] = (float)ut;
grd_u[ij_u] = (float)wt;
grd_n[ij_n] = (gmt_grdfloat)vt;
grd_e[ij_e] = (gmt_grdfloat)ut;
grd_u[ij_u] = (gmt_grdfloat)wt;
ij_n += n_inc;
ij_e += e_inc;
ij_u += u_inc;
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_customio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ void gmtlib_encode (struct GMT_CTRL *GMT, void *vptr, uint64_t k, gmt_grdfloat z
((int *)vptr)[k] = (int)lrintf (z);
break;
case 'f':
((float *)vptr)[k] = (float)z;
((gmt_grdfloat *)vptr)[k] = z;
break;
case 'd':
((double *)vptr)[k] = (double)z;
Expand Down
8 changes: 4 additions & 4 deletions src/gmt_gdalcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ GMT_LOCAL int save_grid_with_GMT(struct GMT_CTRL *GMT, GDALDatasetH hDstDS, stru
return -1;
}

if (nPixelSize != sizeof(float)) { /* If outdata type is not 4 bytes, must create a tmp to copy from because GMT requires floats */
if (nPixelSize != sizeof(gmt_grdfloat)) { /* If outdata type is not 4 bytes, must create a tmp to copy from because GMT requires floats */
size_t k;
if ((tmp = calloc(Grid->header->nm, sizeof(float))) == NULL) {
if ((tmp = calloc(Grid->header->nm, sizeof(gmt_grdfloat))) == NULL) {
GMT_Report (GMT->parent, GMT_MSG_ERROR, "grdgdal: failure to allocate temporary memory\n");
return -1;
}
Expand All @@ -205,7 +205,7 @@ GMT_LOCAL int save_grid_with_GMT(struct GMT_CTRL *GMT, GDALDatasetH hDstDS, stru
return -1;
}
for (k = 0; k < Grid->header->nm; k++)
Grid->data[k] = (float)tmp[k];
Grid->data[k] = (gmt_grdfloat)tmp[k];

free(tmp);
}
Expand All @@ -221,7 +221,7 @@ GMT_LOCAL int save_grid_with_GMT(struct GMT_CTRL *GMT, GDALDatasetH hDstDS, stru
data comes upside-down as comparing to what it used to do. But since that in fact helps
us since we no longer need to a flipud, we did not complain to GDAL dev. */
#if (GDAL_VERSION_MAJOR < 3 && GDAL_VERSION_MINOR < 6)
gmt_grd_flip_vertical (Grid->data, (unsigned)nXSize, (unsigned)nYSize, 0, sizeof(float));
gmt_grd_flip_vertical (Grid->data, (unsigned)nXSize, (unsigned)nYSize, 0, sizeof(gmt_grdfloat));
#endif

if (GMT_Write_Data (GMT->parent, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA,
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_grdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ size_t gmtlib_grd_data_size (struct GMT_CTRL *GMT, unsigned int format, gmt_grdf
return (sizeof (int32_t));
break;
case 'f':
return (sizeof (float));
return (sizeof (gmt_grdfloat));
break;
case 'd':
return (sizeof (double));
Expand Down
2 changes: 2 additions & 0 deletions src/gmt_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ GMT_LOCAL int gmtio_L_read_swab (struct GMT_CTRL *GMT, FILE *fp, uint64_t n, dou

/*! . */
GMT_LOCAL int gmtio_f_read (struct GMT_CTRL *GMT, FILE *fp, uint64_t n, double *d) {
/* Not gmt_grdfloat since applies to tables */
/* read float */
uint64_t i;
size_t k;
Expand Down Expand Up @@ -1845,6 +1846,7 @@ GMT_LOCAL int gmtio_L_write_swab (struct GMT_CTRL *GMT, FILE *fp, uint64_t n, do
/*! . */
GMT_LOCAL int gmtio_f_write (struct GMT_CTRL *GMT, FILE *fp, uint64_t n, double *d) {
/* write float */
/* Not gmt_grdfloat since applies to tables */
uint64_t i;
gmt_M_unused(GMT);
for (i = 0; i < n; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/gmt_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -8389,7 +8389,7 @@ int gmt_grd_project (struct GMT_CTRL *GMT, struct GMT_GRID *I, struct GMT_GRID *
struct GMT_GRID *G = NULL;
if ((G = GMT_Create_Data (GMT->parent, GMT_IS_GRID, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, O->header->wesn, O->header->inc, \
O->header->registration, GMT_PAD_DEFAULT, NULL)) == NULL) goto bail_grd_dbg;
for (k = 0; k < G->header->size; k++) G->data[k] = (float)nz[k];
for (k = 0; k < G->header->size; k++) G->data[k] = (gmt_grdfloat)nz[k];
(void) GMT_Write_Data (GMT->parent, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, "nz_grd_counter.grd", G);
GMT_Report (GMT->parent, GMT_MSG_NOTICE, "gmt_grd_project: Antialias counter nz written to grid file nz_grd_counter.grd\n");
GMT_Destroy_Data (GMT->parent, &G);
Expand Down Expand Up @@ -8618,7 +8618,7 @@ int gmt_img_project (struct GMT_CTRL *GMT, struct GMT_IMAGE *I, struct GMT_IMAGE
struct GMT_GRID *G = NULL;
if ((G = GMT_Create_Data (GMT->parent, GMT_IS_GRID, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, O->header->wesn, O->header->inc, \
O->header->registration, GMT_PAD_DEFAULT, NULL)) == NULL) goto bail_img_dbg;
for (k = 0; k < G->header->size; k++) G->data[k] = (float)nz[k];
for (k = 0; k < G->header->size; k++) G->data[k] = (gmt_grdfloat)nz[k];
(void) GMT_Write_Data (GMT->parent, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, "nz_img_counter.grd", G);
GMT_Report (GMT->parent, GMT_MSG_NOTICE, "gmt_grd_project: Antialias counter nz written to grid file nz_img_counter.grd\n");
GMT_Destroy_Data (GMT->parent, &G);
Expand Down
17 changes: 14 additions & 3 deletions src/gmt_plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -10829,7 +10829,7 @@ struct GMT_POSTSCRIPT * gmt_get_postscript (struct GMT_CTRL *GMT) {
return (P);
}

void gmt_plot_image_graticules (struct GMT_CTRL *GMT, struct GMT_GRID *G, struct GMT_GRID *I, struct GMT_PALETTE *P, struct GMT_PEN *pen, bool skip, double *intensity) {
void gmt_plot_image_graticules (struct GMT_CTRL *GMT, struct GMT_GRID *G, struct GMT_GRID *I, struct GMT_PALETTE *P, struct GMT_PEN *pen, bool skip, double *intensity, bool grdview) {
/* Lay down an image using polygons of the graticules. This is recoded from grdview
* so it can also be used in grdimage.
* G is the data grid
Expand Down Expand Up @@ -10874,8 +10874,19 @@ void gmt_plot_image_graticules (struct GMT_CTRL *GMT, struct GMT_GRID *G, struct
gmt_illuminate (GMT, *intensity, fill.rgb);
n = gmt_graticule_path (GMT, &xx, &yy, 1, true, G->x[col] - inc2[GMT_X], G->x[col] + inc2[GMT_X], G->y[row] - inc2[GMT_Y], G->y[row] + inc2[GMT_Y]);
gmt_setfill (GMT, &fill, outline);
S->data[GMT_X] = xx; S->data[GMT_Y] = yy; S->n_rows = n;
gmt_geo_polygons (GMT, S);
if (GMT->current.proj.three_D && grdview) { /* Deal with grdview */
uint64_t k;
double xp, yp;
for (k = 0; k < n; k++) {
gmt_geoz_to_xy (GMT, xx[k], yy[k], G->data[ij], &xp, &yp);
xx[k] = xp; yy[k] = yp;
}
PSL_plotpolygon (GMT->PSL, xx, yy, n);
}
else { /* 2-D, most likely grdimage w/wo -p */
S->data[GMT_X] = xx; S->data[GMT_Y] = yy; S->n_rows = n;
gmt_geo_polygons (GMT, S);
}
gmt_M_free (GMT, xx);
gmt_M_free (GMT, yy);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ EXTERN_MSC struct GMT_GRID * gmt_duplicate_grid (struct GMT_CTRL *GMT, struct GM

EXTERN_MSC int gmt_two_curve_fill (struct GMT_CTRL *GMT, struct GMT_DATASEGMENT *S1, struct GMT_DATASEGMENT *S2, struct GMT_FILL *F1, struct GMT_FILL *F2, struct GMT_PEN *P1, struct GMT_PEN *P2, struct GMT_PEN *P3, char *sec_label);
EXTERN_MSC void gmt_plot_timex_grid (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double w, double e, double s, double n, unsigned int item);
EXTERN_MSC void gmt_plot_image_graticules (struct GMT_CTRL *GMT, struct GMT_GRID *G, struct GMT_GRID *I, struct GMT_PALETTE *P, struct GMT_PEN *pen, bool skip, double *intensity);
EXTERN_MSC void gmt_plot_image_graticules (struct GMT_CTRL *GMT, struct GMT_GRID *G, struct GMT_GRID *I, struct GMT_PALETTE *P, struct GMT_PEN *pen, bool skip, double *intensity, bool grdview);
EXTERN_MSC double gmt_inch_to_degree_scale (struct GMT_CTRL *GMT, double lon0, double lat0, double azimuth);
EXTERN_MSC bool gmt_text_is_latex (struct GMT_CTRL *GMT, const char *string);
EXTERN_MSC void gmt_map_text (struct GMT_CTRL *GMT, double x, double y, struct GMT_FONT *font, char *label, double angle, int just, unsigned int form);
Expand Down
2 changes: 1 addition & 1 deletion src/grdimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ EXTERN_MSC int GMT_grdimage (void *V_API, int mode, void *args) {

if (Ctrl->T.active) { /* Plot colored graticules instead */
need_to_project = false; /* Since we are not doing reprojection of the grid */
gmt_plot_image_graticules (GMT, Grid_orig, Intens_orig, P, (Ctrl->T.outline) ? &Ctrl->T.pen : NULL, Ctrl->T.skip, Ctrl->I.constant ? &Ctrl->I.value : NULL);
gmt_plot_image_graticules (GMT, Grid_orig, Intens_orig, P, (Ctrl->T.outline) ? &Ctrl->T.pen : NULL, Ctrl->T.skip, Ctrl->I.constant ? &Ctrl->I.value : NULL, false);
goto basemap_and_free; /* Skip all the image projection and just overlay basemap and free memory */
}

Expand Down
4 changes: 2 additions & 2 deletions src/grdinterpolate.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ EXTERN_MSC int GMT_grdinterpolate (void *V_API, int mode, void *args) {
So = Out->table[0]->segment[seg]; /* Short hand to this output segment */
for (row = 0; row < So->n_rows; row++) {
ij = gmt_M_ijp (Grid->header, So->n_rows-row-1, seg); /* Must flip order since rows in grid goes down */
Grid->data[ij] = (float)So->data[3][row];
Grid->data[ij] = (gmt_grdfloat)So->data[3][row];
}
}
if (GMT_Destroy_Data (API, &Out) != GMT_OK) {
Expand Down Expand Up @@ -888,7 +888,7 @@ EXTERN_MSC int GMT_grdinterpolate (void *V_API, int mode, void *args) {
i_value[k] = C[GMT_IN]->data[node+k*C[GMT_IN]->header->size];
gmt_intpol (GMT, C[GMT_IN]->z, i_value, NULL, C[GMT_IN]->header->n_bands, n_layers, level, o_value, 0.0, int_mode); /* Resample at requested output levels */
for (k = 0; k < n_layers; k++) /* For all output levels, place the interpolated values at this (x,y) across all levels */
C[GMT_OUT]->data[node+k*C[GMT_OUT]->header->size] = (float)o_value[k];
C[GMT_OUT]->data[node+k*C[GMT_OUT]->header->size] = (gmt_grdfloat)o_value[k];
}
}
GMT_Destroy_Data (API, &C[GMT_IN]); /* Done with the input cube */
Expand Down
2 changes: 1 addition & 1 deletion src/grdview.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ EXTERN_MSC int GMT_grdview (void *V_API, int mode, void *args) {
}

if (Ctrl->T.active) /* Plot colored graticules instead */
gmt_plot_image_graticules (GMT, Topo, Intens, P, (Ctrl->T.outline) ? &Ctrl->T.pen : NULL, Ctrl->T.skip, Ctrl->I.constant ? &Ctrl->I.value : NULL);
gmt_plot_image_graticules (GMT, Topo, Intens, P, (Ctrl->T.outline) ? &Ctrl->T.pen : NULL, Ctrl->T.skip, Ctrl->I.constant ? &Ctrl->I.value : NULL, true);
else if (Ctrl->Q.mode == GRDVIEW_IMAGE) { /* Plot image */
int nx_i, ny_i, ip, jp, min_i, max_i, min_j, max_j, dist;
int done, layers, last_i, last_j;
Expand Down
6 changes: 3 additions & 3 deletions src/testapi_gmtgrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ int main () {
uint64_t dim[2] = {5, 4};
char args[1000] = {""};
char input[GMT_VF_LEN] = {""};
float *data = NULL;
gmt_grdfloat *data = NULL;

API = GMT_Create_Session ("testapi_gmtgrid", 2U, mode, NULL);

/* Create a container for the grid */
G = GMT_Create_Data (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_CONTAINER_ONLY, dim, NULL, NULL, 0, 2, NULL);

/* Allocate memory of the data array in the external program (C or PyGMT) */
data = (float *)malloc(sizeof(float) * 9 * 8);
for (int i = 0; i < 9 * 8; i++) data[i] = (float)i;
data = (gmt_grdfloat *)malloc(sizeof(gmt_grdfloat) * 9 * 8);
for (int i = 0; i < 9 * 8; i++) data[i] = (gmt_grdfloat)i;

/* Assign the user data to the GMT_GRID structure */
G->data = data;
Expand Down

0 comments on commit 8f9dcae

Please sign in to comment.