Changeset 9534
- Timestamp:
- Oct 13, 2006, 9:06:00 AM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
-
psMetadata.c (modified) (21 diffs)
-
psMetadata.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadata.c
r9523 r9534 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.13 7$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-10-1 2 23:43:58$14 * @version $Revision: 1.138 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-10-13 19:06:00 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1413 1413 } 1414 1414 1415 psPolynomial 2D *psPolynomial2DfromMD (psMetadata *folder)1415 psPolynomial1D *psPolynomial1DfromMD (psMetadata *folder) 1416 1416 { 1417 1417 PS_ASSERT_PTR_NON_NULL(folder, NULL); … … 1420 1420 1421 1421 // get polynomial orders 1422 // XXX add status failures tests1423 1422 int nXorder = psMetadataLookupS32 (&status, folder, "NORDER_X"); 1424 if (!status) 1425 return NULL; 1423 if (!status) { 1424 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial1D in metadata is missing NORDER_X"); 1425 return NULL; 1426 } 1427 // how many polynomial coeffs are expected? 1428 int nElementsExpected = psMetadataLookupS32 (&status, folder, "NELEMENTS"); 1429 if (!status) { 1430 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial1D in metadata is missing NELEMENTS"); 1431 return NULL; 1432 } 1433 1434 psPolynomial1D *poly = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, nXorder); 1435 1436 int nElements = 0; 1437 for (int nx = 0; nx < poly->nX + 1; nx++) { 1438 sprintf (keyword, "VAL_X%02d", nx); 1439 poly->coeff[nx] = psMetadataLookupF64 (&status, folder, keyword); 1440 if (!status) { 1441 // an undefined component implies the component was masked 1442 // this is symmetrical with the 1DtoMD function 1443 poly->mask[nx] = 1; 1444 poly->coeff[nx] = 0; 1445 poly->coeffErr[nx] = 0; 1446 } else { 1447 poly->mask[nx] = 0; 1448 nElements ++; 1449 } 1450 sprintf (keyword, "ERR_X%02d", nx); 1451 poly->coeffErr[nx] = psMetadataLookupF64 (&status, folder, keyword); 1452 } 1453 if (nElements != nElementsExpected) { 1454 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1455 "psPolynomial1D in metadata does not have the correct number of coefficients: " 1456 "%d found vs %d expected", nElements, nElementsExpected); 1457 psFree(poly); 1458 return NULL; 1459 } 1460 return (poly); 1461 } 1462 1463 // XXX : these may need F64, or %g format for output 1464 bool psPolynomial1DtoMD (psMetadata *md, 1465 psPolynomial1D *poly, 1466 char *format, 1467 ...) 1468 { 1469 PS_ASSERT_PTR_NON_NULL(md, false); 1470 PS_ASSERT_PTR_NON_NULL(poly, false); 1471 //XXX: Current implementation only supports ordinary polynomials. 1472 if (poly->type != PS_POLYNOMIAL_ORD) 1473 return false; 1474 1475 int Nbyte; 1476 char tmp; 1477 char *root; 1478 va_list argp; 1479 1480 va_start (argp, format); 1481 Nbyte = vsnprintf (&tmp, 0, format, argp); 1482 va_end (argp); 1483 1484 if (Nbyte <= 0) 1485 return false; 1486 1487 va_start (argp, format); 1488 root = (char *) psAlloc (Nbyte + 1); 1489 memset (root, 0, Nbyte + 1); 1490 vsnprintf (root, Nbyte + 1, format, argp); 1491 va_end (argp); 1492 1493 psMetadata *folder = psMetadataAlloc (); 1494 1495 // specify the polynomial orders 1496 psMetadataAdd (folder, PS_LIST_TAIL, "NORDER_X", PS_DATA_S32, "number of x orders", poly->nX); 1497 1498 char namespace[80]; 1499 char namespace_err[80]; 1500 int nElements = 0; // count the number of unmasked elements 1501 1502 // place polynomial entries on folder 1503 for (int nx = 0; nx < poly->nX + 1; nx++) { 1504 if (poly->mask[nx] == 0) { 1505 sprintf(namespace, "VAL_X%02d", nx); 1506 sprintf(namespace_err, "ERR_X%02d", nx); 1507 psMetadataAdd (folder, PS_LIST_TAIL, namespace, PS_DATA_F64, 1508 "polynomial coefficient", poly->coeff[nx]); 1509 psMetadataAdd (folder, PS_LIST_TAIL, namespace_err, PS_DATA_F64, 1510 "polynomial coefficient error", poly->coeffErr[nx]); 1511 nElements ++; 1512 } 1513 } 1514 psMetadataAdd (folder, PS_LIST_TAIL, "NELEMENTS", PS_DATA_S32, "number of unmasked coeffs", nElements); 1515 psMetadataAdd (md, PS_LIST_TAIL, root, PS_DATA_METADATA, "folder for 1D polynomial", folder); 1516 psFree (root); 1517 psFree(folder); 1518 return true; 1519 } 1520 1521 psPolynomial2D *psPolynomial2DfromMD (psMetadata *folder) 1522 { 1523 PS_ASSERT_PTR_NON_NULL(folder, NULL); 1524 bool status; 1525 char keyword[80]; 1526 1527 // get polynomial orders 1528 int nXorder = psMetadataLookupS32 (&status, folder, "NORDER_X"); 1529 if (!status) { 1530 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial2D in metadata is missing NORDER_X"); 1531 return NULL; 1532 } 1426 1533 int nYorder = psMetadataLookupS32 (&status, folder, "NORDER_Y"); 1427 if (!status) 1428 return NULL; 1534 if (!status) { 1535 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial2D in metadata is missing NORDER_Y"); 1536 return NULL; 1537 } 1538 // how many polynomial coeffs are expected? 1539 int nElementsExpected = psMetadataLookupS32 (&status, folder, "NELEMENTS"); 1540 if (!status) { 1541 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial2D in metadata is missing NELEMENTS"); 1542 return NULL; 1543 } 1429 1544 1430 1545 psPolynomial2D *poly = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder); 1431 1546 1547 int nElements = 0; 1432 1548 for (int nx = 0; nx < poly->nX + 1; nx++) { 1433 1549 for (int ny = 0; ny < poly->nY + 1; ny++) { … … 1435 1551 poly->coeff[nx][ny] = psMetadataLookupF64 (&status, folder, keyword); 1436 1552 if (!status) { 1437 // XXX: Setting the mask of a corrupted polynomial doesn't make sense.1438 // The polynomial is garbage if ANY coeff-element is lost!!!1439 //poly->mask[nx][ny] = 1;1440 p sError(PS_ERR_BAD_PARAMETER_VALUE, false,1441 "psPolynomial2D in metadata has lost a coefficient somewhere!"1442 " >>position= [x,y] = %02d, %02d", nx, ny);1443 p sFree(poly);1444 return NULL;1553 // an undefined component implies the component was masked 1554 // this is symmetrical with the 2DtoMD function 1555 poly->mask[nx][ny] = 1; 1556 poly->coeff[nx][ny] = 0; 1557 poly->coeffErr[nx][ny] = 0; 1558 } else { 1559 poly->mask[nx][ny] = 0; 1560 nElements ++; 1445 1561 } 1446 1562 sprintf (keyword, "ERR_X%02d_Y%02d", nx, ny); 1447 1563 poly->coeffErr[nx][ny] = psMetadataLookupF64 (&status, folder, keyword); 1448 1564 } 1565 } 1566 if (nElements != nElementsExpected) { 1567 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1568 "psPolynomial2D in metadata does not have the correct number of coefficients: " 1569 "%d found vs %d expected", nElements, nElementsExpected); 1570 psFree(poly); 1571 return NULL; 1449 1572 } 1450 1573 return (poly); … … 1462 1585 if (poly->type != PS_POLYNOMIAL_ORD) 1463 1586 return false; 1587 1588 // XXX I'm puzzled by this test. a polynomial of 0 order with a value of 0 is a 1589 // perfectly valid polynomial and can be written out. a polynomial with all elements 1590 // masked still carries information. 1464 1591 //Make sure polynomial isn't 0, completely empty 1465 if (poly->nX == 0 && poly->nY == 0 && poly->coeff[0][0] == 0)1466 return false;1592 //if (poly->nX == 0 && poly->nY == 0 && poly->coeff[0][0] == 0) 1593 //return false; 1467 1594 1468 1595 int Nbyte; … … 1492 1619 char namespace[80]; 1493 1620 char namespace_err[80]; 1621 int nElements = 0; // count the number of unmasked elements 1622 1494 1623 // place polynomial entries on folder 1495 1624 for (int nx = 0; nx < poly->nX + 1; nx++) { … … 1502 1631 psMetadataAdd (folder, PS_LIST_TAIL, namespace_err, PS_DATA_F64, 1503 1632 "polynomial coefficient error", poly->coeffErr[nx][ny]); 1633 nElements ++; 1504 1634 } 1505 1635 } 1506 1636 } 1637 psMetadataAdd (folder, PS_LIST_TAIL, "NELEMENTS", PS_DATA_S32, "number of unmasked coeffs", nElements); 1507 1638 psMetadataAdd (md, PS_LIST_TAIL, root, PS_DATA_METADATA, "folder for 2D polynomial", folder); 1508 1639 psFree (root); … … 1519 1650 1520 1651 // get polynomial orders 1521 // XXX add status failures tests1522 1652 int nXorder = psMetadataLookupS32 (&status, folder, "NORDER_X"); 1523 if (!status) 1524 return NULL; 1653 if (!status) { 1654 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial3D in metadata is missing NORDER_X"); 1655 return NULL; 1656 } 1525 1657 int nYorder = psMetadataLookupS32 (&status, folder, "NORDER_Y"); 1526 if (!status) 1527 return NULL; 1658 if (!status) { 1659 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial3D in metadata is missing NORDER_Y"); 1660 return NULL; 1661 } 1528 1662 int nZorder = psMetadataLookupS32 (&status, folder, "NORDER_Z"); 1529 if (!status) 1530 return NULL; 1663 if (!status) { 1664 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial3D in metadata is missing NORDER_Z"); 1665 return NULL; 1666 } 1667 // how many polynomial coeffs are expected? 1668 int nElementsExpected = psMetadataLookupS32 (&status, folder, "NELEMENTS"); 1669 if (!status) { 1670 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial3D in metadata is missing NELEMENTS"); 1671 return NULL; 1672 } 1531 1673 1532 1674 psPolynomial3D *poly = psPolynomial3DAlloc (PS_POLYNOMIAL_ORD, nXorder, nYorder, nZorder); 1533 1675 1676 int nElements = 0; 1534 1677 for (int nx = 0; nx < poly->nX + 1; nx++) { 1535 1678 for (int ny = 0; ny < poly->nY + 1; ny++) { … … 1538 1681 poly->coeff[nx][ny][nz] = psMetadataLookupF64 (&status, folder, keyword); 1539 1682 if (!status) { 1540 // XXX: Setting the mask of a corrupted polynomial doesn't make sense.1541 // The polynomial is garbage if ANY coeff-element is lost!!!1542 //poly->mask[nx][ny][nz] = 1;1543 p sError(PS_ERR_BAD_PARAMETER_VALUE, false,1544 "psPolynomial3D in metadata has lost a coefficient somewhere!"1545 " >>position= [x,y,z] = %02d, %02d, %02d", nx, ny, nz);1546 p sFree(poly);1547 return NULL;1683 // an undefined component implies the component was masked 1684 // this is symmetrical with the 3DtoMD function 1685 poly->mask[nx][ny][nz] = 1; 1686 poly->coeff[nx][ny][nz] = 0; 1687 poly->coeffErr[nx][ny][nz] = 0; 1688 } else { 1689 poly->mask[nx][ny][nz] = 0; 1690 nElements ++; 1548 1691 } 1549 1692 sprintf (keyword, "ERR_X%02d_Y%02d_Z%02d", nx, ny, nz); … … 1551 1694 } 1552 1695 } 1696 } 1697 if (nElements != nElementsExpected) { 1698 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1699 "psPolynomial3D in metadata does not have the correct number of coefficients: " 1700 "%d found vs %d expected", nElements, nElementsExpected); 1701 psFree(poly); 1702 return NULL; 1553 1703 } 1554 1704 return (poly); … … 1565 1715 if (poly->type != PS_POLYNOMIAL_ORD) 1566 1716 return false; 1567 //Make sure polynomial isn't 0, completely empty1568 if (poly->nX == 0 && poly->nY == 0 && poly->nZ == 0 && poly->coeff[0][0][0] == 0)1569 return false;1570 1717 1571 1718 int Nbyte; … … 1596 1743 char namespace[80]; 1597 1744 char namespace_err[80]; 1745 int nElements = 0; // count the number of unmasked elements 1746 1598 1747 // place polynomial entries on folder 1599 1748 for (int nx = 0; nx < poly->nX + 1; nx++) { … … 1609 1758 PS_DATA_F64, "polynomial coeffficient error", 1610 1759 poly->coeffErr[nx][ny][nz], nx, ny, nz); 1760 nElements ++; 1611 1761 } 1612 1762 } 1613 1763 } 1614 1764 } 1615 1765 psMetadataAdd (folder, PS_LIST_TAIL, "NELEMENTS", PS_DATA_S32, "number of unmasked coeffs", nElements); 1616 1766 psMetadataAdd (md, PS_LIST_TAIL, root, PS_DATA_METADATA, "folder for 3D polynomial", folder); 1617 1767 psFree(root); … … 1620 1770 } 1621 1771 1622 1623 1772 psPolynomial4D *psPolynomial4DfromMD (psMetadata *folder) 1624 1773 { … … 1628 1777 char keyword[80]; 1629 1778 1630 // get polynomial orders1631 // XXX add status failures tests1632 1779 int nXorder = psMetadataLookupS32 (&status, folder, "NORDER_X"); 1633 if (!status) 1634 return NULL; 1780 if (!status) { 1781 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial4D in metadata is missing NORDER_X"); 1782 return NULL; 1783 } 1635 1784 int nYorder = psMetadataLookupS32 (&status, folder, "NORDER_Y"); 1636 if (!status) 1637 return NULL; 1785 if (!status) { 1786 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial4D in metadata is missing NORDER_Y"); 1787 return NULL; 1788 } 1638 1789 int nZorder = psMetadataLookupS32 (&status, folder, "NORDER_Z"); 1639 if (!status) 1640 return NULL; 1790 if (!status) { 1791 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial4D in metadata is missing NORDER_Z"); 1792 return NULL; 1793 } 1641 1794 int nTorder = psMetadataLookupS32 (&status, folder, "NORDER_T"); 1642 if (!status) 1643 return NULL; 1644 1645 psPolynomial4D *poly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, 1646 nXorder, nYorder, nZorder, nTorder); 1647 1795 if (!status) { 1796 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial4D in metadata is missing NORDER_T"); 1797 return NULL; 1798 } 1799 // how many polynomial coeffs are expected? 1800 int nElementsExpected = psMetadataLookupS32 (&status, folder, "NELEMENTS"); 1801 if (!status) { 1802 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "psPolynomial4D in metadata is missing NELEMENTS"); 1803 return NULL; 1804 } 1805 1806 psPolynomial4D *poly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, nXorder, nYorder, nZorder, nTorder); 1807 1808 int nElements = 0; 1648 1809 for (int nx = 0; nx < poly->nX + 1; nx++) { 1649 1810 for (int ny = 0; ny < poly->nY + 1; ny++) { … … 1653 1814 poly->coeff[nx][ny][nz][nt] = psMetadataLookupF64 (&status, folder, keyword); 1654 1815 if (!status) { 1655 // XXX: Setting the mask of a corrupted polynomial doesn't make sense.1656 // The polynomial is garbage if ANY coeff-element is lost!!!1657 //poly->mask[nx][ny][nz][nt] = 1;1658 p sError(PS_ERR_BAD_PARAMETER_VALUE, false,1659 "psPolynomial4D in metadata has lost a coefficient somewhere!"1660 " >>position= [x,y,z,t] = %02d, %02d, %02d, %02d", nx,ny,nz,nt);1661 p sFree(poly);1662 return NULL;1816 // an undefined component implies the component was masked 1817 // this is symmetrical with the 4DtoMD function 1818 poly->mask[nx][ny][nz][nt] = 1; 1819 poly->coeff[nx][ny][nz][nt] = 0; 1820 poly->coeffErr[nx][ny][nz][nt] = 0; 1821 } else { 1822 poly->mask[nx][ny][nz][nt] = 0; 1823 nElements ++; 1663 1824 } 1664 1665 1825 sprintf (keyword, "ERR_X%02d_Y%02d_Z%02d_T%02d", nx, ny, nz, nt); 1666 1826 poly->coeffErr[nx][ny][nz][nt] = psMetadataLookupF64 (&status, folder, keyword); … … 1668 1828 } 1669 1829 } 1830 } 1831 if (nElements != nElementsExpected) { 1832 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1833 "psPolynomial4D in metadata does not have the correct number of coefficients: " 1834 "%d found vs %d expected", nElements, nElementsExpected); 1835 psFree(poly); 1836 return NULL; 1670 1837 } 1671 1838 return (poly); … … 1682 1849 if (poly->type != PS_POLYNOMIAL_ORD) 1683 1850 return false; 1684 //Make sure polynomial isn't 0, completely empty1685 if (poly->nX == 0 && poly->nY == 0 && poly->nZ == 0 && poly->nT == 01686 && poly->coeff[0][0][0][0] == 0)1687 return false;1688 1689 1851 1690 1852 int Nbyte; … … 1716 1878 char namespace[80]; 1717 1879 char namespace_err[80]; 1880 int nElements = 0; // count the number of unmasked elements 1881 1718 1882 // place polynomial entries on folder 1719 1883 for (int nx = 0; nx < poly->nX + 1; nx++) { … … 1730 1894 PS_DATA_F64, "polynomial coeffficient error", 1731 1895 poly->coeffErr[nx][ny][nz][nt], nx, ny, nz, nt); 1896 nElements ++; 1732 1897 } 1733 1898 } … … 1735 1900 } 1736 1901 } 1902 psMetadataAdd (folder, PS_LIST_TAIL, "NELEMENTS", PS_DATA_S32, "number of unmasked coeffs", nElements); 1737 1903 psMetadataAdd (md, PS_LIST_TAIL, root, PS_DATA_METADATA, "folder for 4D polynomial", folder); 1738 1904 psFree(root); -
trunk/psLib/src/types/psMetadata.h
r9523 r9534 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.8 6$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-10-1 2 23:43:58$13 * @version $Revision: 1.87 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-10-13 19:06:00 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1070 1070 ); 1071 1071 1072 /** Allocates a new psPolynomial1D structure with information from a psMetadata. 1073 * 1074 * Parses a psMetadata container with psPolynomial1D information. The first two 1075 * elements of the metadata folder specify the order of the x & y variables. (ie, 1076 * NORDER_X, NORDER_Y). The following elements are the values of the coefficients 1077 * and the coefficient errors. (ie, VAL_X00_Y00, ERR_X00_Y00, etc.). If the orders 1078 * or any coefficients are missing or have incorrect syntax, NULL is returned. 1079 * 1080 * @return psPolynomial1D*: Newly allocated psPolynomial1D from metadata. 1081 */ 1082 psPolynomial1D *psPolynomial1DfromMD( 1083 psMetadata *folder ///< folder containing the polynomial info. 1084 ); 1085 1086 /** Stores the information from a psPolynomial1D structure in a psMetadata container. 1087 * 1088 * Creates a psMetadata folder with psPolynomial1D information. The first two 1089 * elements of the metadata folder specify the order of the x & y variables. (ie, 1090 * NORDER_X, NORDER_Y). The following elements are the values of the coefficients 1091 * and the coefficient errors. (ie, VAL_X00_Y00, ERR_X00_Y00, etc.). The input 1092 * polynomial must be of ordinary type and have a valid name format. False is also 1093 * returned if any inputs are NULL. *If a particular mask element is non-zero, that 1094 * polynomial coefficient (and error) are skipped. 1095 * 1096 * @return bool: True if successful, otherwise false. 1097 */ 1098 bool psPolynomial1DtoMD( 1099 psMetadata *md, ///< Metadata container for polynomial storage. 1100 psPolynomial1D *poly, ///< Polynomial information to be stored. 1101 char *format, ///< Name of polynomial folder. 1102 ... ///< Arguments for name formatting. 1103 ); 1104 1072 1105 /** Allocates a new psPolynomial2D structure with information from a psMetadata. 1073 1106 *
Note:
See TracChangeset
for help on using the changeset viewer.
