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

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

Powered By FusionForge