Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/rst/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,9 @@ in three different situations:

Space will be allocated to hold the results, as needed, and a pointer to
the object is returned. If there are errors we simply return NULL and
report the error. The ``mode`` parameter has different meanings for
report the error. Note that you can read in a GMT_IS_MATRIX either from a text
table (passing ``geometry`` as GMT_IS_POINT) or from a grid (passing ``geometry``
as GMT_IS_SURFACE). The ``mode`` parameter has different meanings for
different data types.

**Color palette table**.
Expand Down
4,920 changes: 2,514 additions & 2,406 deletions src/gmt_api.c

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/gmt_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,7 @@ int gmt_nc_write_grd (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header, gmt_
uint64_t imag_offset;
size_t n, nm;
size_t width_t, height_t;
size_t was_chunk_setting = GMT->current.setting.io_nc4_chunksize[0]; /* Remember current setting */
double limit[2]; /* minmax of z variable */
gmt_grdfloat *pgrid = NULL;
struct GMT_GRID_HEADER_HIDDEN *HH = gmt_get_H_hidden (header);
Expand Down Expand Up @@ -1805,6 +1806,8 @@ int gmt_nc_write_grd (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header, gmt_
if (status != NC_NOERR)
goto nc_err;

GMT->current.setting.io_nc4_chunksize[0] = was_chunk_setting; /* Restore to previous status */

return GMT_NOERROR;

nc_err:
Expand Down
26 changes: 26 additions & 0 deletions src/testapi_grid2matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "gmt_dev.h"

/* Testing reading a grid into a matrix, then writing the matrix to a grid file.
* The test script apigrd2mat,sh will compare the two.
*/

int main () {
unsigned int mode = GMT_SESSION_EXTERNAL;
double wesn[4] = {-90.0, 120.0, -45.0, 50.0};
struct GMT_MATRIX *M1 = NULL, *M2 = NULL;
struct GMTAPI_CTRL *API = NULL;

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

/* Read in earth_relief_01d as a matrix from the remote grid */
M1 = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "@earth_relief_01d_g", NULL);
/* Write out the matrix to another grid file */
GMT_Write_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_WRITE_NORMAL, NULL, "dump_01d.grd", M1);
/* Read in earth_relief_01d as a matrix from the remote grid */
M2 = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, wesn, "@earth_relief_01d_g", NULL);
/* Write out the matrix to another grid file */
GMT_Write_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_WRITE_NORMAL, NULL, "cut_01d.grd", M2);

if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
exit (0);
}
2 changes: 1 addition & 1 deletion src/testapi_imageshading.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main (int argc, char **argv) {
char args[128] = {""}; /* String to hold module command arguments */
/* Initialize the GMT session */
API = GMT_Create_Session ("test", 2U, GMT_SESSION_EXTERNAL, NULL);
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "2d-matrix.txt", NULL);
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_POINT, GMT_READ_NORMAL, NULL, "2d-matrix.txt", NULL);
/* Associate our matrix with a virtual file */
GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IN, M, input);

Expand Down
2 changes: 1 addition & 1 deletion src/testapi_matrix_360.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main () {
API = GMT_Create_Session ("test", 2U, mode, NULL);

/* Read in earth_relief_01d as a matrix from text file and set correct region, inc, registration */
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "@earth_relief_01d.txt", NULL);
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "@earth_relief_01d", NULL);
M->range[0] = -180; M->range[1] = 180; M->range[2] = -90; M->range[3] = 90.0;
M->inc[0] = M->inc[1] = 1.0;
M->registration = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/testapi_matrix_plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main () {
char args[128] = {""}; /* String to hold module command arguments */
/* Initialize the GMT session */
API = GMT_Create_Session ("test", 0U, GMT_SESSION_EXTERNAL, NULL);
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "@matrix_grid.txt", NULL);
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_POINT, GMT_READ_NORMAL, NULL, "@matrix_grid.txt", NULL);
/* Associate our matrix with a virtual file */
GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IN|GMT_IS_REFERENCE, M, input);
/* Prepare the module arguments */
Expand Down
Binary file added test/api/apimat2grd.ps
Binary file not shown.
9 changes: 9 additions & 0 deletions test/api/apimat2grd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
#
# Test the C API for passing a global grid as a matrix to grdimage
# and have the central meridian work correctly.

ps=apimat2grd.ps
testapi_grid2matrix
gmt grdimage dump_01d.grd -JQ270/6.5i -Baf -P -K -Cgeo > $ps
gmt grdimage cut_01d.grd -JQ0/6.5i -Baf -O -Y4.25i -Cgeo >> $ps
Binary file modified test/api/apimat_360.ps
Binary file not shown.
Binary file modified test/api/apimat_360_ref.ps
Binary file not shown.