-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMODEL.tpl
More file actions
5334 lines (4856 loc) · 234 KB
/
MODEL.tpl
File metadata and controls
5334 lines (4856 loc) · 234 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
//Written by: Andre E. Punt
//Modified by: C. Allen Akselrud
//
// Updates of note:
// 2015-05-30:
// Added a fifth column to the tagging data (AIGKC)
// 2015-07-27
// Calculate F35 based on mid-year SSB
GLOBALS_SECTION
#define AGEMODEL 1
#define LENMODEL 2
#define AGELENMODEL 3
#include <admodel.h>
#include <time.h>
#include "statsLib.h"
ofstream CheckFile,OutFile1;
ifstream GradFile;
time_t start,finish;
long hour,minute,second;
double elapsed_time;
adstring_array fleet_names;
adstring hello;
// ===========================================================================
// ===========================================================================
double CheckBounds(const prevariable& xx, double lower, double upper)
{
RETURN_ARRAYS_INCREMENT();
int Status;
double Range;
Status = 0;
Range = upper - lower;
if (xx < lower+Range*0.01) Status = 1;
if (xx > upper-Range*0.01) Status = 2;
OutFile1 << lower << " " << upper << " ";
if (Status == 1) OutFile1 << "*l" << " ";
if (Status == 2) OutFile1 << "*u" << " ";
RETURN_ARRAYS_DECREMENT();
return (Status);
}
dvar_vector logistic(const dvector& x, const prevariable& a, const prevariable& b)
{
RETURN_ARRAYS_INCREMENT();
dvar_vector y;
int n1,n2,Isize; n1 = x.indexmin(); n2 = x.indexmax();
y=elem_div(mfexp(a*(x-b)), 1.0+mfexp(a*(x-b)));
//for (Isize=n1;Isize<=n2;Isize++) y(Isize) /= y(n2);
RETURN_ARRAYS_DECREMENT();
return (y);
}
dvar_vector logistic2(const dvector& x, const prevariable& a, const prevariable& b, const prevariable& c)
{
RETURN_ARRAYS_INCREMENT();
dvar_vector y;
y=c*elem_div(mfexp(a*(x-b)), 1.0+mfexp(a*(x-b)));
RETURN_ARRAYS_DECREMENT();
return (y);
}
dvar_vector logistic3(const dvector& x, const prevariable& a, const prevariable& b, const prevariable& c)
{
RETURN_ARRAYS_INCREMENT();
dvar_vector y;
int n1,n2,Isize; n1 = x.indexmin(); n2 = x.indexmax();
y=elem_div(mfexp(a*(x-b)), 1.0+mfexp(a*(x-b)));
for (Isize=n1;Isize<=n2;Isize++) y(Isize) = c*y(Isize)/y(n2);
RETURN_ARRAYS_DECREMENT();
return (y);
}
dvar_vector doublelogistic(const dvector& MidLen, const dvar_vector& sp,const double& binwidth2)
{
RETURN_ARRAYS_INCREMENT();
int Isize;
int n1,n2; n1 = MidLen.indexmin(); n2 = MidLen.indexmax();
dvar_vector y(n1,n2);
dvariable peak,upselex,downselex,final,point1,point2,peak2;
dvariable join1,join2,t1,t2;
dvariable t1min,t2min;
dvariable asc,dsc;
peak = sp(1);
upselex = exp(sp(3));
downselex = exp(sp(4));
final = sp(6);
point1 = 1.0/(1.0+mfexp(-sp(5)));
t1min = mfexp(-(square(MidLen(n1)-peak)/upselex));
peak2 = peak + binwidth2+ (0.99*MidLen(n2)-peak-binwidth2)/(1.+mfexp(-sp(2)));
point2 = 1.0/(1.0+mfexp(-final));
t2min = mfexp(-(square(MidLen(n2)-peak2)/downselex));
for (Isize=n1;Isize<=n2;Isize++)
{
t1 = MidLen(Isize)-peak; t2 = MidLen(Isize)-peak2;
join1 = 1.0/(1.0+mfexp(-(20.0*t1/(1.0+fabs(t1))))); // note the logit transform on t1 causes range of mfexp to be over -20 to 20
join2 = 1.0/(1.0+mfexp(-(20.0*t2/(1.0+fabs(t2)))));
if (sp(5) > -999)
{asc = point1+(1.0-point1)*(mfexp(-square(t1)/upselex)-t1min)/(1.0-t1min);}
else
{asc = mfexp(-square(t1)/upselex);}
if(sp(6) > -999)
{dsc = 1.0+(point2-1.0)*(mfexp(-square(t2)/downselex)-1.0)/(t2min-1.0);}
else
{dsc = mfexp(-square(t2)/downselex);}
y(Isize) = asc*(1.0-join1)+join1*(1.0-join2+dsc*join2);
}
RETURN_ARRAYS_DECREMENT();
return (y);
}
dvar_vector splineAEP(const dvector& x, const dvar_vector& V,const dvector& MidLen)
{
RETURN_ARRAYS_INCREMENT();
int Isize;
int n1,n2; n1 = MidLen.indexmin(); n2 = MidLen.indexmax();
dvar_vector y(n1,n2);
dvar_vector ders = spline(x,V,0,0);
for (Isize=n1;Isize<=n2;Isize++) y(Isize) = sqrt(square(splint(x,V,ders,MidLen(Isize))));
RETURN_ARRAYS_DECREMENT();
return (y);
}
dvariable GenPrior(const prevariable& xx, double mean, double SD, const int Type)
{
RETURN_ARRAYS_INCREMENT();
dvariable Outcome;
Outcome = 0;
if (Type == 1) Outcome = log(SD) + square(xx-mean)/(2.0*SD*SD);
RETURN_ARRAYS_DECREMENT();
return (Outcome);
}
// ===========================================================================
// ===========================================================================
TOP_OF_MAIN_SECTION
arrmblsize = 50000000;
gradient_structure::set_GRADSTACK_BUFFER_SIZE(450000000);
gradient_structure::set_CMPDIF_BUFFER_SIZE(30000000);
gradient_structure::set_MAX_NVAR_OFFSET(2000);
gradient_structure::set_NUM_DEPENDENT_VARIABLES(1000);
// arrmblsize = 50000000;
// gradient_structure::set_GRADSTACK_BUFFER_SIZE(900000000);
// gradient_structure::set_CMPDIF_BUFFER_SIZE(30000000);
// gradient_structure::set_MAX_NVAR_OFFSET(2000);
// gradient_structure::set_NUM_DEPENDENT_VARIABLES(1000);
time(&start);
CheckFile.open("Check.Out");
// ======================================================================================================================
// ======================================================================================================================
// ======================================================================================================================
DATA_SECTION
int IcntA;
int IfleetA;
int IyearA;
int IsexA;
int ItypeA;
int IsizeA;
int IageA;
int Ilen1A;
int Ilen2A;
int III;
int JJJ;
int IparCnt;
int BlockPnt;
int KKK;
int IsDataError;
!! IsDataError = 0;
int IsCTLError;
!! IsCTLError = 0;
number TotalA;
init_int Model_Type; // Select a type of model
init_int First_Year;
init_int Last_Year;
init_int Nsex;
init_int Nage;
int MaxAge
!! MaxAge = Nage*5;
!! if (MaxAge < 50) MaxAge = 50;
int NageEst
!! NageEst = Nage; if (NageEst < 20) NageEst = 20; // Trick to output growth curves
init_int NsizeDym;
int NsizeMax;
int NsizeAge;
!! if (Model_Type == AGEMODEL) { NsizeAge = NsizeDym; NsizeDym = 1; }
!! if (Model_Type == LENMODEL | Model_Type == AGELENMODEL) { NsizeAge = 0; }
!! if (Model_Type == LENMODEL) { Nage = 1; }
!! if (NsizeAge > NsizeDym) NsizeMax = NsizeAge; else NsizeMax = NsizeDym;
!! CheckFile << "NsizeDym NsizeAge NsizeMax" << endl << NsizeDym << " " << NsizeAge << " " << NsizeMax << endl;
init_int Nplatoon;
init_int NfishFleet;
init_int NsurveyFleet;
int Nfleet;
!! Nfleet = NfishFleet + NsurveyFleet;
// Read the timing of the survey fleets
vector SurveyTime(1,Nfleet);
!!for (IfleetA=NfishFleet+1;IfleetA<=Nfleet;IfleetA++)
!! *(ad_comm::global_datafile) >> SurveyTime(IfleetA);
init_adstring name_read_fleet;
imatrix iname_fleet(1,Nfleet,1,2);
!! CheckFile << name_read_fleet << endl;
LOCAL_CALCS
int k;
adstring_array CRLF; // Blank to terminate lines (not sure why this is needed...)
CRLF+="";
// Set whole array equal to 1 in case not enough names are read:
for(k=1;k<=Nfleet;k++)
{ iname_fleet(k,1)=1; iname_fleet(k,2)=1; }
k=1;
for(III=1;III<=strlen(name_read_fleet);III++)
{
if(adstring(name_read_fleet(III))==adstring(":"))
{ iname_fleet(k,2)=III-1; k++; iname_fleet(k,1)=III+1; }
}
iname_fleet(Nfleet,2)=strlen(name_read_fleet);
for(k=1;k<=Nfleet;k++)
{
fleet_names += name_read_fleet(iname_fleet(k,1),iname_fleet(k,2))+CRLF(1);
}
CheckFile << "fleet_names: " << fleet_names << endl;
CheckFile << "iname_fleet: " << iname_fleet << endl;
END_CALCS
init_int LengthClassType;
number Length1; // First Length
number LengthInc; // Length increment
vector InputLengthClass(1,NsizeMax+1);
!!if (LengthClassType == 1) *(ad_comm::global_datafile) >> Length1 >> LengthInc;
!!if (LengthClassType == 2)
!! for (IsizeA=1;IsizeA<=NsizeMax+1;IsizeA++) *(ad_comm::global_datafile) >> InputLengthClass(IsizeA);
// Treatment of missing data
init_int TreatMissF;
// Catch data specifications
init_matrix Catch_Specs(1,NfishFleet,1,3);
!! CheckFile << "Catch Specifications" << endl << Catch_Specs << endl;
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++)
!! if (Catch_Specs(IfleetA,3) != 1 & Catch_Specs(IfleetA,3) != 0)
!! { cout << "Retained / discarded for fleet " << IfleetA << " must be 0 or 1" << endl; IsDataError = 1; }
// Initial catch data
init_matrix InitialCinp(1,NfishFleet,0,3);
vector InitialC(1,NfishFleet);
vector SigmaIntC(1,NfishFleet);
ivector PhaseInitC(1,NfishFleet);
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++)
!! {
!! InitialC(IfleetA) = InitialCinp(IfleetA,1);
!! SigmaIntC(IfleetA) = InitialCinp(IfleetA,2);
!! PhaseInitC(IfleetA) = int(InitialCinp(IfleetA,3));
!! }
// Catch data input
int NestCatch;
!! NestCatch = 0;
matrix CatchFix(1,NfishFleet,First_Year,Last_Year);
imatrix CatchType(1,NfishFleet,First_Year,Last_Year);
!! CatchFix.initialize();
!! CatchType.initialize();
init_int Ncatches; // Number of catches
init_matrix CatchInput(1,Ncatches,1,4);
int PhaseMissingF;
ivector FleetMissF(1,NfishFleet);
!! CheckFile << "Catch Data" << endl;
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++) FleetMissF(IfleetA) = -1;
!! for (IcntA=1;IcntA<=Ncatches;IcntA++)
!! {
!! IyearA = int(CatchInput(IcntA,1)); IfleetA = int(CatchInput(IcntA,2));
!! CatchFix(IfleetA,IyearA) = CatchInput(IcntA,4)*Catch_Specs(IfleetA,2);
!! CatchType(IfleetA,IyearA) = int(CatchInput(IcntA,3));
!! CheckFile << IcntA << " " << CatchInput(IcntA) << " " << Catch_Specs(IfleetA,2) << " " << CatchFix(IfleetA,IyearA) << " " << CatchType(IfleetA,IyearA) << endl;
!! if (CatchInput(IcntA,4) < 0) { NestCatch += 1; if (TreatMissF==2) FleetMissF(IfleetA) = 1; }
!! }
!! CheckFile << "Number of missing Fs" << endl << NestCatch << endl;
!! CheckFile << "Number of fleets with missing Fs" << endl << FleetMissF << " " << sum(FleetMissF) << endl ;
!! PhaseMissingF = -1;
!! if (TreatMissF==1 || TreatMissF==3) PhaseMissingF = 1;
!! if (TreatMissF==4) PhaseMissingF = -1;
// Index Timing
init_imatrix IndexTiming(1,Nfleet,1,2); // Index timing
// Index data input
init_int NindexData; // Number of data points
init_matrix IndexInput(1,NindexData,1,4);
ivector IndexYear(1,NindexData);
ivector IndexFleet(1,NindexData);
matrix IndexData(1,NindexData,1,2);
!! CheckFile << "Index Data" << endl;
!! for (IcntA=1;IcntA<=NindexData;IcntA++)
!! {
!! IyearA = int(IndexInput(IcntA,1)); IfleetA = int(IndexInput(IcntA,2));
!! IndexYear(IcntA) = IyearA; IndexFleet(IcntA) = IfleetA;
!! IndexData(IcntA,1) = IndexInput(IcntA,3); IndexData(IcntA,2) = IndexInput(IcntA,4);
!! CheckFile << IcntA << " " << IndexInput(IcntA,1) << " " << IndexData(IcntA,1) << " " << IndexData(IcntA,2) << endl;
!! }
!!
// Discard data specifications
init_matrix Discard_Specs(1,NfishFleet,1,4);
!! CheckFile << "Discard Specifications" << endl << Discard_Specs << endl;
ivector Discard_units(1,NfishFleet);
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++) Discard_units(IfleetA) = int(Discard_Specs(IfleetA,2));
ivector Discard_type(1,NfishFleet);
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++) Discard_type(IfleetA) = int(Discard_Specs(IfleetA,4));
// Discard data input
init_int NdiscardData; // Number of data points
init_matrix DiscardInput(1,NdiscardData,1,5); // Basic data
ivector DiscardYear(1,NdiscardData);
ivector DiscardFleet(1,NdiscardData);
ivector DiscardSex(1,NdiscardData);
matrix DiscardData(1,NdiscardData,1,2);
!! CheckFile << "Discard Data" << endl;
!! for (IcntA=1;IcntA<=NdiscardData;IcntA++)
!! {
!! IyearA = int(DiscardInput(IcntA,1)); IfleetA = int(DiscardInput(IcntA,2)); IsexA = int(DiscardInput(IcntA,3));
!! DiscardYear(IcntA) = IyearA; DiscardFleet(IcntA) = IfleetA; DiscardSex(IcntA) = IsexA;
!! DiscardData(IcntA,1) = DiscardInput(IcntA,4)*Discard_Specs(IfleetA,3);
!! DiscardData(IcntA,2) = DiscardInput(IcntA,5);
!! CheckFile << IcntA << " " << DiscardInput(IcntA) << " " << Discard_Specs(IfleetA,3) << " " << Discard_Specs(IfleetA,4) << " " << DiscardData(IcntA,1) << " " << DiscardData(IcntA,2) << endl;
!! }
// Effort data input
init_int NeffortData; // Number of data points
init_matrix EffortInput(1,NeffortData,1,4); // Basic data
ivector EffortYear(1,NeffortData);
ivector EffortFleet(1,NeffortData);
matrix EffortData(1,NeffortData,1,2);
imatrix EffortByYear(1,NfishFleet,First_Year,Last_Year);
vector MaxEffortByFleet(1,NfishFleet); // Maximum effort for this fleet
!! CheckFile << "Effort Data" << endl;
!! for (IcntA=1;IcntA<=NeffortData;IcntA++)
!! {
!! IyearA = int(EffortInput(IcntA,1)); IfleetA = int(EffortInput(IcntA,2));
!! EffortYear(IcntA) = IyearA; EffortFleet(IcntA) = IfleetA;
!! EffortData(IcntA,1) = EffortInput(IcntA,3); EffortData(IcntA,2) = EffortInput(IcntA,4);
!! EffortByYear(IfleetA,IyearA) = EffortInput(IcntA,3);
!! CheckFile << IcntA << " " << EffortData(IcntA,1) << " " << EffortData(IcntA,2) << endl;
!! if (EffortInput(IcntA,3) > MaxEffortByFleet(IfleetA)) MaxEffortByFleet(IfleetA) = EffortInput(IcntA,3);
!! if (EffortData(IcntA,1) <=0 || EffortData(IcntA,2) <=0) { cout << "Effort or its CV cannot be zero" << endl; exit(1); }
!! }
// Length comp data
init_int NlengthData // Number of data points
init_int LengthCompLike;
init_matrix LengthData(1,NlengthData,-4,Nsex*NsizeMax)
!! CheckFile << "Length data" << endl << LengthData << endl;
ivector LengthDataYear(1,NlengthData);
ivector LengthDataFleet(1,NlengthData);
ivector LengthDataSex(1,NlengthData);
ivector LengthDataType(1,NlengthData);
vector LengthDataSS(1,NlengthData);
!! for (IcntA=1;IcntA<=NlengthData;IcntA++)
!! {
!! IyearA = int(LengthData(IcntA,-4)); IfleetA = int(LengthData(IcntA,-3));
!! IsexA = int(LengthData(IcntA,-2)); ItypeA = int(LengthData(IcntA,-1));
!! if (IfleetA > NfishFleet & ItypeA != 0) { CheckFile << "Error Survey data for fleet " << IfleetA << " In year " << IyearA << " should be 0" << endl; IsDataError = 1; }
!! LengthDataYear(IcntA) = IyearA; LengthDataFleet(IcntA) = IfleetA;
!! LengthDataSex(IcntA) = IsexA; LengthDataType(IcntA) = ItypeA;
!! LengthDataSS(IcntA) = LengthData(IcntA,0);
!! TotalA = 0;
!! for (IsizeA=1;IsizeA<=Nsex*NsizeMax;IsizeA++) TotalA += LengthData(IcntA,IsizeA);
!! for (IsizeA=1;IsizeA<=Nsex*NsizeMax;IsizeA++) LengthData(IcntA,IsizeA) /= TotalA;
!! }
!! CheckFile << "Length data" << endl << LengthData << endl;
imatrix LenMinMax(1,NlengthData,1,4);
init_number PlusMinus;
// Age-length comp data
init_int NagelengthData;
!! CheckFile << "NagelengthData: " << NagelengthData << endl;
init_int AgeCompLike;
init_matrix AgeLengthData(1,NagelengthData,-6,Nsex*Nage+Nsex)
!! CheckFile << "AgeLength data" << endl << AgeLengthData << endl;
ivector AgeLengthDataYear(1,NagelengthData);
ivector AgeLengthDataFleet(1,NagelengthData);
ivector AgeLengthDataSex(1,NagelengthData);
ivector AgeLengthDataType(1,NagelengthData);
ivector AgeLengthDataLen1(1,NagelengthData);
ivector AgeLengthDataLen2(1,NagelengthData);
vector AgeLengthDataSS(1,NagelengthData);
!! for (IcntA=1;IcntA<=NagelengthData;IcntA++)
!! {
!! IyearA = int(AgeLengthData(IcntA,-6)); IfleetA = int(AgeLengthData(IcntA,-5));
!! IsexA = int(AgeLengthData(IcntA,-4)); ItypeA = int(AgeLengthData(IcntA,-3));
!! Ilen1A = int(AgeLengthData(IcntA,-2)); Ilen2A = int(AgeLengthData(IcntA,-1));
!! if (IfleetA > NfishFleet & ItypeA != 0) { CheckFile << "Error Survey data for fleet " << IfleetA << " In year " << IyearA << " should be 0" << endl; IsDataError = 1; }
!! AgeLengthDataYear(IcntA) = IyearA; AgeLengthDataFleet(IcntA) = IfleetA;
!! AgeLengthDataSex(IcntA) = IsexA; AgeLengthDataType(IcntA) = ItypeA;
!! AgeLengthDataLen1(IcntA) = Ilen1A; AgeLengthDataLen2(IcntA) = Ilen2A;
!! AgeLengthDataSS(IcntA) = AgeLengthData(IcntA,0);
!! TotalA = 0;
!! for (IageA=1;IageA<=Nsex*(Nage+1);IageA++) TotalA += AgeLengthData(IcntA,IageA);
!! for (IageA=1;IageA<=Nsex*(Nage+1);IageA++) AgeLengthData(IcntA,IageA) /= TotalA;
!! }
!! CheckFile << "AgeLength data" << endl << AgeLengthData << endl;
!! CheckFile << "AgeLength data complete" << endl;
// Mean size-at-age data
init_int NmeansizeData;
ivector MeanSizeDataYear(1,NmeansizeData);
ivector MeanSizeDataFleet(1,NmeansizeData);
ivector MeanSizeDataSex(1,NmeansizeData);
matrix MeanSizeData(1,NmeansizeData,1,Nsex*Nage+Nsex);
matrix MeanSizeDataSS(1,NmeansizeData,1,Nsex*Nage+Nsex);
!! for (IcntA=1;IcntA<=NmeansizeData;IcntA++)
!! {
!! *(ad_comm::global_datafile) >> MeanSizeDataYear(IcntA) >> MeanSizeDataFleet(IcntA) >> MeanSizeDataSex(IcntA);
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! for (IageA=0;IageA<=Nage;IageA++) *(ad_comm::global_datafile) >> MeanSizeData(IcntA,(IsexA-1)*(Nage+1)+IageA+1);
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! for (IageA=0;IageA<=Nage;IageA++) *(ad_comm::global_datafile) >> MeanSizeDataSS(IcntA,(IsexA-1)*(Nage+1)+IageA+1);
!! }
!! CheckFile << "MeanSize data" << endl << MeanSizeData << endl;
!! CheckFile << "MeanSize data complete" << endl;
// Tagging data
init_int NtagData;
init_int TagYear;
int NTagDiag2;
init_matrix TagData(1,NtagData,1,5);
vector TagOffset(1,NtagData);
!! CheckFile << "Tagging data" << endl << TagData << endl;
init_int CheckSum;
!! if (CheckSum != 12345678) { cout << "CheckSum Error Dat File " << CheckSum << endl; exit(1); }
!! if (IsDataError != 0) { cout << "Errors detected in DAT file; stopping; look at Check.Out" << endl; exit(1); }
!! cout << "Completed Data Read-in" << endl;
// ========================================================================================================================
// ========================== CTL FILE ====================================================================================
// ========================================================================================================================
!! ad_comm::change_datafile_name("model.ctl");
init_int Nblock; // Number of blocks
imatrix Blocks(0,999,First_Year,Last_Year+1);
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++) Blocks(0,IyearA) = 1;
!! for (IcntA=1;IcntA<=Nblock;IcntA++) for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)*(ad_comm::global_datafile) >> Blocks(IcntA,IyearA);
ivector BlocksCnt(0,999);
!! BlocksCnt.initialize();
!! for (IcntA=1;IcntA<=Nblock;IcntA++)
!! {
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! if (Blocks(IcntA,IyearA) > BlocksCnt(IcntA)) BlocksCnt(IcntA) = Blocks(IcntA,IyearA);
!! CheckFile << "Blocks" << Blocks(IcntA) << endl;
!! for (III=1;III<=BlocksCnt(IcntA);III++)
!! {
!! JJJ=0;
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! if (Blocks(IcntA,IyearA) == III) JJJ = 1;
!! if (JJJ ==0) { cout << "Expected " << BlocksCnt(IcntA) << " years for block " << IcntA << endl; exit(1); }
!! }
!! BlocksCnt(IcntA) -= 1;
!! }
!! CheckFile << "BlocksCnt" << endl << BlocksCnt << endl;
init_int MatOpt; // Maturity Option
init_int MatAgeLen; // Maturity Option
init_int GrowthOpt; // Growth Option
init_int BiolOffset; // Biological parameters are offsets (1)
init_int SigmaOrCV; // Parameterized in terms of a CV (1) or sigma (2)?
init_int Jump; // Max size classes
//!! Jump = 15;
init_matrix RecPlat(1,Nsex,1,Nplatoon); // Allocation of recruits to platoons
init_number PropWith; // Proportion of growth within and between
!! if (Nplatoon==1) PropWith = 0;
// Spline specifications for maturity
int xknotsMat; // Knots for Spline
!! if (MatOpt == 2) *(ad_comm::global_datafile) >> xknotsMat; else xknotsMat = 1;
ivector xvalsMatL(1,xknotsMat);
!! if (MatOpt == 2) *(ad_comm::global_datafile) >> xvalsMatL;
// Set the base parameters
int NBiolPar // Number of parameters (total)
!! NBiolPar = 2; // Sex Ratio and Phi
!! NBiolPar += 2*Nsex; // Length-weight
!! NBiolPar += 2*Nsex; // Natural mortality
!! if (GrowthOpt == 1) NBiolPar += 3*Nsex; // Vonbert Growth
!! if (GrowthOpt == 2) NBiolPar += 7*Nsex; // Linear (with molt prob) {len1; len2; molt1; molt2; growth1; growth2}
!! if (GrowthOpt == 3) NBiolPar += 7*Nsex; // Curvalinear (with molt prob) {len1; len2; molt1; molt2; growth1; growth2}
!! if (GrowthOpt == 4) NBiolPar += 7*Nsex; // Linear (with molt prob) {len1; len2; molt1; molt2; growth1; growth2}
!! if (GrowthOpt == 5) NBiolPar += 7*Nsex; // Curvalinear (with molt prob) {len1; len2; molt1; molt2; growth1; growth2}
!! if (GrowthOpt == 6) NBiolPar += 7*Nsex; // Linear (with molt prob) {len1; len2; molt1; molt2; growth1; growth2}
!! if (GrowthOpt == 7) NBiolPar += 7*Nsex; // Curvalinear (with molt prob) {len1; len2; molt1; molt2; growth1; growth2}
!! if (MatOpt == 1) NBiolPar += 3*Nsex;
!! if (MatOpt == 2) NBiolPar += Nsex*xknotsMat;
!! CheckFile << "Initial number of Biological Parameters = " << NBiolPar << endl;
imatrix BiolInt(1,1000,1,6);
matrix BiolReal(1,1000,1,6);
!! JJJ = 0;
!! for (IcntA=1;IcntA<=NBiolPar;IcntA++)
!! {
!! JJJ += 1;
!! KKK = JJJ;
!! *(ad_comm::global_datafile) >> BiolReal(KKK,1) >> BiolReal(KKK,2) >> BiolReal(KKK,3) >> BiolInt(KKK,1);
!! *(ad_comm::global_datafile) >> BiolInt(KKK,6) >> BiolReal(KKK,5) >> BiolReal(KKK,6);
!! *(ad_comm::global_datafile) >> BiolInt(KKK,2) >> BiolInt(KKK,3) >> BiolInt(KKK,4) >> BiolInt(KKK,5) >> BiolReal(KKK,4);
!! if (BiolInt(KKK,3) != 0)
!! {
!! if (BiolInt(KKK,4) < First_Year+1) { cout << "WARNING: A biological dev vector starts before " << First_Year+1 << endl; exit(1); }
!! if (BiolInt(KKK,4) > Last_Year) { cout << "WARNING: A biological dev vector ends after " << Last_Year << endl; exit(1); }
!! }
!! BlockPnt = BiolInt(KKK,2);
!! if (BlockPnt > 0)
!! for (III=1;III<=BlocksCnt(BlockPnt);III++)
!! {
!! JJJ += 1;
!! *(ad_comm::global_datafile) >> BiolReal(JJJ,1) >> BiolReal(JJJ,2) >> BiolReal(JJJ,3) >> BiolInt(JJJ,1);
!! *(ad_comm::global_datafile) >> BiolInt(JJJ,6) >> BiolReal(JJJ,5) >> BiolReal(JJJ,6);
!! }
!! BlockPnt = BiolInt(KKK,3);
!! if (BlockPnt > 0)
!! for (III=BiolInt(KKK,4);III<=BiolInt(KKK,5);III++)
!! {
!! JJJ += 1;
!! BiolReal(JJJ,1) = -10; BiolReal(JJJ,2) = 10; BiolReal(JJJ,3) = 0; BiolInt(JJJ,1) = BiolInt(KKK,3);
!! BiolInt(JJJ,6) = 1; BiolReal(JJJ,5) = 0; BiolReal(JJJ,6) = BiolReal(KKK,4);
!! }
!! }
!! NBiolPar = JJJ;
!! CheckFile << "Adjusted number of Biological Parameters = " << NBiolPar << endl;
!! CheckFile << "Refer to Section B.2 (of the .ctl file) for Biological Parameter Names" << endl;
!! CheckFile << "Param Num" << " " << "Min" << " " << "Max" << " " << "Init Num" << " " << "Phase" << endl;
ivector BiolPhases(1,NBiolPar); // Phases
vector BiolInit(1,NBiolPar); // Initial values
vector BiolParMin(1,NBiolPar); // Lower bounds
vector BiolParMax(1,NBiolPar); // Upper bounds
!! for (IcntA=1;IcntA<=NBiolPar;IcntA++)
!! {
!! BiolInit(IcntA) = BiolReal(IcntA,3); BiolPhases(IcntA) = BiolInt(IcntA,1);
!! BiolParMin(IcntA) = BiolReal(IcntA,1); BiolParMax(IcntA) = BiolReal(IcntA,2);
!! CheckFile << IcntA << " " << BiolParMin(IcntA) << " " << BiolParMax(IcntA) << " " << BiolInit(IcntA) << " " << BiolPhases(IcntA) << endl;
!! }
int NSRPar;
!! NSRPar = 6; // SR pars
ivector SRPhases(1,NSRPar); // Phases
vector SRInit(1,NSRPar); // initial values
vector SRParMin(1,NSRPar); // Lower bounds
vector SRParMax(1,NSRPar); // Upper bounds
init_matrix SRParSet(1,NSRPar,1,4) // Stock-recruit parameter set up
init_int Last_Rec_size_Class; // Last recruitment size-class
!! if (Last_Rec_size_Class > NsizeDym) Last_Rec_size_Class = NsizeDym;
!! for (IcntA=1;IcntA<=NSRPar;IcntA++)
!! {
!! SRInit(IcntA) = SRParSet(IcntA,3); SRPhases(IcntA) = int(SRParSet(IcntA,4));
!! SRParMin(IcntA) = SRParSet(IcntA,1); SRParMax(IcntA) = SRParSet(IcntA,2);
!! }
!! CheckFile << "Stock and Recruitment Parameter Set" << endl << "R0 ; R1; Steepness ; SigmaR ; Alpha ; Beta" << endl << "Min Max Init Phase" << endl << SRParSet << endl;
!! CheckFile << "last class to which animals recruit: " << Last_Rec_size_Class << endl;
init_int RecEstYr1; // First year rec
int FirstProj_Yr; // First year of model projection
!! if (RecEstYr1 < First_Year) FirstProj_Yr = RecEstYr1-1; else FirstProj_Yr = First_Year-1;
!! FirstProj_Yr -= 2*NageEst;
init_int RecEstYr2; // Last year rec
init_int RecDevPhase; // Phase for rec_devs
!! CheckFile << "Recruitment estimation years: " << RecEstYr1 << " : " << RecEstYr2 << endl;
!! CheckFile << "First model projection year: " << FirstProj_Yr << endl;
init_int PhaseYr1; // Phase in
init_int PhaseYr2;
!! if (PhaseYr2 <= PhaseYr1) { cout << "PhaseY2 must be > PhaseY1: " << PhaseYr1 << " " << PhaseYr2 << endl; exit(1); }
init_int PhaseYr3;
init_int PhaseYr4; // Phase
!! if (PhaseYr4 <= PhaseYr3) { cout << "PhaseY4 must be > PhaseY3: " << PhaseYr3 << " " << PhaseYr4 << endl; exit(1); }
vector SigPhi(RecEstYr1,RecEstYr2);
init_int EarlyDevEnd; // When do the early devs end
init_number SigmaRecDev; // What is the sigma
init_int F_tune; // Number of times the hybrid method is applied
init_number max_harvest_rate; // Maximum harvest rate in the hybrid method
// Read in Initial Fs
init_matrix InitHrateParSet(1,NfishFleet,1,4) // Initial F Par Setup
!! CheckFile << "Initial Fs " << endl << InitHrateParSet << endl;
vector InitHrateInit(1,NfishFleet);
vector InitHrateMin(1,NfishFleet);
vector InitHrateMax(1,NfishFleet);
ivector InitHratePhases(1,NfishFleet);
!! for (IcntA=1;IcntA<=NfishFleet;IcntA++)
!! {
!! InitHrateInit(IcntA) = InitHrateParSet(IcntA,3); InitHratePhases(IcntA) = int(InitHrateParSet(IcntA,4));
!! InitHrateMin(IcntA) = InitHrateParSet(IcntA,1); InitHrateMax(IcntA) = InitHrateParSet(IcntA,2);
!! }
// Selectivity parameterizarion
init_int SelexParStyle;
!! CheckFile << "SelexParStyle " << SelexParStyle << endl;
// Read in age-selectivity specifications
3darray SelexASpex(1,Nfleet,1,Nsex,1,7);
matrix SelexLSpexR(1,Nfleet,1,Nsex) // Lambda
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! {
!! for (IcntA=1;IcntA<=7; IcntA++) *(ad_comm::global_datafile) >> SelexASpex(IfleetA,IsexA,IcntA);
!! *(ad_comm::global_datafile) >> SelexLSpexR(IfleetA,IsexA);
!! }
!! CheckFile << "SelexASpex = " << endl << SelexASpex << endl;
// Read in size-selectivity specifications
3darray SelexLSpex(1,Nfleet,1,Nsex,1,7);
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! for (IcntA=1;IcntA<=7; IcntA++) *(ad_comm::global_datafile) >> SelexLSpex(IfleetA,IsexA,IcntA);
!! CheckFile << "SelexLSpex" << endl << SelexLSpex << endl;
int BaseRetainAPars; // Basic retention parameters
int NRetainAPatterns; // Retention parameters
int BlockRetainAPars; // Retention parameters (blocks)
imatrix RetainAPnt(1,Nfleet*Nsex,First_Year,Last_Year+1); // Pointers between fleets and actual retain patterns
!! BaseRetainAPars = 0; BlockRetainAPars = 0; NRetainAPatterns = 0; IcntA = 0;
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! {
!! IparCnt = 0;
!! if (SelexASpex(IfleetA,IsexA,6) == 0) IparCnt = 0; // Flat Selex
!! if (SelexASpex(IfleetA,IsexA,6) == 1) IparCnt = 3; // Logistic
!! if (SelexASpex(IfleetA,IsexA,6) > 0) IcntA += 1;
!! if (Catch_Specs(IfleetA,3) == 0 & SelexASpex(IfleetA,IsexA,6) >=0)
!! { cout << "Age retained spec for fleet " << IfleetA << "must be -1 as all catch is discarded" << endl; IsCTLError = 1; }
!! BaseRetainAPars += IparCnt;
!! NRetainAPatterns += 1;
!! if (SelexASpex(IfleetA,IsexA,7) > 0) BlockRetainAPars += BlocksCnt(SelexASpex(IfleetA,IsexA,7))*IparCnt;
!! if (SelexASpex(IfleetA,IsexA,7) > 0) NRetainAPatterns += BlocksCnt(SelexASpex(IfleetA,IsexA,7));
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! if (SelexASpex(IfleetA,IsexA,7) > 0)
!! RetainAPnt((IfleetA-1)*Nsex+IsexA,IyearA) = IcntA + Blocks(SelexASpex(IfleetA,IsexA,7),IyearA)-1;
!! else
!! RetainAPnt((IfleetA-1)*Nsex+IsexA,IyearA) = IcntA;
!! }
!! if (SelexASpex(IfleetA,IsexA,7) > 0) IcntA += BlocksCnt(SelexASpex(IfleetA,IsexA,7));
!! }
!! CheckFile << "Base RetainPars (age) = " << BaseRetainAPars << endl;
!! CheckFile << "Number of retention (age) patterns = " << NRetainAPatterns << endl;
!! CheckFile << "Block RetainPars (age) = " << BlockRetainAPars << endl;
!! CheckFile << RetainAPnt << endl;
int BaseRetainLPars; // Basic retention parameters
int NRetainLPatterns; // Retention parameters
int BlockRetainLPars; // Retention parameters (blocks)
imatrix RetainLPnt(1,Nfleet*Nsex,First_Year,Last_Year+1); // Pointers between fleets and actual retain patterns
!! BaseRetainLPars = 0; BlockRetainLPars = 0; NRetainLPatterns = 0; IcntA = 0;
!! for (IfleetA=1;IfleetA<=NfishFleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! {
!! IparCnt = 0;
!! if (SelexLSpex(IfleetA,IsexA,6) == 0) IparCnt = 0; // Flat Selex
!! if (SelexLSpex(IfleetA,IsexA,6) == 1) IparCnt = 3; // Logistic
!! if (SelexLSpex(IfleetA,IsexA,6) > 0) IcntA += 1;
!! if (Catch_Specs(IfleetA,3) == 0 & SelexLSpex(IfleetA,IsexA,6) >=0)
!! { cout << "Length retained spec for fleet " << IfleetA << "must be -1 as all catch is discarded" << endl; IsCTLError = 1; }
!! BaseRetainLPars += IparCnt;
!! NRetainLPatterns += 1;
!! if (SelexLSpex(IfleetA,IsexA,7) > 0) BlockRetainLPars += BlocksCnt(SelexLSpex(IfleetA,IsexA,7))*IparCnt;
!! if (SelexLSpex(IfleetA,IsexA,7) > 0) NRetainLPatterns += BlocksCnt(SelexLSpex(IfleetA,IsexA,7));
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! if (SelexLSpex(IfleetA,IsexA,7) > 0)
!! RetainLPnt((IfleetA-1)*Nsex+IsexA,IyearA) = IcntA + Blocks(SelexLSpex(IfleetA,IsexA,7),IyearA)-1;
!! else
!! RetainLPnt((IfleetA-1)*Nsex+IsexA,IyearA) = IcntA;
!! }
!! if (SelexLSpex(IfleetA,IsexA,7) > 0) IcntA += BlocksCnt(SelexLSpex(IfleetA,IsexA,7));
!! }
!! CheckFile << "Base RetainPars (length)= " << BaseRetainLPars << endl;
!! CheckFile << "Number of retention (length) patterns " << NRetainLPatterns << endl;
!! CheckFile << "Block RetainPars (length) " << BlockRetainLPars << endl;
!! CheckFile << RetainLPnt << endl;
// Specifications for selectivity knots (age)
matrix xvalsSelexA(1,Nfleet,0,Nage) // Knots
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! if (SelexASpex(IfleetA,IsexA,1) == 3)
!! for (IcntA=1;IcntA<=nknotsSelexA(IfleetA);IcntA++)
!! *(ad_comm::global_datafile) >> xvalsSelexA(IfleetA,IcntA);
!! CheckFile << "Knots for age-specific selctivity" << endl;
!! CheckFile << "nknotsSelexA" << endl << nknotsSelexA << endl;
!! CheckFile << "xvalsSelexA" << endl << xvalsSelexA << endl;
// Specifications for selectivity knots (length)
matrix xvalsSelexL(1,Nfleet,1,NsizeMax) // Knots
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! if (SelexLSpex(IfleetA,IsexA,1) == 3)
!! for (IcntA=1;IcntA<=nknotsSelexL(IfleetA);IcntA++)
!! *(ad_comm::global_datafile) >> xvalsSelexL(IfleetA,IcntA);
!! CheckFile << "Knots for length-specific selctivity" << endl;
!! CheckFile << "nknotsSelexL" << endl << nknotsSelexL << endl;
!! CheckFile << "xvalsSelexL" << endl << xvalsSelexL << endl;
int LLL;
int MMM;
int IFound;
ivector Itest(1,10);
ivector Jtest(1,10);
// Read in selectivity parameters (ageh) (base)
imatrix SelexAInt(1,1000,1,6);
matrix SelexAReal(1,1000,1,6);
int BaseSelexAPars; // Basic selectivity parameters
int NSelexAPatterns; // Selectivity parameters
imatrix SelexAPnt(1,Nfleet*Nsex,First_Year,Last_Year+1); // Pointers between fleets and actual selex patterns
ivector nknotsSelexA(1,Nfleet) // Number of knots
!! nknotsSelexA.initialize();
!! SelexAReal.initialize();
!! NSelexAPatterns = 0; JJJ = 0;
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! SelexAPnt((IfleetA-1)*Nsex+IsexA,IyearA) = -1;
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! {
!! if (SelexASpex(IfleetA,IsexA,1) == 0) IparCnt = 0; // Flat Selex
!! if (SelexASpex(IfleetA,IsexA,1) == 1) IparCnt = 2; // Logistic
!! if (SelexASpex(IfleetA,IsexA,1) == 2) IparCnt = 6; // Double normal
!! if (SelexASpex(IfleetA,IsexA,1) == 3) { IparCnt = SelexASpex(IfleetA,IsexA,2); nknotsSelexA(IfleetA) = IparCnt; } // Spline
!! if (SelexASpex(IfleetA,IsexA,1) == 4) IparCnt = 3; // Logistic with extra parameter
!! if (SelexASpex(IfleetA,IsexA,1) == 5) IparCnt = 0; // Mirrored selectivity
!! if (SelexASpex(IfleetA,IsexA,1) == 5)
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! if (SelexASpex(IfleetA,IsexA,5) == 0 | SelexASpex(IfleetA,IsexA,5) == IsexA)
!! SelexAPnt((IfleetA-1)*Nsex+IsexA,IyearA) = SelexAPnt(SelexASpex(IfleetA,IsexA,3),IyearA);
!! else
!! SelexAPnt((IfleetA-1)*Nsex+IsexA,IyearA) = 0;
!! }
!! SelexASpex(IfleetA,IsexA,4) = IparCnt;
!! LLL = JJJ;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++)
!! {
!! JJJ += 1;
!! KKK = JJJ;
!! Jtest(IcntA) = KKK;
!! CheckFile << "Age-selex reading for fleet " << IfleetA << " and sex " << IsexA;
!! CheckFile << "; parameter is " << IcntA << " of " << IparCnt << endl;
!! *(ad_comm::global_datafile) >> SelexAReal(KKK,1) >> SelexAReal(KKK,2) >> SelexAReal(KKK,3) >> SelexAInt(KKK,1);
!! *(ad_comm::global_datafile) >> SelexAInt(KKK,6) >> SelexAReal(KKK,5) >> SelexAReal(KKK,6);
!! *(ad_comm::global_datafile) >> SelexAInt(KKK,2) >> SelexAInt(KKK,3) >> SelexAInt(KKK,4) >> SelexAInt(KKK,5) >> SelexAReal(KKK,4);
!! if (SelexAInt(KKK,3) != 0)
!! {
!! if (SelexAInt(KKK,4) < First_Year+1) { cout << "WARNING: An age-selectivity dev vector starts before " << First_Year+1 << "for " << IfleetA << " " << IsexA << endl; exit(1); }
!! if (SelexAInt(KKK,4) > Last_Year) { cout << "WARNING: An age-selectivity dev vector ends after " << Last_Year << endl; exit(1); }
!! }
!! CheckFile << SelexAReal(KKK) << " " << SelexAInt(KKK) << endl;
!! BlockPnt = SelexAInt(KKK,2);
!! if (BlockPnt > 0) CheckFile << "Need a block input here: " << BlockPnt << endl;
!! if (BlockPnt > 0)
!! for (III=1;III<=BlocksCnt(BlockPnt);III++)
!! {
!! JJJ += 1;
!! *(ad_comm::global_datafile) >> SelexAReal(JJJ,1) >> SelexAReal(JJJ,2) >> SelexAReal(JJJ,3) >> SelexAInt(JJJ,1);
!! CheckFile << "reading block offset" << III << endl;
!! }
!! BlockPnt = SelexAInt(KKK,3);
!! if (BlockPnt > 0)
!! {
!! Nblock = Nblock + 1;
!! SelexAInt(KKK,3) = Nblock;
!! SelexAInt(KKK,2) = Nblock;
!! MMM = 1;
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! if (IyearA < SelexAInt(KKK,4)) Blocks(Nblock,IyearA) = 1;
!! if (IyearA >=SelexAInt(KKK,4) & IyearA <=SelexAInt(KKK,5))
!! {
!! MMM += 1; JJJ += 1;
!! Blocks(Nblock,IyearA) = MMM;
!! SelexAReal(JJJ,1) = -10; SelexAReal(JJJ,2) = 10; SelexAReal(JJJ,3) = 0; SelexAInt(JJJ,1) = SelexAInt(JJJ,3);
!! SelexAReal(JJJ,4) = SelexAReal(KKK,4); SelexAInt(JJJ,1) = SelexAInt(KKK,1)+1;
!! }
!! if (IyearA > SelexAInt(KKK,5)) Blocks(Nblock,IyearA) = 1;
!! }
!! BlocksCnt(Nblock) = MMM-1;
!! }
!! }
// AEP FIX
!! if (SelexASpex(IfleetA,IsexA,1) != 5) NSelexAPatterns += 1;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++) Itest(IcntA) = Blocks(SelexAInt(Jtest(IcntA),2),First_Year);
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! IFound = 0;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++) if (Itest(IcntA)!= Blocks(SelexAInt(Jtest(IcntA),2),IyearA)) IFound = 1;
!! if (IFound == 1) NSelexAPatterns += 1;
!! if (SelexASpex(IfleetA,IsexA,1) != 5)
!! SelexAPnt((IfleetA-1)*Nsex+IsexA,IyearA) = NSelexAPatterns;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++) Itest(IcntA) = Blocks(SelexAInt(Jtest(IcntA),2),IyearA);
!! }
!! }
!! BaseSelexAPars = JJJ;
!! CheckFile << "Number of age selectivity patterns = " << NSelexAPatterns << endl;
!! CheckFile << "Base SelexPars (age) = " << BaseSelexAPars << endl;
!! CheckFile << SelexAPnt << endl;
vector SelexAInit(1,BaseSelexAPars);
vector SelexAParMin(1,BaseSelexAPars);
vector SelexAParMax(1,BaseSelexAPars);
ivector SelexAPhases(1,BaseSelexAPars);
!! for (IcntA=1;IcntA<=BaseSelexAPars;IcntA++)
!! {
!! SelexAInit(IcntA) = SelexAReal(IcntA,3); SelexAPhases(IcntA) = SelexAInt(IcntA,1);
!! SelexAParMin(IcntA) = SelexAReal(IcntA,1); SelexAParMax(IcntA) = SelexAReal(IcntA,2);
!! CheckFile << IcntA << " " << SelexAParMin(IcntA) << " " << SelexAParMax(IcntA) << " " << SelexAInit(IcntA) << " " << SelexAPhases(IcntA) << endl;
!! }
// Read in selectivity parameters (length) (base)
imatrix SelexLInt(1,1000,1,6);
matrix SelexLReal(1,1000,1,6);
// Read in selectivity parameters (length) (base)
int BaseSelexLPars; // Basic selectivity parameters
int NSelexLPatterns; // Selectivity parameters
imatrix SelexLPnt(1,Nfleet*Nsex,First_Year,Last_Year+1); // Pointers between fleets and actual selex patterns
ivector nknotsSelexL(1,Nfleet) // Number of knots
!! nknotsSelexL.initialize();
!! SelexLReal.initialize();
!! NSelexLPatterns = 0; JJJ = 0;
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! SelexLPnt((IfleetA-1)*Nsex+IsexA,IyearA) = -1;
!! for (IfleetA=1;IfleetA<=Nfleet;IfleetA++)
!! for (IsexA=1;IsexA<=Nsex;IsexA++)
!! {
!! if (SelexLSpex(IfleetA,IsexA,1) == 0) IparCnt = 0; // Flat Selex
!! if (SelexLSpex(IfleetA,IsexA,1) == 1) IparCnt = 2; // Logistic
!! if (SelexLSpex(IfleetA,IsexA,1) == 2) IparCnt = 6; // Double normal
!! if (SelexLSpex(IfleetA,IsexA,1) == 3) { IparCnt = SelexLSpex(IfleetA,IsexA,2); nknotsSelexL(IfleetA) = IparCnt; } // Spline
!! if (SelexLSpex(IfleetA,IsexA,1) == 4) IparCnt = 3; // Logistic with extra parameter
!! if (SelexLSpex(IfleetA,IsexA,1) == 5) IparCnt = 0; // Mirrored selectivity
!! if (SelexLSpex(IfleetA,IsexA,1) == 5)
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! if (SelexLSpex(IfleetA,IsexA,5) == 0 | SelexLSpex(IfleetA,IsexA,5) == IsexA)
!! SelexLPnt((IfleetA-1)*Nsex+IsexA,IyearA) = SelexLPnt(SelexLSpex(IfleetA,IsexA,3),IyearA);
!! else
!! SelexLPnt((IfleetA-1)*Nsex+IsexA,IyearA) = 0;
!! }
!! SelexLSpex(IfleetA,IsexA,4) = IparCnt;
!! LLL = JJJ;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++)
!! {
!! JJJ += 1;
!! KKK = JJJ;
!! Jtest(IcntA) = KKK;
!! CheckFile << "length-selex Reading for fleet " << IfleetA << " and sex " << IsexA;
!! CheckFile << "; parameter is " << IcntA << " of " << IparCnt << endl;
!! *(ad_comm::global_datafile) >> SelexLReal(KKK,1) >> SelexLReal(KKK,2) >> SelexLReal(KKK,3) >> SelexLInt(KKK,1);
!! *(ad_comm::global_datafile) >> SelexLInt(KKK,6) >> SelexLReal(KKK,5) >> SelexLReal(KKK,6);
!! *(ad_comm::global_datafile) >> SelexLInt(KKK,2) >> SelexLInt(KKK,3) >> SelexLInt(KKK,4) >> SelexLInt(KKK,5) >> SelexLReal(KKK,4);
!! if (SelexLInt(KKK,3) != 0)
!! {
!! if (SelexLInt(KKK,4) < First_Year+1) { cout << "WARNING: An length-selectivity dev vector starts before " << First_Year+1 << endl; exit(1); }
!! if (SelexLInt(KKK,4) > Last_Year) { cout << "WARNING: An length-selectivity dev vector ends after " << Last_Year << endl; exit(1); }
!! }
!! CheckFile << SelexLReal(KKK) << " " << SelexLInt(KKK) << endl;
!! BlockPnt = SelexLInt(KKK,2);
!! if (BlockPnt > 0) CheckFile << "Need a block input here: " << BlockPnt << endl;
!! if (BlockPnt > 0)
!! for (III=1;III<=BlocksCnt(BlockPnt);III++)
!! {
!! JJJ += 1;
!! *(ad_comm::global_datafile) >> SelexLReal(JJJ,1) >> SelexLReal(JJJ,2) >> SelexLReal(JJJ,3) >> SelexLInt(JJJ,1);
!! CheckFile << "reading block offset" << III << endl;
!! }
!! BlockPnt = SelexLInt(KKK,3);
!! if (BlockPnt > 0)
!! {
!! Nblock = Nblock + 1;
!! SelexLInt(KKK,3) = Nblock;
!! SelexLInt(KKK,2) = Nblock;
!! MMM = 1;
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! if (IyearA < SelexLInt(KKK,4)) Blocks(Nblock,IyearA) = 1;
!! if (IyearA >=SelexLInt(KKK,4) & IyearA <=SelexLInt(KKK,5))
!! {
!! MMM += 1; JJJ += 1;
!! Blocks(Nblock,IyearA) = MMM;
!! SelexLReal(JJJ,1) = -10; SelexLReal(JJJ,2) = 10; SelexLReal(JJJ,3) = 0; SelexLInt(JJJ,1) = SelexLInt(JJJ,3);
!! SelexLReal(JJJ,4) = SelexLReal(KKK,4); SelexLInt(JJJ,1) = SelexLInt(KKK,1)+1;
!! }
!! if (IyearA > SelexLInt(KKK,5)) Blocks(Nblock,IyearA) = 1;
!! }
!! BlocksCnt(Nblock) = MMM-1;
!! }
!! }
// AEP FIX
!! if (SelexLSpex(IfleetA,IsexA,1) != 5)NSelexLPatterns += 1;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++) Itest(IcntA) = Blocks(SelexLInt(Jtest(IcntA),2),First_Year);
!! CheckFile << IfleetA << " " << IsexA << " " << IparCnt << " "; for (IcntA=1;IcntA<=IparCnt;IcntA++) CheckFile << Itest(IcntA) << " "; CheckFile << endl;
!! for (IyearA=First_Year;IyearA<=Last_Year+1;IyearA++)
!! {
!! IFound = 0;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++) if (Itest(IcntA)!= Blocks(SelexLInt(Jtest(IcntA),2),IyearA)) IFound = 1;
!! if (IFound == 1) NSelexLPatterns += 1;
!! if (SelexLSpex(IfleetA,IsexA,1) != 5)
!! SelexLPnt((IfleetA-1)*Nsex+IsexA,IyearA) = NSelexLPatterns;
!! for (IcntA=1;IcntA<=IparCnt;IcntA++) Itest(IcntA) = Blocks(SelexLInt(Jtest(IcntA),2),IyearA);
!! }
!! }
!! BaseSelexLPars = JJJ;
!! CheckFile << "Number of length selectivity patterns = " << NSelexLPatterns << endl;
!! CheckFile << "Base SelexPars (length) = " << BaseSelexLPars << endl;
!! CheckFile << SelexLPnt << endl;
!! CheckFile << "Updated blocks" << endl;
!! for (IcntA=1;IcntA<=Nblock;IcntA++) CheckFile << Blocks(IcntA) << endl;
vector SelexLInit(1,BaseSelexLPars);
vector SelexLParMin(1,BaseSelexLPars);
vector SelexLParMax(1,BaseSelexLPars);
ivector SelexLPhases(1,BaseSelexLPars);
!! CheckFile << "Selectivity Parameters, Section B.5" << endl;
!! for (IcntA=1;IcntA<=BaseSelexLPars;IcntA++)
!! {
!! SelexLInit(IcntA) = SelexLReal(IcntA,3); SelexLPhases(IcntA) = SelexLInt(IcntA,1);
!! SelexLParMin(IcntA) = SelexLReal(IcntA,1); SelexLParMax(IcntA) = SelexLReal(IcntA,2);
!! CheckFile << IcntA << " " << SelexLParMin(IcntA) << " " << SelexLParMax(IcntA) << " " << SelexLInit(IcntA) << " " << SelexLPhases(IcntA) << endl;
!! }
// Read in Retention parameters (age) (base)
init_matrix RetainAParSet(1,BaseRetainAPars,1,4) // Selex Par Setup
!! CheckFile << "RetainAParSet = " << endl << RetainAParSet << endl;
vector RetainAInit(1,BaseRetainAPars);
vector RetainAParMin(1,BaseRetainAPars);
vector RetainAParMax(1,BaseRetainAPars);
ivector RetainAPhases(1,BaseRetainAPars);
!! for (IcntA=1;IcntA<=BaseRetainAPars;IcntA++)
!! {
!! RetainAInit(IcntA) = RetainAParSet(IcntA,3); RetainAPhases(IcntA) = int(RetainAParSet(IcntA,4));
!! RetainAParMin(IcntA) = RetainAParSet(IcntA,1); RetainAParMax(IcntA) = RetainAParSet(IcntA,2);
!! }
init_matrix RetainABlkParSet(1,BlockRetainAPars,1,4) // Selex Par Setup
!! CheckFile << "RetainABlkParSet = " << endl << RetainABlkParSet << endl;
vector RetainABlkInit(1,BlockRetainAPars);
vector RetainABlkParMin(1,BlockRetainAPars);
vector RetainABlkParMax(1,BlockRetainAPars);
ivector RetainABlkPhases(1,BlockRetainAPars);
!! for (IcntA=1;IcntA<=BlockRetainAPars;IcntA++)
!! {
!! RetainABlkInit(IcntA) = RetainABlkParSet(IcntA,3); RetainABlkPhases(IcntA) = int(RetainABlkParSet(IcntA,4));
!! RetainABlkParMin(IcntA) = RetainABlkParSet(IcntA,1); RetainABlkParMax(IcntA) = RetainABlkParSet(IcntA,2);
!! }
// Read in Retention parameters (length) (base)
init_matrix RetainLParSet(1,BaseRetainLPars,1,4) // Selex Par Setup
!! CheckFile << "RetainLParSet = " << endl << RetainLParSet << endl;
vector RetainLInit(1,BaseRetainLPars);
vector RetainLParMin(1,BaseRetainLPars);
vector RetainLParMax(1,BaseRetainLPars);
ivector RetainLPhases(1,BaseRetainLPars);
!! for (IcntA=1;IcntA<=BaseRetainLPars;IcntA++)
!! {
!! RetainLInit(IcntA) = RetainLParSet(IcntA,3); RetainLPhases(IcntA) = int(RetainLParSet(IcntA,4));
!! RetainLParMin(IcntA) = RetainLParSet(IcntA,1); RetainLParMax(IcntA) = RetainLParSet(IcntA,2);
!! }
init_matrix RetainLBlkParSet(1,BlockRetainLPars,1,4) // Selex Par Setup
!! CheckFile << "RetainLBlkParSet = " << endl << RetainLBlkParSet << endl;