1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: if-1.cpp,v 1.2 2000/06/07 03:50:27 kevin Exp $
7 ** Revision 1.2 2000/06/07 03:50:27 kevin
8 ** *** empty log message ***
10 ** Revision 1.1 2000/06/07 02:29:05 kevin
11 ** Initial C++ versions
13 ** Revision 1.6 2000/05/24 22:50:04 kevin
14 ** Added support for new SGP library
16 ** Revision 1.5 2000/05/16 04:33:59 kevin
17 ** Improved option processing
19 ** Revision 1.4 2000/05/09 14:52:27 kevin
20 ** added sqr and sqrt functions
22 ** Revision 1.3 2000/05/08 20:02:32 kevin
25 ** Revision 1.2 2000/05/03 08:49:50 kevin
28 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
29 ** Initial CVS import for first public release
33 ** This program is free software; you can redistribute it and/or modify
34 ** it under the terms of the GNU General Public License (version 2) as
35 ** published by the Free Software Foundation.
37 ** This program is distributed in the hope that it will be useful,
38 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
39 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 ** GNU General Public License for more details.
42 ** You should have received a copy of the GNU General Public License
43 ** along with this program; if not, write to the Free Software
44 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45 ******************************************************************************/
48 * if-1.c Filter a single IF file
53 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
55 static struct option my_options[] =
57 {"invert", 0, 0, O_INVERT},
58 {"verbose", 0, 0, O_VERBOSE},
62 {"sqrt", 0, 0, O_SQRT},
63 {"help", 0, 0, O_HELP},
64 {"version", 0, 0, O_VERSION},
69 if1_usage (const char *program)
71 fprintf(stdout, "if1_usage: %s infile outfile [OPTIONS]\n", kbasename(program));
72 fprintf(stdout, "Generate a IF file from a IF file\n");
73 fprintf(stdout, "\n");
74 fprintf(stdout, " --invert Invert image\n");
75 fprintf(stdout, " --log Natural logrithm of image\n");
76 fprintf(stdout, " --exp Natural exponential of image\n");
77 fprintf(stdout, " --sqr Square of image\n");
78 fprintf(stdout, " --sqrt Square root of image\n");
79 fprintf(stdout, " --verbose Verbose modem\n");
80 fprintf(stdout, " --version Print version\n");
81 fprintf(stdout, " --help Print this help message\n");
85 if1_main (int argc, char *const argv[])
100 int c = getopt_long (argc, argv, "", my_options, NULL);
127 fprintf(stdout, "Version %s\n", VERSION);
129 fprintf(stderr, "Unknown version number");
142 if (optind + 2 != argc)
148 in_file = argv[optind];
149 out_file = argv[optind + 1];
154 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
157 im_in = new ImageFile (in_file);
158 im_in->adf.fileRead ();
159 int nx = im_in->adf.nx();
160 int ny = im_in->adf.ny();
161 im_out = new ImageFile (out_file, nx, ny);
162 im_out->adf.fileCreate ();
164 ImageFileArray vIn = im_in->adf.getArray();
165 ImageFileArray vOut = im_out->adf.getArray();
168 for (ix = 0; ix < nx; ix++)
169 for (iy = 0; iy < ny; iy++)
170 vOut[ix][iy] = - vIn[ix][iy];
171 histString = "Invert transformation";
174 for (ix = 0; ix < nx; ix++)
175 for (iy = 0; iy < ny; iy++)
176 vOut[ix][iy] = log (vIn[ix][iy]);
177 histString = "Log transformation";
180 for (ix = 0; ix < nx; ix++)
181 for (iy = 0; iy < ny; iy++)
182 vOut[ix][iy] = exp (vIn[ix][iy]);
183 histString = "Exp transformation";
186 for (ix = 0; ix < nx; ix++)
187 for (iy = 0; iy < ny; iy++)
188 vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy];
189 histString = "Sqr transformation";
192 for (ix = 0; ix < nx; ix++)
193 for (iy = 0; iy < ny; iy++)
194 vOut[ix][iy] = sqrt (vIn[ix][iy]);
195 histString = "Sqrt transformation";
198 im_out->adf.arrayDataWrite ();
199 for (int i = 0; i < im_in->adf.getNumLabels(); i++) {
201 im_in->adf.labelRead (l, i);
202 im_out->adf.labelAdd (l);
204 im_out->adf.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
205 im_out->adf.fileClose ();
213 main (int argc, char *const argv[])
215 return (if1_main(argc, argv));