GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/diff.c Lines: 16 32 50.0 %
Date: 2017-05-26 Branches: 1 18 5.6 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "unrrdu.h"
25
#include "privateUnrrdu.h"
26
27
#define INFO "Sees if two nrrds are different in any way"
28
static const char *_unrrdu_diffInfoL =
29
(INFO
30
 ". Looks through all fields to see if two given nrrds contain the "
31
 "same information. Or, array meta-data can be excluded, and comparison "
32
 "only on the data values is done with the -od flag.\n "
33
 "* Uses nrrdCompare");
34
35
int
36
unrrdu_diffMain(int argc, const char **argv, const char *me,
37
                hestParm *hparm) {
38
2
  hestOpt *opt = NULL;
39
1
  char *err;
40
  airArray *mop;
41
  int pret;
42
43
1
  Nrrd *ninA, *ninB;
44
1
  int onlyData, differ;
45
1
  double epsilon;
46
1
  char explain[AIR_STRLEN_LARGE];
47
48
1
  mop = airMopNew();
49
1
  hestOptAdd(&opt, NULL, "ninA", airTypeOther, 1, 1, &ninA, NULL,
50
             "First input nrrd.",
51
1
             NULL, NULL, nrrdHestNrrd);
52
1
  hestOptAdd(&opt, NULL, "ninB", airTypeOther, 1, 1, &ninB, NULL,
53
             "Second input nrrd.",
54
1
             NULL, NULL, nrrdHestNrrd);
55
1
  hestOptAdd(&opt, "eps,epsilon", "eps", airTypeDouble, 1, 1, &epsilon, "0.0",
56
             "threshold for allowable difference in values in "
57
             "data values");
58
1
  hestOptAdd(&opt, "od,onlydata", NULL, airTypeInt, 0, 0, &onlyData, NULL,
59
             "Compare data values only, excluding array meta-data");
60
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
61
62
2
  USAGE(_unrrdu_diffInfoL);
63
  PARSE();
64
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
65
66
  if (nrrdCompare(ninA, ninB, onlyData, epsilon, &differ, explain)) {
67
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
68
    fprintf(stderr, "%s: error doing compare:\n%s", me, err);
69
    airMopError(mop);
70
    return 1;
71
  }
72
  if (differ) {
73
    printf("%s: %s differ: %s\n", me, onlyData ? "data values" : "nrrds",
74
           explain);
75
  } else {
76
    if (0 == epsilon) {
77
      printf("%s: %s are the same\n", me, onlyData ? "data values" : "nrrds");
78
    } else {
79
      printf("%s: %s are same or within %g of each other\n", me,
80
             onlyData ? "data values" : "nrrds", epsilon);
81
    }
82
  }
83
84
  airMopOkay(mop);
85
  return 0;
86
1
}
87
88
UNRRDU_CMD(diff, INFO);