From 1fb37cd86908edb4dab9c6dad28e7e6697897ad7 Mon Sep 17 00:00:00 2001 From: RickMethot Date: Wed, 8 Feb 2023 16:24:40 -0800 Subject: [PATCH 01/22] first commit for B-H with ab add S-R option 10 for a,b formulation --- SS_benchfore.tpl | 12 ++--- SS_param.tpl | 1 + SS_popdyn.tpl | 33 +++++++++++--- SS_readcontrol_330.tpl | 11 ++++- SS_recruit.tpl | 85 ++++++++++++++++++----------------- SS_write_report.tpl | 8 +++- StockSynthesis.code-workspace | 1 + 7 files changed, 94 insertions(+), 57 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index d2e5025e..d95f5171 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -902,7 +902,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } // SPAWN-RECR: calc equil spawn-recr in YPR; need to make this area-specific - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work(2), SR_parm_work(3), SSB_unf, Recr_unf, SSB_equil); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSB_equil); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Bspr = Equ_SpawnRecr_Result(1); Bspr_rec = Equ_SpawnRecr_Result(2); @@ -1017,7 +1017,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) if (rundetail > 0 && mceval_counter == 0 && show_MSY == 1) echoinput << "Calculated F0.1: " << Btgt_Fmult << endl; SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work(2), SR_parm_work(3), SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Btgt = Equ_SpawnRecr_Result(1); Btgt_Rec = Equ_SpawnRecr_Result(2); YPR_Btgt_enc = YPR_enc; // total encountered yield per recruit @@ -1111,7 +1111,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SPR_Btgt = SSB_equil / SPR_unfished; // SPAWN-RECR: calc equil spawn-recr for Btarget calcs; need to make area-specific SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work(2), SR_parm_work(3), SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR yld1(ii) = Equ_SpawnRecr_Result(1); } @@ -1331,7 +1331,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) // SPAWN-RECR: calc spawn-recr for MSY calcs; need to make area-specific MSY_SPR = SSB_equil / SPR_unfished; SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work(2), SR_parm_work(3), SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Bmsy = Equ_SpawnRecr_Result(1); Recr_msy = Equ_SpawnRecr_Result(2); yld1(1) = YPR_opt * Recr_msy; @@ -1424,7 +1424,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) // SPAWN-RECR: calc spawn-recr for MSY calcs; need to make area-specific MSY_SPR = SSB_equil / SPR_unfished; SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work(2), SR_parm_work(3), SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Bmsy = Equ_SpawnRecr_Result(1); Recr_msy = Equ_SpawnRecr_Result(2); Profit = (PricePerF * YPR_val_vec) * Recr_msy - Cost; @@ -1718,7 +1718,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SPR_Btgt2 = SSB_equil / SPR_unfished; // SPAWN-RECR: calc equil spawn-recr for Btarget calcs; need to make area-specific SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work(2), SR_parm_work(3), SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR yld1(ii) = Equ_SpawnRecr_Result(1); } diff --git a/SS_param.tpl b/SS_param.tpl index 9ddf9a86..da7d0d5e 100644 --- a/SS_param.tpl +++ b/SS_param.tpl @@ -416,6 +416,7 @@ PARAMETER_SECTION // note that bycatch_F(1,Nfleet,1,nseas) has similar role number alpha; number beta; + number steepness; number GenTime; number Yield; number Adj4010; diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index e6c64a53..1548b7d4 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -337,17 +337,38 @@ FUNCTION void get_initial_conditions() Fishon = 0; virg_fec = fec; Recr.initialize(); // will store recruitment by area + + // SPAWN-RECR: get expected recruitment globally or by area + if (recr_dist_area == 1 || pop == 1) // do global spawn_recruitment calculations + { + equ_Recr = 1.0; + Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation. Returns SPR because R = 1.0 + SPR_virgin = SSB_equil; // spawners per recruit. Needed for Sr_fxn = 10 + + if(SR_fxn == 10) // B-H with a,b + { + alpha = mfexp(SR_parm(3)); + beta = mfexp(SR_parm(4)); + steepness = alpha * SPR_virgin / (4.00 + alpha * SPR_virgin); + Recr_virgin = 1.0 / beta * (alpha - ( 1.0 / SPR_virgin)); + SR_parm(1) = log(Recr_virgin); + SR_parm(2) = steepness; + // warning<< SR_parm(1) << " Ln(R0) " << mfexp(SR_parm(1)) << endl + // << " alpha_beta: "< SSB_virgin_adj) { SSB_BH1 = SSB_virgin_adj; @@ -167,6 +157,14 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab NewRecruits = Recr_virgin_adj * temp * mfexp(RkrTop); break; } + + case 10: // Beverton-Holt with alpha beta + { + alpha = mfexp(SR_parm_work(3)); + beta = mfexp(SR_parm_work(4)); + NewRecruits = (alpha*SSB_curr_adj) / (1.0 + beta * SSB_curr_adj); + break; + } } RETURN_ARRAYS_DECREMENT(); return NewRecruits; @@ -270,7 +268,7 @@ FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_vir //******************************************************************** /* SS_Label_FUNCTION 44 Equil_Spawn_Recr_Fxn */ // SPAWN-RECR: function Equil_Spawn_Recr_Fxn -FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prevariable& SRparm3, +FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, const prevariable& SSB_virgin, const prevariable& Recr_virgin, const prevariable& SPR_temp) { RETURN_ARRAYS_INCREMENT(); @@ -286,7 +284,7 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev dvariable srz_min; dvariable SRZ_surv; - steepness = SRparm2; // common usage but some different + steepness = SRparm(2); // common usage but some different // SS_Label_44.1 calc equilibrium SpawnBio and Recruitment from input SPR_temp, which is spawning biomass per recruit at some given F level switch (SR_fxn) { @@ -296,16 +294,7 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev write_message (FATAL, 0); // EXIT! break; } - // SS_Label_44.1.1 Beverton-Holt with flattop beyond Bzero - case 6: //Beverton-Holt - { - alpha = 4.0 * steepness * Recr_virgin / (5. * steepness - 1.); - beta = (SSB_virgin * (1. - steepness)) / (5. * steepness - 1.); - B_equil = alpha * SPR_temp - beta; - B_equil = posfun(B_equil, 0.0001, temp); - R_equil = (4. * steepness * Recr_virgin * B_equil) / (SSB_virgin * (1. - steepness) + (5. * steepness - 1.) * B_equil); - break; - } + // SS_Label_44.1.2 Ricker case 2: // Ricker { @@ -314,17 +303,32 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev break; } - // SS_Label_44.1.3 Beverton-Holt + // SS_Label_44.1.1 Beverton-Holt + case 6: //Beverton-Holt with flattop beyond Bzero, but no flattop in equil calcs + { + } + // SS_Label_44.1.3 Beverton-Holt case 3: // same as case 6 { - alpha = 4.0 * steepness * Recr_virgin / (5. * steepness - 1.); - beta = (SSB_virgin * (1. - steepness)) / (5. * steepness - 1.); + dvariable SPR = SSB_virgin / Recr_virgin; + alpha = ((4.0 * steepness) / (1. - steepness)) / SPR ; + beta = (1.0 / Recr_virgin) * (alpha - (1.0 / SPR)); B_equil = alpha * SPR_temp - beta; B_equil = posfun(B_equil, 0.0001, temp); R_equil = (4. * steepness * Recr_virgin * B_equil) / (SSB_virgin * (1. - steepness) + (5. * steepness - 1.) * B_equil); //Beverton-Holt break; } + case 10: // Beverton-Holt with alpha and beta parameterization + { + alpha = mfexp(SRparm(3)); + beta = mfexp(SRparm(4)); + B_equil = alpha * SPR_temp - beta; + B_equil = posfun(B_equil, 0.0001, temp); + R_equil = (alpha * Recr_virgin * B_equil) / (1.0 + beta * Recr_virgin * B_equil); + break; + } + // SS_Label_44.1.4 constant recruitment case 4: // constant; no bias correction { @@ -335,7 +339,7 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev // SS_Label_44.1.5 Hockey Stick case 5: // hockey stick { - alpha = SRparm3 * Recr_virgin; // min recruitment level + alpha = SRparm(3) * Recr_virgin; // min recruitment level // temp=SSB_virgin/R0*steepness; // spawners per recruit at inflection beta = (Recr_virgin - alpha) / (steepness * SSB_virgin); // slope of recruitment on spawners below the inflection B_equil = Join_Fxn(0.0 * SSB_virgin / Recr_virgin, SSB_virgin / Recr_virgin, SSB_virgin / Recr_virgin * steepness, SPR_temp, alpha / ((1. / SPR_temp) - beta), SPR_temp * Recr_virgin); @@ -347,9 +351,8 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev { SRZ_0 = log(1.0 / (SSB_virgin / Recr_virgin)); srz_min = SRZ_0 * (1.0 - steepness); - B_equil = SSB_virgin * (1. - (log(1. / SPR_temp) - SRZ_0) / pow((srz_min - SRZ_0), (1. / SRparm3))); - B_equil = posfun(B_equil, 0.0001, temp); - SRZ_surv = mfexp((1. - pow((B_equil / SSB_virgin), SRparm3)) * (srz_min - SRZ_0) + SRZ_0); // survival + B_equil = SSB_virgin * (1. - (log(1. / SPR_temp) - SRZ_0) / pow((srz_min - SRZ_0), (1. / SRparm(3)))); + SRZ_surv = mfexp((1. - pow((B_equil / SSB_virgin), SRparm(3))) * (srz_min - SRZ_0) + SRZ_0); // survival R_equil = B_equil * SRZ_surv; break; } @@ -367,14 +370,14 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev // REC = (TOP/BOT)**(1.0/POWER)*SPRF0/SPR // Power = exp(logC); // Hupper = 1.0/(5.0 * pow(0.2,Power)); - Shepherd_c = SRparm3; - Shepherd_c2 = pow(0.2, SRparm3); + Shepherd_c = SRparm(3); + Shepherd_c2 = pow(0.2, SRparm(3)); Hupper = 1.0 / (5.0 * Shepherd_c2); - steepness = 0.2 + (SRparm2 - 0.2) / (0.8) * (Hupper - 0.2); + steepness = 0.2 + (SRparm(2) - 0.2) / (0.8) * (Hupper - 0.2); Shep_top = 5.0 * steepness * (1.0 - Shepherd_c2) * (SPR_temp * Recr_virgin) / SSB_virgin - (1.0 - 5.0 * steepness * Shepherd_c2); Shep_bot = 5.0 * steepness - 1.0; Shep_top2 = posfun(Shep_top, 0.001, temp); - R_equil = (SSB_virgin / SPR_temp) * pow((Shep_top2 / Shep_bot), (1.0 / SRparm3)); + R_equil = (SSB_virgin / SPR_temp) * pow((Shep_top2 / Shep_bot), (1.0 / SRparm(3))); B_equil = R_equil * SPR_temp; break; } @@ -382,8 +385,8 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const prevariable& SRparm2, const prev // SS_Label_43.3.8 Ricker-power case 9: // Ricker power 3-parameter SRR. per Punt & Cope 2017 { - steepness = SRparm2; - dvariable RkrPower = SRparm3; + steepness = SRparm(2); + dvariable RkrPower = SRparm(3); temp = SSB_virgin / (SPR_temp * Recr_virgin); dvariable RkrTop = pow(0.8, RkrPower) * log(temp) / log(5.0 * steepness); RkrTop = posfun(RkrTop, 0.000001, CrashPen); diff --git a/SS_write_report.tpl b/SS_write_report.tpl index ed3af3bc..17a54ff3 100644 --- a/SS_write_report.tpl +++ b/SS_write_report.tpl @@ -1783,8 +1783,12 @@ FUNCTION void write_bigoutput() << pick_report_name(19); SS2out << " Function: " << SR_fxn << " RecDev_method: " << do_recdev << " sum_recdev: " << sum_recdev << endl << SR_parm(1) << " Ln(R0) " << mfexp(SR_parm(1)) << endl - << steepness << " steepness" << endl + << steepness << " steepness " << "#_derived_alpha_beta: "< Date: Mon, 13 Feb 2023 17:36:35 -0800 Subject: [PATCH 02/22] revise to use WHAM syntax --- SS_benchfore.tpl | 5 ++++- SS_popdyn.tpl | 5 ++--- SS_recruit.tpl | 43 ++++++++++++++++++++++++++++--------------- SS_write_report.tpl | 23 +++++++++++++++++------ 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index d95f5171..badaeb38 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -748,6 +748,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Recr_unf = mfexp(SR_parm_work(1)); Do_Equil_Calc(Recr_unf); SSB_unf = SSB_equil; + report5<<" calc SSBunf "< SSB_virgin_adj) { SSB_BH1 = SSB_virgin_adj; @@ -162,7 +163,7 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab { alpha = mfexp(SR_parm_work(3)); beta = mfexp(SR_parm_work(4)); - NewRecruits = (alpha*SSB_curr_adj) / (1.0 + beta * SSB_curr_adj); + NewRecruits = (alpha * SSB_curr_adj) / (beta + SSB_curr_adj); break; } } @@ -310,22 +311,34 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, // SS_Label_44.1.3 Beverton-Holt case 3: // same as case 6 { - dvariable SPR = SSB_virgin / Recr_virgin; - alpha = ((4.0 * steepness) / (1. - steepness)) / SPR ; - beta = (1.0 / Recr_virgin) * (alpha - (1.0 / SPR)); - B_equil = alpha * SPR_temp - beta; + // from WHAM per Tim Miller: + // WHAM based on R = A*S/(1+B*S) + // log_SR_a = log(4 * SR_h/(exp(log_SPR0)*(1 - SR_h))); + // log_SR_b = log((5*SR_h - 1)/((1-SR_h)*SR_R0*exp(log_SPR0))); + // SR_h = 0.2 * exp(0.8*log(exp(log_SR_a) * exp(log_SPR0))); + // SR_R0 = log(exp(log_SR_a + log_SPR0))/(exp(log_SR_b + log_SPR0)); + + // SS3 previously used alternative formulation: R = A*S/(B+S) + // converting SS3 to align with WHAM + alpha = 4.0 * steepness / (SPR_virgin * (1. - steepness)); + beta = (5.0 * steepness - 1.0) / ((1 - steepness) * SSB_virgin); + B_equil = (alpha * SPR_temp - 1.0) / beta; B_equil = posfun(B_equil, 0.0001, temp); - R_equil = (4. * steepness * Recr_virgin * B_equil) / (SSB_virgin * (1. - steepness) + (5. * steepness - 1.) * B_equil); //Beverton-Holt + R_equil = alpha * B_equil / (1.0 + beta * B_equil); +// report5<<" WHAM Beq "< Date: Mon, 13 Feb 2023 17:43:58 -0800 Subject: [PATCH 03/22] Update .gitignore --- .gitignore | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 7036b5eb..7dfad946 100644 --- a/.gitignore +++ b/.gitignore @@ -7,10 +7,9 @@ *.htp *.obj *.log -ss.tpl -ss3.tpl -ss_opt.tpl -ss_trans.tpl +Compile/ss.tpl +Compile/ss_opt.tpl +Compile/ss_trans.tpl ~$*.* Compile/ss.log Compile/ss3.log From cc71b493c7c93d17e8fb6640836e58d5d4f6adcf Mon Sep 17 00:00:00 2001 From: RickMethot Date: Fri, 19 May 2023 11:14:13 -0700 Subject: [PATCH 04/22] Srr=10 now matching SRR=3 --- SS_popdyn.tpl | 15 ++++++++------- SS_readcontrol_330.tpl | 2 +- SS_recruit.tpl | 5 ++--- SS_write_report.tpl | 10 ++++------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index 766486c6..724ee024 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -347,17 +347,18 @@ FUNCTION void get_initial_conditions() if(SR_fxn == 10) // B-H with a,b { + // WHAM based on R = A*S/(1+B*S) + // log_SR_a = log(4 * SR_h/(exp(log_SPR0)*(1 - SR_h))); + // log_SR_b = log((5*SR_h - 1)/((1-SR_h)*SR_R0*exp(log_SPR0))); + // h = a * SPR0 / (4. + a * SPR0) + // R0 = 1/b * (a-1/SPR0) + alpha = mfexp(SR_parm(3)); beta = mfexp(SR_parm(4)); - alpha = 4.0 * steepness / (SPR_virgin * (1. - steepness)); - beta = (5.0 * steepness - 1.0) / ((1 - steepness) * SSB_virgin); + steepness = alpha * SPR_virgin / (4. + alpha * SPR_virgin); + Recr_virgin = 1. / beta * (alpha - (1. / SPR_virgin)); SR_parm(1) = log(Recr_virgin); SR_parm(2) = steepness; - // warning<< SR_parm(1) << " Ln(R0) " << mfexp(SR_parm(1)) << endl - // << " alpha_beta: "< Date: Fri, 19 May 2023 17:06:15 -0700 Subject: [PATCH 05/22] adding reporting for timevary growth --- SS_benchfore.tpl | 8 ++++++++ SS_popdyn.tpl | 8 ++++++++ SS_write_report.tpl | 14 ++++++++------ StockSynthesis.code-workspace | 3 ++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index badaeb38..ecafcd8c 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -3650,6 +3650,14 @@ FUNCTION void Get_Forecast() Smry_Table(y, 11) = SSB_equil; Smry_Table(y, 13) = GenTime; + if( SR_fxn == 10 ) + { + temp = SSB_equil / equ_Recr; // current year's SPB/R with current biology at age + alpha = mfexp(SR_parm_work(3)); + beta = mfexp(SR_parm_work(4)); + SR_parm_byyr(y, 2) = alpha * temp / (4. + alpha * temp); // implied steepness + SR_parm_byyr(y, 1) = log( 1. / beta * (alpha - (1. / temp))); // implied ln_R0 + } Fishon = 1; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation if (STD_Yr_Reverse_Ofish(y) > 0) diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index 724ee024..58476d6c 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -1785,6 +1785,14 @@ FUNCTION void get_time_series() Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation with current year's biology Smry_Table(y, 11) = SSB_equil; Smry_Table(y, 13) = GenTime; + if( SR_fxn == 10 ) + { + temp = SSB_equil / Recr_virgin; // current year's SPB/R with current biology at age + alpha = mfexp(SR_parm_work(3)); + beta = mfexp(SR_parm_work(4)); + SR_parm_byyr(y, 2) = alpha * temp / (4. + alpha * temp); // implied steepness + SR_parm_byyr(y, 1) = log( 1. / beta * (alpha - (1. / temp))); // implied ln_R0 + } Fishon = 1; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation with current year's biology and F if (STD_Yr_Reverse_Ofish(y) > 0) diff --git a/SS_write_report.tpl b/SS_write_report.tpl index 10b9b6a3..00e27e89 100644 --- a/SS_write_report.tpl +++ b/SS_write_report.tpl @@ -1789,7 +1789,7 @@ FUNCTION void write_bigoutput() if (SR_fxn == 10) { SS2out << " Ln_alpha_parameter: " << SR_parm(3) << " alpha " << mfexp(SR_parm(3)) << endl; - SS2out << " Ln_beta_parameter: " << SR_parm(4) << " beta " << mfexp(SR_parm(4)) << endl; + SS2out << " Ln_beta_parameter: " << SR_parm(4) << " beta " << mfexp(SR_parm(4)); } else if (SR_fxn == 3) { @@ -1813,9 +1813,7 @@ FUNCTION void write_bigoutput() { SS2out << " Ricker_Power: " << SR_parm(3); } - - SS2out << endl; - SS2out << sigmaR << " sigmaR" << endl; + SS2out << endl << sigmaR << " sigmaR" << endl; SS2out << init_equ_steepness << " # 0/1 to use steepness in initial equ recruitment calculation" << endl; SS2out << SR_parm(N_SRparm2 - 1) << " init_eq: see below" << endl @@ -1848,7 +1846,7 @@ FUNCTION void write_bigoutput() } SS2out << endl; - SS2out << "Yr SpawnBio exp_recr with_regime bias_adjusted pred_recr dev biasadjuster era mature_bio mature_num raw_dev" << endl; + SS2out << "Yr SpawnBio exp_recr with_regime bias_adjusted pred_recr dev biasadjuster era mature_bio mature_num raw_dev SPR0 h R0" << endl; SS2out << "S/Rcurve " << SSB_virgin << " " << Recr_virgin << endl; y = styr - 2; SS2out << "Virg " << SSB_yr(y) << " " << exp_rec(y) << " - " << 0.0 << " Virg " << SSB_B_yr(y) << " " << SSB_N_yr(y) << " 0.0 " << endl; @@ -1899,7 +1897,11 @@ FUNCTION void write_bigoutput() { SS2out << " _ _ Fixed"; } - SS2out << endl; + temp = Smry_Table(y,11) / Recr_virgin; + alpha = mfexp(SR_parm_byyr(y,3)); + beta = mfexp(SR_parm_byyr(y,4)); + SS2out << " " << temp << " " << alpha * temp / (4. + alpha * temp) << " " << 1. / beta * (alpha - (1. / temp)); + SS2out << SR_parm_byyr(y)(1,4) << endl; } // REPORT_KEYWORD SPAWN_RECR_CURVE diff --git a/StockSynthesis.code-workspace b/StockSynthesis.code-workspace index cdd30489..14159ac5 100644 --- a/StockSynthesis.code-workspace +++ b/StockSynthesis.code-workspace @@ -11,7 +11,8 @@ "*.htp": "c", "ostream": "c", "xlocale": "c", - "iosfwd": "c" + "iosfwd": "c", + "cmath": "c" }, "explorer.excludeGitIgnore": true } From 63c8681015a082be98608b94609111a06ee6580c Mon Sep 17 00:00:00 2001 From: RickMethot Date: Wed, 31 May 2023 09:40:07 -0700 Subject: [PATCH 06/22] WIP --- SS_benchfore.tpl | 19 ++++++++++++------- SS_recruit.tpl | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index ecafcd8c..b8e232f6 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -748,18 +748,22 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Recr_unf = mfexp(SR_parm_work(1)); Do_Equil_Calc(Recr_unf); SSB_unf = SSB_equil; - report5<<" calc SSBunf "< Date: Wed, 22 May 2024 16:11:03 -0700 Subject: [PATCH 07/22] working version with a,b --- SS_recruit.tpl | 41 +++++++++++++++++++---------------------- SS_write_report.tpl | 8 ++++---- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/SS_recruit.tpl b/SS_recruit.tpl index c24509c0..5553dd26 100644 --- a/SS_recruit.tpl +++ b/SS_recruit.tpl @@ -49,15 +49,19 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab case 3: // Beverton-Holt { steepness = SR_parm_work(2); -// dvariable SPR = SSB_virgin_adj / Recr_virgin; -// dvariable alpha = (4.0 * steepness) / ( SPR * (1. - steepness)) ; -// dvariable beta = (5.0 * steepness - 1.0 )/((1.0 - steepness ) * Recr_virgin * SPR ); -// beta = (1.0 / Recr_virgin) * (alpha - (1.0 / SPR)); NewRecruits = (4. * steepness * Recr_virgin_adj * SSB_curr_adj) / (SSB_virgin_adj * (1. - steepness) + (5. * steepness - 1.) * SSB_curr_adj); break; } + case 10: // Beverton-Holt with alpha beta per WHAM: R = A*S/(1+B*S) + { + alpha = mfexp(SR_parm_work(3)); + beta = mfexp(SR_parm_work(4)); + NewRecruits = (alpha * SSB_curr_adj) / (1.0 + beta * SSB_curr_adj); + break; + } + // SS_Label_43.3.4 constant expected recruitment case 4: // none { @@ -159,14 +163,6 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab break; } - case 10: // Beverton-Holt with alpha beta - { - // WHAM based on R = A*S/(1+B*S) - alpha = mfexp(SR_parm_work(3)); - beta = mfexp(SR_parm_work(4)); - NewRecruits = (alpha * SSB_curr_adj) / (1.0 + beta * SSB_curr_adj); - break; - } } RETURN_ARRAYS_DECREMENT(); return NewRecruits; @@ -322,18 +318,19 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, SPR_virgin = SSB_virgin / Recr_virgin; alpha = 4.0 * steepness / (SPR_virgin * (1. - steepness)); beta = (5.0 * steepness - 1.0) / ((1 - steepness) * SSB_virgin); - report5<<" alpha "< Date: Tue, 28 May 2024 14:39:34 -0700 Subject: [PATCH 08/22] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 7dfad946..a602a79c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ Compile/ss.tpl Compile/ss_opt.tpl Compile/ss_trans.tpl +Compile/ss3.tpl +Compile/Make_SS_warn.bat ~$*.* Compile/ss.log Compile/ss3.log From d01422e9739e4f8a22d4e406dc72def7b4678a32 Mon Sep 17 00:00:00 2001 From: Rick-Methot-NOAA Date: Wed, 12 Jun 2024 14:50:29 -0700 Subject: [PATCH 09/22] augment spawn_recr report and use to test time-vary SR_parm approach --- SS_benchfore.tpl | 12 ++-- SS_popdyn.tpl | 18 ++++-- SS_readcontrol_330.tpl | 9 +++ SS_recruit.tpl | 13 ++-- SS_write_report.tpl | 139 ++++++++++++++++++++++++++++++++++------- 5 files changed, 156 insertions(+), 35 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index b8e232f6..69dd8ffc 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -753,7 +753,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) { report5 << "SR_parm for benchmark: " << SR_parm_work << endl << "mean from years: " << Bmark_Yr(9) << " " << Bmark_Yr(10) << endl; - SPR_virgin = SSB_virgin / Recr_virgin; + // SPR_virgin = SSB_virgin / Recr_virgin; // already defined Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR report5 << " Virgin SPR0, SSB, R: " << SPR_virgin << " " << Equ_SpawnRecr_Result << endl; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_unfished); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR @@ -1906,15 +1906,15 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } else if (show_MSY == 2) // do brief output { - SS2out << SPR_actual / 100. << " " << SPR_Fmult << " " << Mgmt_quant(10) << " " << YPR_spr_dead / Vbio1_spr << " " << Bspr_rec << " " + report5 << SPR_actual / 100. << " " << SPR_Fmult << " " << Mgmt_quant(10) << " " << YPR_spr_dead / Vbio1_spr << " " << Bspr_rec << " " << Bspr << " " << YPR_spr_dead * Bspr_rec << " " << YPR_spr_ret * Bspr_rec << " " << Vbio1_spr * Bspr_rec << " # "; - SS2out << SPR_Btgt << " " << Btgt / SSB_unf << " " << Btgt_Fmult << " " << Mgmt_quant(7) << " " << YPR_Btgt_dead / Vbio1_Btgt << " " << Btgt_Rec << " " + report5 << SPR_Btgt << " " << Btgt / SSB_unf << " " << Btgt_Fmult << " " << Mgmt_quant(7) << " " << YPR_Btgt_dead / Vbio1_Btgt << " " << Btgt_Rec << " " << Btgt << " " << YPR_Btgt_dead * Btgt_Rec << " " << YPR_Btgt_ret * Btgt_Rec << " " << Vbio1_Btgt * Btgt_Rec << " # "; - SS2out << MSY_SPR << " " << Bmsy / SSB_unf << " " << MSY_Fmult << " " << Mgmt_quant(14) << " " << MSY / (Vbio1_MSY * Recr_msy) << " " << Recr_msy << " " + report5 << MSY_SPR << " " << Bmsy / SSB_unf << " " << MSY_Fmult << " " << Mgmt_quant(14) << " " << MSY / (Vbio1_MSY * Recr_msy) << " " << Recr_msy << " " << Bmsy << " " << MSY << " " << YPR_msy_dead * Recr_msy << " " << YPR_msy_ret * Recr_msy << " " << Vbio1_MSY * Recr_msy << " # " << endl; } @@ -2578,6 +2578,7 @@ FUNCTION void Get_Forecast() } } // SPAWN-RECR: get recruitment in forecast; needs to be area-specific + // SR_fxn if (SR_parm_timevary(1) == 0) // R0 is not time-varying { R0_use = Recr_virgin; @@ -3216,7 +3217,8 @@ FUNCTION void Get_Forecast() } } // SS_Label_Info_24.3.4.1 #Get recruitment from this spawning biomass - // SPAWN-RECR: calc recruitment in time series; need to make this area-specififc + // SPAWN-RECR: calc recruitment in time series; need to make this area-specific + // SR_fxn if (SR_parm_timevary(1) == 0) // R0 is not time-varying { R0_use = Recr_virgin; diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index 58476d6c..265e2c37 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -357,6 +357,7 @@ FUNCTION void get_initial_conditions() beta = mfexp(SR_parm(4)); steepness = alpha * SPR_virgin / (4. + alpha * SPR_virgin); Recr_virgin = 1. / beta * (alpha - (1. / SPR_virgin)); +// warning << " before AB_calcs " << "parm " << SR_parm(1) << " calc " << log(Recr_virgin) << endl; SR_parm(1) = log(Recr_virgin); SR_parm(2) = steepness; } @@ -370,6 +371,8 @@ FUNCTION void get_initial_conditions() SR_parm_virg(i) = SR_parm(i); SR_parm_work(i) = SR_parm(i); } +// if (SR_fxn == 3) warning << "tester_A: " << SR_parm_work(1) << " base: " << SR_parm(1) << endl; +// if (SR_fxn == 10) warning << "tester_A: " << SR_parm_work(4) << " base: " << SR_parm(4) << endl; equ_Recr = Recr_virgin; exp_rec(eq_yr, 1) = Recr_virgin; // expected Recr from s-r parms exp_rec(eq_yr, 2) = Recr_virgin; @@ -476,6 +479,9 @@ FUNCTION void get_initial_conditions() else { SR_parm_work(f) = parm_timevary(SR_parm_timevary(f), eq_yr); +// warning << "tester_B: " << SR_parm_work(f) << " timevary " << " base " << SR_parm(f) < 0 || SR_parm_timevary(4) > 0) ) {SR_update_SPR0 = 1;} // alpha or beta is time-varying + else if ((SR_parm_timevary(1) > 0 || SR_parm_timevary(2) > 0) ) {SR_update_SPR0 = 1;} // R0 or steepness is time-varying } } N_SRparm3 = N_SRparm2; diff --git a/SS_recruit.tpl b/SS_recruit.tpl index 5553dd26..2065b277 100644 --- a/SS_recruit.tpl +++ b/SS_recruit.tpl @@ -22,6 +22,7 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab dvariable SRZ_0; dvariable srz_min; dvariable SRZ_surv; +// warning << y << " Tester_R0 " << Recr_virgin_adj << " SSB0 " << SSB_virgin_adj << " SSB_curr: " << SSB_current << endl; // SS_Label_43.1 add 0.1 to input spawning biomass value to make calculation more rebust SSB_curr_adj = SSB_current + 0.100; // robust @@ -56,8 +57,8 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab case 10: // Beverton-Holt with alpha beta per WHAM: R = A*S/(1+B*S) { - alpha = mfexp(SR_parm_work(3)); - beta = mfexp(SR_parm_work(4)); + dvariable alpha = mfexp(SR_parm_work(3)); + dvariable beta = mfexp(SR_parm_work(4)); NewRecruits = (alpha * SSB_curr_adj) / (1.0 + beta * SSB_curr_adj); break; } @@ -315,10 +316,12 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, // SS3 previously used alternative formulation: R = A*S/(B+S) // converting SS3 to align with WHAM - SPR_virgin = SSB_virgin / Recr_virgin; + // SPR_virgin = SSB_virgin / Recr_virgin; // this is already defined alpha = 4.0 * steepness / (SPR_virgin * (1. - steepness)); beta = (5.0 * steepness - 1.0) / ((1 - steepness) * SSB_virgin); + // " h " << steepness << " derive " << alpha * SPR_virgin / (4. + alpha * SPR_virgin) << " " << endl; + // " R0 " << Recr_virgin << " derive " << 1. / beta * (alpha - 1./SPR_virgin) << endl; // report5 <<" SSB_unf "< 0 && j <= 4 ) // timevary SRparm exists + {SS2out << " #_is_time_vary,_so_SRR_updates_base_SPR_annually";} + if (j == (N_SRparm2 - 1) && SR_parm_timevary(j) > 0) // timevary regime exists + {SS2out << " #_Persistent_deviations_from_SRR_(e.g.regimes)_exist";} + SS2out << endl; + } + + SS2out << "# " < Bmark_Yr(k)) + {SS2out << "#_range_of_years_is_averaged,_so_reduces_standard_error_of_result;_do_this_only_when_timevarying_makes_necessary: " << k << " "<< k+1 << endl;} + } + SS2out << "SPR_unfished_benchmark: " << Mgmt_quant(1) / Mgmt_quant(4) << " #_based_on_averaging_biology_over_benchmark_year_range " << endl; + SS2out << "Bmsy/Bzero: "<< Bmsy / SSB_virgin << " # using styr bio for Bzero" << endl; + SS2out << "Bmsy/Bunf: "<< Bmsy / Mgmt_quant(1) << " # using MSY's averaged bio for Bunf" << endl; + + SS2out << "#" << endl << "RecDev_method: " << do_recdev << endl << "sum_recdev: " << sum_recdev << endl << "recr_logL: " << recr_like << endl; + SS2out << recdev_start << " " << recdev_end << " main_recdev:start_end" << endl + << recdev_adj(1) << " " << recdev_adj(2, 5) << " breakpoints_for_bias_adjustment_ramp " << endl; + + temp = sigmaR * sigmaR; // sigmaR^2 + SS2out << "ERA N RMSE RMSE^2/sigmaR^2 mean_BiasAdj est_rho Durbin-Watson" << endl; + SS2out << "main " << n_rmse(1) << " " << rmse(1) << " " << square(rmse(1)) / temp << " " << rmse(2) << " " << cross / var << " " << Durbin; + if (wrote_bigreport == 0) // first time writing bigreport + { + if (rmse(1) < 0.5 * sigmaR && rmse(2) > (0.01 + 2.0 * square(rmse(1)) / temp)) + { + warnstream << "Main recdev biasadj is >2 times ratio of rmse to sigmaR"; + SS2out << " # " << warnstream.str() ; + write_message (WARN, 0); + } + } + SS2out << endl; + + SS2out << "early " << n_rmse(3) << " " << rmse(3) << " " << square(rmse(3)) / temp << " " << rmse(4); + if (wrote_bigreport == 0) // first time writing bigreport + { + if (rmse(3) < 0.5 * sigmaR && rmse(4) > (0.01 + 2.0 * square(rmse(3)) / temp)) + { + warnstream << "Early recdev biasadj is >2 times ratio of rmse to sigmaR"; + SS2out << " # " << warnstream.str(); + write_message (WARN, 0); + } + } + SS2out << endl << "#" << endl << "Initial_equilibrium: " << init_equ_steepness << " # 0/1_to_use_spawner-recruitment_in_initial_equ_recruitment_calculation" << endl << "#" << endl; + + SS2out << "Yr SpawnBio exp_recr with_regime bias_adjusted pred_recr dev biasadjuster era mature_bio mature_num raw_dev SPR0_curr h_curr R0_curr P1 P2 P3 P4" << endl; SS2out << "S/Rcurve " << SSB_virgin << " " << Recr_virgin << endl; y = styr - 2; SS2out << "Virg " << SSB_yr(y) << " " << exp_rec(y) << " - " << 0.0 << " Virg " << SSB_B_yr(y) << " " << SSB_N_yr(y) << " 0.0 " << endl; @@ -1897,10 +1994,10 @@ FUNCTION void write_bigoutput() { SS2out << " _ _ Fixed"; } - dvariable SPR = Smry_Table(y, 11) / Recr_virgin; - alpha = mfexp(SR_parm_byyr(y,3)); - beta = mfexp(SR_parm_byyr(y,4)); - SS2out << " " << SPR << " " << alpha * SPR / (4. + alpha * SPR) << " " << 1. / beta * (alpha - (1. / SPR)); + dvariable SPR_curr = Smry_Table(y, 11) / Recr_virgin; + SS2out << " " << SPR_curr << " "; + SS2out << alpha * SPR_curr / (4. + alpha * SPR_curr) << " "; // steepness with current SPR + SS2out << 1. / beta * (alpha - (1. / SPR_curr)) << " "; // R0 with current SPR SS2out << SR_parm_byyr(y)(1,4) << endl; } From 92208d49846353ba47287c5351e3034c782e5e05 Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Wed, 26 Jun 2024 15:05:50 -0700 Subject: [PATCH 10/22] adding benchmark change --- SS_benchfore.tpl | 4 ++-- SS_write_report.tpl | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 69dd8ffc..3801e082 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -1340,7 +1340,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) MSY_SPR = SSB_equil / SPR_unfished; SPR_temp = SSB_equil; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - Bmsy = Equ_SpawnRecr_Result(1); + Bmsy = Equ_SpawnRecr_Result(1); // with MSY set to SPR, not directly estimated Recr_msy = Equ_SpawnRecr_Result(2); yld1(1) = YPR_opt * Recr_msy; YPR_msy_enc = YPR_enc; @@ -1433,7 +1433,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) MSY_SPR = SSB_equil / SPR_unfished; SPR_temp = SSB_equil; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - Bmsy = Equ_SpawnRecr_Result(1); + Bmsy = Equ_SpawnRecr_Result(1); // MSY is directly estimated Recr_msy = Equ_SpawnRecr_Result(2); Profit = (PricePerF * YPR_val_vec) * Recr_msy - Cost; if (Do_MSY == 2) // dead catch without excluded bycatch fleets diff --git a/SS_write_report.tpl b/SS_write_report.tpl index a550c756..cee1ba29 100644 --- a/SS_write_report.tpl +++ b/SS_write_report.tpl @@ -1851,7 +1851,7 @@ FUNCTION void write_bigoutput() SS2out << "# " < Date: Wed, 3 Jul 2024 15:30:57 -0700 Subject: [PATCH 11/22] format changes for spawn_recr report --- SS_readcontrol_330.tpl | 6 +++++- SS_write_report.tpl | 40 ++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/SS_readcontrol_330.tpl b/SS_readcontrol_330.tpl index 2a5925ca..338de133 100644 --- a/SS_readcontrol_330.tpl +++ b/SS_readcontrol_330.tpl @@ -1979,7 +1979,11 @@ SR_update_SPR0 = 0; //#_SR_function: 1=null; 2=Ricker; 3=std_B-H; 4=SCAA; 5=Hockey; 6=B-H_flattop; 7=Survival_3Parm; 10=B-H with a,b "< 0 && j <= 4 ) // timevary SRparm exists {SS2out << " #_is_time_vary,_so_SRR_updates_base_SPR_annually";} if (j == (N_SRparm2 - 1) && SR_parm_timevary(j) > 0) // timevary regime exists - {SS2out << " #_Persistent_deviations_from_SRR_(e.g.regimes)_exist";} + {SS2out << " #_Regime_parameter_used_to_offset_from_SRR";} SS2out << endl; } @@ -1869,8 +1870,8 @@ FUNCTION void write_bigoutput() { SS2out << "Ln(alpha): " << SR_parm(3) << " alpha " << mfexp(SR_parm(3)) << endl; SS2out << "Ln(beta): " << SR_parm(4) << " beta " << mfexp(SR_parm(4)) << endl; - SS2out << "steepness_derived: " << alpha * SPR_virgin / (4. + alpha * SPR_virgin) << endl; // steepness virgin SS2out << "ln(R0)_derived: " << log( 1. / beta * (alpha - (1. / SPR_virgin))) << endl; // virgin R0 + SS2out << "steepness_derived: " << alpha * SPR_virgin / (4. + alpha * SPR_virgin) << endl; // steepness virgin break; } case 8: @@ -1882,19 +1883,12 @@ FUNCTION void write_bigoutput() Shepherd_c2 = pow(0.2, Shepherd_c); Hupper = 1.0 / (5.0 * Shepherd_c2); temp = 0.2 + (SR_parm(2) - 0.2) / (0.8) * (Hupper - 0.2); - SS2out << " Shepherd_c: " << Shepherd_c << " steepness_limit: " << Hupper << " Adjusted_steepness: " << temp << endl; - break; - } - case 9: - { - SS2out << " Ricker_Parm1: " << SR_parm(1) << endl; - SS2out << " Ricker_Parm2: " << SR_parm(2) << endl; - SS2out << " Ricker_Power: " << SR_parm(3) << endl; + SS2out << "Shepherd_c: " << Shepherd_c << endl << "Shepard_steepness_limit: " << Hupper << endl << "Shepard_adjusted_steepness: " << temp << endl; break; } default: { - SS2out << "default output needed " << endl; + SS2out << "other_SRR " << endl; break; } } @@ -1914,8 +1908,8 @@ FUNCTION void write_bigoutput() SS2out << "Bmsy/Bunf: "<< Bmsy / Mgmt_quant(1) << " # using MSY's averaged bio for Bunf" << endl; SS2out << "#" << endl << "RecDev_method: " << do_recdev << endl << "sum_recdev: " << sum_recdev << endl << "recr_logL: " << recr_like << endl; - SS2out << recdev_start << " " << recdev_end << " main_recdev:start_end" << endl - << recdev_adj(1) << " " << recdev_adj(2, 5) << " breakpoints_for_bias_adjustment_ramp " << endl; + SS2out << "main_recdev:start_end: " << recdev_start << " " << recdev_end << endl + << "breakpoints_for_bias_adjustment_ramp: " < Date: Tue, 9 Jul 2024 15:13:53 -0700 Subject: [PATCH 12/22] fixes to ss_warn --- Compile/Make_SS_warn.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compile/Make_SS_warn.bat b/Compile/Make_SS_warn.bat index f53510ee..af9b1430 100644 --- a/Compile/Make_SS_warn.bat +++ b/Compile/Make_SS_warn.bat @@ -28,6 +28,6 @@ tpl2cpp ss3 g++ -c -std=c++17 -O2 -D_FILE_OFFSET_BITS=64 -DUSE_ADMB_CONTRIBS -D_USE_MATH_DEFINES -I. -I"C:\ADMB-13.2\include" -I"C:\ADMB-13.2\include\contrib" -Wall -Wextra -o ss3.obj ss3.cpp -g++ -static -o ss3.exe ss3.obj "C:\ADMB-13.2\lib\libadmb-contrib-mingw64-g++12.a" +g++ -static -o ss3.exe ss3.obj "C:\ADMB-13.2\lib\libadmb-contrib-mingw64-g++13.a" dir *.exe From f0342232a69d99e3081393dfee725e4979345b43 Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Tue, 13 Aug 2024 20:06:06 -0700 Subject: [PATCH 13/22] WIP-more work needed on benchmark calcs --- SS_benchfore.tpl | 30 ++++++++++++++++++++------ SS_param.tpl | 1 + SS_popdyn.tpl | 21 +++++++++--------- SS_recruit.tpl | 52 ++++++++++++++++++++++----------------------- SS_write_report.tpl | 6 +++--- 5 files changed, 63 insertions(+), 47 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 3801e082..9b7fcd2f 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -744,6 +744,18 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SR_parm_work(j) = temp / (Bmark_Yr(10) - Bmark_Yr(9) + 1.); } } + + if(SR_fxn == 10) // B-H with alpha, beta + { + alpha = mfexp(SR_parm_work(3)); + beta = mfexp(SR_parm_work(4)); + Fishon = 0; + Recr_unf = 1.0; + Do_Equil_Calc(Recr_unf); + SPR_virgin_adj = SSB_equil / 1.0; + SR_parm_work(2) = alpha * SPR_virgin_adj / (4. + alpha * SPR_virgin_adj); // steepness + SR_parm_work(1) = log(1. / beta * (alpha - (1. / SPR_virgin_adj))); // ln(R0) + } Fishon = 0; Recr_unf = mfexp(SR_parm_work(1)); Do_Equil_Calc(Recr_unf); @@ -751,13 +763,17 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SPR_unfished = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin if (show_MSY == 1) { - report5 << "SR_parm for benchmark: " << SR_parm_work << endl + report5 << "SR_parms for benchmark: " << SR_parm_work << endl << "mean from years: " << Bmark_Yr(9) << " " << Bmark_Yr(10) << endl; // SPR_virgin = SSB_virgin / Recr_virgin; // already defined - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Virgin SPR0, SSB, R: " << SPR_virgin << " " << Equ_SpawnRecr_Result << endl; + report5 << " Virgin SSB, R0: " << SSB_virgin << " " << Recr_virgin << " " << SPR_virgin_adj << endl; + report5 << " unfished SSB, R0: " << SSB_unf << " " << Recr_unf << " " << SPR_unfished << " with current biology " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_virgin_adj); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Virgin SPR0, result_SSB, R: " << SPR_virgin_adj << " " << Equ_SpawnRecr_Result << endl << endl; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_unfished); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SPR0, SSB, R: " << SPR_unfished << " " << Equ_SpawnRecr_Result << endl; + report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unfished << " " << Equ_SpawnRecr_Result << endl << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_unfished); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unfished << " " << Equ_SpawnRecr_Result << " with virgin spawn-recr " << endl; } SR_parm_work(N_SRparm2 + 1) = SSB_unf; Mgmt_quant(1) = SSB_unf; @@ -1930,7 +1946,7 @@ FUNCTION void Get_Forecast() dvariable OFL_catch; dvariable Fcast_Crash; dvariable totcatch; - dvariable R0_use; + dvariable R0_use; // annually updated variable if SR_update_SPR0 == 1 dvariable SSB_use; dvar_matrix catage_w(1, gmorph, 0, nages); dvar_vector tempcatch(1, Nfleet); @@ -2579,7 +2595,7 @@ FUNCTION void Get_Forecast() } // SPAWN-RECR: get recruitment in forecast; needs to be area-specific // SR_fxn - if (SR_parm_timevary(1) == 0) // R0 is not time-varying + if (SR_update_SPR0 == 0) // R0 is not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; @@ -3219,7 +3235,7 @@ FUNCTION void Get_Forecast() // SS_Label_Info_24.3.4.1 #Get recruitment from this spawning biomass // SPAWN-RECR: calc recruitment in time series; need to make this area-specific // SR_fxn - if (SR_parm_timevary(1) == 0) // R0 is not time-varying + if (SR_update_SPR0 == 0) // R0 is not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; diff --git a/SS_param.tpl b/SS_param.tpl index da7d0d5e..06c280ea 100644 --- a/SS_param.tpl +++ b/SS_param.tpl @@ -166,6 +166,7 @@ PARAMETER_SECTION number half_sigmaRsq; number sigmaR; number SPR_virgin; + number SPR_virgin_adj; number regime_change; number rho; number dirichlet_Parm; diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index 265e2c37..3aa6d549 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -344,7 +344,7 @@ FUNCTION void get_initial_conditions() equ_Recr = 1.0; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation. Returns SPR because R = 1.0 SPR_virgin = SSB_equil; // spawners per recruit. Needed for Sr_fxn = 10 - + SPR_virgin_adj = SSB_equil; if(SR_fxn == 10) // B-H with a,b { // WHAM based on R = A*S/(1+B*S) @@ -355,8 +355,8 @@ FUNCTION void get_initial_conditions() alpha = mfexp(SR_parm(3)); beta = mfexp(SR_parm(4)); - steepness = alpha * SPR_virgin / (4. + alpha * SPR_virgin); - Recr_virgin = 1. / beta * (alpha - (1. / SPR_virgin)); + steepness = alpha * SPR_virgin_adj / (4. + alpha * SPR_virgin_adj); + Recr_virgin = 1. / beta * (alpha - (1. / SPR_virgin_adj)); // warning << " before AB_calcs " << "parm " << SR_parm(1) << " calc " << log(Recr_virgin) << endl; SR_parm(1) = log(Recr_virgin); SR_parm(2) = steepness; @@ -380,7 +380,7 @@ FUNCTION void get_initial_conditions() exp_rec(eq_yr, 4) = Recr_virgin; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation SSB_virgin = SSB_equil; - SPR_virgin = SSB_equil / Recr_virgin; // spawners per recruit +// SPR_virgin = SSB_equil / Recr_virgin; // spawners per recruit already calculated if(Do_Benchmark==0) { Mgmt_quant(1)=SSB_virgin; @@ -696,7 +696,7 @@ FUNCTION void get_time_series() dvariable crashtemp1; dvariable interim_tot_catch; dvariable Z_adjuster; - dvariable R0_use; + dvariable R0_use; // annually updated variable if SR_update_SPR0 == 1; gets passed to Spawn_Recr() function dvariable SSB_use; if (Do_Morphcomp > 0) @@ -1024,10 +1024,10 @@ FUNCTION void get_time_series() } } - // SS_Label_Info_24.2.3 #Get the total recruitment produced by this spawning biomass + // SS_Label_Info_24.2.3 #Get the total recruitment produced by this spawning biomass at the beginning of the season // SPAWN-RECR: calc recruitment in time series; need to make this area-specific // SR_Fxn relevant keyword - if (SR_parm_timevary(1) == 0) // R0 is not time-varying + if (SR_update_SPR0 == 0) // SRparm are not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; @@ -1035,12 +1035,12 @@ FUNCTION void get_time_series() else { R0_use = mfexp(SR_parm_work(1)); - warning << y << " set R0use to SRparm_work " << R0_use << " vir: " << Recr_virgin << endl; equ_Recr = R0_use; Fishon = 0; eq_yr = y; bio_yr = y; Do_Equil_Calc(R0_use); // call function to do equilibrium calculation + SSB_use = SSB_equil; if (fishery_on_off == 1) { Fishon = 1; @@ -1049,7 +1049,6 @@ FUNCTION void get_time_series() { Fishon = 0; } - SSB_use = SSB_equil; } Recruits = Spawn_Recr(SSB_use, R0_use, SSB_current); // calls to function Spawn_Recr if (SR_fxn != 7) apply_recdev(Recruits, R0_use); // apply recruitment deviation @@ -1485,7 +1484,7 @@ FUNCTION void get_time_series() SSB_yr(y) = SSB_current; } } - // SS_Label_Info_24.3.4.1 #Get recruitment from this spawning biomass + // SS_Label_Info_24.3.4.1 #Get recruitment from this spawning biomass at some time during the season // SPAWN-RECR: calc recruitment in time series; need to make this area-specific // SR_fxn if (SR_update_SPR0 == 0) // SR parms are not time-varying @@ -1501,6 +1500,7 @@ FUNCTION void get_time_series() eq_yr = y; bio_yr = y; Do_Equil_Calc(R0_use); // call function to do equilibrium calculation + SSB_use = SSB_equil; if (fishery_on_off == 1) { Fishon = 1; @@ -1509,7 +1509,6 @@ FUNCTION void get_time_series() { Fishon = 0; } - SSB_use = SSB_equil; } Recruits = Spawn_Recr(SSB_use, R0_use, SSB_current); // calls to function Spawn_Recr diff --git a/SS_recruit.tpl b/SS_recruit.tpl index 2065b277..179ecd6e 100644 --- a/SS_recruit.tpl +++ b/SS_recruit.tpl @@ -268,7 +268,7 @@ FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_vir /* SS_Label_FUNCTION 44 Equil_Spawn_Recr_Fxn */ // SPAWN-RECR: function Equil_Spawn_Recr_Fxn FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, - const prevariable& SSB_virgin, const prevariable& Recr_virgin, const prevariable& SPR_temp) + const prevariable& SSB_temp, const prevariable& RECR_temp, const prevariable& SPR_temp) { RETURN_ARRAYS_INCREMENT(); dvar_vector Equil_Spawn_Recr_Calc(1, 2); // values to return 1 is B_equil, 2 is R_equil @@ -297,8 +297,8 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, // SS_Label_44.1.2 Ricker case 2: // Ricker { - B_equil = SSB_virgin * (1. + (log(Recr_virgin / SSB_virgin) + log(SPR_temp)) / steepness); - R_equil = Recr_virgin * B_equil / SSB_virgin * mfexp(steepness * (1. - B_equil / SSB_virgin)); + B_equil = SSB_temp * (1. + (log(RECR_temp / SSB_temp) + log(SPR_temp)) / steepness); + R_equil = RECR_temp * B_equil / SSB_temp * mfexp(steepness * (1. - B_equil / SSB_temp)); break; } @@ -316,14 +316,14 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, // SS3 previously used alternative formulation: R = A*S/(B+S) // converting SS3 to align with WHAM - // SPR_virgin = SSB_virgin / Recr_virgin; // this is already defined - alpha = 4.0 * steepness / (SPR_virgin * (1. - steepness)); + // SPR_virgin = SSB_temp / RECR_temp; // this is already defined + alpha = 4.0 * steepness / (SPR_virgin_adj * (1. - steepness)); beta = (5.0 * steepness - 1.0) / ((1 - steepness) * SSB_virgin); // " h " << steepness << " derive " << alpha * SPR_virgin / (4. + alpha * SPR_virgin) << " " << endl; - // " R0 " << Recr_virgin << " derive " << 1. / beta * (alpha - 1./SPR_virgin) << endl; -// report5 <<" SSB_unf "< Date: Thu, 15 Aug 2024 17:02:43 -0700 Subject: [PATCH 14/22] WIP2-need-to-fix-SPR-passing_to_benchmark --- SS_benchfore.tpl | 36 ++++++++++++++++++------------------ SS_popdyn.tpl | 17 ++++++++--------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 9b7fcd2f..37bc9758 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -536,7 +536,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) dvariable last_F1; dvariable Closer; dvariable Vbio1_unfished; - dvariable SPR_unfished; + dvariable SPR_unf; dvariable Vbio_MSY; dvariable Vbio1_MSY; dvariable junk; @@ -751,7 +751,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) beta = mfexp(SR_parm_work(4)); Fishon = 0; Recr_unf = 1.0; - Do_Equil_Calc(Recr_unf); + Do_Equil_Calc(Recr_unf); // SPR_virgin_adj = SSB_equil / 1.0; SR_parm_work(2) = alpha * SPR_virgin_adj / (4. + alpha * SPR_virgin_adj); // steepness SR_parm_work(1) = log(1. / beta * (alpha - (1. / SPR_virgin_adj))); // ln(R0) @@ -759,21 +759,21 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Fishon = 0; Recr_unf = mfexp(SR_parm_work(1)); Do_Equil_Calc(Recr_unf); - SSB_unf = SSB_equil; - SPR_unfished = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin + SSB_unf = SSB_equil; // equilibrium unfished SSB using the benchmark averaged Recr_unf and benchmark averaged biology + SPR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin if (show_MSY == 1) { report5 << "SR_parms for benchmark: " << SR_parm_work << endl << "mean from years: " << Bmark_Yr(9) << " " << Bmark_Yr(10) << endl; // SPR_virgin = SSB_virgin / Recr_virgin; // already defined report5 << " Virgin SSB, R0: " << SSB_virgin << " " << Recr_virgin << " " << SPR_virgin_adj << endl; - report5 << " unfished SSB, R0: " << SSB_unf << " " << Recr_unf << " " << SPR_unfished << " with current biology " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; + report5 << " unfished SSB, R0: " << SSB_unf << " " << Recr_unf << " " << SPR_unf << " with current biology " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_virgin_adj); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR report5 << " Virgin SPR0, result_SSB, R: " << SPR_virgin_adj << " " << Equ_SpawnRecr_Result << endl << endl; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_unfished); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unfished << " " << Equ_SpawnRecr_Result << endl << endl; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_unfished); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unfished << " " << Equ_SpawnRecr_Result << " with virgin spawn-recr " << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unf << " " << Equ_SpawnRecr_Result << endl << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unf << " " << Equ_SpawnRecr_Result << " with virgin spawn-recr " << endl; } SR_parm_work(N_SRparm2 + 1) = SSB_unf; Mgmt_quant(1) = SSB_unf; @@ -808,7 +808,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SPR_target100 = SPR_target * 100.; Do_Equil_Calc(equ_Recr); - SPR_unfished = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin + SPR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin Vbio1_unfished = smrybio; // gets value from equil_calc if (show_MSY == 1) { @@ -854,7 +854,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Fishon = 1; Do_Equil_Calc(equ_Recr); - yld1(ii) = 100. * SSB_equil / SPR_unfished; // spawning potential ratio + yld1(ii) = 100. * SSB_equil / SPR_unf; // spawning potential ratio } SPR_actual = yld1(1); // spawning potential ratio @@ -1008,7 +1008,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) last_F1 = F1(1); if (show_MSY == 1) { - report5 << j << " " << F1(1) << " " << equ_F_std << " " << SSB_equil / SPR_unfished << " " << YPR_opt << " " << F01_actual << " " << F01_second << " last F1 " << last_F1 << " Closer " << Closer << " delta " << (F01_origin * 0.1 - F01_actual) / (F01_second) << endl; + report5 << j << " " << F1(1) << " " << equ_F_std << " " << SSB_equil / SPR_unf << " " << YPR_opt << " " << F01_actual << " " << F01_second << " last F1 " << last_F1 << " Closer " << Closer << " delta " << (F01_origin * 0.1 - F01_actual) / (F01_second) << endl; } F1(1) += (F01_origin * 0.1 - F01_actual) / (F01_second); F1(1) = (1. - Closer) * F1(1) + Closer * last_F1; @@ -1051,7 +1051,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) YPR_Btgt_revenue = (PricePerF * YPR_val_vec) * Btgt_Rec; // vector*vector*scalar // YPR_Btgt_revenue = Price*YPR_ret*Btgt_Rec; YPR_Btgt_profit = YPR_Btgt_revenue - Cost; - SPR_Btgt = SSB_equil / SPR_unfished; + SPR_Btgt = SSB_equil / SPR_unf; Vbio_Btgt = totbio; Vbio1_Btgt = smrybio; Mgmt_quant(7) = equ_F_std; @@ -1131,7 +1131,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) // else Hrate for bycatch fleets already set } Do_Equil_Calc(equ_Recr); // where equ_Recr=1.0, so returned SSB_equil is a SSB/R, - SPR_Btgt = SSB_equil / SPR_unfished; + SPR_Btgt = SSB_equil / SPR_unf; // SPAWN-RECR: calc equil spawn-recr for Btarget calcs; need to make area-specific SPR_temp = SSB_equil; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR @@ -1353,7 +1353,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Do_Equil_Calc(equ_Recr); // SPAWN-RECR: calc spawn-recr for MSY calcs; need to make area-specific - MSY_SPR = SSB_equil / SPR_unfished; + MSY_SPR = SSB_equil / SPR_unf; SPR_temp = SSB_equil; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Bmsy = Equ_SpawnRecr_Result(1); // with MSY set to SPR, not directly estimated @@ -1446,7 +1446,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } Do_Equil_Calc(equ_Recr); // SPAWN-RECR: calc spawn-recr for MSY calcs; need to make area-specific - MSY_SPR = SSB_equil / SPR_unfished; + MSY_SPR = SSB_equil / SPR_unf; SPR_temp = SSB_equil; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Bmsy = Equ_SpawnRecr_Result(1); // MSY is directly estimated @@ -1739,7 +1739,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) // else Hrate for bycatch fleets already set } Do_Equil_Calc(equ_Recr); - SPR_Btgt2 = SSB_equil / SPR_unfished; + SPR_Btgt2 = SSB_equil / SPR_unf; // SPAWN-RECR: calc equil spawn-recr for Btarget calcs; need to make area-specific SPR_temp = SSB_equil; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR @@ -1947,7 +1947,7 @@ FUNCTION void Get_Forecast() dvariable Fcast_Crash; dvariable totcatch; dvariable R0_use; // annually updated variable if SR_update_SPR0 == 1 - dvariable SSB_use; + dvariable SSB_use; // selected version of SSB that gets passes to Spawn_Recr dvar_matrix catage_w(1, gmorph, 0, nages); dvar_vector tempcatch(1, Nfleet); imatrix Do_F_tune(t_base, TimeMax_Fcast_std, 1, Nfleet); // flag for doing F from catch diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index 3aa6d549..f4600932 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -344,7 +344,7 @@ FUNCTION void get_initial_conditions() equ_Recr = 1.0; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation. Returns SPR because R = 1.0 SPR_virgin = SSB_equil; // spawners per recruit. Needed for Sr_fxn = 10 - SPR_virgin_adj = SSB_equil; + SPR_virgin_adj = SSB_equil; // also needed for Sr_fxn 10. Will get revised in benchmark to use averaged biology if requested. if(SR_fxn == 10) // B-H with a,b { // WHAM based on R = A*S/(1+B*S) @@ -381,14 +381,14 @@ FUNCTION void get_initial_conditions() Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation SSB_virgin = SSB_equil; // SPR_virgin = SSB_equil / Recr_virgin; // spawners per recruit already calculated - if(Do_Benchmark==0) + if(Do_Benchmark==0) // assign values that would be created in benchmark section { - Mgmt_quant(1)=SSB_virgin; - SSB_unf=SSB_virgin; - Recr_unf=Recr_virgin; - Mgmt_quant(2)=totbio; // from equil calcs - Mgmt_quant(3)=smrybio; // from equil calcs - Mgmt_quant(4)=Recr_virgin; + Mgmt_quant(1) = SSB_virgin; + SSB_unf = SSB_virgin; + Recr_unf = Recr_virgin; + Mgmt_quant(2) = totbio; // from equil calcs + Mgmt_quant(3) = smrybio; // from equil calcs + Mgmt_quant(4) = Recr_virgin; } Smry_Table(styr - 2, 1) = totbio; // from equil calcs Smry_Table(styr - 2, 2) = smrybio; // from equil calcs @@ -1495,7 +1495,6 @@ FUNCTION void get_time_series() else // update SSB_use and R0_use where will update SPR0 inside the Spawn_recr fxn { R0_use = mfexp(SR_parm_work(1)); // check to be sure this works when R0 is derived from B-H with alpha, beta parameters - equ_Recr = R0_use; Fishon = 0; eq_yr = y; bio_yr = y; From b4ee3f638ed2ef5973e355b26a434bda6ce78794 Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Fri, 13 Sep 2024 16:27:52 -0700 Subject: [PATCH 15/22] WIP: add switch in benchmark to use correct SPR0 --- SS_benchfore.tpl | 42 +++++++-------- SS_popdyn.tpl | 5 +- SS_readcontrol_330.tpl | 2 +- SS_recruit.tpl | 116 ++++++++++++++++++++--------------------- 4 files changed, 80 insertions(+), 85 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 37bc9758..572c7d73 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -745,35 +745,30 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } } - if(SR_fxn == 10) // B-H with alpha, beta + if (SR_update_SPR0 == 0) // use virgin biology for the spawner-recruitment R0,h calculations { - alpha = mfexp(SR_parm_work(3)); - beta = mfexp(SR_parm_work(4)); - Fishon = 0; - Recr_unf = 1.0; - Do_Equil_Calc(Recr_unf); // - SPR_virgin_adj = SSB_equil / 1.0; - SR_parm_work(2) = alpha * SPR_virgin_adj / (4. + alpha * SPR_virgin_adj); // steepness - SR_parm_work(1) = log(1. / beta * (alpha - (1. / SPR_virgin_adj))); // ln(R0) + Recr_unf = Recr_virgin; + SSB_unf = SSB_virgin; + SPR_unf = SSB_unf / Recr_unf; + } + else // use benchmark biology in the spawner-recruitment R0,h calculations + { + Fishon = 0; + Recr_unf = mfexp(SR_parm_work(1)); + Do_Equil_Calc(Recr_unf); + SSB_unf = SSB_equil; // equilibrium unfished SSB using the benchmark averaged Recr_unf and benchmark averaged biology + SPR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin } - Fishon = 0; - Recr_unf = mfexp(SR_parm_work(1)); - Do_Equil_Calc(Recr_unf); - SSB_unf = SSB_equil; // equilibrium unfished SSB using the benchmark averaged Recr_unf and benchmark averaged biology - SPR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin if (show_MSY == 1) { report5 << "SR_parms for benchmark: " << SR_parm_work << endl - << "mean from years: " << Bmark_Yr(9) << " " << Bmark_Yr(10) << endl; - // SPR_virgin = SSB_virgin / Recr_virgin; // already defined - report5 << " Virgin SSB, R0: " << SSB_virgin << " " << Recr_virgin << " " << SPR_virgin_adj << endl; - report5 << " unfished SSB, R0: " << SSB_unf << " " << Recr_unf << " " << SPR_unf << " with current biology " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_virgin_adj); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Virgin SPR0, result_SSB, R: " << SPR_virgin_adj << " " << Equ_SpawnRecr_Result << endl << endl; + << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; + if ( SR_update_SPR0 == 1) report5 << "SPR0 for equilibrium spawner-recruit based on benchmark biology, not virgin biology" << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Virgin SSB, R0, SPR0: " << SSB_virgin << " " << Recr_virgin << " " << SPR_virgin << " equil: " << Equ_SpawnRecr_Result << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unf << " " << Equ_SpawnRecr_Result << endl << endl; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SPR0, result_SSB, R: " << SPR_unf << " " << Equ_SpawnRecr_Result << " with virgin spawn-recr " << endl; + report5 << " Benchmark SSB, R0, SPR0: " << SSB_unf << " " << Recr_unf << " " << SPR_unf << " equil: " << Equ_SpawnRecr_Result << endl; } SR_parm_work(N_SRparm2 + 1) = SSB_unf; Mgmt_quant(1) = SSB_unf; @@ -925,7 +920,6 @@ FUNCTION void Get_Benchmarks(const int show_MSY) // SPAWN-RECR: calc equil spawn-recr in YPR; need to make this area-specific SPR_temp = SSB_equil; // based on most recent call to Do_Equil_Calc Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5< SSB_virgin_adj) + if (SSB_curr_adj > SSB_virgin_use) { - SSB_BH1 = SSB_virgin_adj; + SSB_BH1 = SSB_virgin_use; } else { SSB_BH1 = SSB_curr_adj; } - NewRecruits = (4. * steepness * Recr_virgin_adj * SSB_BH1) / (SSB_virgin_adj * (1. - steepness) + (5. * steepness - 1.) * SSB_BH1); + NewRecruits = (4. * steepness * Recr_virgin_use * SSB_BH1) / (SSB_virgin_use * (1. - steepness) + (5. * steepness - 1.) * SSB_BH1); break; } // SS_Label_43.3.7 survival based case 7: // survival based, so constrained such that recruits cannot exceed fecundity { - // PPR_0=SSB_virgin_adj/Recr_virgin_adj; // pups per recruit at virgin + // PPR_0=SSB_virgin_use/Recr_virgin_use; // pups per recruit at virgin // Surv_0=1./PPR_0; // recruits per pup at virgin - // Pups_0=SSB_virgin_adj; // total population fecundity is the number of pups produced + // Pups_0=SSB_virgin_use; // total population fecundity is the number of pups produced // Sfrac=SR_parm(2); - SRZ_0 = log(1.0 / (SSB_virgin_adj / Recr_virgin_adj)); + SRZ_0 = log(1.0 / (SSB_virgin_use / Recr_virgin_use)); steepness = SR_parm_work(2); srz_min = SRZ_0 * (1.0 - steepness); - SRZ_surv = mfexp((1. - pow((SSB_curr_adj / SSB_virgin_adj), SR_parm_work(3))) * (srz_min - SRZ_0) + SRZ_0); // survival + SRZ_surv = mfexp((1. - pow((SSB_curr_adj / SSB_virgin_use), SR_parm_work(3))) * (srz_min - SRZ_0) + SRZ_0); // survival NewRecruits = SSB_curr_adj * SRZ_surv; exp_rec(y, 1) = NewRecruits; // expected arithmetic mean recruitment // SS_Label_43.3.7.1 Do variation in recruitment by adjusting survival @@ -145,8 +145,8 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab Shepherd_c2 = pow(0.2, SR_parm_work(3)); Hupper = 1.0 / (5.0 * Shepherd_c2); steepness = 0.2 + (SR_parm_work(2) - 0.2) / (0.8) * (Hupper - 0.2); - temp = (SSB_curr_adj) / (SSB_virgin_adj); - NewRecruits = (5. * steepness * Recr_virgin_adj * (1. - Shepherd_c2) * temp) / + temp = (SSB_curr_adj) / (SSB_virgin_use); + NewRecruits = (5. * steepness * Recr_virgin_use * (1. - Shepherd_c2) * temp) / (1.0 - 5.0 * steepness * Shepherd_c2 + (5. * steepness - 1.) * pow(temp, Shepherd_c)); break; } @@ -156,11 +156,11 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab { steepness = SR_parm_work(2); dvariable RkrPower = SR_parm_work(3); - temp = SSB_curr_adj / SSB_virgin_adj; + temp = SSB_curr_adj / SSB_virgin_use; temp2 = posfun(1.0 - temp, 0.0000001, temp3); temp = 1.0 - temp2; // Rick's new line to stabilize recruitment at R0 if B>B0 dvariable RkrTop = log(5.0 * steepness) * pow(temp2, RkrPower) / pow(0.8, RkrPower); - NewRecruits = Recr_virgin_adj * temp * mfexp(RkrTop); + NewRecruits = Recr_virgin_use * temp * mfexp(RkrTop); break; } @@ -169,7 +169,7 @@ FUNCTION dvariable Spawn_Recr(const prevariable& SSB_virgin_adj, const prevariab return NewRecruits; } // end spawner_recruitment -FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_virgin_adj) +FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_virgin_use) { RETURN_ARRAYS_INCREMENT(); // SS_Label_43.4 For non-survival based SRR, get recruitment deviations by adjusting recruitment itself @@ -196,7 +196,7 @@ FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_vir { if (do_recdev >= 3) { - NewRecruits = Recr_virgin_adj * mfexp(recdev(y)); // recruitment deviation + NewRecruits = Recr_virgin_use * mfexp(recdev(y)); // recruitment deviation } else if (SR_fxn != 7) { @@ -228,7 +228,7 @@ FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_vir } case 2: // use multiplier of R0 { - exp_rec(y, 2) = Recr_virgin_adj * Fcast_Loop_Control(4); // apply fcast multiplier to the virgin recruitment + exp_rec(y, 2) = Recr_virgin_use * Fcast_Loop_Control(4); // apply fcast multiplier to the virgin recruitment NewRecruits = exp_rec(y, 2); if (SR_fxn != 4) NewRecruits *= mfexp(-biasadj(y) * half_sigmaRsq); // bias adjustment @@ -268,7 +268,7 @@ FUNCTION void apply_recdev(prevariable& NewRecruits, const prevariable& Recr_vir /* SS_Label_FUNCTION 44 Equil_Spawn_Recr_Fxn */ // SPAWN-RECR: function Equil_Spawn_Recr_Fxn FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, - const prevariable& SSB_temp, const prevariable& RECR_temp, const prevariable& SPR_temp) + const prevariable& SSB_virgin_use, const prevariable& Recr_virgin_use, const prevariable& SPR_current) { RETURN_ARRAYS_INCREMENT(); dvar_vector Equil_Spawn_Recr_Calc(1, 2); // values to return 1 is B_equil, 2 is R_equil @@ -284,7 +284,7 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, dvariable SRZ_surv; steepness = SRparm(2); // common usage but some different - // SS_Label_44.1 calc equilibrium SpawnBio and Recruitment from input SPR_temp, which is spawning biomass per recruit at some given F level + // SS_Label_44.1 calc equilibrium SpawnBio and Recruitment from input SPR_current, which is spawning biomass per recruit at some given F level switch (SR_fxn) { case 1: // previous placement for B-H constrained @@ -297,8 +297,8 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, // SS_Label_44.1.2 Ricker case 2: // Ricker { - B_equil = SSB_temp * (1. + (log(RECR_temp / SSB_temp) + log(SPR_temp)) / steepness); - R_equil = RECR_temp * B_equil / SSB_temp * mfexp(steepness * (1. - B_equil / SSB_temp)); + B_equil = SSB_virgin_use * (1. + (log(Recr_virgin_use / SSB_virgin_use) + log(SPR_current)) / steepness); + R_equil = Recr_virgin_use * B_equil / SSB_virgin_use * mfexp(steepness * (1. - B_equil / SSB_virgin_use)); break; } @@ -316,19 +316,19 @@ FUNCTION dvar_vector Equil_Spawn_Recr_Fxn(const dvar_vector& SRparm, // SS3 previously used alternative formulation: R = A*S/(B+S) // converting SS3 to align with WHAM - // SPR_virgin = SSB_temp / RECR_temp; // this is already defined + // SPR_virgin = SSB_virgin_use / Recr_virgin_use; // this is already defined alpha = 4.0 * steepness / (SPR_virgin_adj * (1. - steepness)); beta = (5.0 * steepness - 1.0) / ((1 - steepness) * SSB_virgin); // " h " << steepness << " derive " << alpha * SPR_virgin / (4. + alpha * SPR_virgin) << " " << endl; - // " R0 " << RECR_temp << " derive " << 1. / beta * (alpha - 1./SPR_virgin) << endl; -// report5 <<" SSB_unf "< Date: Mon, 16 Sep 2024 18:22:06 -0700 Subject: [PATCH 16/22] refactor SPR to SSBpR; clean-up reference to timevary biology --- SS_benchfore.tpl | 73 ++++++++++++++++++++++++--------------------- SS_param.tpl | 6 ++-- SS_popdyn.tpl | 18 ++++++----- SS_recruit.tpl | 54 ++++++++++++++++----------------- SS_write_report.tpl | 14 ++++----- 5 files changed, 85 insertions(+), 80 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 572c7d73..39f9e044 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -536,7 +536,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) dvariable last_F1; dvariable Closer; dvariable Vbio1_unfished; - dvariable SPR_unf; + dvariable SSBpR_unf; dvariable Vbio_MSY; dvariable Vbio1_MSY; dvariable junk; @@ -749,7 +749,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) { Recr_unf = Recr_virgin; SSB_unf = SSB_virgin; - SPR_unf = SSB_unf / Recr_unf; + SSBpR_unf = SSB_unf / Recr_unf; } else // use benchmark biology in the spawner-recruitment R0,h calculations { @@ -757,18 +757,21 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Recr_unf = mfexp(SR_parm_work(1)); Do_Equil_Calc(Recr_unf); SSB_unf = SSB_equil; // equilibrium unfished SSB using the benchmark averaged Recr_unf and benchmark averaged biology - SPR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin + SSBpR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin + SSBpR_virgin_adj = SSB_unf / Recr_unf; // update } if (show_MSY == 1) { report5 << "SR_parms for benchmark: " << SR_parm_work << endl << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; if ( SR_update_SPR0 == 1) report5 << "SPR0 for equilibrium spawner-recruit based on benchmark biology, not virgin biology" << endl; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SPR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Virgin SSB, R0, SPR0: " << SSB_virgin << " " << Recr_virgin << " " << SPR_virgin << " equil: " << Equ_SpawnRecr_Result << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SSBpR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Virgin SSB, R0, SPR0: " << SSB_virgin << " " << Recr_virgin << " " << SSBpR_virgin << " equil: " << Equ_SpawnRecr_Result << endl; + + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Benchmark SSB, R0, SPR0: " << SSB_unf << " " << Recr_unf << " " << SSBpR_unf << " equil: " << Equ_SpawnRecr_Result << endl; + report5 << "Repro_output_by_age_for_morph_1: " << fec(1) << endl; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SSB, R0, SPR0: " << SSB_unf << " " << Recr_unf << " " << SPR_unf << " equil: " << Equ_SpawnRecr_Result << endl; } SR_parm_work(N_SRparm2 + 1) = SSB_unf; Mgmt_quant(1) = SSB_unf; @@ -803,7 +806,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SPR_target100 = SPR_target * 100.; Do_Equil_Calc(equ_Recr); - SPR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin + SSBpR_unf = SSB_unf / Recr_unf; // this corresponds to the biology for benchmark average years, not the virgin SSB_virgin Vbio1_unfished = smrybio; // gets value from equil_calc if (show_MSY == 1) { @@ -849,7 +852,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Fishon = 1; Do_Equil_Calc(equ_Recr); - yld1(ii) = 100. * SSB_equil / SPR_unf; // spawning potential ratio + yld1(ii) = 100. * SSB_equil / SSBpR_unf; // spawning potential ratio } SPR_actual = yld1(1); // spawning potential ratio @@ -918,8 +921,8 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } // SPAWN-RECR: calc equil spawn-recr in YPR; need to make this area-specific - SPR_temp = SSB_equil; // based on most recent call to Do_Equil_Calc - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + SSBpR_temp = SSB_equil; // based on most recent call to Do_Equil_Calc + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Bspr = Equ_SpawnRecr_Result(1); Bspr_rec = Equ_SpawnRecr_Result(2); @@ -1002,7 +1005,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) last_F1 = F1(1); if (show_MSY == 1) { - report5 << j << " " << F1(1) << " " << equ_F_std << " " << SSB_equil / SPR_unf << " " << YPR_opt << " " << F01_actual << " " << F01_second << " last F1 " << last_F1 << " Closer " << Closer << " delta " << (F01_origin * 0.1 - F01_actual) / (F01_second) << endl; + report5 << j << " " << F1(1) << " " << equ_F_std << " " << SSB_equil / SSBpR_unf << " " << YPR_opt << " " << F01_actual << " " << F01_second << " last F1 " << last_F1 << " Closer " << Closer << " delta " << (F01_origin * 0.1 - F01_actual) / (F01_second) << endl; } F1(1) += (F01_origin * 0.1 - F01_actual) / (F01_second); F1(1) = (1. - Closer) * F1(1) + Closer * last_F1; @@ -1033,8 +1036,8 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Btgt_Fmult = F1(1); if (rundetail > 0 && mceval_counter == 0 && show_MSY == 1) echoinput << "Calculated F0.1: " << Btgt_Fmult << endl; - SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + SSBpR_temp = SSB_equil; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Btgt = Equ_SpawnRecr_Result(1); Btgt_Rec = Equ_SpawnRecr_Result(2); YPR_Btgt_enc = YPR_enc; // total encountered yield per recruit @@ -1045,7 +1048,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) YPR_Btgt_revenue = (PricePerF * YPR_val_vec) * Btgt_Rec; // vector*vector*scalar // YPR_Btgt_revenue = Price*YPR_ret*Btgt_Rec; YPR_Btgt_profit = YPR_Btgt_revenue - Cost; - SPR_Btgt = SSB_equil / SPR_unf; + SPR_Btgt = SSB_equil / SSBpR_unf; Vbio_Btgt = totbio; Vbio1_Btgt = smrybio; Mgmt_quant(7) = equ_F_std; @@ -1060,9 +1063,12 @@ FUNCTION void Get_Benchmarks(const int show_MSY) // ****************************************************** if (show_MSY == 1) { - report5 << "#" << endl - << "Find_target_SSB/Bzero; where Bzero is for Bmark years, not Virgin" << endl - << "Iter Fmult ann_F SPR Catch SSB Recruits SSB/Bzero Tot_catch"; + report5 << "#" << endl; + if (SR_update_SPR0 == 0) // use virgin biology for the spawner-recruitment R0,h calculations + {report5 << "Find_target_SSB/Bzero; where Bzero is Virgin SSB:" << SSB_unf << " where SSBpR_unf = " << SSBpR_unf << endl;} + else + {report5 << "Find_target_SSB/Bzero; where Bzero is for Bmark biology and updated SPR0: " << SSB_unf << " where SSBpR_unf = " << SSBpR_unf << endl;} + report5 << "Iter Fmult ann_F SPR Catch SSB Recruits SSB/Bzero Tot_catch"; for (p = 1; p <= pop; p++) for (gp = 1; gp <= N_GP; gp++) { @@ -1088,8 +1094,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Nloops = 28; } - // Btgttgt=BTGT_target*SSB_virgin; // this is relative to virgin, not to the average biology from benchmark years - Btgttgt = BTGT_target * SSB_unf; // now relative to Bmark + Btgttgt = BTGT_target * SSB_unf; for (j = 0; j <= Nloops; j++) // loop find Btarget { @@ -1124,12 +1129,11 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } // else Hrate for bycatch fleets already set } - Do_Equil_Calc(equ_Recr); // where equ_Recr=1.0, so returned SSB_equil is a SSB/R, - SPR_Btgt = SSB_equil / SPR_unf; + Do_Equil_Calc(equ_Recr); // where equ_Recr=1.0, so returned SSB_equil is in units of SSB/R, + SSBpR_temp = SSB_equil; + SPR_Btgt = SSBpR_temp / SSBpR_unf; // where SSBpR_unf = SSB_unf / Recr_unf so units of SSB/R; so result is SPR_Btgt = (fished SSB/R) / (unfished SSB/R) // SPAWN-RECR: calc equil spawn-recr for Btarget calcs; need to make area-specific - SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5< Bmark_Yr(k)) {SS2out << "#_range_of_years_is_averaged,_so_reduces_standard_error_of_result;_do_this_only_when_timevarying_makes_necessary: " << k << " "<< k+1 << endl;} } - SS2out << "SPR_unfished_benchmark: " << Mgmt_quant(1) / Mgmt_quant(4) << " #_based_on_averaging_biology_over_benchmark_year_range " << endl; + SS2out << "SSBpR_unfished_benchmark: " << Mgmt_quant(1) / Mgmt_quant(4) << " #_based_on_averaging_biology_over_benchmark_year_range " << endl; SS2out << "Bmsy/Bzero: "<< Bmsy / SSB_virgin << " # using styr bio for Bzero" << endl; SS2out << "Bmsy/Bunf: "<< Bmsy / Mgmt_quant(1) << " # using MSY's averaged bio for Bunf" << endl; @@ -4912,8 +4912,8 @@ FUNCTION void SPR_profile() Do_Equil_Calc(equ_Recr); // SPAWN-RECR: calc equil spawn-recr in the SPR loop - SPR_temp = SSB_equil; - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SPR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + SSBpR_temp = SSB_equil; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_temp); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR Btgt_prof = Equ_SpawnRecr_Result(1); Btgt_prof_rec = Equ_SpawnRecr_Result(2); if (Btgt_prof < 0.001 || Btgt_prof_rec < 0.001) From f6744984d21e00ee244acc48082e455c2c258741 Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Fri, 20 Sep 2024 09:58:02 -0700 Subject: [PATCH 17/22] create new switch to control updating of SSBpR0 --- SS_benchfore.tpl | 12 +++++----- SS_popdyn.tpl | 8 +++---- SS_readcontrol_330.tpl | 53 +++++++++++++++++++++++++++++++++++++----- SS_write_ssnew.tpl | 6 ++++- 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 39f9e044..63d9475b 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -745,7 +745,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) } } - if (SR_update_SPR0 == 0) // use virgin biology for the spawner-recruitment R0,h calculations + if (SR_update_SSBpR0_bmark == 0) // use virgin biology for the spawner-recruitment R0,h calculations in bmark { Recr_unf = Recr_virgin; SSB_unf = SSB_virgin; @@ -764,7 +764,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) { report5 << "SR_parms for benchmark: " << SR_parm_work << endl << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; - if ( SR_update_SPR0 == 1) report5 << "SPR0 for equilibrium spawner-recruit based on benchmark biology, not virgin biology" << endl; + if ( SR_update_SSBpR0_bmark == 1) report5 << "SPR0 for equilibrium spawner-recruit based on benchmark biology, not virgin biology" << endl; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SSBpR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR report5 << " Virgin SSB, R0, SPR0: " << SSB_virgin << " " << Recr_virgin << " " << SSBpR_virgin << " equil: " << Equ_SpawnRecr_Result << endl; @@ -1064,7 +1064,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) if (show_MSY == 1) { report5 << "#" << endl; - if (SR_update_SPR0 == 0) // use virgin biology for the spawner-recruitment R0,h calculations + if (SR_update_SSBpR0_bmark == 0) // use virgin biology for the spawner-recruitment R0,h calculations {report5 << "Find_target_SSB/Bzero; where Bzero is Virgin SSB:" << SSB_unf << " where SSBpR_unf = " << SSBpR_unf << endl;} else {report5 << "Find_target_SSB/Bzero; where Bzero is for Bmark biology and updated SPR0: " << SSB_unf << " where SSBpR_unf = " << SSBpR_unf << endl;} @@ -1945,7 +1945,7 @@ FUNCTION void Get_Forecast() dvariable OFL_catch; dvariable Fcast_Crash; dvariable totcatch; - dvariable R0_use; // annually updated variable if SR_update_SPR0 == 1 + dvariable R0_use; // annually updated value if SR_update_SSBpR0_timeseries == 1 dvariable SSB_use; // selected version of SSB that gets passes to Spawn_Recr dvar_matrix catage_w(1, gmorph, 0, nages); dvar_vector tempcatch(1, Nfleet); @@ -2594,7 +2594,7 @@ FUNCTION void Get_Forecast() } // SPAWN-RECR: get recruitment in forecast; needs to be area-specific // SR_fxn - if (SR_update_SPR0 == 0) // R0 is not time-varying + if (SR_update_SSBpR0_timeseries == 0) // R0 is not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; @@ -3234,7 +3234,7 @@ FUNCTION void Get_Forecast() // SS_Label_Info_24.3.4.1 #Get recruitment from this spawning biomass // SPAWN-RECR: calc recruitment in time series; need to make this area-specific // SR_fxn - if (SR_update_SPR0 == 0) // R0 is not time-varying + if (SR_update_SSBpR0_timeseries == 0) // R0 is not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index c42f907e..79b1d59f 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -697,7 +697,7 @@ FUNCTION void get_time_series() dvariable crashtemp1; dvariable interim_tot_catch; dvariable Z_adjuster; - dvariable R0_use; // annually updated variable if SR_update_SPR0 == 1; gets passed to Spawn_Recr() function + dvariable R0_use; // annually updated variable if SR_update_SSBpR0_timeseries == 1; gets passed to Spawn_Recr() function dvariable SSB_use; if (Do_Morphcomp > 0) @@ -1028,7 +1028,7 @@ FUNCTION void get_time_series() // SS_Label_Info_24.2.3 #Get the total recruitment produced by this spawning biomass at the beginning of the season // SPAWN-RECR: calc recruitment in time series; need to make this area-specific // SR_Fxn relevant keyword - if (SR_update_SPR0 == 0) // SRparm are not time-varying + if (SR_update_SSBpR0_timeseries == 0) // SRparm are not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; @@ -1489,12 +1489,12 @@ FUNCTION void get_time_series() // SS_Label_Info_24.3.4.1 #Get recruitment from this spawning biomass at some time during the season // SPAWN-RECR: calc recruitment in time series; need to make this area-specific // SR_fxn - if (SR_update_SPR0 == 0) // SR parms are not time-varying + if (SR_update_SSBpR0_timeseries == 0) // SR parms are not time-varying { R0_use = Recr_virgin; SSB_use = SSB_virgin; } - else // update SSB_use and R0_use where will update SPR0 inside the Spawn_recr fxn + else // update SSB_use and R0_use where will update SSBpR0 inside the Spawn_recr fxn { R0_use = mfexp(SR_parm_work(1)); // check to be sure this works when R0 is derived from B-H with alpha, beta parameters Fishon = 0; diff --git a/SS_readcontrol_330.tpl b/SS_readcontrol_330.tpl index a6ed423a..2299f346 100644 --- a/SS_readcontrol_330.tpl +++ b/SS_readcontrol_330.tpl @@ -1943,8 +1943,21 @@ !!echoinput< 0 || SR_parm_timevary(4) > 0) ) {SR_update_SPR0 = 1;} // alpha or beta is time-varying - else if ((SR_parm_timevary(1) > 0 || SR_parm_timevary(2) > 0) ) {SR_update_SPR0 = 1;} // R0 or steepness is time-varying + if (SR_fxn == 10 && (SR_parm_timevary(3) > 0 || SR_parm_timevary(4) > 0) ) {SR_update_parm = 1;} // alpha or beta is time-varying + else if ((SR_parm_timevary(1) > 0 || SR_parm_timevary(2) > 0) ) {SR_update_parm = 1;} // R0 or steepness is time-varying } } N_SRparm3 = N_SRparm2; @@ -2142,6 +2155,34 @@ echoinput << " SR timevary_parm_cnt start and end " << timevary_parm_start_SR << " " << timevary_parm_cnt_SR << endl; echoinput << "link to timevary parms: " << SR_parm_timevary << endl; } + +// SR_update_SSBpR0_rd values +// 1 best: update SSBpR0 for benchmark and for time series only if SRparm R0 or h (not regime) is set to have time-varying property +// 2 incorrect, relic: always update SSBpR0 for benchmark's use of spawner-recruitment (old, incorrect SS3 approach), but only for the time series if there is a timevary SR parm +// 3 option: do not update SSBpR0 (do keep start year SPR0), even if R0 or h is set to have time-varying property + + switch (SR_update_SSBpR0_rd) + { + case 0: + if(timevary_MG_firstyr < YrMax) // timevary biology exists and SR_update not set + { + warnstream << "user must select 1, 2, or 3 for updating SPR0 flag (formerly labelled future feature in SR input) because there is time-varying biology"; + write_message (FATAL, 0); // EXIT! + } + break; + case 1: + SR_update_SSBpR0_bmark = 1 * SR_update_parm; // but conditional on SRparm_timevary, so update value there + SR_update_SSBpR0_timeseries = 1 * SR_update_parm; + break; + case 2: + SR_update_SSBpR0_bmark = 1; + SR_update_SSBpR0_timeseries = 0; + break; + case 3: + SR_update_SSBpR0_bmark = 0; + SR_update_SSBpR0_timeseries = 0; + break; + } echoinput << "SR_Npar and N_SRparm2 and N_SRparm3: " << N_SRparm(SR_fxn) << " " << N_SRparm2 << " " << N_SRparm3 << endl; // clang-format off END_CALCS diff --git a/SS_write_ssnew.tpl b/SS_write_ssnew.tpl index 38a9a5ec..fdd984be 100644 --- a/SS_write_ssnew.tpl +++ b/SS_write_ssnew.tpl @@ -2136,7 +2136,11 @@ FUNCTION void write_nucontrol() report4 << "#" << endl; report4 << SR_fxn << " #_Spawner-Recruitment; Options: 1=NA; 2=Ricker; 3=std_B-H; 4=SCAA; 5=Hockey; 6=B-H_flattop; 7=survival_3Parm; 8=Shepherd_3Parm; 9=RickerPower_3parm" << endl; report4 << init_equ_steepness << " # 0/1 to use steepness in initial equ recruitment calculation" << endl; - report4 << sigmaR_dendep << " # future feature: 0/1 to make realized sigmaR a function of SR curvature" << endl; + report4 << SR_update_SSBpR0_rd << "# SR_update_SSBpR0" << endl << + "# 0 - OK, but only if no timevary biology or SR parm" << endl << + "# 1 - best: update SSBpR0 for benchmark and for time series only if SRparm R0 or h (not regime) is set to have time-varying property" << endl << + "# 2 - incorrect (old, incorrect SS3 approach): always update SSBpR0 for benchmark's use of spawner-recruitment, but only for the time series if there is a timevary SR parm" << endl << + "# 3 - option: do not update SSBpR0 (do keep start year SSBpR0), even if R0 or h is set to have time-varying property" << endl << "#" << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE env-var use_dev dev_mnyr dev_mxyr dev_PH Block Blk_Fxn # parm_name" << endl; report4.unsetf(std::ios_base::fixed); report4.unsetf(std::ios_base::floatfield); From e9b838d4472651266c61e4f1e7f415ffd2af5b26 Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Fri, 4 Oct 2024 14:58:13 -0700 Subject: [PATCH 18/22] too many changes --- SS_benchfore.tpl | 82 +-- SS_global.tpl | 4 +- SS_param.tpl | 250 ++++---- SS_popdyn.tpl | 1229 +++++++++++++++----------------------- SS_proced.tpl | 6 +- SS_readcontrol_330.tpl | 21 +- SS_readdata_330.tpl | 4 +- SS_write.tpl | 2 +- SS_write_report.tpl | 44 +- SS_write_ssnew.tpl | 1267 +++++++++++++++------------------------- 10 files changed, 1154 insertions(+), 1755 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 63d9475b..9bcb1edb 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -4,6 +4,15 @@ // SS_Label_file # * get_forecast() // calculates forecast quantities, includes all popdy characteristics of the time series, writes forecast-report.sso // SS_Label_file # +// Terminology +// SSB refers to spawning stock biomass, calculated from reproductive output at age (fec()) and numbers-at-age at spawn_month in spawn_seas +// SSBpR refers to SSB per recruit calculated with equilibrium age composition in equil_calc +// SPR refers to spawner potential ratio which is the ratio of SSBpR at some level of F to SSBpR with F = 0 + +// SSBpR_virgin calculated and reported, but never used +// SSBpR_virgin_adj used only in the alpha-beta spawner-recruitment. _adj means could be updated if SR_update_SSBpR0_timeseries == 1. Also used to get alpha in equil_spawn_recr B-H +// but note that also uses SSB_virgin_use. So need to align _use with _adj + FUNCTION void setup_Benchmark() // and forecast { // SS_Label_Info_7.5 #Get averages from selected years to use in forecasts @@ -113,12 +122,7 @@ FUNCTION void setup_Benchmark() // and forecast } } t = styr + (endyr + 1 - styr) * nseas + spawn_seas - 1; - fec = Wt_Age_t(t, -2); - // for (g=1;g<=gmorph;g++) - // if(use_morph(g)>0 && sx(g)==1) - // { - // fec(g)=save_sel_num(t,0,g); - // } +// fec = Wt_Age_t(t, -2); this will always be overwritten, so deleting if (Fcast_Loop_Control(3) == 3) // using mean recr_dist from range of years { @@ -569,7 +573,6 @@ FUNCTION void Get_Benchmarks(const int show_MSY) eq_yr = y; t_base = y + (y - styr) * nseas - 1; bio_t_base = styr + (bio_yr - styr) * nseas - 1; - // set the Hrate for bycatch fleets so not scaled with other fleets // bycatch_F(f,s) is created here for use in forecast for (f = 1; f <= Nfleet; f++) @@ -643,6 +646,8 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Make_AgeLength_Key(s, subseas); // SPAWN-RECR: call make_fecundity for benchmarks + // this means that any calculation of SSB in benchmark will use the updated fec + // but SSBpR0 will only use that updated fec if SR_update_SSBpR0_bmark == 1 if (s == spawn_seas) { { @@ -744,7 +749,6 @@ FUNCTION void Get_Benchmarks(const int show_MSY) SR_parm_work(j) = temp / (Bmark_Yr(10) - Bmark_Yr(9) + 1.); } } - if (SR_update_SSBpR0_bmark == 0) // use virgin biology for the spawner-recruitment R0,h calculations in bmark { Recr_unf = Recr_virgin; @@ -763,14 +767,17 @@ FUNCTION void Get_Benchmarks(const int show_MSY) if (show_MSY == 1) { report5 << "SR_parms for benchmark: " << SR_parm_work << endl - << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl; - if ( SR_update_SSBpR0_bmark == 1) report5 << "SPR0 for equilibrium spawner-recruit based on benchmark biology, not virgin biology" << endl; + << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << " flag for updating SSBpR0 = " << SR_update_SSBpR0_bmark << endl; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SSBpR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR report5 << " Virgin SSB, R0, SPR0: " << SSB_virgin << " " << Recr_virgin << " " << SSBpR_virgin << " equil: " << Equ_SpawnRecr_Result << endl; - - Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR - report5 << " Benchmark SSB, R0, SPR0: " << SSB_unf << " " << Recr_unf << " " << SSBpR_unf << " equil: " << Equ_SpawnRecr_Result << endl; - report5 << "Repro_output_by_age_for_morph_1: " << fec(1) << endl; + if ( SR_update_SSBpR0_bmark == 1) + { + report5 << "SPR0 for equilibrium spawner-recruit based on benchmark biology, not virgin biology" << endl; + Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR + report5 << " Benchmark SSB, R0, SPR0: " << SSB_unf << " " << Recr_unf << " " << SSBpR_unf << " equil: " << Equ_SpawnRecr_Result << endl; + } + report5 << 0 << " y: " << y << " Repro_output_by_age_for_morph_1 bench " << fec(1) << endl; +// report5 << "Repro_output_by_age_for_morph_1: " << fec(1) << endl; } SR_parm_work(N_SRparm2 + 1) = SSB_unf; @@ -1849,7 +1856,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) report5 << "ann_F " << Mgmt_quant(10) << endl; report5 << "Exploit(Catch_dead/B_smry) " << YPR_spr_dead / Vbio1_spr << endl; report5 << "Recruits " << Bspr_rec << endl; - report5 << "SPBio " << Bspr << " " << Bspr / Bspr_rec << endl; + report5 << "SSBio " << Bspr << " " << Bspr / Bspr_rec << endl; report5 << "Catch_encountered " << YPR_spr_enc * Bspr_rec << " " << YPR_spr_enc << endl; report5 << "Catch_dead " << YPR_spr_dead * Bspr_rec << " " << YPR_spr_dead << endl; report5 << "Catch_retain " << YPR_spr_ret * Bspr_rec << " " << YPR_spr_ret << endl; @@ -1869,7 +1876,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) report5 << "ann_F " << Mgmt_quant(7) << endl; report5 << "Exploit(Catch_dead/B_smry) " << YPR_Btgt_dead / Vbio1_Btgt << endl; report5 << "Recruits@F0.1 " << Btgt_Rec << endl; - report5 << "SPBio " << Btgt << " " << Btgt / Btgt_Rec << endl; + report5 << "SSBio " << Btgt << " " << Btgt / Btgt_Rec << endl; report5 << "Catch_encountered " << YPR_Btgt_enc * Btgt_Rec << " " << YPR_Btgt_enc << endl; report5 << "Catch_dead " << YPR_Btgt_dead * Btgt_Rec << " " << YPR_Btgt_dead << endl; report5 << "Catch_retain " << YPR_Btgt_ret * Btgt_Rec << " " << YPR_Btgt_ret << endl; @@ -1889,7 +1896,7 @@ FUNCTION void Get_Benchmarks(const int show_MSY) report5 << "ann_F " << Mgmt_quant(7) << endl; report5 << "Exploit(Catch_dead/B_smry) " << YPR_Btgt_dead / Vbio1_Btgt << endl; report5 << "Recruits " << Btgt_Rec << endl; - report5 << "SPBio " << Btgt << " " << Btgt / Btgt_Rec << endl; + report5 << "SSBio " << Btgt << " " << Btgt / Btgt_Rec << endl; report5 << "Catch_encountered " << YPR_Btgt_enc * Btgt_Rec << " " << YPR_Btgt_enc << endl; report5 << "Catch_dead " << YPR_Btgt_dead * Btgt_Rec << " " << YPR_Btgt_dead << endl; report5 << "Catch_retain " << YPR_Btgt_ret * Btgt_Rec << " " << YPR_Btgt_ret << endl; @@ -1906,9 +1913,9 @@ FUNCTION void Get_Benchmarks(const int show_MSY) report5 << "ann_F " << Mgmt_quant(14) << endl; report5 << "Exploit(Catch/Bsmry) " << MSY / (Vbio1_MSY * Recr_msy) << endl; report5 << "Recruits@MSY " << Recr_msy << endl; - report5 << "SPBmsy " << Bmsy << " " << Bmsy / Recr_msy << endl; - report5 << "SPBmsy/SPB_virgin " << Bmsy / SSB_virgin << endl; - report5 << "SPBmsy/SPB_unfished " << Bmsy / SSB_unf << endl; + report5 << "SSBmsy " << Bmsy << " " << Bmsy / Recr_msy << endl; + report5 << "SSBmsy/SSB_virgin " << Bmsy / SSB_virgin << endl; + report5 << "SSBmsy/SSB_unfished " << Bmsy / SSB_unf << endl; report5 << "MSY_for_optimize " << MSY << " " << MSY / Recr_msy << endl; report5 << "MSY_encountered " << YPR_msy_enc * Recr_msy << " " << YPR_msy_enc << endl; report5 << "MSY_dead " << YPR_msy_dead * Recr_msy << " " << YPR_msy_dead << endl; @@ -1934,6 +1941,8 @@ FUNCTION void Get_Benchmarks(const int show_MSY) << " " << Vbio1_MSY * Recr_msy << " # " << endl; } write_bodywt = write_bodywt_save; + report5 << 0 << " y: " << y << " Repro_output_by_age_for_morph_1 end_bench: " << fec(1) << endl; +// report5 << "Repro_output_by_age_for_morph_1_after_benchmark: " << fec(1) << endl; } // end benchmarks FUNCTION void Get_Forecast() @@ -1945,8 +1954,6 @@ FUNCTION void Get_Forecast() dvariable OFL_catch; dvariable Fcast_Crash; dvariable totcatch; - dvariable R0_use; // annually updated value if SR_update_SSBpR0_timeseries == 1 - dvariable SSB_use; // selected version of SSB that gets passes to Spawn_Recr dvar_matrix catage_w(1, gmorph, 0, nages); dvar_vector tempcatch(1, Nfleet); imatrix Do_F_tune(t_base, TimeMax_Fcast_std, 1, Nfleet); // flag for doing F from catch @@ -2220,6 +2227,8 @@ FUNCTION void Get_Forecast() for (int Fcast_Loop1 = 1; Fcast_Loop1 <= jloop; Fcast_Loop1++) // for different forecast conditions { + report5 << Fcast_Loop1 << " y: " << 0 << " Repro_output_by_age_for_morph_1 top_forecast: " << fec(1) << endl; + switch (Fcast_Loop1) // select which ABC_loops to use { case 1: // do OFL only @@ -2290,7 +2299,7 @@ FUNCTION void Get_Forecast() get_growth3(y, t, s, subseas); // in case needed for Lorenzen M Make_AgeLength_Key(s, subseas); // which also updates Wt_Age_beg, etc. } - if (s == spawn_seas) +// if (s == spawn_seas) // { if (WTage_rd == 1) { @@ -2301,12 +2310,12 @@ FUNCTION void Get_Forecast() } else { - get_mat_fec(); + get_mat_fec(); // does spawnseas and stores in wt_Age_t(t, -2) } } } } - + report5 << Fcast_Loop1 << " y: " << y << " updated_Repro_output_by_age_for_morph_1 endyr: " << fec(1) << endl; for (y = endyr + 1; y <= YrMax; y++) { t_base = styr + (y - styr) * nseas - 1; @@ -2496,6 +2505,7 @@ FUNCTION void Get_Forecast() Wt_Age_mid(s, g) = ALK(ALK_idx, g) * wt_len(s, GP(g)); // use for fisheries with no size selectivity } } + report5 << Fcast_Loop1 << " y: " << y << " updated_Repro_output_by_age_for_morph_1 annual: " << fec(1) << endl; Wt_Age_t(t, 0) = Wt_Age_beg(s); for (g = 1; g <= gmorph; g++) if (use_morph(g) > 0) @@ -2577,18 +2587,18 @@ FUNCTION void Get_Forecast() if (Hermaphro_Option != 0) // get male biomass { - MaleSPB(y).initialize(); + MaleSSB(y).initialize(); for (p = 1; p <= pop; p++) { for (g = 1; g <= gmorph; g++) if (sx(g) == 2 && use_morph(g) > 0) // male; all assumed to be mature { - MaleSPB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * natage(t, p, g); // accumulates SSB by area and by growthpattern + MaleSSB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * natage(t, p, g); // accumulates SSB by area and by growthpattern } } - if (Hermaphro_maleSPB > 0.0) // add MaleSPB to female SSB + if (Hermaphro_maleSSB > 0.0) // add MaleSSB to female SSB { - SSB_current += Hermaphro_maleSPB * sum(MaleSPB(y)); + SSB_current += Hermaphro_maleSSB * sum(MaleSSB(y)); SSB_yr(y) = SSB_current; } } @@ -2617,7 +2627,6 @@ FUNCTION void Get_Forecast() } SSB_use = SSB_equil; } - Recruits = Spawn_Recr(SSB_use, R0_use, SSB_current); // calls to function Spawn_Recr if (SR_fxn != 7) apply_recdev(Recruits, R0_use); // apply recruitment deviation if (Fcast_Loop1 < Fcast_Loop_Control(2)) // use expected recruitment this should include environ effect - CHECK THIS @@ -3216,18 +3225,18 @@ FUNCTION void Get_Forecast() if (Hermaphro_Option != 0) // get male biomass { - MaleSPB(y).initialize(); + MaleSSB(y).initialize(); for (p = 1; p <= pop; p++) { for (g = 1; g <= gmorph; g++) if (sx(g) == 2 && use_morph(g) > 0) // male; all assumed to be mature { - MaleSPB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); // accumulates SSB by area and by growthpattern + MaleSSB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); // accumulates SSB by area and by growthpattern } } - if (Hermaphro_maleSPB > 0.0) // add MaleSPB to female SSB + if (Hermaphro_maleSSB > 0.0) // add MaleSSB to female SSB { - SSB_current += Hermaphro_maleSPB * sum(MaleSPB(y)); + SSB_current += Hermaphro_maleSSB * sum(MaleSSB(y)); SSB_yr(y) = SSB_current; } } @@ -3666,7 +3675,7 @@ FUNCTION void Get_Forecast() Smry_Table(y, 4) = Mgmt_quant(Fcast_catch_start + y - endyr); eq_yr = y; equ_Recr = Recr_unf; - bio_yr = endyr; + bio_yr = y; Fishon = 0; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation @@ -3674,7 +3683,7 @@ FUNCTION void Get_Forecast() Smry_Table(y, 13) = GenTime; if( SR_fxn == 10 ) { - temp = SSB_equil / equ_Recr; // current year's SPB/R with current biology at age + temp = SSB_equil / equ_Recr; // current year's SSB/R with current biology at age alpha = mfexp(SR_parm_work(3)); beta = mfexp(SR_parm_work(4)); SR_parm_byyr(y, 2) = alpha * temp / (4. + alpha * temp); // implied steepness @@ -3682,6 +3691,7 @@ FUNCTION void Get_Forecast() } Fishon = 1; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation +// warning < 0) SPR_std(STD_Yr_Reverse_Ofish(y)) = SSB_equil / Smry_Table(y, 11); Smry_Table(y, 9) = totbio; diff --git a/SS_global.tpl b/SS_global.tpl index 4fa5dcfb..c18dc5af 100644 --- a/SS_global.tpl +++ b/SS_global.tpl @@ -1270,10 +1270,10 @@ REPORT_SECTION if (Do_TG > 0) report << " TG-fleetcomp " << TG_like1 << endl << " TG-negbin " << TG_like2 << endl; - report << " -log(L): " << obj_fun << " Spbio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)) << endl; + report << " -log(L): " << obj_fun << " SSBio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)) << endl; report << endl - << "Year Spbio Recruitment" << endl; + << "Year SSBio Recruitment" << endl; report << "Virg " << SSB_yr(styr - 2) << " " << exp_rec(styr - 2, 4) << endl; report << "Init " << SSB_yr(styr - 1) << " " << exp_rec(styr - 1, 4) << endl; for (y = styr; y <= endyr; y++) diff --git a/SS_param.tpl b/SS_param.tpl index 43a4206c..ed5e5a29 100644 --- a/SS_param.tpl +++ b/SS_param.tpl @@ -13,53 +13,52 @@ INITIALIZATION_SECTION PARAMETER_SECTION // { // SS_Label_Info_5.0.1 #Setup convergence critera and max func evaluations - LOCAL_CALCS - // clang-format on - // set the filename to all ADMB output files to "base_modelname.[ext]" - // where base_modelname can be read from command line with command modelname followed by text - // e.g. ss3_win.exe -nohess -stopph 3 modelname ss4you - // if requested modelname.par is not found, then will attempt to read from ss3.par then ss.par - // whatever name is read, the write will be to modelname.par. Which has default of ss3.par - ad_comm::adprogram_name = base_modelname; - echoinput << "Begin setting up parameters" << endl; - cout << "Begin setting up parameters ... "; - if (readparfile >= 1) - { - anystring = base_modelname + ".par"; - cout << " read parm file: " << anystring << endl; - +LOCAL_CALCS +// clang-format on +// set the filename to all ADMB output files to "base_modelname.[ext]" +// where base_modelname can be read from command line with command modelname followed by text +// e.g. ss3_win.exe -nohess -stopph 3 modelname ss4you +// if requested modelname.par is not found, then will attempt to read from ss3.par then ss.par +// whatever name is read, the write will be to modelname.par. Which has default of ss3.par +ad_comm::adprogram_name = base_modelname; +echoinput << "Begin setting up parameters" << endl; +cout << "Begin setting up parameters ... "; +if (readparfile >= 1) { + anystring = base_modelname + ".par"; + cout << " read parm file: " << anystring << endl; + + ifstream fin(anystring); + if (fin.fail()) { + cout << " no find, try ss3.par" << endl; + anystring = "ss3.par"; ifstream fin(anystring); - if(fin.fail() ) { - cout << " no find, try ss3.par" << endl; - anystring = "ss3.par"; - ifstream fin(anystring); - if(fin.fail() ) { + if (fin.fail()) { cout << " no find, try ss.par" << endl; anystring = "ss.par"; ifstream fin(anystring); - if(fin.fail() ) { - warnstream << "could not find ss3.par, ss.par, or requested parfile " << base_modelname << ".par"; - write_message(FATAL, 0); + if (fin.fail()) { + warnstream << "could not find ss3.par, ss.par, or requested parfile " << base_modelname << ".par"; + write_message(FATAL, 0); } - }} - cout << " found "<0) {SR_autocorr=1;} else {SR_autocorr=0;} // flag for recruitment autocorrelation - if (do_recdev == 1) - { - k = recdev_start; - j = recdev_end; - s = 1; - p = -1; - } - else if (do_recdev >= 2) - { - s = recdev_start; - p = recdev_end; - k = 1; - j = -1; - } - else - { - s = 1; - p = -1; - k = 1; - j = -1; - } - // clang-format off +// clang-format on +Ave_Size.initialize(); +// if(SR_parm(N_SRparm2)!=0.0 || SR_parm_PH(N_SRparm2)>0) {SR_autocorr=1;} else {SR_autocorr=0;} // flag for recruitment autocorrelation +if (do_recdev == 1) { + k = recdev_start; + j = recdev_end; + s = 1; + p = -1; +} +else if (do_recdev >= 2) { + s = recdev_start; + p = recdev_end; + k = 1; + j = -1; +} +else { + s = 1; + p = -1; + k = 1; + j = -1; +} +// clang-format off END_CALCS // vector biasadj(styr-nages,YrMax) // biasadj as used; depends on whether a recdev is estimated or not @@ -211,26 +209,22 @@ PARAMETER_SECTION vector recdev(recdev_first,YrMax); LOCAL_CALCS - // clang-format on - if (do_recdev == 0) - { - s = -1; - } - else - { - s = YrMax; - } - if (Do_Impl_Error > 0) - { - k = Fcast_recr_PH2; - j = YrMax; - } - else - { - k = -1; - j = -1; - } - // clang-format off +// clang-format on +if (do_recdev == 0) { + s = -1; +} +else { + s = YrMax; +} +if (Do_Impl_Error > 0) { + k = Fcast_recr_PH2; + j = YrMax; +} +else { + k = -1; + j = -1; +} +// clang-format off END_CALCS init_bounded_vector Fcast_recruitments(recdev_end+1,s,recdev_LO,recdev_HI,Fcast_recr_PH2) init_bounded_vector Fcast_impl_error(endyr+1,j,-1,1,k) @@ -241,9 +235,12 @@ PARAMETER_SECTION number Recr_virgin number SSB_vir_LH - number SSB_unf + number SSB_unf // SSB unfished, based on benchmark biology number Recr_unf + number SSB_use + number R0_use; // annually updated value if SR_update_SSBpR0_timeseries == 1 + number SSB_deplete // SSB that will be used as denominator for depletion calculations and as basis for control rule inflection number SSB_current; // Spawning biomass number SSB_equil; @@ -322,7 +319,7 @@ PARAMETER_SECTION !!k=0; !!if(Hermaphro_Option!=0) k=1; - 3darray MaleSPB(styr-3,YrMax*k,1,pop,1,N_GP) //Male Spawning biomass + 3darray MaleSSB(styr-3,YrMax*k,1,pop,1,N_GP) //Male Spawning biomass matrix SSB_equil_pop_gp(1,pop,1,N_GP); matrix MaleSSB_equil_pop_gp(1,pop,1,N_GP); @@ -388,16 +385,15 @@ PARAMETER_SECTION LOCAL_CALCS - // clang-format on - if (N_Fparm > 0) // continuous F - { - k = N_Fparm; - } - else - { - k = -1; - } - // clang-format off +// clang-format on +if (N_Fparm > 0) // continuous F +{ + k = N_Fparm; +} +else { + k = -1; +} +// clang-format off END_CALCS // defining F_rate as number_vector allows for Fparm_PH to be element specific init_bounded_number_vector F_rate(1,k,0.,max_harvest_rate,Fparm_PH_dim) @@ -493,9 +489,9 @@ PARAMETER_SECTION number overdisp // overdispersion LOCAL_CALCS - // clang-format on - k = Do_TG * (3 * N_TG + 2 * Nfleet1); - // clang-format off + // clang-format on + k = Do_TG * (3 * N_TG + 2 * Nfleet1); +// clang-format off END_CALCS init_bounded_number_vector TG_parm(1,k,TG_parm_LO,TG_parm_HI,TG_parm_PH); @@ -508,12 +504,12 @@ PARAMETER_SECTION matrix parm_timevary(1,timevary_cnt,styr-1,YrMax); // time series of adjusted parm values for block and trend LOCAL_CALCS - // clang-format on - if (Do_Forecast > 0) - k = TimeMax_Fcast_std + nseas; - else - k = TimeMax + nseas; - // clang-format off +// clang-format on +if (Do_Forecast > 0) + k = TimeMax_Fcast_std + nseas; +else + k = TimeMax + nseas; +// clang-format off END_CALCS !!// SS_Label_Info_5.1.7 #Create arrays for storing derived selectivity quantities for use in mortality calculations @@ -599,8 +595,8 @@ PARAMETER_SECTION number equ_M_std !!// SS_Label_Info_5.1.8 #Create matrix called smry to store derived quantities of interest - matrix Smry_Table(styr-3,YrMax,1,17); - // 1=totbio, 2=smrybio, 3=smrynum, 4=enc_catch, 5=dead_catch, 6=ret_catch, 7=spbio, 8=recruit, + matrix Smry_Table(styr-3,YrMax,1,20+2*gmorph); + // 1=totbio, 2=smrybio, 3=smrynum, 4=enc_catch, 5=dead_catch, 6=ret_catch, 7=SSBio, 8=recruit, // 9=equ_totbio, 10=equ_smrybio, 11=equ_SSB_virgin, 12=equ_S1, 13=Gentime, 14=YPR, 15=meanage_spawners, 16=meanage_smrynums, 17=meanage_catch diff --git a/SS_popdyn.tpl b/SS_popdyn.tpl index 79b1d59f..1004e9ab 100644 --- a/SS_popdyn.tpl +++ b/SS_popdyn.tpl @@ -6,7 +6,7 @@ // SS_Label_file # FUNCTION void setup_recdevs() - { +{ // SS_Label_Info_7.1 #Set up recruitment bias_adjustment vector sigmaR = SR_parm(N_SRparm(SR_fxn) + 1); two_sigmaRsq = 2.0 * sigmaR * sigmaR; @@ -14,45 +14,35 @@ FUNCTION void setup_recdevs() biasadj.initialize(); - if (SR_fxn == 4 || do_recdev == 0) - { + if (SR_fxn == 4 || do_recdev == 0) { // keep all at 0.0 if not using SR fxn } // else if (mceval_phase() || initial_params::mc_phase==1 || recdev_adj(5)<0.0) - else if (mceval_phase() || initial_params::mc_phase == 1) - { + else if (mceval_phase() || initial_params::mc_phase == 1) { // biasadj=1.0; biasadj = recdev_doit; // sets to 1.0 for the years or initial ages with estimated recruitments } - else - { + else { if (recdev_do_early > 0 && recdev_options(2) >= 0) // do logic on basis of recdev_options(2), which is read, not recdev_PH which can be reset to a neg. value { - for (i = recdev_early_start; i <= recdev_early_end; i++) - { + for (i = recdev_early_start; i <= recdev_early_end; i++) { if (i >= styr - nages) biasadj(i) = biasadj_full(i); } } - if (do_recdev > 0 && recdev_PH_rd >= 0) - { - for (i = recdev_start; i <= recdev_end; i++) - { + if (do_recdev > 0 && recdev_PH_rd >= 0) { + for (i = recdev_start; i <= recdev_end; i++) { if (i >= styr - nages) biasadj(i) = biasadj_full(i); } } - if (Do_Forecast > 0 && recdev_options(3) >= 0) - { - for (i = recdev_end + 1; i <= YrMax; i++) - { + if (Do_Forecast > 0 && recdev_options(3) >= 0) { + for (i = recdev_end + 1; i <= YrMax; i++) { biasadj(i) = biasadj_full(i); } } - if (recdev_read > 0) - { - for (j = 1; j <= recdev_read; j++) - { + if (recdev_read > 0) { + for (j = 1; j <= recdev_read; j++) { y = recdev_input(j, 1); if (y >= recdev_first && y <= YrMax) biasadj(y) = biasadj_full(y); @@ -61,24 +51,21 @@ FUNCTION void setup_recdevs() } sd_offset_rec = sum(biasadj) * sd_offset; // SS_Label_Info_7.2 #Copy recdev parm vectors into full time series vector - if (recdev_do_early > 0) - { + if (recdev_do_early > 0) { recdev(recdev_early_start, recdev_early_end) = recdev_early(recdev_early_start, recdev_early_end); } - if (do_recdev == 1) - { + if (do_recdev == 1) { recdev(recdev_start, recdev_end) = recdev1(recdev_start, recdev_end); } - else if (do_recdev >= 2) - { + else if (do_recdev >= 2) { recdev(recdev_start, recdev_end) = recdev2(recdev_start, recdev_end); } if (Do_Forecast > 0 && do_recdev > 0) recdev(recdev_end + 1, YrMax) = Fcast_recruitments(recdev_end + 1, YrMax); // only needed here for reporting - } // end setup for recdevs +} // end setup for recdevs FUNCTION void get_initial_conditions() - { +{ //********************************************************************* /* SS_Label_Function_23 #get_initial_conditions */ natage.initialize(); @@ -86,7 +73,7 @@ FUNCTION void get_initial_conditions() annual_catch.initialize(); annual_F.initialize(); Recr.initialize(); - save_gparm = 0; // index for saving time-varying changes to biology quantities + save_gparm = 0; // index for saving time-varying changes to biology quantities if (SzFreq_Nmeth > 0) SzFreq_exp.initialize(); @@ -102,27 +89,24 @@ FUNCTION void get_initial_conditions() // following call is to routine that does this for all timevary parameters // that are then copied over to replace the base parameter for MG, SRR, Q, Selex, or Tag as needed make_timevaryparm(); // this fills array parm_timevary for all years; densitydependence must be done year-by-year later - if (MG_active(0) > 0 || save_for_report > 0) - { + if (MG_active(0) > 0 || save_for_report > 0) { get_MGsetup(y); } - #ifdef DO_ONCE +#ifdef DO_ONCE if (do_once == 1) echoinput << " MGsetup OK " << endl; - #endif +#endif if (MG_active(2) > 0) get_growth1(); // seasonal effects and CV - #ifdef DO_ONCE +#ifdef DO_ONCE if (do_once == 1) echoinput << " growth1 OK" << endl; - #endif - if (MG_active(2) > 0 || do_once == 1) - { +#endif + if (MG_active(2) > 0 || do_once == 1) { ALK_subseas_update = 1; // to indicate that all ALKs need calculation get_growth2(y); t = styr - 1; - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { t++; for (subseas = 1; subseas <= N_subseas; subseas++) // do all subseasons in first year { @@ -133,17 +117,14 @@ FUNCTION void get_initial_conditions() // SS_Label_Info_16.2.4.3 #propagate Ave_Size from early years forward until first year that has time-vary growth k = styr + 1; - do - { - for (s = 1; s <= nseas; s++) - { + do { + for (s = 1; s <= nseas; s++) { t = styr + (k - styr) * nseas + s - 1; Ave_Size(t, 1) = Ave_Size(t - nseas, 1); } // end season loop k++; } while (timevary_MG(k, 2) == 0 && k <= YrMax); - if (k <= YrMax) - { + if (k <= YrMax) { t = styr + (k - styr) * nseas; Ave_Size(t, 1) = Ave_Size(t - nseas, 1); // prep for time-vary next yr } @@ -154,30 +135,26 @@ FUNCTION void get_initial_conditions() if (Hermaphro_Option != 0) get_Hermaphro(); - if (do_once>0 || MG_active(1) > 0) - { - get_natmort(); // gets base M (e.g. M1) by season and stores it in natM(t,0). Later, pred_M2 is added by area - for (s = 1; s <= nseas; s++) - { - natM(t_base - 2 * nseas + s) = natM(t_base + s); // copy to virgin - natM(t_base - nseas + s) = natM(t_base + s); // then to init_conditions year + if (do_once > 0 || MG_active(1) > 0) { + get_natmort(); // gets base M (e.g. M1) by season and stores it in natM(t,0). Later, pred_M2 is added by area + for (s = 1; s <= nseas; s++) { + natM(t_base - 2 * nseas + s) = natM(t_base + s); // copy to virgin + natM(t_base - nseas + s) = natM(t_base + s); // then to init_conditions year } } - #ifdef DO_ONCE +#ifdef DO_ONCE if (do_once == 1) echoinput << "natmort OK" << endl; - #endif +#endif if (MG_active(4) > 0) get_recr_distribution(); - if (y >= Bmark_Yr(7) && y <= Bmark_Yr(8)) - { + if (y >= Bmark_Yr(7) && y <= Bmark_Yr(8)) { for (gp = 1; gp <= N_GP; gp++) for (p = 1; p <= pop; p++) for (settle = 1; settle <= N_settle_timings; settle++) - if (recr_dist_pattern(gp, settle, p) > 0) - { + if (recr_dist_pattern(gp, settle, p) > 0) { recr_dist_unf(gp, settle, p) += recr_dist(y, gp, settle, p); if (gender == 2) recr_dist_unf(gp + N_GP, settle, p) += recr_dist(y, gp + N_GP, settle, p); @@ -186,79 +163,66 @@ FUNCTION void get_initial_conditions() if (MG_active(5) > 0) get_migration(); - #ifdef DO_ONCE - if (do_once == 1) - { +#ifdef DO_ONCE + if (do_once == 1) { echoinput << "migr OK" << endl; } - #endif - if (MG_active(7) > 0) - { +#endif + if (MG_active(7) > 0) { get_catch_mult(y, catch_mult_pointer); - for (j = styr + 1; j <= YrMax; j++) - { + for (j = styr + 1; j <= YrMax; j++) { catch_mult(j) = catch_mult(y); } } - if (Use_AgeKeyZero > 0) - { + if (Use_AgeKeyZero > 0) { if (MG_active(6) > 0) get_age_age(Use_AgeKeyZero, AgeKey_StartAge, AgeKey_Linear1, AgeKey_Linear2); // call function to get the age_age key - if (save_for_report == 1 && store_agekey_add > 0) - { + if (save_for_report == 1 && store_agekey_add > 0) { save_agekey_count = N_ageerr + 1; // first blank key after the used keys age_age(save_agekey_count) = age_age(Use_AgeKeyZero); age_err(save_agekey_count) = age_err(Use_AgeKeyZero); } - #ifdef DO_ONCE - if (do_once == 1) - { +#ifdef DO_ONCE + if (do_once == 1) { echoinput << "age_err key recalc in " << y << endl; } - #endif +#endif } - if (save_for_report > 0) - { + if (save_for_report > 0) { get_saveGparm(); } // SS_Label_Info_23.2 #Calculate selectivity in the initial year get_selectivity(); - #ifdef DO_ONCE - if (do_once == 1) - { +#ifdef DO_ONCE + if (do_once == 1) { echoinput << "selectivity OK" << endl; echoinput << "Calculate ALK" << endl; } - #endif +#endif // SS_Label_Info_23.3 #Loop seasons and subseasons t = styr - 1; - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { t++; - if (WTage_rd > 0) - { + if (WTage_rd > 0) { for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { Wt_Age_beg(s, g) = Wt_Age_t(t, 0, g); Wt_Age_mid(s, g) = Wt_Age_t(t, -1, g); if (s == spawn_seas) fec(g) = Wt_Age_t(t, -2, g); } } - else if (MG_active(2) > 0 || MG_active(3) > 0 || save_for_report > 0 || do_once == 1) - { + else if (MG_active(2) > 0 || MG_active(3) > 0 || save_for_report > 0 || do_once == 1) { // Make_Fecundity(); if (s == spawn_seas && spawn_seas == 1) get_mat_fec(); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { subseas = 1; ALK_idx = (s - 1) * N_subseas + subseas; Wt_Age_beg(s, g) = (ALK(ALK_idx, g) * wt_len(s, GP(g))); // wt-at-age at beginning of period @@ -271,66 +235,59 @@ FUNCTION void get_initial_conditions() Wt_Age_t(t, 0) = Wt_Age_beg(s); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { // SS_Label_Info_23.3.3 #for each platoon, combine size_at_age distribution with length selectivity and weight-at-length to get combined selectivity vectors Make_FishSelex(); } // SS_Label_Info_23.3.4 #add predator M2 to M1 to update seasonal, areal natM in styr and calc surv for use in Pope's - if(N_pred>0) - { -// rebase natM to M1, which is stored in the p=0 section of array - for(p = 1; p <= pop; p++) - { - natM(t, p) = natM(t,0); - } -// calc M2 - for (f1 = 1; f1 <= N_pred; f1++) - { - f = predator(f1); - pred_M2(f1, t) = mgp_adj(predparm_pointer(f1)); // base with no seasonal effect - if (nseas > 1) - pred_M2(f1, t) *= mgp_adj(predparm_pointer(f1) + s); - pred_M2(f1, t-nseas) = pred_M2(f1, t); - pred_M2(f1, t-nseas-nseas) = pred_M2(f1, t); - p = fleet_area(f); // area this predator occurs in - - // a new array for indexing g and gpi could simplify below - // for (gp = 1; gp <= N_GP * gender * N_settle_timings; gp++) - // add each M2 to get total M - for (gp = 1; gp <= N_GP * gender; gp++) - { - g = g_Start(gp); // base platoon - for (settle = 1; settle <= N_settle_timings; settle++) - { - g += N_platoon; - int gpi = GP3(g); // GP*gender*settlement - natM(t, p,gpi) += pred_M2(f1, t) * sel_num(s, f, g); - if (do_once == 1 && p == 1) - echoinput << "init " << y << " s " << s << " t " << t << " area " << 0 << " gp " << gpi << " M1: " << natM(t,0, gpi) << endl; - if (do_once == 1) - echoinput << "init " << y << " s " << s << " t " << t << " area " << p << " gp " << gpi << " M1+M2: " << natM(t, p, gpi) << endl; - } + if (N_pred > 0) { + // rebase natM to M1, which is stored in the p=0 section of array + for (p = 1; p <= pop; p++) { + natM(t, p) = natM(t, 0); + } + // calc M2 + for (f1 = 1; f1 <= N_pred; f1++) { + f = predator(f1); + pred_M2(f1, t) = mgp_adj(predparm_pointer(f1)); // base with no seasonal effect + if (nseas > 1) + pred_M2(f1, t) *= mgp_adj(predparm_pointer(f1) + s); + pred_M2(f1, t - nseas) = pred_M2(f1, t); + pred_M2(f1, t - nseas - nseas) = pred_M2(f1, t); + p = fleet_area(f); // area this predator occurs in + + // a new array for indexing g and gpi could simplify below + // for (gp = 1; gp <= N_GP * gender * N_settle_timings; gp++) + // add each M2 to get total M + for (gp = 1; gp <= N_GP * gender; gp++) { + g = g_Start(gp); // base platoon + for (settle = 1; settle <= N_settle_timings; settle++) { + g += N_platoon; + int gpi = GP3(g); // GP*gender*settlement + natM(t, p, gpi) += pred_M2(f1, t) * sel_num(s, f, g); + if (do_once == 1 && p == 1) + echoinput << "init " << y << " s " << s << " t " << t << " area " << 0 << " gp " << gpi << " M1: " << natM(t, 0, gpi) << endl; + if (do_once == 1) + echoinput << "init " << y << " s " << s << " t " << t << " area " << p << " gp " << gpi << " M1+M2: " << natM(t, p, gpi) << endl; } } - natM(t-nseas) = natM(t); //for initial equilibrium - natM(t-nseas-nseas) = natM(t); // for virgin } + natM(t - nseas) = natM(t); // for initial equilibrium + natM(t - nseas - nseas) = natM(t); // for virgin + } - for(p = 1; p <= pop; p++) - { - int s1 = (p - 1) * nseas + s; - surv1(s1) = mfexp( - natM(t,p) * seasdur_half(s)); - surv2(s1) = square(surv1(s1)); - } + for (p = 1; p <= pop; p++) { + int s1 = (p - 1) * nseas + s; + surv1(s1) = mfexp(-natM(t, p) * seasdur_half(s)); + surv2(s1) = square(surv1(s1)); + } } // end season (s) loop in biology, mortality and selectivity calcs in initial year - #ifdef DO_ONCE +#ifdef DO_ONCE if (do_once == 1) echoinput << "Begin calculating virgin age struc " << endl; - #endif +#endif // SS_Label_Info_23.4 #calculate unfished (virgin) numbers-at-age eq_yr = styr - 2; bio_yr = styr; @@ -344,35 +301,34 @@ FUNCTION void get_initial_conditions() equ_Recr = 1.0; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation. Returns SPR because R = 1.0 SSBpR_virgin = SSB_equil; // spawners per recruit. Needed for Sr_fxn = 10 - SSBpR_virgin_adj = SSB_equil; // also needed for Sr_fxn 10. Will get revised in benchmark to use averaged biology if requested. - if(SR_fxn == 10) // B-H with a,b + SSBpR_virgin_adj = SSB_equil; // also needed for Sr_fxn 10. Will get revised in benchmark to use averaged biology if requested. + if (SR_fxn == 10) // B-H with a,b { - // WHAM based on R = A*S/(1+B*S) - // log_SR_a = log(4 * SR_h/(exp(log_SPR0)*(1 - SR_h))); - // log_SR_b = log((5*SR_h - 1)/((1-SR_h)*SR_R0*exp(log_SPR0))); - // h = a * SPR0 / (4. + a * SPR0) - // R0 = 1/b * (a-1/SPR0) + // WHAM based on R = A*S/(1+B*S) + // log_SR_a = log(4 * SR_h/(exp(log_SPR0)*(1 - SR_h))); + // log_SR_b = log((5*SR_h - 1)/((1-SR_h)*SR_R0*exp(log_SPR0))); + // h = a * SPR0 / (4. + a * SPR0) + // R0 = 1/b * (a-1/SPR0) alpha = mfexp(SR_parm(3)); beta = mfexp(SR_parm(4)); steepness = alpha * SSBpR_virgin_adj / (4. + alpha * SSBpR_virgin_adj); Recr_virgin = 1. / beta * (alpha - (1. / SSBpR_virgin_adj)); -// warning << " before AB_calcs " << "parm " << SR_parm(1) << " calc " << log(Recr_virgin) << endl; + // warning << " before AB_calcs " << "parm " << SR_parm(1) << " calc " << log(Recr_virgin) << endl; SR_parm(1) = log(Recr_virgin); SR_parm(2) = steepness; } else { Recr_virgin = mfexp(SR_parm(1)); } - - for (int i = 1; i <= N_SRparm2; i++) - { - SR_parm_byyr(eq_yr, i) = SR_parm(i); - SR_parm_virg(i) = SR_parm(i); - SR_parm_work(i) = SR_parm(i); - } -// if (SR_fxn == 3) warning << "tester_A: " << SR_parm_work(1) << " base: " << SR_parm(1) << endl; -// if (SR_fxn == 10) warning << "tester_A: " << SR_parm_work(4) << " base: " << SR_parm(4) << endl; + + for (int i = 1; i <= N_SRparm2; i++) { + SR_parm_byyr(eq_yr, i) = SR_parm(i); + SR_parm_virg(i) = SR_parm(i); + SR_parm_work(i) = SR_parm(i); + } + // if (SR_fxn == 3) warning << "tester_A: " << SR_parm_work(1) << " base: " << SR_parm(1) << endl; + // if (SR_fxn == 10) warning << "tester_A: " << SR_parm_work(4) << " base: " << SR_parm(4) << endl; equ_Recr = Recr_virgin; exp_rec(eq_yr, 1) = Recr_virgin; // expected Recr from s-r parms exp_rec(eq_yr, 2) = Recr_virgin; @@ -380,14 +336,14 @@ FUNCTION void get_initial_conditions() exp_rec(eq_yr, 4) = Recr_virgin; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation SSB_virgin = SSB_equil; -// SSBpR_virgin = SSB_equil / Recr_virgin; // spawners per recruit already calculated - if(Do_Benchmark==0) // assign values that would be created in benchmark section + // SSBpR_virgin = SSB_equil / Recr_virgin; // spawners per recruit already calculated + if (Do_Benchmark == 0) // assign values that would be created in benchmark section { - Mgmt_quant(1) = SSB_virgin; + Mgmt_quant(1) = SSB_virgin; // can be overwritten in benchmark by updated SSB_unf SSB_unf = SSB_virgin; Recr_unf = Recr_virgin; - Mgmt_quant(2) = totbio; // from equil calcs - Mgmt_quant(3) = smrybio; // from equil calcs + Mgmt_quant(2) = totbio; // from equil calcs + Mgmt_quant(3) = smrybio; // from equil calcs Mgmt_quant(4) = Recr_virgin; } Smry_Table(styr - 2, 1) = totbio; // from equil calcs @@ -395,55 +351,45 @@ FUNCTION void get_initial_conditions() Smry_Table(styr - 2, 3) = smrynum; // from equil calcs SSB_pop_gp(eq_yr) = SSB_equil_pop_gp; // dimensions of pop x N_GP if (Hermaphro_Option != 0) - MaleSPB(eq_yr) = MaleSSB_equil_pop_gp; + MaleSSB(eq_yr) = MaleSSB_equil_pop_gp; SSB_yr(eq_yr) = SSB_equil; SR_parm_byyr(eq_yr, N_SRparm2 + 1) = SSB_equil; SR_parm_virg(N_SRparm2 + 1) = SSB_equil; SR_parm_work(N_SRparm2 + 1) = SSB_equil; t = styr - 2 * nseas - 1; for (s = 1; s <= nseas; s++) - for (p = 1; p <= pop; p++) - { - for (g = 1; g <= gmorph; g++) - { - if (use_morph(g) > 0) - { + for (p = 1; p <= pop; p++) { + for (g = 1; g <= gmorph; g++) { + if (use_morph(g) > 0) { natage(t + s, p, g)(0, nages) = equ_numbers(s, p, g)(0, nages); Z_rate(t + s, p, g)(0, nages) = equ_Z(s, p, g)(0, nages); } } } - if (save_for_report > 0) - { + if (save_for_report > 0) { SSB_B_yr(eq_yr).initialize(); SSB_N_yr(eq_yr).initialize(); - for (s = 1; s <= nseas; s++) - { - for (p = 1; p <= pop; p++) - for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - if (s == spawn_seas && sx(g) == 1) - { - SSB_B_yr(eq_yr) += make_mature_bio(GP4(g)) * natage(t + s, p, g); - SSB_N_yr(eq_yr) += make_mature_numbers(GP4(g)) * natage(t + s, p, g); - } - Save_PopAge(t + s, p, g) = natage(t + s, p, g); - Save_PopAge(t + s, p + pop, g) = elem_prod(natage(t + s, p, g), mfexp(-Z_rate(t + s, p, g) * 0.5 * seasdur(s))); - if (Settle_seas(settle_g(g)) == s) - Recr(p, t + 1 + Settle_seas_offset(settle_g(g))) += equ_Recr * recr_dist(y, GP(g), settle_g(g), p) * platoon_distr(GP2(g)); - Save_PopBio(t + s, p, g) = elem_prod(natage(t + s, p, g), Wt_Age_beg(s, g)); - Save_PopBio(t + s, p + pop, g) = elem_prod(Save_PopAge(t + s, p + pop, g), Wt_Age_mid(s, g)); + for (s = 1; s <= nseas; s++) { + for (p = 1; p <= pop; p++) + for (g = 1; g <= gmorph; g++) + if (use_morph(g) > 0) { + if (s == spawn_seas && sx(g) == 1) { + SSB_B_yr(eq_yr) += make_mature_bio(GP4(g)) * natage(t + s, p, g); + SSB_N_yr(eq_yr) += make_mature_numbers(GP4(g)) * natage(t + s, p, g); } - for (int ff = 1; ff <= N_pred; ff++) - { + Save_PopAge(t + s, p, g) = natage(t + s, p, g); + Save_PopAge(t + s, p + pop, g) = elem_prod(natage(t + s, p, g), mfexp(-Z_rate(t + s, p, g) * 0.5 * seasdur(s))); + if (Settle_seas(settle_g(g)) == s) + Recr(p, t + 1 + Settle_seas_offset(settle_g(g))) += equ_Recr * recr_dist(y, GP(g), settle_g(g), p) * platoon_distr(GP2(g)); + Save_PopBio(t + s, p, g) = elem_prod(natage(t + s, p, g), Wt_Age_beg(s, g)); + Save_PopBio(t + s, p + pop, g) = elem_prod(Save_PopAge(t + s, p + pop, g), Wt_Age_mid(s, g)); + } + for (int ff = 1; ff <= N_pred; ff++) { f = predator(ff); - for (g = 1; g <= 6; g++) - { + for (g = 1; g <= 6; g++) { catch_fleet(t + s, f, g) = equ_catch_fleet(g, s, f); } - for (g = 1; g <= gmorph; g++) - { + for (g = 1; g <= gmorph; g++) { catage(t + s, f, g) = equ_catage(s, f, g); } } @@ -454,45 +400,36 @@ FUNCTION void get_initial_conditions() { } -// SS_Label_Info_23.5 #Calculate equilibrium using initial F - #ifdef DO_ONCE + // SS_Label_Info_23.5 #Calculate equilibrium using initial F +#ifdef DO_ONCE if (do_once == 1) echoinput << "Begin calculating initial age structure" << endl; - #endif +#endif eq_yr = styr - 1; bio_yr = styr; - if (fishery_on_off == 1) - { + if (fishery_on_off == 1) { Fishon = 1; } - else - { + else { Fishon = 0; } - for (f = 1; f <= N_SRparm2; f++) - { - if (SR_parm_timevary(f) == 0) - { + for (f = 1; f <= N_SRparm2; f++) { + if (SR_parm_timevary(f) == 0) { // no change to SR_parm_work } - else - { + else { SR_parm_work(f) = parm_timevary(SR_parm_timevary(f), eq_yr); -// warning << "tester_B: " << SR_parm_work(f) << " timevary " << " base " << SR_parm(f) < 0) - { + if (init_F_loc(s, f) > 0) { Hrate(f, t) = init_F(init_F_loc(s, f)); } } @@ -522,12 +459,11 @@ FUNCTION void get_initial_conditions() Do_Equil_Calc(equ_Recr); CrashPen += Equ_penalty; } - else - { + else { // SS_Label_Info_23.5.1.2 #Adjustments include spawner-recruitment function // do initial equilibrium with R1 based on offset from spawner-recruitment curve, using same approach as the benchmark calculations // first get SPR for this init_F - // SPAWN-RECR: calc initial equilibrium pop, SPB, Recruitment + // SPAWN-RECR: calc initial equilibrium pop, SSB, Recruitment // equ_Recr=Recr_virgin; equ_Recr = R1_exp * regime_change; @@ -554,7 +490,7 @@ FUNCTION void get_initial_conditions() SSB_pop_gp(eq_yr) = SSB_equil_pop_gp; // dimensions of pop x N_GP if (Hermaphro_Option != 0) - MaleSPB(eq_yr) = MaleSSB_equil_pop_gp; + MaleSSB(eq_yr) = MaleSSB_equil_pop_gp; SSB_yr(eq_yr) = SSB_equil; SR_parm_byyr(eq_yr, N_SRparm2 + 1) = SSB_equil; SR_parm_work(N_SRparm2 + 1) = SSB_equil; @@ -580,68 +516,55 @@ FUNCTION void get_initial_conditions() } } */ -// if (save_for_report > 0) + // if (save_for_report > 0) { - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { t = styr - nseas - 1 + s; - for (int ff = 1; ff <= N_catchfleets(0); ff++) - { + for (int ff = 1; ff <= N_catchfleets(0); ff++) { f = fish_fleet_area(0, ff); - for (g = 1; g <= 6; g++) - { + for (g = 1; g <= 6; g++) { catch_fleet(t, f, g) = equ_catch_fleet(g, s, f); annual_catch(styr - 1, g) += equ_catch_fleet(g, s, f); } - for (g = 1; g <= gmorph; g++) - { + for (g = 1; g <= gmorph; g++) { catage(t, f, g) = equ_catage(s, f, g); } } - for (int ff = 1; ff <= N_pred; ff++) - { + for (int ff = 1; ff <= N_pred; ff++) { f = predator(ff); - for (g = 1; g <= 6; g++) - { + for (g = 1; g <= 6; g++) { catch_fleet(t, f, g) = equ_catch_fleet(g, s, f); } - for (g = 1; g <= gmorph; g++) - { + for (g = 1; g <= gmorph; g++) { catage(t, f, g) = equ_catage(s, f, g); } } } - for (k = 1; k <= 3; k++) - { + for (k = 1; k <= 3; k++) { Smry_Table(styr - 1, k + 3) = annual_catch(styr - 1, k); } } - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { t = styr - nseas - 1 + s; a = styr - 1 + s; for (p = 1; p <= pop; p++) - for (g = 1; g <= gmorph; g++) - { + for (g = 1; g <= gmorph; g++) { natage(t, p, g)(0, nages) = equ_numbers(s, p, g)(0, nages); natage(a, p, g)(0, nages) = equ_numbers(s, p, g)(0, nages); Z_rate(t, p, g) = equ_Z(s, p, g); } } - if (save_for_report > 0) - { + if (save_for_report > 0) { t = styr - nseas - 1; SSB_B_yr(eq_yr).initialize(); SSB_N_yr(eq_yr).initialize(); for (s = 1; s <= nseas; s++) for (p = 1; p <= pop; p++) for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - if (s == spawn_seas && sx(g) == 1) - { + if (use_morph(g) > 0) { + if (s == spawn_seas && sx(g) == 1) { SSB_B_yr(eq_yr) += make_mature_bio(GP4(g)) * natage(t + s, p, g); SSB_N_yr(eq_yr) += make_mature_numbers(GP4(g)) * natage(t + s, p, g); } @@ -661,24 +584,19 @@ FUNCTION void get_initial_conditions() // if recrdevs start before styr, then use them to adjust the initial agecomp // apply a fraction of the bias adjustment, so bias adjustment gets less linearly as proceed back in time - if (recdev_first < styr) - { - if (do_recdev <= 2 && SR_fxn != 4) - { + if (recdev_first < styr) { + if (do_recdev <= 2 && SR_fxn != 4) { for (p = 1; p <= pop; p++) for (g = 1; g <= gmorph; g++) - for (a = styr - recdev_first; a >= 1; a--) - { + for (a = styr - recdev_first; a >= 1; a--) { j = styr - a; natage(styr, p, g, a) *= mfexp(recdev(j) - biasadj(j) * half_sigmaRsq); } } - else - { + else { for (p = 1; p <= pop; p++) for (g = 1; g <= gmorph; g++) - for (a = styr - recdev_first; a >= 1; a--) - { + for (a = styr - recdev_first; a >= 1; a--) { j = styr - a; natage(styr, p, g, a) *= mfexp(recdev(j)); } @@ -687,82 +605,69 @@ FUNCTION void get_initial_conditions() SSB_pop_gp(styr) = SSB_pop_gp(styr - 1); // placeholder in case not calculated early in styr // note: the above keeps SSB_pop_gp(styr) = SSB_equil. It does not adjust for initial agecomp, but probably should - } // end initial_conditions +} // end initial_conditions //********************************************************************* FUNCTION void get_time_series() - { +{ /* SS_Label_Function_24 get_time_series */ dvariable crashtemp; dvariable crashtemp1; dvariable interim_tot_catch; dvariable Z_adjuster; - dvariable R0_use; // annually updated variable if SR_update_SSBpR0_timeseries == 1; gets passed to Spawn_Recr() function - dvariable SSB_use; if (Do_Morphcomp > 0) Morphcomp_exp.initialize(); // SS_Label_Info_24.0 #Retrieve spawning biomass and recruitment from the initial equilibrium - // SPAWN-RECR: begin of time series, retrieve last spbio and recruitment + // SPAWN-RECR: begin of time series, retrieve last SSBio and recruitment SSB_current = SSB_yr(styr); // need these initial assignments in case recruitment distribution occurs before spawnbio&recruits - if (recdev_doit(styr - 1) > 0) - { + if (recdev_doit(styr - 1) > 0) { Recruits = R1 * mfexp(recdev(styr - 1) - biasadj(styr - 1) * half_sigmaRsq); } - else - { + else { Recruits = R1; } // SS_Label_Info_24.1 #Loop the years - for (y = styr; y <= endyr; y++) - { + for (y = styr; y <= endyr; y++) { yz = y; if (STD_Yr_Reverse_F(y) > 0) F_std(STD_Yr_Reverse_F(y)) = 0.0; t_base = styr + (y - styr) * nseas - 1; - for (f = 1; f <= N_SRparm2; f++) - { - if (SR_parm_timevary(f) == 0) - { + for (f = 1; f <= N_SRparm2; f++) { + if (SR_parm_timevary(f) == 0) { // no change to SR_parm_work } - else - { + else { SR_parm_work(f) = parm_timevary(SR_parm_timevary(f), y); -// warning << "tester_C: " << SR_parm_work(f) << " timevary_year " << endl; + // warning << "tester_C: " << SR_parm_work(f) << " timevary_year " << endl; } SR_parm_byyr(y, f) = SR_parm_work(f); } - // SS_Label_Info_24.1.1 #store begin of year quantities for use in density-dependent processes + // SS_Label_Info_24.1.1 #store begin of year quantities for use in density-dependent processes { env_data(y, -1) = log(SSB_current / SSB_yr(styr - 1)); - if (recdev_doit(y) > 0) - { + if (recdev_doit(y) > 0) { env_data(y, -2) = recdev(y); } // store so can do density-dependence - else - { // should be 0.0 + else { // should be 0.0 } t = t_base + 1; // first season s = 1; - if (WTage_rd > 0) - { + if (WTage_rd > 0) { Wt_Age_beg(s) = Wt_Age_t(t, 0); Wt_Age_mid(s) = Wt_Age_t(t, -1); } - else if (timevary_MG(y, 2) > 0 || timevary_MG(y, 3) > 0 || save_for_report == 1) - { + else if (timevary_MG(y, 2) > 0 || timevary_MG(y, 3) > 0 || save_for_report == 1) { get_growth3(y, t, 1, 1); // before season loop, used for summary biomass ALK_subseas_update(1) = 1; // do 1st subseas of 1st season; ADD THIS LINE for 3.30.17 Make_AgeLength_Key(s, 1); // this will give wt_age_beg before any time-varying parameter changes for this year ALK_idx = (s - 1) * N_subseas + 1; for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { Wt_Age_beg(s, g) = (ALK(ALK_idx, g) * wt_len(s, GP(g))); // wt-at-age at beginning of period } } @@ -770,12 +675,10 @@ FUNCTION void get_time_series() smrynum = 0.0; // do not do totbio here because new recruits have not yet occurred for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (p = 1; p <= pop; p++) - { + if (use_morph(g) > 0) { + for (p = 1; p <= pop; p++) { smrybio += natage(t, p, g)(Smry_Age, nages) * Wt_Age_beg(1, g)(Smry_Age, nages); // calc before recruitment and time-vary biology applied - smrynum += sum(natage(t, p, g)(Smry_Age, nages)); //sums to accumulate across platoons and settlements + smrynum += sum(natage(t, p, g)(Smry_Age, nages)); // sums to accumulate across platoons and settlements } } env_data(y, -3) = log(smrybio / Smry_Table(styr - 1, 2)); @@ -785,37 +688,31 @@ FUNCTION void get_time_series() Smry_Table(y, 3) = smrynum; } - // SS_Label_Info_24.1.1 #skip biology updating if y=styr because already done - if (y > styr) - { + // SS_Label_Info_24.1.1 #skip biology updating if y=styr because already done + if (y > styr) { if (do_densitydependent == 1) make_densitydependent_parm(y); // call to adjust for density dependence // SS_Label_Info_24.1.1 #Update the time varying biology factors if necessary if (timevary_MG(y, 0) > 0 || save_for_report > 0) get_MGsetup(y); - if (timevary_MG(y, 2) > 0) - { + if (timevary_MG(y, 2) > 0) { ALK_subseas_update = 1; // indicate that all ALKs will need re-estimation get_growth2(y); // propagates growth to each season this year and to begin next year get_growth3(y, t, 1, 1); // cleans up the linear growth range for begin of this year } - if (timevary_MG(y, 3) > 0) - { + if (timevary_MG(y, 3) > 0) { get_wtlen(); // stores values for all seasons // note that get_mat_fec() will get called in the season loop because it may need the ALK for a later season // but Maunder's M in get_natmort() may use the fecundity vector, so would be using the most recently calculated Problem?? if (Hermaphro_Option != 0) get_Hermaphro(); } - if (timevary_MG(y, 1) > 0) - { + if (timevary_MG(y, 1) > 0) { get_natmort(); } - else - { - for (s = 1; s <= nseas; s++) - { + else { + for (s = 1; s <= nseas; s++) { natM(t_base + s) = natM(t_base - nseas + s); } // set M equal to last year's; // does all areas (p), but if there are predators, then add of pred_M2 occurs in season loop below @@ -823,13 +720,11 @@ FUNCTION void get_time_series() if (timevary_MG(y, 4) > 0) get_recr_distribution(); - if (y >= Bmark_Yr(7) && y <= Bmark_Yr(8)) - { + if (y >= Bmark_Yr(7) && y <= Bmark_Yr(8)) { for (gp = 1; gp <= N_GP; gp++) for (p = 1; p <= pop; p++) for (settle = 1; settle <= N_settle_timings; settle++) - if (recr_dist_pattern(gp, settle, p) > 0) - { + if (recr_dist_pattern(gp, settle, p) > 0) { recr_dist_unf(gp, settle, p) += recr_dist(y, gp, settle, p); if (gender == 2) recr_dist_unf(gp + N_GP, settle, p) += recr_dist(y, gp + N_GP, settle, p); @@ -837,42 +732,35 @@ FUNCTION void get_time_series() } if (timevary_MG(y, 5) > 0) get_migration(); - if (timevary_MG(y, 7) > 0) - { + if (timevary_MG(y, 7) > 0) { get_catch_mult(y, catch_mult_pointer); } - if (Use_AgeKeyZero > 0) - { - if (timevary_MG(y, 6) > 0) - { + if (Use_AgeKeyZero > 0) { + if (timevary_MG(y, 6) > 0) { get_age_age(Use_AgeKeyZero, AgeKey_StartAge, AgeKey_Linear1, AgeKey_Linear2); // call function to get the age_age key - if (save_for_report == 1 && store_agekey_add > 0) - { + if (save_for_report == 1 && store_agekey_add > 0) { save_agekey_count++; // next blank key after the used keys age_age(save_agekey_count) = age_age(Use_AgeKeyZero); age_err(save_agekey_count) = age_err(Use_AgeKeyZero); } - #ifdef DO_ONCE +#ifdef DO_ONCE if (do_once == 1) echoinput << " ageerr_key recalc in " << y << endl; - #endif +#endif } } - if (save_for_report > 0) - { - if (timevary_MG(y, 1) > 0 || timevary_MG(y, 2) > 0 || timevary_MG(y, 3) > 0) - { + if (save_for_report > 0) { + if (timevary_MG(y, 1) > 0 || timevary_MG(y, 2) > 0 || timevary_MG(y, 3) > 0) { get_saveGparm(); } } } // SS_Label_Info_24.2 #Loop the seasons - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { if (docheckup == 1) echoinput << endl << "************************************" << endl @@ -886,43 +774,36 @@ FUNCTION void get_time_series() // SS_Label_Info_24.2.1 #Update the age-length key and the fishery selectivity for this season // if(timevary_MG(y,2)>0 || timevary_MG(y,3)>0 || save_for_report==1 || WTage_rd>0) - if (timevary_MG(y, 2) > 0 || save_for_report == 1) - { + if (timevary_MG(y, 2) > 0 || save_for_report == 1) { get_growth3(y, t, s, 1); // first subseas of season=s Make_AgeLength_Key(s, 1); get_growth3(y, t, s, mid_subseas); // for midseason Make_AgeLength_Key(s, mid_subseas); // SPAWN-RECR: call Make_Fecundity in time series - if (s == spawn_seas) - { - if (spawn_subseas != 1 && spawn_subseas != mid_subseas) - { + if (s == spawn_seas) { + if (spawn_subseas != 1 && spawn_subseas != mid_subseas) { subseas = spawn_subseas; get_growth3(y, t, s, subseas); Make_AgeLength_Key(s, subseas); // spawn subseas } } } - if (WTage_rd > 0) - { + if (WTage_rd > 0) { Wt_Age_beg(s) = Wt_Age_t(t, 0); Wt_Age_mid(s) = Wt_Age_t(t, -1); - if (s == spawn_seas) - { + if (s == spawn_seas) { fec = Wt_Age_t(t, -2); } } - else if (timevary_MG(y, 2) > 0 || timevary_MG(y, 3) > 0 || save_for_report > 0 || do_once == 1) - { + else if (timevary_MG(y, 2) > 0 || timevary_MG(y, 3) > 0 || save_for_report > 0 || do_once == 1) { if (s == spawn_seas) get_mat_fec(); // Make_Fecundity(); ALK_idx = (s - 1) * N_subseas + 1; // subseas=1 int ALK_idx2 = (s - 1) * N_subseas + mid_subseas; for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { Wt_Age_beg(s, g) = (ALK(ALK_idx, g) * wt_len(s, GP(g))); // wt-at-age at beginning of period Wt_Age_mid(s, g) = ALK(ALK_idx2, g) * wt_len(s, GP(g)); // use for fisheries with no size selectivity } @@ -933,72 +814,64 @@ FUNCTION void get_time_series() if (y > styr) // because styr is done as part of initial conditions { for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { Make_FishSelex(); } -// rebase natM to M1 - for(p = 1; p <= pop; p++) - { - natM(t, p) = natM(t,0); + // rebase natM to M1 + for (p = 1; p <= pop; p++) { + natM(t, p) = natM(t, 0); } // SS_Label_Info_24.x.x #add predator M2 inside the yr,seas loop - if(N_pred>0) - { - // add pred_M2 by area - for (f1 = 1; f1 <= N_pred; f1++) - { + if (N_pred > 0) { + // add pred_M2 by area + for (f1 = 1; f1 <= N_pred; f1++) { f = predator(f1); pred_M2(f1, t) = mgp_adj(predparm_pointer(f1)); // base with no seasonal effect if (nseas > 1) pred_M2(f1, t) *= mgp_adj(predparm_pointer(f1) + s); - p = fleet_area(f); // area this predator occurs in + p = fleet_area(f); // area this predator occurs in - // a new array for indexing g and gpi could simplify below - // for (gp = 1; gp <= N_GP * gender * N_settle_timings; gp++) + // a new array for indexing g and gpi could simplify below + // for (gp = 1; gp <= N_GP * gender * N_settle_timings; gp++) - for (gp = 1; gp <= N_GP * gender; gp++) - { + for (gp = 1; gp <= N_GP * gender; gp++) { g = g_Start(gp); // base platoon - for (settle = 1; settle <= N_settle_timings; settle++) - { + for (settle = 1; settle <= N_settle_timings; settle++) { g += N_platoon; int gpi = GP3(g); // GP*gender*settlement - natM(t, p,gpi) += pred_M2(f1, t) * sel_num(s, f, g); - if (do_once == 1 && p == 1) - echoinput << y << " s " << s << " t " << t << " area " << 0 << " gp " << gpi << " M1: " << natM(t,0, gpi) << endl; - if (do_once == 1) - echoinput << y << " s " << s << " t " << t << " area " << p << " gp " << gpi << " M1+M2: " << natM(t, p, gpi) << endl; + natM(t, p, gpi) += pred_M2(f1, t) * sel_num(s, f, g); + if (do_once == 1 && p == 1) + echoinput << y << " s " << s << " t " << t << " area " << 0 << " gp " << gpi << " M1: " << natM(t, 0, gpi) << endl; + if (do_once == 1) + echoinput << y << " s " << s << " t " << t << " area " << p << " gp " << gpi << " M1+M2: " << natM(t, p, gpi) << endl; } } } } - for(p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { int s1 = (p - 1) * nseas + s; - surv1(s1) = mfexp(-natM(t,p) * seasdur_half(s)); + surv1(s1) = mfexp(-natM(t, p) * seasdur_half(s)); surv2(s1) = square(surv1(s1)); } } // SS_Label_Info_24.2.2 #Compute spawning biomass if this is spawning season so recruits could occur later this season - // SPAWN-RECR: calc SPB in time series if spawning is at beginning of the season + // SPAWN-RECR: calc SSB in time series if spawning is at beginning of the season if (s == spawn_seas && spawn_time_seas < 0.0001) // compute spawning biomass if spawning at beginning of season so recruits could occur later this season { SSB_pop_gp(y).initialize(); SSB_B_yr(y).initialize(); SSB_N_yr(y).initialize(); Smry_Table(y, 15) = 0.0; - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { for (g = 1; g <= gmorph; g++) if (sx(g) == 1 && use_morph(g) > 0) // female { SSB_pop_gp(y, p, GP4(g)) += fracfemale_mult * fec(g) * natage(t, p, g); // accumulates SSB by area and by growthpattern SSB_B_yr(y) += fracfemale_mult * make_mature_bio(GP4(g)) * natage(t, p, g); SSB_N_yr(y) += fracfemale_mult * make_mature_numbers(GP4(g)) * natage(t, p, g); - Smry_Table(y, 15) += fracfemale_mult * natage(t, p, g) * elem_prod(fec(g), r_ages); // for mean age of female spawners = GenTime + Smry_Table(y, 15) += fracfemale_mult * natage(t, p, g) * elem_prod(fec(g), r_ages); // for mean age of female spawners = GenTime // SSB_pop_gp(y,p,GP4(g)) += fec(g)*natage(t,p,g); // accumulates SSB by area and by growthpattern // SSB_B_yr(y) += make_mature_bio(GP4(g))*natage(t,p,g); // SSB_N_yr(y) += make_mature_numbers(GP4(g))*natage(t,p,g); @@ -1009,18 +882,17 @@ FUNCTION void get_time_series() if (Hermaphro_Option != 0) // get male biomass { - MaleSPB(y).initialize(); - for (p = 1; p <= pop; p++) - { + MaleSSB(y).initialize(); + for (p = 1; p <= pop; p++) { for (g = 1; g <= gmorph; g++) if (sx(g) == 2 && use_morph(g) > 0) // male; all assumed to be mature { - MaleSPB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * natage(t, p, g); // accumulates SSB by area and by growthpattern + MaleSSB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * natage(t, p, g); // accumulates SSB by area and by growthpattern } } - if (Hermaphro_maleSPB > 0.0) // add MaleSPB to female SSB + if (Hermaphro_maleSSB > 0.0) // add MaleSSB to female SSB { - SSB_current += Hermaphro_maleSPB * sum(MaleSPB(y)); + SSB_current += Hermaphro_maleSSB * sum(MaleSSB(y)); SSB_yr(y) = SSB_current; } } @@ -1033,8 +905,7 @@ FUNCTION void get_time_series() R0_use = Recr_virgin; SSB_use = SSB_virgin; } - else - { + else { R0_use = mfexp(SR_parm_work(1)); equ_Recr = R0_use; Fishon = 0; @@ -1042,18 +913,17 @@ FUNCTION void get_time_series() bio_yr = y; Do_Equil_Calc(R0_use); // call function to do equilibrium calculation with current year's biology and adjusted R0 SSB_use = SSB_equil; - SSBpR_virgin_adj = SSB_use / R0_use; // update - if (fishery_on_off == 1) - { + SSBpR_virgin_adj = SSB_use / R0_use; // update + if (fishery_on_off == 1) { Fishon = 1; } - else - { + else { Fishon = 0; } } Recruits = Spawn_Recr(SSB_use, R0_use, SSB_current); // calls to function Spawn_Recr using either virgin or adjusted R0 and SSB0 - if (SR_fxn != 7) apply_recdev(Recruits, R0_use); // apply recruitment deviation + if (SR_fxn != 7) + apply_recdev(Recruits, R0_use); // apply recruitment deviation // distribute Recruitment of age 0 fish among the current and future settlements; and among areas and morphs // use t offset for each birth event: Settlement_offset(settle) // so the total number of Recruits will be relative to their numbers at the time of the set of settlement_events. @@ -1069,26 +939,23 @@ FUNCTION void get_time_series() // NOTE: the distributed recruits are added into natage because more than one settlement can occur in same season // but each settlement has a unique "g", so maybe additive is not necessary for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { settle = settle_g(g); - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { if (y == styr) natage(t + Settle_seas_offset(settle), p, g, Settle_age(settle)) = 0.0; // to negate the additive code natage(t + Settle_seas_offset(settle), p, g, Settle_age(settle)) += Recruits * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)) * mfexp(natM(t, p, GP3(g), Settle_age(settle)) * Settle_timing_seas(settle)); - Recr(p, t + Settle_seas_offset(settle)) += Recruits * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)); + Recr(p, t + Settle_seas_offset(settle)) += Recruits * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)); // the adjustment for mortality increases recruit value for elapsed time since begin of season because M will then be applied from beginning of season if (docheckup == 1) - echoinput << y << " Recruits, dist, surv, result " << Recruits << " " << recr_dist(y, GP(g), settle, p) << " " << mfexp(natM(t, p, GP3(g), Settle_age(settle)) * Settle_timing_seas(settle)) << " " << natage(t + Settle_seas_offset(settle), p, g, Settle_age(settle)) << " M "< 0) - { + if (use_morph(g) > 0) { // SS_Label_Info_24.3.1 #Get middle of season numbers-at-age from M only; int s1 = (p - 1) * nseas + s; Nmid(g) = elem_prod(natage(t, p, g), surv1(s1, GP3(g))); // get numbers-at-age(g,a) surviving to middle of time period @@ -1108,8 +973,7 @@ FUNCTION void get_time_series() echoinput << p << " " << g << " " << GP3(g) << " area & morph " << endl << "N-at-age " << natage(t, p, g)(0, min(6, nages)) << endl << "survival " << surv1(s, GP3(g))(0, min(6, nages)) << endl; - if (save_for_report == 1) - { + if (save_for_report == 1) { // SS_Label_Info_24.3.2 #Store some beginning of season quantities Save_PopLen(t, p, g) = 0.0; Save_PopLen(t, p + pop, g) = 0.0; // later put midseason here @@ -1120,18 +984,16 @@ FUNCTION void get_time_series() Save_PopBio(t, p, g) = 0.0; Save_PopBio(t, p + pop, g) = 0.0; // later put midseason here ALK_idx = (s - 1) * N_subseas + 1; - for (a = 0; a <= nages; a++) - { + for (a = 0; a <= nages; a++) { Save_PopLen(t, p, g) += value(natage(t, p, g, a)) * value(ALK(ALK_idx, g, a)); Save_PopWt(t, p, g) += value(natage(t, p, g, a)) * value(elem_prod(ALK(ALK_idx, g, a), wt_len(s, GP(g)))); Save_PopAge(t, p, g, a) = value(natage(t, p, g, a)); Save_PopBio(t, p, g, a) = value(natage(t, p, g, a)) * value(Wt_Age_beg(s, g, a)); } // close age loop - if (s == 1) - { + if (s == 1) { totbio += natage(t, p, g)(0, nages) * Wt_Age_beg(s, g)(0, nages); smrybio += natage(t, p, g)(Smry_Age, nages) * Wt_Age_beg(s, g)(Smry_Age, nages); - smrynum += sum(natage(t, p, g)(Smry_Age, nages)); //sums to accumulate across platoons and settlements + smrynum += sum(natage(t, p, g)(Smry_Age, nages)); // sums to accumulate across platoons and settlements } } } @@ -1139,8 +1001,7 @@ FUNCTION void get_time_series() // SS_Label_Info_24.3.3 #Do fishing mortality catage_tot.initialize(); - if ((catch_seas_area(t, p, 0) == 1 && fishery_on_off == 1)) - { + if ((catch_seas_area(t, p, 0) == 1 && fishery_on_off == 1)) { if (F_Method > 1) // not Pope's { // SS_Label_Info_24.3.3.3 #use the hybrid F method by selected fleets @@ -1149,24 +1010,21 @@ FUNCTION void get_time_series() if (k < F_PH_time(0, t)) // some fleet needs hybrid this phase { // SS_Label_Info_24.3.3.3.1 #Start by doing a Pope's approximation - for (int ff = 1; ff <= N_catchfleets(p); ff++) // loop fleets in this area (p) + for (int ff = 1; ff <= N_catchfleets(p); ff++) // loop fleets in this area (p) { f = fish_fleet_area(p, ff); if (k < F_PH_time(f, t)) // do hybrid F for this fleet { vbio.initialize(); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - if (catchunits(f) == 1) - { + if (use_morph(g) > 0) { + if (catchunits(f) == 1) { vbio += Nmid(g) * sel_ret_bio(s, f, g); } // retained catch bio - else - { + else { vbio += Nmid(g) * sel_ret_num(s, f, g); } // retained catch numbers - } //close gmorph loop + } // close gmorph loop // SS_Label_Info_24.3.3.3.2 #Apply constraint so that no fleet's initial calculation of harvest rate would exceed 95% temp = catch_ret_obs(f, t) / (vbio + 0.1 * catch_ret_obs(f, t)); // Pope's rate robust join1 = 1. / (1. + mfexp(30. * (temp - 0.95))); // steep logistic joiner at harvest rate of 0.95 @@ -1177,15 +1035,12 @@ FUNCTION void get_time_series() } // SS_Label_Info_24.3.3.3.4 #Do a specified number of loops to tune up these F values to more closely match the observed catch - for (int tune_F = 1; tune_F <= F_Tune - 1; tune_F++) - { + for (int tune_F = 1; tune_F <= F_Tune - 1; tune_F++) { // SS_Label_Info_24.3.3.3.5 #add F+M to get Z for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - Z_rate(t, p, g) = natM(t, p, GP3(g)); // already includes predators - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + if (use_morph(g) > 0) { + Z_rate(t, p, g) = natM(t, p, GP3(g)); // already includes predators + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); Z_rate(t, p, g) += sel_dead_num(s, f, g) * Hrate(f, t); } @@ -1198,39 +1053,34 @@ FUNCTION void get_time_series() interim_tot_catch = 0.0; // this is the expected total catch that would occur with the current Hrates and Z // totcatch_byarea(t,p) is now recalculated here just for the fleets doing hybrid in this phase double target_catch = 0.0; - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); - + if (current_phase() < F_PH_time(f, t)) // so still doing hybrid; skips bycatch fleets { for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - if (catchunits(f) == 1) - { + if (use_morph(g) > 0) { + if (catchunits(f) == 1) { interim_tot_catch += catch_mult(y, f) * Hrate(f, t) * elem_prod(natage(t, p, g), sel_ret_bio(s, f, g)) * Zrate2(p, g); // biomass basis } - else - { + else { interim_tot_catch += catch_mult(y, f) * Hrate(f, t) * elem_prod(natage(t, p, g), sel_ret_num(s, f, g)) * Zrate2(p, g); // numbers basis } - } //close gmorph loop + } // close gmorph loop target_catch += catch_ret_obs(f, t); } } // close fishery Z_adjuster = target_catch / (interim_tot_catch + 0.0001); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { Z_rate(t, p, g) = natM(t, p, GP3(g)) + Z_adjuster * (Z_rate(t, p, g) - natM(t, p, GP3(g))); // find adjusted Z Zrate2(p, g) = elem_div((1. - mfexp(-seasdur(s) * Z_rate(t, p, g))), Z_rate(t, p, g)); } - for (int ff = 1; ff <= N_catchfleets(p); ff++) //loop over fishing fleets with input catch + for (int ff = 1; ff <= N_catchfleets(p); ff++) // loop over fishing fleets with input catch { f = fish_fleet_area(p, ff); -// if (fleet_type(f) == 1) + // if (fleet_type(f) == 1) { if (current_phase() < F_PH_time(f, t)) // skips bycatch fleets and fixed F values { @@ -1238,17 +1088,14 @@ FUNCTION void get_time_series() // since catch = N * F*sel * (1-e(-Z))/Z // so F = catch / (N*sel * (1-e(-Z)) /Z ) for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - if (catchunits(f) == 1) - { + if (use_morph(g) > 0) { + if (catchunits(f) == 1) { vbio += elem_prod(natage(t, p, g), sel_ret_bio(s, f, g)) * Zrate2(p, g); } - else - { + else { vbio += elem_prod(natage(t, p, g), sel_ret_num(s, f, g)) * Zrate2(p, g); } - } //close gmorph loop + } // close gmorph loop temp = catch_ret_obs(f, t) / (catch_mult(y, f) * vbio + 0.0001); // prototype new F join1 = 1. / (1. + mfexp(30. * (temp - 0.95 * max_harvest_rate))); Hrate(f, t) = join1 * temp + (1. - join1) * max_harvest_rate; // new F value for this fleet @@ -1264,15 +1111,12 @@ FUNCTION void get_time_series() { // SS_Label_Info_24.3.3.2.1 #For each platoon, loop fleets to calculate Z = M+sum(F) for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - Z_rate(t, p, g) = natM(t, p, GP3(g)); // already includes predators M2 + if (use_morph(g) > 0) { + Z_rate(t, p, g) = natM(t, p, GP3(g)); // already includes predators M2 - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); - if (catch_seas_area(t, p, f) == 1) - { + if (catch_seas_area(t, p, f) == 1) { Z_rate(t, p, g) += sel_dead_num(s, f, g) * Hrate(f, t); } } @@ -1280,14 +1124,11 @@ FUNCTION void get_time_series() } // SS_Label_Info_24.3.3.2.2 #For each fleet, loop platoons and accumulate catch - for (int ff = 1; ff <= N_catchfleets(0); ff++) - { + for (int ff = 1; ff <= N_catchfleets(0); ff++) { f = fish_fleet_area(0, ff); - if (catch_seas_area(t, p, f) == 1) - { + if (catch_seas_area(t, p, f) == 1) { for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { catch_fleet(t, f, 1) += Hrate(f, t) * elem_prod(natage(t, p, g), sel_bio(s, f, g)) * Zrate2(p, g); catch_fleet(t, f, 2) += Hrate(f, t) * elem_prod(natage(t, p, g), sel_dead_bio(s, f, g)) * Zrate2(p, g); catch_fleet(t, f, 3) += Hrate(f, t) * elem_prod(natage(t, p, g), sel_ret_bio(s, f, g)) * Zrate2(p, g); // retained bio @@ -1295,47 +1136,41 @@ FUNCTION void get_time_series() catch_fleet(t, f, 5) += Hrate(f, t) * elem_prod(natage(t, p, g), sel_dead_num(s, f, g)) * Zrate2(p, g); catch_fleet(t, f, 6) += Hrate(f, t) * elem_prod(natage(t, p, g), sel_ret_num(s, f, g)) * Zrate2(p, g); // retained numbers catage(t, f, g) = Hrate(f, t) * elem_prod(elem_prod(natage(t, p, g), sel_dead_num(s, f, g)), Zrate2(p, g)); - if (Do_Retain(f) > 0) - { + if (Do_Retain(f) > 0) { disc_age(t, disc_fleet_list(f), g) = Hrate(f, t) * elem_prod(elem_prod(natage(t, p, g), sel_num(s, f, g)), Zrate2(p, g)); // selected numbers disc_age(t, disc_fleet_list(f) + N_retain_fleets, g) = Hrate(f, t) * elem_prod(elem_prod(natage(t, p, g), sel_ret_num(s, f, g)), Zrate2(p, g)); // selected numbers } - } //close gmorph loop + } // close gmorph loop } } // close fishery } // end continuous F method } - else // doing F with Pope's approximation. Predators cannot be used + else // doing F with Pope's approximation. Predators cannot be used { // SS_Label_Info_24.3.3.1 #Use F_Method=1 for Pope's approximation // SS_Label_Info_24.3.3.1.1 #note that pred_M2 not implemented for Pope's - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); - if (catch_seas_area(t, p, f) == 1) - { + if (catch_seas_area(t, p, f) == 1) { dvar_matrix catage_w = catage(t, f); // do shallow copy // SS_Label_Info_24.3.3.1.2 #loop over platoons and calculate the vulnerable biomass for each fleet vbio.initialize(); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { // use sel_l to get total catch and use sel_l_r to get retained vbio // note that vbio in numbers can be used for both survey abund and fishery available "biomass" // vbio is for retained catch only; harvest rate = retainedcatch/vbio; // then harvestrate*catage_w = total kill by this fishery for this morph - if (catchunits(f) == 1) - { + if (catchunits(f) == 1) { vbio += Nmid(g) * sel_ret_bio(s, f, g); } // retained catch bio - else - { + else { vbio += Nmid(g) * sel_ret_num(s, f, g); } // retained catch numbers - } //close gmorph loop + } // close gmorph loop if (docheckup == 1) echoinput << "fleet vbio obs_catch catch_mult vbio*catchmult" << f << " " << vbio << " " << catch_ret_obs(f, t) << " " << catch_mult(y, f) << " " << catch_mult(y, f) * vbio << endl; // SS_Label_Info_24.3.3.1.3 #Calculate harvest rate for each fleet from catch/vulnerable biomass @@ -1343,20 +1178,18 @@ FUNCTION void get_time_series() crashtemp = max_harvest_rate - catch_ret_obs(f, t) / (catch_mult(y, f) * vbio + NilNumbers); crashtemp1 = posfun(crashtemp, 0.000001, CrashPen); harvest_rate = max_harvest_rate - crashtemp1; - if (crashtemp < 0. && rundetail >= 2) - { + if (crashtemp < 0. && rundetail >= 2) { cout << y << " " << f << " crash vbio*catchmult " << catch_ret_obs(f, t) / (catch_mult(y, f) * (vbio + NilNumbers)) << " " << crashtemp << " " << crashtemp1 << " " << CrashPen << " " << harvest_rate << endl; } Hrate(f, t) = harvest_rate; // SS_Label_Info_24.3.3.1.4 #Store various catch quantities in catch_fleet for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { catage_w(g) = harvest_rate * elem_prod(Nmid(g), sel_dead_num(s, f, g)); // total kill numbers at age if (docheckup == 1) echoinput << "killrate " << sel_dead_num(s, f, g)(0, min(6, nages)) << endl; - catage_tot(g) += catage_w(g); //catch at age for all fleets + catage_tot(g) += catage_w(g); // catch at age for all fleets catch_fleet(t, f, 2) += Hrate(f, t) * Nmid(g) * sel_dead_bio(s, f, g); // total fishery kill in biomass catch_fleet(t, f, 5) += Hrate(f, t) * Nmid(g) * sel_dead_num(s, f, g); // total fishery kill in numbers catch_fleet(t, f, 1) += Hrate(f, t) * Nmid(g) * sel_bio(s, f, g); // total fishery encounter in biomass @@ -1369,20 +1202,16 @@ FUNCTION void get_time_series() // SS_Label_Info_24.3.3.1.5 #Check for catch_total across fleets being greater than population numbers for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { for (a = 0; a <= nages; a++) // check for negative abundance, starting at age 1 { - if (natage(t, p, g, a) > 0.0) - { + if (natage(t, p, g, a) > 0.0) { crashtemp = max_harvest_rate - catage_tot(g, a) / (Nmid(g, a) + 0.0000001); crashtemp1 = posfun(crashtemp, 0.000001, CrashPen); - if (crashtemp < 0. && rundetail >= 2) - { + if (crashtemp < 0. && rundetail >= 2) { cout << " crash age " << catage_tot(g, a) / (Nmid(g, a) + 0.0000001) << " " << crashtemp << " " << crashtemp1 << " " << CrashPen << " " << (max_harvest_rate - crashtemp1) * Nmid(g, a) << endl; } - if (crashtemp < 0. && docheckup == 1) - { + if (crashtemp < 0. && docheckup == 1) { echoinput << " crash age " << catage_tot(g, a) / (Nmid(g, a) + 0.0000001) << " " << crashtemp << " " << crashtemp1 << " " << CrashPen << " " << (max_harvest_rate - crashtemp1) * Nmid(g, a) << endl; } catage_tot(g, a) = (max_harvest_rate - crashtemp1) * Nmid(g, a); @@ -1390,8 +1219,7 @@ FUNCTION void get_time_series() temp = natage(t, p, g, a) * surv2(s, GP3(g), a) - catage_tot(g, a) * surv1(s, GP3(g), a); Z_rate(t, p, g, a) = -log(temp / natage(t, p, g, a)) / seasdur(s); } - else - { + else { Z_rate(t, p, g, a) = -log(surv2(s, GP3(g), a)) / seasdur(s); } } @@ -1400,38 +1228,31 @@ FUNCTION void get_time_series() } } // end Pope's approx } // end have some catch in this seas x area - else - { + else { // SS_Label_Info_24.3.3.4 #No catch or fishery turned off, so set Z=M for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - Z_rate(t, p, g) = natM(t, p, GP3(g)); // includes predators + if (use_morph(g) > 0) { + Z_rate(t, p, g) = natM(t, p, GP3(g)); // includes predators Zrate2(p, g) = elem_div((1. - mfexp(-seasdur(s) * Z_rate(t, p, g))), Z_rate(t, p, g)); } } - // SS_Label_Info_24.3.3.4 #save vulnerable biomass and numbers. Use middle of season - if (bigsaver == 1) - { + // SS_Label_Info_24.3.3.4 #save vulnerable biomass and numbers. Use middle of season + if (bigsaver == 1) { vuln_bio(t) = 0.0; vuln_num(t) = 0.0; for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (f = 1; f<= Nfleet; f++) - { - vuln_bio(t, f) += sel_bio(s, f, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * 0.5 * seasdur(s))); - vuln_num(t, f) += sel_num(s, f, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * 0.5 * seasdur(s))); + if (use_morph(g) > 0) { + for (f = 1; f <= Nfleet; f++) { + vuln_bio(t, f) += sel_bio(s, f, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * 0.5 * seasdur(s))); + vuln_num(t, f) += sel_num(s, f, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * 0.5 * seasdur(s))); + } } - } } - for (f1 = 1; f1 <= N_pred; f1++) - { + for (f1 = 1; f1 <= N_pred; f1++) { f = predator(f1); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { catch_fleet(t, f, 1) += pred_M2(f1, t) * elem_prod(natage(t, p, g), sel_bio(s, f, g)) * Zrate2(p, g); catch_fleet(t, f, 2) += pred_M2(f1, t) * elem_prod(natage(t, p, g), sel_dead_bio(s, f, g)) * Zrate2(p, g); catch_fleet(t, f, 3) += pred_M2(f1, t) * elem_prod(natage(t, p, g), sel_ret_bio(s, f, g)) * Zrate2(p, g); // retained bio @@ -1439,11 +1260,10 @@ FUNCTION void get_time_series() catch_fleet(t, f, 5) += pred_M2(f1, t) * elem_prod(natage(t, p, g), sel_dead_num(s, f, g)) * Zrate2(p, g); catch_fleet(t, f, 6) += pred_M2(f1, t) * elem_prod(natage(t, p, g), sel_ret_num(s, f, g)) * Zrate2(p, g); // retained numbers catage(t, f, g) = pred_M2(f1, t) * elem_prod(elem_prod(natage(t, p, g), sel_dead_num(s, f, g)), Zrate2(p, g)); - } //close gmorph loop + } // close gmorph loop } - } //close area loop - if (s == 1 && save_for_report == 1) - { + } // close area loop + if (s == 1 && save_for_report == 1) { Smry_Table(y, 1) = totbio; Smry_Table(y, 2) = smrybio; Smry_Table(y, 3) = smrynum; @@ -1456,33 +1276,31 @@ FUNCTION void get_time_series() SSB_B_yr(y).initialize(); SSB_N_yr(y).initialize(); Smry_Table(y, 15) = 0.0; - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { for (g = 1; g <= gmorph; g++) if (sx(g) == 1 && use_morph(g) > 0) // female { SSB_pop_gp(y, p, GP4(g)) += fracfemale_mult * fec(g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); // accumulates SSB by area and by growthpattern SSB_B_yr(y) += fracfemale_mult * make_mature_bio(GP4(g)) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); SSB_N_yr(y) += fracfemale_mult * make_mature_numbers(GP4(g)) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); - Smry_Table(y, 15) += fracfemale_mult * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)) * elem_prod(fec(g), r_ages); // for mean age of female spawners = GenTime + Smry_Table(y, 15) += fracfemale_mult * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)) * elem_prod(fec(g), r_ages); // for mean age of female spawners = GenTime } } SSB_current = sum(SSB_pop_gp(y)); SSB_yr(y) = SSB_current; if (Hermaphro_Option != 0) // get male biomass { - MaleSPB(y).initialize(); - for (p = 1; p <= pop; p++) - { + MaleSSB(y).initialize(); + for (p = 1; p <= pop; p++) { for (g = 1; g <= gmorph; g++) if (sx(g) == 2 && use_morph(g) > 0) // male; all assumed to be mature { - MaleSPB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); // accumulates SSB by area and by growthpattern + MaleSSB(y, p, GP4(g)) += Wt_Age_t(t, 0, g) * elem_prod(natage(t, p, g), mfexp(-Z_rate(t, p, g) * spawn_time_seas)); // accumulates SSB by area and by growthpattern } } - if (Hermaphro_maleSPB > 0.0) // add MaleSPB to female SSB + if (Hermaphro_maleSSB > 0.0) // add MaleSSB to female SSB { - SSB_current += Hermaphro_maleSPB * sum(MaleSPB(y)); + SSB_current += Hermaphro_maleSSB * sum(MaleSSB(y)); SSB_yr(y) = SSB_current; } } @@ -1494,43 +1312,40 @@ FUNCTION void get_time_series() R0_use = Recr_virgin; SSB_use = SSB_virgin; } - else // update SSB_use and R0_use where will update SSBpR0 inside the Spawn_recr fxn + else // update SSB_use and R0_use where will update SSBpR0 inside the Spawn_recr fxn { - R0_use = mfexp(SR_parm_work(1)); // check to be sure this works when R0 is derived from B-H with alpha, beta parameters + R0_use = mfexp(SR_parm_work(1)); // check to be sure this works when R0 is derived from B-H with alpha, beta parameters Fishon = 0; eq_yr = y; bio_yr = y; Do_Equil_Calc(R0_use); // call function to do equilibrium calculation SSB_use = SSB_equil; - SSBpR_virgin_adj = SSB_use / R0_use; // update - if (fishery_on_off == 1) - { + SSBpR_virgin_adj = SSB_use / R0_use; // update + if (fishery_on_off == 1) { Fishon = 1; } - else - { + else { Fishon = 0; } } Recruits = Spawn_Recr(SSB_use, R0_use, SSB_current); // calls to function Spawn_Recr - if (SR_fxn != 7) apply_recdev(Recruits, R0_use); // apply recruitment deviation + if (SR_fxn != 7) + apply_recdev(Recruits, R0_use); // apply recruitment deviation // distribute Recruitment among settlements, areas and morphs // note that because SSB_current is calculated at end of season to take into account Z, // this means that recruitment cannot occur until a subsequent season for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { settle = settle_g(g); - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { if (y == styr) natage(t + Settle_seas_offset(settle), p, g, Settle_age(settle)) = 0.0; // to negate the additive code natage(t + Settle_seas_offset(settle), p, g, Settle_age(settle)) += Recruits * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)) * mfexp(natM(t, p, GP3(g), Settle_age(settle)) * Settle_timing_seas(settle)); - Recr(p, t + Settle_seas_offset(settle)) += Recruits * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)); + Recr(p, t + Settle_seas_offset(settle)) += Recruits * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)); if (docheckup == 1) echoinput << y << " Recruits, dist, surv, result" << Recruits << " " << recr_dist(y, GP(g), settle, p) << " " << mfexp(natM(t, p, GP3(g), Settle_age(settle)) * Settle_timing_seas(settle)) << " " << natage(t + Settle_seas_offset(settle), p, g, Settle_age(settle)) << endl; } @@ -1538,40 +1353,32 @@ FUNCTION void get_time_series() } // SS_Label_Info_24.6 #Survival to next season and saving midseason numbers and biomass - for (p = 1; p <= pop; p++) - { - if (s == nseas) - { + for (p = 1; p <= pop; p++) { + if (s == nseas) { k = 1; } - else - { + else { k = 0; } // advance age or not for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { settle = settle_g(g); { j = Settle_age(settle); - if (s < nseas && Settle_seas(settle) <= s) - { + if (s < nseas && Settle_seas(settle) <= s) { natage(t + 1, p, g, j) = natage(t, p, g, j) * mfexp(-Z_rate(t, p, g, j) * seasdur(s)); // advance new recruits within year } - for (a = j + 1; a < nages; a++) - { + for (a = j + 1; a < nages; a++) { natage(t + 1, p, g, a) = natage(t, p, g, a - k) * mfexp(-Z_rate(t, p, g, a - k) * seasdur(s)); } natage(t + 1, p, g, nages) = natage(t, p, g, nages) * mfexp(-Z_rate(t, p, g, nages) * seasdur(s)); // plus group if (s == nseas) natage(t + 1, p, g, nages) += natage(t, p, g, nages - 1) * mfexp(-Z_rate(t, p, g, nages - 1) * seasdur(s)); - if (save_for_report == 1) - { + if (save_for_report == 1) { j = p + pop; ALK_idx = (s - 1) * N_subseas + mid_subseas; - for (a = 0; a <= nages; a++) - { + for (a = 0; a <= nages; a++) { Save_PopLen(t, j, g) += value(natage(t, p, g, a) * mfexp(-Z_rate(t, p, g, a) * 0.5 * seasdur(s))) * value(ALK(ALK_idx, g, a)); Save_PopWt(t, j, g) += value(natage(t, p, g, a) * mfexp(-Z_rate(t, p, g, a) * 0.5 * seasdur(s))) * value(elem_prod(ALK(ALK_idx, g, a), wt_len(s, GP(g)))); Save_PopAge(t, j, g, a) = value(natage(t, p, g, a) * mfexp(-Z_rate(t, p, g, a) * 0.5 * seasdur(s))); @@ -1579,8 +1386,7 @@ FUNCTION void get_time_series() } // close age loop } } - if (docheckup == 1) - { + if (docheckup == 1) { echoinput << g << " natM: " << natM(t, p, GP3(g))(0, min(6, nages)) << endl; echoinput << g << " Z: " << Z_rate(t, p, g)(0, min(6, nages)) << endl; echoinput << g << " N_surv: " << natage(t + 1, p, g)(0, min(6, nages)) << endl; @@ -1591,27 +1397,20 @@ FUNCTION void get_time_series() // SS_Label_Info_24.7 #call to Get_expected_values Get_expected_values(y, t); // SS_Label_Info_24.8 #hermaphroditism - if (Hermaphro_Option != 0) - { - if (Hermaphro_seas == -1 || Hermaphro_seas == s) - { + if (Hermaphro_Option != 0) { + if (Hermaphro_seas == -1 || Hermaphro_seas == s) { k = gmorph / 2; // because first half of the "g" are females for (p = 1; p <= pop; p++) // area for (g = 1; g <= k; g++) // loop females - if (use_morph(g) > 0) - { - if (Hermaphro_Option == 1) - { - for (a = 1; a < nages; a++) - { + if (use_morph(g) > 0) { + if (Hermaphro_Option == 1) { + for (a = 1; a < nages; a++) { natage(t + 1, p, g + k, a) += natage(t + 1, p, g, a) * Hermaphro_val(GP4(g), a - 1); // increment males with females natage(t + 1, p, g, a) *= (1. - Hermaphro_val(GP4(g), a - 1)); // decrement females } } - else if (Hermaphro_Option == -1) - { - for (a = 1; a < nages; a++) - { + else if (Hermaphro_Option == -1) { + for (a = 1; a < nages; a++) { natage(t + 1, p, g, a) += natage(t + 1, p, g + k, a) * Hermaphro_val(GP4(g + k), a - 1); // increment females with males natage(t + 1, p, g + k, a) *= (1. - Hermaphro_val(GP4(g + k), a - 1)); // decrement males } @@ -1621,7 +1420,7 @@ FUNCTION void get_time_series() } // SS_Label_Info_24.9 #migration - //do migration between populations, for each gmorph and age PROBLEM need new container so future recruits not wiped out! + // do migration between populations, for each gmorph and age PROBLEM need new container so future recruits not wiped out! if (do_migration > 0) // movement between areas in time series { natage_temp = natage(t + 1); @@ -1629,8 +1428,7 @@ FUNCTION void get_time_series() for (p = 1; p <= pop; p++) // source population for (p2 = 1; p2 <= pop; p2++) // destination population for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { k = move_pattern(s, GP4(g), p, p2); if (k > 0) natage(t + 1, p2, g) += elem_prod(natage_temp(p, g), migrrate(y, k)); @@ -1638,11 +1436,9 @@ FUNCTION void get_time_series() } // end migration // SS_Label_Info_24.10 #save selectivity*Hrate for tag-recapture - if (Do_TG > 0 && t >= TG_timestart) - { + if (Do_TG > 0 && t >= TG_timestart) { for (g = 1; g <= gmorph; g++) - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { Sel_for_tag(t, f, g) = sel_ret_num(s, f, g) * Hrate(f, t); } } @@ -1652,36 +1448,29 @@ FUNCTION void get_time_series() dvariable tempbase; dvariable tempM; dvariable tempZ; - if (fishery_on_off == 1 && (bigsaver == 1 || (F_ballpark_yr >= styr))) - { - for (int ff = 1; ff <= N_catchfleets(0); ff++) - { + if (fishery_on_off == 1 && (bigsaver == 1 || (F_ballpark_yr >= styr))) { + for (int ff = 1; ff <= N_catchfleets(0); ff++) { f = fish_fleet_area(0, ff); - for (k = 1; k <= 6; k++) - { + for (k = 1; k <= 6; k++) { annual_catch(y, k) += catch_fleet(t, f, k); if (k <= 3) Smry_Table(y, k + 3) = annual_catch(y, k); } - if (F_Method == 1) - { + if (F_Method == 1) { annual_F(y, 1) += Hrate(f, t); } - else - { + else { annual_F(y, 1) += Hrate(f, t) * seasdur(s); } } - if (s == nseas) - { + if (s == nseas) { // sum across p and g the number of survivors to end of the year // also project from the initial numbers and M, the number of survivors without F // then F = ln(n+1/n)(M+F) - ln(n+1/n)(M only), but ln(n) cancels out, so only need the ln of the ratio of the two ending quantities // calculated average F weighted by numbers (option 5 is unweighted) - if (F_reporting != 5) - { + if (F_reporting != 5) { tempbase = 0.0; tempM = 0.0; tempZ = 0.0; @@ -1691,15 +1480,12 @@ FUNCTION void get_time_series() for (a = F_reporting_ages(1); a <= F_reporting_ages(2); a++) // should not let a go higher than nages-2 because of accumulator { for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (p = 1; p <= pop; p++) - { + if (use_morph(g) > 0) { + for (p = 1; p <= pop; p++) { tempbase += natage(t - nseas + 1, p, g, a); // sum of numbers at beginning of year tempZ += natage(t + 1, p, g, a + 1); // numbers at beginning of next year temp3 = natage(t - nseas + 1, p, g, a); // numbers at begin of year - for (j = 1; j <= nseas; j++) - { + for (j = 1; j <= nseas; j++) { temp3 *= mfexp(-seasdur(j) * natM(t - nseas + j, p, GP3(g), a)); } tempM += temp3; // survivors if just M operating @@ -1710,8 +1496,7 @@ FUNCTION void get_time_series() annual_F(y, 3) = log(tempbase) - log(tempM); // M } // end if F_reporting!=5 - else - { // F_reporting==5 (ICES-style arithmetic mean across ages) + else { // F_reporting==5 (ICES-style arithmetic mean across ages) // like option 4 above, but F is calculated 1 age at a time to get a // unweighted average across ages within each year countN = 0.0; // used for count of Fs included in average @@ -1722,15 +1507,12 @@ FUNCTION void get_time_series() tempZ = 0.0; // accumulate numbers across all morphs, sexes, and areas for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (p = 1; p <= pop; p++) - { + if (use_morph(g) > 0) { + for (p = 1; p <= pop; p++) { tempbase += natage(t - nseas + 1, p, g, a); // sum of numbers at beginning of year tempZ += natage(t + 1, p, g, a + 1); // numbers at beginning of next year temp3 = natage(t - nseas + 1, p, g, a); // numbers at begin of year - for (j = 1; j <= nseas; j++) - { + for (j = 1; j <= nseas; j++) { temp3 *= mfexp(-seasdur(j) * natM(t - nseas + j, p, GP3(g), a)); } tempM += temp3; // survivors if just M operating @@ -1747,34 +1529,27 @@ FUNCTION void get_time_series() if (STD_Yr_Reverse_F(y) > 0) // save selected std quantity { - if (F_reporting <= 1) - { + if (F_reporting <= 1) { F_std(STD_Yr_Reverse_F(y)) = annual_catch(y, 2) / Smry_Table(y, 2); // dead catch biomass/summary biomass // does not exactly correspond to F, which is for total catch } - else if (F_reporting == 2) - { + else if (F_reporting == 2) { F_std(STD_Yr_Reverse_F(y)) = annual_catch(y, 5) / Smry_Table(y, 3); // dead catch numbers/summary numbers } - else if (F_reporting == 3) - { + else if (F_reporting == 3) { F_std(STD_Yr_Reverse_F(y)) = annual_F(y, 1); } - else if (F_reporting == 4 || F_reporting == 5) - { + else if (F_reporting == 4 || F_reporting == 5) { F_std(STD_Yr_Reverse_F(y)) = annual_F(y, 2); } } } // end s==nseas } - if (write_bodywt > 0) - { - for (g = 1; g <= gmorph; g++) - { + if (write_bodywt > 0) { + for (g = 1; g <= gmorph; g++) { gg = sx(g); - if (ishadow(GP2(g)) == 0) - { + if (ishadow(GP2(g)) == 0) { if (s == spawn_seas) bodywtout << y << " " << s << " " << gg << " " << GP4(g) << " " << Bseas(g) << " " << -2 << " " << fec(g) << " #fecundity " << endl; bodywtout << y << " " << s << " " << gg << " " << GP4(g) << " " << Bseas(g) << " " << 0 << " " << Wt_Age_beg(s, g) << " #popwt_beg " << endl; @@ -1782,13 +1557,12 @@ FUNCTION void get_time_series() } } } - } //close season loop + } // close season loop // SS_Label_Info_24.12 #End loop of seasons // SS_Label_Info_24.13 #Use current F intensity to calculate the equilibrium SPR for this year // if( (save_for_report>0) || ((sd_phase() || mceval_phase()) && (initial_params::mc_phase==0)) ) - if (bigsaver == 1) - { + if (bigsaver == 1) { eq_yr = y; equ_Recr = Recr_virgin; bio_yr = y; @@ -1796,18 +1570,16 @@ FUNCTION void get_time_series() Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation with current year's biology Smry_Table(y, 11) = SSB_equil; Smry_Table(y, 13) = GenTime; - if( SR_fxn == 10 ) - { - temp = SSB_equil / Recr_virgin; // current year's SPB/R with current biology at age + if (SR_fxn == 10) { + temp = SSB_equil / Recr_virgin; // current year's SSB/R with current biology at age alpha = mfexp(SR_parm_work(3)); beta = mfexp(SR_parm_work(4)); - SR_parm_byyr(y, 2) = alpha * temp / (4. + alpha * temp); // implied steepness - SR_parm_byyr(y, 1) = log( 1. / beta * (alpha - (1. / temp))); // implied ln_R0 + SR_parm_byyr(y, 2) = alpha * temp / (4. + alpha * temp); // implied steepness + SR_parm_byyr(y, 1) = log(1. / beta * (alpha - (1. / temp))); // implied ln_R0 } Fishon = 1; Do_Equil_Calc(equ_Recr); // call function to do equilibrium calculation with current year's biology and F - if (STD_Yr_Reverse_Ofish(y) > 0) - { + if (STD_Yr_Reverse_Ofish(y) > 0) { SPR_std(STD_Yr_Reverse_Ofish(y)) = SSB_equil / Smry_Table(y, 11); } Smry_Table(y, 9) = (totbio); @@ -1815,29 +1587,28 @@ FUNCTION void get_time_series() Smry_Table(y, 12) = (SSB_equil); Smry_Table(y, 14) = (YPR_dead); } - } //close year loop + } // close year loop // average quantities accumulated during the time series - if (Do_Benchmark > 0) - { + if (Do_Benchmark > 0) { recr_dist(styr - 3) = recr_dist_unf / float(Bmark_Yr(8) - Bmark_Yr(7) + 1); } if (Do_TG > 0) Tag_Recapture(); - } // end time_series - #ifdef DO_ONCE - if (do_once == 1) +} // end time_series +#ifdef DO_ONCE +if (do_once == 1) echoinput << " finished time series " << endl; - #endif +#endif // SS_Label_Info_24.16 # end of time series function //******************************************************************** - /* SS_Label_FUNCTION 30 Do_Equil_Calc */ +/* SS_Label_FUNCTION 30 Do_Equil_Calc */ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) - { +{ int t_base; int t; int s; @@ -1870,14 +1641,11 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) GenTime = 0.0; // first seed the recruits; seems redundant - for (g = 1; g <= gmorph; g++) - { - if (use_morph(g) > 0) - { + for (g = 1; g <= gmorph; g++) { + if (use_morph(g) > 0) { settle = settle_g(g); - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { equ_numbers(Settle_seas(settle), p, g, Settle_age(settle)) = equ_Recr * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)) * mfexp(natM(t_base + Settle_seas(settle), p, GP3(g), Settle_age(settle)) * Settle_timing_seas(settle)); } @@ -1886,29 +1654,23 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) for (a = 0; a <= 3 * nages; a++) // go to 3x nages to approximate the infinite tail, then add the infinite tail { - if (a <= nages) - { + if (a <= nages) { a1 = a; } - else - { + else { a1 = nages; } // because selex and biology max out at nages - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { t = t_base + s; for (g = 1; g <= gmorph; g++) // need to loop g inside of a because of hermaphroditism - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { gg = sx(g); // gender settle = settle_g(g); - for (p = 1; p <= pop; p++) - { - if (s == Settle_seas(settle) && a == Settle_age(settle)) - { + for (p = 1; p <= pop; p++) { + if (s == Settle_seas(settle) && a == Settle_age(settle)) { equ_numbers(Settle_seas(settle), p, g, Settle_age(settle)) = equ_Recr * recr_dist(y, GP(g), settle, p) * platoon_distr(GP2(g)) * mfexp(natM(t_base + Settle_seas(settle), p, GP3(g), Settle_age(settle)) * Settle_timing_seas(settle)); } @@ -1920,13 +1682,11 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) { N_mid = N_beg * surv1(s, GP3(g), a1); // numbers at middle of season Nsurvive = N_mid; // initial number of fishery survivors - if (Fishon == 1) - { // remove catch this round + if (Fishon == 1) { // remove catch this round // check to see if total harves would exceed max_harvest_rate crashtemp = 0.; harvest_rate = 1.0; - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); crashtemp += Hrate(f, t) * sel_dead_num(s, f, g, a1); } @@ -1938,8 +1698,7 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) harvest_rate = join1 + (1. - join1) * upselex / (crashtemp); // ratio by which all Hrates will be adjusted } - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); temp = N_mid * Hrate(f, t) * harvest_rate; // numbers that would be caught if fully selected Nsurvive -= temp * sel_dead_num(s, f, g, a1); // survival from fishery kill @@ -1956,8 +1715,7 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) Nsurvive *= surv1(s, GP3(g), a1); // decay to end of season - if (a <= a1) - { + if (a <= a1) { equ_Z(s, p, g, a1) = -(log((Nsurvive + 1.0e-13) / (N_beg + 1.0e-10))) / seasdur(s); Fishery_Survival = equ_Z(s, p, g, a1) - natM(t, p, GP3(g), a1); } @@ -1967,12 +1725,9 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) else // Continuous F for method 2 or 3 { equ_Z(s, p, g, a1) = natM(t, p, GP3(g), a1); - if (Fishon == 1) - { - if (a1 <= nages) - { - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + if (Fishon == 1) { + if (a1 <= nages) { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); equ_Z(s, p, g, a1) += sel_dead_num(s, f, g, a1) * Hrate(f, t); } @@ -1982,30 +1737,23 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) } // end F method Survivors(p, g) = Nsurvive; } - else - { + else { equ_Z(s, p, g, a1) = natM(t, p, GP3(g), a1); } } // end pop } // end morph - if (Hermaphro_Option != 0) - { - if (Hermaphro_seas == -1 || Hermaphro_seas == s) - { - for (p = 1; p <= pop; p++) - { + if (Hermaphro_Option != 0) { + if (Hermaphro_seas == -1 || Hermaphro_seas == s) { + for (p = 1; p <= pop; p++) { k = gmorph / 2; for (g = 1; g <= k; g++) - if (use_morph(g) > 0) - { - if (Hermaphro_Option == 1) - { + if (use_morph(g) > 0) { + if (Hermaphro_Option == 1) { Survivors(p, g + k) += Survivors(p, g) * Hermaphro_val(GP4(g), a1); // increment males with females Survivors(p, g) *= (1. - Hermaphro_val(GP4(g), a1)); // decrement females } - else if (Hermaphro_Option == -1) - { + else if (Hermaphro_Option == -1) { Survivors(p, g) += Survivors(p, g + k) * Hermaphro_val(GP4(g + k), a1); // increment females with males Survivors(p, g + k) *= (1. - Hermaphro_val(GP4(g + k), a1)); // decrement males } @@ -2017,11 +1765,9 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) { Survivors2.initialize(); for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { for (p = 1; p <= pop; p++) - for (p2 = 1; p2 <= pop; p2++) - { + for (p2 = 1; p2 <= pop; p2++) { k = move_pattern(s, GP4(g), p, p2); if (k > 0) Survivors2(p2, g) += Survivors(p, g) * migrrate(bio_yr, k, a1); @@ -2031,34 +1777,27 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) } // end do migration for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (p = 1; p <= pop; p++) - { + if (use_morph(g) > 0) { + for (p = 1; p <= pop; p++) { if (s == nseas) // into next age at season 1 { - if (a == 3 * nages) - { + if (a == 3 * nages) { // end of the cohort } else if (a == (3 * nages - 1)) // do infinite tail; note that it uses Z from nseas as if it applies annually { - if (F_Method == 1) - { + if (F_Method == 1) { equ_numbers(1, p, g, a + 1) = Survivors(p, g) / (1. - exp(-equ_Z(nseas, p, g, nages))); } - else - { + else { equ_numbers(1, p, g, a + 1) = Survivors(p, g) / (1. - exp(-equ_Z(nseas, p, g, nages))); } } - else - { + else { equ_numbers(1, p, g, a + 1) = Survivors(p, g); } } - else - { + else { equ_numbers(s + 1, p, g, a) = Survivors(p, g); // same age, next season } } @@ -2068,23 +1807,18 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) // now calc contribution to catch and ssb for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { + if (use_morph(g) > 0) { gg = sx(g); for (s = 1; s <= nseas; s++) - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { t = t_base + s; Zrate2(p, g) = elem_div((1. - mfexp(-seasdur(s) * equ_Z(s, p, g))), equ_Z(s, p, g)); equ_numbers(s, p, g, nages) += sum(equ_numbers(s, p, g)(nages + 1, 3 * nages)); - if (Fishon == 1) - { - if (F_Method >= 2) - { + if (Fishon == 1) { + if (F_Method >= 2) { if (s < Bseas(g)) Zrate2(p, g, 0) = 0.0; - for (int ff = 1; ff <= N_catchfleets(p); ff++) - { + for (int ff = 1; ff <= N_catchfleets(p); ff++) { f = fish_fleet_area(p, ff); equ_catch_fleet(2, s, f) += Hrate(f, t) * elem_prod(equ_numbers(s, p, g)(0, nages), sel_dead_bio(s, f, g)) * Zrate2(p, g); // dead catch bio equ_catch_fleet(5, s, f) += Hrate(f, t) * elem_prod(equ_numbers(s, p, g)(0, nages), sel_dead_num(s, f, g)) * Zrate2(p, g); // deadfish catch numbers @@ -2100,9 +1834,8 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) // already done in the age loop } } - - for (f1 = 1; f1 <= N_pred; f1++) - { + + for (f1 = 1; f1 <= N_pred; f1++) { f = predator(f1); equ_catch_fleet(2, s, f) += pred_M2(f1, t) * elem_prod(equ_numbers(s, p, g)(0, nages), sel_dead_bio(s, f, g)) * Zrate2(p, g); // dead catch bio equ_catch_fleet(5, s, f) += pred_M2(f1, t) * elem_prod(equ_numbers(s, p, g)(0, nages), sel_dead_num(s, f, g)) * Zrate2(p, g); // deadfish catch numbers @@ -2113,16 +1846,14 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) equ_catage(s, f, g) = pred_M2(f1, t) * elem_prod(elem_prod(equ_numbers(s, p, g)(0, nages), sel_dead_num(s, f, g)), Zrate2(p, g)); } - if (s == 1) - { + if (s == 1) { totbio += equ_numbers(s, p, g)(0, nages) * Wt_Age_beg(s, g)(0, nages); smrybio += equ_numbers(s, p, g)(Smry_Age, nages) * Wt_Age_beg(s, g)(Smry_Age, nages); smrynum += sum(equ_numbers(s, p, g)(Smry_Age, nages)); smryage += equ_numbers(s, p, g)(Smry_Age, nages) * r_ages(Smry_Age, nages); } // SPAWN-RECR: calc generation time, etc. - if (s == spawn_seas) - { + if (s == spawn_seas) { if (gg == 1) // compute equilibrium spawning biomass for females { tempvec_a = elem_prod(equ_numbers(s, p, g)(0, nages), mfexp(-spawn_time_seas * equ_Z(s, p, g)(0, nages))); @@ -2135,8 +1866,7 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) // equ_mat_num+=elem_prod(equ_numbers(s,p,g)(0,nages),mfexp(-spawn_time_seas*equ_Z(s,p,g)(0,nages)))*make_mature_numbers(GP4(g)); // GenTime+=tempvec_a*elem_prod(fec(g),r_ages); } - else if (Hermaphro_Option != 0 && gg == 2) - { + else if (Hermaphro_Option != 0 && gg == 2) { tempvec_a = elem_prod(equ_numbers(s, p, g)(0, nages), mfexp(-spawn_time_seas * equ_Z(s, p, g)(0, nages))); MaleSSB_equil_pop_gp(p, GP4(g)) += tempvec_a * Wt_Age_beg(s, g)(0, nages); } @@ -2149,63 +1879,50 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) YPR_N_dead = sum(equ_catch_fleet(5)); // dead numbers per recruit YPR_enc = sum(equ_catch_fleet(1)); // encountered biomass per recruit YPR_ret = sum(equ_catch_fleet(3)); // retained biomass per recruit - YPR_opt = 0.0; //dead biomass per recruit except excludes non-optimized bycatch + YPR_opt = 0.0; // dead biomass per recruit except excludes non-optimized bycatch // YPR_opt used in F0.1 and in biomass based MSY searches YPR_val_vec.initialize(); // retained biomass per recruit as vector, should be same as YPR_ret - for (int ff = 1; ff <= N_catchfleets(0); ff++) - { + for (int ff = 1; ff <= N_catchfleets(0); ff++) { f = fish_fleet_area(0, ff); - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { YPR_opt += equ_catch_fleet(2, s, f) * YPR_mask(f); // using dead catch excluding non-optimized bycatch fleets YPR_val_vec(f) += equ_catch_fleet(3, s, f) * YPR_mask(f); // using retained catch so YPR_mask should be redundant } } - if (Fishon == 1) - { - // shortcut. equ_M_std using M for area 1, gp 1 only - if (F_reporting <= 1) - { + if (Fishon == 1) { + // shortcut. equ_M_std using M for area 1, gp 1 only + if (F_reporting <= 1) { equ_F_std = YPR_dead / smrybio; equ_M_std = natM(t_base + 1, 1, 1, int(nages / 2)); } - else if (F_reporting == 2) - { + else if (F_reporting == 2) { equ_F_std = YPR_N_dead / smrynum; equ_M_std = natM(t_base + 1, 1, 1, int(nages / 2)); } - else if (F_reporting == 3) - { + else if (F_reporting == 3) { equ_M_std = natM(t_base + 1, 1, 1, int(nages / 2)); - if (F_Method == 1) - { - for (s = 1; s <= nseas; s++) - { + if (F_Method == 1) { + for (s = 1; s <= nseas; s++) { t = t_base + s; - for (int ff = 1; ff <= N_catchfleets(0); ff++) - { + for (int ff = 1; ff <= N_catchfleets(0); ff++) { f = fish_fleet_area(0, ff); equ_F_std += Hrate(f, t); } } } - else - { - for (s = 1; s <= nseas; s++) - { + else { + for (s = 1; s <= nseas; s++) { t = t_base + s; - for (int ff = 1; ff <= N_catchfleets(0); ff++) - { + for (int ff = 1; ff <= N_catchfleets(0); ff++) { f = fish_fleet_area(0, ff); equ_F_std += Hrate(f, t) * seasdur(s); } } } } - else if (F_reporting == 4) - { + else if (F_reporting == 4) { tempbase = 0.0; tempM = 0.0; tempZ = 0.0; @@ -2213,16 +1930,13 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) for (a = F_reporting_ages(1); a <= F_reporting_ages(2); a++) // should not let a go higher than nages-2 because of accumulator { for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (p = 1; p <= pop; p++) - { + if (use_morph(g) > 0) { + for (p = 1; p <= pop; p++) { tempbase += equ_numbers(1, p, g, a); // sum of numbers at beginning of year tempZ += equ_numbers(1, p, g, a + 1); // numbers at beginning of next year temp3 = equ_numbers(1, p, g, a); // numbers at begin of year - for (int kkk = 1; kkk <= nseas; kkk++) - { - temp3 *= mfexp(-seasdur(kkk) * natM(t_base+kkk, p, GP3(g), a)); + for (int kkk = 1; kkk <= nseas; kkk++) { + temp3 *= mfexp(-seasdur(kkk) * natM(t_base + kkk, p, GP3(g), a)); } tempM += temp3; // survivors if just M operating } @@ -2231,8 +1945,7 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) equ_F_std = log(tempM) - log(tempZ); // F=Z-M equ_M_std = log(tempbase) - log(tempM); // M } - else if (F_reporting == 5) - { + else if (F_reporting == 5) { // F_reporting==5 (ICES-style arithmetic mean across ages) // like option 4 above, but F is calculated 1 age at a time to get a // unweighted average across ages within each year @@ -2245,16 +1958,13 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) tempZ = 0.0; // accumulate numbers across all morphs, sexes, and areas for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - for (p = 1; p <= pop; p++) - { + if (use_morph(g) > 0) { + for (p = 1; p <= pop; p++) { tempbase += equ_numbers(1, p, g, a); // sum of numbers at beginning of year tempZ += equ_numbers(1, p, g, a + 1); // numbers at beginning of next year temp3 = equ_numbers(1, p, g, a); // numbers at begin of year - for (int kkk = 1; kkk <= nseas; kkk++) - { - temp3 *= mfexp(-seasdur(kkk) * natM(t_base+kkk, p, GP3(g), a)); + for (int kkk = 1; kkk <= nseas; kkk++) { + temp3 *= mfexp(-seasdur(kkk) * natM(t_base + kkk, p, GP3(g), a)); } tempM += temp3; // survivors if just M operating } @@ -2270,12 +1980,9 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) } Cost = 0; - for (f = 1; f <= Nfleet; f++) - { - if (YPR_mask(f) == 1) - { - for (s = 1; s <= nseas; s++) - { + for (f = 1; f <= Nfleet; f++) { + if (YPR_mask(f) == 1) { + for (s = 1; s <= nseas; s++) { Cost += CostPerF(f) * Hrate(f, t_base + s); } } @@ -2284,9 +1991,9 @@ FUNCTION void Do_Equil_Calc(const prevariable& equ_Recr) SSB_equil = sum(SSB_equil_pop_gp); GenTime /= SSB_equil; smryage /= smrynum; - if (Hermaphro_maleSPB > 0.0) // add MaleSPB to female SSB + cumF /= (r_ages(nages) - r_ages(Smry_Age) + 1.); + if (Hermaphro_maleSSB > 0.0) // add MaleSSB to female SSB { - SSB_equil += Hermaphro_maleSPB * sum(MaleSSB_equil_pop_gp); + SSB_equil += Hermaphro_maleSSB * sum(MaleSSB_equil_pop_gp); } - } // end equil calcs - +} // end equil calcs diff --git a/SS_proced.tpl b/SS_proced.tpl index 534adf53..3e545ba7 100644 --- a/SS_proced.tpl +++ b/SS_proced.tpl @@ -206,15 +206,15 @@ PROCEDURE_SECTION temp = sqrt((temp + 0.0000001) / (double(recdev_end - recdev_start + 1))); if (mcmc_counter == 0 && mceval_counter == 0) { - cout << current_phase() << " " << niter << " -log(L): " << obj_fun << " Spbio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)); + cout << current_phase() << " " << niter << " -log(L): " << obj_fun << " SSBio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)); } else if (mcmc_counter > 0) { - cout << " MCMC: " << mcmc_counter << " -log(L): " << obj_fun << " Spbio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)); + cout << " MCMC: " << mcmc_counter << " -log(L): " << obj_fun << " SSBio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)); } else if (mceval_counter > 0) { - cout << " MCeval: " << mceval_counter << " -log(L): " << obj_fun << " Spbio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)); + cout << " MCeval: " << mceval_counter << " -log(L): " << obj_fun << " SSBio: " << value(SSB_yr(styr)) << " " << value(SSB_yr(endyr)); } if (F_Method > 1 && sum(catch_like) > 0.01) { diff --git a/SS_readcontrol_330.tpl b/SS_readcontrol_330.tpl index 2299f346..b54f0bd6 100644 --- a/SS_readcontrol_330.tpl +++ b/SS_readcontrol_330.tpl @@ -1148,11 +1148,11 @@ int Hermaphro_seas; int Hermaphro_firstage; number Hermaphro_seas_rd; - number Hermaphro_maleSPB; + number Hermaphro_maleSSB; LOCAL_CALCS // clang-format on Hermaphro_seas = 0; - Hermaphro_maleSPB = 0.0; + Hermaphro_maleSSB = 0.0; Hermaphro_firstage = 0; MGparm_Hermaphro = 0; @@ -1175,8 +1175,8 @@ // so 2.3 will do switch in season 2 beginning with age 3. echoinput << Hermaphro_seas << " Hermaphro_season (-1 means all seasons)" << endl; echoinput << Hermaphro_firstage << " Hermaphro_firstage (from decimal part of seas input; note that firstage can only be a single digit, so 9 is max" << endl; - *(ad_comm::global_datafile) >> Hermaphro_maleSPB; // read as a fraction (0.0 to 1.0) of the male SSB added into the total SSB - echoinput << Hermaphro_maleSPB << " Hermaphro_maleSPB " << endl; + *(ad_comm::global_datafile) >> Hermaphro_maleSSB; // read as a fraction (0.0 to 1.0) of the male SSB added into the total SSB + echoinput << Hermaphro_maleSSB << " Hermaphro_maleSSB " << endl; } // clang-format off END_CALCS @@ -2183,6 +2183,7 @@ SR_update_SSBpR0_timeseries = 0; break; } + echoinput << "SRupdate " << SR_update_parm << " use " << SR_update_SSBpR0_bmark << " rd " << SR_update_SSBpR0_rd<< endl; echoinput << "SR_Npar and N_SRparm2 and N_SRparm3: " << N_SRparm(SR_fxn) << " " << N_SRparm2 << " " << N_SRparm3 << endl; // clang-format off END_CALCS @@ -5815,7 +5816,7 @@ Extra_Std_N += YrMax - (styr - 2) + 1; if (More_Std_Input(12) == 2) Extra_Std_N += YrMax - (styr - 2) + 1; // for recruitment } - // add 3 values for ln(Spbio) + // add 3 values for ln(SSBio) // (years are automatically generated as startyr, mid-point, and endyr) Do_se_LnSSB = Extra_Std_N + 1; Extra_Std_N += 3; @@ -6869,23 +6870,23 @@ } } - // output ln(SPB) std for selected years - echoinput << " do ln(SPB) std labels for 3 years" << endl; + // output ln(SSB) std for selected years + echoinput << " do ln(SSB) std labels for 3 years" << endl; CoVar_Count++; j++; active_parm(CoVar_Count) = j; sprintf(onenum, "%d", styr); - ParmLabel += "ln(SPB)_" + onenum + CRLF(1); + ParmLabel += "ln(SSB)_" + onenum + CRLF(1); CoVar_Count++; j++; active_parm(CoVar_Count) = j; sprintf(onenum, "%d", int((endyr + styr) / 2)); - ParmLabel += "ln(SPB)_" + onenum + CRLF(1); + ParmLabel += "ln(SSB)_" + onenum + CRLF(1); CoVar_Count++; j++; active_parm(CoVar_Count) = j; sprintf(onenum, "%d", endyr); - ParmLabel += "ln(SPB)_" + onenum + CRLF(1); + ParmLabel += "ln(SSB)_" + onenum + CRLF(1); if (Do_se_smrybio > 0) { diff --git a/SS_readdata_330.tpl b/SS_readdata_330.tpl index d212bcde..56277cb9 100644 --- a/SS_readdata_330.tpl +++ b/SS_readdata_330.tpl @@ -5035,10 +5035,10 @@ if (STD_Yr_Reverse(y) > 0) { j++; - STD_Yr_Reverse(y) = j; // use for SPB and recruitment + STD_Yr_Reverse(y) = j; // use for SSB and recruitment if (y >= styr) { - // depletion must start in year AFTER first catch. It could vary earlier if recdevs happened enough earlier to change spbio, but this is not included + // depletion must start in year AFTER first catch. It could vary earlier if recdevs happened enough earlier to change SSBio, but this is not included if ((depletion_basis > 0 && y > first_catch_yr) || y == endyr) { N_STD_Yr_Dep++; diff --git a/SS_write.tpl b/SS_write.tpl index 96d516b3..a3664db4 100644 --- a/SS_write.tpl +++ b/SS_write.tpl @@ -1011,7 +1011,7 @@ FUNCTION void write_rebuilder_output() rebuild_dat << exp_rec(y, 4) << " "; } rebuild_dat << " #recruits; first value is R0 (virgin)" << endl; - rebuild_dat << SSB_yr(styr - 2) << " " << SSB_yr(styr, k) << " #spbio; first value is SSB_virgin (virgin)" << endl; + rebuild_dat << SSB_yr(styr - 2) << " " << SSB_yr(styr, k) << " #SSBio; first value is SSB_virgin (virgin)" << endl; rebuild_dat << 1 << " "; for (y = styr; y <= k; y++) rebuild_dat << 0 << " "; diff --git a/SS_write_report.tpl b/SS_write_report.tpl index a6accdd4..82794514 100644 --- a/SS_write_report.tpl +++ b/SS_write_report.tpl @@ -1516,8 +1516,8 @@ FUNCTION void write_bigoutput() if (s == spawn_seas) { temp = sum(SSB_pop_gp(y, p)); - if (Hermaphro_maleSPB > 0) - temp += Hermaphro_maleSPB * sum(MaleSPB(y, p)); + if (Hermaphro_maleSSB > 0) + temp += Hermaphro_maleSSB * sum(MaleSSB(y, p)); SS2out << temp; } else @@ -1529,7 +1529,7 @@ FUNCTION void write_bigoutput() { SS2out << SSB_pop_gp(y, p); if (Hermaphro_Option != 0) - SS2out << MaleSPB(y, p); + SS2out << MaleSSB(y, p); } else { @@ -1710,7 +1710,7 @@ FUNCTION void write_bigoutput() if (k < 4) k = 4; // quantities to store summary statistics - dvector rmse(1, k); // used in the SpBio, Index, Lencomp and Agecomp reports + dvector rmse(1, k); // used in the SSBio, Index, Lencomp and Agecomp reports dvector Hrmse(1, k); dvector Rrmse(1, k); dvector n_rmse(1, k); @@ -4733,33 +4733,11 @@ FUNCTION void SPR_profile() for (s = 1; s <= nseas; s++) { t = styr - 3 * nseas + s - 1; - - if (MG_active(2) > 0 || MG_active(3) > 0 || save_for_report > 0 || WTage_rd > 0) - { - subseas = 1; - ALK_idx = (s - 1) * N_subseas + subseas; // for midseason - Make_AgeLength_Key(s, subseas); // for begin season - subseas = mid_subseas; - ALK_idx = (s - 1) * N_subseas + subseas; // for midseason - Make_AgeLength_Key(s, subseas); // for midseason - if (s == spawn_seas) - { - subseas = spawn_subseas; - if (spawn_subseas != 1 && spawn_subseas != mid_subseas) - { - //don't call get_growth3(subseas) because using an average ave_size - Make_AgeLength_Key(s, subseas); // spawn subseas - } - get_mat_fec(); - } - } - - for (g = 1; g <= gmorph; g++) - if (use_morph(g) > 0) - { - ALK_idx = (s - 1) * N_subseas + mid_subseas; // for midseason - Make_FishSelex(); - } + Wt_Age_beg(s) = Wt_Age_t(t, 0); // used for smrybio + Wt_Age_mid(s) = Wt_Age_t(t, -1); + if (s == spawn_seas) + fec = Wt_Age_t(t, -2); + report5 << 0 << " y: " << y << " updated_Repro_output spr/ypr: " << fec(1) << endl; } SS2out << "SPRloop Iter Bycatch Fmult F_std SPR YPR_dead YPR_dead*Recr YPR_ret*Recr Revenue Cost Profit SSB Recruits SSB/Bzero Tot_Catch "; @@ -5013,7 +4991,7 @@ FUNCTION void Global_MSY() // GLOBAL_MSY with knife-edge age selection, then slot-age selection SS2out << endl << pick_report_name(55) << endl; - y = styr - 3; // stores the averaged + y = styr - 3; // stores the averaged biology and selectivity, etc. from benchmark yz = y; bio_yr = y; eq_yr = y; @@ -5092,7 +5070,9 @@ FUNCTION void Global_MSY() SS2out << "Actual "; show_MSY = 2; // invokes just brief output in benchmark did_MSY = 0; + report5 << 0 << " y: " << y << " updated_Repro_output global_1: " << fec(1) << endl; Get_Benchmarks(show_MSY); + report5 << 0 << " y: " << y << " updated_Repro_output global_2: " << fec(1) << endl; did_MSY = 0; } } diff --git a/SS_write_ssnew.tpl b/SS_write_ssnew.tpl index fdd984be..85aaccb6 100644 --- a/SS_write_ssnew.tpl +++ b/SS_write_ssnew.tpl @@ -4,9 +4,9 @@ // SS_Label_file # //******************************************************************** - /* SS_Label_FUNCTION 38 write_nudata */ +/* SS_Label_FUNCTION 38 write_nudata */ FUNCTION void write_nudata() - { +{ // code for multinomial distribution developed by Ian Stewart, Oct 2005 dvector temp_mult(1, 50000); @@ -23,24 +23,20 @@ FUNCTION void write_nudata() irand_seed = long(time(&start)); random_number_generator radm(irand_seed); - for (i = 1; i <= 1234; i++) - { + for (i = 1; i <= 1234; i++) { temp = randn(radm); } - for (Nudat = 1; Nudat <= N_nudata; Nudat++) - { - if (Nudat == 1) - { + for (Nudat = 1; Nudat <= N_nudata; Nudat++) { + if (Nudat == 1) { echoinput << "Begin writing data_echo.ss_new file" << endl; newdatfilename = "data_echo.ss_new"; - datinfostring = "echo_input_data"; + datinfostring = "echo_input_data"; } - else if (Nudat == 2) - { + else if (Nudat == 2) { echoinput << "Begin writing data_expval.ss file" << endl; newdatfilename = "data_expval.ss"; - datinfostring = "expected_values"; + datinfostring = "expected_values"; } else // data_boot files { @@ -48,19 +44,17 @@ FUNCTION void write_nudata() Nubootdat = Nudat - 2; anystring2 = " "; sprintf(anystring2, "%d", Nubootdat); - if (Nubootdat < 10) - { + if (Nubootdat < 10) { newdatfilename = "data_boot_00" + anystring2 + ".ss"; } - else if (Nubootdat < 100) - { + else if (Nubootdat < 100) { newdatfilename = "data_boot_0" + anystring2 + ".ss"; } else // Nubootdat > 99 { newdatfilename = "data_boot_" + anystring2 + ".ss"; } - datinfostring = "bootstrap"; + datinfostring = "bootstrap"; } anystring = ssnew_pathname + newdatfilename; report1.open(anystring); @@ -69,8 +63,8 @@ FUNCTION void write_nudata() << "#_Start_time: " << ctime(&start); report1 << "#_" << datinfostring << endl; report1 << Data_Comments << endl; - if (Nudat > 2) - report1 << "#_bootstrap file: " << Nubootdat << " irand_seed: " << irand_seed << " first rand#: " << randn(radm) << endl; + if (Nudat > 2) + report1 << "#_bootstrap file: " << Nubootdat << " irand_seed: " << irand_seed << " first rand#: " << randn(radm) << endl; report1 << version_info(1) << version_info(2) << version_info(3) << endl; report1 << styr << " #_StartYr" << endl; @@ -90,8 +84,7 @@ FUNCTION void write_nudata() report1 << "#_catch_mult: 0=no; 1=yes" << endl; report1 << "#_rows are fleets" << endl << "#_fleet_type fishery_timing area catch_units need_catch_mult fleetname" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { report1 << fleet_setup(f) << " " << fleetname(f) << " # " << f << endl; } report1 << "#Bycatch_fleet_input_goes_next" << endl; @@ -102,8 +95,7 @@ FUNCTION void write_nudata() report1 << "#e: last year of range" << endl; report1 << "#f: not used" << endl; report1 << "# a b c d e f " << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (fleet_type(f) == 2) report1 << bycatch_setup(f) << " # " << fleetname(f) << endl; } @@ -115,22 +107,16 @@ FUNCTION void write_nudata() report1 << "#_catch_se: standard error of log(catch)" << endl; report1 << "#_NOTE: catch data is ignored for survey fleets" << endl; k = 0; - for (f = 1; f <= Nfleet; f++) - { - if (fleet_type(f) <= 2) - { - for (y = styr - 1; y <= endyr; y++) - { - for (s = 1; s <= nseas; s++) - { + for (f = 1; f <= Nfleet; f++) { + if (fleet_type(f) <= 2) { + for (y = styr - 1; y <= endyr; y++) { + for (s = 1; s <= nseas; s++) { k++; t = styr + (y - styr) * nseas + s - 1; - if (y == styr - 1) - { + if (y == styr - 1) { g = -999; } - else - { + else { g = y; } report1 << g << " " << s << " " << f << " " << catch_ret_obs(f, t) << " " << catch_se(t, f) << endl; @@ -146,7 +132,7 @@ FUNCTION void write_nudata() report1 << "#_errtype: -1=normal; 0=lognormal; 1=lognormal with bias correction; >1=df for T-dist" << endl; report1 << "#_SD_report: 0=not; 1=include survey expected value with se" << endl; report1 << "#_note that link functions are specified in Q_setup section of control file" << endl; - report1 << "#_dataunits = 36 and 35 should use Q_type 5 to provide offset parameter" < 0) for (f = 1; f <= Nfleet; f++) - for (i = 1; i <= Svy_N_fleet(f); i++) - { + for (i = 1; i <= Svy_N_fleet(f); i++) { t = Svy_time_t(f, i); ALK_time = Svy_ALK_time(f, i); report1 << Show_Time(t, 1) << " " << Svy_super(f, i) * data_time(ALK_time, f, 1) << " " << f * Svy_use(f, i) << " "; @@ -170,22 +155,19 @@ FUNCTION void write_nudata() report1 << "# note: only enter units and errtype for fleets with discard " << endl; report1 << "# note: discard data is the total for an entire season, so input of month here must be to a month in that season" << endl; report1 << "#_fleet units errtype" << endl; - if (Ndisc_fleets > 0) - { + if (Ndisc_fleets > 0) { for (f = 1; f <= Nfleet; f++) if (disc_units(f) > 0) report1 << f << " " << disc_units(f) << " " << disc_errtype(f) << " # " << fleetname(f) << endl; report1 << "#_year month fleet obs stderr" << endl; for (f = 1; f <= Nfleet; f++) - for (i = 1; i <= disc_N_fleet(f); i++) - { + for (i = 1; i <= disc_N_fleet(f); i++) { ALK_time = disc_time_ALK(f, i); report1 << Show_Time(disc_time_t(f, i), 1) << " " << yr_disc_super(f, i) * data_time(ALK_time, f, 1) << " " << f * yr_disc_use(f, i) << " "; report1 << obs_disc(f, i) << " " << cv_disc(f, i) << " #_ " << fleetname(f) << endl; } } - else - { + else { report1 << "# "; } report1 << "-9999 0 0 0.0 0.0 # terminator for discard data " << endl; @@ -197,10 +179,8 @@ FUNCTION void write_nudata() report1 << DF_bodywt << " #_DF_for_meanbodysize_T-distribution_like" << endl; report1 << "# note: type=1 for mean length; type=2 for mean body weight " << endl; report1 << "#_year month fleet part type obs stderr" << endl; - if (nobs_mnwt > 0) - { - for (i = 1; i <= nobs_mnwt; i++) - { + if (nobs_mnwt > 0) { + for (i = 1; i <= nobs_mnwt; i++) { f = abs(mnwtdata(3, i)); report1 << Show_Time(mnwtdata(1, i), 1) << " " << mnwtdata(2, i) << " " << mnwtdata(3, i) << " " << mnwtdata(4, i) << " " << mnwtdata(5, i) << " " << mnwtdata(6, i) << " " << mnwtdata(7, i) - var_adjust(3, f) << " #_ " << fleetname(f) << endl; } @@ -212,27 +192,23 @@ FUNCTION void write_nudata() report1 << "#" << endl << "# set up population length bin structure (note - irrelevant if not using size data and using empirical wtatage" << endl; report1 << LenBin_option << " # length bin method: 1=use databins; 2=generate from binwidth,min,max below; 3=read vector" << endl; - if (LenBin_option == 1) - { + if (LenBin_option == 1) { report1 << "# no additional input for option 1" << endl; report1 << "# read binwidth, minsize, lastbin size for option 2" << endl; report1 << "# read N poplen bins, then vector of bin lower boundaries, for option 3" << endl; } - else if (LenBin_option == 2) - { + else if (LenBin_option == 2) { report1 << binwidth2 << " # binwidth for population size comp " << endl; report1 << minLread << " # minimum size in the population (lower edge of first bin and size at age 0.00) " << endl; report1 << maxLread << " # maximum size in the population (lower edge of last bin) " << endl; } - else - { + else { report1 << nlength << " # number of population size bins " << endl; report1 << len_bins << endl; } report1 << use_length_data << " # use length composition data (0/1/2) where 2 invokes new comp_control format" << endl; - if (use_length_data > 0) - { + if (use_length_data > 0) { report1 << "#_mintailcomp: upper and lower distribution for females and males separately are accumulated until exceeding this level." << endl; report1 << "#_addtocomp: after accumulation of tails; this value added to all bins" << endl; report1 << "#_combM+F: males and females treated as combined sex below this bin number " << endl; @@ -241,17 +217,14 @@ FUNCTION void write_nudata() report1 << "#_ParmSelect: consecutive index for dirichlet or MV_Tweedie" << endl; report1 << "#_minsamplesize: minimum sample size; set to 1 to match 3.24, minimum value is 0.001" << endl; report1 << "#" << endl; - if(use_length_data == 1) - { + if (use_length_data == 1) { report1 << "#_Using old format for composition controls" << endl; - report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; - for (f = 1; f <= Nfleet; f++) - { - report1 << min_tail_L(0, f) << " " << min_comp_L(0, f) << " " << CombGender_L(0, f) << " " << AccumBin_L(0, f) << " " << Comp_Err_L(0, f) << " " << Comp_Err_L2(0, f) << " " << min_sample_size_L(0, f) << " #_fleet:" << f << "_" << fleetname(f) << endl; - } + report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; + for (f = 1; f <= Nfleet; f++) { + report1 << min_tail_L(0, f) << " " << min_comp_L(0, f) << " " << CombGender_L(0, f) << " " << AccumBin_L(0, f) << " " << Comp_Err_L(0, f) << " " << Comp_Err_L2(0, f) << " " << min_sample_size_L(0, f) << " #_fleet:" << f << "_" << fleetname(f) << endl; + } } - else if (use_length_data == 2) - { + else if (use_length_data == 2) { report1 << "#_Using new list format for composition controls" << endl; report1 << "#_use negative fleet value to fill for all higher numbered fleets (recommended!)" << endl; report1 << "#_must enter in fleet, partition order; but only need to enter for used combos" << endl; @@ -267,10 +240,8 @@ FUNCTION void write_nudata() << len_bins_dat << endl; // report1< 0) - { - for (i = 0; i <= nobsl_rd - 1; i++) - { + if (nobsl_rd > 0) { + for (i = 0; i <= nobsl_rd - 1; i++) { report1 << lendata[i] << endl; } } @@ -279,19 +250,16 @@ FUNCTION void write_nudata() report1 << "0 "; report1 << endl; } - else - { + else { report1 << "# see manual for format of length composition data " << endl; } report1 << "#" << endl << n_abins << " #_N_age_bins" << endl; - if (n_abins > 0) - { + if (n_abins > 0) { report1 << age_bins1 << endl; } - else - { + else { report1 << "# "; } report1 << N_ageerr << " #_N_ageerror_definitions" << endl; @@ -307,8 +275,7 @@ FUNCTION void write_nudata() report1 << "#_minsamplesize: minimum sample size; set to 1 to match 3.24, minimum value is 0.001" << endl; report1 << "#" << endl; report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (n_abins <= 0) report1 << "# "; report1 << min_tail_A(f) << " " << min_comp_A(f) << " " << CombGender_A(f) << " " << AccumBin_A(f) << " " << Comp_Err_A(f) << " " << Comp_Err_A2(f) << " " << min_sample_size_A(f) << " #_fleet:" << f << "_" << fleetname(f) << endl; @@ -320,10 +287,8 @@ FUNCTION void write_nudata() report1 << "# sex codes: 0=combined; 1=use female only; 2=use male only; 3=use both as joint sex*length distribution" << endl; report1 << "# partition codes: (0=combined; 1=discard; 2=retained" << endl; report1 << "#_year month fleet sex part ageerr Lbin_lo Lbin_hi Nsamp datavector(female-male)" << endl; - if (nobsa_rd > 0) - { - for (i = 0; i <= nobsa_rd - 1; i++) - { + if (nobsa_rd > 0) { + for (i = 0; i <= nobsa_rd - 1; i++) { report1 << Age_Data[i] << endl; } } @@ -337,26 +302,20 @@ FUNCTION void write_nudata() report1 << "#" << endl << use_meansizedata << " #_Use_MeanSize-at-Age_obs (0/1)" << endl; - if (use_meansizedata > 0) - { + if (use_meansizedata > 0) { report1 << "# sex codes: 0=combined; 1=use female only; 2=use male only; 3=use both as joint sex*length distribution" << endl; report1 << "# partition codes: 0=combined; 1=discard; 2=retained" << endl; report1 << "# ageerr codes: positive means mean length-at-age; negative means mean bodywt_at_age" << endl; report1 << "#_year month fleet sex part ageerr ignore datavector(female-male)" << endl; report1 << "# samplesize(female-male)" << endl; - if (nobs_ms_rd > 0) - { - if (finish_starter == 999) - { - for (i = 1; i <= nobs_ms_rd; i++) - { + if (nobs_ms_rd > 0) { + if (finish_starter == 999) { + for (i = 1; i <= nobs_ms_rd; i++) { report1 << sizeAge_Data[i] << endl; } } - else - { - for (i = 0; i <= nobs_ms_rd - 1; i++) - { + else { + for (i = 0; i <= nobs_ms_rd - 1; i++) { report1 << sizeAge_Data[i] << endl; } } @@ -371,24 +330,24 @@ FUNCTION void write_nudata() << N_envvar << " #_N_environ_variables" << endl; report1 << "# -2 in year will subtract mean for that env_var; -1 will subtract mean and divide by stddev (e.g. Z-score)" << endl; report1 << "#_year variable value" << endl; - if (N_envvar > 0) - { + if (N_envvar > 0) { for (i = 0; i <= N_envdata - 1; i++) report1 << env_temp[i] << endl; report1 << "-9999 0 0" << endl; } - report1 << "#" << endl << "# Sizefreq data. Defined by method because a fleet can use multiple methods" << endl; + report1 << "#" << endl + << "# Sizefreq data. Defined by method because a fleet can use multiple methods" << endl; report1 << SzFreq_Nmeth_rd << " # N sizefreq methods to read (or -1 for expanded options)" << endl; if (SzFreq_Nmeth_rd < 0) { report1 << SzFreq_Nmeth << " # N sizefreq methods to read" << endl; } - if (SzFreq_Nmeth != 0) - { + if (SzFreq_Nmeth != 0) { report1 << "# each row below has entry for each sizefreq method " << endl; report1 << "#_ "; - for (int j = 1; j <= SzFreq_Nmeth; j++ ) - { report1 << j << " ";} + for (int j = 1; j <= SzFreq_Nmeth; j++) { + report1 << j << " "; + } report1 << " # Method" << endl; report1 << SzFreq_Nbins << " #_Sizefreq N bins" << endl; report1 << SzFreq_units << " #_Sizefreq units(1=bio/2=num)" << endl; @@ -396,32 +355,31 @@ FUNCTION void write_nudata() report1 << SzFreq_mincomp << " #_Sizefreq: small constant to add to comps" << endl; report1 << SzFreq_nobs << " #_Sizefreq number of obs per method" << endl; if (SzFreq_Nmeth_rd < 0) { - report1 << Comp_Err_Sz << " #_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; + report1 << Comp_Err_Sz << " #_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; report1 << Comp_Err_Sz2 << " #_ParmSelect: consecutive index for dirichlet or MV_Tweedie comp_error" << endl; } report1 << "#_Sizefreq bins. one row for each method" << endl << "#Note: negative value for first bin makes it accumulate all smaller fish vs. truncate small fish" << endl; - for (i = 1; i <= SzFreq_Nmeth; i++) - { report1 << SzFreq_Omit_Small(i) * SzFreq_bins1(i, 1) << SzFreq_bins1(i)(2, SzFreq_Nbins(i)) << endl; } - report1 << "#_method year month fleet sex part Nsamp " << endl << SzFreq_obs1 << endl; + for (i = 1; i <= SzFreq_Nmeth; i++) { + report1 << SzFreq_Omit_Small(i) * SzFreq_bins1(i, 1) << SzFreq_bins1(i)(2, SzFreq_Nbins(i)) << endl; + } + report1 << "#_method year month fleet sex part Nsamp " << endl + << SzFreq_obs1 << endl; } // begin tagging data section #1 (observed data) report1 << "# " << endl << Do_TG_rd << " # do tags (0/1/2); where 2 allows entry of TG_min_recap" << endl; - if (Do_TG_rd > 0) - { + if (Do_TG_rd > 0) { // info on dimensions of tagging data report1 << N_TG << " # N tag groups" << endl; report1 << N_TG_recap << " # N recap events" << endl; report1 << TG_mixperiod << " # TG_mixperiod ## (latency) is the first period in which logL is calculated for this tag group (0 = release period)" << endl; report1 << TG_maxperiods << " # max periods ## to track recaptures (units=seasons), after which tags are still read into this accumulator period" << endl; - if (Do_TG_rd == 2) - { + if (Do_TG_rd == 2) { report1 << TG_min_recap << " # TG_min_recap ## tag group's N recaps >=mixperiod must be >= min_recap to include tag group in logL)" << endl; } - else - { + else { report1 << "# COND: TG_min_recap ## use Do_TG=2 to invoke reading TG_min_recap after TG_maxperiods" << endl; } @@ -432,8 +390,7 @@ FUNCTION void write_nudata() // tag recaptures report1 << "#_TG year seas fleet Nrecap" << endl; - for (j = 1; j <= N_TG_recap; j++) - { + for (j = 1; j <= N_TG_recap; j++) { // fill in first 4 columns: for (k = 1; k <= 5; k++) report1 << TG_recap_data(j, k) << " "; @@ -444,19 +401,16 @@ FUNCTION void write_nudata() report1 << "#" << endl << Do_Morphcomp << " # morphcomp data(0/1) " << endl; - if (Do_Morphcomp > 0) - { + if (Do_Morphcomp > 0) { report1 << Morphcomp_nobs_rd << " # Nobs" << endl; report1 << Morphcomp_nmorph << " # Nmorphs" << endl; report1 << Morphcomp_mincomp << " # add_to_comp" << endl; report1 << "#_year, month, fleet, null, Nsamp, datavector_by_Nmorphs" << endl; - for (i = 1; i <= Morphcomp_nobs_rd; i++) - { + for (i = 1; i <= Morphcomp_nobs_rd; i++) { report1 << Morphcomp_obs_rd << endl; } } - else - { + else { report1 << "# Nobs, Nmorphs, mincomp" << endl; report1 << "#_year, seas, type, partition, Nsamp, datavector_by_Nmorphs" << endl; } @@ -478,33 +432,28 @@ FUNCTION void write_nudata() report1 << "#_catch_se: standard error of log(catch)" << endl; report1 << "#_NOTE: catch data is ignored for survey fleets" << endl; k = 0; - for (f = 1; f <= Nfleet; f++) - { - if (fleet_type(f) <= 2) - { - for (y = styr - 1; y <= endyr; y++) - { - for (s = 1; s <= nseas; s++) - { + for (f = 1; f <= Nfleet; f++) { + if (fleet_type(f) <= 2) { + for (y = styr - 1; y <= endyr; y++) { + for (s = 1; s <= nseas; s++) { k++; t = styr + (y - styr) * nseas + s - 1; - if (y == styr - 1) - { report1 << -999 << " "; } - else - { report1 << y << " "; } + if (y == styr - 1) { + report1 << -999 << " "; + } + else { + report1 << y << " "; + } report1 << s << " " << f << " "; - if (fleet_type(f) == 2 && catch_ret_obs(f, t) > 0.0) - { - report1 << 0.1 << " " << catch_se(t, f) << endl; // for bycatch only fleet - } - else if (catchunits(f) == 1) - { - report1 << catch_fleet(t, f, 3) << " " << catch_se(t, f) << endl; - } - else - { - report1 << catch_fleet(t, f, 6) << " " << catch_se(t, f) << endl; - } + if (fleet_type(f) == 2 && catch_ret_obs(f, t) > 0.0) { + report1 << 0.1 << " " << catch_se(t, f) << endl; // for bycatch only fleet + } + else if (catchunits(f) == 1) { + report1 << catch_fleet(t, f, 3) << " " << catch_se(t, f) << endl; + } + else { + report1 << catch_fleet(t, f, 6) << " " << catch_se(t, f) << endl; + } } } } @@ -517,15 +466,14 @@ FUNCTION void write_nudata() report1 << "#_errtype: -1=normal; 0=lognormal; 1=lognormal with bias correction; >1=df for T-dist" << endl; report1 << "#_SD_report: 0=not; 1=include survey expected value with se" << endl; report1 << "#_note that link functions are specified in Q_setup section of control file" << endl; - report1 << "#_dataunits = 36 and 35 should use Q_type 5 to provide offset parameter" < 0) for (f = 1; f <= Nfleet; f++) - for (i = 1; i <= Svy_N_fleet(f); i++) - { + for (i = 1; i <= Svy_N_fleet(f); i++) { t = Svy_time_t(f, i); ALK_time = Svy_ALK_time(f, i); report1 << Show_Time(t, 1) << " " << Svy_super(f, i) * data_time(ALK_time, f, 1) << " " << f * Svy_use(f, i) << " "; @@ -533,14 +481,13 @@ FUNCTION void write_nudata() { report1 << Svy_est(f, i); } - else if (Svy_errtype(f) == -2) // gamma + else if (Svy_errtype(f) == -2) // gamma { // need gamma here } - else - { - report1 << mfexp(Svy_est(f, i)); // lognormal or T-dist or lognormal w/bias - } + else { + report1 << mfexp(Svy_est(f, i)); // lognormal or T-dist or lognormal w/bias + } report1 << " " << Svy_se_rd(f, i) << " #_orig_obs: " << Svy_obs(f, i) << " " << fleetname(f) << endl; } report1 << "-9999 1 1 1 1 # terminator for survey observations " << endl; @@ -552,16 +499,14 @@ FUNCTION void write_nudata() report1 << "# note: only enter units and errtype for fleets with discard " << endl; report1 << "# note: discard data is the total for an entire season, so input of month here must be to a month in that season" << endl; report1 << "#_fleet units errtype" << endl; - if (Ndisc_fleets > 0) - { + if (Ndisc_fleets > 0) { for (f = 1; f <= Nfleet; f++) if (disc_units(f) > 0) report1 << f << " " << disc_units(f) << " " << disc_errtype(f) << " # " << fleetname(f) << endl; report1 << "#_year month fleet obs stderr" << endl; for (f = 1; f <= Nfleet; f++) if (disc_N_fleet(f) > 0) - for (i = 1; i <= disc_N_fleet(f); i++) - { + for (i = 1; i <= disc_N_fleet(f); i++) { ALK_time = disc_time_ALK(f, i); report1 << Show_Time(disc_time_t(f, i), 1) << " " << yr_disc_super(f, i) * data_time(ALK_time, f, 1) << " " << f * yr_disc_use(f, i) << " "; { @@ -570,8 +515,7 @@ FUNCTION void write_nudata() report1 << " " << cv_disc(f, i) << " #_orig_obs: " << obs_disc(f, i) << " #_ " << fleetname(f) << endl; } } - else - { + else { report1 << "# "; } report1 << "-9999 0 0 0.0 0.0 # terminator for discard data " << endl; @@ -584,10 +528,8 @@ FUNCTION void write_nudata() report1 << DF_bodywt << " #_DF_for_meanbodysize_T-distribution_like" << endl; report1 << "# note: type=1 for mean length; type=2 for mean body weight " << endl; report1 << "#_year month fleet part type obs stderr" << endl; - if (nobs_mnwt > 0) - { - for (i = 1; i <= nobs_mnwt; i++) - { + if (nobs_mnwt > 0) { + for (i = 1; i <= nobs_mnwt; i++) { f = abs(mnwtdata(3, i)); report1 << Show_Time(mnwtdata(1, i), 1) << " " << mnwtdata(2, i) << " " << mnwtdata(3, i) << " " << mnwtdata(4, i) << " " << mnwtdata(5, i) << " " << exp_mnwt(i) << " " << mnwtdata(7, i) - var_adjust(3, f) << " #_orig_obs: " << mnwtdata(6, i) << " #_ " << fleetname(f) << endl; } @@ -599,27 +541,23 @@ FUNCTION void write_nudata() report1 << "#" << endl << "# set up population length bin structure (note - irrelevant if not using size data and using empirical wtatage" << endl; report1 << LenBin_option << " # length bin method: 1=use databins; 2=generate from binwidth,min,max below; 3=read vector" << endl; - if (LenBin_option == 1) - { + if (LenBin_option == 1) { report1 << "# no additional input for option 1" << endl; report1 << "# read binwidth, minsize, lastbin size for option 2" << endl; report1 << "# read N poplen bins, then vector of bin lower boundaries, for option 3" << endl; } - else if (LenBin_option == 2) - { + else if (LenBin_option == 2) { report1 << binwidth2 << " # binwidth for population size comp " << endl; report1 << minLread << " # minimum size in the population (lower edge of first bin and size at age 0.00) " << endl; report1 << maxLread << " # maximum size in the population (lower edge of last bin) " << endl; } - else - { + else { report1 << nlength << " # number of population size bins " << endl; report1 << len_bins << endl; } report1 << use_length_data << " # use length composition data (0/1/2) where 2 invokes new comp_comtrol format" << endl; - if (use_length_data > 0) - { + if (use_length_data > 0) { report1 << "#_mintailcomp: upper and lower distribution for females and males separately are accumulated until exceeding this level." << endl; report1 << "#_addtocomp: after accumulation of tails; this value added to all bins" << endl; report1 << "#_combM+F: males and females treated as combined sex below this bin number " << endl; @@ -628,17 +566,14 @@ FUNCTION void write_nudata() report1 << "#_ParmSelect: consecutive index for dirichlet or MV_Tweedie" << endl; report1 << "#_minsamplesize: minimum sample size; set to 1 to match 3.24, minimum value is 0.001" << endl; report1 << "#" << endl; - if(use_length_data == 1) - { + if (use_length_data == 1) { report1 << "#_Using old format for composition controls" << endl; - report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; - for (f = 1; f <= Nfleet; f++) - { - report1 << min_tail_L(0, f) << " " << min_comp_L(0, f) << " " << CombGender_L(0, f) << " " << AccumBin_L(0, f) << " " << Comp_Err_L(0, f) << " " << Comp_Err_L2(0, f) << " " << min_sample_size_L(0, f) << " #_fleet:" << f << "_" << fleetname(f) << endl; - } + report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; + for (f = 1; f <= Nfleet; f++) { + report1 << min_tail_L(0, f) << " " << min_comp_L(0, f) << " " << CombGender_L(0, f) << " " << AccumBin_L(0, f) << " " << Comp_Err_L(0, f) << " " << Comp_Err_L2(0, f) << " " << min_sample_size_L(0, f) << " #_fleet:" << f << "_" << fleetname(f) << endl; + } } - else if (use_length_data == 2) - { + else if (use_length_data == 2) { report1 << "#_Using new list format for composition controls" << endl; report1 << "#_use negative fleet value to fill for all higher numbered fleets (recommended!)" << endl; report1 << "#_must enter in fleet, partition order; but only need to enter for used combos" << endl; @@ -654,12 +589,9 @@ FUNCTION void write_nudata() << len_bins_dat << endl; // report1< 0) - { - for (i = 1; i <= Nobs_l(f); i++) - { + for (f = 1; f <= Nfleet; f++) { + if (Nobs_l(f) > 0) { + for (i = 1; i <= Nobs_l(f); i++) { k = 1000; if (nsamp_l(f, i) < k) k = nsamp_l(f, i); @@ -673,19 +605,16 @@ FUNCTION void write_nudata() report1 << "0 "; report1 << endl; } - else - { + else { report1 << "# see manual for format of length composition data " << endl; } report1 << "#" << endl << n_abins << " #_N_age_bins" << endl; - if (n_abins > 0) - { + if (n_abins > 0) { report1 << age_bins1 << endl; } - else - { + else { report1 << "# "; } report1 << N_ageerr << " #_N_ageerror_definitions" << endl; @@ -701,8 +630,7 @@ FUNCTION void write_nudata() report1 << "#_minsamplesize: minimum sample size; set to 1 to match 3.24, minimum value is 0.001" << endl; report1 << "#" << endl; report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (n_abins <= 0) report1 << "# "; report1 << min_tail_A(f) << " " << min_comp_A(f) << " " << CombGender_A(f) << " " << AccumBin_A(f) << " " << Comp_Err_A(f) << " " << Comp_Err_A2(f) << " " << min_sample_size_A(f) << " #_fleet:" << f << "_" << fleetname(f) << endl; @@ -715,12 +643,9 @@ FUNCTION void write_nudata() report1 << "# partition codes: (0=combined; 1=discard; 2=retained" << endl; report1 << "#_year month fleet sex part ageerr Lbin_lo Lbin_hi Nsamp datavector(female-male)" << endl; if (Nobs_a_tot > 0) - for (f = 1; f <= Nfleet; f++) - { - if (Nobs_a(f) >= 1) - { - for (i = 1; i <= Nobs_a(f); i++) - { + for (f = 1; f <= Nfleet; f++) { + if (Nobs_a(f) >= 1) { + for (i = 1; i <= Nobs_a(f); i++) { k = 1000; if (nsamp_a(f, i) < k) k = nsamp_a(f, i); // note that nsamp is adjusted by var_adjust, so var_adjust @@ -740,26 +665,20 @@ FUNCTION void write_nudata() report1 << "#" << endl << use_meansizedata << " #_Use_MeanSize-at-Age_obs (0/1)" << endl; - if (use_meansizedata > 0) - { + if (use_meansizedata > 0) { report1 << "# sex codes: 0=combined; 1=use female only; 2=use male only; 3=use both as joint sex*length distribution" << endl; report1 << "# partition codes: 0=combined; 1=discard; 2=retained" << endl; report1 << "# ageerr codes: positive means mean length-at-age; negative means mean bodywt_at_age" << endl; report1 << "#_year month fleet sex part ageerr ignore datavector(female-male)" << endl; report1 << "# samplesize(female-male)" << endl; - for (f = 1; f <= Nfleet; f++) - { - if (Nobs_ms(f) > 0) - { - for (i = 1; i <= Nobs_ms(f); i++) - { + for (f = 1; f <= Nfleet; f++) { + if (Nobs_ms(f) > 0) { + for (i = 1; i <= Nobs_ms(f); i++) { report1 << header_ms(f, i)(1) << " " << header_ms_rd(f, i)(2, 3) << " " << header_ms(f, i)(4, 7); - for (a = 1; a <= n_abins2; a++) - { + for (a = 1; a <= n_abins2; a++) { report1 << " "; temp = exp_ms(f, i, a); - if (temp <= 0.) - { + if (temp <= 0.) { temp = 0.0001; } report1 << temp; @@ -782,24 +701,24 @@ FUNCTION void write_nudata() << N_envvar << " #_N_environ_variables" << endl; report1 << "# -2 in year will subtract mean for that env_var; -1 will subtract mean and divide by stddev (e.g. Z-score)" << endl; report1 << "#_year variable value" << endl; - if (N_envvar > 0) - { + if (N_envvar > 0) { for (i = 0; i <= N_envdata - 1; i++) report1 << env_temp[i] << endl; report1 << "-9999 0 0" << endl; } - report1 << "#" << endl << "# Sizefreq data. Defined by method because a fleet can use multiple methods" << endl; + report1 << "#" << endl + << "# Sizefreq data. Defined by method because a fleet can use multiple methods" << endl; report1 << SzFreq_Nmeth_rd << " # N sizefreq methods to read (or -1 for expanded options)" << endl; if (SzFreq_Nmeth_rd < 0) { report1 << SzFreq_Nmeth << " # N sizefreq methods to read" << endl; } - if (SzFreq_Nmeth != 0) - { + if (SzFreq_Nmeth != 0) { report1 << "# each row below has entry for each sizefreq method " << endl; report1 << "#_ "; - for (int j = 1; j <= SzFreq_Nmeth; j++ ) - { report1 << j << " ";} + for (int j = 1; j <= SzFreq_Nmeth; j++) { + report1 << j << " "; + } report1 << " # Method" << endl; report1 << SzFreq_Nbins << " #_Sizefreq N bins" << endl; report1 << SzFreq_units << " #_Sizefreq units(1=bio/2=num)" << endl; @@ -807,13 +726,14 @@ FUNCTION void write_nudata() report1 << SzFreq_mincomp << " #_Sizefreq: small constant to add to comps" << endl; report1 << SzFreq_nobs << " #_Sizefreq number of obs per method" << endl; if (SzFreq_Nmeth_rd < 0) { - report1 << Comp_Err_Sz << " #_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; + report1 << Comp_Err_Sz << " #_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; report1 << Comp_Err_Sz2 << " #_ParmSelect: consecutive index for dirichlet or MV_Tweedie comp_error" << endl; } report1 << "#_Sizefreq bins. one row for each method" << endl << "#Note: negative value for first bin makes it accumulate all smaller fish vs. truncate small fish" << endl; - for (i = 1; i <= SzFreq_Nmeth; i++) - { report1 << SzFreq_Omit_Small(i) * SzFreq_bins1(i, 1) << SzFreq_bins1(i)(2, SzFreq_Nbins(i)) << endl; } + for (i = 1; i <= SzFreq_Nmeth; i++) { + report1 << SzFreq_Omit_Small(i) * SzFreq_bins1(i, 1) << SzFreq_bins1(i)(2, SzFreq_Nbins(i)) << endl; + } report1 << "#_method year month fleet sex part Nsamp " << endl; for (iobs = 1; iobs <= SzFreq_totobs; iobs++) { report1 << SzFreq_obs1(iobs)(1, 7) << " " << SzFreq_exp(iobs) << endl; @@ -823,8 +743,7 @@ FUNCTION void write_nudata() // begin tagging data section #2 (expected values) report1 << "#" << endl << Do_TG << " # do tags (0/1)" << endl; - if (Do_TG > 0) - { + if (Do_TG > 0) { // info on dimensions of tagging data report1 << N_TG << " # N tag groups" << endl; report1 << N_TG_recap << " # N recap events" << endl; @@ -840,8 +759,7 @@ FUNCTION void write_nudata() report1 << "#_Note: Expected values for tag recaptures are reported only for the same combinations of" << endl; report1 << "# group, year, area, and fleet that had observed recaptures. " << endl; report1 << "#_TG year seas fleet Nrecap" << endl; - for (j = 1; j <= N_TG_recap; j++) - { + for (j = 1; j <= N_TG_recap; j++) { // fill in first 4 columns: for (k = 1; k <= 4; k++) report1 << TG_recap_data(j, k) << " "; @@ -858,20 +776,17 @@ FUNCTION void write_nudata() report1 << "#" << endl << Do_Morphcomp << " # morphcomp data(0/1) " << endl; - if (Do_Morphcomp > 0) - { + if (Do_Morphcomp > 0) { report1 << "# note that raw data, not bootstrap are reported here " << endl; report1 << Morphcomp_nobs << " # Nobs" << endl; report1 << Morphcomp_nmorph << " # Nmorphs" << endl; report1 << Morphcomp_mincomp << " # add_to_comp" << endl; report1 << "#_year, month, fleet, null, Nsamp, datavector_by_Nmorphs" << endl; - for (i = 1; i <= Morphcomp_nobs; i++) - { + for (i = 1; i <= Morphcomp_nobs; i++) { report1 << Morphcomp_obs(i)(1, 5) << " " << Morphcomp_exp(i) << endl; } } - else - { + else { report1 << "# Nobs, Nmorphs, mincomp" << endl; report1 << "#_year, seas, type, partition, Nsamp, datavector_by_Nmorphs" << endl; } @@ -893,32 +808,27 @@ FUNCTION void write_nudata() report1 << "#_catch_se: standard error of log(catch)" << endl; report1 << "#_NOTE: catch data is ignored for survey fleets" << endl; k = 0; - for (f = 1; f <= Nfleet; f++) - { - if (fleet_type(f) <= 2) - { - for (y = styr - 1; y <= endyr; y++) - { - for (s = 1; s <= nseas; s++) - { + for (f = 1; f <= Nfleet; f++) { + if (fleet_type(f) <= 2) { + for (y = styr - 1; y <= endyr; y++) { + for (s = 1; s <= nseas; s++) { k++; t = styr + (y - styr) * nseas + s - 1; - if (y == styr - 1) - { report1 << -999 << " "; } - else - { report1 << y << " "; } + if (y == styr - 1) { + report1 << -999 << " "; + } + else { + report1 << y << " "; + } report1 << s << " " << f << " "; - if (fleet_type(f) == 2 && catch_ret_obs(f, t) > 0.0) - { + if (fleet_type(f) == 2 && catch_ret_obs(f, t) > 0.0) { report1 << 0.1 << " " << catch_se(t, f) << endl; // for bycatch only fleet } - else if (catchunits(f) == 1) - { + else if (catchunits(f) == 1) { report1 << catch_fleet(t, f, 3) * mfexp(randn(radm) * catch_se(t, f) - 0.5 * catch_se(t, f) * catch_se(t, f)) << " " << catch_se(t, f) << endl; } - else - { + else { report1 << catch_fleet(t, f, 6) * mfexp(randn(radm) * catch_se(t, f) - 0.5 * catch_se(t, f) * catch_se(t, f)) << " " << catch_se(t, f) << endl; } @@ -934,15 +844,14 @@ FUNCTION void write_nudata() report1 << "#_errtype: -1=normal; 0=lognormal; 1=lognormal with bias correction; >1=df for T-dist" << endl; report1 << "#_SD_report: 0=not; 1=include survey expected value with se" << endl; report1 << "#_note that link functions are specified in Q_setup section of control file" << endl; - report1 << "#_dataunits = 36 and 35 should use Q_type 5 to provide offset parameter" < 0) for (f = 1; f <= Nfleet; f++) - for (i = 1; i <= Svy_N_fleet(f); i++) - { + for (i = 1; i <= Svy_N_fleet(f); i++) { t = Svy_time_t(f, i); ALK_time = Svy_ALK_time(f, i); double newobs = 0.0; @@ -961,7 +870,7 @@ FUNCTION void write_nudata() temp = sqrt((df + 1.) / df); newobs = value(mfexp(Svy_est(f, i) + randn(radm) * Svy_se_use(f, i) * temp)); // adjusts the sd by the df sample size } - if (Svy_minval(f) >= 0.0 && Svy_errtype(f) != 0) // this logic may need adjustment + if (Svy_minval(f) >= 0.0 && Svy_errtype(f) != 0) // this logic may need adjustment newobs = max(newobs, 0.5 * Svy_minval(f)); report1 << newobs << " " << Svy_se_rd(f, i) << " #_orig_obs: " << Svy_obs(f, i) << " " << fleetname(f) << endl; } @@ -974,41 +883,34 @@ FUNCTION void write_nudata() report1 << "# note: only enter units and errtype for fleets with discard " << endl; report1 << "# note: discard data is the total for an entire season, so input of month here must be to a month in that season" << endl; report1 << "#_Fleet units errtype" << endl; - if (Ndisc_fleets > 0) - { + if (Ndisc_fleets > 0) { for (f = 1; f <= Nfleet; f++) if (disc_units(f) > 0) report1 << f << " " << disc_units(f) << " " << disc_errtype(f) << " # " << fleetname(f) << endl; report1 << "#_year month fleet obs stderr" << endl; for (f = 1; f <= Nfleet; f++) - for (i = 1; i <= disc_N_fleet(f); i++) - { + for (i = 1; i <= disc_N_fleet(f); i++) { ALK_time = disc_time_ALK(f, i); report1 << Show_Time(disc_time_t(f, i), 1) << " " << yr_disc_super(f, i) * data_time(ALK_time, f, 1) << " " << f * yr_disc_use(f, i) << " "; - if (disc_errtype(f) >= 1) - { + if (disc_errtype(f) >= 1) { temp = exp_disc(f, i) + randn(radm) * sd_disc(f, i) * sqrt((disc_errtype(f) + 1.) / disc_errtype(f)) * exp_disc(f, i); if (temp < 0.001) temp = 0.001; } - else if (disc_errtype(f) == 0) - { + else if (disc_errtype(f) == 0) { temp = exp_disc(f, i) + randn(radm) * sd_disc(f, i); if (temp < 0.001) temp = 0.001; } - else if (disc_errtype(f) == -1) - { + else if (disc_errtype(f) == -1) { temp = exp_disc(f, i) + randn(radm) * sd_disc(f, i); if (temp < 0.001) temp = 0.001; } - else if (disc_errtype(f) == -2) - { + else if (disc_errtype(f) == -2) { temp = exp_disc(f, i) * mfexp(randn(radm) * sd_disc(f, i)); } - else if (disc_errtype(f) == -3) - { + else if (disc_errtype(f) == -3) { temp = exp_disc(f, i) + randn(radm) * (sd_disc(f, i) / sqrt(cumd_norm((1 - exp_disc(f, i)) / sd_disc(f, i)) - cumd_norm((0 - exp_disc(f, i)) / sd_disc(f, i)))); if (temp < 0.001) temp = 0.001; @@ -1019,8 +921,7 @@ FUNCTION void write_nudata() report1 << " " << temp << " " << cv_disc(f, i) << " #_orig_obs: " << obs_disc(f, i) << " #_ " << fleetname(f) << endl; } } - else - { + else { report1 << "# "; } report1 << "-9999 0 0 0.0 0.0 # terminator for discard data " << endl; @@ -1035,13 +936,10 @@ FUNCTION void write_nudata() // NOTE, the se stored in mnwtdata(7,i) was adjusted in prelim calc to include the input var_adjustment // so var_adjust is subtracted here when the observation is written - if (nobs_mnwt > 0) - { - for (i = 1; i <= nobs_mnwt; i++) - { + if (nobs_mnwt > 0) { + for (i = 1; i <= nobs_mnwt; i++) { temp = exp_mnwt(i) + randn(radm) * mnwtdata(7, i) * sqrt((DF_bodywt + 1.) / DF_bodywt) * exp_mnwt(i); - if (temp <= 0.0) - { + if (temp <= 0.0) { temp = 0.0001; } f = abs(mnwtdata(3, i)); @@ -1055,27 +953,23 @@ FUNCTION void write_nudata() report1 << "#" << endl << "# set up population length bin structure (note - irrelevant if not using size data and using empirical wtatage" << endl; report1 << LenBin_option << " # length bin method: 1=use databins; 2=generate from binwidth,min,max below; 3=read vector" << endl; - if (LenBin_option == 1) - { + if (LenBin_option == 1) { report1 << "# no additional input for option 1" << endl; report1 << "# read binwidth, minsize, lastbin size for option 2" << endl; report1 << "# read N poplen bins, then vector of bin lower boundaries, for option 3" << endl; } - else if (LenBin_option == 2) - { + else if (LenBin_option == 2) { report1 << binwidth2 << " # binwidth for population size comp " << endl; report1 << minLread << " # minimum size in the population (lower edge of first bin and size at age 0.00) " << endl; report1 << maxLread << " # maximum size in the population (lower edge of last bin) " << endl; } - else - { + else { report1 << nlength << " # number of population size bins " << endl; report1 << len_bins << endl; } report1 << use_length_data << " # use length composition data (0/1/2) where 2 invokes new comp_comtrol format" << endl; - if (use_length_data > 0) - { + if (use_length_data > 0) { report1 << "#_mintailcomp: upper and lower distribution for females and males separately are accumulated until exceeding this level." << endl; report1 << "#_addtocomp: after accumulation of tails; this value added to all bins" << endl; report1 << "#_combM+F: males and females treated as combined sex below this bin number " << endl; @@ -1084,17 +978,14 @@ FUNCTION void write_nudata() report1 << "#_ParmSelect: consecutive index for dirichlet or MV_Tweedie" << endl; report1 << "#_minsamplesize: minimum sample size; set to 1 to match 3.24, minimum value is 0.001" << endl; report1 << "#" << endl; - if(use_length_data == 1) - { + if (use_length_data == 1) { report1 << "#_Using old format for composition controls" << endl; - report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; - for (f = 1; f <= Nfleet; f++) - { - report1 << min_tail_L(0, f) << " " << min_comp_L(0, f) << " " << CombGender_L(0, f) << " " << AccumBin_L(0, f) << " " << Comp_Err_L(0, f) << " " << Comp_Err_L2(0, f) << " " << min_sample_size_L(0, f) << " #_fleet:" << f << "_" << fleetname(f) << endl; - } + report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; + for (f = 1; f <= Nfleet; f++) { + report1 << min_tail_L(0, f) << " " << min_comp_L(0, f) << " " << CombGender_L(0, f) << " " << AccumBin_L(0, f) << " " << Comp_Err_L(0, f) << " " << Comp_Err_L2(0, f) << " " << min_sample_size_L(0, f) << " #_fleet:" << f << "_" << fleetname(f) << endl; + } } - else if (use_length_data == 2) - { + else if (use_length_data == 2) { report1 << "#_Using new list format for composition controls" << endl; report1 << "#_use negative fleet value to fill for all higher numbered fleets (recommended!)" << endl; report1 << "#_must enter in fleet, partition order; but only need to enter for used combos" << endl; @@ -1109,17 +1000,12 @@ FUNCTION void write_nudata() report1 << nlen_bin << " #_N_LengthBins" << endl << len_bins_dat << endl; report1 << "#_year month fleet sex part Nsamp datavector(female-male)" << endl; - for (f = 1; f <= Nfleet; f++) - { - if (Nobs_l(f) > 0) - { - for (i = 1; i <= Nobs_l(f); i++) - { + for (f = 1; f <= Nfleet; f++) { + if (Nobs_l(f) > 0) { + for (i = 1; i <= Nobs_l(f); i++) { int parti = mkt_l(f, i); - switch (Comp_Err_L(parti, f)) - { - case 0: - { + switch (Comp_Err_L(parti, f)) { + case 0: { Nsamp_DM = nsamp_l(f, i); break; } @@ -1130,9 +1016,9 @@ FUNCTION void write_nudata() Nsamp_DM = value(1. / (1. + dirichlet_Parm) + nsamp_l(f, i) * dirichlet_Parm / (1. + dirichlet_Parm)); break; } - case 2: // Dirichlet #2 + case 2: // Dirichlet #2 { - dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_L2(parti,f), 1))); // Thorson's beta from eq 12 + dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_L2(parti, f), 1))); // Thorson's beta from eq 12 // effN_DM = (n+n*beta)/(n+beta) Nsamp_DM = value((nsamp_l(f, i) + dirichlet_Parm * nsamp_l(f, i)) / (dirichlet_Parm + nsamp_l(f, i))); break; @@ -1154,7 +1040,7 @@ FUNCTION void write_nudata() } report1 << header_l_rd(f, i)(1, 5) << " " << Nsamp_DM << " " << exp_l_temp_dat << endl; -// report1 << header_l_rd(f, i)(1, 3) << " " << gen_l(f, i) << " " << header_l_rd(f, i)(5) << " " << Nsamp_DM << " " << exp_l_temp_dat << endl; + // report1 << header_l_rd(f, i)(1, 3) << " " << gen_l(f, i) << " " << header_l_rd(f, i)(5) << " " << Nsamp_DM << " " << exp_l_temp_dat << endl; } } } @@ -1163,19 +1049,16 @@ FUNCTION void write_nudata() report1 << "0 "; report1 << endl; } - else - { + else { report1 << "# see manual for format of length composition data " << endl; } report1 << "#" << endl << n_abins << " #_N_age_bins" << endl; - if (n_abins > 0) - { + if (n_abins > 0) { report1 << age_bins1 << endl; } - else - { + else { report1 << "# "; } report1 << N_ageerr << " #_N_ageerror_definitions" << endl; @@ -1187,12 +1070,11 @@ FUNCTION void write_nudata() report1 << "#_combM+F: males and females treated as combined sex below this bin number " << endl; report1 << "#_compressbins: accumulate upper tail by this number of bins; acts simultaneous with mintailcomp; set=0 for no forced accumulation" << endl; report1 << "#_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; - report1 << "#_ParmSelect: consecutive index for dirichlet or MV_Tweedie" << endl; + report1 << "#_ParmSelect: consecutive index for dirichlet or MV_Tweedie" << endl; report1 << "#_minsamplesize: minimum sample size; set to 1 to match 3.24, minimum value is 0.001" << endl; report1 << "#" << endl; report1 << "#_mintailcomp addtocomp combM+F CompressBins CompError ParmSelect minsamplesize" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (n_abins <= 0) report1 << "# "; report1 << min_tail_A(f) << " " << min_comp_A(f) << " " << CombGender_A(f) << " " << AccumBin_A(f) << " " << Comp_Err_A(f) << " " << Comp_Err_A2(f) << " " << min_sample_size_A(f) << " #_fleet:" << f << "_" << fleetname(f) << endl; @@ -1206,29 +1088,24 @@ FUNCTION void write_nudata() report1 << "#_year month fleet sex part ageerr Lbin_lo Lbin_hi Nsamp datavector(female-male)" << endl; if (Nobs_a_tot > 0) - for (f = 1; f <= Nfleet; f++) - { - if (Nobs_a(f) > 0) - { - for (i = 1; i <= Nobs_a(f); i++) - { - switch (Comp_Err_A(f)) - { - case 0: - { + for (f = 1; f <= Nfleet; f++) { + if (Nobs_a(f) > 0) { + for (i = 1; i <= Nobs_a(f); i++) { + switch (Comp_Err_A(f)) { + case 0: { Nsamp_DM = nsamp_a(f, i); break; } case 1: // Dirichlet #1 { - dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_A2(f),1))); // Thorson's theta from eq 10 + dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_A2(f), 1))); // Thorson's theta from eq 10 // effN_DM = 1/(1+theta) + n*theta/(1+theta) Nsamp_DM = value(1. / (1. + dirichlet_Parm) + nsamp_a(f, i) * dirichlet_Parm / (1. + dirichlet_Parm)); break; } - case 2: // Dirichlet #2 + case 2: // Dirichlet #2 { - dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_A2(f),1))); // Thorson's beta from eq 12 + dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_A2(f), 1))); // Thorson's beta from eq 12 // effN_DM = (n+n*beta)/(n+beta) computed in Fit_LenComp Nsamp_DM = value((nsamp_a(f, i) + dirichlet_Parm * nsamp_a(f, i)) / (dirichlet_Parm + nsamp_a(f, i))); break; @@ -1263,26 +1140,20 @@ FUNCTION void write_nudata() report1 << "#" << endl << use_meansizedata << " #_Use_MeanSize-at-Age_obs (0/1)" << endl; - if (use_meansizedata > 0) - { + if (use_meansizedata > 0) { report1 << "# sex codes: 0=combined; 1=use female only; 2=use male only; 3=use both as joint sex*length distribution" << endl; report1 << "# partition codes: 0=combined; 1=discard; 2=retained" << endl; report1 << "# ageerr codes: positive means mean length-at-age; negative means mean bodywt_at_age" << endl; report1 << "#_year month fleet sex part ageerr ignore datavector(female-male)" << endl; report1 << "# samplesize(female-male)" << endl; - for (f = 1; f <= Nfleet; f++) - { - if (Nobs_ms(f) > 0) - { - for (i = 1; i <= Nobs_ms(f); i++) - { + for (f = 1; f <= Nfleet; f++) { + if (Nobs_ms(f) > 0) { + for (i = 1; i <= Nobs_ms(f); i++) { report1 << header_ms(f, i)(1) << " " << header_ms_rd(f, i)(2, 3) << " " << header_ms(f, i)(4, 7); - for (a = 1; a <= n_abins2; a++) - { + for (a = 1; a <= n_abins2; a++) { report1 << " "; temp = exp_ms(f, i, a) + randn(radm) * exp_ms_sq(f, i, a) / obs_ms_n(f, i, a); - if (temp <= 0.) - { + if (temp <= 0.) { temp = 0.0001; } report1 << temp; @@ -1305,24 +1176,24 @@ FUNCTION void write_nudata() << N_envvar << " #_N_environ_variables" << endl; report1 << "# -2 in year will subtract mean for that env_var; -1 will subtract mean and divide by stddev (e.g. Z-score)" << endl; report1 << "#_year variable value" << endl; - if (N_envvar > 0) - { + if (N_envvar > 0) { for (i = 0; i <= N_envdata - 1; i++) report1 << env_temp[i] << endl; report1 << "-9999 0 0" << endl; } - report1 << "#" << endl << "# Sizefreq data. Defined by method because a fleet can use multiple methods" << endl; + report1 << "#" << endl + << "# Sizefreq data. Defined by method because a fleet can use multiple methods" << endl; report1 << SzFreq_Nmeth_rd << " # N sizefreq methods to read (or -1 for expanded options)" << endl; if (SzFreq_Nmeth_rd < 0) { report1 << SzFreq_Nmeth << " # N sizefreq methods to read" << endl; } - if (SzFreq_Nmeth != 0) - { + if (SzFreq_Nmeth != 0) { report1 << "# each row below has entry for each sizefreq method " << endl; report1 << "#_ "; - for (int j = 1; j <= SzFreq_Nmeth; j++ ) - { report1 << j << " ";} + for (int j = 1; j <= SzFreq_Nmeth; j++) { + report1 << j << " "; + } report1 << " # Method" << endl; report1 << SzFreq_Nbins << " #_Sizefreq N bins" << endl; report1 << SzFreq_units << " #_Sizefreq units(1=bio/2=num)" << endl; @@ -1330,52 +1201,50 @@ FUNCTION void write_nudata() report1 << SzFreq_mincomp << " #_Sizefreq: small constant to add to comps" << endl; report1 << SzFreq_nobs << " #_Sizefreq number of obs per method" << endl; if (SzFreq_Nmeth_rd < 0) { - report1 << Comp_Err_Sz << " #_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; + report1 << Comp_Err_Sz << " #_Comp_Error: 0=multinomial, 1=dirichlet using Theta*n, 2=dirichlet using beta, 3=MV_Tweedie" << endl; report1 << Comp_Err_Sz2 << " #_ParmSelect: consecutive index for dirichlet or MV_Tweedie comp_error" << endl; } report1 << "#_Sizefreq bins. one row for each method" << endl << "#Note: negative value for first bin makes it accumulate all smaller fish vs. truncate small fish" << endl; - for (i = 1; i <= SzFreq_Nmeth; i++) - { report1 << SzFreq_Omit_Small(i) * SzFreq_bins1(i, 1) << SzFreq_bins1(i)(2, SzFreq_Nbins(i)) << endl; } + for (i = 1; i <= SzFreq_Nmeth; i++) { + report1 << SzFreq_Omit_Small(i) * SzFreq_bins1(i, 1) << SzFreq_bins1(i)(2, SzFreq_Nbins(i)) << endl; + } report1 << "#_method year month fleet sex part Nsamp " << endl; j = 2 * max(SzFreq_Nbins); dvector temp_probs3(1, j); dvector SzFreq_newdat(1, j); - for (iobs = 1; iobs <= SzFreq_totobs; iobs++) - { - f = SzFreq_obs1(iobs, 1); // sizefreq method + for (iobs = 1; iobs <= SzFreq_totobs; iobs++) { + f = SzFreq_obs1(iobs, 1); // sizefreq method double Nsamp_dat = 50000; if (SzFreq_obs1(iobs, 7) < Nsamp_dat) - Nsamp_dat = SzFreq_obs1(iobs, 7); + Nsamp_dat = SzFreq_obs1(iobs, 7); SzFreq_newdat.initialize(); - switch (Comp_Err_Sz(f)) - { - case 0: - { - Nsamp_DM = Nsamp_dat; - break; - } - case 1: // Dirichlet #1 - { - dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_Sz2(f),1))); // Thorson's theta from eq 10 - // effN_DM = 1/(1+theta) + n*theta/(1+theta) - Nsamp_DM = value(1. / (1. + dirichlet_Parm) + Nsamp_dat * dirichlet_Parm / (1. + dirichlet_Parm)); - break; - } - case 2: // Dirichlet #2 - { - dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_Sz2(f),1))); // Thorson's beta from eq 12 - // effN_DM = (n+n*beta)/(n+beta) computed in Fit_LenComp - Nsamp_DM = value((nsamp_l(f, i) + dirichlet_Parm * nsamp_l(f, i)) / (dirichlet_Parm + Nsamp_dat)); - break; - } - case 3: // MV_Tweedie - { - // need MV_tweedie - break; - } - } + switch (Comp_Err_Sz(f)) { + case 0: { + Nsamp_DM = Nsamp_dat; + break; + } + case 1: // Dirichlet #1 + { + dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_Sz2(f), 1))); // Thorson's theta from eq 10 + // effN_DM = 1/(1+theta) + n*theta/(1+theta) + Nsamp_DM = value(1. / (1. + dirichlet_Parm) + Nsamp_dat * dirichlet_Parm / (1. + dirichlet_Parm)); + break; + } + case 2: // Dirichlet #2 + { + dirichlet_Parm = mfexp(selparm(Comp_Err_parmloc(Comp_Err_Sz2(f), 1))); // Thorson's beta from eq 12 + // effN_DM = (n+n*beta)/(n+beta) computed in Fit_LenComp + Nsamp_DM = value((nsamp_l(f, i) + dirichlet_Parm * nsamp_l(f, i)) / (dirichlet_Parm + Nsamp_dat)); + break; + } + case 3: // MV_Tweedie + { + // need MV_tweedie + break; + } + } temp_probs3(1, SzFreq_Setup2(iobs)) = value(SzFreq_exp(iobs)); temp_mult.fill_multinomial(radm, temp_probs3(1, SzFreq_Setup2(iobs))); // create multinomial draws with prob = expected values @@ -1385,35 +1254,30 @@ FUNCTION void write_nudata() } report1 << SzFreq_obs1(iobs)(1, 7) << " " << SzFreq_newdat(1, SzFreq_Setup2(iobs)) << endl; - } + } } // begin tagging data section #3 (bootstrap data) report1 << "#" << endl << Do_TG << " # do tags (0/1)" << endl; - if (Do_TG > 0) - { + if (Do_TG > 0) { dvector temp_negbin(1, 50000); // changes authored by Gavin Fay in June 2016 in SS3 3.24Y TG_recap_gen.initialize(); int N_TG_recap_gen = 0; - for (TG = 1; TG <= N_TG; TG++) - { + for (TG = 1; TG <= N_TG; TG++) { overdisp = TG_parm(2 * N_TG + TG); dvector TG_fleet_probs(1, Nfleet); dvector temp_tags(1, Nfleet); // problem: TG_recap_exp only dimensioned to TG_endtime - for (t = 0; t <= min(TG_maxperiods, TG_endtime(TG)); t++) - { - if (value(TG_recap_exp(TG, t, 0)) > 0) - { + for (t = 0; t <= min(TG_maxperiods, TG_endtime(TG)); t++) { + if (value(TG_recap_exp(TG, t, 0)) > 0) { temp_negbin.initialize(); temp_negbin.fill_randnegbinomial(value(TG_recap_exp(TG, t, 0)), value(overdisp), radm); - //cout << TG << " " << t << " " << temp_negbin << " " << TG_recap_exp(TG,t,0) << " " << value(overdisp) << endl; - if (temp_negbin(1) > 0) - { + // cout << TG << " " << t << " " << temp_negbin << " " << TG_recap_exp(TG,t,0) << " " << value(overdisp) << endl; + if (temp_negbin(1) > 0) { TG_fleet_probs = value(TG_recap_exp(TG, t)(1, Nfleet)) / temp_negbin(1); temp_tags = 0.0; temp_mult.fill_multinomial(radm, TG_fleet_probs); @@ -1421,10 +1285,8 @@ FUNCTION void write_nudata() { temp_tags(temp_mult(compindex)) += 1.0; } - for (f = 1; f <= Nfleet; f++) - { - if (temp_tags(f) > 0) - { + for (f = 1; f <= Nfleet; f++) { + if (temp_tags(f) > 0) { N_TG_recap_gen += 1; TG_recap_gen(N_TG_recap_gen, 1) = TG; TG_recap_gen(N_TG_recap_gen, 2) = TG_release(TG, 3) + int((t + TG_release(TG, 4) - 1) / nseas); @@ -1455,8 +1317,7 @@ FUNCTION void write_nudata() report1 << "#_Note: Bootstrap values for tag recaptures are produced only for the same combinations of" << endl; report1 << "# group, year, area, and fleet that had observed recaptures. " << endl; report1 << "#_TG year seas fleet Nrecap" << endl; - for (j = 1; j <= N_TG_recap_gen; j++) - { + for (j = 1; j <= N_TG_recap_gen; j++) { report1 << TG_recap_gen(j) << endl; } } @@ -1464,20 +1325,17 @@ FUNCTION void write_nudata() report1 << "#" << endl << Do_Morphcomp << " # morphcomp data(0/1) " << endl; - if (Do_Morphcomp > 0) - { + if (Do_Morphcomp > 0) { report1 << "# note that raw data, not bootstrap are reported here " << endl; report1 << Morphcomp_nobs << " # Nobs" << endl; report1 << Morphcomp_nmorph << " # Nmorphs" << endl; report1 << Morphcomp_mincomp << " # add_to_comp" << endl; report1 << "#_year, month, fleet, null, Nsamp, datavector_by_Nmorphs (no error added!!!)" << endl; - for (i = 1; i <= Morphcomp_nobs; i++) - { + for (i = 1; i <= Morphcomp_nobs; i++) { report1 << Morphcomp_obs(i)(1, 5) << " " << Morphcomp_exp(i) << endl; } } - else - { + else { report1 << "# Nobs, Nmorphs, mincomp" << endl; report1 << "#_year, seas, type, partition, Nsamp, datavector_by_Nmorphs" << endl; } @@ -1496,12 +1354,12 @@ FUNCTION void write_nudata() // report1 << "ENDDATA" << endl; return; - } // end of write data +} // end of write data //******************************************************************** - /* SS_Label_FUNCTION 39 write_nucontrol write new control file and starter file */ +/* SS_Label_FUNCTION 39 write_nucontrol write new control file and starter file */ FUNCTION void write_nucontrol() - { +{ echoinput << "Write starter.ss_new file " << endl; anystring = ssnew_pathname + "starter.ss_new"; ofstream NuStart(anystring); @@ -1514,16 +1372,13 @@ FUNCTION void write_nucontrol() NuStart << readparfile << " # 0=use init values in control file; 1=use ss.par" << endl; NuStart << rundetail << " # run display detail (0 = minimal; 1=one line per iter; 2=each logL)" << endl; NuStart << reportdetail << " # detailed output (0=minimal for data-limited, 1=high (w/ wtatage.ss_new), 2=brief, 3=custom) " << endl; - if (reportdetail == 3) - { + if (reportdetail == 3) { NuStart << "# custom report options: -100 to start with minimal; -101 to start with all; -number to remove, +number to add, -999 to end" << endl; - for (unsigned j = 0; j <= reportdetail_list.size() - 1; j++) - { + for (unsigned j = 0; j <= reportdetail_list.size() - 1; j++) { NuStart << reportdetail_list[j](1) << endl; } } - else - { + else { NuStart << "#COND: custom report options: -100 to start with minimal; -101 to start with all; -number to remove, +number to add, -999 to end" << endl; } @@ -1548,16 +1403,14 @@ FUNCTION void write_nucontrol() NuStart << final_conv << " # final convergence criteria (e.g. 1.0e-04) " << endl; NuStart << retro_yr - endyr << " # retrospective year relative to end year (e.g. -4)" << endl; NuStart << Smry_Age << " # min age for calc of summary biomass" << endl; - NuStart << depletion_basis_rd << " # Depletion basis: denom is: 0=skip; 1=X*SPBvirgin; 2=X*SPBmsy; 3=X*SPB_styr; 4=X*SPB_endyr; 5=X*dyn_Bzero; values>=11 invoke N multiyr with 10s & 100s digit; append .1 to invoke log(ratio); e.g. 122.1 produces log(12 year trailing average of B/Bmsy)" << endl; + NuStart << depletion_basis_rd << " # Depletion basis: denom is: 0=skip; 1=X*SSBvirgin; 2=X*SSBmsy; 3=X*SSB_styr; 4=X*SSB_endyr; 5=X*dyn_Bzero; values>=11 invoke N multiyr with 10s & 100s digit; append .1 to invoke log(ratio); e.g. 122.1 produces log(12 yr trailing average of B/Bmsy)" << endl; NuStart << depletion_level << " # Fraction (X) for Depletion denominator (e.g. 0.4)" << endl; NuStart << SPR_reporting << " # SPR_report_basis: 0=skip; 1=(1-SPR)/(1-SPR_tgt); 2=(1-SPR)/(1-SPR_MSY); 3=(1-SPR)/(1-SPR_Btarget); 4=rawSPR" << endl; NuStart << F_reporting << " # F_std_reporting_units: 0=skip; 1=exploitation(Bio); 2=exploitation(Num); 3=sum(Apical_F's); 4=mean F for range of ages (numbers weighted); 5=unweighted mean F for range of ages" << endl; - if (F_reporting == 4 || F_reporting == 5) - { + if (F_reporting == 4 || F_reporting == 5) { NuStart << F_reporting_ages << " # min and max age over which mean F will be calculated, with F=Z-M" << endl; } - else - { + else { NuStart << "#COND 10 15 #_min and max age over which mean F will be calculated with F_reporting=4 or 5" << endl; } NuStart << F_std_basis_rd << " # F_std_scaling: 0=no scaling; 1=F/Fspr; 2=F/Fmsy; 3=F/Fbtgt; where F means annual F_std, Fmsy means F_std@msy; values >=11 invoke N multiyr using 10s and 100s digit; append .1 to invoke log(ratio)" << endl; @@ -1577,13 +1430,11 @@ FUNCTION void write_nucontrol() NuFore << Do_Benchmark << " # Benchmarks: 0=skip; 1=calc F_spr,F_btgt,F_msy; 2=calc F_spr,F0.1,F_msy; 3=add F_Blimit; " << endl; NuFore << Do_MSY << " # Do_MSY: 1= set to F(SPR); 2=calc F(MSY); 3=set to F(Btgt) or F0.1; 4=set to F(endyr); 5=calc F(MEY) with MSY_unit options" << endl; NuFore << "# if Do_MSY=5, enter MSY_Units; then list fleet_ID, cost/F, price/mt, include_in_Fmey_scaling; # -fleet_ID to fill; -9999 to terminate" << endl; - if (Do_MSY == 5) - { + if (Do_MSY == 5) { NuFore << MSY_units << " # MSY_units: 1=dead biomass, 2=dead biomass w/o excluded bycatch fleet, 3=retained biomass; 4=profits using price and costs" << endl; NuFore << "# Note: if a fleet's catch is excluded from the Fmey search, its catch or profits are still included in the MSY value using historical F levels from Bmark_years" << endl; NuFore << "# Fleet Cost_per_F Price_per_F include_in_Fmey_search" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (YPR_mask(f) > 0.0) NuFore << f << " " << CostPerF(f) << " " << PricePerF(f) << " " << AdjustBenchF(f) << endl; } @@ -1605,38 +1456,38 @@ FUNCTION void write_nucontrol() NuFore << N_Fcast_Yrs << " # N forecast years " << endl; NuFore << Fcast_Flevel << " # Fmult (only used for Do_Forecast==5) such that apical_F(f)=Fmult*relF(f)" << endl; anystring = ""; - if(Fcast_yr_rd(1) != -12345) - { // write in old format + if (Fcast_yr_rd(1) != -12345) { // write in old format NuFore << "#_Fcast_years for averaging: beg_selex, end_selex, beg_relF, end_relF, beg_mean recruits, end_recruits (enter actual year, or values of 0 or -integer to be rel. endyr)" << endl - << Fcast_yr_rd << endl - << "# " << Fcast_yr << endl; + << Fcast_yr_rd << endl + << "# " << Fcast_yr << endl; NuFore << Fcast_timevary_Selex_rd << " # Forecast selectivity (0=fcast selex is mean from year range; 1=fcast selectivity from time-vary parms). NOTE: logic reverses in new format" << endl; - // + // NuFore << "# A revised protocol for the Fcast_yr specification is available and recommended. Template is below." << endl; - warnstream << "A revised protocol for the Fcast_yr specification is available and recommended."; - write_message (NOTE, 1); + warnstream << "A revised protocol for the Fcast_yr specification is available and recommended."; + write_message(NOTE, 1); anystring = "#"; } -// else - { // new list based format for Fcast years - NuFore << anystring << endl << anystring << "-12345 # code to invoke new format for expanded fcast year controls" << endl - << "# biology and selectivity vectors are updated annually in the forecast according to timevary parameters, so check end year of blocks and dev vectors" << endl - << "# input in this section directs creation of means over historical years to override any time_vary changes" << endl - << "# Factors implemented so far: 1=M, 4=recr_dist, 5=migration, 10=selectivity, 11=rel_F, 12=recruitment" << endl - << "# rel_F and Recruitment also have additional controls later in forecast.ss" << endl - << "# input as list: Factor, method (0, 1), st_yr, end_yr" << endl - << "# Terminate with -9999 for Factor" << endl - << "# st_yr and end_yr input can be actual year; <=0 sets rel. to timeseries endyr; Except -999 for st_yr sets to first year if time series" << endl -// << "#_Factor: 1=M, 2=growth, 3=wtlen, 4=recr_dist&femfrac, 5=migration, 6=ageerror, 7=catchmult, 8=hermaphroditism" << endl - << "# Method = 0 (or omitted) continue using time_vary parms; 1 use mean of derived factor over specified year range"< 0) - { - NuFore << anystring << Fcast_MGparm_ave_rd(i) << " # " << MGtype_Lbl(i) << "; use: " << Fcast_MGparm_ave(i) << endl; - } + if (Fcast_MGparm_ave_rd(i, 1) > 0) { + NuFore << anystring << Fcast_MGparm_ave_rd(i) << " # " << MGtype_Lbl(i) << "; use: " << Fcast_MGparm_ave(i) << endl; + } - NuFore << anystring << "-9999 0 0 0" << endl << "#" < control rule cutoff, or set to -1 to use Bmsy/SSB_unf " << endl; NuFore << H4010_bot << " # Control rule cutoff for no F (as frac of Bzero, e.g. 0.10) " << endl; NuFore << H4010_scale_rd << " # Buffer: enter Control rule target as fraction of Flimit (e.g. 0.75), negative value invokes list of [year, scalar] with filling from year to YrMax " << endl; - if (H4010_scale_rd < 0) - { + if (H4010_scale_rd < 0) { j = H4010_scale_vec_rd.size() - 1; - for (int s = 0; s <= j; s++) - { + for (int s = 0; s <= j; s++) { NuFore << H4010_scale_vec_rd[s] << endl; } } - NuFore << "#" << endl << Fcast_Loop_Control(1) << " #_N forecast loops (1=OFL only; 2=ABC; 3=get F from forecast ABC catch with allocations applied)" << endl; + NuFore << "#" << endl + << Fcast_Loop_Control(1) << " #_N forecast loops (1=OFL only; 2=ABC; 3=get F from forecast ABC catch with allocations applied)" << endl; NuFore << Fcast_Loop_Control(2) << " # First forecast loop with stochastic recruitment" << endl; NuFore << Fcast_Loop_Control(3) << " # Forecast base recruitment: 0= spawn_recr; 1=mult*spawn_recr_fxn; 2=mult*VirginRecr; 3=deprecated; 4=mult*mean_over_yr_range" << endl; NuFore << "# for option 4, set phase for fore_recr_devs to -1 in control to get constant mean in MCMC, else devs will be applied" << endl; - if (Fcast_Loop_Control(3) == 0) - { + if (Fcast_Loop_Control(3) == 0) { NuFore << 1.0 << " # Value multiplier is ignored" << endl; } - else - { + else { NuFore << Fcast_Loop_Control(4) << " # multiplier on base recruitment " << endl; } - NuFore << Fcast_Loop_Control(5) << " # not used" << endl << "#" << endl; + NuFore << Fcast_Loop_Control(5) << " # not used" << endl + << "#" << endl; NuFore << Fcast_Cap_FirstYear << " # FirstYear for caps and allocations (should be after years with fixed inputs) " << endl; @@ -1684,10 +1533,8 @@ FUNCTION void write_nucontrol() NuFore << "# enter list of: season, fleet, relF; if used, terminate with season=-9999" << endl; { for (s = 1; s <= nseas; s++) - for (f = 1; f <= Nfleet; f++) - { - if (Fcast_RelF_Use(s, f) > 0.0) - { + for (f = 1; f <= Nfleet; f++) { + if (Fcast_RelF_Use(s, f) > 0.0) { if (Fcast_RelF_Basis == 1) NuFore << "# "; NuFore << s << " " << f << " " << Fcast_RelF_Use(s, f) << endl; @@ -1699,24 +1546,21 @@ FUNCTION void write_nucontrol() } NuFore << "# enter list of: fleet number, max annual catch for fleets with a max; terminate with fleet=-9999" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (Fcast_MaxFleetCatch(f) > -1 && fleet_type(f) == 1) NuFore << f << " " << Fcast_MaxFleetCatch(f) << endl; } NuFore << "-9999 -1" << endl; NuFore << "# enter list of area ID and max annual catch; terminate with area=-9999" << endl; - for (p = 1; p <= pop; p++) - { + for (p = 1; p <= pop; p++) { if (Fcast_MaxAreaCatch(p) > -1) NuFore << p << " " << Fcast_MaxAreaCatch(p) << endl; } NuFore << "-9999 -1" << endl; NuFore << "# enter list of fleet number and allocation group assignment, if any; terminate with fleet=-9999" << endl; - for (f = 1; f <= Nfleet; f++) - { + for (f = 1; f <= Nfleet; f++) { if (Allocation_Fleet_Assignments(f) > 0) NuFore << f << " " << Allocation_Fleet_Assignments(f) << endl; } @@ -1726,27 +1570,22 @@ FUNCTION void write_nucontrol() NuFore << "# list sequentially because read values fill to end of N forecast" << endl; NuFore << "# terminate with -9999 in year field " << endl; - if (Fcast_Catch_Allocation_Groups > 0) - { - if (finish_starter == 999) - { + if (Fcast_Catch_Allocation_Groups > 0) { + if (finish_starter == 999) { NuFore << endyr + 1 << " " << Fcast_Catch_Allocation(1) << endl; } - else - { + else { j = Fcast_Catch_Allocation_list.size() - 1; for (k = 0; k <= j - 1; k++) NuFore << Fcast_Catch_Allocation_list[k] << endl; } NuFore << " -9999 "; - for (j = 1; j <= Fcast_Catch_Allocation_Groups; j++) - { + for (j = 1; j <= Fcast_Catch_Allocation_Groups; j++) { NuFore << " 1 "; } NuFore << endl; } - else - { + else { NuFore << "# no allocation groups" << endl; } @@ -1758,8 +1597,7 @@ FUNCTION void write_nucontrol() if (Fcast_InputCatch_Basis == -1) NuFore << " Basis "; NuFore << endl; - for (j = 1; j <= N_Fcast_Input_Catches; j++) - { + for (j = 1; j <= N_Fcast_Input_Catches; j++) { NuFore << Fcast_InputCatch_rd(j) << endl; } NuFore << "-9999 1 1 0 "; @@ -1785,19 +1623,17 @@ FUNCTION void write_nucontrol() if (N_platoon == 1) report4 << "#_Cond "; else - sd_ratio_rd = (sd_ratio_rd < 0)? -platoon_sd_ratio: platoon_sd_ratio; + sd_ratio_rd = (sd_ratio_rd < 0) ? -platoon_sd_ratio : platoon_sd_ratio; report4 << sd_ratio_rd << " #_Platoon_within/between_stdev_ratio (no read if N_platoons=1)" << endl; report4 << "#_Cond sd_ratio_rd < 0: platoon_sd_ratio parameter required after movement params." << endl; if (N_platoon == 1) report4 << "#_Cond "; report4 << platoon_distr(1, N_platoon) << " #vector_platoon_dist_(-1_in_first_val_gives_normal_approx)" << endl; report4 << "#" << endl; - if (finish_starter == 999) - { + if (finish_starter == 999) { report4 << 2 << " # recr_dist_method for parameters: 2=main effects for GP, Settle timing, Area; 3=each Settle entity; 4=none, only when N_GP*Nsettle*pop==1" << endl; } - else - { + else { report4 << recr_dist_method << " # recr_dist_method for parameters: 2=main effects for GP, Area, Settle timing; 3=each Settle entity; 4=none (only when N_GP*Nsettle*pop==1)" << endl; } report4 << recr_dist_area << " # not yet implemented; Future usage: Spawner-Recruitment: 1=global; 2=by area" << endl; @@ -1806,37 +1642,31 @@ FUNCTION void write_nucontrol() report4 << "#GPattern month area age (for each settlement assignment)" << endl << settlement_pattern_rd << endl << "#" << endl; - if (pop == 1) - { + if (pop == 1) { report4 << "#_Cond 0 # N_movement_definitions goes here if Nareas > 1" << endl << "#_Cond 1.0 # first age that moves (real age at begin of season, not integer) also cond on do_migration>0" << endl << "#_Cond 1 1 1 2 4 10 # example move definition for seas=1, morph=1, source=1 dest=2, age1=4, age2=10" << endl; } - else - { + else { report4 << do_migration << " #_N_movement_definitions" << endl; - if (do_migration > 0) - { + if (do_migration > 0) { report4 << migr_firstage << " # first age that moves (real age at begin of season, not integer)" << endl << "# seas,GP,source_area,dest_area,minage,maxage" << endl << move_def << endl; } - else - { + else { report4 << "#_Cond 1.0 # first age that moves (real age at begin of season, not integer) if do_migration>0" << endl << "#_Cond 1 1 1 2 4 10 # example move definition for seas=1, GP=1, source=1 dest=2, age1=4, age2=10" << endl; } } report4 << "#" << endl; report4 << N_Block_Designs << " #_Nblock_Patterns" << endl; - if (N_Block_Designs > 0) - { + if (N_Block_Designs > 0) { report4 << Nblk << " #_blocks_per_pattern " << endl << "# begin and end years of blocks" << endl << Block_Design << endl; } - else - { + else { report4 << "#_Cond " << 0 << " #_blocks_per_pattern " << endl << "# begin and end years of blocks" << endl; } @@ -1862,50 +1692,41 @@ FUNCTION void write_nucontrol() << "# setup for M, growth, wt-len, maturity, fecundity, (hermaphro), recr_distr, cohort_grow, (movement), (age error), (catch_mult), sex ratio " << endl; report4 << "#_NATMORT" << endl << natM_type << " #_natM_type:_0=1Parm; 1=N_breakpoints;_2=Lorenzen;_3=agespecific;_4=agespec_withseasinterpolate;_5=BETA:_Maunder_link_to_maturity;_6=Lorenzen_range" << endl; - if (natM_type == 0) - { + if (natM_type == 0) { report4 << " #_no additional input for selected M option; read 1P per morph" << endl; } - else if (natM_type == 1) - { + else if (natM_type == 1) { report4 << N_natMparms << " #_N_breakpoints" << endl << NatM_break << " # age(real) at M breakpoints" << endl; } - else if (natM_type == 2) - { + else if (natM_type == 2) { report4 << natM_amin << " #_reference age for Lorenzen M; read 1P per morph" << endl; } - else if (natM_type == 6) - { + else if (natM_type == 6) { report4 << natM_amin << " #_minimum age for Lorenzen" << endl << natM_amax << " #_maximum age for Lorenzen; read 1P per morph" << endl; } - else if (natM_type >= 3 && natM_type < 5) - { + else if (natM_type >= 3 && natM_type < 5) { report4 << " #_Age_natmort_by sex x growthpattern (nest GP in sex)" << endl << Age_NatMort << endl; } - else - { + else { report4 << natM_5_opt << " #_Maunder_M suboptions: 1 (4 parm per sex*GP, using age_maturity), 2 (4 parm, same), 3 (6 parm)" << endl; report4 << "#_Note:_parm2(young_fish_power)_has_neg_value_(plaus._range:~-3_to_0.0);linear_@_-1.0; const_@_0.0" << endl; } report4 << "#" << endl; report4 << Grow_type << " # GrowthModel: 1=vonBert with L1&L2; 2=Richards with L1&L2; 3=age_specific_K_incr; 4=age_specific_K_decr; 5=age_specific_K_each; 6=NA; 7=NA; 8=growth cessation" << endl; - if (Grow_type <= 5 || Grow_type == 8) - { + if (Grow_type <= 5 || Grow_type == 8) { report4 << AFIX << " #_Age(post-settlement) for L1 (aka Amin); first growth parameter is size at this age; linear growth below this" << endl << AFIX2 << " #_Age(post-settlement) for L2 (aka Amax); 999 to treat as Linf" << endl << Linf_decay << " #_exponential decay for growth above maxage (value should approx initial Z; -999 replicates 3.24; -998 to not allow growth above maxage)" << endl; report4 << "0 #_placeholder for future growth feature" << endl; - if (Grow_type >= 3 && Grow_type <= 5) - { + if (Grow_type >= 3 && Grow_type <= 5) { report4 << Age_K_count << " # number of K multipliers to read" << endl << Age_K_points << " # ages for K multiplier" << endl; } } - else - { + else { report4 << " #_growth type not implemented" << endl; } report4 << "#" << endl; @@ -1913,22 +1734,18 @@ FUNCTION void write_nucontrol() report4 << CV_depvar << " #_CV_Growth_Pattern: 0 CV=f(LAA); 1 CV=F(A); 2 SD=F(LAA); 3 SD=F(A); 4 logSD=F(A)" << endl; report4 << "#" << endl; report4 << Maturity_Option << " #_maturity_option: 1=length logistic; 2=age logistic; 3=read age-maturity matrix by growth_pattern; 4=read age-fecundity; 5=disabled; 6=read length-maturity" << endl; - if (Maturity_Option == 3) - { + if (Maturity_Option == 3) { report4 << "#_Age_Maturity by growth pattern" << endl << Age_Maturity << endl; } - else if (Maturity_Option == 4) - { + else if (Maturity_Option == 4) { report4 << "#_Age_Fecundity by growth pattern" << endl << Age_Maturity << endl; } - else if (Maturity_Option == 5) - { + else if (Maturity_Option == 5) { report4 << "#_Age_Fecundity by growth pattern from wt-at-age.ss now invoked by read bodywt flag" << endl; } - else if (Maturity_Option == 6) - { + else if (Maturity_Option == 6) { report4 << "#_Length_Maturity by growth pattern" << endl << Length_Maturity << endl; } @@ -1938,10 +1755,9 @@ FUNCTION void write_nucontrol() } report4 << Fecund_Option << " #_fecundity_at_length option:(1)eggs=Wt*(a+b*Wt);(2)eggs=a*L^b;(3)eggs=a*Wt^b; (4)eggs=a+b*L; (5)eggs=a+b*W" << endl; report4 << Hermaphro_Option << " #_hermaphroditism option: 0=none; 1=female-to-male age-specific fxn; -1=male-to-female age-specific fxn" << endl; - if (Hermaphro_Option != 0) - { + if (Hermaphro_Option != 0) { report4 << Hermaphro_seas_rd << " # Hermaphro_season.first_age (seas=-1 means all seasons; first_age must be 0 to 9)" << endl - << Hermaphro_maleSPB << " # fraction_of_maleSSB_added_to_total_SSB " << endl; + << Hermaphro_maleSSB << " # fraction_of_maleSSB_added_to_total_SSB " << endl; } report4 << MGparm_def << " #_parameter_offset_approach for M, G, CV_G: 1- direct, no offset**; 2- male=fem_parm*exp(male_parm); 3: male=female*exp(parm) then old=young*exp(parm)" << endl; @@ -1953,36 +1769,29 @@ FUNCTION void write_nucontrol() report4 << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE env_var&link dev_link dev_minyr dev_maxyr dev_PH Block Block_Fxn" << endl; NP = 0; - for (gg = 1; gg <= gender; gg++) - { - for (gp = 1; gp <= N_GP; gp++) - { + for (gg = 1; gg <= gender; gg++) { + for (gp = 1; gp <= N_GP; gp++) { report4 << "# Sex: " << gg << " BioPattern: " << gp << " NatMort" << endl; - for (k = 1; k <= N_natMparms; k++) - { + for (k = 1; k <= N_natMparms; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; } report4 << "# Sex: " << gg << " BioPattern: " << gp << " Growth" << endl; - for (k = 1; k <= N_growparms; k++) - { + for (k = 1; k <= N_growparms; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; } report4 << "# Sex: " << gg << " BioPattern: " << gp << " WtLen" << endl; - for (k = 1; k <= 2; k++) - { + for (k = 1; k <= 2; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; } - if (gg == 1) - { + if (gg == 1) { report4 << "# Sex: " << gg << " BioPattern: " << gp << " Maturity&Fecundity" << endl; - for (k = 1; k <= 4; k++) - { + for (k = 1; k <= 4; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -1991,10 +1800,8 @@ FUNCTION void write_nucontrol() } } report4 << "# Hermaphroditism" << endl; - if (Hermaphro_Option != 0) - { - for (k = 1; k <= 3; k++) - { + if (Hermaphro_Option != 0) { + for (k = 1; k <= 3; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2003,10 +1810,8 @@ FUNCTION void write_nucontrol() report4 << "# Recruitment Distribution " << endl; j = NP + 1; - if (MGP_CGD > j) - { - for (k = j; k <= MGP_CGD - 1; k++) - { + if (MGP_CGD > j) { + for (k = j; k <= MGP_CGD - 1; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2019,10 +1824,8 @@ FUNCTION void write_nucontrol() report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; report4 << "# Movement" << endl; - if (do_migration > 0) - { - for (k = 1; k <= 2 * do_migration; k++) - { + if (do_migration > 0) { + for (k = 1; k <= 2 * do_migration; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2030,18 +1833,15 @@ FUNCTION void write_nucontrol() } report4 << "# Platoon StDev Ratio " << endl; - if (N_platoon > 1 && sd_ratio_rd < 0) - { + if (N_platoon > 1 && sd_ratio_rd < 0) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; } - + report4 << "# Age Error from parameters" << endl; - if (Use_AgeKeyZero > 0) - { - for (k = 1; k <= 7; k++) - { + if (Use_AgeKeyZero > 0) { + for (k = 1; k <= 7; k++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2049,11 +1849,9 @@ FUNCTION void write_nucontrol() } report4 << "# catch multiplier" << endl; - if (catch_mult_pointer > 0) - { + if (catch_mult_pointer > 0) { for (k = 1; k <= Nfleet; k++) - if (need_catch_mult(k) == 1) - { + if (need_catch_mult(k) == 1) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2071,16 +1869,13 @@ FUNCTION void write_nucontrol() if (frac_female_pointer == -1) // 3.24 format { // placeholders to change fracfemale (3.24) to MGparm (3.30) - for (gp = 1; gp <= N_GP; gp++) - { + for (gp = 1; gp <= N_GP; gp++) { report4 << " 0.000001 0.999999 " << femfrac(gp) << " 0.5 0.5 0 -99 0 0 0 0 0 0 0 " << "# FracFemale_GP_" << gp << endl; } } - else - { - for (gp = 1; gp <= N_GP; gp++) - { + else { + for (gp = 1; gp <= N_GP; gp++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2088,8 +1883,7 @@ FUNCTION void write_nucontrol() } report4 << "# M2 parameter for each predator fleet" << endl; - for (int gp = 1; gp <= N_predparms; gp++) - { + for (int gp = 1; gp <= N_predparms; gp++) { NP++; MGparm_1(NP, 3) = value(MGparm(NP)); report4 << MGparm_1(NP) << " # " << ParmLabel(NP) << endl; @@ -2097,20 +1891,17 @@ FUNCTION void write_nucontrol() report4 << "#" << endl; j = N_MGparm; - if (timevary_parm_cnt_MG > 0) - { + if (timevary_parm_cnt_MG > 0) { report4 << "# timevary MG parameters " << endl << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE" << endl; - for (f = 1; f <= timevary_parm_cnt_MG; f++) - { + for (f = 1; f <= timevary_parm_cnt_MG; f++) { NP++; timevary_parm_rd[f](3) = value(timevary_parm(f)); report4 << timevary_parm_rd[f] << " # " << ParmLabel(NP) << endl; } report4 << "# info on dev vectors created for MGparms are reported with other devs after tag parameter section " << endl; } - else - { + else { report4 << "#_no timevary MG parameters" << endl; } @@ -2118,34 +1909,31 @@ FUNCTION void write_nucontrol() report4 << "#_seasonal_effects_on_biology_parms" << endl << MGparm_seas_effects << " #_femwtlen1,femwtlen2,mat1,mat2,fec1,fec2,Malewtlen1,malewtlen2,L1,K" << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE" << endl; - if (MGparm_doseas > 0) - { - for (f = 1; f <= N_MGparm_seas; f++) - { + if (MGparm_doseas > 0) { + for (f = 1; f <= N_MGparm_seas; f++) { NP++; j++; MGparm_seas_1(f, 3) = value(MGparm(j)); report4 << MGparm_seas_1(f) << " # " << ParmLabel(NP) << endl; } } - else - { + else { report4 << "#_Cond -2 2 0 0 -1 99 -2 #_placeholder when no seasonal MG parameters" << endl; } report4 << "#" << endl; report4 << SR_fxn << " #_Spawner-Recruitment; Options: 1=NA; 2=Ricker; 3=std_B-H; 4=SCAA; 5=Hockey; 6=B-H_flattop; 7=survival_3Parm; 8=Shepherd_3Parm; 9=RickerPower_3parm" << endl; report4 << init_equ_steepness << " # 0/1 to use steepness in initial equ recruitment calculation" << endl; - report4 << SR_update_SSBpR0_rd << "# SR_update_SSBpR0" << endl << - "# 0 - OK, but only if no timevary biology or SR parm" << endl << - "# 1 - best: update SSBpR0 for benchmark and for time series only if SRparm R0 or h (not regime) is set to have time-varying property" << endl << - "# 2 - incorrect (old, incorrect SS3 approach): always update SSBpR0 for benchmark's use of spawner-recruitment, but only for the time series if there is a timevary SR parm" << endl << - "# 3 - option: do not update SSBpR0 (do keep start year SSBpR0), even if R0 or h is set to have time-varying property" << endl << "#" << endl; + report4 << SR_update_SSBpR0_rd << " # SR_update_SSBpR0" << endl + << "# 0 - OK, but only if no timevary biology or SR parm" << endl + << "# 1 - best: update SSBpR0 for benchmark and for time series only if SRparm R0 or h (not regime) is set to have time-varying property" << endl + << "# 2 - incorrect (old, incorrect SS3 approach): always update SSBpR0 for benchmark's use of spawner-recruitment, but only for the time series if there is a timevary SR parm" << endl + << "# 3 - option: do not update SSBpR0 (do keep start year SSBpR0), even if R0 or h is set to have time-varying property" << endl + << "#" << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE env-var use_dev dev_mnyr dev_mxyr dev_PH Block Blk_Fxn # parm_name" << endl; report4.unsetf(std::ios_base::fixed); report4.unsetf(std::ios_base::floatfield); - for (f = 1; f <= N_SRparm2; f++) - { + for (f = 1; f <= N_SRparm2; f++) { NP++; SR_parm_1(f, 3) = value(SR_parm(f)); for (j = 1; j <= 6; j++) @@ -2156,11 +1944,9 @@ FUNCTION void write_nucontrol() } report4.unsetf(std::ios_base::fixed); report4.unsetf(std::ios_base::floatfield); - if (N_SRparm3 > N_SRparm2) - { + if (N_SRparm3 > N_SRparm2) { report4 << "# timevary SR parameters" << endl; - for (f = timevary_parm_start_SR; f <= timevary_parm_cnt_SR; f++) - { + for (f = timevary_parm_start_SR; f <= timevary_parm_cnt_SR; f++) { NP++; timevary_parm_rd[f](3) = value(timevary_parm(f)); report4 << timevary_parm_rd[f] << " # " << ParmLabel(NP) << endl; @@ -2169,8 +1955,7 @@ FUNCTION void write_nucontrol() report4.unsetf(std::ios_base::fixed); report4.unsetf(std::ios_base::floatfield); } - else - { + else { report4 << "#_no timevary SR parameters" << endl; } @@ -2179,12 +1964,10 @@ FUNCTION void write_nucontrol() report4 << recdev_end << " # last year of main recr_devs; forecast devs start in following year" << endl; report4 << recdev_PH_rd << " #_recdev phase " << endl; report4 << recdev_adv << " # (0/1) to read 13 advanced options" << endl; - if (recdev_adv == 0) - { + if (recdev_adv == 0) { onenum = "#_Cond "; } - else - { + else { onenum = " "; } report4 << onenum << recdev_early_start_rd << " #_recdev_early_start (0=none; neg value makes relative to recdev_start)" << endl; @@ -2202,99 +1985,77 @@ FUNCTION void write_nucontrol() report4 << onenum << recdev_read << " #_read_recdevs" << endl; report4 << "#_end of advanced SR options" << endl; report4 << "#" << endl; - if (recdev_cycle > 0) - { - for (y = 1; y <= recdev_cycle; y++) - { + if (recdev_cycle > 0) { + for (y = 1; y <= recdev_cycle; y++) { NP++; recdev_cycle_parm_RD(y, 3) = value(recdev_cycle_parm(y)); report4 << recdev_cycle_parm_RD(y) << " # " << ParmLabel(NP) << endl; } } - else - { + else { report4 << "#_placeholder for full parameter lines for recruitment cycles" << endl; } - if (recdev_read > 0) - { + if (recdev_read > 0) { report4 << "# Specified recr devs to read" << endl; report4 << "#_year Input_value # Final_value" << endl; - for (j = 1; j <= recdev_read; j++) - { + for (j = 1; j <= recdev_read; j++) { y = recdev_input(j, 1); report4 << recdev_input(j) << " # "; - if (y >= recdev_first) - { + if (y >= recdev_first) { report4 << recdev(y) << endl; } - else - { + else { report4 << " not used " << endl; } } } - else - { + else { report4 << "# read specified recr devs" << endl; report4 << "#_year Input_value" << endl; } report4 << "#" << endl; report4 << "# all recruitment deviations" << endl << "# "; - if (recdev_do_early > 0) - { - for (y = recdev_early_start; y <= recdev_early_end; y++) - { + if (recdev_do_early > 0) { + for (y = recdev_early_start; y <= recdev_early_end; y++) { report4 << " " << y << "E"; } } - if (do_recdev > 0) - { - for (y = recdev_start; y <= recdev_end; y++) - { + if (do_recdev > 0) { + for (y = recdev_start; y <= recdev_end; y++) { report4 << " " << y << "R"; } } - if (Do_Forecast > 0) - { - for (y = recdev_end + 1; y <= YrMax; y++) - { + if (Do_Forecast > 0) { + for (y = recdev_end + 1; y <= YrMax; y++) { report4 << " " << y << "F"; } } report4 << endl << "# "; - if (recdev_do_early > 0) - { - for (y = recdev_early_start; y <= recdev_early_end; y++) - { + if (recdev_do_early > 0) { + for (y = recdev_early_start; y <= recdev_early_end; y++) { NP++; report4 << " " << recdev(y); } } - if (do_recdev > 0) - { - for (y = recdev_start; y <= recdev_end; y++) - { + if (do_recdev > 0) { + for (y = recdev_start; y <= recdev_end; y++) { NP++; report4 << " " << recdev(y); } } - if (Do_Forecast > 0 && do_recdev > 0) - { - for (y = recdev_end + 1; y <= YrMax; y++) - { + if (Do_Forecast > 0 && do_recdev > 0) { + for (y = recdev_end + 1; y <= YrMax; y++) { NP++; report4 << " " << recdev(y); } report4 << endl; - if (Do_Impl_Error > 0) - { + if (Do_Impl_Error > 0) { report4 << "# implementation error by year in forecast: "; - for (y = endyr + 1; y <= YrMax; y++) - { + for (y = endyr + 1; y <= YrMax; y++) { NP++; report4 << " " << Fcast_impl_error(y); } @@ -2308,12 +2069,10 @@ FUNCTION void write_nucontrol() report4 << F_Method << " # F_Method: 1=Pope midseason rate; 2=F as parameter; 3=F as hybrid; 4=fleet-specific parm/hybrid (#4 is superset of #2 and #3 and is recommended)" << endl; report4 << max_harvest_rate << " # max F (methods 2-4) or harvest fraction (method 1)" << endl; - if (F_Method == 1) - { + if (F_Method == 1) { report4 << "# F_Method 1: no additional input needed" << endl; } - else if (F_Method == 2) - { + else if (F_Method == 2) { report4 << F_parm_intval(1) << " # overall start F value (all fleets; used if start phase = 1 and not reading parfile)" << endl; report4 << F_Method_PH(1) << " # start phase for parms (does hybrid in early phases)" << endl; report4 << F_detail << " # N detailed inputs to read" << endl; @@ -2322,29 +2081,28 @@ FUNCTION void write_nucontrol() if (F_detail > 0) report4 << F_setup2 << endl; } - else if (F_Method == 3) - { + else if (F_Method == 3) { report4 << F_Tune << " # N iterations for tuning in hybrid mode; recommend 3 (faster) to 5 (more precise if many fleets)" << endl; } - else if (F_Method == 4) - { + else if (F_Method == 4) { report4 << "# Read list of fleets that do F as parameter; unlisted fleets stay hybrid, bycatch fleets must be included with start_PH=1, high F fleets should switch early" << endl; - report4 << "# (A) fleet;" << endl <<"# (B) F_starting_value (ignored if start_PH=1 or reading from ss3.par);" << - endl << "# (C) start_PH for fleet's Fparms (99 to stay in hybrid, <0 to stay at starting value)" << endl << - "# Terminate list with -9999 for fleet (use -9998 to read fleet-time specific F values after reading N hybrid tune loops)" << endl; + report4 << "# (A) fleet;" << endl + << "# (B) F_starting_value (ignored if start_PH=1 or reading from ss3.par);" << endl + << "# (C) start_PH for fleet's Fparms (99 to stay in hybrid, <0 to stay at starting value)" << endl + << "# Terminate list with -9999 for fleet (use -9998 to read fleet-time specific F values after reading N hybrid tune loops)" << endl; report4 << "# (A) (B) (C)" << endl; - for (unsigned j = 1; j <= F_Method_4_input.size() - 2; j++) - { + for (unsigned j = 1; j <= F_Method_4_input.size() - 2; j++) { report4 << F_Method_4_input[j] << " # " << fleetname(F_Method_4_input[j](1)) << endl; } - if (F_detail <=0 ) - {report4 << -9999 << " 1 1 # end of list" << endl << - "#F_detail template: fleet year seas F_value catch_se phase" << endl; } - else - {report4 << -9998 << " 1 1 # end of list, trigger reading F_detail" << endl; } + if (F_detail <= 0) { + report4 << -9999 << " 1 1 # end of list" << endl + << "#F_detail template: fleet year seas F_value catch_se phase" << endl; + } + else { + report4 << -9998 << " 1 1 # end of list, trigger reading F_detail" << endl; + } report4 << F_Tune << " #_number of loops for hybrid tuning; 4 precise; 3 faster; 2 enough if switching to parms is enabled" << endl; - if (F_detail > 0) - { + if (F_detail > 0) { report4 << " # F_detail: List of fleet-time specific F related values to read; enter -Yr to fill remaining years&seasons; -999 for phase or catch_se keeps base value for the run" << endl; report4 << "#fleet year seas F_value catch_se phase" << endl; report4 << F_setup2 << endl; @@ -2356,22 +2114,18 @@ FUNCTION void write_nucontrol() report4 << "#_initial_F_parms; for each fleet x season that has init_catch; nest season in fleet; count = " << N_init_F2 << endl; report4 << "#_for unconstrained init_F, use an arbitrary initial catch and set lambda=0 for its logL" << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE" << endl; - if (finish_starter == 999) - { - for (f = 1; f <= Nfleet1; f++) - { + if (finish_starter == 999) { + for (f = 1; f <= Nfleet1; f++) { NP++; - init_F_parm_1(f, 3) = value(init_F(f)); + init_F_parm_1(f, 3) = value(init_F(f)); if (obs_equ_catch(1, f) != 0.) report4 << init_F_parm_1(f) << " # " << ParmLabel(NP) << endl; } } - else if (N_init_F2 > 0) - { - for (f = 1; f <= N_init_F2; f++) - { + else if (N_init_F2 > 0) { + for (f = 1; f <= N_init_F2; f++) { NP++; - init_F_parm_1(f, 3) = value(init_F(f)); + init_F_parm_1(f, 3) = value(init_F(f)); report4 << init_F_parm_1(f) << " # " << ParmLabel(NP) << endl; } } @@ -2380,22 +2134,19 @@ FUNCTION void write_nucontrol() << "# F rates by fleet x season" << endl; report4 << "#_year: "; for (y = styr; y <= YrMax; y++) - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { report4 << " " << y; } report4 << endl << "# seas: "; for (y = styr; y <= YrMax; y++) - for (s = 1; s <= nseas; s++) - { + for (s = 1; s <= nseas; s++) { report4 << " " << s; } report4 << endl; j = styr + (YrMax - styr) * nseas + nseas - 1; for (f = 1; f <= Nfleet; f++) - if (fleet_type(f) <= 2) - { + if (fleet_type(f) <= 2) { report4 << "# " << fleetname(f) << Hrate(f)(styr, j) << endl; } NP += N_Fparm; @@ -2422,10 +2173,8 @@ FUNCTION void write_nucontrol() } report4 << "#_ fleet link link_info extra_se biasadj float # fleetname" << endl; - for (f = 1; f <= Nfleet; f++) - { - if (Svy_N_fleet(f) > 0) - { + for (f = 1; f <= Nfleet; f++) { + if (Svy_N_fleet(f) > 0) { report4 << " " << setw(9) << f; for (j = 1; j <= 5; j++) report4 << setw(10) << Q_setup(f, j); @@ -2436,13 +2185,11 @@ FUNCTION void write_nucontrol() << "#" << endl; report4 << "#_Q_parameters" << endl; - if (Q_Npar > 0) - { + if (Q_Npar > 0) { report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE env-var use_dev dev_mnyr dev_mxyr dev_PH Block Blk_Fxn # parm_name" << endl; report4.unsetf(std::ios_base::fixed); report4.unsetf(std::ios_base::floatfield); - for (f = 1; f <= Q_Npar; f++) - { + for (f = 1; f <= Q_Npar; f++) { NP++; Q_parm_1(f, 3) = value(Q_parm(f)); for (j = 1; j <= 6; j++) @@ -2454,12 +2201,10 @@ FUNCTION void write_nucontrol() report4.unsetf(std::ios_base::fixed); report4.unsetf(std::ios_base::floatfield); - if (timevary_parm_start_Q > 0) - { + if (timevary_parm_start_Q > 0) { report4 << "# timevary Q parameters " << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE # parm_name" << endl; - for (f = timevary_parm_start_Q; f <= timevary_parm_cnt_Q; f++) - { + for (f = timevary_parm_start_Q; f <= timevary_parm_cnt_Q; f++) { NP++; timevary_parm_rd[f](3) = value(timevary_parm(f)); for (j = 1; j <= 6; j++) @@ -2468,8 +2213,7 @@ FUNCTION void write_nucontrol() } report4 << "# info on dev vectors created for Q parms are reported with other devs after tag parameter section " << endl; } - else - { + else { report4 << "#_no timevary Q parameters" << endl; } report4.unsetf(std::ios_base::fixed); @@ -2533,21 +2277,17 @@ FUNCTION void write_nucontrol() { k = 0; - for (f = 1; f <= 2 * Nfleet; f++) - { - if (f > Nfleet) - { + for (f = 1; f <= 2 * Nfleet; f++) { + if (f > Nfleet) { f1 = f - Nfleet; anystring = "AgeSelex"; } - else - { + else { f1 = f; anystring = "LenSelex"; } report4 << "# " << f1 << " " << fleetname(f1) << " " << anystring << endl; - for (j = 1; j <= N_selparmvec(f); j++) - { + for (j = 1; j <= N_selparmvec(f); j++) { NP++; k++; selparm_1(k)(3) = value(selparm(k)); @@ -2558,13 +2298,11 @@ FUNCTION void write_nucontrol() report4 << " # " << ParmLabel(NP) << endl; } } - if (Comp_Err_ParmCount > 0) - { + if (Comp_Err_ParmCount > 0) { report4 << "#_Dirichlet and/or MV Tweedie parameters for composition error" << endl; report4 << "#_multiple_fleets_can_refer_to_same_parm;_but_list_cannot_have_gaps" << endl; k = Comp_Err_Parm_Start; - for (f = 1; f <= Comp_Err_ParmCount; f++) - { + for (f = 1; f <= Comp_Err_ParmCount; f++) { k++; NP++; selparm_1(k)(3) = value(selparm(k)); @@ -2575,18 +2313,15 @@ FUNCTION void write_nucontrol() report4 << " # " << ParmLabel(NP) << endl; } } - else - { + else { report4 << "#_No_Dirichlet parameters" << endl; } - if (N_selparm3 > N_selparm) - { + if (N_selparm3 > N_selparm) { report4 << "# timevary selex parameters " << endl; report4 << "#_ LO HI INIT PRIOR PR_SD PR_type PHASE # parm_name" << endl; // for (f=timevary_parm_start_sel;f<=timevary_parm_cnt_sel;f++) - for (int f = timevary_parm_start_sel; f <= timevary_parm_start_sel + N_selparm3 - N_selparm - 1; f++) - { + for (int f = timevary_parm_start_sel; f <= timevary_parm_start_sel + N_selparm3 - N_selparm - 1; f++) { NP++; timevary_parm_rd[f](3) = value(timevary_parm(f)); for (j = 1; j <= 6; j++) @@ -2595,31 +2330,26 @@ FUNCTION void write_nucontrol() } report4 << "# info on dev vectors created for selex parms are reported with other devs after tag parameter section " << endl; } - else - { + else { report4 << "#_no timevary selex parameters" << endl; } report4 << "#" << endl << TwoD_AR_do << " # use 2D_AR1 selectivity? (0/1)" << endl; - if (TwoD_AR_do > 0) - { + if (TwoD_AR_do > 0) { k = timevary_parm_start_sel + N_selparm3 - N_selparm - 1; // starting point in timevary_parm_rd report4 << "#_specifications for 2D_AR1 and associated parameters" << endl; report4 << "#_specs: fleet, ymin, ymax, amin, amax, sigma_amax, use_rho, len1/age2, devphase, before_range, after_range" << endl; report4 << "#_sigma_amax>amin means create sigma parm for each bin from min to sigma_amax; sigma_amax<0 means just one sigma parm is read and used for all bins" << endl; - for (j = 1; j <= TwoD_AR_cnt; j++) - { + for (j = 1; j <= TwoD_AR_cnt; j++) { ivector tempvec(1, 13); // fleet, ymin, ymax, amin, amax, sigma_amax, use_rho, len1/age2, devphase tempvec(1, 13) = TwoD_AR_def[j](1, 13); tempvec(6) = TwoD_AR_def_rd[j](6); // restore the read value in case it got changed - int isigmasel = TwoD_AR_def[j](13); // index of first sigmasel parm in selparm - if (tempvec(8) == 1) - { + int isigmasel = TwoD_AR_def[j](13); // index of first sigmasel parm in selparm + if (tempvec(8) == 1) { anystring = "LEN"; } - else - { + else { anystring = "AGE"; } @@ -2627,16 +2357,14 @@ FUNCTION void write_nucontrol() int sigma_amax = tempvec(6); int use_rho = tempvec(7); int amin = tempvec(4); - for (a = amin; a <= sigma_amax; a++) - { + for (a = amin; a <= sigma_amax; a++) { dvector dtempvec(1, 7); // Lo, Hi, init, prior, prior_sd, prior_type, phase; k++; dtempvec = timevary_parm_rd[k](1, 7); - dtempvec(3) = value ( selparm(isigmasel + a - amin) ); - report4 << dtempvec << " # sigma_sel for fleet:_" << tempvec(1) << "; " << anystring << "_" << a <amin means create sigma parm for each bin from min to sigma_amax; sigma_amax<0 means just one sigma parm is read and used for all bins" << endl; - report4 << "#_needed parameters follow each fleet's specifications"< 0) - { + if (Do_TG > 0) { report4 << 1 << " # TG_custom: 0=no read and autogen if tag data exist; 1=read" << endl; report4 << "#_Note - tag parameters cannot be time-varying" << endl; report4 << "#_Note - phase=-1000 sets parm value to previous parm; phase=-100X sets to parm(X) value" << endl; - for (f = 1; f <= 3 * N_TG + 2 * Nfleet1; f++) - { + for (f = 1; f <= 3 * N_TG + 2 * Nfleet1; f++) { NP++; report4 << TG_parm2(f)(1, 2) << " " << TG_parm(f) << " " << TG_parm2(f)(4, 14) << " # " << ParmLabel(NP) << endl; } } - else - { + else { report4 << "0 # TG_custom: 0=no read and autogen if tag data exist; 1=read" << endl << "#_Cond -6 6 1 1 2 0.01 -4 0 0 0 0 0 0 0 #_placeholder if no parameters" << endl; ; } report4 << "#" << endl; - if (timevary_cnt == 0) - { + if (timevary_cnt == 0) { report4 << "# no timevary parameters" << endl << "#" << endl; } - else - { + else { report4 << "# deviation vectors for timevary parameters" << endl << "# base base first block block env env dev dev dev dev dev" << endl << "# type index parm trend pattern link var vectr link _mnyr mxyr phase dev_vector" << endl; - for (j = 1; j <= timevary_cnt; j++) - { + for (j = 1; j <= timevary_cnt; j++) { // report4.precision(6); // report4.unsetf(std::ios_base::fixed); // report4.unsetf(std::ios_base::floatfield); @@ -2745,36 +2466,30 @@ FUNCTION void write_nucontrol() report4 << "#" << endl << "# lambdas (for info only; columns are phases)" << endl; - if (Svy_N > 0) - { + if (Svy_N > 0) { for (f = 1; f <= Nfleet; f++) report4 << "# " << surv_lambda(f) << " #_CPUE/survey:_" << f << endl; } - if (nobs_disc > 0) - { + if (nobs_disc > 0) { for (f = 1; f <= Nfleet; f++) report4 << "# " << disc_lambda(f) << " #_discard:_" << f << endl; } - if (nobs_mnwt > 0) - { + if (nobs_mnwt > 0) { for (f = 1; f <= Nfleet; f++) report4 << "# " << mnwt_lambda(f) << " #_meanbodywt:" << f << endl; } - if (Nobs_l_tot > 0) - { + if (Nobs_l_tot > 0) { for (f = 1; f <= Nfleet; f++) report4 << "# " << length_lambda(f) << " #_lencomp:_" << f << endl; } - if (Nobs_a_tot > 0) - { + if (Nobs_a_tot > 0) { for (f = 1; f <= Nfleet; f++) report4 << "# " << age_lambda(f) << " #_agecomp:_" << f << endl; } if (SzFreq_Nmeth > 0) for (f = 1; f <= SzFreq_N_Like; f++) report4 << "# " << SzFreq_lambda(f) << " #_sizefreq:_" << f << endl; - if (nobs_ms_tot > 0) - { + if (nobs_ms_tot > 0) { for (f = 1; f <= Nfleet; f++) report4 << "# " << sizeage_lambda(f) << " #_size-age:_" << f << endl; } @@ -2783,8 +2498,7 @@ FUNCTION void write_nucontrol() report4 << "# " << recrdev_lambda << " #_recruitments" << endl; report4 << "# " << parm_prior_lambda << " #_parameter-priors" << endl; report4 << "# " << parm_dev_lambda << " #_parameter-dev-vectors" << endl; - if (Do_TG > 0) - { + if (Do_TG > 0) { for (TG = 1; TG <= N_TG; TG++) report4 << "# " << TG_lambda1(TG) << " #_TG-comp_group:_" << TG << endl; for (TG = 1; TG <= N_TG; TG++) @@ -2797,15 +2511,15 @@ FUNCTION void write_nucontrol() report4 << Do_More_Std << " # (0/1/2) read specs for more stddev reporting: 0 = skip, 1 = read specs for reporting stdev for selectivity, size, and numbers, 2 = add options for M,Dyn. Bzero, SmryBio" << endl; - //3868 Do_Selex_Std=More_Std_Input(1); - //3869 Selex_Std_AL=More_Std_Input(2); - //3870 Selex_Std_Year=More_Std_Input(3); - //3872 Selex_Std_Cnt=More_Std_Input(4); - //3873 Do_Growth_Std=More_Std_Input(5); - //3875 Growth_Std_Cnt=More_Std_Input(6); - //3876 Do_NatAge_Std=More_Std_Input(7); - //3877 NatAge_Std_Year=More_Std_Input(8); - //3879 NatAge_Std_Cnt=More_Std_Input(9); + // 3868 Do_Selex_Std=More_Std_Input(1); + // 3869 Selex_Std_AL=More_Std_Input(2); + // 3870 Selex_Std_Year=More_Std_Input(3); + // 3872 Selex_Std_Cnt=More_Std_Input(4); + // 3873 Do_Growth_Std=More_Std_Input(5); + // 3875 Growth_Std_Cnt=More_Std_Input(6); + // 3876 Do_NatAge_Std=More_Std_Input(7); + // 3877 NatAge_Std_Year=More_Std_Input(8); + // 3879 NatAge_Std_Cnt=More_Std_Input(9); if (Do_More_Std == 0) // empty/dummy values when extra stddev reporting not used { @@ -2831,39 +2545,31 @@ FUNCTION void write_nucontrol() } if (Do_More_Std > 0) // vectors associated with options 1 and 2 { - if (Do_Selex_Std > 0) - { + if (Do_Selex_Std > 0) { report4 << Selex_Std_Pick << " # vector with selex std bins (-1 in first bin to self-generate)" << endl; } - else - { + else { report4 << " # -1 # list of bin #'s for selex std (-1 in first bin to self-generate)" << endl; } // if(Do_Growth_Std>0){ - if (More_Std_Input(5) > 0) - { + if (More_Std_Input(5) > 0) { report4 << Growth_Std_Pick << " # vector with growth std ages picks (-1 in first bin to self-generate)" << endl; } - else - { + else { report4 << " # -1 # list of ages for growth std (-1 in first bin to self-generate)" << endl; } - if (Do_NatAge_Std != 0) - { + if (Do_NatAge_Std != 0) { report4 << NatAge_Std_Pick << " # vector with NatAge std ages (-1 in first bin to self-generate)" << endl; } - else - { + else { report4 << " # -1 # list of ages for NatAge std (-1 in first bin to self-generate)" << endl; } if (Do_More_Std == 2) // additional output when option 2 is selected { - if (Do_NatM_Std > 0) - { + if (Do_NatM_Std > 0) { report4 << NatM_Std_Pick << " # vector with NatM std ages picks (-1 in first bin to self-generate)" << endl; } - else - { + else { report4 << " # -1 # list of ages for NatM std (-1 in first bin to self-generate)" << endl; } } @@ -2871,5 +2577,4 @@ FUNCTION void write_nucontrol() report4 << fim << endl << endl; // end of file indicator return; - } // end of write nucontrol - +} // end of write nucontrol From 33738c4e54c360417276ae1cfdd2c416011cad2f Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Fri, 4 Oct 2024 16:23:39 -0700 Subject: [PATCH 19/22] add HCR_anchor in forecast.ss --- SS_benchfore.tpl | 37 ++++++++++++++++++++----------------- SS_param.tpl | 1 + SS_readdata_330.tpl | 4 ++-- SS_write_report.tpl | 6 +++--- SS_write_ssnew.tpl | 3 ++- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 9bcb1edb..001ab198 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -776,8 +776,6 @@ FUNCTION void Get_Benchmarks(const int show_MSY) Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_unf, Recr_unf, SSBpR_unf); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR report5 << " Benchmark SSB, R0, SPR0: " << SSB_unf << " " << Recr_unf << " " << SSBpR_unf << " equil: " << Equ_SpawnRecr_Result << endl; } - report5 << 0 << " y: " << y << " Repro_output_by_age_for_morph_1 bench " << fec(1) << endl; -// report5 << "Repro_output_by_age_for_morph_1: " << fec(1) << endl; } SR_parm_work(N_SRparm2 + 1) = SSB_unf; @@ -2211,6 +2209,11 @@ FUNCTION void Get_Forecast() break; } } + if (Fcast_Loop_Control(5) <= 1) + {HCR_anchor = SSB_unf;} + else if (Fcast_Loop_Control(5) ==2) + {HCR_anchor = SSB_virgin;} + report5 << "Control_rule_anchor_approach: " << Fcast_Loop_Control(5) << " HCR_anchor: " << HCR_anchor << endl; report5 << "#" << endl; } @@ -2227,7 +2230,7 @@ FUNCTION void Get_Forecast() for (int Fcast_Loop1 = 1; Fcast_Loop1 <= jloop; Fcast_Loop1++) // for different forecast conditions { - report5 << Fcast_Loop1 << " y: " << 0 << " Repro_output_by_age_for_morph_1 top_forecast: " << fec(1) << endl; +// report5 << Fcast_Loop1 << " y: " << 0 << " Repro_output_by_age_for_morph_1 top_forecast: " << fec(1) << endl; switch (Fcast_Loop1) // select which ABC_loops to use { @@ -2315,7 +2318,7 @@ FUNCTION void Get_Forecast() } } } - report5 << Fcast_Loop1 << " y: " << y << " updated_Repro_output_by_age_for_morph_1 endyr: " << fec(1) << endl; +// report5 << Fcast_Loop1 << " y: " << y << " updated_Repro_output_by_age_for_morph_1 endyr: " << fec(1) << endl; for (y = endyr + 1; y <= YrMax; y++) { t_base = styr + (y - styr) * nseas - 1; @@ -2505,7 +2508,7 @@ FUNCTION void Get_Forecast() Wt_Age_mid(s, g) = ALK(ALK_idx, g) * wt_len(s, GP(g)); // use for fisheries with no size selectivity } } - report5 << Fcast_Loop1 << " y: " << y << " updated_Repro_output_by_age_for_morph_1 annual: " << fec(1) << endl; +// report5 << Fcast_Loop1 << " y: " << y << " updated_Repro_output_by_age_for_morph_1 annual: " << fec(1) << endl; Wt_Age_t(t, 0) = Wt_Age_beg(s); for (g = 1; g <= gmorph; g++) if (use_morph(g) > 0) @@ -2661,9 +2664,9 @@ FUNCTION void Get_Forecast() } else if (ABC_Loop == 2 && s == 1) // Calc the buffer in season 1, will use last year's spawnbio if multiseas and spawnseas !=1 { - temp = SSB_unf; - join1 = 1. / (1. + mfexp(10. * (SSB_current - H4010_bot * temp))); - join2 = 1. / (1. + mfexp(10. * (SSB_current - H4010_top * temp))); + + join1 = 1. / (1. + mfexp(10. * (SSB_current - H4010_bot * HCR_anchor))); + join2 = 1. / (1. + mfexp(10. * (SSB_current - H4010_top * HCR_anchor))); switch (HarvestPolicy) { @@ -2676,8 +2679,8 @@ FUNCTION void Get_Forecast() // ramp scales catch as f(B) and buffer (H4010_scale) applied to F { ABC_buffer(y) = H4010_scale_vec(y) * - ((0.0001 * SSB_current / (H4010_bot * temp)) * (join1) // low - + (0.0001 + (1.0 - 0.0001) * (H4010_top * temp / SSB_current) * (SSB_current - H4010_bot * temp) / (H4010_top * temp - H4010_bot * temp)) * (1.0 - join1) // curve + ((0.0001 * SSB_current / (H4010_bot * HCR_anchor)) * (join1) // low + + (0.0001 + (1.0 - 0.0001) * (H4010_top * HCR_anchor / SSB_current) * (SSB_current - H4010_bot * HCR_anchor) / (H4010_top * HCR_anchor - H4010_bot * HCR_anchor)) * (1.0 - join1) // curve ) * (join2) // scale combo + @@ -2688,8 +2691,8 @@ FUNCTION void Get_Forecast() // ramp scales F as f(B) and buffer (H4010_scale) applied to F { ABC_buffer(y) = H4010_scale_vec(y) * - ((0.0001 * SSB_current / (H4010_bot * temp)) * (join1) // low - + (0.0001 + (1.0 - 0.0001) * (SSB_current - H4010_bot * temp) / (H4010_top * temp - H4010_bot * temp)) * (1.0 - join1) // curve + ((0.0001 * SSB_current / (H4010_bot * HCR_anchor)) * (join1) // low + + (0.0001 + (1.0 - 0.0001) * (SSB_current - H4010_bot * HCR_anchor) / (H4010_top * HCR_anchor - H4010_bot * HCR_anchor)) * (1.0 - join1) // curve ) * (join2) // scale combo + @@ -2700,8 +2703,8 @@ FUNCTION void Get_Forecast() // ramp scales catch as f(B) and buffer (H4010_scale) applied to catch { ABC_buffer(y) = 1.0 * - ((0.0001 * SSB_current / (H4010_bot * temp)) * (join1) // low - + (0.0001 + (1.0 - 0.0001) * (H4010_top * temp / SSB_current) * (SSB_current - H4010_bot * temp) / (H4010_top * temp - H4010_bot * temp)) * (1.0 - join1) // curve + ((0.0001 * SSB_current / (H4010_bot * HCR_anchor)) * (join1) // low + + (0.0001 + (1.0 - 0.0001) * (H4010_top * HCR_anchor / SSB_current) * (SSB_current - H4010_bot * HCR_anchor) / (H4010_top * HCR_anchor - H4010_bot * HCR_anchor)) * (1.0 - join1) // curve ) * (join2) // scale combo + @@ -2712,8 +2715,8 @@ FUNCTION void Get_Forecast() // ramp scales F as f(B) and buffer (H4010_scale) applied to catch { ABC_buffer(y) = 1.0 * - ((0.0001 * SSB_current / (H4010_bot * temp)) * (join1) // low - + (0.0001 + (1.0 - 0.0001) * (SSB_current - H4010_bot * temp) / (H4010_top * temp - H4010_bot * temp)) * (1.0 - join1) // curve + ((0.0001 * SSB_current / (H4010_bot * HCR_anchor)) * (join1) // low + + (0.0001 + (1.0 - 0.0001) * (SSB_current - H4010_bot * HCR_anchor) / (H4010_top * HCR_anchor - H4010_bot * HCR_anchor)) * (1.0 - join1) // curve ) * (join2) // scale combo + @@ -3518,7 +3521,7 @@ FUNCTION void Get_Forecast() f = fish_fleet_area(0, ff); if (fleet_type(f) == 1) { - if (ABC_Loop == 2 && HarvestPolicy >= 3) + if (ABC_Loop == 2 && HarvestPolicy >= 3) // alternative ABC_buffer approach { catch_fleet(t, f) *= H4010_scale_vec(y); } diff --git a/SS_param.tpl b/SS_param.tpl index ed5e5a29..7a9cd6f7 100644 --- a/SS_param.tpl +++ b/SS_param.tpl @@ -229,6 +229,7 @@ else { init_bounded_vector Fcast_recruitments(recdev_end+1,s,recdev_LO,recdev_HI,Fcast_recr_PH2) init_bounded_vector Fcast_impl_error(endyr+1,j,-1,1,k) vector ABC_buffer(endyr+1,YrMax); + number HCR_anchor // basis (denominator) bor inflection in control rule // SPAWN-RECR: define some spawning biomass and recruitment entities number SSB_virgin diff --git a/SS_readdata_330.tpl b/SS_readdata_330.tpl index 56277cb9..96658403 100644 --- a/SS_readdata_330.tpl +++ b/SS_readdata_330.tpl @@ -4345,8 +4345,8 @@ "even when the base is set to the mean of earlier recruitments" << endl; } - echoinput << Fcast_Loop_Control(5) << " #echo: loop control 5 not used" << endl; - + echoinput << Fcast_Loop_Control(5) << " #control rule anchor: 1=unfished_benchmark_SSB(old_approach), 2=virgin_SSB " << endl; + echoinput << "#next enter year in which Fcast loop 3 caps and allocations begin to be applied" << endl; *(ad_comm::global_datafile) >> Fcast_Cap_FirstYear; echoinput << Fcast_Cap_FirstYear << " # echoed value" << endl; diff --git a/SS_write_report.tpl b/SS_write_report.tpl index 82794514..aa5c234e 100644 --- a/SS_write_report.tpl +++ b/SS_write_report.tpl @@ -4737,7 +4737,7 @@ FUNCTION void SPR_profile() Wt_Age_mid(s) = Wt_Age_t(t, -1); if (s == spawn_seas) fec = Wt_Age_t(t, -2); - report5 << 0 << " y: " << y << " updated_Repro_output spr/ypr: " << fec(1) << endl; +// report5 << 0 << " y: " << y << " updated_Repro_output spr/ypr: " << fec(1) << endl; } SS2out << "SPRloop Iter Bycatch Fmult F_std SPR YPR_dead YPR_dead*Recr YPR_ret*Recr Revenue Cost Profit SSB Recruits SSB/Bzero Tot_Catch "; @@ -5070,9 +5070,9 @@ FUNCTION void Global_MSY() SS2out << "Actual "; show_MSY = 2; // invokes just brief output in benchmark did_MSY = 0; - report5 << 0 << " y: " << y << " updated_Repro_output global_1: " << fec(1) << endl; +// report5 << 0 << " y: " << y << " updated_Repro_output global_1: " << fec(1) << endl; Get_Benchmarks(show_MSY); - report5 << 0 << " y: " << y << " updated_Repro_output global_2: " << fec(1) << endl; +// report5 << 0 << " y: " << y << " updated_Repro_output global_2: " << fec(1) << endl; did_MSY = 0; } } diff --git a/SS_write_ssnew.tpl b/SS_write_ssnew.tpl index 85aaccb6..03eb531c 100644 --- a/SS_write_ssnew.tpl +++ b/SS_write_ssnew.tpl @@ -1493,6 +1493,7 @@ FUNCTION void write_nucontrol() NuFore << HarvestPolicy << " # Control rule method (0: none; 1: ramp does catch=f(SSB), buffer on F; 2: ramp does F=f(SSB), buffer on F; 3: ramp does catch=f(SSB), buffer on catch; 4: ramp does F=f(SSB), buffer on catch) " << endl; NuFore << "# values for top, bottom and buffer exist, but not used when Policy=0" << endl; NuFore << H4010_top_rd << " # Control rule inflection for constant F (as frac of Bzero, e.g. 0.40); must be > control rule cutoff, or set to -1 to use Bmsy/SSB_unf " << endl; + NuFore << "# Also see HCR_anchor below" << endl; NuFore << H4010_bot << " # Control rule cutoff for no F (as frac of Bzero, e.g. 0.10) " << endl; NuFore << H4010_scale_rd << " # Buffer: enter Control rule target as fraction of Flimit (e.g. 0.75), negative value invokes list of [year, scalar] with filling from year to YrMax " << endl; if (H4010_scale_rd < 0) { @@ -1513,7 +1514,7 @@ FUNCTION void write_nucontrol() else { NuFore << Fcast_Loop_Control(4) << " # multiplier on base recruitment " << endl; } - NuFore << Fcast_Loop_Control(5) << " # not used" << endl + NuFore << Fcast_Loop_Control(5) << " # HCR_anchor: 0 or 1 uses unfished benchmark SSB (old hardwired approach), 2 = virgin SSB" << endl << "#" << endl; NuFore << Fcast_Cap_FirstYear << " # FirstYear for caps and allocations (should be after years with fixed inputs) " << endl; From 424f3c66b39e343a2dd3533a6f6deb12c496f097 Mon Sep 17 00:00:00 2001 From: Ian Taylor Date: Fri, 18 Oct 2024 09:43:01 -0700 Subject: [PATCH 20/22] revert change in capitalization of Recr_Virgin --- SS_readcontrol_330.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SS_readcontrol_330.tpl b/SS_readcontrol_330.tpl index b54f0bd6..054f7c74 100644 --- a/SS_readcontrol_330.tpl +++ b/SS_readcontrol_330.tpl @@ -6515,7 +6515,7 @@ active_parm(CoVar_Count) = j; if (y == styr - 2) { - ParmLabel += "Recr_virgin"; + ParmLabel += "Recr_Virgin"; } else if (y == styr - 1) { From 27d40957dff93e112515b47e7745601442145dae Mon Sep 17 00:00:00 2001 From: Richard Methot Date: Thu, 17 Oct 2024 16:07:03 -0700 Subject: [PATCH 21/22] latest update --- SS_benchfore.tpl | 25 +++++++++++++------------ SS_param.tpl | 2 +- SS_write_ssnew.tpl | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/SS_benchfore.tpl b/SS_benchfore.tpl index 001ab198..74e2f7e2 100644 --- a/SS_benchfore.tpl +++ b/SS_benchfore.tpl @@ -767,7 +767,8 @@ FUNCTION void Get_Benchmarks(const int show_MSY) if (show_MSY == 1) { report5 << "SR_parms for benchmark: " << SR_parm_work << endl - << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << " flag for updating SSBpR0 = " << SR_update_SSBpR0_bmark << endl; + << "Benchmark biology averaged over years: " << Bmark_Yr(1) << " " << Bmark_Yr(2) << endl << + "input.SR_update_SSBpR0_rd: " << SR_update_SSBpR0_rd << "flag for updating SSBpR0_Bmark: " << SR_update_SSBpR0_bmark << endl; Equ_SpawnRecr_Result = Equil_Spawn_Recr_Fxn(SR_parm_work, SSB_virgin, Recr_virgin, SSBpR_virgin); // returns 2 element vector containing equilibrium biomass and recruitment at this SPR report5 << " Virgin SSB, R0, SPR0: " << SSB_virgin << " " << Recr_virgin << " " << SSBpR_virgin << " equil: " << Equ_SpawnRecr_Result << endl; if ( SR_update_SSBpR0_bmark == 1) @@ -2176,10 +2177,16 @@ FUNCTION void Get_Forecast() { H4010_top = H4010_top_rd; } + if (Fcast_Loop_Control(5) <= 1) + {HCR_anchor = SSB_unf;} + else if (Fcast_Loop_Control(5) ==2) + {HCR_anchor = SSB_virgin;} report5 << "#" << endl; report5 << "N_forecast_yrs: " << N_Fcast_Yrs << endl; - report5 << "OY_Control_Rule " - << " Inflection: " << H4010_top << " Intercept: " << H4010_bot << " Scale: " << H4010_scale_vec(endyr + 1) << "; "; + report5 << "OY_Control_Rule: Inflection: " << H4010_top << " Intercept: " << H4010_bot << " Scale: " << H4010_scale_vec(endyr + 1) << endl + << "Control_rule_anchor_approach: " << Fcast_Loop_Control(5) << " HCR_anchor: " << HCR_anchor << endl; + report5 << "#" << endl; + switch (HarvestPolicy) { case 0: // none @@ -2209,13 +2216,7 @@ FUNCTION void Get_Forecast() break; } } - if (Fcast_Loop_Control(5) <= 1) - {HCR_anchor = SSB_unf;} - else if (Fcast_Loop_Control(5) ==2) - {HCR_anchor = SSB_virgin;} - report5 << "Control_rule_anchor_approach: " << Fcast_Loop_Control(5) << " HCR_anchor: " << HCR_anchor << endl; - report5 << "#" << endl; - } + } int jloop; if (fishery_on_off == 1 || Do_Dyn_Bzero > 0) @@ -2264,7 +2265,7 @@ FUNCTION void Get_Forecast() if (HarvestPolicy == 0) report5 << "pop year ABC_Loop season No_buffer bio-all bio-Smry SpawnBio Depletion recruit-0 "; if (HarvestPolicy <= 2) - report5 << "pop year ABC_Loop season Ramp&Buffer bio-all bio-Smry SpawnBio Depletion recruit-0 "; + report5 << "pop year ABC_Loop season Ramp&Buffer Buffer2 bio-all bio-Smry SpawnBio Depletion recruit-0 "; if (HarvestPolicy >= 3) report5 << "pop year ABC_Loop season Ramp bio-all bio-Smry SpawnBio Depletion recruit-0 "; for (int ff = 1; ff <= N_catchfleets(0); ff++) @@ -3136,7 +3137,7 @@ FUNCTION void Get_Forecast() } if (show_MSY == 1) { - report5 << p << " " << y << " " << ABC_Loop << " " << s << " " << ABC_buffer(y) << " " << totbio << " " << smrybio << " "; + report5 << p << " " << y << " " << ABC_Loop << " " << s << " " << ABC_buffer(y) << " " << H4010_scale_vec(y) << " " << totbio << " " << smrybio << " "; if (s == spawn_seas) { report5 << SSB_current << " "; diff --git a/SS_param.tpl b/SS_param.tpl index 7a9cd6f7..b49727bb 100644 --- a/SS_param.tpl +++ b/SS_param.tpl @@ -229,7 +229,7 @@ else { init_bounded_vector Fcast_recruitments(recdev_end+1,s,recdev_LO,recdev_HI,Fcast_recr_PH2) init_bounded_vector Fcast_impl_error(endyr+1,j,-1,1,k) vector ABC_buffer(endyr+1,YrMax); - number HCR_anchor // basis (denominator) bor inflection in control rule + number HCR_anchor // basis (denominator) for inflection in control rule. Select virgin SSB or benchmark SSB // SPAWN-RECR: define some spawning biomass and recruitment entities number SSB_virgin diff --git a/SS_write_ssnew.tpl b/SS_write_ssnew.tpl index 03eb531c..f5416543 100644 --- a/SS_write_ssnew.tpl +++ b/SS_write_ssnew.tpl @@ -1493,9 +1493,9 @@ FUNCTION void write_nucontrol() NuFore << HarvestPolicy << " # Control rule method (0: none; 1: ramp does catch=f(SSB), buffer on F; 2: ramp does F=f(SSB), buffer on F; 3: ramp does catch=f(SSB), buffer on catch; 4: ramp does F=f(SSB), buffer on catch) " << endl; NuFore << "# values for top, bottom and buffer exist, but not used when Policy=0" << endl; NuFore << H4010_top_rd << " # Control rule inflection for constant F (as frac of Bzero, e.g. 0.40); must be > control rule cutoff, or set to -1 to use Bmsy/SSB_unf " << endl; - NuFore << "# Also see HCR_anchor below" << endl; NuFore << H4010_bot << " # Control rule cutoff for no F (as frac of Bzero, e.g. 0.10) " << endl; NuFore << H4010_scale_rd << " # Buffer: enter Control rule target as fraction of Flimit (e.g. 0.75), negative value invokes list of [year, scalar] with filling from year to YrMax " << endl; + NuFore << "# Also see HCR_anchor below" << endl; if (H4010_scale_rd < 0) { j = H4010_scale_vec_rd.size() - 1; for (int s = 0; s <= j; s++) { From f0bfa6f0ccdf93aefe7e54f2645b9c8401154e0f Mon Sep 17 00:00:00 2001 From: Elizabeth Perl Date: Thu, 31 Oct 2024 17:00:23 -0400 Subject: [PATCH 22/22] go back to g++12.a --- Compile/Make_SS_warn.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compile/Make_SS_warn.bat b/Compile/Make_SS_warn.bat index af9b1430..f53510ee 100644 --- a/Compile/Make_SS_warn.bat +++ b/Compile/Make_SS_warn.bat @@ -28,6 +28,6 @@ tpl2cpp ss3 g++ -c -std=c++17 -O2 -D_FILE_OFFSET_BITS=64 -DUSE_ADMB_CONTRIBS -D_USE_MATH_DEFINES -I. -I"C:\ADMB-13.2\include" -I"C:\ADMB-13.2\include\contrib" -Wall -Wextra -o ss3.obj ss3.cpp -g++ -static -o ss3.exe ss3.obj "C:\ADMB-13.2\lib\libadmb-contrib-mingw64-g++13.a" +g++ -static -o ss3.exe ss3.obj "C:\ADMB-13.2\lib\libadmb-contrib-mingw64-g++12.a" dir *.exe