forked from nmfs-ost/ss3-source-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SS_readcontrol_330.tpl
6920 lines (6620 loc) · 235 KB
/
SS_readcontrol_330.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
// SS_Label_file #4. **SS_readcontrol.tpl**
// SS_Label_file # * read *control_file* named in starter.ss
// SS_Label_file # * define and read needed parameters from model options selected
// SS_Label_file # * creates labels for those parameters
// SS_Label_file # * uses a function found in SS_global, <u>create_timevary()</u>, to create, index and label time-varying parameters; including autogeneration option
// SS_Label_file # * creates and labels derived quantities
// SS_Label_file # * creates covariance matrix
// SS_Label_file # * reads *wt_at_age.ss* if requested
// SS_Label_file # * finish DATA_SECTION
LOCAL_CALCS
// clang-format on
//********CONTROLS********************************
// SS_Label_Info_4.0 #Begin Reading from Control File
// /* SS_Label_Flow begin reading from control file */
ad_comm::change_datafile_name(ctlfilename);
echoinput << endl
<< " Begin reading control file " << endl;
cout << " reading from control file" << endl;
ifstream Control_Stream(ctlfilename); // even if the global_datafile name is used, there still is a different logical device created
// SS_Label_Info_4.1 #Read and store comments at top of control file
k = 0;
N_CC = 0;
while (k == 0)
{
Control_Stream >> readline; // reads the line from input stream
if (length(readline) > 2)
{
checkchar = readline(1);
k = strcmp(checkchar, "#");
checkchar = readline(1, 2);
j = strcmp(checkchar, "#C");
if (j == 0) {
N_CC++;
Control_Comments += readline;
}
}
}
// clang-format off
END_CALCS
// when a parameter is defined and its label (hence usage) is created,
// the value of its min, max, init, prior have not yet been read
// so when it gets created, need to pushback a code to indicate what special conditions affect it
// also may want to save indicator of whether the parameter is multiplier, logit, etc.
// so push_back a code to the ivector Parm_minmax
// and add a string to the adstring_array Parm_info
ivector minmax_types(1,10) // set of canned min-max types
!!// SS_Label_Info_4.2 #Read info for growth patterns, gender, settlement events, platoons
init_int WTage_rd // 0 means do not read wtatage.ss; 1 means read and use wtatage.ss and also read and use growth parameters
// future option 2 will suppress reading and use of growth
!!echoinput<<WTage_rd<<" wtatage switch "<<endl;
init_int N_GP // number of growth patterns (morphs)
!!echoinput<<N_GP<<" N growth patterns "<<endl;
init_int N_platoon // number of platoons 1, 3, 5 are best values to use
!!echoinput<<N_platoon<<" N platoons (1, 3 or 5)"<<endl;
number sd_ratio; // ratio of stddev within platoon to between morphs
number sd_within_platoon
number sd_between_platoon
ivector ishadow(1,N_platoon)
vector shadow(1,N_platoon)
vector platoon_distr(1,N_platoon);
LOCAL_CALCS
// clang-format on
if (WTage_rd > 0 && nobs_mnwt > 0)
{
N_warn++;
warning << N_warn << " "
<< "incompatible option: empirical bodywt-at-age is used, but meanbody_wt obs fit using growth curve" << endl;
}
if (N_platoon > 1)
{
*(ad_comm::global_datafile) >> sd_ratio;
*(ad_comm::global_datafile) >> platoon_distr;
echoinput << sd_ratio << " sd_ratio" << endl;
echoinput << platoon_distr << " platoon_distr" << endl;
}
else
{
sd_ratio = 1.;
platoon_distr(1) = 1.;
echoinput << " do not read sd_ratio or platoon_distr" << endl;
}
// SS_Label_Info_4.2.1 #Assign distribution among growth platoons if needed
if (platoon_distr(1) < 0.)
{
if (N_platoon == 1)
{
platoon_distr(1) = 1.;
}
else if (N_platoon == 3)
{
platoon_distr.fill("{0.15,0.70,0.15}");
}
else if (N_platoon == 5)
{
platoon_distr.fill("{0.031, 0.237, 0.464, 0.237, 0.031}");
}
}
platoon_distr /= sum(platoon_distr);
if (N_platoon > 1)
{
sd_within_platoon = sd_ratio * sqrt(1. / (1. + sd_ratio * sd_ratio));
sd_between_platoon = sqrt(1. / (1. + sd_ratio * sd_ratio));
}
else
{
sd_within_platoon = 1;
sd_between_platoon = 0.000001;
}
if (N_platoon == 1)
{
ishadow(1) = 0;
shadow(1) = 0.;
}
else if (N_platoon == 3)
{
ishadow.fill_seqadd(-1, 1);
shadow.fill_seqadd(-1., 1.);
}
else if (N_platoon == 5)
{
ishadow.fill_seqadd(-2, 1);
shadow.fill_seqadd(-2., 1.);
}
else
{
N_warn++;
cout << " EXIT - see warning " << endl;
warning << N_warn << " "
<< " illegal N platoons, must be 1, 3 or 5 " << N_platoon << endl;
exit(1);
}
// clang-format off
END_CALCS
!!// SS_Label_Info_4.2.2 #Define distribution of recruitment(settlement) among growth patterns, areas, months
int recr_dist_method // 1=like 3.24 (not used); 2=main effects for GP, Settle timing, Area; 3=each Settle entity; 4=no parms (only if GPXsettleXarea=1)
int recr_dist_area // 1=global SRR; 2=area-specific SRR
int N_settle_assignments // number of assigned settlements for GP, Settle_month, Area (>=0)
int N_settle_assignments_rd // number read, needed to distinguish between ss3.24 and SS3.30 setup
int N_settle_timings // number of recruitment settlement timings per spawning (>=1) - important for number of morphs calculation
// will be calculated from the number of unique settle_months among the settle_assignments
int settle // index to settle_assignments
int settle_time // index to setting timings
int Comp_Err_Parm_Start
int recr_dist_inx
LOCAL_CALCS
// clang-format on
* (ad_comm::global_datafile) >> recr_dist_method;
echoinput << recr_dist_method << " # Recruitment distribution method; where: 2=parms for main effects for GP, Area, Settle timing; 3=one parm for each Settle event" << endl;
*(ad_comm::global_datafile) >> recr_dist_area;
echoinput << recr_dist_area << " # future option for recr_dist_area: 1 is hardwired to do global SRR; 2 in future will do area-specific SRR" << endl;
recr_dist_area = 1; //hardwire for testing
N_settle_assignments_rd = 0;
N_settle_assignments = 1; // default
switch (recr_dist_method)
{
case 1:
{
*(ad_comm::global_datafile) >> N_settle_assignments_rd;
*(ad_comm::global_datafile) >> recr_dist_inx;
N_settle_assignments = N_settle_assignments_rd;
break;
}
case 2:
{
*(ad_comm::global_datafile) >> N_settle_assignments;
*(ad_comm::global_datafile) >> recr_dist_inx;
break;
}
case 3:
{
*(ad_comm::global_datafile) >> N_settle_assignments;
*(ad_comm::global_datafile) >> recr_dist_inx;
break;
}
case 4:
{
*(ad_comm::global_datafile) >> N_settle_assignments;
*(ad_comm::global_datafile) >> recr_dist_inx;
if (N_settle_assignments > 1)
{
N_warn++;
cout << "exit with warning" << endl;
warning << N_warn << " Need to change to recr_dist_method=3 because >1 settle assignments requested" << endl;
exit(1);
}
break;
}
}
echoinput << N_settle_assignments << " Number of settlement events: GP/area/month to read (>=0) " << endl;
if (recr_dist_method == 1)
{
N_warn++;
cout << " EXIT - see warning " << endl;
warning << N_warn << " fatal error: recr_dist_method cannot be 1 in SS3.30 " << endl;
exit(1);
}
else if (N_settle_assignments == 1 && recr_dist_method != 4)
{
N_warn++;
warning << N_warn << " "
<< "NOTE: This model has just one settlement event. Changing to recr_dist_method 4 and removing the recruitment distribution parameters at the end of the MG parms section (below growth parameters) will produce identical results and simplify the model." << endl;
}
else if (recr_dist_method == 2)
{
N_warn++;
warning << N_warn << " "
<< "NOTE: recr_dist_method 3 is simpler and takes 1 parm for each settlement" << endl;
}
echoinput << recr_dist_inx << " # unused option " << endl;
// clang-format off
END_CALCS
int birthseas; // is this still needed??
matrix settlement_pattern_rd(1,N_settle_assignments,1,4); // for each settlement event: GPat, Month, area, age
ivector settle_assignments_timing(1,N_settle_assignments); // stores the settle_timing index for each assignment
matrix settle_timings_tempvec(1,N_settle_assignments,1,2) // temporary storage for real_month and age of each settlement_timing
// dimensioned by assignments, but only uses N_settle_timings of these
LOCAL_CALCS
// clang-format on
*(ad_comm::global_datafile) >>
settlement_pattern_rd;
echoinput << " settlement pattern as read " << endl
<< "GPat Month Area Age" << endl
<< "*" << settlement_pattern_rd << "*" << endl;
echoinput << "Now calculate the number of unique settle timings, which will dictate the number of recr_dist_timing parameters " << endl;
N_settle_timings = 0;
settle_timings_tempvec.initialize();
if (N_settle_assignments == 0)
{
N_settle_timings = 1;
settle_timings_tempvec(1, 1) = 1.0;
settle_timings_tempvec(1, 2) = 0;
}
else
{
for (settle = 1; settle <= N_settle_assignments; settle++)
{
real_month = settlement_pattern_rd(settle, 2);
int settle_age_here = settlement_pattern_rd(settle, 4);
if (N_settle_timings == 0)
{
N_settle_timings++;
settle_timings_tempvec(N_settle_timings, 1) = real_month;
settle_timings_tempvec(N_settle_timings, 2) = settle_age_here;
settle_assignments_timing(settle) = N_settle_timings;
}
else
{
k = 0;
for (j = 1; j <= N_settle_timings; j++)
{
if (settle_timings_tempvec(j, 1) == real_month && settle_timings_tempvec(j, 2) == settle_age_here) // found matching settle_time
{
settle_assignments_timing(settle) = j;
k = 1;
}
}
if (k == 0)
{
N_settle_timings++;
settle_timings_tempvec(N_settle_timings, 1) = real_month;
settle_timings_tempvec(N_settle_timings, 2) = settle_age_here;
settle_assignments_timing(settle) = N_settle_timings;
}
}
}
}
echoinput << "N settle timings: " << N_settle_timings << endl
<< " unique_settle_times: " << endl
<< settle_timings_tempvec << endl;
echoinput << "settle events use these settle_times: " << settle_assignments_timing << endl;
if (recr_dist_method == 2)
{
echoinput << " Need to read N_GP * Narea * N_settletimings=" << N_GP * pop * N_settle_timings << " recruitment distribution parameters " << endl;
}
else if (recr_dist_method == 3)
{
echoinput << " Need to read N_settle_assignments=" << N_settle_assignments << " recruitment distribution parameters " << endl;
}
// SS_Label_Info_4.2.3 #Set-up arrays and indexing for growth patterns, gender, settlements, platoons
// clang-format off
END_CALCS
int g3i;
// SPAWN-RECR: define settlement timings
ivector Settle_seas(1,N_settle_timings) // calculated season in which settlement occurs
ivector Settle_seas_offset(1,N_settle_timings) // calculated number of seasons between spawning and the season in which settlement occurs
vector Settle_timing_seas(1,N_settle_timings) // calculated elapsed time (frac of year) between settlement and the begin of season in which it occurs
vector Settle_month(1,N_settle_timings) // month (real)in which settlement occurs
ivector Settle_age(1,N_settle_timings) // calculated age at which settlement occurs, with age 0 being the year in which spawning occurs
3iarray recr_dist_pattern(1,N_GP,1,N_settle_timings,0,pop); // has flag to indicate each settlement events
LOCAL_CALCS
// clang-format on
Settle_seas_offset.initialize();
Settle_timing_seas.initialize();
Settle_age.initialize();
Settle_seas.initialize();
recr_dist_pattern.initialize();
echoinput << "Calculated assignments in which settlement occurs " << endl
<< "Settle_event / Month / Seas / Seas_from_spawn / time_from_seas_start / age_at_settle" << endl;
if (N_settle_assignments > 0)
{
for (settle = 1; settle <= N_settle_assignments; settle++)
{
gp = settlement_pattern_rd(settle, 1); // growth patterns
p = settlement_pattern_rd(settle, 3); // settlement area
settle_time = settle_assignments_timing(settle);
Settle_age(settle_time) = settlement_pattern_rd(settle, 4); // settlement age as read
recr_dist_pattern(gp, settle_time, p) = 1; // indicates that settlement will occur here
recr_dist_pattern(gp, settle_time, 0) = 1; // for growth updating
Settle_month(settle_time) = settle_timings_tempvec(settle_time, 1);
}
for (settle_time = 1; settle_time <= N_settle_timings; settle_time++)
{
j = 0; // temp value for calculated settlement age
if (spawn_month > Settle_month(settle_time))
{
k = 1;
j++; // so sets season 1 as earliest possible settlement at age 1
}
else
{
k = spawn_seas; // earliest possible season for settlement at age 0
}
temp = azero_seas(k); // annual elapsed time fraction at begin of this season
Settle_timing_seas(settle_time) = (Settle_month(settle_time) - 1.0) / sumseas; // fraction of year at settlement month
while ((temp + seasdur(k)) <= Settle_timing_seas(settle_time))
{
temp += seasdur(k);
if (k == nseas)
{
k = 1;
j++;
}
else
{
k++;
}
}
if (j != Settle_age(settle_time))
{
N_warn++;
warning << N_warn << " "
<< "settle_month is less than spawn_month, so logical age at settlement calculated to be: " << j << " for settle_time " << settle_time << ". Does not match read value of "
<< Settle_age(settle_time) << " are you sure? " << endl;
}
Settle_seas(settle_time) = k;
Settle_seas_offset(settle_time) = Settle_seas(settle_time) - spawn_seas + j * nseas; // number of seasons between spawning and the season in which settlement occurs
Settle_timing_seas(settle_time) -= temp; // timing from beginning of this season; needed for mortality calculation
echoinput << settle_time << " / " << Settle_month(settle_time);
echoinput << " / " << Settle_seas(settle_time) << " / " << Settle_seas_offset(settle_time) << " / "
<< Settle_timing_seas(settle_time) << " / " << Settle_age(settle_time) << endl;
if (Settle_seas_offset(settle_time) == 0 && spawn_time_seas > 0.0)
{
N_warn++;
cout << "see warning for fatal input issue" << endl;
warning << N_warn << " "
<< "Cannot have spawn_time_seas after beginning of a season and settlements in the same season" << endl
<< "put spawning at beginning of the season, or move settlements to next season" << endl;
exit(1);
}
}
}
else
{
recr_dist_pattern(1, 1, 1) = 1;
recr_dist_pattern(1, 1, 0) = 1;
Settle_month(1) = 1.;
Settle_timing_seas(1) = 0.0;
Settle_seas(1) = 1;
Settle_seas_offset(1) = 0;
Settle_age(1) = 0;
}
gmorph = gender * N_GP * N_settle_timings * N_platoon; // total potential number of biological entities, some may not get used so see use_morph(g)
// clang-format off
END_CALCS
!!// SS_Label_Info_4.2.1.1 #Define indexing vectors to keep track of characteristics of each morph
ivector sx(1,gmorph) // define sex for each growth morph
ivector GP4(1,gmorph) // index to GPat
ivector GP(1,gmorph) // index for gender*GPat; note that gp is nested inside gender
ivector GP3(1,gmorph) // index for main gender*GPat*settlement
ivector GP2(1,gmorph) // reverse pointer for platoon
imatrix g_finder(1,N_GP,1,gender) // reverse pointer to middle "g" for each main morph (used only with Growth_Std
ivector g_Start(1,N_GP*gender) // base "g" for this growth pattern
ivector Bseas(1,gmorph) // birth season
// following two containers are used to track which morphs are being used
ivector use_morph(1,gmorph)
imatrix TG_use_morph(1,N_TG2,1,gmorph)
imatrix ALK_range_g_lo(1,N_subseas*nseas*gmorph,0,nages)
imatrix ALK_range_g_hi(1,N_subseas*nseas*gmorph,0,nages)
vector azero_G(1,gmorph); // time since Jan 1 at beginning of settlement in which "g" was born
3darray real_age(1,gmorph,1,nseas*N_subseas,0,nages); // real age since settlement
3darray keep_age(1,gmorph,1,nseas*N_subseas,0,nages); // set to 0.0 if real_age<0. this allows omitting virtual young fish to be excluded from expected values
3darray calen_age(1,gmorph,1,nseas*N_subseas,0,nages); // real age since Jan 1 of spawn year
3darray lin_grow(1,gmorph,1,nseas*N_subseas,0,nages) // during linear phase has fraction of Size at Afix
ivector settle_g(1,gmorph) // settlement pattern for each platoon
int ALK_count;
LOCAL_CALCS
// clang-format on
ALK_count = 0;
ALK_range_g_lo = 1;
ALK_range_g_hi = nlength;
use_morph.initialize();
TG_use_morph.initialize();
keep_age.initialize();
keep_age = 1.0;
for (gp = 1; gp <= N_GP * gender; gp++)
{
g_Start(gp) = (gp - 1) * N_settle_timings * N_platoon + int(N_platoon / 2) + 1 - N_platoon; // find the mid-morph being processed
}
g = 0;
g3i = 0;
echoinput << endl
<< "MORPH_INDEXING" << endl;
echoinput << "g Sex GP Settlement Birth_Seas Platoon Platoon% Sex*GP Sex*GP*settle_time Used(0/1) SettleTime_frac_yr" << endl;
for (gg = 1; gg <= gender; gg++)
for (gp = 1; gp <= N_GP; gp++)
for (settle = 1; settle <= N_settle_timings; settle++)
{
g3i++;
{
for (gp2 = 1; gp2 <= N_platoon; gp2++)
{
g++;
GP3(g) = g3i; // track counter for main morphs (gender x pattern x settlement)
Bseas(g) = Settle_seas(settle);
sx(g) = gg;
GP(g) = gp + (gg - 1) * N_GP; // counter for pattern x gender so gp is nested inside gender
GP2(g) = gp2; // reverse pointer to platoon counter
GP4(g) = gp; // counter for growth pattern
settle_g(g) = settle; // to find the settlement timing for this platoon
azero_G(g) = (Settle_month(settle) - 1.0) / sumseas; // settlement month converted to fraction of year; could be > one year
for (p = 1; p <= pop; p++)
{
if (recr_dist_pattern(gp, settle, p) == 1)
{
use_morph(g) = 1;
}
}
if (use_morph(g) == 1)
{
if ((N_platoon == 1) || (N_platoon == 3 && gp2 == 2) || (N_platoon == 5 && gp2 == 3)) g_finder(gp, gg) = g; // finds g for a given GP and gender and last birstseason
}
echoinput << g << " " << sx(g) << " " << GP4(g) << " " << settle << " " << Bseas(g) << " "
<< GP2(g) << " " << 100. * platoon_distr(GP2(g)) << " " << GP(g) << " " << GP3(g) << " " << use_morph(g) << " " << azero_G(g) << endl;
}
}
}
echoinput << "calen_age is elapsed years since beginning of year in which spawning occurred" << endl;
echoinput << "real_age is elapsed years since settlement" << endl;
echoinput << "g s subseas ALK_idx settle_time age@settle age real_age calen_age" << endl;
calen_age.initialize();
real_age.initialize();
keep_age.initialize();
for (g = 1; g <= gmorph; g++)
if (use_morph(g) == 1)
for (s = 1; s <= nseas; s++)
for (subseas = 1; subseas <= N_subseas; subseas++)
{
ALK_idx = (s - 1) * N_subseas + subseas;
settle_time = settle_g(g);
// real_age is real age since settlement and is used in growth calculations
// calen_age is real age since the beginning of the year in which spawning occurred
for (a = 0; a <= nages; a++)
{
calen_age(g, ALK_idx, a) = r_ages(a) + azero_seas(s) + double(subseas - 1) / double(N_subseas) * seasdur(s);
if (a < Settle_age(settle_time))
{
real_age(g, ALK_idx, a) = 0.;
keep_age(g, ALK_idx, a) = 0.;
}
else if (a == Settle_age(settle_time))
{
if (calen_age(g, ALK_idx, a) >= (azero_G(g) + Settle_age(settle_time)))
{
real_age(g, ALK_idx, a) = calen_age(g, ALK_idx, a) - azero_G(g) - Settle_age(settle_time);
keep_age(g, ALK_idx, a) = 1.;
}
else
{
real_age(g, ALK_idx, a) = 0.;
keep_age(g, ALK_idx, a) = 0.;
}
}
else
{
real_age(g, ALK_idx, a) = calen_age(g, ALK_idx, a) - azero_G(g) - Settle_age(settle_time);
keep_age(g, ALK_idx, a) = 1.;
}
if (a < 4) echoinput << g << " " << s << " " << subseas << " " << ALK_idx << " " << settle_time << " " << Settle_age(settle_time)
<< " " << a << " " << real_age(g, ALK_idx, a) << " " << calen_age(g, ALK_idx, a) << endl;
}
}
if (N_TG > 0)
{
for (TG = 1; TG <= N_TG; TG++)
{
for (g = 1; g <= gmorph; g++)
{
if (TG_release(TG, 6) > 2) {
N_warn++;
warning << N_warn << " "
<< " gender for tag groups must be 0, 1 or 2 " << endl;
}
if (use_morph(g) > 0 && (TG_release(TG, 6) == 0 || TG_release(TG, 6) == sx(g))) TG_use_morph(TG, g) = 1;
}
}
}
// clang-format off
END_CALCS
!!// SS_Label_Info_4.3 #Define movement between areas
int do_migration // number of explicit movements to define
number migr_firstage
matrix migr_start(1,nseas,1,N_GP)
LOCAL_CALCS
// clang-format on
migr_firstage = 0.0;
do_migration = 0;
if (pop > 1)
{
*(ad_comm::global_datafile) >> do_migration;
echoinput << do_migration << " N_migration definitions to read" << endl;
if (do_migration > 0)
{
*(ad_comm::global_datafile) >> migr_firstage;
echoinput << migr_firstage << " migr_firstage" << endl;
}
}
else
{
echoinput << " only 1 area, so no read of do_migration or migr_firstage " << endl;
}
// clang-format off
END_CALCS
init_matrix move_def(1,do_migration,1,6) // seas morph source dest minage maxage
// ivector GP3(1,gmorph) // index for main gender*GPat*settlement in that order
// plan to revise such that movement is by GP3, not GP
4iarray move_pattern(1,nseas,1,N_GP,1,pop,1,pop)
int do_migr2
ivector firstBseas(1,N_GP)
LOCAL_CALCS
// clang-format on
move_pattern.initialize();
do_migr2 = 0;
if (do_migration > 0)
{
echoinput << " migration setup " << endl
<< move_def << endl;
for (k = 1; k <= do_migration; k++)
{
s = move_def(k, 1);
gp = move_def(k, 2);
p = move_def(k, 3);
p2 = move_def(k, 4);
move_pattern(s, gp, p, p2) = k; // save index for definition of this pattern to find the right parameters
}
k = do_migration;
for (s = 1; s <= nseas; s++)
for (gp = 1; gp <= N_GP; gp++)
for (p = 1; p <= pop; p++)
{
if (move_pattern(s, gp, p, p) == 0) {
k++;
move_pattern(s, gp, p, p) = k;
} // no explicit migration for staying in this area, so create implicit
}
do_migr2 = k; // number of explicit plus implicit movement rates
migr_start.initialize();
// need to modify so it only does the calc for the first settlement used for each GP???
for (gp = 1; gp <= N_GP; gp++)
{
// use firstBseas so that the start age of migration is calculated only for the first birthseason used for each GP
firstBseas(gp) = 0;
for (g = 1; g <= gmorph; g++)
if (use_morph(g) > 0)
{
if (GP4(g) == gp && firstBseas(gp) == 0) firstBseas(gp) = Bseas(g);
}
}
for (g = 1; g <= gmorph; g++)
if (use_morph(g) > 0 && firstBseas(GP4(g)) == Bseas(g))
{
for (s = 1; s <= nseas; s++)
for (subseas = 1; subseas <= N_subseas; subseas++)
{
a = 0;
ALK_idx = (s - 1) * N_subseas + subseas;
while (real_age(g, ALK_idx, a) < migr_firstage) {
a++;
}
migr_start(s, GP4(g)) = a;
}
}
}
// clang-format off
END_CALCS
matrix move_def2(1,do_migr2,1,6) // movement definitions. First Do_Migration of these are explicit; rest are implicit
LOCAL_CALCS
// clang-format on
if (do_migration > 0)
{
for (k = 1; k <= do_migration; k++) {
move_def2(k) = move_def(k);
}
k = do_migration;
for (s = 1; s <= nseas; s++)
for (gp = 1; gp <= N_GP; gp++)
for (p = 1; p <= pop; p++)
{
if (move_pattern(s, gp, p, p) > do_migration)
{
k++;
move_def2(k, 1) = s;
move_def2(k, 2) = gp;
move_def2(k, 3) = p;
move_def2(k, 4) = p;
move_def2(k, 5) = 0;
move_def2(k, 6) = nages;
}
}
echoinput << "move_def " << endl
<< move_def2 << endl;
}
// clang-format off
END_CALCS
!!// SS_Label_Info_4.4 #Define the time blocks for time-varying parameters
int N_Block_Designs // read N block designs
ivector Nblk(1,1)
imatrix Block_Design(1,1,1,1)
LOCAL_CALCS
// clang-format on
* (ad_comm::global_datafile) >>
N_Block_Designs;
echoinput << N_Block_Designs << " N_Block_Designs" << endl;
if (N_Block_Designs > 0)
{
Nblk.deallocate();
Nblk.allocate(1, N_Block_Designs);
*(ad_comm::global_datafile) >> Nblk(1, N_Block_Designs);
echoinput << Nblk << " N_Blocks_per design" << endl;
ivector Nblk2; // temporary vector to create ragged array of dimensions for block matrix
Nblk2.allocate(1, N_Block_Designs);
Nblk2 = Nblk + Nblk;
Block_Design.deallocate();
Block_Design.allocate(1, N_Block_Designs, 1, Nblk2);
for (j = 1; j <= N_Block_Designs; j++)
{
*(ad_comm::global_datafile) >> Block_Design(j)(1, Nblk2(j));
echoinput << " block design #: " << j << " read year pairs: " << Block_Design(j) << endl;
a = -1;
for (k = 1; k <= Nblk(j); k++)
{
a += 2;
if (Block_Design(j, a + 1) < Block_Design(j, a)) {
N_warn++;
cout << " EXIT - see warning " << endl;
warning << N_warn << " "
<< "Block:" << j << " " << k << " ends before it starts; fatal error" << endl;
exit(1);
}
if (Block_Design(j, a) < styr - 1) {
N_warn++;
warning << N_warn << " "
<< "Block:" << j << " " << k << " starts before styr; resetting" << endl;
Block_Design(j, a) = styr;
}
if (Block_Design(j, a + 1) < styr - 1) {
N_warn++;
cout << " EXIT - see warning " << endl;
warning << N_warn << " "
<< "Block:" << j << " " << k << " ends before styr; fatal error" << endl;
exit(1);
}
if (Block_Design(j, a) > retro_yr + 1) {
N_warn++;
warning << N_warn << " "
<< "Block:" << j << " " << k << " starts after retroyr+1; should not estimate " << endl;
}
if (Block_Design(j, a + 1) > retro_yr + 1) {
N_warn++;
warning << N_warn << " "
<< "Block:" << j << " " << k << " ends in: " << Block_Design(j, a + 1) << " after retroyr+1: " << retro_yr + 1 << endl;
}
if (Block_Design(j, a) > YrMax) {
N_warn++;
cout << " EXIT - see warning " << endl;
warning << N_warn << " "
<< "Block:" << j << " " << k << " starts in: " << Block_Design(j, a + 1) << " which is > YrMax: " << YrMax << " fatal error" << endl;
exit(1);
}
if (Block_Design(j, a + 1) > YrMax) {
N_warn++;
warning << N_warn << " "
<< "Block:" << j << " " << k << " ends in: " << Block_Design(j, a + 1) << " reset to YrMax: " << YrMax << endl;
Block_Design(j, a + 1) = YrMax;
}
}
}
}
else
{
Nblk.allocate(1, 1);
Block_Design.allocate(1, 1, 1, 1);
}
// clang-format off
END_CALCS
init_int parm_adjust_method
!! echoinput<<parm_adjust_method<<" timevarying parameter constraint method"<<endl;
init_ivector autogen_timevary(1,5); // 0 means to autogenerate time-vary parameters; 1 means to read; (2) read then autogen if parm min==-12345
// first element for biology, 2nd for SRR; 3rd for Q; 4th for tag; 5th for selex
!! echoinput<<autogen_timevary<<" timevarying parameter autogenerate (0) or read (1) for each parm type or (2) read then autogen if parm min==-12345"<<endl;
ivector varparm_estimated(1,5) // flag to show what types of variance parameters are estimated
// (1) for growth
// (2) for recruitment sigmaR
// (3) for survey extraSD
!! varparm_estimated.initialize();
!!// SS_Label_Info_4.5 #Read setup and parameters for natmort, growth, biology, recruitment distribution, and migration
// read setup for natmort parameters: LO, HI, INIT, PRIOR, PR_type, CV, PHASE, use_env, use_dev, dev_minyr, dev_maxyr, dev_phase, Block, Block_type
int N_MGparm
int N_natMparms
int N_predparms
ivector predparm_pointer(1,Nfleet+1)
int N_growparms
int N_M_Grow_parms
int recr_dist_parms
int natM_type
int natM_5_opt // option selection for Maunder approach
imatrix MGparm_point(1,gender,1,N_GP)
vector NatM_break(1,1);
matrix Age_NatMort(1,1,1,1);
number natM_amin;
number natM_amax;
number fracfemale;
!!fracfemale=1.00;
number fracfemale_mult;
!!fracfemale_mult=1.0; // multiplier used in female SSB calc; gets changed to femfrac(1) if gender_rd==-1
// read natmort setup
LOCAL_CALCS
// clang-format on
N_natMparms = 0;
N_predparms = N_pred;
if (nseas > 1) N_predparms += N_pred * nseas;
natM_5_opt = 0;
MGparm_point.initialize();
// 0=1Parm; 1=segmented; 2=Lorenzen; 3=agespecific; 4=agespec with seas interpolate; 5=Maunder_M; 6=Lorenzen range
*(ad_comm::global_datafile) >> natM_type;
echoinput << natM_type << " natM_type" << endl;
switch (natM_type)
{
case 0:
{
N_natMparms = 1;
break;
}
case 1:
{
*(ad_comm::global_datafile) >> N_natMparms;
echoinput << N_natMparms << " N breakpoints " << endl;
NatM_break.deallocate();
NatM_break.allocate(1, N_natMparms);
*(ad_comm::global_datafile) >> NatM_break(1, N_natMparms);
echoinput << NatM_break << " NatM_age_segment_breaks " << endl;
break;
}
case 2:
{
N_natMparms = 1;
*(ad_comm::global_datafile) >> natM_amin;
echoinput << natM_amin << " natM_A for Lorenzen" << endl;
break;
}
case 3:
{
// same as 4
}
case 4:
{
N_natMparms = 0;
Age_NatMort.deallocate();
Age_NatMort.allocate(1, N_GP * gender, 0, nages);
for (gp = 1; gp <= N_GP * gender; gp++)
{
*(ad_comm::global_datafile) >> Age_NatMort(gp)(0, nages);
}
echoinput << " Age_NatMort empirical input: " << endl
<< Age_NatMort << endl;
break;
}
case 5:
{
// Maunder et al. age and sex specific M
// A) read in an integer for the method to do maturity Maunder_MatType = 1,2,3
*(ad_comm::global_datafile) >> natM_5_opt;
echoinput << " Maunder_NatMort option: " << natM_5_opt << endl;
N_natMparms = 4;
if (natM_5_opt == 3) N_natMparms = 6;
// Maunder_Mjuv = natMparms(1,gp);
// Maunder_lambda = natMparms(2,gp);
// Maunder_lmat = natMparms(3,gp);
// Maunder_Mmat = natMparms(4,gp);
// if(natM_5_opt==3){ //use two parameters mat50% and mat_slope.
// Maunder_L50 = natMparms(5,gp);
// Maunder_beta = natMparms(6,gp);
break;
}
case 6:
{
N_natMparms = 1;
*(ad_comm::global_datafile) >> natM_amin;
echoinput << natM_amin << " natM_minage for Lorenzen" << endl;
*(ad_comm::global_datafile) >> natM_amax;
echoinput << natM_amax << " natM_maxage for Lorenzen" << endl;
break;
}
}
// clang-format off
END_CALCS
// read growth setup
init_int Grow_type // 1=vonbert; 2=Richards; 3=age-specific K ascend; 4=age-specific K descend; 5=age-specific K; 6=read vector(not implemented); 8=growth cessation
!!echoinput<<Grow_type<<" growth model "<<endl;
!!// SS_Label_Info_4.5.1 #Create time constants for growth
number AFIX;
number AFIX2;
number AFIX2_forCV;
number AFIX_delta;
number AFIX_plus;
number Linf_decay; // decay factor to calculate mean L at maxage from Linf and the decaying abundance above maxage
// forced equal to 0.20 in 3.24 (which also assumed linear, not VBK, growth)
int do_ageK;
ivector first_grow_age(1,gmorph);
!! first_grow_age.initialize();
!! k=0;
!! do_ageK=0;
!! if(Grow_type<=2 || Grow_type==8) {k=4;} // AFIX and AFIX2
!! if (Grow_type>=3 && Grow_type<=5) {do_ageK=1; k=5;} // number of ages for age-specific K
init_vector tempvec5(1,k)
int Age_K_count;
LOCAL_CALCS
// clang-format on
Age_K_count = 0;
if (k > 0) echoinput << tempvec5 << " # growth specifications: AFIX1 AFIX2 LINF_decay placeholder age-specific_K_ages" << endl;
k1 = 0;
AFIX = 0.;
AFIX2 = 999.; // this value invokes setting Linf equal to the L2 parameter
Linf_decay = 0.0; // initialize
if (Grow_type == 1)
{
N_growparms = 5;
AFIX = tempvec5(1);
AFIX2 = tempvec5(2);
Linf_decay = tempvec5(3);
// tempvec(4) is a placeholder
}
else if (Grow_type == 2 || Grow_type == 8)
{
N_growparms = 6;
AFIX = tempvec5(1);
AFIX2 = tempvec5(2);
Linf_decay = tempvec5(3);
if (Grow_type == 8 && AFIX2 != 999)
{
N_warn++;
warning << N_warn << " "
<< "AFIX2 set to 999 for grow_type==8 because only Linfinity allowed for growth cessation " << endl;
AFIX2 = 999.;
}
if (Grow_type == 8 && AFIX != 0.0)
{
N_warn++;
warning << N_warn << " "
<< "AFIX set to 0.0 for grow_type==8; growth cessation " << endl;
AFIX2 = 0.0;
}
// tempvec(4) is a placeholder
}
else if (do_ageK == 1)
{
AFIX = tempvec5(1);
AFIX2 = tempvec5(2);
Linf_decay = tempvec5(3);
// tempvec(4) is a placeholder
Age_K_count = tempvec5(5);
echoinput << " read this number of ages for age-specific K " << Age_K_count << endl;
N_growparms = 5 + Age_K_count;
}
else if (Grow_type == 6) // not implemented
{
N_growparms = 2; // for the two CV parameters
k1 = N_GP * gender; // for reading empirical length_at_age
}
echoinput << " N_growparms " << N_growparms << endl;
AFIX2_forCV = AFIX2;
if (AFIX2_forCV > nages) AFIX2_forCV = nages;
AFIX_delta = AFIX2 - AFIX;
if (AFIX != 0.0)
{
AFIX_plus = AFIX;
}
else
{
AFIX_plus = 1.0e-06;
}
N_M_Grow_parms = N_natMparms + N_growparms;
lin_grow.initialize();
echoinput << "g a seas subseas ALK_idx real_age calen_age lin_grow first_grow_age" << endl;
for (g = 1; g <= gmorph; g++)
if (use_morph(g) > 0)
{
for (a = 0; a <= nages; a++)
{
for (s = 1; s <= nseas; s++)
for (subseas = 1; subseas <= N_subseas; subseas++)
{
ALK_idx = (s - 1) * N_subseas + subseas;
// if(a==0 && s<Bseas(g))
// {lin_grow(g,ALK_idx,a)=0.0;} // so fish are not yet born so will get zero length
if (real_age(g, ALK_idx, a) < AFIX)
{
lin_grow(g, ALK_idx, a) = real_age(g, ALK_idx, a) / AFIX_plus;
} // on linear portion of the growth
else if (real_age(g, ALK_idx, a) == AFIX)
{
lin_grow(g, ALK_idx, a) = 1.0; // at the transition from linear to VBK growth
}
else if (first_grow_age(g) == 0)
{
lin_grow(g, ALK_idx, a) = -1.0; // flag for first age on growth curve beyond AFIX
if (subseas == N_subseas) {
first_grow_age(g) = a;
} // so that lingrow will be -1 for rest of this season
}
else
{
lin_grow(g, ALK_idx, a) = -2.0;
} // flag for being in growth curve
if (a < 4) echoinput << g << " " << a << " " << s << " " << subseas << " " << ALK_idx << " " << real_age(g, ALK_idx, a)
<< " " << calen_age(g, ALK_idx, a) << " " << lin_grow(g, ALK_idx, a) << " " << first_grow_age(g) << endl;
}
}
}
// clang-format off
END_CALCS
init_ivector Age_K_points(1,Age_K_count); // points at which age-specific multipliers to K will be applied
!!if(Age_K_count>0) echoinput<<"Age-specific_K_points"<<Age_K_points<<endl;
init_matrix Len_At_Age_rd(1,k1,0,nages)
!!if(k1>0) echoinput<<" Len_At_Age_rd"<<Len_At_Age_rd<<endl;
init_number SD_add_to_LAA // constant added to SD length-at-age (set to 0.1 for compatibility with SS2 V1.x
!!echoinput<<SD_add_to_LAA<<" SD_add_to_LAA"<<endl;
init_int CV_depvar // select CV_growth pattern; 0 CV=f(LAA); 1 CV=F(A); 2 SD=F(LAA); 3 SD=F(A); 4 logSD=f(A) SS2 V1.x ony had CV=F(LAA)
!!echoinput<<CV_depvar<<" CV_depvar"<<endl;
int CV_depvar_a;
int CV_depvar_b;
int Grow_logN
LOCAL_CALCS
// clang-format on
if (Age_K_count > 1)
{