File: XdmfDiff.cxx

package info (click to toggle)
xdmf 3.0%2Bgit20160803-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,388 kB
  • ctags: 36,627
  • sloc: ansic: 265,382; cpp: 162,889; python: 10,976; f90: 1,378; yacc: 687; fortran: 464; xml: 200; java: 187; lex: 125; makefile: 82; sh: 28
file content (1489 lines) | stat: -rw-r--r-- 41,618 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
261
262
263
264
265
266
267
268
269
270
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
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
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
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
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
/*******************************************************************/
/*                               XDMF                              */
/*                   eXtensible Data Model and Format              */
/*                                                                 */
/*  Id : $Id: XdmfDiff.cxx,v 1.2 2010-01-06 16:34:08 kwleiter Exp $  */
/*  Date : $Date: 2010-01-06 16:34:08 $ */
/*  Version : $Revision: 1.2 $ */
/*                                                                 */
/*  Author:                                                        */
/*     Kenneth Leiter                                              */
/*     kenneth.leiter@arl.army.mil                                 */
/*     US Army Research Laboratory                                 */
/*     Aberdeen Proving Ground, MD                                 */
/*                                                                 */
/*     Copyright @ 2009 US Army Research Laboratory                */
/*     All Rights Reserved                                         */
/*     See Copyright.txt or http://www.arl.hpc.mil/ice 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.                                       */
/*                                                                 */
/*******************************************************************/

/**
 * Determines whether two XDMF files contain equivalent data.
 *
 * Intended to be used as both a command line utility and a framework for code
 * testing purposes.
 *
 * The XdmfDiff utility can be accessed via python or executed as a compiled command line utility.
 *
 * Command Line:
 *   Write a script to access the swig wrapped diff utility
 *
 *   There are two ways to run the command line utility:
 *
 *     XdmfDiff referenceFile newFile
 *       Compares all information contained in referenceFile to newFile .  Extra grids
 *       contained in newFile that are not in referenceFile are ignored.
 *
 *     XdmfDiff referenceFile newFile settingsFile
 *       Compares information contained in referenceFile to newFile according to settings
 *       specified in the settingsFile.  All settings options are outlined below:
 *
 * Settings Options:
 *   RELATIVE_ERROR .15
 *   ABSOLUTE_ERROR 1
 *   INCLUDE_GRID grid1 grid2
 *   IGNORE_GRID grid1 grid2
 *   IGNORE_GEOMETRY
 *   IGNORE_TOPOLOGY
 *   INCLUDE_ATTRIBUTE attr1 attr2
 *   IGNORE_ATTRIBUTE attr1 attr2
 *   IGNORE_ALL_ATTRIBUTES
 *   DISPLAY_FAILURES_ONLY
 *   VERBOSE_OUTPUT
 *
 * Settings can be commented out with #
 *
 * For code testing purposes run XdmfDiff::AreEquivalent().
 */

#include "XdmfDiff.h"

#ifndef BUILD_EXE

#include <XdmfAttribute.h>
#include <XdmfGrid.h>
#include <XdmfGeometry.h>
#include <XdmfTime.h>
#include <XdmfTopology.h>

#include <cmath>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>

class XdmfDiffInternal
{
public:
  /*
   * Collects XdmfDiffEntrys for during a comparison (i.e. stores all differences
   *   between two XdmfGeometry values)
   */
  class XdmfDiffReport
  {
  public:
    /*
     * Error description for a single pair of values
     */
    class XdmfDiffEntry
    {
    public:
      XdmfDiffEntry(std::string errorDescription, XdmfInt64 loc,
          std::string refVals, std::string newVals)
      {
        description = errorDescription;
        location = loc;
        refValues = refVals;
        newValues = newVals;
      }

      ~XdmfDiffEntry()
      {
      }

      friend std::ostream &
      operator<<(std::ostream & toReturn, const XdmfDiffEntry &diffEntry)
      {
        if (diffEntry.location == -1)
        {
          toReturn << "For " << diffEntry.description << " | Expected : "
              << diffEntry.refValues << " | Got : " << diffEntry.newValues;
        }
        else
        {
          toReturn << "For " << diffEntry.description << " | At Tuple "
              << diffEntry.location << " | Expected : " << diffEntry.refValues
              << " | Got : " << diffEntry.newValues;
        }
        return toReturn;
      }

    private:
      XdmfInt64 location;
      std::string refValues;
      std::string newValues;
      std::string description;
    };

    XdmfDiffReport(std::string type)
    {
      valType = type;
    }

    ~XdmfDiffReport()
    {
    }

    void
    AddError(std::string errorDescription, std::string refVals,
        std::string newVals)
    {
      this->AddError(errorDescription, -1, refVals, newVals);
    }

    void
    AddError(std::string errorDescription, XdmfInt64 loc, std::string refVals,
        std::string newVals)
    {
      errors.push_back(XdmfDiffEntry(errorDescription, loc, refVals, newVals));
    }

    void
    AddError(std::string warning)
    {
      warnings.push_back(warning);
    }

    XdmfInt64
    GetNumberOfErrors()
    {
      return errors.size() + warnings.size();
    }

    friend std::ostream &
    operator<<(std::ostream & toReturn, const XdmfDiffReport &diffReport)
    {
      toReturn << diffReport.valType << "\n";
      for (unsigned int i = 0; i < diffReport.warnings.size(); i++)
      {
        toReturn << "\t\t" << diffReport.warnings[i] << "\n";
      }
      for (unsigned int i = 0; i < diffReport.errors.size(); i++)
      {
        toReturn << "\t\t" << diffReport.errors[i] << "\n";
      }
      return toReturn;
    }

  private:
    std::vector<XdmfDiffEntry> errors;
    std::vector<std::string> warnings;
    std::string valType;
  };

  /*
   * Collects XdmfDiffReports for an entire file-wide comparison.  Provides
   *   methods for outputting the comparisons in text
   */
  class XdmfDiffReportCollection
  {
  public:
    XdmfDiffReportCollection(XdmfBoolean failuresOnly, XdmfBoolean verbose)
    {
      displayFailuresOnly = failuresOnly;
      verboseOutput = verbose;
    }

    ~XdmfDiffReportCollection()
    {
    }

    void
    AddReport(std::string gridName, XdmfDiffReport report)
    {
      reports[gridName].push_back(report);
    }

    XdmfInt64
    GetNumberOfErrors()
    {
      int numErrors = 0;
      for (std::map<std::string, std::vector<XdmfDiffReport> >::const_iterator
          iter = reports.begin(); iter != reports.end(); iter++)
      {
        for (unsigned int i = 0; i < iter->second.size(); i++)
        {
          std::vector<XdmfDiffReport> report = iter->second;
          numErrors += report[i].GetNumberOfErrors();
        }
      }
      return numErrors;
    }

    friend std::ostream &
    operator<<(std::ostream & toReturn,
        const XdmfDiffReportCollection &diffCollection)
    {
      for (std::map<std::string, std::vector<XdmfDiffReport> >::const_iterator
          iter = diffCollection.reports.begin(); iter
          != diffCollection.reports.end(); iter++)
      {
        int numGridErrors = 0;
        for (unsigned int i = 0; i < iter->second.size(); i++)
        {
          std::vector<XdmfDiffReport> report = iter->second;
          if (report[i].GetNumberOfErrors() > 0)
          {
            if (numGridErrors == 0 || diffCollection.verboseOutput)
            {
              toReturn << "|FAIL|  Grid Name: " << iter->first << "\n";
            }
            toReturn << "\t" << report[i];
            numGridErrors += report[i].GetNumberOfErrors();
          }
          else if (diffCollection.verboseOutput
              && !diffCollection.displayFailuresOnly)
          {
            toReturn << "|PASS|  Grid Name: " << iter->first;
            toReturn << "\t" << report[i];
          }
        }
        if (numGridErrors == 0 && !diffCollection.displayFailuresOnly
            && !diffCollection.verboseOutput)
        {
          toReturn << "|PASS|  Grid Name: " << iter->first << "\n";
        }
      }
      return toReturn;
    }

  private:
    std::map<std::string, std::vector<XdmfDiffReport> > reports;
    XdmfBoolean displayFailuresOnly;
    XdmfBoolean verboseOutput;
  };

  XdmfDiffInternal(XdmfConstString refFileName, XdmfConstString newFileName);
  XdmfDiffInternal(XdmfDOM * refDOM, XdmfDOM * newDOM);
  void Init();
  ~XdmfDiffInternal();
  std::string GetDiffs();
  std::string GetDiffs(XdmfConstString gridName);
  XdmfInt32 SetRelativeError(XdmfFloat64 & relativeError);
  XdmfInt32 SetAbsoluteError(XdmfFloat64 & absoluteError);
  XdmfInt32 SetDiffFileName(XdmfString name);
  XdmfString GetDiffFileName();
  XdmfBoolean AreEquivalent();
  XdmfInt32 IncludeGrid(XdmfString gridName);
  XdmfInt32 IgnoreGrid(XdmfString gridName);
  XdmfInt32 IncludeAttribute(XdmfString attributeName);
  XdmfInt32 IgnoreAttribute(XdmfString attributeName);
  XdmfInt32 ParseSettingsFile(XdmfConstString settingsFile);

  XdmfSetValueMacro(IgnoreTime, XdmfBoolean);
  XdmfGetValueMacro(IgnoreTime, XdmfBoolean);
  XdmfSetValueMacro(IgnoreGeometry, XdmfBoolean);
  XdmfGetValueMacro(IgnoreGeometry, XdmfBoolean);
  XdmfSetValueMacro(IgnoreTopology, XdmfBoolean);
  XdmfGetValueMacro(IgnoreTopology, XdmfBoolean);
  XdmfSetValueMacro(IgnoreAllAttributes, XdmfBoolean);
  XdmfGetValueMacro(IgnoreAllAttributes, XdmfBoolean);
  XdmfSetValueMacro(DisplayFailuresOnly, XdmfBoolean);
  XdmfGetValueMacro(DisplayFailuresOnly, XdmfBoolean);
  XdmfSetValueMacro(VerboseOutput, XdmfBoolean);
  XdmfGetValueMacro(VerboseOutput, XdmfBoolean);
  XdmfSetValueMacro(CreateDiffFile, XdmfBoolean);
  XdmfGetValueMacro(CreateDiffFile, XdmfBoolean);
  XdmfGetValueMacro(AbsoluteError, XdmfFloat64);
  XdmfGetValueMacro(RelativeError, XdmfFloat64);

private:

  /*
   * Returns the differences between the two XDMF files.  Compares each grid in the
   * reference file to the grid of the same name in the second file.  Stuffs the results
   * of the comparison in the error report
   *
   * @param errorReports an XdmfDiffReportCollection that collects all difference reports during the comparison
   *
   */
  void
  GetDiffs(XdmfDiffReportCollection & errorReports);

  /*
   * Returns the differences between two grids.
   *
   * @param refGrid the reference grid to compare (new grid is searched for using the reference grid's name)
   * @param errorReports an XdmfDiffReportCollection that collects all difference reports during the comparison
   *
   */
  void
  GetDiffs(XdmfGrid & refGrid, XdmfDiffReportCollection & errorReports);

  /*
   * Returns the differences in values between two XdmfGeometries
   *
   * @param refGeometry an XdmfGeometry to compare
   * @param newGeometry an XdmfGeometry to compare
   *
   * @return an XdmfDiffReport containing differences in values
   *
   */
  XdmfDiffReport
  GetGeometryDiffs(XdmfGeometry * refGeometry, XdmfGeometry * newGeometry);

  /*
   * Returns the differences in values between two XdmfTopologies
   *
   * @param refTopology an XdmfTopology to compare
   * @param newTopology an XdmfTopology to compare
   *
   * @return an XdmfDiffReport containing differences in values
   *
   */
  XdmfDiffReport
  GetTopologyDiffs(XdmfTopology * refTopology, XdmfTopology * newTopology);

  /*
   * Returns the differences in values between two XdmfAttributes
   *
   * @param refAttribute an XdmfAttribute to compare
   * @param newAttribute an XdmfAttribute to compare
   *
   * @return an XdmfDiffReport containing differences in values
   *
   */
  XdmfDiffReport
  GetAttributeDiffs(XdmfAttribute * refAttribute, XdmfAttribute * newAttribute);

  /*
   * Entry point for array comparisons ---> passes to templated private function based on number type to do actual value comparisons
   *
   * @param errorReport an XdmfDiffReport to add comparison results to
   * @param refArray an XdmfArray containing values to compare
   * @param newArray an XdmfArray containing values to compare
   * @param startIndex an index to start comparison at
   * @param numValues the number of values to compare
   * @param groupLength how many values are contained together.
   * 		  Useful for reporting changes in multiple values i.e. XYZ geometry (default: 1)
   *
   */
  XdmfArray *
  CompareValues(XdmfDiffReport & errorReport, XdmfArray * refArray,
      XdmfArray * newArray, XdmfInt64 startIndex, XdmfInt64 numValues,
      XdmfInt64 groupLength = 1);

  /*
   * Compares values between two XdmfArrays
   *
   * @param errorReport an XdmfDiffReport to add comparison results to
   * @param refArray an XdmfArray containing values to compare
   * @param newArray an XdmfArray containing values to compare
   * @param startIndex an index to start comparison at
   * @param numValues the number of values to compare
   * @param groupLength how many values are contained together.
   * 		  Useful for reporting changes in multiple values i.e. XYZ geometry (default: 1)
   *
   */
  template<class XdmfType>
    XdmfArray *
    CompareValuesPriv(XdmfDiffReport & errorReport, XdmfArray * refArray,
        XdmfArray * newArray, XdmfInt64 startIndex, XdmfInt64 numValues,
        XdmfInt64 groupLength = 1);

  std::set<std::string> includedGrids;
  std::set<std::string> ignoredGrids;
  std::set<std::string> includedAttributes;
  std::set<std::string> ignoredAttributes;
  XdmfDOM * myRefDOM;
  XdmfDOM * myNewDOM;
  XdmfFloat64 RelativeError;
  XdmfFloat64 AbsoluteError;
  XdmfBoolean IgnoreTime;
  XdmfBoolean IgnoreGeometry;
  XdmfBoolean IgnoreTopology;
  XdmfBoolean IgnoreAllAttributes;
  XdmfBoolean DisplayFailuresOnly;
  XdmfBoolean VerboseOutput;
  XdmfBoolean refDOMIsMine;
  XdmfBoolean newDOMIsMine;
  XdmfBoolean CreateDiffFile;
  XdmfGrid * diffGrid;
  XdmfElement * diffGridParent;
  std::string diffName;
  std::string diffHeavyName;
};

XdmfDiff::XdmfDiff(XdmfConstString refFileName, XdmfConstString newFileName)
{
  myInternal = new XdmfDiffInternal(refFileName, newFileName);
}

XdmfDiff::XdmfDiff(XdmfDOM * refDOM, XdmfDOM * newDOM)
{
  myInternal = new XdmfDiffInternal(refDOM, newDOM);
}

XdmfDiff::~XdmfDiff()
{
  delete myInternal;
}

std::string
XdmfDiff::GetDiffs()
{
  return myInternal->GetDiffs();
}

std::string
XdmfDiff::GetDiffs(XdmfConstString gridName)
{
  return myInternal->GetDiffs(gridName);
}

XdmfInt32
XdmfDiff::SetIgnoreTime(XdmfBoolean value)
{
  return myInternal->SetIgnoreTime(value);
}

XdmfInt32
XdmfDiff::GetIgnoreTime()
{
  return myInternal->GetIgnoreTime();
}

XdmfInt32
XdmfDiff::SetIgnoreGeometry(XdmfBoolean value)
{
  return myInternal->SetIgnoreGeometry(value);
}

XdmfInt32
XdmfDiff::GetIgnoreGeometry()
{
  return myInternal->GetIgnoreGeometry();
}

XdmfInt32
XdmfDiff::SetIgnoreTopology(XdmfBoolean value)
{
  return myInternal->SetIgnoreTopology(value);
}

XdmfInt32
XdmfDiff::GetIgnoreTopology()
{
  return myInternal->GetIgnoreTopology();
}

XdmfInt32
XdmfDiff::SetIgnoreAllAttributes(XdmfBoolean value)
{
  return myInternal->SetIgnoreAllAttributes(value);
}

XdmfInt32
XdmfDiff::GetIgnoreAllAttributes()
{
  return myInternal->GetIgnoreAllAttributes();
}

XdmfInt32
XdmfDiff::SetDisplayFailuresOnly(XdmfBoolean value)
{
  return myInternal->SetDisplayFailuresOnly(value);
}

XdmfInt32
XdmfDiff::GetDisplayFailuresOnly()
{
  return myInternal->GetDisplayFailuresOnly();
}

XdmfInt32
XdmfDiff::SetVerboseOutput(XdmfBoolean value)
{
  return myInternal->SetVerboseOutput(value);
}

XdmfInt32
XdmfDiff::GetVerboseOutput()
{
  return myInternal->GetVerboseOutput();
}

XdmfInt32
XdmfDiff::SetCreateDiffFile(XdmfBoolean value)
{
  return myInternal->SetCreateDiffFile(value);
}

XdmfInt32
XdmfDiff::GetCreateDiffFile()
{
  return myInternal->GetCreateDiffFile();
}

XdmfInt32
XdmfDiff::SetDiffFileName(XdmfString value)
{
  return myInternal->SetDiffFileName(value);
}

XdmfString
XdmfDiff::GetDiffFileName()
{
  return myInternal->GetDiffFileName();
}

XdmfInt32
XdmfDiff::SetRelativeError(XdmfFloat64 relativeError)
{
  return myInternal->SetRelativeError(relativeError);
}

XdmfFloat64
XdmfDiff::GetRelativeError()
{
  return myInternal->GetRelativeError();
}

XdmfInt32
XdmfDiff::SetAbsoluteError(XdmfFloat64 absoluteError)
{
  return myInternal->SetAbsoluteError(absoluteError);
}

XdmfFloat64
XdmfDiff::GetAbsoluteError()
{
  return myInternal->GetAbsoluteError();
}

XdmfInt32
XdmfDiff::IncludeGrid(XdmfString gridName)
{
  return myInternal->IncludeGrid(gridName);
}

XdmfInt32
XdmfDiff::IgnoreGrid(XdmfString gridName)
{
  return myInternal->IgnoreGrid(gridName);
}

XdmfInt32
XdmfDiff::IncludeAttribute(XdmfString attributeName)
{
  return myInternal->IncludeAttribute(attributeName);
}

XdmfInt32
XdmfDiff::IgnoreAttribute(XdmfString attributeName)
{
  return myInternal->IgnoreAttribute(attributeName);
}

XdmfBoolean
XdmfDiff::AreEquivalent()
{
  return myInternal->AreEquivalent();
}

XdmfInt32
XdmfDiff::ParseSettingsFile(XdmfConstString settingsFile)
{
  return myInternal->ParseSettingsFile(settingsFile);
}

XdmfDiffInternal::XdmfDiffInternal(XdmfConstString refFileName,
    XdmfConstString newFileName)
{
  myRefDOM = new XdmfDOM();
  myNewDOM = new XdmfDOM();

  std::string refstr = refFileName;
  size_t reffound = refstr.find_last_of("/\\");
  if (reffound != std::string::npos)
  {
    myRefDOM->SetWorkingDirectory(refstr.substr(0, reffound).substr().c_str());
  }

  std::string newstr = newFileName;
  size_t newfound = newstr.find_last_of("/\\");
  if (newfound != std::string::npos)
  {
    myNewDOM->SetWorkingDirectory(newstr.substr(0, newfound).substr().c_str());
  }

  myRefDOM->Parse(refFileName);
  myNewDOM->Parse(newFileName);

  refDOMIsMine = true;
  newDOMIsMine = true;

  this->Init();
}

XdmfDiffInternal::XdmfDiffInternal(XdmfDOM * refDOM, XdmfDOM * newDOM)
{
  myRefDOM = refDOM;
  myNewDOM = newDOM;

  refDOMIsMine = false;
  newDOMIsMine = false;

  this->Init();
}

void
XdmfDiffInternal::Init()
{
  RelativeError = 0;
  AbsoluteError = 0;
  IgnoreTime = false;
  IgnoreGeometry = false;
  IgnoreTopology = false;
  IgnoreAllAttributes = false;
  DisplayFailuresOnly = false;
  VerboseOutput = false;
  CreateDiffFile = false;
  diffGrid - NULL;
  diffGridParent = NULL;
  std::string path = myRefDOM->GetFileName();
  int endPath = path.find_last_of("/\\") + 1;
  int begSuffix = path.find_last_of(".");
  diffHeavyName = path.substr(endPath, begSuffix - endPath) + "-diff.h5";
  diffName = path.substr(endPath, begSuffix - endPath) + "-diff.xmf";
}

XdmfDiffInternal::~XdmfDiffInternal()
{
  if (this->refDOMIsMine)
    delete myRefDOM;
  if (this->newDOMIsMine)
    delete myNewDOM;
}

XdmfInt32
XdmfDiffInternal::SetRelativeError(XdmfFloat64 & relativeError)
{
  RelativeError = relativeError;
  AbsoluteError = 0;
  return (XDMF_SUCCESS);
}

XdmfInt32
XdmfDiffInternal::SetAbsoluteError(XdmfFloat64 & absoluteError)
{
  AbsoluteError = absoluteError;
  RelativeError = 0;
  return (XDMF_SUCCESS);
}

XdmfInt32
XdmfDiffInternal::SetDiffFileName(XdmfString name)
{
  if (name)
  {
    diffName = name;
    diffHeavyName = diffName.substr(0, diffName.find_last_of(".")) + ".h5";
    return XDMF_SUCCESS;
  }
  return XDMF_FAIL;
}

XdmfString
XdmfDiffInternal::GetDiffFileName()
{
  return (XdmfString) diffName.c_str();
}

XdmfInt32
XdmfDiffInternal::IncludeGrid(XdmfString gridName)
{
  ignoredGrids.erase(gridName);
  includedGrids.insert(gridName);
  return XDMF_SUCCESS;
}

XdmfInt32
XdmfDiffInternal::IgnoreGrid(XdmfString gridName)
{
  includedGrids.erase(gridName);
  ignoredGrids.insert(gridName);
  return XDMF_SUCCESS;
}

XdmfInt32
XdmfDiffInternal::IncludeAttribute(XdmfString attributeName)
{
  ignoredAttributes.erase(attributeName);
  includedAttributes.insert(attributeName);
  return XDMF_SUCCESS;
}

XdmfInt32
XdmfDiffInternal::IgnoreAttribute(XdmfString attributeName)
{
  includedAttributes.erase(attributeName);
  ignoredAttributes.insert(attributeName);
  return XDMF_SUCCESS;
}

std::string
XdmfDiffInternal::GetDiffs()
{
  std::stringstream toReturn;
  XdmfDiffReportCollection myErrors = XdmfDiffReportCollection(
      DisplayFailuresOnly, VerboseOutput);
  this->GetDiffs(myErrors);
  toReturn << myErrors;
  return toReturn.str();
}

std::string
XdmfDiffInternal::GetDiffs(XdmfConstString gridName)
{
  std::stringstream toReturn;
  XdmfXmlNode currDomain = myRefDOM->FindElement("Domain");
  for (int i = 0; i < myRefDOM->FindNumberOfElements("Grid", currDomain); i++)
  {
    XdmfGrid grid = XdmfGrid();
    grid.SetDOM(myRefDOM);
    grid.SetElement(myRefDOM->FindElement("Grid", i, currDomain));
    grid.Update();
    if (strcmp(grid.GetName(), gridName) == 0)
    {
      XdmfDiffInternal::XdmfDiffReportCollection errorReports =
          XdmfDiffInternal::XdmfDiffReportCollection(DisplayFailuresOnly,
              VerboseOutput);
      this->GetDiffs(errorReports);
      toReturn << errorReports;
      return toReturn.str();
    }
  }
  toReturn << "FAIL: Cannot Find Grid Named " << gridName;
  return toReturn.str();
}

void
XdmfDiffInternal::GetDiffs(
    XdmfDiffInternal::XdmfDiffReportCollection & errorReports)
{
  XdmfRoot * diffRoot;
  XdmfDomain * diffDomain;
  XdmfDOM * diffDOM;

  if (CreateDiffFile)
  {
    diffRoot = new XdmfRoot();
    diffDomain = new XdmfDomain();
    diffDOM = new XdmfDOM();

    diffRoot->SetDOM(diffDOM);
    diffRoot->Build();
    diffRoot->Insert(diffDomain);

    diffGridParent = diffDomain;
  }

  XdmfXmlNode currDomain = myRefDOM->FindElement("Domain");
  for (int i = 0; i < myRefDOM->FindNumberOfElements("Grid", currDomain); i++)
  {
    XdmfGrid grid = XdmfGrid();
    grid.SetDOM(myRefDOM);
    grid.SetElement(myRefDOM->FindElement("Grid", i, currDomain));
    grid.Update();
    //grid.Build();
    // Make sure we cleanup well
    for (int j = 0; j < grid.GetNumberOfAttributes(); j++)
    {
      grid.GetAttribute(j)->SetDeleteOnGridDelete(true);
    }
    this->GetDiffs(grid, errorReports);
  }

  if (CreateDiffFile)
  {
    diffDOM->Write(diffName.c_str());
    delete diffRoot;
    delete diffDomain;
    delete diffDOM;
  }
}

void
XdmfDiffInternal::GetDiffs(XdmfGrid & refGrid,
    XdmfDiffInternal::XdmfDiffReportCollection & errorReports)
{
  // Check for user specified grid includes / excludes
  if (includedGrids.size() != 0)
  {
    if (includedGrids.find(refGrid.GetName()) == includedGrids.end())
    {
      return;
    }
  }

  if (ignoredGrids.size() != 0)
  {
    if (ignoredGrids.find(refGrid.GetName()) != ignoredGrids.end())
    {
      return;
    }
  }

  XdmfGrid newGrid = XdmfGrid();
  newGrid.SetDOM(myNewDOM);

  std::string refPath = myRefDOM->GetPath(refGrid.GetElement());
  std::string parentPath = refPath.substr(0, refPath.find_last_of("/"));

  XdmfXmlNode newNode;
  if (refGrid.GetGridType() == XDMF_GRID_COLLECTION)
  {
    newNode = myNewDOM->FindElementByPath(refPath.c_str());
  }
  else
  {
    newNode = myNewDOM->FindElementByAttribute("Name", refGrid.GetName(), 0,
        myNewDOM->FindElementByPath(parentPath.c_str()));
  }

  if (newNode == NULL || newGrid.SetElement(newNode) != XDMF_SUCCESS)
  {
    XdmfDiffReport diffReport = XdmfDiffReport("Grid Name");
    std::stringstream warning;
    warning << "Could Not Find Grid: " << refGrid.GetName();
    diffReport.AddError(warning.str());
    errorReports.AddReport(refGrid.GetName(), diffReport);
    return;
  }
  newGrid.Update();

  XdmfDiffReport diffReport = XdmfDiffReport("Grid Type");
  if (refGrid.GetGridType() != newGrid.GetGridType())
  {
    diffReport.AddError("Grid Type", refGrid.GetGridTypeAsString(),
        newGrid.GetGridTypeAsString());
  }
  errorReports.AddReport(refGrid.GetName(), diffReport);

  if (CreateDiffFile && diffGridParent)
  {
    diffGrid = new XdmfGrid();
    diffGrid->SetGridType(refGrid.GetGridType());
    diffGrid->SetCollectionType(refGrid.GetCollectionType());
    diffGrid->SetName(refGrid.GetName());
    XdmfGeometry * geom = new XdmfGeometry();
    geom->SetLightDataLimit(0);
    geom->SetGeometryType(refGrid.GetGeometry()->GetGeometryType());
    geom->SetNumberOfPoints(refGrid.GetGeometry()->GetNumberOfPoints());
    geom->SetPoints(refGrid.GetGeometry()->GetPoints());
    geom->SetDeleteOnGridDelete(true);
    if (refGrid.GetGeometry()->GetPoints()->GetHeavyDataSetName())
    {
      std::string currHeavyName =
          refGrid.GetGeometry()->GetPoints()->GetHeavyDataSetName();
      currHeavyName = diffHeavyName + currHeavyName.substr(currHeavyName.find(
          ":/"), currHeavyName.size() - currHeavyName.find(":/"));
      geom->GetPoints()->SetHeavyDataSetName(currHeavyName.c_str());
    }
    diffGrid->SetGeometry(geom);
    XdmfTopology * top = new XdmfTopology();
    top->SetLightDataLimit(0);
    top->SetTopologyType(refGrid.GetTopology()->GetTopologyType());
    top->SetNodesPerElement(refGrid.GetTopology()->GetNodesPerElement());
    top->SetNumberOfElements(refGrid.GetTopology()->GetNumberOfElements());
    top->SetConnectivity(refGrid.GetTopology()->GetConnectivity());
    top->SetDeleteOnGridDelete(true);
    if (refGrid.GetTopology()->GetConnectivity()->GetHeavyDataSetName())
    {
      std::string currHeavyName =
          refGrid.GetTopology()->GetConnectivity()->GetHeavyDataSetName();
      currHeavyName = diffHeavyName + currHeavyName.substr(currHeavyName.find(
          ":/"), currHeavyName.size() - currHeavyName.find(":/"));
      top->GetConnectivity()->SetHeavyDataSetName(currHeavyName.c_str());
    }
    diffGrid->SetTopology(top);
    diffGridParent->Insert(diffGrid);
    diffGrid->Build();
    if (refGrid.GetTime()->GetTimeType() != XDMF_TIME_UNSET)
    {
      diffGrid->Insert(refGrid.GetTime());
    }
  }

  if (refGrid.GetGridType() == XDMF_GRID_COLLECTION)
  {
    if (newGrid.GetGridType() == XDMF_GRID_COLLECTION)
    {
      XdmfDiffReport diffReport = XdmfDiffReport("Collection Type");
      if (refGrid.GetCollectionType() != newGrid.GetCollectionType())
      {
        diffReport.AddError(0, refGrid.GetCollectionTypeAsString(),
            newGrid.GetCollectionTypeAsString());
      }
      errorReports.AddReport(refGrid.GetName(), diffReport);
    }
  }
  else
  {
    if (!IgnoreGeometry)
    {
      errorReports.AddReport(refGrid.GetName(), this->GetGeometryDiffs(
          refGrid.GetGeometry(), newGrid.GetGeometry()));
    }

    if (!IgnoreTopology)
    {
      errorReports.AddReport(refGrid.GetName(), this->GetTopologyDiffs(
          refGrid.GetTopology(), newGrid.GetTopology()));
    }

    if (!IgnoreAllAttributes)
    {
      for (int i = 0; i < refGrid.GetNumberOfAttributes(); i++)
      {
        refGrid.GetAttribute(i)->Update();
        XdmfAttribute * newAttribute = NULL;
        for (int j = 0; j < newGrid.GetNumberOfAttributes(); j++)
        {
          if (strcmp(newGrid.GetAttribute(j)->GetName(),
              refGrid.GetAttribute(i)->GetName()) == 0)
          {
            newAttribute = newGrid.GetAttribute(j);
            newAttribute->Update();
          }
        }
        if (newAttribute != NULL)
        {
          if (includedAttributes.size() != 0)
          {
            if (includedAttributes.find(refGrid.GetAttribute(i)->GetName())
                != includedAttributes.end())
            {
              errorReports.AddReport(
                  refGrid.GetName(),
                  this->GetAttributeDiffs(refGrid.GetAttribute(i), newAttribute));
            }
          }
          else
          {
            if (ignoredAttributes.size() != 0)
            {
              if (ignoredAttributes.find(refGrid.GetAttribute(i)->GetName())
                  == ignoredAttributes.end())
              {
                errorReports.AddReport(refGrid.GetName(),
                    this->GetAttributeDiffs(refGrid.GetAttribute(i),
                        newAttribute));
              }
            }
            else
            {
              errorReports.AddReport(
                  refGrid.GetName(),
                  this->GetAttributeDiffs(refGrid.GetAttribute(i), newAttribute));
            }
          }
        }
        else
        {
          std::stringstream heading;
          heading << "Attribute " << refGrid.GetAttribute(i)->GetName();
          XdmfDiffReport diffReport = XdmfDiffReport(heading.str());
          std::stringstream warning;
          warning << "Could Not Find " << "Attribute: "
              << refGrid.GetAttribute(i)->GetName();
          diffReport.AddError(warning.str());
          errorReports.AddReport(refGrid.GetName(), diffReport);
        }
      }
    }
  }

  if (!IgnoreTime)
  {
    if (refGrid.GetTime()->GetValue() != newGrid.GetTime()->GetValue())
    {
      XdmfDiffReport diffReport = XdmfDiffReport("Time");
      std::stringstream refTime;
      std::stringstream newTime;
      refTime << refGrid.GetTime()->GetValue();
      newTime << newGrid.GetTime()->GetValue();
      diffReport.AddError(0, refTime.str(), newTime.str());
      errorReports.AddReport(refGrid.GetName(), diffReport);
    }
  }

  if (CreateDiffFile && diffGridParent)
  {
    diffGrid->Build();
  }

  if (refGrid.GetNumberOfChildren() > 0)
  {
    if (CreateDiffFile && diffGridParent)
    {
      diffGridParent = diffGrid;
    }
    for (int i = 0; i < refGrid.GetNumberOfChildren(); i++)
    {
      XdmfGrid grid = XdmfGrid();
      grid.SetDOM(myRefDOM);
      grid.SetElement(refGrid.GetChild(i)->GetElement());
      grid.Update();
      this->GetDiffs(grid, errorReports);
    }
  }
}

XdmfDiffInternal::XdmfDiffReport
XdmfDiffInternal::GetGeometryDiffs(XdmfGeometry * refGeometry,
    XdmfGeometry * newGeometry)
{
  XdmfDiffReport diffReport = XdmfDiffReport("Geometry");

  if (refGeometry->GetGeometryType() != newGeometry->GetGeometryType())
  {
    diffReport.AddError("Geometry Type",
        refGeometry->GetGeometryTypeAsString(),
        newGeometry->GetGeometryTypeAsString());
  }

  switch (refGeometry->GetGeometryType())
    {
  case XDMF_GEOMETRY_XYZ:
    this->CompareValues(diffReport, refGeometry->GetPoints(),
        newGeometry->GetPoints(), 0,
        refGeometry->GetPoints()->GetNumberOfElements(), 3);
    break;
  case XDMF_GEOMETRY_XY:
    this->CompareValues(diffReport, refGeometry->GetPoints(),
        newGeometry->GetPoints(), 0,
        refGeometry->GetPoints()->GetNumberOfElements(), 2);
    break;
  default:
    this->CompareValues(diffReport, refGeometry->GetPoints(),
        newGeometry->GetPoints(), 0,
        refGeometry->GetPoints()->GetNumberOfElements());
    }

  return diffReport;
}

XdmfDiffInternal::XdmfDiffReport
XdmfDiffInternal::GetTopologyDiffs(XdmfTopology * refTopology,
    XdmfTopology * newTopology)
{
  XdmfDiffReport diffReport = XdmfDiffReport("Topology");

  if (refTopology->GetTopologyType() != newTopology->GetTopologyType())
  {
    diffReport.AddError("Topology Type",
        refTopology->GetTopologyTypeAsString(),
        newTopology->GetTopologyTypeAsString());
  }

  this->CompareValues(diffReport, refTopology->GetConnectivity(),
      newTopology->GetConnectivity(), 0, refTopology->GetNumberOfElements(),
      refTopology->GetNodesPerElement());

  return diffReport;
}

XdmfDiffInternal::XdmfDiffReport
XdmfDiffInternal::GetAttributeDiffs(XdmfAttribute * refAttribute,
    XdmfAttribute * newAttribute)
{
  std::stringstream valType;
  valType << "Attribute " << refAttribute->GetName();
  XdmfDiffReport diffReport = XdmfDiffReport(valType.str());

  int numValsPerNode = 1;
  switch (refAttribute->GetAttributeType())
    {
  case XDMF_ATTRIBUTE_TYPE_VECTOR:
    numValsPerNode = 3;
    break;
  case XDMF_ATTRIBUTE_TYPE_TENSOR6:
    numValsPerNode = 6;
    break;
  case XDMF_ATTRIBUTE_TYPE_TENSOR:
    numValsPerNode = 9;
    break;
  default:
    numValsPerNode = 1;
    break;
    }

  if (refAttribute->GetAttributeCenter() != newAttribute->GetAttributeCenter())
  {
    diffReport.AddError("Attribute Center",
        refAttribute->GetAttributeCenterAsString(),
        newAttribute->GetAttributeCenterAsString());
  }

  if (refAttribute->GetAttributeType() != newAttribute->GetAttributeType())
  {
    numValsPerNode = 1;
    diffReport.AddError("Attribute Type",
        refAttribute->GetAttributeTypeAsString(),
        newAttribute->GetAttributeTypeAsString());
  }

  XdmfArray * diffs = this->CompareValues(diffReport,
      refAttribute->GetValues(), newAttribute->GetValues(), 0,
      refAttribute->GetValues()->GetNumberOfElements(), numValsPerNode);

  if (CreateDiffFile && diffs && diffGrid)
  {
    XdmfAttribute * attr = new XdmfAttribute();
    attr->SetLightDataLimit(0);
    attr->SetName(refAttribute->GetName());
    attr->SetAttributeType(refAttribute->GetAttributeType());
    attr->SetAttributeCenter(refAttribute->GetAttributeCenter());
    attr->SetValues(diffs);
    attr->SetDeleteOnGridDelete(true);
    diffGrid->Insert(attr);
  }

  return diffReport;
}

XdmfArray *
XdmfDiffInternal::CompareValues(XdmfDiffReport & errorReport,
    XdmfArray * refArray, XdmfArray * newArray, XdmfInt64 startIndex,
    XdmfInt64 numValues, XdmfInt64 groupLength)
{
  switch (refArray->GetNumberType())
    {
  case XDMF_FLOAT64_TYPE:
    return this->CompareValuesPriv<XdmfFloat64> (errorReport, refArray,
        newArray, startIndex, numValues, groupLength);
  case XDMF_FLOAT32_TYPE:
    return this->CompareValuesPriv<XdmfFloat32> (errorReport, refArray,
        newArray, startIndex, numValues, groupLength);
  case XDMF_INT64_TYPE:
    return this->CompareValuesPriv<XdmfInt64> (errorReport, refArray, newArray,
        startIndex, numValues, groupLength);
  case XDMF_INT32_TYPE:
    return this->CompareValuesPriv<XdmfInt32> (errorReport, refArray, newArray,
        startIndex, numValues, groupLength);
  case XDMF_INT16_TYPE:
    return this->CompareValuesPriv<XdmfInt16> (errorReport, refArray, newArray,
        startIndex, numValues, groupLength);
  case XDMF_INT8_TYPE:
    return this->CompareValuesPriv<XdmfInt8> (errorReport, refArray, newArray,
        startIndex, numValues, groupLength);
  case XDMF_UINT32_TYPE:
    return this->CompareValuesPriv<XdmfUInt32> (errorReport, refArray,
        newArray, startIndex, numValues, groupLength);
  case XDMF_UINT16_TYPE:
    return this->CompareValuesPriv<XdmfUInt16> (errorReport, refArray,
        newArray, startIndex, numValues, groupLength);
  case XDMF_UINT8_TYPE:
    return this->CompareValuesPriv<XdmfUInt8> (errorReport, refArray, newArray,
        startIndex, numValues, groupLength);
  default:
    return this->CompareValuesPriv<XdmfFloat64> (errorReport, refArray,
        newArray, startIndex, numValues, groupLength);
    }
  return NULL;
}

template<class XdmfType>
  XdmfArray *
  XdmfDiffInternal::CompareValuesPriv(XdmfDiffReport & errorReport,
      XdmfArray * refArray, XdmfArray * newArray, XdmfInt64 startIndex,
      XdmfInt64 numValues, XdmfInt64 groupLength)
  {

    if (groupLength < 1)
    {
      return NULL;
    }

    if (refArray->GetNumberOfElements() != newArray->GetNumberOfElements())
    {
      std::stringstream refArrayElem;
      std::stringstream newArrayElem;
      refArrayElem << refArray->GetNumberOfElements();
      newArrayElem << newArray->GetNumberOfElements();
      errorReport.AddError("Number of Elements", refArrayElem.str(),
          newArrayElem.str());
    }

    if (strcmp(refArray->GetShapeAsString(), newArray->GetShapeAsString()) != 0)
    {
      errorReport.AddError("Shape", refArray->GetShapeAsString(),
          newArray->GetShapeAsString());
    }

    if (refArray->GetNumberType() != newArray->GetNumberType())
    {
      errorReport.AddError("Number Type", refArray->GetNumberTypeAsString(),
          newArray->GetNumberTypeAsString());
    }

    XdmfType * refVals = (XdmfType*) refArray->GetDataPointer(startIndex);
    XdmfType * newVals = (XdmfType*) newArray->GetDataPointer(startIndex);

    XdmfArray * toReturn = new XdmfArray();
    if (refArray->GetHeavyDataSetName())
    {
      std::string currHeavyName = refArray->GetHeavyDataSetName();
      currHeavyName = diffHeavyName + currHeavyName.substr(currHeavyName.find(
          ":/"), currHeavyName.size() - currHeavyName.find(":/"));
      toReturn->SetHeavyDataSetName(currHeavyName.c_str());
    }
    toReturn->SetNumberType(refArray->GetNumberType());
    toReturn->SetNumberOfElements(refArray->GetNumberOfElements());
    XdmfType * toReturnArray = (XdmfType*) toReturn->GetDataPointer(startIndex);

    for (int i = 0; i < numValues; i++)
    {
      double acceptableError = fabs(AbsoluteError);
      if (acceptableError == 0)
      {
        acceptableError = fabs(refVals[startIndex + i] * RelativeError);
      }
      XdmfType diff = newVals[startIndex + i] - refVals[startIndex + i];
      toReturnArray[startIndex + i] = diff;
      if (fabs((float) diff) > acceptableError)
      {
        XdmfInt64 groupIndex = (int) ((startIndex + i) / groupLength);
        std::stringstream refValsReturn;
        std::stringstream newValsReturn;
        for (int j = 0; j < groupLength; j++)
        {
          refValsReturn << refVals[startIndex + i + j];
          newValsReturn << newVals[startIndex + i + j];
          if (j > 0)
          {
            toReturnArray[startIndex + i + j] = newVals[startIndex + i + j]
                - refVals[startIndex + i + j];
          }
          if (j + 1 < groupLength)
          {
            refValsReturn << ", ";
            newValsReturn << ", ";
          }
        }
        errorReport.AddError("Values", groupIndex, refValsReturn.str(),
            newValsReturn.str());
        i = startIndex + i + groupLength - 1;
      }
    }
    return toReturn;
  }

XdmfBoolean
XdmfDiffInternal::AreEquivalent()
{
  XdmfDiffReportCollection myErrors = XdmfDiffReportCollection(
      DisplayFailuresOnly, VerboseOutput);
  this->GetDiffs(myErrors);
  if (myErrors.GetNumberOfErrors() == 0)
  {
    return true;
  }
  return false;
}

/**
 *
 * Parses a file containing settings for the comparison.  Settings are outlined at the top
 * of this file.  Commented lines starting with '#' are ignored.
 *
 * @param settingsFile the path to the settings file
 *
 */

XdmfInt32
XdmfDiffInternal::ParseSettingsFile(XdmfConstString settingsFile)
{
  std::string str;
  ifstream ifs(settingsFile, ifstream::in);
  while (std::getline(ifs, str))
  {
    if (str != "")
    {
      std::string buf;
      std::stringstream ss(str);

      std::vector<std::string> tokens;
      while (ss >> buf)
      {
        tokens.push_back(buf);
      }

      if (tokens[0].compare("RELATIVE_ERROR") == 0)
      {
        std::istringstream stm;
        stm.str(tokens[1]);
        double d;
        stm >> d;
        this->SetRelativeError(d);
      }

      if (tokens[0].compare("ABSOLUTE_ERROR") == 0)
      {
        std::istringstream stm;
        stm.str(tokens[1]);
        double d;
        stm >> d;
        this->SetAbsoluteError(d);
      }

      if (tokens[0].compare("INCLUDE_GRID") == 0)
      {
        for (unsigned int i = 1; i < tokens.size(); i++)
        {
          includedGrids.insert(tokens[i]);
        }
      }

      if (tokens[0].compare("IGNORE_GRID") == 0)
      {
        for (unsigned int i = 1; i < tokens.size(); i++)
        {
          ignoredGrids.insert(tokens[i]);
        }
      }

      if (tokens[0].compare("IGNORE_TIME") == 0)
      {
        this->SetIgnoreTime(true);
      }

      if (tokens[0].compare("IGNORE_GEOMETRY") == 0)
      {
        this->SetIgnoreGeometry(true);
      }

      if (tokens[0].compare("IGNORE_TOPOLOGY") == 0)
      {
        this->SetIgnoreTopology(true);
      }

      if (tokens[0].compare("INCLUDE_ATTRIBUTE") == 0)
      {
        for (unsigned int i = 1; i < tokens.size(); i++)
        {
          includedAttributes.insert(tokens[i]);
        }
      }

      if (tokens[0].compare("IGNORE_ATTRIBUTE") == 0)
      {
        for (unsigned int i = 1; i < tokens.size(); i++)
        {
          ignoredAttributes.insert(tokens[i]);
        }
      }

      if (tokens[0].compare("IGNORE_ALL_ATTRIBUTES") == 0)
      {
        this->SetIgnoreAllAttributes(true);
      }

      if (tokens[0].compare("DISPLAY_FAILURES_ONLY") == 0)
      {
        this->SetDisplayFailuresOnly(true);
      }

      if (tokens[0].compare("VERBOSE_OUTPUT") == 0)
      {
        this->SetVerboseOutput(true);
      }
    }
  }
  ifs.close();
  return XDMF_SUCCESS;
}

#else

/**
 * Entry point for command line utility
 *
 */
int
main(int argc, char* argv[])
{

  XdmfDiff * diffFramework;

  std::string usage = "Compares Xdmf files for equality: \n \n Usage: \n \n   XdmfDiff <path-to-reference-xdmf-file> <path-to-xdmf-file> (Optional: <path-to-settings-file>)";

  if (argc < 3)
  {
    cout << usage << endl;
    return 1;
  }

  if (argc >= 3)
  {
    FILE * refFile = fopen(argv[1], "r");
    if (refFile)
    {
      // Success
      fclose(refFile);
    }
    else
    {
      cout << "Cannot open: " << argv[1] << endl;
      return 1;
    }

    FILE * newFile = fopen(argv[2], "r");
    if (newFile)
    {
      // Success
      fclose(newFile);
    }
    else
    {
      cout << "Cannot open: " << argv[2] << endl;
      return 1;
    }

    diffFramework = new XdmfDiff(argv[1], argv[2]);

    if (argc >= 4)
    {
      FILE * defFile = fopen(argv[3], "r");
      if (defFile)
      {
        // Success
        fclose(defFile);
      }
      else
      {
        cout << "Cannot open: " << argv[3] << endl;
        delete diffFramework;
        return 1;
      }
      diffFramework->ParseSettingsFile(argv[3]);
    }
  }

  //diffFramework.SetCreateDiffFile(true);
  std::string output = diffFramework->GetDiffs();
  cout << output << endl;
  delete diffFramework;
  return 0;
}

#endif // BUILD_EXE