-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmacsbase_20240516AEP.TPL
12859 lines (11922 loc) · 622 KB
/
gmacsbase_20240516AEP.TPL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==================================================================================== //
// Gmacs: A generalized size-structured stock assessment modeling framework.
//
// Authors: gmacs development team at the
// Alaska Fisheries Science Centre, Seattle
// and the University of Washington.
//
// Info: https://github.com/seacode/gmacs Copyright (C) 2014-2019. All rights reserved.
//
// ACKNOWLEDGEMENTS:
// finacial support provided by NOAA and Bering Sea Fisheries Research Foundation.
//
// INDEXES:
// g/ig = group
// h = sex
// i = year
// j = time step (years)
// k = gear or fleet
// l = index for length class
// m = index for maturity state
// o = index for shell condition.
//
// OUTPUT FILES:
// gmacs.rep Main result file for reading into R etc
// gmacs.std Result file for reading into R etc
// gmacsall.out Result file for all all sorts of purposes.
//
// FOR DEBUGGING INPUT FILES: (for accessing easily with read_admb() function)
// gmacs_files_in.dat Which control and data files were specified for the current run
// gmacs_in.ctl Code-generated copy of control file content (useful for checking read)
// gmacs_in.dat Code-generated copy of data file content (useful for checking read)
// gmacs_in.prj Code-generated copy of projection file content (useful for checking read)
//
// TO ECHO INPUT
// checkfile.rep All of data read in
//
// COMMANDLINE OPTIONS
// The following specify using an ascii pin file fnPin to set parameter values,
// and set usepinfile=1 regardless of the value in gmacs.dat. Pinfile usage can
// also be turned "on" in the gmacs.dat file (in which case the commandline options
// are only usful for specifying a non-default pinfile name).
// If fnPin not given, then fnPin = "gmacs.pin" (the ADMB default).
// -pin fnPin
// -ainp fnPin
// -apin fnPin
// ==================================================================================== //
// ************************************************************************************ //
// Developers
// ************************************************************************************ //
// AEP: Andre E. Punt
// CS: Cody Szuwalski
// JI: Jim Ianelli
// WTS: William T. Stockhausen
// AW: Athol Whitten
// DW: Darcey Webber
// MV: Matthieu Veron
// TJ: Tyler Jackson
// ************************************************************************************ //
// Submodels labeling
// ************************************************************************************ //
// Label 130: Projection inputs
// Label 200: INITIALIZATION_SECTION
// Label 400: calc_objective_function
// Label 401: catch_likelihood
// Label 402: index_likelihhod
// Label 403: length_likelihood
// Label 404: recruitment_likelihood
// Label 405: growth_likelihood
// Label 500: calc_spr_reference_points2
// Label 501: calc_brute_equilibrium
// Label 502: project_biomass_OFL
// Label 503: calc_predicted_project
// Label 504: project_biomass
// Label 505: compute_OFL_and_ABC
// Label 506: project_one_year
// Label 600: CreateOutput
// Label 700: write_eval
// ************************************************************************************ //
DATA_SECTION
!! TheHeader = adstring("## GMACS Version 2.20.13; ** AEP & WTS **; Compiled 2024-05-15");
//-------------------------------
// Sandbox for testing functions |
//-------------------------------
LOCAL_CALCS
{
//
//@brief command line option for sandbox.
//
int on = 0; int opt;//defined for local scope only here
int testingflag = 0;
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-testing",opt))>-1 )
{
testingflag = 1;
}
if (testingflag==1){
//Testing alternative dat file reader
cout<<"|---------------------------------------|"<<endl;
cout<<"| Testing with alternative dat file |"<<endl;
cout<<"|---------------------------------------|"<<endl;
//cifstream is("TannerCrab_NewDatFile.dat",ios::in);
//DatFileReader* pDFR = new DatFileReader();
//is>>(*pDFR);
//is.close();
//cout<<(*pDFR)<<endl;
exit(1);
}
if (0){
//Testing selectivity using "constant" values
cout<<"|---------------------------------------|"<<endl;
cout<<"| Testing sandbox using constant values |"<<endl;
cout<<"|---------------------------------------|"<<endl;
class gsm::Selex<dvector> *pSLX;
dvector z(1,32);
for (int i=z.indexmin();i<=z.indexmax();i++) z(i) = 27.5+(i-1)*5.0;
cout<<"--Cubic Spline"<<endl;
dvector x_knts(1,5);
x_knts[1]=z[1]; for (int i=1;i<=4;i++) x_knts[i+1] = z[8*i];
dvector y_vals = 1.0/(1.0+exp(-(x_knts-100.0)/30.0));
cout<<"x_knts = "<<x_knts<<endl;
cout<<"y_vals = "<<y_vals<<endl;
pSLX = new class gsm::SelectivitySpline<dvector,dvector>(y_vals,x_knts);
cout<<"z = "<<x_knts<<endl;
cout<<"sel = "<<pSLX->Selectivity(x_knts)<<endl;
cout<<"z = "<<z<<endl;
cout<<"sel = "<<pSLX->Selectivity(z)<<endl;
cout<<"logsel = "<<pSLX->logSelectivity(z)<<endl;
cout<<"logselM1 = "<<pSLX->logSelexMeanOne(z)<<endl;
cout<<"--change knots and y_vals to check reallocation"<<endl;
dvector x_knts1(1,9);
x_knts1[1]=z[1]; for (int i=1;i<=8;i++) x_knts1[i+1] = z[4*i];
dvector y_vals1 = 1.0/(1.0+exp(-(x_knts1-100.0)/30.0));
((gsm::SelectivitySpline<dvector,dvector>*)pSLX)->initSpline(y_vals1,x_knts1);
cout<<"z = "<<x_knts1<<endl;
cout<<"sel = "<<pSLX->Selectivity(x_knts1)<<endl;
cout<<"z = "<<z<<endl;
cout<<"sel = "<<pSLX->Selectivity(z)<<endl;
cout<<"logsel = "<<pSLX->logSelectivity(z)<<endl;
cout<<"logselM1 = "<<pSLX->logSelexMeanOne(z)<<endl;
//exit(1);
cout<<"--DoubleNormal"<<endl;
double p1 = 30.0;
double p2 = 100.0;
double p3 = 50.0;
pSLX = new class gsm::DoubleNormal<dvector,double>(p1,p2,p3);
cout<<z<<endl;
cout<<pSLX->Selectivity(z)<<endl;
cout<<pSLX->logSelectivity(z)<<endl;
cout<<pSLX->logSelexMeanOne(z)<<endl;
cout<<"--DoubleNormal4"<<endl;
p1 = 30.0;
p2 = 100.0;
p3 = 50.0;
double p4 = 130.0;
pSLX = new class gsm::DoubleNormal4<dvector,double>(p1,p2,p3,p4);
cout<<z<<endl;
cout<<pSLX->Selectivity(z)<<endl;
cout<<pSLX->logSelectivity(z)<<endl;
cout<<pSLX->logSelexMeanOne(z)<<endl;
cout<<"--Uniform"<<endl;
pSLX = new class gsm::UniformCurve<dvector>();
cout<<z<<endl;
cout<<pSLX->Selectivity(z)<<endl;
cout<<pSLX->logSelectivity(z)<<endl;
cout<<pSLX->logSelexMeanOne(z)<<endl;
cout<<"--Uniform0"<<endl;
pSLX = new class gsm::Uniform0Curve<dvector>();
cout<<z<<endl;
cout<<pSLX->Selectivity(z)<<endl;
cout<<pSLX->logSelectivity(z)<<endl;
cout<<pSLX->logSelexMeanOne(z)<<endl;
exit(1);
}
}//--end local scope
END_CALCS
//friend_class gmacs_comm;
// |---------------------|
// | SIMULATION CONTROLS |
// |---------------------|
int jitflag;//--jitter indicator from commandline
int simflag;
int rseed;
LOC_CALCS
jitflag = 0;
simflag = 0;
rseed = 0;
int opt,on;
sexes(0) = "undetermined";
sexes(1) = "male";
sexes(2) = "female";
maturestate(0) = "undetermined";
maturestate(1) = "mature";
maturestate(2) = "immature";
shellstate(0) = "undetermined";
shellstate(1) = "new";
shellstate(2) = "old";
catchtypes(0) = "total";
catchtypes(1) = "retained";
catchtypes(2) = "discarded";
unitstypes += "biommass";
unitstypes += "numbers";
seltypes += "selectivity";
seltypes += "retention";
/**
* @brief command line option for simulating data.
**/
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-sim",opt))>-1 )
{
simflag = 1;
rseed = atoi(ad_comm::argv[on+1]);
}
/**
* @brief command line option for jittering parameter values (overrides gmacs.dat setting).
**/
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-jitter",opt))>-1 )
{
jitflag = 1;
rseed = atoi(ad_comm::argv[on+1]);//set rseed to 0 to use start time
}
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-i",opt))>-1 )
{
cout << "\n";
cout << " +----------------------------------------------------------+\n";
cout << " | CONTRIBUTIONS (code and intellectual) |\n";
cout << " +----------------------------------------------------------+\n";
cout << " | Name: Organization: |\n";
cout << " | James Ianelli NOAA-NMFS |\n";
cout << " | D'Arcy Webber Quantifish |\n";
cout << " | Steven Martell SeaState |\n";
cout << " | Jack Turnock NOAA-NMFS |\n";
cout << " | Jie Zheng ADF&G |\n";
cout << " | Hamachan Hamazaki ADF&G |\n";
cout << " | Athol Whitten University of Washington |\n";
cout << " | Andre Punt University of Washington |\n";
cout << " | Dave Fournier Otter Research |\n";
cout << " | John Levitt Mathemetician |\n";
cout << " | William Stockhausen NOAA-NMFS |\n";
cout << " +----------------------------------------------------------+\n";
cout << "\n";
cout << " +----------------------------------------------------------+\n";
cout << " | FINANCIAL SUPPORT |\n";
cout << " +----------------------------------------------------------+\n";
cout << " | Financial support for this project was provided by the |\n";
cout << " | National Marine Fisheries Service, the Bering Sea |\n";
cout << " | Fisheries Research Foundation, ... |\n";
cout << " +----------------------------------------------------------+\n";
cout << "\n";
cout << " +----------------------------------------------------------+\n";
cout << " | DOCUMENTATION |\n";
cout << " +----------------------------------------------------------+\n";
cout << " | online api: http://seacode.github.io/gmacs/index.html |\n";
cout << " +----------------------------------------------------------+\n";
cout << "\n";
exit(1);
}
// Command line option here to do retrospective analysis
if ( (on=option_match(ad_comm::argc,ad_comm::argv, "-retro", opt))>-1 )
{
cout << "\n";
cout << " +----------------------------------------------------------+\n";
cout << " | Running retrospective model with " << ad_comm::argv[on+1] << " recent yrs removed |\n";
cout << " +----------------------------------------------------------+\n";
cout << " | YET TO BE IMPLEMENTED |\n";
cout << " +----------------------------------------------------------+\n";
exit(1);
}
END_CALCS
// create a random number generator for projections
// |------------------------|
// | DATA AND CONTROL FILES |
// |------------------------|
//--read gmacs.dat file
!!WriteFileName(TheHeader);
init_adstring datafile;
init_adstring controlfile;
init_adstring projectfile;
init_adstring weightunit;
init_adstring numbersunit;
init_adstring StockName;
!!WriteFileName(datafile); WriteFileName(controlfile); WriteFileName(projectfile);
!!WriteFileName(weightunit);
!!WriteFileName(numbersunit);
!!WriteFileName(StockName);
init_int IsJittered;
init_number sdJitter;
!! if (jitflag) IsJittered = 1;
!! if (IsJittered==1) cout << "Jittering with sd: " << sdJitter << endl;
!! WriteFileName(IsJittered);
!! WriteFileName(sdJitter);
init_int OutRefPars;
!! WriteFileName(OutRefPars);
init_int OutRecruit;
!! WriteFileName(OutRecruit);
init_int OutSSB;
!! WriteFileName(OutSSB);
init_int Outfbar;
!! WriteFileName(Outfbar);
init_int OutDynB0;
!! WriteFileName(OutDynB0);
init_int nyrRetro; ///> Retrospective end year
!! WriteFileName(nyrRetro);
init_int TurnOffPhase; ///> Maximum phase
init_int StopAfterFnCall ///> Number of function calls to stop after
init_int CalcRefPoints; ///> Set this to zero not to compute reference points
init_int usepinfile ///> Read in a special file (0=normal;1=pin file)
init_int verbose; ///> Flag to print to screen
//check for commandline overide of pinfile use (if set, overrides value from gmacs.dat)
LOCAL_CALCS
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-verbose",opt))>-1 ){
verbose = atoi(ad_comm::argv[on+1]);
cout<<"#--verbose level set to: "<<verbose<<endl;
}
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-ainp",opt))>-1 ){
usepinfile = 1;
adstring fnPin = ad_comm::argv[on+1];
if (std::fstream(fnPin)){
ad_comm::change_pinfile_name(fnPin);
cout<<"#Initial parameter values from pin file: "<<fnPin<<endl;
} else {
cout<<"#Initial parameter values from pin file: gmacs.pin"<<endl;
}
}
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-apin",opt))>-1 ){
usepinfile = 1;
adstring fnPin = ad_comm::argv[on+1];
if (std::fstream(fnPin)){
ad_comm::change_pinfile_name(fnPin);
cout<<"#Initial parameter values from pin file: "<<fnPin<<endl;
} else {
cout<<"#Initial parameter values from pin file: gmacs.pin"<<endl;
}
}
if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-pin",opt))>-1 ){
usepinfile = 1;
adstring fnPin = ad_comm::argv[on+1];
if (std::fstream(fnPin)){
ad_comm::change_pinfile_name(fnPin);
cout<<"#Initial parameter values from pin file: "<<fnPin<<endl;
} else {
cout<<"#Initial parameter values from pin file: gmacs.pin"<<endl;
}
}
END_CALCS
!!gmacs_files << TurnOffPhase << " # Maximum phase (stop the estimation after this phase)" << endl;
!!gmacs_files << StopAfterFnCall << " # Maximum number of function calls" << endl;
!!gmacs_files << CalcRefPoints << " # Calculate reference points (0=no)" << endl;
!!gmacs_files << usepinfile << " # use pin file (0=no, 1=yes)" << endl;
!!gmacs_files << verbose << " # VERBOSE FLAG (0 = off, 1 = on, 2 = objective func; 3 diagnostics)" << endl;
!!echoinput << TurnOffPhase << " # Maximum phase (stop the estimation after this phase)" << endl;
!!echoinput << StopAfterFnCall << " # Maximum number of function calls" << endl;
!!echoinput << CalcRefPoints << " # Calculate reference points (0=no)" << endl;
!!echoinput << usepinfile << " # use pin file (0=no, 1=yes)" << endl;
!!echoinput << verbose << " # VERBOSE FLAG (0 = off, 1 = on, 2 = objective func; 3 diagnostics)" << endl;
init_int dataeof;
!! WriteFileName(dataeof);
!! if ( dataeof != 9999 ) {cout << "Error reading GMACS.DAT" << endl; exit(1);}
!! cout << "end of GMACS.DAT" << endl;
//----------------------------------------------------------------------------
//--read data file
!! ad_comm::change_datafile_name(datafile);
!! cout << "+----------------------+" << endl;
!! cout << "| Reading data file |" << endl;
!! cout << "+----------------------+" << endl;
!! gmacs_data << "# =========================================" << endl;
!! gmacs_data << "# The inputs for catch and index data are CV. To convert from CVs to standard errors of the log and to weights is given by" << endl;
!! gmacs_data << "# sigma = sqrt(ln(1.0+CV^2))" << endl;
!! gmacs_data << "# weight = 1.0/(2*sigma^2)" << endl;
!! gmacs_data << "# CV = sqrt(exp(1/(2*Weight))-1)" << endl;
!! gmacs_data << "# =========================================" << endl << endl;
// |------------------|
// | MODEL DIMENSIONS |
// |------------------|
!! cout << " * Model dimensions" << endl;
!! WRITEDAT(TheHeader);
init_int syr; ///> initial year
init_int nyr; ///> terminal year
int nyrRetroNo;
!! nyrRetroNo = nyrRetro;
!! nyrRetro = nyr-nyrRetro; ///> Adjust to nyear_retro
init_int nseason; ///> time step (years)
init_int nfleet; ///> number of gears (including surveys and fisheries)
init_int nsex; ///> number of sexes
!! if (nsex != 1 && nsex != 2)
!! { cout << "nsex can only be 1 or 2; STOPPING" << endl; exit(1); }
init_int nshell; ///> number of shell conditions
init_int nmature; ///> number of maturity types
init_int nclass; ///> number of size-classes
init_int season_recruitment; ///> Season that recruitment occurs (end of year before growth)
init_int season_growth; ///> Season that growth occurs (end of year after recruitment)
init_int season_ssb; ///> Season to calculate SSB (end of year)
init_int season_N; ///> Season to output N
init_ivector nSizeSex(1,nsex); ///> Number of size-classes by sex
int n_grp; ///> number of sex/newshell/oldshell groups
int nlikes; ///> 1 2 3 4 5
int Nyears;
!! Nyears =(nyrRetro-syr+1);
int Nyears2;
!! Nyears2 =(nyrRetro+1-syr+1);
LOC_CALCS
n_grp = nsex * nshell * nmature;
nlikes = 5; ///> catch, cpue, size comps, recruits, molt increments
gmacs_data << syr << " # Start year" << endl;
gmacs_data << nyrRetro << " # End year (retro)" << endl;
gmacs_data << nseason << " # Number of seasons" << endl;
gmacs_data << nfleet << " # Number of distinct data groups (fleet, among fishing fleets and surveys)" << endl;
gmacs_data << nsex << " # Number of sexes" << endl;
gmacs_data << nshell << " # Number of shell condition types" << endl;
gmacs_data << nmature << " # Number of maturity types" << endl;
gmacs_data << nclass << " # Number of size-classes in the model" << endl;
gmacs_data << season_recruitment << " # Season recruitment occurs" << endl;
gmacs_data << season_growth << " # Season molting and growth occurs" << endl;
gmacs_data << season_ssb << " # Season to calculate SSB (changed to match Feb mating)" << endl;
gmacs_data << season_N << " # Season for N output" << endl;
gmacs_data << "# maximum size-class (males then females)" << endl;
gmacs_data << nSizeSex << endl;
// Check at least one matches nclass
if (max(nSizeSex)!=nclass) { cout << "One of the maximum size-classes needs to match nclass; STOPPING" << endl; exit(1); }
END_CALCS
// Set up index pointers
ivector isex(1,n_grp);
ivector ishell(1,n_grp);
ivector imature(1,n_grp);
3darray pntr_hmo(1,nsex,1,nmature,1,nshell);
LOC_CALCS
int h,m,o;
int hmo=1;
gmacs_data << "# Group definitions: " << n_grp << endl;
gmacs_data << "# Index Sex Shell Maturity" << endl;
for ( h = 1; h <= nsex; h++ )
for ( m = 1; m <= nmature; m++ )
for ( o = 1; o <= nshell; o++ )
{
isex(hmo) = h;
ishell(hmo) = o;
imature(hmo) = m;
gmacs_data << "# " << hmo << " : " << sexes(h) << " ";
if (o==NEW_SHELL) gmacs_data << "New shell(" << o << ") ";
if (o==OLD_SHELL) gmacs_data << "old shell(" << o << ") ";
if (m==IMMATURE) gmacs_data << "Immature(" << m << ") ";
if (m==MATURE) gmacs_data << "Mature(" << m << ") ";
pntr_hmo(h,m,o) = hmo++;
gmacs_data << pntr_hmo(h,m,o) << endl;
}
END_CALCS
init_vector size_breaks(1,nclass+1);
vector mid_points(1,nclass);
!! gmacs_data << "# size_breaks (a vector giving the break points between size intervals with dimension nclass+1)" << endl;
!! gmacs_data << size_breaks << endl;
// |-------------------------------|
// | NATURAL MORTALITY |
// |-------------------------------|
!! cout << " * Natural mortality" << endl;
init_int m_prop_type; ///> 1 for vector by season; 2 for matrix by year and season
!! if (m_prop_type != 1 && m_prop_type != 2)
!! { cout << "m_prop_type can only be 1 or 2; STOPPING" << endl; exit(1); }
int m_dim;
LOC_CALCS
m_dim = 1;
if ( m_prop_type == 2 ) m_dim = nyr - syr + 1;
END_CALCS
init_matrix m_prop_in(1,m_dim,1,nseason);
!! gmacs_data << "# Natural mortality per season input type (1 = vector by season, 2 = matrix by season/year)" << endl << " 2" << endl;
matrix m_prop(syr,nyrRetro,1,nseason);
LOC_CALCS
switch ( m_prop_type )
{
// vector by season
case 1:
for ( int i = syr; i <= nyrRetro; i++ )
for ( int j = 1; j <= nseason; j++ )
m_prop(i,j) = m_prop_in(1,j);
break;
// matrix by year and season
case 2:
for ( int i = syr; i <= nyrRetro; i++ )
for ( int j = 1; j <= nseason; j++ )
m_prop(i,j) = m_prop_in(i-syr+1,j);
break;
}
for ( int i = syr; i <= nyrRetro; i++ )
if ( sum(m_prop(i)) > 1.0000001 || sum(m_prop(i)) < 0.999999 )
{
cout << "Error: the proportion of natural mortality applied each season (in the .dat file) does not sum to 1! It sums to " << sum(m_prop(i)) << endl;
exit(1);
}
gmacs_data << "# Proportion of the total natural mortality to be applied each season" << endl;
for (int i=syr;i<=nyrRetro;i++)
gmacs_data << setw(14) << setprecision(11) << setfixed() << m_prop(i) << " # " << i << endl;
END_CALCS
// |-------------|
// | FLEET NAMES |
// |-------------|
!! for (int ifleet=1;ifleet<=nfleet;ifleet++)
!! {
!! *(ad_comm::global_datafile) >> anystring;
!! fleetname+=anystring;
!! }
!! WRITEDAT(fleetname)
// |-------------|
// | FLEET TYPES |
// |-------------|
init_ivector season_type(1,nseason); ///> Set to 0 for discrete; 1 for continuous
!! gmacs_data << "#Season type: Set to 1 for continuous F and 0 for instantanous F" << endl;
!! gmacs_data << season_type << endl;
// |---------------|
// |--CLASS Subst--|
// |---------------|
LOCAL_CALCS
//class to provide substitutions from/to strings/integers
class Subst{
public:
int fleetID(adstring& flt,adstring_array& fleetname){
int id = 0;
for (int f=fleetname.indexmin();f<=fleetname.indexmax();f++)
if (flt==fleetname[f]) id = f;
return id;
cout<<"Problem assigning fleetID to '"<< flt <<"'."<< endl;
cout<<"Allowed values are ";
for (int f=fleetname.indexmin();f<fleetname.indexmax();f++)
cout<<"'"<<fleetname[f]<<"', ";
cout<<"or '"<<fleetname[fleetname.indexmax()]<<"'."<< endl;
exit(-1);
}
int catchTypeID(adstring& str){
int id = -1;
adstring strp = to_lower(str);
if (strp=="retained") return(RETAINED);
if (strp=="discard") return(DISCARDED);
if (strp=="discarded") return(DISCARDED);
if (strp=="total") return(TOTALCATCH);
cout<<"Problem assigning catchTypeID to '"<< str <<"'."<< endl;
cout<<"Allowed values are 'retained', 'discard', 'discarded' or 'total'."<< endl;
exit(-1);
return(id);
}
int unitsTypeID(adstring& str){
int id = -1;
adstring strp = to_lower(str);
if (strp=="abundance") return(ABUNDANCE);
if (strp=="biomass") return(BIOMASS);
cout<<"Problem assigning unitsTypeID to '"<< str <<"'."<< endl;
cout<<"Allowed values are 'abundance' or 'biomass'."<< endl;
exit(-1);
return(id);
}
int indexTypeID(adstring& str){
int id = -1;
adstring strp = to_lower(str);
if (strp=="sel") return(1);
if (strp=="sel+ret") return(2);
cout<<"Problem assigning indexTypeID to '"<< str <<"'."<< endl;
cout<<"Allowed values are 'sel' or 'sel+ret'."<< endl;
exit(-1);
return(id);
}
int sexID(adstring& str){
int id = -1;
adstring strp = to_lower(str);
if (strp=="males") return(MALES);
if (strp=="females") return(FEMALES);
if (strp=="male") return(MALES);
if (strp=="female") return(FEMALES);
if (strp=="undetermined") return(UNDET_SEX);
return(id);
cout<<"Problem assigning sexID to '"<< str <<"'."<< endl;
cout<<"Allowed values are 'male', 'males', 'female', 'females', or 'undetermined'."<< endl;
exit(-1);
}
int matID(adstring& str){
int id = -1;
adstring strp = to_lower(str);
if (strp=="immature") return(IMMATURE);
if (strp=="mature") return(MATURE);
if (strp=="undetermined") return(UNDET_MATURE);
cout<<"Problem assigning matID to '"<< str << endl;
cout<<"Allowed values are 'immature' or 'mature'."<< endl;
exit(-1);
return(id);
}
int shellID(adstring& str){
int id = -1;
adstring strp = to_lower(str);
if (strp=="new shell") return(NEW_SHELL);
if (strp=="new_shell") return(NEW_SHELL);
if (strp=="old shell") return(OLD_SHELL);
if (strp=="old_shell") return(OLD_SHELL);
if (strp=="undetermined") return(UNDET_SHELL);
cout<<"Problem assigning shellID to '"<< str <<"'."<< endl;
cout<<"Allowed values are 'new shell', 'new_shell', 'old shell', 'old_shell', or 'undetermined'."<< endl;
exit(-1);
return(id);
}
};
Subst substStuff;
END_CALCS
// |--------------|
// | CATCH SERIES |
// |--------------|
!! cout << " * Catch data" << endl;
!! gmacs_data << "\n"<<endl;
!! gmacs_data << "##------------------------------------------------------------" << endl;
!! gmacs_data << "##--CATCH DATA------------------------------------------------" << endl;
!! gmacs_data << "##------------------------------------------------------------" << endl;
init_int fmtCDS_in;
!! gmacs_data << fmtCDS_in << " #--input catch data format (0: old format, 1: new format)" << endl;
init_int nCatchDF;
!! gmacs_data << nCatchDF << " #--Number of catch data frames" << endl;
ivector nCatchRows(1,nCatchDF); // this can't be an init_vector here--incompatible with "new" format
3darray dCatchData(1,nCatchDF); // array of catch data WTS: full allocation delayed until nCatchRows is determined
!!float TempW;
!!float SDlogD;
LOCAL_CALCS
{
cifstream* pGD = ad_comm::global_datafile;
if (fmtCDS_in==0){
//--read in using old format
(*pGD) >> nCatchRows;
gmacs_data << "# Number of lines for each dataframe (this is not correct for retrospective analyses)" << endl;
gmacs_data << nCatchRows << endl;
for (int idf=1;idf<=nCatchDF;idf++) dCatchData(idf).allocate(1,nCatchRows(idf),1,11);//--finish allocation
(*pGD) >> dCatchData;
} else {
//--read in using new format
adstring unitsType,catchType,fleet,sex,maturity, shell;
int iUT,iCT,iF,iX,iM,iS;
for (int idf=1;idf<=nCatchDF;idf++) {
gmacs_data << "#----------------" << endl;
gmacs_data << "# catch dataframe number " << idf << endl;
(*pGD) >> unitsType; iUT = substStuff.unitsTypeID(unitsType);
(*pGD) >> catchType; iCT = substStuff.catchTypeID(catchType);
(*pGD) >> fleet; iF = substStuff.fleetID(fleet,fleetname);
(*pGD) >> sex; iX = substStuff.sexID(sex);
(*pGD) >> maturity; iM = substStuff.matID(maturity);
(*pGD) >> shell; iS = substStuff.shellID(shell);
(*pGD) >> nCatchRows(idf);
gmacs_data << unitsType << " #--units type" << endl;
gmacs_data << catchType << " #--catch type (retained, discard(ed), total)" << endl;
gmacs_data << fleet << " #--fleet name" << endl;
gmacs_data << sex << " #--sex (male(s), female(s), undetermined)" << endl;
gmacs_data << maturity << " #--maturity (immature, mature, undetermined)" << endl;
gmacs_data << shell << " #--shell condition (new shell, old shell, undetermined)" << endl;
gmacs_data << nCatchRows(idf) << " #--number of rows in dataframe" << endl;
dmatrix inpCatchData(1,nCatchRows(idf),1,7);
dCatchData(idf).allocate(1,nCatchRows(idf),1,11);//--finish allocation
(*pGD) >> inpCatchData;
gmacs_data << "#year season value cv multiplier effort discard_mortality" << endl;
gmacs_data << inpCatchData << endl;
for (int irw=1;irw<=nCatchRows(idf);irw++){
dCatchData(idf,irw, 1) = (int) inpCatchData(irw,1);
dCatchData(idf,irw, 2) = (int) inpCatchData(irw,2);
dCatchData(idf,irw, 3) = iF;
dCatchData(idf,irw, 4) = iX;
dCatchData(idf,irw, 5) = inpCatchData(irw,3);
dCatchData(idf,irw, 6) = inpCatchData(irw,4);
dCatchData(idf,irw, 7) = iCT;
dCatchData(idf,irw, 8) = iUT;
dCatchData(idf,irw, 9) = inpCatchData(irw,5);
dCatchData(idf,irw,10) = inpCatchData(irw,6);
dCatchData(idf,irw,11) = inpCatchData(irw,7);
}//--irw
}//--idf
gmacs_data << "#--old format:"<<endl;
}//--end reading new format
gmacs_data << "## Sex: 1 = male, 2 = female, 0 = both" << endl;
gmacs_data << "## Type of catch: 1 = retained, 2 = discard, 0 = total" << endl;
gmacs_data << "## Units of catch: 1 = biomass, 2 = numbers" << endl;
gmacs_data << "## Mult: 1= use data as they are, 2 = multiply by this number (e.g., lbs to kg)" << endl;
gmacs_data << "# Year Season Fleet Sex Obs CV Type Units Mult Effort Discard_mortality" << endl;
for (int iCatOut=1;iCatOut<=nCatchDF;iCatOut++){
for (int irow=1;irow<=nCatchRows(iCatOut); irow++) {
if (dCatchData(iCatOut,irow,1) <= nyrRetro) {
if (fmtCDS_in>0) gmacs_data << "# ";
gmacs_data << (int) dCatchData(iCatOut,irow)(1) << " ";
gmacs_data << (int) dCatchData(iCatOut,irow)(2) << " ";
gmacs_data << (int) dCatchData(iCatOut,irow)(3) << " ";
gmacs_data << (int) dCatchData(iCatOut,irow)(4) << " ";
gmacs_data << dCatchData(iCatOut,irow)(5,6) << " ";
gmacs_data << (int) dCatchData(iCatOut,irow)(7) << " ";
gmacs_data << (int) dCatchData(iCatOut,irow)(8) << " ";
gmacs_data << dCatchData(iCatOut,irow)(9,11) << " ";
anystring = "# " + fleetname(dCatchData(iCatOut,irow,3));
if (dCatchData(iCatOut,irow,4)==MALES) anystring = anystring +"_male";
if (dCatchData(iCatOut,irow,4)==FEMALES) anystring = anystring +"_female";
if (dCatchData(iCatOut,irow,7)==TOTALCATCH) anystring = anystring +"_total";
if (dCatchData(iCatOut,irow,7)==RETAINED) anystring = anystring +"_retained";
if (dCatchData(iCatOut,irow,7)==DISCARDED) anystring = anystring +"_discard";
if (dCatchData(iCatOut,irow,8)==BIOMASS) anystring = anystring +"_biomass";
if (dCatchData(iCatOut,irow,8)==ABUNDANCE) anystring = anystring +"_numbers";
if (dCatchData(iCatOut,irow,6) <= 0) {
cout << "Error: CV of catch is zero (or less) for group " << iCatOut << " row " << irow << endl;
exit(1);
}
gmacs_data << anystring << " ";
SDlogD = sqrt(log(1.0 + square(dCatchData(iCatOut,irow,6))));
TempW = 0.5/(SDlogD*SDlogD);
gmacs_data << "Sd of log = " << SDlogD << "; Weight = " << TempW << " ";
gmacs_data << endl;
}//--dCatchData(iCatOut,irow,1) <= nyrRetro
}//--irow
}//--iCatOut
}
END_CALCS
matrix obs_catch(1,nCatchDF,1,nCatchRows);
matrix obs_effort(1,nCatchDF,1,nCatchRows);
3darray dCatchData_out(1,nCatchDF,syr,nyr,1,11);
matrix obs_catch_out(1,nCatchDF,syr,nyr);
matrix catch_cv(1,nCatchDF,1,nCatchRows);
matrix catch_dm(1,nCatchDF,1,nCatchRows);
matrix catch_mult(1,nCatchDF,1,nCatchRows);
LOC_CALCS
for ( int k = 1; k <= nCatchDF; k++ )
{
catch_mult(k) = column(dCatchData(k),9);
obs_catch(k) = column(dCatchData(k),5);
catch_cv(k) = column(dCatchData(k),6);
catch_dm(k) = column(dCatchData(k),11);
obs_catch(k) = elem_prod(obs_catch(k), catch_mult(k)); ///> rescale catch by multiplier
obs_effort(k) = column(dCatchData(k),10);
}
ECHO(obs_catch);
ECHO(catch_cv);
END_CALCS
// From the catch series determine the number of fishing mortality rate parameters that need to be estimated.
// Note that there are a number of combinations which require an F to be estimated.
ivector nFparams(1,nfleet); ///> The number of deviations required for each fleet
ivector nYparams(1,nfleet); ///> The number of deviations for female Fs
3darray fhit(syr,nyrRetro,1,nseason,1,nfleet); ///> set to 1 for present; 0 for absent
3darray yhit(syr,nyrRetro,1,nseason,1,nfleet); ///> set to 1 for present; 0 for absent
matrix dmr(syr,nyrRetro,1,nfleet); ///> discard mortality - has to be the same for all catch series for each fleet
matrix fhitfut(1,nseason,1,nfleet); ///> set to 1 for present in any year; 0 for absent
LOC_CALCS
nFparams.initialize();
nYparams.initialize();
fhit.initialize();
yhit.initialize();
dmr.initialize();
echoinput<<"\n\nDetermining number of fishing rate parameters to be estimated."<<endl;
for ( int k = 1; k <= nCatchDF; k++ )
{
echoinput<<"catchDF (k) = "<<k<<endl;
for ( int i = 1; i <= nCatchRows(k); i++ )
if (dCatchData(k)(i,1) <= nyrRetro && dCatchData(k)(i,1) >= syr)
{
int y = dCatchData(k)(i,1); ///> year
int j = dCatchData(k)(i,2); ///> season
int g = dCatchData(k)(i,3); ///> fleet
int h = dCatchData(k)(i,4); ///> sex
echoinput<<"Processing i,y,j,g,h (row,year, season, fleet, sex): "<<i<<" "<<y<<" "<<j<<" "<<g<<" "<<h<<endl;
// Check whether the fleet is instantaneous but natural mortality in the relevant period is not zero!
if (season_type(j) == INSTANT_F && m_prop(y,j) > 0)
{
cout << "The proportion of M should be zero for season " << j << " in year " << y << endl;
echoinput << "The proportion of M should be zero for season " << j << " in year " << y << endl;
exit(1);
}
if ( !fhit(y,j,g) )
{
fhit(y,j,g) ++;
nFparams(g) ++;
dmr(y,g) = catch_dm(k)(i);//TODO: presumably dmr could depend on season and sex, as well as year and gear/fleet
}
if ( !yhit(y,j,g) && h == 2 )
{
yhit(y,j,g) ++;
nYparams(g) ++;
dmr(y,g) = catch_dm(k)(i);
}
}
}
for (int g=1;g<=nfleet; g++) { if (nFparams(g) == 0) nFparams(g) = 1; }
for (int g=1;g<=nfleet; g++) { if (nYparams(g) == 0) nYparams(g) = 1; }
ECHO(nFparams); ECHO(nYparams); // ECHO(fhit); ECHO(yhit); ECHO(dmr);
echoinput << "fhit" << endl;
echoinput << "iy(yr) j(season) hit_for_fleet " <<endl;
fhitfut.initialize();
for (int iy=syr;iy<=nyrRetro;iy++)
for (int j=1;j<=nseason;j++)
{
echoinput << iy << " " << j << " ";
for (int g=1;g<=nfleet;g++) echoinput << fhit(iy,j,g) << " ";
for (int g=1;g<=nfleet;g++) if (fhit(iy,j,g)==1) fhitfut(j,g) = 1;
echoinput << endl;
}
echoinput << "fhitfut" << endl;
echoinput << "j(season) hit_for_fleet? " <<endl;
for (int j=1;j<=nseason;j++)
{
echoinput << " " << j << " ";
for (int g=1;g<=nfleet;g++) echoinput << fhitfut(j,g) << " ";
echoinput << endl;
}
echoinput << "yhit" << endl;
echoinput << "iy(yr) j(season) hit_for_fleet? " <<endl;
for (int iy=syr;iy<=nyrRetro;iy++)
for (int j=1;j<=nseason;j++)
{
echoinput << iy << " " << j << " ";
for (int g=1;g<=nfleet;g++) echoinput << yhit(iy,j,g) << " ";
echoinput << endl;
}
ECHO(dmr);
echoinput<<"dmr:"<<endl;
echoinput<<"year fleet dmr"<<endl;
for (int iy=syr;iy<=nyrRetro;iy++)
for (int g=1;g<=nfleet;g++) echoinput<<iy<<" "<<g<<" "<<dmr(iy,g)<<endl;
// Check for errors in discard rate assumptions
for ( int k = 1; k <= nCatchDF; k++ )
for ( int i = 1; i <= nCatchRows(k); i++ )
if (dCatchData(k)(i,1) <= nyrRetro && dCatchData(k)(i,1) >= syr)
{
int y = dCatchData(k)(i,1); ///> year
int g = dCatchData(k)(i,3); ///> fleet
if (catch_dm(k)(i) != dmr(y,g))
{ cout << "ERROR: discard rates do not match: year " << y << " and fleet " << g << " in CatchDF " << k<< endl;
gmacs_data << "ERROR: discard rates do not match: year " << y << " and fleet " << g << " in CatchDF " << k<< endl;
gmacs_data << "k = "<<k<<" i = "<<i<<" y = "<<y<<" g = "<<g<<endl;
gmacs_data << "catch_dm(k)(i) = " <<catch_dm(k)(i) << " dmr(y,g) = " << dmr(y,g) << endl;
exit(1); }
}
// Create the dCatchData_out object for output and plotting in R, this object simply fills in the years that don't have data with zero catch
dCatchData_out.initialize();
obs_catch_out.initialize();
for ( int k = 1; k <= nCatchDF; k++ )
for ( int i = syr; i <= nyrRetro; i++ )
{
dCatchData_out(k,i,1) = i; // Year
int j = 1;
for ( int ii = 1; ii <= nCatchRows(k); ii++ )
{
if ( i == dCatchData(k,ii,1) ) // year index
{
j = ii;
obs_catch_out(k,i) = dCatchData(k,ii,5); // Obs
dCatchData_out(k,i,5) = dCatchData(k,ii,5); // Obs
dCatchData_out(k,i,6) = dCatchData(k,ii,6); // CV
dCatchData_out(k,i,9) = dCatchData(k,j,9); // Mult
dCatchData_out(k,i,10) = dCatchData(k,j,10); // Effort
dCatchData_out(k,i,11) = dCatchData(k,j,11); // Discard mortality
}
}
// Replicate these variables
dCatchData_out(k,i,2) = dCatchData(k,j,2); // Season
dCatchData_out(k,i,3) = dCatchData(k,j,3); // Fleet
dCatchData_out(k,i,4) = dCatchData(k,j,4); // Sex
dCatchData_out(k,i,7) = dCatchData(k,j,7); // Type
dCatchData_out(k,i,8) = dCatchData(k,j,8); // Units
}
END_CALCS
// |----------------------------|
// | RELATIVE ABUNDANCE INDICES |
// |----------------------------|
!! cout << " * Abundance data" << endl;
!! gmacs_data << "\n" << endl;
!! gmacs_data << "##------------------------------------------------------------" << endl;
!! gmacs_data << "##--RELATIVE ABUNDANCE DATA-----------------------------------" << endl;
!! gmacs_data << "##------------------------------------------------------------" << endl;
init_int fmtRAD; ///> Format type (0: old format, 1: new format)
!!gmacs_data << fmtRAD << " #--input format type (0: old format, 1: new format)" << endl;
init_int nSurveys; ///> Number of survey series
!! gmacs_data << nSurveys << " #--Number of dataframes" << endl; //TODO: change name to nSurveyDFs
ivector SurveyType(1,nSurveys); ///> Type of survey
int nSurveyRows; ///> total number of rows in survey dataframes
matrix dSurveyData; ///> survey data
LOCAL_CALCS
{
cifstream* pGD = ad_comm::global_datafile;
if (fmtRAD==0){
//old format
gmacs_data << "# Type of 'survey' catchability (1=Selectivity; 2=Selectivity+Retention), by data frame" << endl;
(*pGD) >> SurveyType;
gmacs_data << SurveyType << endl;
gmacs_data << "# Number of data rows, by data frame" << endl;
(*pGD) >> nSurveyRows;
gmacs_data << "# NOTE: this is not correct for retrospective analyses" << endl;
gmacs_data << nSurveyRows << endl;;
dSurveyData.allocate(1,nSurveyRows,0,9);
(*pGD) >> dSurveyData;
gmacs_data << "# Survey data:"<<endl;
gmacs_data << dSurveyData <<endl;
} else {
//new format
adstring indexType, unitsType, fleet, sexType, matType, shlType;
ivector nrows(1,nSurveys), idIndex(1,nSurveys),idUnits(1,nSurveys);
ivector idFlt(1,nSurveys),idSex(1,nSurveys),idMat(1,nSurveys),idShl(1,nSurveys);
d3_array inpDFs(1,nSurveys);
for (int idf = 1;idf<=nSurveys;idf++){
gmacs_data << "#----------------" << endl;
gmacs_data << "# relative abundance dataframe number " << idf << endl;
(*pGD) >> unitsType; idUnits(idf) = substStuff.unitsTypeID(unitsType);
(*pGD) >> indexType; idIndex(idf) = substStuff.indexTypeID(indexType);
(*pGD) >> fleet; idFlt(idf) = substStuff.fleetID(fleet,fleetname);
(*pGD) >> sexType; idSex(idf) = substStuff.sexID(sexType);
(*pGD) >> matType; idMat(idf) = substStuff.matID(matType);
(*pGD) >> shlType; idShl(idf) = substStuff.shellID(shlType);
(*pGD) >> nrows(idf);
gmacs_data << indexType << " #--abundance index type ('sel' or 'sel+ret')" << endl;
gmacs_data << unitsType << " #--units type ('abundance' or 'biomass')" << endl;
gmacs_data << fleet << " #--fleet name" << endl;
gmacs_data << sexType << " #--sex (male(s), female(s), undetermined)" << endl;
gmacs_data << matType << " #--maturity (immature, mature, undetermined)" << endl;
gmacs_data << shlType << " #--shell condition (new_shell, old_shell, undetermined)" << endl;
inpDFs(idf).allocate(1,nrows(idf),1,7);//--allocate dataframe
(*pGD) >> inpDFs(idf);
gmacs_data << "# q_index year season value cv multiplier CPUE_timing " <<endl;
gmacs_data << inpDFs(idf) <<endl;
}//--idf
nSurveyRows = sum(nrows);
dSurveyData.allocate(1,nSurveyRows,0,9);
int jrw = 1;
for (int idf = 1;idf<=nSurveys;idf++){
SurveyType(idf) = idIndex(idf);
for (int irw = 1;irw<=nrows(idf);irw++){
dSurveyData(jrw, 0) = inpDFs(idf,irw,1); //--q_index
dSurveyData(jrw, 1) = inpDFs(idf,irw,2); //--year
dSurveyData(jrw, 2) = inpDFs(idf,irw,3); //--season
dSurveyData(jrw, 3) = idFlt(idf); //--fleet
dSurveyData(jrw, 4) = idSex(idf); //--sex
dSurveyData(jrw, 5) = idMat(idf); //--maturity
dSurveyData(jrw, 6) = inpDFs(idf,irw,4); //--observed value
dSurveyData(jrw, 7) = inpDFs(idf,irw,5); //--cv
dSurveyData(jrw, 8) = inpDFs(idf,irw,6); //--units scaling
dSurveyData(jrw, 9) = inpDFs(idf,irw,7); //--cpue timing
jrw++;
}//--irw
}//--idf
}//--if (fmtRAD)
}
END_CALCS
vector obs_cpue(1,nSurveyRows);
vector cpue_cv(1,nSurveyRows);
vector cpue_sd(1,nSurveyRows);
vector cpue_cv_add(1,nSurveyRows);
vector cpue_time(1,nSurveyRows);
LOC_CALCS
obs_cpue = column(dSurveyData,6);
cpue_cv = column(dSurveyData,7);
cpue_sd = sqrt(log(1.0 + square(cpue_cv)));
cpue_time = column(dSurveyData,9);
if (fmtRAD) gmacs_data << "# old format:" << endl;
gmacs_data << "## Index: One q is estimated for each index (the number of index values should match nSurveys" << endl;
gmacs_data << "## Sex: 1 = male, 2 = female, 0 = both" << endl;
gmacs_data << "## Maturity: 1 = mature, 2 = immature, 0 = both" << endl;
gmacs_data << "## Units of survey: 1 = biomass, 2 = numbers" << endl;
gmacs_data << "# row Index Year Season Fleet Sex Maturity Obs CV Units CPUE_time" << endl;
for (int irow=1;irow<=nSurveyRows; irow++)
if (((dSurveyData(irow,1) <= nyrRetro) || ((dSurveyData(irow,1) == nyrRetro+1) && (dSurveyData(irow,2) == 1))) && dSurveyData(irow,1) >= syr)
{
gmacs_data << "# " << irow << " " << (int) dSurveyData(irow,0) << " ";
gmacs_data << (int) dSurveyData(irow,1) << " ";//year