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/gadget.cc
[mareframe] / trunk / gadget / gadget.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/gadget.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "ecosystem.h"
2 :     #include "maininfo.h"
3 :     #include "runid.h"
4 :     #include "gadget.h"
5 :     #include "errorhandler.h"
6 :     #include "stochasticdata.h"
7 :     #include "interrupthandler.h"
8 :     #include "global.h"
9 :    
10 :     Ecosystem* EcoSystem;
11 :    
12 :    
13 :     int main(int aNumber, char* const aVector[]) {
14 :    
15 :     MainInfo main;
16 :     StochasticData* data = 0;
17 :     int check = 0;
18 :    
19 :     //Initialise random number generator with system time [MNAA 02.02.26]
20 :     srand((int)time(NULL));
21 :    
22 :     //Test to see if the function double lgamma(double) is returning an integer.
23 :     //lgamma is a non-ansi function and on some platforms when compiled with the
24 :     //-ansi flag lgamma returns an integer value. [MNAA&AJ 05.2001]
25 :     assert(lgamma(1.2) != floor(lgamma(1.2)));
26 :    
27 :     char* workingdir = getenv("GADGET_WORKING_DIR");
28 :     if (workingdir == 0) {
29 :     if ((workingdir = (char*)malloc(LongString)) == NULL)
30 :     handle.logMessage(LOGFAIL, "Error - failed to malloc space for current working directory");
31 :     check = 1;
32 :     if (getcwd(workingdir, LongString) == NULL)
33 :     handle.logMessage(LOGFAIL, "Error - failed to get current working directory");
34 :     }
35 :     if (chdir(workingdir) != 0)
36 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
37 :    
38 :     char* inputdir = getenv("GADGET_DATA_DIR");
39 :     if (inputdir == 0)
40 :     inputdir = workingdir;
41 :     if (chdir(inputdir) != 0)
42 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
43 :     if (chdir(workingdir) != 0) //JMB change back to where we were ...
44 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
45 :    
46 :     main.read(aNumber, aVector);
47 :     main.checkUsage(inputdir, workingdir);
48 :    
49 :     if (chdir(inputdir) != 0)
50 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
51 :     EcoSystem = new Ecosystem(main);
52 :    
53 :     #ifdef INTERRUPT_HANDLER
54 :     //JMB dont register interrupt if doing a network run
55 :     if (!(main.runNetwork()))
56 :     registerInterrupts(&EcoSystem->interrupted);
57 :     #endif
58 :    
59 :     if (chdir(workingdir) != 0)
60 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
61 :     if ((main.getPI()).getPrint())
62 :     EcoSystem->writeInitialInformation((main.getPI()).getOutputFile());
63 :    
64 :     if (main.runStochastic()) {
65 :     if (main.runNetwork()) {
66 :     #ifdef GADGET_NETWORK //to help compiling when pvm libraries are unavailable
67 :     EcoSystem->Initialise();
68 :     data = new StochasticData();
69 :     while (data->getDataFromNetwork()) {
70 :     EcoSystem->Update(data);
71 :     EcoSystem->Simulate(main.runPrint());
72 :     data->sendDataToNetwork(EcoSystem->getLikelihood());
73 :     data->readNextLineFromNetwork();
74 :     }
75 :     delete data;
76 :     #endif
77 :    
78 :     } else if (main.getInitialParamGiven()) {
79 :     if (chdir(inputdir) != 0) //JMB need to change back to inputdir to read the file
80 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
81 :     data = new StochasticData(main.getInitialParamFile());
82 :     if (chdir(workingdir) != 0)
83 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
84 :    
85 :     EcoSystem->Update(data);
86 :     EcoSystem->checkBounds();
87 :    
88 :     EcoSystem->Initialise();
89 :     if (main.printInitial()) {
90 :     EcoSystem->Reset(); //JMB only need to call reset() before the print commands
91 :     EcoSystem->writeStatus(main.getPrintInitialFile());
92 :     }
93 :    
94 :     EcoSystem->Simulate(main.runPrint());
95 :     if ((main.getPI()).getPrint())
96 :     EcoSystem->writeValues();
97 :    
98 :     while (data->isDataLeft()) {
99 :     data->readNextLine();
100 :     EcoSystem->Update(data);
101 :     EcoSystem->checkBounds();
102 :     EcoSystem->Simulate(main.runPrint());
103 :     if ((main.getPI()).getPrint())
104 :     EcoSystem->writeValues();
105 :     }
106 :     delete data;
107 :    
108 :     } else {
109 :     if (EcoSystem->numVariables() != 0)
110 :     handle.logMessage(LOGWARN, "Warning - no parameter input file given, using default values");
111 :    
112 :     EcoSystem->Initialise();
113 :     if (main.printInitial()) {
114 :     EcoSystem->Reset(); //JMB only need to call reset() before the print commands
115 :     EcoSystem->writeStatus(main.getPrintInitialFile());
116 :     }
117 :    
118 :     EcoSystem->Simulate(main.runPrint());
119 :     if ((main.getPI()).getPrint())
120 :     EcoSystem->writeValues();
121 :     }
122 :    
123 :     } else if (main.runOptimise()) {
124 :     if (EcoSystem->numVariables() == 0)
125 :     handle.logMessage(LOGFAIL, "Error - no parameters can be optimised");
126 :    
127 :     if (main.getInitialParamGiven()) {
128 :     if (chdir(inputdir) != 0) //JMB need to change back to inputdir to read the file
129 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
130 :     data = new StochasticData(main.getInitialParamFile());
131 :     if (chdir(workingdir) != 0)
132 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
133 :    
134 :     EcoSystem->Update(data);
135 :     EcoSystem->checkBounds();
136 :     delete data;
137 :     } else
138 :     handle.logMessage(LOGFAIL, "Error - no parameter input file specified");
139 :    
140 :     EcoSystem->Initialise();
141 :     if (main.printInitial()) {
142 :     EcoSystem->Reset(); //JMB only need to call reset() before the print commands
143 :     EcoSystem->writeStatus(main.getPrintInitialFile());
144 :     }
145 :    
146 :     EcoSystem->Optimise();
147 :     if (main.getForcePrint())
148 :     EcoSystem->Simulate(main.getForcePrint());
149 :     }
150 :    
151 :     handle.logMessage(LOGMESSAGE, ""); //write blank line to log file
152 :     if (main.printFinal() && !(main.runNetwork()))
153 :     EcoSystem->writeStatus(main.getPrintFinalFile());
154 :    
155 :     //JMB print final values of parameters
156 :     if (!(main.runNetwork()))
157 :     EcoSystem->writeParams((main.getPI()).getParamOutFile(), (main.getPI()).getPrecision());
158 :    
159 :     if (check)
160 :     free(workingdir);
161 :    
162 :     delete EcoSystem;
163 :     handle.logFinish();
164 :     return EXIT_SUCCESS;
165 :     }

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

Powered By FusionForge