-
Notifications
You must be signed in to change notification settings - Fork 0
/
WalleyeAgeStrucSpr.pro
4746 lines (4555 loc) · 354 KB
/
WalleyeAgeStrucSpr.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;########################################################################################################
PRO WalleyeAgeStrucSpr
; converting length to age for WI walleye data
; calcualted total production of WI walleye from spring surveys and tribal harvest from creel surveys
PRINT, 'a function to convert length to age for walleye stocks in Wisconsin, USA'
PRINT, 'Created: Apr 26, 2014'
PRINT, 'Updated: Jun 5, 2015'
;########################################################################################################
tstart = SYSTIME(/seconds);
; Identify a direcotry for exporting daily output of state variables as .csv file
CD, 'C:\Users\Daisuke\Desktop\Walleye_production_project\Walleye outputs'
; Input file paths
; 1.walleye length data from spring surveys
file = FILEPATH('walleye_length_PE_data3_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 2.Length key with lake-years
file2 = FILEPATH('walleye_age_length_key_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 3.Length key with lake only
file3 = FILEPATH('walleye_age_length_key_lake_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 4.Length key for region-wide
file4 = FILEPATH('walleye_age_length_key_region_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 5.YOY data
file5 = FILEPATH('walleye_YOY_data_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 6.Length data from creel surveys (Spearing)
file6 = FILEPATH('walleye_length_N_Spr_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 7.length-mass function parameters - lake-year-specific
file7 = FILEPATH('WI.wae_grow_lmem_ranef_lake-year_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; 8.length-mass function parameters - lake-specific
file8 = FILEPATH('WI.wae_grow_lmem_ranef_lake_IDL.csv', Root_dir = 'C:', SUBDIR = 'Users\Daisuke\Desktop\Walleye_production_project\Data')
; Check if the file is not blank
IF (N_ELEMENTS(file) EQ 0L) THEN MESSAGE, 'FILE is undefined'
;IF (N_ELEMENTS(maxcols) EQ 0L) THEN maxcols = 8L
; Read the file
; Input file order
; Define the data structure
;N = 272935L ; survey data
N = 289450L ; survey data - data set3
Nkey = 24864L ; lake-year-specific age-length key
Nkey2 = 13542L ; lake-specific age-length key
Nkey3 = 37L ; region-wide age-length key
Nyoy = 2340L
NSpr = 57326L ; harvested fish
Nlm = 1050L ; lake-year-specific length-mass parameters
Nlm2 = 508L ; lake-specific length-mass parameters
Length_Data = DOUBLE(FLTARR(14L, N))
Length_key = DOUBLE(FLTARR(93L, Nkey))
Length_key2 = DOUBLE(FLTARR(93L, Nkey2))
Length_key3 = DOUBLE(FLTARR(93L, Nkey3))
YOY_data = DOUBLE(FLTARR(6L, Nyoy))
Length_Spr_data = DOUBLE(FLTARR(10L, NSpr))
AgeArray = -1+FLTARR(N)
LengthArray = FLTARR(N)
AgeArraySpr = -1+FLTARR(NSpr)
LengthArraySpr = FLTARR(NSpr)
Length_mass_par = DOUBLE(FLTARR(6L, Nlm))
Length_mass_par2 = DOUBLE(FLTARR(3L, Nlm2))
; read input length & PE data
OPENR, lun, file, /GET_LUN
READF, lun, Length_Data;, FORMAT='(A17, x, I0)';
WBIC_Year = Length_Data[0, *]
WBIC = Length_Data[1, *]
SurveyYear = Length_Data[2, *]
Length = Length_Data[3, *]
Sex = Length_Data[4, *]
PE = Length_Data[5, *]
PEmodel = Length_Data[6, *]
LakeArea = Length_Data[7, *]
LakeSizeCode = Length_Data[8, *]
RegionCode = Length_Data[9, *]
LakeCode = Length_Data[10, *]
Longitude = Length_Data[11, *]
Latitude = Length_Data[12, *]
StockType = Length_Data[13, *]
FREE_LUN, lun
; read lake-year-specific age-length key data
OPENR, lun, file2, /GET_LUN
READF, lun, Length_key;, FORMAT='(A17, x, I0)';
FREE_LUN, lun
; read lake-specific age-length key data
OPENR, lun, file3, /GET_LUN
READF, lun, Length_key2;, FORMAT='(A17, x, I0)';
FREE_LUN, lun
; read region key
OPENR, lun, file4, /GET_LUN
READF, lun, Length_key3;, FORMAT='(A17, x, I0)';
FREE_LUN, lun
; read yoy data
OPENR, lun, file5, /GET_LUN
READF, lun, YOY_data;, FORMAT='(A17, x, I0)';
WBIC_Year_YOY = YOY_data[0, *]
WBIC_YOY = YOY_data[1, *]
SurveyYear_YOY = YOY_data[2, *]
Density_YOY = YOY_data[3, *]
Length_YOY = YOY_data[4, *]
Stock_YOY = YOY_data[5, *]
FREE_LUN, lun
; Spearing data
OPENR, lun, file6, /GET_LUN
READF, lun, Length_Spr_Data;, FORMAT='(A17, x, I0)';
WBIC_Year_spr = Length_spr_Data[0, *]
WBIC_spr = Length_spr_Data[1, *]
SurveyYear_spr = Length_spr_Data[2, *]
Length_spr = Length_spr_Data[3, *]
Sex_spr = Length_spr_Data[4, *]
adultPE_spr = Length_spr_Data[5, *]
HarvRate_spr = Length_spr_Data[6, *]
N_harv_spr = Length_spr_Data[7, *]
Season = Length_spr_Data[8, *]
LakeArea_spr = Length_spr_Data[9, *]
FREE_LUN, lun
; read lake-specific age-length key data
OPENR, lun, file7, /GET_LUN
READF, lun, Length_mass_par;, FORMAT='(A17, x, I0)';
FREE_LUN, lun
; read region key
OPENR, lun, file8, /GET_LUN
READF, lun, Length_mass_par2;, FORMAT='(A17, x, I0)';
FREE_LUN, lun
; Array for a cumulative number of lake-years/lakes with the length-age data
N_Lake_year_Wkeys = fltarr(1) ; number of lake years with lake-year-specific keys
N_Lake_Wkeys = fltarr(1) ; number of lake years iwth lake-specific keys
N_Lake_WOkeys = fltarr(1) ; number of lake years w/o keys
N_Lake_year_Spr = fltarr(1)
N_Lake_Spr = fltarr(1)
N_Lake_WOkeys_Spr = fltarr(1) ; number of lake-years w/o keys
N_Lake_year_LMfunc = fltarr(1) ; number of lake years with lake-year-specific length-mass fucntions
N_Lake_LMfunc = fltarr(1) ; number of lake years iwth lake-specific length-mass functions
N_state_LMfunc = fltarr(1) ; number of lake years w/o specfic length-mass fuctions
N_Lake_year_yoy = fltarr(1)
AgeLengthKeyLevel = 0.05 ; age-length key conversion threshold
AgeLengthKeyCheck_Spr1 = fltarr(1)
AgeLengthKeyCheck_Spr2 = fltarr(1)
logMeanLength = 2.612
LengthMassPar1all = 2.781
LengthMassPar2all = 3.177
; Find unique lake-years for production estiamtes
uniqWBIC_Year = WBIC_Year[UNIQ(WBIC_Year, SORT(WBIC_Year))] ; 568 lake years with potential estimates
PRINT, 'Total N of WBIC_years', n_elements(uniqWBIC_Year)
uniqWBIC = WBIC[UNIQ(WBIC, SORT(WBIC))] ; 264 lakes
PRINT, 'Total N of WBIC', n_elements(uniqWBIC)
; Create arrays for parameter outputs
paramset = FLTARR(234L, N_ELEMENTS(uniqWBIC_Year)) ; all fish
paramsetM = FLTARR(217L, N_ELEMENTS(uniqWBIC_Year)) ; males
paramsetF = FLTARR(217L, N_ELEMENTS(uniqWBIC_Year)) ; females
paramsetU = FLTARR(217L, N_ELEMENTS(uniqWBIC_Year)) ; unknowns
paramset_Spr = FLTARR(232L, N_ELEMENTS(uniqWBIC_Year)) ;
AgeBioProd = FLTARR(40L, N_ELEMENTS(uniqWBIC_Year)*27L) ; all fish
AgeBioProd_spr = FLTARR(25L, N_ELEMENTS(uniqWBIC_Year)*27L) ; harvested fish
LengthSelect_Data = FLTARR(20, N_ELEMENTS(uniqWBIC_Year)*37L) ; output array for size-selectivity
; Create arrays for size-at-age outputs
WAE_size_age = FLTARR(409L, N_ELEMENTS(uniqWBIC_Year)+1L) ; an array for mean size-at-age
WAE_size_age_all = FLTARR(198, MAX(SurveyYear)-MIN(SurveyYear)+1L)
;WAE_size_age_all = FLTARR(198, 40)
year = INDGEN(MAX(SurveyYear)-MIN(SurveyYear)+1L)+MIN(SurveyYear) ; an index for year
NumLengthBin = 37L ; numebr of length bins in a default array (NEED TO CORRECT)
Nageclass = 28 ; number of age classes
FishProb = FLTARR(27);, Nkey) ; probability of age in a given length bin
LengthDist = FLTARR(37L+7L, N_ELEMENTS(uniqWBIC_Year))
LengthDist_spr = FLTARR(37L+8L, N_ELEMENTS(uniqWBIC_Year))
LengthDist_spr2 = FLTARR(37L+8L, N_ELEMENTS(uniqWBIC_Year))
LengthDist_spr_PLUS = FLTARR(37L, N_ELEMENTS(uniqWBIC_Year))
Prop_LengthDist_spr_PLUS = FLTARR(N_ELEMENTS(uniqWBIC_Year))
WAE_length_bin=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_mean=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_binM=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_meanM=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_binF=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_meanF=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_binU=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_meanU=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_bin_Spr = fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
WAE_length_mean_Spr=fltarr(37*3L, N_ELEMENTS(uniqWBIC_Year)*NumLengthBin+37)
; Create arrays for population-level estimates
Total_production = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass = FLTARR(N_ELEMENTS(uniqWBIC_Year))
P_over_B = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_production_adult = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_adult = FLTARR(N_ELEMENTS(uniqWBIC_Year))
P_over_B_adult = FLTARR(N_ELEMENTS(uniqWBIC_Year))
;Output_production = FLTARR(50L, N_ELEMENTS(uniqWBIC_Year))
YOY_PE = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_production_adultM = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_production_adultF = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_production_adultU = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_adultM = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_adultF = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_adultU = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_productionM = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_productionF = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_productionU = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomassM = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomassF = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomassU = FLTARR(N_ELEMENTS(uniqWBIC_Year))
; Spearing
Total_production_Spr = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_Spr = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_Spr_direct = FLTARR(N_ELEMENTS(uniqWBIC_Year))
P_over_B_Spr = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Ecotroph = fltarr(N_ELEMENTS(uniqWBIC_Year))
Total_production_adult_Spr = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Total_biomass_adult_Spr = FLTARR(N_ELEMENTS(uniqWBIC_Year))
P_over_B_adult_Spr = FLTARR(N_ELEMENTS(uniqWBIC_Year))
Adult_ecotroph = fltarr(N_ELEMENTS(uniqWBIC_Year))
; Estimate age structure for each lake-year
; 1. Loop through WBIC_years
FOR i = 0L, N_ELEMENTS(uniqWBIC_Year)-1L DO BEGIN
PRINT, 'i', i
IF i EQ 0L THEN adj = 0 ; adjustment to the loop index for outputs
IF i GT 1L THEN adj = 1
; Index for unique WBIC-year walleye stocks spring surveys w/ body length data
INDEX_lengthdata = WHERE((WBIC_Year[*] EQ uniqWBIC_Year[i]), INDEX_lengthdatacount)
IF INDEX_lengthdatacount GT 0 THEN PRINT, 'WBIC_year', WBIC_Year[INDEX_lengthdata[0]]
IF INDEX_lengthdatacount GT 0 THEN BEGIN; if the length survey data exist...
PRINT, 'WBIC_year', WBIC_Year[INDEX_lengthdata[0]]
; Index for unique WBIC_year for walleye YOY
INDEX_YOYdata = WHERE((WBIC_year_YOY[*] EQ WBIC_Year[INDEX_lengthdata[0]]), INDEX_YOYdatacount)
paramset[210, i] = INDEX_YOYdatacount
stock = ' [U]' ; code for 'unknown stock type' used in the plot
IF INDEX_YOYdatacount GT 0 THEN BEGIN; if yoy data exist...
YOY_PE[i] = ROUND(Density_YOY[INDEX_YOYdata] * LakeArea[INDEX_lengthdata[0]])
print, 'YOY PE', YOY_PE[i]
paramset[215, i] = Stock_YOY[INDEX_YOYdata]
IF Stock_YOY[INDEX_YOYdata] EQ 0 THEN stock = ' [N]'
IF Stock_YOY[INDEX_YOYdata] EQ 1 THEN stock = ' [S]'
IF Stock_YOY[INDEX_YOYdata] EQ 2 THEN stock = ' [R]'
IF Stock_YOY[INDEX_YOYdata] EQ 3 THEN stock = ' [U]'
paramset[40, i] = Length_YOY[INDEX_YOYdata]
N_Lake_year_yoy = N_Lake_year_yoy + 1L
PRINT, 'N of lake-year with yoy data', N_Lake_year_yoy
ENDIF
IF INDEX_YOYdatacount LE 0 THEN PRINT, 'No YOY data available'
Sex_prod = Sex[INDEX_lengthdata] ; sex data, male=0; female=1; unknown=2
Length_prod = Length[INDEX_lengthdata] ; length data
FishAge = AgeArray[INDEX_lengthdata] ; assigned age
FishLength = LengthArray[INDEX_lengthdata] ; length check
;PRINT, 'FishAge', FishAge
;PRINT, 'length_prod', length[INDEX_lengthdata]
PRINT, 'Population demographics info:'
Male = WHERE(Sex_prod eq 0, malecount)
Female = WHERE(Sex_prod eq 1, femalecount)
unknown = WHERE(Sex_prod eq 2, unknowncount)
print, 'N of males in survey data', malecount
print, 'N of females in survey data', femalecount
print, 'N of unknown in survey data', unknowncount
; record basic demographic data for output files
paramset[0, i] = uniqWBIC_Year[i] ; WBIC_year (abbrev)
paramset[1, i] = WBIC[INDEX_lengthdata[0]] ; WBIC
paramset[2, i] = SurveyYear[INDEX_lengthdata[0]] ; year
paramset[231, i] = LakeSizeCode[INDEX_lengthdata[0]] ; lake size <500=0, otherwise, 1
paramset[232, i] = RegionCode[INDEX_lengthdata[0]] ; northeast=1, northwest=2, south=3
paramset[233, i] = LakeCode[INDEX_lengthdata[0]] ; code for size & region combined
paramset[3, i] = N_ELEMENTS(Length_prod) ; N of all fish
paramset[4, i] = malecount ; N of males
paramset[5, i] = femalecount ; N of females
paramset[6, i] = unknowncount ; N of unknowns
paramset[7, i] = MAX(length[INDEX_lengthdata]) ; max length for all fish
paramset[8, i] = MIN(length[INDEX_lengthdata]) ; min length for all fish
paramset[9, i] = MAX(length[INDEX_lengthdata[male]]) ; max length for males
paramset[10, i] = MIN(length[INDEX_lengthdata[male]]) ; min length for males
paramset[11, i] = MAX(length[INDEX_lengthdata[female]]) ; max length for females
paramset[12, i] = MIN(length[INDEX_lengthdata[female]]) ; min length for males
paramset[219, i] = MEAN(length[INDEX_lengthdata]) ; mean length for all fish
paramset[220, i] = STDDEV(length[INDEX_lengthdata]) ; SD length for all fish
paramset[221, i] = MEAN(length[INDEX_lengthdata[male]]) ; mean length for males
paramset[222, i] = STDDEV(length[INDEX_lengthdata[male]]) ; SD length for males
paramset[223, i] = MEAN(length[INDEX_lengthdata[female]]) ; mean length for females
paramset[224, i] = STDDEV(length[INDEX_lengthdata[female]]) ; SD length for females
print, 'N of fish', paramset[3, i], malecount+femalecount+unknowncount
print, 'WBIC', paramset[1, i]
print, 'Year', paramset[2, i]
print, 'Max length (mm)', Max(length[INDEX_lengthdata])
print, 'Min length (mm)', Min(length[INDEX_lengthdata])
print, 'Female max length (mm)', Max(length[INDEX_lengthdata[female]])
print, 'Female min length (mm)', Min(length[INDEX_lengthdata[female]])
print, 'Male max length (mm)', Max(length[INDEX_lengthdata[male]])
print, 'Male min length (mm)', Min(length[INDEX_lengthdata[male]])
; Assess length group distributions - ALL FISH
SizeLT100 = WHERE(Length_prod LT 100., SizeLT100count)
Size100to120 = WHERE((Length_prod GE 100.) AND (Length_prod LT 120.), Size100to120count)
Size120to140 = WHERE((Length_prod GE 120.) AND (Length_prod LT 140.), Size120to140count)
Size140to160 = WHERE((Length_prod GE 140.) AND (Length_prod LT 160.), Size140to160count)
Size160to180 = WHERE((Length_prod GE 160.) AND (Length_prod LT 180.), Size160to180count)
Size180to200 = WHERE((Length_prod GE 180.) AND (Length_prod LT 200.), Size180to200count)
Size200to220 = WHERE((Length_prod GE 200.) AND (Length_prod LT 220.), Size200to220count)
Size220to240 = WHERE((Length_prod GE 220.) AND (Length_prod LT 240.), Size220to240count)
Size240to260 = WHERE((Length_prod GE 240.) AND (Length_prod LT 260.), Size240to260count)
Size260to280 = WHERE((Length_prod GE 260.) AND (Length_prod LT 280.), Size260to280count)
Size280to300 = WHERE((Length_prod GE 280.) AND (Length_prod LT 300.), Size280to300count)
Size300to320 = WHERE((Length_prod GE 300.) AND (Length_prod LT 320.), Size300to320count)
Size320to340 = WHERE((Length_prod GE 320.) AND (Length_prod LT 340.), Size320to340count)
Size340to360 = WHERE((Length_prod GE 340.) AND (Length_prod LT 360.), Size340to360count)
Size360to380 = WHERE((Length_prod GE 360.) AND (Length_prod LT 380.), Size360to380count)
Size380to400 = WHERE((Length_prod GE 380.) AND (Length_prod LT 400.), Size380to400count)
Size400to420 = WHERE((Length_prod GE 400.) AND (Length_prod LT 420.), Size400to420count)
Size420to440 = WHERE((Length_prod GE 420.) AND (Length_prod LT 440.), Size420to440count)
Size440to460 = WHERE((Length_prod GE 440.) AND (Length_prod LT 460.), Size440to460count)
Size460to480 = WHERE((Length_prod GE 460.) AND (Length_prod LT 480.), Size460to480count)
Size480to500 = WHERE((Length_prod GE 480.) AND (Length_prod LT 500.), Size480to500count)
Size500to520 = WHERE((Length_prod GE 500.) AND (Length_prod LT 520.), Size500to520count)
Size520to540 = WHERE((Length_prod GE 520.) AND (Length_prod LT 540.), Size520to540count)
Size540to560 = WHERE((Length_prod GE 540.) AND (Length_prod LT 560.), Size540to560count)
Size560to580 = WHERE((Length_prod GE 560.) AND (Length_prod LT 580.), Size560to580count)
Size580to600 = WHERE((Length_prod GE 580.) AND (Length_prod LT 600.), Size580to600count)
Size600to620 = WHERE((Length_prod GE 600.) AND (Length_prod LT 620.), Size600to620count)
Size620to640 = WHERE((Length_prod GE 620.) AND (Length_prod LT 640.), Size620to640count)
Size640to660 = WHERE((Length_prod GE 640.) AND (Length_prod LT 660.), Size640to660count)
Size660to680 = WHERE((Length_prod GE 660.) AND (Length_prod LT 680.), Size660to680count)
Size680to700 = WHERE((Length_prod GE 680.) AND (Length_prod LT 700.), Size680to700count)
Size700to720 = WHERE((Length_prod GE 700.) AND (Length_prod LT 720.), Size700to720count)
Size720to740 = WHERE((Length_prod GE 720.) AND (Length_prod LT 740.), Size720to740count)
Size740to760 = WHERE((Length_prod GE 740.) AND (Length_prod LT 760.), Size740to760count)
Size760to780 = WHERE((Length_prod GE 760.) AND (Length_prod LT 780.), Size760to780count)
Size780to800 = WHERE((Length_prod GE 780.) AND (Length_prod LT 800.), Size780to800count)
SizeGE800 = WHERE((Length_prod GE 800.), SizeGE800count)
; size distribution of the length only data
LengthDist[0, i] = SizeLT100count
LengthDist[1, i] = Size100to120count
LengthDist[2, i] = Size120to140count
LengthDist[3, i] = Size140to160count
LengthDist[4, i] = Size160to180count
LengthDist[5, i] = Size180to200count
LengthDist[6, i] = Size200to220count
LengthDist[7, i] = Size220to240count
LengthDist[8, i] = Size240to260count
LengthDist[9, i] = Size260to280count
LengthDist[10, i] = Size280to300count
LengthDist[11, i] = Size300to320count
LengthDist[12, i] = Size320to340count
LengthDist[13, i] = Size340to360count
LengthDist[14, i] = Size360to380count
LengthDist[15, i] = Size380to400count
LengthDist[16, i] = Size400to420count
LengthDist[17, i] = Size420to440count
LengthDist[18, i] = Size440to460count
LengthDist[19, i] = Size460to480count
LengthDist[20, i] = Size480to500count
LengthDist[21, i] = Size500to520count
LengthDist[22, i] = Size520to540count
LengthDist[23, i] = Size540to560count
LengthDist[24, i] = Size560to580count
LengthDist[25, i] = Size580to600count
LengthDist[26, i] = Size600to620count
LengthDist[27, i] = Size620to640count
LengthDist[28, i] = Size640to660count
LengthDist[29, i] = Size660to680count
LengthDist[30, i] = Size680to700count
LengthDist[31, i] = Size700to720count
LengthDist[32, i] = Size720to740count
LengthDist[33, i] = Size740to760count
LengthDist[34, i] = Size760to780count
LengthDist[35, i] = Size780to800count
LengthDist[36, i] = SizeGE800count
PRINT, 'length distribution (bin size = 20mm)', LengthDist[0:36, i]
LengthDist[37, i] = paramset[1, i] ; WBIC
LengthDist[38, i] = paramset[2, i] ; year
LengthDist[39, i] = paramset[3, i] ; sample size
LengthDist[40, i] = PE[INDEX_lengthdata[0]] ; adult PE
LengthDist[41, i] = paramset[4, i]
LengthDist[42, i] = paramset[5, i]
LengthDist[43, i] = paramset[6, i] ;
; Assign fish to length groups - MALES
SizeLT100M = WHERE(Length_prod[male] LT 100., SizeLT100Mcount)
Size100to120M = WHERE((Length_prod[male] GE 100.) AND (Length_prod[male] LT 120.), Size100to120Mcount)
Size120to140M = WHERE((Length_prod[male] GE 120.) AND (Length_prod[male] LT 140.), Size120to140Mcount)
Size140to160M = WHERE((Length_prod[male] GE 140.) AND (Length_prod[male] LT 160.), Size140to160Mcount)
Size160to180M = WHERE((Length_prod[male] GE 160.) AND (Length_prod[male] LT 180.), Size160to180Mcount)
Size180to200M = WHERE((Length_prod[male] GE 180.) AND (Length_prod[male] LT 200.), Size180to200Mcount)
Size200to220M = WHERE((Length_prod[male] GE 200.) AND (Length_prod[male] LT 220.), Size200to220Mcount)
Size220to240M = WHERE((Length_prod[male] GE 220.) AND (Length_prod[male] LT 240.), Size220to240Mcount)
Size240to260M = WHERE((Length_prod[male] GE 240.) AND (Length_prod[male] LT 260.), Size240to260Mcount)
Size260to280M = WHERE((Length_prod[male] GE 260.) AND (Length_prod[male] LT 280.), Size260to280Mcount)
Size280to300M = WHERE((Length_prod[male] GE 280.) AND (Length_prod[male] LT 300.), Size280to300Mcount)
Size300to320M = WHERE((Length_prod[male] GE 300.) AND (Length_prod[male] LT 320.), Size300to320Mcount)
Size320to340M = WHERE((Length_prod[male] GE 320.) AND (Length_prod[male] LT 340.), Size320to340Mcount)
Size340to360M = WHERE((Length_prod[male] GE 340.) AND (Length_prod[male] LT 360.), Size340to360Mcount)
Size360to380M = WHERE((Length_prod[male] GE 360.) AND (Length_prod[male] LT 380.), Size360to380Mcount)
Size380to400M = WHERE((Length_prod[male] GE 380.) AND (Length_prod[male] LT 400.), Size380to400Mcount)
Size400to420M = WHERE((Length_prod[male] GE 400.) AND (Length_prod[male] LT 420.), Size400to420Mcount)
Size420to440M = WHERE((Length_prod[male] GE 420.) AND (Length_prod[male] LT 440.), Size420to440Mcount)
Size440to460M = WHERE((Length_prod[male] GE 440.) AND (Length_prod[male] LT 460.), Size440to460Mcount)
Size460to480M = WHERE((Length_prod[male] GE 460.) AND (Length_prod[male] LT 480.), Size460to480Mcount)
Size480to500M = WHERE((Length_prod[male] GE 480.) AND (Length_prod[male] LT 500.), Size480to500Mcount)
Size500to520M = WHERE((Length_prod[male] GE 500.) AND (Length_prod[male] LT 520.), Size500to520Mcount)
Size520to540M = WHERE((Length_prod[male] GE 520.) AND (Length_prod[male] LT 540.), Size520to540Mcount)
Size540to560M = WHERE((Length_prod[male] GE 540.) AND (Length_prod[male] LT 560.), Size540to560Mcount)
Size560to580M = WHERE((Length_prod[male] GE 560.) AND (Length_prod[male] LT 580.), Size560to580Mcount)
Size580to600M = WHERE((Length_prod[male] GE 580.) AND (Length_prod[male] LT 600.), Size580to600Mcount)
Size600to620M = WHERE((Length_prod[male] GE 600.) AND (Length_prod[male] LT 620.), Size600to620Mcount)
Size620to640M = WHERE((Length_prod[male] GE 620.) AND (Length_prod[male] LT 640.), Size620to640Mcount)
Size640to660M = WHERE((Length_prod[male] GE 640.) AND (Length_prod[male] LT 660.), Size640to660Mcount)
Size660to680M = WHERE((Length_prod[male] GE 660.) AND (Length_prod[male] LT 680.), Size660to680Mcount)
Size680to700M = WHERE((Length_prod[male] GE 680.) AND (Length_prod[male] LT 700.), Size680to700Mcount)
Size700to720M = WHERE((Length_prod[male] GE 700.) AND (Length_prod[male] LT 720.), Size700to720Mcount)
Size720to740M = WHERE((Length_prod[male] GE 720.) AND (Length_prod[male] LT 740.), Size720to740Mcount)
Size740to760M = WHERE((Length_prod[male] GE 740.) AND (Length_prod[male] LT 760.), Size740to760Mcount)
Size760to780M = WHERE((Length_prod[male] GE 760.) AND (Length_prod[male] LT 780.), Size760to780Mcount)
Size780to800M = WHERE((Length_prod[male] GE 780.) AND (Length_prod[male] LT 800.), Size780to800Mcount)
SizeGE800M = WHERE((Length_prod[male] GE 800.), SizeGE800Mcount)
; Assign fish to length groups - FEMALES
SizeLT100F = WHERE(Length_prod[female] LT 100., SizeLT100Fcount)
Size100to120F = WHERE((Length_prod[female] GE 100.) AND (Length_prod[female] LT 120.), Size100to120Fcount)
Size120to140F = WHERE((Length_prod[female] GE 120.) AND (Length_prod[female] LT 140.), Size120to140Fcount)
Size140to160F = WHERE((Length_prod[female] GE 140.) AND (Length_prod[female] LT 160.), Size140to160Fcount)
Size160to180F = WHERE((Length_prod[female] GE 160.) AND (Length_prod[female] LT 180.), Size160to180Fcount)
Size180to200F = WHERE((Length_prod[female] GE 180.) AND (Length_prod[female] LT 200.), Size180to200Fcount)
Size200to220F = WHERE((Length_prod[female] GE 200.) AND (Length_prod[female] LT 220.), Size200to220Fcount)
Size220to240F = WHERE((Length_prod[female] GE 220.) AND (Length_prod[female] LT 240.), Size220to240Fcount)
Size240to260F = WHERE((Length_prod[female] GE 240.) AND (Length_prod[female] LT 260.), Size240to260Fcount)
Size260to280F = WHERE((Length_prod[female] GE 260.) AND (Length_prod[female] LT 280.), Size260to280Fcount)
Size280to300F = WHERE((Length_prod[female] GE 280.) AND (Length_prod[female] LT 300.), Size280to300Fcount)
Size300to320F = WHERE((Length_prod[female] GE 300.) AND (Length_prod[female] LT 320.), Size300to320Fcount)
Size320to340F = WHERE((Length_prod[female] GE 320.) AND (Length_prod[female] LT 340.), Size320to340Fcount)
Size340to360F = WHERE((Length_prod[female] GE 340.) AND (Length_prod[female] LT 360.), Size340to360Fcount)
Size360to380F = WHERE((Length_prod[female] GE 360.) AND (Length_prod[female] LT 380.), Size360to380Fcount)
Size380to400F = WHERE((Length_prod[female] GE 380.) AND (Length_prod[female] LT 400.), Size380to400Fcount)
Size400to420F = WHERE((Length_prod[female] GE 400.) AND (Length_prod[female] LT 420.), Size400to420Fcount)
Size420to440F = WHERE((Length_prod[female] GE 420.) AND (Length_prod[female] LT 440.), Size420to440Fcount)
Size440to460F = WHERE((Length_prod[female] GE 440.) AND (Length_prod[female] LT 460.), Size440to460Fcount)
Size460to480F = WHERE((Length_prod[female] GE 460.) AND (Length_prod[female] LT 480.), Size460to480Fcount)
Size480to500F = WHERE((Length_prod[female] GE 480.) AND (Length_prod[female] LT 500.), Size480to500Fcount)
Size500to520F = WHERE((Length_prod[female] GE 500.) AND (Length_prod[female] LT 520.), Size500to520Fcount)
Size520to540F = WHERE((Length_prod[female] GE 520.) AND (Length_prod[female] LT 540.), Size520to540Fcount)
Size540to560F = WHERE((Length_prod[female] GE 540.) AND (Length_prod[female] LT 560.), Size540to560Fcount)
Size560to580F = WHERE((Length_prod[female] GE 560.) AND (Length_prod[female] LT 580.), Size560to580Fcount)
Size580to600F = WHERE((Length_prod[female] GE 580.) AND (Length_prod[female] LT 600.), Size580to600Fcount)
Size600to620F = WHERE((Length_prod[female] GE 600.) AND (Length_prod[female] LT 620.), Size600to620Fcount)
Size620to640F = WHERE((Length_prod[female] GE 620.) AND (Length_prod[female] LT 640.), Size620to640Fcount)
Size640to660F = WHERE((Length_prod[female] GE 640.) AND (Length_prod[female] LT 660.), Size640to660Fcount)
Size660to680F = WHERE((Length_prod[female] GE 660.) AND (Length_prod[female] LT 680.), Size660to680Fcount)
Size680to700F = WHERE((Length_prod[female] GE 680.) AND (Length_prod[female] LT 700.), Size680to700Fcount)
Size700to720F = WHERE((Length_prod[female] GE 700.) AND (Length_prod[female] LT 720.), Size700to720Fcount)
Size720to740F = WHERE((Length_prod[female] GE 720.) AND (Length_prod[female] LT 740.), Size720to740Fcount)
Size740to760F = WHERE((Length_prod[female] GE 740.) AND (Length_prod[female] LT 760.), Size740to760Fcount)
Size760to780F = WHERE((Length_prod[female] GE 760.) AND (Length_prod[female] LT 780.), Size760to780Fcount)
Size780to800F = WHERE((Length_prod[female] GE 780.) AND (Length_prod[female] LT 800.), Size780to800Fcount)
SizeGE800F = WHERE((Length_prod[female] GE 800.), SizeGE800Fcount)
; Assign fish to length groups - UNKNOWNS
SizeLT100U = WHERE(Length_prod[unknown] LT 100., SizeLT100Ucount)
Size100to120U = WHERE((Length_prod[unknown] GE 100.) AND (Length_prod[unknown] LT 120.), Size100to120Ucount)
Size120to140U = WHERE((Length_prod[unknown] GE 120.) AND (Length_prod[unknown] LT 140.), Size120to140Ucount)
Size140to160U = WHERE((Length_prod[unknown] GE 140.) AND (Length_prod[unknown] LT 160.), Size140to160Ucount)
Size160to180U = WHERE((Length_prod[unknown] GE 160.) AND (Length_prod[unknown] LT 180.), Size160to180Ucount)
Size180to200U = WHERE((Length_prod[unknown] GE 180.) AND (Length_prod[unknown] LT 200.), Size180to200Ucount)
Size200to220U = WHERE((Length_prod[unknown] GE 200.) AND (Length_prod[unknown] LT 220.), Size200to220Ucount)
Size220to240U = WHERE((Length_prod[unknown] GE 220.) AND (Length_prod[unknown] LT 240.), Size220to240Ucount)
Size240to260U = WHERE((Length_prod[unknown] GE 240.) AND (Length_prod[unknown] LT 260.), Size240to260Ucount)
Size260to280U = WHERE((Length_prod[unknown] GE 260.) AND (Length_prod[unknown] LT 280.), Size260to280Ucount)
Size280to300U = WHERE((Length_prod[unknown] GE 280.) AND (Length_prod[unknown] LT 300.), Size280to300Ucount)
Size300to320U = WHERE((Length_prod[unknown] GE 300.) AND (Length_prod[unknown] LT 320.), Size300to320Ucount)
Size320to340U = WHERE((Length_prod[unknown] GE 320.) AND (Length_prod[unknown] LT 340.), Size320to340Ucount)
Size340to360U = WHERE((Length_prod[unknown] GE 340.) AND (Length_prod[unknown] LT 360.), Size340to360Ucount)
Size360to380U = WHERE((Length_prod[unknown] GE 360.) AND (Length_prod[unknown] LT 380.), Size360to380Ucount)
Size380to400U = WHERE((Length_prod[unknown] GE 380.) AND (Length_prod[unknown] LT 400.), Size380to400Ucount)
Size400to420U = WHERE((Length_prod[unknown] GE 400.) AND (Length_prod[unknown] LT 420.), Size400to420Ucount)
Size420to440U = WHERE((Length_prod[unknown] GE 420.) AND (Length_prod[unknown] LT 440.), Size420to440Ucount)
Size440to460U = WHERE((Length_prod[unknown] GE 440.) AND (Length_prod[unknown] LT 460.), Size440to460Ucount)
Size460to480U = WHERE((Length_prod[unknown] GE 460.) AND (Length_prod[unknown] LT 480.), Size460to480Ucount)
Size480to500U = WHERE((Length_prod[unknown] GE 480.) AND (Length_prod[unknown] LT 500.), Size480to500Ucount)
Size500to520U = WHERE((Length_prod[unknown] GE 500.) AND (Length_prod[unknown] LT 520.), Size500to520Ucount)
Size520to540U = WHERE((Length_prod[unknown] GE 520.) AND (Length_prod[unknown] LT 540.), Size520to540Ucount)
Size540to560U = WHERE((Length_prod[unknown] GE 540.) AND (Length_prod[unknown] LT 560.), Size540to560Ucount)
Size560to580U = WHERE((Length_prod[unknown] GE 560.) AND (Length_prod[unknown] LT 580.), Size560to580Ucount)
Size580to600U = WHERE((Length_prod[unknown] GE 580.) AND (Length_prod[unknown] LT 600.), Size580to600Ucount)
Size600to620U = WHERE((Length_prod[unknown] GE 600.) AND (Length_prod[unknown] LT 620.), Size600to620Ucount)
Size620to640U = WHERE((Length_prod[unknown] GE 620.) AND (Length_prod[unknown] LT 640.), Size620to640Ucount)
Size640to660U = WHERE((Length_prod[unknown] GE 640.) AND (Length_prod[unknown] LT 660.), Size640to660Ucount)
Size660to680U = WHERE((Length_prod[unknown] GE 660.) AND (Length_prod[unknown] LT 680.), Size660to680Ucount)
Size680to700U = WHERE((Length_prod[unknown] GE 680.) AND (Length_prod[unknown] LT 700.), Size680to700Ucount)
Size700to720U = WHERE((Length_prod[unknown] GE 700.) AND (Length_prod[unknown] LT 720.), Size700to720Ucount)
Size720to740U = WHERE((Length_prod[unknown] GE 720.) AND (Length_prod[unknown] LT 740.), Size720to740Ucount)
Size740to760U = WHERE((Length_prod[unknown] GE 740.) AND (Length_prod[unknown] LT 760.), Size740to760Ucount)
Size760to780U = WHERE((Length_prod[unknown] GE 760.) AND (Length_prod[unknown] LT 780.), Size760to780Ucount)
Size780to800U = WHERE((Length_prod[unknown] GE 780.) AND (Length_prod[unknown] LT 800.), Size780to800Ucount)
SizeGE800U = WHERE((Length_prod[unknown] GE 800.), SizeGE800Ucount)
; Assign arrays to age-length keys for lake-years
WBIC_year_key = Length_key[0, *]
WBIC_key = Length_key[1, *]
sample_year_key = Length_key[2, *]
total_N_fish = Length_key[3, *]
max_length = Length_key[4, *]
min_length = Length_key[5, *]
max_age = Length_key[6, *]
min_age = Length_key[7, *]
Length_bin_low = Length_key[8, *]
Length_N_fish = Length_key[9, *]
uniqWBIC_Year_key = WBIC_Year_key[UNIQ(WBIC_Year_key, SORT(WBIC_Year_key))]
;PRINT, 'Total N of WBIC_year_key', n_elements(uniqWBIC_Year_key)
uniqWBIC_key = WBIC_key[UNIQ(WBIC_key, SORT(WBIC_key))]
;PRINT, 'Total N of WBIC_Key', n_elements(uniqWBIC_key)
; probability for each age; ALL FISH (length_key 10-36)
prop_age0 = Length_key[10, *]
prop_age1 = Length_key[11, *]
prop_age2 = Length_key[12, *]
prop_age3 = Length_key[13, *]
prop_age4 = Length_key[14, *]
prop_age5 = Length_key[15, *]
prop_age6 = Length_key[16, *]
prop_age7 = Length_key[17, *]
prop_age8 = Length_key[18, *]
prop_age9 = Length_key[19, *]
prop_age10 = Length_key[20, *]
prop_age11 = Length_key[21, *]
prop_age12 = Length_key[22, *]
prop_age13 = Length_key[23, *]
prop_age14 = Length_key[24, *]
prop_age15 = Length_key[25, *]
prop_age16 = Length_key[26, *]
prop_age17 = Length_key[27, *]
prop_age18 = Length_key[28, *]
prop_age19 = Length_key[29, *]
prop_age20 = Length_key[30, *]
prop_age21 = Length_key[31, *]
prop_age22 = Length_key[32, *]
prop_age23 = Length_key[33, *]
prop_age24 = Length_key[34, *]
prop_age25 = Length_key[35, *]
prop_age26 = Length_key[36, *]
; MALES
Length_N_fishM = Length_key[37, *]
prop_age0M = Length_key[38, *]
prop_age1M = Length_key[39, *]
prop_age2M = Length_key[40, *]
prop_age3M = Length_key[41, *]
prop_age4M = Length_key[42, *]
prop_age5M = Length_key[43, *]
prop_age6M = Length_key[44, *]
prop_age7M = Length_key[45, *]
prop_age8M = Length_key[46, *]
prop_age9M = Length_key[47, *]
prop_age10M = Length_key[48, *]
prop_age11M = Length_key[49, *]
prop_age12M = Length_key[50, *]
prop_age13M = Length_key[51, *]
prop_age14M = Length_key[52, *]
prop_age15M = Length_key[53, *]
prop_age16M = Length_key[54, *]
prop_age17M = Length_key[55, *]
prop_age18M = Length_key[56, *]
prop_age19M = Length_key[57, *]
prop_age20M = Length_key[58, *]
prop_age21M = Length_key[59, *]
prop_age22M = Length_key[60, *]
prop_age23M = Length_key[61, *]
prop_age24M = Length_key[62, *]
prop_age25M = Length_key[63, *]
prop_age26M = Length_key[64, *]
; FEMALES
Length_N_fishF = Length_key[65, *]
prop_age0F = Length_key[66, *]
prop_age1F = Length_key[67, *]
prop_age2F = Length_key[68, *]
prop_age3F = Length_key[69, *]
prop_age4F = Length_key[70, *]
prop_age5F = Length_key[71, *]
prop_age6F = Length_key[72, *]
prop_age7F = Length_key[73, *]
prop_age8F = Length_key[74, *]
prop_age9F = Length_key[75, *]
prop_age10F = Length_key[76, *]
prop_age11F = Length_key[77, *]
prop_age12F = Length_key[78, *]
prop_age13F = Length_key[79, *]
prop_age14F = Length_key[80, *]
prop_age15F = Length_key[81, *]
prop_age16F = Length_key[82, *]
prop_age17F = Length_key[83, *]
prop_age18F = Length_key[84, *]
prop_age19F = Length_key[85, *]
prop_age20F = Length_key[86, *]
prop_age21F = Length_key[87, *]
prop_age22F = Length_key[88, *]
prop_age23F = Length_key[89, *]
prop_age24F = Length_key[90, *]
prop_age25F = Length_key[91, *]
prop_age26F = Length_key[92, *]
; ; array index for WBIC years w/ key
; INDEX_lengthdata2 = WHERE((WBIC_year_key[*] EQ WBIC_Year[INDEX_lengthdata[0]]), INDEX_lengthdata2count)
; IF INDEX_lengthdata2count GT 0 THEN BEGIN; if WBIC_year key exists...
; PRINT, 'WBIC_year', WBIC_year_key[INDEX_lengthdata2[0]]
; ; Check if age-key for all fish exist for size bins with data...
;########################################################
;#Calculate harvested fish age structure for production #
;########################################################
; Array index for SPEARING data
INDEX_lengthdataSpr = WHERE((WBIC_year_Spr[*] EQ WBIC_year[INDEX_lengthdata[0]]), INDEX_lengthdataSprcount)
IF INDEX_lengthdataSprcount GT 0 THEN BEGIN ; if Spearing data exist...
PRINT, 'WBIC_Spr', WBIC_year_Spr[INDEX_lengthdataSpr[0]]
PRINT, 'Harvest data availabile'
Length_prod_Spr = Length_Spr[INDEX_lengthdataSpr] ; WBIC_year data
Sex_prod_spr = Sex_spr[INDEX_lengthdataSpr] ; sex data, male=0; female=1; unknown=2
FishAgeSpr = AgeArraySpr[INDEX_lengthdataSpr] ; assigned age
FishLengthSpr = LengthArraySpr[INDEX_lengthdataSpr] ; length check
PRINT, 'Length_prod_Spr', Length_Spr[INDEX_lengthdataSpr]
paramset_Spr[0, i] = uniqWBIC_Year[i] ; WBIC_year (abbrev)
paramset_Spr[1, i] = WBIC_Spr[INDEX_lengthdataSpr[0]] ; WBIC
paramset_Spr[2, i] = SurveyYear_Spr[INDEX_lengthdataSpr[0]] ; year
paramset_Spr[3, i] = N_ELements(Length_prod_Spr) ; N of fish
paramset_Spr[7, i] = Max(length_Spr[INDEX_lengthdataSpr])
paramset_Spr[8, i] = Min(length_Spr[INDEX_lengthdataSpr])
Male_spr = WHERE(Sex_prod_spr eq 0, male_sprcount)
Female_spr = WHERE(Sex_prod_spr eq 1, female_sprcount)
unknown_spr = WHERE(Sex_prod_spr eq 2, unknown_sprcount)
print, 'N of males in tribal data', male_sprcount
print, 'N of females in tribal data', female_sprcount
print, 'N of unknown in tribal data', unknown_sprcount
paramset_Spr[4, i] = male_sprcount
paramset_Spr[5, i] = female_sprcount
paramset_Spr[6, i] = unknown_sprcount
paramset_Spr[218, i] = MEAN(length_Spr[INDEX_lengthdataSpr]) ; mean length for all fish
paramset_Spr[219, i] = STDDEV(length_Spr[INDEX_lengthdataSpr]) ; SD length for all fish
paramset_Spr[220, i] = MEAN(length_Spr[INDEX_lengthdataSpr[Male_spr]]) ; mean length for males
paramset_Spr[221, i] = STDDEV(length_Spr[INDEX_lengthdataSpr[Male_spr]]) ; SD length for males
paramset_Spr[222, i] = MEAN(length_Spr[INDEX_lengthdataSpr[Female_spr]]) ; mean length for females
paramset_Spr[223, i] = STDDEV(length_Spr[INDEX_lengthdataSpr[Female_spr]]); SD length for females
print, 'N of fish', paramset_Spr[3, i] ;, malecount+femalecount+unknowncount
print, 'WBIC', paramset_Spr[1, i]
print, 'Year', paramset_Spr[2, i]
print, 'Max length (mm)', Max(length_Spr[INDEX_lengthdataSpr])
print, 'Min length (mm)', Min(length_Spr[INDEX_lengthdataSpr])
; Directed estiamted total biomass (kg/km2) - sum of individual masses
Total_biomass_Spr_direct[i] $
= TOTAL(1.5868E-006*Length_Spr[INDEX_lengthdataSpr]^3.2962) $
/LakeArea[INDEX_lengthdata[0]]*1000000./1000.
PRINT, 'Directedly estimated Total harvested biomass (kg/km2)'
PRINT, Total_biomass_Spr_direct[i]
paramset_Spr[203, i] = Total_biomass_Spr_direct[i]
; Lake-year-specific length-mass relations
INDEX_lengthmass = WHERE((Length_mass_par[3, *] EQ WBIC_Year[INDEX_lengthdata[0]]), INDEX_lengthmasscount)
INDEX_lengthmass2 = WHERE((Length_mass_par2[0, *] EQ WBIC[INDEX_lengthdata[0]]), INDEX_lengthmass2count)
LengthMassPar1a = string(Length_mass_par[4, INDEX_lengthmass], Format='(D0.3)')
LengthMassPar1b = string(Length_mass_par2[1, INDEX_lengthmass2], Format='(D0.3)')
print,'LengthMassPar1',LengthMassPar1a,LengthMassPar1b
IF (INDEX_lengthmasscount GT 0) THEN BEGIN
LengthMassPar1 = LengthMassPar1all+LengthMassPar1a
LengthMassPar2 = LengthMassPar2all
LengthMassParCheck = 1
ENDIF
IF (INDEX_lengthmasscount LE 0) AND (INDEX_lengthmass2count GT 0) THEN BEGIN
LengthMassPar1 = LengthMassPar1all+LengthMassPar1b
LengthMassPar2 = LengthMassPar2all
LengthMassParCheck = 2
ENDIF
IF (INDEX_lengthmasscount LE 0) AND (INDEX_lengthmass2count LE 0) THEN BEGIN
LengthMassPar1 = LengthMassPar1all
LengthMassPar2 = LengthMassPar2all
LengthMassParCheck = 3
ENDIF
PRINT, 'LengthMass params=', LengthMassParCheck
PRINT, LengthMassPar1, LengthMassPar2
paramset_Spr[231, i] = LengthMassParCheck; age-length key type
; Population-mean body mass
Mean_mass_lakeyear = 10.^(LengthMassPar1 + LengthMassPar2*(ALOG10(Length_Spr[INDEX_lengthdataSpr])-logMeanLength) + 5.006e-03*0.5)
PRINT, 'Mean_mass_lakeyear', Mean_mass_lakeyear
Total_biomass_Spr_direct[i] $
= TOTAL(Mean_mass_lakeyear) $
/LakeArea[INDEX_lengthdata[0]]*1000000./1000.
PRINT, 'Directedly estimated Total harvested biomass (kg/km2)'
PRINT, Total_biomass_Spr_direct[i]
paramset_Spr[203, i] = Total_biomass_Spr_direct[i]
; Allocate fish to group groups - ALL FISH
SizeLT100_Spr = WHERE(Length_prod_Spr LT 100., SizeLT100_Sprcount)
Size100to120_Spr = WHERE((Length_prod_Spr GE 100.) AND (Length_prod_Spr LT 120.), Size100to120_Sprcount)
Size120to140_Spr = WHERE((Length_prod_Spr GE 120.) AND (Length_prod_Spr LT 140.), Size120to140_Sprcount)
Size140to160_Spr = WHERE((Length_prod_Spr GE 140.) AND (Length_prod_Spr LT 160.), Size140to160_Sprcount)
Size160to180_Spr = WHERE((Length_prod_Spr GE 160.) AND (Length_prod_Spr LT 180.), Size160to180_Sprcount)
Size180to200_Spr = WHERE((Length_prod_Spr GE 180.) AND (Length_prod_Spr LT 200.), Size180to200_Sprcount)
Size200to220_Spr = WHERE((Length_prod_Spr GE 200.) AND (Length_prod_Spr LT 220.), Size200to220_Sprcount)
Size220to240_Spr = WHERE((Length_prod_Spr GE 220.) AND (Length_prod_Spr LT 240.), Size220to240_Sprcount)
Size240to260_Spr = WHERE((Length_prod_Spr GE 240.) AND (Length_prod_Spr LT 260.), Size240to260_Sprcount)
Size260to280_Spr = WHERE((Length_prod_Spr GE 260.) AND (Length_prod_Spr LT 280.), Size260to280_Sprcount)
Size280to300_Spr = WHERE((Length_prod_Spr GE 280.) AND (Length_prod_Spr LT 300.), Size280to300_Sprcount)
Size300to320_Spr = WHERE((Length_prod_Spr GE 300.) AND (Length_prod_Spr LT 320.), Size300to320_Sprcount)
Size320to340_Spr = WHERE((Length_prod_Spr GE 320.) AND (Length_prod_Spr LT 340.), Size320to340_Sprcount)
Size340to360_Spr = WHERE((Length_prod_Spr GE 340.) AND (Length_prod_Spr LT 360.), Size340to360_Sprcount)
Size360to380_Spr = WHERE((Length_prod_Spr GE 360.) AND (Length_prod_Spr LT 380.), Size360to380_Sprcount)
Size380to400_Spr = WHERE((Length_prod_Spr GE 380.) AND (Length_prod_Spr LT 400.), Size380to400_Sprcount)
Size400to420_Spr = WHERE((Length_prod_Spr GE 400.) AND (Length_prod_Spr LT 420.), Size400to420_Sprcount)
Size420to440_Spr = WHERE((Length_prod_Spr GE 420.) AND (Length_prod_Spr LT 440.), Size420to440_Sprcount)
Size440to460_Spr = WHERE((Length_prod_Spr GE 440.) AND (Length_prod_Spr LT 460.), Size440to460_Sprcount)
Size460to480_Spr = WHERE((Length_prod_Spr GE 460.) AND (Length_prod_Spr LT 480.), Size460to480_Sprcount)
Size480to500_Spr = WHERE((Length_prod_Spr GE 480.) AND (Length_prod_Spr LT 500.), Size480to500_Sprcount)
Size500to520_Spr = WHERE((Length_prod_Spr GE 500.) AND (Length_prod_Spr LT 520.), Size500to520_Sprcount)
Size520to540_Spr = WHERE((Length_prod_Spr GE 520.) AND (Length_prod_Spr LT 540.), Size520to540_Sprcount)
Size540to560_Spr = WHERE((Length_prod_Spr GE 540.) AND (Length_prod_Spr LT 560.), Size540to560_Sprcount)
Size560to580_Spr = WHERE((Length_prod_Spr GE 560.) AND (Length_prod_Spr LT 580.), Size560to580_Sprcount)
Size580to600_Spr = WHERE((Length_prod_Spr GE 580.) AND (Length_prod_Spr LT 600.), Size580to600_Sprcount)
Size600to620_Spr = WHERE((Length_prod_Spr GE 600.) AND (Length_prod_Spr LT 620.), Size600to620_Sprcount)
Size620to640_Spr = WHERE((Length_prod_Spr GE 620.) AND (Length_prod_Spr LT 640.), Size620to640_Sprcount)
Size640to660_Spr = WHERE((Length_prod_Spr GE 640.) AND (Length_prod_Spr LT 660.), Size640to660_Sprcount)
Size660to680_Spr = WHERE((Length_prod_Spr GE 660.) AND (Length_prod_Spr LT 680.), Size660to680_Sprcount)
Size680to700_Spr = WHERE((Length_prod_Spr GE 680.) AND (Length_prod_Spr LT 700.), Size680to700_Sprcount)
Size700to720_Spr = WHERE((Length_prod_Spr GE 700.) AND (Length_prod_Spr LT 720.), Size700to720_Sprcount)
Size720to740_Spr = WHERE((Length_prod_Spr GE 720.) AND (Length_prod_Spr LT 740.), Size720to740_Sprcount)
Size740to760_Spr = WHERE((Length_prod_Spr GE 740.) AND (Length_prod_Spr LT 760.), Size740to760_Sprcount)
Size760to780_Spr = WHERE((Length_prod_Spr GE 760.) AND (Length_prod_Spr LT 780.), Size760to780_Sprcount)
Size780to800_Spr = WHERE((Length_prod_Spr GE 780.) AND (Length_prod_Spr LT 800.), Size780to800_Sprcount)
SizeGE800_Spr = WHERE((Length_prod_Spr GE 800.), SizeGE800_Sprcount)
LengthDist_spr[0, i] = SizeLT100_sprcount
LengthDist_spr[1, i] = Size100to120_sprcount
LengthDist_spr[2, i] = Size120to140_sprcount
LengthDist_spr[3, i] = Size140to160_sprcount
LengthDist_spr[4, i] = Size160to180_sprcount
LengthDist_spr[5, i] = Size180to200_sprcount
LengthDist_spr[6, i] = Size200to220_sprcount
LengthDist_spr[7, i] = Size220to240_sprcount
LengthDist_spr[8, i] = Size240to260_sprcount
LengthDist_spr[9, i] = Size260to280_sprcount
LengthDist_spr[10, i] = Size280to300_sprcount
LengthDist_spr[11, i] = Size300to320_sprcount
LengthDist_spr[12, i] = Size320to340_sprcount
LengthDist_spr[13, i] = Size340to360_sprcount
LengthDist_spr[14, i] = Size360to380_sprcount
LengthDist_spr[15, i] = Size380to400_sprcount
LengthDist_spr[16, i] = Size400to420_sprcount
LengthDist_spr[17, i] = Size420to440_sprcount
LengthDist_spr[18, i] = Size440to460_sprcount
LengthDist_spr[19, i] = Size460to480_sprcount
LengthDist_spr[20, i] = Size480to500_sprcount
LengthDist_spr[21, i] = Size500to520_sprcount
LengthDist_spr[22, i] = Size520to540_sprcount
LengthDist_spr[23, i] = Size540to560_sprcount
LengthDist_spr[24, i] = Size560to580_sprcount
LengthDist_spr[25, i] = Size580to600_sprcount
LengthDist_spr[26, i] = Size600to620_sprcount
LengthDist_spr[27, i] = Size620to640_sprcount
LengthDist_spr[28, i] = Size640to660_sprcount
LengthDist_spr[29, i] = Size660to680_sprcount
LengthDist_spr[30, i] = Size680to700_sprcount
LengthDist_spr[31, i] = Size700to720_sprcount
LengthDist_spr[32, i] = Size720to740_sprcount
LengthDist_spr[33, i] = Size740to760_sprcount
LengthDist_spr[34, i] = Size760to780_sprcount
LengthDist_spr[35, i] = Size780to800_sprcount
LengthDist_spr[36, i] = SizeGE800_sprcount
PRINT, 'length distribution - spearing (bin size = 20mm)', LengthDist_spr[0:36, i]
LengthDist_spr[37, i] = paramset_spr[1, i] ; WBIC
LengthDist_spr[38, i] = paramset_spr[2, i] ; year
LengthDist_spr[39, i] = paramset_spr[3, i] ; sample size
LengthDist_spr[40, i] = adultPE_spr[INDEX_lengthdataSpr[0]] ; adult PE
LengthDist_spr[41, i] = HarvRate_spr[INDEX_lengthdataSpr[0]] ; harvest rate
LengthDist_spr[42, i] = (paramset_spr[4, i])
LengthDist_spr[43, i] = (paramset_spr[5, i])
LengthDist_spr[44, i] = (paramset_spr[6, i])
LengthDist_spr2[0, i] = paramset_spr[1, i] ; WBIC
LengthDist_spr2[1, i] = paramset_spr[2, i] ; year
LengthDist_spr2[2, i] = paramset_spr[3, i] ; sample size
LengthDist_spr2[3, i] = adultPE_spr[INDEX_lengthdataSpr[0]]*HarvRate_spr[INDEX_lengthdataSpr[0]] ; adult PE
LengthDist_spr2[4, i] = paramset_spr[4, i] ; n of male
LengthDist_spr2[5, i] = paramset_spr[5, i] ; n of female
LengthDist_spr2[6, i] = paramset_spr[6, i] ; n of unknowns
LengthDist_spr2[7:43, i] = LengthDist_spr[0:36, i]/TOTAL(LengthDist_spr[0:36, i]) $
*adultPE_spr[INDEX_lengthdataSpr[0]]*HarvRate_spr[INDEX_lengthdataSpr[0]]
; check for discrepancies between spearing data and length-age keys...
IF (SizeLT100_sprcount GT 0) AND (LengthDist[0, i] LE 0) THEN LengthDist_spr_PLUS[0, i] = SizeLT100_sprcount
IF (Size100to120_sprcount GT 0) AND (LengthDist[1, i] LE 0) THEN LengthDist_spr_PLUS[1, i] = Size100to120_sprcount
IF (Size120to140_sprcount GT 0) AND (LengthDist[2, i] LE 0) THEN LengthDist_spr_PLUS[2, i] = Size120to140_sprcount
IF (Size140to160_sprcount GT 0) AND (LengthDist[3, i] LE 0) THEN LengthDist_spr_PLUS[3, i] = Size140to160_sprcount
IF (Size160to180_sprcount GT 0) AND (LengthDist[4, i] LE 0) THEN LengthDist_spr_PLUS[4, i] = Size160to180_sprcount
IF (Size180to200_sprcount GT 0) AND (LengthDist[5, i] LE 0) THEN LengthDist_spr_PLUS[5, i] = Size180to200_sprcount
IF (Size200to220_sprcount GT 0) AND (LengthDist[6, i] LE 0) THEN LengthDist_spr_PLUS[6, i] = Size200to220_sprcount
IF (Size220to240_sprcount GT 0) AND (LengthDist[7, i] LE 0) THEN LengthDist_spr_PLUS[7, i] = Size220to240_sprcount
IF (Size240to260_sprcount GT 0) AND (LengthDist[8, i] LE 0) THEN LengthDist_spr_PLUS[8, i] = Size240to260_sprcount
IF (Size260to280_sprcount GT 0) AND (LengthDist[9, i] LE 0) THEN LengthDist_spr_PLUS[9, i] = Size260to280_sprcount
IF (Size280to300_sprcount GT 0) AND (LengthDist[10, i] LE 0) THEN LengthDist_spr_PLUS[10, i] = Size280to300_sprcount
IF (Size300to320_sprcount GT 0) AND (LengthDist[11, i] LE 0) THEN LengthDist_spr_PLUS[11, i] = Size300to320_sprcount
IF (Size320to340_sprcount GT 0) AND (LengthDist[12, i] LE 0) THEN LengthDist_spr_PLUS[12, i] = Size320to340_sprcount
IF (Size340to360_sprcount GT 0) AND (LengthDist[13, i] LE 0) THEN LengthDist_spr_PLUS[13, i] = Size340to360_sprcount
IF (Size360to380_sprcount GT 0) AND (LengthDist[14, i] LE 0) THEN LengthDist_spr_PLUS[14, i] = Size360to380_sprcount
IF (Size380to400_sprcount GT 0) AND (LengthDist[15, i] LE 0) THEN LengthDist_spr_PLUS[15, i] = Size380to400_sprcount
IF (Size400to420_sprcount GT 0) AND (LengthDist[16, i] LE 0) THEN LengthDist_spr_PLUS[16, i] = Size400to420_sprcount
IF (Size420to440_sprcount GT 0) AND (LengthDist[17, i] LE 0) THEN LengthDist_spr_PLUS[17, i] = Size420to440_sprcount
IF (Size440to460_sprcount GT 0) AND (LengthDist[18, i] LE 0) THEN LengthDist_spr_PLUS[18, i] = Size440to460_sprcount
IF (Size460to480_sprcount GT 0) AND (LengthDist[19, i] LE 0) THEN LengthDist_spr_PLUS[19, i] = Size460to480_sprcount
IF (Size480to500_sprcount GT 0) AND (LengthDist[20, i] LE 0) THEN LengthDist_spr_PLUS[20, i] = Size480to500_sprcount
IF (Size500to520_sprcount GT 0) AND (LengthDist[21, i] LE 0) THEN LengthDist_spr_PLUS[21, i] = Size500to520_sprcount
IF (Size520to540_sprcount GT 0) AND (LengthDist[22, i] LE 0) THEN LengthDist_spr_PLUS[22, i] = Size520to540_sprcount
IF (Size540to560_sprcount GT 0) AND (LengthDist[23, i] LE 0) THEN LengthDist_spr_PLUS[23, i] = Size540to560_sprcount
IF (Size560to580_sprcount GT 0) AND (LengthDist[24, i] LE 0) THEN LengthDist_spr_PLUS[24, i] = Size560to580_sprcount
IF (Size580to600_sprcount GT 0) AND (LengthDist[25, i] LE 0) THEN LengthDist_spr_PLUS[25, i] = Size580to600_sprcount
IF (Size600to620_sprcount GT 0) AND (LengthDist[26, i] LE 0) THEN LengthDist_spr_PLUS[26, i] = Size600to620_sprcount
IF (Size620to640_sprcount GT 0) AND (LengthDist[27, i] LE 0) THEN LengthDist_spr_PLUS[27, i] = Size620to640_sprcount
IF (Size640to660_sprcount GT 0) AND (LengthDist[28, i] LE 0) THEN LengthDist_spr_PLUS[28, i] = Size640to660_sprcount
IF (Size660to680_sprcount GT 0) AND (LengthDist[29, i] LE 0) THEN LengthDist_spr_PLUS[29, i] = Size660to680_sprcount
IF (Size680to700_sprcount GT 0) AND (LengthDist[30, i] LE 0) THEN LengthDist_spr_PLUS[30, i] = Size680to700_sprcount
IF (Size700to720_sprcount GT 0) AND (LengthDist[31, i] LE 0) THEN LengthDist_spr_PLUS[31, i] = Size700to720_sprcount
IF (Size720to740_sprcount GT 0) AND (LengthDist[32, i] LE 0) THEN LengthDist_spr_PLUS[32, i] = Size720to740_sprcount
IF (Size740to760_sprcount GT 0) AND (LengthDist[33, i] LE 0) THEN LengthDist_spr_PLUS[33, i] = Size740to760_sprcount
IF (Size760to780_sprcount GT 0) AND (LengthDist[34, i] LE 0) THEN LengthDist_spr_PLUS[34, i] = Size760to780_sprcount
IF (Size780to800_sprcount GT 0) AND (LengthDist[35, i] LE 0) THEN LengthDist_spr_PLUS[35, i] = Size780to800_sprcount
IF (SizeGE800_sprcount GT 0) AND (LengthDist[36, i] LE 0) THEN LengthDist_spr_PLUS[36, i] = SizeGE800_sprcount
IF TOTAL(LengthDist_spr_PLUS[*, i]) GT 0 THEN PRINT, 'length bins w/o spring survey data (bin size = 20mm)', LengthDist_spr_PLUS[0:36, i]
Prop_LengthDist_spr_PLUS[i] = TOTAL(LengthDist_spr_PLUS[*, i]) / TOTAL(LengthDist_spr[*, i])
; If fish length bins were not sampled in spring surveys, they were not included in age structure analysis
IF LengthDist_spr_PLUS[0, i] GT 0 THEN SizeLT100_sprcount = 0
IF LengthDist_spr_PLUS[1, i] GT 0 THEN Size100to120_sprcount = 0
IF LengthDist_spr_PLUS[2, i] GT 0 THEN Size120to140_sprcount = 0
IF LengthDist_spr_PLUS[3, i] GT 0 THEN Size140to160_sprcount = 0
IF LengthDist_spr_PLUS[4, i] GT 0 THEN Size160to180_sprcount = 0
IF LengthDist_spr_PLUS[5, i] GT 0 THEN Size180to200_sprcount = 0
IF LengthDist_spr_PLUS[6, i] GT 0 THEN Size200to220_sprcount = 0
IF LengthDist_spr_PLUS[7, i] GT 0 THEN Size220to240_sprcount = 0
IF LengthDist_spr_PLUS[8, i] GT 0 THEN Size240to260_sprcount = 0
IF LengthDist_spr_PLUS[9, i] GT 0 THEN Size260to280_sprcount = 0
IF LengthDist_spr_PLUS[10, i] GT 0 THEN Size280to300_sprcount = 0
IF LengthDist_spr_PLUS[11, i] GT 0 THEN Size300to320_sprcount = 0
IF LengthDist_spr_PLUS[12, i] GT 0 THEN Size320to340_sprcount = 0
IF LengthDist_spr_PLUS[13, i] GT 0 THEN Size340to360_sprcount = 0
IF LengthDist_spr_PLUS[14, i] GT 0 THEN Size360to380_sprcount = 0
IF LengthDist_spr_PLUS[15, i] GT 0 THEN Size380to400_sprcount = 0
IF LengthDist_spr_PLUS[16, i] GT 0 THEN Size400to420_sprcount = 0
IF LengthDist_spr_PLUS[17, i] GT 0 THEN Size420to440_sprcount = 0
IF LengthDist_spr_PLUS[18, i] GT 0 THEN Size440to460_sprcount = 0
IF LengthDist_spr_PLUS[19, i] GT 0 THEN Size460to480_sprcount = 0
IF LengthDist_spr_PLUS[20, i] GT 0 THEN Size480to500_sprcount = 0
IF LengthDist_spr_PLUS[21, i] GT 0 THEN Size500to520_sprcount = 0
IF LengthDist_spr_PLUS[22, i] GT 0 THEN Size520to540_sprcount = 0
IF LengthDist_spr_PLUS[23, i] GT 0 THEN Size540to560_sprcount = 0
IF LengthDist_spr_PLUS[24, i] GT 0 THEN Size560to580_sprcount = 0
IF LengthDist_spr_PLUS[25, i] GT 0 THEN Size580to600_sprcount = 0
IF LengthDist_spr_PLUS[26, i] GT 0 THEN Size600to620_sprcount = 0
IF LengthDist_spr_PLUS[27, i] GT 0 THEN Size620to640_sprcount = 0
IF LengthDist_spr_PLUS[28, i] GT 0 THEN Size640to660_sprcount = 0
IF LengthDist_spr_PLUS[29, i] GT 0 THEN Size660to680_sprcount = 0
IF LengthDist_spr_PLUS[30, i] GT 0 THEN Size680to700_sprcount = 0
IF LengthDist_spr_PLUS[31, i] GT 0 THEN Size700to720_sprcount = 0
IF LengthDist_spr_PLUS[32, i] GT 0 THEN Size720to740_sprcount = 0
IF LengthDist_spr_PLUS[33, i] GT 0 THEN Size740to760_sprcount = 0
IF LengthDist_spr_PLUS[34, i] GT 0 THEN Size760to780_sprcount = 0
IF LengthDist_spr_PLUS[35, i] GT 0 THEN Size780to800_sprcount = 0
IF LengthDist_spr_PLUS[36, i] GT 0 THEN SizeGE800_sprcount = 0
; Array index for WBIC years w/ key
INDEX_lengthdataSpr2 = WHERE((WBIC_year_key[*] EQ WBIC_Year_Spr[INDEX_lengthdataSpr[0]]), INDEX_lengthdataSpr2count)
IF (INDEX_lengthdataSpr2count GT 0) THEN BEGIN ; if a key exists for each lake-year...
PRINT, 'WBIC_Year_Spr', WBIC_year_key[INDEX_lengthdataSpr2[0]]
length_key_check_Spr = fltarr(37)
IF (SizeLT100_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[0]] LE 0) THEN length_key_check_Spr[0] = SizeLT100_Sprcount
IF (Size100to120_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[1]] LE 0) THEN length_key_check_Spr[1] = Size100to120_Sprcount
IF (Size120to140_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[2]] LE 0) THEN length_key_check_Spr[2] = Size120to140_Sprcount
IF (Size140to160_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[3]] LE 0) THEN length_key_check_Spr[3] = Size140to160_Sprcount
IF (Size160to180_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[4]] LE 0) THEN length_key_check_Spr[4] = Size160to180_Sprcount
IF (Size180to200_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[5]] LE 0) THEN length_key_check_Spr[5] = Size180to200_Sprcount
IF (Size200to220_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[6]] LE 0) THEN length_key_check_Spr[6] = Size200to220_Sprcount
IF (Size220to240_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[7]] LE 0) THEN length_key_check_Spr[7] = Size220to240_Sprcount
IF (Size240to260_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[8]] LE 0) THEN length_key_check_Spr[8] = Size240to260_Sprcount
IF (Size260to280_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[9]] LE 0) THEN length_key_check_Spr[9] = Size260to280_Sprcount
IF (Size280to300_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[10]] LE 0) THEN length_key_check_Spr[10] = Size280to300_Sprcount
IF (Size300to320_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[11]] LE 0) THEN length_key_check_Spr[11] = Size300to320_Sprcount
IF (Size320to340_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[12]] LE 0) THEN length_key_check_Spr[12] = Size320to340_Sprcount
IF (Size340to360_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[13]] LE 0) THEN length_key_check_Spr[13] = Size340to360_Sprcount
IF (Size360to380_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[14]] LE 0) THEN length_key_check_Spr[14] = Size360to380_Sprcount
IF (Size380to400_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[15]] LE 0) THEN length_key_check_Spr[15] = Size380to400_Sprcount
IF (Size400to420_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[16]] LE 0) THEN length_key_check_Spr[16] = Size400to420_Sprcount
IF (Size420to440_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[17]] LE 0) THEN length_key_check_Spr[17] = Size420to440_Sprcount
IF (Size440to460_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[18]] LE 0) THEN length_key_check_Spr[18] = Size440to460_Sprcount
IF (Size460to480_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[19]] LE 0) THEN length_key_check_Spr[19] = Size460to480_Sprcount
IF (Size480to500_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[20]] LE 0) THEN length_key_check_Spr[20] = Size480to500_Sprcount
IF (Size500to520_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[21]] LE 0) THEN length_key_check_Spr[21] = Size500to520_Sprcount
IF (Size520to540_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[22]] LE 0) THEN length_key_check_Spr[22] = Size520to540_Sprcount
IF (Size540to560_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[23]] LE 0) THEN length_key_check_Spr[23] = Size540to560_Sprcount
IF (Size560to580_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[24]] LE 0) THEN length_key_check_Spr[24] = Size560to580_Sprcount
IF (Size580to600_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[25]] LE 0) THEN length_key_check_Spr[25] = Size580to600_Sprcount
IF (Size600to620_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[26]] LE 0) THEN length_key_check_Spr[26] = Size600to620_Sprcount
IF (Size620to640_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[27]] LE 0) THEN length_key_check_Spr[27] = Size620to640_Sprcount
IF (Size640to660_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[28]] LE 0) THEN length_key_check_Spr[28] = Size640to660_Sprcount
IF (Size660to680_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[29]] LE 0) THEN length_key_check_Spr[29] = Size660to680_Sprcount
IF (Size680to700_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[30]] LE 0) THEN length_key_check_Spr[30] = Size680to700_Sprcount
IF (Size700to720_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[31]] LE 0) THEN length_key_check_Spr[31] = Size700to720_Sprcount
IF (Size720to740_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[32]] LE 0) THEN length_key_check_Spr[32] = Size720to740_Sprcount
IF (Size740to760_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[33]] LE 0) THEN length_key_check_Spr[33] = Size740to760_Sprcount
IF (Size760to780_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[34]] LE 0) THEN length_key_check_Spr[34] = Size760to780_Sprcount
IF (Size780to800_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[35]] LE 0) THEN length_key_check_Spr[35] = Size780to8000_Sprcount
IF (SizeGE800_Sprcount GT 0) AND (Length_N_fish[INDEX_lengthdataSpr2[36]] LE 0) THEN length_key_check_Spr[36] = SizeGE800_Sprcount
PRINT, 'total N of fish w/o key', TOTAL(length_key_check_Spr)
paramset[212, i] = TOTAL(length_key_check_Spr)
PRINT, 'size bins w/o key', length_key_check_Spr
AgeLengthKeyCheck_Spr1 = (TOTAL(length_key_check_Spr)/N_ELEMENTS(Length_prod_Spr))
PRINT, 'AgeLengthKeyCheck_Spr1', AgeLengthKeyCheck_Spr1
IF AgeLengthKeyCheck_Spr1 LT AgeLengthKeyLevel THEN BEGIN ; the proportion of unaged fish is less than the threshold...
N_Lake_year_Spr = N_Lake_year_Spr + 1L
PRINT, 'N of lake-years with harvested biomass estimated with lake-year-specific keys', N_Lake_year_Spr
;1.Assign age semi-randomly to lengths - ALL FISH
IF SizeLT100_Sprcount GT 0 THEN BEGIN
LengthBinIndex1 = 0
LengthBinIndex2 = SizeLT100_Spr
FishProb = AgeLengthKey(prop_age0, prop_age1, prop_age2, prop_age3, prop_age4, prop_age5 $
, prop_age6, prop_age7, prop_age8, prop_age9, prop_age10, prop_age11, prop_age12 $
, prop_age13, prop_age14, prop_age15, prop_age16, prop_age17, prop_age18, prop_age19 $
, prop_age20, prop_age21, prop_age22, prop_age23, prop_age24, prop_age25 $
, prop_age26, INDEX_lengthdataSpr2, LengthBinIndex1)
;PRINT, 'FishProb', FishProb
AgeAssignSpr = WalleyeAgeAssign(Length_prod_Spr[LengthBinIndex2], LengthBinIndex2 $
, FishProb, FishAgeSpr[LengthBinIndex2], i+NumLengthBin+adj)
WAE_length_mean_Spr[10:36, i*NumLengthBin+adj+LengthBinIndex1] = AgeAssignSpr[0, *]
WAE_length_bin_Spr[10:36, i*NumLengthBin+adj+LengthBinIndex1] = AgeAssignSpr[1, *]
AgeAssignIndSpr = WalleyeAgeAssignInd(Length_prod_Spr[LengthBinIndex2], LengthBinIndex2 $
, FishProb, FishAgeSpr[LengthBinIndex2], i+NumLengthBin+adj)
FishAgeSpr[LengthBinIndex2] = AgeAssignIndSpr[0,*]
FishLengthSpr[LengthBinIndex2] = AgeAssignIndSpr[1,*]
ENDIF
IF Size100to120_Sprcount GT 0 THEN BEGIN
LengthBinIndex1 = 1
LengthBinIndex2 = Size100to120_Spr
FishProb = AgeLengthKey(prop_age0, prop_age1, prop_age2, prop_age3, prop_age4, prop_age5 $
, prop_age6, prop_age7, prop_age8, prop_age9, prop_age10, prop_age11, prop_age12 $
, prop_age13, prop_age14, prop_age15, prop_age16, prop_age17, prop_age18, prop_age19 $
, prop_age20, prop_age21, prop_age22, prop_age23, prop_age24, prop_age25 $
, prop_age26, INDEX_lengthdataSpr2, LengthBinIndex1)
;PRINT, 'FishProb', FishProb
AgeAssignSpr = WalleyeAgeAssign(Length_prod_Spr[LengthBinIndex2], LengthBinIndex2 $
, FishProb, FishAgeSpr[LengthBinIndex2], i+NumLengthBin+adj)
WAE_length_mean_Spr[10:36, i*NumLengthBin+adj+LengthBinIndex1] = AgeAssignSpr[0, *]
WAE_length_bin_Spr[10:36, i*NumLengthBin+adj+LengthBinIndex1] = AgeAssignSpr[1, *]
AgeAssignIndSpr = WalleyeAgeAssignInd(Length_prod_Spr[LengthBinIndex2], LengthBinIndex2 $
, FishProb, FishAgeSpr[LengthBinIndex2], i+NumLengthBin+adj)
FishAgeSpr[LengthBinIndex2] = AgeAssignIndSpr[0,*]
FishLengthSpr[LengthBinIndex2] = AgeAssignIndSpr[1,*]
ENDIF
IF Size120to140_Sprcount GT 0 THEN BEGIN
LengthBinIndex1 = 2
LengthBinIndex2 = Size120to140_Spr
FishProb = AgeLengthKey(prop_age0, prop_age1, prop_age2, prop_age3, prop_age4, prop_age5 $
, prop_age6, prop_age7, prop_age8, prop_age9, prop_age10, prop_age11, prop_age12 $
, prop_age13, prop_age14, prop_age15, prop_age16, prop_age17, prop_age18, prop_age19 $
, prop_age20, prop_age21, prop_age22, prop_age23, prop_age24, prop_age25 $
, prop_age26, INDEX_lengthdataSpr2, LengthBinIndex1)
;PRINT, 'FishProb', FishProb
AgeAssignSpr = WalleyeAgeAssign(Length_prod_Spr[LengthBinIndex2], LengthBinIndex2 $
, FishProb, FishAgeSpr[LengthBinIndex2], i+NumLengthBin+adj)
WAE_length_mean_Spr[10:36, i*NumLengthBin+adj+LengthBinIndex1] = AgeAssignSpr[0, *]
WAE_length_bin_Spr[10:36, i*NumLengthBin+adj+LengthBinIndex1] = AgeAssignSpr[1, *]
AgeAssignIndSpr = WalleyeAgeAssignInd(Length_prod_Spr[LengthBinIndex2], LengthBinIndex2 $
, FishProb, FishAgeSpr[LengthBinIndex2], i+NumLengthBin+adj)
FishAgeSpr[LengthBinIndex2] = AgeAssignIndSpr[0,*]
FishLengthSpr[LengthBinIndex2] = AgeAssignIndSpr[1,*]
ENDIF