Commit d9f9f2bdde43285620410d060868cd2baecff281

Authored by Jürgen Knödlseder
1 parent 84c6461f

Use support function in main.cpp code of ctools

src/ctbin/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctbin.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctbin application. It allocates a
42 42 * ctbin object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -51,41 +51,26 @@ int main (int argc, char *argv[])
51 51 // Initialise pointer on application
52 52 ctbin* application = NULL;
53 53  
54   - // Execute application
  54 + // Try creating an instance of the application and executing the instance
55 55 try {
56 56  
57 57 // Create instance of application
58 58 application = new ctbin(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctbin. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctbin", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctbkgcube/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctbkgcube.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctbkgcube application. It allocates a
42 42 * ctbkgcube object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctbkgcube(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctbkgcube. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctbkgcube", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctbutterfly/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctbutterfly.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctbutterfly application. It allocates
42 42 * a ctbutterfly object and executes the application. Any exceptions that
43 43 * occur will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctbutterfly(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctbutterfly. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctbutterfly", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctcubemask/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctcubemask.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctcubemask application. It allocates
42 42 * a ctcubemask object and executes the application. Any exceptions that
43 43 * occur will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctcubemask(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctcubemask. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctcubemask", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << message << std::endl;
86   - std::cout << signal << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctedispcube/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctedispcube.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctedispcube application. It allocates
42 42 * a ctedispcube object and executes the application. Any exceptions that
43 43 * occur will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctedispcube(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctedispcube. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctedispcube", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/cterror/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <iostream>
  31 +#include "support.hpp"
32 32 #include "cterror.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the cterror application. It allocates a
42 42 * cterror object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new cterror(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "cterror. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("cterror", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctexpcube/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctexpcube.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctexpcube application. It allocates a
42 42 * ctexpcube object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -60,32 +60,20 @@ int main (int argc, char *argv[])
60 60 // Execute application
61 61 application->execute();
62 62  
63   - // Delete application
64   - delete application;
  63 + // Execute ctool
  64 + rc = execute_ctool(application);
65 65  
66   - // Signal success
67   - rc = 0;
68 66 }
69   - catch (std::exception &e) {
70 67  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctexpcube. Run aborted ...";
  68 + catch (std::exception &e) {
75 69  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  70 + // Report exception
  71 + report_ctool_failure("ctexpcube", e.what());
83 72  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  73 + }
87 74  
88   - } // endcatch: catched any application error
  75 + // Delete application
  76 + delete application;
89 77  
90 78 // Return
91 79 return rc;
... ...
src/ctlike/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctlike.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctlike application. It allocates a
42 42 * ctlike object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctlike(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctlike. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctlike", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctmapcube/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctmapcube.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctmapcube application. It allocates a
42 42 * ctmapcube object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctmapcube(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctmapcube. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctmapcube", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctmodel/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctmodel.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctmodel application. It allocates a
42 42 * ctmodel object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,34 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctmodel(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
  64 +
69 65 catch (std::exception &e) {
70 66  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctmodel. Run aborted ...";
  67 + // Report exception
  68 + report_ctool_failure("ctmodel", e.what());
75 69  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
83   - // Write error on standard output
84   - std::cout << signal << std::endl;
85   - std::cout << message << std::endl;
  70 + }
86 71  
87   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
88 74  
89 75 // Return
90 76 return rc;
... ...
src/ctobssim/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctobssim.hpp"
33 33  
34 34  
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctobssim(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctobssim. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctobssim", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctpsfcube/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctpsfcube.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctpsfcube application. It allocates a
42 42 * ctpsfcube object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctpsfcube(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctpsfcube. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctpsfcube", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctselect/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctselect.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctselect application. It allocates a
42 42 * ctselect object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctselect(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctselect. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctselect", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << message << std::endl;
86   - std::cout << signal << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctskymap/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctskymap.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the ctskymap application. It allocates a
42 42 * ctskymap object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new ctskymap(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "ctskymap. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("ctskymap", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/cttsmap/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "cttsmap.hpp"
33 33  
34 34  
... ... @@ -41,7 +41,7 @@
41 41 * This is the main entry point of the cttsmap application. It allocates a
42 42 * cttsmap object and executes the application. Any exceptions that occur
43 43 * will be catched and corresponding error messages written in the
44   - * application logger and on the standard output.
  44 + * application logger and into the standard output.
45 45 ***************************************************************************/
46 46 int main (int argc, char *argv[])
47 47 {
... ... @@ -57,35 +57,20 @@ int main (int argc, char *argv[])
57 57 // Create instance of application
58 58 application = new cttsmap(argc, argv);
59 59  
60   - // Execute application
61   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
62 62  
63   - // Delete application
64   - delete application;
65   -
66   - // Signal success
67   - rc = 0;
68 63 }
69   - catch (std::exception &e) {
70 64  
71   - // Extract error message
72   - std::string message = e.what();
73   - std::string signal = "*** ERROR encounterted in the execution of "
74   - "cttsmap. Run aborted ...";
  65 + catch (std::exception &e) {
75 66  
76   - // If application exists then write error in logger and delete
77   - // application
78   - if (application != NULL) {
79   - application->log << signal << std::endl;
80   - application->log << message << std::endl;
81   - delete application;
82   - }
  67 + // Report exception
  68 + report_ctool_failure("cttsmap", e.what());
83 69  
84   - // Write error on standard output
85   - std::cout << signal << std::endl;
86   - std::cout << message << std::endl;
  70 + }
87 71  
88   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
89 74  
90 75 // Return
91 76 return rc;
... ...
src/ctulimit/main.cpp
... ... @@ -28,7 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <cstdio>
  31 +#include "support.hpp"
32 32 #include "ctulimit.hpp"
33 33  
34 34  
... ... @@ -39,7 +39,9 @@
39 39 * @param[in] argv Command line arguments.
40 40 *
41 41 * This is the main entry point of the ctulimit application. It allocates a
42   - * ctupperlimit object and runs the application.
  42 + * ctulimit object and executes the application. Any exceptions that occur
  43 + * will be catched and corresponding error messages written in the
  44 + * application logger and into the standard output.
43 45 ***************************************************************************/
44 46 int main (int argc, char *argv[])
45 47 {
... ... @@ -55,35 +57,20 @@ int main (int argc, char *argv[])
55 57 // Create instance of application
56 58 application = new ctulimit(argc, argv);
57 59  
58   - // Execute application
59   - application->execute();
  60 + // Execute ctool
  61 + rc = execute_ctool(application);
60 62  
61   - // Delete application
62   - delete application;
63   -
64   - // Signal success
65   - rc = 0;
66 63 }
67   - catch (std::exception &e) {
68 64  
69   - // Extract error message
70   - std::string message = e.what();
71   - std::string signal = "*** ERROR encounterted in the execution of "
72   - "ctulimit. Run aborted ...";
  65 + catch (std::exception &e) {
73 66  
74   - // If application exists then write error in logger and delete
75   - // application
76   - if (application != NULL) {
77   - application->log << signal << std::endl;
78   - application->log << message << std::endl;
79   - delete application;
80   - }
  67 + // Report exception
  68 + report_ctool_failure("ctulimit", e.what());
81 69  
82   - // Write error on standard output
83   - std::cout << signal << std::endl;
84   - std::cout << message << std::endl;
  70 + }
85 71  
86   - } // endcatch: catched any application error
  72 + // Delete application
  73 + delete application;
87 74  
88 75 // Return
89 76 return rc;
... ...
src/support/Makefile.am
... ... @@ -20,7 +20,8 @@
20 20 #############################################################################
21 21  
22 22 # Define sources for this directory
23   -sources = ctool.cpp ctool.hpp \
  23 +sources = support.cpp support.hpp \
  24 + ctool.cpp ctool.hpp \
24 25 ctobservation.cpp ctobservation.hpp \
25 26 ctlikelihood.cpp ctlikelihood.hpp
26 27  
... ...
src/support/support.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * support - support functions *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2016 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file support
  23 + * @brief Support function implementation
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +//#include <cstdlib> // std::getenv() function
  32 +//#include <cstdio> // std::fopen(), etc. functions
  33 +#include "GammaLib.hpp"
  34 +#include "GCTALib.hpp"
  35 +#include "support.hpp"
  36 +//#include "GTools.hpp"
  37 +
  38 +/* __ Method name definitions ____________________________________________ */
  39 +
  40 +/* __ Debug definitions __________________________________________________ */
  41 +
  42 +/* __ Coding definitions _________________________________________________ */
  43 +
  44 +
  45 +/*==========================================================================
  46 + = =
  47 + = Support functions =
  48 + = =
  49 + ==========================================================================*/
  50 +
  51 +/***********************************************************************//**
  52 + * @brief Execute ctool
  53 + *
  54 + * @param[in] tool Pointer to ctool.
  55 + * @return Return code
  56 + *
  57 + * Executes a ctool. The execution is enclosed in a try-catch statement so
  58 + * that any exceptions that occur during execution will be properly logged
  59 + * and written into the standard output.
  60 + ***************************************************************************/
  61 +int execute_ctool(ctool* tool)
  62 +{
  63 + // Initialise return code
  64 + int rc = 1;
  65 +
  66 + // Try executing tool. This catches any exceptions that occur during
  67 + // the execution.
  68 + try {
  69 +
  70 + // Execute ctool
  71 + tool->execute();
  72 +
  73 + // Signal success
  74 + rc = 0;
  75 +
  76 + } // endtry
  77 +
  78 + // Handle any exceptions that have occured
  79 + catch (std::exception &e) {
  80 +
  81 + // Extract error message
  82 + std::string message = e.what();
  83 + std::string signal = "*** ERROR encounterted in the execution of "+
  84 + tool->name()+". Run aborted ...";
  85 +
  86 + // Write error in logger
  87 + tool->log << signal << std::endl;
  88 + tool->log << message << std::endl;
  89 +
  90 + // Write error in standard output
  91 + std::cout << signal << std::endl;
  92 + std::cout << message << std::endl;
  93 +
  94 + } // endcatch: catched any exception
  95 +
  96 + // Return return code
  97 + return rc;
  98 +}
  99 +
  100 +
  101 +/***********************************************************************//**
  102 + * @brief Report ctool failure
  103 + *
  104 + * @param[in] name Name of ctool.
  105 + * @param[in] message Exception message.
  106 + *
  107 + * Reports a ctools failure.
  108 + ***************************************************************************/
  109 +void report_ctool_failure(const std::string& name, const std::string& message)
  110 +{
  111 + // Set signal string
  112 + std::string signal = "*** ERROR encounterted in the execution of "+
  113 + name+". Run aborted ...";
  114 +
  115 + // Write error in standard output
  116 + std::cout << signal << std::endl;
  117 + std::cout << message << std::endl;
  118 +
  119 + // Return
  120 + return;
  121 +}
... ...
src/support/support.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * support - support functions *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2016 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file support
  23 + * @brief Support function definitions
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +#ifndef SUPPORT_HPP
  28 +#define SUPPORT_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include "ctool.hpp"
  32 +
  33 +/* __ Definitions ________________________________________________________ */
  34 +
  35 +/* __ Prototypes _________________________________________________________ */
  36 +int execute_ctool(ctool* tool);
  37 +void report_ctool_failure(const std::string& name, const std::string& message);
  38 +
  39 +#endif /* SUPPORT_HPP */
... ...
test/test_ctbin.py
... ... @@ -82,7 +82,7 @@ class Test(test):
82 82 'Self test of test script')
83 83  
84 84 # Check if execution was successful
85   - self.test_assert(self._execute(cmd) == 0,
  85 + self.test_value(self._execute(cmd), 0,
86 86 'Check successful execution from command line')
87 87  
88 88 # Load counts cube and check content.
... ... @@ -107,13 +107,11 @@ class Test(test):
107 107 # Check if execution was successful in case that the CTOOLS
108 108 # environment variable was set or failed otherwise
109 109 if 'CTOOLS' in os.environ:
110   - rc = 0
111   - what = 'success'
  110 + self.test_value(self._execute(cmd), 0,
  111 + 'Check successful execution with --help option')
112 112 else:
113   - rc = 1
114   - what = 'failure'
115   - self.test_value(self._execute(cmd), rc,
116   - 'Check execution %s from command line with --help option' % what)
  113 + self.test_assert(self._execute(cmd) != 0,
  114 + 'Check execution failure with --help option')
117 115  
118 116 # Return
119 117 return
... ...
test/test_ctbkgcube.py
... ... @@ -110,13 +110,11 @@ class Test(test):
110 110 # Check if execution was successful in case that the CTOOLS
111 111 # environment variable was set or failed otherwise
112 112 if 'CTOOLS' in os.environ:
113   - rc = 0
114   - what = 'success'
  113 + self.test_value(self._execute(cmd), 0,
  114 + 'Check successful execution with --help option')
115 115 else:
116   - rc = 1
117   - what = 'failure'
118   - self.test_value(self._execute(cmd), rc,
119   - 'Check execution %s from command line with --help option' % what)
  116 + self.test_assert(self._execute(cmd) != 0,
  117 + 'Check execution failure with --help option')
120 118  
121 119 # Return
122 120 return
... ...
test/test_ctbutterfly.py
... ... @@ -102,13 +102,11 @@ class Test(test):
102 102 # Check if execution was successful in case that the CTOOLS
103 103 # environment variable was set or failed otherwise
104 104 if 'CTOOLS' in os.environ:
105   - rc = 0
106   - what = 'success'
  105 + self.test_value(self._execute(cmd), 0,
  106 + 'Check successful execution with --help option')
107 107 else:
108   - rc = 1
109   - what = 'failure'
110   - self.test_value(self._execute(cmd), rc,
111   - 'Check execution %s from command line with --help option' % what)
  108 + self.test_assert(self._execute(cmd) != 0,
  109 + 'Check execution failure with --help option')
112 110  
113 111 # Return
114 112 return
... ...
test/test_ctcubemask.py
... ... @@ -105,13 +105,11 @@ class Test(test):
105 105 # Check if execution was successful in case that the CTOOLS
106 106 # environment variable was set or failed otherwise
107 107 if 'CTOOLS' in os.environ:
108   - rc = 0
109   - what = 'success'
  108 + self.test_value(self._execute(cmd), 0,
  109 + 'Check successful execution with --help option')
110 110 else:
111   - rc = 1
112   - what = 'failure'
113   - self.test_value(self._execute(cmd), rc,
114   - 'Check execution %s from command line with --help option' % what)
  111 + self.test_assert(self._execute(cmd) != 0,
  112 + 'Check execution failure with --help option')
115 113  
116 114 # Return
117 115 return
... ...
test/test_ctedispcube.py
... ... @@ -108,13 +108,11 @@ class Test(test):
108 108 # Check if execution was successful in case that the CTOOLS
109 109 # environment variable was set or failed otherwise
110 110 if 'CTOOLS' in os.environ:
111   - rc = 0
112   - what = 'success'
  111 + self.test_value(self._execute(cmd), 0,
  112 + 'Check successful execution with --help option')
113 113 else:
114   - rc = 1
115   - what = 'failure'
116   - self.test_value(self._execute(cmd), rc,
117   - 'Check execution %s from command line with --help option' % what)
  114 + self.test_assert(self._execute(cmd) != 0,
  115 + 'Check execution failure with --help option')
118 116  
119 117 # Return
120 118 return
... ...
test/test_cterror.py
... ... @@ -100,13 +100,11 @@ class Test(test):
100 100 # Check if execution was successful in case that the CTOOLS
101 101 # environment variable was set or failed otherwise
102 102 if 'CTOOLS' in os.environ:
103   - rc = 0
104   - what = 'success'
  103 + self.test_value(self._execute(cmd), 0,
  104 + 'Check successful execution with --help option')
105 105 else:
106   - rc = 1
107   - what = 'failure'
108   - self.test_value(self._execute(cmd), rc,
109   - 'Check execution %s from command line with --help option' % what)
  106 + self.test_assert(self._execute(cmd) != 0,
  107 + 'Check execution failure with --help option')
110 108  
111 109 # Return
112 110 return
... ...
test/test_ctexpcube.py
... ... @@ -106,13 +106,11 @@ class Test(test):
106 106 # Check if execution was successful in case that the CTOOLS
107 107 # environment variable was set or failed otherwise
108 108 if 'CTOOLS' in os.environ:
109   - rc = 0
110   - what = 'success'
  109 + self.test_value(self._execute(cmd), 0,
  110 + 'Check successful execution with --help option')
111 111 else:
112   - rc = 1
113   - what = 'failure'
114   - self.test_value(self._execute(cmd), rc,
115   - 'Check execution %s from command line with --help option' % what)
  112 + self.test_assert(self._execute(cmd) != 0,
  113 + 'Check execution failure with --help option')
116 114  
117 115 # Return
118 116 return
... ...
test/test_ctlike.py
... ... @@ -100,13 +100,11 @@ class Test(test):
100 100 # Check if execution was successful in case that the CTOOLS
101 101 # environment variable was set or failed otherwise
102 102 if 'CTOOLS' in os.environ:
103   - rc = 0
104   - what = 'success'
  103 + self.test_value(self._execute(cmd), 0,
  104 + 'Check successful execution with --help option')
105 105 else:
106   - rc = 1
107   - what = 'failure'
108   - self.test_value(self._execute(cmd), rc,
109   - 'Check execution %s from command line with --help option' % what)
  106 + self.test_assert(self._execute(cmd) != 0,
  107 + 'Check execution failure with --help option')
110 108  
111 109 # Return
112 110 return
... ...
test/test_ctmapcube.py
... ... @@ -106,13 +106,11 @@ class Test(test):
106 106 # Check if execution was successful in case that the CTOOLS
107 107 # environment variable was set or failed otherwise
108 108 if 'CTOOLS' in os.environ:
109   - rc = 0
110   - what = 'success'
  109 + self.test_value(self._execute(cmd), 0,
  110 + 'Check successful execution with --help option')
111 111 else:
112   - rc = 1
113   - what = 'failure'
114   - self.test_value(self._execute(cmd), rc,
115   - 'Check execution %s from command line with --help option' % what)
  112 + self.test_assert(self._execute(cmd) != 0,
  113 + 'Check execution failure with --help option')
116 114  
117 115 # Return
118 116 return
... ...
test/test_ctmodel.py
... ... @@ -110,13 +110,11 @@ class Test(test):
110 110 # Check if execution was successful in case that the CTOOLS
111 111 # environment variable was set or failed otherwise
112 112 if 'CTOOLS' in os.environ:
113   - rc = 0
114   - what = 'success'
  113 + self.test_value(self._execute(cmd), 0,
  114 + 'Check successful execution with --help option')
115 115 else:
116   - rc = 1
117   - what = 'failure'
118   - self.test_value(self._execute(cmd), rc,
119   - 'Check execution %s from command line with --help option' % what)
  116 + self.test_assert(self._execute(cmd) != 0,
  117 + 'Check execution failure with --help option')
120 118  
121 119 # Return
122 120 return
... ...
test/test_ctobssim.py
... ... @@ -108,13 +108,11 @@ class Test(test):
108 108 # Check if execution was successful in case that the CTOOLS
109 109 # environment variable was set or failed otherwise
110 110 if 'CTOOLS' in os.environ:
111   - rc = 0
112   - what = 'success'
  111 + self.test_value(self._execute(cmd), 0,
  112 + 'Check successful execution with --help option')
113 113 else:
114   - rc = 1
115   - what = 'failure'
116   - self.test_value(self._execute(cmd), rc,
117   - 'Check execution %s from command line with --help option' % what)
  114 + self.test_assert(self._execute(cmd) != 0,
  115 + 'Check execution failure with --help option')
118 116  
119 117 # Return
120 118 return
... ...
test/test_ctpsfcube.py
... ... @@ -108,13 +108,11 @@ class Test(test):
108 108 # Check if execution was successful in case that the CTOOLS
109 109 # environment variable was set or failed otherwise
110 110 if 'CTOOLS' in os.environ:
111   - rc = 0
112   - what = 'success'
  111 + self.test_value(self._execute(cmd), 0,
  112 + 'Check successful execution with --help option')
113 113 else:
114   - rc = 1
115   - what = 'failure'
116   - self.test_value(self._execute(cmd), rc,
117   - 'Check execution %s from command line with --help option' % what)
  114 + self.test_assert(self._execute(cmd) != 0,
  115 + 'Check execution failure with --help option')
118 116  
119 117 # Return
120 118 return
... ...
test/test_ctselect.py
... ... @@ -105,13 +105,11 @@ class Test(test):
105 105 # Check if execution was successful in case that the CTOOLS
106 106 # environment variable was set or failed otherwise
107 107 if 'CTOOLS' in os.environ:
108   - rc = 0
109   - what = 'success'
  108 + self.test_value(self._execute(cmd), 0,
  109 + 'Check successful execution with --help option')
110 110 else:
111   - rc = 1
112   - what = 'failure'
113   - self.test_value(self._execute(cmd), rc,
114   - 'Check execution %s from command line with --help option' % what)
  111 + self.test_assert(self._execute(cmd) != 0,
  112 + 'Check execution failure with --help option')
115 113  
116 114 # Return
117 115 return
... ...
test/test_ctskymap.py
... ... @@ -102,13 +102,11 @@ class Test(test):
102 102 # Check if execution was successful in case that the CTOOLS
103 103 # environment variable was set or failed otherwise
104 104 if 'CTOOLS' in os.environ:
105   - rc = 0
106   - what = 'success'
  105 + self.test_value(self._execute(cmd), 0,
  106 + 'Check successful execution with --help option')
107 107 else:
108   - rc = 1
109   - what = 'failure'
110   - self.test_value(self._execute(cmd), rc,
111   - 'Check execution %s from command line with --help option' % what)
  108 + self.test_assert(self._execute(cmd) != 0,
  109 + 'Check execution failure with --help option')
112 110  
113 111 # Return
114 112 return
... ...
test/test_cttsmap.py
... ... @@ -104,13 +104,11 @@ class Test(test):
104 104 # Check if execution was successful in case that the CTOOLS
105 105 # environment variable was set or failed otherwise
106 106 if 'CTOOLS' in os.environ:
107   - rc = 0
108   - what = 'success'
  107 + self.test_value(self._execute(cmd), 0,
  108 + 'Check successful execution with --help option')
109 109 else:
110   - rc = 1
111   - what = 'failure'
112   - self.test_value(self._execute(cmd), rc,
113   - 'Check execution %s from command line with --help option' % what)
  110 + self.test_assert(self._execute(cmd) != 0,
  111 + 'Check execution failure with --help option')
114 112  
115 113 # Return
116 114 return
... ...
test/test_ctulimit.py
... ... @@ -98,13 +98,11 @@ class Test(test):
98 98 # Check if execution was successful in case that the CTOOLS
99 99 # environment variable was set or failed otherwise
100 100 if 'CTOOLS' in os.environ:
101   - rc = 0
102   - what = 'success'
  101 + self.test_value(self._execute(cmd), 0,
  102 + 'Check successful execution with --help option')
103 103 else:
104   - rc = 1
105   - what = 'failure'
106   - self.test_value(self._execute(cmd), rc,
107   - 'Check execution %s from command line with --help option' % what)
  104 + self.test_assert(self._execute(cmd) != 0,
  105 + 'Check execution failure with --help option')
108 106  
109 107 # Return
110 108 return
... ...