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

Annotation of /trunk/gadget/time.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "areatime.h"
2 :     #include "errorhandler.h"
3 :     #include "readfunc.h"
4 :     #include "readword.h"
5 :     #include "gadget.h"
6 :     #include "global.h"
7 :    
8 :     TimeClass::TimeClass(CommentStream& infile, double maxratio) {
9 :    
10 :     char text[MaxStrLength];
11 :     strncpy(text, "", MaxStrLength);
12 :     int i;
13 :    
14 :     maxratioconsumed = maxratio;
15 :     readWordAndVariable(infile, "firstyear", firstyear);
16 :     readWordAndVariable(infile, "firststep", firststep);
17 :     readWordAndVariable(infile, "lastyear", lastyear);
18 :     readWordAndVariable(infile, "laststep", laststep);
19 :     readWordAndVariable(infile, "notimesteps", numtimesteps);
20 :     numsubsteps.resize(numtimesteps, 1);
21 :    
22 :     timesteps.resize(numtimesteps + 1, 0.0);
23 :     for (i = 1; i <= numtimesteps; i++)
24 :     infile >> ws >> timesteps[i];
25 :    
26 :     infile >> ws;
27 :     if (!(infile.eof())) {
28 :     infile >> text >> ws;
29 :     if (strcasecmp(text, "nrofsubsteps") != 0)
30 :     handle.logFileUnexpected(LOGFAIL, "nrofsubsteps", text);
31 :     for (i = 0; i < numtimesteps; i++)
32 :     infile >> numsubsteps[i] >> ws;
33 :     for (i = 0; i < numtimesteps; i++)
34 :     if (numsubsteps[i] == 0)
35 :     handle.logFileMessage(LOGFAIL, "number of substeps must be non-zero");
36 :     }
37 :    
38 :     lengthofyear = 0.0;
39 :     for (i = 1; i <= numtimesteps; i++)
40 :     lengthofyear += timesteps[i];
41 :    
42 :     if (!(isEqual(lengthofyear, 12.0)))
43 :     handle.logFileMessage(LOGWARN, "length of year does not equal 12");
44 :     if (firstyear > lastyear || (firstyear == lastyear && firststep > laststep))
45 :     handle.logFileMessage(LOGFAIL, "time period is empty");
46 :    
47 :     //JMB store lengthofyear as 1/lengthofyear to save processing time
48 :     if (isZero(lengthofyear))
49 :     handle.logFileMessage(LOGFAIL, "length of year is zero");
50 :     lengthofyear = 1.0 / lengthofyear;
51 :     currentyear = firstyear;
52 :     currentstep = firststep;
53 :     currentsubstep = 1;
54 :     handle.logMessage(LOGMESSAGE, "Read time file - number of timesteps", this->numTotalSteps());
55 :     }
56 :    
57 :     void TimeClass::IncrementTime() {
58 :     if (currentyear == lastyear && currentstep == laststep) {
59 :     if (handle.getLogLevel() >= LOGMESSAGE)
60 :     handle.logMessage(LOGMESSAGE, "\nThe simulation has reached the last timestep for the current model run");
61 :    
62 :     } else {
63 :     currentsubstep = 1;
64 :     if (currentstep == numtimesteps) {
65 :     currentstep = 1;
66 :     currentyear++;
67 :     } else
68 :     currentstep++;
69 :    
70 :     if (handle.getLogLevel() >= LOGMESSAGE)
71 :     handle.logMessage(LOGMESSAGE, "\nIncreased time in the simulation to timestep", this->getTime());
72 :     }
73 :     }
74 :    
75 :     int TimeClass::isWithinPeriod(int year, int step) const {
76 :     if ((year < firstyear) || (year > lastyear))
77 :     return 0; // year outside range
78 :     if ((step < 1) || (step > numtimesteps))
79 :     return 0; // step outside range
80 :     if ((year == firstyear) && (step < firststep))
81 :     return 0; // first year
82 :     if ((year == lastyear) && (step > laststep))
83 :     return 0; // last year
84 :     return 1;
85 :     }
86 :    
87 :     int TimeClass::didStepSizeChange() const {
88 :     if (currentstep == 1)
89 :     return (timesteps[1] != timesteps[numtimesteps]);
90 :     return (timesteps[currentstep] != timesteps[currentstep - 1]);
91 :     }
92 :    
93 :     void TimeClass::Reset() {
94 :     currentyear = firstyear;
95 :     currentstep = firststep;
96 :     currentsubstep = 1;
97 :     if (handle.getLogLevel() >= LOGMESSAGE)
98 :     handle.logMessage(LOGMESSAGE, "\nReset time in the simulation to timestep", this->getTime());
99 :     }
100 :    
101 :     double TimeClass::getMaxRatioConsumed() const {
102 :     if (numsubsteps[currentstep - 1] == 1)
103 :     return maxratioconsumed;
104 :     return pow(maxratioconsumed, numsubsteps[currentstep - 1]);
105 :     }

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

Powered By FusionForge