@@ -674,126 +674,125 @@ FUNCTION void Get_expected_values(const int y, const int t);
674674 SzFreqMethod = SzFreq_obs_hdr(iobs, 6);
675675 SzFreqMethod_seas = nseas * (SzFreqMethod - 1) + s; // index that combines sizefreqmethod and season and used in SzFreqTrans
676676 for (gg = 1; gg <= gender; gg++)
677- {
678- if (gg == 1)
679- {
680- z1 = 1;
681- z2 = nlength;
682- } // female
683- else
684- {
685- z1 = nlength1;
686- z2 = nlength2;
687- } // male
688-
689- // NOTE: wt_len_low is calculated separately for each growth pattern (GPat)
690- // but the code below still just uses GPat= 1 for calculation of the sizefreq transition matrix
691- dvector src_edges(1, nlength + 1); // +1 to create a dummy bin holding upper edge of the actual last bin
692- src_edges(1, nlength) = len_bins(1, nlength);
693- src_edges(nlength + 1) = src_edges(nlength) + (src_edges(nlength) - src_edges(nlength - 1));
694- dvar_vector dest_edges(1,SzFreq_Nbins(SzFreqMethod) + 1); // +1 to create a dummy bin holding upper edge of the actual last bin
695- dest_edges.initialize();
696- for (ibin = 1; ibin <= SzFreq_Nbins(SzFreqMethod); ibin++) {
697- dest_edges(ibin) = SzFreq_bins(SzFreqMethod, ibin);
698- }
699- if (SzFreq_Omit_Small(SzFreqMethod) < 0.0)
700- {
701- dest_edges(1) = 0.; // so src_bins smaller than first actual dest_bin are included in first bin
702- }
703-
704- dest_edges(SzFreq_Nbins(SzFreqMethod) + 1) = 99999.; // dest_edges(SzFreq_Nbins(SzFreqMethod)) + (dest_edges(SzFreq_Nbins(SzFreqMethod)) - dest_edges(SzFreq_Nbins(SzFreqMethod) - 1));
705- dvar_vector dest_comp(1,SzFreq_Nbins(SzFreqMethod)); // destination composition. one-sex at a time
706-
707- // convert dest_edges to cm
708- // as in the legacy method, this conversion is sex and season specific, but only uses Gpat = 1
709- switch (SzFreq_scale(SzFreqMethod)) // biomass vs. numbers are accumulated in the bins
710- {
711- case (1): // scale is kg
712- {
713- // fall thru to calcs in the lb case
714- }
715- case (2): // scale is lb, or fall thru from kg
716- {
717- // bin boundary in lb have already been converted to kg
718- // wt_len(s, gp) is potentially by season and by Gpat within sex. Here, only s= =1 and Gpat= =1 will be used. It will be sex-specific
719- // wt_len_low(s, GPat)(1, nlength) = wtlen_p(GPat, 1) * pow(len_bins2(1, nlength), wtlen_p(GPat, 2));
720- // W= a*L^b; so L = exp((ln(W)-ln(a))/B)
721- dvariable wtlen_a;
722- dvariable wtlen_b;
723- GPat = 1; // this means that any (unusual) use of multiple Gpatterns will still use biology of GPat 1 for szfreq purposes
724- // female parms are at 1, 2; males at 7,8
725- int parm_loc = 1 + (gg - 1) * 6;
726- wtlen_a = wtlen_p(GPat, parm_loc);
727- wtlen_b = wtlen_p(GPat, parm_loc + 1);
728- // if (do_once== 1) echoinput<< gg<< " parmloc " << parm_loc<< " a, b " << wtlen_a<< " " << wtlen_b<< endl;
729- if (MGparm_seas_effects(1) > 0 || MGparm_seas_effects(2) > 0) // get seasonal effect on wtlen parameters
730- {
731- wtlen_a *= wtlen_seas(s, GPat, parm_loc);
732- wtlen_b *= wtlen_seas(s, GPat, parm_loc + 1);
733- }
734- dest_edges = exp((log(dest_edges)-log(wtlen_a))/wtlen_b);
735- break ;
736- }
737- case (3): // scale is in cm
738- {
739- break ;
740- }
741- case 4: // scale is in inches. Already converted to cm in readdata. Relic feature for some ancient recreational fishery data
742- {
743- break ;
744- }
745- } // end calc of new dest_edges
746- if (do_once == 1) echoinput << " Szfreq_method: " << SzFreqMethod << " sex: " << gg << " dest_edges_in_cm " << dest_edges<< endl;
747-
748- dvar_vector pass_comp(z1, z2); // this gets males or females range according to z1, z2
749- pass_comp.initialize();
750- // if (do_once == 1) echoinput << " retain/discard obs type: " << SzFreq_obs_hdr(iobs, 5)<< endl;
751- switch (SzFreq_obs_hdr(iobs, 5)) // discard/retained partition
752- {
753- case (0):
754- {
755- pass_comp = exp_l_temp(z1, z2);
756- // SzFreq_exp(iobs) = trans(SzFreqTrans(SzFreqMethod_seas)) * exp_l_temp;
757- break ;
758- }
759- case (1):
760- {
761- pass_comp = exp_l_temp(z1, z2) - exp_l_temp_ret(z1, z2);
762- // SzFreq_exp(iobs) = trans(SzFreqTrans(SzFreqMethod_seas)) * (exp_l_temp - exp_l_temp_ret);
763- break ;
764- }
765- case (2):
766- {
767- pass_comp = exp_l_temp_ret(z1, z2);
768- // SzFreq_exp(iobs) = trans(SzFreqTrans(SzFreqMethod_seas)) * exp_l_temp_ret;
769- break ;
770- }
771- }
772- int use_GP;
773- use_GP = 1;
774- if (gg == 2) { use_GP += N_GP;} // because GPat is nested in sex
775- pass_comp.shift(1); // change index to 1
776- if (SzFreq_units(SzFreqMethod) == 1) // biomass is accumulated in the bins
777- {
778- pass_comp = elem_prod(pass_comp, wt_len(s, use_GP)); // where wtlen has been calculated using mid length of length bins
779- if (do_once == 1) echoinput<< " pass_comp_biomass: " << pass_comp<< endl;
780- // wt_len being referenced here by gg (sex), but actually is stored by gp which is sex and GPat. So, only the first Gpat gets used
781- }
782- // if (do_once == 1) echoinput<< " ready to call rebin, pass_comp: " << pass_comp<< endl<< " sum_pass: " << sum(pass_comp)<< endl;
783- dest_comp = rebin(SzFreq_Omit_Small(SzFreqMethod), src_edges, pass_comp, dest_edges);
784- // if (do_once == 1) echoinput << " dest_comp: " << dest_comp<< endl<< " sum_dest: " << sum(dest_comp)<< endl;
677+ {
678+ if (gg == 1)
679+ {
680+ z1 = 1;
681+ z2 = nlength;
682+ } // female
683+ else
684+ {
685+ z1 = nlength1;
686+ z2 = nlength2;
687+ } // male
688+
689+ // NOTE: wt_len_low is calculated separately for each growth pattern (GPat)
690+ // but the code below still just uses GPat= 1 for calculation of the sizefreq transition matrix
691+ dvector src_edges(1, nlength + 1); // +1 to create a dummy bin holding upper edge of the actual last bin
692+ src_edges(1, nlength) = len_bins(1, nlength);
693+ src_edges(nlength + 1) = src_edges(nlength) + (src_edges(nlength) - src_edges(nlength - 1));
694+ dvar_vector dest_edges(1,SzFreq_Nbins(SzFreqMethod) + 1); // +1 to create a dummy bin holding upper edge of the actual last bin
695+ dvar_vector dest_edges_wt(1,SzFreq_Nbins(SzFreqMethod) + 1);
696+ dest_edges.initialize();
697+ for (ibin = 1; ibin <= SzFreq_Nbins(SzFreqMethod); ibin++) {
698+ dest_edges(ibin) = SzFreq_bins(SzFreqMethod, ibin);
699+ dest_edges_wt(ibin) = dest_edges(ibin); // save in raw units
700+ }
701+ dest_edges(SzFreq_Nbins(SzFreqMethod) + 1) = 99999.;
702+ dest_edges_wt(ibin) = dest_edges_wt(ibin - 1) + (dest_edges_wt(ibin - 1) - dest_edges_wt(ibin - 2));
703+ if (SzFreq_Omit_Small(SzFreqMethod) < 0.0)
704+ {
705+ dest_edges(1) = 0.; // so src_bins smaller than first actual dest_bin are included in first bin
706+ }
785707
786- if ( gg == 1)
787- {
788- SzFreq_exp(iobs)(1, SzFreq_Nbins(SzFreqMethod)) = dest_comp;
789- }
790- else
791- {
792- dest_comp.shift(SzFreq_Nbins(SzFreqMethod) + 1);
793- SzFreq_exp(iobs)(SzFreq_Nbins(SzFreqMethod) + 1, 2 * SzFreq_Nbins(SzFreqMethod)) = dest_comp;
794- }
708+ dvar_vector dest_comp(1,SzFreq_Nbins(SzFreqMethod)); // destination composition. one-sex at a time
709+ // convert dest_edges to cm
710+ // as in the legacy method, this conversion is sex and season specific, but only uses Gpat = 1
711+ switch (SzFreq_scale(SzFreqMethod)) // biomass vs. numbers are accumulated in the bins
712+ {
713+ case (1): // scale is kg
714+ {
715+ // fall thru to calcs in the lb case
716+ }
717+ case (2): // scale is lb, or fall thru from kg
718+ {
719+ // bin boundary in lb have already been converted to kg
720+ // wt_len(s, gp) is potentially by season and by Gpat within sex. Here, only Gpat= =1 will be used. It will be sex-specific
721+ // W= a*L^b; so L = exp((ln(W)-ln(a))/B)
722+ dvariable wtlen_a;
723+ dvariable wtlen_b;
724+ GPat = 1; // this means that any (unusual) use of multiple Gpatterns will still use biology of GPat 1 for szfreq purposes
725+ // female parms are at 1, 2; males at 7,8
726+ int parm_loc = 1 + (gg - 1) * 6;
727+ wtlen_a = wtlen_p(GPat, parm_loc);
728+ wtlen_b = wtlen_p(GPat, parm_loc + 1);
729+ if (MGparm_seas_effects(1) > 0 || MGparm_seas_effects(2) > 0) // get seasonal effect on wtlen parameters
730+ {
731+ wtlen_a *= wtlen_seas(s, GPat, parm_loc);
732+ wtlen_b *= wtlen_seas(s, GPat, parm_loc + 1);
733+ }
734+ dest_edges = exp((log(dest_edges)-log(wtlen_a))/wtlen_b);
735+ break ;
736+ }
737+ case (3): // scale is in cm
738+ {
739+ break ;
740+ }
741+ case 4: // scale is in inches. Already converted to cm in readdata. Relic feature for some ancient recreational fishery data
742+ {
743+ break ;
744+ }
745+ } // end calc of new dest_edges
746+ if (do_once == 1) echoinput << " Szfreq_method: " << SzFreqMethod << " sex: " << gg << " dest_edges_converted_to_cm " << dest_edges<< endl;
795747
796- } // end gender loop
748+ dvar_vector pass_comp(z1, z2); // this gets males or females range according to z1, z2
749+ pass_comp.initialize();
750+ switch (SzFreq_obs_hdr(iobs, 5)) // discard/retained partition
751+ {
752+ case (0):
753+ {
754+ pass_comp = exp_l_temp(z1, z2);
755+ // SzFreq_exp(iobs) = trans(SzFreqTrans(SzFreqMethod_seas)) * exp_l_temp;
756+ break ;
757+ }
758+ case (1):
759+ {
760+ pass_comp = exp_l_temp(z1, z2) - exp_l_temp_ret(z1, z2);
761+ // SzFreq_exp(iobs) = trans(SzFreqTrans(SzFreqMethod_seas)) * (exp_l_temp - exp_l_temp_ret);
762+ break ;
763+ }
764+ case (2):
765+ {
766+ pass_comp = exp_l_temp_ret(z1, z2);
767+ // SzFreq_exp(iobs) = trans(SzFreqTrans(SzFreqMethod_seas)) * exp_l_temp_ret;
768+ break ;
769+ }
770+ }
771+ int use_GP;
772+ use_GP = 1;
773+ if (gg == 2) { use_GP += N_GP;} // because GPat is nested in sex; only GPat 1 bio gets used for szfreq data
774+ pass_comp.shift(1); // change index to 1
775+ if (SzFreq_units(SzFreqMethod) == 1) // biomass is accumulated in the bins
776+ {
777+ dvar_vector pass_src_wt(z1, z2+1);
778+ pass_src_wt(z1,z2) = wt_len_low(s, 1)(z1,z2); // just one sex' s range is passed
779+ pass_src_wt.shift(1); // change index to 1
780+ dest_comp = rebin_bio(src_edges, pass_comp, dest_edges, pass_src_wt, dest_edges_wt);
781+ }
782+ else
783+ {
784+ dest_comp = rebin(src_edges, pass_comp, dest_edges);
785+ }
786+ if( gg == 1)
787+ {
788+ SzFreq_exp(iobs)(1, SzFreq_Nbins(SzFreqMethod)) = dest_comp;
789+ }
790+ else
791+ {
792+ dest_comp.shift(SzFreq_Nbins(SzFreqMethod) + 1);
793+ SzFreq_exp(iobs)(SzFreq_Nbins(SzFreqMethod) + 1, 2 * SzFreq_Nbins(SzFreqMethod)) = dest_comp;
794+ }
795+ } // end gender loop
797796
798797 if (gender == 2)
799798 {
0 commit comments