XdmfHDF5Writer.cpp 67.8 KB
Newer Older
Kenneth Leiter's avatar
Kenneth Leiter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfHDF5Writer.cpp                                                  */
/*                                                                           */
/*  Author:                                                                  */
/*     Kenneth Leiter                                                        */
/*     kenneth.leiter@arl.army.mil                                           */
/*     US Army Research Laboratory                                           */
/*     Aberdeen Proving Ground, MD                                           */
/*                                                                           */
/*     Copyright @ 2011 US Army Research Laboratory                          */
/*     All Rights Reserved                                                   */
/*     See Copyright.txt for details                                         */
/*                                                                           */
/*     This software is distributed WITHOUT ANY WARRANTY; without            */
/*     even the implied warranty of MERCHANTABILITY or FITNESS               */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice             */
/*     for more information.                                                 */
/*                                                                           */
/*****************************************************************************/
23

24
#include <hdf5.h>
25
#include <sstream>
26
#include <cstdio>
27
#include <cmath>
28
#include <set>
29
#include <list>
30
#include "XdmfItem.hpp"
31
#include "XdmfArray.hpp"
32
#include "XdmfArrayType.hpp"
33
#include "XdmfError.hpp"
34
#include "XdmfHDF5Controller.hpp"
35
#include "XdmfHDF5Writer.hpp"
36

37 38 39 40 41 42
namespace {

  const static unsigned int DEFAULT_CHUNK_SIZE = 0;

}

43 44 45 46 47 48 49 50
/**
 * PIMPL
 */
class XdmfHDF5Writer::XdmfHDF5WriterImpl {

public:

  XdmfHDF5WriterImpl():
51
    mHDF5Handle(-1),
52
    mChunkSize(DEFAULT_CHUNK_SIZE),
53
    mOpenFile(""),
54 55 56
    mHDF5FileSizeLimit(-1),
    mDepth(0),
    mFileIndex(0)
57 58 59 60 61 62 63 64 65 66 67 68
  {
  };

  ~XdmfHDF5WriterImpl()
  {
    closeFile();
  };

  void
  closeFile()
  {
    if(mHDF5Handle >= 0) {
69
      /*herr_t status =*/H5Fclose(mHDF5Handle);
70 71
      mHDF5Handle = -1;
    }
72
    mOpenFile = "";
73 74
  };  

75 76 77
  int
  openFile(const std::string & filePath,
           const int fapl)
78 79 80 81 82 83 84 85 86 87 88 89
  {
    if(mHDF5Handle >= 0) {
      // Perhaps we should throw a warning.
      closeFile();
    }

    // Save old error handler and turn off error handling for now
    H5E_auto_t old_func;
    void * old_client_data;
    H5Eget_auto(0, &old_func, &old_client_data);
    H5Eset_auto2(0, NULL, NULL);
  
90
    int toReturn = 0;
91

92 93
    mOpenFile.assign(filePath);

94 95 96 97
    if(H5Fis_hdf5(filePath.c_str()) > 0) {
      mHDF5Handle = H5Fopen(filePath.c_str(), 
                            H5F_ACC_RDWR, 
                            fapl);
98
      hsize_t numObjects;
99 100
      /*herr_t status = */H5Gget_num_objs(mHDF5Handle,
                                          &numObjects);
101
      toReturn = numObjects;
102 103 104 105 106 107 108 109 110 111 112
    }
    else {
      mHDF5Handle = H5Fcreate(filePath.c_str(),
                              H5F_ACC_TRUNC,
                              H5P_DEFAULT,
                              fapl);
    }

    // Restore previous error handler
    H5Eset_auto2(0, old_func, old_client_data);

113 114
    return toReturn;

115 116 117
  }

  hid_t mHDF5Handle;
118
  unsigned int mChunkSize;
119
  std::string mOpenFile;
120 121 122 123
  int mHDF5FileSizeLimit;
  int mFileIndex;
  int mDepth;
  std::set<const XdmfItem *> mWrittenItems;
124 125

};
126

127
shared_ptr<XdmfHDF5Writer>
128 129
XdmfHDF5Writer::New(const std::string & filePath,
                    const bool clobberFile)
130
{
131 132 133
  if(clobberFile) {
    std::remove(filePath.c_str());
  }
134
  shared_ptr<XdmfHDF5Writer> p(new XdmfHDF5Writer(filePath));
135
  return p;
136 137
}

138
XdmfHDF5Writer::XdmfHDF5Writer(const std::string & filePath) :
139 140
  XdmfHeavyDataWriter(filePath),
  mImpl(new XdmfHDF5WriterImpl())
141 142 143 144 145
{
}

XdmfHDF5Writer::~XdmfHDF5Writer()
{
146
  delete mImpl;
147 148
}

149
shared_ptr<XdmfHDF5Controller>
150 151
XdmfHDF5Writer::createHDF5Controller(const std::string & hdf5FilePath,
                                     const std::string & dataSetPath,
152
                                     const shared_ptr<const XdmfArrayType> type,
153 154
                                     const std::vector<unsigned int> & start,
                                     const std::vector<unsigned int> & stride,
155 156
                                     const std::vector<unsigned int> & dimensions,
                                     const std::vector<unsigned int> & dataspaceDimensions)
157
{
158 159 160 161 162
  return XdmfHDF5Controller::New(hdf5FilePath,
                                 dataSetPath,
                                 type,
                                 start,
                                 stride,
163 164
                                 dimensions,
                                 dataspaceDimensions);
165 166
}

167 168 169 170 171 172 173 174 175 176 177 178 179

void
XdmfHDF5Writer::setFileSizeLimit(int newSize)
{
  mImpl->mHDF5FileSizeLimit = newSize;
}

int
XdmfHDF5Writer::getFileSizeLimit()
{
  return mImpl->mHDF5FileSizeLimit;
}

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
void
XdmfHDF5Writer::setFileIndex(int newSize)
{
  mImpl->mFileIndex = newSize;
}

int
XdmfHDF5Writer::getFileIndex()
{
  return mImpl->mFileIndex;
}

unsigned int
XdmfHDF5Writer::getChunkSize() const
{
  return mImpl->mChunkSize;
}

198 199 200 201 202 203 204 205 206
void 
XdmfHDF5Writer::closeFile()
{
  mImpl->closeFile();
}

void 
XdmfHDF5Writer::openFile()
{
207 208 209 210 211 212 213 214
  this->openFile(H5P_DEFAULT);
}

void
XdmfHDF5Writer::openFile(const int fapl)
{
  mDataSetId = mImpl->openFile(mFilePath,
                               fapl);
215 216
}

217 218 219 220 221 222
void
XdmfHDF5Writer::setChunkSize(const unsigned int chunkSize)
{
  mImpl->mChunkSize = chunkSize;
}

223 224
void
XdmfHDF5Writer::visit(XdmfArray & array,
225
                      const shared_ptr<XdmfBaseVisitor> visitor)
226
{
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
  mImpl->mDepth++;
  std::set<const XdmfItem *>::iterator checkWritten = mImpl->mWrittenItems.find(&array);
  if (checkWritten == mImpl->mWrittenItems.end() || array.getItemTag() == "DataItem") {
    //if it has children send the writer to them too.
    array.traverse(visitor);
    //only do this if the object has not already been written
    this->write(array, H5P_DEFAULT);
    mImpl->mWrittenItems.insert(&array);

  }
  //if the object has already been written, just end, it already has the data
  mImpl->mDepth--;
  if(mImpl->mDepth <= 0) {
    mImpl->mWrittenItems.clear();
  }
}

void
XdmfHDF5Writer::visit(XdmfItem & item,
                      const shared_ptr<XdmfBaseVisitor> visitor)
{
  mImpl->mDepth++;
  //This is similar to the algorithm for writing XPaths
  //shouldn't be a problem if XPaths are turned off because all this does is avoid writing an object twice
  //if it was written once then all instances of the object should have the ocntroller
  std::set<const XdmfItem *>::iterator checkWritten = mImpl->mWrittenItems.find(&item);
  if (checkWritten == mImpl->mWrittenItems.end()) {
    mImpl->mWrittenItems.insert(&item);
    item.traverse(visitor);
  }
  mImpl->mDepth--;
  if(mImpl->mDepth <= 0) {
    mImpl->mWrittenItems.clear();
  }
261 262
}

263

264 265 266
void
XdmfHDF5Writer::write(XdmfArray & array,
                      const int fapl)
267
{
268
	printf("write started\n");
269
  hid_t datatype = -1;
270
  bool closeDatatype = false;
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299

  if(array.isInitialized()) {
    if(array.getArrayType() == XdmfArrayType::Int8()) {
      datatype = H5T_NATIVE_CHAR;
    }
    else if(array.getArrayType() == XdmfArrayType::Int16()) {
      datatype = H5T_NATIVE_SHORT;
    }
    else if(array.getArrayType() == XdmfArrayType::Int32()) {
      datatype = H5T_NATIVE_INT;
    }
    else if(array.getArrayType() == XdmfArrayType::Int64()) {
      datatype = H5T_NATIVE_LONG;
    }
    else if(array.getArrayType() == XdmfArrayType::Float32()) {
      datatype = H5T_NATIVE_FLOAT;
    }
    else if(array.getArrayType() == XdmfArrayType::Float64()) {
      datatype = H5T_NATIVE_DOUBLE;
    }
    else if(array.getArrayType() == XdmfArrayType::UInt8()) {
      datatype = H5T_NATIVE_UCHAR;
    }
    else if(array.getArrayType() == XdmfArrayType::UInt16()) {
      datatype = H5T_NATIVE_USHORT;
    }
    else if(array.getArrayType() == XdmfArrayType::UInt32()) {
      datatype = H5T_NATIVE_UINT;
    }
300 301 302 303 304
    else if(array.getArrayType() == XdmfArrayType::String()) {
      datatype = H5Tcopy(H5T_C_S1);
      H5Tset_size(datatype, H5T_VARIABLE);
      closeDatatype = true;
    }
305
    else {
306 307 308
      XdmfError::message(XdmfError::FATAL,
                         "Array of unsupported type in "
                         "XdmfHDF5Writer::write");
309 310 311
    }
  }

312 313
  herr_t status;

314 315
  if(datatype != -1) {
    std::string hdf5FilePath = mFilePath;
316

317 318 319 320 321 322 323 324 325 326 327 328 329
    size_t extIndex;
    std::string checkFileName;
    std::string checkFileExt;
    extIndex = hdf5FilePath.find_last_of(".");
    if (extIndex == std::string::npos) {
      checkFileName = hdf5FilePath;
      checkFileExt = "";
    }
    else {
      checkFileName = hdf5FilePath.substr(0, extIndex);
      checkFileExt = hdf5FilePath.substr(extIndex+1);
    }

330 331
    std::stringstream dataSetPath;

332 333 334 335
    std::vector<shared_ptr<XdmfHeavyDataController> > previousControllers;

    for(int i = 0; i < array.getNumberHeavyDataControllers(); i++) {
      previousControllers.push_back(array.getHeavyDataController(i));
336
    }
337 338 339

    //remove controllers from the array, they will be replaced by the controllers created by this function.
    while(array.getNumberHeavyDataControllers() != 0) {
340
      array.removeHeavyDataController(array.getNumberHeavyDataControllers() -1);
341 342 343
    }


344 345 346 347 348 349 350 351 352 353 354 355

    if (previousControllers.size() == 0) {
      //create a temporary controller if the array doesn't have one
      shared_ptr<XdmfHDF5Controller> tempDataController =
        this->createHDF5Controller(hdf5FilePath,
                                   "Data",
                                   array.getArrayType(),
                                   std::vector<unsigned int>(1, 0),
                                   std::vector<unsigned int>(1, 1),
                                   std::vector<unsigned int>(1, array.getSize()),
                                   std::vector<unsigned int>(1, array.getSize()));
      previousControllers.push_back(tempDataController);
356
    }
357

358
    int controllerIndexOffset = 0;
359

360 361 362 363 364 365 366 367
    for(int i = 0; i < previousControllers.size(); i++)// it is assumed that the array will have at least one controller
    {
      if (mMode == Append) {//append only cares about the last controller, so add the rest back in
	for (; i < previousControllers.size() - 1; i++) {
          array.insert(previousControllers[i]);
	}
      }

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
      std::list<std::string> filesWritten;
      std::list<shared_ptr<XdmfArray> > arraysWritten;
      std::list<std::vector<unsigned int> > startsWritten;
      std::list<std::vector<unsigned int> > stridesWritten;
      std::list<std::vector<unsigned int> > dimensionsWritten;
      std::list<std::vector<unsigned int> > dataSizesWritten;

      // Open a hdf5 dataset and write to it on disk.
      hsize_t size = array.getSize();

      // Save old error handler and turn off error handling for now
      H5E_auto_t old_func;
      void * old_client_data;
      H5Eget_auto(0, &old_func, &old_client_data);
      H5Eset_auto2(0, NULL, NULL);

      bool startedloop = false;
      unsigned int origFileIndex = mImpl->mFileIndex;
      while ((mMode == Hyperslab && i < previousControllers.size()) || !startedloop){




      startedloop = true;

393 394 395
      shared_ptr<XdmfHeavyDataController> heavyDataController =
        previousControllers[i];
      //stats for the data currently stored in the array
396
      const std::vector<unsigned int> & dimensions = heavyDataController->getDimensions();
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
      std::vector<unsigned int> dataspaceDimensions = dimensions;
      std::vector<unsigned int> start(dimensions.size(), 0);
      std::vector<unsigned int> stride(dimensions.size(), 1);

      if((mMode == Overwrite || mMode == Append || mMode == Hyperslab)
        && heavyDataController) {

        // Write to the previous dataset
        dataSetPath.str(std::string());
        dataSetPath << heavyDataController->getDataSetPath();
        hdf5FilePath = heavyDataController->getFilePath();
        if(mMode == Hyperslab) {//start, stride, and dataspace dimensions only matter for hyperslab mode
          dataspaceDimensions = heavyDataController->getDataspaceDimensions();
          start = heavyDataController->getStart();
          stride = heavyDataController->getStride();
        }
      }
      else {
415
        dataSetPath.str(std::string());
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
        dataSetPath << "Data" << mDataSetId;
      }

      //check here for if the file would become larger than the limit after the addition.
      //then check subsequent files for the same limitation
      //currently assuming that at least one dimension will be written per file.
      //probably for append and default	
      //no need to check for overwrite the data is already alloted
      //  might need to check after all as overwrite might expand data size.
      //might need to check for hyperslab, if the data wasn't alloted yet.

      bool splittingPossible = false;
      //check if splitting is necessary
      if (mMode == Overwrite) {//might need a split if data written is larger than data alotted
        splittingPossible = true;
      }
      if (mMode == Default) {//new data set is created with each call
        splittingPossible = true;
      }
      if (mMode == Append) {//data is added onto end of sets
        splittingPossible = true;
      }
      if (mMode == Hyperslab) {//splitting is only required if the slab is not set up yet
        //check if slab already exists
        int numData = mImpl->openFile(hdf5FilePath,
                                      fapl);
        if (numData > 0) {//if it already exists the file does not need to be split.
          splittingPossible = false;
        }
        else {
          splittingPossible = true;
        }
      }

      //this is the file splitting algorithm
      if (mImpl->mHDF5FileSizeLimit > 0 && splittingPossible) {//only if the file limit is positive, disabled if 0 or negative
        //repeat until a suitable file is found
        bool suitableFound = false;
        unsigned int currentDimension = 0;
        unsigned int previousDimension = currentDimension;
        unsigned int previousDataSize = 0;
457 458 459 460

	std::vector<unsigned int> previousDimensions;
        std::vector<unsigned int> previousDataSizes;
	unsigned int amountAlreadyWritten = 0;
461 462 463 464 465 466 467
        //Even though theoretically this could be an infinite loop
        //if all possible files with the specified name are produced
        //the chances of that happening are small.
        //It can handle up to 65535 different files.
        //This value may vary depending on the compiler and platform.
        //The variable UINT_MAX holds the value in question.
        //If all files are take up it will loop until a file opens up since adding past the max causes overflow.
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
	

	unsigned int containedInController = 1;
	for (int j = 0; j < dataspaceDimensions.size(); j++)
	{
		containedInController *= dataspaceDimensions[j];
	}
        while (amountAlreadyWritten < containedInController) {


		std::vector<unsigned int> partialStarts;
		std::vector<unsigned int> partialStrides;
		std::vector<unsigned int> partialDimensions;
		std::vector<unsigned int> partialDataSizes;

483 484 485 486 487 488 489 490 491 492 493

          std::stringstream testFile;
          if (mImpl->mFileIndex == 0) {//if sequentially named files need to be created or referenced
            testFile << checkFileName << "." << checkFileExt;
          }
          else {
            testFile << checkFileName << mImpl->mFileIndex << "." << checkFileExt;
          }
          int sizeOffset = 0;
          FILE *checkFile = NULL;
          int fileSize = 0;//if the file doesn't exist the size is 0 because there's no data
494 495
          // get the file stream
          checkFile = fopen(testFile.str().c_str(), "a");
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
          if (checkFile != NULL) {
            // set the file pointer to end of file
            fseek(checkFile, 0, SEEK_END);
            // get the file size, in bytes
            fileSize = ftell(checkFile);

            //if overwrite subtract previous data size.
            if (mMode == Overwrite) {
              //find previous data size
              mImpl->openFile(testFile.str(),
                              fapl);
              hid_t checkset = H5Dopen(mImpl->mHDF5Handle,
                                       dataSetPath.str().c_str(),
                                       H5P_DEFAULT);
              hid_t checkspace = H5S_ALL;
              checkspace = H5Dget_space(checkset);
              hssize_t checksize = H5Sget_simple_extent_npoints(checkspace);
              status = H5Dclose(checkset);
              if(checkspace != H5S_ALL) {
                status = H5Sclose(checkspace);
              }
              fileSize = fileSize - checksize;//remove previous set's size, since it's overwritten
              if (fileSize < 0) {
                fileSize = 0;
              }
            }
            fclose(checkFile);
          }
          else if (previousDataSize == 0) {
            sizeOffset += 800;//base size of an hdf5 file is 800
          }
          // close stream and release buffer
          //check size to see if it's within range
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140

if (closeDatatype == true) //closetype is only true if strings are being used, it's set at the beginning when types are checked.
{

	//size needed is equal to the dataspaceDimensions if in hyperslab mode
	//otherwise is equal to the size of the written array
	unsigned int remainingValues = 0;
	unsigned int sizeArrayIndex = 0;
	if (mMode == Hyperslab)
	{
		remainingValues += 1;
		sizeArrayIndex += 1;
		for (int j = 0; j < dataspaceDimensions[j]; j++)
		{
			remainingValues *= dataspaceDimensions[j];
			sizeArrayIndex *= dimensions[j];
		}
	}
	else
	{
		remainingValues += array.getSize();
		sizeArrayIndex = amountAlreadyWritten;
	}
	remainingValues -= amountAlreadyWritten;//reduce by number of values already written
	if (remainingValues == 0)//end if no remaining values
	{
		break;
	}
	//if remaining size is less than available space, just write all of what's left
	//calculate remaining size
	unsigned int remainingSize = 0;
	for (int j = sizeArrayIndex; j < array.getSize(); j++)
	{
		remainingSize += array.getValue<std::string>(j).size() * 8;
	}

	if (mMode == Hyperslab)
	{
		//size is estimated based on averages
		remainingSize = (remainingSize / (array.getSize() - sizeArrayIndex)) * remainingValues;
	}

	if (remainingSize + previousDataSize + fileSize < mImpl->mHDF5FileSizeLimit*(1024*1024))
	{
		//if the array hasn't been split
		if (amountAlreadyWritten == 0)
		{
			//just pass all data to the partial vectors
			for (int j = 0; j < dimensions.size(); j++)//done using a loop so that data is copied, not referenced
			{
				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				partialDimensions.push_back(dimensions[j]);
				partialDataSizes.push_back(dataspaceDimensions[j]);
			}
		}
		else//if the array has been split
		{
			int dimensionIndex = previousDimensions.size() - 1;

			//loop previous dimensions in
			int j = 0;
			for (j = 0; j < dimensionIndex; j++)
			{
				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				partialDimensions.push_back(dimensions[j]);
				partialDataSizes.push_back(dataspaceDimensions[j]);
			}
		
			if (mMode == Hyperslab)
			{
				int newStart = (start[j] + stride[j] * previousDimensions[j]) - dataspaceDimensions[j];
				while (newStart < 0)
				{
					newStart += stride[j];
				}
				partialStarts.push_back(newStart);
				//stride should not change in this algorithm
				partialStrides.push_back(stride[j]);
				//total up number of blocks for the higher dimesions and subtract the amount already written

				unsigned int dimensiontotal = dimensions[j];
				unsigned int dataspacetotal = dataspaceDimensions[j];
				for (int k = j + 1; k < dimensions.size(); k++)
				{
					dimensiontotal *= dimensions[k];
					dataspacetotal *= dataspaceDimensions[k];
				}
				if (previousDimensions.size() > 0)
				{
					partialDimensions.push_back(dimensiontotal-previousDimensions[j]);
				}
				else
				{
					partialDimensions.push_back(dimensiontotal);
				}
				if (previousDataSizes.size() > 0)
				{
					partialDataSizes.push_back(dataspacetotal-previousDataSizes[j]);
				}
				else
				{
					partialDataSizes.push_back(dataspacetotal);
				}
			}
			else
			{
				//start and stride are not used outside of hyperslab
				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				//total up number of blocks for the higher dimesions and subtract the amount already written
				//since it isn't hyperslab dimensions and dataspacedimensions should be the same

				unsigned int dimensiontotal = dimensions[j];

				for (int k = j + 1; k < dimensions.size(); k++)
				{
					dimensiontotal *= dimensions[k];
				}

				if (previousDimensions.size() > 0)
				{
					partialDimensions.push_back(dimensiontotal-previousDimensions[j]);
				}
				else
				{
					partialDimensions.push_back(dimensiontotal);
				}
				if (previousDataSizes.size() > 0)
				{
					partialDataSizes.push_back(dimensiontotal-previousDataSizes[j]);
				}
				else
				{
					partialDataSizes.push_back(dimensiontotal);
				}
			}
		}
	}
	else//otherwise, take remaining size and start removing dimensions until the dimension block is less, then take a fraction of the dimension
	{
		//calculate the number of values of the data type you're using will fit
		unsigned int usableSpace = (mImpl->mHDF5FileSizeLimit*(1024*1024) - (previousDataSize + fileSize));
		//if the array hasn't been split
		if (amountAlreadyWritten == 0)
		{
			//see if it will fit in the next file
			//if it will just go to the next file
			//otherwise split it.
			if (remainingSize + 800 > mImpl->mHDF5FileSizeLimit*(1024*1024))
			{
				//figure out the size of the largest block that will fit.
				unsigned int blockSizeSubtotal = 0;
				unsigned int dimensionSizeTotal = 1;
				int dimensionIndex = 0;
				//find the dimension that was split
				while (dimensionIndex < dataspaceDimensions.size() && blockSizeSubtotal <= usableSpace)
				{
					//this is totally different for strings
					dimensionSizeTotal *= dimensions[dimensionIndex];
					blockSizeSubtotal = 0;
					for (int k = 0; k < dimensionSizeTotal; k++)
					{
						if (amountAlreadyWritten + k > array.getSize())
						{
							XdmfError::message(XdmfError::FATAL,
		                                                           "Error: Invalid Dimension in HDF5 Write.\n");
						}
						blockSizeSubtotal += array.getValue<std::string>(amountAlreadyWritten + k).size();
					}
					dimensionIndex++;
				}//It should end on the "blockSizeSubtotal <= usableSpace" statement, the other half is for backup
				//move back one dimension so we're working on the dimension that was split, not the one after it
				dimensionIndex--;
				blockSizeSubtotal /= dataspaceDimensions[dimensionIndex];

				//determine how many of those blocks will fit
				unsigned int numBlocks = usableSpace / blockSizeSubtotal;//this should be less than the current value for the dimension
				//add dimensions as required.

				int j = 0;
				for (; j < dimensionIndex; j++)
				{
					partialStarts.push_back(start[j]);
					partialStrides.push_back(stride[j]);
					partialDimensions.push_back(dimensions[j]);
					partialDataSizes.push_back(dataspaceDimensions[j]);
				}

				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				partialDataSizes.push_back(numBlocks);
				if (dimensions[j] == dataspaceDimensions[j])//this is for non-hyperslab and specific cases of hyperslab
				{
					partialDimensions.push_back(numBlocks);
				}
				else
				{//for hyperslab in general
					//determine how many values from the array will fit into the blocks being used with the dimensions specified
					unsigned int displacement = (numBlocks - start[j]) / stride[j];
					if (dimensions[j] <= displacement)//if there are less values than there are space for, just write all of them.
					{
						partialDimensions.push_back(dimensions[j]);
					}
					else//otherwise write what space allows for
					{
						partialDimensions.push_back(displacement);
					}
				}
			}
		}
		else//if the array has been split
		{//This case should not come up often as it requires truly gigantic data sets
			//see if the remaining data will fit in the next file
			//if yes, skip to it
			//if no, split
			if (remainingSize + 800 > mImpl->mHDF5FileSizeLimit*(1024*1024))
			{
				//figure out the size of the largest block that will fit.
				unsigned int blockSizeSubtotal = 0;
				unsigned int tempTotal = 0;
				unsigned int dimensionSizeTotal = 1;
				int dimensionIndex = 0;
				//find the dimension that was split
				while (dimensionIndex < dataspaceDimensions.size() && blockSizeSubtotal <= usableSpace)
				{
					//this is totally different for strings
					dimensionSizeTotal *= dimensions[dimensionIndex];
					tempTotal = blockSizeSubtotal;
					blockSizeSubtotal = 0;
					for (int k = 0; k < dimensionSizeTotal; k++)
					{
						if (amountAlreadyWritten + k > array.getSize())
						{
							XdmfError::message(XdmfError::FATAL,
		                                                           "Error: Invalid Dimension in HDF5 Write.\n");
						}
						blockSizeSubtotal += array.getValue<std::string>(amountAlreadyWritten + k).size();
					}
					dimensionIndex++;
				}//It should end on the "blockSizeSubtotal <= usableSpace" statement, the other half is for backup
				//move back one dimension so we're working on the dimension that was split, not the one after it
				dimensionIndex--;
				blockSizeSubtotal = tempTotal;


                                int j = 0;
                                for (; j < dimensionIndex; j++)
                                {
                                        partialStarts.push_back(start[j]);
                                        partialStrides.push_back(stride[j]);
                                        partialDimensions.push_back(dimensions[j]);
                                        partialDataSizes.push_back(dataspaceDimensions[j]);
                                }

				//continue if the block is smaller than the available size
				if (blockSizeSubtotal <=usableSpace)
				{
					//find number of blocks that will fit
					unsigned int previousNumBlocks = amountAlreadyWritten / blockSizeSubtotal;
					//this should be less than the current value for the dimension
					unsigned int numBlocks = usableSpace / blockSizeSubtotal;
					//add dimensions to the partial vectors
					if (mMode == Hyperslab)
					{
						int newStart = (start[j] + stride[j] * previousDimensions[j]) - previousDataSizes[j];
						while (newStart < 0)
						{
							newStart += stride[j];
						}
						partialStarts.push_back(newStart);
						//stride should not change in this algorithm
						partialStrides.push_back(stride[j]);
						partialDataSizes.push_back(numBlocks);
						//determine how many values from the array will fit into the blocks being used
						//with the dimensions specified
						unsigned int displacement = (numBlocks - newStart) / stride[j];
						if ((dimensions[j] - previousDimensions[j]) <= displacement)
						{//if there are less values than there are space for, just write all of them.
							partialDimensions.push_back(dimensions[j] - previousDimensions[j]);
						}
						else//otherwise write what space allows for
						{
							partialDimensions.push_back(displacement);
						}
					}
					else
					{
						//start and stride are only specified in hyperslab
						partialStarts.push_back(start[j]);
						partialStrides.push_back(stride[j]);
						partialDataSizes.push_back(numBlocks);
						partialDimensions.push_back(numBlocks);
					}
					//place dimensions into previous dimensions for later iterations
				}
				else
				{//if this is larger than usable space, try the next file
					//if moving to next file, just do nothing and pass out of the if statement
					//but also check if specified file size is too small
					if (mImpl->mHDF5FileSizeLimit*(1024*1024) < blockSizeSubtotal)
					{//this shouldn't ever trigger, but it's good to cover ourselves
						//and throw an error if the block size won't work
						XdmfError::message(XdmfError::FATAL,
	               		                      "Error: Dimension Block size / Maximum File size mismatch.\n");
					}
				}
			}
		}
		//move to next file
		mImpl->mFileIndex++;
		previousDataSize = 0;
	}
}
else
{

	//if needed split the written array into smaller arrays based on dimension blocks
	//working with strings has a more resource intensive version of this algorithm

	//size needed is equal to the dataspaceDimensions if in hyperslab mode
	//otherwise is equal to the size of the written array
	unsigned int remainingValues = 0;

	if (mMode == Hyperslab)
	{
		remainingValues += 1;
		for (int j = 0; j < dataspaceDimensions.size(); j++)
		{
			remainingValues *= dataspaceDimensions[j];
		}
	}
	else
	{
		remainingValues += 1;
		for (int j = 0; j < dimensions.size(); j++)
		{
			remainingValues *= dimensions[j];
		}
	}
	remainingValues -= amountAlreadyWritten;//reduce by number of values already written
	if (remainingValues == 0)//end if no remaining values
	{
		break;
	}

	unsigned int dataItemSize = array.getArrayType()->getElementSize();	

	//if remaining size is less than available space, just write all of what's left
	if ((remainingValues * dataItemSize) + previousDataSize + fileSize < mImpl->mHDF5FileSizeLimit*(1024*1024))
	{
		//if the array hasn't been split
		if (amountAlreadyWritten == 0)
		{
			printf("fits and not split\n");
			//just pass all data to the partial vectors
			for (int j = 0; j < dimensions.size(); j++)//done using a loop so that data is copied, not referenced
			{
				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				partialDimensions.push_back(dimensions[j]);
				partialDataSizes.push_back(dataspaceDimensions[j]);
			}
		}
		else//if the array has been split
		{
			printf("fits and split\n");
			int dimensionIndex = previousDimensions.size() - 1;

			//loop previous dimensions in
			int j = 0;
			for (j = 0; j < dimensionIndex; j++)
			{
				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				partialDimensions.push_back(dimensions[j]);
				partialDataSizes.push_back(dataspaceDimensions[j]);
			}

			if (mMode == Hyperslab)
			{
				int newStart = (start[j] + stride[j] * previousDimensions[j]) - previousDataSizes[j];
                                while (newStart < 0)
                                {
	                                newStart += stride[j];
					printf("newStart = %d\n", newStart);
                                }
                                partialStarts.push_back(newStart);

				//stride should not change in this algorithm
				partialStrides.push_back(stride[j]);
				//total up number of blocks for the higher dimesions and subtract the amount already written

				unsigned int dimensiontotal = dimensions[j];
				unsigned int dataspacetotal = dataspaceDimensions[j];

				for (int k = j + 1; k < dimensions.size(); k++)
				{
					dimensiontotal *= dimensions[k];
					dataspacetotal *= dataspaceDimensions[k];
				}
				if (previousDimensions.size() > 0)
				{
					partialDimensions.push_back(dimensiontotal-previousDimensions[j]);
				}
				else
				{
					partialDimensions.push_back(dimensiontotal);
				}
				if (previousDataSizes.size() > 0)
				{
					partialDataSizes.push_back(dataspacetotal-previousDataSizes[j]);
				}
				else
				{
					partialDataSizes.push_back(dataspacetotal);
				}
			}
			else
			{
				//start and stride are not used outside of hyperslab
				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				//total up number of blocks for the higher dimesions and subtract the amount already written
				//since it isn't hyperslab dimensions and dataspacedimensions should be the same

				unsigned int dimensiontotal = dimensions[j];

				for (int k = j + 1; k < dimensions.size(); k++)
				{
					dimensiontotal *= dimensions[k];
				}

				if (previousDimensions.size() > 0)
				{
					partialDimensions.push_back(dimensiontotal-previousDimensions[j]);
				}
				else
				{
					partialDimensions.push_back(dimensiontotal);
				}
				if (previousDataSizes.size() > 0)
				{
					partialDataSizes.push_back(dimensiontotal-previousDataSizes[j]);
				}
				else
				{
					partialDataSizes.push_back(dimensiontotal);
				}
			}
		}
	}
	else//otherwise, take remaining size and start removing dimensions until the dimension block is less, then take a fraction of the dimension
	{
		//calculate the number of values of the data type you're using will fit
		unsigned int usableSpace = (mImpl->mHDF5FileSizeLimit*(1024*1024) - (previousDataSize + fileSize)) / dataItemSize;
		//if the array hasn't been split
		if (amountAlreadyWritten == 0)
		{
			printf("doesn't fit and not split\n");
			//see if it will fit in the next file
			//if it will just go to the next file
			//otherwise split it.
			if ((remainingValues * dataItemSize) + 800 > mImpl->mHDF5FileSizeLimit*(1024*1024) && usableSpace > 0)
			{
				//figure out the size of the largest block that will fit.
				unsigned int blockSizeSubtotal = 1;
				int dimensionIndex = 0;
				//find the dimension that was split
				while (dimensionIndex < dataspaceDimensions.size() && blockSizeSubtotal <= usableSpace)
				{
					blockSizeSubtotal *= dataspaceDimensions[dimensionIndex];
					dimensionIndex++;
				}//It should end on the "blockSizeSubtotal <= arrayStartIndex" statement, the other half is for backup
				//move back one dimension so we're working on the dimension that was split, not the one after it
				dimensionIndex--;
				blockSizeSubtotal /= dataspaceDimensions[dimensionIndex];

				//determine how many of those blocks will fit
				unsigned int numBlocks = usableSpace / blockSizeSubtotal;//this should be less than the current value for the dimension
				//add dimensions as required.

				int j = 0;
				for (j = 0; j < dimensionIndex; j++)
				{
					partialStarts.push_back(start[j]);
					partialStrides.push_back(stride[j]);
					partialDimensions.push_back(dimensions[j]);
					partialDataSizes.push_back(dataspaceDimensions[j]);
				}

				partialStarts.push_back(start[j]);
				partialStrides.push_back(stride[j]);
				partialDataSizes.push_back(numBlocks);
				if (dimensions[j] == dataspaceDimensions[j])//this is for non-hyperslab and specific cases of hyperslab
				{
					partialDimensions.push_back(numBlocks);
				}
				else
				{//for hyperslab in general
					//determine how many values from the array will fit into the blocks being used with the dimensions specified
					unsigned int displacement = (numBlocks - start[j]) / stride[j];
					if (dimensions[j] <= displacement)//if there are less values than there are space for, just write all of them.
					{
						partialDimensions.push_back(dimensions[j]);
					}
					else//otherwise write what space allows for
					{
						partialDimensions.push_back(displacement);
					}
				}
			}
		}
		else//if the array has been split
		{//This case should not come up often as it requires truly gigantic data sets
			printf("doesn't fit and is split\n");
			//see if it will fit in the next file
			//if it will just go to the next file
			//otherwise split it.
			if ((remainingValues * dataItemSize) + 800 > mImpl->mHDF5FileSizeLimit*(1024*1024) && usableSpace > 0)
			{
				unsigned int blockSizeSubtotal = 1;
				int dimensionIndex = 0;
				//find the dimension that was split
				while (dimensionIndex < dataspaceDimensions.size() && blockSizeSubtotal <= amountAlreadyWritten)
				{
					blockSizeSubtotal *= dataspaceDimensions[dimensionIndex];
					dimensionIndex++;
				}//It should end on the "blockSizeSubtotal <= arrayStartIndex" statement, the other half is for backup
				//move back one dimension so we're working on the dimension that was split, not the one after it
				dimensionIndex--;
				blockSizeSubtotal /= dataspaceDimensions[dimensionIndex];

                                int j = 0;
                                for (j = 0; j < dimensionIndex; j++)
                                {
                                        partialStarts.push_back(start[j]);
                                        partialStrides.push_back(stride[j]);
                                        partialDimensions.push_back(dimensions[j]);
                                        partialDataSizes.push_back(dataspaceDimensions[j]);
                                }


				//continue if the block is smaller than the available size
				if (blockSizeSubtotal <=usableSpace)
				{
					//find number of blocks that will fit
					unsigned int previousNumBlocks = amountAlreadyWritten / blockSizeSubtotal;
					//this should be less than the current value for the dimension
					unsigned int numBlocks = usableSpace / blockSizeSubtotal;
					//add dimensions to the partial vectors
					if (mMode == Hyperslab)
					{
						int newStart = (start[j] + stride[j] * previousDimensions[j]) - previousDataSizes[j];
						while (newStart < 0)
						{
							newStart += stride[j];
							printf("newStart = %d\n", newStart);
						}
						partialStarts.push_back(newStart);
						//stride should not change in this algorithm
						partialStrides.push_back(stride[j]);
						partialDataSizes.push_back(numBlocks);
						//determine how many values from the array will fit into the blocks being used
						//with the dimensions specified
						unsigned int displacement = (numBlocks - newStart) / stride[j];
						
						if ((dimensions[j] - previousDimensions[j]) <= displacement)
						{//if there are less values than there are space for, just write all of them.
							partialDimensions.push_back(dimensions[j] - previousDimensions[j]);
						}
						else//otherwise write what space allows for
						{
							partialDimensions.push_back(displacement);
						}
					}
					else
					{
						//start and stride are only specified in hyperslab
						partialStarts.push_back(start[j]);
						partialStrides.push_back(stride[j]);
						partialDataSizes.push_back(numBlocks);
						partialDimensions.push_back(numBlocks);
					}
					//place dimensions into previous dimensions for later iterations
				}
				else
				{//if this is larger than usable space, try the next file
					//if moving to next file, just do nothing and pass out of the if statement
					//but also check if specified file size is too small
					if (mImpl->mHDF5FileSizeLimit*(1024*1024) < blockSizeSubtotal)
					{//this shouldn't ever trigger, but it's good to cover ourselves
						//and throw an error if the block size won't work
						XdmfError::message(XdmfError::FATAL,
		                                     "Error: Dimension Block size / Maximum File size mismatch.\n");
					}
				}
			}
		}
		//move to next file
		mImpl->mFileIndex++;
	}
}


if (partialDimensions.size() > 0)
{//building the array to be written
            int containedInDimensions = 1;//count moved
            for (int j = 0 ; j < partialDimensions.size(); j++)
            {
              containedInDimensions *= partialDimensions[j];
1141 1142
            }
            int containedInPriorDimensions = controllerIndexOffset;//starting index
1143 1144 1145 1146
            int startOffset = 1;
            for (int j = 0; j < previousDimensions.size(); j++)
            {
              startOffset *= previousDimensions[j];
1147
            }
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
	    if (previousDimensions.size() == 0)
            {
              startOffset = 0;
            }
            containedInPriorDimensions += startOffset;

            int dimensionTotal = 1;
            for (int j = 0; j < dimensions.size(); j++)
            {
              dimensionTotal *= dimensions[j];
1158
            }
1159 1160 1161 1162 1163
            

            if (containedInDimensions + containedInPriorDimensions == dimensionTotal)
            {
              controllerIndexOffset += dimensionTotal;
1164
            }
1165

1166 1167 1168
            shared_ptr<XdmfArray> partialArray = XdmfArray::New();
            if (datatype == H5T_NATIVE_CHAR){
              partialArray->initialize(XdmfArrayType::Int8(), 0);
1169

1170 1171 1172
              char movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1173

1174 1175 1176
            }
            else if (datatype == H5T_NATIVE_SHORT){
              partialArray->initialize(XdmfArrayType::Int16(), 0);
1177

1178 1179 1180
              short movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1181

1182 1183 1184
            }
            else if (datatype == H5T_NATIVE_INT){
              partialArray->initialize(XdmfArrayType::Int32(), 0);
1185

1186 1187 1188
              int movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1189

1190 1191 1192
            }
            else if (datatype == H5T_NATIVE_LONG){
              partialArray->initialize(XdmfArrayType::Int64(), 0);
1193

1194 1195 1196
              long movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1197

1198 1199 1200
            }
            else if (datatype == H5T_NATIVE_FLOAT){
              partialArray->initialize(XdmfArrayType::Float32(), 0);
1201

1202 1203 1204
              float movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1205

1206

1207 1208 1209
            }
            else if (datatype == H5T_NATIVE_DOUBLE){
              partialArray->initialize(XdmfArrayType::Float64(), 0);
1210

1211 1212 1213
              double movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1214

1215 1216 1217
            }
            else if (datatype == H5T_NATIVE_UCHAR){
              partialArray->initialize(XdmfArrayType::UInt8(), 0);
1218

1219 1220 1221
              unsigned char movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1222

1223 1224 1225
            }
            else if (datatype == H5T_NATIVE_USHORT){
              partialArray->initialize(XdmfArrayType::UInt16(), 0);
1226

1227 1228 1229
              unsigned short movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1230

1231 1232 1233
            }
            else if (datatype == H5T_NATIVE_UINT) {
              partialArray->initialize(XdmfArrayType::UInt32(), 0);
1234

1235 1236 1237
              unsigned int movedData [containedInDimensions];
              array.getValues(containedInPriorDimensions, movedData, containedInDimensions);
              partialArray->insert(0, movedData, containedInDimensions);
1238 1239 1240
            }
            else if (closeDatatype) {//closeDatatype is only true if strings are being used
              partialArray->initialize(XdmfArrayType::String(), 0);
1241
              for (int j = containedInPriorDimensions; j < containedInPriorDimensions + containedInDimensions; j++){
1242 1243 1244
                partialArray->pushBack(array.getValue<std::string>(j));
              }
            }
1245

1246 1247 1248 1249 1250 1251 1252

            arraysWritten.push_back(partialArray);
            filesWritten.push_back(testFile.str());
            startsWritten.push_back(partialStarts);
            stridesWritten.push_back(partialStrides);
            dimensionsWritten.push_back(partialDimensions);
            dataSizesWritten.push_back(partialDataSizes);
1253

1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331

            //for hyperslab the space is controlled by the dataspace dimensions
            //so use that since the dimensions should be equal to the dataspace dimensions in all other variations
            //total up written data space
            unsigned int writtenDataSpace = 1;
            for (int j = 0; j < partialDataSizes.size(); j++)
            {
              writtenDataSpace *= partialDataSizes[j];
            }
            amountAlreadyWritten += writtenDataSpace;


            //generate previous dimensions
            if (previousDataSizes.size() == 0)
            {
              previousDataSizes = partialDataSizes;
              previousDimensions = partialDimensions;
            }
            else
            {
              //determine if the sizes match
              //if they do, add the top values together
              //otherwise, compress the higher dimensions and then add them

              if (previousDimensions.size() == partialDimensions.size())
              {
                previousDimensions[previousDimensions.size()-1] += partialDimensions[previousDimensions.size()-1];
              }
              else if (previousDimensions.size() < partialDimensions.size())
              {
                unsigned int overflowDimensions = 1;
                for (int j = previousDimensions.size() - 1; j < partialDimensions.size(); j++)
		{
			overflowDimensions *= partialDimensions[j];
		}
		previousDimensions[previousDimensions.size()-1] += overflowDimensions;
              }
              else if (previousDimensions.size() > partialDimensions.size())
              {
                unsigned int overflowDimensions = 1;
                for (int j = partialDimensions.size() - 1; j < previousDimensions.size(); j++)
		{
			overflowDimensions *= previousDimensions[j];
		}
		previousDimensions.resize(partialDimensions.size());
		previousDimensions[partialDimensions.size()-1] = overflowDimensions;
		previousDimensions[previousDimensions.size()-1] += partialDimensions[previousDimensions.size()-1];
              }

              if (previousDataSizes.size() == partialDataSizes.size())
              {
                previousDataSizes[previousDataSizes.size()-1] += partialDataSizes[previousDataSizes.size()-1];
              }
              else if (previousDataSizes.size() < partialDataSizes.size())
              {
                unsigned int overflowDataSizes = 1;
                for (int j = previousDataSizes.size() - 1; j < partialDataSizes.size(); j++)
                {
                        overflowDataSizes *= partialDataSizes[j];
                }
                previousDataSizes[previousDataSizes.size()-1] += overflowDataSizes;
              }
              else if (previousDataSizes.size() > partialDataSizes.size())
              {
                unsigned int overflowDataSizes = 1;
                for (int j = partialDataSizes.size() - 1; j < previousDataSizes.size(); j++)
                {
                        overflowDataSizes *= previousDataSizes[j];
                }
                previousDataSizes.resize(partialDataSizes.size());
                previousDataSizes[partialDataSizes.size()-1] = overflowDataSizes;
                previousDataSizes[previousDataSizes.size()-1] += partialDataSizes[previousDataSizes.size()-1];
              }
            }
}
}

if (mMode == Append) {
1332
          //if the written filename is different write add the previous controller
1333
          if (*(filesWritten.rbegin()) != heavyDataController->getFilePath()) {
1334 1335
            //should also be different from previous controller
            if (filesWritten.size() > 1) {
1336
              if (*(filesWritten.rbegin()) != *((filesWritten.rbegin())++)) {
1337 1338 1339 1340 1341 1342 1343 1344
                array.insert(heavyDataController);
              }
            }
            else {
              array.insert(heavyDataController);
            }
          }
        }
1345 1346


1347 1348 1349 1350 1351
      }
      else {
        //otherwise work with the full array
        shared_ptr<XdmfArray> partialArray = XdmfArray::New();
	//need to copy by duplicating the contents of the array
1352 1353
	int j = controllerIndexOffset;
        int movedSize = 0;
1354 1355
        if (datatype == H5T_NATIVE_CHAR){
          partialArray->initialize(XdmfArrayType::Int8(), 0);
1356

1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          char movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1367

1368
/*
1369 1370 1371
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize() ; j++){
            partialArray->pushBack(array.getValue<char>(j));
          }
1372
*/
1373 1374 1375
        }
        else if (datatype == H5T_NATIVE_SHORT){
          partialArray->initialize(XdmfArrayType::Int16(), 0);
1376

1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          short movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1387

1388
/*
1389 1390 1391
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<short>(j));
          }
1392
*/
1393 1394 1395
        }
        else if (datatype == H5T_NATIVE_INT){
          partialArray->initialize(XdmfArrayType::Int32(), 0);
1396

1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          int movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1407

1408
/*
1409 1410 1411
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<int>(j));
          }
1412
*/
1413 1414 1415
        }
        else if (datatype == H5T_NATIVE_LONG){
          partialArray->initialize(XdmfArrayType::Int64(), 0);
1416

1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          long movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1427

1428
/*
1429 1430 1431
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<long>(j));
          }
1432
*/
1433 1434 1435
        }
        else if (datatype == H5T_NATIVE_FLOAT){
          partialArray->initialize(XdmfArrayType::Float32(), 0);
1436

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          float movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1447

1448
/*
1449 1450 1451
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<float>(j));
          }
1452
*/
1453 1454 1455
        }
        else if (datatype == H5T_NATIVE_DOUBLE){
          partialArray->initialize(XdmfArrayType::Float64(), 0);
1456

1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          double movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1467

1468
/*
1469 1470 1471
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<double>(j));
          }
1472
*/
1473 1474 1475
        }
        else if (datatype == H5T_NATIVE_UCHAR){
          partialArray->initialize(XdmfArrayType::UInt8(), 0);
1476

1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          unsigned char movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1487

1488
/*
1489 1490 1491
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<unsigned char>(j));
          }
1492
*/
1493 1494 1495
        }
        else if (datatype == H5T_NATIVE_USHORT){
          partialArray->initialize(XdmfArrayType::UInt16(), 0);
1496

1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          unsigned short movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1507

1508
/*
1509 1510 1511
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<unsigned short>(j));
          }
1512
*/
1513 1514 1515
        }
        else if (datatype == H5T_NATIVE_UINT) {
          partialArray->initialize(XdmfArrayType::UInt32(), 0);
1516

1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
          if ((array.getSize() - controllerIndexOffset) <= heavyDataController->getSize()) {
            movedSize = array.getSize() - controllerIndexOffset;
          }
          else if (heavyDataController->getSize() < (array.getSize() - controllerIndexOffset)) {
            movedSize = heavyDataController->getSize();
          }
          unsigned int movedData [movedSize];
          array.getValues(controllerIndexOffset, movedData, movedSize);
          partialArray->insert(0, movedData, movedSize);
          j+=movedSize;
1527

1528
/*
1529 1530 1531
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<unsigned int>(j));
          }
1532
*/
1533 1534 1535
        }
        else if (closeDatatype) {//closeDatatype is only true if strings are being used
          partialArray->initialize(XdmfArrayType::String(), 0);
1536
          //transfering via loop because the getValues function is not fully tested with strings
1537 1538 1539
          for (j = controllerIndexOffset; j < controllerIndexOffset + heavyDataController->getSize() && j < array.getSize(); j++){
            partialArray->pushBack(array.getValue<std::string>(j));
          }
1540

1541 1542 1543 1544
        }

	controllerIndexOffset = j;//set the offset to the point after the end of the current subset
        if (partialArray->getSize()==0) {
1545 1546
          break;
        }
1547

1548 1549 1550 1551 1552 1553 1554
        arraysWritten.push_back(partialArray);
        filesWritten.push_back(hdf5FilePath);
        //also need to push the starts and strides loaded from the HeavyDataController
        startsWritten.push_back(start);
        stridesWritten.push_back(stride);
        dimensionsWritten.push_back(dimensions);
        dataSizesWritten.push_back(dataspaceDimensions);
1555
      }
1556

1557 1558 1559 1560 1561 1562 1563 1564 1565
      if (mMode == Hyperslab)
      {
      	i++;
	mImpl->mFileIndex = origFileIndex;
      }

}


1566 1567 1568 1569 1570 1571 1572
      std::list<std::string>::iterator fileNameWalker = filesWritten.begin();
      std::list<shared_ptr<XdmfArray> >::iterator arrayWalker = arraysWritten.begin();
      std::list<std::vector<unsigned int> >::iterator startWalker = startsWritten.begin();
      std::list<std::vector<unsigned int> >::iterator strideWalker = stridesWritten.begin();
      std::list<std::vector<unsigned int> >::iterator dimensionWalker = dimensionsWritten.begin();
      std::list<std::vector<unsigned int> >::iterator dataSizeWalker = dataSizesWritten.begin();

1573

1574 1575 1576
      //loop based on the amount of blocks split from the array.
      for (int writeIndex = 0; writeIndex < arraysWritten.size(); writeIndex++) {

1577 1578 1579 1580 1581 1582 1583
        std::string curFileName = *fileNameWalker;
        shared_ptr<XdmfArray> curArray = *arrayWalker;
        std::vector<unsigned int> curStart = *startWalker;
        std::vector<unsigned int> curStride = *strideWalker;
        std::vector<unsigned int> curDimensions = *dimensionWalker;
        std::vector<unsigned int> curDataSize = *dataSizeWalker;

1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605

		printf("starts:\n");
		for (int j = 0; j< curStart.size(); j++)
                {
                        printf("Stride[%d] = %d\n", j, curStart[j]);
                }
		printf("strides:\n");
		for (int j = 0; j< curStride.size(); j++)
                {
                        printf("Stride[%d] = %d\n", j, curStride[j]);
                }
		printf("dimensions:\n");
		for (int j = 0; j< curDimensions.size(); j++)
		{
			printf("dimension[%d] = %d\n", j, curDimensions[j]);
		}
		printf("dataspace:\n");
                for (int j = 0; j< curDataSize.size(); j++)
                {
                        printf("dataspace[%d] = %d\n", j, curDataSize[j]);
                }

1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
	bool closeFile = false;
        //This is meant to open files if it isn't already opened by the write prior
        //If it wasn't open prior to writing it will be closed after writing
        if (mImpl->mOpenFile.compare(curFileName) != 0) {
          if(mImpl->mHDF5Handle < 0) {
            closeFile = true;
          }
          mImpl->openFile(curFileName,
                          fapl);
        }
1616 1617 1618 1619 1620

        hid_t dataset = H5Dopen(mImpl->mHDF5Handle,
                                dataSetPath.str().c_str(),
                                H5P_DEFAULT);

1621 1622 1623 1624 1625 1626
        //hid_t checkspace = H5S_ALL;
        //checkspace = H5Dget_space(dataset);
        //hssize_t checksize = H5Sget_simple_extent_npoints(checkspace);
        //if(checkspace != H5S_ALL) {
        //  status = H5Sclose(checkspace);
        //}
1627

1628 1629
        // if default mode find a new data set to write to (keep
        // incrementing dataSetId)
1630
        if(dataset >=0 && mMode == Default) {
1631 1632 1633 1634
          while(true) {
            dataSetPath.str(std::string());
            dataSetPath << "Data" << ++mDataSetId;
            if(!H5Lexists(mImpl->mHDF5Handle,
1635
                          dataSetPath.str().c_str(),
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
                          H5P_DEFAULT)) {
              dataset = H5Dopen(mImpl->mHDF5Handle,
                                dataSetPath.str().c_str(),
                                H5P_DEFAULT);
              break;
            }
          }
        }

        // Restore previous error handler
        H5Eset_auto2(0, old_func, old_client_data);

        hid_t dataspace = H5S_ALL;
        hid_t memspace = H5S_ALL;

1651 1652
        std::vector<hsize_t> current_dims(curDataSize.begin(),
                                          curDataSize.end());
1653

1654
        if(dataset < 0) {//if the dataset doesn't contain anything
1655

1656
          std::vector<hsize_t> maximum_dims(curDimensions.size(), H5S_UNLIMITED);
1657
          //create a new dataspace
1658
          dataspace = H5Screate_simple(current_dims.size(),
1659 1660 1661
                                       &current_dims[0],
                                       &maximum_dims[0]);
          hid_t property = H5Pcreate(H5P_DATASET_CREATE);
1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682

          const hsize_t totalDimensionsSize =
            std::accumulate(current_dims.begin(),
                            current_dims.end(),
                            1,
                            std::multiplies<hsize_t>());
          const double factor =
            std::pow(((double)mImpl->mChunkSize / totalDimensionsSize),
                     1.0 / current_dims.size());
          std::vector<hsize_t> chunk_size(current_dims.begin(),
                                          current_dims.end());
	  if (mImpl->mChunkSize > 0)
          {
            for(std::vector<hsize_t>::iterator iter = chunk_size.begin();
                iter != chunk_size.end(); ++iter) {
              *iter = (hsize_t)(*iter * factor);
              if(*iter == 0) {
                *iter = 1;
              }
            }
          }
1683 1684

          status = H5Pset_chunk(property, current_dims.size(), &chunk_size[0]);
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
          //use that dataspace to create a new dataset
          dataset = H5Dcreate(mImpl->mHDF5Handle,
                              dataSetPath.str().c_str(),
                              datatype,
                              dataspace,
                              H5P_DEFAULT,
                              property,
                              H5P_DEFAULT);
          status = H5Pclose(property);
        }

        if(mMode == Append) {
          // Need to resize dataset to fit new data

          // Get size of old dataset
          dataspace = H5Dget_space(dataset);
          hssize_t datasize = H5Sget_simple_extent_npoints(dataspace);
          status = H5Sclose(dataspace);


		//rethink this algorithm for finding the size
1706
          if (curFileName != previousControllers[i]->getFilePath()) {
1707 1708 1709 1710 1711 1712 1713
            datasize = 0;
          }
          if (dataSetPath.str() != previousControllers[i]->getDataSetPath()) {
            datasize = 0;
          }

          // Resize to fit size of old and new data.
1714
          hsize_t newSize = curArray->getSize() + datasize;
1715
          status = H5Dset_extent(dataset, &newSize);
1716
          
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
          // Select hyperslab to write to.
          memspace = H5Screate_simple(1, &size, NULL);
          dataspace = H5Dget_space(dataset);
          hsize_t dataStart = datasize;
          status = H5Sselect_hyperslab(dataspace,
                                       H5S_SELECT_SET,
                                       &dataStart,
                                       NULL,
                                       &size,
                                       NULL);
        }
        else if(mMode == Overwrite) {
          // Overwriting - dataset rank must remain the same (hdf5 constraint)
          dataspace = H5Dget_space(dataset);

          const unsigned int ndims = H5Sget_simple_extent_ndims(dataspace);
          if(ndims != current_dims.size())
            XdmfError::message(XdmfError::FATAL,                            \
                               "Data set rank different -- ndims != "
                               "current_dims.size() -- in "
                               "XdmfHDF5Writer::write");

          status = H5Dset_extent(dataset, &current_dims[0]);
          dataspace = H5Dget_space(dataset);
        }
        else if(mMode == Hyperslab) {
          // Hyperslab - dataset rank must remain the same (hdf5 constraint)
          dataspace = H5Dget_space(dataset);

          const unsigned int ndims = H5Sget_simple_extent_ndims(dataspace);
          if(ndims != current_dims.size())
            XdmfError::message(XdmfError::FATAL,                            \
                               "Data set rank different -- ndims != "
                               "current_dims.size() -- in "
                               "XdmfHDF5Writer::write");

          status = H5Dset_extent(dataset, &current_dims[0]);
          dataspace = H5Dget_space(dataset);

1756 1757 1758 1759 1760 1761 1762 1763 1764



          std::vector<hsize_t> count(curDimensions.begin(),
                                     curDimensions.end());
          std::vector<hsize_t> currStride(curStride.begin(),
                                          curStride.end());
          std::vector<hsize_t> currStart(curStart.begin(),
                                         curStart.end());
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784

          memspace = H5Screate_simple(count.size(),
                                      &(count[0]),
                                      NULL);
          status = H5Sselect_hyperslab(dataspace,
                                       H5S_SELECT_SET,
                                       &currStart[0],
                                       &currStride[0],
                                       &count[0],
                                       NULL) ;

          if(status < 0) {
            XdmfError::message(XdmfError::FATAL,
                               "H5Dset_extent returned failure in "
                               "XdmfHDF5Writer::write -- status: " + status);
          }
        }


        status = H5Dwrite(dataset,
1785
                          datatype,
1786
                          memspace,
1787
                          dataspace,
1788
                          H5P_DEFAULT,
1789 1790
                          curArray->getValuesInternal());

1791

1792 1793 1794 1795 1796
        if(status < 0) {
          XdmfError::message(XdmfError::FATAL,
                             "H5Dwrite returned failure in XdmfHDF5Writer::write "
                             "-- status: " + status);
        }
1797

1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
        if(dataspace != H5S_ALL) {
          status = H5Sclose(dataspace);
        }
        if(memspace != H5S_ALL) {
          status = H5Sclose(memspace);
        }
        status = H5Dclose(dataset);
        if(closeFile) {
          mImpl->closeFile();
        }
1808

1809 1810 1811
        if(mMode == Default) {
          ++mDataSetId;
        }
1812

1813

1814 1815 1816 1817


        // Attach a new controller to the array
        shared_ptr<XdmfHDF5Controller> newDataController =
1818
          shared_ptr<XdmfHDF5Controller>();
1819 1820 1821 1822

        unsigned int newSize;
        if(mMode == Append) {
          //find data size
1823
          mImpl->openFile(curFileName,
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845
                          fapl);
          hid_t checkset = H5Dopen(mImpl->mHDF5Handle,
                                   dataSetPath.str().c_str(),
                                   H5P_DEFAULT);
          hid_t checkspace = H5S_ALL;
          checkspace = H5Dget_space(checkset);
          newSize = H5Sget_simple_extent_npoints(checkspace);
          status = H5Dclose(checkset);
	  if(checkspace != H5S_ALL) {
	    status = H5Sclose(checkspace);
          }
 
          std::vector<unsigned int> insertStarts;
          insertStarts.push_back(0);
          std::vector<unsigned int> insertStrides;
          insertStrides.push_back(1);
          std::vector<unsigned int> insertDimensions;
          insertDimensions.push_back(newSize);
          std::vector<unsigned int> insertDataSpaceDimensions;
          insertDataSpaceDimensions.push_back(newSize);

          newDataController =
1846
            this->createHDF5Controller(curFileName,
1847
                                       dataSetPath.str(),
1848
                                       curArray->getArrayType(),
1849 1850 1851 1852 1853
                                       insertStarts,
                                       insertStrides,
                                       insertDimensions,
                                       insertDataSpaceDimensions);
        }
1854

1855 1856
        if(!newDataController) {
          newDataController =
1857
            this->createHDF5Controller(curFileName,
1858
                                       dataSetPath.str(),
1859 1860 1861 1862 1863
                                       curArray->getArrayType(),
                                       curStart,
                                       curStride,
                                       curDimensions,
                                       curDataSize);
1864
        }
1865

1866 1867
        array.insert(newDataController);

1868 1869 1870 1871 1872 1873 1874 1875
        fileNameWalker++;
        arrayWalker++;
        startWalker++;
        strideWalker++;
        dimensionWalker++;
        dataSizeWalker++;


1876
      }
1877

1878
    }
1879

1880 1881
    if(closeDatatype) {
      status = H5Tclose(datatype);
1882
    }
1883 1884 1885 1886

    if(mReleaseData) {
      array.release();
    }
1887
  }
1888
	printf("write done\n");
1889
}