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

Function deploy_test

src/testapi_userdataset.c:175–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175int deploy_test (unsigned int intype, unsigned int outtype, int alloc_in_GMT, int V) {
176 /* Run the test using the specified in and out types */
177 uint64_t dim[4] = {NCOLS, NROWS, 1, 0}; /* ncols, nrows, nlayers, type */
178 int bad = 0;
179 unsigned int out_via = (outtype + 1) * 100 + GMT_IS_POINT; /* To get GMT_VIA_<type */
180 unsigned int mode = GMT_SESSION_EXTERNAL;
181 double diff;
182 //void *API = NULL; /* The API control structure */
183 struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output datasets as matrix */
184 char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */
185 char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */
186 char args[128] = {""}; /* String to hold module command arguments */
187 void *in_data = NULL, *out_data = NULL;
188 struct GMTAPI_CTRL *API = NULL;
189
190 if (V) mode += (6 << 16); /* Activate -Vd */
191 in_data = get_array (intype, 1); /* Create dummy user dataset in_data[] = k */
192
193 /* Initialize a GMT session */
194 API = GMT_Create_Session ("test", 2U, mode, NULL);
195 /* Create a blank matrix container that will hold our user in_data */
196 if ((M[GMT_IN] = GMT_Create_Data (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POINT, GMT_CONTAINER_ONLY, dim, NULL, NULL, 0, 0, NULL)) == NULL) return (EXIT_FAILURE);
197 /* Hook the user input array up to this container */
198 GMT_Put_Matrix (API, M[GMT_IN], intype, 0, in_data);
199 /* Associate our matrix container with a virtual dataset file to "read" from */
200 GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POINT, GMT_IN|GMT_IS_REFERENCE, M[GMT_IN], input);
201 if (alloc_in_GMT) /* Request matrix container for output data to be allocated by GMT */
202 GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, out_via, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
203 else { /* Preallocate array space here in the app */
204 out_data = get_array (outtype, 0); /* Make user space for output */
205 /* Create a blank matrix container that will hold our user out_data, but pass dimensions so we know */
206 M[GMT_OUT] = GMT_Create_Data (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POINT, GMT_IS_OUTPUT, dim, NULL, NULL, 0, 0, NULL);
207 /* Hook the user output array up to this containers */
208 GMT_Put_Matrix (API, M[GMT_OUT], outtype, 0, out_data);
209 /* Associate our data matrix with a virtual dataset file to "write" to */
210 GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POINT, GMT_OUT, M[GMT_OUT], output);
211 }
212 /* Prepare the module arguments to multiply the input dataset by 10 then add 1 */
213 sprintf (args, "%s 10 MUL 1 ADD = %s", input, output);
214 /* Call the gmtmath module */
215 GMT_Call_Module (API, "gmtmath", GMT_MODULE_CMD, args);
216 if (alloc_in_GMT) { /* Obtain the matrix container from the output virtual file */
217 M[GMT_OUT] = GMT_Read_VirtualFile (API, output);
218 /* Get the pointer to the modified user output array */
219 out_data = GMT_Get_Matrix (API, M[GMT_OUT]);
220 }
221 /* Close the virtual files */
222 GMT_Close_VirtualFile (API, input);
223 GMT_Close_VirtualFile (API, output);
224 diff = sum_array (out_data, outtype) - sum_array (in_data, intype) - 495.0; /* Expected diff = 0 */
225 if (fabs (diff) > 0.0) {
226 fprintf (stderr, "\nTest matrix/dataset/matrix for Input = index [%s], output = 10*input + 1 [%s]\n", type[intype], type[outtype]);
227 fprintf (stderr, "Misfit = %g\n", diff);
228 /* Print out the input and output values */
229 put_array (in_data, intype, "Input: ");
230 put_array (out_data, outtype, "Output:");
231 bad = 1;
232 fprintf (stderr, "\n\n");

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