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 "Write data segment of a nrrd file" |
28 |
|
|
static const char *_unrrdu_dataInfoL = |
29 |
|
|
(INFO ". The value of this is to pass the data segment in isolation to a " |
30 |
|
|
"stand-alone decoder, in case this Teem build lacks an optional " |
31 |
|
|
"data encoding required for a given nrrd file. Caveats: " |
32 |
|
|
"Will start copying characters from the datafile " |
33 |
|
|
"to output file until EOF is hit, so this won't work " |
34 |
|
|
"correctly if the datafile has extraneous content at the end. Will " |
35 |
|
|
"skip lines (as per \"line skip:\" header field) if needed, but can only " |
36 |
|
|
"skip bytes (as per \"byte skip:\") if the encoding is NOT a compression. " |
37 |
|
|
"\n \n " |
38 |
|
|
"To make vol.raw contain the uncompressed data from vol.nrrd " |
39 |
|
|
"which uses \"gz\" encoding: \"unu data vol.nrrd | gunzip > vol.raw\"\n " |
40 |
|
|
"\n " |
41 |
|
|
"* Uses nrrdLoad with nio->skipData and nio->keepNrrdDataFileOpen both " |
42 |
|
|
"true in the NrrdIoState nio."); |
43 |
|
|
|
44 |
|
|
int |
45 |
|
|
unrrdu_dataMain(int argc, const char **argv, const char *me, |
46 |
|
|
hestParm *hparm) { |
47 |
|
2 |
hestOpt *opt = NULL; |
48 |
|
1 |
char *err, *inS=NULL; |
49 |
|
|
Nrrd *nin; |
50 |
|
|
NrrdIoState *nio; |
51 |
|
|
airArray *mop; |
52 |
|
|
int car, pret; |
53 |
|
|
|
54 |
|
1 |
mop = airMopNew(); |
55 |
|
1 |
hestOptAdd(&opt, NULL, "nin", airTypeString, 1, 1, &inS, NULL, |
56 |
|
|
"input nrrd"); |
57 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
58 |
|
|
|
59 |
✓✗ |
2 |
USAGE(_unrrdu_dataInfoL); |
60 |
|
|
PARSE(); |
61 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
62 |
|
|
|
63 |
|
|
nio = nrrdIoStateNew(); |
64 |
|
|
airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways); |
65 |
|
|
nio->skipData = AIR_TRUE; |
66 |
|
|
nio->keepNrrdDataFileOpen = AIR_TRUE; |
67 |
|
|
nin = nrrdNew(); |
68 |
|
|
airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways); |
69 |
|
|
|
70 |
|
|
if (nrrdLoad(nin, inS, nio)) { |
71 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
72 |
|
|
fprintf(stderr, "%s: error reading header:\n%s", me, err); |
73 |
|
|
airMopError(mop); |
74 |
|
|
return 1; |
75 |
|
|
} |
76 |
|
|
if (_nrrdDataFNNumber(nio) > 1) { |
77 |
|
|
fprintf(stderr, "%s: sorry, currently can't operate with multiple " |
78 |
|
|
"detached datafiles\n", me); |
79 |
|
|
airMopError(mop); |
80 |
|
|
return 1; |
81 |
|
|
} |
82 |
|
|
if (!( nrrdFormatNRRD == nio->format )) { |
83 |
|
|
fprintf(stderr, "%s: can only print data of NRRD format files\n", me); |
84 |
|
|
airMopError(mop); return 1; |
85 |
|
|
} |
86 |
|
|
car = fgetc(nio->dataFile); |
87 |
|
|
#ifdef _MSC_VER |
88 |
|
|
/* needed because otherwise printing a carraige return will |
89 |
|
|
automatically also produce a newline */ |
90 |
|
|
_setmode(_fileno(stdout), _O_BINARY); |
91 |
|
|
#endif |
92 |
|
|
while (EOF != car) { |
93 |
|
|
fputc(car, stdout); |
94 |
|
|
car = fgetc(nio->dataFile); |
95 |
|
|
} |
96 |
|
|
airFclose(nio->dataFile); |
97 |
|
|
|
98 |
|
|
airMopOkay(mop); |
99 |
|
|
return 0; |
100 |
|
1 |
} |
101 |
|
|
|
102 |
|
|
UNRRDU_CMD(data, INFO); |