1175 {
1176 double *data, *indepData, *weightData;
1177 long i1, i2 = 0, i2save, mode;
1178 int64_t imin, imax;
1179 int64_t i, n_data, count;
1180 double min, max, top, base, point1, point2;
1181 double slope, intercept, variance;
1182 long returnValue, matchfound;
1183 char **stringData, **matchData;
1184 short *keep;
1185 double quartilePoint[2] = {25.0, 75.0}, quartileResult[2];
1186 double decilePoint[2] = {10.0, 90.0}, decileResult[2];
1187 double percentilePoint[2], percentileResult[2];
1188 char temp_str[256];
1189
1190 i1 = i2save = 0;
1191 matchfound = 0;
1192 mode = processing_ptr->mode;
1193#if DEBUG
1194 fprintf(stderr, "process_column: column=%s, mode=%s\n", processing_ptr->column_name,
1195 process_column_data[mode].name);
1196#endif
1197
1198 *stringResult = NULL;
1200 if (mode != PROCESS_COLUMN_COUNT)
1201 *result = processing_ptr->defaultValue;
1202 else
1203 *result = n_data;
1204 return 1;
1205 }
1207 &processing_ptr->lowerLimit))
1208 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1210 &processing_ptr->upperLimit))
1211 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1212
1214 &processing_ptr->head))
1215 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1217 &processing_ptr->tail))
1218 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1220 &processing_ptr->fhead))
1221 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1223 &processing_ptr->ftail))
1224 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1225 if (processing_ptr->offset_par) {
1226 if (
wild_match(processing_ptr->offset_par,
"%s*")) {
1227 sprintf(temp_str, processing_ptr->offset_par, processing_ptr->column_name);
1229 &processing_ptr->offset))
1230 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1232 &processing_ptr->offset))
1233 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1234 }
1235 if (processing_ptr->factor_par) {
1236 if (
wild_match(processing_ptr->factor_par,
"%s*")) {
1237 sprintf(temp_str, processing_ptr->factor_par, processing_ptr->column_name);
1239 &processing_ptr->factor))
1240 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1242 &processing_ptr->factor))
1243 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1244 }
1245 if ((processing_ptr->flags & PROCESSING_INVERT_OFFSET) && (processing_ptr->flags & PROCESSING_OFFSET_GIVEN))
1246 processing_ptr->offset *=-1;
1247 if ((processing_ptr->flags & PROCESSING_FACTOR_GIVEN) && (processing_ptr->flags & PROCESSING_INVERT_FACTOR))
1248 processing_ptr->factor = 1/processing_ptr->factor;
1249
1251 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1252 indepData = weightData = NULL;
1253 stringData = matchData = NULL;
1254
1256 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1257 if (processing_ptr->functionOf &&
1260 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1261 if (processing_ptr->functionOf &&
1263 !(stringData =
SDDS_GetColumn(Dataset, processing_ptr->functionOf)))
1264 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1265
1266 keep = NULL;
1267 if (processing_ptr->flags & (PROCESSING_LOLIM_GIVEN | PROCESSING_UPLIM_GIVEN | PROCESSING_TAIL_GIVEN | PROCESSING_HEAD_GIVEN | PROCESSING_FTAIL_GIVEN | PROCESSING_FHEAD_GIVEN | PROCESSING_MATCHCOLUMN_GIVEN | PROCESSING_TOPLIM_GIVEN | PROCESSING_BOTLIM_GIVEN)) {
1268 keep =
tmalloc(
sizeof(*keep) * n_data);
1269 for (i = 0; i < n_data; i++)
1270 keep[i] = 1;
1271 }
1272 if (processing_ptr->flags & PROCESSING_MATCHCOLUMN_GIVEN) {
1273 if (!(matchData =
SDDS_GetColumn(Dataset, processing_ptr->match_column)))
1274 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
1275 for (i = 0; i < n_data; i++)
1276 keep[i] = 0;
1277 for (i = 0; i < n_data; i++) {
1278 if (
wild_match(matchData[i], processing_ptr->match_value)) {
1279 matchfound = 1;
1280 keep[i] = 1;
1281 }
1282 }
1283 for (i = 0; i < n_data; i++)
1284 free(matchData[i]);
1285 free(matchData);
1286 if (!matchfound) {
1287 if (warnings)
1288 fprintf(stderr, "Warning: no values in column %s match %s.\n",
1289 processing_ptr->match_column, processing_ptr->match_value);
1290 free(keep);
1291 free(data);
1292 *result = processing_ptr->defaultValue;
1293 return 1;
1294 }
1295 }
1296 if (processing_ptr->flags & PROCESSING_LOLIM_GIVEN && indepData) {
1297#if DEBUG
1298 fprintf(stderr, "lower limit processing: value %e\n", processing_ptr->lowerLimit);
1299#endif
1300 for (i = 0; i < n_data; i++)
1301 if (processing_ptr->lowerLimit > indepData[i])
1302 keep[i] = 0;
1303 }
1304
1305 if (processing_ptr->flags & PROCESSING_UPLIM_GIVEN && indepData) {
1306#if DEBUG
1307 fprintf(stderr, "upper limit processing: value %e\n", processing_ptr->upperLimit);
1308#endif
1309 for (i = 0; i < n_data; i++) {
1310 if (processing_ptr->upperLimit < indepData[i])
1311 keep[i] = 0;
1312 if (isinf(indepData[i]) || isnan(indepData[i]))
1313 keep[i] = 0;
1314 }
1315 }
1316
1317 if (processing_ptr->flags & PROCESSING_TOPLIM_GIVEN) {
1318 for (i = 0; i < n_data; i++) {
1319 if (processing_ptr->topLimit < data[i])
1320 keep[i] = 0;
1321 if (isinf(data[i]) || isnan(data[i]))
1322 keep[i] = 0;
1323 }
1324 }
1325
1326 if (processing_ptr->flags & PROCESSING_BOTLIM_GIVEN) {
1327 for (i = 0; i < n_data; i++)
1328 if (processing_ptr->bottomLimit > data[i])
1329 keep[i] = 0;
1330 }
1331
1332 if (processing_ptr->flags & PROCESSING_HEAD_GIVEN) {
1333 count = 0;
1334#if DEBUG
1335 fprintf(stderr, "head processing: %ld points\n", processing_ptr->head);
1336#endif
1337 if (processing_ptr->head > 0) {
1338
1339 for (i = 0; i < n_data && count < processing_ptr->head; i++)
1340 if (keep[i])
1341 count++;
1342 for (; i < n_data; i++)
1343 keep[i] = 0;
1344 } else {
1345
1346 for (i = 0; i < n_data && count < -processing_ptr->head; i++)
1347 if (keep[i]) {
1348 count++;
1349 keep[i] = 0;
1350 }
1351 }
1352 }
1353
1354 if (processing_ptr->flags & PROCESSING_FHEAD_GIVEN) {
1355 long head;
1356 count = 0;
1357 head = fabs(n_data * processing_ptr->fhead + 0.5);
1358 if (processing_ptr->fhead > 0) {
1359 for (i = 0; i < n_data && count < head; i++)
1360 if (keep[i])
1361 count++;
1362 for (; i < n_data; i++)
1363 keep[i] = 0;
1364 } else
1365 for (i = 0; i < n_data && count < head; i++)
1366 if (keep[i]) {
1367 count++;
1368 keep[i] = 0;
1369 }
1370 }
1371
1372 if (processing_ptr->flags & PROCESSING_TAIL_GIVEN) {
1373 count = 0;
1374#if DEBUG
1375 fprintf(stderr, "tail processing: %ld points\n", processing_ptr->tail);
1376#endif
1377 if (processing_ptr->tail > 0) {
1378 for (i = n_data - 1; i >= 0 && count < processing_ptr->tail; i--)
1379 if (keep[i])
1380 count++;
1381 for (; i >= 0; i--)
1382 keep[i] = 0;
1383 } else
1384 for (i = n_data - 1; i >= 0 && count < -processing_ptr->tail; i--)
1385 if (keep[i]) {
1386 count++;
1387 keep[i] = 0;
1388 }
1389 }
1390
1391 if (processing_ptr->flags & PROCESSING_FTAIL_GIVEN) {
1392 long tail;
1393 count = 0;
1394 tail = fabs(processing_ptr->ftail * n_data + 0.5);
1395 if (processing_ptr->ftail > 0) {
1396 for (i = n_data - 1; i >= 0 && count < tail; i--)
1397 if (keep[i])
1398 count++;
1399 for (; i >= 0; i--)
1400 keep[i] = 0;
1401 } else
1402 for (i = n_data - 1; i >= 0 && count < tail; i--)
1403 if (keep[i]) {
1404 count++;
1405 keep[i] = 0;
1406 }
1407 }
1408
1409 if (keep) {
1410 int64_t j;
1411 for (i = j = 0; i < n_data; i++) {
1412 if (keep[i]) {
1413 if (i != j) {
1414 data[j] = data[i];
1415 if (indepData)
1416 indepData[j] = indepData[i];
1417 if (stringData) {
1418 free(stringData[j]);
1419 stringData[j] = stringData[i];
1420 stringData[i] = NULL;
1421 }
1422 if (weightData)
1423 weightData[j] = weightData[i];
1424 }
1425 j++;
1426 }
1427 }
1428 n_data = j;
1429#if DEBUG
1430 fprintf(stderr, "%" PRId64 " points kept\n", n_data);
1431#endif
1432 }
1433 if (n_data == 0) {
1434 free(data);
1435 if (indepData)
1436 free(indepData);
1437 if (weightData)
1438 free(weightData);
1439 if (keep)
1440 free(keep);
1441 if (warnings)
1442 fprintf(stderr, "warning: no matches found");
1443 if (mode != PROCESS_COLUMN_COUNT) {
1444 *result = processing_ptr->defaultValue;
1445 *stringResult = NULL;
1446 return 1;
1447 } else {
1448 *result = 0;
1449 *stringResult = NULL;
1450 return 1;
1451 }
1452 }
1453
1454 if (processing_ptr->flags & PROCESSING_OFFSET_GIVEN) {
1455#if DEBUG
1456 fprintf(stderr, "offsetting by %f\n", processing_ptr->offset);
1457#endif
1458 for (i = 0; i < n_data; i++)
1459 data[i] += processing_ptr->offset;
1460 }
1461
1462 if (processing_ptr->flags & PROCESSING_FACTOR_GIVEN) {
1463#if DEBUG
1464 fprintf(stderr, "multiplying by %f\n", processing_ptr->factor);
1465#endif
1466 for (i = 0; i < n_data; i++)
1467 data[i] *= processing_ptr->factor;
1468 }
1469
1470#if DEBUG
1471 fprintf(stderr, "data points:\n");
1472 for (i = 0; i < n_data; i++)
1473 fprintf(stderr, "%e%c", data[i], (i + 1) % 8 == 0 ? '\n' : ' ');
1474 fputc('\n', stderr);
1475#endif
1476
1477 *result = 0;
1478 returnValue = 1;
1479 switch (mode) {
1480 case PROCESS_COLUMN_ZEROCROSSING:
1481 for (i = 0; i < n_data - 1; i++) {
1482 if (data[i] == 0)
1483 break;
1484 if ((data[i] < 0 && data[i + 1] >= 0) || (data[i] > 0 && data[i + 1] <= 0))
1485 break;
1486 }
1487 if (i != n_data - 1) {
1488 if (indepData) {
1489 if (data[i] == 0)
1490 *result = indepData[i];
1491 else
1492 *result = indepData[i] + (indepData[i + 1] - indepData[i]) / (data[i + 1] - data[i]) * (-data[i]);
1493 }
1494 if (stringData) {
1495 *stringResult = stringData[i];
1496 stringData[i] = NULL;
1497 }
1498 } else
1499 returnValue = 0;
1500 break;
1501 case PROCESS_COLUMN_MEAN:
1502 if (weightData)
1504 else
1506 break;
1507 case PROCESS_COLUMN_RMS:
1508 if (weightData)
1510 else
1512 break;
1513 case PROCESS_COLUMN_SUM:
1514 if (weightData) {
1515 double sum;
1516 for (i = sum = 0; i < n_data; i++)
1517 sum += data[i] * weightData[i];
1518 *result = sum;
1519 } else
1521 break;
1522 case PROCESS_COLUMN_PRODUCT:
1523 if (weightData) {
1524 double product = 1;
1525 for (i = 0; i < n_data; i++)
1526 product *= data[i] * weightData[i];
1527 *result = product;
1528 } else {
1529 double product = 1;
1530 for (i = 0; i < n_data; i++)
1531 product *= data[i];
1532 *result = product;
1533 }
1534 break;
1535 case PROCESS_COLUMN_STAND_DEV:
1536 if (weightData)
1538 else
1540 break;
1541 case PROCESS_COLUMN_SIGMA:
1542 if (weightData)
1544 else
1546 *result /= sqrt(1.0 * n_data);
1547 break;
1548 case PROCESS_COLUMN_MAD:
1549 if (weightData)
1551 else
1553 break;
1554 case PROCESS_COLUMN_SIGNEDSMALLEST:
1555 imin = 0;
1556 for (i = 1; i < n_data; i++)
1557 if (fabs(data[imin]) > fabs(data[i]))
1558 imin = i;
1559 *result = data[imin];
1560 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1561 if (indepData)
1562 *result = indepData[imin];
1563 if (stringData) {
1564 *stringResult = stringData[imin];
1565 stringData[imin] = NULL;
1566 }
1567 }
1568 break;
1569 case PROCESS_COLUMN_SIGNEDLARGEST:
1570 imax = 0;
1571 for (i = 1; i < n_data; i++)
1572 if (fabs(data[imax]) < fabs(data[i]))
1573 imax = i;
1574 *result = data[imax];
1575 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1576 if (indepData)
1577 *result = indepData[imax];
1578 if (stringData) {
1579 *stringResult = stringData[imax];
1580 stringData[imax] = NULL;
1581 }
1582 }
1583 break;
1584 case PROCESS_COLUMN_SMALLEST:
1585 case PROCESS_COLUMN_LARGEST:
1586 for (i = 0; i < n_data; i++)
1587 data[i] = fabs(data[i]);
1589 returnValue = 0;
1590 else {
1591 switch (mode) {
1592 case PROCESS_COLUMN_SMALLEST:
1593 *result = data[i1 = imin];
1594 break;
1595 case PROCESS_COLUMN_LARGEST:
1596 *result = data[i1 = imax];
1597 break;
1598 }
1599 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1600 if (indepData)
1601 *result = indepData[i1];
1602 if (stringData) {
1603 *stringResult = stringData[i1];
1604 stringData[i1] = NULL;
1605 }
1606 }
1607 }
1608 break;
1609 case PROCESS_COLUMN_MINIMUM:
1610 case PROCESS_COLUMN_MAXIMUM:
1611 case PROCESS_COLUMN_SPREAD:
1613 returnValue = 0;
1614 else {
1615 min = data[imin];
1616 max = data[imax];
1617 switch (mode) {
1618 case PROCESS_COLUMN_MINIMUM:
1619 i1 = imin;
1620 *result = min;
1621 break;
1622 case PROCESS_COLUMN_MAXIMUM:
1623 i1 = imax;
1624 *result = max;
1625 break;
1626 case PROCESS_COLUMN_SMALLEST:
1627 if (fabs(min) < fabs(max)) {
1628 i1 = imin;
1629 *result = fabs(min);
1630 } else {
1631 i1 = imax;
1632 *result = fabs(max);
1633 }
1634 break;
1635 case PROCESS_COLUMN_LARGEST:
1636 if (fabs(min) > fabs(max)) {
1637 i1 = imin;
1638 *result = fabs(min);
1639 } else {
1640 i1 = imax;
1641 *result = fabs(max);
1642 }
1643 break;
1644 case PROCESS_COLUMN_SPREAD:
1645 *result = max - min;
1646 break;
1647 }
1648 if (processing_ptr->flags & PROCESSING_POSITION_GIVEN) {
1649 if (indepData)
1650 *result = indepData[i1];
1651 if (stringData) {
1652 *stringResult = stringData[i1];
1653 stringData[i1] = NULL;
1654 }
1655 }
1656 }
1657 break;
1658 case PROCESS_COLUMN_FIRST:
1659 *result = data[0];
1660 break;
1661 case PROCESS_COLUMN_LAST:
1662 *result = data[n_data - 1];
1663 break;
1664 case PROCESS_COLUMN_COUNT:
1665 *result = n_data;
1666 break;
1667 case PROCESS_COLUMN_MEDIAN:
1669 returnValue = 0;
1670 break;
1671 case PROCESS_COLUMN_MODE:
1672 if (processing_ptr->flags & PROCESSING_BINSIZE_GIVEN) {
1673 if (
computeMode(result, data, n_data, processing_ptr->binSize, 0) <= 0)
1674 returnValue = 0;
1675 }
else if (
computeMode(result, data, n_data, 0, 100) <= 0)
1676 returnValue = 0;
1677 break;
1678 case PROCESS_COLUMN_BASELEVEL:
1679 case PROCESS_COLUMN_TOPLEVEL:
1680 case PROCESS_COLUMN_AMPLITUDE:
1681 case PROCESS_COLUMN_RISETIME:
1682 case PROCESS_COLUMN_FALLTIME:
1683 case PROCESS_COLUMN_FWHA:
1684 case PROCESS_COLUMN_FWTA:
1685 case PROCESS_COLUMN_CENTER:
1686 case PROCESS_COLUMN_FWHM:
1687 case PROCESS_COLUMN_FWTM:
1690 returnValue = 0;
1691 else {
1692 if ((top - base) < 0.75 * (data[imax] - base))
1693 top = data[imax];
1694 switch (mode) {
1695 case PROCESS_COLUMN_BASELEVEL:
1696 *result = base;
1697 break;
1698 case PROCESS_COLUMN_TOPLEVEL:
1699 *result = top;
1700 break;
1701 case PROCESS_COLUMN_AMPLITUDE:
1702 *result = top - base;
1703 break;
1704 case PROCESS_COLUMN_RISETIME:
1705 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1706 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, indepData, &point2)) < 0)
1707 returnValue = 0;
1708 else
1709 *result = point2 - point1;
1710 break;
1711 case PROCESS_COLUMN_FALLTIME:
1712 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.9, -1, indepData, &point1)) < 0 ||
1713 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0)
1714 returnValue = 0;
1715 else
1716 *result = point2 - point1;
1717 break;
1718 case PROCESS_COLUMN_FWHA:
1719 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1720 (i2 = i2save =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1721 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1722 if (warnings) {
1723 fprintf(stderr, "warning: couldn't find crossing point for FWHA of %s\n",
1724 processing_ptr->column_name);
1725 fprintf(stderr, "top, base = %e, %e min, max = %e, %e\n", top, base,
1726 data[imin], data[imax]);
1727 if (i1 > 0)
1728 fprintf(stderr, "#1: %ld, (%e, %e)\n",
1729 i1, indepData[i1], data[i1]);
1730 if (i2save > 0)
1731 fprintf(stderr, "#2: %ld, (%e, %e)\n",
1732 i2save, indepData[i2save], data[i2save]);
1733 if (i2 > 0)
1734 fprintf(stderr, "#2a: %ld, (%e, %e)\n",
1735 i2, indepData[i2], data[i2]);
1736 }
1737 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1738 (i2 = i2save =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1739 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1740 returnValue = 0;
1741 } else {
1742 *result = point2 - point1;
1743 }
1744 } else
1745 *result = point2 - point1;
1746 break;
1747 case PROCESS_COLUMN_FWTA:
1748 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1749 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1750 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0) {
1751 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.1, 1, indepData, &point1)) < 0 ||
1752 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1753 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.1, -1, indepData, &point2)) < 0) {
1754 returnValue = 0;
1755 } else {
1756 *result = point2 - point1;
1757 }
1758 } else
1759 *result = point2 - point1;
1760 break;
1761 case PROCESS_COLUMN_FWHM:
1762 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.5, 1, indepData, &point1)) < 0 ||
1763 (i2 = i2save =
findCrossingPoint(i1, data, n_data, top * 0.9, -1, NULL, NULL)) < 0 ||
1764 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.5, -1, indepData, &point2)) < 0) {
1765 if (warnings) {
1766 fprintf(stderr, "warning: couldn't find crossing point for FWHM of %s\n",
1767 processing_ptr->column_name);
1768 fprintf(stderr, "top, base = %e, %e\n", top, base);
1769 if (i1 > 0)
1770 fprintf(stderr, "#1: %ld, (%e, %e)\n",
1771 i1, indepData[i1], data[i1]);
1772 if (i2save > 0)
1773 fprintf(stderr, "#2: %ld, (%e, %e)\n",
1774 i2save, indepData[i2save], data[i2save]);
1775 }
1776 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.5, 1, indepData, &point1)) < 0 ||
1777 (i2 = i2save =
findCrossingPoint(i1, data, n_data, top * 0.9, 1, NULL, NULL)) < 0 ||
1778 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.5, -1, indepData, &point2)) < 0) {
1779 returnValue = 0;
1780 } else {
1781 *result = point2 - point1;
1782 }
1783 } else
1784 *result = point2 - point1;
1785 break;
1786 case PROCESS_COLUMN_FWTM:
1787 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.1, 1, indepData, &point1)) < 0 ||
1789 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.1, -1, indepData, &point2)) < 0) {
1790 if ((i1 =
findCrossingPoint(0, data, n_data, top * 0.1, 1, indepData, &point1)) < 0 ||
1792 (i2 =
findCrossingPoint(i2, data, n_data, top * 0.1, -1, indepData, &point2)) < 0) {
1793 returnValue = 0;
1794 } else {
1795 *result = point2 - point1;
1796 }
1797 } else
1798 *result = point2 - point1;
1799 break;
1800 case PROCESS_COLUMN_CENTER:
1801 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1802 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, -1, NULL, NULL)) < 0 ||
1803 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1804 if ((i1 =
findCrossingPoint(0, data, n_data, base + (top - base) * 0.5, 1, indepData, &point1)) < 0 ||
1805 (i2 =
findCrossingPoint(i1, data, n_data, base + (top - base) * 0.9, 1, NULL, NULL)) < 0 ||
1806 (i2 =
findCrossingPoint(i2, data, n_data, base + (top - base) * 0.5, -1, indepData, &point2)) < 0) {
1807 returnValue = 0;
1808 } else {
1809 *result = (point1 + point2) / 2;
1810 }
1811 } else
1812 *result = (point1 + point2) / 2;
1813 break;
1814 }
1815 }
1816 break;
1817 case PROCESS_COLUMN_SLOPE:
1818 case PROCESS_COLUMN_INTERCEPT:
1819 case PROCESS_COLUMN_LFSD:
1821 returnValue = 0;
1822 else
1823 switch (mode) {
1824 case PROCESS_COLUMN_SLOPE:
1825 *result = slope;
1826 break;
1827 case PROCESS_COLUMN_INTERCEPT:
1828 *result = intercept;
1829 break;
1830 case PROCESS_COLUMN_LFSD:
1831 *result = sqrt(variance);
1832 break;
1833 }
1834 break;
1835 case PROCESS_COLUMN_INTEGRAL:
1837 break;
1838 case PROCESS_COLUMN_GMINTEGRAL:
1839 GillMillerIntegration1(indepData, data, n_data, result);
1840 break;
1841 case PROCESS_COLUMN_QRANGE:
1843 returnValue = 0;
1844 else
1845 *result = quartileResult[1] - quartileResult[0];
1846 break;
1847 case PROCESS_COLUMN_DRANGE:
1849 returnValue = 0;
1850 else
1851 *result = decileResult[1] - decileResult[0];
1852 break;
1853 case PROCESS_COLUMN_PERCENTILE:
1854 if (!
compute_percentiles(percentileResult, &processing_ptr->percentileLevel, 1, data, n_data))
1855 returnValue = 0;
1856 else {
1857 *result = percentileResult[0];
1858 returnValue = 1;
1859 }
1860 break;
1861 case PROCESS_COLUMN_PRANGE:
1862 percentilePoint[1] = 50 + processing_ptr->percentileLevel / 2.0;
1863 percentilePoint[0] = 50 - processing_ptr->percentileLevel / 2.0;
1865 returnValue = 0;
1866 else {
1867 *result = percentileResult[1] - percentileResult[0];
1868 returnValue = 1;
1869 }
1870 break;
1871 case PROCESS_COLUMN_CORRELATION:
1873 returnValue = 1;
1874 break;
1875 default:
1876 returnValue = 0;
1877 break;
1878 }
1879
1880 free(data);
1881 if (indepData)
1882 free(indepData);
1883 if (weightData)
1884 free(weightData);
1885 if (keep)
1886 free(keep);
1887 if (stringData) {
1888 for (i = 0; i < n_data; i++)
1889 if (stringData[i])
1890 free(stringData[i]);
1891 free(stringData);
1892 }
1893 if (!returnValue) {
1894 if (warnings)
1895 fprintf(stderr, "warning: processing of %s with mode %s failed--value %e returned\n",
1896 processing_ptr->column_name,
1897 process_column_name[processing_ptr->mode],
1898 processing_ptr->defaultValue);
1899 *result = processing_ptr->defaultValue;
1900 *stringResult = NULL;
1901 }
1902 return 1;
1903}
int index_min_max(int64_t *imin, int64_t *imax, double *list, int64_t n)
Finds the indices of the minimum and maximum values in a list of doubles.
double linearCorrelationCoefficient(double *data1, double *data2, short *accept1, short *accept2, long rows, long *count)
Compute the linear correlation coefficient for two data sets.
long unweightedLinearFit(double *xData, double *yData, long nData, double *slope, double *intercept, double *variance)
Performs an unweighted linear fit on the provided data.
long computeMode(double *result, double *data, long pts, double binSize, long bins)
Computes the mode of a dataset using histogram binning.
double weightedStDevThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted standard deviation of an array of doubles using multiple threads.
double standardDeviationThreaded(double *x, long n, long numThreads)
Calculates the standard deviation of an array of doubles using multiple threads.
double rmsValueThreaded(double *y, long n, long numThreads)
Calculates the RMS (Root Mean Square) value of an array of doubles using multiple threads.
double arithmeticAverageThreaded(double *y, long n, long numThreads)
Calculates the arithmetic average of an array of doubles using multiple threads.
double weightedRMSThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted RMS (Root Mean Square) value of an array of doubles using multiple threads.
double meanAbsoluteDeviationThreaded(double *y, long n, long numThreads)
Calculates the mean absolute deviation of an array of doubles using multiple threads.
double weightedMADThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted mean absolute deviation of an array of doubles using multiple threads.
double weightedAverageThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted average of an array of doubles using multiple threads.
long findTopBaseLevels(double *top, double *base, double *data, int64_t points, long bins, double sigmasRequired)
Finds the top-level and base-level of a dataset.
int64_t findCrossingPoint(int64_t start, double *data, int64_t points, double level, long direction, double *indepData, double *location)
Finds the crossing point in the data where the data crosses a specified level.
long trapazoidIntegration(double *x, double *y, long n, double *integral)
Computes the integral of a dataset using the trapezoidal rule.
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.