Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/interruptinterface.cc
[mareframe] / trunk / gadget / interruptinterface.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/interruptinterface.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (view) (download)

1 : agomez 1 #include "interruptinterface.h"
2 :     #include "charptrvector.h"
3 :     #include "ecosystem.h"
4 :     #include "gadget.h"
5 :    
6 :     extern Ecosystem* EcoSystem;
7 : ulcessvp 17 extern volatile int interrupted;
8 : ulcessvp 16 #ifdef _OPENMP
9 : ulcessvp 11 extern Ecosystem** EcoSystems;
10 :     #endif
11 :    
12 : agomez 1 void InterruptInterface::printMenu() {
13 :     if (EcoSystem->getFuncEval() != 0)
14 : ulcessvp 11 {
15 :     int iters = EcoSystem->getFuncEval();
16 : ulcessvp 16 #ifdef _OPENMP
17 : ulcessvp 11 int numThr = omp_get_max_threads ( );
18 :     for (int i = 0; i < numThr; i++)
19 :     iters += EcoSystems[i]->getFuncEval();
20 :     #endif
21 :     cout << "\nInterrupted after a total of " << iters << " iterations ...";
22 :     }
23 : agomez 1 cout << "\nInterrupted at year " << EcoSystem->getCurrentYear() << ", step "
24 :     << EcoSystem->getCurrentStep() << " (" << EcoSystem->getCurrentTime()
25 :     << " of " << EcoSystem->numTotalSteps() << " timesteps)\n"
26 :     << " q -> quit simulation\n"
27 :     << " c -> continue simulation\n"
28 :     << " p -> write current parameters to file\n"
29 :     << " f -> dump current model to file\n";
30 :     cout.flush();
31 :     }
32 :    
33 :     int InterruptInterface::menu() {
34 : ulcessvp 17 interrupted = 0;
35 : agomez 1 char userinput[MaxStrLength];
36 :     char interruptfile[MaxStrLength];
37 :     strncpy(userinput, "", MaxStrLength);
38 :     strncpy(interruptfile, "", MaxStrLength);
39 :    
40 :     this->printMenu();
41 :     while (1) {
42 :     cout << "> ";
43 :     cout.flush();
44 :     while (fgets(userinput, MaxStrLength, stdin) == 0) {};
45 :     switch (userinput[0]) {
46 :     case 'c':
47 :     case 'C':
48 :     cout << "\nContinuing current simulation ...\n";
49 :     cout.flush();
50 :     return 1;
51 :     case 'q':
52 :     case 'Q':
53 :     cout << "\nQuitting current simulation ...\nThe best parameter values will be written to file (called interrupt.out)\n";
54 :     cout.flush();
55 :     return 0;
56 :     case 'f':
57 :     case 'F':
58 :     cout << "\nWriting current model to file (called modeldump.out) ...\n";
59 :     strcpy(interruptfile, "modeldump.out");
60 :     EcoSystem->writeStatus(interruptfile);
61 :     strncpy(interruptfile, "", MaxStrLength); //JMB clear the text string
62 :     break;
63 :     case 'p':
64 :     case 'P':
65 :     cout << "\nWriting current parameters to file (called current.out) ...\n";
66 :     strcpy(interruptfile, "current.out");
67 :     EcoSystem->writeParams(interruptfile, 0);
68 :     strncpy(interruptfile, "", MaxStrLength); //JMB clear the text string
69 :     break;
70 :     case 'h':
71 :     case 'H':
72 :     case '?':
73 :     this->printMenu();
74 :     break;
75 :     default:
76 :     break;
77 :     }
78 :     }
79 :     return 1; //JMB default return value
80 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge