SDDSlib
Loading...
Searching...
No Matches
sddsxref.c File Reference

Creates an SDDS data set by cross-referencing two or more input data sets. More...

#include "mdb.h"
#include "SDDS.h"
#include "SDDSaps.h"
#include "scan.h"
#include <ctype.h>

Go to the source code of this file.

Classes

struct  TRANSFER_DEFINITION
 
struct  REFDATA
 
struct  EDIT_NAME_REQUEST
 

Macros

#define COLUMN_MODE   0
 
#define PARAMETER_MODE   1
 
#define ARRAY_MODE   2
 
#define MODES   3
 
#define COLUMN_REPLACE   0
 
#define PARAMETER_REPLACE   1
 
#define ARRAY_REPLACE   2
 
#define REPLACE_TYPES   3
 
#define PARAMETER_TRANSFER   0
 
#define ARRAY_TRANSFER   1
 
#define TRANSFER_TYPES   2
 

Typedefs

typedef char * STRING_PAIR[2]
 

Enumerations

enum  option_type {
  SET_TAKE_COLUMNS , SET_LEAVE_COLUMNS , SET_MATCH_COLUMN , SET_EQUATE_COLUMN ,
  SET_TRANSFER , SET_REUSE , SET_IFNOT , SET_NOWARNINGS ,
  SET_IFIS , SET_PIPE , SET_FILLIN , SET_RENAME ,
  SET_EDIT_NAMES , SET_WILD_MATCH , SET_MAJOR_ORDER , SET_REPLACE ,
  N_OPTIONS
}
 

Functions

long expandTransferRequests (char ***match, int32_t *matches, long type, TRANSFER_DEFINITION *transfer, long transfers, SDDS_DATASET *inSet)
 
void add_newnames (SDDS_DATASET *SDDS_dataset, REFDATA *new_data, REFDATA rename_data, EDIT_NAME_REQUEST *edit_column_request, long edit_column_requests, EDIT_NAME_REQUEST *edit_parameter_request, long edit_parameter_requests, EDIT_NAME_REQUEST *edit_array_request, long edit_array_requests, long filenumber)
 
char ** process_editnames (char **orig_name, long **orig_flags, long orig_names, EDIT_NAME_REQUEST *edit_request, long edit_requests, long filenumber)
 
long CopyRowToNewColumn (SDDS_DATASET *target, int64_t target_row, SDDS_DATASET *source, int64_t source_row, REFDATA new_data, long columns, char *input2)
 
long CopyParametersFromSecondInput (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, REFDATA new_data)
 
long CopyArraysFromSecondInput (SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, REFDATA new_data)
 
int main (int argc, char **argv)
 

Variables

static char * mode_name [MODES]
 
static char * replace_type [REPLACE_TYPES]
 
static char * transfer_type [TRANSFER_TYPES]
 
char * option [N_OPTIONS]
 
char * USAGE
 

Detailed Description

Creates an SDDS data set by cross-referencing two or more input data sets.

The sddsxref program merges data from one SDDS file into another based on matching or filtering of column data. It allows selective transfer of columns, parameters, and arrays, along with options for renaming and editing names. This is a faster version of sddsmxref with fewer capabilities.

Usage

sddsxref [<input1>] <input2> <input3> [<input4>...] [<output>]
[-pipe[=input][,output]]
[-ifis={column|parameter|array},<name>[,...]]
[-ifnot={parameter|column|array},<name>[,...]]
[-transfer={parameter|array},<name>[,...]]
[-take=<column-name>[,...]]
[-leave=<column-name>[,...]]
[-replace=column|parameter|array,<name list>]
[-fillIn]
[-reuse[=[rows][,page]]]
[-match=<column-name>[=<column-name>]]
[-wildMatch=<column-name>[=<column-name>]]
[-rename={column|parameter|array},<oldname>=<newname>[,...]]
[-editnames={column|parameter|array},<wildcard-string>,<edit-string>]
[-equate=<column-name>[=<column-name>]]
[-majorOrder=row|column]
License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday, L. Emery, H. Shang

Definition in file sddsxref.c.

Macro Definition Documentation

◆ ARRAY_MODE

#define ARRAY_MODE   2

Definition at line 70 of file sddsxref.c.

◆ ARRAY_REPLACE

#define ARRAY_REPLACE   2

Definition at line 80 of file sddsxref.c.

◆ ARRAY_TRANSFER

#define ARRAY_TRANSFER   1

Definition at line 86 of file sddsxref.c.

◆ COLUMN_MODE

#define COLUMN_MODE   0

Definition at line 68 of file sddsxref.c.

◆ COLUMN_REPLACE

#define COLUMN_REPLACE   0

Definition at line 78 of file sddsxref.c.

◆ MODES

#define MODES   3

Definition at line 71 of file sddsxref.c.

◆ PARAMETER_MODE

#define PARAMETER_MODE   1

Definition at line 69 of file sddsxref.c.

◆ PARAMETER_REPLACE

#define PARAMETER_REPLACE   1

Definition at line 79 of file sddsxref.c.

◆ PARAMETER_TRANSFER

#define PARAMETER_TRANSFER   0

Definition at line 85 of file sddsxref.c.

◆ REPLACE_TYPES

#define REPLACE_TYPES   3

Definition at line 81 of file sddsxref.c.

◆ TRANSFER_TYPES

#define TRANSFER_TYPES   2

Definition at line 87 of file sddsxref.c.

Typedef Documentation

◆ STRING_PAIR

typedef char* STRING_PAIR[2]

Definition at line 132 of file sddsxref.c.

Enumeration Type Documentation

◆ option_type

enum option_type

Definition at line 48 of file sddsxref.c.

48 {
49 SET_TAKE_COLUMNS,
50 SET_LEAVE_COLUMNS,
51 SET_MATCH_COLUMN,
52 SET_EQUATE_COLUMN,
53 SET_TRANSFER,
54 SET_REUSE,
55 SET_IFNOT,
56 SET_NOWARNINGS,
57 SET_IFIS,
58 SET_PIPE,
59 SET_FILLIN,
60 SET_RENAME,
61 SET_EDIT_NAMES,
62 SET_WILD_MATCH,
63 SET_MAJOR_ORDER,
64 SET_REPLACE,
65 N_OPTIONS
66};

Function Documentation

◆ add_newnames()

void add_newnames ( SDDS_DATASET * SDDS_dataset,
REFDATA * new_data,
REFDATA rename_data,
EDIT_NAME_REQUEST * edit_column_request,
long edit_column_requests,
EDIT_NAME_REQUEST * edit_parameter_request,
long edit_parameter_requests,
EDIT_NAME_REQUEST * edit_array_request,
long edit_array_requests,
long filenumber )

Definition at line 1434 of file sddsxref.c.

1437 {
1438 long i, k = 0, *orig_columnflags;
1439 int32_t columns, parameters, arrays;
1440 long *orig_parameterflags, *orig_arrayflags;
1441 char **column_names, **parameter_names, **array_names, **new_names;
1442
1443 columns = parameters = arrays = 0;
1444 column_names = parameter_names = array_names = new_names = NULL;
1445 orig_columnflags = orig_parameterflags = orig_arrayflags = NULL;
1446 new_data->columns = new_data->parameters = new_data->arrays = 0;
1447 new_data->new_column = new_data->orig_column = NULL;
1448 new_data->new_parameter = new_data->orig_parameter = NULL;
1449 new_data->new_array = new_data->orig_array = NULL;
1450
1451 /* No edit requests at all */
1452 if (!edit_column_requests && !edit_parameter_requests && !edit_array_requests &&
1453 !rename_data.columns && !rename_data.parameters && !rename_data.arrays)
1454 return;
1455
1456 /* Transfer renames to new_data */
1457 (*new_data).columns = rename_data.columns;
1458 (*new_data).parameters = rename_data.parameters;
1459 (*new_data).arrays = rename_data.arrays;
1460 if (rename_data.columns) {
1461 (*new_data).new_column = (char **)malloc(sizeof(char *) * rename_data.columns);
1462 (*new_data).orig_column = (char **)malloc(sizeof(char *) * rename_data.columns);
1463 for (i = 0; i < rename_data.columns; i++) {
1464 SDDS_CopyString(&(*new_data).new_column[i], rename_data.new_column[i]);
1465 SDDS_CopyString(&(*new_data).orig_column[i], rename_data.orig_column[i]);
1466 }
1467 }
1468 if (rename_data.parameters) {
1469 (*new_data).new_parameter = (char **)malloc(sizeof(char *) * rename_data.parameters);
1470 (*new_data).orig_parameter = (char **)malloc(sizeof(char *) * rename_data.parameters);
1471 for (i = 0; i < rename_data.parameters; i++) {
1472 SDDS_CopyString(&(*new_data).new_parameter[i], rename_data.new_parameter[i]);
1473 SDDS_CopyString(&(*new_data).orig_parameter[i], rename_data.orig_parameter[i]);
1474 }
1475 }
1476 if (rename_data.arrays) {
1477 (*new_data).new_array = (char **)malloc(sizeof(char *) * rename_data.arrays);
1478 (*new_data).orig_array = (char **)malloc(sizeof(char *) * rename_data.arrays);
1479 for (i = 0; i < rename_data.arrays; i++) {
1480 SDDS_CopyString(&(*new_data).new_array[i], rename_data.new_array[i]);
1481 SDDS_CopyString(&(*new_data).orig_array[i], rename_data.orig_array[i]);
1482 }
1483 }
1484
1485 if (!(column_names = SDDS_GetColumnNames(SDDS_dataset, &columns))) {
1486 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1487 exit(EXIT_FAILURE);
1488 }
1489 if (!(parameter_names = SDDS_GetParameterNames(SDDS_dataset, &parameters))) {
1490 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1491 exit(EXIT_FAILURE);
1492 }
1493
1494 if (!(array_names = SDDS_GetArrayNames(SDDS_dataset, &arrays))) {
1495 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1496 exit(EXIT_FAILURE);
1497 }
1498
1499 /* Process edit names */
1500 if (edit_column_requests) {
1501 if ((new_names = process_editnames(column_names, &orig_columnflags, columns, edit_column_request, edit_column_requests, filenumber))) {
1502 for (i = 0; i < columns; i++) {
1503 if (orig_columnflags[i]) {
1504 k = (*new_data).columns;
1505 (*new_data).new_column = trealloc((*new_data).new_column, sizeof(char *) * (k + 1));
1506 (*new_data).orig_column = trealloc((*new_data).orig_column, sizeof(char *) * (k + 1));
1507 SDDS_CopyString(&(*new_data).new_column[k], new_names[i]);
1508 SDDS_CopyString(&(*new_data).orig_column[k], column_names[i]);
1509 (*new_data).columns++;
1510 }
1511 free(new_names[i]);
1512 }
1513 free(new_names);
1514 }
1515 }
1516
1517 if (edit_parameter_requests) {
1518 if ((new_names = process_editnames(parameter_names, &orig_parameterflags, parameters, edit_parameter_request, edit_parameter_requests, filenumber))) {
1519 for (i = 0; i < parameters; i++) {
1520 if (orig_parameterflags[i]) {
1521 k = (*new_data).parameters;
1522 (*new_data).new_parameter = trealloc((*new_data).new_parameter, sizeof(char *) * (k + 1));
1523 (*new_data).orig_parameter = trealloc((*new_data).orig_parameter, sizeof(char *) * (k + 1));
1524 SDDS_CopyString(&(*new_data).new_parameter[k], new_names[i]);
1525 SDDS_CopyString(&(*new_data).orig_parameter[k], parameter_names[i]);
1526 (*new_data).parameters++;
1527 }
1528 free(new_names[i]);
1529 }
1530 free(new_names);
1531 }
1532 }
1533
1534 if (edit_array_requests) {
1535 if ((new_names = process_editnames(array_names, &orig_arrayflags, arrays, edit_array_request, edit_array_requests, filenumber))) {
1536 for (i = 0; i < arrays; i++) {
1537 if (orig_arrayflags[i]) {
1538 k = (*new_data).arrays;
1539 (*new_data).new_array = trealloc((*new_data).new_array, sizeof(char *) * (k + 1));
1540 (*new_data).orig_array = trealloc((*new_data).orig_array, sizeof(char *) * (k + 1));
1541 SDDS_CopyString(&(*new_data).new_array[k], new_names[i]);
1542 SDDS_CopyString(&(*new_data).orig_array[k], array_names[i]);
1543 (*new_data).arrays++;
1544 }
1545 free(new_names[i]);
1546 }
1547 free(new_names);
1548 }
1549 }
1550
1551 if (orig_columnflags)
1552 free(orig_columnflags);
1553 if (orig_parameterflags)
1554 free(orig_parameterflags);
1555 if (orig_arrayflags)
1556 free(orig_arrayflags);
1557 for (i = 0; i < columns; i++)
1558 free(column_names[i]);
1559 free(column_names);
1560 for (i = 0; i < parameters; i++)
1561 free(parameter_names[i]);
1562 free(parameter_names);
1563 for (i = 0; i < arrays; i++)
1564 free(array_names[i]);
1565 free(array_names);
1566}
char ** SDDS_GetParameterNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all parameters in the SDDS dataset.
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.
Definition SDDS_utils.c:432
char ** SDDS_GetArrayNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all arrays in the SDDS dataset.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
Definition SDDS_utils.c:856
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181

◆ CopyArraysFromSecondInput()

long CopyArraysFromSecondInput ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
REFDATA new_data )

Definition at line 1700 of file sddsxref.c.

1700 {
1701 long i, j, k, m;
1702 char s[1024];
1703
1704 if (new_data.arrays == 0)
1705 return 1;
1706 for (i = 0; i < new_data.arrays; i++) {
1707 if ((j = SDDS_GetArrayIndex(SDDS_source, new_data.orig_array[i])) < 0)
1708 continue;
1709 if ((k = SDDS_GetArrayIndex(SDDS_target, new_data.new_array[i])) < 0) {
1710 sprintf(s, "Warning, array %s not defined in output.\n", new_data.new_array[i]);
1711 SDDS_SetError(s);
1712 continue;
1713 }
1714 if (SDDS_source->layout.array_definition[j].type != SDDS_target->layout.array_definition[k].type) {
1715 SDDS_SetError("Can't copy arrays between different types (SDDS_CopyArrays)");
1716 return 0;
1717 }
1718 SDDS_target->array[k].definition = SDDS_target->layout.array_definition + k;
1719 SDDS_target->array[k].elements = SDDS_source->array[j].elements;
1720 if (!(SDDS_target->array[k].dimension = (int32_t *)SDDS_Malloc(sizeof(*SDDS_target->array[k].dimension) * SDDS_target->array[k].definition->dimensions)) ||
1721 !(SDDS_target->array[k].data = SDDS_Realloc(SDDS_target->array[k].data, SDDS_type_size[SDDS_target->array[k].definition->type - 1] * SDDS_target->array[k].elements))) {
1722 SDDS_SetError("Unable to copy arrays--allocation failure (SDDS_CopyArrays)");
1723 return (0);
1724 }
1725 for (m = 0; m < SDDS_target->array[k].definition->dimensions; m++)
1726 SDDS_target->array[k].dimension[m] = SDDS_source->array[j].dimension[m];
1727
1728 if (SDDS_target->array[k].definition->type != SDDS_STRING)
1729 memcpy(SDDS_target->array[k].data, SDDS_source->array[j].data, SDDS_type_size[SDDS_target->array[k].definition->type - 1] * SDDS_target->array[k].elements);
1730 else if (!SDDS_CopyStringArray(SDDS_target->array[k].data, SDDS_source->array[j].data, SDDS_target->array[k].elements)) {
1731 SDDS_SetError("Unable to copy arrays (SDDS_CopyArrays)");
1732 return (0);
1733 }
1734 }
1735 return 1;
1736}
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
Definition SDDS_utils.c:639
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85

◆ CopyParametersFromSecondInput()

long CopyParametersFromSecondInput ( SDDS_DATASET * SDDS_target,
SDDS_DATASET * SDDS_source,
REFDATA new_data )

Definition at line 1674 of file sddsxref.c.

1674 {
1675 long i, j, k;
1676 char s[1024];
1677
1678 if (new_data.parameters == 0)
1679 return 1;
1680 if (new_data.parameters) {
1681 for (i = 0; i < new_data.parameters; i++) {
1682 if ((j = SDDS_GetParameterIndex(SDDS_source, new_data.orig_parameter[i])) < 0) {
1683 continue;
1684 }
1685
1686 if ((k = SDDS_GetParameterIndex(SDDS_target, new_data.new_parameter[i])) < 0) {
1687 fprintf(stderr, "Warning, parameter %s not defined in output.\n", new_data.new_parameter[i]);
1688 continue;
1689 }
1690 if (!SDDS_SetParameters(SDDS_target, SDDS_SET_BY_INDEX | SDDS_PASS_BY_REFERENCE, k, SDDS_source->parameter[j], -1)) {
1691 sprintf(s, "Unable to copy parameters for parameter %s", new_data.new_parameter[i]);
1692 SDDS_SetError(s);
1693 return (0);
1694 }
1695 }
1696 }
1697 return 1;
1698}
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.

◆ CopyRowToNewColumn()

long CopyRowToNewColumn ( SDDS_DATASET * target,
int64_t target_row,
SDDS_DATASET * source,
int64_t source_row,
REFDATA new_data,
long columns,
char * input2 )

Definition at line 1639 of file sddsxref.c.

1640 {
1641 long i, j, k, type, size;
1642 char s[1024];
1643
1644 if (!columns)
1645 return 1;
1646
1647 for (i = 0; i < columns; i++) {
1648 if ((j = SDDS_GetColumnIndex(source, new_data.orig_column[i])) < 0) {
1649 sprintf(s, "error: column %s not found in file %s\n", new_data.orig_column[i], input2);
1650 SDDS_SetError(s);
1651 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1652 continue;
1653 }
1654 if ((k = SDDS_GetColumnIndex(target, new_data.new_column[i])) < 0) {
1655 sprintf(s, "error: column %s not defined in output\n", new_data.new_column[i]);
1656 SDDS_SetError(s);
1657 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1658 continue;
1659 }
1660
1661 if ((type = SDDS_GetColumnType(target, k)) == SDDS_STRING) {
1662 if (!SDDS_CopyString(((char ***)target->data)[k] + target_row, ((char ***)source->data)[j][source_row])) {
1663 SDDS_SetError("Unable to copy row--string copy failed (SDDS_CopyRow)");
1664 return (0);
1665 }
1666 } else {
1667 size = SDDS_type_size[type - 1];
1668 memcpy((char *)target->data[k] + size * target_row, (char *)source->data[j] + size * source_row, size);
1669 }
1670 }
1671 return (1);
1672}
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
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.

◆ expandTransferRequests()

long expandTransferRequests ( char *** match,
int32_t * matches,
long type,
TRANSFER_DEFINITION * transfer,
long transfers,
SDDS_DATASET * inSet )

Definition at line 1401 of file sddsxref.c.

1402 {
1403 long i, first;
1404 int32_t (*matchRoutine)(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode, ...);
1405
1406 *matches = 0;
1407 *match = NULL;
1408 if (!transfers)
1409 return 1;
1410 switch (type) {
1411 case PARAMETER_TRANSFER:
1412 matchRoutine = SDDS_MatchParameters;
1413 break;
1414 case ARRAY_TRANSFER:
1415 matchRoutine = SDDS_MatchArrays;
1416 break;
1417 default:
1418 SDDS_Bomb("invalid transfer type--this shouldn't happen");
1419 exit(EXIT_FAILURE);
1420 break;
1421 }
1422 first = 0;
1423 for (i = 0; i < transfers; i++) {
1424 if (transfer[i].type == type) {
1425 if ((*matches = (*matchRoutine)(inSet, match, SDDS_MATCH_STRING, FIND_ANY_TYPE, transfer[i].name, SDDS_OR | (first ? SDDS_0_PREVIOUS : 0))) == -1) {
1426 return 0;
1427 }
1428 first = 0;
1429 }
1430 }
1431 return 1;
1432}
int32_t SDDS_MatchParameters(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves parameter names from an SDDS dataset based on specified criteria.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
int32_t SDDS_MatchArrays(SDDS_DATASET *SDDS_dataset, char ***nameReturn, int32_t matchMode, int32_t typeMode,...)
Matches and retrieves array names from an SDDS dataset based on specified criteria.

◆ main()

int main ( int argc,
char ** argv )

Definition at line 175 of file sddsxref.c.

175 {
176 SDDS_DATASET SDDS_1, SDDS_output;
177 SDDS_DATASET *SDDS_ref;
178 REFDATA *new_data, rename_data, *take_RefData, *replace_RefData;
179 long j, i_arg, reuse, reusePage, endWarning, k;
180 int64_t i, i1, i2, i3, rows1, rows2, rows2Max;
181 SCANNED_ARG *s_arg;
182 char s[200], *ptr;
183
184 char **take_column, **leave_column, **replace_column, **replace_parameter, **replace_array, **output_column = NULL;
185 char **inputfile, **referfile;
186 char **match_column, **equate_column;
187 long take_columns, replace_columns, leave_columns, match_columns, equate_columns, leave_all_columns, replace_parameters, replace_arrays;
188 int32_t output_columns = 0;
189 char *input1, *input2, *output;
190 long tmpfile_used, retval1, retval2, inputfiles, referfiles;
191 long wildMatch;
192 TRANSFER_DEFINITION *transfer;
193 long transfers;
194 long warnings;
195 IFITEM_LIST ifnot_item, ifis_item;
196 unsigned long pipeFlags, majorOrderFlag;
197 long fillIn, keyGroups = 0;
198 KEYED_EQUIVALENT **keyGroup = NULL;
199 long outputInitialized;
200 int z, it, itm, datatype1, datatype2;
201 long col;
202 int firstRun, copyInput1Only;
203 char **string1, **string2;
204 double *value1, *value2;
205 long matched;
206 short columnMajorOrder = -1;
207
208 EDIT_NAME_REQUEST *edit_column_request, *edit_parameter_request, *edit_array_request;
209 long edit_column_requests, edit_parameter_requests, edit_array_requests;
210
212 argc = scanargs(&s_arg, argc, argv);
213 if (argc < 3) {
214 fprintf(stderr, "%s", USAGE);
215 exit(EXIT_FAILURE);
216 }
217
218 SDDS_ref = NULL;
219 take_RefData = replace_RefData = NULL;
220 new_data = NULL;
221
222 rename_data.columns = rename_data.parameters = rename_data.arrays = 0;
223 rename_data.new_column = rename_data.orig_column = rename_data.new_parameter = rename_data.orig_parameter = rename_data.new_array = rename_data.orig_array = NULL;
224 edit_column_request = edit_parameter_request = edit_array_request = NULL;
225 edit_column_requests = edit_parameter_requests = edit_array_requests = 0;
226
227 input1 = input2 = output = NULL;
228 take_column = leave_column = replace_column = replace_parameter = replace_array = NULL;
229 match_column = equate_column = NULL;
230 inputfile = referfile = NULL;
231 take_columns = leave_columns = replace_columns = match_columns = equate_columns = reuse = reusePage = replace_parameters = replace_arrays = 0;
232 tmpfile_used = inputfiles = referfiles = 0;
233 transfer = NULL;
234 transfers = 0;
235 ifnot_item.items = ifis_item.items = 0;
236 warnings = 1;
237 pipeFlags = 0;
238 fillIn = 0;
239 outputInitialized = 0;
240 rows1 = rows2 = output_columns = 0;
241 string1 = string2 = NULL;
242 wildMatch = 0;
243
244 for (i_arg = 1; i_arg < argc; i_arg++) {
245 if (s_arg[i_arg].arg_type == OPTION) {
246 delete_chars(s_arg[i_arg].list[0], "_");
247 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
248 case SET_MAJOR_ORDER:
249 majorOrderFlag = 0;
250 s_arg[i_arg].n_items--;
251 if (s_arg[i_arg].n_items > 0 &&
252 (!scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
253 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
254 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
255 SDDS_Bomb("invalid -majorOrder syntax/values");
256 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
257 columnMajorOrder = 1;
258 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
259 columnMajorOrder = 0;
260 break;
261 case SET_LEAVE_COLUMNS:
262 if (s_arg[i_arg].n_items < 2)
263 SDDS_Bomb("invalid -leave syntax");
264 leave_column = trealloc(leave_column, sizeof(*leave_column) * (leave_columns + s_arg[i_arg].n_items - 1));
265 for (i = 1; i < s_arg[i_arg].n_items; i++)
266 leave_column[i - 1 + leave_columns] = s_arg[i_arg].list[i];
267 leave_columns += s_arg[i_arg].n_items - 1;
268 break;
269 case SET_TAKE_COLUMNS:
270 if (s_arg[i_arg].n_items < 2)
271 SDDS_Bomb("invalid -take syntax");
272 take_column = trealloc(take_column, sizeof(*take_column) * (take_columns + s_arg[i_arg].n_items - 1));
273 for (i = 1; i < s_arg[i_arg].n_items; i++)
274 take_column[i - 1 + take_columns] = s_arg[i_arg].list[i];
275 take_columns += s_arg[i_arg].n_items - 1;
276 break;
277 case SET_WILD_MATCH:
278 wildMatch = 1;
279 /* fall-through to SET_MATCH_COLUMN */
280 case SET_MATCH_COLUMN:
281 if (s_arg[i_arg].n_items != 2)
282 SDDS_Bomb("invalid -match or -wildMatch syntax");
283 if (match_columns != 0)
284 SDDS_Bomb("only one -match or -wildMatch option may be given");
285 match_column = tmalloc(sizeof(*match_column) * 2);
286 if ((ptr = strchr(s_arg[i_arg].list[1], '=')))
287 *ptr++ = 0;
288 else
289 ptr = s_arg[i_arg].list[1];
290 match_column[0] = s_arg[i_arg].list[1];
291 match_column[1] = ptr;
292 match_columns = 1;
293 break;
294 case SET_EQUATE_COLUMN:
295 if (s_arg[i_arg].n_items != 2)
296 SDDS_Bomb("invalid -equate syntax");
297 if (equate_columns != 0)
298 SDDS_Bomb("only one -equate option may be given");
299 equate_column = tmalloc(sizeof(*equate_column) * 2);
300 if ((ptr = strchr(s_arg[i_arg].list[1], '=')))
301 *ptr++ = 0;
302 else
303 ptr = s_arg[i_arg].list[1];
304 equate_column[0] = s_arg[i_arg].list[1];
305 equate_column[1] = ptr;
306 equate_columns = 1;
307 break;
308 case SET_REPLACE:
309 if (s_arg[i_arg].n_items < 3)
310 SDDS_Bomb("invalid -replace syntax");
311 switch (match_string(s_arg[i_arg].list[1], replace_type, REPLACE_TYPES, 0)) {
312 case COLUMN_REPLACE:
313 replace_column = trealloc(replace_column, sizeof(*replace_column) * (replace_columns + s_arg[i_arg].n_items - 2));
314 for (i = 2; i < s_arg[i_arg].n_items; i++)
315 replace_column[i - 2 + replace_columns] = s_arg[i_arg].list[i];
316 replace_columns += s_arg[i_arg].n_items - 2;
317 break;
318 case PARAMETER_REPLACE:
319 replace_parameter = trealloc(replace_parameter, sizeof(*replace_parameter) * (replace_parameters + s_arg[i_arg].n_items - 2));
320 for (i = 2; i < s_arg[i_arg].n_items; i++)
321 replace_parameter[i - 2 + replace_parameters] = s_arg[i_arg].list[i];
322 replace_parameters += s_arg[i_arg].n_items - 2;
323 break;
324 case ARRAY_REPLACE:
325 replace_array = trealloc(replace_array, sizeof(*replace_array) * (replace_arrays + s_arg[i_arg].n_items - 2));
326 for (i = 2; i < s_arg[i_arg].n_items; i++)
327 replace_array[i - 2 + replace_arrays] = s_arg[i_arg].list[i];
328 replace_arrays += s_arg[i_arg].n_items - 2;
329 break;
330 default:
331 SDDS_Bomb("unknown type of transfer");
332 break;
333 }
334 break;
335 case SET_TRANSFER:
336 if (s_arg[i_arg].n_items < 3)
337 SDDS_Bomb("invalid -transfer syntax");
338 transfer = trealloc(transfer, sizeof(*transfer) * (transfers + s_arg[i_arg].n_items - 2));
339 switch (match_string(s_arg[i_arg].list[1], transfer_type, TRANSFER_TYPES, 0)) {
340 case PARAMETER_TRANSFER:
341 for (i = 2; i < s_arg[i_arg].n_items; i++) {
342 transfer[i - 2 + transfers].type = PARAMETER_TRANSFER;
343 transfer[i - 2 + transfers].name = s_arg[i_arg].list[i];
344 }
345 break;
346 case ARRAY_TRANSFER:
347 for (i = 2; i < s_arg[i_arg].n_items; i++) {
348 transfer[i - 2 + transfers].type = ARRAY_TRANSFER;
349 transfer[i - 2 + transfers].name = s_arg[i_arg].list[i];
350 }
351 break;
352 default:
353 SDDS_Bomb("unknown type of transfer");
354 break;
355 }
356 transfers += s_arg[i_arg].n_items - 2;
357 break;
358 case SET_REUSE:
359 if (s_arg[i_arg].n_items == 1)
360 reuse = 1;
361 else {
362 char *reuseOptions[2] = {"rows", "page"};
363 for (i = 1; i < s_arg[i_arg].n_items; i++) {
364 switch (match_string(s_arg[i_arg].list[i], reuseOptions, 2, 0)) {
365 case 0:
366 reuse = 1;
367 break;
368 case 1:
369 reusePage = 1;
370 break;
371 default:
372 SDDS_Bomb("unknown reuse keyword");
373 break;
374 }
375 }
376 }
377 break;
378 case SET_IFNOT:
379 if (s_arg[i_arg].n_items < 3)
380 SDDS_Bomb("invalid -ifnot usage");
381 add_ifitem(&ifnot_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
382 break;
383 case SET_NOWARNINGS:
384 warnings = 0;
385 break;
386 case SET_IFIS:
387 if (s_arg[i_arg].n_items < 3)
388 SDDS_Bomb("invalid -ifis usage");
389 add_ifitem(&ifis_item, s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1);
390 break;
391 case SET_PIPE:
392 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
393 SDDS_Bomb("invalid -pipe syntax");
394 break;
395 case SET_FILLIN:
396 fillIn = 1;
397 break;
398 case SET_RENAME:
399 if (s_arg[i_arg].n_items < 3)
400 SDDS_Bomb("invalid -rename syntax");
401 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
402 case COLUMN_MODE:
403 k = rename_data.columns;
404 rename_data.new_column = trealloc(rename_data.new_column, sizeof(char *) * (k + s_arg[i_arg].n_items - 2));
405 rename_data.orig_column = trealloc(rename_data.orig_column, sizeof(char *) * (k + s_arg[i_arg].n_items - 2));
406 for (i = 2; i < s_arg[i_arg].n_items; i++) {
407 if (!(ptr = strchr(s_arg[i_arg].list[i], '=')))
408 SDDS_Bomb("invalid -rename syntax");
409 *ptr++ = 0;
410 rename_data.orig_column[k + i - 2] = s_arg[i_arg].list[i];
411 rename_data.new_column[k + i - 2] = ptr;
412 }
413 rename_data.columns += s_arg[i_arg].n_items - 2;
414 break;
415 case PARAMETER_MODE:
416 k = rename_data.parameters;
417 rename_data.new_parameter = trealloc(rename_data.new_parameter, sizeof(char *) * (k + s_arg[i_arg].n_items - 2));
418 rename_data.orig_parameter = trealloc(rename_data.orig_parameter, sizeof(char *) * (k + s_arg[i_arg].n_items - 2));
419 for (i = 2; i < s_arg[i_arg].n_items; i++) {
420 if (!(ptr = strchr(s_arg[i_arg].list[i], '=')))
421 SDDS_Bomb("invalid -rename syntax");
422 *ptr++ = 0;
423 rename_data.orig_parameter[k + i - 2] = s_arg[i_arg].list[i];
424 rename_data.new_parameter[k + i - 2] = ptr;
425 }
426 rename_data.parameters += s_arg[i_arg].n_items - 2;
427 break;
428 case ARRAY_MODE:
429 k = rename_data.arrays;
430 rename_data.new_array = trealloc(rename_data.new_array, sizeof(char *) * (k + s_arg[i_arg].n_items - 2));
431 rename_data.orig_array = trealloc(rename_data.orig_array, sizeof(char *) * (k + s_arg[i_arg].n_items - 2));
432 for (i = 2; i < s_arg[i_arg].n_items; i++) {
433 if (!(ptr = strchr(s_arg[i_arg].list[i], '=')))
434 SDDS_Bomb("invalid -rename syntax");
435 *ptr++ = 0;
436 rename_data.orig_array[k + i - 2] = s_arg[i_arg].list[i];
437 rename_data.new_array[k + i - 2] = ptr;
438 }
439 rename_data.arrays += s_arg[i_arg].n_items - 2;
440 break;
441 default:
442 SDDS_Bomb("invalid -rename syntax: specify column, parameter, or array keyword");
443 break;
444 }
445 break;
446 case SET_EDIT_NAMES:
447 if (s_arg[i_arg].n_items != 4)
448 SDDS_Bomb("invalid -editnames syntax");
449 switch (match_string(s_arg[i_arg].list[1], mode_name, MODES, 0)) {
450 case COLUMN_MODE:
451 edit_column_request = trealloc(edit_column_request, sizeof(*edit_column_request) * (edit_column_requests + 1));
452 edit_column_request[edit_column_requests].match_string = s_arg[i_arg].list[2];
453 edit_column_request[edit_column_requests].edit_string = s_arg[i_arg].list[3];
454 edit_column_requests++;
455 break;
456 case PARAMETER_MODE:
457 edit_parameter_request = trealloc(edit_parameter_request, sizeof(*edit_parameter_request) * (edit_parameter_requests + 1));
458 edit_parameter_request[edit_parameter_requests].match_string = s_arg[i_arg].list[2];
459 edit_parameter_request[edit_parameter_requests].edit_string = s_arg[i_arg].list[3];
460 edit_parameter_requests++;
461 break;
462 case ARRAY_MODE:
463 edit_array_request = trealloc(edit_array_request, sizeof(*edit_array_request) * (edit_array_requests + 1));
464 edit_array_request[edit_array_requests].match_string = s_arg[i_arg].list[2];
465 edit_array_request[edit_array_requests].edit_string = s_arg[i_arg].list[3];
466 edit_array_requests++;
467 break;
468 default:
469 SDDS_Bomb("invalid -editnames syntax: specify column, parameter, or array keyword");
470 break;
471 }
472 break;
473 default:
474 fprintf(stderr, "error: unknown switch: %s\n", s_arg[i_arg].list[0]);
475 SDDS_Bomb(NULL);
476 break;
477 }
478 } else {
479 inputfile = trealloc(inputfile, sizeof(*inputfile) * (inputfiles + 1));
480 inputfile[inputfiles++] = s_arg[i_arg].list[0];
481 }
482 }
483
484 if (inputfiles == 0) {
485 SDDS_Bomb("too few reference files given");
486 } else {
487 if (!(pipeFlags & USE_STDIN) && !(pipeFlags & USE_STDOUT)) {
488 if (inputfiles < 2) {
489 SDDS_Bomb("too few reference files given");
490 } else if (inputfiles == 2) {
491 input1 = output = inputfile[0];
492 referfile = trealloc(referfile, sizeof(*referfile) * (referfiles + 1));
493 referfile[0] = inputfile[1];
494 referfiles++;
495 } else {
496 input1 = inputfile[0];
497 output = inputfile[--inputfiles];
498 for (z = 1; z < inputfiles; z++) {
499 referfile = trealloc(referfile, sizeof(*referfile) * (referfiles + 1));
500 referfile[z - 1] = inputfile[z];
501 referfiles++;
502 }
503 }
504 } else if (!(pipeFlags & USE_STDIN) && (pipeFlags & USE_STDOUT)) {
505 if (inputfiles < 2) {
506 SDDS_Bomb("too few reference files given");
507 } else {
508 input1 = inputfile[0];
509 for (z = 1; z < inputfiles; z++) {
510 referfile = trealloc(referfile, sizeof(*referfile) * (referfiles + 1));
511 referfile[z - 1] = inputfile[z];
512 referfiles++;
513 }
514 }
515 } else if ((pipeFlags & USE_STDIN) && !(pipeFlags & USE_STDOUT)) {
516 if (inputfiles < 2) {
517 SDDS_Bomb("too few reference files given");
518 } else {
519 output = inputfile[--inputfiles];
520 for (z = 0; z < inputfiles; z++) {
521 referfile = trealloc(referfile, sizeof(*referfile) * (referfiles + 1));
522 referfile[z] = inputfile[z];
523 referfiles++;
524 }
525 }
526 } else {
527 for (z = 0; z < inputfiles; z++) {
528 referfile = trealloc(referfile, sizeof(*referfile) * (referfiles + 1));
529 referfile[z] = inputfile[z];
530 referfiles++;
531 }
532 }
533 }
534
535 processFilenames("sddsxref", &input1, &output, pipeFlags, !warnings, &tmpfile_used);
536
537 if (equate_columns && match_columns)
538 SDDS_Bomb("only one of -equate or -match may be given");
539
540 if (!SDDS_InitializeInput(&SDDS_1, input1)) {
541 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
542 exit(EXIT_FAILURE);
543 }
544
545 if (!check_ifitems(&SDDS_1, &ifnot_item, 0, warnings) || !check_ifitems(&SDDS_1, &ifis_item, 1, warnings))
546 exit(EXIT_SUCCESS);
547
548 for (it = 0; it < ifnot_item.items; it++) {
549 switch (ifnot_item.type[it]) {
550 case COLUMN_BASED:
551 leave_column = trealloc(leave_column, sizeof(*leave_column) * (leave_columns + 1));
552 leave_column[leave_columns] = ifnot_item.name[it];
553 leave_columns++;
554 break;
555 case PARAMETER_BASED:
556 for (itm = 0; itm < transfers; itm++) {
557 if (strcmp(transfer[itm].name, ifnot_item.name[it]) == 0) {
558 SDDS_Bomb("Excluded item is a part of -transfer list.");
559 exit(EXIT_FAILURE);
560 }
561 }
562 break;
563 case ARRAY_BASED:
564 for (itm = 0; itm < transfers; itm++) {
565 if (strcmp(transfer[itm].name, ifnot_item.name[it]) == 0) {
566 SDDS_Bomb("Excluded item is a part of -transfer list.");
567 exit(EXIT_FAILURE);
568 }
569 }
570 break;
571 default:
572 SDDS_Bomb("internal error---unknown ifitem type");
573 exit(EXIT_FAILURE);
574 break;
575 }
576 }
577
578 /* Allocate memory for new_data */
579 new_data = malloc(sizeof(*new_data) * referfiles);
580 for (z = 0; z < referfiles; z++) {
581 SDDS_ref = trealloc(SDDS_ref, sizeof(*SDDS_ref) * (z + 1));
582 input2 = referfile[z];
583 if (!SDDS_InitializeInput(&SDDS_ref[z], input2)) {
584 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
585 exit(EXIT_FAILURE);
586 }
587
588 take_RefData = trealloc(take_RefData, sizeof(*take_RefData) * (z + 1));
589 take_RefData[z].columns = 0;
590 replace_RefData = trealloc(replace_RefData, sizeof(*replace_RefData) * (z + 1));
591 replace_RefData[z].columns = replace_RefData[z].parameters = replace_RefData[z].arrays = 0;
592
593 add_newnames(&SDDS_ref[z], &new_data[z], rename_data, edit_column_request, edit_column_requests,
594 edit_parameter_request, edit_parameter_requests, edit_array_request, edit_array_requests, z + 1);
595
596 if (SDDS_ColumnCount(&SDDS_ref[z])) {
597 SDDS_SetColumnFlags(&SDDS_ref[z], 1);
598 if (take_columns) {
599 SDDS_SetColumnFlags(&SDDS_ref[z], 0);
600 for (i = 0; i < take_columns; i++) {
601 if (!has_wildcards(take_column[i]) && SDDS_GetColumnIndex(&SDDS_ref[z], take_column[i]) < 0) {
602 sprintf(s, "error: column %s not found in file %s take_columns %ld SDDS_ref[z] %" PRId64 "\n", take_column[i], input2, take_columns, SDDS_ref[z].n_rows);
603 SDDS_SetError(s);
604 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
605 }
606 if (!SDDS_SetColumnsOfInterest(&SDDS_ref[z], SDDS_MATCH_STRING, take_column[i], SDDS_OR))
607 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
608 }
609 }
610
611 leave_all_columns = 0;
612 if (leave_columns == 1 && strcmp(leave_column[0], "*") == 0)
613 leave_all_columns = 1;
614 else {
615 if (!take_columns)
616 SDDS_SetColumnFlags(&SDDS_ref[z], 1);
617 for (i = 0; i < leave_columns; i++) {
618 if (!has_wildcards(leave_column[i]) &&
619 SDDS_GetColumnIndex(&SDDS_ref[z], leave_column[i]) < 0)
620 continue;
621 if (!SDDS_SetColumnsOfInterest(&SDDS_ref[z], SDDS_MATCH_STRING, leave_column[i], SDDS_AND | SDDS_NEGATE_MATCH))
622 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
623 }
624
625 if (!(take_RefData[z].orig_column = (char **)SDDS_GetColumnNames(&SDDS_ref[z], &take_RefData[z].columns))) {
626 SDDS_SetError("error: no columns selected to take from input file");
627 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
628 }
629 }
630 if (replace_columns) {
631 SDDS_SetColumnFlags(&SDDS_ref[z], 0);
632 for (i = 0; i < replace_columns; i++) {
633 if (!has_wildcards(replace_column[i]) && SDDS_GetColumnIndex(&SDDS_ref[z], replace_column[i]) < 0) {
634 sprintf(s, "error: column %s not found in file %s replace_columns %ld SDDS_ref[z] %" PRId64 "\n", replace_column[i], input2, replace_columns, SDDS_ref[z].n_rows);
635 SDDS_SetError(s);
636 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
637 }
638 if (!SDDS_SetColumnsOfInterest(&SDDS_ref[z], SDDS_MATCH_STRING, replace_column[i], SDDS_OR))
639 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
640 }
641 if (!(replace_RefData[z].orig_column = (char **)SDDS_GetColumnNames(&SDDS_ref[z], &replace_RefData[z].columns))) {
642 SDDS_SetError("error: no columns selected to replace from input file");
643 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
644 }
645 }
646 if (match_columns) {
647 if ((j = SDDS_GetColumnIndex(&SDDS_1, match_column[0])) < 0 ||
648 SDDS_GetColumnType(&SDDS_1, j) != SDDS_STRING) {
649 sprintf(s, "error: column %s not found or not string type in file %s", match_column[0], input1 ? input1 : "stdin");
650 SDDS_SetError(s);
651 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
652 }
653 if ((j = SDDS_GetColumnIndex(&SDDS_ref[z], match_column[1])) < 0 ||
654 SDDS_GetColumnType(&SDDS_ref[z], j) != SDDS_STRING) {
655 sprintf(s, "error: column %s not found or not string type in file %s", match_column[1], input2);
656 SDDS_SetError(s);
657 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
658 }
659 }
660 if (equate_columns) {
661 if ((j = SDDS_GetColumnIndex(&SDDS_1, equate_column[0])) < 0 ||
663 sprintf(s, "error: column %s not found or not numeric type in file %s", equate_column[0], input1 ? input1 : "stdin");
664 SDDS_SetError(s);
665 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
666 }
667 if ((j = SDDS_GetColumnIndex(&SDDS_ref[z], equate_column[1])) < 0 ||
668 !SDDS_NUMERIC_TYPE(SDDS_GetColumnType(&SDDS_ref[z], j))) {
669 sprintf(s, "error: column %s not found or not numeric type in file %s", equate_column[1], input2);
670 SDDS_SetError(s);
671 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
672 }
673 }
674 } else {
675 take_RefData[z].columns = 0;
676 leave_all_columns = 1;
677 }
678 if (!take_RefData[z].columns && !leave_all_columns && warnings)
679 fprintf(stderr, "warning: there are no columns being taken from %s that are not already in %s\n", input2, input1 ? input1 : "stdin");
680
681 if (leave_all_columns)
682 take_RefData[z].columns = 0;
683
684 if (!outputInitialized) {
685 if (!SDDS_InitializeCopy(&SDDS_output, &SDDS_1, output, "w")) {
686 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
687 exit(EXIT_FAILURE);
688 }
689 outputInitialized = 1;
690 if (columnMajorOrder != -1)
691 SDDS_output.layout.data_mode.column_major = columnMajorOrder;
692 else
693 SDDS_output.layout.data_mode.column_major = SDDS_1.layout.data_mode.column_major;
694 }
695
696 /* Get the new name for new_data if there is a match of original name */
697 if (take_RefData[z].columns)
698 take_RefData[z].new_column = (char **)malloc(sizeof(char *) * take_RefData[z].columns);
699
700 for (i = 0; i < take_RefData[z].columns; i++) {
701 k = 0;
702 /* If there are new names (renamed or edited), find the corresponding original name index,
703 and assign the new name to take_RefData */
704 if (new_data[z].columns) {
705 k = match_string(take_RefData[z].orig_column[i], new_data[z].orig_column, new_data[z].columns, EXACT_MATCH);
706 if (k == -1)
707 SDDS_CopyString(&take_RefData[z].new_column[i], take_RefData[z].orig_column[i]);
708 else
709 SDDS_CopyString(&take_RefData[z].new_column[i], new_data[z].new_column[k]);
710 } else
711 SDDS_CopyString(&take_RefData[z].new_column[i], take_RefData[z].orig_column[i]);
712 if (SDDS_GetColumnIndex(&SDDS_output, take_RefData[z].new_column[i]) >= 0) {
713 free(take_RefData[z].new_column[i]);
714 free(take_RefData[z].orig_column[i]);
715 for (j = i; j < take_RefData[z].columns - 1; j++)
716 take_RefData[z].orig_column[j] = take_RefData[z].orig_column[j + 1];
717 take_RefData[z].columns -= 1;
718 i--;
719 if (take_RefData[z].columns == 0)
720 break;
721 } else {
722 /* Transfer column definition */
723 if (!SDDS_TransferColumnDefinition(&SDDS_output, &SDDS_ref[z], take_RefData[z].orig_column[i], take_RefData[z].new_column[i]))
724 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
725 }
726 }
727
728 if (!take_RefData[z].columns && !leave_all_columns && warnings)
729 fprintf(stderr, "warning: there are no columns being taken from %s that are not already in %s\n", input2, input1 ? input1 : "stdin");
730 output_columns = 0;
731 if (take_RefData[z].columns &&
732 (!(output_column = (char **)SDDS_GetColumnNames(&SDDS_output, &output_columns)) || output_columns == 0)) {
733 SDDS_SetError("Problem getting output column names");
734 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
735 }
736 if (output_columns) {
737 for (i = 0; i < output_columns; i++)
738 free(output_column[i]);
739 free(output_column);
740 }
741 /* Check if the column in replace_column exists in the output file */
742 for (i = 0; i < replace_RefData[z].columns; i++) {
743 if (SDDS_GetColumnIndex(&SDDS_1, replace_RefData[z].orig_column[i]) < 0) {
744 if (warnings) {
745 fprintf(stderr, "Warning, %s replace column does not exist in the input1, ignore.\n", replace_RefData[z].orig_column[i]);
746 }
747 } else {
748 /* Check if column types are the same */
749 j = SDDS_GetColumnIndex(&SDDS_ref[z], replace_RefData[z].orig_column[i]);
750 k = SDDS_GetColumnIndex(&SDDS_output, replace_RefData[z].orig_column[i]);
751 datatype1 = SDDS_GetColumnType(&SDDS_ref[z], j);
752 datatype2 = SDDS_GetColumnType(&SDDS_output, k);
753 if (datatype1 != datatype2 && (datatype1 == SDDS_STRING || datatype2 == SDDS_STRING)) {
754 if (warnings) {
755 if (datatype1 == SDDS_STRING)
756 fprintf(stderr, "Warning: cannot replace a numeric column with a string column, replace %s ignored.\n", replace_RefData[z].orig_column[i]);
757 if (datatype2 == SDDS_STRING)
758 fprintf(stderr, "Warning: cannot replace a string column with a numeric column, replace %s ignored.\n", replace_RefData[z].orig_column[i]);
759 }
760 } else {
761 if (datatype1 != datatype2) {
762 if (warnings)
763 fprintf(stderr, "Warning, replace column %s has different data type as the column in input1; redefining the column type\n", replace_RefData[z].orig_column[i]);
764 if (!SDDS_ChangeColumnInformation(&SDDS_output, "type", SDDS_type_name[datatype1 - 1], SDDS_PASS_BY_STRING | SDDS_SET_BY_NAME, replace_RefData[z].orig_column[i])) {
765 fprintf(stderr, "Problem redefining column type for %s\n", replace_RefData[z].orig_column[i]);
766 exit(EXIT_FAILURE);
767 }
768 }
769 /* Add replace_column to take_column, while the orig_name and new_name are the same */
770 take_RefData[z].orig_column = trealloc(take_RefData[z].orig_column, sizeof(*(take_RefData[z].orig_column)) * (take_RefData[z].columns + 1));
771 take_RefData[z].new_column = trealloc(take_RefData[z].new_column, sizeof(*(take_RefData[z].new_column)) * (take_RefData[z].columns + 1));
772 SDDS_CopyString(&take_RefData[z].orig_column[take_RefData[z].columns], replace_RefData[z].orig_column[i]);
773 SDDS_CopyString(&take_RefData[z].new_column[take_RefData[z].columns], replace_RefData[z].orig_column[i]);
774 take_RefData[z].columns++;
775 }
776 }
777 free(replace_RefData[z].orig_column[i]);
778 }
779
780 take_RefData[z].parameters = take_RefData[z].arrays = 0;
781 if (transfers) {
782 if (!expandTransferRequests(&take_RefData[z].orig_parameter, &take_RefData[z].parameters, PARAMETER_TRANSFER, transfer, transfers, &SDDS_ref[z]) ||
783 !expandTransferRequests(&take_RefData[z].orig_array, &take_RefData[z].arrays, ARRAY_TRANSFER, transfer, transfers, &SDDS_ref[z]))
784 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
785 }
786
787 /* Get the new name for parameters, define parameters for output */
788 if (take_RefData[z].parameters)
789 take_RefData[z].new_parameter = (char **)malloc(sizeof(char *) * take_RefData[z].parameters);
790 if (take_RefData[z].arrays)
791 take_RefData[z].new_array = (char **)malloc(sizeof(char *) * take_RefData[z].arrays);
792
793 for (i = 0; i < take_RefData[z].parameters; i++) {
794 k = 0;
795 if (new_data[z].parameters) {
796 k = match_string(take_RefData[z].orig_parameter[i], new_data[z].orig_parameter, new_data[z].parameters, EXACT_MATCH);
797 if (k != -1)
798 SDDS_CopyString(&take_RefData[z].new_parameter[i], new_data[z].new_parameter[k]);
799 else
800 SDDS_CopyString(&take_RefData[z].new_parameter[i], take_RefData[z].orig_parameter[i]);
801 } else
802 SDDS_CopyString(&take_RefData[z].new_parameter[i], take_RefData[z].orig_parameter[i]);
803 if (SDDS_GetParameterIndex(&SDDS_output, take_RefData[z].new_parameter[i]) >= 0) {
804 free(take_RefData[z].orig_parameter[i]);
805 free(take_RefData[z].new_parameter[i]);
806 for (col = i; col < take_RefData[z].parameters - 1; col++)
807 take_RefData[z].orig_parameter[col] = take_RefData[z].orig_parameter[col + 1];
808 take_RefData[z].parameters -= 1;
809 i--;
810 if (take_RefData[z].parameters == 0)
811 break;
812 } else {
813 if (!SDDS_TransferParameterDefinition(&SDDS_output, &SDDS_ref[z], take_RefData[z].orig_parameter[i], take_RefData[z].new_parameter[i]))
814 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
815 }
816 }
817 /* Get the new name for arrays, and define arrays for output */
818 for (i = 0; i < take_RefData[z].arrays; i++) {
819 k = 0;
820 if (new_data[z].arrays) {
821 k = match_string(take_RefData[z].orig_array[i], new_data[z].orig_array, new_data[z].arrays, EXACT_MATCH);
822 if (k == -1)
823 SDDS_CopyString(&take_RefData[z].new_array[i], take_RefData[z].orig_array[i]);
824 else
825 SDDS_CopyString(&take_RefData[z].new_array[i], new_data[z].new_array[k]);
826 } else
827 SDDS_CopyString(&take_RefData[z].new_array[i], take_RefData[z].orig_array[i]);
828 if (SDDS_GetArrayIndex(&SDDS_output, take_RefData[z].new_array[i]) >= 0) {
829 free(take_RefData[z].orig_array[i]);
830 free(take_RefData[z].new_array[i]);
831 for (col = i; col < take_RefData[z].arrays - 1; col++)
832 take_RefData[z].orig_array[col] = take_RefData[z].orig_array[col + 1];
833 take_RefData[z].arrays -= 1;
834 i--;
835 if (take_RefData[z].arrays == 0)
836 break;
837 } else {
838 if (!SDDS_TransferArrayDefinition(&SDDS_output, &SDDS_ref[z], take_RefData[z].orig_array[i], take_RefData[z].new_array[i]))
839 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
840 }
841 }
842
843 /* Check replace parameters and arrays, adding them to take_refData */
844 if (replace_parameters) {
845 for (i = 0; i < replace_parameters; i++) {
846 replace_RefData[z].parameters += SDDS_MatchParameters(&SDDS_ref[z], &replace_RefData[z].orig_parameter, SDDS_MATCH_STRING, FIND_ANY_TYPE, replace_parameter[i], SDDS_OR | SDDS_1_PREVIOUS);
847 }
848
849 /* Check if replace parameters exist in input1 */
850 for (i = 0; i < replace_RefData[z].parameters; i++) {
851 if (SDDS_GetParameterIndex(&SDDS_1, replace_RefData[z].orig_parameter[i]) < 0) {
852 if (warnings) {
853 fprintf(stderr, "Warning, parameter %s replace parameter does not exist in the input1, ignore.\n", replace_RefData[z].orig_parameter[i]);
854 }
855 } else {
856 /* Check if parameter types are the same */
857 j = SDDS_GetParameterIndex(&SDDS_ref[z], replace_RefData[z].orig_parameter[i]);
858 k = SDDS_GetParameterIndex(&SDDS_output, replace_RefData[z].orig_parameter[i]);
859 datatype1 = SDDS_GetParameterType(&SDDS_ref[z], j);
860 datatype2 = SDDS_GetParameterType(&SDDS_output, k);
861 if (datatype1 != datatype2 && (datatype1 == SDDS_STRING || datatype2 == SDDS_STRING)) {
862 if (warnings) {
863 if (datatype1 == SDDS_STRING)
864 fprintf(stderr, "Warning: cannot replace a numeric parameter with a string parameter, replace %s ignored.\n", replace_RefData[z].orig_parameter[i]);
865 if (datatype2 == SDDS_STRING)
866 fprintf(stderr, "Warning: cannot replace a string parameter with a numeric parameter, replace %s ignored.\n", replace_RefData[z].orig_parameter[i]);
867 }
868 } else {
869 if (datatype1 != datatype2) {
870 if (warnings)
871 fprintf(stderr, "Warning, replace parameter %s type is different from input1, redefining parameter type.\n", replace_RefData[z].orig_parameter[i]);
872
873 if (!SDDS_ChangeParameterInformation(&SDDS_output, "type", SDDS_type_name[datatype1 - 1], SDDS_PASS_BY_STRING | SDDS_SET_BY_NAME, replace_RefData[z].orig_parameter[i])) {
874 fprintf(stderr, "Problem redefining parameter type for %s\n", replace_RefData[z].orig_parameter[i]);
875 exit(EXIT_FAILURE);
876 }
877 }
878 /* Add replace_parameter to take_parameter, while the orig_name and new_name are the same */
879 take_RefData[z].orig_parameter = trealloc(take_RefData[z].orig_parameter, sizeof(*(take_RefData[z].orig_parameter)) * (take_RefData[z].parameters + 1));
880 take_RefData[z].new_parameter = trealloc(take_RefData[z].new_parameter, sizeof(*(take_RefData[z].new_parameter)) * (take_RefData[z].parameters + 1));
881 SDDS_CopyString(&take_RefData[z].orig_parameter[take_RefData[z].parameters], replace_RefData[z].orig_parameter[i]);
882 SDDS_CopyString(&take_RefData[z].new_parameter[take_RefData[z].parameters], replace_RefData[z].orig_parameter[i]);
883 take_RefData[z].parameters++;
884 }
885 }
886 free(replace_RefData[z].orig_parameter[i]);
887 }
888
889 if (replace_arrays) {
890 for (i = 0; i < replace_arrays; i++) {
891 replace_RefData[z].arrays += SDDS_MatchArrays(&SDDS_ref[z], &replace_RefData[z].orig_array, SDDS_MATCH_STRING, FIND_ANY_TYPE, replace_array[i], SDDS_OR | SDDS_1_PREVIOUS);
892 }
893 /* Check if replace arrays exist in input1 */
894 for (i = 0; i < replace_RefData[z].arrays; i++) {
895 if (SDDS_GetArrayIndex(&SDDS_1, replace_RefData[z].orig_array[i]) < 0) {
896 if (warnings) {
897 fprintf(stderr, "Warning, array %s replace array does not exist in the input, ignore.\n", replace_RefData[z].orig_array[i]);
898 }
899 } else {
900 /* Check if array types are the same */
901 j = SDDS_GetArrayIndex(&SDDS_ref[z], replace_RefData[z].orig_array[i]);
902 k = SDDS_GetArrayIndex(&SDDS_output, replace_RefData[z].orig_array[i]);
903 datatype1 = SDDS_GetArrayType(&SDDS_ref[z], j);
904 datatype2 = SDDS_GetArrayType(&SDDS_output, k);
905 if (datatype1 != datatype2 && (datatype1 == SDDS_STRING || datatype2 == SDDS_STRING)) {
906 if (warnings) {
907 if (datatype1 == SDDS_STRING)
908 fprintf(stderr, "Warning: cannot replace a numeric array with a string array, replace %s ignored.\n", replace_RefData[z].orig_array[i]);
909 if (datatype2 == SDDS_STRING)
910 fprintf(stderr, "Warning: cannot replace a string array with a numeric array, replace %s ignored.\n", replace_RefData[z].orig_array[i]);
911 }
912 } else {
913 if (datatype1 != datatype2) {
914 if (warnings)
915 fprintf(stderr, "Warning, replace array %s has different data type as the array in input1; redefining\n", replace_RefData[z].orig_array[i]);
916 if (!SDDS_ChangeArrayInformation(&SDDS_output, "type", SDDS_type_name[datatype1 - 1], SDDS_PASS_BY_STRING | SDDS_SET_BY_NAME, replace_RefData[z].orig_array[i])) {
917 fprintf(stderr, "Problem redefining array type for %s\n", replace_RefData[z].orig_array[i]);
918 exit(EXIT_FAILURE);
919 }
920 }
921 /* Add replace_array to take_array, while the orig_name and new_name are the same */
922 take_RefData[z].orig_array = trealloc(take_RefData[z].orig_array, sizeof(*(take_RefData[z].orig_array)) * (take_RefData[z].arrays + 1));
923 SDDS_CopyString(&take_RefData[z].orig_array[take_RefData[z].arrays], replace_RefData[z].orig_array[i]);
924 SDDS_CopyString(&take_RefData[z].new_array[take_RefData[z].arrays], replace_RefData[z].orig_array[i]);
925 take_RefData[z].arrays++;
926 }
927 }
928 free(replace_RefData[z].orig_array[i]);
929 }
930 }
931 }
932 }
933
934 if (!SDDS_WriteLayout(&SDDS_output))
935 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
936
937 free(leave_column);
938 if (take_columns) {
939 SDDS_FreeStringArray(take_column, take_columns);
940 free(take_column);
941 }
942
943 endWarning = 0;
944
945 while ((retval1 = SDDS_ReadPage(&SDDS_1)) > 0) {
946 copyInput1Only = 0;
947 rows1 = SDDS_CountRowsOfInterest(&SDDS_1);
948 if (!SDDS_StartPage(&SDDS_output, rows1)) {
949 SDDS_SetError("Problem starting output page");
950 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
951 }
952 if (fillIn && !SDDS_ClearPage(&SDDS_output)) {
953 SDDS_SetError("Problem clearing output page");
954 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
955 }
956 if (!SDDS_CopyParameters(&SDDS_output, &SDDS_1) ||
957 !SDDS_CopyArrays(&SDDS_output, &SDDS_1)) {
958 SDDS_SetError("Problem copying parameter or array data from first input file");
959 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
960 }
961
962 for (z = 0; z < referfiles; z++) {
963 input2 = referfile[z];
964 if (!reusePage) {
965 if ((retval2 = SDDS_ReadPage(&SDDS_ref[z])) <= 0 && !endWarning) {
966 if (warnings)
967 fprintf(stderr, "warning: %s ends prematurely\n", input2 ? input2 : "stdin");
968 endWarning = 1;
969 }
970 } else {
971 if (retval1 == 1 && (retval2 = SDDS_ReadPage(&SDDS_ref[z])) <= 0) {
972 if (!endWarning && warnings)
973 fprintf(stderr, "warning: %s has no data\n", input2 ? input2 : "stdin");
974 endWarning = 1;
975 } else
976 SDDS_SetRowFlags(&SDDS_ref[z], 1);
977 }
978
979 if (take_RefData[z].columns &&
980 (!SDDS_SetColumnFlags(&SDDS_ref[z], 0) ||
981 !SDDS_SetColumnsOfInterest(&SDDS_ref[z], SDDS_NAME_ARRAY, take_RefData[z].columns, take_RefData[z].orig_column)))
982 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
983
984 /* Copy parameters and arrays */
985 if (!CopyParametersFromSecondInput(&SDDS_output, &SDDS_ref[z], take_RefData[z])) {
986 SDDS_SetError("Problem copying parameter from second input file");
987 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
988 }
989 if (!CopyArraysFromSecondInput(&SDDS_output, &SDDS_ref[z], take_RefData[z])) {
990 SDDS_SetError("Problem copying parameter from second input file");
991 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
992 }
993 }
994
995 firstRun = 1;
996 for (z = rows2Max = 0; z < referfiles; z++) {
997 input2 = referfile[z];
998 rows2 = SDDS_CountRowsOfInterest(&SDDS_ref[z]);
999 rows2Max = rows2 > rows2Max ? rows2 : rows2Max;
1000
1001 if (!firstRun) {
1002 /* DO NOT USE SDDS_CountRowsOfInterest because
1003 CopyRowToNewColumn and SDDS_AssertRowFlags expect
1004 the real row index and not the index of rows of interest */
1005 rows1 = SDDS_RowCount(&SDDS_output);
1006 }
1007 if (take_RefData[z].columns) {
1008 if (!rows2) {
1009 if (!SDDS_SetRowFlags(&SDDS_output, fillIn)) {
1010 SDDS_SetError("Problem setting row flags for output file.");
1011 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1012 }
1013 } else if (rows1) {
1014 if (match_columns) {
1015 if (firstRun) {
1016 if (!(string1 = (char **)SDDS_GetColumn(&SDDS_1, match_column[0]))) {
1017 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1018 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1019 }
1020 } else {
1021 if (!(string1 = (char **)SDDS_GetColumn(&SDDS_output, match_column[0]))) {
1022 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1023 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1024 }
1025 }
1026 if (!(string2 = (char **)SDDS_GetColumn(&SDDS_ref[z], match_column[1]))) {
1027 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[1], input2);
1028 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1029 }
1030 if (!wildMatch)
1031 keyGroup = MakeSortedKeyGroups(&keyGroups, SDDS_STRING, string2, rows2);
1032 i3 = 0;
1033 for (i1 = 0; i1 < rows1; i1++) {
1034 if (firstRun) {
1035 if (!SDDS_CopyRowDirect(&SDDS_output, i1, &SDDS_1, i1)) {
1036 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1037 SDDS_SetError(s);
1038 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1039 }
1040 }
1041 matched = 0;
1042 if ((&SDDS_output)->row_flag[i1]) {
1043 if (!wildMatch) {
1044 if ((i2 = FindMatchingKeyGroup(keyGroup, keyGroups, SDDS_STRING, string1 + i3, reuse)) >= 0)
1045 matched = 1;
1046 } else {
1047 if ((i2 = match_string(string1[i3], string2, rows2, WILDCARD_MATCH)) >= 0)
1048 matched = 1;
1049 }
1050 if (matched) {
1051 if (!CopyRowToNewColumn(&SDDS_output, i1, &SDDS_ref[z], i2, take_RefData[z], take_RefData[z].columns, input2)) {
1052 fprintf(stderr, "error in copying data to output!\n");
1053 exit(EXIT_FAILURE);
1054 }
1055 } else {
1056 if (!fillIn && !SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, i1, i1, (int32_t)0))
1057 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1058 if (warnings)
1059 fprintf(stderr, "warning: no match for row %" PRId64 " (%s = \"%s\")\n", i3, match_column[0], string1[i3]);
1060 }
1061 i3++;
1062 }
1063 }
1064 firstRun = 0;
1065 if (string1) {
1066 for (i = 0; i < i3; i++)
1067 free(string1[i]);
1068 free(string1);
1069 }
1070 if (string2) {
1071 for (i = 0; i < rows2; i++)
1072 free(string2[i]);
1073 free(string2);
1074 }
1075
1076 for (i = 0; i < keyGroups; i++) {
1077 free(keyGroup[i]->equivalent);
1078 free(keyGroup[i]);
1079 }
1080 free(keyGroup);
1081 } else if (equate_columns) {
1082 if (firstRun) {
1083 if (!(value1 = SDDS_GetColumnInDoubles(&SDDS_1, equate_column[0]))) {
1084 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1085 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1086 }
1087 } else {
1088 if (!(value1 = SDDS_GetColumnInDoubles(&SDDS_output, equate_column[0]))) {
1089 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1090 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1091 }
1092 }
1093 if (!(value2 = SDDS_GetColumnInDoubles(&SDDS_ref[z], equate_column[1]))) {
1094 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[1], input2);
1095 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1096 }
1097
1098 i3 = 0;
1099 keyGroup = MakeSortedKeyGroups(&keyGroups, SDDS_DOUBLE, value2, rows2);
1100 for (i1 = 0; i1 < rows1; i1++) {
1101 if (firstRun) {
1102 if (!SDDS_CopyRowDirect(&SDDS_output, i1, &SDDS_1, i1)) {
1103 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1104 SDDS_SetError(s);
1105 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1106 }
1107 }
1108 if ((&SDDS_output)->row_flag[i1]) {
1109 if ((i2 = FindMatchingKeyGroup(keyGroup, keyGroups, SDDS_DOUBLE, value1 + i3, reuse)) >= 0) {
1110 if (!CopyRowToNewColumn(&SDDS_output, i1, &SDDS_ref[z], i2, take_RefData[z], take_RefData[z].columns, input2)) {
1111 fprintf(stderr, "error in copying data to output!\n");
1112 exit(EXIT_FAILURE);
1113 }
1114 } else {
1115 if (!fillIn && !SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, i1, i1, (int32_t)0))
1116 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1117 if (warnings)
1118 fprintf(stderr, "warning: no equal for row %" PRId64 " (%s = %g)\n", i3, equate_column[0], value1[i3]);
1119 }
1120 i3++;
1121 }
1122 }
1123 firstRun = 0;
1124 if (i3 && equate_columns)
1125 free(value1);
1126 if (rows2 && equate_columns)
1127 free(value2);
1128 for (i = 0; i < keyGroups; i++) {
1129 free(keyGroup[i]->equivalent);
1130 free(keyGroup[i]);
1131 }
1132 free(keyGroup);
1133 } else {
1134 for (i1 = 0; i1 < rows1; i1++) {
1135 i2 = i1;
1136 if (i2 >= rows2) {
1137 if (!reuse) {
1138 if (fillIn) {
1139 if (!SDDS_CopyRowDirect(&SDDS_output, i1, &SDDS_1, i1)) {
1140 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1141 SDDS_SetError(s);
1142 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1143 }
1144 }
1145 if (warnings)
1146 fprintf(stderr, "warning: no row in file 2 for row %" PRId64 " in file 1\n", i1);
1147 continue;
1148 } else
1149 i2 = rows2 - 1;
1150 }
1151 if (firstRun) {
1152 if (!SDDS_CopyRowDirect(&SDDS_output, i1, &SDDS_1, i1)) {
1153 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1154 SDDS_SetError(s);
1155 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1156 }
1157 }
1158 if (take_RefData[z].columns &&
1159 !CopyRowToNewColumn(&SDDS_output, i1, &SDDS_ref[z], i2, take_RefData[z], take_RefData[z].columns, input2)) {
1160 fprintf(stderr, "error in copying data to output!\n");
1161 exit(EXIT_FAILURE);
1162 }
1163 }
1164 firstRun = 0;
1165 }
1166 }
1167 } else {
1168 if (rows2) {
1169 if (rows1) {
1170 if (match_columns) {
1171 if (firstRun) {
1172 if (!(string1 = (char **)SDDS_GetColumn(&SDDS_1, match_column[0]))) {
1173 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1174 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1175 }
1176 } else {
1177 if (!(string1 = (char **)SDDS_GetColumn(&SDDS_output, match_column[0]))) {
1178 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[0], input1 ? input1 : "stdin");
1179 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1180 }
1181 }
1182 if (!(string2 = (char **)SDDS_GetColumn(&SDDS_ref[z], match_column[1]))) {
1183 fprintf(stderr, "Error: problem getting column %s from file %s\n", match_column[1], input2);
1184 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1185 }
1186 keyGroup = MakeSortedKeyGroups(&keyGroups, SDDS_STRING, string2, rows2);
1187 i3 = 0;
1188 for (i1 = 0; i1 < rows1; i1++) {
1189 if (firstRun) {
1190 if (!SDDS_CopyRowDirect(&SDDS_output, i1, &SDDS_1, i1)) {
1191 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1192 SDDS_SetError(s);
1193 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1194 }
1195 }
1196 if ((&SDDS_output)->row_flag[i1]) {
1197 if ((FindMatchingKeyGroup(keyGroup, keyGroups, SDDS_STRING, string1 + i3, reuse)) < 0) {
1198 if (!fillIn && !SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, i1, i1, (int32_t)0))
1199 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1200 if (warnings)
1201 fprintf(stderr, "warning: no match for row %" PRId64 " (%s = \"%s\")\n", i3, match_column[0], string1[i3]);
1202 }
1203 i3++;
1204 }
1205 }
1206 firstRun = 0;
1207 if (string1) {
1208 for (i = 0; i < i3; i++)
1209 free(string1[i]);
1210 free(string1);
1211 }
1212 if (string2) {
1213 for (i = 0; i < rows2; i++)
1214 free(string2[i]);
1215 free(string2);
1216 }
1217
1218 for (i = 0; i < keyGroups; i++) {
1219 free(keyGroup[i]->equivalent);
1220 free(keyGroup[i]);
1221 }
1222 free(keyGroup);
1223 } else if (equate_columns) {
1224 if (firstRun) {
1225 if (!(value1 = SDDS_GetColumnInDoubles(&SDDS_1, equate_column[0]))) {
1226 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1227 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1228 }
1229 } else {
1230 if (!(value1 = SDDS_GetColumnInDoubles(&SDDS_output, equate_column[0]))) {
1231 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[0], input1 ? input1 : "stdin");
1232 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1233 }
1234 }
1235 if (!(value2 = SDDS_GetColumnInDoubles(&SDDS_ref[z], equate_column[1]))) {
1236 fprintf(stderr, "Error: problem getting column %s from file %s\n", equate_column[1], input2);
1237 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1238 }
1239 keyGroup = MakeSortedKeyGroups(&keyGroups, SDDS_DOUBLE, value2, rows2);
1240 i3 = 0;
1241 for (i1 = 0; i1 < rows1; i1++) {
1242 if (firstRun) {
1243 if (!SDDS_CopyRowDirect(&SDDS_output, i1, &SDDS_1, i1)) {
1244 sprintf(s, "Problem copying row %" PRId64 " of first data set", i1);
1245 SDDS_SetError(s);
1246 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1247 }
1248 }
1249 if ((&SDDS_output)->row_flag[i1]) {
1250 if ((FindMatchingKeyGroup(keyGroup, keyGroups, SDDS_DOUBLE, value1 + i3, reuse)) < 0) {
1251 if (!fillIn && !SDDS_AssertRowFlags(&SDDS_output, SDDS_INDEX_LIMITS, i1, i1, (int32_t)0))
1252 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1253 if (warnings)
1254 fprintf(stderr, "warning: no equal for row %" PRId64 " (%s = %g)\n", i3, equate_column[0], value1[i3]);
1255 }
1256 i3++;
1257 }
1258 }
1259 firstRun = 0;
1260 if (i3 && equate_columns)
1261 free(value1);
1262 if (rows2 && equate_columns)
1263 free(value2);
1264 for (i = 0; i < keyGroups; i++) {
1265 free(keyGroup[i]->equivalent);
1266 free(keyGroup[i]);
1267 }
1268 free(keyGroup);
1269 }
1270 }
1271 }
1272 copyInput1Only++;
1273 }
1274 }
1275 if ((rows2Max == 0 && fillIn) || (copyInput1Only == referfiles && !match_columns && !equate_columns)) {
1276 if (!SDDS_CopyColumns(&SDDS_output, &SDDS_1)) {
1277 SDDS_SetError("Problem copying tabular data for output file.");
1278 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1279 }
1280 }
1281
1282 if (!SDDS_WritePage(&SDDS_output)) {
1283 SDDS_SetError("Problem writing data to output file");
1284 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1285 }
1286 }
1287
1288 for (z = 0; z < referfiles; z++) {
1289 free(referfile[z]);
1290
1291 if (take_RefData[z].columns) {
1292 for (i = 0; i < take_RefData[z].columns; i++) {
1293 free(take_RefData[z].new_column[i]);
1294 free(take_RefData[z].orig_column[i]);
1295 }
1296 free(take_RefData[z].new_column);
1297 free(take_RefData[z].orig_column);
1298 }
1299
1300 if (take_RefData[z].parameters) {
1301 for (i = 0; i < take_RefData[z].parameters; i++) {
1302 free(take_RefData[z].new_parameter[i]);
1303 free(take_RefData[z].orig_parameter[i]);
1304 }
1305 free(take_RefData[z].new_parameter);
1306 free(take_RefData[z].orig_parameter);
1307 }
1308
1309 if (take_RefData[z].arrays) {
1310 for (i = 0; i < take_RefData[z].arrays; i++) {
1311 free(take_RefData[z].new_array[i]);
1312 free(take_RefData[z].orig_array[i]);
1313 }
1314 free(take_RefData[z].new_array);
1315 free(take_RefData[z].orig_array);
1316 }
1317
1318 if (new_data[z].columns) {
1319 for (i = 0; i < new_data[z].columns; i++) {
1320 free(new_data[z].new_column[i]);
1321 free(new_data[z].orig_column[i]);
1322 }
1323 free(new_data[z].new_column);
1324 free(new_data[z].orig_column);
1325 }
1326
1327 if (new_data[z].parameters) {
1328 for (i = 0; i < new_data[z].parameters; i++) {
1329 free(new_data[z].new_parameter[i]);
1330 free(new_data[z].orig_parameter[i]);
1331 }
1332 free(new_data[z].new_parameter);
1333 free(new_data[z].orig_parameter);
1334 }
1335 if (new_data[z].arrays) {
1336 for (i = 0; i < new_data[z].arrays; i++) {
1337 free(new_data[z].new_array[i]);
1338 free(new_data[z].orig_array[i]);
1339 }
1340 free(new_data[z].new_array);
1341 free(new_data[z].orig_array);
1342 }
1343 }
1344 if (new_data)
1345 free(new_data);
1346
1347 if (edit_column_requests) {
1348 for (i = 0; i < edit_column_requests; i++) {
1349 free(edit_column_request[i].match_string);
1350 free(edit_column_request[i].edit_string);
1351 }
1352 free(edit_column_request);
1353 }
1354 if (edit_parameter_requests) {
1355 for (i = 0; i < edit_parameter_requests; i++) {
1356 free(edit_parameter_request[i].match_string);
1357 free(edit_parameter_request[i].edit_string);
1358 }
1359 free(edit_parameter_request);
1360 }
1361
1362 if (edit_array_requests) {
1363 for (i = 0; i < edit_array_requests; i++) {
1364 free(edit_array_request[i].match_string);
1365 free(edit_array_request[i].edit_string);
1366 }
1367 free(edit_array_request);
1368 }
1369
1370 free(take_RefData);
1371 if (replace_RefData)
1372 free(replace_RefData);
1373 free(referfile);
1374 free(inputfile);
1375
1376 if (match_columns)
1377 free(match_column);
1378 if (equate_columns)
1379 free(equate_column);
1380
1381 /*#ifdef SOLARIS */
1382 if (!SDDS_Terminate(&SDDS_output) || !SDDS_Terminate(&SDDS_1)) {
1383 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1384 exit(EXIT_FAILURE);
1385 }
1386 for (z = 0; z < referfiles; z++) {
1387 if (!SDDS_Terminate(&SDDS_ref[z])) {
1388 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
1389 exit(EXIT_FAILURE);
1390 }
1391 }
1392 free(SDDS_ref);
1393 /*#endif */
1394 if (tmpfile_used && !replaceFileAndBackUp(input1, output))
1395 exit(EXIT_FAILURE);
1396 free(input1);
1397 free(output);
1398 return EXIT_SUCCESS;
1399}
int32_t SDDS_CopyColumns(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:387
int32_t SDDS_CopyParameters(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:286
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
Definition SDDS_copy.c:40
int32_t SDDS_CopyRowDirect(SDDS_DATASET *SDDS_target, int64_t target_row, SDDS_DATASET *SDDS_source, int64_t source_row)
Definition SDDS_copy.c:834
int32_t SDDS_CopyArrays(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
Definition SDDS_copy.c:334
char * SDDS_type_name[SDDS_NUM_TYPES]
Array of supported data type names.
Definition SDDS_data.c:43
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_ClearPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_AssertRowFlags(SDDS_DATASET *SDDS_dataset, uint32_t mode,...)
Sets acceptance flags for rows based on specified criteria.
void * SDDS_GetColumn(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves a copy of the data for a specified column, including only rows marked as "of interest".
int64_t SDDS_CountRowsOfInterest(SDDS_DATASET *SDDS_dataset)
Counts the number of rows marked as "of interest" in the current data table.
int32_t SDDS_SetRowFlags(SDDS_DATASET *SDDS_dataset, int32_t row_flag_value)
Sets the acceptance flags for all rows in the current data table of a data set.
int32_t SDDS_SetColumnsOfInterest(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
Sets the acceptance flags for columns based on specified naming criteria.
int32_t SDDS_SetColumnFlags(SDDS_DATASET *SDDS_dataset, int32_t column_flag_value)
Sets the acceptance flags for all columns in the current data table of a data set.
double * SDDS_GetColumnInDoubles(SDDS_DATASET *SDDS_dataset, char *column_name)
Retrieves the data of a specified numerical column as an array of doubles, considering only rows mark...
int32_t SDDS_ChangeParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a parameter definition within the SDDS dataset.
Definition SDDS_info.c:485
int32_t SDDS_ChangeArrayInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in an array definition within the SDDS dataset.
Definition SDDS_info.c:597
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS dataset.
Definition SDDS_info.c:364
int32_t SDDS_InitializeInput(SDDS_DATASET *SDDS_dataset, char *filename)
Definition SDDS_input.c:49
int32_t SDDS_Terminate(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_ReadPage(SDDS_DATASET *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.
int32_t SDDS_TransferColumnDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a column definition from a source dataset to a target dataset.
int32_t SDDS_TransferArrayDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers an array definition from a source dataset to a target dataset.
int32_t SDDS_TransferParameterDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a parameter definition from a source dataset to a target dataset.
int32_t SDDS_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
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_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
int32_t SDDS_GetArrayType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of an array in the SDDS dataset by its index.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
Definition SDDStypes.h:138
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
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.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
Definition replacefile.c:75
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
Definition scanargs.c:36
long processPipeOption(char **item, long items, unsigned long *flags)
Definition scanargs.c:356
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
Definition scanargs.c:390
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.
KEYED_EQUIVALENT ** MakeSortedKeyGroups(long *keyGroups, long keyType, void *data, long points)
Create sorted key groups from data.
long FindMatchingKeyGroup(KEYED_EQUIVALENT **keyGroup, long keyGroups, long keyType, void *searchKeyData, long reuse)
Find a matching key group for a search key.
int has_wildcards(char *template)
Check if a template string contains any wildcard characters.
Definition wild_match.c:498

◆ process_editnames()

char ** process_editnames ( char ** orig_name,
long ** orig_flags,
long orig_names,
EDIT_NAME_REQUEST * edit_request,
long edit_requests,
long filenumber )

Definition at line 1568 of file sddsxref.c.

1569 {
1570 long i, j, i1, i2 = 0, k;
1571 char **new_name, s[1024], tmpstr[1024];
1572 char *ptr, **editstr, *pch;
1573 char edit_buffer[1024];
1574
1575 *orig_flags = NULL;
1576
1577 *orig_flags = tmalloc(sizeof(**orig_flags) * orig_names);
1578 new_name = tmalloc(sizeof(*new_name) * orig_names);
1579
1580 editstr = (char **)malloc(sizeof(*editstr) * edit_requests);
1581 ptr = malloc(sizeof(char) * 256);
1582 sprintf(s, "%ld", filenumber);
1583
1584 for (i = 0; i < edit_requests; i++) {
1585 SDDS_CopyString(&editstr[i], edit_request[i].edit_string);
1586 if (strstr(editstr[i], "%%ld"))
1587 replace_string(ptr, editstr[i], "%%ld", "%ld");
1588 else if (strstr(editstr[i], "%ld")) {
1589 sprintf(s, "%ld", filenumber);
1590 replace_string(ptr, editstr[i], "%ld", s);
1591 } else if (wild_match(editstr[i], "*%*ld*")) {
1592 /* Find the format of %*ld */
1593 /* Find position of '%' */
1594 pch = strchr(editstr[i], '%');
1595 i1 = pch - editstr[i];
1596 /* Find the position of 'd' after '%' */
1597 for (k = 0; k < strlen(editstr[i]); k++) {
1598 if (editstr[i][k] == 'd') {
1599 i2 = k;
1600 if (i2 > i1)
1601 break;
1602 }
1603 }
1604 strncpy(tmpstr, pch, i2 - i1 + 1);
1605 tmpstr[i2 - i1 + 1] = '\0';
1606 sprintf(s, tmpstr, filenumber);
1607 replace_string(ptr, editstr[i], tmpstr, s);
1608 } else
1609 continue;
1610 free(editstr[i]);
1611 SDDS_CopyString(&editstr[i], ptr);
1612 }
1613 free(ptr);
1614 ptr = NULL;
1615 for (j = 0; j < orig_names; j++) {
1616 (*orig_flags)[j] = 0;
1617 SDDS_CopyString(new_name + j, orig_name[j]);
1618 for (i = 0; i < edit_requests; i++) {
1619 ptr = expand_ranges(edit_request[i].match_string);
1620 free(edit_request[i].match_string);
1621 edit_request[i].match_string = ptr;
1622 if (wild_match(new_name[j], edit_request[i].match_string)) {
1623 strcpy(edit_buffer, new_name[j]);
1624 if (!edit_string(edit_buffer, editstr[i]))
1625 SDDS_Bomb("error editing name");
1626 free(new_name[j]);
1627 SDDS_CopyString(&new_name[j], edit_buffer);
1628 (*orig_flags)[j] = 1;
1629 }
1630 }
1631 }
1632
1633 for (i = 0; i < edit_requests; i++)
1634 free(editstr[i]);
1635 free(editstr);
1636 return new_name;
1637}
int replace_string(char *t, char *s, char *orig, char *repl)
Replace all occurrences of one string with another string.
char * expand_ranges(char *template)
Expand range specifiers in a wildcard template into explicit character lists.
Definition wild_match.c:429
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.
Definition wild_match.c:49

Variable Documentation

◆ mode_name

char* mode_name[MODES]
static
Initial value:
= {
"column",
"parameter",
"array",
}

Definition at line 72 of file sddsxref.c.

72 {
73 "column",
74 "parameter",
75 "array",
76};

◆ option

char* option[N_OPTIONS]
Initial value:
= {
"take", "leave", "match", "equate", "transfer", "reuse", "ifnot",
"nowarnings", "ifis", "pipe", "fillin", "rename", "editnames", "wildmatch", "majorOrder", "replace"}

Definition at line 134 of file sddsxref.c.

134 {
135 "take", "leave", "match", "equate", "transfer", "reuse", "ifnot",
136 "nowarnings", "ifis", "pipe", "fillin", "rename", "editnames", "wildmatch", "majorOrder", "replace"};

◆ replace_type

char* replace_type[REPLACE_TYPES]
static
Initial value:
= {
"column", "parameter", "array"}

Definition at line 82 of file sddsxref.c.

82 {
83 "column", "parameter", "array"};

◆ transfer_type

char* transfer_type[TRANSFER_TYPES]
static
Initial value:
= {
"parameter", "array"}

Definition at line 88 of file sddsxref.c.

88 {
89 "parameter", "array"};

◆ USAGE

char* USAGE

Definition at line 138 of file sddsxref.c.