bio_polynow.F90 128 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910
!$id: bio_polynow.F90,v 1.11 2016-05-05 11:49:15 dd Exp $
#include"cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: bio_fasham --- Fasham et al. biological model \label{sec:bio-fasham}
!
! !INTERFACE:
   module bio_polynow
!
!----DESCRIPTION:--------------------------------------------------------------
!  The model developed by Fashametal1990 
!  uses nitrogen as 'currency' according to the evidence that in
!  most cases nitrogen is the limiting macronutrient. It consists of
!  seven state variables: phytoplankton, zooplankton, bacteria,
!  particulate organic matter (detritus), dissolved organic matter
!  and the nutrients nitrate and ammonium.
!  The structure of the biogeochemical model in 14 states variables
!1 - Phytoplankton (phy) 
!2 - Zooplankton (zoo)
!3 - Bacteria (bac),
! NUTRIENTS ---
!5- Nitrate (nit)
!6- Ammonium (amm)
!7- Labile dissolved organic nitrogen (ldn)
! DETRITUS ----
!4 -Dead phytoplankton(Dph)
!8 -Dead zooplankton (Dzo)
!9 -Fecal pellets (Fp)
!10 - Marine snow (Msn)
! TRAITS of Marine Snow ---
!11 - Size of marine snow after coagulation
!12 - Size of marine snow when coagulation happens
!13 - Size of marine snow when fragmentation occurs
!14 - Final size of marine snow


! The concentrations are in mmol N\m^-3,and all fluxes are conservative.
!---------------------------------------------------------------------------------

! !USES:
!  default: all is private.
   use bio_var       ! S,T,zlev,rho
   use output
   use observations, only : aa,g2
   use turbulence,   only : eps  
   use meanflow,     only : Rho_0
 
   private
!
! !PUBLIC MEMBER FUNCTIONS:
   public init_bio_polynow, init_var_polynow, var_info_polynow, &
          light_polynow, do_bio_polynow, end_bio_polynow
   REALTYPE, public,parameter   :: pi= 3.141592654
   REALTYPE, public,parameter   :: g= 9.80665     !m/s2 
   REALTYPE                     :: pres = 10.1325 !  gauge pressure (absolute pressure - 10.1325 bar)

!-----LOCAL VARIABLES:---------- from a namelist : bio_polynow.nml----------------------

!-----These parameters need to be similar to those in gotmrun.nml (dt, depth) or those in bio.nml (split_factor)----------------------
  REALTYPE                  :: dt_bio 
  REALTYPE                  :: splitfac_bio
  REALTYPE                  :: depth_bio

!-----INITIAL and Minimum concentration for the variables 

  REALTYPE                  ::  p_init_value  = 1.0
  REALTYPE                  ::  p_initial     = 0.01
  REALTYPE                  ::  z_p_gauss_init= 2.0
  REALTYPE                  ::  sigma_p       = 2.0

  REALTYPE                  ::  zoo_init_value = 1.0
  REALTYPE                  ::  z_initial      = 0.01
  REALTYPE                  ::  z_zoo_gauss_init= 2.0
  REALTYPE                  ::  sigma_zoo      = 2.0

  REALTYPE                  ::  b_initial      = 0.001

  REALTYPE                  ::  dph_init_value = 1.0
  REALTYPE                  ::  dph_initial    = 0.01
  REALTYPE                  ::  z_dph_gauss_init= 2.0
  REALTYPE                  ::  sigma_dph      = 2.0

  REALTYPE                  ::  dzo_init_value = 1.0
  REALTYPE                  ::  dzo_initial    = 0.01
  REALTYPE                  ::  z_dzo_gauss_init= 2.0
  REALTYPE                  ::  sigma_dzo      = 2.0

  REALTYPE                  ::  fp_init_value  = 1.0
  REALTYPE                  ::  fp_initial     = 0.01
  REALTYPE                  ::  z_fp_gauss_init= 2.0
  REALTYPE                  ::  sigma_fp       = 2.0

  REALTYPE                  ::  msn_init_value = 1.0
  REALTYPE                  ::  msn_initial    = 0.01
  REALTYPE                  ::  z_msn_gauss_init= 2.0
  REALTYPE                  ::  sigma_msn      = 2.0

  REALTYPE                  ::  l_initial      = 0.14
  REALTYPE                  ::  p0             = 0.0
  REALTYPE                  ::  z0             = 0.0
  REALTYPE                  ::  b0             = 0.0
  REALTYPE                  ::  mu5            = 0.02  
!-----Phytoplankton and dead-phytoplankton
  REALTYPE                  ::  vp             = 1.5
  REALTYPE                  ::  alpha          = 0.065
  REALTYPE                  ::  inib           = 0.05
  REALTYPE, public          ::  kc             = 0.03
  REALTYPE                  ::  k1             = 0.2
  REALTYPE                  ::  k2             = 0.8
  REALTYPE                  ::  mu1            = 0.05
  REALTYPE                  ::  k5             = 0.2
  REALTYPE                  ::  gamma          = 0.05
  REALTYPE                  ::  txloss_p       = 0.7  
  REALTYPE                  ::  txloss_dph     = 0.05  
!-----Zooplankton
  REALTYPE                  ::  gmax           = 1.0
  REALTYPE                  ::  k3             = 1.0
  REALTYPE                  ::  beta           = 0.625
  REALTYPE                  ::  mu2            = 0.3
  REALTYPE                  ::  k6             = 0.2
  REALTYPE                  ::  delta          = 0.1
  REALTYPE                  ::  epsi           = 0.70
  REALTYPE                  ::  eg             = 0.05   
  REALTYPE                  ::  r1             = 0.55   ! phy
  REALTYPE                  ::  r2             = 0.4    ! zoo
  REALTYPE                  ::  r3             = 0.05   ! dph  
  REALTYPE                  ::  r4             = 0.05   ! dzo 
  REALTYPE                  ::  r5             = 0.05   ! fp   
  REALTYPE                  ::  r6             = 0.05   ! msn 
  REALTYPE                  ::  txloss_dzo     = 0.05  
  REALTYPE                  ::  txloss_fp      = 0.05 
!-----Zooplankton Vertical migration(From Ariadna Nocera)
  REALTYPE                  ::  Migra_zoo      = 1.0   
  REALTYPE                  ::  pmin           = 0.05
  REALTYPE                  ::  w_zmax         = 100.0  
  REALTYPE                  ::  bertha         = 0.05   
  REALTYPE                  ::  parcrit        = 0.02   
!-----Bacterias and LDON
  REALTYPE                  ::  vb             = 1.2
  REALTYPE                  ::  remi           = 0.1
  REALTYPE                  ::  k4             = 0.5
  REALTYPE                  ::  mu3            = 0.15
  REALTYPE                  ::  eta            = 0.0
  REALTYPE                  ::  mbac           = 0.0    
  REALTYPE                  ::  dphlossb       = 0.4
  REALTYPE                  ::  dphlossl       = 10.0  
  REALTYPE                  ::  dzolossl       = 10.0  
  REALTYPE                  ::  dzolossb       = 10.0  
  REALTYPE                  ::  fplossl        = 10.0 
  REALTYPE                  ::  fplossb        = 10.0 
  REALTYPE                  ::  leak           = 0.1
  REALTYPE                  ::  mldon          = 0.02    
  REALTYPE                  ::  lmin           = 0.02    
!----- Detritus/Settling
  REALTYPE                  ::  Phys_w         = 0.0 
  REALTYPE                  ::  w_msnow        = 0.0 
  REALTYPE                  ::  w_p            = -0.5
  REALTYPE                  ::  w_dph          = -1.0   
  REALTYPE                  ::  w_dzo          = -10.0   
  REALTYPE                  ::  w_fp           = -100.0  
  REALTYPE                  ::  w_msn          = -2.0    
  REALTYPE                  ::  rho_p          = 0.02 
  REALTYPE                  ::  rho_dph        = 0.02 
  REALTYPE                  ::  rho_dzo        = 0.02 
  REALTYPE                  ::  rho_fp         = 0.02 
  REALTYPE                  ::  rho_msn        = 0.02 
!----- Coagulation  
  REALTYPE                  ::  Coag_coef      = 0.0     
  REALTYPE                  ::  betap_p        = 0.2
  REALTYPE                  ::  betap_dph      =  1
  REALTYPE                  ::  betap_dzo      = 1
  REALTYPE                  ::  betap_fp       = 1 
  REALTYPE                  ::  betadph_dph    = 0.2
  REALTYPE                  ::  betadph_dzo    = 1
  REALTYPE                  ::  betadph_fp     = 1
  REALTYPE                  ::  betadzo_dzo    = 0.02    
  REALTYPE                  ::  betadzo_fp     = 0.02  
  REALTYPE                  ::  betafp_fp      = 0.02   
  REALTYPE                  ::  betaBr         = 1.0
  REALTYPE                  ::  betaSh         = 1.0 
  REALTYPE                  ::  betaDs         = 1.0 
  REALTYPE                  ::  eps_const      = 1.0 
  REALTYPE                  ::  eps_n          = 1.0 
  REALTYPE                  ::  cons_min       = 0.00001 
  REALTYPE                  ::  sti_cst        = 0.0
  REALTYPE                  ::  stip_p         = -0.5  
  REALTYPE                  ::  stip_dph       = -0.5  
  REALTYPE                  ::  stip_dzo       = -0.5   
  REALTYPE                  ::  stip_fp        = -0.5   
  REALTYPE                  ::  stidph_dph     = -0.5  
  REALTYPE                  ::  stidph_dzo     = -0.5  
  REALTYPE                  ::  stidph_fp      = -0.5   
  REALTYPE                  ::  stidzo_dzo     = -0.5   
  REALTYPE                  ::  stidzo_fp      = -0.5   
  REALTYPE                  ::  stifp_fp       = -0.5   
!-----  Settling
  REALTYPE                  ::   CSF           =1.0
  REALTYPE                  ::   size_rand     = 1.0
  REALTYPE                  ::   size_phy_us   = -0.5  
  REALTYPE                  ::   size_phy_up   = -0.5 
  REALTYPE                  ::   size_dph_us   = 0.00001
  REALTYPE                  ::   size_dph_up   = 0.00001
  REALTYPE                  ::   size_dzo_us   = 0.000100
  REALTYPE                  ::   size_dzo_up   = 0.000100
  REALTYPE                  ::   size_fp_us    = 0.000050
  REALTYPE                  ::   size_fp_up    = 0.000050 
  REALTYPE                  ::   dm_msn        = 0.0
  REALTYPE                  ::   coef1         = 0.0
  REALTYPE                  ::   coef2         = 0.0
  REALTYPE                  ::   diam_msn_us   = 0.01  
  REALTYPE                  ::   coef3         = -0.5  
  REALTYPE                  ::   cons_max      = -0.5  
  REALTYPE                  ::   dynvis        = -0.5  
  REALTYPE                  ::   kinvis        = -0.5  
  REALTYPE                  ::   kB            = -0.5  
!-----Fragmentation
  REALTYPE                   :: Frag_meth      = 0.0 
  REALTYPE                   :: swim_brk       = 0.8
  REALTYPE                   :: Floc_coef      = 0.1
  REALTYPE                   :: Daugther_part  = 1.0

   integer                   ::  out_unit
!Variables declarations
 integer, parameter        ::  p=1,z=2,b=3,d1=4,n=5,a=6,l=7,d2=8,d3=9,d4=10, &
                               size_intrm=11,size_coag=12,size_frag=13,size_msn=14

!EOP
!-----------------------------------------------------------------------

   contains

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the bio module
!
! !INTERFACE:
   subroutine init_bio_polynow(namlst,fname,unit)
!
! !DESCRIPTION:
!  Here, the bio namelist bio_polynow.nml is read and
!  various variables (rates and settling velocities)
!  are transformed into SI units.
!
! !USES:
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
   integer,          intent(in)   :: namlst
   character(len=*), intent(in)   :: fname
   character(len=20)              :: pfile
   integer,          intent(in)   :: unit
!
! !REVISION HISTORY:
!  Original author(s): Hans Burchard & Karsten Bolding
!
! !LOCAL VARIABLES:
   namelist /bio_polynow_nml/ numc, &
                                                        
   dt_bio,splitfac_bio,depth_bio,&
!-----INITIAL and Minimum concentration for the variables 
   p_init_value,p_initial,z_p_gauss_init,sigma_p,          &
   zoo_init_value,z_initial,z_zoo_gauss_init,sigma_zoo,    &
   b_initial,                                              &
   dph_init_value,dph_initial,z_dph_gauss_init,sigma_dph,  &
   dzo_init_value,dzo_initial,z_dzo_gauss_init,sigma_dzo,  &
   fp_init_value,fp_initial,z_fp_gauss_init,sigma_fp,      &
   msn_init_value,msn_initial,z_msn_gauss_init,sigma_msn,  & 
   l_initial,p0,z0,b0,mu5,                                 &
!-----Phytoplankton and dead-phytoplankton
   vp,alpha,inib,kc,k1,k2,mu1,k5,gamma,txloss_p,txloss_dph,& 
!-----Zooplankton
   gmax,k3,beta,mu2,k6,delta,epsi,eg,r1,r2,r3,r4,r5,r6,    & 
   txloss_dzo,txloss_fp, &
   Migra_zoo,pmin,w_zmax,bertha,parcrit,                   & 
!-----Bacterias and LDON
   vb,remi,k4,mu3,eta,mbac,dphlossb,dphlossl,dzolossl,dzolossb,fplossl,fplossb, & 
   leak,mldon,lmin,                                        & 
!----- Detritus/Settling
   Phys_w,w_msnow,w_p,w_dph,w_dzo,w_fp,w_msn,              & 
   rho_p,rho_dph,rho_dzo,rho_fp,rho_msn,                   &  
!----- Coagulation  
   Coag_coef,                                              &
   betap_p,betap_dph,betap_dzo,betap_fp,                   &
   betadph_dph,betadph_dzo,betadph_fp,                     &
   betadzo_dzo,betadzo_fp,betafp_fp,                       & 
   betaBr,betaSh,betaDs,                                   &
   eps_const,eps_n,cons_min,                               &
   sti_cst,                                                &
   stip_p,stip_dph,stip_dzo,stip_fp,stidph_dph,stidph_dzo,stidph_fp,stidzo_dzo,stidzo_fp,stifp_fp, &
!-----  Settling
   CSF,size_rand,size_phy_us,size_phy_up,size_dph_us,size_dph_up,size_dzo_us,size_dzo_up,&
   size_fp_us,size_fp_up,dm_msn,coef1,coef2,diam_msn_us,   &
   coef3,cons_max,                                         &
   dynvis,kinvis,kB,                                       &
!-----Fragmentation
   Frag_meth,swim_brk,Floc_coef, Daugther_part                
             
!EOP
!-----------------------------------------------------------------------
!BOC
   LEVEL2 'init_bio_polynow'

   open(namlst,file=fname,action='read',status='old',err=98)
   read(namlst,nml=bio_polynow_nml,err=99)
   close(namlst)

   numcc=numc
!----Print some parameter values in standard output and save them in a separate file [out_fn]_polynow.par
   pfile = trim(out_fn) // '_polynow.par'
   open(10,status='unknown',action='write',file=pfile)
   LEVEL3 'Biogeochemical parameters saved in ', pfile
  
   write(*,900) '                dt_bio     = ',dt_bio
   write(10,901) dt_bio
   write(*,900) '                splitfac_bio  = ',splitfac_bio
   write(10,901) splitfac_bio
   write(*,900) '                depth_bio     = ',depth_bio
   write(10,901) depth_bio
!-----INITIAL and Minimum concentration for the variables 
   write(*,900) '                p_init_value      = ',p_init_value 
   write(10,901) p_init_value 
   write(*,900) '                p_initial     = ',p_initial
   write(10,901) p_initial
   write(*,900) '                z_p_gauss_init     = ',z_p_gauss_init
   write(10,901) z_p_gauss_init
   write(*,900) '                sigma_p     = ',sigma_p
   write(10,901) sigma_p
   write(*,900) '                zoo_init_value      = ',zoo_init_value 
   write(10,901) zoo_init_value 
   write(*,900) '                z_initial     = ',z_initial
   write(10,901) z_initial
   write(*,900) '                z_zoo_gauss_init     = ',z_zoo_gauss_init
   write(10,901) z_zoo_gauss_init
   write(*,900) '                sigma_zoo     = ',sigma_zoo
   write(10,901) sigma_zoo
   write(*,900) '                b_initial     = ',b_initial
   write(10,901) b_initial
   write(*,900) '                dph_init_value      = ',dph_init_value 
   write(10,901) dph_init_value 
   write(*,900) '                dph_initial     = ',dph_initial
   write(10,901) dph_initial
   write(*,900) '                z_dph_gauss_init     = ',z_dph_gauss_init
   write(10,901) z_dph_gauss_init
   write(*,900) '                sigma_dph     = ',sigma_dph
   write(10,901) sigma_dph
   write(*,900) '                dzo_init_value      = ',dzo_init_value 
   write(10,901) dzo_init_value 
   write(*,900) '                dzo_initial     = ',dzo_initial
   write(10,901) dzo_initial
   write(*,900) '                z_dzo_gauss_init     = ',z_dzo_gauss_init
   write(10,901) z_dzo_gauss_init
   write(*,900) '                sigma_dzo     = ',sigma_dzo
   write(10,901) sigma_dzo
   write(*,900) '                fp_init_value      = ',fp_init_value 
   write(10,901) fp_init_value 
   write(*,900) '                fp_initial     = ',fp_initial
   write(10,901) fp_initial
   write(*,900) '                z_fp_gauss_init     = ',z_fp_gauss_init
   write(10,901) z_fp_gauss_init
   write(*,900) '                sigma_fp     = ',sigma_fp
   write(10,901) sigma_fp
   write(*,900) '                msn_init_value      = ',msn_init_value 
   write(10,901) msn_init_value 
   write(*,900) '                msn_initial     = ',msn_initial
   write(10,901) msn_initial
   write(*,900) '                z_msn_gauss_init     = ',z_msn_gauss_init
   write(10,901) z_msn_gauss_init
   write(*,900) '                sigma_msn     = ',sigma_msn
   write(10,901) sigma_msn
   write(*,900) '                l_initial     = ',l_initial
   write(10,901) l_initial
   write(*,900) '                p0     = ',p0
   write(10,901) p0
   write(*,900) '                z0     = ',z0
   write(10,901) z0
   write(*,900) '                b0     = ',b0
   write(10,901) b0
   write(*,900) '                mu5     = ',mu5
   write(10,901) mu5
!-----Phytoplankton and dead-phytoplankton 
   write(*,900) '                vp     = ',vp
   write(10,901) vp
   write(*,900) '                alpha  = ',alpha
   write(10,901) alpha
   write(*,900) '                inib   = ',inib
   write(10,901) inib
   write(*,900) '                kc     = ',kc
   write(10,901) kc
   write(*,900) '                k1     = ',k1
   write(10,901) k1
   write(*,900) '                k2     = ',k2
   write(10,901) k2
   write(*,900) '                mu1     = ',mu1
   write(10,901) mu1
   write(*,900) '                k5     = ',k5
   write(10,901) k5
   write(*,900) '               gamma     = ',gamma
   write(10,901) gamma
   write(*,900) '               txloss_p = ',txloss_p
   write(10,901) txloss_p
   write(*,900) '               txloss_dph = ',txloss_dph
   write(10,901) txloss_dph
!-----Zooplankton
   write(*,900) '                gmax  = ',gmax
   write(10,901) gmax
   write(*,900) '                k3     = ',k3
   write(10,901) k3
   write(*,900) '                beta     = ',beta
   write(10,901) beta
   write(*,900) '                mu2      = ',mu2
   write(10,901) mu2
   write(*,900) '                k6     = ',k6
   write(10,901) k6
   write(*,900) '                delta    = ',delta
   write(10,901) delta
   write(*,900) '                epsi    = ',epsi
   write(10,901) epsi
   write(*,900) '                eg     = ',eg
   write(10,901) eg
   write(*,900) '                r1     = ',r1
   write(10,901) r1
   write(*,900) '                r2   = ',r2
   write(10,901) r2
   write(*,900) '                r3    = ',r3
   write(10,901) r3
   write(*,900) '                r4    = ',r4
   write(10,901) r4
   write(*,900) '                r5     = ',r5
   write(10,901) r5
   write(*,900) '                r6     = ',r6
   write(10,901) r6
   write(*,900) '               txloss_dzo = ',txloss_dzo
   write(10,901) txloss_dzo
   write(*,900) '               txloss_fp = ',txloss_fp
   write(10,901) txloss_fp
   write(*,900) '               Migra_zoo = ',Migra_zoo
   write(10,901) Migra_zoo
   write(*,900) '                pmin     = ',pmin
   write(10,901) pmin
   write(*,900) '                w_zmax    = ',w_zmax
   write(10,901) w_zmax
   write(*,900) '                bertha    = ',bertha
   write(10,901) bertha
   write(*,900) '                parcrit     = ',parcrit
   write(10,901) parcrit
!-----Bacterias and LDON
   write(*,900) '                vb    = ',vb
   write(10,901) vb
   write(*,900) '                remi    = ',remi
   write(10,901) remi
   write(*,900) '                k4    = ',k4
   write(10,901) k4
   write(*,900) '                mu3    = ',mu3
   write(10,901) mu3
   write(*,900) '                eta    = ',eta
   write(10,901) eta
   write(*,900) '                mbac    = ',mbac
   write(10,901) mbac
   write(*,900) '                dphlossb    = ',dphlossb
   write(10,901) dphlossb
   write(*,900) '               dphlossl    = ',dphlossl
   write(10,901) dphlossl
   write(*,900) '               dzolossl    = ',dzolossl
   write(10,901) dzolossl
   write(*,900) '               dzolossb   = ',dzolossb
   write(10,901) dzolossb
   write(*,900) '               fplossl    = ',fplossl
   write(10,901) fplossl
   write(*,900) '               fplossb   = ',fplossb
   write(10,901) fplossb
   write(*,900) '                leak    = ',leak
   write(10,901) leak
   write(*,900) '               mldon   = ',mldon
   write(10,901) mldon
   write(*,900) '               lmin   = ',lmin
   write(10,901) lmin
!----- Detritus/Settling
   write(*,900) '               Phys_w   = ',Phys_w
   write(10,901) Phys_w
   write(*,900) '               w_msnow   = ',w_msnow
   write(10,901) w_msnow
   write(*,900) '               w_p   = ',w_p
   write(10,901) w_p
   write(*,900) '               w_dph    = ',w_dph
   write(10,901) w_dph
   write(*,900) '               w_dzo    = ',w_dzo
   write(10,901) w_dzo
   write(*,900) '               w_fp  = ',w_fp
   write(10,901) w_fp
   write(*,900) '               w_msn    = ',w_msn
   write(10,901) w_msn
   write(*,900) '               rho_p    = ',rho_p
   write(10,901) rho_p
   write(*,900) '               rho_dph    = ',rho_dph
   write(10,901) rho_dph
   write(*,900) '               rho_dzo    = ',rho_dzo
   write(10,901) rho_dzo
   write(*,900) '               rho_fp    = ',rho_fp
   write(10,901) rho_fp
   write(*,900) '               rho_msn    = ',rho_msn
   write(10,901) rho_msn
!----- Coagulation 
   write(*,900) '               coag_coef    = ',Coag_coef
   write(10,901) Coag_coef
   write(*,900) '               betap_p   = ',betap_p
   write(10,901) betap_p
   write(*,900) '               betap_dph   = ',betap_dph
   write(10,901) betap_dph
   write(*,900) '               betap_dzo   = ',betap_dzo
   write(10,901) betap_dzo
   write(*,900) '               betap_fp   = ',betap_fp
   write(10,901) betap_fp
   write(*,900) '               betadph_dph   = ',betadph_dph
   write(10,901) betadph_dph
   write(*,900) '               betadph_dzo   = ',betadph_dzo
   write(10,901) betadph_dzo
   write(*,900) '               betadph_fp   = ',betadph_fp
   write(10,901) betadph_fp
   write(*,900) '               betadzo_dzo   = ',betadzo_dzo
   write(10,901) betadzo_dzo
   write(*,900) '               betadzo_fp   = ',betadzo_fp
   write(10,901) betadzo_fp
   write(*,900) '               betafp_fp   = ',betafp_fp
   write(10,901) betafp_fp
   write(*,900) '               betaBr   = ',betaBr
   write(10,901) betaBr
   write(*,900) '               betaSh   = ',betaSh
   write(10,901) betaSh
   write(*,900) '               betaDs   = ',betaDs
   write(10,901) betaDs
   write(*,900) '               eps_const   = ',eps_const
   write(10,901)eps_const
   write(*,900) '               eps_n   = ',eps_n
   write(10,901)eps_n
   write(*,900) '               cons_min   = ',cons_min
   write(10,901)cons_min
   write(*,900) '              sti_cst   = ',sti_cst
   write(10,901)sti_cst
   write(*,900) '               stip_p   = ',stip_p
   write(10,901) stip_p
   write(*,900) '               stip_dph   = ',stip_dph
   write(10,901) stip_dph
   write(*,900) '               stip_dzo   = ',stip_dzo
   write(10,901) stip_dzo
   write(*,900) '               stip_fp   = ',stip_fp
   write(10,901) stip_fp
   write(*,900) '               stidph_dph   = ',stidph_dph
   write(10,901) stidph_dph
   write(*,900) '               stidph_dzo   = ',stidph_dzo
   write(10,901) stidph_dzo
   write(*,900) '               stidph_fp   = ',stidph_fp
   write(10,901) stidph_fp
   write(*,900) '               stidzo_dzo   = ',stidzo_dzo
   write(10,901) stidzo_dzo
   write(*,900) '               stidzo_fp   = ',stidzo_fp
   write(10,901) stidzo_fp
   write(*,900) '               stifp_fp   = ',stifp_fp
   write(10,901) stifp_fp
!-----  Settling
   write(*,900) '               CSF   = ',CSF
   write(10,901) CSF
   write(*,900) '               size_rand   = ',size_rand
   write(10,901) size_rand
   write(*,900) '               size_phy_us   = ',size_phy_us
   write(10,901) size_phy_us
   write(*,900) '               size_phy_up   = ',size_phy_up
   write(10,901) size_phy_up
   write(*,900) '               size_dph_us   = ',size_dph_us
   write(10,901) size_dph_us
   write(*,900) '               size_dph_up   = ',size_dph_up
   write(10,901) size_dph_up
   write(*,900) '               size_dzo_us   = ',size_dzo_us
   write(10,901) size_dzo_us
   write(*,900) '               size_dzo_up   = ',size_dzo_up
   write(10,901) size_dzo_up
   write(*,900) '               size_fp_us  = ',size_fp_us
   write(10,901) size_fp_us
   write(*,900) '               size_fp_up  = ',size_fp_up
   write(10,901) size_fp_up
   write(*,900) '               dm_msn  = ',dm_msn
   write(10,901) dm_msn
   write(*,900) '               coef1  = ',coef1 
   write(10,901) coef1 
   write(*,900) '               coef2  = ',coef2
   write(10,901) coef2
   write(*,900) '               diam_msn_us  = ',diam_msn_us
   write(10,901) diam_msn_us
   write(*,900) '               coef3  = ',coef3
   write(10,901) coef3
   write(*,900) '               cons_max  = ',cons_max
   write(10,901) cons_max
   write(*,900) '               dynvis   = ',dynvis
   write(10,901) dynvis
   write(*,900) '               kinvis   = ',kinvis
   write(10,901) kinvis
   write(*,900) '               kB   = ',kB
   write(10,901) kB
!-----Fragmentation
   write(*,900) '               Frag_meth   = ',Frag_meth
   write(10,901) Frag_meth
   write(*,900) '                swim_brk   = ', swim_brk
   write(10,901)  swim_brk
   write(*,900) '               Floc_coef   = ', Floc_coef
   write(10,901)  Floc_coef
   write(*,900) '                Daugther_part     = ', Daugther_part  
   write(10,901)  Daugther_part  

900 format (a,f8.5)
901 format (f8.5)

!  Conversion from day to second (Days in the nml but the model go in seconds !)
 
!-----INITIAL and Minimum concentration for the variables
   mu5      = mu5 /secs_pr_day  
!-----Phytoplankton and dead-phytoplankton    
   vp       = vp /secs_pr_day
   alpha    = alpha /secs_pr_day                
   inib     = inib /secs_pr_day         
   mu1      = mu1 /secs_pr_day
   txloss_p = txloss_p /secs_pr_day 
  txloss_dph= txloss_dph /secs_pr_day 
!-----Zooplankton
   gmax     = gmax /secs_pr_day
   mu2      = mu2 /secs_pr_day
txloss_dzo  = txloss_dph /secs_pr_day  
txloss_fp   = txloss_fp /secs_pr_day 
  w_zmax    = w_zmax /secs_pr_day      
!-----Bacterias and LDON
   vb       = vb /secs_pr_day
  remi      = remi/secs_pr_day
   mu3      = mu3 /secs_pr_day
   mbac     = mbac /secs_pr_day       
  dphlossb  = dphlossb/secs_pr_day 
  dphlossl  = dphlossl/secs_pr_day 
  dzolossl  = dzolossl/secs_pr_day 
  dzolossb  = dzolossb/secs_pr_day 
  fplossl   = fplossl/secs_pr_day
  fplossb   = fplossb/secs_pr_day
  leak      = leak/secs_pr_day 
  mldon     = mldon /secs_pr_day       
!----- Detritus/Settling
   w_p      = w_p /secs_pr_day
   w_dph    = w_dph /secs_pr_day    
   w_dzo    = w_dzo /secs_pr_day    
   w_fp     = w_fp /secs_pr_day    
   w_msn    = w_msn /secs_pr_day    
!----- Coagulation  
betap_p     = betap_p /secs_pr_day    
betap_dph   = betap_dph /secs_pr_day   
betap_dzo   = betap_dzo /secs_pr_day   
betap_fp    = betap_fp /secs_pr_day    
betadph_dph = betadph_dph/secs_pr_day 
betadph_dzo = betadph_dzo/secs_pr_day 
betadph_fp  = betadph_fp/secs_pr_day 
betadzo_dzo = betadzo_dzo /secs_pr_day    
betadzo_fp  = betadzo_fp /secs_pr_day    
betafp_fp   = betafp_fp /secs_pr_day 
!-----Fragmentation
swim_brk   =  swim_brk /secs_pr_day


   out_unit=unit

   LEVEL3 'polynow bio module initialised ...'

   return

98 LEVEL2 'I could not open bio_polynow.nml'
   LEVEL2 'If thats not what you want you have to supply bio_polynow.nml'
   LEVEL2 'See the bio example on www.gotm.net for a working bio_polynow.nml'
   return
99 FATAL 'I could not read bio_polynow.nml'
   stop 'init_bio_polynow'
   end subroutine init_bio_polynow
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialise the concentration variables
!
! !INTERFACE:
   subroutine init_var_polynow(nlev)
!
! !DESCRIPTION:
!  Here, the the initial conditions are set and the settling velocities are
!  transferred to all vertical levels. All concentrations are declared
!  as non-negative variables, and it is defined which variables would be
!  taken up by benthic filter feeders.
!
! !USES:
   use observations,    only: nprof,aprof              
   use meanflow,        only: nit,amm,T,S               
 
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
   integer, intent(in)                 :: nlev
!
! !REVISION HISTORY:
!  Original author(s): Hans Burchard & Karsten Bolding

! !LOCAL VARIABLES:
  integer                    :: i,j
  REALTYPE                   :: gauss_p,gauss_dph,gauss_dzo,gauss_fp,gauss_msn,gauss_zoo              

!EOP
!-----------------------------------------------------------------------
!BOC

!-----------------------------------------------------------------------------------
!-----------------------------------------------------------------------------------
!   Variable INITIAL PROFILES
!-----------------------------------------------------------------------------------
!-----------------------------------------------------------------------------------

   do i=1,nlev

!-----------------------------------------------------------------------------------
!   Phytoplankton initial profile
!-----------------------------------------------------------------------------------

!!       ---If p_init_value .eq.1 --» Cst initial value for all the depth as mentionned in the nml.
if (p_init_value .eq. 1.0) then
      cc(p,i)=p_initial
!!       ---If p_init_value .eq.0 --» Initial profile describe according to gaussian curve (Mean + standard error)
else
  gauss_p=p_initial*exp(-((i-z_p_gauss_init)**2/(2*(sigma_p**2))))
     cc(p,i)= gauss_p
endif

!-----------------------------------------------------------------------------------
!   Zooplankton initial profiles
!-----------------------------------------------------------------------------------

!       ---If zoo_init_value .eq.1 --» Cst initial value for all the depth as mentionned in the nml.
if (zoo_init_value .eq. 1.0) then
      cc(z,i)=z_initial
!       ---If zoo_init_value.eq.0 --» Initial profile describe according to gaussian curve (Mean + standard error)
else
  gauss_zoo=z_initial*exp(-((i-z_zoo_gauss_init)**2/(2*(sigma_zoo**2))))
     cc(z,i)= gauss_zoo
endif
!-----------------------------------------------------------------------------------
!   Dead- Phytoplankton initial profile
!-----------------------------------------------------------------------------------

!!       ---If dph_init_value .eq.1 --» Cst initial value for all the depth as mentionned in the nml.
if (dph_init_value .eq. 1.0) then
      cc(d1,i)=dph_initial
!!       ---If dph_init_value .eq.0 --» Initial profile describe according to gaussian curve (Mean + standard error)
else
  gauss_dph=dph_initial*exp(-((i-z_dph_gauss_init)**2/(2*(sigma_dph**2))))
   cc(d1,i)= gauss_dph
endif

!-----------------------------------------------------------------------------------
!   Dead- Zooplankton initial profile
!-----------------------------------------------------------------------------------

!!       ---If dzo_init_value .eq.1 --» Cst initial value for all the depth as mentionned in the nml.
if (dzo_init_value .eq. 1.0) then
      cc(d2,i)=dzo_initial
!!       ---If dzo_init_value .eq.0 --» Initial profile describe according to gaussian curve (Mean + standard error)
else
  gauss_dzo=dzo_initial*exp(-((i-z_dzo_gauss_init)**2/(2*(sigma_dzo**2))))
     cc(d2,i)= gauss_dzo
endif

!-----------------------------------------------------------------------------------
!   Fecal pellets initial profile
!-----------------------------------------------------------------------------------

!!       ---If fp_init_value .eq.1 --» Cst initial value for all the depth as mentionned in the nml.
if (fp_init_value .eq. 1.0) then
      cc(d3,i)=fp_initial
!!       ---If fp_init_value .eq.0 --» Initial profile describe according to gaussian curve (Mean + standard error)
else
  gauss_fp=fp_initial*exp(-((i-z_fp_gauss_init)**2/(2*(sigma_fp**2))))
     cc(d3,i)= gauss_fp
endif

!-----------------------------------------------------------------------------------
!   Marine snow initial profile
!-----------------------------------------------------------------------------------

!!       ---If msn_init_value .eq.1 --» Cst initial value for all the depth as mentionned in the nml.
if (msn_init_value .eq. 1.0) then
      cc(d4,i)=msn_initial
!!       ---If msn_init_value.eq.0 --» Initial profile describe according to gaussian curve (Mean + standard error)
else
  gauss_msn=msn_initial*exp(-((i-z_msn_gauss_init)**2/(2*(sigma_msn**2))))
     cc(d4,i)= gauss_msn
endif


!-----------------------------------------------------------------------------------
!  Bacteria- Nitrate/ammonium / LDON initial profiles
!-----------------------------------------------------------------------------------
      cc(b,i)=b_initial
      cc(n,i)=nprof(i)       
      cc(a,i)=aprof(i)       
      cc(l,i)=l_initial

   end do

!-----------------------------------------------------------------------------------
!   Settling/swimming velocity
!-----------------------------------------------------------------------------------

   do i=0,nlev
      ws(z,i) = _ZERO_
      ws(b,i) = _ZERO_
      ws(n,i) = _ZERO_
      ws(a,i) = _ZERO_
      ws(l,i) = _ZERO_

if(Phys_w .eq. 0.0) then    
      ws(p,i) = w_p
      ws(d1,i)= w_dph   
      ws(d2,i)= w_dzo   
      ws(d3,i)= w_fp    
      ws(d4,i)= w_msn 
else
     ws(p,i) =_ZERO_           
     ws(d1,i)=_ZERO_
     ws(d2,i)=_ZERO_ 
     ws(d3,i)=_ZERO_ 
     ws(d4,i)=_ZERO_ 

end if

!-----------------------------------------------------------------------------------
!   Marine Snow Size and settling velocity
!-----------------------------------------------------------------------------------
  cc(size_intrm,i) =_ZERO_
  cc(size_coag,i)  =_ZERO_
  cc(size_frag,i)  =_ZERO_

  cc(size_msn,i)=_ZERO_
  ws(size_msn,i)=_ZERO_


   end do

   posconc(p) = 1
   posconc(z) = 1
   posconc(b) = 1
   posconc(n) = 1
   posconc(a) = 1
   posconc(l) = 1
  
  posconc(d1) = 1 
  posconc(d2) = 1 
  posconc(d3) = 1 
  posconc(d4) = 1 

#if 0
   mussels_inhale(p) = .true.
   mussels_inhale(z) = .true.
   mussels_inhale(b) = .false.
   mussels_inhale(n) = .false.
   mussels_inhale(a) = .false.
   mussels_inhale(l) = .true.
 
   mussels_inhale(d1) = .true.  
   mussels_inhale(d2) = .true.  
   mussels_inhale(d3) = .true.  
   mussels_inhale(d4) = .true.  

#endif

   LEVEL3 'polynow variables initialised ...'

   return

   end subroutine init_var_polynow
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Providing info on variables
!
! !INTERFACE:
   subroutine var_info_polynow()
!
! !DESCRIPTION:
!  This subroutine provides information about the variable names as they
!  will be used when storing data in NetCDF files.
!
! !USES:
   IMPLICIT NONE
!
! !REVISION HISTORY:
!  Original author(s): Hans Burchard & Karsten Bolding
!
! !LOCAL VARIABLES:
!EOP
!-----------------------------------------------------------------------
!BOC
   var_names(1) = 'phy'
   var_units(1) = 'mmol/m**3'
   var_long(1)  = 'phytoplankton'

   var_names(2) = 'zoo'
   var_units(2) = 'mmol/m**3'
   var_long(2)  = 'zooplankton'

   var_names(3) = 'bac'
   var_units(3) = 'mmol/m**3'
   var_long(3)  = 'bacteria'

   var_names(4) = 'dph'                
   var_units(4) = 'mmol/m**3'
   var_long(4)  = 'dead phytoplankton'

   var_names(5) = 'nit'
   var_units(5) = 'mmol/m**3'
   var_long(5)  = 'nitrate'

   var_names(6) = 'amm'
   var_units(6) = 'mmol/m**3'
   var_long(6)  = 'ammonium'

   var_names(7) = 'ldn'
   var_units(7) = 'mmol/m**3'
   var_long(7)  = 'labile_dissolved_organic_nitrogen'

   var_names(8) = 'dzo'                            
   var_units(8) = 'mmol/m**3'                      
   var_long(8)  = 'dead zooplankton'           

   var_names(9) = 'fp'                              
   var_units(9) = 'mmol/m**3'
   var_long(9)  = 'fecal pellets'

   var_names(10) = 'msn'                          
   var_units(10) = 'mmol/m**3'
   var_long(10)  = 'marine snow'

!--------------------------------------------------

   var_names(11) = 'Size_intrm'                          
   var_units(11) = 'm'
   var_long(11)  = 'Intermediate size of marine snow'


   var_names(12) = 'size_coag'                          
   var_units(12) = 'm'
   var_long(12)  = 'Size augmentation of msn due to Coag.'


   var_names(13) = 'size_frag'                          
   var_units(13) = 'm'
   var_long(13)  = 'Size of msn due to Frag.'


   var_names(14) = 'size_msn'                          
   var_units(14) = 'm'
   var_long(14)  = 'Final size of marine snow'


   return
   end subroutine var_info_polynow
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Light properties for the Fasham model
!
! !INTERFACE:
   subroutine light_polynow(nlev,bioshade_feedback)
!
! !DESCRIPTION:
! Here, the photosynthetically available radiation is calculated
! by simply assuming that the short wave part of the total
! radiation is available for photosynthesis. 
! The photosynthetically
! available radiation, $I_{PAR}$, follows from (\ref{light}).
! The user should make
! sure that this is consistent with the light class given in the
! {\tt extinct} namelist of the {\tt obs.nml} file.
! The self-shading effect is also calculated in this subroutine,
! which may be used to consider the effect of bio-turbidity also
! in the temperature equation (if {\tt bioshade\_feedback} is set
! to true in {\tt bio.nml}).
! For details, see section \ref{sec:do-bio}.
!
! !USES:
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
  integer, intent(in)                  :: nlev
  logical, intent(in)                  :: bioshade_feedback
!
! !REVISION HISTORY:
!  Original author(s): Hans Burchard, Karsten Bolding
!
! !LOCAL VARIABLES:
   integer                   :: i
   REALTYPE                  :: zz,add
!EOP
!-----------------------------------------------------------------------
!BOC
   zz = _ZERO_
   add = _ZERO_
   do i=nlev,1,-1
      add=add+0.5*h(i)*(cc(p,i)+p0)
      zz=zz+0.5*h(i)
      par(i)=rad(nlev)*(1.-aa)*exp(-zz/g2)*exp(-kc*add)
      add=add+0.5*h(i)*(cc(p,i)+p0)
      zz=zz+0.5*h(i)
      if (bioshade_feedback) bioshade_(i)=exp(-kc*add)
   end do


   return
   end subroutine light_polynow
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Right hand sides of geobiochemical model \label{sec:bio-fasham-rhs}
!
! !INTERFACE:
   subroutine do_bio_polynow(first,numc,nlev,cc,pp,dd)
!
! !DESCRIPTION:
! The model consisting of the following state variable:
! phytoplankton, bacteria, detritus (4 types), zooplankton, 
! nitrate, ammonium and dissolved organic nitrogen as well as traits link to the size evolution of marine snow (4)
!
!-----BIBLIOGRAPHY:
! Platt et al., 1980
! Moore et al., 2002
! Alldredge and Gotschalk 1988
! Kajihara 1971
! Komar 1981 & 1978 
! Ghosh 2013 
! Mc Donnell 2010 
! Alldredge 1990
! Biddanda 1998
! Ploug and Grossart 2000
! Jokulsdottir 2011
! Jackson 1990
! Bagheri 2015
! VanRijn 1993
! Spicer et al 1996
! Dilling 2000
!
! !USES: Force the user to declare all the variables 
!The variables who do not have declaration will follow the rules : If the variables start with a letters from I to N will be integer, otherwise they will be reals. 
  IMPLICIT NONE

! !INPUT PARAMETERS:
   logical, intent(in)        :: first
   integer, intent(in)        :: numc,nlev

! -- Concentrations
   REALTYPE, intent(out)      :: cc(1:numc,0:nlev)
!With INTENT(IN), you are promising to the compiler that argument cc is not modified nor its definition status changed. 

! !OUTPUT PARAMETERS:
   REALTYPE, intent(out)      :: pp(1:numc,1:numc,0:nlev)
! -- Fluxes
   REALTYPE, intent(out)      :: dd(1:numc,1:numc,0:nlev)
!Similarly, INTENT(OUT) says that variables pp and dd are always assigned a value in the routine.

! !LOCAL VARIABLES:
   integer                    :: i,j,ci
!   Light and nutrient limitation factors & Zooplankton and bacterias needed factors
   REALTYPE                   :: Ps,ff
   REALTYPE                   :: q1,q2
   REALTYPE                   :: fac,min67
!!   Size variation for each particle type
   REALTYPE                   ::size_phy,size_dph,size_dzo,size_fp
   REALTYPE                   ::size_phy_max,size_dph_max,size_dzo_max,size_fp_max
   REALTYPE                   ::diam_phy,diam_dph,diam_dzo,diam_fp,diam_msn 
!Collision & Aggregation
!!   Sedimentation rate for each particle type
     REALTYPE                    ::w_p_m,w_dph_m,w_dzo_m,w_fp_m
     REALTYPE                    ::densFlu
     REALTYPE                    ::Rp,Rdph,Rdzo,Rfp
      REALTYPE                   ::Re_phy,Re_dph,Re_dzo,Re_fp
     REALTYPE                    ::CSF_phy,CSF_dph,CSF_dzo,CSF_fp,CSF_msn
   REALTYPE                    ::CSF_phy_calc,CSF_dph_calc,CSF_dzo_calc,CSF_fp_calc,CSF_msn_calc
!!   Maximum loss for aggregation for each particle type
      REALTYPE                    ::pprime   
      REALTYPE                    ::d1rime  
      REALTYPE                    ::d2rime
      REALTYPE                    ::d3rime
!!   Stickiness for each particle type interaction
      REAL                        :: r_phy, r_dph, r_dzo, r_fp
      REALTYPE                    :: stip ,stidph,stidzo,stifp
!'No physical coagulation happens here [Constant Beta are set]'
! Phytoplankton loss by aggregation
      REALTYPE                    ::coli_pp_NoPhys,agg_pp
      REALTYPE                    ::coli_pdph_NoPhys,agg_pdph
      REALTYPE                    ::coli_pdzo_NoPhys,agg_pdzo
      REALTYPE                    ::coli_pfp_NoPhys,agg_pfp
! Dead Phytoplankton loss by aggregation
      REALTYPE                    ::coli_dphdph_NoPhys,agg_dphdph
      REALTYPE                    ::coli_dphdzo_NoPhys,agg_dphdzo
      REALTYPE                    :: coli_dphfp_NoPhys,agg_dphfp
! Dead Zooplankton loss by aggregation
      REALTYPE                    ::coli_dzodzo_NoPhys,agg_dzodzo
      REALTYPE                    ::coli_dzofp_NoPhys,agg_dzofp
! Fecal pellets loss by aggregation
      REALTYPE                    ::coli_fpfp_NoPhys,agg_fpfp
!Coagulate only with : BetaBR'
      REALTYPE                    ::T_degK
      REALTYPE                    ::physic_Br
  !Phytoplankton
      REALTYPE                    :: betaBr_pp,coli_pp
      REALTYPE                    :: betaBr_pdph,coli_pdph
      REALTYPE                    :: betaBr_pdzo,coli_pdzo
      REALTYPE                    :: betaBr_pfp,coli_pfp
  !Dead Phytoplankton
      REALTYPE                    :: betaBr_dphdph,coli_dphdph
      REALTYPE                    :: betaBr_dphdzo,coli_dphdzo
      REALTYPE                    :: betaBr_dphfp,coli_dphfp
  !Dead Zooplankton
      REALTYPE                    :: betaBr_dzodzo,coli_dzodzo
      REALTYPE                    :: betaBr_dzofp,coli_dzofp
  !Fecal pellets
      REALTYPE                    :: betaBr_fpfp,coli_fpfp
!Coagulate only with : BetaSh'
      REALTYPE                    ::bio_eps
  !Phytoplankton
      REALTYPE                    ::q_pp,betaSh_pp
      REALTYPE                    ::q_pdph,betaSh_pdph
      REALTYPE                    ::q_pdzo,betaSh_pdzo
      REALTYPE                    ::q_pfp,betaSh_pfp
  !Dead Phytoplankton
      REALTYPE                    ::q_dphdph,betaSh_dphdph
      REALTYPE                    ::q_dphdzo,betaSh_dphdzo
      REALTYPE                    ::q_dphfp,betaSh_dphfp
  !Dead Zooplankton
      REALTYPE                    ::q_dzodzo,betaSh_dzodzo
      REALTYPE                    ::q_dzofp,betaSh_dzofp
  !Fecal pellets
      REALTYPE                    ::q_fpfp,betaSh_fpfp
!Coagulate only with : BetaDs'
  !Phytoplankton
      REALTYPE                    ::abs_pp, betaDs_pp
      REALTYPE                    ::abs_pdph,betaDs_pdph
      REALTYPE                    ::abs_pdzo,betaDs_pdzo
      REALTYPE                    ::abs_pfp,betaDs_pfp
  !Dead Phytoplankton
      REALTYPE                    :: abs_dphdph,betaDs_dphdph
      REALTYPE                    :: abs_dphdzo,betaDs_dphdzo
      REALTYPE                    :: abs_dphfp,betaDs_dphfp
  !Dead Zooplankton
      REALTYPE                    :: abs_dzodzo,betaDs_dzodzo
      REALTYPE                    :: abs_dzofp,betaDs_dzofp
  !Fecal pellets
      REALTYPE                    :: abs_fpfp,betaDs_fpfp
!'Physical Coagulation happens here ![Beta are calculated via physic]'
  !Phytoplankton
      REALTYPE                    ::kernel_coef_pp
      REALTYPE                    ::kernel_coef_pdph
      REALTYPE                    ::kernel_coef_pdzo
      REALTYPE                    ::kernel_coef_pfp
  !Dead Phytoplankton
      REALTYPE                    :: kernel_coef_dphdph
      REALTYPE                    :: kernel_coef_dphdzo
      REALTYPE                    :: kernel_coef_dphfp
  !Dead Zooplankton
      REALTYPE                    :: kernel_coef_dzodzo
      REALTYPE                    :: kernel_coef_dzofp
  !Fecal pellets
      REALTYPE                    :: kernel_coef_fpfp
!SIZE Marine Snow with aggregation
      REALTYPE                    :: Ratio_P,Ratio_D1,Ratio_D2,Ratio_D3
      REALTYPE                    :: size_msn_m
      REALTYPE                    :: max_flux
!FRAGMENTATION
      REALTYPE                    :: Frag_bio,Frag_phys,leackage,remineralization
      REALTYPE                    :: kolmog,stable_size
      REALTYPE                    :: prob_break_msn,r_msn
      REALTYPE                    :: diam_msn_max,min_size_msn
!   Sedimentation rate msn
      REALTYPE                    :: w_msn_m,Re_msn,Rmsn,CFL

REALTYPE :: ceci

!EOP
!-----------------------------------------------------------------------
!BOC
!KBK - is it necessary to initialise every time - expensive in a 3D model
   pp = _ZERO_
   dd = _ZERO_

   do ci=1,nlev   !#A 

!-----------------------------------------------------------------------------------
!   Light and nutrient limitation factors & Zooplankton and bacterias needed factors
!-----------------------------------------------------------------------------------

!!       ---Light : Platt et al. (1980) - inhibition
      Ps= vp/((alpha/(alpha+inib))*(alpha/(alpha+inib))**(inib/alpha))
      ff= Ps*(1.-exp(-1.*alpha*par(ci)/Ps))*exp(-1.*inib*par(ci)/Ps)
      lumlim1(ci)=ff
!!        ---Nitrate :
      q1=(cc(n,ci)/k1)/(1.+cc(n,ci)/k1+cc(a,ci)/k2)
      nitlim1(ci)=q1
!!        ---Ammonium :
      q2=(cc(a,ci)/k2)/(1.+cc(n,ci)/k1+cc(a,ci)/k2)
      ammlim1(ci)=q2
!!        ---Zooplankton grazing preference normalization factor  
      fac=(cc(z,ci)+z0)/(k3*(r1*cc(p,ci)+r2*cc(b,ci)+  &
             r3*cc(d1,ci)+r4*cc(d2,ci)+r5*cc(d3,ci)+r6*cc(d4,ci))+  &          
                      r1*cc(p,ci)**2+r2*cc(b,ci)**2+   &
             r3*cc(d1,ci)**2+r4*cc(d2,ci)**2+r5*cc(d3,ci)**2+r6*cc(d4,ci)**2)  
!!        --- ???
      min67=min(cc(a,ci),eta*cc(l,ci))  

!-----------------------------------------------------------------------------------
!   Nutrients 
!-----------------------------------------------------------------------------------

      dd(n,p,ci)=ff*q1*(cc(p,ci)+p0)
      dd(a,p,ci)=ff*q2*(cc(p,ci)+p0)

!!    ---Bacteria respiration [Bacteria biomass growth]
      dd(a,b,ci)=vb*min67/(k4+min67+cc(l,ci))*(cc(b,ci)+b0)
      dd(l,b,ci)=vb*cc(l,ci)/(k4+min67+cc(l,ci))*(cc(b,ci)+b0)

!!    ---Condition of [ldon] to allow ldon to become a matrix for the aggregate 
if (cc(l,ci) .ge. lmin) then        !#1                           
     dd(l,d4,ci)=mldon*cc(l,ci)                            
else                                !#1                       
     dd(l,d4,ci)= 0.0                                         
end if                              !#1                 
!!    ---Nitrification rate 
     dd(a,n,ci)=mu5*cc(a,ci)                                 
      
!-----------------------------------------------------------------------------------
!   Phytoplankton [LOSSES]
!-----------------------------------------------------------------------------------

!!    ---Grazing losses (if beta =1 zooplankton eat everything)
      dd(p,z,ci)=beta*gmax*r1*cc(p,ci)**2*fac

!!    ---Non grazing losses : Excretion
      dd(p,l,ci)=gamma*ff*(q1+q2)*cc(p,ci)

!!    ---Non grazing losses : 
!!            -viral lysis (not taken into acount here)
!!            -internal respiration degradation
!In Moore et al,.2002, all Non grazing losses are estimated at 10% for diatom and small phytoplankton.
     dd(p,d1,ci)=mu1*(cc(p,ci)+p0)/(k5+cc(p,ci)+p0)*cc(p,ci)  &  
                 +(1.-beta)*gmax*r1*cc(p,ci)**2*fac

!!    ---Aggregation losses (See section COLLISION & AGGREGATION PROCESSES)

!-----------------------------------------------------------------------------------
!   Zooplankton [LOSSES]
!-----------------------------------------------------------------------------------

!!    ---Excretion
       dd(z,a,ci)=epsi*mu2*(cc(z,ci)+z0)/(k6+cc(z,ci)+z0)*cc(z,ci)
       dd(z,l,ci)=delta*mu2*(cc(z,ci)+z0)/(k6+cc(z,ci)+z0)*cc(z,ci)
!!    ---Sloppy feeding (z to dph or d1) :Taken into account in dd(p,d1,ci) see above.
!!    ---Fecal pelets
      dd(z,d3,ci)=eg*mu2*(cc(z,ci)+z0)/(k6+cc(z,ci)+z0)*cc(z,ci)
!!    ---Dead Zoo
      dd(z,d2,ci)=(1.-epsi-delta-eg)  &                       
        *mu2*(cc(z,ci)+z0)/(k6+cc(z,ci)+z0)*cc(z,ci) 

!-----------------------------------------------------------------------------------
!   Zooplankton [Diurnal migration]
!               -----------
! As a function of light and [phytoplancton](food)
!-----------------------------------------------------------------------------------

  if (Migra_zoo.eq. 1.0) then  !#2
      if (cc(p,ci) .lt. pmin .or. cc(d1,ci) .lt. dph_initial )  then        !#3    
          ws(z,ci) = -1.0*w_zmax*tanh(bertha*(par(ci)-parcrit)) 
      else !#3
          ws(z,ci) = 0.0
      end if !#3
 else            !#2
  ws(z,ci) = 0.0
 end if          !#2

!-----------------------------------------------------------------------------------
!   Bacterias [LOSSES]
!-----------------------------------------------------------------------------------
!!    ---Bacteria remineralisation    
       dd(b,a,ci)=mu3*cc(b,ci)   
!!    ---Bacteria grazed by zooplankton     
       dd(b,z,ci)=beta*gmax*r2*cc(b,ci)**2*fac
!!    ---Bacteria in aggregate (D4)
       dd(b,d4,ci)=mbac*cc(b,ci)                        
!!    ---Bacteria to detritus-non grazing mortality (D1)
       dd(b,d1,ci)=(1.-beta)*gmax*r2*cc(b,ci)**2*fac   

!-----------------------------------------------------------------------------------
!   Detritus [LOSSES]
!-----------------------------------------------------------------------------------
 
!!    ---Exsudation (see Moore et al., 2002)
      dd(d1,l,ci)=dphlossl*cc(d1,ci)            
      dd(d2,l,ci)=dzolossl*cc(d2,ci)            
      dd(d3,l,ci)=fplossl*cc(d3,ci)             

!!    ---Grazing
      dd(d1,z,ci)=beta*gmax*r3*cc(d1,ci)**2*fac       !Grazing-Saprophagy
      dd(d2,z,ci)=beta*gmax*r4*cc(d2,ci)**2*fac       !Carnivory/cannibalism/necrophagy
      dd(d3,z,ci)=beta*gmax*r5*cc(d3,ci)**2*fac       !Copprophagy/scatophagy
      dd(d4,z,ci)=beta*gmax*r6*cc(d4,ci)**2*fac       !Grazing-Macrophagie


!-------------------------------------------------------------------------------------
!!   Size (radius in m) variation for each particle type 
!-------------------------------------------------------------------------------------

if (size_rand .eq. 1.0) then!#4

  call random_number(r_phy)
size_phy=size_phy_us+((size_phy_up-size_phy_us)*r_phy)
   call random_number(r_dph)
size_dph=size_dph_us+((size_dph_up-size_dph_us)*r_dph)
   call random_number(r_dzo)
size_dzo=size_dzo_us+((size_dzo_up-size_dzo_us)*r_dzo)
  call random_number(r_fp)
size_fp=size_fp_us+((size_fp_up-size_fp_us)*r_fp)
   
else  !#4
size_phy=size_phy_us
size_dph=size_dph_us
size_dzo=size_dzo_us
size_fp=size_fp_us

endif !#4


!-----------------------------------------------------------------------------------
!   COLLISION & AGGREGATION 
!-----------------------------------------------------------------------------------
 

!-------------------------------------------------------------------------------------
!!   Usuefull parameters of Sedimentation rate for each particle type 
!------------------------------------------------------------------------------------- 

!----------Definition of the equivalent diameter of our particles [Bagheri 2015]-Unit of size [m]
!dS,i=racine3(LIS)   
!With L the longest dimension of the particle, I the longest dimension perpendicular to L, and S the longest dimension perpendicular to L and I (Bagheri 2015).
!With for phytoplankton and dead phytoplankton : L=I=S= size_X*2, and for dead zoo plankton and fecal pellets : L=I=size_x*4 and S= size_X*2 --» With size_X which represents the radius of our particle.
!We consider size_X the value of size that we can multiply to have the dimension we are looking for.
!Calculation of the cubic racin of X --» SIGN(ABS(X)**(1./3.),X) [FORTRAN, le langage normalisé, Michel Dubesset,Jean Vignes]

diam_phy = sign(abs(((size_phy*2.)*(size_phy*2.)*(size_phy*2.)))**(1./3.),((size_phy*2.)*(size_phy*2.)*(size_phy*2.)))

diam_dph = sign(abs(((size_dph*2.)*(size_dph*2.)*(size_dph*2.)))**(1./3.),((size_dph*2.)*(size_dph*2.)*(size_dph*2.))) 

diam_dzo = sign(abs(((size_dzo*4.)*(size_dzo*4.)*(size_dzo*2.)))**(1./3.),((size_dzo*4.)*(size_dzo*4.)*(size_dzo*2.)))

diam_fp  = sign(abs(((size_fp*4.)*(size_fp*4.)*(size_fp*2.)))**(1./3.),((size_fp*4.)*(size_fp*4.)*(size_fp*2.)))

!--» Does CFL limit 
  CFL = (depth_bio/nlev)/dt_bio

!----------Calculation of the CSF factor
!--Phytoplankton
  CSF_phy = (size_phy*2)/sqrt((size_phy*2)*(size_phy*2))
       if(CSF_phy .ge. 0.0 .and. CSF_phy.lt. 0.4) then !#5.5
          CSF_phy_calc = 2.18-(2.09*CSF_phy)
       else if (CSF_phy .ge. 0.4 .and. CSF_phy .lt. 0.8) then !#5.6
          CSF_phy_calc = 0.946*(CSF_phy)**(-0.378)
       else if (CSF_phy .ge. 0.8 .and. CSF_phy .le. 1.0) then !#5.6
          CSF_phy_calc = 1.0 ! consider as a sphere
        else  !#5.6
          write (*,*) 'Error in CSF values for phytoplankton : CSF .NE. [0-1]', CSF_phy
       endif !#5.6

!--Dead Phytoplankton
  CSF_dph = (size_dph*2)/sqrt((size_dph*2)*(size_dph*2))
write(*,*) 'CSF_dph',CSF_dph
 if(CSF_dph .ge. 0.0 .and. CSF_dph.lt. 0.4) then !#5.7
          CSF_dph_calc = 2.18-(2.09*CSF_dph)
      else if (CSF_dph .ge. 0.4 .and. CSF_dph .lt. 0.8) then !#5.7
           CSF_dph_calc = 0.946*(CSF_dph)**(-0.378)
      else if (CSF_dph .ge. 0.8 .and. CSF_dph .le. 1.0) then !#5.7
           CSF_dph_calc = 1.0 ! consider as a sphere
      else !#5.7
           write (*,*) 'Error in CSF values for Dead phytoplankton : CSF .NE. [0-1]',CSF_dph
      endif !#5.7

!--Dead Zooplankton
  CSF_dzo = (size_dzo*2)/sqrt((size_dzo*4)*(size_dzo*4))
   if(CSF_dzo .ge. 0.0 .and. CSF_dzo.lt. 0.4) then !#5.8
          CSF_dzo_calc = 2.18-(2.09*CSF_dzo)
      else if (CSF_dzo .ge. 0.4 .and. CSF_dzo .lt. 0.8) then !#5.8
           CSF_dzo_calc = 0.946*(CSF_dzo)**(-0.378)
      else if (CSF_dzo .ge. 0.8 .and. CSF_dzo .le. 1.0) then !#5.8
           CSF_dzo_calc = 1.0 ! consider as a sphere
      else  !#5.8
           write (*,*) 'Error in CSF values for dead zooplankton : CSF .NE. [0-1]',CSF_dzo
      endif !#5.8

!--Fecal Pellets
 CSF_fp = (size_fp*2)/sqrt((size_fp*4)*(size_fp*4))
write(*,*) 'CSF_fp',CSF_fp
      if(CSF_fp .ge. 0.0 .and. CSF_fp.lt. 0.4) then !#5.9
          CSF_fp_calc = 2.18-(2.09*CSF_fp)
      else if (CSF_fp .ge. 0.4 .and. CSF_fp .lt. 0.8) then !#5.9
           CSF_fp_calc = 0.946*(CSF_fp)**(-0.378)
      else if (CSF_fp .ge. 0.8 .and. CSF_fp .le. 1.0) then !#5.9
           CSF_fp_calc = 1.0 ! consider as a sphere
      else !#5.9
            write (*,*) 'Error in CSF values for fecal pellets : CSF .NE. [0-1]',CSF_fp
      endif !#5.9


!----------Calcul of densities
!Fluid density
densFlu = rho_0
!Difference of densities
Rp = (rho_p-densFlu)
Rdph= (rho_dph-densFlu)
Rdzo =(rho_dzo-densFlu)
Rfp =(rho_fp-densFlu)
Rmsn = (rho_msn-densFlu)

        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------

!----------Estimation of the maximum size allowed for particles
 !--» Comparaison with CFL limit 
    size_phy_max = ((CFL/0.93)**2)*(1/(g*(Rp/densFlu)))
    size_dph_max = ((CFL/0.93)**2)*(1/(g*(Rdph/densFlu)))
    size_dzo_max = ((CFL/0.93)**2)*(1/(g*(Rdzo/densFlu)))
    size_fp_max  = ((CFL/0.93)**2)*(1/(g*(Rfp/densFlu)))

!---------- Attribution of the good size
if (size_phy .gt. size_phy_max) then
  size_phy = size_phy_max
   write(*,*) 'Size of Phy OVERPASSES Max.Size of Phy to respect CFL limit'
endif
if (size_dph .gt. size_dph_max) then
  size_dph = size_dph_max
   write(*,*) 'Size of Dph OVERPASSES Max.Size of Dph to respect CFL limit'
endif
if (size_dzo .gt. size_dzo_max) then
  size_dzo = size_dzo_max
   write(*,*) 'Size of Dzo OVERPASSES Max.Size of Dzo to respect CFL limit'
endif
if (size_fp .gt. size_fp_max) then
  size_fp = size_fp_max
   write(*,*) 'Size of Fp OVERPASSES Max.Size of FP to respect CFL limit'
endif

!-------------------------------------------------------------------------------------
!!   Calculation of Sedimentation rates 
!------------------------------------------------------------------------------------- 

!!--------!Calculated by value from the .nml
if (Phys_w .eq. 0.0 ) then  !#5

      w_p_m   = w_p   ! [m/s]
      w_dph_m = w_dph ! [m/s]
      w_dzo_m = w_dzo ! [m/s]
      w_fp_m  = w_fp  ! [m/s]

!!--------Stokes's law from Ghosh et al 2013
!     all particles are considered as sphere,so the value of diameter needed in the equation = radius*2                     
else if (Phys_w .eq. 1.0) then  !#5

      !--Phytoplankton
      w_p_m=(g*((2*size_phy)**2)*Rp)/(18*dynvis)  ! [m/s]

      !--Dead phytoplankton
      w_dph_m=(g*((2*size_dph)**2)*Rdph)/(18*dynvis)  ! [m/s]
 
      !--Dead Zooplankton
      w_dzo_m=(g*((2*size_dzo)**2)*Rdzo)/(18*dynvis) ! [m/s]
    
      !--Fecal pellets
      w_fp_m=(g*((2*size_fp)**2)*Rfp)/(18*dynvis) ! [m/s]


!!--------Modified Stoke's law (For cylindrical particles) from McDonnell et al 2010
!   Utilisation of spherical diameter as D of particles, and respective values of L,I,S to represent particle shapes
!Even if the values of L,I,S of phy and dph represents a spehrical particles, it will be used in the same way following this special stoke's law for cylindrical
!    [w=((0.079*(r_X-r_F)*L^2*g)/dynvis)*(L/D)^-1.664].

else if (Phys_w .eq. 2.0) then !#5

      !--Phytoplankton 
      w_p_m=((0.079*Rp*((2*size_phy)**2)*g)/dynvis)*((2*size_phy)/(diam_phy))**(-1.664) ! [m/s]

      !--Dead phytoplankton
      w_dph_m=((0.079*Rdph*((2*size_dph)**2)*g)/dynvis)*((2*size_dph)/(diam_dph))**(-1.664)! [m/s]

      !--Dead Zooplankton
      w_dzo_m = ((0.079*Rdzo*((4*size_dzo)**2)*g)/dynvis)*((4*size_dzo)/(diam_dzo))**(-1.664)  ! [m/s]
  
      !--Fecal pellets
      w_fp_m = ((0.079*Rfp*((4*size_fp)**2)*g)/dynvis)*((4*size_fp)/(diam_fp))**(-1.664)  

!!--------Power law evolution from Alldredge and Gotschalk, 1988 based on Kajihara 1971 and from Komar 1981
!                    Calculation of the settling velocity (m/j)/secs_pr_day = m/s - utilisation here of the diameters 
else if (Phys_w .eq. 3.0) then !#5

      !--Phytoplankton ! [m/s]
      if (diam_phy .gt. 0.001) then !#5.1
       w_p_m =-(50*((diam_phy)**0.26))/secs_pr_day 
      else if (diam_phy .lt. 0.001 .and. diam_phy .gt. 0.0) then !#5.1
       w_p_m =-(160*((diam_phy)**0.57))/secs_pr_day  
      else !#5.1
       w_p_m =0.0
      endif!#5.1

   !--Dead Phytoplankton ! [m/s]
      if (diam_dph .gt. 0.001) then !#5.2
      w_dph_m =-(50*((diam_dph)**0.26))/secs_pr_day 
      else if (diam_dph.lt. 0.001 .and. diam_dph.gt. 0.0) then !#5.2
      w_dph_m =-(160*((diam_dph)**0.57))/secs_pr_day  
      else !#5.2
      w_dph_m =0.0
      endif !#5.2

   !--Dead Zooplankton ! [m/s]
      if (diam_dzo .gt. 0.001) then !#5.3
      w_dzo_m =-(50*((diam_dzo)**0.26))/secs_pr_day 
      else if (diam_dzo.lt. 0.001 .and. diam_dzo.gt. 0.0) then !#5.3
      w_dzo_m =-(160*((diam_dzo)**0.57))/secs_pr_day  
      else!#5.3
      w_dzo_m =0.0
      endif !#5.3

   !-- Fecal pellets ! [m/s]
      if (diam_fp .gt. 0.001) then !#5.4
      w_fp_m =-(50*((diam_fp)**0.26))/secs_pr_day 
      else if (diam_fp.lt. 0.001 .and. diam_fp.gt. 0.0) then !#5.4
      w_fp_m =-(160*((diam_fp)**0.57))/secs_pr_day  
      else!#5.4
      w_fp_m =0.0
      endif!#5.4

!!--------Stokes law for high reynolds number + Corey Shape Factor [Komar 1978]
else if (Phys_w .eq. 4.0) then !#5

      !--Phytoplankton 
      ! w_p_m=(1/(18*(kinvis*densFlu)))*(1/CSF_phy_calc)*(Rp)*g*(diam_phy)**2 ![m/s]
       w_p_m=(1/(18*(kinvis*densFlu)))*(1/CSF_phy_calc)*(Rp/densFlu)*g*(diam_phy)**2 ![m/s]
  
      !--Dead phytoplankton
     !  w_dph_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dph_calc)*(Rdph)*g*(diam_dph)**2  ![m/s]
       w_dph_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dph_calc)*(Rdph/densFlu)*g*(diam_dph)**2 ![m/s]

      !--Dead Zooplankton
   !   w_dzo_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dzo_calc)*(Rdzo)*g*(diam_dzo)**2 ![m/s]
      w_dzo_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dzo_calc)*(Rdzo/densFlu)*g*(diam_dzo)**2 ![m/s]

      !--Fecal pellets
   !   w_fp_m=(1/(18*(kinvis*densFlu)))*(1/CSF_fp_calc)*(Rfp)*g*(diam_fp)**2 ![m/s]
      w_fp_m=(1/(18*(kinvis*densFlu)))*(1/CSF_fp_calc)*(Rfp/densFlu)*g*(diam_fp)**2 ![m/s]

!!--------Depending on CSF + Re
else if (Phys_w .eq. 5.0) then !#5

  !--Phytoplankton
  if (CSF_phy .eq. 1.0) then ! Considered as a sphere
        !   w_p_m = -(((Rp/densFlu)*g*(diam_phy**2))/(18*kinvis)) ![m/s]
         w_p_m=(1/(18*(kinvis*densFlu)))*(1/CSF_phy_calc)*(Rp/densFlu)*g*(diam_phy)**2 ![m/s]
    !!        write(*,*) 'CSF_phy = 1 --> Sphere, then Stokes Law ',w_p_m
        ! Comparaison with the Stokes range ! VanRijn 1993
            Re_phy = abs(w_p_m*(diam_phy/kinvis))            
         if (Re_phy .gt. 1.0) then
            w_p_m = -(diam_phy**0.5/secs_pr_day) ![m/s]
    !!        write(*,*) 'Reynolds number for phytoplankton > 1',w_p_m
        endif
  else   ! No spherical
        if(diam_phy .le. 0.0001 )then
                 ! If the diameter of phy (d) -->  1 < d <= 100 micrometers (VanRijn 1993)
              !   w_p_m =-(((Rp/densFlu)*g*(diam_phy**2))/(18*kinvis)) ![m/s]
              w_p_m=(1/(18*(kinvis*densFlu)))*(1/CSF_phy_calc)*(Rp/densFlu)*g*(diam_phy)**2 ![m/s]
   !!          write(*,*) 'CSF .ne. 1.0 --> Diameter of phy : 1< d <= 100 micrometers, settling =' ,w_p_m 
        elseif(diam_phy .gt. 0.0001 .and. diam_phy .lt. 0.001)then
                  ! If the diameter of Phy (d) -->  100< d micrometers (VanRijn 1993)
             w_p_m= ((10.0*kinvis)/diam_phy)*(((1+((0.01*(Rp/densFlu)*g*((diam_phy)**3.0))/(kinvis**2.0)))**0.5)-1) ![m/s]
    !!        write(*,*) 'CSF .ne. 1.0 --> Diameter of phy :  100< d  micrometers, settling =' ,w_p_m 
       elseif(diam_phy .ge. 0.001) then
                  ! If the diameter of Phy (d) --> d > 1000 micrometers (VanRijn 1993)
                 ! w_p_m = (1.1*((Rp/densFlu)*g*diam_phy)**0.5) ![m/s]
                 w_p_m = (0.93*sqrt(Rp*g*diam_phy/densFlu))![m/s]
     !!                             write(*,*) 'Diameter of Phy : d > 1000 micrometers, settling =' ,w_p_m                                      
           endif                    
   endif
!--Dead Phytoplankton
write(*,*) 'CSF_dph_Calculated',CSF_dph_calc
write(*,*) 'diam_dph',diam_dph
  if (CSF_dph .eq. 1.0) then ! Considered as a sphere
      !     w_dph_m = -(((Rdph/densFlu)*g*(diam_dph**2))/(18*kinvis)) ![m/s]
  w_dph_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dph_calc)*(Rdph/densFlu)*g*(diam_dph)**2 ![m/s]
            write(*,*) 'CSF_dph = 1 --> Sphere, then Stokes Law ',w_dph_m
        ! Comparaison with the Stokes range ! VanRijn 1993
            Re_dph = abs(w_dph_m*(diam_dph/kinvis))            
         if (Re_dph .gt. 1.0) then
            w_dph_m = -diam_dph**0.5/secs_pr_day ![m/s]
            write(*,*) 'Reynolds number for Dead-phytoplankton > 1',w_dph_m
        endif
  else   ! No spherical
        if(diam_dph .le. 0.0001 )then
                 ! If the diameter of dph (d) -->  1 < d <= 100 micrometers (VanRijn 1993)
              !   w_dph_m =-(((Rdph/densFlu)*g*(diam_dph**2))/(18*kinvis)) ![m/s]
             w_dph_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dph_calc)*(Rdph/densFlu)*g*(diam_dph)**2 ![m/s]
             write(*,*) 'CSF .ne. 1.0 --> Diameter of dph : 1< d <= 100 micrometers, settling =' ,w_dph_m 
        elseif(diam_dph .gt. 0.0001 .and. diam_dph .lt. 0.001 )then
                  ! If the diameter of dph (d) -->  100< d micrometers (VanRijn 1993)
            w_dph_m= ((10.0*kinvis)/diam_dph)*(((1+((0.01*(Rdph/densFlu)*g*((diam_dph)**3.0))/(kinvis**2.0)))**0.5)-1) ![m/s]
            write(*,*) 'CSF .ne. 1.0 --> Diameter of dph :  100< d  micrometers, settling =' ,w_dph_m 
        elseif(diam_dph .ge. 0.001) then
                  ! If the diameter of dph (d) --> d > 1000 micrometers (VanRijn 1993)
                !  w_dph_m = (1.1*((Rdph/densFlu)*g*diam_dph)**0.5) ![m/s]
                  w_dph_m = (0.93*sqrt(Rdph*g*diam_dph/densFlu)) ![m/s]
             write(*,*) 'Diameter of dph : d > 1000 micrometers, settling =' ,w_dph_m                                      
        endif                    
   endif
!--Dead Zooplankton
  if (CSF_dzo .eq. 1.0) then ! Considered as a sphere
        !   w_dzo_m = -(((Rdzo/densFlu)*g*(diam_dzo**2))/(18*kinvis)) ![m/s]
            w_dzo_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dzo_calc)*(Rdzo/densFlu)*g*(diam_dzo)**2 ![m/s]
   !!         write(*,*) 'CSF_dzo = 1 --> Sphere, then Stokes Law ',w_dzo_m
        ! Comparaison with the Stokes range ! VanRijn 1993
            Re_dzo = abs(w_dzo_m*(diam_dzo/kinvis))            
         if (Re_dzo .gt. 1.0) then
            w_dzo_m = -diam_dzo**0.5/secs_pr_day ![m/s]
    !!        write(*,*) 'Reynolds number for Dead-zooplankton > 1',w_dzo_m
        endif
  else   ! No spherical
        if(diam_dzo .le. 0.0001 )then
                 ! If the diameter of dzo (d) -->  1 < d <= 100 micrometers (VanRijn 1993)
              !   w_dzo_m =-(((Rdzo/densFlu)*g*(diam_dzo**2))/(18*kinvis)) ![m/s]
             w_dzo_m=(1/(18*(kinvis*densFlu)))*(1/CSF_dzo_calc)*(Rdzo/densFlu)*g*(diam_dzo)**2 ![m/s]
    !!         write(*,*) 'CSF .ne.1.0 --> Diameter of dzo: 1< d <= 100 micrometers, settling =' ,w_dzo_m 
        elseif(diam_dzo .gt. 0.0001 .and. diam_dzo .lt. 0.001)then
                  ! If the diameter of dzo (d) -->  100< d micrometers (VanRijn 1993)
     w_dzo_m= ((10.0*kinvis)/diam_dzo)*(((1+((0.01*(Rdzo/densFlu)*g*((diam_dzo)**3.0))/(kinvis**2.0)))**0.5)-1) ![m/s]
    !!        write(*,*) 'CSF .ne. 1.0 --> Diameter of dzo :  100< d  micrometers, settling =' ,w_dzo_m 
      elseif(diam_dzo .ge. 0.001) then
                  ! If the diameter of Dzo (d) --> d > 1000 micrometers (VanRijn 1993)
             !     w_dzo_m = (1.1*((Rdzo/densFlu)*g*diam_dzo)**0.5) ![m/s]
                   w_dzo_m = (0.93*sqrt(Rdzo*g*diam_dzo/densFlu)) ![m/s]
    !!      write(*,*) 'Diameter of Dzo : d > 1000 micrometers, settling =' ,w_dzo_m                                      
           endif                    
   endif
  !--Fecal pellets
write(*,*) 'CSF_fp_Calculated',CSF_fp_calc
write(*,*) 'diam_fp',diam_fp
  if (CSF_fp .eq. 1.0) then ! Considered as a sphere
     !      w_fp_m = -(((Rfp/densFlu)*g*(diam_fp**2))/(18*kinvis)) ![m/s]
        w_fp_m=(1/(18*(kinvis*densFlu)))*(1/CSF_fp_calc)*(Rfp/densFlu)*g*(diam_fp)**2 ![m/s]
            write(*,*) 'CSF_fp = 1 --> Sphere, then Stokes Law ',w_fp_m
        ! Comparaison with the Stokes range ! VanRijn 1993
            Re_fp = abs(w_fp_m*(diam_fp/kinvis))            
         if (Re_fp .gt. 1.0) then
            w_fp_m = -diam_fp**0.5/secs_pr_day ![m/s]
            write(*,*) 'Reynolds number for Fecal pellets > 1',w_fp_m
        endif
  else   ! No spherical
        if( diam_fp .le. 0.0001 )then
                 ! If the diameter of fp (d) -->  1 < d <= 100 micrometers (VanRijn 1993)
          !       w_fp_m =-(((Rfp/densFlu)*g*(diam_fp**2))/(18*kinvis)) ![m/s]
                 w_fp_m=(1/(18*(kinvis*densFlu)))*(1/CSF_fp_calc)*(Rfp/densFlu)*g*(diam_fp)**2 ![m/s]
             write(*,*) 'CSF .ne. 1.0 --> Diameter of fp: 1< d <= 100 micrometers, settling =' ,w_fp_m 
        elseif(diam_fp .gt. 0.0001 .and. diam_fp .lt. 0.001)then
                  ! If the diameter of fp (d) -->  100< d micrometers (VanRijn 1993)
     w_fp_m= ((10.0*kinvis)/diam_fp)*(((1+((0.01*(Rfp/densFlu)*g*((diam_fp)**3.0))/(kinvis**2.0)))**0.5)-1) ![m/s]
            write(*,*) 'CSF .ne. 1.0 --> Diameter of fp :  100< d  micrometers, settling =' ,w_fp_m 
       elseif(diam_fp .ge. 0.001) then
                  ! If the diameter of Fp (d) --> d > 1000 micrometers (VanRijn 1993)
             !     w_fp_m = (1.1*((Rfp/densFlu)*g*diam_fp)**0.5) ![m/s]
                   w_fp_m = (0.93*sqrt(Rdzo*g*diam_dzo/densFlu))  ![m/s]
             write(*,*) 'Diameter of Fp : d > 1000 micrometers, settling =' ,w_fp_m                                      
      endif                    
   endif
else !#5
      write(*,*) 'No specification for settling velocity of particles,set to nml values'
       w_p_m   = w_p  ![m/s]
       w_dph_m = w_dph![m/s]
       w_dzo_m = w_dzo![m/s]
       w_fp_m  = w_fp ![m/s]
endif !#5

If (Phys_w .ne. 5.0) then
! ! Comparaison with the Stokes range ! VanRijn 1993
 Re_phy = abs(w_p_m*(diam_phy/kinvis))
 Re_dph = abs(w_dph_m*(diam_dph/kinvis))
 Re_dzo = abs(w_dzo_m*(diam_dzo/kinvis))
 Re_fp  = abs(w_fp_m*(diam_fp/kinvis))
 
if (Re_phy .gt. 1.0)then !#6
w_p_m = -diam_phy**0.5/secs_pr_day ![m/s]
write(*,*) 'Reynolds number for phytoplankton > 1'
endif !#6

if (Re_dph .gt. 1.0)then !#7
w_dph_m = -diam_dph**0.5/secs_pr_day ![m/s]
write(*,*) 'Reynolds number for Dead phytoplankton > 1'
endif !#7

if (Re_dzo .gt. 1.0)then !#8
w_dzo_m = -diam_dzo**0.5/secs_pr_day ![m/s]
write(*,*) 'Reynolds number for Dead zooplankton > 1'
endif !#8

if (Re_fp .gt. 1.0)then !#9
w_fp_m = -diam_fp**0.5/secs_pr_day ![m/s]
write(*,*) 'Reynolds number for fecal pellets > 1'
endif !#9

endif

!Everyone will settle at the end of the loop (see below)

!!    ---Condition of the environment to allow collision and aggregation
if (cc(l,ci) .ge. lmin) then  ! #1
!  LEVEL1 'Let"s coagulate buddy ! [LDON Concentration greater than lmin]'

!-------------------------------------------------------------------------------------
!!   Maximum loss for aggregation for each particle type  ! Moore et al.2002
!-------------------------------------------------------------------------------------
!!    ---Phytoplankton 
  pprime=max(cc(p,ci),p0)  
!!    ---Dead Phytoplankton 
  d1rime=max(cc(d1,ci),p0)
!!    ---Dead zooplankton
  d2rime=max(cc(d2,ci),p0)
!!    ---Fecal pellets 
  d3rime=max(cc(d3,ci),p0)

!-------------------------------------------------------------------------------------
!!   Stickiness for each particle type interaction
!-------------------------------------------------------------------------------------

if(sti_cst .eq. 1.0) then ! #1.2
     !Stickiness equal the value given in the nml.
         sti_2p(ci)    = stip_p
         sti_pdph(ci)  = stip_dph
         sti_pdzo(ci)  = stip_dzo
         sti_pfp(ci)   = stip_fp 
         sti_2dph(ci)  = stidph_dph
         sti_dphdzo(ci)= stidph_dzo
         sti_dphfp(ci) = stidph_fp
         sti_2dzo(ci)  = stidzo_dzo
         sti_dzofp(ci) = stidzo_fp
         sti_2fp(ci)   = stifp_fp

else !#1.2
!Select a random value for the stickiness

   call random_number(r_phy)
   stip=r_phy
   call random_number(r_dph)
   stidph=r_dph
   call random_number(r_dzo)
   stidzo=r_dzo
  call random_number(r_fp)
   stifp=r_fp

!Kiorboe 1994
  sti_2p(ci)     = 0.5*(stip+stip)
  sti_pdph(ci)   = 0.5*(stip+stidph)
  sti_pdzo(ci)   = 0.5*(stip+stidzo)
  sti_pfp(ci)    = 0.5*(stip+stifp)
  sti_2dph(ci)   = 0.5*(stidph+stidph)
  sti_dphdzo(ci) = 0.5*(stidph+stidzo)
  sti_dphfp(ci)  = 0.5*(stidph+stifp)
  sti_2dzo(ci)   = 0.5*(stidzo+stidzo)
  sti_dzofp(ci)  = 0.5*(stidzo+stifp)
  sti_2fp(ci)    = 0.5*(stifp+stifp)

endif  ! #1.2

     if (Coag_coef .eq. 0.0) then !#2
!-------------------------------------------------------------------------------------
!        LEVEL2 'No physical coagulation happens here [Constant Beta are set]'
!-------------------------------------------------------------------------------------
             if(betaBr .eq. 0.0 .and. betaSh .eq. 0.0 .and. betaDs .eq. 0.0) then  ! #3
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 1 : Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
 !!    ---A - Aggregation with itself
    coli_pp_NoPhys=sti_2p(ci)*betap_p*cc(p,ci)*cc(p,ci)
    agg_pp=min((txloss_p*pprime),coli_pp_NoPhys)
!!    ---B - Aggregation with dead phytoplankton
   coli_pdph_NoPhys=sti_pdph(ci)*betap_dph*cc(p,ci)*cc(d1,ci)
   agg_pdph=min((txloss_p*pprime),coli_pdph_NoPhys)
!!    ---C - Aggregation with dead zooplankton
   coli_pdzo_NoPhys=sti_pdzo(ci)*betap_dzo*cc(p,ci)*cc(d2,ci)
   agg_pdzo=min((txloss_p*pprime),coli_pdzo_NoPhys)
!!    ---D - Aggregation with Fecal pellets
   coli_pfp_NoPhys=sti_pfp(ci)*betap_fp*cc(p,ci)*cc(d3,ci)
   agg_pfp=min((txloss_p*pprime),coli_pfp_NoPhys)

!*********
dd(p,d4,ci)= (agg_pp)+(agg_pdph)+(agg_pdzo)+(agg_pfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 2 : Dead Phytoplankton loss by aggregation 
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
 !!    ---A - Aggregation with itself
    coli_dphdph_NoPhys=sti_2dph(ci)*betadph_dph*cc(d1,ci)*cc(d1,ci)
    agg_dphdph=min((txloss_dph*d1rime),coli_dphdph_NoPhys)
!!    ---B - Aggregation with dead zooplankton
   coli_dphdzo_NoPhys=sti_dphdzo(ci)*betap_dzo*cc(d1,ci)*cc(d2,ci)
   agg_dphdzo=min((txloss_dph*d1rime),coli_dphdzo_NoPhys)
!!    ---C - Aggregation with Fecal pellets
   coli_dphfp_NoPhys=sti_dphfp(ci)*betadph_fp*cc(d1,ci)*cc(d3,ci)
   agg_dphfp=min((txloss_dph*d1rime),coli_dphfp_NoPhys)

!*********
dd(d1,d4,ci)= (agg_pdph)+(agg_dphdph)+(agg_dphdzo)+(agg_dphfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 3 : Dead Zooplankton loss by aggregation 
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
 !!    ---A - Aggregation with itself
    coli_dzodzo_NoPhys=sti_2dzo(ci)*betadzo_dzo*cc(d2,ci)*cc(d2,ci)
    agg_dzodzo=min((txloss_dzo*d2rime),coli_dzodzo_NoPhys)
!!    ---B - Aggregation with Fecal pellets
   coli_dzofp_NoPhys=sti_dzofp(ci)*betadzo_fp*cc(d2,ci)*cc(d3,ci)
   agg_dzofp=min((txloss_dzo*d2rime),coli_dzofp_NoPhys)

!*********
dd(d2,d4,ci)= (agg_pdzo)+(agg_dphdzo)+(agg_dzodzo)+(agg_dzofp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 4 : Fecal pellets loss by aggregation 
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself
    coli_fpfp_NoPhys=sti_2fp(ci)*betafp_fp*cc(d3,ci)*cc(d3,ci)
    agg_fpfp=min((txloss_fp*d3rime),coli_fpfp_NoPhys)

!*********
dd(d3,d4,ci)= (agg_pfp)+(agg_dphfp)+(agg_dzofp)+(agg_fpfp)
!*********
endif !#3

!*************************************************************************************
!!    ---Choice from the user to use and study only betaBr for the calculation of the kernel coefficient

!-------------------------------------------------------------------------------------
!LEVEL3 'Nevertheless...I rather prefer Coagulate only with : BetaBR'
!-------------------------------------------------------------------------------------
if(betaBr .eq. 1.0 .and. betaSh .eq. 0.0 .and. betaDs .eq. 0.0) then !#4
!-------------------------------------------------------------------------------------
! Usefull data
!-------------------------------------------------------------------------------------

!!    ---Conversion of field C° temperature to K° - description of physic_Br for easier calcul
!LEVEL2 'Temperature bath is dependant of mother-ocean"s mood ! [Temp. variable due to field/physical]'
   T_degK=t(ci)+ 273.15 
   physic_Br = (2*kB*T_degK)/(3*dynvis)

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 1 : Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself
    betaBr_pp=(physic_Br)*(((size_phy+size_phy)**2)/(size_phy*size_phy))
    coli_pp=sti_2p(ci)* betaBr_pp*cc(p,ci)*cc(p,ci)
    agg_pp=min((txloss_p*pprime),coli_pp)
!!    ---B - Aggregation with dead phytoplankton
   betaBr_pdph=(physic_Br)*(((size_phy+size_dph)**2)/(size_phy*size_dph))
   coli_pdph=sti_pdph(ci)*betaBr_pdph*cc(p,ci)*cc(d1,ci)
   agg_pdph=min((txloss_p*pprime),coli_pdph)
!!    ---C - Aggregation with dead zooplankton
   betaBr_pdzo=(physic_Br)*(((size_phy+size_dzo)**2)/(size_phy*size_dzo))
   coli_pdzo=sti_pdzo(ci)*betaBr_pdzo*cc(p,ci)*cc(d2,ci)
   agg_pdzo=min((txloss_p*pprime),coli_pdzo)
!!    ---D - Aggregation with Fecal pellets
   betaBr_pfp=(physic_Br)*(((size_phy+size_fp)**2)/(size_phy*size_fp))
   coli_pfp=sti_pfp(ci)*betaBr_pfp*cc(p,ci)*cc(d3,ci)
   agg_pfp=min((txloss_p*pprime),coli_pfp)

!*********
!!    ---Loss of p to msn
dd(p,d4,ci)= (agg_pp)+(agg_pdph)+(agg_pdzo)+(agg_pfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 2 : Dead Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself       
     betaBr_dphdph=(physic_Br)*(((size_dph+size_dph)**2)/(size_dph*size_dph))
     coli_dphdph=sti_2dph(ci)*betaBr_dphdph*cc(d1,ci)*cc(d1,ci)
     agg_dphdph=min((txloss_dph*d1rime),coli_dphdph)
!!    ---B - Aggregation with dead zooplankton           
     betaBr_dphdzo=(physic_Br)*(((size_dph+size_dzo)**2)/(size_dph*size_dzo))
     coli_dphdzo=sti_dphdzo(ci)*betaBr_dphdzo*cc(d1,ci)*cc(d2,ci)
     agg_dphdzo=min((txloss_dph*d1rime),coli_dphdzo)
!!    ---C - Aggregation with fecal pellets         
     betaBr_dphfp=(physic_Br)*(((size_dph+size_fp)**2)/(size_dph*size_fp))
     coli_dphfp=sti_dphfp(ci)*betaBr_dphfp*cc(d1,ci)*cc(d3,ci)
     agg_dphfp=min((txloss_dph*d1rime),coli_dphfp)

!*********
!!    ---Loss of D1 or dph to msn
dd(d1,d4,ci)= (agg_pdph)+(agg_dphdph)+(agg_dphdzo)+(agg_dphfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 3 : Dead zoo loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself          
    betaBr_dzodzo=(physic_Br)*(((size_dzo+size_dzo)**2)/(size_dzo*size_dzo))
    coli_dzodzo=sti_2dzo(ci)*betaBr_dzodzo*cc(d2,ci)*cc(d2,ci)
    agg_dzodzo=min((txloss_dzo*d2rime),coli_dzodzo)
!!    ---B - Aggregation with fecal pellets
   betaBr_dzofp=(physic_Br)*(((size_dzo+size_fp)**2)/(size_dzo*size_fp))
   coli_dzofp=sti_dzofp(ci)*betaBr_dzofp*cc(d2,ci)*cc(d3,ci)
   agg_dzofp=min((txloss_dzo*d2rime),coli_dzofp)

!*********
!!    ---Loss of D2 or dzo to msn
dd(d2,d4,ci)= (agg_pdzo)+(agg_dphdzo)+(agg_dzodzo)+(agg_dzofp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 4 : Fecal pellets loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself             
      betaBr_fpfp=(physic_Br)*(((size_fp+size_fp)**2)/(size_fp*size_fp))
      coli_fpfp=sti_2fp(ci)*betaBr_fpfp*cc(d3,ci)*cc(d3,ci)
      agg_fpfp=min((txloss_fp*d3rime),coli_fpfp)

!*********
!!    ---Loss of D3 or fp to msn
dd(d3,d4,ci)= (agg_pfp)+(agg_dphfp)+(agg_dzofp)+(agg_fpfp)
!*********

endif !#4 

!*************************************************************************************
!!    ---Choice from the user to use and study only betaSh (Curvilinear kernel for turbulence) for the calculation of the kernel coefficient
!-------------------------------------------------------------------------------------
!LEVEL3 'Nevertheless...I rather prefer Coagulate only with : BetaSh'
!-------------------------------------------------------------------------------------
if (betaBr .eq. 0.0 .and. betaSh .eq. 1.0 .and. betaDs .eq. 0.0) then  ! #5

if(eps_const .eq. 1.0) then !#5.1
!LEVEL4 'Go and shake up the bath by an EPS constant value'
 bio_eps= eps_n
else !#5.1
!LEVEL4 'Go and shake up the bath by an EPS obtains via physical environment'
 bio_eps=eps(ci)
endif !#5.1

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 1 : Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself
   q_pp=(min(size_phy,size_phy))/(max(size_phy,size_phy))
betaSh_pp=9.8*((q_pp**2)/(1+2*q_pp**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_phy)**3
    coli_pp=sti_2p(ci)*betaSh_pp*cc(p,ci)*cc(p,ci)
    agg_pp=min((txloss_p*pprime),coli_pp)
!!    ---B - Aggregation with dead phytoplankton
   q_pdph=(min(size_phy,size_dph))/(max(size_phy,size_dph))
betaSh_pdph=9.8*((q_pdph**2)/(1+2*q_pdph**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_dph)**3
   coli_pdph=sti_pdph(ci)*betaSh_pdph*cc(p,ci)*cc(d1,ci)
   agg_pdph=min((txloss_p*pprime),coli_pdph)
!!    ---C - Aggregation with dead zooplankton
   q_pdzo=(min(size_phy,size_dzo))/(max(size_phy,size_dzo))
betaSh_pdzo=9.8*((q_pdzo**2)/(1+2*q_pdzo**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_dzo)**3
   coli_pdzo=sti_pdzo(ci)*betaSh_pdzo*cc(p,ci)*cc(d2,ci)
   agg_pdzo=min((txloss_p*pprime),coli_pdzo)
!!    ---D - Aggregation with Fecal pellets
   q_pfp=(min(size_phy,size_fp))/(max(size_phy,size_fp))
betaSh_pfp=9.8*((q_pfp**2)/(1+2*q_pfp**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_fp)**3
   coli_pfp=sti_pfp(ci)*betaSh_pfp*cc(p,ci)*cc(d3,ci)
   agg_pfp=min((txloss_p*pprime),coli_pfp)

!*********
!!    ---Loss of p to msn
dd(p,d4,ci)= (agg_pp)+(agg_pdph)+(agg_pdzo)+(agg_pfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 2 : Dead Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself       
   q_dphdph=(min(size_dph,size_dph))/(max(size_dph,size_dph))
betaSh_dphdph=9.8*((q_dphdph**2)/(1+2*q_dphdph**2))*(sqrt(eps(ci)/kinvis))*(size_dph+size_dph)**3
     coli_dphdph=sti_2dph(ci)*betaSh_dphdph*cc(d1,ci)*cc(d1,ci)
     agg_dphdph=min((txloss_dph*d1rime),coli_dphdph)
!!    ---B - Aggregation with dead zooplankton           
   q_dphdzo=(min(size_dph,size_dzo))/(max(size_dph,size_dzo))
betaSh_dphdzo=9.8*((q_dphdzo**2)/(1+2*q_dphdzo**2))*(sqrt(eps(ci)/kinvis))*(size_dph+size_dzo)**3
     coli_dphdzo=sti_dphdzo(ci)*betaSh_dphdzo*cc(d1,ci)*cc(d2,ci)
     agg_dphdzo=min((txloss_dph*d1rime),coli_dphdzo)
!!    ---C - Aggregation with fecal pellets         
   q_dphfp=(min(size_dph,size_fp))/(max(size_dph,size_fp))
betaSh_dphfp=9.8*((q_dphfp**2)/(1+2*q_dphfp**2))*(sqrt(eps(ci)/kinvis))*(size_dph+size_fp)**3
     coli_dphfp=sti_dphfp(ci)*betaSh_dphfp*cc(d1,ci)*cc(d3,ci)
     agg_dphfp=min((txloss_dph*d1rime),coli_dphfp)

!*********
!!    ---Loss of D1 or dph to msn
dd(d1,d4,ci)= (agg_pdph)+(agg_dphdph)+(agg_dphdzo)+(agg_dphfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 3 : Dead zoo loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself          
   q_dzodzo=(min(size_dzo,size_dzo))/(max(size_dzo,size_dzo))
betaSh_dzodzo=9.8*((q_dzodzo**2)/(1+2*q_dzodzo**2))*(sqrt(eps(ci)/kinvis))*(size_dzo+size_dzo)**3
 coli_dzodzo=sti_2dzo(ci)*betaSh_dzodzo*cc(d2,ci)*cc(d2,ci)
    agg_dzodzo=min((txloss_dzo*d2rime),coli_dzodzo)
!!    ---B - Aggregation with fecal pellets
   q_dzofp=(min(size_dzo,size_fp))/(max(size_dzo,size_fp))
betaSh_dzofp=9.8*((q_dzofp**2)/(1+2*q_dzofp**2))*(sqrt(eps(ci)/kinvis))*(size_dzo+size_fp)**3
   coli_dzofp=sti_dzofp(ci)*betaSh_dzofp*cc(d2,ci)*cc(d3,ci)
   agg_dzofp=min((txloss_dzo*d2rime),coli_dzofp)

!*********
!!    ---Loss of D2 or dzo to msn
dd(d2,d4,ci)= (agg_pdzo)+(agg_dphdzo)+(agg_dzodzo)+(agg_dzofp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 4 : Fecal pellets loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself             
   q_fpfp=(min(size_fp,size_fp))/(max(size_fp,size_fp))
betaSh_fpfp=9.8*((q_fpfp**2)/(1+2*q_fpfp**2))*(sqrt(eps(ci)/kinvis))*(size_fp+size_fp)**3
   coli_fpfp=sti_2fp(ci)*betaSh_fpfp*cc(d3,ci)*cc(d3,ci)
      agg_fpfp=min((txloss_fp*d3rime),coli_fpfp)

!*********
!!    ---Loss of D3 or fp to msn
dd(d3,d4,ci)= (agg_pfp)+(agg_dphfp)+(agg_dzofp)+(agg_fpfp)
!*********

endif ! #5

!*************************************************************************************
!!    ---Choice from the user to use and study only betaDs (curvilinear) for the calculation of the kernel coefficient
!-------------------------------------------------------------------------------------
!LEVEL3 'Nevertheless...I rather prefer Coagulate only with : BetaDs'
!-------------------------------------------------------------------------------------
if (betaBr .eq. 0.0 .and. betaSh .eq. 0.0 .and. betaDs .eq. 1.0) then ! #6

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 1 : Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself
!abs_pp=ABS(w_p_m-w_p_m)
!betaDs_pp=0.5*pi*(size_phy**2)*abs_pp
! coli_pp=sti_2p(ci)*betaDs_pp*cc(p,ci)*cc(p,ci)
! agg_pp=(min((txloss_p*pprime),coli_pp))

!!    ---B - Aggregation with dead phytoplankton
 abs_pdph= ABS(w_p_m-w_dph_m)  
betaDs_pdph=0.5*pi*(min(size_phy,size_dph)**2)*abs_pdph
   coli_pdph=sti_pdph(ci)*betaDs_pdph*cc(p,ci)*cc(d1,ci)
   agg_pdph=min((txloss_p*pprime),coli_pdph)
!!    ---C - Aggregation with dead zooplankton
 abs_pdzo= ABS(w_p_m-w_dzo_m)  
 betaDs_pdzo=0.5*pi*(min(size_phy,size_dzo)**2)*abs_pdzo
   coli_pdzo=sti_pdzo(ci)* betaDs_pdzo*cc(p,ci)*cc(d2,ci)
   agg_pdzo=min((txloss_p*pprime),coli_pdzo)
!!    ---D - Aggregation with Fecal pellets
 abs_pfp= ABS(w_p_m-w_fp_m)  
 betaDs_pfp=0.5*pi*(min(size_phy,size_fp)**2)*abs_pfp
   coli_pfp=sti_pfp(ci)*betaDs_pfp*cc(p,ci)*cc(d3,ci)
   agg_pfp=min((txloss_p*pprime),coli_pfp)

!*********
!!    ---Loss of p to msn
!dd(p,d4,ci)=(agg_pp)+ (agg_pdph)+(agg_pdzo)+(agg_pfp)
dd(p,d4,ci)=(agg_pdph)+(agg_pdzo)+(agg_pfp)

!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 2 : Dead Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself       
!abs_dphdph=ABS(w_dph-w_dph)
!betaDs_dphdph=0.5*pi*(size_dph**2)*abs_dphdph
! coli_dphdph=sti_2dph(ci)*betaDs_dphdph*cc(d1,ci)*cc(d1,ci)
! agg_dphdph=(min((txloss_dph*d1rime),coli_dphdph))
!!    ---B - Aggregation with dead zooplankton           
 abs_dphdzo= ABS(w_dph_m-w_dzo_m) 
 betaDs_dphdzo=0.5*pi*(min(size_dph,size_dzo)**2)*abs_dphdzo
     coli_dphdzo=sti_dphdzo(ci)*betaDs_dphdzo*cc(d1,ci)*cc(d2,ci)
     agg_dphdzo=min((txloss_dph*d1rime),coli_dphdzo)
!!    ---C - Aggregation with fecal pellets         
 abs_dphfp= ABS(w_dph_m-w_fp_m) 
 betaDs_dphfp=0.5*pi*(min(size_dph,size_fp)**2)*abs_dphfp
     coli_dphfp=sti_dphfp(ci)*betaDs_dphfp*cc(d1,ci)*cc(d3,ci)
     agg_dphfp=min((txloss_dph*d1rime),coli_dphfp)

!*********
!!    ---Loss of D1 or dph to msn
!dd(d1,d4,ci)= (agg_dphdph)+(agg_pdph)+(agg_dphdzo)+(agg_dphfp)
dd(d1,d4,ci)= (agg_pdph)+(agg_dphdzo)+(agg_dphfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 3 : Dead zoo loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself          
! abs_dzodzo= ABS(w_dzo_m-w_dzo_m) 
! betaDs_dzofp=0.5*pi*(size_dzo**2)*abs_dzodzo
!   coli_dzodzo=sti_2dzo(ci)*betaDs_dzodzo*cc(d2,ci)*cc(d2,ci)
!   agg_dzodzo=min((txloss_dzo*d2rime),coli_dzodzo)
!!    ---B - Aggregation with fecal pellets
 abs_dzofp= ABS(w_dzo_m-w_fp_m) 
 betaDs_dzofp=0.5*pi*(min(size_dzo,size_fp)**2)*abs_dzofp
   coli_dzofp=sti_dzofp(ci)*betaDs_dzofp*cc(d2,ci)*cc(d3,ci)
   agg_dzofp=min((txloss_dzo*d2rime),coli_dzofp)

!*********
!!    ---Loss of D2 or dzo to msn
dd(d2,d4,ci)=(agg_pdzo)+(agg_dphdzo)+(agg_dzofp)
!dd(d2,d4,ci)=(agg_dzodzo)+ (agg_pdzo)+(agg_dphdzo)+(agg_dzofp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 4 : Fecal pellets loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself             
!abs_fpfp=abs(w_fp_m-w_fp_m)
!betaDs_fpfp=0.5*pi*(size_fp**2)*abs_fpfp
! coli_fpfp=sti_2fp(ci)*betaDs_fpfp*cc(d3,ci)*cc(d3,ci)
! agg_fpfp=min((txloss_fp*d3rime),coli_fpfp)
!*********
!!    ---Loss of D3 or fp to msn
!dd(d3,d4,ci)= (agg_fpfp)+(agg_pfp)+(agg_dphfp)+(agg_dzofp)
dd(d3,d4,ci)= (agg_pfp)+(agg_dphfp)+(agg_dzofp)
!*********
endif !#6

!*************************************************************************************
else!#2 (if Coag.Coef .eq. 1.0)
!-------------------------------------------------------------------------------------
!LEVEL3 'Physical Coagulation happens here ![Beta are calculated via physic]'
!-------------------------------------------------------------------------------------

!-------------------------------------------------------------------------------------
! Usefull data
!-------------------------------------------------------------------------------------
!!    ---Conversion of field C° temperature to K°
   T_degK=t(ci)+ 273.15 

!!    ---Determination of the value of eps
if(eps_const .eq. 1.0) then !#2.1
 bio_eps= eps_n
else !#2.1
 bio_eps=eps(ci)
endif !#2.1
!!    ---Determination of physic_Br
   physic_Br = (2*kB*T_degK)/(3*dynvis)


!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 1 : Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!!    ---A - Aggregation with itself
betaBr_pp=(physic_Br)*(((size_phy+size_phy)**2)/(size_phy*size_phy))
 q_pp=(min(size_phy,size_phy))/(max(size_phy,size_phy))
betaSh_pp=9.8*((q_pp**2)/(1+2*q_pp**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_phy)**3
!No BDs 

    kernel_coef_pp=betaBr_pp+betaSh_pp
    coli_pp=sti_2p(ci)*kernel_coef_pp*cc(p,ci)*cc(p,ci)
    agg_pp=min((txloss_p*pprime),coli_pp)

!!    ---B - Aggregation with dead phytoplankton
betaBr_pdph=(physic_Br)*(((size_phy+size_dph)**2)/(size_phy*size_dph))
 q_pdph=(min(size_phy,size_dph))/(max(size_phy,size_dph))
betaSh_pdph=9.8*((q_pdph**2)/(1+2*q_pdph**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_dph)**3
 abs_pdph= ABS(w_p_m-w_dph_m)  
betaDs_pdph=(1/2)*pi*(min(size_phy,size_dph)**2)*abs_pdph
    
   kernel_coef_pdph=betaBr_pdph+betaSh_pdph+betaDs_pdph
   coli_pdph=sti_pdph(ci)*kernel_coef_pdph*cc(p,ci)*cc(d1,ci)
   agg_pdph=min((txloss_p*pprime),coli_pdph)

!!    ---C - Aggregation with dead zooplankton
betaBr_pdzo=(physic_Br)*(((size_phy+size_dzo)**2)/(size_phy*size_dzo))
 q_pdzo=(min(size_phy,size_dzo))/(max(size_phy,size_dzo))
betaSh_pdzo=9.8*((q_pdzo**2)/(1+2*q_pdzo**2))*(sqrt(bio_eps/kinvis))*(size_phy+size_dzo)**3
 abs_pdzo= ABS(w_p_m-w_dzo_m)  
betaDs_pdzo=(1/2)*pi*(min(size_phy,size_dzo)**2)*abs_pdzo

    kernel_coef_pdzo=betaBr_pdzo+betaSh_pdzo+betaDs_pdzo
    coli_pdzo=sti_pdzo(ci)*kernel_coef_pdzo*cc(p,ci)*cc(d2,ci)
    agg_pdzo=min((txloss_p*pprime),coli_pdzo)

!!    ---D - Aggregation with Fecal pellets
betaBr_pfp=(physic_Br)*(((size_phy+size_fp)**2)/(size_phy*size_fp))
 q_pfp=(min(size_phy,size_fp))/(max(size_phy,size_fp))
betaSh_pfp=9.8*((q_pfp**2)/(1+2*q_pfp**2))*(sqrt(eps(ci)/kinvis))*(size_phy+size_fp)**3
 abs_pfp= ABS(w_p_m-w_fp_m)  
betaDs_pfp=(1/2)*pi*(min(size_phy,size_fp)**2)*abs_pfp
    
    kernel_coef_pfp=betaBr_pfp+betaSh_pfp+betaDs_pfp
    coli_pfp=sti_pfp(ci)*kernel_coef_pfp*cc(p,ci)*cc(d3,ci)
    agg_pfp=min((txloss_p*pprime),coli_pfp)

!*********
!!    ---Loss of p to msn
dd(p,d4,ci)= (agg_pp)+(agg_pdph)+(agg_pdzo)+(agg_pfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 2 : Dead Phytoplankton loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------

!!    ---A - Aggregation with itself       
betaBr_dphdph=(physic_Br)*(((size_dph+size_dph)**2)/(size_dph*size_dph))
   q_dphdph=(min(size_dph,size_dph))/(max(size_dph,size_dph))
betaSh_dphdph=9.8*((q_dphdph**2)/(1+2*q_dphdph**2))*(sqrt(bio_eps/kinvis))*(size_dph+size_dph)**3
!No BDs 

    kernel_coef_dphdph=betaBr_dphdph+betaSh_dphdph
     coli_dphdph=sti_2dph(ci)*kernel_coef_dphdph*cc(d1,ci)*cc(d1,ci)
     agg_dphdph=min((txloss_dph*d1rime),coli_dphdph)

!!    ---B - Aggregation with dead zooplankton           
betaBr_dphdzo=(physic_Br)*(((size_dph+size_dzo)**2)/(size_dph*size_dzo))
   q_dphdzo=(min(size_dph,size_dzo))/(max(size_dph,size_dzo))
betaSh_dphdzo=9.8*((q_dphdzo**2)/(1+2*q_dphdzo**2))*(sqrt(bio_eps/kinvis))*(size_dph+size_dzo)**3
 abs_dphdzo= ABS(w_dph_m-w_dzo_m) 
betaDs_dphdzo=(1/2)*pi*(min(size_dph,size_dzo)**2)*abs_dphdzo

    kernel_coef_dphdzo=betaBr_dphdzo+betaSh_dphdzo+betaDs_dphdzo
     coli_dphdzo=sti_dphdzo(ci)*kernel_coef_dphdzo*cc(d1,ci)*cc(d2,ci)
     agg_dphdzo=min((txloss_dph*d1rime),coli_dphdzo)

!!    ---C - Aggregation with fecal pellets         
betaBr_dphfp=(physic_Br)*(((size_dph+size_fp)**2)/(size_dph*size_fp))
   q_dphfp=(min(size_dph,size_fp))/(max(size_dph,size_fp))
betaSh_dphfp=9.8*((q_dphfp**2)/(1+2*q_dphfp**2))*(sqrt(bio_eps/kinvis))*(size_dph+size_fp)**3
 abs_dphfp= ABS(w_dph_m-w_fp_m) 
betaDs_dphfp=(1/2)*pi*(min(size_dph,size_fp)**2)*abs_dphfp

     kernel_coef_dphfp=betaBr_dphfp+betaSh_dphfp+betaDs_dphfp
     coli_dphfp=sti_dphfp(ci)*kernel_coef_dphfp*cc(d1,ci)*cc(d3,ci)
     agg_dphfp=min((txloss_dph*d1rime),coli_dphfp)

!*********
!!    ---Loss of d1 or dph to msn
dd(d1,d4,ci)= (agg_pdph)+(agg_dphdph)+(agg_dphdzo)+(agg_dphfp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 3 : Dead zoo loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------

!!    ---A - Aggregation with itself          
betaBr_dzodzo=(physic_Br)*(((size_dzo+size_dzo)**2)/(size_dzo*size_dzo))
   q_dzodzo=(min(size_dzo,size_dzo))/(max(size_dzo,size_dzo))
betaSh_dzodzo=9.8*((q_dzodzo**2)/(1+2*q_dzodzo**2))*(sqrt(bio_eps/kinvis))*(size_dzo+size_dzo)**3
! No BDs

    kernel_coef_dzodzo=betaBr_dzodzo+betaSh_dzodzo
    coli_dzodzo=sti_2dzo(ci)*kernel_coef_dzodzo*cc(d2,ci)*cc(d2,ci)
    agg_dzodzo=min((txloss_dzo*d2rime),coli_dzodzo)

!!    ---B - Aggregation with fecal pellets
betaBr_dzofp=(physic_Br)*(((size_dzo+size_fp)**2)/(size_dzo*size_fp))
   q_dzofp=(min(size_dzo,size_fp))/(max(size_dzo,size_fp))
betaSh_dzofp=9.8*((q_dzofp**2)/(1+2*q_dzofp**2))*(sqrt(bio_eps/kinvis))*(size_dzo+size_fp)**3
 abs_dzofp= ABS(w_dzo_m-w_fp_m) 
betaDs_dzofp=(1/2)*pi*(min(size_dzo,size_fp)**2)*abs_dzofp

    kernel_coef_dzofp=betaBr_dzofp+betaSh_dzofp+betaDs_dzofp
    coli_dzofp=sti_dzofp(ci)*kernel_coef_dzofp*cc(d2,ci)*cc(d3,ci)
    agg_dzofp=min((txloss_dzo*d2rime),coli_dzofp) 

!*********
!!    ---Loss of D2 or dzo to msn
dd(d2,d4,ci)= (agg_pdzo)+(agg_dphdzo)+(agg_dzodzo)+(agg_dzofp)
!*********

!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
!Case 4 : Fecal pellets loss by aggregation
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------

!!    ---A - Aggregation with itself             
betaBr_fpfp=(physic_Br)*(((size_fp+size_fp)**2)/(size_fp*size_fp))
   q_fpfp=(min(size_fp,size_fp))/(max(size_fp,size_fp))
betaSh_fpfp=9.8*((q_fpfp**2)/(1+2*q_fpfp**2))*(sqrt(bio_eps/kinvis))*(size_fp+size_fp)**3
!No BDs

    kernel_coef_fpfp=betaBr_fpfp+betaSh_fpfp
    coli_fpfp=sti_2fp(ci)*kernel_coef_fpfp*cc(d3,ci)*cc(d3,ci)
    agg_fpfp=min((txloss_fp*d3rime),coli_fpfp)

!*********
!!    ---Loss of D3 or fp to msn
dd(d3,d4,ci)= (agg_pfp)+(agg_dphfp)+(agg_dzofp)+(agg_fpfp)
!*********
endif !#2

!!    ---No aggregation due to [LDON] in the environment
else  ! #1  (if cc(l,ci « lmin))

!LEVEL1 'LDON Concentration smaller than lmin'

  dd(p,d4,ci) = 0.0
  dd(d1,d4,ci)= 0.0
  dd(d2,d4,ci)= 0.0
  dd(d3,d4,ci)= 0.0
endif !#1

!-----------------------------------------------------------------------------------
!             SIZE Marine Snow with aggregation
!-----------------------------------------------------------------------------------

              ! ---Maximum size at dissagregation 
                if(dm_msn .eq. 1.0) then  !--» Comparaison with CFL limit           
                diam_msn_max = ((CFL/0.93)**2)*(1/(g*(Rmsn/densFlu)))
                else !--» From the nml
                diam_msn_max = diam_msn_us ! [m] 
                         if (diam_msn_us .gt. ((CFL/0.93)**2)*(1/(g*(Rmsn/densFlu))) ) then
                         write(*,*)'The Max. Diam mentionned in the nml do not allow to respect CFL limit',ci
                          stop
                          endif
                endif

            ! ---Flux from particules to msn [mmol/m3/s]
                Flux_P(ci)  = (agg_pp)+(agg_pdph)+(agg_pdzo)+(agg_pfp)
                Flux_D1(ci) = (agg_pdph)+(agg_dphdph)+(agg_dphdzo)+(agg_dphfp)
                Flux_D2(ci) =  (agg_pdzo)+(agg_dphdzo)+(agg_dzodzo)+(agg_dzofp)
                Flux_D3(ci) =  (agg_pfp)+(agg_dphfp)+(agg_dzofp)+(agg_fpfp)

            ! ---Maximum Flux of Particles to msn [mmol/m3/s]
                max_flux= max(Flux_P(ci),Flux_D1(ci),Flux_D2(ci),Flux_D3(ci))

            ! ---Total Flux received by msn [mmol/m3/s]
                flux_msn(ci) = Flux_P(ci)+Flux_D1(ci)+Flux_D2(ci)+Flux_D3(ci) 

        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------

             ! ---Sum of ratio should equal 1
                if(Flux_P(ci)+Flux_D1(ci)+Flux_D2(ci)+Flux_D3(ci).gt. 1.0) then
                  write(*,*)'At depth-----',ci
                  write(*,*)'Warning: sum of Ratio > 1.0', Flux_P(ci)+Flux_D1(ci)+Flux_D2(ci)+Flux_D3(ci)
                endif

                if (flux_msn(ci) .ne. Flux_P(ci)+Flux_D1(ci)+Flux_D2(ci)+Flux_D3(ci)) then
                 write(*,*)'Warning :msn incomming flux .ne. to the sum of particles flux at depth ',ci
                endif

             ! ---Flux out from D1, d2, d3, or P can't be superior to the concentration of D1,D2,D3 and P
       !         if(Flux_P(ci) .gt. cc(p,ci) .Or. Flux_D1(ci) .gt. cc(d1,ci) &
       !             .or. Flux_D2(ci) .gt. cc(d2,ci) .or. Flux_D3(ci) .gt. cc(d3,ci)) then
       !         99 FATAL 'Coagulation rate overpass [Variables]'
       !            stop 'do_bio'
       !         endif

             ! ---Size modification due to Coagulation
if (Coag_coef .eq. 1.0) then  ! #1   Size modified only if coagulation happenned

             ! ---Initialize the size radius augmentation variable for the msn and the size for the coagulation
                cc(size_coag,ci)  = 0.0
                cc(size_intrm,ci) = 0.0
 
        !-----------------------------------------------------------------------------------
        !----------Definition of the size diameter augmentation of msn (m)
        !
        !Calculation of the cubic racin of X --» SIGN(ABS(X)**(1./3.),X) [FORTRAN, le langage normalisé, Michel Dubesset,Jean Vignes]
        !-----------------------------------------------------------------------------------

             ! ---Depends on what composed it
                cc(size_coag,ci)= Flux_P(ci)*diam_phy+Flux_D1(ci)*diam_dph+Flux_D2(ci)*diam_dzo+Flux_D3(ci)*diam_fp ![m/s] 

        ! ---Definition of the diameter size of marine snow
        !-----------------------------------------------------------------------------------
             !At this stage 'size_coag' is still the radius and diam_msn the equivalent spherical diameter
             !We defined L,I,S for Marine snow L=I=size_x*4 and S= size_X*2 
             !--» With size_X which represents the radius (cc(size_coag,ci)) of our marine snow.
        !-----------------------------------------------------------------------------------
                 if (cc(size_coag,ci) .ne. 0.0 .and. cc(size_coag,ci).gt. 0.0) then !#2
                       diam_msn  = sign(abs(((cc(size_coag,ci)*4.)*(cc(size_coag,ci)*4.)*(cc(size_coag,ci)*2.)))**(1./3.),&
                                   ((cc(size_coag,ci)*4.)*(cc(size_coag,ci)*4.)*(cc(size_coag,ci)*2.))) ![m/s]
                 else !#2
                       diam_msn = 0.0
                 endif !#2

             ! ---The projected area equivalent diameter of our particles of marine snow 
             cc(size_coag,ci) = (diam_msn**(CSF))*(dt_bio/splitfac_bio) ![m]

             !--» At this points 'size_coag' is the projected area equivalent diameter in m.

             ! ---Elaboration of the size variable (diameter), available for the fragmentation eventually (size_intrm).
                if(cc(d4,ci) .gt. cons_min) then
                 cc(size_intrm,ci) = cc(size_coag,ci) + cc(size_msn,ci) ![m]
             !--» Msn size after coagulation will depend on the increase of size due to coagaluation (size_coag) &
             !--» + the size at the previous time step (size_msn) of the particles

        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------
                      if(cc(size_intrm,ci).lt. 0.0 .OR. &
                        cc(size_coag,ci) .lt. 0.0 .OR. &
                        cc(size_msn,ci) .lt. 0.0) then
                         write(*,*)'Size _intrm - May be equal to 0 :', cc(size_intrm,ci)
                         write(*,*)'Size _coag - May be equal to 0 :', cc(size_coag,ci)
                         write(*,*)'Size _msn - May be equal to 0 :', cc(size_msn,ci)
                     endif

               else
             !--» If there is not need to have a size augmentation due to low concentration of marine snow, the size of previous step remains
                  cc(size_intrm,ci) = cc(size_msn,ci) ![m]
             !   write(*,*)'No size augmentation as [msn] < cons_min - The size stays the same', cc(size_msn,ci)
                endif

else !#1  Size not modified because no coagulation happenned
 cc(size_coag,ci) = 0.0
 cc(size_intrm,ci) = cc(size_msn,ci) ![m]
 write(*,*)'Size not modified because no coagulation happenned'

endif !#1
 
        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------
             !--» Msn size can not over pass the maximum diameter specified by the user.               
                   if(cc(size_intrm,ci).gt.diam_msn_max) then
                      cc(size_intrm,ci) = diam_msn_max
                      write(*,*)'Maximum size reach - Marine snow size equal :', cc(size_intrm,ci)
                  endif

             !--» If there is no marine snow, there is no reason to set up a size, then the size will equal 0.
     !              if (cc(d4,ci).lt.cons_min)then
     !                cc(size_msn,ci) = _ZERO_
     !                cc(size_intrm,ci) = _ZERO_
             !        write(*,*)'Size but no msn at :',ci
      !            endif
!-----------------------------------------------------------------------------------
!              FRAGMENTATION
!               -----------
!!    ---Biological Fragmentation - Size reduction = Modification of particle type
!           -- Leackage in dissolved organic matter 
!           -- Bacterial remineralization 
!        Only in the euphotic zone where zooplankton are, following vertical migration:
!           -- Grazing (see before dd(d4,z,ci) = beta*gmax*r6*cc(d4,ci)**2*fac)).
!           -- By swimming zooplankton.
!!    ---Physical Fragmentation  [Alldredge 1990]
!-----------------------------------------------------------------------------------

if (Frag_meth .eq. 1.0) then !Fragmentation happens  

             ! ---Kolmogorov microscale of turbulence ! Alldredge 1990
                  kolmog = (kinvis**3/eps(ci))**0.25 ![m]
             ! ---Minimum size of what composed the marine snow - Be careful to be sure that their is this particles in the field
                  if (max_flux .eq. flux_P(ci)) then
                     min_size_msn = Ratio_P*diam_phy 
                  elseif (max_flux .eq. flux_D1(ci)) then
                     min_size_msn = Ratio_D1*diam_dph 
                  elseif (max_flux .eq. flux_D2(ci)) then
                     min_size_msn = Ratio_D2*diam_dzo 
                  elseif (max_flux .eq. flux_D3(ci)) then
                     min_size_msn = Ratio_D3* diam_fp 
                  else
                     write(*,*)'Error for estimation of min_size_msn'
                  endif

        !-----------------------------------------------------------------------------------
        !!    ---Biological Fragmentation rate
        !-----------------------------------------------------------------------------------
             !         -- Leackage in dissolved organic matter  -[mmolN/m3/s]
                  dd(d4,l,ci) = leak*cc(d4,ci) 
                  leackage = dd(d4,l,ci)
             !           -- Bacterial remineralization [Ploug 1999 - Ploug 2000 - Kiorboe 2001]-[mmolN/m3/s]
                  dd(d4,b,ci)=remi*cc(d4,ci)*cc(b,ci)
                  ! dd(d4,b,ci) = (0.61*cc(size_msn,ci)**(-1.50))  
                  ! Do not work Yet :Ploug 1999 for remineralisation following size increase of msn 
                  remineralization = dd(d4,b,ci)
             !           -- By swimming zooplankton ! Goldwaith 2005  [mmolN/m3/s] 
                  Frag_bio=(swim_brk*cc(z,ci)*cc(d4,ci))
 
        !-----------------------------------------------------------------------------------
        !!    ---Physical Fragmentation rate
        !-----------------------------------------------------------------------------------
             !--» We decide if we have energy dissipation rates able to fragment our msn (Alldredge 1990)

                  if (cc(size_intrm,ci) .ge. diam_msn_max .OR. eps(ci) .ge. 0.0001 ) then
             ! ---Value for the stable_size parameter(depending on the diameter)
                                    if (cc(size_intrm,ci) .gt. kolmog) then 
                                       stable_size = 1
                                    else
                                      stable_size = 0.5
                                    endif
                     Frag_phys = Floc_coef*(sqrt(eps(ci)/kinvis)**(stable_size))*cc(d4,ci) ![Spicer et al. 1996]
                     write(*,*)'Physical fragmentation happens'
                  else
                     Frag_phys= 0.0
                !     write(*,*)'No Physical fragmentation'
                  end if

        !-----------------------------------------------------------------------------------
        !!    ---FLUXES : ---Calculation of the flux of msn that will return 
        !!    ---when fragmentation happen to the "initial boxes" : dph, dzo, fp 
        !-----------------------------------------------------------------------------------
             !--» The return can happen only if the fragmentation rate is different of 0 otherwise &
             !--» NaN values will be attributed to the dd(d4,x,ci) flux.

                  if (Frag_phys+Frag_bio+leackage+remineralization .gt. flux_msn(ci) .OR. &
                      cc(size_intrm,ci) .ge. diam_msn_max .OR. eps(ci) .ge. 0.0001 ) then
                     dd(d4,d1,ci)=  Frag_phys+Frag_bio+leackage+remineralization 
                     dd(d4,d2,ci)=  Frag_phys+Frag_bio+leackage+remineralization
                     dd(d4,d3,ci)=  Frag_phys+Frag_bio+leackage+remineralization
                     write(*,*) 'Return from msn to initial boxes due to :'
                         if(Frag_phys+Frag_bio+leackage+remineralization .gt. flux_msn(ci)) then
                            write(*,*) 'Frag_phys+Frag_bio+leackage+remineralization > Flux to msn'
                         endif
                         if(cc(size_intrm,ci) .gt. diam_msn_max) then
                            write(*,*) 'cc(size_intrm,ci) > diam_msn_max'
                         endif
                         if(eps(ci) .ge. 0.0001) then
                            write(*,*) 'eps(ci) >= 0.0001'
                         endif
                  else
                     write(*,*) 'Loss by fragmentation equal or lower than 0'
                     dd(d4,d1,ci)= 0.0
                     dd(d4,d2,ci)= 0.0
                     dd(d4,d3,ci)= 0.0
                  endif

        !-----------------------------------------------------------------------------------
        !!    ---SIZE : ---Elaboration of the size variable, available for the next timestep (the radius will be modified)
        !-----------------------------------------------------------------------------------
                  if (Frag_phys+Frag_bio+leackage+remineralization .gt. flux_msn(ci) .OR.&
                     cc(size_intrm,ci) .ge. diam_msn_max .OR. eps(ci) .ge. 0.0001 ) then 

             !--» Choice for the Size reduction scheme
              
                                   if (Daugther_part.eq. 1.0) then ! Utilisation of probability of break fragment
                                      call random_number(r_msn)
                                      prob_break_msn=r_msn
                                             if (r_msn .lt. 0.7) then ! (70% chance --» in 2 parts) (Alldredge 1990 - Dilling 2000)
                                                 size_msn_m = cc(size_intrm,ci)/2
                                             elseif (r_msn .lt. 0.15) then ! (15% chance --» in 3 parts)
                                                 size_msn_m = cc(size_intrm,ci)/3
                                             elseif (r_msn .lt. 0.115) then ! (11.5% chance --» in 10 parts)
                                                 size_msn_m = cc(size_intrm,ci)/10
                                             else
                                                 size_msn_m = cc(size_intrm,ci)
                                             endif
                                    else
                                      size_msn_m = cc(size_intrm,ci)/3 !Average of (7*2 (70%), 2*3 (20%), 1*10 (11.5%))
                                    endif 

        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------

             !--» If there is no marine snow, there is no reason to set up a size, then the size will equal 0.
                                                      if (cc(d4,ci).lt. cons_min)then
                                                         write(*,*)'Size but no msn'
                                                         size_msn_m = 0.0
                                                      endif

        !-----------------------------------------------------------------------------------
        !!    ---New values of size if fragmentation occurs
        !-----------------------------------------------------------------------------------
                    cc(size_frag,ci) = size_msn_m ! Keep in memory for the next step
                    cc(size_msn,ci) = cc(size_frag,ci) 

                  else  ! no size modification
                    write(*,*)'No size modification due to fragmentation'
                    cc(size_frag,ci) = 0.0
                    cc(size_msn,ci) = cc(size_intrm,ci)
                  endif 

elseif (Frag_meth .eq. 0.0) then   !No Fragmentation
        !-----------------------------------------------------------------------------------
        !!    --- FLUXES
        !-----------------------------------------------------------------------------------
                  dd(d4,l,ci)= 0.0
                  dd(d4,b,ci)= 0.0
                  dd(d4,d1,ci)= 0.0
                  dd(d4,d2,ci)= 0.0
                  dd(d4,d3,ci)= 0.0
        !-----------------------------------------------------------------------------------
        !!    --- SIZE - no size modification
        !-----------------------------------------------------------------------------------
                  !  write(*,*)'No size modification due to fragmentation'
                    cc(size_frag,ci) = 0.0
                    cc(size_msn,ci)= cc(size_intrm,ci)
else 
                  write(*,*)'Wrong specification for fragmentation'
endif


!-------------------------------------------------------------------------------------
!   SEDIMENTATION rate msn
!     We want to use a calculated settling velocity for the msn
!     Settling velocity send to the advection scheme as well as the size of the msn
!-------------------------------------------------------------------------------------

!--» cc(size_msn,ci) --> is the diameter after coag and frag 


if (cc(d4,ci) .le. cons_min) then
      w_msn_m = 0.0
     write(*,*)'[msn] lt Cons_min, settling velocity set to :',w_msn_m

  !--» We set here the concentration limit in the water column from free settling of marine snow vs flocculation settling (Metha 1989)
elseif (cc(d4,ci) .lt. cons_max) then   !#1 
  !   if (cc(d4,ci) .lt. cons_max) then   !#1    
        !!    --- Calculated by value from the .nml
                  if (w_msnow .eq. 0.0 ) then !#2
                    w_msn_m  = w_msn ![m/s]

        !!    --- Stokes's law from Ghosh et al 2013
            !--» msn is considered as a sphere                    
                  else if (w_msnow .eq. 1.0) then !#2
                    w_msn_m= (g*((cc(size_msn,ci))**2)*Rmsn)/(18*dynvis) ![m/s]

        !!    --- Modified Stoke's law 
            !--» considered as cylindrical and will follow a specific Stoke's law [w=((0.079*(r_X-r_F)*L^2*g)/dynvis)*(L/D)^-1.664].
                  else if (w_msnow .eq. 2.0) then !#2
                    w_msn_m= (0.079*Rmsn*(cc(size_msn,ci)+(1./2.))*g)/dynvis*((cc(size_msn,ci)+(1./2.))/&
                             (cc(size_msn,ci)))**(-1.664)  ![m/s]

        !!    --- Power law evolution from Alldredge and Gotschalk, 1988 based on Kajihara 1971 and from Komar 1981
            !--» Calculation of the settling velocity (m/j)/secs_pr_day = m/s - utilisation here of the diameters 
                  else if (w_msnow .eq. 3.0) then!#2

                                    if (cc(size_msn,ci).gt. 0.001) then  !#2.1
                                       w_msn_m =-(50*((cc(size_msn,ci))**0.26))/secs_pr_day ![m/s]
                                    else if (cc(size_msn,ci) .lt. 0.001 .and. cc(size_msn,ci) .gt. 0.0) then !#2.1
                                       w_msn_m =-(160*((cc(size_msn,ci))**0.57))/secs_pr_day ![m/s]
                                    else !#2.1
                                       w_msn_m = 0.0
                                    endif !#2.1
        !!    --- Stokes law for high reynolds number + Corey Shape Factor [Komar 1978]
                  else if (w_msnow  .eq. 4.0) then !#2

                                    if(CSF .ge. 0.0 .and. CSF.lt. 0.4) then !#2.3
                                              CSF_msn_calc = 2.18-(2.09*CSF)
                                    else if (CSF .ge. 0.4 .and. CSF .lt. 0.8) then!#2.3
                                              CSF_msn_calc = 0.946*(CSF)**(-0.378)
                                    else if (CSF .ge. 0.8 .and. CSF .le. 1.0) then!#2.3
                                              CSF_msn_calc = 1.0 ! consider as a sphere
                                     else !#2.3
                                             write (*,*) 'Error in CSF values for Marine snow : CSF .NE. [0-1]'
                                    endif !#2.3

                    w_msn_m=(1/(18*(kinvis*densFlu)))*(1/CSF_msn_calc)*(Rmsn)*g*(cc(size_msn,ci))**2 ![m/s]

 
        !!    ---[Komar 1978] and VanRijn 1993
                elseif (w_msnow .eq. 5.0) then !#2! 

 ! If the diameter of Msn (d) -->  d <= 100 micrometers (Komar 1978)
                   if(cc(size_msn,ci) .le. 0.0001 )then                            
                                   if(CSF .ge. 0.0 .and. CSF.lt. 0.4) then !#2.3
                                             CSF_msn_calc = 2.18-(2.09*CSF)
                                    else if (CSF .ge. 0.4 .and. CSF .lt. 0.8) then!#2.3
                                              CSF_msn_calc = 0.946*(CSF)**(-0.378)
                                    else if (CSF .ge. 0.8 .and. CSF .le. 1.0) then!#2.3
                                              CSF_msn_calc = 1.0 ! consider as a sphere
                                     else !#2.3
                                             write (*,*) 'Error in CSF values for Marine snow : CSF .NE. [0-1]'
                                    endif !#2.3
             w_msn_m=(1/(18*(kinvis*densFlu)))*(1/CSF_msn_calc)*(Rmsn/densFlu)*g*(cc(size_msn,ci))**2 ![m/s]
             write(*,*) 'Diameter of msn :  d <= 100 micrometers, settling (Stokes Law is used !) =' ,w_msn_m 

! If the diameter of Msn (d) -->  100< d <= 1000 micrometers (VanRijn 1993)
                 elseif(cc(size_msn,ci) .gt. 0.0001 .and. cc(size_msn,ci) .lt. 0.001 ) then                         
             w_msn_m= ((10.0*kinvis)/cc(size_msn,ci))*(((1+((0.01*(Rmsn/densFlu)*g*(cc(size_msn,ci)**3.0))/(kinvis**2.0)))**0.5)-1) ![m/s]
             write(*,*) 'Diameter of msn :  100< d <= 1000 micrometers, settling =' ,w_msn_m                 

                 elseif( cc(size_msn,ci) .ge. 0.001 ) then 
              w_msn_m = (0.93*sqrt(Rmsn*g*cc(size_msn,ci)/densFlu)) ![m/s]
              write(*,*) 'Diameter of msn : d > 1000 micrometers, settling =' ,w_msn_m 
                 else                
                write(*,*) ' No size mentioned for Msn',cc(size_msn,ci)
                stop
                endif

                 else !#2! 
!if (w_msnow .ne. 0.0 .and. w_msnow .ne. 1.0 .and. w_msnow .ne. 2.0 .and. w_msnow .ne. 3.0 .and. w_msnow .ne. 4.0 .and.w_msnow .ne. 5.0 .and. w_msnow .ne. 6.0   ) then
                    write(*,*) 'No settling velocity choice for msn, value set to 0'
                    w_msn_m = 0.0
                  endif!#2

elseif (cc(d4,ci) .ge. cons_max)then !#1
     w_msn_m=-(coef3*cc(d4,ci)**(1.6))/secs_pr_day ![m/s] ! Metha 1989
     write(*,*)'[msn] > cons_max at :',ci

else !#1
  write(*,*)'At Depth : ',ci
  write(*,*)'Error with the specification of [msn] that equal : ',cc(d4,ci)
  w_msn_m = 0.0
 stop "Nan for cc(d4,ci)"  

endif !#1

        !-----------------------------------------------------------------------------------
        !!    --- Convertion & Comparaison with the Stokes range
        !-----------------------------------------------------------------------------------
!if (w_msnow .ne. 6.0) then
            !--» Comparaison with the Stokes range ! VanRijn 1993
!   Re_msn = abs(w_msn_m*(cc(size_msn,ci)/kinvis))
 
!   if (Re_msn .lt. 1.0)then !#3
    !   write(*,*) 'Reynolds number for marine snow allow to respect Stockes range < 1'
!  else !#3
!     write(*,*) 'Reynolds number for marine snow > 1'
!     w_msn_m = -(cc(size_msn,ci)**0.5/secs_pr_day) ![m/s]
!          if (w_msnow .eq. 1.0 .or. w_msnow .eq. 2.0 .or. w_msnow .eq. 3.0 )then
!          write(*,*) 'Reynolds number for marine snow > 1, another settling velocity scheme should be chose for msn'
!         endif
!  endif !#3
!endif

!-----------------------------------------------------------------------------------
!      ADVECTION (WS) OF THE PARTICLES
!-----------------------------------------------------------------------------------

        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------
            !--» Does density difference with the fluid allow to go up ?

            if (rho_p .gt. densFlu .AND. w_p_m .gt. 0.0) then
            w_p_m = -w_p_m
            endif

            if (rho_dph .gt. densFlu .AND. w_dph_m .gt. 0.0) then
            w_dph_m = -w_dph_m
            endif

            if (rho_dzo .gt. densFlu .AND. w_dzo_m .gt. 0.0) then
            w_dzo_m = -w_dzo_m
            endif

            if (rho_fp .gt. densFlu .AND. w_fp_m .gt. 0.0) then
            w_fp_m = -w_fp_m
            endif

            if (rho_msn .gt. densFlu .AND. w_msn_m .gt. 0.0) then
             write(*,*)' Msn density > dens_fluid  AND W_msn_m > 0 --> Settling go up, but is constrain to go down !'
            w_msn_m = -w_msn_m
            endif

            !--» let them settling(m/s)
            !--» The ncdf output(bio_save) do ws(x,ci) *86400 to have  the ouptut in m/j.

        !-----------------------------------------------------------------------------------
        !!    ---Safety check
        !-----------------------------------------------------------------------------------

!--» Does CFL limit respected ?

            !--» Case of Phytoplankton 
if (abs(w_p_m) .gt. (depth_bio/nlev)/dt_bio )then
 write(*,*) 'CFL Constrain is OVERPASS for W-Phy'
w_p_m = -((depth_bio/nlev)/dt_bio)
endif
ws(p,ci) = w_p_m

            !--» Case of Dead_Phytoplankton 
if (abs(w_dph_m) .gt. (depth_bio/nlev)/dt_bio )then
 write(*,*) 'CFL Constrain is OVERPASS for W-Dph'
w_dph_m = -((depth_bio/nlev)/dt_bio)
endif
ws(d1,ci) = w_dph_m

           !--» Case of Dead Zooplankton
if (abs(w_dzo_m) .gt. (depth_bio/nlev)/dt_bio )then
 write(*,*) 'CFL Constrain is OVERPASS for W-dzo'
w_dzo_m = -((depth_bio/nlev)/dt_bio)
endif
ws(d2,ci) = w_dzo_m

            !--» Case of Fecal pellets 
if (abs(w_fp_m) .gt. (depth_bio/nlev)/dt_bio )then
 write(*,*) 'CFL Constrain is OVERPASS for W-fp'
w_fp_m = -((depth_bio/nlev)/dt_bio)
endif
ws(d3,ci) = w_fp_m

            !--» Case of marine snow 
if (abs(w_msn_m) .gt. (depth_bio/nlev)/dt_bio )then
 write(*,*) 'CFL Constrain is OVERPASS for W-msn'
w_msn_m = -((depth_bio/nlev)/dt_bio)
endif
ws(d4,ci) = w_msn_m

!--Size of marine snow
ws(size_msn,ci) = ws(d4,ci)


!-----------------------------------------------------------------------------------
!      NET PRIMARY PRODUCTION
!-----------------------------------------------------------------------------------
 !orig ppnet(ci) =(dd(a,p,ci)+dd(n,p,ci)-dd(p,d,ci)-dd(p,z,ci)-dd(p,l,ci))*secs_pr_day
       ppnet(ci) =(dd(a,p,ci)+dd(n,p,ci)-dd(p,d1,ci)-dd(p,z,ci)-dd(p,l,ci)-dd(p,d4,ci))*secs_pr_day
!-----------------------------------------------------------------------



      do i=1,numc
         do j=1,numc
            pp(i,j,ci)=dd(j,i,ci)
         end do
      end do

  end do
!----- End of the loop ci

!-----------------------------------------------------------------------

   return
   end subroutine do_bio_polynow
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Finish the bio calculations
!
! !INTERFACE:
   subroutine end_bio_polynow
!
! !DESCRIPTION:
!  Nothing done yet --- supplied for completeness.
!
! !USES:
   IMPLICIT NONE
!
! !REVISION HISTORY:
!  Original author(s): Hans Burchard & Karsten Bolding
!
!EOP
!-----------------------------------------------------------------------
!BOC

   return
   end subroutine end_bio_polynow
!EOC

!-----------------------------------------------------------------------

   end module bio_polynow

!-----------------------------------------------------------------------
! Copyright by the GOTM-team under the GNU Public License - www.gnu.org
!-----------------------------------------------------------------------