rfft.f90 70.6 KB
Newer Older
Matthias Redies's avatar
Matthias Redies committed
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
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

MODULE m_rfft
   use m_juDFT
   PRIVATE
! odule also contains routines vrffti,vrfftf&vrfftb as private routines below
   PUBLIC rfft
CONTAINS
   SUBROUTINE rfft( &
      isn,n1d,n2d,n3d,n1,n2,n3, &
      nw1,nw2,nw3,wsave,b, &
      a)
! **********************************************************************

! isn = +1 : FFT a real, 3dim array "a" of dimensions n1*n2*n3 to a complex
!            array of size n1*n2*(n3+1)/2 [if n3 is odd] or n1*n2*(n3/2+1)
!            [n3 is even].
! isn = -1 : back-FFT of a complex array "a" of size n1*n2*(n3+1)/2 [odd]
!            or n1*n2*(n3/2+1) [even] to a real, 3dim array

! the actual array is assumed to be located between
!                                  1 ... nw1+1    &     n1-nw1+1 ... n1
!                                  1 ... nw2+1    &     n2-nw2+1 ... n2
!                                  1 ... nw3+1    &     n3-nw3+1 ... n3
! and padded with zeros in between.
! if nw1 >= (n1-1)/2, no padding is assumed (-> aliasing errors!)

!                                                  G.Bihlmayer (UniWien)

! **********************************************************************
      USE m_cfft
      IMPLICIT NONE

      INTEGER :: n1d,n2d,n3d,n1,n2,n3,nw1,nw2,nw3,isn
      REAL :: a(n1d,n2d,0:n3d),b(n1d,n2d,n3d),wsave(n3d+15)

      INTEGER :: i1,i2,i3,nup
      REAL :: factor
      LOGICAL :: l_nopad

! a ... array for FFT
! b ... work array
! wsave ... stores tables for r-2-c FFT
! n1,n2,n3 ... dimensions to be transformed
! nw1,nw2,nw3 ... actual dimensions of a before FFT
! n1d,n2d,n3d ... dimensions of a,b

! check for input errors

      IF ((isn/=-1) .AND. (isn /= 1))  CALL juDFT_error("choose isn=+/- 1" &
                                                        ,calledby ="rfft")
      IF ((n1d < n1) .OR. (n2d < n2) .OR. (n3d < n3)) THEN
         WRITE (6,*) 'n1d,n2d,n3d =',n1d,n2d,n3d
         WRITE (6,*) 'n1 ,n2 ,n3  =',n1 ,n2 ,n3
         CALL juDFT_error("n(i) > n(i)d",calledby ="rfft")
      ENDIF
      IF ((n1 <= 2*nw1+1) .OR. &
          (n2 <= 2*nw2+1) .OR. &
          (n3 <= 2*nw3+1)) THEN
         !        WRITE (6,*) 'n1 ,n2 ,n3  =',n1 ,n2 ,n3
         !        WRITE (6,*) 'nw1,nw2,nw3 =',nw1,nw2,nw3
         l_nopad= .TRUE.
      ELSE
         l_nopad= .FALSE.
      ENDIF

! ******************** f o r w a r d - t r a n s f o r m *******************

      IF (isn == 1) THEN

         ! array a is assumed to be zero from (1,1,0) to (n1d,n2d,0) and the array
         ! to be FFT'd starts at (1,1,1) as n1*n2*n3 real numbers.
         ! first transform n1*n2 real sequences of lenghth n3 to n3/2 complex values

         CALL vrffti(n3,wsave)
         IF (l_nopad) THEN
            CALL vrfftf(n1*n2,n3,a(1,1,1),b,n1d*n2d,wsave)
         ELSE
            DO i2=1,nw2+1
               CALL vrfftf(nw1+1,n3,a(1,i2,1),b,n1d*n2d,wsave)
               CALL vrfftf(nw1  ,n3,a(n1-nw1+1,i2,1),b,n1d*n2d,wsave)
            ENDDO
            DO i2=n2-nw2+1,n2
               CALL vrfftf(nw1+1,n3,a(1,i2,1),b,n1d*n2d,wsave)
               CALL vrfftf(nw1  ,n3,a(n1-nw1+1,i2,1),b,n1d*n2d,wsave)
            ENDDO
         ENDIF

         ! now we have the FFT'd array stored as described in vrfftf
         ! (mixed real & compex data)
         ! remove the norm 1/sqrt(n3) (to be compatible with cfft)

         factor = sqrt(1.0*n3)
         ! ALL CPP_BLAS_sscal(n1d*n2d*n3,factor,a(1,1,1),1)
         a=a*factor

         ! now, the real part of f(0) has to be moved to a(n1,n2,0) to get a purely
         ! complex array starting at a(1,1,0)

         DO i1=1,n1
            DO i2=1,n2
               a(i1,i2,0)=a(i1,i2,1)
               a(i1,i2,1)=0.0
            ENDDO
         ENDDO

      ENDIF

! ******************** g e n e r a l  p a r t *******************

! now perform n2*n3/2 and n1*n3/2 complex FFT's; a is assumed to be
! complex and starting at (1,1,0)

      IF (ABS((n3/2.)-NINT(n3/2.)) > 0.1) THEN
         nup = n3
      ELSE
         nup = n3+1
         IF (n3+1>n3d)  CALL juDFT_error("n3 even & n3+1 > n3d" ,calledby &
                                         ="rfft")
         a(:,:,n3+1)=0.0
      ENDIF

      IF (l_nopad) THEN
         DO i3=1,nup,2
            CALL cfft(a(1,1,i3-1),a(1,1,i3),n1*n2,n1,n1,isn)
            CALL cfft(a(1,1,i3-1),a(1,1,i3),n1*n2,n2,n1*n2,isn)
         ENDDO
      ELSE
         DO i3=1,nup,2
            CALL cfft(a(1,1,i3-1),a(1,1,i3),(nw2+1)*n1,n1,n1,isn)
            CALL cfft(a(1,n2-nw2+1,i3-1),a(1,n2-nw2+1,i3), &
                      nw2*n1,n1,n1,isn)
            CALL cfft(a(1,1,i3-1),a(1,1,i3),n1*n2,n2,n1*n2,isn)
         ENDDO
      ENDIF

! ******************** b a c k w a r d - t r a n s f o r m *******************

      IF (isn == -1) THEN

         ! the real part of f(0) has to be moved to a(n1,n2,1) for a correct
         ! setup for vrfftb (see comments therein)

         DO i1=1,n1
            DO i2=1,n2
               a(i1,i2,1)=a(i1,i2,0)
               a(i1,i2,0)=0.0
            ENDDO
         ENDDO

         ! transform n1*n2 mixed real and complex sequences of lenghth n3/2
         ! to n3 real values

         CALL vrffti(n3,wsave)
         IF (l_nopad) THEN
            CALL vrfftb(n1*n2,n3,a(1,1,1),b,n1d*n2d,wsave)
         ELSE
            DO i2=1,nw2+1
               CALL vrfftb(nw1+1,n3,a(1,i2,1),b,n1d*n2d,wsave)
               CALL vrfftb(nw1  ,n3,a(n1-nw1+1,i2,1),b,n1d*n2d,wsave)
            ENDDO
            DO i2=n2-nw2+1,n2
               CALL vrfftb(nw1+1,n3,a(1,i2,1),b,n1d*n2d,wsave)
               CALL vrfftb(nw1  ,n3,a(n1-nw1+1,i2,1),b,n1d*n2d,wsave)
            ENDDO
         ENDIF

         ! remove the norm 1/sqrt(n3) (compatibility with cfft)

         factor = sqrt(1.0*n3)
         ! ALL CPP_BLAS_sscal(n1d*n2d*n3,factor,a(1,1,1),1)
         a=a*factor

      ENDIF

   END SUBROUTINE rfft

   SUBROUTINE vrffti(n,wsave)
!***BEGIN PROLOGUE  VRFFTI
!***DATE WRITTEN   860701   (YYMMDD)
!***REVISION DATE  900509   (YYMMDD)
!***CATEGORY NO.  J1A1
!***KEYWORDS  FAST FOURIER TRANSFORM, REAL PERIODIC TRANSFORM,
!             MULTIPLE SEQUENCES
!***AUTHOR  SWEET, R.A. (NIST) AND LINDGREN, L.L. (NIST)
!***PURPOSE  Initialization for VRFFTF and VRFFTB.
!***DESCRIPTION

!  Subroutine VRFFTI initializes the array WSAVE which is used in
!  both VRFFTF and VRFFTB.  The prime factorization of N together with
!  a tabulation of certain trigonometric functions are computed and
!  stored in the array WSAVE.

!  Input Parameter

!  N       the length of the sequence to be transformed.  There is no
!          restriction on N.

!  Output Parameter

!  WSAVE   a work array which must be dimensioned at least N+15.
!          The same work array can be used for both VRFFTF and VRFFTB
!          as long as N remains unchanged.  Different WSAVE arrays
!          are required for different values of N.  The contents of
!          WSAVE must not be changed between calls of VRFFTF or VRFFTB.

!              * * * * * * * * * * * * * * * * * * * * *
!              *                                       *
!              *         PROGRAM SPECIFICATIONS        *
!              *                                       *
!              * * * * * * * * * * * * * * * * * * * * *

!     Dimension of    R(MDIMR,N), RT(MDIMR,N), WSAVE(N+15)
!     Arguments

!     Latest          AUGUST 1, 1985
!     Revision

!     Subprograms     VRFFTI, VRFTI1, VRFFTF, VRFTF1, VRADF2, VRADF3,
!     Required        VRADF4, VRADF5, VRADFG, VRFFTB, VRFTB1, VRADB2,
!                     VRADB3, VRADB4, VRADB5, VRADBG, PIMACH

!     Special         NONE
!     Conditions

!     Common          NONE
!     blocks

!     I/O             NONE

!     Precision       SINGLE

!     Specialist      ROLAND SWEET

!     Language        FORTRAN

!     History         WRITTEN BY LINDA LINDGREN AND ROLAND SWEET AT THE
!                     NATIONAL BUREAU OF STANDARDS (BOULDER).

!     Algorithm       A REAL VARIANT OF THE STOCKHAM AUTOSORT VERSION
!                     OF THE COOLEY-TUKEY FAST FOURIER TRANSFORM.

!     Portability     AMERICAN NATIONAL STANDARDS INSTITUTE FORTRAN 77.
!                     THE ONLY MACHINE DEPENDENT CONSTANT IS LOCATED IN
!                     THE FUNCTION PIMACH.

!     Required        COS,SIN
!     resident
!     Routines

!***REFERENCES  P. N. Swarztrauber, Vectorizing the FFTs, in Parallel
!               Computations, (G. Rodrigue, ed.), Academic Press, 1982,
!               pp. 51-83.
!***ROUTINES CALLED  VRFTI1
!***END PROLOGUE  VRFFTI

!     VRFFTPK, VERSION 1, AUGUST 1985

      DIMENSION wsave(n+15)
!***FIRST EXECUTABLE STATEMENT  VRFFTI
      IF (n == 1) RETURN
      CALL vrfti1(n,wsave(1),wsave(n+1))
      RETURN
   END subroutine
   SUBROUTINE vrfti1(n,wa,fac)

!     VRFFTPK, VERSION 1, AUGUST 1985

      USE m_constants, ONLY : pimach
      DIMENSION wa(n),fac(15),ntryh(4)
      DATA ntryh(1),ntryh(2),ntryh(3),ntryh(4)/4,2,3,5/

      nl = n
      nf = 0
      j = 0
10    j = j + 1
      IF ( j <=4 ) THEN
         ntry = ntryh(j)
      ELSE
         ntry = ntry + 2
      ENDIF
40    nq = nl/ntry
      nr = nl - ntry*nq
      IF ( nr /= 0 ) THEN
         GOTO 10
      ENDIF
      nf = nf + 1
      fac(nf+2) = ntry
      nl = nq
      IF (ntry /= 2) GO TO 70
      IF (nf == 1) GO TO 70
      DO 60 i = 2,nf
         ib = nf - i + 2
         fac(ib+2) = fac(ib+1)
60    END DO
      fac(3) = 2
70    IF (nl /= 1) GO TO 40
      fac(1) = n
      fac(2) = nf
      tpi = 2.*pimach()
      argh = tpi/real(n)
      is = 0
      nfm1 = nf - 1
      l1 = 1
      IF (nfm1 == 0) RETURN
      DO 100 k1 = 1,nfm1
         ip = fac(k1+2)
         ld = 0
         l2 = l1*ip
         ido = n/l2
         ipm = ip - 1
         DO 90 j = 1,ipm
            ld = ld + l1
            i = is
            argld = real(ld)*argh
            fi = 0.
            DO 80 ii = 3,ido,2
               i = i + 2
               fi = fi + 1.
               arg = fi*argld
               wa(i-1) = cos(arg)
               wa(i) = sin(arg)
80          END DO
            is = is + ido
90       END DO
         l1 = l2
100   END DO
      RETURN
   END subroutine
   SUBROUTINE vrfftf(m,n,r,rt,mdimr,wsave)

!***BEGIN PROLOGUE  VRFFTF
!***DATE WRITTEN   850801   (YYMMDD)
!***REVISION DATE  900509   (YYMMDD)
!***CATEGORY NO.  J1A1
!***KEYWORDS  FAST FOURIER TRANSFORM, REAL PERIODIC TRANSFORM,
!             FOURIER ANALYSIS, FORWARD TRANSFORM, MULTIPLE SEQUENCES
!***AUTHOR  SWEET, R.A. (NIST) AND LINDGREN, L.L. (NIST)
!***PURPOSE  Forward real periodic transform, M sequences.
!***DESCRIPTION

!  Subroutine VRFFTF computes the Fourier coefficients (forward
!  transform) of a number of real periodic sequences.  Specifically,
!  for each sequence the subroutine claculates the independent
!  Fourier coefficients described below at output parameter R.

!  The array WSAVE which is used by subroutine VRFFTF must be
!  initialized by calling subroutine VRFFTI(N,WSAVE).

!  Input Parameters

!  M       the number of sequences to be transformed.

!  N       the length of the sequences to be transformed.  The method
!          is most efficient when N is a product of small primes,
!          however n may be any positive integer.

!  R       areal two-dimensional array of size MDIMX x N containing the
!          the sequences to be transformed.  The sequences are stored
!          in the ROWS of R.  Thus, the I-th sequence to be transformed,
!          X(I,J), J=0,1,...,N-1, is stored as

!               R(I,J) = X(I,J-1) , J=1, 2, . . . , N.

!  RT      a real two-dimensional work array of size MDIMX x N.

!  MDIMR   the row (or first) dimension of the arrays R and RT exactly
!          as they appear in the calling program.  This parameter is
!          used to specify the variable dimension of these arrays.

!  WSAVE   a real one-dimensional work array which must be dimensioned
!          at least N+15.  The WSAVE array must be initialized by
!          calling subroutine VRFFTI.  A different WSAVE array must be
!          used for each different value of N.  This initialization does
!          not have to be repeated so long as N remains unchanged.  The
!          same WSAVE array may be used by VRFFTF and VRFFTB.

!  Output Parameters

!  R       contains the Fourier coefficients F(K) for each of the M
!          input sequences.  Specifically, row I of R, R(I,J),
!          J=1,2,..,N, contains the independent Fourier coefficients
!          F(I,K), for the I-th input sequence stored as

!             R(I,1) = REAL( F(I,0) ),
!                    = SQRT(1/N)*SUM(J=0,N-1)[ X(I,J) ],

!             R(I,2*K) = REAL( F(I,K) )
!                      = SQRT(1/N)*SUM(J=0,N-1)[X(I,J)*COS(2J*K*PI/N)]

!             R(I,2*K+1) = IMAG( F(I,K) )
!                        =-SQRT(1/N)*SUM(J=0,N-1)[X(I,J)*SIN(2J*K*PI/N)]

!                   for K = 1, 2, . . . , M-1,

!              and, when N is even,

!              R(I,N) = REAL( F(I,N/2) ).
!                     = SQRT(1/N)*SUM(J=0,N-1)[ (-1)**J*X(I,J) ].

!  WSAVE   contains results which must not be destroyed between calls
!          to VRFFTF or VRFFTB.

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

!  NOTE  -  A call of VRFFTF followed immediately by a call of
!           of VRFFTB will return the original sequences R.  Thus,
!           VRFFTB is the correctly normalized inverse of VRFFTF.

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

!  VRFFTF is a straightforward extension of the subprogram RFFTF to
!  handle M simultaneous sequences.  RFFTF was originally developed
!  by P. N. Swarztrauber of NCAR.

!              * * * * * * * * * * * * * * * * * * * * *
!              *                                       *
!              *         PROGRAM SPECIFICATIONS        *
!              *                                       *
!              * * * * * * * * * * * * * * * * * * * * *

!     Dimension of    R(MDIMR,N), RT(MDIMR,N), WSAVE(N+15)
!     Arguments

!     Latest          AUGUST 1, 1985
!     Revision

!     Subprograms     VRFFTI, VRFTI1, VRFFTF, VRFTF1, VRADF2, VRADF3,
!     Required        VRADF4, VRADF5, VRADFG, VRFFTB, VRFTB1, VRADB2,
!                     VRADB3, VRADB4, VRADB5, VRADBG, PIMACH

!     Special         NONE
!     Conditions

!     Common          NONE
!     blocks

!     I/O             NONE

!     Precision       SINGLE

!     Specialist      ROLAND SWEET

!     Language        FORTRAN

!     History         WRITTEN BY LINDA LINDGREN AND ROLAND SWEET AT THE
!                     NATIONAL BUREAU OF STANDARDS (BOULDER).

!     Algorithm       A REAL VARIANT OF THE STOCKHAM AUTOSORT VERSION
!                     OF THE COOLEY-TUKEY FAST FOURIER TRANSFORM.

!     Portability     AMERICAN NATIONAL STANDARDS INSTITUTE FORTRAN 77.
!                     THE ONLY MACHINE DEPENDENT CONSTANT IS LOCATED IN
!                     THE FUNCTION PIMACH.

!     Required        COS,SIN
!     resident
!     Routines

!***REFERENCES  P. N. Swarztrauber, Vectorizing the FFTs, in Parallel
!               Computations, (G. Rodrigue, ed.), Academic Press, 1982,
!               pp. 51-83.
!***ROUTINES CALLED  VRFTF1
!***END PROLOGUE  VRFFTF

!     VRFFTPK, VERSION 1, AUGUST 1985

      DIMENSION r(mdimr,n),rt(mdimr,n),wsave(n+15)
!***FIRST EXECUTABLE STATEMENT  VRFFTF
      IF (n == 1) RETURN
      CALL vrftf1(m,n,r,rt,mdimr,wsave(1),wsave(n+1))
      RETURN
   END subroutine
   SUBROUTINE vradf2(mp,ido,l1,cc,ch,mdimc,wa1)

!     VRFFTPK, VERSION 1, AUGUST 1985

      DIMENSION ch(mdimc,ido,2,l1),cc(mdimc,ido,l1,2),wa1(ido)

      DO 20 k = 1,l1
         DO 10 m = 1,mp
            ch(m,1,1,k) = cc(m,1,k,1) + cc(m,1,k,2)
            ch(m,ido,2,k) = cc(m,1,k,1) - cc(m,1,k,2)
10       END DO
20    END DO
      IF ( ido ==  2 ) THEN
         GOTO 70
      ELSEIF ( ido < 2 ) THEN
         GOTO 100
      ENDIF
      idp2 = ido + 2
      DO 60 k = 1,l1
         DO 50 i = 3,ido,2
            ic = idp2 - i
            DO 40 m = 1,mp
               ch(m,i,1,k) = cc(m,i,k,1) + &
                             (wa1(i-2)*cc(m,i,k,2)-wa1(i-1)* &
                              cc(m,i-1,k,2))
               ch(m,ic,2,k) = (wa1(i-2)*cc(m,i,k,2)- &
                               wa1(i-1)*cc(m,i-1,k,2)) - cc(m,i,k,1)
               ch(m,i-1,1,k) = cc(m,i-1,k,1) + &
                               (wa1(i-2)*cc(m,i-1,k,2)+wa1(i-1)* &
                                cc(m,i,k,2))
               ch(m,ic-1,2,k) = cc(m,i-1,k,1) - &
                                (wa1(i-2)*cc(m,i-1,k,2)+wa1(i-1)* &
                                 cc(m,i,k,2))
40          END DO
50       END DO
60    END DO
      IF (mod(ido,2) == 1) RETURN
70    DO 90 k = 1,l1
         DO 80 m = 1,mp
            ch(m,1,2,k) = -cc(m,ido,k,2)
            ch(m,ido,1,k) = cc(m,ido,k,1)
80       END DO
90    END DO
100   RETURN
   END subroutine
   SUBROUTINE vradf3(mp,ido,l1,cc,ch,mdimc,wa1,wa2)

!     VRFFTPK, VERSION 1, AUGUST 1985

      USE m_constants, ONLY : pimach
      DIMENSION ch(mdimc,ido,3,l1),cc(mdimc,ido,l1,3),wa1(ido),wa2(ido)

      arg = 2.*pimach()/3.
      taur = cos(arg)
      taui = sin(arg)
      DO 20 k = 1,l1
         DO 10 m = 1,mp
            ch(m,1,1,k) = cc(m,1,k,1) + (cc(m,1,k,2)+cc(m,1,k,3))
            ch(m,1,3,k) = taui* (cc(m,1,k,3)-cc(m,1,k,2))
            ch(m,ido,2,k) = cc(m,1,k,1) + &
                            taur* (cc(m,1,k,2)+cc(m,1,k,3))
10       END DO
20    END DO
      IF (ido == 1) RETURN
      idp2 = ido + 2
      DO 50 k = 1,l1
         DO 40 i = 3,ido,2
            ic = idp2 - i
            DO 30 m = 1,mp
               ch(m,i-1,1,k) = cc(m,i-1,k,1) + &
               ((wa1(i-2)*cc(m,i-1,k,2)+wa1(i-1)*cc(m,i, &
               k,2))+ (wa2(i-2)*cc(m,i-1,k, &
               &                          3)+wa2(i-1)*cc(m,i,k,3)))
               ch(m,i,1,k) = cc(m,i,k,1) + &
               ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1,k, &
               &                        2))+ (wa2(i-2)*cc(m,i,k,3)-wa2(i-1)*cc(m, &
               i-1,k,3)))
               ch(m,i-1,3,k) = (cc(m,i-1,k,1)+ &
               taur* ((wa1(i-2)*cc(m,i-1,k, &
               &                          2)+wa1(i-1)*cc(m,i,k,2))+ (wa2(i-2)*cc(m, &
               i-1,k,3)+wa2(i-1)*cc(m,i,k,3)))) + &
               (taui* ((wa1(i-2)*cc(m,i,k, &
               &                          2)-wa1(i-1)*cc(m,i-1,k, &
               &                          2))- (wa2(i-2)*cc(m,i,k,3)-wa2(i-1)*cc(m, &
               i-1,k,3))))
               ch(m,ic-1,2,k) = (cc(m,i-1,k,1)+ &
               taur* ((wa1(i-2)*cc(m,i-1,k, &
               &                           2)+wa1(i-1)*cc(m,i,k, &
               &                           2))+ (wa2(i-2)*cc(m,i-1,k, &
               &                           3)+wa2(i-1)*cc(m,i,k,3)))) - &
               (taui* ((wa1(i-2)*cc(m,i,k, &
               &                           2)-wa1(i-1)*cc(m,i-1,k, &
               &                           2))- (wa2(i-2)*cc(m,i,k, &
               &                           3)-wa2(i-1)*cc(m,i-1,k,3))))
               ch(m,i,3,k) = (cc(m,i,k,1)+taur* &
               ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1,k, &
               &                        2))+ (wa2(i-2)*cc(m,i,k,3)-wa2(i-1)*cc(m, &
               i-1,k,3)))) + (taui* ((wa2(i-2)*cc(m,i-1,k, &
               &                        3)+wa2(i-1)*cc(m,i,k,3))- (wa1(i-2)*cc(m, &
               i-1,k,2)+wa1(i-1)*cc(m,i,k,2))))
               ch(m,ic,2,k) = (taui* ((wa2(i-2)*cc(m,i-1,k, &
               &                         3)+wa2(i-1)*cc(m,i,k,3))- (wa1(i-2)*cc(m, &
               i-1,k,2)+wa1(i-1)*cc(m,i,k,2)))) - &
               (cc(m,i,k,1)+taur* ((wa1(i-2)*cc(m,i,k, &
               &                         2)-wa1(i-1)*cc(m,i-1,k, &
               &                         2))+ (wa2(i-2)*cc(m,i,k,3)-wa2(i-1)*cc(m, &
               i-1,k,3))))
30          END DO
40       END DO
50    END DO
      RETURN
   END subroutine
   SUBROUTINE vradf4(mp,ido,l1,cc,ch,mdimc,wa1,wa2,wa3)

!     VRFFTPK, VERSION 1, AUGUST 1985

      DIMENSION cc(mdimc,ido,l1,4),ch(mdimc,ido,4,l1),wa1(ido),wa2(ido), &
         wa3(ido)

      hsqt2 = sqrt(2.)/2.
      DO 20 k = 1,l1
         DO 10 m = 1,mp
            ch(m,1,1,k) = (cc(m,1,k,2)+cc(m,1,k,4)) + &
                          (cc(m,1,k,1)+cc(m,1,k,3))
            ch(m,ido,4,k) = (cc(m,1,k,1)+cc(m,1,k,3)) - &
                            (cc(m,1,k,2)+cc(m,1,k,4))
            ch(m,ido,2,k) = cc(m,1,k,1) - cc(m,1,k,3)
            ch(m,1,3,k) = cc(m,1,k,4) - cc(m,1,k,2)
10       END DO
20    END DO
      IF ( ido ==  2 ) THEN
         GOTO 70
      ELSEIF ( ido < 2 ) THEN
         GOTO 100
      ENDIF
      idp2 = ido + 2
      DO 60 k = 1,l1
         DO 50 i = 3,ido,2
            ic = idp2 - i
            DO 40 m = 1,mp
               ch(m,i-1,1,k) = ((wa1(i-2)*cc(m,i-1,k,2)+wa1(i-1)*cc(m,i, &
               k,2))+ (wa3(i-2)*cc(m,i-1,k, &
               &                          4)+wa3(i-1)*cc(m,i,k,4))) + &
               (cc(m,i-1,k,1)+ (wa2(i-2)*cc(m,i-1,k, &
               &                          3)+wa2(i-1)*cc(m,i,k,3)))
               ch(m,ic-1,4,k) = (cc(m,i-1,k,1)+ &
               (wa2(i-2)*cc(m,i-1,k,3)+wa2(i-1)*cc(m,i, &
               k,3))) - ((wa1(i-2)*cc(m,i-1,k, &
               &                           2)+wa1(i-1)*cc(m,i,k,2))+ &
               (wa3(i-2)*cc(m,i-1,k,4)+wa3(i-1)*cc(m,i, &
               k,4)))
               ch(m,i,1,k) = ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1,k, &
               &                        2))+ (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m, &
               i-1,k,4))) + (cc(m,i,k,1)+ &
               (wa2(i-2)*cc(m,i,k,3)-wa2(i-1)*cc(m,i-1,k, &
               &                        3)))
               ch(m,ic,4,k) = ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1, &
               k,2))+ (wa3(i-2)*cc(m,i,k, &
               &                         4)-wa3(i-1)*cc(m,i-1,k,4))) - &
               (cc(m,i,k,1)+ (wa2(i-2)*cc(m,i,k, &
               &                         3)-wa2(i-1)*cc(m,i-1,k,3)))
               ch(m,i-1,3,k) = ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1, &
               k,2))- (wa3(i-2)*cc(m,i,k, &
               &                          4)-wa3(i-1)*cc(m,i-1,k,4))) + &
               (cc(m,i-1,k,1)- (wa2(i-2)*cc(m,i-1,k, &
               &                          3)+wa2(i-1)*cc(m,i,k,3)))
               ch(m,ic-1,2,k) = (cc(m,i-1,k,1)- &
               (wa2(i-2)*cc(m,i-1,k,3)+wa2(i-1)*cc(m,i, &
               k,3))) - ((wa1(i-2)*cc(m,i,k, &
               &                           2)-wa1(i-1)*cc(m,i-1,k,2))- &
               (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m,i-1, &
               k,4)))
               ch(m,i,3,k) = ((wa3(i-2)*cc(m,i-1,k,4)+wa3(i-1)*cc(m,i,k, &
               &                        4))- (wa1(i-2)*cc(m,i-1,k,2)+wa1(i-1)*cc(m, &
               i,k,2))) + (cc(m,i,k,1)- &
               (wa2(i-2)*cc(m,i,k,3)-wa2(i-1)*cc(m,i-1,k, &
               &                        3)))
               ch(m,ic,2,k) = ((wa3(i-2)*cc(m,i-1,k,4)+wa3(i-1)*cc(m,i, &
               k,4))- (wa1(i-2)*cc(m,i-1,k, &
               &                         2)+wa1(i-1)*cc(m,i,k,2))) - &
               (cc(m,i,k,1)- (wa2(i-2)*cc(m,i,k, &
               &                         3)-wa2(i-1)*cc(m,i-1,k,3)))
40          END DO
50       END DO
60    END DO
      IF (mod(ido,2) == 1) RETURN
70    CONTINUE
      DO 90 k = 1,l1
         DO 80 m = 1,mp
            ch(m,ido,1,k) = (hsqt2* (cc(m,ido,k,2)-cc(m,ido,k,4))) + &
                            cc(m,ido,k,1)
            ch(m,ido,3,k) = cc(m,ido,k,1) - &
                            (hsqt2* (cc(m,ido,k,2)-cc(m,ido,k,4)))
            ch(m,1,2,k) = (-hsqt2* (cc(m,ido,k,2)+cc(m,ido,k,4))) - &
                          cc(m,ido,k,3)
            ch(m,1,4,k) = (-hsqt2* (cc(m,ido,k,2)+cc(m,ido,k,4))) + &
                          cc(m,ido,k,3)
80       END DO
90    END DO
100   RETURN
   END subroutine
   SUBROUTINE vradf5(mp,ido,l1,cc,ch,mdimc,wa1,wa2,wa3,wa4)

!     VRFFTPK, VERSION 1, AUGUST 1985

      USE m_constants, ONLY : pimach
      DIMENSION cc(mdimc,ido,l1,5),ch(mdimc,ido,5,l1),wa1(ido),wa2(ido), &
         wa3(ido),wa4(ido)

      arg = 2.*pimach()/5.
      tr11 = cos(arg)
      ti11 = sin(arg)
      tr12 = cos(2.*arg)
      ti12 = sin(2.*arg)
      DO 20 k = 1,l1
         DO 10 m = 1,mp
            ch(m,1,1,k) = cc(m,1,k,1) + (cc(m,1,k,5)+cc(m,1,k,2)) + &
                          (cc(m,1,k,4)+cc(m,1,k,3))
            ch(m,ido,2,k) = cc(m,1,k,1) + &
                            tr11* (cc(m,1,k,5)+cc(m,1,k,2)) + &
                            tr12* (cc(m,1,k,4)+cc(m,1,k,3))
            ch(m,1,3,k) = ti11* (cc(m,1,k,5)-cc(m,1,k,2)) + &
                          ti12* (cc(m,1,k,4)-cc(m,1,k,3))
            ch(m,ido,4,k) = cc(m,1,k,1) + &
                            tr12* (cc(m,1,k,5)+cc(m,1,k,2)) + &
                            tr11* (cc(m,1,k,4)+cc(m,1,k,3))
            ch(m,1,5,k) = ti12* (cc(m,1,k,5)-cc(m,1,k,2)) - &
                          ti11* (cc(m,1,k,4)-cc(m,1,k,3))
10       END DO
20    END DO
      IF (ido == 1) RETURN
      idp2 = ido + 2
      DO 50 k = 1,l1
         DO 40 i = 3,ido,2
            ic = idp2 - i
            DO 30 m = 1,mp
               ch(m,i-1,1,k) = cc(m,i-1,k,1) + &
               ((wa1(i-2)*cc(m,i-1,k,2)+wa1(i-1)*cc(m,i, &
               k,2))+ (wa4(i-2)*cc(m,i-1,k, &
               &                          5)+wa4(i-1)*cc(m,i,k,5))) + &
               ((wa2(i-2)*cc(m,i-1,k,3)+wa2(i-1)*cc(m,i, &
               k,3))+ (wa3(i-2)*cc(m,i-1,k, &
               &                          4)+wa3(i-1)*cc(m,i,k,4)))
               ch(m,i,1,k) = cc(m,i,k,1) + &
               ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1,k, &
               &                        2))+ (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5))) + ((wa2(i-2)*cc(m,i,k, &
               &                        3)-wa2(i-1)*cc(m,i-1,k,3))+ &
               (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m,i-1,k, &
               &                        4)))
               ch(m,i-1,3,k) = cc(m,i-1,k,1) + &
                               tr11* (wa1(i-2)*cc(m,i-1,k,2)+ &
                                      wa1(i-1)*cc(m,i,k,2)+ &
                                      wa4(i-2)*cc(m,i-1,k,5)+ &
                                      wa4(i-1)*cc(m,i,k,5)) + &
                               tr12* (wa2(i-2)*cc(m,i-1,k,3)+ &
                                      wa2(i-1)*cc(m,i,k,3)+ &
                                      wa3(i-2)*cc(m,i-1,k,4)+ &
                                      wa3(i-1)*cc(m,i,k,4)) + &
                               ti11* (wa1(i-2)*cc(m,i,k,2)- &
                                      wa1(i-1)*cc(m,i-1,k,2)- &
                                      (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m,i-1, &
                                                                        k,5))) + ti12* (wa2(i-2)*cc(m,i,k,3)- &
                                                                                        wa2(i-1)*cc(m,i-1,k,3)- &
                                                                                        (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m,i-1, &
                                                                                                                          k,4)))
               ch(m,ic-1,2,k) = cc(m,i-1,k,1) + &
               tr11* (wa1(i-2)*cc(m,i-1,k,2)+ &
               wa1(i-1)*cc(m,i,k,2)+ &
               wa4(i-2)*cc(m,i-1,k,5)+ &
               wa4(i-1)*cc(m,i,k,5)) + &
               tr12* (wa2(i-2)*cc(m,i-1,k,3)+ &
               wa2(i-1)*cc(m,i,k,3)+ &
               wa3(i-2)*cc(m,i-1,k,4)+ &
               wa3(i-1)*cc(m,i,k,4)) - &
               (ti11* (wa1(i-2)*cc(m,i,k, &
               &                           2)-wa1(i-1)*cc(m,i-1,k, &
               &                           2)- (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5)))+ti12* (wa2(i-2)*cc(m,i,k, &
               &                           3)-wa2(i-1)*cc(m,i-1,k, &
               &                           3)- (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m, &
               i-1,k,4))))
               ch(m,i,3,k) = (cc(m,i,k,1)+tr11* &
               ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1,k, &
               &                        2))+ (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5)))+tr12* ((wa2(i-2)*cc(m,i,k, &
               &                        3)-wa2(i-1)*cc(m,i-1,k,3))+ (wa3(i-2)*cc(m, &
               i,k,4)-wa3(i-1)*cc(m,i-1,k,4)))) + &
               (ti11* ((wa4(i-2)*cc(m,i-1,k, &
               &                        5)+wa4(i-1)*cc(m,i,k,5))- (wa1(i-2)*cc(m, &
               i-1,k,2)+wa1(i-1)*cc(m,i,k,2)))+ &
               ti12* ((wa3(i-2)*cc(m,i-1,k, &
               &                        4)+wa3(i-1)*cc(m,i,k,4))- (wa2(i-2)*cc(m, &
               i-1,k,3)+wa2(i-1)*cc(m,i,k,3))))
               ch(m,ic,2,k) = (ti11* ((wa4(i-2)*cc(m,i-1,k, &
               &                         5)+wa4(i-1)*cc(m,i,k,5))- (wa1(i-2)*cc(m, &
               i-1,k,2)+wa1(i-1)*cc(m,i,k,2)))+ &
               ti12* ((wa3(i-2)*cc(m,i-1,k, &
               &                         4)+wa3(i-1)*cc(m,i,k,4))- (wa2(i-2)*cc(m, &
               i-1,k,3)+wa2(i-1)*cc(m,i,k,3)))) - &
               (cc(m,i,k,1)+tr11* ((wa1(i-2)*cc(m,i,k, &
               &                         2)-wa1(i-1)*cc(m,i-1,k, &
               &                         2))+ (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5)))+tr12* ((wa2(i-2)*cc(m,i,k, &
               &                         3)-wa2(i-1)*cc(m,i-1,k, &
               &                         3))+ (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m, &
               i-1,k,4))))
               ch(m,i-1,5,k) = (cc(m,i-1,k,1)+ &
               tr12* ((wa1(i-2)*cc(m,i-1,k, &
               &                          2)+wa1(i-1)*cc(m,i,k,2))+ (wa4(i-2)*cc(m, &
               i-1,k,5)+wa4(i-1)*cc(m,i,k,5)))+ &
               tr11* ((wa2(i-2)*cc(m,i-1,k, &
               &                          3)+wa2(i-1)*cc(m,i,k,3))+ (wa3(i-2)*cc(m, &
               i-1,k,4)+wa3(i-1)*cc(m,i,k,4)))) + &
               (ti12* ((wa1(i-2)*cc(m,i,k, &
               &                          2)-wa1(i-1)*cc(m,i-1,k, &
               &                          2))- (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5)))-ti11* ((wa2(i-2)*cc(m,i,k, &
               &                          3)-wa2(i-1)*cc(m,i-1,k, &
               &                          3))- (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m, &
               i-1,k,4))))
               ch(m,ic-1,4,k) = (cc(m,i-1,k,1)+ &
               tr12* ((wa1(i-2)*cc(m,i-1,k, &
               &                           2)+wa1(i-1)*cc(m,i,k, &
               &                           2))+ (wa4(i-2)*cc(m,i-1,k, &
               &                           5)+wa4(i-1)*cc(m,i,k,5)))+ &
               tr11* ((wa2(i-2)*cc(m,i-1,k, &
               &                           3)+wa2(i-1)*cc(m,i,k, &
               &                           3))+ (wa3(i-2)*cc(m,i-1,k, &
               &                           4)+wa3(i-1)*cc(m,i,k,4)))) - &
               (ti12* ((wa1(i-2)*cc(m,i,k, &
               &                           2)-wa1(i-1)*cc(m,i-1,k, &
               &                           2))- (wa4(i-2)*cc(m,i,k, &
               &                           5)-wa4(i-1)*cc(m,i-1,k,5)))- &
               ti11* ((wa2(i-2)*cc(m,i,k, &
               &                           3)-wa2(i-1)*cc(m,i-1,k, &
               &                           3))- (wa3(i-2)*cc(m,i,k, &
               &                           4)-wa3(i-1)*cc(m,i-1,k,4))))
               ch(m,i,5,k) = (cc(m,i,k,1)+tr12* &
               ((wa1(i-2)*cc(m,i,k,2)-wa1(i-1)*cc(m,i-1,k, &
               &                        2))+ (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5)))+tr11* ((wa2(i-2)*cc(m,i,k, &
               &                        3)-wa2(i-1)*cc(m,i-1,k,3))+ (wa3(i-2)*cc(m, &
               i,k,4)-wa3(i-1)*cc(m,i-1,k,4)))) + &
               (ti12* ((wa4(i-2)*cc(m,i-1,k, &
               &                        5)+wa4(i-1)*cc(m,i,k,5))- (wa1(i-2)*cc(m, &
               i-1,k,2)+wa1(i-1)*cc(m,i,k,2)))- &
               ti11* ((wa3(i-2)*cc(m,i-1,k, &
               &                        4)+wa3(i-1)*cc(m,i,k,4))- (wa2(i-2)*cc(m, &
               i-1,k,3)+wa2(i-1)*cc(m,i,k,3))))
               ch(m,ic,4,k) = (ti12* ((wa4(i-2)*cc(m,i-1,k, &
               &                         5)+wa4(i-1)*cc(m,i,k,5))- (wa1(i-2)*cc(m, &
               i-1,k,2)+wa1(i-1)*cc(m,i,k,2)))- &
               ti11* ((wa3(i-2)*cc(m,i-1,k, &
               &                         4)+wa3(i-1)*cc(m,i,k,4))- (wa2(i-2)*cc(m, &
               i-1,k,3)+wa2(i-1)*cc(m,i,k,3)))) - &
               (cc(m,i,k,1)+tr12* ((wa1(i-2)*cc(m,i,k, &
               &                         2)-wa1(i-1)*cc(m,i-1,k, &
               &                         2))+ (wa4(i-2)*cc(m,i,k,5)-wa4(i-1)*cc(m, &
               i-1,k,5)))+tr11* ((wa2(i-2)*cc(m,i,k, &
               &                         3)-wa2(i-1)*cc(m,i-1,k, &
               &                         3))+ (wa3(i-2)*cc(m,i,k,4)-wa3(i-1)*cc(m, &
               i-1,k,4))))
30          END DO
40       END DO
50    END DO
      RETURN
   END subroutine
   SUBROUTINE vradfg(mp,ido,ip,l1,idl1,cc,c1,c2,ch,ch2,mdimc,wa)

!     VRFFTPK, VERSION 1, AUGUST 1985

      USE m_constants, ONLY : pimach
      DIMENSION ch(mdimc,ido,l1,ip),cc(mdimc,ido,ip,l1), &
         c1(mdimc,ido,l1,ip),c2(mdimc,idl1,ip), &
         ch2(mdimc,idl1,ip),wa(ido)

      tpi = 2.*pimach()
      arg = tpi/real(ip)
      dcp = cos(arg)
      dsp = sin(arg)
      ipph = (ip+1)/2
      ipp2 = ip + 2
      idp2 = ido + 2
      nbd = (ido-1)/2
      IF (ido == 1) GO TO 250
      DO 20 ik = 1,idl1
         DO 10 m = 1,mp
            ch2(m,ik,1) = c2(m,ik,1)
10       END DO
20    END DO
      DO 50 j = 2,ip
         DO 40 k = 1,l1
            DO 30 m = 1,mp
               ch(m,1,k,j) = c1(m,1,k,j)
30          END DO
40       END DO
50    END DO
      IF (nbd > l1) GO TO 100
      is = -ido
      DO 90 j = 2,ip
         is = is + ido
         idij = is
         DO 80 i = 3,ido,2
            idij = idij + 2
            DO 70 k = 1,l1
               DO 60 m = 1,mp
                  ch(m,i-1,k,j) = wa(idij-1)*c1(m,i-1,k,j) + &
                                  wa(idij)*c1(m,i,k,j)
                  ch(m,i,k,j) = wa(idij-1)*c1(m,i,k,j) - &
                                wa(idij)*c1(m,i-1,k,j)
60             END DO
70          END DO
80       END DO
90    END DO
      GO TO 150
100   is = -ido
      DO 140 j = 2,ip
         is = is + ido
         DO 130 k = 1,l1
            idij = is
            DO 120 i = 3,ido,2
               idij = idij + 2
               DO 110 m = 1,mp
                  ch(m,i-1,k,j) = wa(idij-1)*c1(m,i-1,k,j) + &
                                  wa(idij)*c1(m,i,k,j)
                  ch(m,i,k,j) = wa(idij-1)*c1(m,i,k,j) - &
                                wa(idij)*c1(m,i-1,k,j)
110            END DO
120         END DO
130      END DO
140   END DO
150   IF (nbd < l1) GO TO 200
      DO 190 j = 2,ipph
         jc = ipp2 - j
         DO 180 k = 1,l1
            DO 170 i = 3,ido,2
               DO 160 m = 1,mp
                  c1(m,i-1,k,j) = ch(m,i-1,k,j) + ch(m,i-1,k,jc)
                  c1(m,i-1,k,jc) = ch(m,i,k,j) - ch(m,i,k,jc)
                  c1(m,i,k,j) = ch(m,i,k,j) + ch(m,i,k,jc)
                  c1(m,i,k,jc) = ch(m,i-1,k,jc) - ch(m,i-1,k,j)
160            END DO
170         END DO
180      END DO
190   END DO
      GO TO 280
200   DO 240 j = 2,ipph
         jc = ipp2 - j
         DO 230 i = 3,ido,2
            DO 220 k = 1,l1
               DO 210 m = 1,mp
                  c1(m,i-1,k,j) = ch(m,i-1,k,j) + ch(m,i-1,k,jc)
                  c1(m,i-1,k,jc) = ch(m,i,k,j) - ch(m,i,k,jc)
                  c1(m,i,k,j) = ch(m,i,k,j) + ch(m,i,k,jc)
                  c1(m,i,k,jc) = ch(m,i-1,k,jc) - ch(m,i-1,k,j)
210            END DO
220         END DO
230      END DO
240   END DO
      GO TO 280
250   DO 270 ik = 1,idl1
         DO 260 m = 1,mp
            c2(m,ik,1) = ch2(m,ik,1)
260      END DO
270   END DO
280   DO 310 j = 2,ipph
         jc = ipp2 - j
         DO 300 k = 1,l1
            DO 290 m = 1,mp
               c1(m,1,k,j) = ch(m,1,k,j) + ch(m,1,k,jc)
               c1(m,1,k,jc) = ch(m,1,k,jc) - ch(m,1,k,j)
290         END DO
300      END DO
310   END DO

      ar1 = 1.
      ai1 = 0.
      DO 370 l = 2,ipph
         lc = ipp2 - l
         ar1h = dcp*ar1 - dsp*ai1
         ai1 = dcp*ai1 + dsp*ar1
         ar1 = ar1h
         DO 330 ik = 1,idl1
            DO 320 m = 1,mp
               ch2(m,ik,l) = c2(m,ik,1) + ar1*c2(m,ik,2)
               ch2(m,ik,lc) = ai1*c2(m,ik,ip)
320         END DO
330      END DO
         dc2 = ar1
         ds2 = ai1
         ar2 = ar1
         ai2 = ai1
         DO 360 j = 3,ipph
            jc = ipp2 - j
            ar2h = dc2*ar2 - ds2*ai2
            ai2 = dc2*ai2 + ds2*ar2
            ar2 = ar2h
            DO 350 ik = 1,idl1
               DO 340 m = 1,mp
                  ch2(m,ik,l) = ch2(m,ik,l) + ar2*c2(m,ik,j)
                  ch2(m,ik,lc) = ch2(m,ik,lc) + ai2*c2(m,ik,jc)
340            END DO
350         END DO
360      END DO
370   END DO
      DO 400 j = 2,ipph
         DO 390 ik = 1,idl1
            DO 380 m = 1,mp
               ch2(m,ik,1) = ch2(m,ik,1) + c2(m,ik,j)
380         END DO
390      END DO
400   END DO

      IF (ido < l1) GO TO 440
      DO 430 k = 1,l1
         DO 420 i = 1,ido
            DO 410 m = 1,mp
               cc(m,i,1,k) = ch(m,i,k,1)
410         END DO
420      END DO
430   END DO
      GO TO 480
440   DO 470 i = 1,ido
         DO 460 k = 1,l1
            DO 450 m = 1,mp
               cc(m,i,1,k) = ch(m,i,k,1)
450         END DO
460      END DO
470   END DO
480   DO 510 j = 2,ipph
         jc = ipp2 - j
         j2 = j + j
         DO 500 k = 1,l1
            DO 490 m = 1,mp
               cc(m,ido,j2-2,k) = ch(m,1,k,j)
               cc(m,1,j2-1,k) = ch(m,1,k,jc)
490         END DO
500      END DO
510   END DO
      IF (ido == 1) RETURN
      IF (nbd < l1) GO TO 560
      DO 550 j = 2,ipph
         jc = ipp2 - j
         j2 = j + j
         DO 540 k = 1,l1
            DO 530 i = 3,ido,2
               ic = idp2 - i
               DO 520 m = 1,mp
                  cc(m,i-1,j2-1,k) = ch(m,i-1,k,j) + ch(m,i-1,k,jc)
                  cc(m,ic-1,j2-2,k) = ch(m,i-1,k,j) - ch(m,i-1,k,jc)
                  cc(m,i,j2-1,k) = ch(m,i,k,j) + ch(m,i,k,jc)
                  cc(m,ic,j2-2,k) = ch(m,i,k,jc) - ch(m,i,k,j)
520            END DO
530         END DO
540      END DO
550   END DO
      RETURN
560   DO 600 j = 2,ipph
         jc = ipp2 - j
         j2 = j + j
         DO 590 i = 3,ido,2
            ic = idp2 - i
            DO 580 k = 1,l1
               DO 570 m = 1,mp
                  cc(m,i-1,j2-1,k) = ch(m,i-1,k,j) + ch(m,i-1,k,jc)
                  cc(m,ic-1,j2-2,k) = ch(m,i-1,k,j) - ch(m,i-1,k,jc)
                  cc(m,i,j2-1,k) = ch(m,i,k,j) + ch(m,i,k,jc)
                  cc(m,ic,j2-2,k) = ch(m,i,k,jc) - ch(m,i,k,j)
570            END DO
580         END DO
590      END DO
600   END DO
      RETURN
   END subroutine
   SUBROUTINE vrftf1(m,n,c,ch,mdimc,wa,fac)

!     VRFFTPK, VERSION 1, AUGUST 1985

      DIMENSION ch(mdimc,n),c(mdimc,n),wa(n),fac(15)

      nf = fac(2)
      na = 1
      l2 = n
      iw = n
      DO 110 k1 = 1,nf
         kh = nf - k1
         ip = fac(kh+3)
         l1 = l2/ip
         ido = n/l2
         idl1 = ido*l1
         iw = iw - (ip-1)*ido
         na = 1 - na
         IF (ip /= 4) GO TO 20
         ix2 = iw + ido
         ix3 = ix2 + ido
         IF (na /= 0) GO TO 10
         CALL vradf4(m,ido,l1,c,ch,mdimc,wa(iw),wa(ix2),wa(ix3))
         GO TO 100
10       CALL vradf4(m,ido,l1,ch,c,mdimc,wa(iw),wa(ix2),wa(ix3))
         GO TO 100
20       IF (ip /= 2) GO TO 40
         IF (na /= 0) GO TO 30
         CALL vradf2(m,ido,l1,c,ch,mdimc,wa(iw))
         GO TO 100
30       CALL vradf2(m,ido,l1,ch,c,mdimc,wa(iw))
         GO TO 100
40       IF (ip /= 3) GO TO 60
         ix2 = iw + ido
         IF (na /= 0) GO TO 50
         CALL vradf3(m,ido,l1,c,ch,mdimc,wa(iw),wa(ix2))
         GO TO 100
50       CALL vradf3(m,ido,l1,ch,c,mdimc,wa(iw),wa(ix2))
         GO TO 100
60       IF (ip /= 5) GO TO 80
         ix2 = iw + ido
         ix3 = ix2 + ido
         ix4 = ix3 + ido
         IF (na /= 0) GO TO 70
         CALL vradf5(m,ido,l1,c,ch,mdimc,wa(iw),wa(ix2),wa(ix3),wa(ix4))
         GO TO 100
70       CALL vradf5(m,ido,l1,ch,c,mdimc,wa(iw),wa(ix2),wa(ix3),wa(ix4))
         GO TO 100
80       IF (ido == 1) na = 1 - na
         IF (na /= 0) GO TO 90
         CALL vradfg(m,ido,ip,l1,idl1,c,c,c,ch,ch,mdimc,wa(iw))
         na = 1
         GO TO 100
90       CALL vradfg(m,ido,ip,l1,idl1,ch,ch,ch,c,c,mdimc,wa(iw))
         na = 0
100      l2 = l1
110   END DO
      scale = sqrt(1./n)
      IF (na == 1) GO TO 140
      DO 130 j = 1,n
         DO 120 i = 1,m
            c(i,j) = scale*ch(i,j)
120      END DO
130   END DO
      RETURN
140   DO 160 j = 1,n
         DO 150 i = 1,m
            c(i,j) = scale*c(i,j)
150      END DO
160   END DO
      RETURN
   END subroutine

   SUBROUTINE vrfftb(m,n,r,rt,mdimr,wsave)
!***BEGIN PROLOGUE  VRFFTB
!***DATE WRITTEN   850801   (YYMMDD)
!***REVISION DATE  900509   (YYMMDD)
!***CATEGORY NO.  J1A1
!***KEYWORDS  FAST FOURIER TRANSFORM, REAL PERIODIC TRANSFORM,
!             FOURIER SYNTHESIS, BACKWARD TRANSFORM, MULTIPLE SEQUENCES
!***AUTHOR  SWEET, R.A. (NIST) AND LINDGREN, L.L. (NIST)
!***PURPOSE  Backward real periodic transform, M sequences.
!***DESCRIPTION

!  Subroutine VRFFTB computes the synthesis (backward transform) of a
!  number of real periodic sequences from their Fourier coefficients.
!  Specifically, for each set of independent Fourier coefficients
!  F(K), the corresponding real periodic sequence is computed.

!  The array WSAVE which is used by subroutine VRFFTB must be
!  initialized by calling subroutine VRFFTI(N,WSAVE).

!  Input Parameters

!  M       the number of sets of coefficients.

!  N       the length of the sequences of coefficients to be
!          transformed.  The method is most efficient when N is a
!          product of small primes, however n may be any positive
!          integer.

!  R       areal two-dimensional array of size MDIMX x N containing the
!          coefficients to be transformed.  Each set of coefficients
!          F(K), K\0,1,..,N-1, is stored as a ROW of R.  Specifically,
!          the I-th set of independent Fourier coefficients is stored

!                R(I,1) = REAL( F(I,0) ),

!                R(I,2*K) = REAL( F(I,K) )

!                R(I,2*K+1) = IMAG( F(I,K) )

!                   for K = 1, 2, . . . , M-1,

!                and, when N is even,

!                R(I,N) = REAL( F(I,N/2) ).

!  RT      a real two-dimensional work array of size MDIMX x N.

!  MDIMR   the row (or first) dimension of the arrays R and RT exactly
!          as they appear in the calling program.  This parameter is
!          used to specify the variable dimension of these arrays.

!  WSAVE   a real one-dimensional work array which must be dimensioned
!          at least N+15.  The WSAVE array must be initialized by
!          calling subroutine VRFFTI.  A different WSAVE array must be
!          used for each different value of N.  This initialization does
!          not have to be repeated so long as N remains unchanged.  The
!          same WSAVE array may be used by VRFFTB and VRFFTB.

!  Output Parameters

!  R       contains M real periodic sequences corresponding to the given
!          coefficients.  Specifically, the I-th row of R contains the
!          real periodic sequence corresponding to the I-th set of
!          independent Fourier coefficients F(I,K) stored as

!               R(I,J) = X(I,J-1) ,   J = 1, 2, . . . , N, where

!               X(I,J) = SQRT(1/N)* F(I,0) + (-1)**J*F(I,N/2)
!                        + 2*SUM(K=1,M)[ REAL(F(I,2K))*COS(2K*J*PI/N)
!                        - IMAG(F(I,2K+1))*SIN(2K*J*PI/N) ]  ,

!                 when N is even, and

!               X(I,J) = SQRT(1/N)* F(I,0) +
!                        2*SUM(K=1,M)[ REAL(F(I,2K))*COS(2K*J*PI/N)
!                        - IMAG(F(I,2K+1))*SIN(2K*J*PI/N) ]  ,

!                 when N is odd.

!  WSAVE   contains results which must not be destroyed between calls
!          to VRFFTF or VRFFTB.

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

!  NOTE  -  A call of VRFFTF followed immediately by a call of
!           of VRFFTB will return the original sequences R.  Thus,
!           VRFFTB is the correctly normalized inverse of VRFFTF.

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

!  VRFFTB is a straightforward extension of the subprogram RFFTB to
!  handle M simultaneous sequences.  RFFTB was originally developed
!  by P. N. Swarztrauber of NCAR.

!              * * * * * * * * * * * * * * * * * * * * *
!              *                                       *
!              *         PROGRAM SPECIFICATIONS        *
!              *                                       *
!              * * * * * * * * * * * * * * * * * * * * *

!     Dimension of    R(MDIMR,N), RT(MDIMR,N), WSAVE(N+15)
!     Arguments

!     Latest          AUGUST 1, 1985
!     Revision

!     Subprograms     VRFFTI, VRFTI1, VRFFTF, VRFTF1, VRADF2, VRADF3,
!     required        VRADF4, VRADF5, VRADFG, VRFFTB, VRFTB1, VRADB2,
!                     VRADB3, VRADB4, VRADB5, VRADBG, PIMACH

!     Special         NONE
!     Conditions

!     Common          NONE
!     blocks

!     I/O             NONE

!     Precision       SINGLE

!     Specialist      ROLAND SWEET

!     Language        FORTRAN

!     History         WRITTEN BY LINDA LINDGREN AND ROLAND SWEET AT THE
!                     NATIONAL BUREAU OF STANDARDS (BOULDER).

!     Algorithm       A REAL VARIANT OF THE STOCKHAM AUTOSORT VERSION
!                     OF THE COOLEY-TUKEY FAST FOURIER TRANSFORM.

!     Portability     AMERICAN NATIONAL STANDARDS INSTITUTE FORTRAN 77.
!                     THE ONLY MACHINE DEPENDENT CONSTANT IS LOCATED IN
!                     THE FUNCTION PIMACH.

!     Required        COS,SIN
!     resident
!     Routines

!***REFERENCES  P. N. Swarztrauber, Vectorizing the FFTs, in Parallel
!               Computations, (G. Rodrigue, ed.), Academic Press, 1982,
!               pp. 51-83.
!***ROUTINES CALLED  VRFTB1
!***END PROLOGUE  VRFFTB

!     VRFFTPK, VERSION 1, AUGUST 1985

      IMPLICIT NONE
      INTEGER, INTENT(IN) :: n, m, mdimr
      REAL :: r(mdimr,n),rt(mdimr,n),wsave(n+15)

      IF (n == 1) RETURN
      CALL vrftb1(m,n,r,rt,mdimr,wsave(1),wsave(n+1))
      RETURN

   CONTAINS

      SUBROUTINE vradb2(mp,ido,l1,cc,ch,mdimc,wa1)

!     VRFFTPK, VERSION 1, AUGUST 1985

         IMPLICIT NONE
         INTEGER, INTENT(IN) :: mp, ido, l1, mdimc
         REAL, INTENT(IN)    :: cc(mdimc,ido,2,l1), wa1(ido)
         REAL, INTENT(INOUT) :: ch(mdimc,ido,l1,2)

         INTEGER :: i, m, k, ic, idp2

         DO 20 k = 1,l1
            DO 10 m = 1,mp
               ch(m,1,k,1) = cc(m,1,1,k) + cc(m,ido,2,k)
               ch(m,1,k,2) = cc(m,1,1,k) - cc(m,ido,2,k)
10          END DO
20       END DO
         IF ( ido ==  2 ) THEN
            GOTO 70
         ELSEIF ( ido < 2 ) THEN
            GOTO 100
         ENDIF
         idp2 = ido + 2
         DO 60 k = 1,l1
            DO 50 i = 3,ido,2
               ic = idp2 - i
               DO 40 m = 1,mp
                  ch(m,i-1,k,1) = cc(m,i-1,1,k) + cc(m,ic-1,2,k)
                  ch(m,i,k,1) = cc(m,i,1,k) - cc(m,ic,2,k)
                  ch(m,i-1,k,2) = wa1(i-2)* (cc(m,i-1,1,k)- &
                                             cc(m,ic-1,2,k)) - wa1(i-1)* &
                                  (cc(m,i,1,k)+cc(m,ic,2,k))
                  ch(m,i,k,2) = wa1(i-2)* (cc(m,i,1,k)+cc(m,ic,2,k)) + &
                                wa1(i-1)* (cc(m,i-1,1,k)-cc(m,ic-1,2,k))
40             END DO
50          END DO
60       END DO
         IF (mod(ido,2) == 1) RETURN
70       DO 90 k = 1,l1
            DO 80 m = 1,mp
               ch(m,ido,k,1) = cc(m,ido,1,k) + cc(m,ido,1,k)
               ch(m,ido,k,2) = - (cc(m,1,2,k)+cc(m,1,2,k))
80          END DO
90       END DO
100      RETURN
      END SUBROUTINE vradb2

      SUBROUTINE vradb3(mp,ido,l1,cc,ch,mdimc,wa1,wa2)

!     VRFFTPK, VERSION 1, AUGUST 1985

         USE m_constants, ONLY : pimach
         IMPLICIT NONE
         INTEGER, INTENT(IN) :: mp, ido, l1, mdimc
         REAL, INTENT(IN)    :: cc(mdimc,ido,3,l1), wa1(ido), wa2(ido)
         REAL, INTENT(INOUT) :: ch(mdimc,ido,l1,3)

         INTEGER :: i, k, idp2, ic, m
         REAL :: arg, taur, taui

         arg = 2.*pimach()/3.
         taur = cos(arg)
         taui = sin(arg)
         DO 20 k = 1,l1
            DO 10 m = 1,mp
               ch(m,1,k,1) = cc(m,1,1,k) + 2.*cc(m,ido,2,k)
               ch(m,1,k,2) = cc(m,1,1,k) + (2.*taur)*cc(m,ido,2,k) - &
                             (2.*taui)*cc(m,1,3,k)
               ch(m,1,k,3) = cc(m,1,1,k) + (2.*taur)*cc(m,ido,2,k) + &
               &                     2.*taui*cc(m,1,3,k)
10          END DO
20       END DO
         IF (ido == 1) RETURN
         idp2 = ido + 2
         DO 50 k = 1,l1
            DO 40 i = 3,ido,2
               ic = idp2 - i
               DO 30 m = 1,mp
                  ch(m,i-1,k,1) = cc(m,i-1,1,k) + &
                                  (cc(m,i-1,3,k)+cc(m,ic-1,2,k))
                  ch(m,i,k,1) = cc(m,i,1,k) + (cc(m,i,3,k)-cc(m,ic,2,k))
                  ch(m,i-1,k,2) = wa1(i-2)* ((cc(m,i-1,1,k)+taur* (cc(m, &
                                                                      i-1,3,k)+cc(m,ic-1,2,k)))- &
                                             (taui* (cc(m,i,3,k)+cc(m,ic,2,k)))) - &
                                  wa1(i-1)* ((cc(m,i,1,k)+taur* (cc(m,i,3, &
                                                                    k)-cc(m,ic,2,k)))+ (taui* (cc(m,i-1,3, &
                                                                                                  k)-cc(m,ic-1,2,k))))
                  ch(m,i,k,2) = wa1(i-2)* ((cc(m,i,1,k)+taur* (cc(m,i,3, &
                  k)-cc(m,ic,2,k)))+ (taui* (cc(m,i-1,3, &
                  k)-cc(m,ic-1,2,k)))) + &
                  wa1(i-1)* ((cc(m,i-1,1,k)+taur* (cc(m,i-1, &
                  &                        3,k)+cc(m,ic-1,2,k)))- &
                  (taui* (cc(m,i,3,k)+cc(m,ic,2,k))))
                  ch(m,i-1,k,3) = wa2(i-2)* ((cc(m,i-1,1,k)+taur* (cc(m, &
                                                                      i-1,3,k)+cc(m,ic-1,2,k)))+ &
                                             (taui* (cc(m,i,3,k)+cc(m,ic,2,k)))) - &
                                  wa2(i-1)* ((cc(m,i,1,k)+taur* (cc(m,i,3, &
                                                                    k)-cc(m,ic,2,k)))- (taui* (cc(m,i-1,3, &
                                                                                                  k)-cc(m,ic-1,2,k))))
                  ch(m,i,k,3) = wa2(i-2)* ((cc(m,i,1,k)+taur* (cc(m,i,3, &
                  k)-cc(m,ic,2,k)))- (taui* (cc(m,i-1,3, &
                  k)-cc(m,ic-1,2,k)))) + &
                  wa2(i-1)* ((cc(m,i-1,1,k)+taur* (cc(m,i-1, &
                  &                        3,k)+cc(m,ic-1,2,k)))+ &
                  (taui* (cc(m,i,3,k)+cc(m,ic,2,k))))
30             END DO
40          END DO
50       END DO
         RETURN
      END SUBROUTINE vradb3

      SUBROUTINE vradb4(mp,ido,l1,cc,ch,mdimc,wa1,wa2,wa3)

!     VRFFTPK, VERSION 1, AUGUST 1985

         IMPLICIT NONE
         INTEGER, INTENT(IN) :: mp, ido, l1, mdimc
         REAL, INTENT(IN)    :: cc(mdimc,ido,4,l1), wa1(ido), wa2(ido), &
                                wa3(ido)
         REAL, INTENT(INOUT) :: ch(mdimc,ido,l1,4)

         INTEGER :: k, m, i, idp2, ic
         REAL :: sqrt2

         sqrt2 = sqrt(2.)
         DO 20 k = 1,l1
            DO 10 m = 1,mp
               ch(m,1,k,3) = (cc(m,1,1,k)+cc(m,ido,4,k)) - &
                             (cc(m,ido,2,k)+cc(m,ido,2,k))
               ch(m,1,k,1) = (cc(m,1,1,k)+cc(m,ido,4,k)) + &
                             (cc(m,ido,2,k)+cc(m,ido,2,k))
               ch(m,1,k,4) = (cc(m,1,1,k)-cc(m,ido,4,k)) + &
                             (cc(m,1,3,k)+cc(m,1,3,k))
               ch(m,1,k,2) = (cc(m,1,1,k)-cc(m,ido,4,k)) - &
                             (cc(m,1,3,k)+cc(m,1,3,k))
10          END DO
20       END DO
         IF ( ido ==  2 ) THEN
            GOTO 70
         ELSEIF ( ido < 2 ) THEN
            GOTO 100
         ENDIF
         idp2 = ido + 2
         DO 60 k = 1,l1
            DO 50 i = 3,ido,2
               ic = idp2 - i
               DO 40 m = 1,mp
                  ch(m,i-1,k,1) = (cc(m,i-1,1,k)+cc(m,ic-1,4,k)) + &
                                  (cc(m,i-1,3,k)+cc(m,ic-1,2,k))
                  ch(m,i,k,1) = (cc(m,i,1,k)-cc(m,ic,4,k)) + &
                                (cc(m,i,3,k)-cc(m,ic,2,k))
                  ch(m,i-1,k,2) = wa1(i-2)* ((cc(m,i-1,1,k)-cc(m,ic-1,4, &
                                                               k))- (cc(m,i,3,k)+cc(m,ic,2,k))) - &
                                  wa1(i-1)* ((cc(m,i,1,k)+cc(m,ic,4,k))+ &
                                             (cc(m,i-1,3,k)-cc(m,ic-1,2,k)))
                  ch(m,i,k,2) = wa1(i-2)* ((cc(m,i,1,k)+cc(m,ic,4,k))+ &
                                           (cc(m,i-1,3,k)-cc(m,ic-1,2,k))) + &
                                wa1(i-1)* ((cc(m,i-1,1,k)-cc(m,ic-1,4,k))- &
                                           (cc(m,i,3,k)+cc(m,ic,2,k)))
                  ch(m,i-1,k,3) = wa2(i-2)* ((cc(m,i-1,1,k)+cc(m,ic-1,4, &
                                                               k))- (cc(m,i-1,3,k)+cc(m,ic-1,2,k))) - &
                                  wa2(i-1)* ((cc(m,i,1,k)-cc(m,ic,4,k))- &
                                             (cc(m,i,3,k)-cc(m,ic,2,k)))
                  ch(m,i,k,3) = wa2(i-2)* ((cc(m,i,1,k)-cc(m,ic,4,k))- &
                                           (cc(m,i,3,k)-cc(m,ic,2,k))) + &
                                wa2(i-1)* ((cc(m,i-1,1,k)+cc(m,ic-1,4,k))- &
                                           (cc(m,i-1,3,k)+cc(m,ic-1,2,k)))
                  ch(m,i-1,k,4) = wa3(i-2)* ((cc(m,i-1,1,k)-cc(m,ic-1,4, &
                                                               k))+ (cc(m,i,3,k)+cc(m,ic,2,k))) - &
                                  wa3(i-1)* ((cc(m,i,1,k)+cc(m,ic,4,k))- &
                                             (cc(m,i-1,3,k)-cc(m,ic-1,2,k)))
                  ch(m,i,k,4) = wa3(i-2)* ((cc(m,i,1,k)+cc(m,ic,4,k))- &
                                           (cc(m,i-1,3,k)-cc(m,ic-1,2,k))) + &
                                wa3(i-1)* ((cc(m,i-1,1,k)-cc(m,ic-1,4,k))+ &
                                           (cc(m,i,3,k)+cc(m,ic,2,k)))
40             END DO
50          END DO
60       END DO
         IF (mod(ido,2) == 1) RETURN
70       CONTINUE
         DO 90 k = 1,l1
            DO 80 m = 1,mp
               ch(m,ido,k,1) = (cc(m,ido,1,k)+cc(m,ido,3,k)) + &
                               (cc(m,ido,1,k)+cc(m,ido,3,k))
               ch(m,ido,k,2) = sqrt2* ((cc(m,ido,1,k)-cc(m,ido,3,k))- &
                                       (cc(m,1,2,k)+cc(m,1,4,k)))
               ch(m,ido,k,3) = (cc(m,1,4,k)-cc(m,1,2,k)) + &
                               (cc(m,1,4,k)-cc(m,1,2,k))
               ch(m,ido,k,4) = -sqrt2* ((cc(m,ido,1,k)-cc(m,ido,3,k))+ &
                                        (cc(m,1,2,k)+cc(m,1,4,k)))
80          END DO
90       END DO
100      RETURN
      END SUBROUTINE vradb4

      SUBROUTINE vradb5(mp,ido,l1,cc,ch,mdimc,wa1,wa2,wa3,wa4)

!     VRFFTPK, VERSION 1, AUGUST 1985

         USE m_constants, ONLY : pimach
         IMPLICIT NONE
         INTEGER, INTENT(IN) :: mp, ido, l1, mdimc
         REAL, INTENT(IN)    :: cc(mdimc,ido,5,l1), wa1(ido), wa2(ido), &
                                wa3(ido),wa4(ido)
         REAL, INTENT(INOUT) :: ch(mdimc,ido,l1,5)

         INTEGER :: i, k, m, ic, idp2
         REAL :: arg, tr11, ti11, tr12, ti12

         arg = 2.*pimach()/5.
         tr11 = cos(arg)
         ti11 = sin(arg)
         tr12 = cos(2.*arg)
         ti12 = sin(2.*arg)
         DO 20 k = 1,l1
            DO 10 m = 1,mp
               ch(m,1,k,1) = cc(m,1,1,k) + 2.*cc(m,ido,2,k) + &
               &                     2.*cc(m,ido,4,k)
               ch(m,1,k,2) = (cc(m,1,1,k)+tr11*2.*cc(m,ido,2,k)+ &
                              tr12*2.*cc(m,ido,4,k)) - &
                             (ti11*2.*cc(m,1,3,k)+ti12*2.*cc(m,1,5,k))
               ch(m,1,k,3) = (cc(m,1,1,k)+tr12*2.*cc(m,ido,2,k)+ &
                              tr11*2.*cc(m,ido,4,k)) - &