1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdfinfo.c,v 1.2 2000/05/08 20:02:32 kevin Exp $
7 ** Revision 1.2 2000/05/08 20:02:32 kevin
10 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
11 ** Initial CVS import for first public release
15 ** This program is free software; you can redistribute it and/or modify
16 ** it under the terms of the GNU General Public License (version 2) as
17 ** published by the Free Software Foundation.
19 ** This program is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
24 ** You should have received a copy of the GNU General Public License
25 ** along with this program; if not, write to the Free Software
26 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 ******************************************************************************/
29 * sdfinfo.c Display info on sdf files
34 enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
36 static struct option my_options[] =
38 {"labels", 0, 0, O_LABELS},
39 {"no-labels", 0, 0, O_NO_LABELS},
40 {"stats", 0, 0, O_STATS},
41 {"no-stats", 0, 0, O_NO_STATS},
42 {"debug", 0, 0, O_DEBUG},
43 {"verbose", 0, 0, O_VERBOSE},
44 {"help", 0, 0, O_HELP},
45 {"version", 0, 0, O_VERSION},
50 usage (const char *program)
52 fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program));
53 fprintf(stdout, "Analyze an SDF2D file\n");
54 fprintf(stdout, "\n");
55 fprintf(stdout, " infile Name of input SDF file\n");
56 fprintf(stdout, " --display Display image\n");
57 fprintf(stdout, " --labels Print image labels (default)\n");
58 fprintf(stdout, " --no-labels Do not print image labels\n");
59 fprintf(stdout, " --stats Print image statistics (default)\n");
60 fprintf(stdout, " --no-stats Do not print image statistics\n");
61 fprintf(stdout, " --debug Debug mode\n");
62 fprintf(stdout, " --verbose Verbose mode\n");
63 fprintf(stdout, " --version Print version\n");
64 fprintf(stdout, " --help Print this help message\n");
69 main (int argc, char *const argv[])
80 int c = getopt_long (argc, argv, "", my_options, NULL);
107 fprintf(stdout, "Version %s\n", VERSION);
109 fprintf(stderr, "Unknown version number");
122 if (optind + 1 != argc)
128 in_file = argv[optind];
130 im = image_load (in_file);
134 int nlabels = im->dfp_2d->dfp->num_label;
137 for (i = 0; i < nlabels; i++)
140 if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK)
142 if (blk.lab.label_type == LT_HISTORY) {
143 fprintf(stdout, "History: %s\n", blk.lab.label_str);
144 fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time);
145 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
146 } else if (blk.lab.label_type == LT_TITLE) {
147 fprintf(stdout, "Title: %s\n", blk.lab.label_str);
148 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
149 } else if (blk.lab.label_type == LT_NOTE) {
150 fprintf(stdout, "Note: %s\n", blk.lab.label_str);
151 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
158 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
159 double mode = 0, mean = 0, stddev = 0;
162 int ibin, nbin = 256;
163 int max_bin, max_binindex;
168 for (ix = 0; ix < im->nx; ix++)
170 for (iy = 0; iy < im->ny; iy++)
172 if (im->v[ix][iy] > maxfound)
173 maxfound = im->v[ix][iy];
174 if (im->v[ix][iy] < minfound)
175 minfound = im->v[ix][iy];
176 mean += im->v[ix][iy];
179 spread = maxfound - minfound;
184 for (ibin = 0; ibin < nbin; ibin++)
186 for (ix = 0; ix < im->nx; ix++)
188 for (iy = 0; iy < im->ny; iy++)
190 int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
196 for (ibin = 0; ibin < nbin; ibin++)
198 if (hist[ibin] > max_bin)
200 max_bin = hist[ibin];
204 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
207 mean /= im->nx * im->ny;
208 for (ix = 0; ix < im->nx; ix++)
210 for (iy = 0; iy < im->ny; iy++)
212 double diff = (im->v[ix][iy] - mean);
213 stddev += diff * diff;
216 stddev = sqrt(stddev / (im->nx * im->ny));
217 fprintf(stdout,"nx=%d\n", im->nx);
218 fprintf(stdout,"ny=%d\n", im->ny);
219 fprintf(stdout,"min=%f\n", minfound);
220 fprintf(stdout,"max=%f\n", maxfound);
221 fprintf(stdout,"mean=%f\n", mean);
222 fprintf(stdout,"mode=%f\n", mode);
223 fprintf(stdout,"stddev=%f\n", stddev);