Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new C program for testing #21

Merged
merged 1 commit into from
Aug 17, 2018
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
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ endif (DO_EXAMPLES OR DO_TESTS AND NOT DCW_FOUND)

if (DO_API_TESTS)
# These lines are temporarily here for the beta release - comment to avoid in the build
set (GMT_DEMOS_SRCS testapi.c testpsl.c testgmt.c testgmtio.c testgrdio.c testio.c
set (GMT_DEMOS_SRCS testapi.c testpsl.c testgmt.c testgmtshell.c testgmtio.c testgrdio.c testio.c
testapiconv.c example1.c testapi_matrix.c testapi_matrix_plot.c testapi_vector.c test_JL.c testapi_mixmatrix.c
test_walter.c testapi_usergrid.c testapi_userdataset.c testapi_uservectors.c)
endif (DO_API_TESTS)
Expand Down
63 changes: 63 additions & 0 deletions src/testgmtshell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*--------------------------------------------------------------------
*
* Copyright (c) 1991-2018 by P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis and F. Wobbe
* See LICENSE.TXT file for copying and redistribution conditions.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Contact info: gmt.soest.hawaii.edu
*--------------------------------------------------------------------*/
/*
* Simulates a shell script but with a single API session. Non-gmt calls
* are run via system while GMT calls are run via GMT_Call_Module.
*
* Version: 6
* Created: 16-Aug-2018
*
*/

#include "gmt.h"

int main () {

int status = 0; /* Status code from GMT API */
char line[BUFSIZ] = {""}; /* Input line buffer */
char first[64] = {""}, module[32] = {""}, args[1024] = {""};
struct GMTAPI_CTRL *API = NULL; /* GMT API control structure */

/* 1. Initializing new GMT session */
if ((API = GMT_Create_Session ("TEST", GMT_PAD_DEFAULT, GMT_SESSION_NORMAL, NULL)) == NULL) exit (EXIT_FAILURE);

/* 2. Loop over all commands and run them as is */

while (fgets (line, BUFSIZ, stdin)) {
if (line[0] == '#' || line[0] == '\n') continue; /* Skip comments and blank lines */
sscanf (line, "%s %s %[^\n]", first, module, args);
if (strncmp (first, "gmt", 3U)) { /* 3a. Make a system call since not GMT module */
status = system (line);
if (status) {
GMT_Report (API, GMT_MSG_NORMAL, "system call returned error %d\n", status);
exit (EXIT_FAILURE);
}
}
else { /* 3b. Call the module */
status = GMT_Call_Module (API, module, GMT_MODULE_CMD, args); /* This allocates memory for the export grid associated with the -G option */
if (status) {
GMT_Report (API, GMT_MSG_NORMAL, "%s returned error %d\n", module, status);
exit (EXIT_FAILURE);
}
}
}

/* 4. Destroy GMT session */
if (GMT_Destroy_Session (API)) exit (EXIT_FAILURE);

exit (GMT_NOERROR); /* Return the status from this program */
}