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 "Print out min and max values in one or more nrrds" |
28 |
|
|
static const char *_unrrdu_minmaxInfoL = |
29 |
|
|
(INFO ". Unlike other commands, this doesn't produce a nrrd. It only " |
30 |
|
|
"prints to standard out the min and max values found in the input nrrd(s), " |
31 |
|
|
"and it also indicates if there are non-existent values.\n " |
32 |
|
|
"* Uses nrrdRangeNewSet"); |
33 |
|
|
|
34 |
|
|
int |
35 |
|
|
unrrdu_minmaxDoit(const char *me, char *inS, int blind8BitRange, FILE *fout) { |
36 |
|
|
Nrrd *nrrd; |
37 |
|
|
NrrdRange *range; |
38 |
|
|
airArray *mop; |
39 |
|
|
|
40 |
|
|
mop = airMopNew(); |
41 |
|
|
airMopAdd(mop, nrrd=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); |
42 |
|
|
if (nrrdLoad(nrrd, inS, NULL)) { |
43 |
|
|
biffMovef(me, NRRD, "%s: trouble loading \"%s\"", me, inS); |
44 |
|
|
airMopError(mop); return 1; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
range = nrrdRangeNewSet(nrrd, blind8BitRange); |
48 |
|
|
airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); |
49 |
|
|
airSinglePrintf(fout, NULL, "min: %.17g\n", range->min); |
50 |
|
|
airSinglePrintf(fout, NULL, "max: %.17g\n", range->max); |
51 |
|
|
if (range->min == range->max) { |
52 |
|
|
if (0 == range->min) { |
53 |
|
|
fprintf(fout, "# min == max == 0.0 exactly\n"); |
54 |
|
|
} else { |
55 |
|
|
fprintf(fout, "# min == max\n"); |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
if (range->hasNonExist) { |
59 |
|
|
fprintf(fout, "# has non-existent values\n"); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
airMopOkay(mop); |
63 |
|
|
return 0; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
int |
67 |
|
|
unrrdu_minmaxMain(int argc, const char **argv, const char *me, |
68 |
|
|
hestParm *hparm) { |
69 |
|
2 |
hestOpt *opt = NULL; |
70 |
|
1 |
char *err, **inS; |
71 |
|
|
airArray *mop; |
72 |
|
1 |
int pret, blind8BitRange; |
73 |
|
1 |
unsigned int ni, ninLen; |
74 |
|
|
#define B8DEF "false" |
75 |
|
|
|
76 |
|
1 |
mop = airMopNew(); |
77 |
|
1 |
hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange, |
78 |
|
|
B8DEF, /* NOTE: not using nrrdStateBlind8BitRange here |
79 |
|
|
for consistency with previous behavior */ |
80 |
|
|
"whether to blindly assert the range of 8-bit data, " |
81 |
|
|
"without actually going through the data values, i.e. " |
82 |
|
|
"uchar is always [0,255], signed char is [-128,127]. " |
83 |
|
|
"Note that even if you do not use this option, the default " |
84 |
|
|
"(" B8DEF ") is potentialy over-riding the effect of " |
85 |
|
|
"environment variable NRRD_STATE_BLIND_8_BIT_RANGE; " |
86 |
|
|
"see \"unu env\""); |
87 |
|
1 |
hestOptAdd(&opt, NULL, "nin1", airTypeString, 1, -1, &inS, NULL, |
88 |
|
|
"input nrrd(s)", &ninLen); |
89 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
90 |
|
|
|
91 |
✓✗ |
2 |
USAGE(_unrrdu_minmaxInfoL); |
92 |
|
|
PARSE(); |
93 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
94 |
|
|
|
95 |
|
|
for (ni=0; ni<ninLen; ni++) { |
96 |
|
|
if (ninLen > 1) { |
97 |
|
|
fprintf(stdout, "==> %s <==\n", inS[ni]); |
98 |
|
|
} |
99 |
|
|
if (unrrdu_minmaxDoit(me, inS[ni], blind8BitRange, stdout)) { |
100 |
|
|
airMopAdd(mop, err = biffGetDone(me), airFree, airMopAlways); |
101 |
|
|
fprintf(stderr, "%s: trouble with \"%s\":\n%s", |
102 |
|
|
me, inS[ni], err); |
103 |
|
|
/* continue working on the remaining files */ |
104 |
|
|
} |
105 |
|
|
if (ninLen > 1 && ni < ninLen-1) { |
106 |
|
|
fprintf(stdout, "\n"); |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
airMopOkay(mop); |
111 |
|
|
return 0; |
112 |
|
1 |
} |
113 |
|
|
|
114 |
|
|
UNRRDU_CMD(minmax, INFO); |