XdmfArray.cpp 52 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 : XdmfArray.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.                                                 */
/*                                                                           */
/*****************************************************************************/
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
23

24
#include <boost/tokenizer.hpp>
25
#include <boost/assign.hpp>
26
#include <limits>
27
#include <sstream>
28
#include <utility>
29 30
#include <stack>
#include <math.h>
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
31
#include "XdmfArray.hpp"
32
#include "XdmfArrayType.hpp"
33
#include "XdmfHDF5Controller.hpp"
34
#include "XdmfHeavyDataController.hpp"
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
35
#include "XdmfVisitor.hpp"
36
#include "XdmfError.hpp"
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
std::string XdmfArray::mSupportedOperations = "|#()";
const std::string XdmfArray::mValidVariableChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_:.";
const std::string XdmfArray::mValidDigitChars = "-1234567890.";
//list the priorities for the operations, based on the order of operations
//the index of the corresponding operation in validOperationChars is the same as the index of its priority in this array
int XdmfArray::mOperationPriority [8] = {2, 1, 0, 0};
//the higher the value, the earlier the operation is evaluated in the order of operations
//with the exception of parenthesis which are evaluated as soon as the closing parenthesis is found

//note, it doesn't handle overloaded functions well. Will generate errors unless overload methods are typecast.
std::map<std::string, shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >)> XdmfArray::arrayFunctions = boost::assign::map_list_of ("SUM", (shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))XdmfArray::sum) ("AVE", (shared_ptr<XdmfArray> (*)(std::vector<shared_ptr<XdmfArray> >))XdmfArray::ave);
std::map<char, shared_ptr<XdmfArray> (*)(shared_ptr<XdmfArray>, shared_ptr<XdmfArray>)> XdmfArray::operations = boost::assign::map_list_of ('|', XdmfArray::chunk) ('#', XdmfArray::interlace);



53 54 55 56 57
XDMF_CHILDREN_IMPLEMENTATION(XdmfArray,
                             XdmfHeavyDataController,
                             HeavyDataController,
                             Name)

58
class XdmfArray::Clear : public boost::static_visitor<void> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
59
public:
60

61 62 63 64 65 66
  Clear(XdmfArray * const array) :
    mArray(array)
  {
  }

  void
67
  operator()(const boost::blank & array) const
68
  {
69
    return;
70 71 72 73
  }

  template<typename T>
  void
74
  operator()(const shared_ptr<std::vector<T> > & array) const
75
  {
76
    array->clear();
77
  }
78 79 80 81 82 83 84 85 86 87

  template<typename T>
  void
  operator()(const boost::shared_array<const T> & array) const
  {
    mArray->internalizeArrayPointer();
    boost::apply_visitor(*this,
                         mArray->mArray);
  }

88
private: 
89
  XdmfArray * const mArray;
90 91
};

92
class XdmfArray::Erase : public boost::static_visitor<void> {
93 94
public:

95 96 97
  Erase(XdmfArray * const array,
        const unsigned int index) :
    mArray(array),
98 99 100
    mIndex(index)
  {
  }
101

102
  void
103
  operator()(const boost::blank & array) const
104 105 106 107
  {
    return;
  }

108 109
  template<typename T>
  void
110
  operator()(const shared_ptr<std::vector<T> > & array) const
111 112 113
  {
    array->erase(array->begin() + mIndex);
  }
114

115 116
  template<typename T>
  void
117
  operator()(const boost::shared_array<const T> & array) const
118 119 120 121 122 123
  {
    mArray->internalizeArrayPointer();
    boost::apply_visitor(*this,
                         mArray->mArray);
  }

124 125
private:

126
  XdmfArray * const mArray;
127
  const unsigned int mIndex;
128 129
};

130
class XdmfArray::GetArrayType :
131
  public boost::static_visitor<shared_ptr<const XdmfArrayType> > {
132 133
public:

134 135
  GetArrayType(const shared_ptr<XdmfHeavyDataController> & heavyDataController) :
    mHeavyDataController(heavyDataController)
136 137 138
  {
  }

139
  shared_ptr<const XdmfArrayType>
140 141 142 143 144
  getArrayType(const char * const) const
  {
    return XdmfArrayType::Int8();
  }

145
  shared_ptr<const XdmfArrayType>
146 147 148 149 150
  getArrayType(const short * const) const
  {
    return XdmfArrayType::Int16();
  }

151
  shared_ptr<const XdmfArrayType>
152 153 154 155 156
  getArrayType(const int * const) const
  {
    return XdmfArrayType::Int32();
  }

157
  shared_ptr<const XdmfArrayType>
158 159 160 161 162
  getArrayType(const long * const) const
  {
    return XdmfArrayType::Int64();
  }

163
  shared_ptr<const XdmfArrayType>
164 165 166 167 168
  getArrayType(const float * const) const
  {
    return XdmfArrayType::Float32();
  }

169
  shared_ptr<const XdmfArrayType>
170 171 172 173 174
  getArrayType(const double * const) const
  {
    return XdmfArrayType::Float64();
  }

175
  shared_ptr<const XdmfArrayType>
176 177 178 179 180
  getArrayType(const unsigned char * const) const
  {
    return XdmfArrayType::UInt8();
  }

181
  shared_ptr<const XdmfArrayType>
182 183 184 185 186
  getArrayType(const unsigned short * const) const
  {
    return XdmfArrayType::UInt16();
  }

187
  shared_ptr<const XdmfArrayType>
188 189 190 191 192
  getArrayType(const unsigned int * const) const
  {
    return XdmfArrayType::UInt32();
  }

Kenneth Leiter's avatar
Kenneth Leiter committed
193 194 195 196 197 198
  shared_ptr<const XdmfArrayType>
  getArrayType(const std::string * const) const
  {
    return XdmfArrayType::String();
  }

199
  shared_ptr<const XdmfArrayType>
200
  operator()(const boost::blank & array) const
201
  {
202 203
    if(mHeavyDataController) {
      return mHeavyDataController->getType();
204 205 206 207
    }
    return XdmfArrayType::Uninitialized();
  }

208
  template<typename T>
209 210
  shared_ptr<const XdmfArrayType>
  operator()(const shared_ptr<std::vector<T> > & array) const
211 212 213 214 215
  {
    return this->getArrayType(&(array.get()->operator[](0)));
  }

  template<typename T>
216
  shared_ptr<const XdmfArrayType>
217 218 219 220
  operator()(const boost::shared_array<const T> & array) const
  {
    return this->getArrayType(array.get());
  }
221 222 223 224

private:

  const shared_ptr<XdmfHeavyDataController> mHeavyDataController;
225 226 227 228 229
};

class XdmfArray::GetCapacity : public boost::static_visitor<unsigned int> {
public:

230 231 232
  GetCapacity()
  {
  }
233

234
  unsigned int
235
  operator()(const boost::blank & array) const
236 237 238 239
  {
    return 0;
  }

240 241
  template<typename T>
  unsigned int
242
  operator()(const shared_ptr<std::vector<T> > & array) const
243 244 245
  {
    return array->capacity();
  }
246 247 248

  template<typename T>
  unsigned int
249
  operator()(const boost::shared_array<const T> & array) const
250 251 252
  {
    return 0;
  }
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
253 254
};

255
class XdmfArray::GetValuesPointer :
256
  public boost::static_visitor<const void *> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
257 258
public:

259 260 261 262
  GetValuesPointer()
  {
  }

263
  const void *
264
  operator()(const boost::blank & array) const
265 266 267 268
  {
    return NULL;
  }

269
  template<typename T>
270
  const void *
271
  operator()(const shared_ptr<std::vector<T> > & array) const
272 273 274 275 276
  {
    return &array->operator[](0);
  }

  template<typename T>
277
  const void *
278 279 280 281
  operator()(const boost::shared_array<const T> & array) const
  {
    return array.get();
  }
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
282 283
};

284
class XdmfArray::GetValuesString : public boost::static_visitor<std::string> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
285 286
public:

287 288 289 290 291
  GetValuesString(const int arrayPointerNumValues) :
    mArrayPointerNumValues(arrayPointerNumValues)
  {
  }

292
  template<typename T, typename U>
293
  std::string
294
  getValuesString(const T * const array,
295 296
                  const int numValues) const
  {
297
    const int lastIndex = numValues - 1;
298 299 300 301 302

    if(lastIndex < 0) {
      return "";
    }

303
    std::stringstream toReturn;
304
    toReturn.precision(std::numeric_limits<U>::digits10 + 2);
305
    for(int i=0; i<lastIndex; ++i) {
306
      toReturn << (U)array[i] << " ";
307
    }
308
    toReturn << (U)array[lastIndex];
309 310 311
    return toReturn.str();
  }

312 313 314 315 316 317 318
  std::string
  getValuesString(const char * const array,
                  const int numValues) const
  {
    return getValuesString<char, int>(array, numValues);
  }

319 320 321 322
  std::string
  getValuesString(const unsigned char * const array,
                  const int numValues) const
  {
323
    return getValuesString<unsigned char, int>(array, numValues);
324 325 326 327 328 329 330
  }

  template<typename T>
  std::string
  getValuesString(const T * const array,
                  const int numValues) const
  {
331
    return getValuesString<T, T>(array, numValues);
332 333
  }

334
  std::string
335
  operator()(const boost::blank & array) const
336 337 338 339
  {
    return "";
  }

340 341
  template<typename T>
  std::string
342
  operator()(const shared_ptr<std::vector<T> > & array) const
343 344 345 346 347 348 349 350 351 352
  {
    return getValuesString(&(array->operator[](0)), array->size());
  }

  template<typename T>
  std::string
  operator()(const boost::shared_array<const T> & array) const
  {
    return getValuesString(array.get(), mArrayPointerNumValues);
  }
353 354 355

private:

356
  const unsigned int mArrayPointerNumValues;
357 358
};

359 360 361
class XdmfArray::InsertArray : public boost::static_visitor<void> {
public:

362 363
  InsertArray(XdmfArray * const array,
              const unsigned int startIndex,
364 365 366
              const unsigned int valuesStartIndex,
              const unsigned int numValues,
              const unsigned int arrayStride,
367
              const unsigned int valuesStride,
368 369 370
              std::vector<unsigned int> & dimensions,
              const shared_ptr<const XdmfArray> & arrayToCopy) :
    mArray(array),
371 372 373 374
    mStartIndex(startIndex),
    mValuesStartIndex(valuesStartIndex),
    mNumValues(numValues),
    mArrayStride(arrayStride),
375
    mValuesStride(valuesStride),
376 377
    mDimensions(dimensions),
    mArrayToCopy(arrayToCopy)
378 379 380 381
  {
  }

  void
382
  operator()(const boost::blank & array) const
383 384 385 386 387 388 389 390 391
  {
    mArray->initialize(mArrayToCopy->getArrayType());
    boost::apply_visitor(*this,
                         mArray->mArray);
  }

  template<typename T>
  void
  operator()(const shared_ptr<std::vector<T> > & array) const
392 393 394 395 396 397 398
  {
    unsigned int size = mStartIndex + mNumValues;
    if(mArrayStride > 1) {
      size = mStartIndex + mNumValues * mArrayStride - 1;
    }
    if(array->size() < size) {
      array->resize(size);
399
      mDimensions.clear();
400
    }
401 402 403 404 405 406 407 408 409 410 411 412 413 414
    mArrayToCopy->getValues(mValuesStartIndex,
                            &(array->operator[](mStartIndex)),
                            mNumValues,
                            mValuesStride,
                            mArrayStride);
  }

  template<typename T>
  void
  operator()(const boost::shared_array<const T> & array) const
  {
    mArray->internalizeArrayPointer();
    boost::apply_visitor(*this,
                         mArray->mArray);
415
  }
416 417 418

private:

419
  XdmfArray * const mArray;
420 421 422 423 424
  const unsigned int mStartIndex;
  const unsigned int mValuesStartIndex;
  const unsigned int mNumValues;
  const unsigned int mArrayStride;
  const unsigned int mValuesStride;
425
  std::vector<unsigned int> & mDimensions;
426
  const shared_ptr<const XdmfArray> mArrayToCopy;
427 428
};

429
class XdmfArray::InternalizeArrayPointer : public boost::static_visitor<void> {
430 431
public:

432 433 434 435 436
  InternalizeArrayPointer(XdmfArray * const array) :
    mArray(array)
  {
  }

437
  void
438
  operator()(const boost::blank & array) const
439 440 441 442 443 444
  {
    return;
  }

  template<typename T>
  void
445
  operator()(const shared_ptr<std::vector<T> > & array) const
446 447 448 449
  {
    return;
  }

450 451 452 453
  template<typename T>
  void
  operator()(const boost::shared_array<const T> & array) const
  {
454 455 456 457
    const T * const pointer = array.get();
    shared_ptr<std::vector<T> > newArray(new std::vector<T>(pointer,
                                                            pointer + mArray->mArrayPointerNumValues));
    mArray->mArray = newArray;
458 459
    mArray->mArrayPointerNumValues = 0;
  }
460 461 462

private:

463
  XdmfArray * const mArray;
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
464 465
};

466
class XdmfArray::Reserve : public boost::static_visitor<void> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
467 468
public:

469 470 471 472
  Reserve(XdmfArray * const array,
          const unsigned int size):
    mArray(array),
    mSize(size)
473 474 475 476
  {
  }

  void
477
  operator()(const boost::blank & array) const
478
  {
479
    mArray->mTmpReserveSize = mSize;
480
  }
481

482 483 484
  template<typename T>
  void
  operator()(shared_ptr<std::vector<T> > & array) const
485
  {
486
    array->reserve(mSize);
487
  }
488

489 490
  template<typename T>
  void
491
  operator()(const boost::shared_array<const T> & array) const
492
  {
493 494 495
    mArray->internalizeArrayPointer();
    boost::apply_visitor(*this,
                         mArray->mArray);
496
  }
497 498 499

private:

500
  XdmfArray * const mArray;
501
  const unsigned int mSize;
502 503
};

504 505 506
class XdmfArray::Size : public boost::static_visitor<unsigned int> {
public:

507 508 509 510 511 512
  Size(const XdmfArray * const array) :
    mArray(array)
  {
  }

  unsigned int
513
  operator()(const boost::blank & array) const
514
  {
515 516 517 518 519 520 521
    if(mArray->mHeavyDataControllers.size()>0) {
	int total = 0;
	for (int i = 0; i < mArray->mHeavyDataControllers.size(); i++)
	{
		total += mArray->mHeavyDataControllers[i]->getSize();
	}
      return total;//modify this to compile all controllers
522 523
    }
    return 0;
524
  }
525

526 527
  template<typename T>
  unsigned int
528
  operator()(const shared_ptr<std::vector<T> > & array) const
529 530 531
  {
    return array->size();
  }
532 533 534

  template<typename T>
  unsigned int
535
  operator()(const boost::shared_array<const T> & array) const
536 537 538 539 540 541
  {
    return mArray->mArrayPointerNumValues;
  }

private:

542
  const XdmfArray * const mArray; 
543 544
};

545
shared_ptr<XdmfArray>
546
XdmfArray::New()
547
{
548
  shared_ptr<XdmfArray> p(new XdmfArray());
549
  return p;
550 551
}

Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
552
XdmfArray::XdmfArray() :
553 554 555
  mArrayPointerNumValues(0),
  mName(""),
  mTmpReserveSize(0)
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
556 557 558 559 560 561 562
{
}

XdmfArray::~XdmfArray()
{
}

563
const std::string XdmfArray::ItemTag = "DataItem";
564

565 566
void
XdmfArray::clear()
567
{
568
  boost::apply_visitor(Clear(this), 
569 570
                       mArray);
  mDimensions.clear();
571 572
}

573 574
void
XdmfArray::erase(const unsigned int index)
575
{
576 577 578 579
  boost::apply_visitor(Erase(this,
                             index),
                       mArray);
  mDimensions.clear();
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 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 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
//This function and the functions it depends on are reimplemented in XdmfCore.i in order to properly interface with python.
//There are differences between the versions, but the overall algorithm remains mostly the same.
shared_ptr<XdmfArray>
XdmfArray::evaluateExpression(std::string expression, std::map<std::string, shared_ptr<XdmfArray> > variables)
{
	std::stack<shared_ptr<XdmfArray> > valueStack;
	std::stack<char> operationStack;

	//string is parsed left to right
	//elements of the same priority are evaluated right to left
	for (int i = 0; i < expression.size(); i++)
	{
		if (mValidDigitChars.find(expression[i]) != std::string::npos)//found to be a digit
		{
			//progress until a non-digit is found
			int valueStart = i;
			while (mValidDigitChars.find(expression[i + 1]) != std::string::npos)
			{
				i++;
			}
			//push back to the value stack
			shared_ptr<XdmfArray> valueArray = XdmfArray::New();
			valueArray->insert(0, atof(expression.substr(valueStart, i + 1 - valueStart).c_str()));//use this to convert to double
			valueStack.push(valueArray);
		}
		else if (mValidVariableChars.find(expression[i]) != std::string::npos)//found to be a variable
		{
			int valueStart = i;
			//progress until a nonvariable value is found
			while (mValidVariableChars.find(expression[i + 1]) != std::string::npos)
			{
				i++;
			}
			//convert to equivalent
			if (variables.find(expression.substr(valueStart, i + 1 - valueStart)) == variables.end())
			{
				if (arrayFunctions.find(expression.substr(valueStart, i + 1 - valueStart)) == arrayFunctions.end())
				{
					XdmfError::message(XdmfError::FATAL,
						"Error: Invalid Variable in evaluateExpression " + expression.substr(valueStart, i + 1 - valueStart));
				}
				else
				{
					std::string currentFunction = expression.substr(valueStart, i + 1 - valueStart);
					//check if next character is an open parenthesis
					if (expression[i+1] != '(')
					{
						XdmfError::message(XdmfError::FATAL,
							"Error: No values supplied to function " + expression.substr(valueStart, i + 1 - valueStart));
					}
					//if it is grab the string between paranthesis
					i = i + 2;
					valueStart = i;
					int numOpenParenthesis = 0;
					while ((expression[i] != ')' || numOpenParenthesis) && i < expression.size())
					{
						if (expression[i] == '(')
						{
							numOpenParenthesis++;
						}
						else if (expression[i] == ')')
						{
							numOpenParenthesis--;
						}
						i++;
					}
					std::string functionParameters = expression.substr(valueStart, i - valueStart);
					std::vector<shared_ptr<XdmfArray> > parameterVector;
					//split that string at commas
					size_t parameterSplit = 0;
					while (parameterSplit != std::string::npos)
					{
						parameterSplit = 0;
						parameterSplit = functionParameters.find_first_of(",", parameterSplit);
						//feed the substrings to the parse function
						if (parameterSplit == std::string::npos)
						{
							parameterVector.push_back(evaluateExpression(functionParameters, variables));
						}
						else
						{
							parameterVector.push_back(evaluateExpression(functionParameters.substr(0, parameterSplit), variables));
							functionParameters = functionParameters.substr(parameterSplit+1);
						}
					}
					valueStack.push(evaluateFunction(parameterVector, currentFunction));
				}
			}
			else
			{
				//push equivalent to value stack
				valueStack.push(variables.find(expression.substr(valueStart, i + 1 - valueStart))->second);
			}
		}
		else if (mSupportedOperations.find(expression[i]) != std::string::npos)//found to be an operation
		{
			//pop operations off the stack until one of a lower or equal importance is found
			if (operationStack.size() > 0)
			{
				if (expression[i] == ')')
				{
					//to close a parenthesis pop off all operations until another parentheis is found
					while (operationStack.size() > 0 && operationStack.top() != '(')
					{
						if (valueStack.size() < 2)//must be at least two values for this loop to work properly
						{
							XdmfError::message(XdmfError::FATAL,
								"Error: Not Enough Values in evaluateExpression");
						}
						else
						{
							shared_ptr<XdmfArray> val2 = valueStack.top();
							valueStack.pop();
							shared_ptr<XdmfArray> val1 = valueStack.top();
							valueStack.pop();
							valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
							operationStack.pop();
						}
					}
					operationStack.pop();
				}
				else if (expression[i] == '(')
				{
					//just add it if it's a start parenthesis
					//nothing happens here in that case
					//addition happens after the if statement
				}
				else
				{
					int operationLocation = getOperationPriority(expression[i]);
					int topOperationLocation = getOperationPriority(operationStack.top());
					//see order of operations to determine importance
					while (operationStack.size() > 0 && operationLocation < topOperationLocation)
					{
						if (valueStack.size() < 2)//must be at least two values for this loop to work properly
						{
							XdmfError::message(XdmfError::FATAL,
								"Error: Not Enough Values in evaluateExpression");
						}
						else
						{
							shared_ptr<XdmfArray> val2 = valueStack.top();
							valueStack.pop();
							shared_ptr<XdmfArray> val1 = valueStack.top();
							valueStack.pop();
							valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
							operationStack.pop();
							if (operationStack.size() == 0)
							{
								break;
							}
							topOperationLocation = getOperationPriority(operationStack.top());
						}
					}
				}
			}
			if (expression[i] != ')')
			{
				//add the operation to the operation stack
				operationStack.push(expression[i]);
			}
		}
		//if not a value or operation the character is ignored
	}


	//empty what's left in the stacks before finishing
	while (valueStack.size() > 1 && operationStack.size() > 0)
	{
		if (valueStack.size() < 2)//must be at least two values for this loop to work properly
		{
			XdmfError::message(XdmfError::FATAL,
				"Error: Not Enough Values in evaluateExpression");
		}
		else
		{
			if(operationStack.top() == '(')
			{
				XdmfError::message(XdmfError::WARNING,
					"Warning: Unpaired Parenthesis");
			}
			else
			{
				shared_ptr<XdmfArray> val2 = valueStack.top();
				valueStack.pop();
				shared_ptr<XdmfArray> val1 = valueStack.top();
				valueStack.pop();
				if (operationStack.size() == 0)
				{
					XdmfError::message(XdmfError::FATAL,
						"Error: Not Enough Operators in evaluateExpression");
				}
				else
				{
					valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
					operationStack.pop();
				}
			}
		}
	}

	//throw error if there's extra operations
	if (operationStack.size() > 0)
	{
		XdmfError::message(XdmfError::WARNING,
			"Warning: Left Over Operators in evaluateExpression");
	}

	if (valueStack.size() > 1)
	{
		XdmfError::message(XdmfError::WARNING,
			"Warning: Left Over Values in evaluateExpression");
	}

	return valueStack.top();
}

shared_ptr<XdmfArray>
XdmfArray::evaluateOperation(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2, char operation)
{
	if (operations.find(operation) != operations.end())
	{
		return (*(shared_ptr<XdmfArray>(*)(shared_ptr<XdmfArray>, shared_ptr<XdmfArray>))operations[operation])(val1, val2);
	}
	else
	{
		return shared_ptr<XdmfArray>();
	}
}

int
XdmfArray::addOperation(char newoperator, shared_ptr<XdmfArray>(*operationref)(shared_ptr<XdmfArray>, shared_ptr<XdmfArray>), int priority)
{
	if (newoperator == '(' || newoperator == ')')
	{
		XdmfError::message(XdmfError::FATAL,
			"Error: Parenthesis can not be redefined");
	}
	//give warning if the operation already exists
	size_t origsize = operations.size();
	operations[newoperator] = operationref;//place reference in the associated location
	if (origsize == operations.size())
	{//it's nice to let people know they're doing this so they don't get surprised about changes in behavior
		XdmfError::message(XdmfError::WARNING,
			"Warning: Function Overwritten");
		//overwrite the existing info for that operation
		//add the priority to the specified location in the priority array
		size_t priorityLocation = mSupportedOperations.find(newoperator);
		mOperationPriority[priorityLocation] = priority;
	}
	else
	{
		//create new operation
		//as long as the operation isn't a valid function character
		if (mValidVariableChars.find(newoperator) != std::string::npos || mValidDigitChars.find(newoperator) != std::string::npos)
		{
			XdmfError::message(XdmfError::FATAL,
				"Error: Operation Overlaps with Variables");
		}
		else //build the operation
		{
			//add operation to the supported character string
			mSupportedOperations.push_back(newoperator);
			int priorityArraySize = sizeof(mOperationPriority)/sizeof(int);
			if (mSupportedOperations.size()-1 > priorityArraySize)//first check to see if the priority array is large enough
			{
				//if it isn't make it bigger, double size should be fine
				int newArray [priorityArraySize*2];
				std::copy(mOperationPriority, mOperationPriority+(priorityArraySize-1), newArray);
				delete mOperationPriority;
				*mOperationPriority = *newArray;
			}
			size_t priorityLocation = mSupportedOperations.find(newoperator);
			mOperationPriority[priorityLocation] = priority;
		}
	}
	return operations.size();
}

shared_ptr<XdmfArray>
XdmfArray::chunk(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
	//join chunk (add the new array to the end of the first one)
	//joins into new array and returns it
	shared_ptr<XdmfArray> returnArray = XdmfArray::New();
	returnArray->insert(0, val1, 0, val1->getSize(),  1, 1);
	returnArray->insert(val1->getSize(), val2, 0, val2->getSize(), 1, 1);
	return returnArray;
}

shared_ptr<XdmfArray>
XdmfArray::interlace(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
	//join interlace (evenly space the second array within the first one)
	//builds a new array
	shared_ptr<XdmfArray> returnArray = XdmfArray::New();
	//resize to the combined size of both arrays
	//determining what type to class it as in order to not lose data, and to still have the smallest data type of the two
	shared_ptr<const XdmfArrayType> arrayType1 = val1->getArrayType();
	shared_ptr<const XdmfArrayType> arrayType2 = val2->getArrayType();
	if (arrayType1 == XdmfArrayType::Int8())
	{
		//if floats reclass as floats of the appropriate size
		if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints reclass as ints of the appropriate size
		else if (arrayType2 == XdmfArrayType::Int64() || arrayType2 == XdmfArrayType::UInt32())
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Int32() || arrayType2 == XdmfArrayType::UInt16())
		{
			int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Int16() || arrayType2 == XdmfArrayType::UInt8())
		{
			short sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else
		{
			char sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::Int16())
	{
		//if floats reclass as floats of the appropriate size
		if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints reclass as ints of the appropriate size
		else if (arrayType2 == XdmfArrayType::Int64() || arrayType2 == XdmfArrayType::UInt32())
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Int32() || arrayType2 == XdmfArrayType::UInt16())
		{
			int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else
		{
			short sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::Int32())
	{
		//if floats reclass as floats of the appropriate size
		if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints reclass as ints of the appropriate size
		else if (arrayType2 == XdmfArrayType::Int64() || arrayType2 == XdmfArrayType::UInt32())
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else
		{
			int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::Int64())
	{
		//if floats reclass as floats of the appropriate size
		if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints reclass as ints of the appropriate size
		else
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::Float32())
	{
		//use floats of the appropriate size
		if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::Float64())
	{
		//use floats of the appropriate size
		if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::UInt8())
	{
		//if int are used reclass as int of the larger size
		if (arrayType2 == XdmfArrayType::Int8() || arrayType2 == XdmfArrayType::Int16())
		{
			short sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Int32())
		{
			int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Int64())
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if floats are used, reclass as floats of the appropriate size
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints are used, adjust size as required
		else if (arrayType2 == XdmfArrayType::UInt8())
		{
			unsigned char sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::UInt16())
		{
			unsigned short sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::UInt32())
		{
			unsigned int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::UInt16())
	{
		//if int are used reclass as int of the larger size
		if (arrayType2 == XdmfArrayType::Int8() || arrayType2 == XdmfArrayType::Int16() || arrayType2 == XdmfArrayType::Int32())
		{
			int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Int64())
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if floats are used, reclass as floats of the appropriate size
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints are used, adjust size as required
		else if (arrayType2 == XdmfArrayType::UInt8() || arrayType2 == XdmfArrayType::UInt16())
		{
			unsigned short sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::UInt32())
		{
			unsigned int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::UInt32())
	{
		//if int are used reclass as int of the larger size
		if (arrayType2 == XdmfArrayType::Int8() || arrayType2 == XdmfArrayType::Int16() || arrayType2 == XdmfArrayType::Int32() || arrayType2 == XdmfArrayType::Int64())
		{
			long sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if floats are used, reclass as floats of the appropriate size
		else if (arrayType2 == XdmfArrayType::Float32())
		{
			float sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::Float64())
		{
			double sampleValue = 0.0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		//if uints are used, adjust size as required
		else if (arrayType2 == XdmfArrayType::UInt8() || arrayType2 == XdmfArrayType::UInt16() || arrayType2 == XdmfArrayType::UInt32())
		{
			unsigned int sampleValue = 0;
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
		else if (arrayType2 == XdmfArrayType::String())
		{
			//string is the only compatible type here
			std::string sampleValue = "";
			returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
		}
	}
	else if (arrayType1 == XdmfArrayType::String())
	{
		//string is the only compatible type here
		std::string sampleValue = "";
		returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
	}
	//determine ratio of array sizes
	int arrayRatio1 = floor(static_cast<double>(val1->getSize())/val2->getSize());
	int arrayRatio2 = floor(static_cast<double>(val2->getSize())/val1->getSize());
	if (arrayRatio1 < 1)
	{
		arrayRatio1 = 1;
	}
	if (arrayRatio2 < 1)
	{
		arrayRatio2 = 1;
	}
	//stride is equal to the ratios rounded up and added together
	int stride = arrayRatio1+arrayRatio2;
	int arrayExcess1 = 0;
	int arrayExcess2 = 0;
	for (int i = 0; i < stride; i++)
	{
		//add the values of each array, using strides to interlace and starting index to offset
		//first array gets the first value of the new array
		if (i<arrayRatio1)
		{
			int amountWritten = val1->getSize()/arrayRatio1;
			if (((amountWritten * arrayRatio1) + i) < val1->getSize())
			{
				amountWritten++;
			}
			if (amountWritten > floor(val2->getSize()/arrayRatio2))
			{
				arrayExcess1 += amountWritten - floor(val2->getSize()/arrayRatio2);
				amountWritten = floor(val2->getSize()/arrayRatio2);
			}
			returnArray->insert(i, val1, i, amountWritten, stride, arrayRatio1);
		}
		else //second array takes the rest
		{
			int amountWritten = val2->getSize()/arrayRatio2;
			if (((amountWritten * arrayRatio2) + i) < val2->getSize())
			{
				amountWritten++;
			}
			if (amountWritten > floor(val1->getSize()/arrayRatio1))
			{
				arrayExcess2 += amountWritten - floor(val1->getSize()/arrayRatio1);
				amountWritten = floor(val1->getSize()/arrayRatio1);
			}
			returnArray->insert(i, val2, i-arrayRatio1, amountWritten, stride, arrayRatio2);
		}
	}
	if (arrayExcess1 > 0)
	{
		returnArray->insert(val1->getSize()+val2->getSize()-arrayExcess1, val1, 0, arrayExcess1, 1, 1);
	}
	else if (arrayExcess2 > 0)
	{
		returnArray->insert(val1->getSize()+val2->getSize()-arrayExcess2, val2, 0, arrayExcess2, 1, 1);
	}
	returnArray->resize(val1->getSize()+val2->getSize(), 0);
	//after all inserts are done, add the excess values to the end of the array? Possibly do during the initial insert process?
	return returnArray;
}

//this is how you use references to functions
shared_ptr<XdmfArray>
XdmfArray::evaluateFunction(std::vector<shared_ptr<XdmfArray> > valueVector, std::string functionName)
{
	if (arrayFunctions.find(functionName) != arrayFunctions.end())
	{
		return (*(shared_ptr<XdmfArray>(*)(std::vector<shared_ptr<XdmfArray> >))arrayFunctions[functionName])(valueVector);
	}
	else
	{
		return shared_ptr<XdmfArray>();
	}
}

int
XdmfArray::addFunction(std::string name, shared_ptr<XdmfArray>(*functionref)(std::vector<shared_ptr<XdmfArray> >))
{
	//check to ensure that the name has valid characters
	for (int i = 0; i < name.size(); i++)
	{
		if (mValidVariableChars.find(name[i]) == std::string::npos)//if the character is not found in the list of valid characters
		{//then throw an error
			XdmfError::message(XdmfError::FATAL,
				"Error: Function Name Contains Invalid Characters");
		}
	}
	size_t origsize = arrayFunctions.size();
	arrayFunctions[name] = functionref;
	if (origsize == arrayFunctions.size())//if no new functions were added
	{//toss a warning, it's nice to let people know that they're doing this
		XdmfError::message(XdmfError::WARNING,
			"Warning: Function Overwritten");
	}
	return arrayFunctions.size();
}

shared_ptr<XdmfArray>
XdmfArray::sum(std::vector<shared_ptr<XdmfArray> > values)
{
	double total = 0.0;
	for (int i = 0; i < values.size(); i++)
	{
		for (int j = 0; j < values[i]->getSize(); j++)
		{
			total += values[i]->getValue<double>(j);
		}
	}
	shared_ptr<XdmfArray> returnArray = XdmfArray::New();
	returnArray->insert(0, total);
	return returnArray;
}

shared_ptr<XdmfArray>
XdmfArray::ave(std::vector<shared_ptr<XdmfArray> > values)
{
	double total = sum(values)->getValue<double>(0);;
	int totalSize = 0;
	for (int i = 0; i < values.size(); i++)
	{
		totalSize += values[i]->getSize();
	}
	shared_ptr<XdmfArray> returnArray = XdmfArray::New();
	returnArray->insert(0, total/totalSize);
	return returnArray;
}

1310
shared_ptr<const XdmfArrayType>
1311
XdmfArray::getArrayType() const
1312
{
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
  if (mHeavyDataControllers.size()>0)
  {
    return boost::apply_visitor(GetArrayType(mHeavyDataControllers[0]), 
                                mArray);
  }
  else
  {
    return boost::apply_visitor(GetArrayType(shared_ptr<XdmfHDF5Controller>()),
                                mArray);
  }
1323 1324
}

1325 1326
unsigned int
XdmfArray::getCapacity() const
1327
{
1328
  return boost::apply_visitor(GetCapacity(), 
1329
                              mArray);
1330 1331
}

1332 1333 1334
std::vector<unsigned int>
XdmfArray::getDimensions() const
{
1335
  if(mDimensions.size() == 0) {
1336 1337 1338
    if(!this->isInitialized() && mHeavyDataControllers.size() > 0) {
      std::vector<unsigned int> returnDimensions;
      std::vector<unsigned int> tempDimensions;
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
	//find the controller with the most dimensions
	int dimControllerIndex = 0;
	int dimSizeMax = 0;
	unsigned int dimTotal = 0;
	for (int i = 0; i < mHeavyDataControllers.size(); i++)
	{
		dimTotal += mHeavyDataControllers[i]->getSize();
		if (mHeavyDataControllers[i]->getSize() > dimSizeMax)
		{
			dimSizeMax = mHeavyDataControllers[i]->getSize();
			dimControllerIndex = i;
		}
	}
	//total up the size of the lower dimensions
	int controllerDimensionSubtotal = 1;
	for (int i = 0; i < mHeavyDataControllers[dimControllerIndex]->getDimensions().size() - 1; i++)
	{
		returnDimensions.push_back(mHeavyDataControllers[dimControllerIndex]->getDimensions()[i]);
		controllerDimensionSubtotal *= mHeavyDataControllers[dimControllerIndex]->getDimensions()[i];
	}
	//divide the total contained by the dimensions by the size of the lower dimensions
	returnDimensions.push_back(dimTotal/controllerDimensionSubtotal);
1361
      return returnDimensions;
1362
    }
1363 1364
    const unsigned int size = this->getSize();
    return std::vector<unsigned int>(1, size);
1365
  }
1366
  return mDimensions;
1367 1368
}

1369
std::string
1370
XdmfArray::getDimensionsString() const
1371
{
1372
  const std::vector<unsigned int> dimensions = this->getDimensions();
1373 1374
  return GetValuesString(dimensions.size()).getValuesString(&dimensions[0],
                                                            dimensions.size());
1375 1376
}

1377 1378
std::map<std::string, std::string>
XdmfArray::getItemProperties() const
1379
{
1380
  std::map<std::string, std::string> arrayProperties;
1381
  if(mHeavyDataControllers.size()>0) {
1382
    arrayProperties.insert(std::make_pair("Format",