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

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

Powered By FusionForge