-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopmodel.cpp
More file actions
4365 lines (4322 loc) · 164 KB
/
opmodel.cpp
File metadata and controls
4365 lines (4322 loc) · 164 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <admodel.h>
// NOTE: some of the code is a bit archaic and more C-like because the
// Borland C++ 5.2 compiler/linker SUCKS and doesn't support std namespace classes
// perhaps it's an include file issue. or something else.
// using namespace std;
// the class components and method names are hopefully self-explanatory
class stringNode
{
private:
adstring *as;
stringNode* prevNode;
stringNode* nextNode;
public:
stringNode();
void setPrevNode(stringNode *prev);
stringNode* getPrevNode(void);
void setNextNode(stringNode *next);
stringNode* getNextNode(void);
void setNodeString(const char *s);
adstring getNodeString(void);
~stringNode();
friend class stringLinkList;
};
stringNode::stringNode()
{
// constructor
as = NULL;
prevNode = NULL;
nextNode = NULL;
}
stringNode::~stringNode()
{
// destructor
delete as;
as = NULL;
prevNode = NULL;
nextNode = NULL;
}
void stringNode::setPrevNode(stringNode *ptr)
{
prevNode = ptr;
}
stringNode* stringNode::getPrevNode(void)
{
return prevNode;
}
void stringNode::setNextNode(stringNode *ptr)
{
nextNode = ptr;
}
stringNode* stringNode::getNextNode(void)
{
return nextNode;
}
void stringNode::setNodeString(const char *s)
{
if (as != NULL)
{
delete as;
as = NULL;
}
// strncpy(as,s,strlen(s));
as = new adstring(s);
}
adstring stringNode::getNodeString(void)
{
return (*as);
}
// the class components and method names are hopefully self-explanatory
class stringLinkList
{
private:
stringNode *head;
stringNode *cursor;
int nNodes;
public:
stringLinkList();
void addNodeBegin(const char *s);
void addNodeEnd(adstring s);
void addNodeBefore(int num, const char *s);
void addNodeAfter(int num, const char *s);
int findNodeNum(const char *s);
void appendNodeString(int num, const char *sS);
void replaceNodeString(int num, const char *rS);
void replaceNodeString(const char *oS, const char *rS);
stringNode* getNode(int num);
stringNode* getNode(const char *s);
adstring getNodeString(int num);
void deleteNode(int num);
void deleteNode(const char *s);
int countNodes();
stringLinkList(const stringLinkList& sLL);
void copyStringLinkList(const stringLinkList& sLL);
~stringLinkList();
};
stringLinkList::stringLinkList()
{
// constructor
head = NULL;
cursor = NULL;
nNodes = 0;
}
stringLinkList::~stringLinkList()
{
// destructor
stringNode *tmp;
cursor = NULL;
nNodes = 0;
while (head != NULL)
{
tmp = head;
head = head->nextNode;
delete tmp;
}
}
void stringLinkList::addNodeBegin(const char *s)
{
stringNode *newSN;
newSN = new stringNode;
newSN->setNodeString(s);
newSN->nextNode = head;
head->prevNode = newSN;
head = newSN;
nNodes++;
}
void stringLinkList::addNodeEnd(adstring s)
{
if (head == NULL)
{
// empty list
head = new stringNode;
head->setNodeString(s);
head->prevNode = NULL;
head->nextNode = NULL;
}
else
{
// search for end of list
stringNode *holdSN, *newSN;
holdSN = head;
while (holdSN->nextNode != NULL)
{
holdSN = holdSN->nextNode;
}
newSN = new stringNode;
newSN->setNodeString(s);
newSN->nextNode = NULL;
newSN->prevNode = holdSN;
holdSN->nextNode = newSN;
}
nNodes++;
}
void stringLinkList::addNodeBefore(int n, const char *s)
{
stringNode *holdSN, *afterSN, *newSN;
int i;
holdSN = head;
for (i = 1; i < n; i++)
{
if (holdSN == NULL)
{
cout << "stringLinkList::addNodeBefore: Bad link number " << n << ", nNodes = " << nNodes << endl;
return;
}
holdSN = holdSN->nextNode;
}
afterSN = holdSN->nextNode;
newSN = new stringNode;
newSN->setNodeString(s);
newSN->nextNode = holdSN->nextNode;
newSN->prevNode = holdSN;
holdSN->nextNode = newSN;
afterSN->prevNode = newSN;
nNodes++;
}
void stringLinkList::addNodeAfter(int n, const char *s)
{
stringNode *holdSN, *afterSN, *newSN;
int i;
holdSN = head;
for (i = 1; i < n; i++)
{
if (holdSN == NULL)
{
cout << "stringLinkList::addNodeAfter: Bad link number " << n << ", nNodes = " << nNodes << endl;
return;
}
holdSN = holdSN->nextNode;
}
afterSN = holdSN->nextNode;
newSN = new stringNode;
newSN->setNodeString(s);
newSN->nextNode = holdSN->nextNode;
newSN->prevNode = holdSN;
holdSN->nextNode = newSN;
afterSN->prevNode = newSN;
nNodes++;
}
int stringLinkList::findNodeNum(const char *s)
{
stringNode *holdSN;
bool foundIt = false;
int nNode = 0;
int len_s = strlen(s);
holdSN = head;
while (holdSN != NULL && !foundIt)
{
nNode++;
foundIt = (strncmp(holdSN->getNodeString(),s,len_s) == 0);
holdSN = holdSN->nextNode;
}
return nNode;
}
void stringLinkList::appendNodeString(int n, const char *appS)
{
stringNode *currNode;
adstring currS;
currNode = getNode(n);
if (currNode != NULL)
{
// what's wrong with this? is this the problem?
// pointer vs. data
currS = currNode->getNodeString();
// strncat(currS,appS,strlen(appS));
currS = currS + adstring(appS);
currNode->setNodeString(currS);
}
else
{
cout << "stringLinkList::appendNodeString: did not find node " << n << endl;
}
}
void stringLinkList::replaceNodeString(int n, const char *replS)
{
stringNode *currNode;
currNode = getNode(n);
if (currNode != NULL)
{
currNode->setNodeString(replS);
}
else
{
cout << "stringLinkList::replaceNodeString: did not find node " << n << endl;
}
}
void stringLinkList::replaceNodeString(const char *oldS, const char *replS)
{
stringNode *currNode;
currNode = getNode(oldS);
if (currNode != NULL)
{
currNode->setNodeString(replS);
}
else
{
cout << "stringLinkList::replaceNodeString: did not find nodeString \'" << oldS << "\'" << endl;
}
}
stringNode* stringLinkList::getNode(int n)
{
if (n <= 0 || n > nNodes)
{
cout << "stringLinkList::getNode: Bad link number " << n << ", nNodes = " << nNodes << endl;
return NULL;
}
else
{
stringNode *holdSN;
int i;
holdSN = head;
// don't go to the next link if the node to get is the first one
if (n > 1)
{
for (i = 1; i < n; i++)
{
holdSN = holdSN->nextNode;
if (holdSN == NULL)
{
cout << "stringLinkList::getNode: Bad link number " << n << ", nNodes = " << nNodes << endl;
return NULL;
}
}
}
return holdSN;
}
}
stringNode* stringLinkList::getNode(const char *s)
{
if (&s == NULL)
{
cout << "stringLinkList::getNode: Bad link string \'" << s << "\'" << endl;
return NULL;
}
else
{
stringNode *holdSN;
int i;
bool foundIt = false;
int len_s = strlen(s);
holdSN = head;
// if the first node has what we're looking for, then don't search
if (strncmp(holdSN->getNodeString(),s,len_s) == 0)
{
// in ADMB 6.2.1, CLASS adstring doesn't have an operator for "!="
}
else
{
for (i = 2; i <= nNodes && !foundIt; i++)
{
holdSN = holdSN->nextNode;
if (holdSN == NULL)
{
cout << "stringLinkList::getNode: Bad link string \'" << s << "\', nNodes = " << nNodes << endl;
return NULL;
}
foundIt = (strncmp(holdSN->getNodeString(),s,len_s) == 0);
}
}
return holdSN;
}
}
adstring stringLinkList::getNodeString(int n)
{
if (n <= 0 || n > nNodes)
{
cout << "stringLinkList::getNode: Bad link number " << n << ", nNodes = " << nNodes << endl;
return ("");
}
else
{
stringNode *holdSN;
int i;
holdSN = head;
// don't go to the next link if the node to get is the first one
if (n > 1)
{
for (i = 1; i < n; i++)
{
holdSN = holdSN->nextNode;
if (holdSN == NULL)
{
cout << "stringLinkList::getNode: Bad link number " << n << ", nNodes = " << nNodes << endl;
return ("");
}
}
}
return (holdSN->getNodeString());
}
}
void stringLinkList::deleteNode(int n)
{
if (n <= 0 || n > nNodes)
{
cout << "stringLinkList::getNode: Bad link number " << n << ", nNodes = " << nNodes << endl;
}
else
{
stringNode *holdSN, *nextSN, *prevSN;
int i;
holdSN = head;
// don't go to the next link if the node to delete is the first one
if (n > 1)
{
for (i = 1; i < n; i++)
{
holdSN = holdSN->nextNode;
if (holdSN == NULL)
{
cout << "stringLinkList::getNode: Bad link number " << n << ", nNodes = " << nNodes << endl;
return;
}
}
}
prevSN = holdSN->prevNode;
nextSN = holdSN->nextNode;
prevSN->nextNode = nextSN;
nextSN->prevNode = prevSN;
delete holdSN;
nNodes--;
}
}
void stringLinkList::deleteNode(const char *s)
{
stringNode *holdSN, *nextSN, *prevSN;
int len_s = strlen(s);
holdSN = head;
// delete the first node
if (strncmp(holdSN->getNodeString(),s,len_s) == 0)
{
head = head->nextNode;
head->prevNode = NULL;
delete holdSN;
nNodes--;
return;
}
else
{
prevSN = holdSN;
while (holdSN != NULL)
{
if (strncmp(holdSN->getNodeString(),s,len_s) == 0)
{
nextSN = holdSN->nextNode;
prevSN = holdSN->prevNode;
prevSN->nextNode = nextSN;
nextSN->prevNode = prevSN;
delete holdSN;
nNodes--;
return;
}
prevSN = holdSN;
holdSN = holdSN->nextNode;
}
}
nNodes--;
}
int stringLinkList::countNodes()
{
nNodes = 0;
if (head != NULL)
{
stringNode *holdSN;
holdSN = head;
while (holdSN != NULL)
{
nNodes++;
holdSN = holdSN->nextNode;
}
}
return nNodes;
}
stringLinkList::stringLinkList(const stringLinkList& sLL)
{
// copy-constructor for explicit data copy, not address copy
// what does the compiler default copy-constructor do?
// initialize new object
head = NULL;
cursor = NULL;
nNodes = 0;
if (sLL.head != NULL && sLL.nNodes > 0)
{
stringNode *holdSN;
int i;
holdSN = sLL.head;
// if there is stuff, then make copies of it
for (i = 1; i <= sLL.nNodes; i++)
{
addNodeEnd(holdSN->getNodeString());
holdSN = holdSN->nextNode;
}
}
cout << "stringLinkList copy-constructor: copied " << sLL.nNodes << " nodes to " << nNodes << " nodes" << endl;
}
void stringLinkList::copyStringLinkList(const stringLinkList& sLL)
{
// just like the copy-constructor, but does it work differently?
stringNode *holdSN, *tmpSN;
int delNodes = 0;
// if head != NULL, then do what is in the object destructor
if (head != NULL)
{
holdSN = head;
while (holdSN != NULL)
{
tmpSN = holdSN;
holdSN = holdSN->nextNode;
delete tmpSN;
delNodes++;
}
cout << "stringLinkList::copyStringLinkList: deleted " << delNodes << " nodes" << endl;
}
// initialize object
head = NULL;
cursor = NULL;
nNodes = 0;
if (sLL.head != NULL && sLL.nNodes > 0)
{
stringNode *holdSN;
int i;
holdSN = sLL.head;
// if there is stuff, then make copies of it
for (i = 1; i <= sLL.nNodes; i++)
{
addNodeEnd(holdSN->getNodeString());
holdSN = holdSN->nextNode;
}
}
cout << "stringLinkList::copyStringLinkList: copied " << sLL.nNodes << " nodes to " << nNodes << " nodes" << endl;
}
stringLinkList idf;
stringLinkList idf_proj;
bool readIDFfile = false;
time_t rawtime;
struct tm *timeinfo;
#include <admodel.h>
#include <contrib.h>
extern "C" {
void ad_boundf(int i);
}
#include <test.htp>
model_data::model_data(int argc,char * argv[]) : ad_comm(argc,argv)
{
ad_comm::change_datafile_name("stock_assess.dat");
styr.allocate("styr");
endyr.allocate("endyr");
base_endyr.allocate("base_endyr");
hcr_styr.allocate("hcr_styr");
rcrage.allocate("rcrage");
trmage.allocate("trmage");
nbins1.allocate("nbins1");
nbins2.allocate("nbins2");
nbins3.allocate("nbins3");
cattot.allocate(styr,endyr,"cattot");
cattot_log_sd.allocate(styr,endyr,"cattot_log_sd");
nyrs_fsh.allocate("nyrs_fsh");
fshyrs.allocate(1,nyrs_fsh,"fshyrs");
multN_fsh.allocate(1,nyrs_fsh,"multN_fsh");
ac_yng_fsh.allocate(1,nyrs_fsh,"ac_yng_fsh");
ac_old_fsh.allocate(1,nyrs_fsh,"ac_old_fsh");
nyrslen_fsh.allocate("nyrslen_fsh");
fshlenyrs.allocate(1,nyrslen_fsh,"fshlenyrs");
multNlen_fsh.allocate(1,nyrslen_fsh,"multNlen_fsh");
rwlk_sd.allocate(styr,endyr-1,"rwlk_sd");
catp.allocate(1,nyrs_fsh,rcrage,trmage,"catp");
lenp.allocate(1,nyrslen_fsh,1,nbins1,"lenp");
wt_fsh.allocate(styr,endyr,rcrage,trmage,"wt_fsh");
nyrs_srv1_bs.allocate("nyrs_srv1_bs");
srvyrs1_bs.allocate(1,nyrs_srv1_bs,"srvyrs1_bs");
indxsurv1_bs.allocate(1,nyrs_srv1_bs,"indxsurv1_bs");
indxsurv_log_sd1_bs.allocate(1,nyrs_srv1_bs,"indxsurv_log_sd1_bs");
nyrs_srv1_ek.allocate("nyrs_srv1_ek");
srvyrs1_ek.allocate(1,nyrs_srv1_ek,"srvyrs1_ek");
indxsurv1_ek.allocate(1,nyrs_srv1_ek,"indxsurv1_ek");
indxsurv_log_sd1_ek.allocate(1,nyrs_srv1_ek,"indxsurv_log_sd1_ek");
nyrs_srv1_dy.allocate("nyrs_srv1_dy");
srvyrs1_dy.allocate(1,nyrs_srv1_dy,"srvyrs1_dy");
indxsurv1_dy.allocate(1,nyrs_srv1_dy,"indxsurv1_dy");
indxsurv_log_sd1_dy.allocate(1,nyrs_srv1_dy,"indxsurv_log_sd1_dy");
yrfrct_srv1.allocate(styr,endyr,"yrfrct_srv1");
nyrsac_srv1.allocate("nyrsac_srv1");
srv_acyrs1.allocate(1,nyrsac_srv1,"srv_acyrs1");
multN_srv1.allocate(1,nyrsac_srv1,"multN_srv1");
ac_yng_srv1.allocate(1,nyrsac_srv1,"ac_yng_srv1");
ac_old_srv1.allocate(1,nyrsac_srv1,"ac_old_srv1");
nyrslen_srv1.allocate("nyrslen_srv1");
srv_lenyrs1.allocate(1,nyrslen_srv1,"srv_lenyrs1");
multNlen_srv1.allocate(1,nyrslen_srv1,"multNlen_srv1");
srvp1.allocate(1,nyrsac_srv1,rcrage,trmage,"srvp1");
srvlenp1.allocate(1,nyrslen_srv1,1,nbins3,"srvlenp1");
wt_srv1.allocate(styr,endyr,rcrage,trmage,"wt_srv1");
nyrs_srv2.allocate("nyrs_srv2");
srvyrs2.allocate(1,nyrs_srv2,"srvyrs2");
indxsurv2.allocate(1,nyrs_srv2,"indxsurv2");
indxsurv_log_sd2.allocate(1,nyrs_srv2,"indxsurv_log_sd2");
yrfrct_srv2.allocate(styr,endyr,"yrfrct_srv2");
nyrsac_srv2.allocate("nyrsac_srv2");
srv_acyrs2.allocate(1,nyrsac_srv2,"srv_acyrs2");
multN_srv2.allocate(1,nyrsac_srv2,"multN_srv2");
ac_yng_srv2.allocate(1,nyrsac_srv2,"ac_yng_srv2");
ac_old_srv2.allocate(1,nyrsac_srv2,"ac_old_srv2");
nyrslen_srv2.allocate("nyrslen_srv2");
srv_lenyrs2.allocate(1,nyrslen_srv2,"srv_lenyrs2");
multNlen_srv2.allocate(1,nyrslen_srv2,"multNlen_srv2");
srvp2.allocate(1,nyrsac_srv2,rcrage,trmage,"srvp2");
srvlenp2.allocate(1,nyrslen_srv2,1,nbins2,"srvlenp2");
wt_srv2.allocate(styr,endyr,rcrage,trmage,"wt_srv2");
nyrs_srv3.allocate("nyrs_srv3");
srvyrs3.allocate(1,nyrs_srv3,"srvyrs3");
indxsurv3.allocate(1,nyrs_srv3,"indxsurv3");
indxsurv_log_sd3.allocate(1,nyrs_srv3,"indxsurv_log_sd3");
yrfrct_srv3.allocate(styr,endyr,"yrfrct_srv3");
nyrsac_srv3.allocate("nyrsac_srv3");
srv_acyrs3.allocate(1,nyrsac_srv3,"srv_acyrs3");
multN_srv3.allocate(1,nyrsac_srv3,"multN_srv3");
nyrslen_srv3.allocate("nyrslen_srv3");
srv_lenyrs3.allocate(1,nyrslen_srv3,"srv_lenyrs3");
multNlen_srv3.allocate(1,nyrslen_srv3,"multNlen_srv3");
srvp3.allocate(1,nyrsac_srv3,rcrage,trmage,"srvp3");
srvlenp3.allocate(1,nyrslen_srv3,1,nbins2,"srvlenp3");
wt_srv3.allocate(styr,endyr,rcrage,trmage,"wt_srv3");
age_trans.allocate(rcrage,trmage,rcrage,trmage,"age_trans");
len_trans1.allocate(rcrage,trmage,1,nbins1,"len_trans1");
len_trans2.allocate(rcrage,trmage,1,nbins2,"len_trans2");
len_trans3.allocate(rcrage,trmage,1,nbins3,"len_trans3");
wt_pop.allocate(styr,endyr,rcrage,trmage,"wt_pop");
wt_spawn.allocate(styr,endyr,rcrage,trmage,"wt_spawn");
mat_old.allocate(rcrage,trmage,"mat_old");
mat.allocate(rcrage,trmage,"mat");
wt_pop_proj.allocate(rcrage,trmage,"wt_pop_proj");
wt_spawn_proj.allocate(rcrage,trmage,"wt_spawn_proj");
wt_fsh_proj.allocate(rcrage,trmage,"wt_fsh_proj");
wt_srv_proj.allocate(rcrage,trmage,"wt_srv_proj");
Ftarget.allocate(endyr+1,endyr+5,"Ftarget");
B40.allocate("B40");
log_mean_recr_proj.allocate("log_mean_recr_proj");
sigmasq_recr.allocate("sigmasq_recr");
ad_comm::change_datafile_name("opmodel.dat");
st_age.allocate("st_age");
end_age.allocate("end_age");
om_hcr_styr.allocate("om_hcr_styr");
om_rec_avg_styr.allocate("om_rec_avg_styr");
nsel_fsh.allocate("nsel_fsh");
fsh_frac.allocate(1,nsel_fsh,"fsh_frac");
nsel_srv.allocate("nsel_srv");
srv_frac.allocate(1,nsel_srv,"srv_frac");
sp_frac.allocate("sp_frac");
styr_fsh_sel.allocate("styr_fsh_sel");
frac_catch.allocate(styr_fsh_sel,endyr,1,nsel_fsh,"frac_catch");
nyrs_fsh_paa_all.allocate("nyrs_fsh_paa_all");
yrs_fsh_paa_all.allocate(1,nyrs_fsh_paa_all,"yrs_fsh_paa_all");
multN_fsh_paa_all.allocate(1,nyrs_fsh_paa_all,"multN_fsh_paa_all");
fsh_paa_all.allocate(1,nyrs_fsh_paa_all,st_age,end_age,"fsh_paa_all");
nyrs_srv_1_paa_all.allocate("nyrs_srv_1_paa_all");
yrs_srv_1_paa_all.allocate(1,nyrs_srv_1_paa_all,"yrs_srv_1_paa_all");
multN_srv_1_paa_all.allocate(1,nyrs_srv_1_paa_all,"multN_srv_1_paa_all");
srv_1_paa_all.allocate(1,nyrs_srv_1_paa_all,st_age,end_age,"srv_1_paa_all");
nyrs_srv_2_paa_all.allocate("nyrs_srv_2_paa_all");
yrs_srv_2_paa_all.allocate(1,nyrs_srv_2_paa_all,"yrs_srv_2_paa_all");
multN_srv_2_paa_all.allocate(1,nyrs_srv_2_paa_all,"multN_srv_2_paa_all");
srv_2_paa_all.allocate(1,nyrs_srv_2_paa_all,st_age,end_age,"srv_2_paa_all");
M.allocate(st_age,end_age,"M");
s_r_relat.allocate("s_r_relat");
nsel_lengths.allocate("nsel_lengths");
sel_lengths.allocate(1,nsel_lengths,"sel_lengths");
phase_fsh_sel.allocate("phase_fsh_sel");
phase_q.allocate(1,nsel_srv,"phase_q");
phase_srv_sel_age1.allocate(1,nsel_srv,"phase_srv_sel_age1");
phase_srv_sel_a1.allocate(1,nsel_srv,"phase_srv_sel_a1");
phase_srv_sel_b1.allocate(1,nsel_srv,"phase_srv_sel_b1");
phase_srv_sel_a2.allocate(1,nsel_srv,"phase_srv_sel_a2");
phase_srv_sel_b2.allocate(1,nsel_srv,"phase_srv_sel_b2");
age_trans_all.allocate(st_age,end_age,st_age,end_age,"age_trans_all");
age_len_trans.allocate(st_age,end_age,1,nsel_lengths,"age_len_trans");
maa_old.allocate(st_age,end_age);
maa.allocate(st_age,end_age);
waa_pop.allocate(st_age,end_age,"waa_pop");
waa_fsh.allocate(st_age,end_age,"waa_fsh");
waa_srv.allocate(1,nsel_srv,st_age,end_age,"waa_srv");
nyrs_proj.allocate("nyrs_proj");
init_M_proj.allocate(endyr+1,endyr+nyrs_proj,st_age,end_age,"init_M_proj");
nsubsample.allocate("nsubsample");
complex_flag.allocate("complex_flag");
future_rec_flag.allocate("future_rec_flag");
debug_flag.allocate("debug_flag");
catch_flag.allocate("catch_flag");
BRP_M_flag.allocate("BRP_M_flag");
if (catch_flag == 3)
{
ad_comm::change_datafile_name("future_catch.dat");
proj_catch_array.allocate(1,100,endyr+1,endyr+nyrs_proj,"proj_catch_array");
}
#define MAX_IDF_LINES 4096 // maximum number of lines in stock_assess_proj.dat
#define MAX_IDF_LINE_LEN 4096 // maximum line length of lines in stock_assess_proj.dat
#define MAX_BISECT_ITER 128 // maximum number of iterations for the bisection
#define BISECT_TOL 0.000001 // maximum tolerance for bisection
cout << "Data check" << endl;
cout << "nyrs_srv2\t" << nyrs_srv2 << endl;
cout << "srv_frac\t" << srv_frac << endl;
cout << "phase_q\t" << phase_q << endl;
cout << "nyrs_proj\t" << nyrs_proj << endl;
nsel_tot = nsel_fsh + nsel_srv;
nyears_simple = styr_fsh_sel - styr;
nyears_complex = endyr - styr_fsh_sel + 1;
nyears = endyr - styr + 1;
nages = end_age - st_age + 1;
first_rec_year = styr;
last_rec_year = endyr;
// styr_fsh_sel_dev = styr + 11; // HARDCODED - skip the years that BBB has random walk SD as 0.001
// rwlk_sd *= 3.0; // HARDCODED - test
// rwlk_sd(styr_fsh_sel_dev) *= 2.0; // HARDCODED - increase the SD for the first year used
styr_fsh_sel_dev = styr; // stop messing about with the rwlk_sd vector
if (s_r_relat == 1 || s_r_relat == 2 || s_r_relat == 3)
{
h_phase = 2;
}
else
{
h_phase = -2;
}
// map BBB maturity at age to (larger) maturity at age
maa_old.initialize();
maa.initialize();
maa_old = maa = 0.0;
if (trmage <= end_age)
{
maa_old(rcrage,trmage) = mat_old(rcrage,trmage);
maa(rcrage,trmage) = mat(rcrage,trmage);
if (trmage < end_age)
{
for (int a = (trmage + 1); a <= end_age; a++)
{
maa_old(a) = 1.0;
maa(a) = 1.0;
}
}
}
sigma_f = 1.0;
sigma_r = 1.0;
Tier3_alpha = 0.05;
mult_factor = 0.000001;
conv_factor = 1000000000.; // convert from kg to millions of metric tonnes
R0_mean = 1.0446e+009;
R0_stddev = 0.1 * R0_mean; // DDD-specified CV of 0.1
o = 0.00001;
mcmc_iter = 0;
}
void model_parameters::initializationfunction(void)
{
}
model_parameters::model_parameters(int sz,int argc,char * argv[]) :
model_data(argc,argv) , function_minimizer(sz)
{
initializationfunction();
log_R0.allocate(5.0,35.0,1,"log_R0");
log_h.allocate(-1.6,1.6,h_phase,"log_h");
log_q.allocate(-10.0,10.0,-1,"log_q");
log_q_fsh.allocate(1,nsel_fsh,-10.0,10.0,-1,"log_q_fsh");
log_q_srv_bs.allocate(-10.0,10.0,5,"log_q_srv_bs");
log_q_srv_ek.allocate(-10.0,10.0,5,"log_q_srv_ek");
log_q_srv.allocate(1,nsel_srv,-10.0,10.0,phase_q,"log_q_srv");
log_initR.allocate(5.0,35.0,1,"log_initR");
mean_log_Fmort.allocate(-10.0,10.0,1,"mean_log_Fmort");
log_Fmort_dev.allocate(styr,endyr,-10.0,10.0,2,"log_Fmort_dev");
log_rec_dev.allocate(first_rec_year,last_rec_year,-15.0,15.0,3,"log_rec_dev");
log_init_dev.allocate(st_age+1,end_age,-15.0,15.0,-2,"log_init_dev");
log_fsh_sel_cont_a1.allocate(0.0,2.0,phase_fsh_sel,"log_fsh_sel_cont_a1");
log_fsh_sel_cont_b1.allocate(-5.0,5.0,phase_fsh_sel,"log_fsh_sel_cont_b1");
log_fsh_sel_cont_a2.allocate(1.0,3.0,phase_fsh_sel,"log_fsh_sel_cont_a2");
log_fsh_sel_cont_b2.allocate(-5.0,5.0,phase_fsh_sel,"log_fsh_sel_cont_b2");
log_fsh_sel_a1.allocate(1,nsel_fsh,0.0,5.0,-phase_fsh_sel,"log_fsh_sel_a1");
log_fsh_sel_b1.allocate(1,nsel_fsh,-5.0,5.0,-phase_fsh_sel,"log_fsh_sel_b1");
log_fsh_sel_a2.allocate(1,nsel_fsh,1.0,5.0,-phase_fsh_sel,"log_fsh_sel_a2");
log_fsh_sel_b2.allocate(1,nsel_fsh,-5.0,5.0,-phase_fsh_sel,"log_fsh_sel_b2");
log_srv_sel_age1.allocate(1,nsel_srv,-15.0,1.0,phase_srv_sel_age1,"log_srv_sel_age1");
log_srv_sel_a1.allocate(1,nsel_srv,0.0,5.0,phase_srv_sel_a1,"log_srv_sel_a1");
log_srv_sel_b1.allocate(1,nsel_srv,-5.0,5.0,phase_srv_sel_b1,"log_srv_sel_b1");
log_srv_sel_a2.allocate(1,nsel_srv,1.0,5.0,phase_srv_sel_a2,"log_srv_sel_a2");
log_srv_sel_b2.allocate(1,nsel_srv,-5.0,5.0,phase_srv_sel_b2,"log_srv_sel_b2");
fsh_sel_cont_a1_dev.allocate(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel,"fsh_sel_cont_a1_dev");
fsh_sel_cont_b1_dev.allocate(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel,"fsh_sel_cont_b1_dev");
fsh_sel_cont_a2_dev.allocate(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel,"fsh_sel_cont_a2_dev");
fsh_sel_cont_b2_dev.allocate(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel,"fsh_sel_cont_b2_dev");
N.allocate(styr,endyr+1,st_age,end_age,"N");
#ifndef NO_AD_INITIALIZE
N.initialize();
#endif
C.allocate(styr,endyr,st_age,end_age,"C");
#ifndef NO_AD_INITIALIZE
C.initialize();
#endif
F.allocate(styr,endyr,st_age,end_age,"F");
#ifndef NO_AD_INITIALIZE
F.initialize();
#endif
Slen.allocate(1,nsel_tot+1,1,nsel_lengths,"Slen");
#ifndef NO_AD_INITIALIZE
Slen.initialize();
#endif
Sage.allocate(1,nsel_tot+1,st_age,end_age,"Sage");
#ifndef NO_AD_INITIALIZE
Sage.initialize();
#endif
Sage_fsh.allocate(styr,endyr,st_age,end_age,"Sage_fsh");
#ifndef NO_AD_INITIALIZE
Sage_fsh.initialize();
#endif
Z.allocate(styr,endyr,st_age,end_age,"Z");
#ifndef NO_AD_INITIALIZE
Z.initialize();
#endif
expZ.allocate(styr,endyr,st_age,end_age,"expZ");
#ifndef NO_AD_INITIALIZE
expZ.initialize();
#endif
expZsp.allocate(styr,endyr,st_age,end_age,"expZsp");
#ifndef NO_AD_INITIALIZE
expZsp.initialize();
#endif
expZfrac.allocate(1,nsel_srv,styr,endyr,st_age,end_age,"expZfrac");
#ifndef NO_AD_INITIALIZE
expZfrac.initialize();
#endif
initN.allocate(st_age,end_age,"initN");
#ifndef NO_AD_INITIALIZE
initN.initialize();
#endif
Fmort.allocate(styr,endyr,"Fmort");
#ifndef NO_AD_INITIALIZE
Fmort.initialize();
#endif
spawn_biomass.allocate(styr-1,endyr+1,"spawn_biomass");
#ifndef NO_AD_INITIALIZE
spawn_biomass.initialize();
#endif
total_biomass.allocate(styr-1,endyr+1,"total_biomass");
#ifndef NO_AD_INITIALIZE
total_biomass.initialize();
#endif
age_3_plus_biomass.allocate(styr-1,endyr+1,"age_3_plus_biomass");
#ifndef NO_AD_INITIALIZE
age_3_plus_biomass.initialize();
#endif
estsrvbio_bs.allocate(styr,endyr,"estsrvbio_bs");
#ifndef NO_AD_INITIALIZE
estsrvbio_bs.initialize();
#endif
estsrvbio_ek.allocate(styr,endyr,"estsrvbio_ek");
#ifndef NO_AD_INITIALIZE
estsrvbio_ek.initialize();
#endif
estsrvbio.allocate(1,nsel_srv,styr,endyr,"estsrvbio");
#ifndef NO_AD_INITIALIZE
estsrvbio.initialize();
#endif
fsh_sel_cont_a1.allocate("fsh_sel_cont_a1");
#ifndef NO_AD_INITIALIZE
fsh_sel_cont_a1.initialize();
#endif
fsh_sel_cont_b1.allocate("fsh_sel_cont_b1");
#ifndef NO_AD_INITIALIZE
fsh_sel_cont_b1.initialize();
#endif
fsh_sel_cont_a2.allocate("fsh_sel_cont_a2");
#ifndef NO_AD_INITIALIZE
fsh_sel_cont_a2.initialize();
#endif
fsh_sel_cont_b2.allocate("fsh_sel_cont_b2");
#ifndef NO_AD_INITIALIZE
fsh_sel_cont_b2.initialize();
#endif
fsh_sel_a1.allocate(1,nsel_fsh,"fsh_sel_a1");
#ifndef NO_AD_INITIALIZE
fsh_sel_a1.initialize();
#endif
fsh_sel_b1.allocate(1,nsel_fsh,"fsh_sel_b1");
#ifndef NO_AD_INITIALIZE
fsh_sel_b1.initialize();
#endif
fsh_sel_a2.allocate(1,nsel_fsh,"fsh_sel_a2");
#ifndef NO_AD_INITIALIZE
fsh_sel_a2.initialize();
#endif
fsh_sel_b2.allocate(1,nsel_fsh,"fsh_sel_b2");
#ifndef NO_AD_INITIALIZE
fsh_sel_b2.initialize();
#endif
srv_sel_age1.allocate(1,nsel_srv,"srv_sel_age1");
#ifndef NO_AD_INITIALIZE
srv_sel_age1.initialize();
#endif
srv_sel_a1.allocate(1,nsel_srv,"srv_sel_a1");
#ifndef NO_AD_INITIALIZE
srv_sel_a1.initialize();
#endif
srv_sel_b1.allocate(1,nsel_srv,"srv_sel_b1");
#ifndef NO_AD_INITIALIZE
srv_sel_b1.initialize();
#endif
srv_sel_a2.allocate(1,nsel_srv,"srv_sel_a2");
#ifndef NO_AD_INITIALIZE
srv_sel_a2.initialize();
#endif
srv_sel_b2.allocate(1,nsel_srv,"srv_sel_b2");
#ifndef NO_AD_INITIALIZE
srv_sel_b2.initialize();
#endif
R0.allocate("R0");
#ifndef NO_AD_INITIALIZE
R0.initialize();
#endif
h.allocate("h");
#ifndef NO_AD_INITIALIZE
h.initialize();
#endif
steepness.allocate("steepness");
#ifndef NO_AD_INITIALIZE
steepness.initialize();
#endif
q.allocate("q");
#ifndef NO_AD_INITIALIZE
q.initialize();
#endif
q_fsh.allocate(1,nsel_fsh,"q_fsh");
#ifndef NO_AD_INITIALIZE
q_fsh.initialize();
#endif
q_srv_bs.allocate("q_srv_bs");
#ifndef NO_AD_INITIALIZE
q_srv_bs.initialize();
#endif
q_srv_ek.allocate("q_srv_ek");
#ifndef NO_AD_INITIALIZE
q_srv_ek.initialize();
#endif
q_srv.allocate(1,nsel_srv,"q_srv");
#ifndef NO_AD_INITIALIZE
q_srv.initialize();
#endif
initR.allocate("initR");
#ifndef NO_AD_INITIALIZE
initR.initialize();
#endif
pred_catch.allocate(styr,endyr,"pred_catch");
#ifndef NO_AD_INITIALIZE
pred_catch.initialize();
#endif
pred_fsh_paa_all.allocate(styr,endyr,st_age,end_age,"pred_fsh_paa_all");
#ifndef NO_AD_INITIALIZE
pred_fsh_paa_all.initialize();
#endif
pred_fsh_paa.allocate(styr,endyr,rcrage,trmage,"pred_fsh_paa");
#ifndef NO_AD_INITIALIZE
pred_fsh_paa.initialize();
#endif
pred_srv_paa_all.allocate(1,nsel_srv,styr,endyr,st_age,end_age,"pred_srv_paa_all");
#ifndef NO_AD_INITIALIZE
pred_srv_paa_all.initialize();
#endif
pred_srv_paa.allocate(1,nsel_srv,styr,endyr,rcrage,trmage,"pred_srv_paa");
#ifndef NO_AD_INITIALIZE
pred_srv_paa.initialize();
#endif
pred_fsh_pal.allocate(1,nyrslen_fsh,1,nbins1,"pred_fsh_pal");
#ifndef NO_AD_INITIALIZE
pred_fsh_pal.initialize();
#endif
pred_srv_1_pal.allocate(1,nyrslen_srv1,1,nbins3,"pred_srv_1_pal");
#ifndef NO_AD_INITIALIZE
pred_srv_1_pal.initialize();
#endif
pred_srv_2_pal.allocate(1,nyrslen_srv2,1,nbins2,"pred_srv_2_pal");
#ifndef NO_AD_INITIALIZE
pred_srv_2_pal.initialize();
#endif
pred_srv_3_pal.allocate(1,nyrslen_srv3,1,nbins2,"pred_srv_3_pal");
#ifndef NO_AD_INITIALIZE
pred_srv_3_pal.initialize();
#endif
N_proj.allocate(endyr+1,endyr+nyrs_proj+1,st_age,end_age,"N_proj");
#ifndef NO_AD_INITIALIZE
N_proj.initialize();
#endif
C_proj.allocate(endyr+1,endyr+nyrs_proj,st_age,end_age,"C_proj");
#ifndef NO_AD_INITIALIZE
C_proj.initialize();
#endif
F_proj.allocate(endyr+1,endyr+nyrs_proj,"F_proj");
#ifndef NO_AD_INITIALIZE
F_proj.initialize();
#endif
M_proj.allocate(endyr+1,endyr+nyrs_proj,st_age,end_age,"M_proj");
#ifndef NO_AD_INITIALIZE
M_proj.initialize();
#endif
Z_proj.allocate(endyr+1,endyr+nyrs_proj,st_age,end_age,"Z_proj");
#ifndef NO_AD_INITIALIZE
Z_proj.initialize();
#endif
expZ_proj.allocate(endyr+1,endyr+nyrs_proj,st_age,end_age,"expZ_proj");
#ifndef NO_AD_INITIALIZE
expZ_proj.initialize();
#endif
expZsp_proj.allocate(endyr+1,endyr+nyrs_proj,st_age,end_age,"expZsp_proj");
#ifndef NO_AD_INITIALIZE
expZsp_proj.initialize();
#endif
expZfrac_proj.allocate(1,nsel_srv,endyr+1,endyr+nyrs_proj,st_age,end_age,"expZfrac_proj");
#ifndef NO_AD_INITIALIZE
expZfrac_proj.initialize();
#endif
fsh_paa_all_proj.allocate(endyr,endyr+nyrs_proj,st_age,end_age,"fsh_paa_all_proj");
#ifndef NO_AD_INITIALIZE
fsh_paa_all_proj.initialize();
#endif
srv_paa_all_proj.allocate(1,nsel_srv,endyr+1,endyr+nyrs_proj,st_age,end_age,"srv_paa_all_proj");
#ifndef NO_AD_INITIALIZE
srv_paa_all_proj.initialize();
#endif
catch_proj.allocate(endyr+1,endyr+nyrs_proj,"catch_proj");
#ifndef NO_AD_INITIALIZE
catch_proj.initialize();
#endif
spawn_biomass_proj.allocate(endyr+1,endyr+nyrs_proj,"spawn_biomass_proj");
#ifndef NO_AD_INITIALIZE
spawn_biomass_proj.initialize();
#endif
total_biomass_proj.allocate(endyr+1,endyr+nyrs_proj,"total_biomass_proj");
#ifndef NO_AD_INITIALIZE
total_biomass_proj.initialize();
#endif