/
xrwhistplot.c
126 lines (109 loc) · 3.05 KB
/
xrwhistplot.c
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
/* xrwhistoplot.c
*
* Michael Eager 2016
*/
/* xrwhisto.c
*
* Copyright 2012 David G. Barnes
*
* This file is part of S2VOLSURF.
*
* S2VOLSURF is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* S2VOLSURF is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with S2VOLSURF. If not, see <http://www.gnu.org/licenses/>.
*
* We would appreciate it if research outcomes using S2VOLSURF would
* provide the following acknowledgement:
*
* "Three-dimensional visualisation was conducted with the S2PLOT
* progamming library"
*
* and a reference to
*
* D.G.Barnes, C.J.Fluke, P.D.Bourke & O.T.Parry, 2006, Publications
* of the Astronomical Society of Australia, 23(2), 82-93.
*
* $Id: xrwhisto.c 70 2012-11-22 23:00:34Z barnesd $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "libxrw.c"
float datastats[4];
void getstats(VOL_STRUCT *xv) {
fprintf(stdout, "Parsed data (from '%s'):\n", xv->filename);
fprintf(stdout, "volume dimensions: %6d %6d %6d\n", xv->nx, xv->ny, xv->nz);
fprintf(stdout, " voxel sizes: %6.3f %6.3f %6.3f\n", xv->wdx, xv->wdy, xv->wdz);
fprintf(stdout, "total volume size: %6.1f %6.1f %6.1f\n", xv->wdx*xv->nx, xv->wdy*xv->ny,
xv->wdz*xv->nz);
int i, j, k;
float v, min, max, mean, meansq;
min = max = xv->data[0][0][0];
mean = 0.0;
meansq = 0.0;
for (i = 0; i < xv->nx; i++) {
for (j = 0; j < xv->ny; j++) {
for (k = 0; k < xv->nz; k++) {
v = xv->data[i][j][k];
if (v < min) {
min = v;
}
if (v > max) {
max = v;
}
mean += v;
meansq += v*v;
}
}
}
meansq /= (float)(xv->nx * xv->ny * xv->nz);
mean /= (float)(xv->nx * xv->ny * xv->nz);
float rms = sqrt(meansq - mean*mean);
fprintf(stdout, " min, mean(stddev), max: %6.4f %6.4f(%6.4f) %6.4f\n",
min, mean, rms, max);
datastats[0]=min;
datastats[1]=max;
datastats[2]=rms;
datastats[3]=mean;
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s xrwfilename\n", argv[0]);
return -1;
}
XRAW_STRUCT *xr = loadXraw(argv[1]);
if (!xr) {
fprintf(stderr, "Failed to open or read '%s'.\n", argv[1]);
return -1;
}
int nbin = 256;
float x[256];
float data[256];
int centre = 1;
int i;
for (i = 0; i < 256; i++) {
x[i] = ((float)i + 0.5) / 256.0;
data[i] = 0.;
}
for (i = 0; i < xr->nx * xr->ny * xr->nz; i++) {
data[xr->data[i]] += 1.0;
}
for (i = 0; i < 256; i++) {
data[i] = log10f(data[i]+1);
}
fprintf(stdout,"Normalised data value\tLog(count)\t%s\n", argv[1]);
for (i = 0; i < 256; i++) {
fprintf(stdout,"%4.8f\t%4.8f\n", x[i],data[i]);
}
return 0;
}