forked from NOAA-EDAB/hydra_sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhydra_sim.tpl
3628 lines (3120 loc) · 184 KB
/
hydra_sim.tpl
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
// Copyright (c) 2008, 2009, 2010 Regents of the University of California.
//
// ADModelbuilder and associated libraries and documentations are
// provided under the general terms of the "BSD" license.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the University of California, Otter Research,
// nor the ADMB Foundation nor the names of its contributors may be used
// to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
// MultiSpecies Size Structured Assessment Model MS3AM
// based on LeMANS as modified by M. Fogarty and S. Gaichas
// coded by S. Gaichas, help from K. Curti, G. Fay, T. Miller
// testing version, February 2012
// initial working version, July 2012
//
// Renamed hydra_sim and modified for use as size structued simulation model
// operating model for testing produciton, nonlinear time series models
// May 2013
//
// Dec 29, 2016: Modified and extended by Andy Beet
// : see word doc, documenting changes
//=======================================================================================
GLOBALS_SECTION
//=======================================================================================
//Including C++ libraries
#include "statsLib.h"
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <sstream>
#include <time.h>
time_t baseTime;
clock_t startTime = clock();
// ofstream test("test.csv"); // for debugging only
ofstream gavjunk("gav.junk");
ofstream pmse_predvals("pmse_predvals.out");
//=======================================================================================
DATA_SECTION
//=======================================================================================
//Debug statements from Kiersten Curti's model
// 0's = Main body of program
// = 1: Exits after data section
// = 2: Exits after parameter section
// = 3: Exits at end of procedure section
// = 4: Prints checkpoints after each function in the procedure section, except those within the year loop
// = 5: Prints checkpoints after each function within the year loop
// = 6: Prints parameter estimates after each iteration
// = 7: Prints pop dy variables after each iteration
// = 8: Prints trophic matrices at end of year loop, then exits
// = 9: Prints out predicted indices that go into the objective function after each iteration
//10's = Initial states function
// = 10: Outputs food-selection parameters at the end of the function and then exits
// = 11: Outputs food selection paramters at the end of each iteration
// = 12: Outputs fishery and survey selectivity matrices at the end of the function and then exits
// = 13: Outputs abundance and biomass arrays and then exits
// = 14: Outputs Yr1, Age1 and iFt matrices to ensure 'means + devt'ns' parameterized correctly and then exits
// = 15: Outputs initial N and proportion mature arrays
//20's = Suitability function
// = 20: Output at end of function
// = 21: Output at end of function, then exits
// = 22: Outputs suitability and scaled suitability for each predator sp and then exits
// = 23: Outputs Eta, Sigma, WtRatio, G for pred, prey combos and then exits
//30's = Predation mortality function
// = 30: Prints checkpoints throughout the function
// = 31: Prints intermediate arrays (Avail, scAv, Consum) for each predator sp and then exits
// = 32: Prints intermediate arrays for each prey sp (Consum, sumCon) and then exits
// = 33: Prints sumCon and B right before M2 is calculated, and M2 after it is calculated
// = 34: Debug 31 but does not exit
// = 35: Prints nf and Other Food in every year
//40's = Population dynamics function
// = 40: Outputs N, C_hat and Cprop_hat at end of function
// = 41: Outputs N, C_hat and Cprop_hat at end of function and then exits
// = 42: Outputs mortality components for each species in each year and exits at end of year loop after trophic =1
// = 43: Outputs mortality components at end of function and then exits
//50's = Survey abundance function
// = 50: Prints intermediate arrays for species where survey data is one contiguous time series and then exits
// = 51: Prints intermediate arrays for species where the survey data is split into multiple segments and then exits
// = 52: Prints predicted q, FICs, FIC_hat and N for each species and then exits
// = 53: Prints estimated q matrix at the end of each iteration
//60's = Log likelihood function
// = 60: Prints checkpoints after each likelihood component
// = 61: Prints checkpoints for multinomial components within the year loop
// = 62: Prints predicted and log predicted indices for TotC and TotFIC
// = 63: Prints predicted and log predicted indices for Cprop
// = 64: Prints predicted and log predicted indices for Sprop
// = 65: FHprop, when added
// = 66: Prints summary of objective function components at end of each iteration
//70's = Food habits function
// = 70: Prints Avpd (scAv) and FHtmp for each predator, year and then exits
// = 71: Prints Avpd, Avpy for each prey species within Avpd, the colsum of Avpy, and FHtmp; exits after all predator species
// = 72: Prints bin years, FHtmp, FHsum, and average FH, FH_hat, for each FH bin, and exits after all predator species
// = 73: Prints total %W for each pred age, summed across prey sp, for each pred sp and FH bin. This value should always == 1.
//80's = Penalty functions
// = 80: Biomass penalty function: Prints pre- and post- B for every species and year, regardless of whether a penalty is imposed
// = 81: Biomass penalty function: Prints pre- and post- biomass and assorted arrays when biomass falls below threshold
// = 82: Yr1 penalty function: Prints avgZ, thYr1, Yr1 and Ypen arrays and then exits at end of function
// = 83: Recruitment penalty function: Prints Age1 parameter estimates, calculated CV and recruitment penalty
//take random number seeds from command line,
//code from https://groups.nceas.ucsb.edu/non-linear-modeling/projects/skate/ADMB/skatesim.tpl
//#1: spinydog
//#2: winterskate
//#3: Aherring
//#4: Acod
//#5: haddock
//#6: yellowtailfl
//#7: winterfl
//#8: Amackerel
//#9: silverhake
//#10: goosefish
int sim;
int rseed;
LOC_CALCS
int on,opt;
sim=0;
rseed=1;
// rseed=123456;
//the following line checks for the "-sim" command line option
//if it exists the if statement retreives the random number seed
//that is required for the simulation model
if((on=option_match(ad_comm::argc,ad_comm::argv,"-sim",opt))>-1)
{
sim=1;
rseed=atoi(ad_comm::argv[on+1]);
}
END_CALCS
init_int debug; //Debugger switch, 0 off, other above, now in dat file
//read in bounding indices from .dat file
init_int Nyrs //number of years
init_int Nspecies //number of species
init_int Nsizebins //number of size bins
init_int Nareas //number of areas
init_int Nfleets //number of fleets
init_int Nsurveys //number of surveys (e.g. NEFSC spring, NEFSC fall, NEAMAP, etc)
// init_int Nages //number of age classes
int Totsizebins
!! Totsizebins = Nspecies*Nsizebins;
int spp //loop counter species
int size //loop counter lengthbins
int area //loop counter areas
int pred //loop counter predators
int prey //loop counter prey
int t //loop counter timestep
int yr //loop counter year
int fleet //loop counter fleet
int Nstepsyr //model timesteps per year, set using max(growthprob_phi) below
int Tottimesteps //total timesteps for dimensioning state variable arrays
int yrct //year counter for dynamics
int iguild // loop counter in calc_survey_abundance
int iassess // loop counter in calc_assessment_strategy
int ithreshold // loop counter in calc_assessment_strategy
ivector maxThreshold(1,Nareas) // stored most severe threshold detected
int Nprey
!! Nprey = Nspecies + 1;
number o
!! o = 0.001; //small number to add before taking logs in objective function calcs
// should add 1 since log of 1 = 0. objecive function not changed! Andy Beet
init_number wtconv //multiply by weight in grams to desired units for biomass, catch
// time series data file
init_adstring datfilename;
//read in length bin sizes, weight at length parameters from .dat file
init_matrix binwidth(1,Nspecies,1,Nsizebins) //length bin width in cm
//init_3darray binwidth(1,Nareas,1,Nspecies,1,Nsizebins) //length bin width in cm, area specific
init_vector lenwt_a(1,Nspecies) //weight = lenwt_a * length ^ lenwt_b UNITS cm to g
init_vector lenwt_b(1,Nspecies) //weight = lenwt_a * length ^ lenwt_b UNITS cm to g
//init_matrix lenwt_a(1,Nareas,1,Nspecies) //weight = lenwt_a * length ^ lenwt_b, area specific
//init_matrix lenwt_b(1,Nareas,1,Nspecies) //weight = lenwt_a * length ^ lenwt_b, area specific
//calculate length and weight attributes of bins
//dimension all by area and add outside area loop to make these area specific
matrix lbinmax(1,Nspecies,1,Nsizebins) //upper end of length bins
matrix lbinmin(1,Nspecies,1,Nsizebins) //lower end of length bins
matrix lbinmidpt(1,Nspecies,1,Nsizebins) //midpoint of length bins
matrix wtbinmax(1,Nspecies,1,Nsizebins) //max weight of length bins
matrix wtbinmin(1,Nspecies,1,Nsizebins) //min weight of length bins
matrix wtatlbinmidpt(1,Nspecies,1,Nsizebins) //wt at length midpoint of length bins
matrix binavgwt(1,Nspecies,1,Nsizebins) //average weight for length bins
matrix powlbinmaxb(1,Nspecies,1,Nsizebins)
!! for (spp=1; spp<=Nspecies; spp++){
!! lbinmax(spp,1) = binwidth(spp,1);
!! lbinmin(spp,1) = 0.0; //lowest bin assumed to start at 0!
!! lbinmidpt(spp,1) = binwidth(spp,1)/2.0;
!! for (size=2; size<=Nsizebins; size++){
!! lbinmax(spp, size) = binwidth(spp, size) + lbinmax(spp, size-1);
!! lbinmin(spp, size) = lbinmax(spp, size-1);
!! lbinmidpt(spp, size) = binwidth(spp, size)/2.0 + lbinmax(spp, size-1);
!! }
!! wtbinmax(spp) = lenwt_a(spp)* pow(lbinmax(spp), lenwt_b(spp));
!! wtbinmin(spp) = lenwt_a(spp)* pow(lbinmin(spp), lenwt_b(spp));
!! wtatlbinmidpt(spp) = lenwt_a(spp)* pow(lbinmidpt(spp), lenwt_b(spp));
!! }
!! binavgwt = (wtbinmin + wtbinmax)/2.0;
//read in covariate information from .dat file
init_int Nrecruitment_cov //number of recruitment covariates
init_int Nmaturity_cov //number of maturity covariates
init_int Ngrowth_cov //number of growth covariates
init_matrix recruitment_cov(1,Nrecruitment_cov,1,Nyrs) //time series of recruitment covariates
init_matrix maturity_cov(1,Nmaturity_cov,1,Nyrs) //time series of maturity covariates
init_matrix growth_cov(1,Ngrowth_cov,1,Nyrs)
//time series of growth covariates
//init_3darray recruitment_cov(1,Nareas,1,Nrecruitment_cov,1,Nyrs) //time series of recruitment covariates, area specific
//init_3darray maturity_cov(1,Nareas,1,Nmaturity_cov,1,Nyrs) //time series of maturity covariates, area specific
//init_3darray growth_cov(1,Nareas,1,Ngrowth_cov,1,Nyrs) //time series of growth covariates, area specific
//read in survey and catch observations from .dat file
// SKG: for now, sub in Nsurveys for the unused Nareas dimension for input survey indices and comps
//init_3darray obs_survey_biomass(1,Nareas,1,Nspecies,1,Nyrs) //spring or fall? units needed
init_3darray obs_effort(1,Nareas,1,Nfleets,1,Nyrs) //standardized effort units needed
//init_4darray for survey size comp by area, species, year?
//init_4darray obs_survey_size(1,Nsurveys,1,Nspecies,1,Nyrs,1,Nsizebins) //numbers, uncomment when in dat file
//init_5darray for catch at size by area, species, fleet, year?
//read in mean stomach content weight time series from .dat file for intake calculation
init_4darray mean_stomwt(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins)
//want variance for this in this for fitting?
//read in temperature time series from .dat file for intake calculation
init_matrix obs_temp(1,Nareas,1,Nyrs) //want variance measure? data source?
//read in estimation phases from .dat file
init_int yr1Nphase //year 1 N at size estimation phase
init_int recphase //recruitment parameter estimation phase
init_int avg_rec_phase //average recruitment estimation phase (could make species specific, currently global)
init_int recsigmaphase // std dev of recruit resids phase (could make species specific, currently global)
init_int avg_F_phase //average fishing mort estimation phase (could make species specific, currently global)
init_int dev_rec_phase //recruitment deviation estimation phase (could make species specific, currently global)
init_int dev_F_phase //fishing mort deviation estimation phase (could make species specific, currently global)
init_int fqphase //fishery q estimation phase
init_int fsphase //fishery selectivity estimation phase
init_int sqphase //survey q estimation phase
init_int ssphase //survey selectivity estimation phase
init_int ssig_phase //survey sigma (obs error) phase
init_int csig_phase //catch sigma (obs error) phase
init_int m1_phase // M1 phase
init_int oF1_phase // amount of other food included in the M2 term for the base (predator 1) phase
init_int oFdev_phase //deviation from base other food for predators 2+ phase
init_int vuln_phase // phase for vulnerability parameters
//read in lists of species names, area names, fleet names, actual years from .dat file
//the following are parameters that will be fixed in initial runs, so read in as "data" from .dat
//to estimate any of them within the model, place in parameter section, initialize from .pin file
//recruitment parameters from .dat file
init_matrix recGamma_alpha(1,Nareas,1,Nspecies) //eggprod gamma Ricker model alpha
init_matrix recGamma_shape(1,Nareas,1,Nspecies) //eggprod gamma Ricker model shape parameter
init_matrix recGamma_beta(1,Nareas,1,Nspecies) //eggprod gamma Ricker model beta
init_matrix recDS_alpha(1,Nareas,1,Nspecies) //SSB Deriso-Schnute model alpha
init_matrix recDS_shape(1,Nareas,1,Nspecies) //SSB Deriso-Schnute model shape parameter
init_matrix recDS_beta(1,Nareas,1,Nspecies) //SSB Deriso-Schnute model beta
init_matrix recGamSSB_alpha(1,Nareas,1,Nspecies) //SSB gamma alpha
init_matrix recGamSSB_shape(1,Nareas,1,Nspecies) //SSB gamma shape parameter
init_matrix recGamSSB_beta(1,Nareas,1,Nspecies) //SSB gamma beta
init_matrix recRicker_alpha(1,Nareas,1,Nspecies) //SSB Ricker model alpha
init_matrix recRicker_shape(1,Nareas,1,Nspecies) //SSB Ricker model shape parameter=1.0 not used
init_matrix recRicker_beta(1,Nareas,1,Nspecies) //SSB Ricker model beta
init_matrix recBH_alpha(1,Nareas,1,Nspecies) //SSB Beverton Holt model alpha
init_matrix recBH_shape(1,Nareas,1,Nspecies) //SSB Beverton Holt model shape parameter=1.0 not used
init_matrix recBH_beta(1,Nareas,1,Nspecies) //SSB Beverton Holt model beta
init_matrix recShepherd_alpha(1,Nareas,1,Nspecies) //SSB Shepherd model alpha
init_matrix recShepherd_shape(1,Nareas,1,Nspecies) //SSB Shepherd model shape parameter=1.0 not used
init_matrix recShepherd_beta(1,Nareas,1,Nspecies) //SSB Shepherd model beta
init_matrix recHockey_alpha(1,Nareas,1,Nspecies) //SSB Hockey Stick model alpha
init_matrix recHockey_shape(1,Nareas,1,Nspecies) //SSB Hockey stick model shape (S*) breakpoint
init_matrix recHockey_beta(1,Nareas,1,Nspecies) //SSB Hockey Stick model beta parameter=1.0 not used
init_matrix recSegmented_alpha(1,Nareas,1,Nspecies) //SSB Segmented regression model alpha
init_matrix recSegmented_shape(1,Nareas,1,Nspecies) //SSB Segmented regression model shape. use this for the breakpoint
init_matrix recSegmented_beta(1,Nareas,1,Nspecies) //SSB Segmented regression model beta
init_ivector rectype(1,Nspecies) //switch for alternate recruitment functions
init_ivector stochrec(1,Nspecies) //switch for stochastic recruitment
matrix rec_alpha(1,Nareas,1,Nspecies)
matrix rec_shape(1,Nareas,1,Nspecies)
matrix rec_beta(1,Nareas,1,Nspecies)
//initialize recruitment parameters for each type (case 9 no functional form, dummy pars)
!! for (area=1; area<=Nareas; area++){
!! for(spp=1; spp<=Nspecies; spp++){
!! switch (rectype (spp)){
!! case 1: //egg production based recruitment, 3 par gamma (Ricker-ish)
!! rec_alpha(area,spp) = recGamma_alpha(area,spp);
!! rec_shape(area,spp) = recGamma_shape(area,spp);
!! rec_beta(area,spp) = recGamma_beta(area,spp);
!! break;
!! case 2: //SSB based recruitment, 3 par Deriso-Schnute; see Quinn & Deriso 1999 p 95
!! rec_alpha(area,spp) = recDS_alpha(area,spp);
!! rec_shape(area,spp) = recDS_shape(area,spp);
!! rec_beta(area,spp) = recDS_beta(area,spp);
!! break;
!! case 3: //SSB based recruitment, 3 par gamma
!! rec_alpha(area,spp) = recGamSSB_alpha(area,spp);
!! rec_shape(area,spp) = recGamSSB_shape(area,spp);
!! rec_beta(area,spp) = recGamSSB_beta(area,spp);
!! break;
!! case 4: //SSB based recruitment, 2 par Ricker
!! rec_alpha(area,spp) = recRicker_alpha(area,spp);
!! rec_shape(area,spp) = recRicker_shape(area,spp);
!! rec_beta(area,spp) = recRicker_beta(area,spp);
!! break;
!! case 5: //SSB based recruitment, 2 par BevHolt
!! rec_alpha(area,spp) = recBH_alpha(area,spp);
!! rec_shape(area,spp) = recBH_shape(area,spp);
!! rec_beta(area,spp) = recBH_beta(area,spp);
!! break;
!! case 6: // SSB based recruitment, 3 parameters Shepherd
!! rec_alpha(area,spp) = recShepherd_alpha(area,spp);
!! rec_shape(area,spp) = recShepherd_shape(area,spp);
!! rec_beta(area,spp) = recShepherd_beta(area,spp);
!! break;
!! case 7: // SSB based rcruitment. hockeyStick
!! rec_alpha(area,spp) = recHockey_alpha(area,spp);
!! rec_shape(area,spp) = recHockey_shape(area,spp);
!! rec_beta(area,spp) = recHockey_beta(area,spp);
!! break;
!! case 8: // SSB based recruitment,segmented regresion with breakpoint
!! rec_alpha(area,spp) = recSegmented_alpha(area,spp);
!! rec_shape(area,spp) = recSegmented_shape(area,spp);
!! rec_beta(area,spp) = recSegmented_beta(area,spp);
!! break;
!! case 9: //no functional form, uses average+devs in .pin file
!! rec_alpha(area,spp) = 0;
!! rec_shape(area,spp) = 0;
!! rec_beta(area,spp) = 0;
!! break;
!! default:
!! cout<<"undefined recruitment type, check .dat file"<<endl;
!! exit(1);
!! }
!! }
!! }
init_matrix sexratio(1,Nareas,1,Nspecies) //this is proportion female
init_matrix recruitment_covwt(1,Nspecies,1,Nrecruitment_cov) //recruitment covariate weighting factor
//init_3darray recruitment_covwt(1,Nareas,1,Nspecies,1,Nrecruitment_cov) //area specific weighting
//fecundity parameters from .dat file and calculate fecundity at length
init_matrix fecund_d(1,Nareas,1,Nspecies)
init_matrix fecund_h(1,Nareas,1,Nspecies)
init_3darray fecund_theta(1,Nareas,1,Nspecies,1,Nsizebins)
3darray fecundity(1,Nareas,1,Nspecies,1,Nsizebins)
!! for (area=1; area<=Nareas; area++){
!! for(spp=1; spp<=Nspecies; spp++){
!! fecundity(area, spp) = elem_prod(fecund_theta(area, spp),
!! (fecund_d(area, spp)
!! * pow(lbinmidpt(spp),fecund_h(area, spp))));
!! }
!! }
//maturity parameters from .dat file
init_matrix maturity_nu(1,Nareas,1,Nspecies)
init_matrix maturity_omega(1,Nareas,1,Nspecies)
init_matrix maturity_covwt(1,Nspecies,1,Nmaturity_cov)
matrix covariates_M(1,Nspecies,1,Nyrs) // intermediate calculation to obtain maturity covariates //AndyBeet
//growth parameters from .dat file and calculate simple (no cov) prob of growing through length interval
init_matrix growth_psi(1,Nareas,1,Nspecies) //power function growth length=psi*age^kappa
init_matrix growth_kappa(1,Nareas,1,Nspecies) //power function growth length=psi*age^kappa
init_matrix growth_covwt(1,Nspecies,1,Ngrowth_cov)
init_matrix vonB_Linf(1,Nareas,1,Nspecies) //alternate parameterization, vonB growth
init_matrix vonB_k(1,Nareas,1,Nspecies) //alternate parameterization, vonB growth
init_ivector growthtype(1,Nspecies) //switch for alternate growth types
init_number phimax
4darray growthprob_phi(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins)
vector delta_t(1,Nsizebins)
vector lmax_test(1,2);
number lmax_use
!! for (area=1; area<=Nareas; area++){
!! for(spp=1; spp<=Nspecies; spp++){
!! for(yr=1; yr<=Nyrs; yr++){
!! switch (growthtype (spp)){
!! case 1: //exponential no covariates
!! // these yimes of growing out of bin relative to size zero. SGaichas
!! delta_t = pow((lbinmax(spp)/growth_psi(area, spp)),(1.0/growth_kappa(area, spp)));
!! // these are "probabilities" of growing into size bin, r given in size bin r-1. ABeet
!! growthprob_phi(area, spp, yr,1) = 1/delta_t(1);
!! for (int isize=2;isize<=Nsizebins; isize++) {
!! growthprob_phi(area, spp, yr, isize) = 1/(delta_t(isize) - delta_t(isize-1));
!! }
!! break;
!! case 2: //exponential with covariates
!! // these "probabilitlies of growing out of bin relative to size zero. SGaichas
!! delta_t = pow((lbinmax(spp)/growth_psi(area, spp)* mfexp(growth_covwt(spp)*trans(growth_cov)(yr))),
!! (1.0/growth_kappa(area, spp)));
!! // these are "probabilities" of growing into size bin, r given in size bin r-1. ABeet
!! growthprob_phi(area, spp, yr,1) = 1/delta_t(1);
!! for (int isize=2;isize<=Nsizebins; isize++) {
!! growthprob_phi(area, spp, yr, isize) = 1/(delta_t(isize) - delta_t(isize-1));
!! }
!! break;
!! case 3: //VonB no covariates
// !! lmax_test(1) = 1e-09;
// !! for (size=1;size<=Nsizebins;size++) {
// !! lmax_test(2) = vonB_Linf(area, spp)-lbinmax(spp,size);
// !! lmax_use = max(lmax_test);
// !! cout << spp << " " << yr << " " << size << " " << lmax_use << endl;
// !! growthprob_phi(area, spp, yr, size) = vonB_k(area, spp)/log(
// !! ((vonB_Linf(area, spp)-lbinmin(spp,size))/
// !! (lmax_use)));
// !! }
!! for (size=1;size<=Nsizebins;size++) {
!! if (lbinmin(spp,size)>=vonB_Linf(area, spp) || lbinmax(spp,size)>=vonB_Linf(area, spp)) {
!! growthprob_phi(area, spp, yr, size) = 0.0;
!! }
!! if (lbinmax(spp,size)<vonB_Linf(area, spp)) {
!! growthprob_phi(area, spp, yr, size) = vonB_k(area, spp)/log(
!! (vonB_Linf(area, spp)-lbinmin(spp,size))/
!! (vonB_Linf(area, spp)-lbinmax(spp,size)));
!! }
!! }
// !! growthprob_phi(area, spp, yr) = vonB_k(area, spp)/log(
// !! elem_div((vonB_Linf(area, spp)-lbinmin(spp)),
// !! (vonB_Linf(area, spp)-lbinmax(spp))));
// !! cout << "Growthprob " << spp << " " << growthprob_phi(area,spp,yr) << endl;
!! break;
!! case 4: //VonB with covariates
!! growthprob_phi(area, spp, yr) = vonB_k(area, spp)/log(
!! elem_div((vonB_Linf(area, spp)*mfexp(growth_covwt(spp)*trans(growth_cov)(yr))-lbinmin(spp)),
!! (vonB_Linf(area, spp)*mfexp(growth_covwt(spp)*trans(growth_cov)(yr))-lbinmax(spp))));
!! break;
!! default:
!! cout<<"undefined growth type, check .dat file"<<endl;
!! exit(1);
!! }
!! growthprob_phi(area, spp, yr)(Nsizebins) = 0.0; //set prob of outgrowing highest bin to 0
!! double tempmax = max(growthprob_phi(area, spp, yr));
!! phimax = max(tempmax,phimax);
!! }
!! }
!! growthprob_phi(area) /= phimax; //rescale so no group has >1 prob growing out
!! }
!!// growthprob_phi /= phimax; //rescale so no group has >1 prob growing out--not working on 4d array
!! Nstepsyr = round(phimax); //set model timestep to phimax
!! Tottimesteps = Nstepsyr*Nyrs; //for scaling state variable arrays
//intake parameters from .dat file
init_matrix intake_alpha(1,Nareas,1,Nspecies)
init_matrix intake_beta(1,Nareas,1,Nspecies)
4darray intake(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins)
!! for (area=1; area<=Nareas; area++){
!! for(spp=1; spp<=Nspecies; spp++){
!! for(yr=1; yr<=Nyrs; yr++){
!! intake(area, spp, yr) = 24.0 * (intake_alpha (area, spp) *
!! mfexp(intake_beta (area, spp) * obs_temp (area,yr))) *
!! mean_stomwt(area, spp,yr) * //daily intake in g
!! 365.0 / //annual intake
!! Nstepsyr; //intake per model timestep
!! }
!! }
!! }
////natural mortality parameters from .dat file and calculate weight ratio, size preference, suitability
// init_3darray M1ann(1,Nareas,1,Nspecies,1,Nsizebins)
// 3darray M1(1,Nareas,1,Nspecies,1,Nsizebins)
// !! for (area=1; area<=Nareas; area++){
// !! for(spp=1; spp<=Nspecies; spp++){
// !! M1(area, spp) = 1.0 - pow((1.0 - M1ann(area, spp)), (1.0 / Nstepsyr)) ; //scale for steps per year to equal annual input from dat
//// !!!! M1(area, spp) = M1ann(area, spp)/Nstepsyr;
// !! }
// !! }
init_3darray isprey(1,Nareas,1,Nspecies,1,Nspecies) //preds in columns, prey in rows
int Npred
int Npreypar
!! Npreypar = 0;
!! Npred = 0;
!! Npreypar = sum(isprey(1));
!! for (spp=1;spp<=Nspecies;spp++) {
!! if(sum(extract_column(isprey(1),spp))>0) Npred += 1;
!! }
init_matrix preferred_wtratio(1,Nareas,1,Nspecies) //pred specific, not size
init_vector sd_sizepref(1,Nspecies) //pred specific, not size
4darray wtratio(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins) //2nd dim pred spp, 3rd all spp as prey lengths, 4th pred lengths
!! for (area=1; area<=Nareas; area++){
!! for (pred=1; pred<=Nspecies; pred++){
!! for(prey=1; prey<=Nspecies; prey++){
!! dmatrix wttemp = outer_prod(wtatlbinmidpt(prey), 1.0/wtatlbinmidpt(pred));// ijth = prey size i/pred size j
!! wttemp.rowshift(prey*Nsizebins-(Nsizebins-1));
!! // since wttemp is inserted into a larger matrix you need to set the .rowmin() property to the row it will be inseted into
!! wtratio(area, pred).sub(prey*Nsizebins-(Nsizebins-1), prey*Nsizebins) = wttemp;
!! }
!! }
!! } //
4darray sizepref(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins) //2nd dim pred spp, 3rd all spp as prey lengths, 4th pred lengths
!! // log normal distribution mu's and sigmas, read in. wtratioprey variable.
!! for (area=1; area<=Nareas; area++){
!! for (pred=1; pred<=Nspecies; pred++){
!! for(prey=1; prey<=Totsizebins; prey++){
!! for(int isize=1; isize<=Nsizebins; isize++){
!! double wtratioprey = wtratio(area, pred, prey, isize);
!! sizepref(area, pred, prey, isize) =
!! 1/(wtratioprey*sd_sizepref(pred)*sqrt(2*M_PI))*exp(-square(log(wtratioprey)-preferred_wtratio(area, pred))/(2*square(sd_sizepref(pred))));
!!
!!
!! }
!! }
!! }
!! } //ok
// GF - moved to procedure section
// 4darray suitability(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins)
// !! //suitability = sizepref * isprey
// !! for (area=1; area<=Nareas; area++){
// !! for (pred=1; pred<=Nspecies; pred++){
// !! for(prey=1; prey<=Nspecies; prey++){
// !! double sumOfSizePrefs = sum(sizepref(area,pred).sub(prey*Nsizebins-(Nsizebins-1), prey*Nsizebins));
// !! suitability(area, pred).sub(prey*Nsizebins-(Nsizebins-1), prey*Nsizebins) =
// !! sizepref(area, pred).sub(prey*Nsizebins-(Nsizebins-1), prey*Nsizebins)*
// !! // (sizepref(area, pred).sub(prey*Nsizebins-(Nsizebins-1), prey*Nsizebins)/sumOfSizePrefs)* // normalize rates
// !! isprey(area, prey, pred);
// !! }
// !! }
// !! }
// GF - moved to parameter section
// //fishery selectivity pars from dat file, for now not area specific
// init_matrix fishsel_c(1,Nspecies,1,Nfleets) //fishery selectivity c par
// init_matrix fishsel_d(1,Nspecies,1,Nfleets) //fishery selectivity d par
// All inputs below have been added by andyBeet
init_matrix B0(1,Nareas,1,Nspecies) // Equilibrium biomass. Obtained from a baseline run with zero fishing effort and no Errors added(recruitment, survey, catch)
init_int Nguilds // number of guilds
imatrix catchToDiscardsGuild(1,Nareas,1,Nguilds) // binary vector indicating which guilds have dropped below the most severe threshold
imatrix catchToDiscardsSpecies(1,Nareas,1,Nspecies) // binary vector indicating which species have dropped below the most severe threshold
imatrix maxGuildThreshold(1,Nareas,1,Nguilds) // most severe exceedence for each guild
imatrix maxSpeciesThreshold(1,Nareas,1,Nspecies) // most severe exceedence for each species. currently a binary response
init_ivector guildMembers(1,Nspecies) // assign each species to a guild. 1,2,3 etc.
init_ivector fleetMembers(1,Nguilds) // assign each guild to a fleet (1,2,...,Nfleets). A fleet that predominantly catches the guild
init_int AssessmentPeriod // time (yrs) when we assess guildlevel biomass levels
matrix B0_guilds(1,Nareas,1,Nguilds) // equilibrium biomass for guild.
// calculates the unfished equilibrium biomass of guild
!! for (area=1; area<=Nareas; area++) {
!! for (iguild=1; iguild<=Nguilds; iguild++ ) {
!! for (spp=1; spp<=Nspecies; spp++) {
!! if (guildMembers(spp)== iguild) {
!! // sum up equilibr biomass for each guild
!! B0_guilds(area,iguild) += B0(area,spp);
!!
!! }
!! }
!! }
!! }
init_int flagRamp // flag for type of response function. 0 = step function , 1 = linear ramp
init_vector minExploitation(1,Nfleets) //min exploitation for each fleet
init_vector maxExploitation(1,Nfleets) //max Exploitation for each fleet
init_vector minMaxExploitation(1,2) //[MinExploitation,MaxExploitation
init_vector minMaxThreshold(1,2) // MinThreshold,MaxThreshold]
init_int Nthresholds // number of thresholds used for corrective fishing rules
init_vector threshold_proportion(1,Nthresholds) //levels at which action is taken
init_vector exploitation_levels(1,Nthresholds) //levels to drop exploitation to if threshold is exceeded
init_vector threshold_species(1,Nspecies) // individual species thresholds (fraction)
init_int AssessmentOn // binary, yes or no
init_int speciesDetection // binary yes or no. Determins if species level should influence exploitation rate change during assessment
init_int LFI_size // determins the size deemed a large fish. Used in LFI calc_health_indices module
init_number scaleInitialN // scale the initial values of yr1N individuals
//init_number otherFood // amount of other food included in the M2 term. previously hard coded //GF moving to parameter section
init_matrix effortScaled(1,Nareas,1,Nspecies) // species specific scaling of effort due to S-R function data. eg. herring/mackerel use NE effort, others GB effort
init_4darray discard_Coef(1,Nareas,1,Nspecies,1,Nfleets,1,Nsizebins) // proportion of fleet catch that are discarded
init_4darray discardSurvival_Coef(1,Nareas,1,Nspecies,1,Nfleets,1,Nsizebins) // of the discards what proportion survives
init_vector predOrPrey(1,Nspecies) // binary vector indicating which species are considered predators. used in pred:prey indices
init_int bandwidth_metric // moving window for catch variance
init_number baseline_threshold // value of threshold that we stop landing catch. Typically 0.2
// !! baseline_threshold = 0.2;
// GF March 2022 - modifying fishing for estimation
init_3darray indicator_fishery_q(1,Nareas,1,Nfleets,1,Nspecies) // used to determin which species used to calculate updated effort under assessment
//!! cout << indicator_fishery_q << endl;
int Nqpars
!! Nqpars = sum(indicator_fishery_q)-(Nfleets*Nareas);
imatrix f_map(1,Nareas,1,Nfleets) //primary species for each fleet (i.e. which species the F refers to)
int dim2
!! dim2 = Nqpars;
!! if (dim2 == 0) dim2 = 1;
imatrix q_map(1,dim2,1,3) //object that maps the catchability parameters to area, species, and fleet
int dum
!! f_map = 0;
!! q_map = 0;
!! dum = 0;
!! for(int area=1;area<=Nareas;area++) {
!! for (int ifleet=1;ifleet<=Nfleets;ifleet++) {
!! for (int species=1;species<=Nspecies;species++) {
!! if (Nqpars >0) {
!! if (f_map(area,ifleet)!=0 && indicator_fishery_q(area,ifleet,species) == 1) {
!! dum += 1;
!! q_map(dum,1) = area;
!! q_map(dum,2) = species;
!! q_map(dum,3) = ifleet;
!! }
!! }
!! if (f_map(area,ifleet)==0 && indicator_fishery_q(area,ifleet,species) == 1) f_map(area,ifleet) = species;
!! }
!!
!! }
!! }
!! cout << "q par map" << endl;
!! cout << Nqpars << endl;
!! cout << f_map << endl;
!! cout << q_map << endl;
//!! exit(-1);
init_vector AR_parameters(1,3) // rho (autoregressive parameters) for survey, recruitment, catch
number rho_AR_Survey
!! rho_AR_Survey = AR_parameters(1);
number rho_AR_Recruitment
!! rho_AR_Recruitment = AR_parameters(2);
number rho_AR_Catch
!! rho_AR_Catch = AR_parameters(3);
3darray sim_survey_error(1,Nareas,1,Nspecies,1,Nyrs) // used to calculate AR process for survey
3darray sim_recruit_error(1,Nareas,1,Nspecies,1,Nyrs) // used to calculate AR process for recruitment
4darray sim_catch_error(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs) // used to calculate AR process for catch
3darray sim_extreme_recruit_error(1,Nareas,1,Nspecies,1,Nyrs) // used to calculate errors for extreme event
init_int flagMSE //flag to determine output created. If MSE = 1, otherwise = 0
init_matrix residentTime(1,Nareas,1,Nspecies) // proportion of time each species spent in management area
// .10 1 .17 1 1 1 1 .14 1 1
init_matrix areaMortality(1,Nareas,1,Nspecies) // total mortality of pop outside management area
// 0 0 0 0 0 0 0 0 0 0
//survey obs error
// init_matrix ln_surv_sigma(1,Nareas,1,Nspecies)
// matrix surv_sigma(1,Nareas,1,Nspecies)
// 3darray surv_obsError(1,Nareas,1,Nspecies,1,Nyrs)
// //catch obs error
// init_3darray ln_catch_sigma(1,Nareas,1,Nspecies,1,Nfleets)
// 3darray catch_sigma(1,Nareas,1,Nspecies,1,Nfleets)
// 4darray catch_obsError(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs)
// time varying mortality (fixed multiplier for prey items)
init_int m1_change_yr // yr to implement change, if -99 no change applied
init_number m1_multiplier // value to scale M1 by
// time varying other food (fixed multiplier, same for all)
init_int of_change_yr // yr to implement change, if -99 no change applied
init_number of_multiplier // value to scale oF by
// whether to have varying q or a fixed input
init_int flag_tvar_q // 0 = fixed value over time, 1 = annual values
int Nqpar_vec
!! Nqpar_vec = 1;
!! if(flag_tvar_q==1) Nqpar_vec = Nyrs;
//flag marking end of file for data input
init_int eof;
//change to read in raw data
!!ad_comm::change_datafile_name(datfilename);
//init_3darray obs_survey_biomass(1,Nsurveys,1,Nspecies,1,Nyrs) //input spring, fall separately, in tons
//init_int Nsurvey_obs //number of survey observations
init_int Nsurvey_obs;
!!cout << Nsurvey_obs << endl;
init_matrix obs_survey_biomass(1,Nsurvey_obs,1,5) //GF May 2021 revised structure
//read in survey size comp data
init_int Nsurvey_size_obs;
!! int ncol = Nsizebins+5;
init_matrix obs_survey_size(1,Nsurvey_size_obs,1,ncol) //legnth comps for surveys
// GF May 2021 - alternate data structure
init_int Ncatch_obs //number of catch observations
init_matrix obs_catch_biomass(1,Ncatch_obs,1,6) //total catch in tons
//init_3darray obs_catch_biomass(1,Nareas,1,Nspecies,1,Nyrs) //total catch in tons
init_int Ncatch_size_obs
!! ncol = Nsizebins+6;
init_matrix obs_catch_size(1,Ncatch_size_obs,1,ncol)
//read in diet proportion data
init_int Ndietprop_obs;
!! ncol = Nspecies+6;
init_matrix obs_dietprop(1,Ndietprop_obs,1,ncol) //diet proportions by weight
//!! cout << obs_dietprop << endl;
//debugging section, check inputs and initial calculations
LOCAL_CALCS
if (debug == 1)
{
cout<<"Nyrs\n"<<Nyrs<<endl;
cout<<"Nspecies\n"<<Nspecies<<endl;
cout<<"Nsizebins\n"<<Nsizebins<<endl;
cout<<"Nareas\n"<<Nareas<<endl;
cout<<"Nfleets\n"<<Nfleets<<endl;
cout<<"wtconv\n"<<wtconv<<endl;
cout<<"Totsizebins\n"<<Totsizebins<<endl;
cout<<"binwidth\n"<<binwidth<<endl;
cout<<"lenwt_a\n"<<lenwt_a<<endl;
cout<<"lenwt_b\n"<<lenwt_b<<endl;
cout<<"lbinmax\n"<<lbinmax<<endl;
cout<<"lbinmin\n"<<lbinmin<<endl;
cout<<"lbinmidpt\n"<<lbinmidpt<<endl;
cout<<"wtbinmax\n"<<wtbinmax<<endl;
cout<<"wtbinmin\n"<<wtbinmin<<endl;
cout<<"wtatlbinmidpt\n"<<wtatlbinmidpt<<endl;
cout<<"binavgwt\n"<<binavgwt<<endl;
cout<<"Nrecruitment_cov\n"<<Nrecruitment_cov<<endl;
cout<<"Nmaturity_cov\n"<<Nmaturity_cov<<endl;
cout<<"Ngrowth_cov\n"<<Ngrowth_cov<<endl;
cout<<"recruitment_cov\n"<<recruitment_cov<<endl;
cout<<"maturity_cov\n"<<maturity_cov<<endl;
cout<<"growth_cov\n"<<growth_cov<<endl;
cout<<"obs_survey_biomass\n"<<obs_survey_biomass<<endl;
cout<<"obs_survey_size\n"<<obs_survey_size<<endl;
cout<<"obs_catch_biomass\n"<<obs_catch_biomass<<endl;
cout<<"obs_catch_size\n"<<obs_catch_size<<endl;
cout<<"obs_dietprop\n"<<obs_dietprop<<endl;
cout<<"mean_stomwt\n"<<mean_stomwt<<endl;
cout<<"obs_temp\n"<<obs_temp<<endl;
cout<<"recruitment_covwt\n"<<recruitment_covwt<<endl;
cout<<"rectype\n"<<rectype<<endl;
cout<<"stochrec\n"<<stochrec<<endl;
cout<<"rec_alpha\n"<<rec_alpha<<endl;
cout<<"rec_shape\n"<<rec_shape<<endl;
cout<<"rec_beta\n"<<rec_beta<<endl;
cout<<"fecund_d\n"<<fecund_d<<endl;
cout<<"fecund_h\n"<<fecund_h<<endl;
cout<<"fecund_theta\n"<<fecund_theta<<endl;
cout<<"fecundity\n"<<fecundity<<endl;
cout<<"maturity_nu\n"<<maturity_nu<<endl;
cout<<"maturity_omega\n"<<maturity_omega<<endl;
cout<<"maturity_covwt\n"<<maturity_covwt<<endl;
cout<<"growth_psi\n"<<growth_psi<<endl;
cout<<"growth_kappa\n"<<growth_kappa<<endl;
cout<<"growth_covwt\n"<<growth_covwt<<endl;
cout<<"vonB_Linf\n"<<vonB_Linf<<endl;
cout<<"vonB_k\n"<<vonB_k<<endl;
cout<<"growthtype (1 power, 2 power/covariates, 3 vonB, 4 vonB covariates)\n"<<growthtype<<endl;
cout<<"growthprob_phi\n"<<growthprob_phi<<endl;
cout<<"phimax\n"<<phimax<<endl;
cout<<"Nstepsyr\n"<<Nstepsyr<<endl;
cout<<"Tottimesteps\n"<<Tottimesteps<<endl;
cout<<"intake_alpha\n"<<intake_alpha<<endl;
cout<<"intake_beta\n"<<intake_beta<<endl;
cout<<"intake\n"<<intake<<endl;
// cout<<"M1ann\n"<<M1ann<<endl;
// cout<<"M1\n"<<M1<<endl;
cout<<"isprey\n"<<isprey<<endl;
cout<<"Npred\n"<<Npred<<endl;
cout<<"preferred_wtratio\n"<<preferred_wtratio<<endl;
cout<<"sd_sizepref\n"<<sd_sizepref<<endl;
cout<<"wtratio\n"<<wtratio<<endl;
cout<<"sizepref\n"<<sizepref<<endl;
//cout<<"suitability\n"<<suitability<<endl;
cout<<"B0\n"<<B0<<endl;
cout<<"Nguilds\n"<<Nguilds<<endl;
cout<<"guildMembers\n"<<guildMembers<<endl;
cout<<"AssessmentPeriod\n"<<AssessmentPeriod<<endl;
// cout<<setprecision(10)<<"FH\n"<<FH<<endl;
// cout<<setprecision(10)<<"FHideal\n"<<FHideal<<endl;
cout<<"eof\n"<<eof<<endl;
}
if(eof != 54321) {cout<<"Stop, data input failed"<<endl<<"eof: "<<eof<<endl; exit(1);}
if (debug == 1) {cout<<"\nManually exiting at end of data section..."<<endl; exit(-1);}
END_CALCS
//=======================================================================================
INITIALIZATION_SECTION
//=======================================================================================
//=======================================================================================
PARAMETER_SECTION
//=======================================================================================
matrix effort_updated(1,Nareas,1,Nfleets) // calculated new Effort for each fleet following threshold exceedence calc_assessment_strategy
3darray obs_effortAssess(1,Nareas,1,Nfleets,1,Nyrs) //standardized effort units needed
!!obs_effortAssess = obs_effort;
//Initial N year 1
init_3darray ln_yr1N(1,Nareas,1,Nspecies,1,Nsizebins,yr1Nphase) //initial year N at size, millions
3darray yr1N(1,Nareas,1,Nspecies,1,Nsizebins); //initial year N at size, millions
// recruitment parameters all read in from Dat file. These are redundant. Andy Beet
//recruitment parameters (alts in .dat file read in with switch for rec form by spp)
init_matrix recruitment_alpha(1,Nareas,1,Nspecies,recphase) //recruitment model alpha
init_matrix recruitment_shape(1,Nareas,1,Nspecies,recphase) //recruitment model shape parameter
init_matrix recruitment_beta(1,Nareas,1,Nspecies,recphase) //recruitment model beta
//proportion mature
4darray propmature(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) //from maturity pars and covs
//egg production
3darray eggprod(1,Nareas,1,Nspecies,1,Nyrs) //from fecundity, propmature, sexratio, N, in millions
//recruitment: average annual, annual devs, actual (avg+dev)
init_matrix ln_avg_recruitment(1,Nareas,1,Nspecies,avg_rec_phase) //average annual recruitment by area, species
matrix avg_recruitment(1,Nareas,1,Nspecies) //average annual recruitment by area, species
init_3darray recruitment_devs(1,Nareas,1,Nspecies,2,Nyrs,dev_rec_phase) //recruitment deviations by area, species
3darray recruitment(1,Nareas,1,Nspecies,2,Nyrs) //by definition into first size bin for each species, millions
//recruitment simulation
init_matrix ln_recsigma(1,Nareas,1,Nspecies,recsigmaphase) //sigma for stochastic recruitment from SR curve
matrix recsigma(1,Nareas,1,Nspecies) //sigma for stochastic recruitment from SR curve
3darray rec_procError(1,Nareas,1,Nspecies,1,Nyrs) //to generate deviations from SR curve
//growth options
//independent of bioenergetics--age based, use growthprob_phi above based on pars of age predicting length
//4darray length(1,Nareas,1,Nspecies,1,Nages,1,Nyrs) //not needed in basic calculations so leave aside for now
//bioenergetics based, depends on consumption--to be added
//fishing mort: average annual, annual devs, actual (avg+dev)
//**needs to be done by fleet, currently assuming each fleet has the same avg_F, F_devs and Ftot**
//**then they sum to give F by species**
//init_3darray avg_F(1,Nareas,1,Nspecies,1,Nfleets,avg_F_phase) //logspace average annual fishing mort by area, species
init_matrix avg_F(1,Nareas,1,Nfleets,avg_F_phase) //logspace average annual fishing mort by area, species
//init_3darray F_devs(1,Nspecies,1,Nfleets,1,Nyrs,dev_F_phase) //logspace F deviations by area, species--NEEDS TO BE 4D, CANT DO?, FIX
init_3darray F_devs(1,Nareas,1,Nfleets,1,Nyrs,dev_F_phase) //logspace F deviations by area, species--NEEDS TO BE 4D, CANT DO?, FIX
//
//***********June 2014 replace with F = q*E formulation*****************************
4darray Fyr(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs) //array to get annual Fs by fleet from either avg/devs or q*effort, logspace
4darray suitpreybio(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins); //suitable prey for each predator size and year, see weight unit above for units
!!cout << "Nprey " << Nprey << endl;
init_vector logit_vuln(1,Npreypar,vuln_phase);
3darray vulnerability(1,Nareas,1,Nspecies,1,Nspecies);
4darray suitability(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins); //GF moved here 01/09/2023 because vulnerabilities shifted
5darray biomass_prey_avail_no_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,1,Nprey);
//N, B, F, Z, M2, C, need total prey consumed per pred, suitability, available prey, food habits?
4darray N(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //numbers by area of total pop, species, size, timestep , in millions
4darray Narea(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //numbers by area of pop in area, species, size, timestep , in millions
4darray Nnotarea(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //numbers by area of pop outside, species, size, timestep , in millions
4darray B(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //biomass by area, species, size, timestep , see weight unit above for units
4darray F(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //fishing mort by area, species, size, timestep
4darray C(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //catch numbers by area, species, size, timestep , in millions
4darray Z(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //total mort by area, species, size, timestep
4darray M2(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //predation mort by area, species, size, timestep
4darray eatN(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //number eaten by predators by area, species, size, timestep
4darray discardN(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //number discarded by vessels by area, species, size, timestep
4darray otherDead(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //number unknown deaths by area, species, size, timestep
4darray D(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins) //discard mortality by area, species, size, timestep
//Fishery selectivities, fleet F and catch, fishery q
init_matrix fishsel_pars(1,2,1,Nfleets,fsphase)
matrix fishsel_c(1,Nspecies,1,Nfleets) //fishery selectivity c par
matrix fishsel_d(1,Nspecies,1,Nfleets) //fishery selectivity d par
4darray fishsel(1,Nareas,1,Nspecies,1,Nfleets,1,Nsizebins) //fishery selectivity
5darray Ffl(1,Nareas,1,Nspecies,1,Nfleets,1,Tottimesteps,1,Nsizebins) //fleet specific Fs
5darray Dfl(1,Nareas,1,Nspecies,1,Nfleets,1,Tottimesteps,1,Nsizebins) //fleet specific Discard mortaliy s
5darray Cfl(1,Nareas,1,Nspecies,1,Nfleets,1,Tottimesteps,1,Nsizebins) //fleet specific Catch in numbers
//init_matrix ln_fishery_q(1,Nyrs,1,Nqpars,fqphase) //Nareas,1,Nspecies,1,Nfleets,fqphase)
init_matrix ln_fishery_q(1,Nqpar_vec,1,Nqpars,fqphase) //Nareas,1,Nspecies,1,Nfleets,fqphase)
4darray fishery_q(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs)
3darray mean_guild_fishery_q(1,Nareas,1,Nguilds,1,Nfleets) // mean q for guild and fleet// andybeet
// matrix mean_fishery_q(1,Nareas,1,Nfleets) // mean q for fleet. ignore values of zero //andybeet
// gavinfay March 2022 - moving this code to procedure section as function of estimated parameters
// // calculates the mean fishery_q for each guild (over fleets)
// !! for (area=1; area<=Nareas; area++) {
// !! for (iguild=1; iguild<=Nguilds; iguild++ ) {
// !! for (int ifleet=1;ifleet<=Nfleets;ifleet++) {
// !! int icount = 0;
// !! for (spp=1; spp<=Nspecies; spp++) {
// !! if (guildMembers(spp)== iguild) {
// !! icount++;
// !! // sum up q's
// !! mean_guild_fishery_q(area,iguild,ifleet) += fishery_q(area,spp,ifleet);
// !! }
// !! }
// !! mean_guild_fishery_q(area,iguild,ifleet) = mean_guild_fishery_q(area,iguild,ifleet)/icount;
// !! }
// !! }
// !! }
//
//
// // calculates the mean q for each fleet ignoring zero q's.
// // this is used to update effort when an assessment dictates
// !! for (area=1; area<=Nareas; area++) {
// !! for (int ifleet=1;ifleet<=Nfleets;ifleet++) {
// !! int icount = 0;
// !! mean_fishery_q(area,ifleet) = 0;
// !! for (spp=1; spp<=Nspecies; spp++) {
// !! if (fishery_q(area,spp,ifleet) < 1e-29) {
// !! //ignore
// !! } else {
// !! icount = icount + indicator_fishery_q(area,spp,ifleet);
// !! mean_fishery_q(area,ifleet) += indicator_fishery_q(area,spp,ifleet)*fishery_q(area,spp,ifleet);
// !! }
// !! }
// !! if (icount == 0) { // then all q's are < 1-e29. This occurs during testing a new fleet with no information
// !! mean_fishery_q(area,ifleet) = 0;
// !! } else {
// !! mean_fishery_q(area,ifleet) = mean_fishery_q(area,ifleet)/icount;
// !! }
// !! }
// !! }
//Survey qs
init_bounded_matrix ln_survey_q(1,Nsurveys,1,Nspecies,-30,2,sqphase)
matrix survey_q(1,Nsurveys,1,Nspecies)
//Survey selectivity (will want to be derived based on estimated parameters)
init_matrix survey_selpars(1,2,1,Nsurveys,ssphase)
3darray survey_sel(1,Nsurveys,1,Nspecies,1,Nsizebins)
// //survey obs error
// init_matrix ln_surv_sigma(1,Nareas,1,Nspecies,ssig_phase)
// matrix surv_sigma(1,Nareas,1,Nspecies)
// 3darray surv_obsError(1,Nareas,1,Nspecies,1,Nyrs)
// //catch obs error
// init_3darray ln_catch_sigma(1,Nareas,1,Nspecies,1,Nfleets,csig_phase)
// 3darray catch_sigma(1,Nareas,1,Nspecies,1,Nfleets)
// 4darray catch_obsError(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs)
//annual total B and SSB
3darray avByr(1,Nareas,1,Nspecies,1,Nyrs) //uses B units--"true" simulated biomass
3darray SSB(1,Nareas,1,Nspecies,1,Nyrs) //uses B units--"true" SSB
//annual eaten B
3darray eaten_biomass(1,Nareas,1,Nspecies,1,Nyrs) //uses B units. M2
3darray discard_biomass(1,Nareas,1,Nspecies,1,Nyrs) //uses B units. discards
3darray otherDead_biomass(1,Nareas,1,Nspecies,1,Nyrs) //uses B units. M1
3darray total_biomass(1,Nareas,1,Nspecies,1,Nyrs) //uses B units. N
4darray eaten_biomass_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) //uses B units. M2
4darray discard_biomass_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) //uses B units. discards
4darray otherDead_biomass_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) //uses B units. M1
4darray total_biomass_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) //uses B units. N
4darray catch_biomass_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) //uses B units--"true" simulated catch
3darray predation_mortality(1,Nareas,1,Nspecies,1,Nyrs) // uses B units = eaten/total biomass
3darray fishing_mortality(1,Nareas,1,Nspecies,1,Nyrs) // uses B units = (landing+discards) / total biomass
4darray predation_mortality_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) // uses B units = eaten/total biomass
4darray fishing_mortality_size(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins) // uses B units = (landing+discards) / total biomass
//estimated fishery catch and survey catch