#include "gmt.h"
/*
 * Testing a specific case where we wish to pass and receive a GMT_VECTOR or GMT_MATRIX
 * to/from a module that expect to read/write GMT_DATASETs.
 */
int main () {
	void *API = NULL;                 /* The API control structure */
	struct GMT_MATRIX *M[2] = {NULL, NULL};     /* Structure to hold input/output dataset as matrix */
	char input[GMT_VF_LEN] = {""};     			/* String to hold virtual input filename */
	char output[GMT_VF_LEN] = {""};    			/* String to hold virtual output filename */
	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_IN] = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "belgium.txt", NULL);
	/* Associate our data table with a virtual file */
	GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_PLP, GMT_IN, M[GMT_IN], input);
	/* Open a virtual file to hold the sampled points */
	GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_IS_MATRIX, GMT_IS_PLP, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
	/* Prepare the module arguments */
	sprintf (args, "-sa %s -Gtopo.nc ->%s", input, output);
	/* Call the grdtrack module */
	GMT_Call_Module (API, "grdtrack", GMT_MODULE_CMD, args);
	/* Obtain the data from the virtual file */
	M[GMT_OUT] = GMT_Read_VirtualFile (API, output);
	/* Close the virtual files */
	GMT_Close_VirtualFile (API, input);
	GMT_Close_VirtualFile (API, output);
	/* Associate our sampled table with a virtual file */
	GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_PLP, GMT_IN, M[GMT_OUT], input);
	/* Prepare the module arguments */
	sprintf (args, "-R3/9/50/54 -JM6i -P -Baf -W0.5p %s ->apimat.ps", input);
	/* Call the psxy module */
	GMT_Call_Module (API, "psxy", GMT_MODULE_CMD, args);
	/* Close the virtual files */
	GMT_Close_VirtualFile (API, input);
	if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
};
