Ticket #59: template.cpp

File template.cpp, 3.6 kB (added by peter, 4 months ago)

the offending program

Line 
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others.  For conditions of distribution and use see copyright notice in license.txt */
3 /* Template main program for calling Cloudy as a subroutine
4  * Routine returns 0 if model is ok, and 1 if problems occurred. */
5 #include "cddefines.h"
6 #include "cddrive.h"
7
8 int main( int argc, char *argv[] )
9 {
10         DEBUG_ENTRY( "main()" ); // do not remove this!
11
12         try {
13                 // ============================================================================
14                 // START ENTERING YOUR CODE AFTER THIS LINE
15                 // inside this try block you can enter your code to call Cloudy as a subroutine
16                 // replace the code between here and the next ===== line with your own program
17
18                 bool lgBad;
19                 long nleft;
20                 char Version[200];
21
22                 // you can call Cloudy in a loop if you want...
23                 for( int i=0; i < 1; ++i )
24                 {
25                         // the code always needs to be initialized first
26                         cdInit();
27                         cdVersion( Version );
28                         // replace this with a series of calls to cdRead to define the input script
29                         // this particular command line exercises the smoke test
30                         nleft = cdRead( "test" );
31                         // this calls Cloudy to execute the input script you defined above
32                         lgBad = cdDrive();
33                 }
34
35                 cdEXIT(lgBad); // always exit with cdEXIT, this assures files are properly closed.
36                 // ============================================================================
37                 // THIS IS THE END OF THE PROGRAM YOU WROTE
38                 // this ends the try block - your code calling Cloudy ends above this line
39         }
40         // here we catch all the possible exceptions that the code can throw, do not remove this!
41         catch( bad_alloc )
42         {
43                 fprintf( ioQQQ, " DISASTER - A memory allocation has failed. Bailing out...\n" );
44                 cdExit(EXIT_FAILURE);
45         }
46         catch( out_of_range& e )
47         {
48                 fprintf( ioQQQ, " DISASTER - An out_of_range exception was caught, what() = %s. Bailing out...\n",
49                          e.what() );
50                 cdExit(EXIT_FAILURE);
51         }
52         catch( bad_assert& e )
53         {
54                 MyAssert( e.file(), e.line() );
55                 cdExit(EXIT_FAILURE);
56         }
57 #ifdef CATCH_SIGNAL
58         catch( bad_signal& e )
59         {
60                 if( ioQQQ != NULL )
61                 {
62                         if( e.sig() == SIGINT )
63                                 fprintf( ioQQQ, " User interrupt request. Bailing out...\n" );
64                         else if( e.sig() == SIGTERM )
65                                 fprintf( ioQQQ, " Termination request. Bailing out...\n" );
66                         else if( e.sig() == SIGILL )
67                                 fprintf( ioQQQ, " DISASTER - An illegal instruction was found. Bailing out...\n" );
68                         else if( e.sig() == SIGFPE )
69                                 fprintf( ioQQQ, " DISASTER - A floating point exception occurred. Bailing out...\n" );
70                         else if( e.sig() == SIGSEGV )
71                                 fprintf( ioQQQ, " DISASTER - A segmentation violation occurred. Bailing out...\n" );
72 #                       ifdef SIGBUS
73                         else if( e.sig() == SIGBUS )
74                                 fprintf( ioQQQ, " DISASTER - A bus error occurred. Bailing out...\n" );
75 #                       endif
76                         else
77                                 fprintf( ioQQQ, " DISASTER - A signal %d was caught. Bailing out...\n", e.sig() );
78
79                 }
80                 cdExit(EXIT_FAILURE);
81         }
82 #endif
83         catch( cloudy_exit& e )
84         {
85                 if( ioQQQ != NULL )
86                 {
87                         ostringstream oss;
88                         oss << " [Stop in " << e.routine();
89                         oss << " at " << e.file() << ":" << e.line();
90                         if( e.exit_status() == 0 )
91                                 oss << ", Cloudy exited OK]";
92                         else
93                                 oss << ", something went wrong]";
94                         fprintf( ioQQQ, "%s\n", oss.str().c_str() );
95                 }
96                 cdExit(e.exit_status());
97         }
98         catch( exception& e )
99         {
100                 fprintf( ioQQQ, " DISASTER - An unknown exception was caught, what() = %s. Bailing out...\n",
101                          e.what() );
102                 cdExit(EXIT_FAILURE);
103         }
104         // generic catch-all in case we forget any specific exception above... so this MUST be the last one.
105         catch( ... )
106         {
107                 fprintf( ioQQQ, " DISASTER - An unknown exception was caught. Bailing out...\n" );
108                 cdExit(EXIT_FAILURE);
109         }
110 }