56#include "non_dominated_sort.h"
62# include <sys/types.h>
75 SET_NON_DOMINATE_SORT,
80char *option[N_OPTIONS] = {
93 "sddssort [<SDDSinput>] [<SDDSoutput>]\n"
94 " [-pipe=[input][,output]]\n"
95 " [-column=<name>[,{increasing|decreasing}|{minimize|maximize}][,absolute]...] \n"
96 " [-unique[=count]]\n"
98 " [-parameter=<name>[,{increasing|decreasing}]...]\n"
100 " [-nonDominateSort] \n"
101 " [-majorOrder=row|column]\n"
103 " -pipe=[input][,output]\n"
104 " Enable piping for input and/or output.\n\n"
105 " -column=<name>[,{increasing|decreasing}|{minimize|maximize}][,absolute]...\n"
106 " Specify one or more columns to sort by.\n"
107 " - 'increasing' or 'decreasing' sets the sorting direction for regular sorting.\n"
108 " - 'minimize' or 'maximize' sets the sorting direction for non-dominated sorting.\n"
109 " - 'absolute' sorts based on absolute values.\n\n"
111 " Eliminate duplicate rows based on sort columns.\n"
112 " If 'count' is specified, an 'IdenticalCount' column is added to indicate the number of identical rows.\n\n"
114 " Suppress warning messages.\n\n"
115 " -parameter=<name>[,{increasing|decreasing}]...\n"
116 " Specify parameters to sort by.\n\n"
118 " Prioritize numeric characters over other characters in string comparisons.\n"
119 " Also ranks numeric character sets with fewer characters below those with more characters.\n\n"
120 " -nonDominateSort\n"
121 " Perform non-dominated sorting when multiple sort columns are provided.\n"
122 " Note: Non-dominated sorting only works for numeric columns.\n\n"
123 " -majorOrder=row|column\n"
124 " Set the major order for data storage, either row-major or column-major.\n\n"
125 "Program by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
131 short decreasing_order, maximize_order, absolute;
135static char *order_mode[5] = {
143long SDDS_SortRows(
SDDS_DATASET *SDDS_dataset,
SORT_REQUEST *xsort_request,
long xsort_requests,
long non_dominate_sort);
144long SDDS_UnsetDuplicateRows(
SDDS_DATASET *SDDS_dataset,
SORT_REQUEST *xsort_request,
long xsort_requests,
long provideIdenticalCount);
147 SORT_REQUEST *xsort_parameter,
long xsort_parameters,
long uniqueRows,
long provideIdenticalCount,
148 long pipeFlags,
long non_dominate_sort);
150double *read_constr_violation(
SDDS_DATASET *SDDS_dataset);
152long numericHigh = 0, constDefined = 0;
154int main(
int argc,
char **argv) {
156 char *input, *output;
157 long i_arg, non_dominate_sort = 0;
160 long tmpfile_used, sort_requests, noWarnings, uniqueRows, provideIdenticalCount, tmpfileForInternalPipe;
161 long sort_parameters;
163 unsigned long pipeFlags, majorOrderFlag;
164 short columnMajorOrder = -1;
167 argc =
scanargs(&s_arg, argc, argv);
172 input = output = NULL;
173 tmpfile_used = sort_requests = noWarnings = sort_parameters = tmpfileForInternalPipe = 0;
174 sort_request = sort_parameter = NULL;
176 uniqueRows = provideIdenticalCount = 0;
177 for (i_arg = 1; i_arg < argc; i_arg++) {
178 if (s_arg[i_arg].arg_type == OPTION) {
179 switch (
match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
180 case SET_MAJOR_ORDER:
182 s_arg[i_arg].n_items--;
183 if (s_arg[i_arg].n_items > 0 &&
184 (!
scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
185 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
186 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
187 SDDS_Bomb(
"invalid -majorOrder syntax/values");
188 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
189 columnMajorOrder = 1;
190 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
191 columnMajorOrder = 0;
193 case SET_NON_DOMINATE_SORT:
194 non_dominate_sort = 1;
197 if (s_arg[i_arg].n_items < 2 || s_arg[i_arg].n_items > 4)
199 sort_request =
trealloc(sort_request,
sizeof(*sort_request) * (sort_requests + 1));
200 sort_request[sort_requests].name = s_arg[i_arg].list[1];
201 sort_request[sort_requests].maximize_order = 0;
202 sort_request[sort_requests].decreasing_order = 0;
203 sort_request[sort_requests].absolute = 0;
204 if (s_arg[i_arg].n_items >= 3) {
206 for (j = 2; j < s_arg[i_arg].n_items; j++) {
207 switch (
match_string(s_arg[i_arg].list[j], order_mode, 5, 0)) {
211 sort_request[sort_requests].decreasing_order = 1;
216 sort_request[sort_requests].maximize_order = 1;
219 sort_request[sort_requests].absolute = 1;
222 fprintf(stderr,
"unknown sort order specified--give 'increasing' or 'decreasing' for dominated sorting\n or'maximize' or 'minimize' for non-dominated-sorting.\n");
231 if (s_arg[i_arg].n_items < 2 || s_arg[i_arg].n_items > 3)
233 sort_parameter =
trealloc(sort_parameter,
sizeof(*sort_parameter) * (sort_parameters + 1));
234 sort_parameter[sort_parameters].name = s_arg[i_arg].list[1];
235 if (s_arg[i_arg].n_items == 3) {
236 if ((sort_parameter[sort_parameters].decreasing_order =
match_string(s_arg[i_arg].list[2], order_mode, 2, 0)) < 0)
237 SDDS_Bomb(
"unknown sort order specified--give 'increasing' or 'decreasing'");
239 sort_parameter[sort_parameters].decreasing_order = 0;
245 case SET_NUMERICHIGH:
249 if (!
processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
254 if (s_arg[i_arg].n_items > 1) {
256 if (s_arg[i_arg].n_items > 2 ||
257 strncmp(
"count", s_arg[i_arg].list[1], strlen(s_arg[i_arg].list[1])) != 0)
259 provideIdenticalCount = 1;
263 fprintf(stderr,
"error: unknown switch: %s\n", s_arg[i_arg].list[0]);
269 input = s_arg[i_arg].list[0];
270 else if (output == NULL)
271 output = s_arg[i_arg].list[0];
277 if (!sort_requests && !sort_parameters)
279 processFilenames(
"sddssort", &input, &output, pipeFlags, noWarnings, &tmpfile_used);
284 if (sort_requests <= 1)
285 non_dominate_sort = 0;
287 if (SDDS_input.layout.popenUsed) {
292 char tmpfileName[1024];
294 sprintf(tmpfileName,
"/tmp/sddssort.%ld", (
long)pid);
295 tmpfileForInternalPipe = 1;
300 if (columnMajorOrder != -1)
301 SDDS_tmp.layout.data_mode.column_major = columnMajorOrder;
303 SDDS_tmp.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
304 if (non_dominate_sort) {
340 if (columnMajorOrder != -1)
341 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
343 SDDS_output.layout.data_mode.column_major = SDDS_input.layout.data_mode.column_major;
344 if (provideIdenticalCount &&
349 if (non_dominate_sort) {
363 if (!SDDS_SortAll(&SDDS_input, &SDDS_output, sort_request, sort_requests, sort_parameter, sort_parameters,
364 uniqueRows, provideIdenticalCount, pipeFlags, non_dominate_sort)) {
382static long sort_requests;
383static int64_t *sort_row_index;
385int SDDS_CompareData(
SDDS_DATASET *SDDS_dataset,
short type,
short absolute,
void *data1,
void *data2) {
397 if ((ldouble_diff = *(
long double *)data1 - *(
long double *)data2) > 0)
399 else if (ldouble_diff < 0)
403 if ((double_diff = *(
double *)data1 - *(
double *)data2) > 0)
405 else if (double_diff < 0)
409 if ((float_diff = *(
float *)data1 - *(
float *)data2) > 0)
411 else if (float_diff < 0)
415 if ((long64_diff = *(int64_t *)data1 - *(int64_t *)data2) > 0)
417 else if (long64_diff < 0)
421 if ((long_diff = *(int32_t *)data1 - *(int32_t *)data2) > 0)
423 else if (long_diff < 0)
427 if ((short_diff = *(
short *)data1 - *(
short *)data2) > 0)
429 else if (short_diff < 0)
433 if (*(uint64_t *)data1 > *(uint64_t *)data2)
435 if (*(uint64_t *)data1 < *(uint64_t *)data2)
439 if (*(uint32_t *)data1 > *(uint32_t *)data2)
441 if (*(uint32_t *)data1 < *(uint32_t *)data2)
445 if (*(
unsigned short *)data1 > *(
unsigned short *)data2)
447 if (*(
unsigned short *)data1 < *(
unsigned short *)data2)
451 if ((char_diff = *(
char *)data1 - *(
char *)data2) > 0)
453 else if (char_diff < 0)
458 return (
strcmp_nh(*(
char **)data1, *(
char **)data2));
460 return (strcmp(*(
char **)data1, *(
char **)data2));
462 SDDS_SetError(
"Problem doing data comparison--invalid data type (SDDS_CompareData)");
469 if ((ldouble_diff = fabsl(*(
long double *)data1) - fabsl(*(
long double *)data2)) > 0)
471 else if (ldouble_diff < 0)
475 if ((double_diff = fabs(*(
double *)data1) - fabs(*(
double *)data2)) > 0)
477 else if (double_diff < 0)
481 if ((float_diff = fabsf(*(
float *)data1) - fabsf(*(
float *)data2)) > 0)
483 else if (float_diff < 0)
487 if ((long64_diff = llabs(*(int64_t *)data1) - llabs(*(int64_t *)data2)) > 0)
489 else if (long64_diff < 0)
493 if ((long_diff = labs(*(int32_t *)data1) - labs(*(int32_t *)data2)) > 0)
495 else if (long_diff < 0)
499 if ((short_diff = abs(*(
short *)data1) - abs(*(
short *)data2)) > 0)
501 else if (short_diff < 0)
505 if (*(uint64_t *)data1 > *(uint64_t *)data2)
507 if (*(uint64_t *)data1 < *(uint64_t *)data2)
511 if (*(uint32_t *)data1 > *(uint32_t *)data2)
513 if (*(uint32_t *)data1 < *(uint32_t *)data2)
517 if (*(
unsigned short *)data1 > *(
unsigned short *)data2)
519 if (*(
unsigned short *)data1 < *(
unsigned short *)data2)
523 if ((char_diff = *(
char *)data1 - *(
char *)data2) > 0)
525 else if (char_diff < 0)
530 return (
strcmp_nh(*(
char **)data1, *(
char **)data2));
532 return (strcmp(*(
char **)data1, *(
char **)data2));
534 SDDS_SetError(
"Problem doing data comparison--invalid data type (SDDS_CompareData)");
541int SDDS_CompareRows(
const void *vrow1,
const void *vrow2) {
545 static double data1, data2;
546 static int64_t row1, row2;
550 row1 = *(int64_t *)vrow1;
551 row2 = *(int64_t *)vrow2;
553 for (i = 0; i < sort_requests; i++) {
556 SDDS_SetError(
"Problem getting value for sort (SDDS_CompareRows)");
560 if ((comparison = SDDS_CompareData(SDDS_sort, sort_request[i].type, sort_request[i].absolute,
561 (
void *)&data1, (
void *)&data2))) {
565 free(*((
char **)p1));
566 free(*((
char **)p2));
570 return (sort_request[i].decreasing_order ? -comparison : comparison);
575 free(*((
char **)p1));
576 free(*((
char **)p2));
584long SDDS_SwapRows(
SDDS_DATASET *SDDS_dataset, int64_t row1, int64_t row2) {
585#define SWAP_BUFFER_SIZE 16
586 static char buffer[SWAP_BUFFER_SIZE];
589 data = SDDS_dataset->data;
591 fprintf(stderr,
"swapping row %" PRId64
" with row %" PRId64
"\n", row1, row2);
593 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
594 if ((size =
SDDS_GetTypeSize(SDDS_dataset->layout.column_definition[i].type)) > SWAP_BUFFER_SIZE) {
595 SDDS_SetError(
"Unable to swap rows--swap buffer is too small (SDDS_SwapRows)");
599 if (SDDS_dataset->layout.column_definition[i].type ==
SDDS_STRING)
600 fprintf(stderr,
" %s <--> %s\n", *(
char **)((
char *)(data[i]) + row1 * size), *(
char **)((
char *)(data[i]) + row2 * size));
602 memcpy((
char *)buffer, (
char *)(data[i]) + row1 * size, size);
603 memcpy((
char *)(data[i]) + row1 * size, (
char *)(data[i]) + row2 * size, size);
604 memcpy((
char *)(data[i]) + row2 * size, (
char *)buffer, size);
609long SDDS_SortRows(
SDDS_DATASET *SDDS_dataset,
SORT_REQUEST *xsort_request,
long xsort_requests,
long non_dominate_sort) {
610 int64_t i, j, k, rows;
611 int64_t *row_location;
613 double **data = NULL, *dist = NULL, *const_violation = NULL;
614 int32_t *rank = NULL;
616 long *maximize = NULL;
618 SDDS_sort = SDDS_dataset;
619 sort_request = xsort_request;
620 sort_requests = xsort_requests;
624 for (i = 0; i < sort_requests; i++) {
626 sprintf(s,
"column name \"%s\" is not recognized(SDDS_GetColumnIndex)", sort_request[i].name);
633 if (non_dominate_sort) {
634 data = (
double **)malloc(
sizeof(*data) * sort_requests);
635 maximize = (
long *)malloc(
sizeof(*maximize) * sort_requests);
636 for (i = 0; i < sort_requests; i++) {
638 fprintf(stderr,
"Non-dominated sort is not available for string column.\n");
646 maximize[i] = sort_request[i].maximize_order;
648 const_violation = read_constr_violation(SDDS_sort);
649 fill_population(&pop, rows, sort_requests, data, maximize, const_violation);
651 rank = (int32_t *)malloc(
sizeof(*rank) * rows);
652 dist = (
double *)malloc(
sizeof(*dist) * rows);
653 if (!const_violation)
654 const_violation = calloc(rows,
sizeof(*const_violation));
655 for (i = 0; i < rows; i++) {
656 rank[i] = pop.ind[sort_row_index[i]].rank;
657 dist[i] = pop.ind[sort_row_index[i]].crowd_dist;
658 const_violation[i] = pop.ind[sort_row_index[i]].constr_violation;
661 for (i = 0; i < sort_requests; i++)
666 sort_row_index =
tmalloc(
sizeof(*sort_row_index) * rows);
667 for (i = 0; i < rows; i++)
668 sort_row_index[i] = i;
672 qsort((
void *)sort_row_index, rows,
sizeof(*sort_row_index), SDDS_CompareRows);
678 fprintf(stderr,
"new row order:\n");
679 for (i = 0; i < rows; i++)
680 fprintf(stderr,
"%" PRId64
" %" PRId64
"\n", i, sort_row_index[i]);
681 fprintf(stderr,
"\n");
684 row_location =
tmalloc(
sizeof(*sort_row_index) * rows);
685 for (i = 0; i < rows; i++)
686 row_location[sort_row_index[i]] = i;
687 for (i = 0; i < rows; i++) {
688 if ((j = sort_row_index[i]) != i) {
690 if (!SDDS_SwapRows(SDDS_sort, i, j)) {
691 SDDS_SetError(
"Problem swapping rows after index sort (SDDS_SortRows");
696 sort_row_index[i] = i;
699 sort_row_index[k] = j;
703 fprintf(stderr,
"new row order:\n");
704 for (j = 0; j < rows; j++)
705 fprintf(stderr,
"%" PRId64
" %" PRId64
"\n", j, sort_row_index[j]);
706 fprintf(stderr,
"\n");
709 if (non_dominate_sort) {
710 if (
SDDS_SetColumn(SDDS_sort, SDDS_SET_BY_NAME, rank, rows,
"Rank", NULL) != 1 ||
711 SDDS_SetColumn(SDDS_sort, SDDS_SET_BY_NAME, dist, rows,
"CrowdingDistance", NULL) != 1 ||
712 SDDS_SetColumn(SDDS_sort, SDDS_SET_BY_NAME, const_violation, rows,
"ConstraintsViolation", NULL) != 1) {
718 free(const_violation);
720 free(sort_row_index);
725long SDDS_UnsetDuplicateRows(
SDDS_DATASET *SDDS_dataset,
SORT_REQUEST *xsort_request,
long xsort_requests,
long provideIdenticalCount) {
727 int64_t *identicalCount;
731 SDDS_sort = SDDS_dataset;
732 sort_request = xsort_request;
733 sort_requests = xsort_requests;
735 for (i = 0; i < sort_requests; i++) {
737 sprintf(s,
"column name \"%s\" is not recognized(SDDS_GetColumnIndex)", sort_request[i].name);
748 rowFlag =
tmalloc(
sizeof(*rowFlag) * rows);
749 identicalCount =
tmalloc(
sizeof(*identicalCount) * rows);
750 for (i = 0; i < rows; i++)
751 rowFlag[i] = identicalCount[i] = 1;
753 for (i = 0; i < rows - 1; i++) {
756 for (j = i + 1; j < rows; j++) {
758 if (SDDS_CompareRows(&i, &j) == 0) {
759 identicalCount[i] += 1;
768 if (provideIdenticalCount && !
SDDS_SetColumn(SDDS_sort, SDDS_SET_BY_NAME, identicalCount, rows,
"IdenticalCount"))
775static long sort_parameters;
778int SDDS_ComparePages(
const void *vpage1,
const void *vpage2) {
782 static int32_t page1, page2;
786 page1 = *(int32_t *)vpage1;
787 page2 = *(int32_t *)vpage2;
789 for (i = 0; i < sort_parameters; i++) {
790 if ((comparison = SDDS_CompareData(SDDS_sortpage, sort_parameter[i].type, sort_parameter[i].absolute,
791 (
void *)&(sort_parameter[i].data[page1]), (
void *)&(sort_parameter[i].data[page2])))) {
796 return (sort_parameter[i].decreasing_order ? -comparison : comparison);
807 long xsort_requests,
SORT_REQUEST *xsort_parameter,
long xsort_parameters,
long uniqueRows,
808 long provideIdenticalCount,
long xpipeFlags,
long non_dominate_sort) {
810 int32_t *xsort_page_index;
815 SDDS_sortpage = SDDS_inputx;
816 sort_parameter = xsort_parameter;
817 sort_parameters = xsort_parameters;
818 sort_request = xsort_request;
819 sort_requests = xsort_requests;
820 xsort_page_index = NULL;
821 pages = i = j = k = 0;
822 for (i = 0; i < sort_parameters; i++) {
824 sprintf(s,
"Unable to get parameter value--parameter name \"%s\" is not recognized(SDDS_GetParameterIndex)", sort_parameter[i].name);
831 if (sort_parameters) {
832 if (xpipeFlags == 0 && !SDDS_sortpage->layout.gzipFile)
834 for (i = 0; i < sort_parameters; i++)
835 sort_parameter[i].data = NULL;
837 if (xpipeFlags || SDDS_sortpage->layout.gzipFile) {
840 tmp_datasets = realloc(tmp_datasets,
sizeof(*tmp_datasets) * (pages + 1));
850 for (i = 0; i < sort_parameters; i++) {
851 sort_parameter[i].data = realloc(sort_parameter[i].data,
sizeof(*sort_parameter[i].data) * (pages + 1));
854 SDDS_SetError(
"Problem getting parameter value for sort (SDDS_SortAll)");
862 xsort_page_index =
tmalloc(
sizeof(*xsort_page_index) * pages);
863 for (k = 0; k < pages; k++)
864 xsort_page_index[k] = k;
866 qsort((
void *)xsort_page_index, pages,
sizeof(*xsort_page_index), SDDS_ComparePages);
869 for (i = 0; i < pages; i++) {
870 j = xsort_page_index[i];
871 if (xpipeFlags || SDDS_sortpage->layout.gzipFile) {
901 if (!SDDS_SortRows(SDDS_outputx, sort_request, sort_requests, non_dominate_sort)) {
906 if (uniqueRows && !SDDS_UnsetDuplicateRows(SDDS_outputx, sort_request, sort_requests, provideIdenticalCount)) {
927 if (!SDDS_SortRows(SDDS_outputx, sort_request, sort_requests, non_dominate_sort)) {
932 if (uniqueRows && !SDDS_UnsetDuplicateRows(SDDS_outputx, sort_request, sort_requests, provideIdenticalCount)) {
947 if (xsort_page_index)
948 free(xsort_page_index);
952double *read_constr_violation(
SDDS_DATASET *SDDS_dataset) {
953 double *const_violation = NULL, **data = NULL;
954 int32_t columns, constraints, j;
956 char **columnName = NULL;
958 columns = constraints = 0;
960 if (!constDefined && !(const_violation = (
double *)
SDDS_GetColumnInDoubles(SDDS_dataset,
"ConstraintsViolation")))
965 for (i = 0; i < columns; i++) {
966 if (
wild_match(columnName[i],
"*Constraints*") && strcmp(columnName[i],
"ConstraintsViolation") != 0) {
967 data =
SDDS_Realloc(data,
sizeof(*data) * (constraints + 1));
968 data[constraints] = NULL;
975 const_violation = calloc(rows,
sizeof(*const_violation));
976 for (i = 0; i < rows; i++) {
977 for (j = 0; j < constraints; j++) {
979 const_violation[i] += data[j][i];
982 for (j = 0; j < constraints; j++)
987 return const_violation;
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_SetDefaultIOBufferSize(int32_t newValue)
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_GetParameterType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a parameter in the SDDS dataset by its index.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_CheckColumn(SDDS_DATASET *SDDS_dataset, char *name, char *units, int32_t type, FILE *fp_message)
Checks if a column exists in the SDDS dataset with the specified name, units, and type.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_GetTypeSize(int32_t type)
Retrieves the size in bytes of a specified SDDS data type.
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_ANY_NUMERIC_TYPE
Special identifier used by SDDS_Check*() routines to accept any numeric type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int64_t * non_dominated_sort(population *new_pop)
Performs non-dominated sorting on a population and assigns ranks and crowding distances.
void fill_population(population *pop, long rows, long columns, double **columnValue, long *maximize, double *const_violation)
Initializes and fills the population structure with individuals and their objective values.
void free_pop_mem(population *pop)
Frees all dynamically allocated memory associated with a population.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
void free_scanargs(SCANNED_ARG **scanned, int argc)
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.
char * str_tolower(char *s)
Convert a string to lower case.
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
int strcmp_nh(const char *s1, const char *s2)
Compare two strings with a custom non-hierarchical ranking.