X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fif-2.cpp;h=545920ad0d74475310afc64ef449a6dd2e05d3bf;hb=3e346e67f7f7a331919a32439b0f54a4d53d3029;hp=51fc23d97b5f08b1cf6cfec08c850af138667301;hpb=4b16507e92bb80b09575b28bed66810e33d2681f;p=ctsim.git diff --git a/src/if-2.cpp b/src/if-2.cpp index 51fc23d..545920a 100644 --- a/src/if-2.cpp +++ b/src/if-2.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if-2.cpp,v 1.3 2000/06/09 11:03:08 kevin Exp $ +** $Id: if-2.cpp,v 1.9 2000/06/28 15:25:34 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -26,10 +26,11 @@ ******************************************************************************/ /* FILE - * sdf-2.c Generate a SDF file from two input SDF files + * if-2.c Generate a IF file from two input IF files */ #include "ct.h" +#include "timer.h" enum {O_ADD, O_SUB, O_MUL, O_COMP, O_VERBOSE, O_HELP, O_VERSION}; @@ -46,25 +47,25 @@ static struct option my_options[] = }; void -sdf2_usage (const char *program) +if2_usage (const char *program) { - fprintf(stdout, "sdf2_usage: %s infile1 infile2 outfile [OPTIONS]\n", kbasename(program)); - fprintf(stdout, "Generate an SDF2D file from two input SDF2D files\n"); - fprintf(stdout, "\n"); - fprintf(stdout, " infile1 Name of first input SDF file\n"); - fprintf(stdout, " infile2 Name of second input SDF file\n"); - fprintf(stdout, " outfile Name of output SDF file\n"); - fprintf(stdout, " --add Add images\n"); - fprintf(stdout, " --sub Subtract image 2 from image 1\n"); - fprintf(stdout, " --mul Multiply images\n"); - fprintf(stdout, " --comp Compare images\n"); - fprintf(stdout, " --verbose Verbose modem\n"); - fprintf(stdout, " --version Print version\n"); - fprintf(stdout, " --help Print this help message\n"); + cout << "usage: " << fileBasename(program) << " infile1 infile2 outfile [OPTIONS]" << endl; + cout << "Generate an image file from two input image files files" << endl; + cout << endl; + cout << " infile1 Name of first input IF file" << endl; + cout << " infile2 Name of second input IF file" << endl; + cout << " outfile Name of output IF file" << endl; + cout << " --add Add images" << endl; + cout << " --sub Subtract image 2 from image 1" << endl; + cout << " --mul Multiply images" << endl; + cout << " --comp Compare images" << endl; + cout << " --verbose Verbose modem" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int -sdf2_main (int argc, char *const argv[]) +if2_main (int argc, char *const argv[]) { ImageFile* pim_in1; ImageFile* pim_in2; @@ -78,6 +79,8 @@ sdf2_main (int argc, char *const argv[]) int opt_mul = 0; int opt_comp = 0; + Timer timerProgram; + while (1) { int c = getopt_long (argc, argv, "", my_options, NULL); @@ -102,23 +105,23 @@ sdf2_main (int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif - exit(0); + return (0); case O_HELP: case '?': - sdf2_usage(argv[0]); + if2_usage(argv[0]); return (0); default: - sdf2_usage(argv[0]); + if2_usage(argv[0]); return (1); } } if (optind + 3 != argc) { - sdf2_usage(argv[0]); + if2_usage(argv[0]); return (1); } @@ -126,32 +129,28 @@ sdf2_main (int argc, char *const argv[]) in_file2 = argv[optind + 1]; out_file = argv[optind + 2]; - pim_in1 = new ImageFile (in_file1); - pim_in2 = new ImageFile (in_file2); + pim_in1 = new ImageFile (); + pim_in2 = new ImageFile (); ImageFile& im_in1 = *pim_in1; ImageFile& im_in2 = *pim_in2; - if (! im_in1.fileRead() || ! im_in2.fileRead()) { + if (! im_in1.fileRead(in_file1) || ! im_in2.fileRead(in_file2)) { sys_error (ERR_WARNING, "Error reading an image"); return (1); } if (im_in1.nx() != im_in2.nx() || im_in1.ny() != im_in2.ny()) { - fprintf(stderr, "Error: Size of image 1 (%d,%d) and image 2 (%d,%d) do not match\n", + sys_error (ERR_SEVERE, "Error: Size of image 1 (%d,%d) and image 2 (%d,%d) do not match", im_in1.nx(), im_in1.ny(), im_in2.nx(), im_in2.ny()); return(1); } if (im_in1.nx() < 0 || im_in1.ny() < 0) { - fprintf(stderr, "Error: Size of image < 0"); + sys_error (ERR_SEVERE, "Error: Size of image < 0"); return(1); } - pim_out = new ImageFile (out_file, im_in1.nx(), im_in1.ny()); + pim_out = new ImageFile (im_in1.nx(), im_in1.ny()); ImageFile& im_out = *pim_out; - if (! im_out.fileCreate()) { - sys_error (ERR_WARNING, "Could not open output file %s", out_file); - return (1); - } string strOperation; ImageFileArray v1 = im_in1.getArray(); @@ -195,19 +194,18 @@ sdf2_main (int argc, char *const argv[]) for (int iy = 0; iy < im_in1.ny(); iy++) { double diff = *in1++ - *in2++; *out++ = diff; - abs_error += fabs(diff); } } - abs_error /= (im_in1.nx() * im_in1.ny()); - fprintf(stdout, "Average Error = %f\n", abs_error); + double d, r, e; + im_in1.comparativeStatistics (im_in2, d, r, e); + cout << "d=" << d << ", r=" << r << ", e=" << e << endl; } - im_out.arrayDataWrite(); im_out.labelsCopy (im_in1, "if-2 file 1: "); im_out.labelsCopy (im_in2, "if-2 file 2: "); - im_out.labelAdd (Array2dFileLabel::L_HISTORY, strOperation.c_str()); + im_out.labelAdd (Array2dFileLabel::L_HISTORY, strOperation.c_str(), timerProgram.timerEnd()); - im_out.fileClose(); + im_out.fileWrite(out_file); return (0); } @@ -216,7 +214,17 @@ sdf2_main (int argc, char *const argv[]) int main (int argc, char *const argv[]) { - return (sdf2_main(argc, argv)); + int retval = 1; + + try { + retval = if2_main(argc, argv); + } catch (exception e) { + cerr << "Exception: " << e.what() << endl; + } catch (...) { + cerr << "Unknown exception" << endl; + } + + return (retval); } #endif