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

Function gmtsupport_unique_array

src/gmt_support.c:17884–17903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17882}
17883
17884GMT_LOCAL double *gmtsupport_unique_array (struct GMT_CTRL *GMT, double *array, uint64_t *n) {
17885 size_t k, j;
17886 /* Sort the array in case user did not enter values that were monotonically increasing */
17887 gmt_sort_array (GMT, array, *n, GMT_DOUBLE);
17888 /* Skip any duplicates in the sorted array */
17889 k = 0; j = 1;
17890 while (j < *n) {
17891 if (doubleAlmostEqualZero (array[j], array[k])) /* Skip repeated point */
17892 j++;
17893 else /* Copy over unique value */
17894 array[++k] = array[j++];
17895 }
17896 k++; /* (new) total number of unique values */
17897 if (k < *n) { /* Update array count */
17898 *n = k;
17899 array = gmt_M_memory (GMT, array, *n, double); /* Reallocate exact length of array */
17900 GMT_Report (GMT->parent, GMT_MSG_WARNING, "Eliminated %d duplicate values from the sorted array\n", (int)(j-k));
17901 }
17902 return array;
17903}
17904
17905double *gmt_list_to_array (struct GMT_CTRL *GMT, char *list, unsigned int type, bool unique, uint64_t *n) {
17906 /* Given a comma-separated string of values of type, parse and return array and its length */

Callers 2

gmt_list_to_arrayFunction · 0.85
gmt_create_arrayFunction · 0.85

Calls 2

gmt_sort_arrayFunction · 0.85
GMT_ReportFunction · 0.85

Tested by

no test coverage detected