1340
1341
1342
1343
1344 integer, intent(in) :: ng, model
1345
1346
1347
1348 logical, dimension((Ngrids-1)*2) :: Lcoincident
1349 logical, dimension((Ngrids-1)*2) :: Lcomposite
1350 logical, dimension((Ngrids-1)*2) :: Lmosaic
1351 logical, dimension((Ngrids-1)*2) :: Lrefinement
1352
1353 logical, dimension((Ngrids-1)*2) :: Linterpolate
1354
1355 integer :: cr, dg, ibry, ic, ig, ip, m, rg, vindex
1356 integer :: my_Ncontact, my_Ngrids, my_nLweights, my_nQweights
1357
1358 integer, dimension(Ngrids) :: my_Lm, my_Mm
1359 integer, dimension(Ngrids) :: refine_factor
1360
1361 integer, dimension((Ngrids-1)*2) :: NpointsR
1362 integer, dimension((Ngrids-1)*2) :: NpointsU
1363 integer, dimension((Ngrids-1)*2) :: NpointsV
1364
1365 real(r8), allocatable :: Lweight(:,:)
1366# ifdef QUADRATIC_WEIGHTS
1367 real(r8), allocatable :: Qweight(:,:)
1368# endif
1369 real(r8), allocatable :: Xrg(:), Yrg(:)
1370 real(r8), allocatable :: angle(:)
1371 real(r8), allocatable :: dmde(:), dndx(:)
1372 real(r8), allocatable :: f(:)
1373 real(r8), allocatable :: h(:)
1374 real(r8), allocatable :: mask(:)
1375 real(r8), allocatable :: pm(:), pn(:)
1376
1377 character (len=*), parameter :: MyFile = &
1378 & __FILE__//", set_contact_pio"
1379
1380 TYPE (file_desc_t) :: NGCpioFile
1381
1382 sourcefile=myfile
1383
1384
1385
1386
1387
1388
1389
1390
1391 CALL pio_netcdf_open (ng, model, ngcname, 0, ngcpiofile)
1392 IF (founderror(exit_flag, noerror, __line__, myfile)) THEN
1393 WRITE (stdout,20) trim(ngcname)
1394 20 FORMAT (/,' SET_CONTACT_PIO - unable to open contact points ', &
1395 & ' NetCDF file: ',a)
1396 RETURN
1397 END IF
1398
1399
1400
1401 CALL pio_netcdf_inq_var (ng, model, ngcname, &
1402 & piofile = ngcpiofile)
1403 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1404
1405
1406
1407 CALL pio_netcdf_get_dim (ng, model, ngcname, &
1408 & piofile = ngcpiofile, &
1409 & dimname = 'Ngrids', &
1410 & dimsize = my_ngrids)
1411 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1412
1413 IF (my_ngrids.ne.ngrids) THEN
1414 IF (master) THEN
1415 WRITE (stdout,10) 'inconsistent parameter, Ngrids = ', &
1416 & ngrids, my_ngrids
1417 10 FORMAT (/,' SET_CONTACT_PIO - ', a, i4, 2x, i4, &
1418 & /,19x,'in input file:'2x,a)
1419 END IF
1420 exit_flag=5
1421 RETURN
1422 END IF
1423
1424
1425
1426 CALL pio_netcdf_get_dim (ng, model, ngcname, &
1427 & piofile = ngcpiofile, &
1428 & dimname = 'Ncontact', &
1429 & dimsize = my_ncontact)
1430 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1431
1432 IF (my_ncontact.ne.(ngrids-1)*2) THEN
1433 IF (master) THEN
1434 WRITE (stdout,10) 'inconsistent parameter, Ncontact = ', &
1435 & (ngrids-1)*2, my_ncontact
1436 END IF
1437 exit_flag=5
1438 RETURN
1439 END IF
1440 ncontact=(ngrids-1)*2
1441
1442
1443
1444 CALL pio_netcdf_get_dim (ng, model, ngcname, &
1445 & piofile = ngcpiofile, &
1446 & dimname = 'nLweights', &
1447 & dimsize = my_nlweights)
1448 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1449
1450 IF (my_nlweights.ne.4) THEN
1451 IF (master) THEN
1452 WRITE (stdout,10) 'inconsistent parameter, nLweights = ', &
1453 & 4, my_nlweights
1454 END IF
1455 exit_flag=5
1456 RETURN
1457 END IF
1458
1459# ifdef QUADRATIC_WEIGHTS
1460
1461
1462
1463 CALL pio_netcdf_get_dim (ng, model, ngcname, &
1464 & piofile = ngcpiofile, &
1465 & dimname = 'nQweights', &
1466 & dimsize = my_nqweights)
1467 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1468
1469 IF (my_nqweights.ne.9) THEN
1470 IF (master) THEN
1471 WRITE (stdout,10) 'inconsistent parameter, nQweights = ', &
1472 & 9, my_nqweights
1473 END IF
1474 exit_flag=5
1475 RETURN
1476 END IF
1477# endif
1478
1479
1480
1481
1482 CALL pio_netcdf_get_dim (ng, model, ngcname, &
1483 & piofile = ngcpiofile, &
1484 & dimname = 'datum', &
1485 & dimsize = ncdatum)
1486 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1487
1488
1489
1490
1491 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1492 & 'Lm', my_lm, &
1493 & piofile = ngcpiofile)
1494 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1495
1496 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1497 & 'Mm', my_mm, &
1498 & piofile = ngcpiofile)
1499 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1500
1501 DO ig=1,ngrids
1502 IF (my_lm(ig).ne.lm(ig)) THEN
1503 IF (master) THEN
1504 WRITE (stdout,10) 'inconsistent grid order, Lm = ', &
1505 & lm(ig), my_lm(ig)
1506 END IF
1507 exit_flag=5
1508 RETURN
1509 END IF
1510 IF (my_mm(ig).ne.mm(ig)) THEN
1511 IF (master) THEN
1512 WRITE (stdout,10) 'inconsistent grid order, Mm = ', &
1513 & mm(ig), my_mm(ig)
1514 END IF
1515 exit_flag=5
1516 RETURN
1517 END IF
1518 END DO
1519
1520
1521
1522 CALL pio_netcdf_get_lvar (ng, model, ngcname, &
1523 & 'coincident', lcoincident, &
1524 & piofile = ngcpiofile)
1525 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1526
1527 CALL pio_netcdf_get_lvar (ng, model, ngcname, &
1528 & 'composite', lcomposite, &
1529 & piofile = ngcpiofile)
1530 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1531
1532 CALL pio_netcdf_get_lvar (ng, model, ngcname, &
1533 & 'mosaic', lmosaic, &
1534 & piofile = ngcpiofile)
1535 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1536
1537 CALL pio_netcdf_get_lvar (ng, model, ngcname, &
1538 & 'refinement', lrefinement, &
1539 & piofile = ngcpiofile)
1540 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1541
1542
1543
1544 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1545 & 'refine_factor', refine_factor, &
1546 & piofile = ngcpiofile)
1547 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1548
1549
1550
1551 CALL pio_netcdf_get_lvar (ng, model, ngcname, &
1552 & 'interpolate', linterpolate, &
1553 & piofile = ngcpiofile)
1554 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1555
1556
1557
1558 IF (.not.allocated(donor_grid)) THEN
1559 allocate ( donor_grid((ngrids-1)*2) )
1560 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1561 END IF
1562 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1563 & 'donor_grid', donor_grid, &
1564 & piofile = ngcpiofile)
1565 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1566
1567 IF (.not.allocated(receiver_grid)) THEN
1568 allocate ( receiver_grid((ngrids-1)*2) )
1569 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1570 END IF
1571 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1572 & 'receiver_grid', receiver_grid, &
1573 & piofile = ngcpiofile)
1574 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1575
1576
1577
1578
1579 IF (.not.allocated(i_left)) THEN
1580 allocate ( i_left(ngrids) )
1581 dmem(ng)=dmem(ng)+real(ngrids,r8)
1582 END IF
1583 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1584 & 'I_left', i_left, &
1585 & piofile = ngcpiofile)
1586 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1587
1588 IF (.not.allocated(i_right)) THEN
1589 allocate ( i_right(ngrids) )
1590 dmem(ng)=dmem(ng)+real(ngrids,r8)
1591 END IF
1592 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1593 & 'I_right', i_right, &
1594 & piofile = ngcpiofile)
1595 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1596
1597 IF (.not.allocated(j_bottom)) THEN
1598 allocate ( j_bottom(ngrids) )
1599 dmem(ng)=dmem(ng)+real(ngrids,r8)
1600 END IF
1601 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1602 & 'J_bottom', j_bottom, &
1603 & piofile = ngcpiofile)
1604 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1605
1606 IF (.not.allocated(j_top)) THEN
1607 allocate ( j_top(ngrids) )
1608 dmem(ng)=dmem(ng)+real(ngrids,r8)
1609 END IF
1610 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1611 & 'J_top', j_top, &
1612 & piofile = ngcpiofile)
1613 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1614
1615
1616
1617
1618 IF (.not.allocated(nstrr)) THEN
1619 allocate ( nstrr((ngrids-1)*2) )
1620 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1621 END IF
1622 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1623 & 'NstrR', nstrr, &
1624 & piofile = ngcpiofile)
1625 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1626
1627 IF (.not.allocated(nendr)) THEN
1628 allocate ( nendr((ngrids-1)*2) )
1629 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1630 END IF
1631 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1632 & 'NendR', nendr, &
1633 & piofile = ngcpiofile)
1634 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1635
1636 IF (.not.allocated(nstru)) THEN
1637 allocate ( nstru((ngrids-1)*2) )
1638 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1639 END IF
1640 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1641 & 'NstrU', nstru, &
1642 & piofile = ngcpiofile)
1643 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1644
1645 IF (.not.allocated(nendu)) THEN
1646 allocate ( nendu((ngrids-1)*2) )
1647 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1648 END IF
1649 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1650 & 'NendU', nendu, &
1651 & piofile = ngcpiofile)
1652 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1653
1654 IF (.not.allocated(nstrv)) THEN
1655 allocate ( nstrv((ngrids-1)*2) )
1656 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1657 END IF
1658 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1659 & 'NstrV', nstrv, &
1660 & piofile = ngcpiofile)
1661 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1662
1663 IF (.not.allocated(nendv)) THEN
1664 allocate ( nendv((ngrids-1)*2) )
1665 dmem(ng)=dmem(ng)+real((ngrids-1)*2,r8)
1666 END IF
1667 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1668 & 'NendV', nendv, &
1669 & piofile = ngcpiofile)
1670 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1671
1672
1673
1674 IF (.not.allocated(contact_region)) THEN
1675 allocate ( contact_region(ncdatum) )
1676 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1677 END IF
1678 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1679 & 'contact_region', contact_region, &
1680 & piofile = ngcpiofile)
1681 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1682
1683
1684
1685
1686
1687 IF (.not.allocated(on_boundary)) THEN
1688 allocate ( on_boundary(ncdatum) )
1689 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1690 END IF
1691 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1692 & 'on_boundary', on_boundary, &
1693 & piofile = ngcpiofile)
1694 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1695
1696
1697
1698
1699 IF (.not.allocated(idg_cp)) THEN
1700 allocate ( idg_cp(ncdatum) )
1701 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1702 END IF
1703 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1704 & 'Idg', idg_cp, &
1705 & piofile = ngcpiofile)
1706 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1707
1708 IF (.not.allocated(jdg_cp)) THEN
1709 allocate ( jdg_cp(ncdatum) )
1710 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1711 END IF
1712 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1713 & 'Jdg', jdg_cp, &
1714 & piofile = ngcpiofile)
1715 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1716
1717
1718
1719 IF (.not.allocated(irg_cp)) THEN
1720 allocate ( irg_cp(ncdatum) )
1721 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1722 END IF
1723 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1724 & 'Irg', irg_cp, &
1725 & piofile = ngcpiofile)
1726 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1727
1728 IF (.not.allocated(jrg_cp)) THEN
1729 allocate ( jrg_cp(ncdatum) )
1730 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1731 END IF
1732 CALL pio_netcdf_get_ivar (ng, model, ngcname, &
1733 & 'Jrg', jrg_cp, &
1734 & piofile = ngcpiofile)
1735 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1736
1737
1738
1739 IF (.not.allocated(xrg)) THEN
1740 allocate ( xrg(ncdatum) )
1741 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1742 END IF
1743 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1744 & 'Xrg', xrg, &
1745 & piofile = ngcpiofile)
1746 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1747
1748 IF (.not.allocated(yrg)) THEN
1749 allocate ( yrg(ncdatum) )
1750 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1751 END IF
1752 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1753 & 'Yrg', yrg, &
1754 & piofile = ngcpiofile)
1755 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1756
1757
1758
1759
1760 IF (.not.allocated(lweight)) THEN
1761 allocate ( lweight(my_nlweights,ncdatum) )
1762 dmem(ng)=dmem(ng)+real(my_nlweights*ncdatum,r8)
1763 END IF
1764 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1765 & 'Lweight', lweight, &
1766 & piofile = ngcpiofile)
1767 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1768
1769# ifdef QUADRATIC_WEIGHTS
1770
1771
1772
1773
1774 IF (.not.allocated(qweight)) THEN
1775 allocate ( qweight(my_nqweights,ncdatum) )
1776 dmem(ng)=dmem(ng)+real(my_nqweights*ncdatum,r8)
1777 END IF
1778 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1779 & 'Qweight', qweight, &
1780 & piofile = ngcpiofile)
1781 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1782# endif
1783
1784
1785
1786 IF (.not.allocated(h)) THEN
1787 allocate ( h(ncdatum) )
1788 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1789 END IF
1790 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1791 & 'h', h, &
1792 & piofile = ngcpiofile)
1793 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1794
1795
1796
1797 IF (.not.allocated(f)) THEN
1798 allocate ( f(ncdatum) )
1799 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1800 END IF
1801 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1802 & 'f', f, &
1803 & piofile = ngcpiofile)
1804 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1805
1806
1807
1808
1809 IF (.not.allocated(pm)) THEN
1810 allocate ( pm(ncdatum) )
1811 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1812 END IF
1813 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1814 & 'pm', pm, &
1815 & piofile = ngcpiofile)
1816 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1817
1818 IF (.not.allocated(pn)) THEN
1819 allocate ( pn(ncdatum) )
1820 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1821 END IF
1822 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1823 & 'pn', pn, &
1824 & piofile = ngcpiofile)
1825 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1826
1827
1828
1829
1830 IF (.not.allocated(dndx)) THEN
1831 allocate ( dndx(ncdatum) )
1832 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1833 END IF
1834 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1835 & 'dndx', dndx, &
1836 & piofile = ngcpiofile)
1837 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1838
1839 IF (.not.allocated(dmde)) THEN
1840 allocate ( dmde(ncdatum) )
1841 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1842 END IF
1843 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1844 & 'dmde', dmde, &
1845 & piofile = ngcpiofile)
1846 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1847
1848
1849
1850 IF (.not.allocated(angle)) THEN
1851 allocate ( angle(ncdatum) )
1852 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1853 END IF
1854 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1855 & 'angle', angle, &
1856 & piofile = ngcpiofile)
1857 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1858
1859
1860
1861 IF (.not.allocated(mask)) THEN
1862 allocate ( mask(ncdatum) )
1863 dmem(ng)=dmem(ng)+real(ncdatum,r8)
1864 END IF
1865 CALL pio_netcdf_get_fvar (ng, model, ngcname, &
1866 & 'mask', mask, &
1867 & piofile = ngcpiofile)
1868 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1869
1870
1871
1872 CALL pio_netcdf_close (ng, model, ngcpiofile, ngcname, .false.)
1873 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1874
1875
1876
1877
1878
1879
1880
1881 IF (.not.allocated(ncpoints)) THEN
1882 allocate ( ncpoints(ncontact) )
1883 dmem(ng)=dmem(ng)+real(ncontact,r8)
1884 END IF
1885 DO cr=1,ncontact
1886 npointsr(cr)=nendr(cr)-nstrr(cr)+1
1887 npointsu(cr)=nendu(cr)-nstru(cr)+1
1888 npointsv(cr)=nendv(cr)-nstrv(cr)+1
1889 ncpoints(cr)=npointsr(cr)+npointsu(cr)+npointsv(cr)
1890 END DO
1891
1892
1893
1894 allocate ( rcontact(ncontact) )
1895 allocate ( ucontact(ncontact) )
1896 allocate ( vcontact(ncontact) )
1897 dmem(ng)=dmem(ng)+3.0_r8*real(ncontact,r8)
1898
1899
1900
1901 DO cr=1,ncontact
1902 dg=donor_grid(cr)
1903 rg=receiver_grid(cr)
1904
1905 allocate ( rcontact(cr) % Irg(npointsr(cr)) )
1906 allocate ( ucontact(cr) % Irg(npointsu(cr)) )
1907 allocate ( vcontact(cr) % Irg(npointsv(cr)) )
1908
1909 allocate ( rcontact(cr) % Jrg(npointsr(cr)) )
1910 allocate ( ucontact(cr) % Jrg(npointsu(cr)) )
1911 allocate ( vcontact(cr) % Jrg(npointsv(cr)) )
1912
1913 allocate ( rcontact(cr) % Idg(npointsr(cr)) )
1914 allocate ( ucontact(cr) % Idg(npointsu(cr)) )
1915 allocate ( vcontact(cr) % Idg(npointsv(cr)) )
1916
1917 allocate ( rcontact(cr) % Jdg(npointsr(cr)) )
1918 allocate ( ucontact(cr) % Jdg(npointsu(cr)) )
1919 allocate ( vcontact(cr) % Jdg(npointsv(cr)) )
1920
1921 dmem(dg)=dmem(dg)+4.0_r8*real(npointsr(cr),r8)
1922 dmem(dg)=dmem(dg)+4.0_r8*real(npointsu(cr),r8)
1923 dmem(dg)=dmem(dg)+4.0_r8*real(npointsv(cr),r8)
1924
1925# ifdef SOLVE3D
1926 allocate ( rcontact(cr) % Kdg(n(dg),npointsr(cr)) )
1927 allocate ( ucontact(cr) % Kdg(n(dg),npointsu(cr)) )
1928 allocate ( vcontact(cr) % Kdg(n(dg),npointsv(cr)) )
1929
1930 dmem(dg)=dmem(dg)+real(n(dg)*npointsr(cr),r8)
1931 dmem(dg)=dmem(dg)+real(n(dg)*npointsu(cr),r8)
1932 dmem(dg)=dmem(dg)+real(n(dg)*npointsv(cr),r8)
1933# endif
1934
1935 allocate ( rcontact(cr) % Lweight(4,npointsr(cr)) )
1936 allocate ( ucontact(cr) % Lweight(4,npointsu(cr)) )
1937 allocate ( vcontact(cr) % Lweight(4,npointsv(cr)) )
1938
1939 dmem(dg)=dmem(dg)+4.0_r8*real(npointsr(cr),r8)
1940 dmem(dg)=dmem(dg)+4.0_r8*real(npointsu(cr),r8)
1941 dmem(dg)=dmem(dg)+4.0_r8*real(npointsv(cr),r8)
1942
1943# ifdef WET_DRY
1944 allocate ( rcontact(cr) % LweightUnmasked(4,npointsr(cr)) )
1945 allocate ( ucontact(cr) % LweightUnmasked(4,npointsu(cr)) )
1946 allocate ( vcontact(cr) % LweightUnmasked(4,npointsv(cr)) )
1947
1948 dmem(dg)=dmem(dg)+4.0_r8*real(npointsr(cr),r8)
1949 dmem(dg)=dmem(dg)+4.0_r8*real(npointsu(cr),r8)
1950 dmem(dg)=dmem(dg)+4.0_r8*real(npointsv(cr),r8)
1951# endif
1952
1953# ifdef QUADRATIC_WEIGHTS
1954 allocate ( rcontact(cr) % Qweight(9,npointsr(cr)) )
1955 allocate ( ucontact(cr) % Qweight(9,npointsu(cr)) )
1956 allocate ( vcontact(cr) % Qweight(9,npointsv(cr)) )
1957
1958 dmem(dg)=dmem(dg)+9.0_r8*real(npointsr(cr),r8)
1959 dmem(dg)=dmem(dg)+9.0_r8*real(npointsu(cr),r8)
1960 dmem(dg)=dmem(dg)+9.0_r8*real(npointsv(cr),r8)
1961
1962# ifdef WET_DRY
1963 allocate ( rcontact(cr) % QweightUnmasked(9,npointsr(cr)) )
1964 allocate ( ucontact(cr) % QweightUnmasked(9,npointsu(cr)) )
1965 allocate ( vcontact(cr) % QweightUnmasked(9,npointsv(cr)) )
1966
1967 dmem(dg)=dmem(dg)+9.0_r8*real(npointsr(cr),r8)
1968 dmem(dg)=dmem(dg)+9.0_r8*real(npointsu(cr),r8)
1969 dmem(dg)=dmem(dg)+9.0_r8*real(npointsv(cr),r8)
1970# endif
1971# endif
1972
1973# ifdef SOLVE3D
1974 allocate ( rcontact(cr) % Vweight(2,n(dg),npointsr(cr)) )
1975 allocate ( ucontact(cr) % Vweight(2,n(dg),npointsu(cr)) )
1976 allocate ( vcontact(cr) % Vweight(2,n(dg),npointsv(cr)) )
1977
1978 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsr(cr),r8)
1979 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsu(cr),r8)
1980 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsv(cr),r8)
1981
1982# if defined TANGENT || defined TL_IOMS
1983 allocate ( rcontact(cr) % tl_Vweight(2,n(dg),npointsr(cr)) )
1984 allocate ( ucontact(cr) % tl_Vweight(2,n(dg),npointsu(cr)) )
1985 allocate ( vcontact(cr) % tl_Vweight(2,n(dg),npointsv(cr)) )
1986
1987 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsr(cr),r8)
1988 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsu(cr),r8)
1989 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsv(cr),r8)
1990# endif
1991
1992# ifdef ADJOINT
1993 allocate ( rcontact(cr) % ad_Vweight(2,n(dg),npointsr(cr)) )
1994 allocate ( ucontact(cr) % ad_Vweight(2,n(dg),npointsu(cr)) )
1995 allocate ( vcontact(cr) % ad_Vweight(2,n(dg),npointsv(cr)) )
1996
1997 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsr(cr),r8)
1998 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsu(cr),r8)
1999 dmem(dg)=dmem(dg)+2.0_r8*real(n(dg)*npointsv(cr),r8)
2000# endif
2001# endif
2002 END DO
2003
2004
2005
2006 DO cr=1,ncontact
2007 dg=donor_grid(cr)
2008 rg=receiver_grid(cr)
2009
2010 rcontact(cr) % coincident = lcoincident(rg)
2011 ucontact(cr) % coincident = lcoincident(rg)
2012 vcontact(cr) % coincident = lcoincident(rg)
2013
2014 rcontact(cr) % interpolate = linterpolate(rg)
2015 ucontact(cr) % interpolate = linterpolate(rg)
2016 vcontact(cr) % interpolate = linterpolate(rg)
2017
2018 rcontact(cr) % donor_grid = dg
2019 ucontact(cr) % donor_grid = dg
2020 vcontact(cr) % donor_grid = dg
2021
2022 rcontact(cr) % receiver_grid = rg
2023 ucontact(cr) % receiver_grid = rg
2024 vcontact(cr) % receiver_grid = rg
2025
2026 rcontact(cr) % Npoints = npointsr(cr)
2027 ucontact(cr) % Npoints = npointsu(cr)
2028 vcontact(cr) % Npoints = npointsv(cr)
2029
2030 DO m=1,npointsr(cr)
2031 ip=m+nstrr(cr)-1
2032 rcontact(cr) % Irg(m) = irg_cp(ip)
2033 rcontact(cr) % Jrg(m) = jrg_cp(ip)
2034 rcontact(cr) % Idg(m) = idg_cp(ip)
2035 rcontact(cr) % Jdg(m) = jdg_cp(ip)
2036# ifdef WET_DRY
2037 rcontact(cr) % LweightUnmasked(1,m) = lweight(1,ip)
2038 rcontact(cr) % LweightUnmasked(2,m) = lweight(2,ip)
2039 rcontact(cr) % LweightUnmasked(3,m) = lweight(3,ip)
2040 rcontact(cr) % LweightUnmasked(4,m) = lweight(4,ip)
2041# endif
2042 rcontact(cr) % Lweight(1,m) = lweight(1,ip)
2043 rcontact(cr) % Lweight(2,m) = lweight(2,ip)
2044 rcontact(cr) % Lweight(3,m) = lweight(3,ip)
2045 rcontact(cr) % Lweight(4,m) = lweight(4,ip)
2046# ifdef QUADRATIC_WEIGHTS
2047# ifdef WET_DRY
2048 rcontact(cr) % QweightUnmasked(1,m) = qweight(1,ip)
2049 rcontact(cr) % QweightUnmasked(2,m) = qweight(2,ip)
2050 rcontact(cr) % QweightUnmasked(3,m) = qweight(3,ip)
2051 rcontact(cr) % QweightUnmasked(4,m) = qweight(4,ip)
2052 rcontact(cr) % QweightUnmasked(5,m) = qweight(5,ip)
2053 rcontact(cr) % QweightUnmasked(6,m) = qweight(6,ip)
2054 rcontact(cr) % QweightUnmasked(7,m) = qweight(7,ip)
2055 rcontact(cr) % QweightUnmasked(8,m) = qweight(8,ip)
2056 rcontact(cr) % QweightUnmasked(9,m) = qweight(9,ip)
2057# endif
2058 rcontact(cr) % Qweight(1,m) = qweight(1,ip)
2059 rcontact(cr) % Qweight(2,m) = qweight(2,ip)
2060 rcontact(cr) % Qweight(3,m) = qweight(3,ip)
2061 rcontact(cr) % Qweight(4,m) = qweight(4,ip)
2062 rcontact(cr) % Qweight(5,m) = qweight(5,ip)
2063 rcontact(cr) % Qweight(6,m) = qweight(6,ip)
2064 rcontact(cr) % Qweight(7,m) = qweight(7,ip)
2065 rcontact(cr) % Qweight(8,m) = qweight(8,ip)
2066 rcontact(cr) % Qweight(9,m) = qweight(9,ip)
2067# endif
2068 END DO
2069
2070 DO m=1,npointsu(cr)
2071 ip=m+nstru(cr)-1
2072 ucontact(cr) % Irg(m) = irg_cp(ip)
2073 ucontact(cr) % Jrg(m) = jrg_cp(ip)
2074 ucontact(cr) % Idg(m) = idg_cp(ip)
2075 ucontact(cr) % Jdg(m) = jdg_cp(ip)
2076# ifdef WET_DRY
2077 ucontact(cr) % LweightUnmasked(1,m) = lweight(1,ip)
2078 ucontact(cr) % LweightUnmasked(2,m) = lweight(2,ip)
2079 ucontact(cr) % LweightUnmasked(3,m) = lweight(3,ip)
2080 ucontact(cr) % LweightUnmasked(4,m) = lweight(4,ip)
2081# endif
2082 ucontact(cr) % Lweight(1,m) = lweight(1,ip)
2083 ucontact(cr) % Lweight(2,m) = lweight(2,ip)
2084 ucontact(cr) % Lweight(3,m) = lweight(3,ip)
2085 ucontact(cr) % Lweight(4,m) = lweight(4,ip)
2086# ifdef QUADRATIC_WEIGHTS
2087# ifdef WET_DRY
2088 ucontact(cr) % QweightUnmasked(1,m) = qweight(1,ip)
2089 ucontact(cr) % QweightUnmasked(2,m) = qweight(2,ip)
2090 ucontact(cr) % QweightUnmasked(3,m) = qweight(3,ip)
2091 ucontact(cr) % QweightUnmasked(4,m) = qweight(4,ip)
2092 ucontact(cr) % QweightUnmasked(5,m) = qweight(5,ip)
2093 ucontact(cr) % QweightUnmasked(6,m) = qweight(6,ip)
2094 ucontact(cr) % QweightUnmasked(7,m) = qweight(7,ip)
2095 ucontact(cr) % QweightUnmasked(8,m) = qweight(8,ip)
2096 ucontact(cr) % QweightUnmasked(9,m) = qweight(9,ip)
2097# endif
2098 ucontact(cr) % Qweight(1,m) = qweight(1,ip)
2099 ucontact(cr) % Qweight(2,m) = qweight(2,ip)
2100 ucontact(cr) % Qweight(3,m) = qweight(3,ip)
2101 ucontact(cr) % Qweight(4,m) = qweight(4,ip)
2102 ucontact(cr) % Qweight(5,m) = qweight(5,ip)
2103 ucontact(cr) % Qweight(6,m) = qweight(6,ip)
2104 ucontact(cr) % Qweight(7,m) = qweight(7,ip)
2105 ucontact(cr) % Qweight(8,m) = qweight(8,ip)
2106 ucontact(cr) % Qweight(9,m) = qweight(9,ip)
2107# endif
2108 END DO
2109
2110 DO m=1,npointsv(cr)
2111 ip=m+nstrv(cr)-1
2112 vcontact(cr) % Irg(m) = irg_cp(ip)
2113 vcontact(cr) % Jrg(m) = jrg_cp(ip)
2114 vcontact(cr) % Idg(m) = idg_cp(ip)
2115 vcontact(cr) % Jdg(m) = jdg_cp(ip)
2116# ifdef WET_DRY
2117 vcontact(cr) % LweightUnmasked(1,m) = lweight(1,ip)
2118 vcontact(cr) % LweightUnmasked(2,m) = lweight(2,ip)
2119 vcontact(cr) % LweightUnmasked(3,m) = lweight(3,ip)
2120 vcontact(cr) % LweightUnmasked(4,m) = lweight(4,ip)
2121# endif
2122 vcontact(cr) % Lweight(1,m) = lweight(1,ip)
2123 vcontact(cr) % Lweight(2,m) = lweight(2,ip)
2124 vcontact(cr) % Lweight(3,m) = lweight(3,ip)
2125 vcontact(cr) % Lweight(4,m) = lweight(4,ip)
2126# ifdef QUADRATIC_WEIGHTS
2127# ifdef WET_DRY
2128 vcontact(cr) % QweightUnmasked(1,m) = qweight(1,ip)
2129 vcontact(cr) % QweightUnmasked(2,m) = qweight(2,ip)
2130 vcontact(cr) % QweightUnmasked(3,m) = qweight(3,ip)
2131 vcontact(cr) % QweightUnmasked(4,m) = qweight(4,ip)
2132 vcontact(cr) % QweightUnmasked(5,m) = qweight(5,ip)
2133 vcontact(cr) % QweightUnmasked(6,m) = qweight(6,ip)
2134 vcontact(cr) % QweightUnmasked(7,m) = qweight(7,ip)
2135 vcontact(cr) % QweightUnmasked(8,m) = qweight(8,ip)
2136 vcontact(cr) % QweightUnmasked(9,m) = qweight(9,ip)
2137# endif
2138 vcontact(cr) % Qweight(1,m) = qweight(1,ip)
2139 vcontact(cr) % Qweight(2,m) = qweight(2,ip)
2140 vcontact(cr) % Qweight(3,m) = qweight(3,ip)
2141 vcontact(cr) % Qweight(4,m) = qweight(4,ip)
2142 vcontact(cr) % Qweight(5,m) = qweight(5,ip)
2143 vcontact(cr) % Qweight(6,m) = qweight(6,ip)
2144 vcontact(cr) % Qweight(7,m) = qweight(7,ip)
2145 vcontact(cr) % Qweight(8,m) = qweight(8,ip)
2146 vcontact(cr) % Qweight(9,m) = qweight(9,ip)
2147# endif
2148 END DO
2149
2150 END DO
2151
2152
2153
2154
2155
2156
2157
2158 allocate ( contact_metric(ncontact) )
2159
2160
2161
2162 DO cr=1,ncontact
2163 allocate ( contact_metric(cr) % angler(npointsr(cr)) )
2164 allocate ( contact_metric(cr) % dndx (npointsr(cr)) )
2165 allocate ( contact_metric(cr) % dmde (npointsr(cr)) )
2166 allocate ( contact_metric(cr) % f (npointsr(cr)) )
2167 allocate ( contact_metric(cr) % h (npointsr(cr)) )
2168 allocate ( contact_metric(cr) % rmask (npointsr(cr)) )
2169 allocate ( contact_metric(cr) % umask (npointsu(cr)) )
2170 allocate ( contact_metric(cr) % vmask (npointsv(cr)) )
2171 allocate ( contact_metric(cr) % pm (npointsr(cr)) )
2172 allocate ( contact_metric(cr) % pn (npointsr(cr)) )
2173 allocate ( contact_metric(cr) % Xr (npointsr(cr)) )
2174 allocate ( contact_metric(cr) % Yr (npointsr(cr)) )
2175 allocate ( contact_metric(cr) % Xu (npointsu(cr)) )
2176 allocate ( contact_metric(cr) % Yu (npointsu(cr)) )
2177 allocate ( contact_metric(cr) % Xv (npointsv(cr)) )
2178 allocate ( contact_metric(cr) % Yv (npointsv(cr)) )
2179
2180 dmem(ng)=dmem(ng)+10.0_r8*real(npointsr(cr),r8)
2181 dmem(ng)=dmem(ng)+ 3.0_r8*real(npointsu(cr),r8)
2182 dmem(ng)=dmem(ng)+ 3.0_r8*real(npointsv(cr),r8)
2183 END DO
2184
2185
2186
2187 DO cr=1,ncontact
2188 DO m=1,npointsr(cr)
2189 ip=m+nstrr(cr)-1
2190 contact_metric(cr) % angler(m) = angle(ip)
2191 contact_metric(cr) % dndx (m) = dndx(ip)
2192 contact_metric(cr) % dmde (m) = dmde(ip)
2193 contact_metric(cr) % f (m) = f(ip)
2194 contact_metric(cr) % h (m) = h(ip)
2195 contact_metric(cr) % rmask (m) = mask(ip)
2196 contact_metric(cr) % pm (m) = pm(ip)
2197 contact_metric(cr) % pn (m) = pn(ip)
2198 contact_metric(cr) % Xr (m) = xrg(ip)
2199 contact_metric(cr) % Yr (m) = yrg(ip)
2200 END DO
2201
2202 DO m=1,npointsu(cr)
2203 ip=m+nstru(cr)-1
2204 contact_metric(cr) % umask(m) = mask(ip)
2205 contact_metric(cr) % Xu (m) = xrg(ip)
2206 contact_metric(cr) % Yu (m) = yrg(ip)
2207 END DO
2208
2209 DO m=1,npointsv(cr)
2210 ip=m+nstrv(cr)-1
2211 contact_metric(cr) % vmask(m) = mask(ip)
2212 contact_metric(cr) % Xv (m) = xrg(ip)
2213 contact_metric(cr) % Yv (m) = yrg(ip)
2214 END DO
2215 END DO
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226 IF (.not.allocated(contactregion)) THEN
2227 allocate ( contactregion(4,ngrids) )
2228 contactregion = .false.
2229 dmem(ng)=dmem(ng)+4.0_r8*real(ngrids,r8)
2230 END IF
2231
2232 DO m=1,ncdatum
2233 cr=contact_region(m)
2234 rg=receiver_grid(cr)
2235 ibry=on_boundary(m)
2236 IF ((ibry.eq.iwest ).or.(ibry.eq.ieast ).or. &
2237 & (ibry.eq.isouth).or.(ibry.eq.inorth)) THEN
2238 IF (.not.contactregion(ibry,rg)) THEN
2239 contactregion(ibry,rg)=.true.
2240 END IF
2241 END IF
2242 END DO
2243
2244
2245
2246 DO cr=1,ncontact
2247 rg=receiver_grid(cr)
2248 DO ibry=1,4
2249 IF (lcomposite(cr).and.contactregion(ibry,rg)) THEN
2250 compositegrid(ibry,rg)=.true.
2251 END IF
2252 END DO
2253 refinedgrid(rg)=lrefinement(cr)
2254 END DO
2255
2256
2257
2258
2259 IF (.not.any(lcoincident).and.any(lcomposite)) THEN
2260 get_vweights=.true.
2261 ELSE
2262 get_vweights=.false.
2263 END IF
2264
2265
2266
2267 DO ig=1,ngrids
2268 refinescale(ig)=refine_factor(ig)
2269 END DO
2270
2271
2272
2273
2274
2275
2276
2277 IF (.not.allocated(coarserdonor)) THEN
2278 allocate ( coarserdonor(ngrids) )
2279 coarserdonor = 0
2280 dmem(ng)=dmem(ng)+real(ngrids,r8)
2281 END IF
2282
2283
2284
2285
2286
2287
2288
2289 IF (.not.allocated(finerdonor)) THEN
2290 allocate ( finerdonor(ngrids) )
2291 finerdonor = 0
2292 dmem(ng)=dmem(ng)+real(ngrids,r8)
2293 END IF
2294
2295
2296
2297
2298
2299
2300
2301 IF (.not.allocated(donortofiner)) THEN
2302 allocate ( donortofiner(ngrids) )
2303 donortofiner = .false.
2304 dmem(ng)=dmem(ng)+real(ngrids,r8)
2305 END IF
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317 IF (.not.allocated(refinesteps)) THEN
2318 allocate ( refinesteps(ngrids) )
2319 dmem(ng)=dmem(ng)+real(ngrids,r8)
2320 DO ig=1,ngrids
2321 refinesteps(ig)=refine_factor(ig)
2322 END DO
2323 END IF
2324
2325
2326
2327
2328
2329 IF (.not.allocated(refinestepscounter)) THEN
2330 allocate ( refinestepscounter(ngrids) )
2331 refinestepscounter = 0
2332 dmem(ng)=dmem(ng)+real(ngrids,r8)
2333 END IF
2334
2335
2336
2337 IF (.not.allocated(twowayinterval)) THEN
2338 allocate ( twowayinterval(ngrids) )
2339 twowayinterval = 0.0_r8
2340 dmem(ng)=dmem(ng)+real(ngrids,r8)
2341 END IF
2342
2343
2344
2345
2346
2347 IF (.not.allocated(telescoping)) THEN
2348 allocate ( telescoping(ngrids) )
2349 telescoping = .false.
2350 dmem(ng)=dmem(ng)+real(ngrids,r8)
2351 END IF
2352
2353
2354
2355
2356
2357
2358 IF (.not.allocated(rollingindex)) THEN
2359 allocate ( rollingindex(ncontact) )
2360 rollingindex = 0
2361 dmem(ng)=dmem(ng)+real(ncontact,r8)
2362 END IF
2363
2364 IF (.not.allocated(rollingtime)) THEN
2365 allocate ( rollingtime(2,ncontact) )
2366 rollingtime = 0
2367 dmem(ng)=dmem(ng)+2.0_r8*real(ncontact,r8)
2368 END IF
2369
2370
2371
2372
2373
2374
2375 IF (any(compositegrid)) THEN
2376
2377
2378
2379 allocate ( composite(ncontact) )
2380
2381
2382
2383 DO cr=1,ncontact
2384 dg=donor_grid(cr)
2385
2386 allocate ( composite(cr) % bustr(4,npointsu(cr)) )
2387 allocate ( composite(cr) % bvstr(4,npointsv(cr)) )
2388
2389 allocate ( composite(cr) % ubar(4,npointsu(cr),2) )
2390 allocate ( composite(cr) % vbar(4,npointsv(cr),2) )
2391 allocate ( composite(cr) % zeta(4,npointsr(cr),2) )
2392
2393 allocate ( composite(cr) % rzeta(4,npointsr(cr)) )
2394
2395 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsr(cr),r8)
2396 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsu(cr),r8)
2397 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsv(cr),r8)
2398
2399# if defined TANGENT || defined TL_IOMS
2400 allocate ( composite(cr) % tl_bustr(4,npointsu(cr)) )
2401 allocate ( composite(cr) % tl_bvstr(4,npointsv(cr)) )
2402
2403 allocate ( composite(cr) % tl_ubar(4,npointsu(cr),2) )
2404 allocate ( composite(cr) % tl_vbar(4,npointsv(cr),2) )
2405 allocate ( composite(cr) % tl_zeta(4,npointsr(cr),2) )
2406
2407 allocate ( composite(cr) % tl_rzeta(4,npointsr(cr)) )
2408
2409 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsr(cr),r8)
2410 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsu(cr),r8)
2411 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsv(cr),r8)
2412# endif
2413
2414# ifdef ADJOINT
2415 allocate ( composite(cr) % ad_bustr(4,npointsu(cr)) )
2416 allocate ( composite(cr) % ad_bvstr(4,npointsv(cr)) )
2417
2418 allocate ( composite(cr) % ad_ubar(4,npointsu(cr),2) )
2419 allocate ( composite(cr) % ad_vbar(4,npointsv(cr),2) )
2420 allocate ( composite(cr) % ad_zeta(4,npointsr(cr),2) )
2421
2422 allocate ( composite(cr) % ad_rzeta(4,npointsr(cr)) )
2423
2424 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsr(cr),r8)
2425 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsu(cr),r8)
2426 dmem(dg)=dmem(dg)+2.0_r8*real(4*npointsv(cr),r8)
2427# endif
2428
2429# ifdef SOLVE3D
2430 allocate ( composite(cr) % DU_avg1(4,npointsu(cr)) )
2431 allocate ( composite(cr) % DV_avg1(4,npointsv(cr)) )
2432 allocate ( composite(cr) % Zt_avg1(4,npointsr(cr)) )
2433
2434 dmem(dg)=dmem(dg)+real(4*npointsr(cr),r8)
2435 dmem(dg)=dmem(dg)+real(4*npointsu(cr),r8)
2436 dmem(dg)=dmem(dg)+real(4*npointsv(cr),r8)
2437
2438 allocate ( composite(cr) % u(4,n(dg),npointsu(cr)) )
2439 allocate ( composite(cr) % v(4,n(dg),npointsv(cr)) )
2440
2441 allocate ( composite(cr) % Huon(4,n(dg),npointsu(cr)) )
2442 allocate ( composite(cr) % Hvom(4,n(dg),npointsv(cr)) )
2443
2444 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsu(cr),r8)
2445 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsv(cr),r8)
2446
2447 allocate ( composite(cr) % t(4,n(dg),npointsr(cr),nt(dg)) )
2448
2449 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsu(cr)*nt(dg),r8)
2450
2451# if defined TANGENT || defined TL_IOMS
2452 allocate ( composite(cr) % tl_DU_avg1(4,npointsu(cr)) )
2453 allocate ( composite(cr) % tl_DV_avg1(4,npointsv(cr)) )
2454 allocate ( composite(cr) % tl_Zt_avg1(4,npointsr(cr)) )
2455
2456 dmem(dg)=dmem(dg)+real(4*npointsr(cr),r8)
2457 dmem(dg)=dmem(dg)+real(4*npointsu(cr),r8)
2458 dmem(dg)=dmem(dg)+real(4*npointsv(cr),r8)
2459
2460 allocate ( composite(cr) % tl_u(4,n(dg),npointsu(cr)) )
2461 allocate ( composite(cr) % tl_v(4,n(dg),npointsv(cr)) )
2462
2463 allocate ( composite(cr) % tl_Huon(4,n(dg),npointsu(cr)) )
2464 allocate ( composite(cr) % tl_Hvom(4,n(dg),npointsv(cr)) )
2465
2466 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsu(cr),r8)
2467 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsv(cr),r8)
2468
2469 allocate ( composite(cr) % tl_t(4,n(dg),npointsr(cr),nt(dg)) )
2470
2471 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsu(cr)*nt(dg),r8)
2472# endif
2473
2474# ifdef ADJOINT
2475 allocate ( composite(cr) % ad_DU_avg1(4,npointsu(cr)) )
2476 allocate ( composite(cr) % ad_DV_avg1(4,npointsv(cr)) )
2477 allocate ( composite(cr) % ad_Zt_avg1(4,npointsr(cr)) )
2478
2479 dmem(dg)=dmem(dg)+real(4*npointsr(cr),r8)
2480 dmem(dg)=dmem(dg)+real(4*npointsu(cr),r8)
2481 dmem(dg)=dmem(dg)+real(4*npointsv(cr),r8)
2482
2483 allocate ( composite(cr) % ad_u(4,n(dg),npointsu(cr)) )
2484 allocate ( composite(cr) % ad_v(4,n(dg),npointsv(cr)) )
2485
2486 allocate ( composite(cr) % ad_Huon(4,n(dg),npointsu(cr)) )
2487 allocate ( composite(cr) % ad_Hvom(4,n(dg),npointsv(cr)) )
2488
2489 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsu(cr),r8)
2490 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsv(cr),r8)
2491
2492 allocate ( composite(cr) % ad_t(4,n(dg),npointsr(cr),nt(dg)) )
2493
2494 dmem(dg)=dmem(dg)+2.0_r8*real(4*n(dg)*npointsu(cr)*nt(dg),r8)
2495# endif
2496# endif
2497 END DO
2498 END IF
2499
2500
2501
2502
2503
2504 IF (any(refinedgrid)) THEN
2505
2506
2507
2508 allocate ( refined(ncontact) )
2509
2510
2511
2512 DO cr=1,ncontact
2513 rg=receiver_grid(cr)
2514
2515 allocate ( refined(cr) % ubar(4,npointsu(cr),2) )
2516 allocate ( refined(cr) % vbar(4,npointsv(cr),2) )
2517 allocate ( refined(cr) % zeta(4,npointsr(cr),2) )
2518
2519 allocate ( refined(cr) % U2d_flux(4,npointsu(cr),2) )
2520 allocate ( refined(cr) % V2d_flux(4,npointsv(cr),2) )
2521
2522 allocate ( refined(cr) % on_u(npointsu(cr)) )
2523 allocate ( refined(cr) % om_v(npointsv(cr)) )
2524
2525 dmem(rg)=dmem(rg)+real(4*npointsr(cr),r8)
2526 dmem(rg)=dmem(rg)+3.0_r8*real(4*npointsu(cr),r8)
2527 dmem(rg)=dmem(rg)+3.0_r8*real(4*npointsv(cr),r8)
2528
2529# if defined TANGENT || defined TL_IOMS
2530 allocate ( refined(cr) % tl_ubar(4,npointsu(cr),2) )
2531 allocate ( refined(cr) % tl_vbar(4,npointsv(cr),2) )
2532 allocate ( refined(cr) % tl_zeta(4,npointsr(cr),2) )
2533
2534 allocate ( refined(cr) % tl_U2d_flux(4,npointsu(cr),2) )
2535 allocate ( refined(cr) % tl_V2d_flux(4,npointsv(cr),2) )
2536
2537 dmem(rg)=dmem(rg)+real(4*npointsr(cr),r8)
2538 dmem(rg)=dmem(rg)+3.0_r8*real(4*npointsu(cr),r8)
2539 dmem(rg)=dmem(rg)+3.0_r8*real(4*npointsv(cr),r8)
2540# endif
2541
2542# ifdef ADJOINT
2543 allocate ( refined(cr) % ad_ubar(4,npointsu(cr),2) )
2544 allocate ( refined(cr) % ad_vbar(4,npointsv(cr),2) )
2545 allocate ( refined(cr) % ad_zeta(4,npointsr(cr),2) )
2546
2547 allocate ( refined(cr) % ad_U2d_flux(4,npointsu(cr),2) )
2548 allocate ( refined(cr) % ad_V2d_flux(4,npointsv(cr),2) )
2549
2550 dmem(rg)=dmem(rg)+real(4*npointsr(cr),r8)
2551 dmem(rg)=dmem(rg)+3.0_r8*real(4*npointsu(cr),r8)
2552 dmem(rg)=dmem(rg)+3.0_r8*real(4*npointsv(cr),r8)
2553# endif
2554
2555# ifdef SOLVE3D
2556 allocate ( refined(cr) % u(4,n(rg),npointsu(cr),2) )
2557 allocate ( refined(cr) % v(4,n(rg),npointsv(cr),2) )
2558
2559 dmem(rg)=dmem(rg)+3.0_r8*real(4*n(rg)*npointsu(cr),r8)
2560 dmem(rg)=dmem(rg)+3.0_r8*real(4*n(rg)*npointsv(cr),r8)
2561
2562 allocate ( refined(cr) % t(4,n(rg),npointsr(cr),2,nt(rg)) )
2563
2564 dmem(rg)=dmem(rg)+2.0_r8*real(4*n(rg)*npointsr(cr)*nt(rg),r8)
2565
2566# if defined TANGENT || defined TL_IOMS
2567 allocate ( refined(cr) % tl_u(4,n(rg),npointsu(cr),2) )
2568 allocate ( refined(cr) % tl_v(4,n(rg),npointsv(cr),2) )
2569
2570 dmem(rg)=dmem(rg)+3.0_r8*real(4*n(rg)*npointsu(cr),r8)
2571 dmem(rg)=dmem(rg)+3.0_r8*real(4*n(rg)*npointsv(cr),r8)
2572
2573 allocate ( refined(cr) % tl_t(4,n(rg),npointsr(cr),2,nt(rg)) )
2574
2575 dmem(rg)=dmem(rg)+2.0_r8*real(4*n(rg)*npointsr(cr)*nt(rg),r8)
2576# endif
2577
2578# ifdef ADJOINT
2579 allocate ( refined(cr) % ad_u(4,n(rg),npointsu(cr),2) )
2580 allocate ( refined(cr) % ad_v(4,n(rg),npointsv(cr),2) )
2581
2582 dmem(rg)=dmem(rg)+3.0_r8*real(4*n(rg)*npointsu(cr),r8)
2583 dmem(rg)=dmem(rg)+3.0_r8*real(4*n(rg)*npointsv(cr),r8)
2584
2585 allocate ( refined(cr) % ad_t(4,n(rg),npointsr(cr),2,nt(rg)) )
2586
2587 dmem(rg)=dmem(rg)+2.0_r8*real(4*n(rg)*npointsr(cr)*nt(rg),r8)
2588# endif
2589# endif
2590 END DO
2591 END IF
2592
2593 RETURN