- Timestamp:
- 24/10/11 16:43:58 (7 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
bindings/cpp/NeXusFile.cpp (modified) (4 diffs)
-
bindings/cpp/NeXusFile.hpp (modified) (3 diffs)
-
test/napi_test_cpp.cxx (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bindings/cpp/NeXusFile.cpp
r1654 r1711 370 370 371 371 372 373 template <typename NumT> 374 void File::writeExtendibleData(const string& name, vector<NumT>& value) 375 { 376 // Use a default chunk size of 4096 bytes. TODO: Is this optimal? 377 writeExtendibleData(name, value, 4096); 378 } 379 380 template <typename NumT> 381 void File::writeExtendibleData(const string& name, vector<NumT>& value, const int64_t chunk) 382 { 383 vector<int64_t> dims(1, NX_UNLIMITED); 384 vector<int64_t> chunk_dims(1, chunk); 385 // Use chunking without using compression 386 this->makeCompData(name, getType<NumT>(), dims, NONE, chunk_dims, true ); 387 this->putSlab(value, int64_t(0), int64_t(value.size())); 388 this->closeData(); 389 } 390 391 template <typename NumT> 392 void File::writeExtendibleData(const string& name, vector<NumT>& value, 393 vector<int64_t>& dims, std::vector<int64_t> & chunk) 394 { 395 // Create the data with unlimited 0th dimensions 396 std::vector<int64_t> unlim_dims(dims); 397 unlim_dims[0] = NX_UNLIMITED; 398 // Use chunking without using compression 399 this->makeCompData(name, getType<NumT>(), unlim_dims, NONE, chunk, true ); 400 // And put that slab of that of that given size in there 401 std::vector<int64_t> start( dims.size(), 0 ); 402 this->putSlab(value, start, dims); 403 this->closeData(); 404 405 } 406 407 408 template <typename NumT> 409 void File::writeUpdatedData(const std::string& name, std::vector<NumT>& value) 410 { 411 this->openData(name); 412 this->putSlab(value, int64_t(0), int64_t(value.size())); 413 this->closeData(); 414 } 415 416 template <typename NumT> 417 void File::writeUpdatedData(const std::string& name, std::vector<NumT>& value, 418 std::vector<int64_t>& dims) 419 { 420 this->openData(name); 421 std::vector<int64_t> start( dims.size(), 0 ); 422 this->putSlab(value, start, dims); 423 this->closeData(); 424 } 425 426 372 427 void File::makeCompData(const string& name, const NXnumtype type, 373 428 const vector<int>& dims, const NXcompression comp, … … 807 862 this->closeData(); 808 863 } 864 865 template <typename NumT> 866 void File::readData(const std::string & dataName, NumT & data) 867 { 868 std::vector<NumT> dataVector; 869 this->openData(dataName); 870 this->getData(dataVector); 871 if (dataVector.size() > 0) 872 data = dataVector[0]; 873 this->closeData(); 874 } 875 809 876 void File::readData(const std::string & dataName, std::string& data) 810 877 { … … 1347 1414 1348 1415 template 1416 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value); 1417 template 1418 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value); 1419 template 1420 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value); 1421 template 1422 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value); 1423 template 1424 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value); 1425 template 1426 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value); 1427 template 1428 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value); 1429 template 1430 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value); 1431 template 1432 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value); 1433 template 1434 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value); 1435 template 1436 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value); 1437 1438 template 1439 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value, const int64_t chunk); 1440 template 1441 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value, const int64_t chunk); 1442 template 1443 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value, const int64_t chunk); 1444 template 1445 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value, const int64_t chunk); 1446 template 1447 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value, const int64_t chunk); 1448 template 1449 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value, const int64_t chunk); 1450 template 1451 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value, const int64_t chunk); 1452 template 1453 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value, const int64_t chunk); 1454 template 1455 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value, const int64_t chunk); 1456 template 1457 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value, const int64_t chunk); 1458 template 1459 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value, const int64_t chunk); 1460 1461 template 1462 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1463 template 1464 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1465 template 1466 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1467 template 1468 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1469 template 1470 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1471 template 1472 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1473 template 1474 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1475 template 1476 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1477 template 1478 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1479 template 1480 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1481 template 1482 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk); 1483 1484 template 1485 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<float>& value); 1486 template 1487 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<double>& value); 1488 template 1489 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int8_t>& value); 1490 template 1491 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint8_t>& value); 1492 template 1493 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int16_t>& value); 1494 template 1495 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint16_t>& value); 1496 template 1497 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int32_t>& value); 1498 template 1499 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint32_t>& value); 1500 template 1501 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int64_t>& value); 1502 template 1503 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint64_t>& value); 1504 template 1505 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<char>& value); 1506 1507 template 1508 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<float>& value, std::vector<int64_t> & dims); 1509 template 1510 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<double>& value, std::vector<int64_t> & dims); 1511 template 1512 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int8_t>& value, std::vector<int64_t> & dims); 1513 template 1514 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint8_t>& value, std::vector<int64_t> & dims); 1515 template 1516 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int16_t>& value, std::vector<int64_t> & dims); 1517 template 1518 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint16_t>& value, std::vector<int64_t> & dims); 1519 template 1520 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int32_t>& value, std::vector<int64_t> & dims); 1521 template 1522 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint32_t>& value, std::vector<int64_t> & dims); 1523 template 1524 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int64_t>& value, std::vector<int64_t> & dims); 1525 template 1526 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint64_t>& value, std::vector<int64_t> & dims); 1527 template 1528 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<char>& value, std::vector<int64_t> & dims); 1529 1530 template 1349 1531 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<float> & value, 1350 1532 const vector<int> & dims, const NXcompression comp, … … 1495 1677 template 1496 1678 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<char>& data); 1679 1680 template 1681 NXDLL_EXPORT void File::readData(const std::string & dataName, float& data); 1682 template 1683 NXDLL_EXPORT void File::readData(const std::string & dataName, double& data); 1684 template 1685 NXDLL_EXPORT void File::readData(const std::string & dataName, int8_t& data); 1686 template 1687 NXDLL_EXPORT void File::readData(const std::string & dataName, uint8_t& data); 1688 template 1689 NXDLL_EXPORT void File::readData(const std::string & dataName, int16_t& data); 1690 template 1691 NXDLL_EXPORT void File::readData(const std::string & dataName, uint16_t& data); 1692 template 1693 NXDLL_EXPORT void File::readData(const std::string & dataName, int32_t& data); 1694 template 1695 NXDLL_EXPORT void File::readData(const std::string & dataName, uint32_t& data); 1696 template 1697 NXDLL_EXPORT void File::readData(const std::string & dataName, int64_t& data); 1698 template 1699 NXDLL_EXPORT void File::readData(const std::string & dataName, uint64_t& data); 1497 1700 1498 1701 template -
trunk/bindings/cpp/NeXusFile.hpp
r1710 r1711 332 332 const std::vector<int>& dims); 333 333 334 335 /** Create a 1D data field with an unlimited dimension, insert the data, and close the data. 336 * 337 * \tparam NumT numeric data type of \a value 338 * \param name :: The name of the field to create. 339 * \param value :: The vector to put into the file. 340 */ 341 template <typename NumT> 342 void writeExtendibleData(const std::string& name, std::vector<NumT>& value); 343 344 /** Create a 1D data field with an unlimited dimension, insert the data, and close the data. 345 * 346 * \tparam NumT numeric data type of \a value 347 * \param name :: The name of the field to create. 348 * \param value :: The vector to put into the file. 349 * \param chunkSize :: chunk size to use when writing 350 */ 351 template <typename NumT> 352 void writeExtendibleData(const std::string& name, std::vector<NumT>& value, const int64_t chunk); 353 354 /** Create a 1D data field with an unlimited dimension, insert the data, and close the data. 355 * 356 * \tparam NumT numeric data type of \a value 357 * \param name :: The name of the field to create. 358 * \param value :: The vector to put into the file. 359 * \param dims :: The dimensions of the data. 360 * \param chunk :: chunk size to use when writing 361 */ 362 template <typename NumT> 363 void writeExtendibleData(const std::string& name, std::vector<NumT>& value, 364 std::vector<int64_t>& dims, std::vector<int64_t> & chunk); 365 366 367 /** Updates the data written into an already-created 368 * data vector. If the data was created as extendible, it will be resized. 369 * 370 * \tparam NumT numeric data type of \a value 371 * \param name :: The name of the field to create. 372 * \param value :: The vector to put into the file. 373 */ 374 template <typename NumT> 375 void writeUpdatedData(const std::string& name, std::vector<NumT>& value); 376 377 /** Updates the data written into an already-created 378 * data vector. If the data was created as extendible, it will be resized. 379 * 380 * \tparam NumT numeric data type of \a value 381 * \param name :: The name of the field to create. 382 * \param value :: The vector to put into the file. 383 * \param dims :: The dimensions of the data. 384 */ 385 template <typename NumT> 386 void writeUpdatedData(const std::string& name, std::vector<NumT>& value, 387 std::vector<int64_t>& dims); 388 334 389 /** 335 390 * \copydoc makeCompData(const std::string&, const NXnumtype, … … 581 636 void readData(const std::string & dataName, std::vector<NumT>& data); 582 637 583 /** Put data into the supplied vector. The vector does not need to 638 /** Put data into the supplied value. 639 * 640 * The named data object is opened, loaded, then closed. 641 * 642 * \param dataName :: name of the data to open. 643 * \param data :: Where to put the data. 644 * \tparam NumT numeric data type of \a data 645 */ 646 template <typename NumT> 647 void readData(const std::string & dataName, NumT & data); 648 649 /** Put data into the supplied string. The vector does not need to 584 650 * be the correct size, just the correct type as it is resized to 585 651 * the appropriate value. … … 589 655 * @param dataName :: name of the data to open. 590 656 * @param data :: Where to put the data. 591 * \tparam NumT numeric data type of \a data592 657 */ 593 658 void readData(const std::string & dataName, std::string & data); -
trunk/test/napi_test_cpp.cxx
r1596 r1711 130 130 cdims.push_back(20); 131 131 file.writeCompData("comp_data", comp_array, array_dims, NeXus::LZW, cdims); 132 133 // ---------- Test write Extendible Data -------------------------- 134 std::vector<int> data(10, 123); 135 file.makeGroup("extendible_data", "NXdata", 1); 136 file.writeExtendibleData("mydata1", data); 137 file.writeExtendibleData("mydata2", data, 1000); 138 std::vector<int64_t> dims(2); 139 dims[0] = 5; 140 dims[1] = 2; 141 std::vector<int64_t> chunk(2, 2); 142 file.writeExtendibleData("my2Ddata", data, dims, chunk); 143 file.putAttr("string_attrib", "some short string"); 144 145 // Data vector can grow 146 for (size_t i=0; i<6; i++) 147 data.push_back(456); 148 data[0]=789; 149 file.writeUpdatedData("mydata1", data); 150 151 dims[0] = 8; 152 dims[1] = 2; 153 file.writeUpdatedData("my2Ddata", data, dims); 154 155 // Data vector can also shrink! 156 data.clear(); 157 data.resize(5, 234); 158 file.writeUpdatedData("mydata2", data); 159 160 // Exit the group 161 file.closeGroup(); 162 // ---------- End Test write Extendible Data -------------------------- 132 163 133 164 // simple flush test … … 493 524 NeXus::File file(fname); 494 525 multimap<string, string> *map = file.getTypeMap(); 495 int mapsize = 2 1;526 int mapsize = 25; 496 527 // HDF4 does not have int64 capability, so resulting map is one shorter than HDF5 and XML files 497 528 if (fname == string("napi_test_cpp.hdf")) {
Note: See TracChangeset
for help on using the changeset viewer.
