Skip to content

Commit 2b0f9fe

Browse files
Adding API test for plotting a global matrix/grid for different central meridians (#3811) (#3812)
* Explore passing matrix to grdimage for different central longitudes * Update testapi_matrix_360.c * Try rotating the grid * Update testapi_matrix_360.c * Add the test script * Update gmt_api.c Co-authored-by: Paul Wessel <[email protected]>
1 parent 7f34541 commit 2b0f9fe

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/testapi_matrix_360.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "gmt_dev.h"
2+
3+
/* Testing the passing of a matrix to grdimage for global projection
4+
* when the central meridian changes. This currently fails as in
5+
* https://github.com/GenericMappingTools/pygmt/issues/515#issue-655281714
6+
*/
7+
8+
int main () {
9+
unsigned int mode = GMT_SESSION_EXTERNAL;
10+
struct GMT_MATRIX *M = NULL;
11+
char input[GMT_VF_LEN], args[256] = {""};
12+
struct GMTAPI_CTRL *API = NULL;
13+
14+
API = GMT_Create_Session ("test", 2U, mode, NULL);
15+
16+
/* Read in earth_relief_01d as a matrix from text file and set correct region, inc, registartion */
17+
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "@earth_relief_01d.txt", NULL);
18+
M->range[0] = -180; M->range[1] = 180; M->range[2] = -90; M->range[3] = 90.0;
19+
M->inc[0] = M->inc[1] = 1.0;
20+
M->registration = 1;
21+
/* Create a virtual file to pass as a grid */
22+
GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IN|GMT_IS_REFERENCE, M, input);
23+
/* Call grdimage with central longitude 0, which is the center of the grid */
24+
sprintf (args, "%s -Rg -JH0/6i -Bg30 -K -Cgeo -P", input);
25+
GMT_Call_Module (API, "grdimage", GMT_MODULE_CMD, args);
26+
GMT_Init_VirtualFile (API, 0, input);
27+
/* Call grdimage with central longitude 180 which means grid needs to be rotated 180 */
28+
sprintf (args, "%s -R -JH180/6i -Bg30 -O -Cgeo -Y3.5i", input);
29+
GMT_Call_Module (API, "grdimage", GMT_MODULE_CMD, args);
30+
GMT_Close_VirtualFile (API, input);
31+
32+
if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
33+
exit (0);
34+
}

test/api/apimat_360.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Test the C API for passing a global grid as a matrix to grdimage
4+
# and have the central meridian work correctly.
5+
6+
ps=apimat_360.ps
7+
testapi_matrix_360 > $ps

0 commit comments

Comments
 (0)