86 SET_STANDARDDEVIATION,
106char *option[N_OPTIONS] = {
129#define TOPLIMIT_GIVEN 0x0001U
130#define BOTTOMLIMIT_GIVEN 0x0002U
131#define POSITIONCOLUMN_GIVEN 0x0004U
132#define PERCENT_GIVEN 0x0008U
138 char **sourceColumn, *resultColumn, *positionColumn;
139 long sourceColumns, sumPower, optionCode, positionColumnIndex;
142 double topLimit, bottomLimit;
150 char **sourceColumn, *resultColumn, *positionColumn;
151 long sourceColumns, optionCode, resultIndex, sumPower, positionColumnIndex;
154 double topLimit, bottomLimit;
157long addStatRequests(
STAT_REQUEST **statRequest,
long requests,
char **item,
long items,
long code,
unsigned long flag);
162 "sddsrowstats [<input>] [<output>]\n"
163 " [-pipe[=input][,output]]\n"
165 " [-mean=<newName>,[,<limitOps>],<columnNameList>]\n"
166 " [-rms=<newName>,[,<limitOps>],<columnNameList>]\n"
167 " [-median=<newName>[,<limitOps>],<columnNameList>]\n"
168 " [-minimum=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>]\n"
169 " [-maximum=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>]\n"
170 " [-standardDeviation=<newName>[,<limitOps>],<columnNameList>]\n"
171 " [-sigma=<newName>[,<limitOps>],<columnNameList>]\n"
172 " [-mad=<newName>[,<limitOps>],<columnNameList>]\n"
173 " [-sum=<newName>[,<limitOps>][,power=<integer>],<columnNameList>] \n"
174 " [-spread=<newName>[,<limitOps>],<columnNameList>]\n"
175 " [-drange=<newName>[,<limitOps>],<columnNameList>]\n"
176 " [-qrange=<newName>[,<limitOps>],<columnNameList>]\n"
177 " [-smallest=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>]\n"
178 " [-largest=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>]\n"
179 " [-count=<newName>[,<limitOps>],<columnNameList>]\n"
180 " [-percentile=<newName>[,<limitOps>],value=<percent>,<columnNameList]\n"
181 " [-majorOrder=row|column]\n"
182 " [-threads=<number>]\n"
184 " -pipe[=input][,output]\n"
185 " Use pipe for input and/or output.\n"
187 " Suppress warning messages.\n"
188 " -mean=<newName>[,<limitOps>],<columnNameList>\n"
189 " Compute the mean of the specified columns.\n"
190 " -rms=<newName>[,<limitOps>],<columnNameList>\n"
191 " Compute the root mean square of the specified columns.\n"
192 " -median=<newName>[,<limitOps>],<columnNameList>\n"
193 " Compute the median of the specified columns.\n"
194 " -minimum=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>\n"
195 " Compute the minimum value among the specified columns.\n"
196 " -maximum=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>\n"
197 " Compute the maximum value among the specified columns.\n"
198 " -standardDeviation=<newName>[,<limitOps>],<columnNameList>\n"
199 " Compute the standard deviation of the specified columns.\n"
200 " -sigma=<newName>[,<limitOps>],<columnNameList>\n"
201 " Compute the sigma (standard deviation) of the specified columns.\n"
202 " -mad=<newName>[,<limitOps>],<columnNameList>\n"
203 " Compute the median absolute deviation (MAD) of the specified columns.\n"
204 " -sum=<newName>[,<limitOps>][,power=<integer>],<columnNameList>\n"
205 " Compute the sum of the specified columns.\n"
206 " -spread=<newName>[,<limitOps>],<columnNameList>\n"
207 " Compute the spread (max - min) of the specified columns.\n"
208 " -drange=<newName>[,<limitOps>],<columnNameList>\n"
209 " Compute the decile range of the specified columns.\n"
210 " -qrange=<newName>[,<limitOps>],<columnNameList>\n"
211 " Compute the quartile range of the specified columns.\n"
212 " -smallest=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>\n"
213 " Compute the smallest absolute value among the specified columns.\n"
214 " -largest=<newName>[,positionColumn=<name>][,<limitOps>],<columnNameList>\n"
215 " Compute the largest absolute value among the specified columns.\n"
216 " -count=<newName>[,<limitOps>],<columnNameList>\n"
217 " Count the number of valid entries in the specified columns.\n"
218 " -percentile=<newName>[,<limitOps>],value=<percent>,<columnNameList>\n"
219 " Compute the specified percentile of the given columns.\n"
220 " -majorOrder=row|column\n"
221 " Set the data ordering to row-major or column-major.\n"
222 " -threads=<number>\n"
223 " Specify the number of threads to use for computations.\n"
224 "\n<limitOps> is of the form [topLimit=<value>,][bottomLimit=<value>]\n"
225 "\nComputes statistics for each row of each input table, adding new columns to the\n"
226 "output table. Each row statistic is done using data from the columns listed in\n"
227 "<columnNameList>, which is a comma-separated list of optionally-wildcarded column\n"
228 "names. positionColumn=<name> for minimum, maximum, smallest, largest option is to store \n"
229 "the corresponding column name of the minimum, maximum, smallest, or largest in each row to \n"
230 "the new output column - <name>.\n"
231 "\nProgram by Michael Borland. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n";
233int main(
int argc,
char **argv) {
238 SCANNED_ARG *scanned;
242 long i_arg, code, iStat, tmpFileUsed, iColumn, posColIndex;
243 int64_t rows, row, count;
244 long noWarnings, maxSourceColumns;
245 char *input, *output, *positionColumn, **posColumnName;
246 double **inputData, *outputData, value1, value2, topLimit, bottomLimit;
247 unsigned long pipeFlags, scanFlags, majorOrderFlag;
249 double *statWorkArray;
250 double quartilePoint[2] = {25.0, 75.0}, quartileResult[2];
251 double decilePoint[2] = {10.0, 90.0}, decileResult[2];
253 short columnMajorOrder = -1;
257 argc =
scanargs(&scanned, argc, argv);
259 bomb(
"too few arguments", USAGE);
262 posColumnName = NULL;
263 input = output = positionColumn = NULL;
266 stats = requests = pipeFlags = 0;
269 statWorkArray = NULL;
271 for (i_arg = 1; i_arg < argc; i_arg++) {
273 if (scanned[i_arg].arg_type == OPTION) {
275 switch (code =
match_string(scanned[i_arg].list[0], option, N_OPTIONS, 0)) {
280 case SET_STANDARDDEVIATION:
290 if (scanned[i_arg].n_items < 3) {
291 fprintf(stderr,
"error: invalid -%s syntax\n", option[code]);
294 if (!
scanItemList(&scanFlags, scanned[i_arg].list, &scanned[i_arg].n_items,
295 SCANITEMLIST_UNKNOWN_VALUE_OK | SCANITEMLIST_REMOVE_USED_ITEMS |
296 SCANITEMLIST_IGNORE_VALUELESS,
297 "positionColumn",
SDDS_STRING, &positionColumn, 1, POSITIONCOLUMN_GIVEN,
298 "toplimit",
SDDS_DOUBLE, &topLimit, 1, TOPLIMIT_GIVEN,
299 "bottomlimit",
SDDS_DOUBLE, &bottomLimit, 1, BOTTOMLIMIT_GIVEN, NULL)) {
300 sprintf(s,
"invalid -%s syntax", scanned[i_arg].list[0]);
303 requests = addStatRequests(&request, requests, scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, code, scanFlags);
304 request[requests - 1].topLimit = topLimit;
305 request[requests - 1].bottomLimit = bottomLimit;
306 if (positionColumn) {
307 if (code == SET_MAXIMUM || code == SET_MINIMUM || code == SET_LARGEST || code == SET_SMALLEST)
308 SDDS_CopyString(&request[requests - 1].positionColumn, positionColumn);
309 free(positionColumn);
310 positionColumn = NULL;
314 if (scanned[i_arg].n_items < 3) {
315 fprintf(stderr,
"error: invalid -%s syntax\n", option[code]);
318 if (!
scanItemList(&scanFlags, scanned[i_arg].list, &scanned[i_arg].n_items,
319 SCANITEMLIST_UNKNOWN_VALUE_OK | SCANITEMLIST_REMOVE_USED_ITEMS |
320 SCANITEMLIST_IGNORE_VALUELESS,
322 "toplimit",
SDDS_DOUBLE, &topLimit, 1, TOPLIMIT_GIVEN,
323 "bottomlimit",
SDDS_DOUBLE, &bottomLimit, 1, BOTTOMLIMIT_GIVEN, NULL) ||
324 !(scanFlags & PERCENT_GIVEN) || percent <= 0 || percent >= 100)
326 requests = addStatRequests(&request, requests, scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, code, scanFlags);
327 request[requests - 1].percent = percent;
328 request[requests - 1].topLimit = topLimit;
329 request[requests - 1].bottomLimit = bottomLimit;
332 if (scanned[i_arg].n_items < 3) {
333 fprintf(stderr,
"error: invalid -%s syntax\n", option[code]);
337 if (!
scanItemList(&scanFlags, scanned[i_arg].list, &scanned[i_arg].n_items,
338 SCANITEMLIST_UNKNOWN_VALUE_OK | SCANITEMLIST_REMOVE_USED_ITEMS | SCANITEMLIST_IGNORE_VALUELESS,
340 "toplimit",
SDDS_DOUBLE, &topLimit, 1, TOPLIMIT_GIVEN,
341 "bottomlimit",
SDDS_DOUBLE, &bottomLimit, 1, BOTTOMLIMIT_GIVEN, NULL))
343 requests = addStatRequests(&request, requests, scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, code, scanFlags);
344 request[requests - 1].sumPower = power;
345 request[requests - 1].topLimit = topLimit;
346 request[requests - 1].bottomLimit = bottomLimit;
349 if (!
processPipeOption(scanned[i_arg].list + 1, scanned[i_arg].n_items - 1, &pipeFlags))
355 case SET_MAJOR_ORDER:
357 scanned[i_arg].n_items--;
358 if (scanned[i_arg].n_items > 0 &&
359 (!
scanItemList(&majorOrderFlag, scanned[i_arg].list + 1, &scanned[i_arg].n_items, 0,
360 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
361 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
362 SDDS_Bomb(
"invalid -majorOrder syntax/values");
363 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
364 columnMajorOrder = 1;
365 else if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
366 columnMajorOrder = 0;
369 if (scanned[i_arg].n_items != 2 ||
370 !sscanf(scanned[i_arg].list[1],
"%d", &threads) || threads < 1)
374 fprintf(stderr,
"error: unknown option '%s' given\n", scanned[i_arg].list[0]);
381 input = scanned[i_arg].list[0];
383 output = scanned[i_arg].list[0];
389 processFilenames(
"sddsrowstats", &input, &output, pipeFlags, noWarnings, &tmpFileUsed);
397 if (!(stat = compileStatDefinitions(&inData, request, requests, &stats, noWarnings))) {
402 SDDS_Bomb(
"No valid statistics requests.");
403 for (iStat = maxSourceColumns = 0; iStat < stats; iStat++) {
404 if (stat[iStat].sourceColumns > maxSourceColumns)
405 maxSourceColumns = stat[iStat].sourceColumns;
407 if (!(statWorkArray = malloc(
sizeof(*statWorkArray) * maxSourceColumns)))
408 SDDS_Bomb(
"allocation failure (statWorkArray)");
410 if (!setupOutputFile(&outData, output, &inData, stat, stats, columnMajorOrder)) {
423 if (!(outputData = (
double *)malloc(
sizeof(*outputData) * rows))) {
426 if (!(posColumnName = (
char **)malloc(
sizeof(*posColumnName) * rows))) {
429 for (iStat = 0; iStat < stats; iStat++) {
430 if (!(inputData = (
double **)malloc(
sizeof(*inputData) * stat[iStat].sourceColumns))) {
433 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
438 for (row = 0; row < rows; row++)
439 outputData[row] = DBL_MAX;
440 switch (stat[iStat].optionCode) {
442 for (row = 0; row < rows; row++) {
445 posColumnName[row] = NULL;
446 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
447 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
449 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
451 if (inputData[iColumn][row] < value1) {
452 value1 = inputData[iColumn][row];
453 posColIndex = iColumn;
456 outputData[row] = value1;
457 if (stat[iStat].positionColumn)
458 posColumnName[row] = stat[iStat].sourceColumn[posColIndex];
462 for (row = 0; row < rows; row++) {
465 posColumnName[row] = NULL;
466 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
467 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
469 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
471 if (inputData[iColumn][row] > value1) {
472 posColIndex = iColumn;
473 value1 = inputData[iColumn][row];
476 outputData[row] = value1;
477 if (stat[iStat].positionColumn)
478 posColumnName[row] = stat[iStat].sourceColumn[posColIndex];
482 for (row = 0; row < rows; row++) {
485 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
486 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
488 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
490 value1 += inputData[iColumn][row];
494 outputData[row] = value1 / count;
498 for (row = 0; row < rows; row++) {
499 for (iColumn = count = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
500 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
502 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
504 statWorkArray[count] = inputData[iColumn][row];
511 case SET_STANDARDDEVIATION:
512 for (row = 0; row < rows; row++) {
516 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
517 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
519 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
521 value1 += inputData[iColumn][row];
522 value2 += inputData[iColumn][row] * inputData[iColumn][row];
526 if ((value1 = value2 / count - sqr(value1 / count)) <= 0)
529 outputData[row] = sqrt(value1 * count / (count - 1.0));
534 for (row = 0; row < rows; row++) {
538 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
539 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
541 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
543 value1 += inputData[iColumn][row];
544 value2 += inputData[iColumn][row] * inputData[iColumn][row];
548 if ((value1 = value2 / count - sqr(value1 / count)) <= 0)
551 outputData[row] = sqrt(value1 / (count - 1.0));
556 for (row = 0; row < rows; row++) {
559 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
560 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
562 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
564 value1 += sqr(inputData[iColumn][row]);
568 outputData[row] = sqrt(value1 / count);
572 for (row = 0; row < rows; row++) {
575 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
576 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
578 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
580 value1 +=
ipow(inputData[iColumn][row], stat[iStat].sumPower);
584 outputData[row] = value1;
588 for (row = 0; row < rows; row++) {
590 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
591 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
593 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
597 outputData[row] = count;
601 for (row = 0; row < rows; row++) {
602 for (iColumn = count = value1 = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
603 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
605 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
607 statWorkArray[count] = inputData[iColumn][row];
615 for (row = 0; row < rows; row++) {
616 for (iColumn = count = value1 = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
617 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
619 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
621 statWorkArray[count] = inputData[iColumn][row];
625 outputData[row] = decileResult[1] - decileResult[0];
629 for (row = 0; row < rows; row++) {
630 for (iColumn = count = value1 = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
631 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
633 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
635 statWorkArray[count] = inputData[iColumn][row];
639 outputData[row] = quartileResult[1] - quartileResult[0];
643 for (row = 0; row < rows; row++) {
646 posColumnName[row] = NULL;
647 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
648 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
650 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
652 if ((value2 = fabs(inputData[iColumn][row])) < value1) {
653 posColIndex = iColumn;
657 outputData[row] = value1;
658 if (stat[iStat].positionColumn)
659 posColumnName[row] = stat[iStat].sourceColumn[posColIndex];
663 for (row = 0; row < rows; row++) {
666 posColumnName[row] = NULL;
667 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
668 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
670 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
672 if ((value2 = fabs(inputData[iColumn][row])) > value1) {
673 posColIndex = iColumn;
677 outputData[row] = value1;
678 if (stat[iStat].positionColumn)
679 posColumnName[row] = stat[iStat].sourceColumn[posColIndex];
683 for (row = 0; row < rows; row++) {
686 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
687 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
689 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
691 if (inputData[iColumn][row] < value1)
692 value1 = inputData[iColumn][row];
693 if (inputData[iColumn][row] > value2)
694 value2 = inputData[iColumn][row];
696 outputData[row] = value2 - value1;
700 for (row = 0; row < rows; row++) {
701 for (iColumn = count = value1 = 0; iColumn < stat[iStat].sourceColumns; iColumn++) {
702 if (stat[iStat].flags & TOPLIMIT_GIVEN && inputData[iColumn][row] > stat[iStat].topLimit)
704 if (stat[iStat].flags & BOTTOMLIMIT_GIVEN && inputData[iColumn][row] < stat[iStat].bottomLimit)
706 statWorkArray[count] = inputData[iColumn][row];
709 outputData[row] = HUGE_VAL;
715 SDDS_Bomb(
"invalid statistic code (accumulation loop)");
718 if (!
SDDS_SetColumn(&outData, SDDS_SET_BY_INDEX, outputData, rows, stat[iStat].resultIndex))
721 if (stat[iStat].positionColumn) {
722 if (!
SDDS_SetColumn(&outData, SDDS_SET_BY_INDEX, posColumnName, rows, stat[iStat].positionColumnIndex))
725 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++)
726 free(inputData[iColumn]);
733 posColumnName = NULL;
739 for (iStat = 0; iStat < stats; iStat++) {
740 if (stat[iStat].positionColumn)
741 free(stat[iStat].positionColumn);
742 for (iColumn = 0; iColumn < stat[iStat].sourceColumns; iColumn++)
743 free(stat[iStat].sourceColumn[iColumn]);
744 free(stat[iStat].sourceColumn);
760long addStatRequests(
STAT_REQUEST **statRequest,
long requests,
char **item,
long items,
long code,
unsigned long flags) {
762 if (!(*statRequest =
SDDS_Realloc(*statRequest,
sizeof(**statRequest) * (requests + 1))) ||
763 !((*statRequest)[requests].sourceColumn = (
char **)malloc(
sizeof(*(*statRequest)[requests].sourceColumn) * (items - 1))))
765 for (i = 0; i < items - 1; i++)
766 SDDS_CopyString(&((*statRequest)[requests].sourceColumn[i]), item[i + 1]);
767 (*statRequest)[requests].resultColumn = item[0];
768 (*statRequest)[requests].sourceColumns = items - 1;
769 (*statRequest)[requests].optionCode = code;
770 (*statRequest)[requests].sumPower = 1;
771 (*statRequest)[requests].flags = flags;
772 (*statRequest)[requests].positionColumn = NULL;
779 long iReq, iName, iStat;
783 for (iReq = iStat = 0; iReq < requests; iReq++) {
784 if ((stat[iStat].sourceColumns = expandColumnPairNames(inData, &request[iReq].sourceColumn, NULL, request[iReq].sourceColumns, NULL, 0, FIND_NUMERIC_TYPE, 0)) <= 0) {
786 fprintf(stderr,
"Warning: no match for column names (sddsrowstats):\n");
787 for (iName = 0; iName < request[iReq].sourceColumns; iName++)
788 fprintf(stderr,
"%s, ", request[iReq].sourceColumn[iName]);
792 stat[iStat].sourceColumn = request[iReq].sourceColumn;
793 stat[iStat].resultColumn = request[iReq].resultColumn;
794 stat[iStat].optionCode = request[iReq].optionCode;
795 stat[iStat].sumPower = request[iReq].sumPower;
796 stat[iStat].flags = request[iReq].flags;
797 stat[iStat].topLimit = request[iReq].topLimit;
798 stat[iStat].bottomLimit = request[iReq].bottomLimit;
799 stat[iStat].positionColumn = request[iReq].positionColumn;
800 stat[iStat].percent = request[iReq].percent;
811 char s[SDDS_MAXLINE];
815 if (columnMajorOrder != -1)
816 outData->layout.data_mode.column_major = columnMajorOrder;
818 outData->layout.data_mode.column_major = inData->layout.data_mode.column_major;
819 for (column = 0; column < stats; column++) {
821 sprintf(s,
"Problem transferring definition of column %s to %s\n", stat[column].sourceColumn[0], stat[column].resultColumn);
825 if ((stat[column].resultIndex =
SDDS_GetColumnIndex(outData, stat[column].resultColumn)) < 0) {
826 sprintf(s,
"Problem creating column %s", stat[column].resultColumn);
830 if (stat[column].positionColumn) {
832 sprintf(s,
"Problem define column %s\n", stat[column].positionColumn);
836 if ((stat[column].positionColumnIndex =
SDDS_GetColumnIndex(outData, stat[column].positionColumn)) < 0) {
837 sprintf(s,
"Problem creating column %s", stat[column].positionColumn);
845 sprintf(s,
"Problem changing attributes of new column %s", stat[column].resultColumn);
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
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_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.
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.
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.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column 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.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
Utility functions for SDDS dataset manipulation and string array operations.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
double ipow(const double x, const int64_t p)
Compute x raised to the power p (x^p).
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 computeMomentsThreaded(double *mean, double *rms, double *standDev, double *meanAbsoluteDev, double *x, long n, long numThreads)
Computes the mean, RMS, standard deviation, and mean absolute deviation of an array using multiple th...
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.