1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: if-1.cpp,v 1.3 2000/06/07 07:43:19 kevin Exp $
7 ** Revision 1.3 2000/06/07 07:43:19 kevin
8 ** Converted to IF data files and C++
10 ** Revision 1.2 2000/06/07 03:50:27 kevin
11 ** *** empty log message ***
13 ** Revision 1.1 2000/06/07 02:29:05 kevin
14 ** Initial C++ versions
16 ** Revision 1.6 2000/05/24 22:50:04 kevin
17 ** Added support for new SGP library
19 ** Revision 1.5 2000/05/16 04:33:59 kevin
20 ** Improved option processing
22 ** Revision 1.4 2000/05/09 14:52:27 kevin
23 ** added sqr and sqrt functions
25 ** Revision 1.3 2000/05/08 20:02:32 kevin
28 ** Revision 1.2 2000/05/03 08:49:50 kevin
31 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
32 ** Initial CVS import for first public release
36 ** This program is free software; you can redistribute it and/or modify
37 ** it under the terms of the GNU General Public License (version 2) as
38 ** published by the Free Software Foundation.
40 ** This program is distributed in the hope that it will be useful,
41 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
42 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 ** GNU General Public License for more details.
45 ** You should have received a copy of the GNU General Public License
46 ** along with this program; if not, write to the Free Software
47 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 ******************************************************************************/
51 * if-1.c Filter a single IF file
56 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
58 static struct option my_options[] =
60 {"invert", 0, 0, O_INVERT},
61 {"verbose", 0, 0, O_VERBOSE},
65 {"sqrt", 0, 0, O_SQRT},
66 {"help", 0, 0, O_HELP},
67 {"version", 0, 0, O_VERSION},
72 if1_usage (const char *program)
74 fprintf(stdout, "if1_usage: %s infile outfile [OPTIONS]\n", kbasename(program));
75 fprintf(stdout, "Generate a IF file from a IF file\n");
76 fprintf(stdout, "\n");
77 fprintf(stdout, " --invert Invert image\n");
78 fprintf(stdout, " --log Natural logrithm of image\n");
79 fprintf(stdout, " --exp Natural exponential of image\n");
80 fprintf(stdout, " --sqr Square of image\n");
81 fprintf(stdout, " --sqrt Square root of image\n");
82 fprintf(stdout, " --verbose Verbose modem\n");
83 fprintf(stdout, " --version Print version\n");
84 fprintf(stdout, " --help Print this help message\n");
88 if1_main (int argc, char *const argv[])
103 int c = getopt_long (argc, argv, "", my_options, NULL);
130 fprintf(stdout, "Version %s\n", VERSION);
132 fprintf(stderr, "Unknown version number");
145 if (optind + 2 != argc)
151 in_file = argv[optind];
152 out_file = argv[optind + 1];
157 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
160 im_in = new ImageFile (in_file);
161 im_in->adf.fileRead ();
162 int nx = im_in->nx();
163 int ny = im_in->ny();
164 im_out = new ImageFile (out_file, nx, ny);
165 im_out->adf.fileCreate ();
167 ImageFileArray vIn = im_in->getArray();
168 ImageFileArray vOut = im_out->getArray();
171 for (ix = 0; ix < nx; ix++)
172 for (iy = 0; iy < ny; iy++)
173 vOut[ix][iy] = - vIn[ix][iy];
174 histString = "Invert transformation";
177 for (ix = 0; ix < nx; ix++)
178 for (iy = 0; iy < ny; iy++)
179 vOut[ix][iy] = log (vIn[ix][iy]);
180 histString = "Log transformation";
183 for (ix = 0; ix < nx; ix++)
184 for (iy = 0; iy < ny; iy++)
185 vOut[ix][iy] = exp (vIn[ix][iy]);
186 histString = "Exp transformation";
189 for (ix = 0; ix < nx; ix++)
190 for (iy = 0; iy < ny; iy++)
191 vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy];
192 histString = "Sqr transformation";
195 for (ix = 0; ix < nx; ix++)
196 for (iy = 0; iy < ny; iy++)
197 vOut[ix][iy] = sqrt (vIn[ix][iy]);
198 histString = "Sqrt transformation";
201 im_out->adf.arrayDataWrite ();
202 im_out->adf.labelsCopy (im_in->adf);
203 im_out->adf.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
204 im_out->adf.fileClose ();
212 main (int argc, char *const argv[])
214 return (if1_main(argc, argv));