1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdfinfo.c,v 1.1 2000/04/28 13:02:44 kevin Exp $
7 ** Revision 1.1 2000/04/28 13:02:44 kevin
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License (version 2) as
13 ** published by the Free Software Foundation.
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU General Public License for more details.
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ******************************************************************************/
25 * sdfinfo.c Display info on sdf files
37 #define O_NO_LABELS 12
39 static struct option my_options[] =
41 {"labels", 0, 0, O_LABELS},
42 {"no-labels", 0, 0, O_NO_LABELS},
43 {"stats", 0, 0, O_STATS},
44 {"no-stats", 0, 0, O_NO_STATS},
45 {"debug", 0, 0, O_DEBUG},
46 {"verbose", 0, 0, O_VERBOSE},
47 {"help", 0, 0, O_HELP},
48 {"version", 0, 0, O_VERSION},
53 usage (const char *program)
55 fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program));
56 fprintf(stdout, "Analyze an SDF2D file\n");
57 fprintf(stdout, "\n");
58 fprintf(stdout, " infile Name of input SDF file\n");
59 fprintf(stdout, " --display Display image\n");
60 fprintf(stdout, " --labels Print image labels (default)\n");
61 fprintf(stdout, " --no-labels Do not print image labels\n");
62 fprintf(stdout, " --stats Print image statistics (default)\n");
63 fprintf(stdout, " --no-stats Do not print image statistics\n");
64 fprintf(stdout, " --debug Debug mode\n");
65 fprintf(stdout, " --verbose Verbose mode\n");
66 fprintf(stdout, " --version Print version\n");
67 fprintf(stdout, " --help Print this help message\n");
72 main (int argc, char *const argv[])
83 int c = getopt_long (argc, argv, "", my_options, NULL);
110 fprintf(stdout, "Version %s\n", VERSION);
112 fprintf(stderr, "Unknown version number");
125 if (optind + 1 != argc)
131 in_file = argv[optind];
133 im = image_load (in_file);
137 int nlabels = im->dfp_2d->dfp->num_label;
140 for (i = 0; i < nlabels; i++)
143 if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK)
145 if (blk.lab.label_type == LT_HISTORY) {
146 fprintf(stdout, "History: %s\n", blk.lab.label_str);
147 fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time);
148 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
149 } else if (blk.lab.label_type == LT_TITLE) {
150 fprintf(stdout, "Title: %s\n", blk.lab.label_str);
151 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
152 } else if (blk.lab.label_type == LT_NOTE) {
153 fprintf(stdout, "Note: %s\n", blk.lab.label_str);
154 fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));
161 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
162 double mode = 0, mean = 0, stddev = 0;
165 int ibin, nbin = 256;
166 int max_bin, max_binindex;
171 for (ix = 0; ix < im->nx; ix++)
173 for (iy = 0; iy < im->ny; iy++)
175 if (im->v[ix][iy] > maxfound)
176 maxfound = im->v[ix][iy];
177 if (im->v[ix][iy] < minfound)
178 minfound = im->v[ix][iy];
179 mean += im->v[ix][iy];
182 spread = maxfound - minfound;
187 for (ibin = 0; ibin < nbin; ibin++)
189 for (ix = 0; ix < im->nx; ix++)
191 for (iy = 0; iy < im->ny; iy++)
193 int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
199 for (ibin = 0; ibin < nbin; ibin++)
201 if (hist[ibin] > max_bin)
203 max_bin = hist[ibin];
207 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
210 mean /= im->nx * im->ny;
211 for (ix = 0; ix < im->nx; ix++)
213 for (iy = 0; iy < im->ny; iy++)
215 double diff = (im->v[ix][iy] - mean);
216 stddev += diff * diff;
219 stddev = sqrt(stddev / (im->nx * im->ny));
220 fprintf(stdout,"nx=%d\n", im->nx);
221 fprintf(stdout,"ny=%d\n", im->ny);
222 fprintf(stdout,"min=%f\n", minfound);
223 fprintf(stdout,"max=%f\n", maxfound);
224 fprintf(stdout,"mean=%f\n", mean);
225 fprintf(stdout,"mode=%f\n", mode);
226 fprintf(stdout,"stddev=%f\n", stddev);