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

Function deploy_test

src/testapi_usergrid.c:186–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186int deploy_test (unsigned int intype, unsigned int outtype, int alloc_in_GMT, int def_mode, int V) {
187 /* Run the test using the specified in and out types */
188 uint64_t dim[4] = {NCOLS, NROWS, 1, 0}; /* ncols, nrows, nlayers, type */
189 int bad = 0;
190 unsigned int out_via = (outtype + 1) * 100 + GMT_IS_SURFACE; /* To get GMT_VIA_<type */
191 unsigned int mode = GMT_SESSION_EXTERNAL;
192 double diff, wesn[6] = {1.0, NCOLS, 1.0, NROWS, 0.0, 0.0}, inc[2] = {1.0, 1.0};
193 //void *API = NULL; /* The API control structure */
194 struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output grids as matrix */
195 char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */
196 char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */
197 char args[128] = {""}; /* String to hold module command arguments */
198 void *in_data = NULL, *out_data = NULL;
199 struct GMTAPI_CTRL *API = NULL;
200
201 if (V) mode += (6 << 16); /* Activate -Vd */
202 in_data = get_array (intype, 1); /* Create dummy user grid in_data[] = k */
203 if (intype == GMT_FLOAT)
204 bad = 0;
205
206 /* Initialize a GMT session */
207 API = GMT_Create_Session ("test", 2U, mode, NULL);
208 /* Create a blank matrix container that will hold our user in_data */
209 if (def_mode == 0) { /* Use dimensions to allocate */
210 if ((M[GMT_IN] = GMT_Create_Data (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_CONTAINER_ONLY, dim, NULL, NULL, 0, 0, NULL)) == NULL) return (EXIT_FAILURE);
211 }
212 else { /* Use region and inc to allocate space */
213 if ((M[GMT_IN] = GMT_Create_Data (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_CONTAINER_ONLY, NULL, wesn, inc, 0, 0, NULL)) == NULL) return (EXIT_FAILURE);
214 }
215 /* Hook the user input array up to this container */
216 GMT_Put_Matrix (API, M[GMT_IN], intype, 0, in_data);
217 /* Associate our matrix container with a virtual grid file to "read" from via duplication */
218 GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IN, M[GMT_IN], input);
219 if (alloc_in_GMT) /* Request matrix container for output data to be allocated by GMT */
220 GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, out_via, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
221 else { /* Preallocate array space here in the app */
222 out_data = get_array (outtype, 0); /* Make user space for output */
223 /* Create a blank matrix container that will hold our user out_data, but pass dim so it can set the dimensions */
224 if (def_mode == 0) { /* Use dimensions to allocate */
225 M[GMT_OUT] = GMT_Create_Data (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IS_OUTPUT, dim, NULL, NULL, 0, 0, NULL);
226 }
227 else { /* Use region and inc instead */
228 M[GMT_OUT] = GMT_Create_Data (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_IS_OUTPUT, NULL, wesn, inc, 0, 0, NULL);
229 }
230 /* Hook the user output array up to this containers */
231 GMT_Put_Matrix (API, M[GMT_OUT], outtype, 0, out_data);
232 /* Associate our data matrix with a virtual grid file to "write" to */
233 GMT_Open_VirtualFile (API, GMT_IS_GRID|GMT_VIA_MATRIX, GMT_IS_SURFACE, GMT_OUT, M[GMT_OUT], output);
234 }
235 /* Prepare the module arguments to multiply the input grid by 10 then add 1 */
236 sprintf (args, "%s 10 MUL 1 ADD = %s", input, output);
237 /* Call the grdmath module */
238 GMT_Call_Module (API, "grdmath", GMT_MODULE_CMD, args);
239 if (alloc_in_GMT) { /* Obtain the matrix container from the output virtual file */
240 M[GMT_OUT] = GMT_Read_VirtualFile (API, output);
241 /* Get the pointer to the modified user output array */
242 out_data = GMT_Get_Matrix (API, M[GMT_OUT]);
243 }

Callers 1

mainFunction · 0.70

Calls 12

GMT_Create_SessionFunction · 0.85
GMT_Create_DataFunction · 0.85
GMT_Put_MatrixFunction · 0.85
GMT_Open_VirtualFileFunction · 0.85
GMT_Call_ModuleFunction · 0.85
GMT_Read_VirtualFileFunction · 0.85
GMT_Get_MatrixFunction · 0.85
GMT_Close_VirtualFileFunction · 0.85
GMT_Destroy_SessionFunction · 0.85
get_arrayFunction · 0.70
sum_arrayFunction · 0.70
put_arrayFunction · 0.70

Tested by

no test coverage detected