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

Annotation of /trunk/gadget/agebandmatrixratiomemberfunctions.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "agebandmatrixratio.h"
2 :     #include "agebandmatrixratioptrvector.h"
3 :     #include "errorhandler.h"
4 :     #include "gadget.h"
5 :     #include "global.h"
6 :    
7 :     void AgeBandMatrixRatio::updateAndTagLoss(const AgeBandMatrix& Total, const DoubleVector& tagloss) {
8 :    
9 :     int numTagExperiments = this->numTagExperiments();
10 :     int minlen, maxlen, age, length, tag;
11 :     if (numTagExperiments > 0) {
12 :     for (age = minage; age < minage + nrow; age++) {
13 :     minlen = this->minLength(age);
14 :     maxlen = this->maxLength(age);
15 :     for (length = minlen; length < maxlen; length++) {
16 :     for (tag = 0; tag < numTagExperiments; tag++) {
17 :     (*v[age - minage])[length][tag].R *= tagloss[tag];
18 :     (*(*v[age - minage])[length][tag].N) = (*v[age - minage])[length][tag].R * Total[age][length].N;
19 :     }
20 :     }
21 :     }
22 :     }
23 :     }
24 :    
25 :     void AgeBandMatrixRatio::updateNumbers(const AgeBandMatrix& Total) {
26 :    
27 :     int numTagExperiments = this->numTagExperiments();
28 :     int minlen, maxlen, age, length, tag;
29 :     double number, ratio;
30 :    
31 :     if (numTagExperiments > 0) {
32 :     for (age = minage; age < minage + nrow; age++) {
33 :     minlen = this->minLength(age);
34 :     maxlen = this->maxLength(age);
35 :     for (length = minlen; length < maxlen; length++) {
36 :     for (tag = 0; tag < numTagExperiments; tag++) {
37 :     number = Total[age][length].N;
38 :     ratio = (*v[age - minage])[length][tag].R;
39 :     if (number < verysmall || ratio < verysmall) {
40 :     (*(*v[age - minage])[length][tag].N) = 0.0;
41 :     (*v[age - minage])[length][tag].R = 0.0;
42 :     } else {
43 :     (*(*v[age - minage])[length][tag].N) = ratio * number;
44 :     }
45 :     }
46 :     }
47 :     }
48 :     }
49 :     }
50 :    
51 :     void AgeBandMatrixRatio::updateRatio(const AgeBandMatrix& Total) {
52 :    
53 :     int numTagExperiments = this->numTagExperiments();
54 :     int minlen, maxlen, age, length, tag;
55 :     double tagnum, totalnum;
56 :    
57 :     if (numTagExperiments > 0) {
58 :     for (age = minage; age < minage + nrow; age++) {
59 :     minlen = this->minLength(age);
60 :     maxlen = this->maxLength(age);
61 :     for (length = minlen; length < maxlen; length++) {
62 :     for (tag = 0; tag < numTagExperiments; tag++) {
63 :     tagnum = (*(*v[age - minage])[length][tag].N);
64 :     totalnum = Total[age][length].N;
65 :     if (tagnum < verysmall || totalnum < verysmall) {
66 :     (*(*v[age - minage])[length][tag].N) = 0.0;
67 :     (*v[age - minage])[length][tag].R = 0.0;
68 :     } else {
69 :     (*v[age - minage])[length][tag].R = tagnum / totalnum;
70 :     }
71 :     }
72 :     }
73 :     }
74 :     }
75 :     }
76 :    
77 :     void AgeBandMatrixRatio::IncrementAge(const AgeBandMatrix& Total) {
78 :    
79 :     int numTagExperiments = this->numTagExperiments();
80 :     int i, j, j1, j2, tag;
81 :    
82 :     if (nrow <= 1)
83 :     return;
84 :    
85 :     if (numTagExperiments > 0) {
86 :     i = nrow - 1;
87 :     j1 = max(v[i]->minCol(), v[i - 1]->minCol());
88 :     j2 = min(v[i]->maxCol(), v[i - 1]->maxCol());
89 :     //For the highest age group
90 :     for (j = j1; j < j2; j++)
91 :     for (tag = 0; tag < numTagExperiments; tag++)
92 :     (*(*v[i])[j][tag].N) += (*(*v[i - 1])[j][tag].N);
93 :    
94 :     for (j = v[i - 1]->minCol(); j < v[i - 1]->maxCol(); j++)
95 :     for (tag = 0; tag < numTagExperiments; tag++) {
96 :     (*(*v[i - 1])[j][tag].N) = 0.0;
97 :     (*v[i - 1])[j][tag].R = 0.0;
98 :     }
99 :    
100 :     //For the other age groups.
101 :     //At the end of each for (i=nrow-2...) loop, the intersection of v[i-1] with
102 :     //v[i] has been copied from v[i-1] to v[i] and v[i-1] has been set to 0.
103 :     for (i = nrow - 2; i > 0; i--) {
104 :     j1 = max(v[i]->minCol(), v[i - 1]->minCol());
105 :     j2 = min(v[i]->maxCol(), v[i - 1]->maxCol());
106 :     for (j = v[i - 1]->minCol(); j < j1; j++) {
107 :     for (tag = 0; tag < numTagExperiments; tag++) {
108 :     (*(*v[i - 1])[j][tag].N) = 0.0;
109 :     (*v[i - 1])[j][tag].R = 0.0;
110 :     }
111 :     }
112 :    
113 :     for (j = j1; j < j2; j++) {
114 :     for (tag = 0; tag < numTagExperiments; tag++) {
115 :     (*(*v[i])[j][tag].N) = (*(*v[i - 1])[j][tag].N);
116 :     (*(*v[i - 1])[j][tag].N) = 0.0;
117 :     (*v[i - 1])[j][tag].R = 0.0;
118 :     }
119 :     }
120 :    
121 :     for (j = j2; j < v[i - 1]->maxCol(); j++) {
122 :     for (tag = 0; tag < numTagExperiments; tag++) {
123 :     (*(*v[i - 1])[j][tag].N) = 0.0;
124 :     (*v[i - 1])[j][tag].R = 0.0;
125 :     }
126 :     }
127 :     }
128 :    
129 :     //set number in age zero to zero.
130 :     for (j = v[0]->minCol(); j < v[0]->maxCol(); j++)
131 :     for (tag = 0; tag < numTagExperiments; tag++)
132 :     (*(*v[0])[j][tag].N) = 0;
133 :    
134 :     this->updateRatio(Total);
135 :     }
136 :     }
137 :    
138 :     void AgeBandMatrixRatioPtrVector::Add(const AgeBandMatrixRatioPtrVector& Addition,
139 :     int area, const ConversionIndex &CI, double ratio) {
140 :    
141 :     //JMB - note area has already been converted to internal area
142 :     int minage = max(v[area]->minAge(), Addition[area].minAge());
143 :     int maxage = min(v[area]->maxAge(), Addition[area].maxAge());
144 :    
145 :     if ((maxage < minage) || isZero(ratio))
146 :     return;
147 :    
148 :     int age, minl, maxl, i, l, tagid, numtags, offset;
149 :     double numfish;
150 :    
151 :     numtags = Addition.numTagExperiments();
152 :     if (numtags > tagID.Size())
153 :     handle.logMessage(LOGFAIL, "Error in agebandmatrixratio - wrong number of tagging experiments");
154 :    
155 :     if (numtags == 0)
156 :     return;
157 :    
158 :     IntVector tagconversion(numtags, -1);
159 :     for (i = 0; i < numtags; i++) {
160 :     tagconversion[i] = this->getTagID(Addition.getTagName(i));
161 :     if (tagconversion[i] < 0)
162 :     handle.logMessage(LOGFAIL, "Error in agebandmatrixratio - unrecognised tagging experiment", Addition.getTagName(i));
163 :     }
164 :    
165 :     numfish = 0.0;
166 :     if (CI.isSameDl()) { //Same dl on length distributions
167 :     offset = CI.getOffset();
168 :     for (age = minage; age <= maxage; age++) {
169 :     minl = max(v[area]->minLength(age), Addition[area].minLength(age) + offset);
170 :     maxl = min(v[area]->maxLength(age), Addition[area].maxLength(age) + offset);
171 :     for (l = minl; l < maxl; l++) {
172 :     for (tagid = 0; tagid < numtags; tagid++) {
173 :     numfish = *(Addition[area][age][l - offset][tagid].N) * ratio;
174 :     *((*v[area])[age][l][tagconversion[tagid]].N) += numfish;
175 :     }
176 :     }
177 :     }
178 :    
179 :     } else { //Not same dl.
180 :     if (CI.isFiner()) {
181 :     //Stock that is added to has finer division than the stock that is added to it.
182 :     for (age = minage; age <= maxage; age++) {
183 :     minl = max(v[area]->minLength(age), CI.minPos(Addition[area].minLength(age)));
184 :     maxl = min(v[area]->maxLength(age), CI.maxPos(Addition[area].maxLength(age) - 1) + 1);
185 :     for (l = minl; l < maxl; l++) {
186 :     for (tagid = 0; tagid < numtags; tagid++) {
187 :     numfish = *(Addition[area][age][CI.getPos(l)][tagid].N) * ratio;
188 :     numfish /= CI.getNumPos(l); //JMB CI.getNumPos() should never be zero
189 :     *((*v[area])[age][l][tagconversion[tagid]].N) += numfish;
190 :     }
191 :     }
192 :     }
193 :    
194 :     } else {
195 :     //Stock that is added to has coarser division than the stock that is added to it.
196 :     for (age = minage; age <= maxage; age++) {
197 :     minl = max(CI.minPos(v[area]->minLength(age)), Addition[area].minLength(age));
198 :     maxl = min(CI.maxPos(v[area]->maxLength(age) - 1) + 1, Addition[area].maxLength(age));
199 :     if (maxl > minl && CI.getPos(maxl - 1) < v[area]->maxLength(age)
200 :     && CI.getPos(minl) >= v[area]->minLength(age)) {
201 :    
202 :     for (l = minl; l < maxl; l++) {
203 :     for (tagid = 0; tagid < numtags; tagid++) {
204 :     numfish = *(Addition[area][age][l][tagid].N) * ratio;
205 :     *((*v[area])[age][CI.getPos(l)][tagconversion[tagid]].N) += numfish;
206 :     }
207 :     }
208 :     }
209 :     }
210 :     }
211 :     }
212 :     }
213 :    
214 :     void AgeBandMatrixRatioPtrVector::Migrate(const DoubleMatrix& MI, const AgeBandMatrixPtrVector& Total) {
215 :    
216 :     DoubleVector tmp(size, 0.0);
217 :     int i, j, age, length, tag;
218 :     int numTagExperiments = tagID.Size();
219 :     if (numTagExperiments > 0) {
220 :     for (age = v[0]->minAge(); age <= v[0]->maxAge(); age++) {
221 :     for (length = v[0]->minLength(age); length < v[0]->maxLength(age); length++) {
222 :     for (tag = 0; tag < numTagExperiments; tag++) {
223 :     tmp.setToZero();
224 :     for (j = 0; j < size; j++)
225 :     for (i = 0; i < size; i++)
226 :     tmp[j] += *((*v[i])[age][length][tag].N) * MI[j][i];
227 :    
228 :     for (j = 0; j < size; j++)
229 :     *((*v[j])[age][length][tag].N) = tmp[j];
230 :     }
231 :     }
232 :     }
233 :     for (i = 0; i < size; i++)
234 :     v[i]->updateRatio(Total[i]);
235 :     }
236 :     }

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

Powered By FusionForge