Skip to content

Commit

Permalink
Adding API test for plotting a global matrix/grid for different centr…
Browse files Browse the repository at this point in the history
…al 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 <pwessel@hawaii.edu>
  • Loading branch information
github-actions[bot] and PaulWessel authored Aug 1, 2020
1 parent 7f34541 commit 2b0f9fe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/testapi_matrix_360.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "gmt_dev.h"

/* Testing the passing of a matrix to grdimage for global projection
* when the central meridian changes. This currently fails as in
* https://github.com/GenericMappingTools/pygmt/issues/515#issue-655281714
*/

int main () {
unsigned int mode = GMT_SESSION_EXTERNAL;
struct GMT_MATRIX *M = NULL;
char input[GMT_VF_LEN], args[256] = {""};
struct GMTAPI_CTRL *API = NULL;

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

/* Read in earth_relief_01d as a matrix from text file and set correct region, inc, registartion */
M = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "@earth_relief_01d.txt", 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;
/* Create a virtual file to pass as a grid */
GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IN|GMT_IS_REFERENCE, M, input);
/* Call grdimage with central longitude 0, which is the center of the grid */
sprintf (args, "%s -Rg -JH0/6i -Bg30 -K -Cgeo -P", input);
GMT_Call_Module (API, "grdimage", GMT_MODULE_CMD, args);
GMT_Init_VirtualFile (API, 0, input);
/* Call grdimage with central longitude 180 which means grid needs to be rotated 180 */
sprintf (args, "%s -R -JH180/6i -Bg30 -O -Cgeo -Y3.5i", input);
GMT_Call_Module (API, "grdimage", GMT_MODULE_CMD, args);
GMT_Close_VirtualFile (API, input);

if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
exit (0);
}
7 changes: 7 additions & 0 deletions test/api/apimat_360.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/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=apimat_360.ps
testapi_matrix_360 > $ps

0 comments on commit 2b0f9fe

Please sign in to comment.