MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / main

Function main

src/testapi_columns.c:20–54  ·  view source on GitHub ↗

* Testing the implementation of -i in the API. * The test script api/apicolumns_icol.sh will run this and compare. * * We read in the file @wus_gps_final_crowell.txt which has 3277 records of 7 columns. * * We will use -i to select some of the columns, including a repeat column, and * apply the scale/offset modifiers * * The equivalent command line that gives the comparing data is here:

Source from the content-addressed store, hash-verified

18 * Notes: 1) Another issue to fix for datasets, so k starts at 1
19 */
20int main () {
21 void *API = NULL; /* The API control structure */
22 void *data[2] = {NULL, NULL};
23 const char *convert = "-i1,0,3,3+d2,2,5+s10,6+o10 --FORMAT_FLOAT_OUT=%8.3f";
24 const char *file[3] = {"dataset.txt", "matrix.txt", "vector.txt"};
25 char cmd[128], filename[128] = {""}, input[GMT_VF_LEN] = {""}, output[GMT_VF_LEN] = {""};
26 unsigned int family[3] = {GMT_IS_DATASET, GMT_IS_MATRIX, GMT_IS_VECTOR};
27 unsigned int reference[3] = {GMT_IS_DUPLICATE, GMT_IS_REFERENCE, GMT_IS_REFERENCE};
28 unsigned int k, via[3] = {0, GMT_VIA_MATRIX, GMT_VIA_VECTOR};
29
30 /* Initialize the GMT session */
31 API = GMT_Create_Session ("test", 2U, GMT_SESSION_EXTERNAL, NULL);
32 for (k = 1; k < 3; k++) {
33 /* Read in our data table to memory */
34 data[GMT_IN] = GMT_Read_Data (API, family[k], GMT_IS_FILE, GMT_IS_POINT, GMT_READ_NORMAL, NULL, "@wus_gps_final_crowell.txt", NULL);
35 /* Create a virtual file for this input data set */
36 GMT_Open_VirtualFile (API, GMT_IS_DATASET|via[k], GMT_IS_POINT, GMT_IN|reference[k], data[GMT_IN], input);
37 /* Create a virtual file to hold the output */
38 GMT_Open_VirtualFile (API, GMT_IS_DATASET|via[k], GMT_IS_POINT, GMT_OUT, data[GMT_OUT], output);
39 /* Create command for module gmtconvert */
40 sprintf (cmd, "%s %s ->%s", convert, input, output);
41 /* Call the gmtconvert module */
42 GMT_Call_Module (API, "gmtconvert", GMT_MODULE_CMD, cmd);
43 /* Obtain the output container from the output virtual file */
44 data[GMT_OUT] = GMT_Read_VirtualFile (API, output);
45 /* Write the result out to a table */
46 sprintf (filename, "%s", file[k]);
47 GMT_Write_Data (API, family[k], GMT_IS_FILE, GMT_IS_POINT, GMT_WRITE_NORMAL|GMT_IO_RESET, NULL, filename, data[GMT_OUT]);
48 /* Destroy the two memory resources */
49 GMT_Destroy_Data (API, &data[GMT_IN]);
50 GMT_Destroy_Data (API, &data[GMT_OUT]);
51 }
52 /* Destroy the GMT session */
53 if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
54};

Callers

nothing calls this directly

Calls 8

GMT_Create_SessionFunction · 0.85
GMT_Read_DataFunction · 0.85
GMT_Open_VirtualFileFunction · 0.85
GMT_Call_ModuleFunction · 0.85
GMT_Read_VirtualFileFunction · 0.85
GMT_Write_DataFunction · 0.85
GMT_Destroy_DataFunction · 0.85
GMT_Destroy_SessionFunction · 0.85

Tested by

no test coverage detected