GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — seapodym-codebase/src/ReadWrite_TXT.cpp at master · PacificCommunity/seapodym-codebase Expand file tree/ Copy pathReadWrite_TXT.cppMore file actions 1081 lines (940 loc) · 40.9 KB / Copy pathReadWrite_TXT.cppFile metadata and controls1081 lines (940 loc) · 40.9 KB 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 //#include "StdAfx.h" #include "ReadWrite.h" #include "SaveTimeArea.h" #include "Numfunc.h" ////////////////////////////////////////////////////////// //WRITE HEADERS OF FR_SP_AREA.TXT //ecriture des noms de variable du fichier species_FR_area.txt ////////////////////////////////////////////////////////// /* void CReadWrite::InitFRspeciesFileTxt(CParam& param) { const int nb_species = param.get_nbspecies(); const int nb_forage = param.get_nbforage(); //Generate the name of the files for (int sp=0; sp<nb_species;sp++) FileSpFR.push_back(param.strdir_output+param.sp_name[sp]+"_FR_area.txt"); int nb_reg =0; ofstream ecritFR; for (int sp=0; sp<nb_species;sp++) { ecritFR.open(FileSpFR[sp].c_str(), ios::out); if (ecritFR) { ecritFR << param.sp_name[sp]<<'\t'<<'\t'<<'\t'<<endl; ecritFR << "young: from age "<< param.age_autonomous[sp]<<" to age "<<param.age_mature[sp]<<'\t'<<'\t'<<'\t'; ecritFR<<endl; ecritFR << "Adult: from age "<<param.age_mature[sp]<<" to age " <<param.sp_nb_cohorts[sp] <<'\t'<<'\t'<<'\t'; ecritFR<<endl<<endl; ecritFR << "year" <<'\t'<< "month"<< '\t'; int nb_reg = param.nb_region_sp_B[sp]; if (nb_reg==0) nb_reg = 1; for (int a=0; a<nb_reg; a++) for (int n=0; n< nb_forage; n++) ecritFR << param.sp_name[sp] << " young: area " << param.area_sp_B[sp][a] << " FR " << param.frg_name[n] << '\t'; for (int a=0; a<nb_reg; a++) for (int n=0; n< nb_forage; n++) ecritFR << param.sp_name[sp] << " adult: area " << param.area_sp_B[sp][a] << " FR " << param.frg_name[n] << '\t'; ecritFR << endl; ecritFR.close(); } else cout<<endl<<"WARNING : Failed to initialize file "<<FileSpFR[sp]<<endl; } } /// Recording FR by species by area in files Species_FR.txt void CReadWrite::SaveFRspeciesFileTxt(CParam& param, CMatrices& mat, PMap& map, int mois2, int yr2) { CSaveTimeArea save; const int nb_species = param.get_nbspecies(); const int nb_forage = param.get_nbforage(); // dmatrix FR_area_average; ofstream ecritFR; for (int sp=0; sp< nb_species;sp++){ int nb_reg = param.nb_region_sp_B[sp]; if (nb_reg==0) nb_reg = 1; // FR_area_average.allocate(0,nb_forage-1,0,nb_reg-1); // FR_area_average.initialize(); ecritFR.open(FileSpFR[sp].c_str(), ios::app); if (ecritFR) { ecritFR << yr2 <<'\t' << mois2 <<'\t'; // for (int n=0;n<nb_forage;n++){ // save.AverageByArea(map,FR_species,FR_area_average[n],cell_area,nb_reg); for (int reg=0; reg< param.nb_region_sp_B[sp]; reg++) for (int n=0;n<nb_forage;n++) ecritFR << mat.FR_young(sp,n,reg) <<'\t'; // for (int n=0;n<nb_forage;n++) // save.AverageByArea(map,FR_species,FR_area_average[n],cell_area,nb_reg); for (int reg=0; reg<nb_reg; reg++) for (int n=0;n<nb_forage;n++) ecritFR << mat.FR_adult(sp,n,reg) <<'\t'; // ecritFR << endl; ecritFR.close(); } else cout<<endl<<"WARNING : Cannot write file "<<FileSpFR[sp]<<endl; } } */ ///Put here all variables that need to be initialized for writing void CReadWrite::init_writing(CParam& param) { const int nbi = param.get_nbi(); const int nbj = param.get_nbj(); //this mask will be used in comparison with MFCL estimations mask_catch.allocate(0,nbi-1,0,nbj-1); mask_catch.initialize(); //Note, if no fishing, the use_mask_catch=false also if (!param.use_mask_catch) mask_catch = 1e3; } ////////////////////////////////////////////////////////// // ECRITURE EN-TETE FICHIERS DE SAUVEGARDE SEPODYM 'TEXT' ////////////////////////////////////////////////////////// void CReadWrite::InitSepodymFileTxt(CParam& param) { //cerr << "Force Exit[" << __FILE__ << ':' << __LINE__ << "]: function hasn't been fixed yet\n"; ////////////////////////////////////// //WRITE HEADERS OF SUMDYM.TXT //ecriture des noms de variable du fichier SumDym.txt // fichier sommes mensuelles string fileSumDym = param.strdir_output + "SumDym.txt"; ofstream ecritSumDym; ecritSumDym.open(fileSumDym.c_str(), ios::out); const int nb_species = param.get_nbspecies(); const int nb_fishery = param.get_nbfishery(); const int nb_forage = param.get_nbforage(); if (ecritSumDym) { //ecritSumDym <<"date"<< '\t'<<"tstep"<< '\t' << "P" <<'\t'; ecritSumDym <<"date"<< '\t'<<"tstep"<< '\t' << "P in 10N-45N" << '\t' << "P in 10S-10N" <<'\t'<< "P in 35S-10S" <<'\t'<< "P total" <<'\t'; for(int n = 0; n< nb_forage;n++) { //ecritSumDym <<"Fprime_"<<param.frg_name[n]<<'\t' ecritSumDym <<"F_"<<param.frg_name[n]<<'\t'; //<<"F_"<<param.frg_name[n]<<" in pred. area"<<'\t' //<<"F_"<<param.frg_name[n]<<" required by pred."<<'\t' //<<"Mean Omega_"<<param.frg_name[n]<<'\t' ; } for (int sp=0; sp<nb_species;sp++) { ecritSumDym <<"B Larvae "<<param.sp_name[sp] <<'\t' <<"B Juv "<<param.sp_name[sp] <<'\t' <<"B Rec "<<param.sp_name[sp] <<'\t' <<"B Young "<<param.sp_name[sp] <<'\t' <<"B Adult "<<param.sp_name[sp] <<'\t' <<"B Total"<<param.sp_name[sp] <<'\t'; } if (nb_fishery && !param.flag_no_fishing){ for (int f=0;f<nb_fishery; f++){ for (int sp=0;sp<nb_species;sp++){ if (param.mask_fishery_sp[sp][f]){ ecritSumDym <<"effort " << param.list_fishery_name[f] << '\t' ; ecritSumDym <<"obs C_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumDym <<"pred C_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumDym <<"obs CPUE_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumDym <<"pred CPUE_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; } } } } ecritSumDym << endl; } else { cout<<endl<<"WARNING : Cannot write file "<<fileSumDym<<endl; } ////////////////////////////////////// //WRITE HEADERS OF SUMQAREA.TXT //ecriture des noms de variable du fichier SumQArea.txt // fichier sum by quarter and area (MFCL) string fileSumQA = param.strdir_output + "SumQArea.txt"; ofstream ecritSumQA; ecritSumQA.open(fileSumQA.c_str(), ios::out); //NOTE: cohorts larvae-recruits will be written in numbers, young-adult in tonnes if (ecritSumQA) { for (int sp=0; sp<nb_species;sp++) ecritSumQA << param.sp_name[sp]<< " regions: "<< '\t'<<'\t'<<'\t'; ecritSumQA <<endl; for (int r=0; r<param.nb_region;r++) ecritSumQA << param.area[r]->lgmin <<" "<< param.area[r]->lgmax<< " " << param.area[r]->ltmin << " " << param.area[r]->ltmax << endl; for (int sp=0; sp<nb_species;sp++) ecritSumQA << "juvenile: from age 0 to " <<param.age_autonomous[sp]<<'\t'<<'\t'<<'\t'; ecritSumQA <<endl; for (int sp=0; sp<nb_species;sp++) ecritSumQA << "young: from age "<< param.age_autonomous[sp]<<" to age" << param.age_mature[sp] << " (see maturity at age)"<<'\t'<<'\t'<<'\t'; ecritSumQA <<endl; for (int sp=0; sp<nb_species;sp++) ecritSumQA << "Recruit: at age "<< param.age_recruit[sp] <<'\t'<<'\t'<<'\t'; ecritSumQA <<endl; for (int sp=0; sp<nb_species;sp++) ecritSumQA << "Adult: from age "<<param.age_mature[sp]<<" to age " <<param.sp_a0_adult[sp] <<'\t'<<'\t'<<'\t'; ecritSumQA <<endl; for (int sp=0; sp<nb_species;sp++) ecritSumQA << "Total biomass: from age "<<param.age_autonomous[sp]<< " to " <<param.sp_nb_cohorts[sp] <<'\t'<<'\t'<<'\t'; ecritSumQA <<endl<<endl; ecritSumQA << "year" <<'\t'<<"month" <<'\t' << "day" << '\t'; if (param.nb_region) { for (int sp=0; sp<nb_species;sp++) { int nb_reg = param.nb_region_sp_B[sp]; if (nb_reg>0){ for (int a=0; a<nb_reg; a++) ecritSumQA<<param.sp_name[sp] << " N Larvae region " << param.area_sp_B[sp][a] << '\t'; ecritSumQA<< "Total N Larvae"<<'\t'; for (int a=0; a<nb_reg; a++) ecritSumQA<<param.sp_name[sp] << " N Juv. region " << param.area_sp_B[sp][a] << '\t'; ecritSumQA<< "Total N Juv."<<'\t'; for (int a=0; a<nb_reg; a++) ecritSumQA<<param.sp_name[sp]<< " N Rec. region " << param.area_sp_B[sp][a] << '\t'; ecritSumQA<< "Total N. Rec."<<'\t'; for (int a=0; a<nb_reg; a++) ecritSumQA<<param.sp_name[sp]<< " B Young region " << param.area_sp_B[sp][a] << '\t'; ecritSumQA<< "Total B. Young"<<'\t'; for (int a=0; a<nb_reg; a++) ecritSumQA<<param.sp_name[sp]<< " B Adult region " << param.area_sp_B[sp][a] << '\t'; ecritSumQA<< "Total B Adult"<<'\t'; for (int a=0; a<nb_reg; a++) ecritSumQA<<param.sp_name[sp]<< " B tot. region " << param.area_sp_B[sp][a] << '\t'; ecritSumQA<< "Total B"<<'\t'; } } } ecritSumQA<<endl; ecritSumQA.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<fileSumQA<<endl; } ////////////////////////////////////// // WRITE HEADERS OF SumEEZ.txt files (Inna 06/2011) // one file by EEZ: // date, N.Larvae, N.Juveniles, N.Recruites, B.Young, B.Adult, B.tot, E[f], Cobs[f], Cpred[f] if (param.nb_EEZ!=0){ for (int a=0; a<param.nb_EEZ; a++){ string fileSumEEZ = param.strdir_output + "SumEEZ" + "_" + param.EEZ_name[a] + ".txt"; ofstream ecritSumEEZ; ecritSumEEZ.open(fileSumEEZ.c_str(), ios::out); if (ecritSumEEZ){ ecritSumEEZ << "year" <<'\t'<<"month" <<'\t' << "day" << '\t'; for (int sp=0; sp<nb_species;sp++){ //NOTE: cohorts larvae-recruits will be written in numbers, young-adult in tonnes ecritSumEEZ<<param.sp_name[sp]<< " N Larvae " << param.EEZ_name[a] << '\t'; ecritSumEEZ<<param.sp_name[sp]<< " N Juv. " << param.EEZ_name[a] << '\t'; ecritSumEEZ<<param.sp_name[sp]<< " N Rec. " << param.EEZ_name[a] << '\t'; ecritSumEEZ<<param.sp_name[sp]<< " B Young " << param.EEZ_name[a] << '\t'; ecritSumEEZ<<param.sp_name[sp]<< " B Adult " << param.EEZ_name[a] << '\t'; ecritSumEEZ<<param.sp_name[sp]<< " B tot. " << param.EEZ_name[a] << '\t'; if (nb_fishery && !param.flag_no_fishing){ for (int f=0;f<nb_fishery; f++){ if (param.mask_fishery_sp[sp][f]){ ecritSumEEZ <<"Nb.obs " << param.list_fishery_name[f] << '\t' ; ecritSumEEZ <<"effort " << param.list_fishery_name[f] << '\t' ; ecritSumEEZ <<"obs C_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumEEZ <<"pred C_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumEEZ <<"obs CPUE_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumEEZ <<"std obs CPUE_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; ecritSumEEZ <<"pred CPUE_" << param.sp_name[sp]<<"_"<<param.list_fishery_name[f] <<'\t' ; } } } } ecritSumEEZ<<endl; ecritSumEEZ.close(); } else cout<<endl<<"WARNING : Cannot write file "<<fileSumEEZ<<endl; } } //////////////////////////////////// //WRITE HEADER OF MEANVAR.TXT for (int sp=0; sp<nb_species;sp++){ string fileMeanVar = param.strdir_output + param.sp_name[sp] + "_MeanVar.txt"; ofstream ecritMeanVar; ecritMeanVar.open(fileMeanVar.c_str(), ios::out); if (ecritMeanVar){ ecritMeanVar << "year" <<'\t'<<"month" <<'\t' << "day" << '\t'; for (int sp=0; sp<nb_species;sp++){ int nb_ages = param.sp_nb_cohorts(sp); for (int a=0; a< nb_ages; a++) ecritMeanVar<<param.sp_name[sp]<< " mortality-at-age " << a << '\t'; for (int a=0; a< nb_ages; a++) ecritMeanVar<<param.sp_name[sp]<< " speed-at-age " << a << '\t'; for (int a=0; a< nb_ages; a++) ecritMeanVar<<param.sp_name[sp]<< " diffusion-at-age " << a << '\t'; for (int a=0; a< nb_ages; a++) ecritMeanVar<<param.sp_name[sp]<< " temperature-at-age " << a << '\t'; } ecritMeanVar<<endl; } else cout<<endl<<"WARNING : Cannot write file "<<fileMeanVar<<endl; } ////////////////////////////////////// // WRITE HEADERS OF SPATIALCORR.TXT // ecriture des noms de variable du fichier SpatialCorr.txt // un fichier par espece // fichier correlations captures predites-observees if (!param.flag_no_fishing){ if (nb_fishery) { //Generate the name of the files for (int sp=0; sp<nb_species;sp++) { dymFileSpCorr.push_back(param.strdir_output+param.sp_name[sp]+"_Spatial_Corr.txt"); } } ofstream ecritcor; if (nb_fishery) { for (int sp=0; sp<nb_species;sp++) { ecritcor.open(dymFileSpCorr[sp].c_str(), ios::out); if (ecritcor) { ecritcor <<"date"<< '\t' ; for (int f=0;f<nb_fishery; f++){ if (param.mask_fishery_sp[sp][f]) ecritcor <<"n" << '\t'<<"r " << param.list_fishery_name[f]<<"_"<<param.sp_name[sp]<< '\t'<<"prob" << '\t' << "cpue_r " << param.list_fishery_name[f]<<"_"<<param.sp_name[sp]<< '\t'<<"prob" << '\t'; } ecritcor<< endl; ecritcor.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<dymFileSpCorr[sp]<<endl; } } } } ////////////////////////////////////// //WRITE HEADERS OF SP_LF_Q_FISHERY.TXT //ecriture des noms de variable du fichier LF_QFishery.txt //fichier Frequences de longueurs par trimestre if (!param.flag_no_fishing){ if (nb_fishery>0) { //Generate the name of the files for (int sp=0; sp<nb_species;sp++) { dymFileSpLF.push_back(param.strdir_output+param.sp_name[sp]+"_LF_Q_fishery.txt"); } } ofstream ecritQtr_N; if (nb_fishery > 0){ for (int sp=0; sp<nb_species;sp++){ const int a0 = param.sp_a0_adult[sp]; const int nb_ages = param.sp_nb_cohorts[sp]; ecritQtr_N.open(dymFileSpLF[sp].c_str(), ios::out); if (ecritQtr_N) { int nb_reg = param.nb_region_sp_B[sp]; ecritQtr_N << nb_reg << " " << nb_fishery << endl; for (int a=a0;a<nb_ages;a++) ecritQtr_N <<param.length[sp][a]<<'\t'; ecritQtr_N << endl; ecritQtr_N << "Year "<< '\t' << "Quarter "<< '\t'<< "Month " << '\t'<< "Fishery " << '\t' << "Region " << '\t' << "LF[1] .. " << "LF[" << nb_ages << "]" << endl; /* ecritQtr_N <<"Quarter "<< '\t'<< "Year "<< endl; ecritQtr_N << "length" <<'\t' ; for (int reg=0; reg< param.nb_region_sp_B[sp]; reg++){ for (int f=0; f<nb_fishery; f++){ if (param.mask_fishery_sp[sp][f]) ecritQtr_N<<param.list_fishery_name[f]<<"_"<<param.sp_name[sp]<<"_region_"<<param.area_sp_B[sp][reg] <<'\t'; } } ecritQtr_N << endl; */ ecritQtr_N.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<dymFileSpLF[sp]<<endl; } } } } } void CReadWrite::InitFluxesCohortsFileTxt(CParam& param) { int nb_species = param.get_nbspecies(); int nb_reg = param.nb_EEZ; if (!nb_reg){ nb_reg = param.nb_region_sp_B[0];//attn sp =0! } if (param.nb_region || param.nb_EEZ){ for (int sp=0; sp<nb_species;sp++){ double mean_age_cohort = (double).5*param.sp_unit_cohort[sp][0]; for (int a=0; a<param.sp_nb_cohorts[sp]; a++){ std::ostringstream ostr; ostr << a; string fileJreg = param.strdir_output + param.sp_name[sp] + "_FluxesRegion_age" + ostr.str() + ".txt"; ofstream ecritJreg; ecritJreg.open(fileJreg.c_str(), ios::out); if (ecritJreg){ ecritJreg << "Regional fluxes predicted for "<< param.sp_name[sp] << endl; ecritJreg << "Mean age(months) " << mean_age_cohort << endl; ecritJreg << "Mean length(cm) " << param.length(sp,a) << endl; ecritJreg << "Mean weight(kg) " << param.weight(sp,a) << endl; ecritJreg << "Nb.regions " << nb_reg << endl; ecritJreg<<endl; ecritJreg.close(); } else cout<<endl<<"WARNING : Cannot write file "<<fileJreg<<endl; if (a<param.sp_nb_cohorts[sp]-1) mean_age_cohort = mean_age_cohort + .5*param.sp_unit_cohort[sp][a]+.5*param.sp_unit_cohort[sp][a+1]; } } } } void CReadWrite::SaveFluxesCohortsFileTxt(CParam& param, CMatrices& mat, PMap& map, int day, int month, int year) { int nb_species = param.get_nbspecies(); int fluxes_between_polygons = 1; int nb_reg = param.nb_EEZ; if (!nb_reg){ nb_reg = param.nb_region_sp_B[0];//attn sp =0! fluxes_between_polygons = 0; } if (param.nb_region || param.nb_EEZ){ for (int sp=0; sp<nb_species;sp++){ for (int a=0; a<param.sp_nb_cohorts[sp]; a++){ std::ostringstream ostr; ostr << a; string fileJreg = param.strdir_output + param.sp_name[sp] + "_FluxesRegion_age" + ostr.str() + ".txt"; ofstream ecritJreg; ecritJreg.open(fileJreg.c_str(), ios::app); if (ecritJreg){ ecritJreg << "# "<< year << '-' << month << '-' << day << endl; if (!fluxes_between_polygons){ int nbreg = param.nb_region_sp_B[sp]; if (nbreg>0){ for (int ri=0; ri<nb_reg; ri++){ int reg_i = param.area_sp_B[sp][ri]-1; for (int rj=0; rj<nb_reg; rj++){ int reg_j = param.area_sp_B[sp][rj]-1; ecritJreg << mat.fluxes_region(a,reg_i,reg_j) << '\t'; } ecritJreg << endl; } } } else { for (int ri=0; ri<nb_reg; ri++){ for (int rj=0; rj<nb_reg; rj++){ ecritJreg << mat.fluxes_region(a,ri,rj) << '\t'; } ecritJreg << endl; } } ecritJreg.close(); } else cout<<endl<<"WARNING : Cannot append to the file "<<fileJreg<<endl; } } } } /////////////////////////////////////////////////////////////////////////////// void CReadWrite::SaveSepodymFileTxt(CParam& param, CMatrices& mat, PMap& map, dvector sumP, DVECTOR& sumF, DVECTOR& sumFprime, DVECTOR& sumF_area_pred, DVECTOR& sumF_required_by_sp, DVECTOR& mean_omega_sp,int day, int mois2, int yr2, int t_total, /*int ntq,*/ int qtr1, int qtr2, int nbi, int nbj) { //cerr << "Force Exit[" << __FILE__ << ':' << __LINE__ << "]: function hasn't been fixed yet\n"; CSaveTimeArea save; CNumfunc fonction; const int nb_species = param.get_nbspecies(); const int nb_fishery = param.get_nbfishery(); const int nb_forage = param.get_nbforage(); ////////////////////////////////////// //UPDATE SUMDYM.TXT double total=0.f; //opening the existing file in mode append string fileSumDym = param.strdir_output +"SumDym.txt"; ofstream ecritSumDym; ecritSumDym.open(fileSumDym.c_str(), ios::app); if (ecritSumDym) { // writing the date // Patrick 23Nov04 //Modified Inna 27Jan11 ecritSumDym << yr2 << "-" << mois2 << "-" << day <<'\t'; //writing the data ecritSumDym << t_total << '\t'<< sumP[0] << '\t' << sumP[1] << '\t' << sumP[2] << '\t' << sumP[3] << '\t'; for (int n=0;n<nb_forage;n++) { //ecritSumDym << sumFprime[n] <<'\t' ecritSumDym <<sumF[n] <<'\t'; //<< sumF_area_pred[n]<<'\t' //<<sumF_required_by_sp[n] <<'\t' //<< mean_omega_sp[n] <<'\t'; } for (int sp=0; sp<nb_species;sp++) { ecritSumDym << mat.sum_B_larvae[sp] <<'\t' << mat.sum_B_juv[sp]<<'\t' << mat.sum_B_recruit[sp]<<'\t' << mat.sum_B_young[sp] <<'\t' << mat.sum_B_adult[sp] <<'\t' << mat.sum_total_pop[sp]<<'\t'; } if (nb_fishery>0 && !param.flag_no_fishing){ int k = 0; for (int f=0; f<nb_fishery; f++){ for (int sp=0;sp<nb_species;sp++){ if (param.mask_fishery_sp[sp][f]){ // observed fishing effort // calcule et enregistre l'effort total de la pecherie total=0.f; for (int i=1; i< nbi-1; i++){ for (int j=1; j < nbj-1 ; j++){ if (map.carte(i,j)) total += mat.effort[f][i][j]; } } ecritSumDym << total << '\t'; //cout <<"total effort by fishery "<<f<< " " << total << endl; //for (int sp=0; sp< nb_species;sp++){ // if (param.mask_fishery_sp[sp][f]){ // observed catch total=0.f; for (int i=1; i< nbi-1; i++){ for (int j=1; j < nbj-1 ; j++){ if (map.carte(i,j)) total += mat.catch_obs(sp,k,i,j); } } ecritSumDym << total << '\t'; // predicted catch total=0.f; for (int i=1; i< nbi-1; i++){ for (int j=1; j < nbj-1 ; j++){ if (map.carte(i,j)) total += mat.catch_est(sp,k,i,j); } } ecritSumDym << total << '\t'; //start test // observed CPUE total=0.f; int N = 0; double cpue = 0; for (int i=1; i< nbi-1; i++){ for (int j=1; j < nbj-1 ; j++){ if (map.carte(i,j)){ double efr = mat.effort[f][i][j]; double Cobs = mat.catch_obs(sp,k,i,j); //double Cest = mat.catch_est(sp,k,i,j); if (Cobs){ total += Cobs/efr; N++; } } } } if (N>0) cpue = total/N; //cout << f << " OBSERVED: "<< N << " CPUE: " << total << " MEAN: " << total/(N+1) << " " << cpue; ecritSumDym << cpue << '\t'; //ecritSumDym << total << '\t'; // predicted CPUE total=0.f; cpue = 0; for (int i=1; i< nbi-1; i++){ for (int j=1; j < nbj-1 ; j++){ if (map.carte(i,j)){ double efr = mat.effort[f][i][j]; double Cobs = mat.catch_obs(sp,k,i,j); double Cest = mat.catch_est(sp,k,i,j); if (Cobs){ //if (efr && mat.catch_obs(sp,k,i,j)){ total += Cest/efr; } } } } if (N>0) cpue = total/N; //cout << "\t PREDICTED CPUE: " << total << " MEAN: " << total/(N+1) << " " << cpue << endl; ecritSumDym << cpue << '\t'; //ecritSumDym << total << '\t'; //end test k++; }// else { // ecritSumDym << 0 << '\t' << 0 << '\t'; //} } } } ecritSumDym << endl; ecritSumDym.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<fileSumDym<<endl; } //will be necessary in both SumQArea and SumByEEZ files dvector cell_area; dvector no_area; cell_area.allocate(map.jmin, map.jmax); no_area.allocate(map.jmin, map.jmax); cell_area.initialize(); no_area.initialize(); for (int j=map.jmin;j<=map.jmax;j++) cell_area[j] = param.cell_surface_area(j); no_area = 1.0; ////////////////////////////////////// //UPDATE SUMQAREA.TXT //opening the existing file in mode append string fileSumQA = param.strdir_output + "SumQArea.txt"; ofstream ecritSumQA; ecritSumQA.open(fileSumQA.c_str(), ios::app); if (ecritSumQA) { // writing the date ecritSumQA << yr2 << '\t' << mois2 << '\t' << day << '\t'; /* dvector cell_area;//_corr; cell_area.allocate(map.jmin, map.jmax); cell_area.initialize(); const double cell_area = 1.852*param.deltaX*1.852*param.deltaY; for (int j=map.jmin;j<=map.jmax;j++) cell_area[j] = cell_area / mat.lat_correction[j]; */ //int nbt_yr = (int) (365.25/param.deltaT); const int nbt = param.get_nbt();//(int) (nbt_yr*(param.save_last_yr - param.save_first_yr + 1.0/nbt_yr) ); //sum by region (rectangle) if (param.nb_region) { for (int sp=0; sp< nb_species;sp++) { int nb_reg = param.nb_region_sp_B[sp]; if (nb_reg>0) { DVECTOR sum_area(0, nb_reg); save.SumByArea(map, mask_catch, mat.larvae[sp], sum_area, cell_area, nb_reg, nbt); for (int z =0; z< nb_reg+1;z++) ecritSumQA << sum_area[z] <<'\t'; save.SumByArea(map, mask_catch, mat.juvenile[sp], sum_area, cell_area, nb_reg, nbt); for (int z =0; z< nb_reg+1;z++) ecritSumQA << sum_area[z] <<'\t'; save.SumByArea(map, mask_catch, mat.recruit[sp], sum_area, cell_area, nb_reg, nbt); for (int z =0; z< nb_reg+1;z++) ecritSumQA << sum_area[z] <<'\t'; save.SumByArea(map, mask_catch, mat.young[sp], sum_area, cell_area, nb_reg, nbt); for (int z =0; z< nb_reg+1;z++) ecritSumQA << sum_area[z] <<'\t'; save.SumByArea(map, mask_catch, mat.adult[sp], sum_area, cell_area, nb_reg, nbt); for (int z =0; z< nb_reg+1;z++) ecritSumQA << sum_area[z] <<'\t'; save.SumByArea(map, mask_catch, mat.total_pop[sp], sum_area, cell_area, nb_reg, nbt); for (int z =0; z< nb_reg+1;z++) ecritSumQA << sum_area[z] <<'\t'; } } } ecritSumQA<<endl; ecritSumQA.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<fileSumQA<<endl; } ////////////////////////////////////// // Update SumEEZ.txt files (Inna 06/2011) if (param.nb_EEZ!=0){ int nlon = param.nlong; int nlat = param.nlat; for (int a=0; a<param.nb_EEZ; a++){ int EEZ_ID = param.EEZ_ID[a]; string fileSumEEZ = param.strdir_output + "SumEEZ" + "_" + param.EEZ_name[a] + ".txt"; ofstream ecritSumEEZ; ecritSumEEZ.open(fileSumEEZ.c_str(), ios::app); if (ecritSumEEZ){ double sumEEZ = 0.0; ecritSumEEZ << yr2 << '\t' << mois2 << '\t' << day << '\t'; for (int sp=0; sp<nb_species;sp++){ //NOTE: cohorts larvae-recruits will be written in numbers, young-adult in tonnes sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.larvae[sp],cell_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.juvenile[sp],cell_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.recruit[sp],cell_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.young[sp],cell_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.adult[sp],cell_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.total_pop[sp],cell_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; if (nb_fishery && !param.flag_no_fishing){ int k = 0; int Nb_obs = 0; for (int f=0;f<nb_fishery; f++){ if (param.mask_fishery_sp[sp][f]){ Nb_obs = save.NobsByEEZ(map,EEZ_ID,mat.effort[f],nlon,nlat); ecritSumEEZ << Nb_obs <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.effort[f],no_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.catch_obs(sp,k),no_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.catch_est(sp,k),no_area,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.catch_obs(sp,k),mat.effort(f),nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; double mean_CPUE = 0; if (Nb_obs>0) mean_CPUE = sumEEZ/Nb_obs; sumEEZ = save.StdCPUEByEEZ(map,EEZ_ID,mat.catch_obs(sp,k),mat.effort(f),mean_CPUE,Nb_obs,nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; sumEEZ = save.SumByEEZ(map,EEZ_ID,mat.catch_est(sp,k),mat.effort(f),nlon,nlat); ecritSumEEZ << sumEEZ <<'\t'; k++; } } } } ecritSumEEZ<<endl; ecritSumEEZ.close(); } else cout<<endl<<"WARNING : Cannot write file "<<fileSumEEZ<<endl; } } //////////////////////////////////// //UPDATE MEANVAR.TXT for (int sp=0; sp<nb_species;sp++){ string fileMeanVar = param.strdir_output + param.sp_name[sp] + "_MeanVar.txt"; ofstream ecritMeanVar; ecritMeanVar.open(fileMeanVar.c_str(), ios::app); if (ecritMeanVar){ ecritMeanVar << yr2 << '\t' << mois2 << '\t' << day << '\t'; for (int sp=0; sp<nb_species;sp++){ int nb_ages = param.sp_nb_cohorts(sp); for (int a=0; a< nb_ages; a++) ecritMeanVar << mat.mean_mortality(sp,a) << '\t'; for (int a=0; a< nb_ages; a++) ecritMeanVar << mat.mean_speed(sp,a) << '\t'; for (int a=0; a< nb_ages; a++) ecritMeanVar << mat.mean_diffusion(sp,a) << '\t'; for (int a=0; a< nb_ages; a++) ecritMeanVar << mat.mean_temperature(sp,a) << '\t'; } ecritMeanVar<<endl; } else cout<<endl<<"WARNING : Cannot write file "<<fileMeanVar<<endl; } ////////////////////////////////////// //UPDATE SPATIALCORR.TXT ofstream ecritcor; if (nb_fishery>0 && !param.flag_no_fishing) { for (int sp=0;sp<nb_species;sp++) { ecritcor.open(dymFileSpCorr[sp].c_str(), ios::app); if (ecritcor) { double cor_catch =0.f; double cor_cpue =0.f; double z_catch =0.f; double z_cpue =0.f; double prob_catch= 0.f; double prob_cpue= 0.f; int nn=0; ecritcor << mois2 <<"-" << yr2 <<'\t'; int k=0; for (int f=0; f<nb_fishery; f++) if (param.mask_fishery_sp[sp][f]){ fonction.corcatch(mat.catch_est[sp][k], mat.catch_obs[sp][k], map.imin, map.imax, map.jinf, map.jsup, nn, cor_catch, z_catch, prob_catch, map.carte, 0) ; fonction.corcpue(mat.catch_est[sp][k], mat.catch_obs[sp][k], mat.effort[f], map.imin, map.imax, map.jinf, map.jsup, nn, cor_cpue, z_cpue, prob_cpue, map.carte, 0) ; ecritcor << nn << '\t'<< cor_catch << '\t' << prob_catch << '\t' << cor_cpue << '\t' << prob_cpue << '\t'; k++; } ecritcor << endl; ecritcor.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<dymFileSpCorr[sp]<<endl; } } } ////////////////////////////////////// //UPDATE SP_LF_Q_FISHERY.TXT if (!param.flag_no_fishing){ // quarterly catch in number by age(size)by species and fishery ofstream ecritQtr_N; if (sum(param.mask_fishery_sp[0])!=0) {year0_fishing = (int)(param.ndatini/10000);} int year = yr2-year0_fishing;//(int)param.save_first_yr; if ( (nb_fishery>0) && (mois2==3 || mois2==6 || mois2==9 || mois2==12)) { for (int sp=0; sp< nb_species;sp++){ const int a0 = param.sp_a0_adult[sp]; const int nb_ages = param.sp_nb_cohorts[sp]; ecritQtr_N.open(dymFileSpLF[sp].c_str(), ios::app); if (ecritQtr_N) { int k = 0; for (int f=0; f<nb_fishery; f++){ if (param.mask_fishery_sp[sp][f]){ for (int reg=0; reg< param.nb_region_sp_B[sp]; reg++){ double sumpred = 0.0; double sumobs = 0.0; for (int a=a0;a<nb_ages;a++){ sumpred += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; if (!param.nb_yr_forecast) sumobs += frq(f,reg,year,mois2/3-1,a); } if (sumpred>0){ ecritQtr_N << yr2 << '\t'<< qtr1 <<'\t'<< mois2 << '\t'<< param.list_fishery_name[f] << '\t' << reg+1 << '\t'; for (int a=a0;a<nb_ages;a++) ecritQtr_N << mat.C_N_sp_age_fishery_qtr[sp][a][reg][k] <<'\t'; ecritQtr_N << endl; } } k++; } } ecritQtr_N.close(); } else { cout<<endl<<"WARNING : Cannot write file "<<dymFileSpLF[sp]<<endl; } } } } /* // IS 20230512, suppressing the output of SP_LF_Q_SUM // This file is obsolete and to be removed. The same // information can be derived from LF_Q_fishery. // The routine is extremely slow for multiple regions // (e.g. 100% of runtime with 600 regions). ////////////////////////////////////// // Write/Rewrite the file (s) ////////////////////////////////////// //UPDATE SP_LF_Q_SUM.TXT if (!param.flag_no_fishing){ //sum of catch in number by age(size) by species, by region and fishery //sum for each of four quarter over all the series + sum of the four quarters //if ( (nb_fishery>0) && (qtr2 != qtr1) && (ntq>0) ) if ( (nb_fishery>0) && (mois2==3 || mois2==6 || mois2==9 || mois2==12)) { for (int sp=0 ; sp<nb_species ; sp++) { const int a0 = param.sp_a0_adult[sp]; const int nb_ages = param.sp_nb_cohorts[sp]; for (int a=a0 ; a<nb_ages; a++) { const int nb_region_sp_B = param.nb_region_sp_B[sp]; for (int r=0; r< nb_region_sp_B; r++) { int reg = param.area_sp_B[sp][r]-1; const int nb_fishery_by_sp = param.nb_fishery_by_sp[sp]; for (int k=0;k<nb_fishery_by_sp; k++) { // somme pour la climatologie trimestrielle par region et pecherie mat.Sum_C_N_sp_age_fishery_area[sp][a][qtr1-1][reg][k] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; // somme pour la climatologie trimestrielle par pecherie mat.Sum_C_N_sp_age_fishery_area[sp][a][qtr1-1][nb_region_sp_B][k] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; // somme pour la climatologie trimestrielle par region mat.Sum_C_N_sp_age_fishery_area[sp][a][qtr1-1][reg][nb_fishery_by_sp] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; // somme totale par pecherie et par region mat.Sum_C_N_sp_age_fishery_area[sp][a][5-1][reg][k] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; // somme totale par pecherie mat.Sum_C_N_sp_age_fishery_area[sp][a][5-1][nb_region_sp_B][k] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; // somme totale par region mat.Sum_C_N_sp_age_fishery_area[sp][a][5-1][reg][nb_fishery_by_sp] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; // somme grand total par trimestre mat.Sum_C_N_sp_age_fishery_area[sp][a][qtr1-1][nb_region_sp_B][nb_fishery_by_sp] += mat.C_N_sp_age_fishery_qtr[sp][a][reg][k]; } } } } } } ////////////////////////////////////// //WRITE HEADERS OF SP_LF_Q_SUM.TXT //ecriture des noms de variable du fichier LF_QFishery.txt //fichier Frequences de longueurs par trimestre if (!param.flag_no_fishing){ //if ( (nb_fishery>0) && (qtr2 != qtr1) && (ntq>0) ) if ( (nb_fishery>0) && (mois2==3 || mois2==6 || mois2==9 || mois2==12)) { //Generate the name of the files for (int sp=0; sp<nb_species;sp++) { dymFileSumSpLF.push_back(param.strdir_output+param.sp_name[sp]+"_LF_Q_sum.txt"); } } ofstream ecritQtr_S; //if ( (nb_fishery>0) && (qtr2 != qtr1) && (ntq>0) ){ if ( (nb_fishery>0) && (mois2==3 || mois2==6 || mois2==9 || mois2==12)) { for (int sp=0; sp<nb_species;sp++){ ecritQtr_S.open(dymFileSumSpLF[sp].c_str(), ios::out); if (ecritQtr_S){ ecritQtr_S << "length" <<'\t' ; for (int reg=0; reg< param.nb_region_sp_B[sp]; reg++){ for (int f=0; f< nb_fishery; f++){ if (param.mask_fishery_sp[sp][f]) ecritQtr_S << param.list_fishery_name[f]<<"_" << param.sp_name[sp]<<"_region_"<<param.area_sp_B[sp][reg]<<'\t'; } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |